orx 1.16
Portable Game Engine
Loading...
Searching...
No Matches
orx.h
Go to the documentation of this file.
1/* Orx - Portable Game Engine
2 *
3 * Copyright (c) 2008- Orx-Project
4 *
5 * This software is provided 'as-is', without any express or implied
6 * warranty. In no event will the authors be held liable for any damages
7 * arising from the use of this software.
8 *
9 * Permission is granted to anyone to use this software for any purpose,
10 * including commercial applications, and to alter it and redistribute it
11 * freely, subject to the following restrictions:
12 *
13 * 1. The origin of this software must not be misrepresented; you must not
14 * claim that you wrote the original software. If you use this software
15 * in a product, an acknowledgment in the product documentation would be
16 * appreciated but is not required.
17 *
18 * 2. Altered source versions must be plainly marked as such, and must not be
19 * misrepresented as being the original software.
20 *
21 * 3. This notice may not be removed or altered from any source
22 * distribution.
23 */
24
32
40
41#ifdef __EMSCRIPTEN__
42#include <emscripten.h>
43#endif /* __EMSCRIPTEN__ */
44
45#ifdef __cplusplus
46extern "C" {
47#endif /* __cplusplus */
48
49#ifndef _orx_H_
50#define _orx_H_
51
52#define __orxEXTERN__ /* Not compiling orx library */
53
54
55#include "orxInclude.h"
56#include "orxKernel.h"
57#include "orxUtils.h"
58
59#ifndef __orxPLUGIN__
60
61/***************************************************************************
62 * Static variables *
63 ***************************************************************************/
64
67static orxBOOL sbStopByEvent = orxFALSE;
68
69
70/***************************************************************************
71 * Public functions *
72 ***************************************************************************/
73
78static orxSTATUS orxFASTCALL orx_DefaultEventHandler(const orxEVENT *_pstEvent)
79{
81
82 /* Checks */
84 orxASSERT(_pstEvent->eID == orxSYSTEM_EVENT_CLOSE);
85
86 /* Updates status */
88
89 /* Done! */
90 return eResult;
91}
92
109
110/* iOS */
111#if defined(__orxIOS__)
112
113 #ifdef __orxOBJC__
114
115#import <UIKit/UIKit.h>
116
119@interface orxAppDelegate : NSObject <UIAccelerometerDelegate>
120{
121 UIWindow *poWindow;
122 orxViewController *poViewController;
123}
124
125@property (nonatomic, retain) UIWindow *poWindow;
126@property (nonatomic, retain) UIViewController *poViewController;
127
128- (void) MainLoop;
129
130@end
131
132extern orxSTATUS (orxFASTCALL *spfnRun)();
133
141static orxINLINE void orx_Execute(orxU32 _u32NbParams, orxSTRING _azParams[], const orxMODULE_INIT_FUNCTION _pfnInit, const orxMODULE_RUN_FUNCTION _pfnRun, const orxMODULE_EXIT_FUNCTION _pfnExit)
142{
143 /* Inits the Debug System */
145
146 /* Checks */
147 orxASSERT(_u32NbParams > 0);
148 orxASSERT(_azParams != orxNULL);
149 orxASSERT(_pfnRun != orxNULL);
150
151 /* Registers main module */
152 orxModule_Register(orxMODULE_ID_MAIN, "MAIN", orx_MainSetup, _pfnInit, _pfnExit);
153
154 /* Stores run callback */
155 spfnRun = _pfnRun;
156
157 /* Sends the command line arguments to orxParam module */
158 if(orxParam_SetArgs(_u32NbParams, _azParams) != orxSTATUS_FAILURE)
159 {
160 NSAutoreleasePool *poPool;
161
162 /* Allocates memory pool */
163 poPool = [[NSAutoreleasePool alloc] init];
164
165 /* Launches application */
166 UIApplicationMain(_u32NbParams, _azParams, nil, @"orxAppDelegate");
167
168 /* Releases memory pool */
169 [poPool release];
170
171 /* Clears params */
172 orxParam_SetArgs(0, orxNULL);
173 }
174
175 /* Done! */
176 return;
177}
178
179 #endif /* __orxOBJC__ */
180
181/* Android */
182#elif defined(__orxANDROID__)
183
185
193static orxINLINE void orx_Execute(orxU32 _u32NbParams, orxSTRING _azParams[], const orxMODULE_INIT_FUNCTION _pfnInit, const orxMODULE_RUN_FUNCTION _pfnRun, const orxMODULE_EXIT_FUNCTION _pfnExit)
194{
195 /* Inits the Debug System */
197
198 /* Checks */
199 orxASSERT(_pfnRun != orxNULL);
200
201 /* Registers main module */
202 orxModule_Register(orxMODULE_ID_MAIN, "MAIN", orx_MainSetup, _pfnInit, _pfnExit);
203
204 /* Sends the command line arguments to orxParam module */
205 if(orxParam_SetArgs(_u32NbParams, _azParams) != orxSTATUS_FAILURE)
206 {
207 /* Sets thread callbacks */
209
210 /* Inits the engine */
212 {
213 orxSYSTEM_EVENT_PAYLOAD stPayload;
214 orxSTATUS eClockStatus, eMainStatus;
215 orxBOOL bStop;
216
217 /* Registers default event handler */
220
221 /* Clears payload */
222 orxMemory_Zero(&stPayload, sizeof(orxSYSTEM_EVENT_PAYLOAD));
223
224 /* Main loop */
225 for(bStop = orxFALSE, sbStopByEvent = orxFALSE;
226 bStop == orxFALSE;
227 bStop = ((sbStopByEvent != orxFALSE) || (eMainStatus == orxSTATUS_FAILURE) || (eClockStatus == orxSTATUS_FAILURE)) ? orxTRUE : orxFALSE)
228 {
229 /* Sends frame start event */
231
232 /* Runs non-game specific code (external middleware, platform SDKs, etc.) */
233 eMainStatus = _pfnRun();
234
235 /* Updates clock system */
236 eClockStatus = orxClock_Update();
237
238 /* Sends frame stop event */
240
241 /* Updates frame count */
242 stPayload.u32FrameCount++;
243 }
244
245 /* Removes event handler */
247
248 /* Exits from the engine */
250 }
251
252 /* Clears params */
253 orxParam_SetArgs(0, orxNULL);
254 }
255
256 /* Exits from the Debug system */
258}
259
260/* Web */
261#elif defined(__orxWEB__)
262
263static orxSTATUS (orxFASTCALL *spfnRun)();
264
265static void orx_MainLoop()
266{
267 orxSTATUS eMainStatus, eClockStatus;
268 static orxSYSTEM_EVENT_PAYLOAD sstPayload = {};
269
270 /* Sends frame start event */
272
273 /* Runs non-game specific code (external middleware, platform SDKs, etc.) */
274 eMainStatus = spfnRun();
275
276 /* Updates clock system */
277 eClockStatus = orxClock_Update();
278
279 /* Sends frame stop event */
281
282 /* Updates frame count */
283 sstPayload.u32FrameCount++;
284
285 /* Should stop? */
286 if((sbStopByEvent != orxFALSE) || (eMainStatus == orxSTATUS_FAILURE) || (eClockStatus == orxSTATUS_FAILURE))
287 {
288 /* Removes event handler */
290
291 /* Exits from the engine */
293
294 /* Clears params */
295 orxParam_SetArgs(0, orxNULL);
296
297 /* Exits from the Debug system */
299
300 /* Cancels main loop */
301 emscripten_cancel_main_loop();
302 }
303}
304
312static orxINLINE void orx_Execute(orxU32 _u32NbParams, orxSTRING _azParams[], const orxMODULE_INIT_FUNCTION _pfnInit, const orxMODULE_RUN_FUNCTION _pfnRun, const orxMODULE_EXIT_FUNCTION _pfnExit)
313{
314 /* Inits the Debug System */
316
317 /* Checks */
318 orxASSERT(_u32NbParams > 0);
319 orxASSERT(_azParams != orxNULL);
320 orxASSERT(_pfnRun != orxNULL);
321
322 /* Registers main module */
323 orxModule_Register(orxMODULE_ID_MAIN, "MAIN", orx_MainSetup, _pfnInit, _pfnExit);
324
325 /* Replaces the executable name */
326 _azParams[0] = (orxSTRING)orxWEB_EXECUTABLE_NAME;
327
328 /* Stores run callback */
329 spfnRun = _pfnRun;
330
331 /* Sends the command line arguments to orxParam module */
332 if(orxParam_SetArgs(_u32NbParams, _azParams) != orxSTATUS_FAILURE)
333 {
334 /* Inits the engine */
336 {
337 /* Registers default event handler */
340
341 /* Runs main loop */
342 emscripten_set_main_loop(orx_MainLoop, 0, true);
343
344 /* Should never be reached! */
346 }
347
348 /* Clears params */
349 orxParam_SetArgs(0, orxNULL);
350 }
351
352 /* Exits from the Debug system */
354}
355
356/* Others */
357#else
358
366static orxINLINE void orx_Execute(orxU32 _u32NbParams, orxSTRING _azParams[], const orxMODULE_INIT_FUNCTION _pfnInit, const orxMODULE_RUN_FUNCTION _pfnRun, const orxMODULE_EXIT_FUNCTION _pfnExit)
367{
368 /* Inits the Debug System */
370
371 /* Checks */
372 orxASSERT(_u32NbParams > 0);
373 orxASSERT(_azParams != orxNULL);
374 orxASSERT(_pfnRun != orxNULL);
375
376 /* Registers main module */
377 orxModule_Register(orxMODULE_ID_MAIN, "MAIN", orx_MainSetup, _pfnInit, _pfnExit);
378
379 /* Sends the command line arguments to orxParam module */
380 if(orxParam_SetArgs(_u32NbParams, _azParams) != orxSTATUS_FAILURE)
381 {
382#ifdef __orxSTATIC__
383 /* Silences param & plugin warnings */
386#endif /* __orxSTATIC */
387
388 /* Inits the engine */
390 {
391 orxSYSTEM_EVENT_PAYLOAD stPayload;
392 orxSTATUS eClockStatus, eMainStatus;
393 orxBOOL bStop;
394
395 /* Registers default event handler */
398
399 /* Clears payload */
400 orxMemory_Zero(&stPayload, sizeof(orxSYSTEM_EVENT_PAYLOAD));
401
402 /* Main loop */
403 for(bStop = orxFALSE, sbStopByEvent = orxFALSE;
404 bStop == orxFALSE;
405 bStop = ((sbStopByEvent != orxFALSE) || (eMainStatus == orxSTATUS_FAILURE) || (eClockStatus == orxSTATUS_FAILURE)) ? orxTRUE : orxFALSE)
406 {
407 /* Sends frame start event */
409
410 /* Runs non-game specific code (external middleware, platform SDKs, etc.) */
411 eMainStatus = _pfnRun();
412
413 /* Updates clock system */
414 eClockStatus = orxClock_Update();
415
416 /* Sends frame stop event */
418
419 /* Updates frame count */
420 stPayload.u32FrameCount++;
421 }
422
423 /* Removes event handler */
425
426 /* Exits from the engine */
428 }
429
430 /* Clears params */
431 orxParam_SetArgs(0, orxNULL);
432 }
433
434 /* Exits from the Debug system */
436}
437
438#endif /* __orxIOS__ || __orxANDROID__ || __orxWEB__ */
439
440#endif /* !__orxPLUGIN__ */
441
442#endif /*_orx_H_*/
443
444#ifdef __cplusplus
445}
446#endif /* __cplusplus */
447
static orxINLINE void orx_Execute(orxU32 _u32NbParams, orxSTRING _azParams[], const orxMODULE_INIT_FUNCTION _pfnInit, const orxMODULE_RUN_FUNCTION _pfnRun, const orxMODULE_EXIT_FUNCTION _pfnExit)
Definition orx.h:366
static void orxFASTCALL orx_MainSetup()
Definition orx.h:95
static orxBOOL sbStopByEvent
Definition orx.h:67
static orxSTATUS orxFASTCALL orx_DefaultEventHandler(const orxEVENT *_pstEvent)
Definition orx.h:78
orxSTATUS orxFASTCALL orxAndroid_JNI_SetupThread(void *_pContext)
orxDLLAPI orxSTATUS orxFASTCALL orxClock_Update()
#define orxASSERT(TEST,...)
Definition orxDebug.h:378
#define orxDEBUG_ENABLE_LEVEL(LEVEL, ENABLE)
Definition orxDebug.h:346
#define orxDEBUG_EXIT()
Definition orxDebug.h:249
#define orxDEBUG_INIT()
Definition orxDebug.h:221
@ orxDEBUG_LEVEL_PLUGIN
Definition orxDebug.h:97
@ orxDEBUG_LEVEL_PARAM
Definition orxDebug.h:95
#define orxEVENT_KU32_MASK_ID_ALL
Definition orxEvent.h:70
orxDLLAPI orxSTATUS orxFASTCALL orxEvent_RemoveHandler(orxEVENT_TYPE _eEventType, orxEVENT_HANDLER _pfnEventHandler)
#define orxEVENT_GET_FLAG(ID)
Definition orxEvent.h:68
#define orxEVENT_SEND(TYPE, ID, SENDER, RECIPIENT, PAYLOAD)
Definition orxEvent.h:60
orxDLLAPI orxSTATUS orxFASTCALL orxEvent_SetHandlerIDFlags(orxEVENT_HANDLER _pfnEventHandler, orxEVENT_TYPE _eEventType, void *_pContext, orxU32 _u32AddIDFlags, orxU32 _u32RemoveIDFlags)
orxDLLAPI orxSTATUS orxFASTCALL orxEvent_AddHandler(orxEVENT_TYPE _eEventType, orxEVENT_HANDLER _pfnEventHandler)
@ orxEVENT_TYPE_SYSTEM
Definition orxEvent.h:91
static orxINLINE void * orxMemory_Zero(void *_pDest, orxU32 _u32Size)
Definition orxMemory.h:227
orxSTATUS(orxFASTCALL * orxMODULE_RUN_FUNCTION)()
Definition orxModule.h:118
orxDLLAPI void orxFASTCALL orxModule_AddDependency(orxMODULE_ID _eModuleID, orxMODULE_ID _eDependID)
orxDLLAPI void orxFASTCALL orxModule_Register(orxMODULE_ID _eModuleID, const orxSTRING _zModuleName, const orxMODULE_SETUP_FUNCTION _pfnSetup, const orxMODULE_INIT_FUNCTION _pfnInit, const orxMODULE_EXIT_FUNCTION _pfnExit)
orxDLLAPI void orxFASTCALL orxModule_Exit(orxMODULE_ID _eModuleID)
orxDLLAPI void orxFASTCALL orxModule_AddOptionalDependency(orxMODULE_ID _eModuleID, orxMODULE_ID _eDependID)
orxSTATUS(orxFASTCALL * orxMODULE_INIT_FUNCTION)()
Definition orxModule.h:116
void(orxFASTCALL * orxMODULE_EXIT_FUNCTION)()
Definition orxModule.h:117
orxDLLAPI orxSTATUS orxFASTCALL orxModule_Init(orxMODULE_ID _eModuleID)
@ orxMODULE_ID_MAIN
Definition orxModule.h:78
@ orxMODULE_ID_RENDER
Definition orxModule.h:86
@ orxMODULE_ID_INPUT
Definition orxModule.h:74
@ orxMODULE_ID_LOCALE
Definition orxModule.h:77
@ orxMODULE_ID_PARAM
Definition orxModule.h:82
@ orxMODULE_ID_SCREENSHOT
Definition orxModule.h:88
@ orxMODULE_ID_OBJECT
Definition orxModule.h:81
orxDLLAPI orxSTATUS orxFASTCALL orxParam_SetArgs(orxU32 _u32NbParams, orxSTRING _azParams[])
@ orxSYSTEM_EVENT_CLOSE
Definition orxSystem.h:53
@ orxSYSTEM_EVENT_GAME_LOOP_STOP
Definition orxSystem.h:61
@ orxSYSTEM_EVENT_GAME_LOOP_START
Definition orxSystem.h:60
orxDLLAPI orxSTATUS orxFASTCALL orxThread_SetCallbacks(const orxTHREAD_FUNCTION _pfnStart, const orxTHREAD_FUNCTION _pfnStop, void *_pContext)
orxSTATUS
Definition orxType.h:270
#define orxFALSE
Definition orxType.h:210
#define orxTRUE
Definition orxType.h:211
@ orxSTATUS_SUCCESS
Definition orxType.h:272
@ orxSTATUS_FAILURE
Definition orxType.h:271
orxEVENT_TYPE eType
Definition orxEvent.h:117
orxENUM eID
Definition orxEvent.h:118

Generated for orx by doxygen 1.8.11