00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00044 #ifndef _orxSTRUCTURE_H_
00045 #define _orxSTRUCTURE_H_
00046
00047 #include "orxInclude.h"
00048
00049 #include "core/orxClock.h"
00050 #include "debug/orxDebug.h"
00051 #include "memory/orxMemory.h"
00052
00053
00056 #define orxSTRUCTURE_GET_POINTER(STRUCTURE, TYPE) ((orx##TYPE *)_orxStructure_GetPointer(STRUCTURE, orxSTRUCTURE_ID_##TYPE))
00057
00058 #define orxSTRUCTURE(STRUCTURE) (((STRUCTURE != orxNULL) && ((((orxSTRUCTURE *)STRUCTURE)->eID ^ orxSTRUCTURE_MAGIC_TAG_ACTIVE) < orxSTRUCTURE_ID_NUMBER)) ? (orxSTRUCTURE *)STRUCTURE : (orxSTRUCTURE *)orxNULL)
00059
00060 #define orxANIM(STRUCTURE) orxSTRUCTURE_GET_POINTER(STRUCTURE, ANIM)
00061 #define orxANIMPOINTER(STRUCTURE) orxSTRUCTURE_GET_POINTER(STRUCTURE, ANIMPOINTER)
00062 #define orxANIMSET(STRUCTURE) orxSTRUCTURE_GET_POINTER(STRUCTURE, ANIMSET)
00063 #define orxBODY(STRUCTURE) orxSTRUCTURE_GET_POINTER(STRUCTURE, BODY)
00064 #define orxCAMERA(STRUCTURE) orxSTRUCTURE_GET_POINTER(STRUCTURE, CAMERA)
00065 #define orxCLOCK(STRUCTURE) orxSTRUCTURE_GET_POINTER(STRUCTURE, CLOCK)
00066 #define orxFONT(STRUCTURE) orxSTRUCTURE_GET_POINTER(STRUCTURE, FONT)
00067 #define orxFRAME(STRUCTURE) orxSTRUCTURE_GET_POINTER(STRUCTURE, FRAME)
00068 #define orxFX(STRUCTURE) orxSTRUCTURE_GET_POINTER(STRUCTURE, FX)
00069 #define orxFXPOINTER(STRUCTURE) orxSTRUCTURE_GET_POINTER(STRUCTURE, FXPOINTER)
00070 #define orxGRAPHIC(STRUCTURE) orxSTRUCTURE_GET_POINTER(STRUCTURE, GRAPHIC)
00071 #define orxOBJECT(STRUCTURE) orxSTRUCTURE_GET_POINTER(STRUCTURE, OBJECT)
00072 #define orxSOUND(STRUCTURE) orxSTRUCTURE_GET_POINTER(STRUCTURE, SOUND)
00073 #define orxSOUNDPOINTER(STRUCTURE) orxSTRUCTURE_GET_POINTER(STRUCTURE, SOUNDPOINTER)
00074 #define orxSHADER(STRUCTURE) orxSTRUCTURE_GET_POINTER(STRUCTURE, SHADER)
00075 #define orxSHADERPOINTER(STRUCTURE) orxSTRUCTURE_GET_POINTER(STRUCTURE, SHADERPOINTER)
00076 #define orxSPAWNER(STRUCTURE) orxSTRUCTURE_GET_POINTER(STRUCTURE, SPAWNER)
00077 #define orxTEXT(STRUCTURE) orxSTRUCTURE_GET_POINTER(STRUCTURE, TEXT)
00078 #define orxTEXTURE(STRUCTURE) orxSTRUCTURE_GET_POINTER(STRUCTURE, TEXTURE)
00079 #define orxVIEWPORT(STRUCTURE) orxSTRUCTURE_GET_POINTER(STRUCTURE, VIEWPORT)
00080
00083 #define orxSTRUCTURE_REGISTER(TYPE, STORAGE_TYPE, MEMORY_TYPE, UPDATE_FUNCTION) \
00084 orxStructure_Register(orxSTRUCTURE_ID_##TYPE, STORAGE_TYPE, MEMORY_TYPE, sizeof(orx##TYPE), UPDATE_FUNCTION)
00085
00088 #define orxSTRUCTURE_ASSERT(STRUCTURE) \
00089 orxASSERT((STRUCTURE) != orxNULL); \
00090 orxASSERT((((orxSTRUCTURE *)(STRUCTURE))->eID ^ orxSTRUCTURE_MAGIC_TAG_ACTIVE) < orxSTRUCTURE_ID_NUMBER);
00091
00094 #ifdef __orxDEBUG__
00095 #define orxSTRUCTURE_MAGIC_TAG_ACTIVE 0xDEFACED0
00096 #else
00097 #define orxSTRUCTURE_MAGIC_TAG_ACTIVE 0x00000000
00098 #endif
00099
00100 #define orxSTRUCTURE_MAGIC_TAG_DELETED 0xDEADC0DE
00101
00102
00105 typedef enum __orxSTRUCTURE_ID_t
00106 {
00107
00108
00109 orxSTRUCTURE_ID_ANIMPOINTER = 0,
00110 orxSTRUCTURE_ID_BODY,
00111 orxSTRUCTURE_ID_CLOCK,
00112 orxSTRUCTURE_ID_FRAME,
00113 orxSTRUCTURE_ID_FXPOINTER,
00114 orxSTRUCTURE_ID_GRAPHIC,
00115 orxSTRUCTURE_ID_SHADERPOINTER,
00116 orxSTRUCTURE_ID_SOUNDPOINTER,
00117 orxSTRUCTURE_ID_SPAWNER,
00118
00119 orxSTRUCTURE_ID_LINKABLE_NUMBER,
00120
00121
00122
00123 orxSTRUCTURE_ID_ANIM = orxSTRUCTURE_ID_LINKABLE_NUMBER,
00124 orxSTRUCTURE_ID_ANIMSET,
00125 orxSTRUCTURE_ID_CAMERA,
00126 orxSTRUCTURE_ID_FONT,
00127 orxSTRUCTURE_ID_FX,
00128 orxSTRUCTURE_ID_OBJECT,
00129 orxSTRUCTURE_ID_SHADER,
00130 orxSTRUCTURE_ID_SOUND,
00131 orxSTRUCTURE_ID_TEXT,
00132 orxSTRUCTURE_ID_TEXTURE,
00133 orxSTRUCTURE_ID_VIEWPORT,
00134
00135 orxSTRUCTURE_ID_NUMBER,
00136
00137 orxSTRUCTURE_ID_NONE = orxENUM_NONE
00138
00139 } orxSTRUCTURE_ID;
00140
00143 typedef enum __orxSTRUCTURE_STORAGE_TYPE_t
00144 {
00145 orxSTRUCTURE_STORAGE_TYPE_LINKLIST = 0,
00146 orxSTRUCTURE_STORAGE_TYPE_TREE,
00147
00148 orxSTRUCTURE_STORAGE_TYPE_NUMBER,
00149
00150 orxSTRUCTURE_STORAGE_TYPE_NONE = orxENUM_NONE,
00151
00152 } orxSTRUCTURE_STORAGE_TYPE;
00153
00156 typedef struct __orxSTRUCTURE_t
00157 {
00158 orxSTRUCTURE_ID eID;
00159 orxU32 s32RefCounter;
00160 orxU32 u32Flags;
00161 orxHANDLE hStorageNode;
00163 } orxSTRUCTURE;
00164
00165
00168 typedef orxSTATUS (orxFASTCALL *orxSTRUCTURE_UPDATE_FUNCTION)(orxSTRUCTURE *_pstStructure, const orxSTRUCTURE *_pstCaller, const orxCLOCK_INFO *_pstClockInfo);
00169
00170
00176 static orxINLINE orxSTRUCTURE *_orxStructure_GetPointer(const void *_pStructure, orxSTRUCTURE_ID _eStructureID)
00177 {
00178 orxSTRUCTURE *pstResult;
00179
00180
00181 pstResult = ((_pStructure != orxNULL) && (((orxSTRUCTURE *)_pStructure)->eID ^ orxSTRUCTURE_MAGIC_TAG_ACTIVE) == _eStructureID) ? (orxSTRUCTURE *)_pStructure : (orxSTRUCTURE *)orxNULL;
00182
00183
00184 return pstResult;
00185 }
00186
00187
00190 extern orxDLLAPI void orxFASTCALL orxStructure_Setup();
00191
00195 extern orxDLLAPI orxSTATUS orxFASTCALL orxStructure_Init();
00196
00199 extern orxDLLAPI void orxFASTCALL orxStructure_Exit();
00200
00201
00210 extern orxDLLAPI orxSTATUS orxFASTCALL orxStructure_Register(orxSTRUCTURE_ID _eStructureID, orxSTRUCTURE_STORAGE_TYPE _eStorageType, orxMEMORY_TYPE _eMemoryType, orxU32 _u32Size, const orxSTRUCTURE_UPDATE_FUNCTION _pfnUpdate);
00211
00216 extern orxDLLAPI orxSTATUS orxFASTCALL orxStructure_Unregister(orxSTRUCTURE_ID _eStructureID);
00217
00218
00223 extern orxDLLAPI orxSTRUCTURE *orxFASTCALL orxStructure_Create(orxSTRUCTURE_ID _eStructureID);
00224
00229 extern orxDLLAPI orxSTATUS orxFASTCALL orxStructure_Delete(void *_pStructure);
00230
00231
00236 extern orxDLLAPI orxSTRUCTURE_STORAGE_TYPE orxFASTCALL orxStructure_GetStorageType(orxSTRUCTURE_ID _eStructureID);
00237
00242 extern orxDLLAPI orxU32 orxFASTCALL orxStructure_GetCounter(orxSTRUCTURE_ID _eStructureID);
00243
00250 extern orxDLLAPI orxSTATUS orxFASTCALL orxStructure_Update(void *_pStructure, const void *_phCaller, const orxCLOCK_INFO *_pstClockInfo);
00251
00252
00260 extern orxDLLAPI orxSTRUCTURE *orxFASTCALL orxStructure_GetFirst(orxSTRUCTURE_ID _eStructureID);
00261
00266 extern orxDLLAPI orxSTRUCTURE *orxFASTCALL orxStructure_GetLast(orxSTRUCTURE_ID _eStructureID);
00267
00272 extern orxDLLAPI orxSTRUCTURE *orxFASTCALL orxStructure_GetParent(const void *_pStructure);
00273
00278 extern orxDLLAPI orxSTRUCTURE *orxFASTCALL orxStructure_GetChild(const void *_pStructure);
00279
00284 extern orxDLLAPI orxSTRUCTURE *orxFASTCALL orxStructure_GetSibling(const void *_pStructure);
00285
00290 extern orxDLLAPI orxSTRUCTURE *orxFASTCALL orxStructure_GetPrevious(const void *_pStructure);
00291
00296 extern orxDLLAPI orxSTRUCTURE *orxFASTCALL orxStructure_GetNext(const void *_pStructure);
00297
00303 extern orxDLLAPI orxSTATUS orxFASTCALL orxStructure_SetParent(void *_pStructure, void *_phParent);
00304
00305
00312 static orxINLINE void orxStructure_IncreaseCounter(void *_pStructure)
00313 {
00314
00315 orxSTRUCTURE_ASSERT(_pStructure);
00316
00317
00318 (orxSTRUCTURE(_pStructure))->s32RefCounter++;
00319
00320 return;
00321 }
00322
00326 static orxINLINE void orxStructure_DecreaseCounter(void *_pStructure)
00327 {
00328
00329 orxSTRUCTURE_ASSERT(_pStructure);
00330 orxASSERT(orxSTRUCTURE(_pStructure)->s32RefCounter > 0);
00331
00332
00333 orxSTRUCTURE(_pStructure)->s32RefCounter--;
00334
00335 return;
00336 }
00337
00342 static orxINLINE orxS32 orxStructure_GetRefCounter(const void *_pStructure)
00343 {
00344
00345 orxSTRUCTURE_ASSERT(_pStructure);
00346
00347
00348 return(orxSTRUCTURE(_pStructure)->s32RefCounter);
00349 }
00350
00355 static orxINLINE orxSTRUCTURE_ID orxStructure_GetID(const void *_pStructure)
00356 {
00357
00358 orxSTRUCTURE_ASSERT(_pStructure);
00359
00360
00361 return((orxSTRUCTURE_ID)(orxSTRUCTURE(_pStructure)->eID ^ orxSTRUCTURE_MAGIC_TAG_ACTIVE));
00362 }
00363
00369 static orxINLINE orxBOOL orxStructure_TestFlags(const void *_pStructure, orxU32 _u32Flags)
00370 {
00371
00372 orxSTRUCTURE_ASSERT(_pStructure);
00373
00374
00375 return(orxFLAG_TEST(orxSTRUCTURE(_pStructure)->u32Flags, _u32Flags));
00376 }
00377
00383 static orxINLINE orxBOOL orxStructure_TestAllFlags(const void *_pStructure, orxU32 _u32Flags)
00384 {
00385
00386 orxSTRUCTURE_ASSERT(_pStructure);
00387
00388
00389 return(orxFLAG_TEST_ALL(orxSTRUCTURE(_pStructure)->u32Flags, _u32Flags));
00390 }
00391
00397 static orxINLINE orxU32 orxStructure_GetFlags(const void *_pStructure, orxU32 _u32Mask)
00398 {
00399
00400 orxSTRUCTURE_ASSERT(_pStructure);
00401
00402
00403 return(orxFLAG_GET(orxSTRUCTURE(_pStructure)->u32Flags, _u32Mask));
00404 }
00405
00411 static orxINLINE void orxStructure_SetFlags(void *_pStructure, orxU32 _u32AddFlags, orxU32 _u32RemoveFlags)
00412 {
00413
00414 orxSTRUCTURE_ASSERT(_pStructure);
00415
00416 orxFLAG_SET(orxSTRUCTURE(_pStructure)->u32Flags, _u32AddFlags, _u32RemoveFlags);
00417
00418 return;
00419 }
00420
00421 #endif
00422