-
Notifications
You must be signed in to change notification settings - Fork 0
/
rTemplate.h
850 lines (674 loc) · 22.4 KB
/
rTemplate.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
// rSDK stuff
// Include guard
#ifndef RTEMPLATE_INC
#define RTEMPLATE_INC
// C++ only
#ifndef __cplusplus
#pragma message("rSDK will only compile with a C++ compiler")
#endif
// VC++ only
#ifndef _MSC_VER
#pragma message("rSDK will only compile under Microsoft Visual C++")
#endif
// Dynamic array class if needed
#ifndef _VECTOR_
template<class T> class rVector {
protected:
T * A;
size_t C;
size_t M;
public:
// Constructor and destructor
inline rVector() { M=3; C=0; A=(T *)malloc(sizeof(T)*M); }
~rVector() { free(A); }
// Copy constructor
inline rVector(rVector<T> &O) {
C=O.size();
M=C+1;
A=(T *)malloc(sizeof(T)*M);
memcpy(A,O.array(),sizeof(T)*C);
}
// Assignment operator
inline void operator = (rVector<T> &O) {
C=O.size();
M=C+1;
free(A);
A=(T *)malloc(sizeof(T)*M);
memcpy(A,O.array(),sizeof(T)*C);
}
// Push an item onto the top of the vector
inline void push_back(T O) {
if(C>=M) {
M=C*3+1;
A=(T *)realloc(A,sizeof(T)*M);
}
A[C]=O;
C++;
}
// Pop an item from the top of the vector
inline void pop_back() {
if(C<(M>>1)) {
M>>=1;
A=(T *)realloc(A,sizeof(T)*M);
}
C--;
}
// Get the size of the vector
inline size_t size() const { return C; }
// Get an item at any location in the vector
inline T at(size_t I) const { return A[I]; }
inline T operator [] (size_t I) const { return A[I]; }
// Get the last item in the vector
inline T back() const { return A[C-1]; }
// Get a raw pointer to the array
inline T * array() const { return A; }
};
#else
#define rVector vector
#endif
// Property macros
#define PROPS_IDS_START() enum { PROPID_SETTINGS=PROPID_EXTITEM_CUSTOM_FIRST,
#define PROPS_IDS_END() };
#define PROPS_DATA_START() PropData Properties[]={
#define PROPS_DATA_END() PropData_End()};
// Debugger macros
#define DEBUGGER_IDS_START() enum {
#define DEBUGGER_IDS_END() };
#define DEBUGGER_ITEMS_START() WORD DebugTree[]={
#define DEBUGGER_ITEMS_END() DB_END};
// ID macros
#ifdef __ID_TIMES_TEN__
#define CONDITION_ID(id) (26000+(id)*10)
#define ACTION_ID(id) (25000+(id)*10)
#define EXPRESSION_ID(id) (27000+(id)*10)
#else
#define CONDITION_ID(id) (26000+(id))
#define ACTION_ID(id) (25000+(id))
#define EXPRESSION_ID(id) (27000+(id))
#endif
// Some of the menu macros (the rest are specific to actions/conditions/expressions)
#define SUB_START(string) m.AddMenu(SubMenu,_T(string));
#define SUB_END m.AddMenu(MenuItem,_T(""));
#define SEPARATOR m.AddMenu(-3,_T(""));
// Should be placed globally in some CPP file
#define EXT_INIT() rVector<ExtFunction*> Conditions; \
rVector<ExtFunction*> Actions; \
rVector<ExtFunction*> Expressions; \
short * conditionsInfos; \
short * actionsInfos; \
short * expressionsInfos; \
LPCONDITION * ConditionJumps; \
LPACTION * ActionJumps; \
LPEXPRESSION * ExpressionJumps;
// Macros for the number of each type of function
#define CONDITION_COUNT Conditions.size()
#define ACTION_COUNT Actions.size()
#define EXPRESSION_COUNT Expressions.size()
// Safe variable macro- use in macros that need to declare variables to avoid any conflict (what a hack)
#define SVAR(s) _SAFE__##s##_
// Macros to return different types
#define ReturnFloat(flt) rdPtr->rHo.hoFlags|=HOF_FLOAT; return rdPtr->rRd->Float2Long(flt)
#define ReturnString(str) rdPtr->rHo.hoFlags|=HOF_STRING; return (long)str;
// For consistency
#define ReturnInteger(i) return i;
#define ReturnBool(b) return b;
// Safe return of a string- returns a copy
#define ReturnStringSafe(str) int SVAR(1)=sizeof(TCHAR)*(_tcslen(str)+1); \
TCHAR * SVAR(2)= (TCHAR*)rdPtr->rRd->GetStringSpace(SVAR(1)); \
memcpy(SVAR(2),str,SVAR(1)); \
rdPtr->rHo.hoFlags|=HOF_STRING; \
return long(SVAR(2))
// Macros to get parameters
#define ExParam(type) rdPtr->rRd->GetExpressionParameter((short)param1,type)
#define Param(type) rdPtr->rRd->GetParameter((short)param1,type)
// Copy something from edPtr to rdPtr (if it is copiable and has the same name on both sides)
#define CopyToRd(s) rdPtr->s=edPtr->s
// Fixing some of the spelling mistakes
#define PARAM_COMPARISON PARAM_COMPARAISON
// Fixing confusion
#undef PARAM_STRING
#define PARAM_STRING PARAM_EXPSTRING
#define PARAM_NUMBER PARAM_EXPRESSION
#define EXPPARAM_NUMBER EXPPARAM_LONG
// For the Param macro
#define TYPE_GENERIC 0x0003
// Registered ID constants
#define REGID_PRIVATE -1
#define REGID_RUNTIME -2
// Property strings are just cast to an int
#define PSTR(s) ((int)s)
// To generate an identifier
#define MAKEID(a,b,c,d) ((#@a<<24)|(#@b<<16)|(#@c<<8)|(#@d))
// The build of MMF
#define MMF_BUILD (mV->mvGetVersion()&MMFBUILD_MASK)
// Common include
#include "common.h"
// Typedefs for pointers to actions, conditions and expressions
typedef long (WINAPI DLLExport * LPCONDITION)(LPRDATA,long,long);
typedef short (WINAPI DLLExport * LPACTION)(LPRDATA,long,long);
typedef long (WINAPI DLLExport * LPEXPRESSION)(LPRDATA,long);
// Class to hold a list of parameters (thanks turbo)
class param_list {
public:
// The constructor fills up the vectors with the given parameters
param_list(size_t count,...) {
// Variable argument list
va_list list;
// Start going through the arguments
va_start(list,count);
// This is twice the number of parameters given
int count_dbl=count*2;
// Loop through all the arguments
for(int i=0;i<count_dbl;i++) {
// If the argument is odd
if(i%2==0)
// It must be a type; push it onto the types vector
Type.push_back(va_arg(list,short));
// If the argument is even
else
// It must be a name; push it onto the names vector
Name.push_back(va_arg(list,const TCHAR *));
}
// Stop going through the arguments
va_end(list);
}
// This will hold the type of each argument
rVector<short> Type;
// This will hold the name of each argument
rVector<const TCHAR *> Name;
};
// Temporary declaration of the ExtFunction class
class ExtFunction;
// Extern declarations of the condition, action and expression vectors
extern rVector<ExtFunction*> Conditions;
extern rVector<ExtFunction*> Actions;
extern rVector<ExtFunction*> Expressions;
// This class holds an action, condition or expression
class ExtFunction {
protected:
// A vector to hold the types of the parameters
rVector<short> ParamTypes;
// A vector to hold the names of the parameters
rVector<const TCHAR *> ParamStrings;
// Pointers to conditions, actions and expressions- we have them all but don't use them all
LPCONDITION mCondition;
LPACTION mAction;
LPEXPRESSION mExpression;
// The name of the function
const TCHAR * Name;
// The flags
short Flags;
public:
// The first constructor overload, for a condition
ExtFunction(LPCONDITION con,short flags,const TCHAR * name,param_list params) {
// Set the condition pointer
mCondition=con;
// Store the param types/names and function name
ParamTypes=params.Type;
ParamStrings=params.Name;
Name=name;
// Store the function flags
Flags=flags;
// Push the function into the vector
Conditions.push_back(this);
}
// Constructor overload for an action
ExtFunction(LPACTION act,short flags,const TCHAR * name,param_list params) {
// Set the action pointer
mAction=act;
// Store the param types/names and function name
ParamTypes=params.Type;
ParamStrings=params.Name;
Name=name;
// Store the function flags
Flags=flags;
// Push the function into the vector
Actions.push_back(this);
}
// Constructor overload for an expression
ExtFunction(LPEXPRESSION exp,short flags,const TCHAR * name,param_list params) {
// Set the expression pointer
mExpression=exp;
// Store the param types/names and function name
ParamTypes=params.Type;
ParamStrings=params.Name;
Name=name;
// Store the function flags
Flags=flags;
// Push the function into the vector
Expressions.push_back(this);
}
// Inline functions to access protected variables
inline LPCONDITION getCondition() { return mCondition; }
inline LPACTION getAction() { return mAction; }
inline LPEXPRESSION getExpression() { return mExpression; }
inline const TCHAR * getName() { return Name; }
inline size_t getParamCount() { return ParamTypes.size(); }
inline short getParamType(size_t i) { return ParamTypes[i]; }
inline const TCHAR * getParamName(size_t i) { return ParamStrings[i]; }
inline short getFlags() { return Flags; }
};
// Macro for a condition in main.cpp
#define CONDITION(num, name, flags, params) \
long WINAPI DLLExport ConditionFunc##num(LPRDATA, long, long); \
ExtFunction ConditionClass##num((LPCONDITION)ConditionFunc##num, flags, name, param_list##params); \
long WINAPI DLLExport ConditionFunc##num(LPRDATA rdPtr, long param1, long param2) \
// Macro for an action in main.cpp
#ifndef OPTIMIZED_ACTION
#define ACTION(num, name, flags, params) \
short WINAPI DLLExport ActionFunc##num(LPRDATA, long, long); \
void IActionFunc##num(LPRDATA, long, long); \
ExtFunction ActionClass##num((LPACTION)ActionFunc##num, flags, name, param_list##params); \
short WINAPI DLLExport ActionFunc##num(LPRDATA rdPtr, long param1, long param2) { \
IActionFunc##num(rdPtr,param1,param2); return 0; \
} inline void IActionFunc##num(LPRDATA rdPtr,long param1, long param2)
#else
#define ACTION(num, name, flags, params) \
short WINAPI DLLExport ActionFunc##num(LPRDATA, long, long); \
ExtFunction ActionClass##num((LPACTION)ActionFunc##num, flags, name, param_list##params); \
short WINAPI DLLExport ActionFunc##num(LPRDATA rdPtr, long param1, long param2)
#endif
// Macro for an expression in main.cpp
//#define EXPRESSION(num, name, flags, params) \
// long WINAPI DLLExport ExpressionFunc##num(LPRDATA rdPtr, long param1); \
// long IExpressionFunc##num(LPRDATA, long); \
// ExtFunction ExpressionClass##num((LPEXPRESSION)ExpressionFunc##num, flags, name, param_list##params); \
// long WINAPI DLLExport ExpressionFunc##num(LPRDATA rdPtr, long param1) { \
// rdPtr->rRd->P_GetExpressionParameter=G_GetFirstExpressionParameter; \
// return IExpressionFunc##num(rdPtr,param1); \
// } inline long IExpressionFunc##num(LPRDATA rdPtr,long param1)
#define EXPRESSION(num, name, flags, params) \
long WINAPI DLLExport ExpressionFunc##num(LPRDATA rdPtr, long param1); \
long IExpressionFunc##num(LPRDATA, long); \
ExtFunction ExpressionClass##num((LPEXPRESSION)ExpressionFunc##num, flags, name, param_list##params); \
long WINAPI DLLExport ExpressionFunc##num(LPRDATA rdPtr, long param1) { \
long (* cur)(LPRDATA rdPtr,short param1,long type) = rdPtr->rRd->P_GetExpressionParameter; \
rdPtr->rRd->P_GetExpressionParameter=G_GetFirstExpressionParameter; \
long ret = IExpressionFunc##num(rdPtr,param1); \
rdPtr->rRd->P_GetExpressionParameter = cur; \
return ret; \
} inline long IExpressionFunc##num(LPRDATA rdPtr,long param1)
// Include oop_ext.h (the code from TurboTemplate)
#include "oop_ext.h"
// Constants for the menu class
const int SubMenu=-1;
const int MenuItem=-2;
const int Separator=-3;
#ifndef RUN_ONLY
// Class to hold a menu
class Menu {
private:
HMENU RootMenu;
rVector<HMENU> SubMenus;
rVector<const TCHAR *> SubMenuNames;
public:
// The constructor creates a root menu and pushes it onto the submenu vector
Menu() {
RootMenu=CreateMenu();
SubMenus.push_back(RootMenu);
}
void AddMenu(int id,const TCHAR * str,bool disabled=false) {
if(id>0) {
AppendMenu(SubMenus.back(),MF_BYPOSITION|MF_STRING,id,str);
} else if(id==SubMenu) {
HMENU hSubMenu=CreatePopupMenu();
SubMenus.push_back(hSubMenu);
SubMenuNames.push_back(str);
} else if(id==MenuItem&&!disabled) {
AppendMenu(SubMenus[SubMenus.size()-2],MF_BYPOSITION|MF_STRING|MF_POPUP,(UINT)SubMenus.back(), SubMenuNames.back());
SubMenus.pop_back();
SubMenuNames.pop_back();
} else if(id==MenuItem&&disabled) {
AppendMenu(SubMenus[SubMenus.size()-2],MF_BYPOSITION|MF_STRING|MF_POPUP|MF_GRAYED,(UINT)SubMenus.back(),SubMenuNames.back());
SubMenus.pop_back();
SubMenuNames.pop_back();
} else if(id==Separator) {
AppendMenu(SubMenus.back(),MF_BYPOSITION|MF_SEPARATOR,0,NULL);
}
}
inline HMENU GetMenu() { return RootMenu; }
};
inline HMENU ConditionMenu(LPEDATA edPtr) {
#define CONDITION_MENU
#define ITEM(id,string) m.AddMenu(CONDITION_ID(id),_T(string));
#define DISABLED(id,string) m.AddMenu(CONDITION_ID(id),_T(string),true);
Menu m;
#include "menu.h"
return m.GetMenu();
#undef CONDITION_MENU
#undef ITEM
#undef DISABLED
}
inline HMENU ActionMenu(LPEDATA edPtr) {
#define ACTION_MENU
#define ITEM(id,string) m.AddMenu(ACTION_ID(id),_T(string));
#define DISABLED(id,string) m.AddMenu(ACTION_ID(id),_T(string),true);
Menu m;
#include "menu.h"
return m.GetMenu();
#undef ACTION_MENU
#undef ITEM
#undef DISABLED
}
inline HMENU ExpressionMenu(LPEDATA edPtr) {
#define EXPRESSION_MENU
#define ITEM(id,string) m.AddMenu(EXPRESSION_ID(id),_T(string));
#define DISABLED(id,string) m.AddMenu(EXPRESSION_ID(id),_T(string),true);
Menu m;
#include "menu.h"
return m.GetMenu();
#undef EXPRESSION_MENU
#undef ITEM
#undef DISABLED
}
#endif
// A function designed to be called by the rRd thread functions
typedef void (__cdecl * rThread)(LPRDATA);
// Global functions to get expression parameters
inline long G_GetFirstExpressionParameter(LPRDATA rdPtr,short param1,long type);
inline long G_GetNextExpressionParameter(LPRDATA rdPtr,short param1,long type);
// A class to hold runtime functions
class rRundata {
protected:
// A pointer to rdPtr
LPRDATA rdPtr;
public:
// Class constructor
inline rRundata(LPRDATA _rdPtr) {
rdPtr=_rdPtr;
P_GetExpressionParameter=G_GetFirstExpressionParameter;
}
// A function pointer to one of the parameter functions
long (* P_GetExpressionParameter)(LPRDATA rdPtr,short param1,long type);
// A function to call the function pointer
inline long GetExpressionParameter(short param1,long type) {
return P_GetExpressionParameter(rdPtr,param1,type);
}
// Functions to get expression parameters
inline long GetFirstExpressionParameter(short param1,long type) {
return G_GetFirstExpressionParameter(rdPtr,param1,type);
}
inline long GetNextExpressionParameter(short param1,long type) {
return G_GetNextExpressionParameter(rdPtr,param1,type);
}
// Function to get action/condition parameters
inline long GetParameter(short param1,long type) {
switch(type) {
default:
return CNC_GetParameter(rdPtr);
case TYPE_INT:
return CNC_GetIntParameter(rdPtr);
case TYPE_STRING:
return CNC_GetStringParameter(rdPtr);
case TYPE_FLOAT:
long tmpf=CNC_GetFloatParameter(rdPtr);
float param=*(float*)&tmpf;
return (long)param;
};
}
// To call a runtime function
inline long CallFunction(short funcNum, short wParam, long lParam) {
return callRunTimeFunction(rdPtr,funcNum,wParam,lParam);
}
// Forces the HandleRunObject routine to be called at next loop
inline void Rehandle() {
CallFunction(RFUNCTION_REHANDLE,0,0);
}
// Generates a triggered event
inline void GenerateEvent(int EventID) {
CallFunction(RFUNCTION_GENERATEEVENT,EventID,0);
}
// Generate an event at the end of the loop (safer)
inline void PushEvent(int EventID) {
CallFunction(RFUNCTION_PUSHEVENT,EventID,0);
}
// Allocate some space to store a string
inline TCHAR * GetStringSpace(size_t size) {
return (TCHAR *)callRunTimeFunction(rdPtr,RFUNCTION_GETSTRINGSPACE_EX,0,size*sizeof(TCHAR));
}
// Pause the application before a lengthy task, without messing up timers etc.
inline void Pause() {
CallFunction(RFUNCTION_PAUSE,0,0);
}
// Continue the application after pausing
inline void Continue() {
CallFunction(RFUNCTION_CONTINUE,0,0);
}
// Force a complete redraw of the frame
inline void Redisplay() {
CallFunction(RFUNCTION_REDISPLAY,0,0);
}
// Get the drive of the application
inline void GetApplicationDrive(TCHAR * buf) {
CallFunction(RFUNCTION_GETFILEINFOS,FILEINFO_DRIVE,(long)buf);
}
// Get the directory of the application
inline void GetApplicationDirectory(TCHAR * buf) {
CallFunction(RFUNCTION_GETFILEINFOS,FILEINFO_DIR,(long)buf);
}
// Get the complete path of the application
inline void GetApplicationPath(TCHAR * buf) {
CallFunction(RFUNCTION_GETFILEINFOS,FILEINFO_PATH,(long)buf);
}
// Get the application name
inline void GetApplicationName(TCHAR * buf) {
CallFunction(RFUNCTION_GETFILEINFOS,FILEINFO_APPNAME,(long)buf);
}
// Force a call of the DisplayRunObject routine during the display update process
inline void Redraw() {
CallFunction(RFUNCTION_REDRAW,0,0);
}
// Destroy the object
inline void Destroy() {
CallFunction(RFUNCTION_DESTROY,0,0);
}
// Execute an external program
inline void ExecuteProgram(prgParam * program) {
CallFunction(RFUNCTION_EXECPROGRAM,0,(long)program);
}
// Open a dialog box to edit a integer value.
inline long EditInt(EditDebugInfo * edi) {
return CallFunction(RFUNCTION_EDITINT,0,(long)edi);
}
// Open a dialog box to edit a string
inline long EditText(EditDebugInfo * edi) {
return CallFunction(RFUNCTION_EDITTEXT,0,(long)edi);
}
// Call a movement's ActionEntry function
inline void CallMovement(short id,long param) {
CallFunction(RFUNCTION_CALLMOVEMENT,id,param);
}
// Change the position of the object
inline void SetPosition(int x,int y) {
CallFunction(RFUNCTION_SETPOSITION,x,y);
}
// Simplify creating threads with rdPtr access
inline HANDLE StartThread(rThread function) {
return CreateThread(0,0,(LPTHREAD_START_ROUTINE)function,rdPtr,0,0);
}
// Grab the cSurface of another object
void GrabSurface(LPRO object,cSurface &destination) {
fprh rhPtr=rdPtr->rHo.hoAdRunHeader;
cSurface imageSurface;
LockImageSurface(rhPtr->rhIdAppli,object->roc.rcImage,imageSurface);
destination=imageSurface;
UnlockImageSurface(imageSurface);
}
// Convert a float to a long for returning to MMF
long Float2Long(double value) {
float IntoFloat=(float)value;
long myAnswer=0;
memcpy((void *)&myAnswer,(void *)&IntoFloat,sizeof(float));
return myAnswer;
}
// All the (useful) TigsExt.hpp functions which people might miss
// are now included in rRundata (or at least similar stuff)
// Check if a number is within the bounds of min and max
inline bool CheckBounds(int number,int min,int max) {
return !(number<min||number>max);
}
// Float version
inline bool CheckBounds(float number,float min,float max) {
return !(number<min||number>max);
}
// Force a number to be within the bounds of min and max
inline int ForceBounds(int number,int min,int max) {
number=number>max?max:number;
number=number<min?min:number;
return number;
}
// Float version
inline float ForceBounds(float number,float min,float max) {
number=number>max?max:number;
number=number<min?min:number;
return number;
}
// Convert an LPRO to a fixed value
inline int LPRO2Fixed(LPRO o) {
return ((o->roHo.hoCreationId<<16)+o->roHo.hoNumber);
}
// Convert a fixed value to an LPRO
inline LPRO Fixed2LPRO(int fixed) {
LPOBL objList=rdPtr->rHo.hoAdRunHeader->rhObjectList;
return LPRO(objList[0x0000FFFF&fixed].oblOffset);
}
// Call a function in an LPRO
inline void LPRO_CallFunction(LPRO o,short funcNum, short wParam=0, long lParam=0) {
LPRH(o->roHo.hoAdRunHeader)->rh4.rh4KpxFunctions[funcNum].routine((LPHO)o,wParam,lParam);
}
// Update an LPRO
inline void LPRO_Update(LPRO o) {
o->roc.rcChanged=1;
}
// Check if an LPRO is destroyed
inline bool LPRO_IsDestroyed(LPRO o) {
return (o->roHo.hoFlags&HOF_DESTROYED?1:0);
}
// Move an LPRO
inline void LPRO_Move(LPRO o,int x,int y) {
LPRO_CallFunction(o,RFUNCTION_SETPOSITION,x,y);
}
// Rehandle an LPRO
inline void LPRO_Rehandle(LPRO o) {
LPRO_CallFunction(o,RFUNCTION_REHANDLE);
}
// Redraw an LPRO
inline void LPRO_Redraw(LPRO o) {
LPRO_CallFunction(o,RFUNCTION_REDRAW);
}
// Generate an event within an LPRO
inline void LPRO_GenerateEvent(LPRO o,int EventNumber) {
LPRO_CallFunction(o,RFUNCTION_GENERATEEVENT,EventNumber);
}
// Push an event within an LPRO
inline void LPRO_PushEvent(LPRO o,int EventNumber) {
LPRO_CallFunction(o,RFUNCTION_PUSHEVENT,EventNumber);
}
// Destroy an LPRO
inline void LPRO_Destroy(LPRO o) {
LPRO_CallFunction(o,RFUNCTION_DESTROY);
}
};
// The actual functions for getting parameters
inline long G_GetFirstExpressionParameter(LPRDATA rdPtr,short param1,long type) {
rdPtr->rRd->P_GetExpressionParameter=G_GetNextExpressionParameter;
return CNC_GetFirstExpressionParameter(rdPtr,param1,type);
}
inline long G_GetNextExpressionParameter(LPRDATA rdPtr,short param1,long type) {
return CNC_GetNextExpressionParameter(rdPtr,param1,type);
}
// A long pointer to rRundata
typedef rRundata * LPRRDATA;
// Makes the flags based on what was defined in information.h
inline void MagicFlags(DWORD &d) {
d=0;
#ifdef M_OEFLAG_DISPLAYINFRONT
d|=OEFLAG_DISPLAYINFRONT;
#endif
#ifdef M_OEFLAG_BACKGROUND
d|=OEFLAG_BACKGROUND;
#endif
#ifdef M_OEFLAG_BACKSAVE
d|=OEFLAG_BACKSAVE;
#endif
#ifdef M_OEFLAG_RUNBEFOREFADEIN
d|=OEFLAG_RUNBEFOREFADEIN;
#endif
#ifdef M_OEFLAG_MOVEMENTS
d|=OEFLAG_MOVEMENTS;
#endif
#ifdef M_OEFLAG_ANIMATIONS
d|=OEFLAG_ANIMATIONS;
#endif
#ifdef M_OEFLAG_TABSTOP
d|=OEFLAG_TABSTOP;
#endif
#ifdef M_OEFLAG_WINDOWPROC
d|=OEFLAG_WINDOWPROC;
#endif
#ifdef M_OEFLAG_VALUES
d|=OEFLAG_VALUES;
#endif
#ifdef M_OEFLAG_SPRITES
d|=OEFLAG_SPRITES;
#endif
#ifdef M_OEFLAG_INTERNALBACKSAVE
d|=OEFLAG_INTERNALBACKSAVE;
#endif
#ifdef M_OEFLAG_SCROLLINGINDEPENDANT
d|=OEFLAG_SCROLLINGINDEPENDANT;
#endif
#ifdef M_OEFLAG_QUICKDISPLAY
d|=OEFLAG_QUICKDISPLAY;
#endif
#ifdef M_OEFLAG_NEVERKILL
d|=OEFLAG_NEVERKILL;
#endif
#ifdef M_OEFLAG_NEVERSLEEP
d|=OEFLAG_NEVERSLEEP;
#endif
#ifdef M_OEFLAG_MANUALSLEEP
d|=OEFLAG_MANUALSLEEP;
#endif
#ifdef M_OEFLAG_TEXT
d|=OEFLAG_TEXT;
#endif
}
// Makes the prefs based on what was defined in information.h
inline void MagicPrefs(short &d) {
d=0;
#ifdef M_OEPREFS_BACKSAVE
d|=OEPREFS_BACKSAVE;
#endif
#ifdef M_OEPREFS_SCROLLINGINDEPENDANT
d|=OEPREFS_SCROLLINGINDEPENDANT;
#endif
#ifdef M_OEPREFS_QUICKDISPLAY
d|=OEPREFS_QUICKDISPLAY;
#endif
#ifdef M_OEPREFS_SLEEP
d|=OEPREFS_SLEEP;
#endif
#ifdef M_OEPREFS_LOADONCALL
d|=OEPREFS_LOADONCALL;
#endif
#ifdef M_OEPREFS_GLOBAL
d|=OEPREFS_GLOBAL;
#endif
#ifdef M_OEPREFS_BACKEFFECTS
d|=OEPREFS_BACKEFFECTS;
#endif
#ifdef M_OEPREFS_KILL
d|=OEPREFS_KILL;
#endif
#ifdef M_OEPREFS_INKEFFECTS
d|=OEPREFS_INKEFFECTS;
#endif
#ifdef M_OEPREFS_TRANSITIONS
d|=OEPREFS_TRANSITIONS;
#endif
#ifdef M_OEPREFS_FINECOLLISIONS
d|=OEPREFS_FINECOLLISIONS;
#endif
}
#endif // !RTEMPLATE_INC