-
Notifications
You must be signed in to change notification settings - Fork 0
/
Runtime.cpp
442 lines (386 loc) · 10.4 KB
/
Runtime.cpp
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
// ============================================================================
//
// This file contains routines that are handled during the Runtime
//
// ============================================================================
// Common Include
#include "common.h"
// --------------------
// GetRunObjectDataSize
// --------------------
// Returns the size of the runtime datazone of the object
//
short WINAPI DLLExport GetRunObjectDataSize(fprh rhPtr, LPEDATA edPtr)
{
return(sizeof(RUNDATA));
}
// ---------------
// CreateRunObject
// ---------------
// The routine where the object is actually created
//
short WINAPI DLLExport CreateRunObject(LPRDATA rdPtr, LPEDATA edPtr, fpcob cobPtr)
{
// Do some rSDK stuff
new (rdPtr) RUNDATA; //Call rdPtr's Constructor
#include "rCreateRunObject.h"
/*
This routine runs when your object is created, as you might have guessed.
It is here that you must transfer any data you need in rdPtr from edPtr,
because after this has finished you cannot access it again!
Also, if you have anything to initialise (e.g. dynamic arrays, surface objects)
you should do it here, and free your resources in DestroyRunObject.
See Graphic_Object_Ex.txt for an example of what you may put here.
*/
// No errors
return 0;
}
// ----------------
// DestroyRunObject
// ----------------
// Destroys the run-time object
//
short WINAPI DLLExport DestroyRunObject(LPRDATA rdPtr, long fast)
{
/*
When your object is destroyed (either with a Destroy action or at the end of
the frame) this routine is called. You must free any resources you have allocated!
See Graphic_Object_Ex.txt for an example of what you may put here.
*/
// No errors
delete rdPtr->rRd;
rdPtr->~RUNDATA();
return 0;
}
// ----------------
// HandleRunObject
// ----------------
// Called (if you want) each loop, this routine makes the object live
//
short WINAPI DLLExport HandleRunObject(LPRDATA rdPtr)
{
//Needs to add fixed value to vector array
/*
If your extension will draw to the MMF window you should first
check if anything about its display has changed :
return rdPtr->roc.rcChanged?REFLAG_DISPLAY:0;
You will also need to make sure you change this flag yourself
to 1 whenever you want to redraw your object
If your extension won't draw to the window, but it still needs
to do something every MMF loop use :
return 0;
If you don't need to do something every loop, use :
return REFLAG_ONESHOT;
This doesn't mean this function can never run again. If you want MMF
to handle your object again (causing this code to run) use this function:
rdPtr->rRd->Rehandle();
At the end of the loop this code will run
*/
return 0;
}
// ----------------
// DisplayRunObject
// ----------------
// Draw the object in the application screen.
//
short WINAPI DLLExport DisplayRunObject(LPRDATA rdPtr)
{
/*
If you return REFLAG_DISPLAY in HandleRunObject this routine will run.
See Graphic_Object_Ex.txt for an example of what you may put here.
*/
// Ok
return 0;
}
// -------------------
// GetRunObjectSurface
// -------------------
// Implement this function instead of DisplayRunObject if your extension
// supports ink effects and transitions. Note: you can support ink effects
// in DisplayRunObject too, but this is automatically done if you implement
// GetRunObjectSurface (MMF applies the ink effect to the transition).
//
// Note: do not forget to enable the function in the .def file
// if you remove the comments below.
/*
cSurface* WINAPI DLLExport GetRunObjectSurface(LPRDATA rdPtr)
{
return NULL;
}
*/
// -------------------------
// GetRunObjectCollisionMask
// -------------------------
// Implement this function if your extension supports fine collision mode (OEPREFS_FINECOLLISIONS),
// Or if it's a background object and you want Obstacle properties for this object.
//
// Should return NULL if the object is not transparent.
//
// Note: do not forget to enable the function in the .def file
// if you remove the comments below.
//
/*
cSurface* WINAPI DLLExport GetRunObjectCollisionMask(LPRDATA rdPtr, LPARAM lParam)
{
// Typical example for active objects
// ----------------------------------
// Opaque? collide with box
if ( (rdPtr->rs.rsEffect & EFFECTFLAG_TRANSPARENT) == 0 ) // Note: only if your object has the OEPREFS_INKEFFECTS option
return NULL;
// Transparent? Create mask
LPSMASK pMask = rdPtr->m_pColMask;
if ( pMask == NULL )
{
if ( rdPtr->m_pSurface != NULL )
{
DWORD dwMaskSize = rdPtr->m_pSurface->CreateMask(NULL, lParam);
if ( dwMaskSize != 0 )
{
pMask = (LPSMASK)calloc(dwMaskSize, 1);
if ( pMask != NULL )
{
rdPtr->m_pSurface->CreateMask(pMask, lParam);
rdPtr->m_pColMask = pMask;
}
}
}
}
// Note: for active objects, lParam is always the same.
// For background objects (OEFLAG_BACKGROUND), lParam maybe be different if the user uses your object
// as obstacle and as platform. In this case, you should store 2 collision masks
// in your data: one if lParam is 0 and another one if lParam is different from 0.
return pMask;
}
*/
// ----------------
// PauseRunObject
// ----------------
// Enters the pause mode
//
short WINAPI DLLExport PauseRunObject(LPRDATA rdPtr)
{
// Ok
return 0;
}
// -----------------
// ContinueRunObject
// -----------------
// Quits the pause mode
//
short WINAPI DLLExport ContinueRunObject(LPRDATA rdPtr)
{
// Ok
return 0;
}
// ============================================================================
//
// START APP / END APP / START FRAME / END FRAME routines
//
// ============================================================================
// -------------------
// StartApp
// -------------------
// Called when the application starts or restarts.
// Useful for storing global data
//
void WINAPI DLLExport StartApp(mv _far *mV, CRunApp* pApp)
{
// Example
// -------
// Delete global data (if restarts application)
// CMyData* pData = (CMyData*)mV->mvGetExtUserData(pApp, hInstLib);
// if ( pData != NULL )
// {
// delete pData;
// mV->mvSetExtUserData(pApp, hInstLib, NULL);
// }
}
// -------------------
// EndApp
// -------------------
// Called when the application ends.
//
void WINAPI DLLExport EndApp(mv _far *mV, CRunApp* pApp)
{
// Example
// -------
// Delete global data
// CMyData* pData = (CMyData*)mV->mvGetExtUserData(pApp, hInstLib);
// if ( pData != NULL )
// {
// delete pData;
// mV->mvSetExtUserData(pApp, hInstLib, NULL);
// }
}
// -------------------
// StartFrame
// -------------------
// Called when the frame starts or restarts.
//
void WINAPI DLLExport StartFrame(mv _far *mV, DWORD dwReserved, int nFrameIndex)
{
}
// -------------------
// EndFrame
// -------------------
// Called when the frame ends.
//
void WINAPI DLLExport EndFrame(mv _far *mV, DWORD dwReserved, int nFrameIndex)
{
}
// ============================================================================
//
// TEXT ROUTINES (if OEFLAG_TEXT)
//
// ============================================================================
// -------------------
// GetRunObjectFont
// -------------------
// Return the font used by the object.
//
/*
// Note: do not forget to enable the functions in the .def file
// if you remove the comments below.
void WINAPI GetRunObjectFont(LPRDATA rdPtr, LOGFONT* pLf)
{
// Example
// -------
// GetObject(rdPtr->m_hFont, sizeof(LOGFONT), pLf);
}
// -------------------
// SetRunObjectFont
// -------------------
// Change the font used by the object.
//
void WINAPI SetRunObjectFont(LPRDATA rdPtr, LOGFONT* pLf, RECT* pRc)
{
// Example
// -------
// HFONT hFont = CreateFontIndirect(pLf);
// if ( hFont != NULL )
// {
// if (rdPtr->m_hFont!=0)
// DeleteObject(rdPtr->m_hFont);
// rdPtr->m_hFont = hFont;
// SendMessage(rdPtr->m_hWnd, WM_SETFONT, (WPARAM)rdPtr->m_hFont, FALSE);
// }
}
// ---------------------
// GetRunObjectTextColor
// ---------------------
// Return the text color of the object.
//
COLORREF WINAPI GetRunObjectTextColor(LPRDATA rdPtr)
{
// Example
// -------
return 0; // rdPtr->m_dwColor;
}
// ---------------------
// SetRunObjectTextColor
// ---------------------
// Change the text color of the object.
//
void WINAPI SetRunObjectTextColor(LPRDATA rdPtr, COLORREF rgb)
{
// Example
// -------
rdPtr->m_dwColor = rgb;
InvalidateRect(rdPtr->m_hWnd, NULL, TRUE);
}
*/
// ============================================================================
//
// DEBUGGER ROUTINES
//
// ============================================================================
// -----------------
// GetDebugTree
// -----------------
// This routine returns the address of the debugger tree
//
LPWORD WINAPI DLLExport GetDebugTree(LPRDATA rdPtr)
{
#if !defined(RUN_ONLY)
return DebugTree;
#else
return NULL;
#endif // !defined(RUN_ONLY)
}
// -----------------
// GetDebugItem
// -----------------
// This routine returns the text of a given item.
//
void WINAPI DLLExport GetDebugItem(LPSTR pBuffer, LPRDATA rdPtr, int id)
{
#if !defined(RUN_ONLY)
// Example
// -------
/*
char temp[DB_BUFFERSIZE];
switch (id)
{
case DB_CURRENTSTRING:
LoadString(hInstLib, IDS_CURRENTSTRING, temp, DB_BUFFERSIZE);
wsprintf(pBuffer, temp, rdPtr->text);
break;
case DB_CURRENTVALUE:
LoadString(hInstLib, IDS_CURRENTVALUE, temp, DB_BUFFERSIZE);
wsprintf(pBuffer, temp, rdPtr->value);
break;
case DB_CURRENTCHECK:
LoadString(hInstLib, IDS_CURRENTCHECK, temp, DB_BUFFERSIZE);
if (rdPtr->check)
wsprintf(pBuffer, temp, "TRUE");
else
wsprintf(pBuffer, temp, "FALSE");
break;
case DB_CURRENTCOMBO:
LoadString(hInstLib, IDS_CURRENTCOMBO, temp, DB_BUFFERSIZE);
wsprintf(pBuffer, temp, rdPtr->combo);
break;
}
*/
#endif // !defined(RUN_ONLY)
}
// -----------------
// EditDebugItem
// -----------------
// This routine allows to edit editable items.
//
void WINAPI DLLExport EditDebugItem(LPRDATA rdPtr, int id)
{
#if !defined(RUN_ONLY)
// Example
// -------
/*
switch (id)
{
case DB_CURRENTSTRING:
{
EditDebugInfo dbi;
char buffer[256];
dbi.pText=buffer;
dbi.lText=TEXT_MAX;
dbi.pTitle=NULL;
strcpy(buffer, rdPtr->text);
long ret=callRunTimeFunction(rdPtr, RFUNCTION_EDITTEXT, 0, (LPARAM)&dbi);
if (ret)
strcpy(rdPtr->text, dbi.pText);
}
break;
case DB_CURRENTVALUE:
{
EditDebugInfo dbi;
dbi.value=rdPtr->value;
dbi.pTitle=NULL;
long ret=callRunTimeFunction(rdPtr, RFUNCTION_EDITINT, 0, (LPARAM)&dbi);
if (ret)
rdPtr->value=dbi.value;
}
break;
}
*/
#endif // !defined(RUN_ONLY)
}