diff options
author | Erwin Coumans <blender@erwincoumans.com> | 2006-11-29 08:24:52 +0300 |
---|---|---|
committer | Erwin Coumans <blender@erwincoumans.com> | 2006-11-29 08:24:52 +0300 |
commit | e720f86a836b9343388beafb56be5be9956a3629 (patch) | |
tree | a703505b43d0936b433dd0fc177644ebdbc2b64b /extern/bullet2/src/LinearMath | |
parent | c5db2965fad723982857c9099114360330f90146 (diff) |
updated to latest Bullet 2.x
Diffstat (limited to 'extern/bullet2/src/LinearMath')
-rw-r--r-- | extern/bullet2/src/LinearMath/btScalar.h | 4 | ||||
-rw-r--r-- | extern/bullet2/src/LinearMath/btStackAlloc.h | 106 |
2 files changed, 108 insertions, 2 deletions
diff --git a/extern/bullet2/src/LinearMath/btScalar.h b/extern/bullet2/src/LinearMath/btScalar.h index aa046b89df0..46b8145a766 100644 --- a/extern/bullet2/src/LinearMath/btScalar.h +++ b/extern/bullet2/src/LinearMath/btScalar.h @@ -37,7 +37,7 @@ subject to the following restrictions: //#define ATTRIBUTE_ALIGNED16(a) __declspec(align(16)) a #define ATTRIBUTE_ALIGNED16(a) a #include <assert.h> - #define ASSERT assert + #define btAssert assert #else //non-windows systems @@ -47,7 +47,7 @@ subject to the following restrictions: #ifndef assert #include <assert.h> #endif - #define ASSERT assert + #define btAssert assert #endif diff --git a/extern/bullet2/src/LinearMath/btStackAlloc.h b/extern/bullet2/src/LinearMath/btStackAlloc.h new file mode 100644 index 00000000000..d219b453537 --- /dev/null +++ b/extern/bullet2/src/LinearMath/btStackAlloc.h @@ -0,0 +1,106 @@ +/* +Copyright (c) 2003-2006 Gino van den Bergen / Erwin Coumans http://continuousphysics.com/Bullet/ + +This software is provided 'as-is', without any express or implied warranty. +In no event will the authors be held liable for any damages arising from the use of this software. +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it freely, +subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. +2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. +*/ + +/* +StackAlloc extracted from GJK-EPA collision solver by Nathanael Presson +Nov.2006 +*/ + +#ifndef BT_STACK_ALLOC +#define BT_STACK_ALLOC + +#include "btScalar.h" //for btAssert + +struct btBlock +{ + btBlock* previous; + unsigned char* address; +}; + +///StackAlloc provides some fast stack-based memory allocator (LIFO last-in first-out) +class btStackAlloc +{ +public: + + btStackAlloc(unsigned int size) { ctor();create(size); } + ~btStackAlloc() { destroy(); } + + inline void create(unsigned int size) + { + destroy(); + data = new unsigned char[size]; + totalsize = size; + } + inline void destroy() + { + btAssert(usedsize==0); + //Raise(L"StackAlloc is still in use"); + + if(usedsize==0) + { + if(!ischild) delete[] data; + data = 0; + usedsize = 0; + } + + } + unsigned char* allocate(unsigned int size) + { + const unsigned int nus(usedsize+size); + if(nus<totalsize) + { + usedsize=nus; + return(data+(usedsize-size)); + } + btAssert(0); + //&& (L"Not enough memory")); + + return(0); + } + inline btBlock* beginBlock() + { + btBlock* pb = (btBlock*)allocate(sizeof(btBlock)); + pb->previous = current; + pb->address = data+usedsize; + current = pb; + return(pb); + } + inline void endBlock(btBlock* block) + { + btAssert(block==current); + //Raise(L"Unmatched blocks"); + if(block==current) + { + current = block->previous; + usedsize = (unsigned int)((block->address-data)-sizeof(btBlock)); + } + } + +private: + void ctor() + { + data = 0; + totalsize = 0; + usedsize = 0; + current = 0; + ischild = false; + } + unsigned char* data; + unsigned int totalsize; + unsigned int usedsize; + btBlock* current; + bool ischild; +}; + +#endif //BT_STACK_ALLOC |