orx  1.14
Portable Game Engine
orx.h
Go to the documentation of this file.
1 /* Orx - Portable Game Engine
2  *
3  * Copyright (c) 2008-2022 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 
41 #ifdef __cplusplus
42 extern "C" {
43 #endif /* __cplusplus */
44 
45 #ifndef _orx_H_
46 #define _orx_H_
47 
48 #define __orxEXTERN__ /* Not compiling orx library */
49 
50 
51 #include "orxInclude.h"
52 #include "orxKernel.h"
53 #include "orxUtils.h"
54 
55 #ifndef __orxPLUGIN__
56 
57 /***************************************************************************
58  * Static variables *
59  ***************************************************************************/
60 
63 static orxBOOL sbStopByEvent = orxFALSE;
64 
65 
66 /***************************************************************************
67  * Public functions *
68  ***************************************************************************/
69 
74 static orxSTATUS orxFASTCALL orx_DefaultEventHandler(const orxEVENT *_pstEvent)
75 {
76  orxSTATUS eResult = orxSTATUS_SUCCESS;
77 
78  /* Checks */
79  orxASSERT(_pstEvent->eType == orxEVENT_TYPE_SYSTEM);
80  orxASSERT(_pstEvent->eID == orxSYSTEM_EVENT_CLOSE);
81 
82  /* Updates status */
83  sbStopByEvent = orxTRUE;
84 
85  /* Done! */
86  return eResult;
87 }
88 
91 static void orxFASTCALL orx_MainSetup()
92 {
93  /* Adds module dependencies */
96 
98 
99  /* Done! */
100  return;
101 }
102 
103 #ifdef __orxIOS__
104 
105  #ifdef __orxOBJC__
106 
107 #import <UIKit/UIKit.h>
108 
111 @interface orxAppDelegate : NSObject <UIAccelerometerDelegate>
112 {
113  UIWindow *poWindow;
114  orxViewController *poViewController;
115 }
116 
117 @property (nonatomic, retain) UIWindow *poWindow;
118 @property (nonatomic, retain) UIViewController *poViewController;
119 
120 - (void) MainLoop;
121 
122 @end
123 
124 extern orxSTATUS (orxFASTCALL *spfnRun)();
125 
133 static orxINLINE void orx_Execute(orxU32 _u32NbParams, orxSTRING _azParams[], const orxMODULE_INIT_FUNCTION _pfnInit, const orxMODULE_RUN_FUNCTION _pfnRun, const orxMODULE_EXIT_FUNCTION _pfnExit)
134 {
135  /* Inits the Debug System */
136  orxDEBUG_INIT();
137 
138  /* Checks */
139  orxASSERT(_u32NbParams > 0);
140  orxASSERT(_azParams != orxNULL);
141  orxASSERT(_pfnRun != orxNULL);
142 
143  /* Registers main module */
144  orxModule_Register(orxMODULE_ID_MAIN, "MAIN", orx_MainSetup, _pfnInit, _pfnExit);
145 
146  /* Stores run callback */
147  spfnRun = _pfnRun;
148 
149  /* Sends the command line arguments to orxParam module */
150  if(orxParam_SetArgs(_u32NbParams, _azParams) != orxSTATUS_FAILURE)
151  {
152  NSAutoreleasePool *poPool;
153 
154  /* Allocates memory pool */
155  poPool = [[NSAutoreleasePool alloc] init];
156 
157  /* Launches application */
158  UIApplicationMain(_u32NbParams, _azParams, nil, @"orxAppDelegate");
159 
160  /* Releases memory pool */
161  [poPool release];
162  }
163 
164  /* Done! */
165  return;
166 }
167 
168  #endif /* __orxOBJC__ */
169 
170 #else /* __orxIOS__ */
171 
172  #if defined(__orxANDROID__)
173 
174 #include "main/android/orxAndroid.h"
175 
183 static orxINLINE void orx_Execute(orxU32 _u32NbParams, orxSTRING _azParams[], const orxMODULE_INIT_FUNCTION _pfnInit, const orxMODULE_RUN_FUNCTION _pfnRun, const orxMODULE_EXIT_FUNCTION _pfnExit)
184 {
185  /* Inits the Debug System */
186  orxDEBUG_INIT();
187 
188  /* Checks */
189  orxASSERT(_pfnRun != orxNULL);
190 
191  /* Registers main module */
192  orxModule_Register(orxMODULE_ID_MAIN, "MAIN", orx_MainSetup, _pfnInit, _pfnExit);
193 
194  /* Sends the command line arguments to orxParam module */
195  if(orxParam_SetArgs(_u32NbParams, _azParams) != orxSTATUS_FAILURE)
196  {
197  /* Sets thread callbacks */
199 
200  /* Inits the engine */
202  {
203  orxSYSTEM_EVENT_PAYLOAD stPayload;
204  orxSTATUS eClockStatus, eMainStatus;
205  orxBOOL bStop;
206 
207  /* Registers default event handler */
210 
211  /* Clears payload */
212  orxMemory_Zero(&stPayload, sizeof(orxSYSTEM_EVENT_PAYLOAD));
213 
214  /* Main loop */
215  for(bStop = orxFALSE, sbStopByEvent = orxFALSE;
216  bStop == orxFALSE;
217  bStop = ((sbStopByEvent != orxFALSE) || (eMainStatus == orxSTATUS_FAILURE) || (eClockStatus == orxSTATUS_FAILURE)) ? orxTRUE : orxFALSE)
218  {
219  /* Sends frame start event */
221 
222  /* Runs game specific code */
223  eMainStatus = _pfnRun();
224 
225  /* Updates clock system */
226  eClockStatus = orxClock_Update();
227 
228  /* Sends frame stop event */
229  orxEVENT_SEND(orxEVENT_TYPE_SYSTEM, orxSYSTEM_EVENT_GAME_LOOP_STOP, orxNULL, orxNULL, &stPayload);
230 
231  /* Updates frame count */
232  stPayload.u32FrameCount++;
233  }
234 
235  /* Removes event handler */
237 
238  /* Exits from the engine */
240  }
241  }
242 
243  /* Exits from the Debug system */
244  orxDEBUG_EXIT();
245 }
246 
247  #else /* __orxANDROID__ */
248 
256 static orxINLINE void orx_Execute(orxU32 _u32NbParams, orxSTRING _azParams[], const orxMODULE_INIT_FUNCTION _pfnInit, const orxMODULE_RUN_FUNCTION _pfnRun, const orxMODULE_EXIT_FUNCTION _pfnExit)
257 {
258  /* Inits the Debug System */
259  orxDEBUG_INIT();
260 
261  /* Checks */
262  orxASSERT(_u32NbParams > 0);
263  orxASSERT(_azParams != orxNULL);
264  orxASSERT(_pfnRun != orxNULL);
265 
266  /* Registers main module */
267  orxModule_Register(orxMODULE_ID_MAIN, "MAIN", orx_MainSetup, _pfnInit, _pfnExit);
268 
269  /* Sends the command line arguments to orxParam module */
270  if(orxParam_SetArgs(_u32NbParams, _azParams) != orxSTATUS_FAILURE)
271  {
272  /* Inits the engine */
274  {
275  orxSYSTEM_EVENT_PAYLOAD stPayload;
276  orxSTATUS eClockStatus, eMainStatus;
277  orxBOOL bStop;
278 
279  /* Registers default event handler */
282 
283  /* Clears payload */
284  orxMemory_Zero(&stPayload, sizeof(orxSYSTEM_EVENT_PAYLOAD));
285 
286  /* Main loop */
287  for(bStop = orxFALSE, sbStopByEvent = orxFALSE;
288  bStop == orxFALSE;
289  bStop = ((sbStopByEvent != orxFALSE) || (eMainStatus == orxSTATUS_FAILURE) || (eClockStatus == orxSTATUS_FAILURE)) ? orxTRUE : orxFALSE)
290  {
291  /* Sends frame start event */
293 
294  /* Runs game specific code */
295  eMainStatus = _pfnRun();
296 
297  /* Updates clock system */
298  eClockStatus = orxClock_Update();
299 
300  /* Sends frame stop event */
301  orxEVENT_SEND(orxEVENT_TYPE_SYSTEM, orxSYSTEM_EVENT_GAME_LOOP_STOP, orxNULL, orxNULL, &stPayload);
302 
303  /* Updates frame count */
304  stPayload.u32FrameCount++;
305  }
306 
307  /* Removes event handler */
309 
310  /* Exits from the engine */
312  }
313  }
314 
315  /* Exits from the Debug system */
316  orxDEBUG_EXIT();
317 }
318 
319  #endif /* __orxANDROID__ */
320 
321 #endif /* __orxIOS__ */
322 
323 #endif /* !__orxPLUGIN__ */
324 
325 #endif /*_orx_H_*/
326 
327 #ifdef __cplusplus
328 }
329 #endif /* __cplusplus */
330 
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 orxSTATUS orxFASTCALL orxEvent_RemoveHandler(orxEVENT_TYPE _eEventType, orxEVENT_HANDLER _pfnEventHandler)
#define orxEVENT_SEND(TYPE, ID, SENDER, RECIPIENT, PAYLOAD)
Definition: orxEvent.h:60
orxDLLAPI orxSTATUS orxFASTCALL orxThread_SetCallbacks(const orxTHREAD_FUNCTION _pfnStart, const orxTHREAD_FUNCTION _pfnStop, void *_pContext)
orxSTATUS orxFASTCALL orxAndroid_JNI_SetupThread(void *_pContext)
#define orxTRUE
Definition: orxType.h:198
orxDLLAPI void orxFASTCALL orxModule_AddOptionalDependency(orxMODULE_ID _eModuleID, orxMODULE_ID _eDependID)
orxDLLAPI orxSTATUS orxFASTCALL orxClock_Update()
#define orxDEBUG_EXIT()
Definition: orxDebug.h:249
#define orxFALSE
Definition: orxType.h:197
orxEVENT_TYPE eType
Definition: orxEvent.h:112
orxDLLAPI orxSTATUS orxFASTCALL orxEvent_AddHandler(orxEVENT_TYPE _eEventType, orxEVENT_HANDLER _pfnEventHandler)
orxDLLAPI orxSTATUS orxFASTCALL orxParam_SetArgs(orxU32 _u32NbParams, orxSTRING _azParams[])
orxDLLAPI orxSTATUS orxFASTCALL orxEvent_SetHandlerIDFlags(orxEVENT_HANDLER _pfnEventHandler, orxEVENT_TYPE _eEventType, void *_pContext, orxU32 _u32AddIDFlags, orxU32 _u32RemoveIDFlags)
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:256
#define orxDEBUG_INIT()
Definition: orxDebug.h:221
static void orxFASTCALL orx_MainSetup()
Definition: orx.h:91
orxSTATUS
Definition: orxType.h:256
orxENUM eID
Definition: orxEvent.h:113
static orxINLINE void * orxMemory_Zero(void *_pDest, orxU32 _u32Size)
Definition: orxMemory.h:211
orxDLLAPI void orxFASTCALL orxModule_Exit(orxMODULE_ID _eModuleID)
orxDLLAPI orxSTATUS orxFASTCALL orxModule_Init(orxMODULE_ID _eModuleID)
typedef void(orxFASTCALL *orxMODULE_EXIT_FUNCTION)()
static orxBOOL sbStopByEvent
Definition: orx.h:63
orxDLLAPI void orxFASTCALL orxModule_AddDependency(orxMODULE_ID _eModuleID, orxMODULE_ID _eDependID)
static orxSTATUS orxFASTCALL orx_DefaultEventHandler(const orxEVENT *_pstEvent)
Definition: orx.h:74
#define orxEVENT_KU32_MASK_ID_ALL
Definition: orxEvent.h:70
#define orxEVENT_GET_FLAG(ID)
Definition: orxEvent.h:68
#define orxASSERT(TEST,...)
Definition: orxDebug.h:372

Generated for orx by doxygen 1.8.11