orx  1.9
Portable Game Engine
orx.h
Go to the documentation of this file.
1 /* Orx - Portable Game Engine
2  *
3  * Copyright (c) 2008-2018 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 
81  /* Depending on event ID */
82  switch(_pstEvent->eID)
83  {
84  /* Close event */
86  {
87  /* Updates status */
88  sbStopByEvent = orxTRUE;
89 
90  break;
91  }
92 
93  default:
94  {
95  break;
96  }
97  }
98 
99  /* Done! */
100  return eResult;
101 }
102 
105 static void orxFASTCALL orx_MainSetup()
106 {
107  /* Adds module dependencies */
118 
122 
123  return;
124 }
125 
126 #ifdef __orxIOS__
127 
128  #ifdef __orxOBJC__
129 
130 #import <UIKit/UIKit.h>
131 
134 @interface orxAppDelegate : NSObject <UIAccelerometerDelegate>
135 {
136  UIWindow *poWindow;
137  orxViewController *poViewController;
138 }
139 
140 @property (nonatomic, retain) UIWindow *poWindow;
141 @property (nonatomic, retain) UIViewController *poViewController;
142 
143 - (void) MainLoop;
144 
145 @end
146 
147 extern orxSTATUS (orxFASTCALL *spfnRun)();
148 
156 static orxINLINE void orx_Execute(orxU32 _u32NbParams, orxSTRING _azParams[], const orxMODULE_INIT_FUNCTION _pfnInit, const orxMODULE_RUN_FUNCTION _pfnRun, const orxMODULE_EXIT_FUNCTION _pfnExit)
157 {
158  /* Inits the Debug System */
159  orxDEBUG_INIT();
160 
161  /* Checks */
162  orxASSERT(_u32NbParams > 0);
163  orxASSERT(_azParams != orxNULL);
164  orxASSERT(_pfnRun != orxNULL);
165 
166  /* Registers main module */
167  orxModule_Register(orxMODULE_ID_MAIN, "MAIN", orx_MainSetup, _pfnInit, _pfnExit);
168 
169  /* Stores run callback */
170  spfnRun = _pfnRun;
171 
172  /* Sends the command line arguments to orxParam module */
173  if(orxParam_SetArgs(_u32NbParams, _azParams) != orxSTATUS_FAILURE)
174  {
175  NSAutoreleasePool *poPool;
176 
177  /* Allocates memory pool */
178  poPool = [[NSAutoreleasePool alloc] init];
179 
180  /* Launches application */
181  UIApplicationMain(_u32NbParams, _azParams, nil, @"orxAppDelegate");
182 
183  /* Releases memory pool */
184  [poPool release];
185  }
186 
187  /* Done! */
188  return;
189 }
190 
191  #endif /* __orxOBJC__ */
192 
193 #else /* __orxIOS__ */
194 
195  #if defined(__orxANDROID__) || defined(__orxANDROID_NATIVE__)
196 
197 #include "main/orxAndroid.h"
198 
206 static orxINLINE void orx_Execute(orxU32 _u32NbParams, orxSTRING _azParams[], const orxMODULE_INIT_FUNCTION _pfnInit, const orxMODULE_RUN_FUNCTION _pfnRun, const orxMODULE_EXIT_FUNCTION _pfnExit)
207 {
208  /* Inits the Debug System */
209  orxDEBUG_INIT();
210 
211  /* Checks */
212  orxASSERT(_pfnRun != orxNULL);
213 
214  /* Registers main module */
215  orxModule_Register(orxMODULE_ID_MAIN, "MAIN", orx_MainSetup, _pfnInit, _pfnExit);
216 
217  /* Sends the command line arguments to orxParam module */
218  if(orxParam_SetArgs(_u32NbParams, _azParams) != orxSTATUS_FAILURE)
219  {
220  /* Inits the engine */
222  {
223  orxSYSTEM_EVENT_PAYLOAD stPayload;
224  orxSTATUS eClockStatus, eMainStatus;
225  orxBOOL bStop;
226 
227  /* Registers default event handler */
229 
230  /* Clears payload */
231  orxMemory_Zero(&stPayload, sizeof(orxSYSTEM_EVENT_PAYLOAD));
232 
233  /* Main loop */
234  for(bStop = orxFALSE, sbStopByEvent = orxFALSE;
235  bStop == orxFALSE;
236  bStop = ((sbStopByEvent != orxFALSE) || (eMainStatus == orxSTATUS_FAILURE) || (eClockStatus == orxSTATUS_FAILURE)) ? orxTRUE : orxFALSE)
237  {
239 
240  /* Sends frame start event */
242 
243  /* Runs the engine */
244  eMainStatus = _pfnRun();
245 
246  /* Updates clock system */
247  eClockStatus = orxClock_Update();
248 
249  /* Sends frame stop event */
250  orxEVENT_SEND(orxEVENT_TYPE_SYSTEM, orxSYSTEM_EVENT_GAME_LOOP_STOP, orxNULL, orxNULL, &stPayload);
251 
252  /* Updates frame count */
253  stPayload.u32FrameCount++;
254  }
255  }
256 
257  /* Removes event handler */
259 
260  /* Exits from engine */
262  }
263 
264  /* Exits from the Debug system */
265  orxDEBUG_EXIT();
266 }
267 
268  #else /* __orxANDROID__ || __orxANDROID_NATIVE__ */
269 
277 static orxINLINE void orx_Execute(orxU32 _u32NbParams, orxSTRING _azParams[], const orxMODULE_INIT_FUNCTION _pfnInit, const orxMODULE_RUN_FUNCTION _pfnRun, const orxMODULE_EXIT_FUNCTION _pfnExit)
278 {
279  /* Inits the Debug System */
280  orxDEBUG_INIT();
281 
282  /* Checks */
283  orxASSERT(_u32NbParams > 0);
284  orxASSERT(_azParams != orxNULL);
285  orxASSERT(_pfnRun != orxNULL);
286 
287  /* Registers main module */
288  orxModule_Register(orxMODULE_ID_MAIN, "MAIN", orx_MainSetup, _pfnInit, _pfnExit);
289 
290  /* Sends the command line arguments to orxParam module */
291  if(orxParam_SetArgs(_u32NbParams, _azParams) != orxSTATUS_FAILURE)
292  {
293  /* Inits the engine */
295  {
296  orxSYSTEM_EVENT_PAYLOAD stPayload;
297  orxSTATUS eClockStatus, eMainStatus;
298  orxBOOL bStop;
299 
300  /* Registers default event handler */
302 
303  /* Clears payload */
304  orxMemory_Zero(&stPayload, sizeof(orxSYSTEM_EVENT_PAYLOAD));
305 
306  /* Main loop */
307  for(bStop = orxFALSE, sbStopByEvent = orxFALSE;
308  bStop == orxFALSE;
309  bStop = ((sbStopByEvent != orxFALSE) || (eMainStatus == orxSTATUS_FAILURE) || (eClockStatus == orxSTATUS_FAILURE)) ? orxTRUE : orxFALSE)
310  {
311  /* Sends frame start event */
313 
314  /* Runs the engine */
315  eMainStatus = _pfnRun();
316 
317  /* Updates clock system */
318  eClockStatus = orxClock_Update();
319 
320  /* Sends frame stop event */
321  orxEVENT_SEND(orxEVENT_TYPE_SYSTEM, orxSYSTEM_EVENT_GAME_LOOP_STOP, orxNULL, orxNULL, &stPayload);
322 
323  /* Updates frame count */
324  stPayload.u32FrameCount++;
325  }
326  }
327 
328  /* Removes event handler */
330 
331  /* Exits from engine */
333  }
334 
335  /* Exits from the Debug system */
336  orxDEBUG_EXIT();
337 }
338 
339  #ifdef __orxMSVC__
340 
346 static orxINLINE void orx_WinExecute(const orxMODULE_INIT_FUNCTION _pfnInit, const orxMODULE_RUN_FUNCTION _pfnRun, const orxMODULE_EXIT_FUNCTION _pfnExit)
347 {
348  #define orxMAX_ARGS 256
349 
350  int argc;
351  char *argv[orxMAX_ARGS];
352  char *pcToken, *pcNextToken, *pcFirstDelimiters;
353  LPSTR lpFullCmdLine;
354 
355  /* Gets full command line */
356  lpFullCmdLine = GetCommandLineA();
357 
358  /* Starts with a double quote? */
359  if(*orxString_SkipWhiteSpaces(lpFullCmdLine) == '"')
360  {
361  /* Gets first delimiters */
362  pcFirstDelimiters = "\"";
363  }
364  else
365  {
366  /* Gets first delimiters */
367  pcFirstDelimiters = " ";
368  }
369 
370  /* Process command line */
371  for(argc = 0, pcNextToken = NULL, pcToken = strtok_s(lpFullCmdLine, pcFirstDelimiters, &pcNextToken);
372  pcToken && (argc < orxMAX_ARGS);
373  pcToken = strtok_s(NULL, " ", &pcNextToken))
374  {
375  argv[argc++] = pcToken;
376  }
377 
378  /* Inits and executes orx */
379  orx_Execute(argc, argv, _pfnInit, _pfnRun, _pfnExit);
380 }
381 
382  #endif /* __orxMSVC__ */
383 
384  #endif /* __orxANDROID__ || __orxANDROID_NATIVE__ */
385 
386 #endif /* __orxIOS__ */
387 
388 #endif /* __orxPLUGIN__ */
389 
390 #endif /*_orx_H_*/
391 
392 #ifdef __cplusplus
393 }
394 #endif /* __cplusplus */
395 
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
static orxINLINE const orxSTRING orxString_SkipWhiteSpaces(const orxSTRING _zString)
Definition: orxString.h:99
#define orxTRUE
Definition: orxType.h:186
orxDLLAPI void orxFASTCALL orxModule_AddOptionalDependency(orxMODULE_ID _eModuleID, orxMODULE_ID _eDependID)
orxDLLAPI orxSTATUS orxFASTCALL orxClock_Update()
#define orxDEBUG_EXIT()
Definition: orxDebug.h:202
#define orxFALSE
Definition: orxType.h:185
orxEVENT_TYPE eType
Definition: orxEvent.h:108
orxDLLAPI orxSTATUS orxFASTCALL orxEvent_AddHandler(orxEVENT_TYPE _eEventType, orxEVENT_HANDLER _pfnEventHandler)
orxDLLAPI orxSTATUS orxFASTCALL orxParam_SetArgs(orxU32 _u32NbParams, orxSTRING _azParams[])
void orxAndroid_PumpEvents()
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:277
#define orxDEBUG_INIT()
Definition: orxDebug.h:174
static void orxFASTCALL orx_MainSetup()
Definition: orx.h:105
orxSTATUS
Definition: orxType.h:243
orxENUM eID
Definition: orxEvent.h:109
static orxINLINE void * orxMemory_Zero(void *_pDest, orxU32 _u32Size)
Definition: orxMemory.h:221
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 orxASSERT(TEST,...)
Definition: orxDebug.h:298

Generated for orx by doxygen 1.8.11