orx  stable
Portable Game Engine
orxStructure.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 
44 #ifndef _orxSTRUCTURE_H_
45 #define _orxSTRUCTURE_H_
46 
47 #include "orxInclude.h"
48 
49 #include "core/orxClock.h"
50 #include "memory/orxMemory.h"
51 #include "utils/orxLinkList.h"
52 #include "utils/orxTree.h"
53 
54 
57 #define orxSTRUCTURE_GET_POINTER(STRUCTURE, TYPE) ((orx##TYPE *)_orxStructure_GetPointer(STRUCTURE, orxSTRUCTURE_ID_##TYPE))
58 
59 #define orxSTRUCTURE(STRUCTURE) (((STRUCTURE != orxNULL) && (((((orxSTRUCTURE *)STRUCTURE)->u64GUID & orxSTRUCTURE_GUID_MASK_STRUCTURE_ID) >> orxSTRUCTURE_GUID_SHIFT_STRUCTURE_ID) < orxSTRUCTURE_ID_NUMBER)) ? (orxSTRUCTURE *)STRUCTURE : (orxSTRUCTURE *)orxNULL)
60 
61 #define orxANIM(STRUCTURE) orxSTRUCTURE_GET_POINTER(STRUCTURE, ANIM)
62 #define orxANIMPOINTER(STRUCTURE) orxSTRUCTURE_GET_POINTER(STRUCTURE, ANIMPOINTER)
63 #define orxANIMSET(STRUCTURE) orxSTRUCTURE_GET_POINTER(STRUCTURE, ANIMSET)
64 #define orxBODY(STRUCTURE) orxSTRUCTURE_GET_POINTER(STRUCTURE, BODY)
65 #define orxCAMERA(STRUCTURE) orxSTRUCTURE_GET_POINTER(STRUCTURE, CAMERA)
66 #define orxCLOCK(STRUCTURE) orxSTRUCTURE_GET_POINTER(STRUCTURE, CLOCK)
67 #define orxFONT(STRUCTURE) orxSTRUCTURE_GET_POINTER(STRUCTURE, FONT)
68 #define orxFRAME(STRUCTURE) orxSTRUCTURE_GET_POINTER(STRUCTURE, FRAME)
69 #define orxFX(STRUCTURE) orxSTRUCTURE_GET_POINTER(STRUCTURE, FX)
70 #define orxFXPOINTER(STRUCTURE) orxSTRUCTURE_GET_POINTER(STRUCTURE, FXPOINTER)
71 #define orxGRAPHIC(STRUCTURE) orxSTRUCTURE_GET_POINTER(STRUCTURE, GRAPHIC)
72 #define orxOBJECT(STRUCTURE) orxSTRUCTURE_GET_POINTER(STRUCTURE, OBJECT)
73 #define orxSOUND(STRUCTURE) orxSTRUCTURE_GET_POINTER(STRUCTURE, SOUND)
74 #define orxSOUNDPOINTER(STRUCTURE) orxSTRUCTURE_GET_POINTER(STRUCTURE, SOUNDPOINTER)
75 #define orxSHADER(STRUCTURE) orxSTRUCTURE_GET_POINTER(STRUCTURE, SHADER)
76 #define orxSHADERPOINTER(STRUCTURE) orxSTRUCTURE_GET_POINTER(STRUCTURE, SHADERPOINTER)
77 #define orxSPAWNER(STRUCTURE) orxSTRUCTURE_GET_POINTER(STRUCTURE, SPAWNER)
78 #define orxTEXT(STRUCTURE) orxSTRUCTURE_GET_POINTER(STRUCTURE, TEXT)
79 #define orxTEXTURE(STRUCTURE) orxSTRUCTURE_GET_POINTER(STRUCTURE, TEXTURE)
80 #define orxTIMELINE(STRUCTURE) orxSTRUCTURE_GET_POINTER(STRUCTURE, TIMELINE)
81 #define orxVIEWPORT(STRUCTURE) orxSTRUCTURE_GET_POINTER(STRUCTURE, VIEWPORT)
82 
85 #define orxSTRUCTURE_REGISTER(TYPE, STORAGE_TYPE, MEMORY_TYPE, BANK_SIZE, UPDATE_FUNCTION) \
86  orxStructure_Register(orxSTRUCTURE_ID_##TYPE, STORAGE_TYPE, MEMORY_TYPE, sizeof(orx##TYPE), BANK_SIZE, UPDATE_FUNCTION)
87 
90 #define orxSTRUCTURE_ASSERT(STRUCTURE) \
91  orxASSERT((STRUCTURE != orxNULL) && (((((orxSTRUCTURE *)(STRUCTURE))->u64GUID & orxSTRUCTURE_GUID_MASK_STRUCTURE_ID) >> orxSTRUCTURE_GUID_SHIFT_STRUCTURE_ID) < orxSTRUCTURE_ID_NUMBER));
92 
95 #define orxSTRUCTURE_GUID_MAGIC_TAG_DELETED 0xDEFACED0DEADC0DEULL
96 
99 #define orxSTRUCTURE_GUID_MASK_STRUCTURE_ID 0x000000000000001FULL
100 #define orxSTRUCTURE_GUID_SHIFT_STRUCTURE_ID 0
101 
102 #define orxSTRUCTURE_GUID_MASK_ITEM_ID 0x0000FFFF00000000ULL
103 #define orxSTRUCTURE_GUID_SHIFT_ITEM_ID 32
104 
105 #define orxSTRUCTURE_GUID_MASK_REF_COUNTER 0xFFFF000000000000ULL
106 #define orxSTRUCTURE_GUID_SHIFT_REF_COUNTER 48
107 
108 #define orxSTRUCTURE_GUID_MASK_INSTANCE_ID 0x00000000FFFFFFE0ULL
109 #define orxSTRUCTURE_GUID_SHIFT_INSTANCE_ID 5
110 
111 
114 typedef enum __orxSTRUCTURE_ID_t
115 {
116  /* *** Following structures can be linked to objects *** */
117 
128 
130 
131  /* *** Below this point, structures can not be linked to objects *** */
132 
144 
146 
147  orxSTRUCTURE_ID_NONE = orxENUM_NONE
148 
150 
153 typedef enum __orxSTRUCTURE_STORAGE_TYPE_t
154 {
157 
159 
161 
163 
166 typedef struct __orxSTRUCTURE_t
167 {
168  orxU64 u64GUID;
169  orxU64 u64OwnerGUID;
171  union
172  {
175  } stStorage;
177  orxU32 u32Flags;
179 } orxSTRUCTURE;
180 
181 
184 typedef orxSTATUS (orxFASTCALL *orxSTRUCTURE_UPDATE_FUNCTION)(orxSTRUCTURE *_pstStructure, const orxSTRUCTURE *_pstCaller, const orxCLOCK_INFO *_pstClockInfo);
185 
186 
192 static orxINLINE orxSTRUCTURE *_orxStructure_GetPointer(const void *_pStructure, orxSTRUCTURE_ID _eStructureID)
193 {
194  orxSTRUCTURE *pstResult;
195 
196  /* Updates result */
197  pstResult = ((_pStructure != orxNULL) && ((((orxSTRUCTURE *)_pStructure)->u64GUID & orxSTRUCTURE_GUID_MASK_STRUCTURE_ID) >> orxSTRUCTURE_GUID_SHIFT_STRUCTURE_ID) == _eStructureID) ? (orxSTRUCTURE *)_pStructure : (orxSTRUCTURE *)orxNULL;
198 
199  /* Done! */
200  return pstResult;
201 }
202 
207 static orxINLINE const orxSTRING orxStructure_GetIDString(orxSTRUCTURE_ID _eID)
208 {
209  const orxSTRING zResult;
210 
211 #define orxSTRUCTURE_DECLARE_ID_ENTRY(ID) case orxSTRUCTURE_ID_##ID: zResult = #ID; break
212 
213  /* Depending on ID */
214  switch(_eID)
215  {
216  orxSTRUCTURE_DECLARE_ID_ENTRY(ANIMPOINTER);
222  orxSTRUCTURE_DECLARE_ID_ENTRY(SHADERPOINTER);
223  orxSTRUCTURE_DECLARE_ID_ENTRY(SOUNDPOINTER);
237 
238  default: zResult = "INVALID STRUCTURE ID"; break;
239  }
240 
241 #undef orxSTRUCTURE_DECLARE_ID_ENTRY
242 
243  /* Done! */
244  return zResult;
245 }
246 
247 
250 extern orxDLLAPI void orxFASTCALL orxStructure_Setup();
251 
255 extern orxDLLAPI orxSTATUS orxFASTCALL orxStructure_Init();
256 
259 extern orxDLLAPI void orxFASTCALL orxStructure_Exit();
260 
261 
271 extern orxDLLAPI orxSTATUS orxFASTCALL orxStructure_Register(orxSTRUCTURE_ID _eStructureID, orxSTRUCTURE_STORAGE_TYPE _eStorageType, orxMEMORY_TYPE _eMemoryType, orxU32 _u32Size, orxU32 _u32BankSize, const orxSTRUCTURE_UPDATE_FUNCTION _pfnUpdate);
272 
277 extern orxDLLAPI orxSTATUS orxFASTCALL orxStructure_Unregister(orxSTRUCTURE_ID _eStructureID);
278 
279 
284 extern orxDLLAPI orxSTRUCTURE *orxFASTCALL orxStructure_Create(orxSTRUCTURE_ID _eStructureID);
285 
290 extern orxDLLAPI orxSTATUS orxFASTCALL orxStructure_Delete(void *_pStructure);
291 
292 
298 
303 extern orxDLLAPI orxU32 orxFASTCALL orxStructure_GetCounter(orxSTRUCTURE_ID _eStructureID);
304 
311 extern orxDLLAPI orxSTATUS orxFASTCALL orxStructure_Update(void *_pStructure, const void *_phCaller, const orxCLOCK_INFO *_pstClockInfo);
312 
313 
321 extern orxDLLAPI orxSTRUCTURE *orxFASTCALL orxStructure_Get(orxU64 _u64GUID);
322 
327 extern orxDLLAPI orxSTRUCTURE *orxFASTCALL orxStructure_GetOwner(const void *_pStructure);
328 
334 extern orxDLLAPI orxSTATUS orxFASTCALL orxStructure_SetOwner(void *_pStructure, void *_pOwner);
335 
340 extern orxDLLAPI orxSTRUCTURE *orxFASTCALL orxStructure_GetFirst(orxSTRUCTURE_ID _eStructureID);
341 
346 extern orxDLLAPI orxSTRUCTURE *orxFASTCALL orxStructure_GetLast(orxSTRUCTURE_ID _eStructureID);
347 
352 extern orxDLLAPI orxSTRUCTURE *orxFASTCALL orxStructure_GetParent(const void *_pStructure);
353 
358 extern orxDLLAPI orxSTRUCTURE *orxFASTCALL orxStructure_GetChild(const void *_pStructure);
359 
364 extern orxDLLAPI orxSTRUCTURE *orxFASTCALL orxStructure_GetSibling(const void *_pStructure);
365 
370 extern orxDLLAPI orxSTRUCTURE *orxFASTCALL orxStructure_GetPrevious(const void *_pStructure);
371 
376 extern orxDLLAPI orxSTRUCTURE *orxFASTCALL orxStructure_GetNext(const void *_pStructure);
377 
383 extern orxDLLAPI orxSTATUS orxFASTCALL orxStructure_SetParent(void *_pStructure, void *_phParent);
384 
385 
392 static orxINLINE void orxStructure_IncreaseCounter(void *_pStructure)
393 {
394  orxU64 u64Counter;
395 
396  /* Checks */
397  orxSTRUCTURE_ASSERT(_pStructure);
398 
399  /* Gets current counter */
401 
402  /* Updates it */
403  u64Counter++;
404 
405  /* Checks */
407 
408  /* Stores it */
409  orxSTRUCTURE(_pStructure)->u64GUID = (orxSTRUCTURE(_pStructure)->u64GUID & ~orxSTRUCTURE_GUID_MASK_REF_COUNTER) | (u64Counter << orxSTRUCTURE_GUID_SHIFT_REF_COUNTER);
410 
411  /* Done! */
412  return;
413 }
414 
418 static orxINLINE void orxStructure_DecreaseCounter(void *_pStructure)
419 {
420  orxU64 u64Counter;
421 
422  /* Checks */
423  orxSTRUCTURE_ASSERT(_pStructure);
424 
425  /* Gets current counter */
427 
428  /* Checks */
429  orxASSERT(u64Counter != 0);
430 
431  /* Updates it */
432  u64Counter--;
433 
434  /* Stores it */
435  orxSTRUCTURE(_pStructure)->u64GUID = (orxSTRUCTURE(_pStructure)->u64GUID & ~orxSTRUCTURE_GUID_MASK_REF_COUNTER) | (u64Counter << orxSTRUCTURE_GUID_SHIFT_REF_COUNTER);
436 
437  /* Done! */
438  return;
439 }
440 
445 static orxINLINE orxU32 orxStructure_GetRefCounter(const void *_pStructure)
446 {
447  /* Checks */
448  orxSTRUCTURE_ASSERT(_pStructure);
449 
450  /* Done! */
451  return((orxU32)((orxSTRUCTURE(_pStructure)->u64GUID & orxSTRUCTURE_GUID_MASK_REF_COUNTER) >> orxSTRUCTURE_GUID_SHIFT_REF_COUNTER));
452 }
453 
458 static orxINLINE orxU64 orxStructure_GetGUID(const void *_pStructure)
459 {
460  /* Checks */
461  orxSTRUCTURE_ASSERT(_pStructure);
462 
463  /* Done! */
464  return orxSTRUCTURE(_pStructure)->u64GUID & ~orxSTRUCTURE_GUID_MASK_REF_COUNTER;
465 }
466 
471 static orxINLINE orxSTRUCTURE_ID orxStructure_GetID(const void *_pStructure)
472 {
473  /* Checks */
474  orxSTRUCTURE_ASSERT(_pStructure);
475 
476  /* Done! */
478 }
479 
485 static orxINLINE orxBOOL orxStructure_TestFlags(const void *_pStructure, orxU32 _u32Flags)
486 {
487  /* Checks */
488  orxSTRUCTURE_ASSERT(_pStructure);
489 
490  /* Done! */
491  return(orxFLAG_TEST(orxSTRUCTURE(_pStructure)->u32Flags, _u32Flags));
492 }
493 
499 static orxINLINE orxBOOL orxStructure_TestAllFlags(const void *_pStructure, orxU32 _u32Flags)
500 {
501  /* Checks */
502  orxSTRUCTURE_ASSERT(_pStructure);
503 
504  /* Done! */
505  return(orxFLAG_TEST_ALL(orxSTRUCTURE(_pStructure)->u32Flags, _u32Flags));
506 }
507 
513 static orxINLINE orxU32 orxStructure_GetFlags(const void *_pStructure, orxU32 _u32Mask)
514 {
515  /* Checks */
516  orxSTRUCTURE_ASSERT(_pStructure);
517 
518  /* Done! */
519  return(orxFLAG_GET(orxSTRUCTURE(_pStructure)->u32Flags, _u32Mask));
520 }
521 
527 static orxINLINE void orxStructure_SetFlags(void *_pStructure, orxU32 _u32AddFlags, orxU32 _u32RemoveFlags)
528 {
529  /* Checks */
530  orxSTRUCTURE_ASSERT(_pStructure);
531 
532  orxFLAG_SET(orxSTRUCTURE(_pStructure)->u32Flags, _u32AddFlags, _u32RemoveFlags);
533 
534  /* Done! */
535  return;
536 }
537 
538 #endif /* _orxSTRUCTURE_H_ */
539 
orxDLLAPI orxSTRUCTURE *orxFASTCALL orxStructure_GetFirst(orxSTRUCTURE_ID _eStructureID)
static orxINLINE orxU32 orxStructure_GetFlags(const void *_pStructure, orxU32 _u32Mask)
Definition: orxStructure.h:513
orxDLLAPI orxSTRUCTURE *orxFASTCALL orxStructure_GetNext(const void *_pStructure)
static orxINLINE orxBOOL orxStructure_TestAllFlags(const void *_pStructure, orxU32 _u32Flags)
Definition: orxStructure.h:499
orxDLLAPI orxSTRUCTURE_STORAGE_TYPE orxFASTCALL orxStructure_GetStorageType(orxSTRUCTURE_ID _eStructureID)
orxTREE_NODE stTreeNode
Definition: orxStructure.h:174
orxDLLAPI orxSTRUCTURE *orxFASTCALL orxStructure_GetLast(orxSTRUCTURE_ID _eStructureID)
orxDLLAPI orxSTRUCTURE *orxFASTCALL orxStructure_GetChild(const void *_pStructure)
orxSTRUCTURE_STORAGE_TYPE
Definition: orxStructure.h:153
static orxINLINE void orxStructure_IncreaseCounter(void *_pStructure)
Definition: orxStructure.h:392
#define orxFLAG_TEST(X, F)
Definition: orxDecl.h:422
#define orxSTRUCTURE_DECLARE_ID_ENTRY(ID)
#define orxSTRUCTURE_ASSERT(STRUCTURE)
Definition: orxStructure.h:90
orxDLLAPI orxSTATUS orxFASTCALL orxStructure_SetOwner(void *_pStructure, void *_pOwner)
orxDLLAPI orxSTRUCTURE *orxFASTCALL orxStructure_Create(orxSTRUCTURE_ID _eStructureID)
#define orxSTRUCTURE_GUID_SHIFT_STRUCTURE_ID
Definition: orxStructure.h:100
orxDLLAPI orxSTATUS orxFASTCALL orxStructure_Register(orxSTRUCTURE_ID _eStructureID, orxSTRUCTURE_STORAGE_TYPE _eStorageType, orxMEMORY_TYPE _eMemoryType, orxU32 _u32Size, orxU32 _u32BankSize, const orxSTRUCTURE_UPDATE_FUNCTION _pfnUpdate)
orxDLLAPI orxU32 orxFASTCALL orxStructure_GetCounter(orxSTRUCTURE_ID _eStructureID)
orxDLLAPI orxSTRUCTURE *orxFASTCALL orxStructure_GetParent(const void *_pStructure)
#define orxSTRUCTURE(STRUCTURE)
Definition: orxStructure.h:59
#define orxSTRUCTURE_GUID_MASK_STRUCTURE_ID
Definition: orxStructure.h:99
orxDLLAPI orxSTRUCTURE *orxFASTCALL orxStructure_GetPrevious(const void *_pStructure)
static orxINLINE const orxSTRING orxStructure_GetIDString(orxSTRUCTURE_ID _eID)
Definition: orxStructure.h:207
orxMEMORY_TYPE
Definition: orxMemory.h:98
static orxINLINE orxU64 orxStructure_GetGUID(const void *_pStructure)
Definition: orxStructure.h:458
#define orxSTRUCTURE_GUID_MASK_REF_COUNTER
Definition: orxStructure.h:105
orxDLLAPI void orxFASTCALL orxStructure_Exit()
static orxINLINE orxSTRUCTURE * _orxStructure_GetPointer(const void *_pStructure, orxSTRUCTURE_ID _eStructureID)
Definition: orxStructure.h:192
#define orxFLAG_SET(X, A, R)
Definition: orxDecl.h:436
orxDLLAPI void orxFASTCALL orxStructure_Setup()
orxSTATUS
Definition: orxType.h:243
static orxINLINE void orxStructure_SetFlags(void *_pStructure, orxU32 _u32AddFlags, orxU32 _u32RemoveFlags)
Definition: orxStructure.h:527
#define orxSTRUCTURE_GUID_SHIFT_REF_COUNTER
Definition: orxStructure.h:106
orxDLLAPI orxSTATUS orxFASTCALL orxStructure_Delete(void *_pStructure)
orxDLLAPI orxSTATUS orxFASTCALL orxStructure_Unregister(orxSTRUCTURE_ID _eStructureID)
orxDLLAPI orxSTRUCTURE *orxFASTCALL orxStructure_GetSibling(const void *_pStructure)
orxDLLAPI orxSTATUS orxFASTCALL orxStructure_Init()
#define orxDLLAPI
Definition: orxDecl.h:387
orxDLLAPI orxSTATUS orxFASTCALL orxStructure_Update(void *_pStructure, const void *_phCaller, const orxCLOCK_INFO *_pstClockInfo)
static orxINLINE orxU32 orxStructure_GetRefCounter(const void *_pStructure)
Definition: orxStructure.h:445
orxU64 u64OwnerGUID
Definition: orxStructure.h:169
orxDLLAPI orxSTRUCTURE *orxFASTCALL orxStructure_GetOwner(const void *_pStructure)
orxSTRUCTURE_ID
Definition: orxStructure.h:114
orxU64 u64GUID
Definition: orxStructure.h:168
#define orxFLAG_TEST_ALL(X, F)
Definition: orxDecl.h:415
static orxINLINE orxBOOL orxStructure_TestFlags(const void *_pStructure, orxU32 _u32Flags)
Definition: orxStructure.h:485
static orxINLINE orxSTRUCTURE_ID orxStructure_GetID(const void *_pStructure)
Definition: orxStructure.h:471
#define orxASSERT(TEST,...)
Definition: orxDebug.h:298
orxLINKLIST_NODE stLinkListNode
Definition: orxStructure.h:173
orxU32 u32Flags
Definition: orxStructure.h:177
orxDLLAPI orxSTRUCTURE *orxFASTCALL orxStructure_Get(orxU64 _u64GUID)
orxSTATUS(orxFASTCALL * orxSTRUCTURE_UPDATE_FUNCTION)(orxSTRUCTURE *_pstStructure, const orxSTRUCTURE *_pstCaller, const orxCLOCK_INFO *_pstClockInfo)
Definition: orxStructure.h:184
static orxINLINE void orxStructure_DecreaseCounter(void *_pStructure)
Definition: orxStructure.h:418
orxDLLAPI orxSTATUS orxFASTCALL orxStructure_SetParent(void *_pStructure, void *_phParent)
#define orxFLAG_GET(X, M)
Definition: orxDecl.h:429

Generated for orx by doxygen 1.5.6