00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00036 #pragma once
00037
00038 #include <PsArray.h>
00039 #include <PsHashMap.h>
00040 #include <PsAlignedMalloc.h>
00041 #include "NvCloth/Callbacks.h"
00042
00043 namespace nv
00044 {
00045 namespace cloth
00046 {
00047
00048 void* allocate(size_t);
00049 void deallocate(void*);
00050
00051 class NonTrackingAllocator
00052 {
00053 public:
00054 PX_FORCE_INLINE NonTrackingAllocator(const char* = 0)
00055 {
00056 }
00057 PX_FORCE_INLINE void* allocate(size_t size, const char* file, int line)
00058 {
00059 return !size ? 0 : GetNvClothAllocator()->allocate(size, "NonTrackedAlloc", file, line);
00060 }
00061 PX_FORCE_INLINE void deallocate(void* ptr)
00062 {
00063 if (ptr)
00064 GetNvClothAllocator()->deallocate(ptr);
00065 }
00066 };
00067
00068
00069
00070 template <typename T>
00071 struct Vector
00072 {
00073 typedef physx::shdfnd::Array<T, NonTrackingAllocator> Type;
00074 };
00075
00076 template <typename T, size_t alignment>
00077 struct AlignedVector
00078 {
00079 typedef physx::shdfnd::Array<T, physx::shdfnd::AlignedAllocator<alignment, NonTrackingAllocator> > Type;
00080 };
00081
00082 template <class Key, class Value, class HashFn = physx::shdfnd::Hash<Key> >
00083 struct HashMap
00084 {
00085 typedef physx::shdfnd::HashMap<Key, Value, HashFn, NonTrackingAllocator> Type;
00086 };
00087
00088 struct NvClothOverload{};
00089 #define NV_CLOTH_NEW(T) new (__FILE__, __LINE__, nv::cloth::NvClothOverload()) T
00090 #define NV_CLOTH_ALLOC(n, name) GetNvClothAllocator()->allocate(n, name, __FILE__, __LINE__)
00091 #define NV_CLOTH_FREE(x) GetNvClothAllocator()->deallocate(x)
00092 #define NV_CLOTH_DELETE(x) delete x
00093
00094 }
00095 }
00096
00097
00098 template <typename T>
00099 PX_INLINE void* operator new(size_t size, const char* fileName,
00100 typename physx::shdfnd::EnableIfPod<T, int>::Type line, nv::cloth::NvClothOverload overload)
00101 {
00102 PX_UNUSED(overload);
00103 return GetNvClothAllocator()->allocate(size, "<TypeName Unknown>", fileName, line);
00104 }
00105
00106 template <typename T>
00107 PX_INLINE void* operator new [](size_t size, const char* fileName,
00108 typename physx::shdfnd::EnableIfPod<T, int>::Type line, nv::cloth::NvClothOverload overload)
00109 {
00110 PX_UNUSED(overload);
00111 return GetNvClothAllocator()->allocate(size, "<TypeName Unknown>", fileName, line);
00112 }
00113
00114
00115 template <typename T>
00116 PX_INLINE void operator delete(void* ptr, const char* fileName,
00117 typename physx::shdfnd::EnableIfPod<T, int>::Type line, nv::cloth::NvClothOverload overload)
00118 {
00119 PX_UNUSED(fileName);
00120 PX_UNUSED(line);
00121 PX_UNUSED(overload);
00122
00123 return GetNvClothAllocator()->deallocate(ptr);
00124 }
00125
00126
00127 template <typename T>
00128 PX_INLINE void operator delete [](void* ptr, const char* fileName,
00129 typename physx::shdfnd::EnableIfPod<T, int>::Type line, nv::cloth::NvClothOverload overload)
00130 {
00131 PX_UNUSED(fileName);
00132 PX_UNUSED(line);
00133 PX_UNUSED(overload);
00134
00135 return GetNvClothAllocator()->deallocate(ptr);
00136 }
00137
00138 namespace nv
00139 {
00140 namespace cloth
00141 {
00142
00143 class UserAllocated
00144 {
00145 public:
00146 PX_INLINE void* operator new(size_t size, const char* fileName, int line, NvClothOverload overload)
00147 {
00148 PX_UNUSED(overload);
00149 return GetNvClothAllocator()->allocate(size, "<TypeName Unknown>", fileName, line);
00150 }
00151 PX_INLINE void* operator new [](size_t size, const char* fileName, int line, NvClothOverload overload)
00152 {
00153 PX_UNUSED(overload);
00154 return GetNvClothAllocator()->allocate(size, "<TypeName Unknown>", fileName, line);
00155 }
00156
00157
00158 PX_INLINE void operator delete(void* ptr, const char* fileName, int line, NvClothOverload overload)
00159 {
00160 PX_UNUSED(fileName);
00161 PX_UNUSED(line);
00162 PX_UNUSED(overload);
00163 GetNvClothAllocator()->deallocate(ptr);
00164 }
00165 PX_INLINE void operator delete [](void* ptr, const char* fileName, int line, NvClothOverload overload)
00166 {
00167 PX_UNUSED(fileName);
00168 PX_UNUSED(line);
00169 PX_UNUSED(overload);
00170 GetNvClothAllocator()->deallocate(ptr);
00171 }
00172 PX_INLINE void operator delete(void* ptr)
00173 {
00174 return GetNvClothAllocator()->deallocate(ptr);
00175 }
00176 PX_INLINE void operator delete [](void* ptr)
00177 {
00178 return GetNvClothAllocator()->deallocate(ptr);
00179 }
00180 };
00181
00182 }
00183 }