orx  stable
Portable Game Engine
orx.h
Go to the documentation of this file.
1 /* Orx - Portable Game Engine
2  *
3  * Copyright (c) 2008-2017 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 counter */
253  stPayload.u32FrameCounter++;
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 counter */
324  stPayload.u32FrameCounter++;
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 
393 static orxINLINE orxSTATUS orx_LogAllStructures()
394 {
395 #define orx_MAX_NAME_LENGTH 20
396 #define orx_DECLARE_STRUCTURE_INFO(ID, FN) {orxSTRUCTURE_ID_##ID, (orxSTRUCTURE_GETNAME)FN}
397 
398  typedef orxSTRING(orxFASTCALL *orxSTRUCTURE_GETNAME)(const void *_pStructure);
399 
400  static struct
401  {
402  orxSTRUCTURE_ID eID;
403  orxSTRUCTURE_GETNAME pfnGetName;
404  }
405  sastStructureInfoList[] =
406  {
422  orx_DECLARE_STRUCTURE_INFO(TIMELINE, orxNULL)
423  };
424  orxU32 i;
425  orxHASHTABLE *pstTable;
426  orxSTATUS eResult = orxSTATUS_FAILURE;
427 
428  /* Creates table */
430 
431  /* Valid? */
432  if(pstTable != orxNULL)
433  {
434  orxCHAR acBuffer[1024] = {0};
435  orxU32 u32DebugFlags;
436 
437  /* Backups debug flags */
438  u32DebugFlags = orxDEBUG_GET_FLAGS();
439 
440  /* Sets new debug flags */
443 
444  /* Logs header */
445  orxLOG("*** BEGIN STRUCTURE LOG ***\n");
446 
447  /* For all IDs */
448  for(i = 0; i < orxARRAY_GET_ITEM_COUNT(sastStructureInfoList); i++)
449  {
450  orxSTRUCTURE *pstStructure;
451 
452  /* Checks */
454 
455  /* For all structures */
456  for(pstStructure = orxStructure_GetFirst(sastStructureInfoList[i].eID);
457  pstStructure != orxNULL;
458  pstStructure = orxStructure_GetNext(pstStructure))
459  {
460  /* Is owner-less? */
461  if(orxStructure_GetOwner(pstStructure) == orxNULL)
462  {
463  orxSTRUCTURE **ppstBucket;
464 
465  /* Retrieves hashtable bucket */
466  ppstBucket = (orxSTRUCTURE **)orxHashTable_Retrieve(pstTable, orxStructure_GetGUID(pstStructure));
467 
468  /* Valid and not already logged? */
469  if((ppstBucket != orxNULL) && (*ppstBucket == orxNULL))
470  {
471  /* Adds it to table */
472  *ppstBucket = pstStructure;
473 
474  /* Logs it */
475  if(sastStructureInfoList[i].pfnGetName != orxNULL)
476  {
477  orxU32 u32Offset;
478  u32Offset = orxString_NPrint(acBuffer, sizeof(acBuffer) - 1, "%-8s \"%s\"", orxStructure_GetIDString(sastStructureInfoList[i].eID), sastStructureInfoList[i].pfnGetName(pstStructure));
479  orxLOG("%s%*s[% 016llX]\n", acBuffer, orxMAX(0, orx_MAX_NAME_LENGTH + 12 - u32Offset), orxSTRING_EMPTY, pstStructure->u64GUID);
480  }
481  else
482  {
483  orxLOG("%-8s %*s [%016llX]\n", orxStructure_GetIDString(sastStructureInfoList[i].eID), orx_MAX_NAME_LENGTH + 2, orxSTRING_EMPTY, pstStructure->u64GUID);
484  }
485 
487  }
488  }
489  }
490  }
491 
492  /* Logs footer */
493  orxLOG("*** END STRUCTURE LOG ***");
494 
495  /* Restores debug flags */
497 
498  /* Updates result */
499  eResult = orxSTATUS_SUCCESS;
500 
501  /* Deletes table */
502  orxHashTable_Delete(pstTable);
503  }
504 
505 #undef orx_DECLARE_STRUCTURE_INFO
506 #undef orx_MAX_NAME_LENGTH
507 
508  /* Done! */
509  return eResult;
510 }
511 
512 #endif /*_orx_H_*/
513 
514 #ifdef __cplusplus
515 }
516 #endif /* __cplusplus */
517 
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 orxSTRUCTURE *orxFASTCALL orxStructure_GetFirst(orxSTRUCTURE_ID _eStructureID)
#define orxDEBUG_SET_FLAGS(SET, UNSET)
Definition: orxDebug.h:300
#define orxARRAY_GET_ITEM_COUNT(ARRAY)
Definition: orxDecl.h:405
orxDLLAPI const orxSTRING orxFASTCALL orxBody_GetName(const orxBODY *_pstBody)
struct __orxHASHTABLE_t orxHASHTABLE
Definition: orxHashTable.h:50
orxDLLAPI orxSTATUS orxFASTCALL orxEvent_RemoveHandler(orxEVENT_TYPE _eEventType, orxEVENT_HANDLER _pfnEventHandler)
#define orxEVENT_SEND(TYPE, ID, SENDER, RECIPIENT, PAYLOAD)
Definition: orxEvent.h:60
orxDLLAPI orxSTRUCTURE *orxFASTCALL orxStructure_GetNext(const void *_pStructure)
orxDLLAPI const orxSTRING orxFASTCALL orxObject_GetName(const orxOBJECT *_pstObject)
orxDLLAPI orxSTRUCTURE_STORAGE_TYPE orxFASTCALL orxStructure_GetStorageType(orxSTRUCTURE_ID _eStructureID)
static orxINLINE const orxSTRING orxString_SkipWhiteSpaces(const orxSTRING _zString)
Definition: orxString.h:99
orxDLLAPI const orxSTRING orxFASTCALL orxText_GetName(const orxTEXT *_pstText)
#define orx_MAX_NAME_LENGTH
#define orxTRUE
Definition: orxType.h:186
orxDLLAPI void orxFASTCALL orxModule_AddOptionalDependency(orxMODULE_ID _eModuleID, orxMODULE_ID _eDependID)
orxDLLAPI orxSTATUS orxFASTCALL orxClock_Update()
orxDLLAPI orxSTATUS orxFASTCALL orxHashTable_Delete(orxHASHTABLE *_pstHashTable)
#define orxDEBUG_EXIT()
Definition: orxDebug.h:202
#define orxFALSE
Definition: orxType.h:185
orxEVENT_TYPE eType
Definition: orxEvent.h:108
#define orxDEBUG_KU32_STATIC_MASK_USER_ALL
Definition: orxDebug.h:68
orxDLLAPI const orxSTRING orxSTRING_EMPTY
orxDLLAPI const orxSTRING orxFASTCALL orxSpawner_GetName(const orxSPAWNER *_pstSpawner)
#define orx_DECLARE_STRUCTURE_INFO(ID, FN)
static orxINLINE const orxSTRING orxStructure_GetIDString(orxSTRUCTURE_ID _eID)
Definition: orxStructure.h:207
orxDLLAPI orxSTATUS orxFASTCALL orxEvent_AddHandler(orxEVENT_TYPE _eEventType, orxEVENT_HANDLER _pfnEventHandler)
orxDLLAPI orxSTATUS orxFASTCALL orxParam_SetArgs(orxU32 _u32NbParams, orxSTRING _azParams[])
orxDLLAPI const orxSTRING orxFASTCALL orxTexture_GetName(const orxTEXTURE *_pstTexture)
static orxINLINE orxU64 orxStructure_GetGUID(const void *_pStructure)
Definition: orxStructure.h:458
#define orxMAX(A, B)
Definition: orxMath.h:78
#define orxDEBUG_KU32_STATIC_FLAG_NONE
Definition: orxDebug.h:53
#define orxDEBUG_KU32_STATIC_FLAG_TIMESTAMP
Definition: orxDebug.h:55
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
static orxINLINE orxSTATUS orx_LogAllStructures()
Definition: orx.h:393
orxDLLAPI const orxSTRING orxFASTCALL orxShader_GetName(const orxSHADER *_pstShader)
#define orxDEBUG_INIT()
Definition: orxDebug.h:174
orxDLLAPI const orxSTRING orxFASTCALL orxClock_GetName(const orxCLOCK *_pstClock)
static void orxFASTCALL orx_MainSetup()
Definition: orx.h:105
orxSTATUS
Definition: orxType.h:243
orxDLLAPI const orxSTRING orxFASTCALL orxCamera_GetName(const orxCAMERA *_pstCamera)
orxENUM eID
Definition: orxEvent.h:109
#define orxDEBUG_GET_FLAGS()
Definition: orxDebug.h:301
orxDLLAPI const orxSTRING orxFASTCALL orxFont_GetName(const orxFONT *_pstFont)
orxDLLAPI const orxSTRING orxFASTCALL orxAnim_GetName(const orxANIM *_pstAnim)
static orxINLINE orxS32 orxCDECL orxString_NPrint(orxSTRING _zDstString, orxU32 _u32CharNumber, const orxSTRING _zSrcString,...)
Definition: orxString.h:1554
static orxINLINE void * orxMemory_Zero(void *_pDest, orxU32 _u32Size)
Definition: orxMemory.h:221
orxDLLAPI void orxFASTCALL orxModule_Exit(orxMODULE_ID _eModuleID)
orxDLLAPI const orxSTRING orxFASTCALL orxFX_GetName(const orxFX *_pstFX)
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)
orxDLLAPI orxSTRUCTURE *orxFASTCALL orxStructure_GetOwner(const void *_pStructure)
orxDLLAPI const orxSTRING orxFASTCALL orxViewport_GetName(const orxVIEWPORT *_pstViewport)
orxSTRUCTURE_ID
Definition: orxStructure.h:114
orxDLLAPI orxHASHTABLE *orxFASTCALL orxHashTable_Create(orxU32 _u32NbKey, orxU32 _u32Flags, orxMEMORY_TYPE _eMemType)
static orxSTATUS orxFASTCALL orx_DefaultEventHandler(const orxEVENT *_pstEvent)
Definition: orx.h:74
orxU64 u64GUID
Definition: orxStructure.h:168
orxDLLAPI const orxSTRING orxFASTCALL orxSound_GetName(const orxSOUND *_pstSound)
orxDLLAPI const orxSTRING orxFASTCALL orxGraphic_GetName(const orxGRAPHIC *_pstGraphic)
#define orxHASHTABLE_KU32_FLAG_NONE
Definition: orxHashTable.h:53
orxDLLAPI void **orxFASTCALL orxHashTable_Retrieve(orxHASHTABLE *_pstHashTable, orxU64 _u64Key)
#define orxASSERT(TEST,...)
Definition: orxDebug.h:298
orxDLLAPI const orxSTRING orxFASTCALL orxAnimSet_GetName(const orxANIMSET *_pstAnimSet)
#define orxDEBUG_KU32_STATIC_FLAG_TYPE
Definition: orxDebug.h:57

Generated for orx by doxygen 1.5.6