orx 1.16
Portable Game Engine
Loading...
Searching...
No Matches
orxStructure.h
Go to the documentation of this file.
1/* Orx - Portable Game Engine
2 *
3 * Copyright (c) 2008- 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
32
42
43
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 orxSPAWNER(STRUCTURE) orxSTRUCTURE_GET_POINTER(STRUCTURE, SPAWNER)
77#define orxTEXT(STRUCTURE) orxSTRUCTURE_GET_POINTER(STRUCTURE, TEXT)
78#define orxTEXTURE(STRUCTURE) orxSTRUCTURE_GET_POINTER(STRUCTURE, TEXTURE)
79#define orxTIMELINE(STRUCTURE) orxSTRUCTURE_GET_POINTER(STRUCTURE, TIMELINE)
80#define orxTRIGGER(STRUCTURE) orxSTRUCTURE_GET_POINTER(STRUCTURE, TRIGGER)
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 0x00000000000000FFULL
100#define orxSTRUCTURE_GUID_SHIFT_STRUCTURE_ID 0
101
102#define orxSTRUCTURE_GUID_MASK_ITEM_ID 0x00000000FFFFFF00ULL
103#define orxSTRUCTURE_GUID_SHIFT_ITEM_ID 8
104
105#define orxSTRUCTURE_GUID_MASK_INSTANCE_ID 0xFFFFFFFF00000000ULL
106#define orxSTRUCTURE_GUID_SHIFT_INSTANCE_ID 32
107
108
147
160
163typedef struct __orxSTRUCTURE_t
164{
165 orxU64 u64GUID;
167 orxU32 u32Flags;
168 orxU32 u32RefCount;
169
170 union
171 {
174 } stStorage;
175
177
178
181typedef orxSTATUS (orxFASTCALL *orxSTRUCTURE_UPDATE_FUNCTION)(orxSTRUCTURE *_pstStructure, const orxSTRUCTURE *_pstCaller, const orxCLOCK_INFO *_pstClockInfo);
182
183
189static orxINLINE orxSTRUCTURE *_orxStructure_GetPointer(const void *_pStructure, orxSTRUCTURE_ID _eStructureID)
190{
191 orxSTRUCTURE *pstResult;
192
193 /* Updates result */
194 pstResult = ((_pStructure != orxNULL) && ((((orxSTRUCTURE *)_pStructure)->u64GUID & orxSTRUCTURE_GUID_MASK_STRUCTURE_ID) >> orxSTRUCTURE_GUID_SHIFT_STRUCTURE_ID) == _eStructureID) ? (orxSTRUCTURE *)_pStructure : (orxSTRUCTURE *)orxNULL;
195
196 /* Done! */
197 return pstResult;
198}
199
204static orxINLINE const orxSTRING orxStructure_GetIDString(orxSTRUCTURE_ID _eID)
205{
206 const orxSTRING zResult;
207
208#define orxSTRUCTURE_DECLARE_ID_ENTRY(ID) case orxSTRUCTURE_ID_##ID: zResult = #ID; break
209
210 /* Depending on ID */
211 switch(_eID)
212 {
220 orxSTRUCTURE_DECLARE_ID_ENTRY(SOUNDPOINTER);
234
235 default: zResult = "INVALID STRUCTURE ID"; break;
236 }
237
238#undef orxSTRUCTURE_DECLARE_ID_ENTRY
239
240 /* Done! */
241 return zResult;
242}
243
244
247extern orxDLLAPI void orxFASTCALL orxStructure_Setup();
248
253
256extern orxDLLAPI void orxFASTCALL orxStructure_Exit();
257
258
268extern orxDLLAPI orxSTATUS orxFASTCALL orxStructure_Register(orxSTRUCTURE_ID _eStructureID, orxSTRUCTURE_STORAGE_TYPE _eStorageType, orxMEMORY_TYPE _eMemoryType, orxU32 _u32Size, orxU32 _u32BankSize, const orxSTRUCTURE_UPDATE_FUNCTION _pfnUpdate);
269
275
276
282
287extern orxDLLAPI orxSTATUS orxFASTCALL orxStructure_Delete(void *_pStructure);
288
289
295
300extern orxDLLAPI orxU32 orxFASTCALL orxStructure_GetCount(orxSTRUCTURE_ID _eStructureID);
301
308extern orxDLLAPI orxSTATUS orxFASTCALL orxStructure_Update(void *_pStructure, const void *_phCaller, const orxCLOCK_INFO *_pstClockInfo);
309
310
312
313
318extern orxDLLAPI orxSTRUCTURE *orxFASTCALL orxStructure_Get(orxU64 _u64GUID);
319
324extern orxDLLAPI orxSTRUCTURE *orxFASTCALL orxStructure_GetOwner(const void *_pStructure);
325
331extern orxDLLAPI orxSTATUS orxFASTCALL orxStructure_SetOwner(void *_pStructure, void *_pOwner);
332
338
344
349extern orxDLLAPI orxSTRUCTURE *orxFASTCALL orxStructure_GetParent(const void *_pStructure);
350
355extern orxDLLAPI orxSTRUCTURE *orxFASTCALL orxStructure_GetChild(const void *_pStructure);
356
361extern orxDLLAPI orxSTRUCTURE *orxFASTCALL orxStructure_GetSibling(const void *_pStructure);
362
367extern orxDLLAPI orxSTRUCTURE *orxFASTCALL orxStructure_GetPrevious(const void *_pStructure);
368
373extern orxDLLAPI orxSTRUCTURE *orxFASTCALL orxStructure_GetNext(const void *_pStructure);
374
380extern orxDLLAPI orxSTATUS orxFASTCALL orxStructure_SetParent(void *_pStructure, void *_phParent);
381
382
387extern orxDLLAPI orxSTATUS orxFASTCALL orxStructure_LogAll(orxBOOL _bPrivate);
388
389
391
392
396static orxINLINE void orxStructure_IncreaseCount(void *_pStructure)
397{
398 /* Checks */
399 orxSTRUCTURE_ASSERT(_pStructure);
400 orxASSERT(orxSTRUCTURE(_pStructure)->u32RefCount < 0xFFFFFFFF);
401
402 /* Increases ref count */
403 orxSTRUCTURE(_pStructure)->u32RefCount++;
404
405 /* Done! */
406 return;
407}
408
412static orxINLINE void orxStructure_DecreaseCount(void *_pStructure)
413{
414 /* Checks */
415 orxSTRUCTURE_ASSERT(_pStructure);
416 orxASSERT(orxSTRUCTURE(_pStructure)->u32RefCount != 0);
417
418 /* Decreases ref count */
419 orxSTRUCTURE(_pStructure)->u32RefCount--;
420
421 /* Done! */
422 return;
423}
424
429static orxINLINE orxU32 orxStructure_GetRefCount(const void *_pStructure)
430{
431 /* Checks */
432 orxSTRUCTURE_ASSERT(_pStructure);
433
434 /* Done! */
435 return orxSTRUCTURE(_pStructure)->u32RefCount;
436}
437
442static orxINLINE orxU64 orxStructure_GetGUID(const void *_pStructure)
443{
444 /* Checks */
445 orxSTRUCTURE_ASSERT(_pStructure);
446
447 /* Done! */
448 return orxSTRUCTURE(_pStructure)->u64GUID;
449}
450
455static orxINLINE orxSTRUCTURE_ID orxStructure_GetID(const void *_pStructure)
456{
457 /* Checks */
458 orxSTRUCTURE_ASSERT(_pStructure);
459
460 /* Done! */
462}
463
469static orxINLINE orxBOOL orxStructure_TestFlags(const void *_pStructure, orxU32 _u32Flags)
470{
471 /* Checks */
472 orxSTRUCTURE_ASSERT(_pStructure);
473
474 /* Done! */
475 return(orxFLAG_TEST(orxSTRUCTURE(_pStructure)->u32Flags, _u32Flags));
476}
477
483static orxINLINE orxBOOL orxStructure_TestAllFlags(const void *_pStructure, orxU32 _u32Flags)
484{
485 /* Checks */
486 orxSTRUCTURE_ASSERT(_pStructure);
487
488 /* Done! */
489 return(orxFLAG_TEST_ALL(orxSTRUCTURE(_pStructure)->u32Flags, _u32Flags));
490}
491
497static orxINLINE orxU32 orxStructure_GetFlags(const void *_pStructure, orxU32 _u32Mask)
498{
499 /* Checks */
500 orxSTRUCTURE_ASSERT(_pStructure);
501
502 /* Done! */
503 return(orxFLAG_GET(orxSTRUCTURE(_pStructure)->u32Flags, _u32Mask));
504}
505
511static orxINLINE void orxStructure_SetFlags(void *_pStructure, orxU32 _u32AddFlags, orxU32 _u32RemoveFlags)
512{
513 /* Checks */
514 orxSTRUCTURE_ASSERT(_pStructure);
515
516 orxFLAG_SET(orxSTRUCTURE(_pStructure)->u32Flags, _u32AddFlags, _u32RemoveFlags);
517
518 /* Done! */
519 return;
520}
521
522#endif /* _orxSTRUCTURE_H_ */
523
#define orxASSERT(TEST,...)
Definition orxDebug.h:378
#define orxFLAG_TEST(X, F)
Definition orxDecl.h:417
#define orxFLAG_TEST_ALL(X, F)
Definition orxDecl.h:410
#define orxFLAG_SET(X, A, R)
Definition orxDecl.h:431
#define orxFLAG_GET(X, M)
Definition orxDecl.h:424
#define orxDLLAPI
Definition orxDecl.h:381
orxMEMORY_TYPE
Definition orxMemory.h:95
orxSTRUCTURE_STORAGE_TYPE
orxDLLAPI orxSTATUS orxFASTCALL orxStructure_SetParent(void *_pStructure, void *_phParent)
static orxINLINE const orxSTRING orxStructure_GetIDString(orxSTRUCTURE_ID _eID)
orxDLLAPI orxSTATUS orxFASTCALL orxStructure_LogAll(orxBOOL _bPrivate)
orxDLLAPI orxSTRUCTURE *orxFASTCALL orxStructure_Create(orxSTRUCTURE_ID _eStructureID)
orxDLLAPI orxSTATUS orxFASTCALL orxStructure_Update(void *_pStructure, const void *_phCaller, const orxCLOCK_INFO *_pstClockInfo)
orxDLLAPI orxSTRUCTURE *orxFASTCALL orxStructure_GetOwner(const void *_pStructure)
orxDLLAPI orxSTRUCTURE *orxFASTCALL orxStructure_GetSibling(const void *_pStructure)
orxDLLAPI void orxFASTCALL orxStructure_Exit()
orxDLLAPI void orxFASTCALL orxStructure_Setup()
#define orxSTRUCTURE_GUID_SHIFT_STRUCTURE_ID
orxDLLAPI orxSTRUCTURE *orxFASTCALL orxStructure_Get(orxU64 _u64GUID)
static orxINLINE orxU64 orxStructure_GetGUID(const void *_pStructure)
#define orxSTRUCTURE_ASSERT(STRUCTURE)
#define orxSTRUCTURE(STRUCTURE)
orxDLLAPI orxSTATUS orxFASTCALL orxStructure_Delete(void *_pStructure)
static orxINLINE orxU32 orxStructure_GetFlags(const void *_pStructure, orxU32 _u32Mask)
#define orxSTRUCTURE_GUID_MASK_STRUCTURE_ID
orxSTRUCTURE_ID
orxDLLAPI orxSTRUCTURE *orxFASTCALL orxStructure_GetPrevious(const void *_pStructure)
orxSTATUS(orxFASTCALL * orxSTRUCTURE_UPDATE_FUNCTION)(orxSTRUCTURE *_pstStructure, const orxSTRUCTURE *_pstCaller, const orxCLOCK_INFO *_pstClockInfo)
static orxINLINE void orxStructure_IncreaseCount(void *_pStructure)
orxDLLAPI orxSTATUS orxFASTCALL orxStructure_Init()
orxDLLAPI orxU32 orxFASTCALL orxStructure_GetCount(orxSTRUCTURE_ID _eStructureID)
orxDLLAPI orxSTRUCTURE_STORAGE_TYPE orxFASTCALL orxStructure_GetStorageType(orxSTRUCTURE_ID _eStructureID)
static orxINLINE void orxStructure_SetFlags(void *_pStructure, orxU32 _u32AddFlags, orxU32 _u32RemoveFlags)
static orxINLINE orxBOOL orxStructure_TestFlags(const void *_pStructure, orxU32 _u32Flags)
orxDLLAPI orxSTRUCTURE *orxFASTCALL orxStructure_GetLast(orxSTRUCTURE_ID _eStructureID)
orxDLLAPI orxSTRUCTURE *orxFASTCALL orxStructure_GetParent(const void *_pStructure)
orxDLLAPI orxSTRUCTURE *orxFASTCALL orxStructure_GetFirst(orxSTRUCTURE_ID _eStructureID)
orxDLLAPI orxSTATUS orxFASTCALL orxStructure_Unregister(orxSTRUCTURE_ID _eStructureID)
orxDLLAPI orxSTATUS orxFASTCALL orxStructure_Register(orxSTRUCTURE_ID _eStructureID, orxSTRUCTURE_STORAGE_TYPE _eStorageType, orxMEMORY_TYPE _eMemoryType, orxU32 _u32Size, orxU32 _u32BankSize, const orxSTRUCTURE_UPDATE_FUNCTION _pfnUpdate)
static orxINLINE orxU32 orxStructure_GetRefCount(const void *_pStructure)
static orxINLINE orxBOOL orxStructure_TestAllFlags(const void *_pStructure, orxU32 _u32Flags)
static orxINLINE void orxStructure_DecreaseCount(void *_pStructure)
orxDLLAPI orxSTRUCTURE *orxFASTCALL orxStructure_GetNext(const void *_pStructure)
static orxINLINE orxSTRUCTURE * _orxStructure_GetPointer(const void *_pStructure, orxSTRUCTURE_ID _eStructureID)
orxDLLAPI orxSTATUS orxFASTCALL orxStructure_SetOwner(void *_pStructure, void *_pOwner)
orxDLLAPI orxSTRUCTURE *orxFASTCALL orxStructure_GetChild(const void *_pStructure)
static orxINLINE orxSTRUCTURE_ID orxStructure_GetID(const void *_pStructure)
@ orxSTRUCTURE_STORAGE_TYPE_NONE
@ orxSTRUCTURE_STORAGE_TYPE_TREE
@ orxSTRUCTURE_STORAGE_TYPE_LINKLIST
@ orxSTRUCTURE_STORAGE_TYPE_NUMBER
@ orxSTRUCTURE_ID_SOUND
@ orxSTRUCTURE_ID_FXPOINTER
@ orxSTRUCTURE_ID_FONT
@ orxSTRUCTURE_ID_CAMERA
@ orxSTRUCTURE_ID_NONE
@ orxSTRUCTURE_ID_OBJECT
@ orxSTRUCTURE_ID_SOUNDPOINTER
@ orxSTRUCTURE_ID_ANIMPOINTER
@ orxSTRUCTURE_ID_VIEWPORT
@ orxSTRUCTURE_ID_TEXTURE
@ orxSTRUCTURE_ID_SPAWNER
@ orxSTRUCTURE_ID_CLOCK
@ orxSTRUCTURE_ID_FRAME
@ orxSTRUCTURE_ID_ANIMSET
@ orxSTRUCTURE_ID_TEXT
@ orxSTRUCTURE_ID_BODY
@ orxSTRUCTURE_ID_FX
@ orxSTRUCTURE_ID_LINKABLE_NUMBER
@ orxSTRUCTURE_ID_TRIGGER
@ orxSTRUCTURE_ID_ANIM
@ orxSTRUCTURE_ID_NUMBER
@ orxSTRUCTURE_ID_TIMELINE
@ orxSTRUCTURE_ID_SHADER
@ orxSTRUCTURE_ID_GRAPHIC
orxSTATUS
Definition orxType.h:270
#define orxSTRUCTURE_DECLARE_ID_ENTRY(ID)
orxTREE_NODE stTreeNode
orxU64 u64OwnerGUID
orxLINKLIST_NODE stLinkListNode
orxU32 u32RefCount

Generated for orx by doxygen 1.8.11