[1378] | 1 | #ifndef NX_PHYSICS_ALLOCATEABLE
|
---|
| 2 | #define NX_PHYSICS_ALLOCATEABLE
|
---|
| 3 | /*----------------------------------------------------------------------------*\
|
---|
| 4 | |
|
---|
| 5 | | NovodeX Technology
|
---|
| 6 | |
|
---|
| 7 | | www.novodex.com
|
---|
| 8 | |
|
---|
| 9 | \*----------------------------------------------------------------------------*/
|
---|
| 10 | /** \addtogroup physics
|
---|
| 11 | @{
|
---|
| 12 | */
|
---|
| 13 |
|
---|
| 14 | #include "Nxp.h"
|
---|
| 15 | #include "NxUserAllocator.h"
|
---|
| 16 | #include "PhysXLoader.h"
|
---|
| 17 |
|
---|
| 18 |
|
---|
| 19 | /*
|
---|
| 20 | Should be called Allocateable but then we collide with Ice::Allocateable.
|
---|
| 21 | */
|
---|
| 22 |
|
---|
| 23 | /**
|
---|
| 24 | \brief Subclasses of this base class automatically take part in user memory management.
|
---|
| 25 | */
|
---|
| 26 | class NxAllocateable
|
---|
| 27 | {
|
---|
| 28 | public:
|
---|
| 29 | NX_INLINE void* operator new(size_t size, NxMemoryType type);
|
---|
| 30 | NX_INLINE void* operator new[](size_t size, NxMemoryType type);
|
---|
| 31 | NX_INLINE void operator delete(void* p);
|
---|
| 32 | NX_INLINE void operator delete[](void* p);
|
---|
| 33 | #ifdef _DEBUG
|
---|
| 34 | NX_INLINE void* operator new(size_t size, const char* fileName, int line, const char* className, NxMemoryType type);
|
---|
| 35 | NX_INLINE void* operator new[](size_t size, const char* fileName, int line, const char* className, NxMemoryType type);
|
---|
| 36 | NX_INLINE void operator delete(void* p, const char*, int, const char*, NxMemoryType type);
|
---|
| 37 | NX_INLINE void operator delete[](void* p, const char*, int, const char*, NxMemoryType type);
|
---|
| 38 | #endif
|
---|
| 39 | // PT: delete parameters have been added to fix warning C4291 in VC7. But they're not used.
|
---|
| 40 | };
|
---|
| 41 |
|
---|
| 42 | NX_INLINE void* NxAllocateable::operator new(size_t size, NxMemoryType type)
|
---|
| 43 | {
|
---|
| 44 | return NxGetPhysicsSDKAllocator()->malloc(size, type);
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 | NX_INLINE void* NxAllocateable::operator new[](size_t size, NxMemoryType type)
|
---|
| 48 | {
|
---|
| 49 | return NxGetPhysicsSDKAllocator()->malloc(size, type);
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | NX_INLINE void NxAllocateable::operator delete(void* p)
|
---|
| 53 | {
|
---|
| 54 | NxGetPhysicsSDKAllocator()->free(p);
|
---|
| 55 | }
|
---|
| 56 |
|
---|
| 57 | NX_INLINE void NxAllocateable::operator delete[](void* p)
|
---|
| 58 | {
|
---|
| 59 | NxGetPhysicsSDKAllocator()->free(p);
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | #ifdef _DEBUG
|
---|
| 63 | NX_INLINE void* NxAllocateable::operator new(size_t size, const char* fileName, int line, const char* className, NxMemoryType type)
|
---|
| 64 | {
|
---|
| 65 | return NxGetPhysicsSDKAllocator()->mallocDEBUG(size, fileName, line, className, type);
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | NX_INLINE void* NxAllocateable::operator new[](size_t size, const char* fileName, int line, const char* className, NxMemoryType type)
|
---|
| 69 | {
|
---|
| 70 | return NxGetPhysicsSDKAllocator()->mallocDEBUG(size, fileName, line, className, type);
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | NX_INLINE void NxAllocateable::operator delete(void* p, const char*, int, const char*, NxMemoryType)
|
---|
| 74 | {
|
---|
| 75 | NxGetPhysicsSDKAllocator()->free(p);
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | NX_INLINE void NxAllocateable::operator delete[](void* p, const char*, int, const char*, NxMemoryType)
|
---|
| 79 | {
|
---|
| 80 | NxGetPhysicsSDKAllocator()->free(p);
|
---|
| 81 | }
|
---|
| 82 | #endif
|
---|
| 83 |
|
---|
| 84 |
|
---|
| 85 |
|
---|
| 86 | #ifndef NX_PHYSICS_DLL //only define for user code, our internal versions are defined in foundation/src/include/Allocateable.h
|
---|
| 87 | #ifndef NX_USE_SDK_STATICLIBS
|
---|
| 88 | #ifndef CORELIB //TODO: this macro needs an NX prefix!
|
---|
| 89 | #ifdef NX_FOUNDATION_ALLOCATEABLE
|
---|
| 90 | #error Something went wrong, duplicate macro def!
|
---|
| 91 | #endif
|
---|
| 92 | #ifdef _DEBUG
|
---|
| 93 | #define NX_ALLOC_TMP(x) NxGetPhysicsSDKAllocator()->mallocDEBUG(x, (const char *)__FILE__, __LINE__, #x, NX_MEMORY_TEMP)
|
---|
| 94 | #define NX_ALLOC(x) NxGetPhysicsSDKAllocator()->mallocDEBUG(x, (const char *)__FILE__, __LINE__, #x, NX_MEMORY_PERSISTENT)
|
---|
| 95 | #else
|
---|
| 96 | #define NX_ALLOC_TMP(x) NxGetPhysicsSDKAllocator()->malloc(x, NX_MEMORY_TEMP)
|
---|
| 97 | #define NX_ALLOC(x) NxGetPhysicsSDKAllocator()->malloc(x, NX_MEMORY_PERSISTENT)
|
---|
| 98 | #endif
|
---|
| 99 | #define NX_FREE(x) if(x) { NxGetPhysicsSDKAllocator()->free(x); x = NULL; }
|
---|
| 100 |
|
---|
| 101 | #endif
|
---|
| 102 | #endif
|
---|
| 103 | #endif
|
---|
| 104 |
|
---|
| 105 | /** @} */
|
---|
| 106 | #endif
|
---|
| 107 |
|
---|
| 108 |
|
---|
| 109 | //AGCOPYRIGHTBEGIN
|
---|
| 110 | ///////////////////////////////////////////////////////////////////////////
|
---|
| 111 | // Copyright © 2005 AGEIA Technologies.
|
---|
| 112 | // All rights reserved. www.ageia.com
|
---|
| 113 | ///////////////////////////////////////////////////////////////////////////
|
---|
| 114 | //AGCOPYRIGHTEND
|
---|
| 115 |
|
---|