diff options
author | Erwin Coumans <blender@erwincoumans.com> | 2006-12-12 06:08:15 +0300 |
---|---|---|
committer | Erwin Coumans <blender@erwincoumans.com> | 2006-12-12 06:08:15 +0300 |
commit | 9a169f26333141b1f9e0ef4609c7ef3dba2f5835 (patch) | |
tree | 3c5ca488888a6befac6fe29e596d64115a4584ea /extern/bullet2/src/LinearMath | |
parent | 237e7417e733f6942068131a612acb495a6742cf (diff) |
added some new Bullet files, and upgraded to latest Bullet 2.x
Please make sure to have extern/bullet/src/LinearMath/btAlignedAllocator.cpp in your build, if you add the files by name, instead of wildcard *.cpp
Diffstat (limited to 'extern/bullet2/src/LinearMath')
-rw-r--r-- | extern/bullet2/src/LinearMath/btAlignedAllocator.cpp | 47 | ||||
-rw-r--r-- | extern/bullet2/src/LinearMath/btAlignedAllocator.h | 77 | ||||
-rw-r--r-- | extern/bullet2/src/LinearMath/btAlignedObjectArray.h | 175 | ||||
-rw-r--r-- | extern/bullet2/src/LinearMath/btGeometryUtil.cpp | 10 | ||||
-rw-r--r-- | extern/bullet2/src/LinearMath/btGeometryUtil.h | 13 | ||||
-rw-r--r-- | extern/bullet2/src/LinearMath/btQuadWord.h | 5 | ||||
-rw-r--r-- | extern/bullet2/src/LinearMath/btScalar.h | 12 |
7 files changed, 320 insertions, 19 deletions
diff --git a/extern/bullet2/src/LinearMath/btAlignedAllocator.cpp b/extern/bullet2/src/LinearMath/btAlignedAllocator.cpp new file mode 100644 index 00000000000..e32bc9f6880 --- /dev/null +++ b/extern/bullet2/src/LinearMath/btAlignedAllocator.cpp @@ -0,0 +1,47 @@ +/* +Bullet Continuous Collision Detection and Physics Library +Copyright (c) 2003-2006 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. +*/ + +#include "btAlignedAllocator.h" + + +#if defined (WIN32) && !defined(__MINGW32__) && !defined(__CYGWIN__) + +#include <malloc.h> +void* btAlignedAlloc (int size, int alignment) +{ + return _aligned_malloc(size,alignment); +} + +void btAlignedFree (void* ptr) +{ + _aligned_free(ptr); +} + +#else + +///todo +///will add some multi-platform version that works without _aligned_malloc/_aligned_free + +void* btAlignedAlloc (int size, int alignment) +{ + return new char[size]; +} + +void btAlignedFree (void* ptr) +{ + delete ptr; +} + +#endif
\ No newline at end of file diff --git a/extern/bullet2/src/LinearMath/btAlignedAllocator.h b/extern/bullet2/src/LinearMath/btAlignedAllocator.h new file mode 100644 index 00000000000..159399ce7d4 --- /dev/null +++ b/extern/bullet2/src/LinearMath/btAlignedAllocator.h @@ -0,0 +1,77 @@ +/* +Bullet Continuous Collision Detection and Physics Library +Copyright (c) 2003-2006 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. +*/ + +#ifndef BT_ALIGNED_ALLOCATOR +#define BT_ALIGNED_ALLOCATOR + +///we probably replace this with our own aligned memory allocator +///so we replace _aligned_malloc and _aligned_free with our own +///that is better portable and more predictable + +#include "btScalar.h" + +void* btAlignedAlloc (int size, int alignment); + +void btAlignedFree (void* ptr); + + +typedef int size_type; + + +template < typename T , unsigned Alignment > +class btAlignedAllocator { + + typedef btAlignedAllocator< T , Alignment > self_type; + +public: + //just going down a list: + btAlignedAllocator() {} + + btAlignedAllocator( const self_type & ) {} + + template < typename Other > + btAlignedAllocator( const btAlignedAllocator< Other , Alignment > & ) {} + + typedef const T* const_pointer; + typedef const T& const_reference; + typedef T* pointer; + typedef T& reference; + typedef T value_type; + + pointer address ( reference ref ) const { return &ref; } + const_pointer address ( const_reference ref ) const { return &ref; } + pointer allocate ( size_type n , const_pointer * hint = 0 ) { + return reinterpret_cast< pointer >(btAlignedAlloc( sizeof(value_type) * n , Alignment )); + } + void construct ( pointer ptr , const value_type & value ) { new (ptr) value_type( value ); } + void deallocate( pointer ptr ) { + btAlignedFree( reinterpret_cast< void * >( ptr ) ); + } + void destroy ( pointer ptr ) { ptr->~value_type(); } + + + template < typename O > struct rebind { + typedef btAlignedAllocator< O , Alignment > other; + }; + template < typename O > + self_type & operator=( const btAlignedAllocator< O , Alignment > & ) { return *this; } + + friend bool operator==( const self_type & , const self_type & ) { return true; } +}; + + + +#endif //BT_ALIGNED_ALLOCATOR + diff --git a/extern/bullet2/src/LinearMath/btAlignedObjectArray.h b/extern/bullet2/src/LinearMath/btAlignedObjectArray.h new file mode 100644 index 00000000000..79469c03c29 --- /dev/null +++ b/extern/bullet2/src/LinearMath/btAlignedObjectArray.h @@ -0,0 +1,175 @@ +/* +Bullet Continuous Collision Detection and Physics Library +Copyright (c) 2003-2006 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. +*/ + + +#ifndef BT_OBJECT_ARRAY__ +#define BT_OBJECT_ARRAY__ + +#include "btScalar.h" // has definitions like SIMD_FORCE_INLINE +#include "btAlignedAllocator.h" + +///btAlignedObjectArray uses a subset of the stl::vector interface for its methods +///It is developed to replace stl::vector to avoid STL alignment issues to add SIMD/SSE data +template <typename T> +//template <class T> +class btAlignedObjectArray +{ + int m_size; + int m_capacity; + T* m_data; + + btAlignedAllocator<T , 16> m_allocator; + + protected: + SIMD_FORCE_INLINE int allocSize(int size) + { + return (size ? size*2 : 1); + } + SIMD_FORCE_INLINE void copy(int start,int end, T* dest) + { + int i; + for (i=0;i<m_size;++i) + dest[i] = m_data[i]; + } + + SIMD_FORCE_INLINE void init() + { + m_data = 0; + m_size = 0; + m_capacity = 0; + } + SIMD_FORCE_INLINE void destroy(int first,int last) + { + int i; + for (i=0; i<m_size;i++) + { + m_data[i].~T(); + } + } + + SIMD_FORCE_INLINE void* allocate(int size) + { + if (size) + return m_allocator.allocate(size); + return 0; + } + + SIMD_FORCE_INLINE void deallocate() + { + if(m_data) + m_allocator.deallocate(m_data); + } + + + public: + + btAlignedObjectArray() + { + init(); + } + + ~btAlignedObjectArray() + { + clear(); + } + + SIMD_FORCE_INLINE int capacity() const + { // return current length of allocated storage + return m_capacity; + } + + SIMD_FORCE_INLINE int size() const + { // return length of sequence + return m_size; + } + + SIMD_FORCE_INLINE const T& operator[](int n) const + { + return m_data[n]; + } + + SIMD_FORCE_INLINE T& operator[](int n) + { + return m_data[n]; + } + + + SIMD_FORCE_INLINE void clear() + { + destroy(0,size()); + + deallocate(); + + init(); + } + + SIMD_FORCE_INLINE void pop_back() + { + m_size--; + m_data[m_size].~T(); + } + + SIMD_FORCE_INLINE void resize(int newsize) + { + if (newsize > size()) + { + reserve(newsize); + } + + m_size = newsize; + } + + + + SIMD_FORCE_INLINE void push_back(const T& _Val) + { + int sz = size(); + if( sz == capacity() ) + { + reserve( allocSize(size()) ); + } + + m_data[size()] = _Val; + //::new ( m_data[m_size] ) T(_Val); + m_size++; + } + + + + SIMD_FORCE_INLINE void reserve(int _Count) + { // determine new minimum length of allocated storage + if (capacity() < _Count) + { // not enough room, reallocate + if (capacity() < _Count) + { + T* s = (T*)allocate(_Count); + + copy(0, size(), s); + + destroy(0,size()); + + deallocate(); + + m_data = s; + + m_capacity = _Count; + + } + } + } + +}; + +#endif //BT_OBJECT_ARRAY__
\ No newline at end of file diff --git a/extern/bullet2/src/LinearMath/btGeometryUtil.cpp b/extern/bullet2/src/LinearMath/btGeometryUtil.cpp index 5176d317417..5036894b2b3 100644 --- a/extern/bullet2/src/LinearMath/btGeometryUtil.cpp +++ b/extern/bullet2/src/LinearMath/btGeometryUtil.cpp @@ -16,7 +16,7 @@ subject to the following restrictions: #include "btGeometryUtil.h" -bool btGeometryUtil::isPointInsidePlanes(const std::vector<btVector3>& planeEquations, const btVector3& point, float margin) +bool btGeometryUtil::isPointInsidePlanes(const btAlignedObjectArray<btVector3>& planeEquations, const btVector3& point, float margin) { int numbrushes = planeEquations.size(); for (int i=0;i<numbrushes;i++) @@ -33,7 +33,7 @@ bool btGeometryUtil::isPointInsidePlanes(const std::vector<btVector3>& planeEqua } -bool btGeometryUtil::areVerticesBehindPlane(const btVector3& planeNormal, const std::vector<btVector3>& vertices, float margin) +bool btGeometryUtil::areVerticesBehindPlane(const btVector3& planeNormal, const btAlignedObjectArray<btVector3>& vertices, float margin) { int numvertices = vertices.size(); for (int i=0;i<numvertices;i++) @@ -48,7 +48,7 @@ bool btGeometryUtil::areVerticesBehindPlane(const btVector3& planeNormal, const return true; } -bool notExist(const btVector3& planeEquation,const std::vector<btVector3>& planeEquations) +bool notExist(const btVector3& planeEquation,const btAlignedObjectArray<btVector3>& planeEquations) { int numbrushes = planeEquations.size(); for (int i=0;i<numbrushes;i++) @@ -62,7 +62,7 @@ bool notExist(const btVector3& planeEquation,const std::vector<btVector3>& plane return true; } -void btGeometryUtil::getPlaneEquationsFromVertices(std::vector<btVector3>& vertices, std::vector<btVector3>& planeEquationsOut ) +void btGeometryUtil::getPlaneEquationsFromVertices(btAlignedObjectArray<btVector3>& vertices, btAlignedObjectArray<btVector3>& planeEquationsOut ) { const int numvertices = vertices.size(); // brute force: @@ -110,7 +110,7 @@ void btGeometryUtil::getPlaneEquationsFromVertices(std::vector<btVector3>& verti } -void btGeometryUtil::getVerticesFromPlaneEquations(const std::vector<btVector3>& planeEquations , std::vector<btVector3>& verticesOut ) +void btGeometryUtil::getVerticesFromPlaneEquations(const btAlignedObjectArray<btVector3>& planeEquations , btAlignedObjectArray<btVector3>& verticesOut ) { const int numbrushes = planeEquations.size(); // brute force: diff --git a/extern/bullet2/src/LinearMath/btGeometryUtil.h b/extern/bullet2/src/LinearMath/btGeometryUtil.h index 525291e6051..018ffa72296 100644 --- a/extern/bullet2/src/LinearMath/btGeometryUtil.h +++ b/extern/bullet2/src/LinearMath/btGeometryUtil.h @@ -15,23 +15,24 @@ subject to the following restrictions: #ifndef BT_GEOMETRY_UTIL_H #define BT_GEOMETRY_UTIL_H -#include <vector> + #include "btVector3.h" +#include "btAlignedObjectArray.h" class btGeometryUtil { public: - static void getPlaneEquationsFromVertices(std::vector<btVector3>& vertices, std::vector<btVector3>& planeEquationsOut ); + static void getPlaneEquationsFromVertices(btAlignedObjectArray<btVector3>& vertices, btAlignedObjectArray<btVector3>& planeEquationsOut ); - static void getVerticesFromPlaneEquations(const std::vector<btVector3>& planeEquations , std::vector<btVector3>& verticesOut ); + static void getVerticesFromPlaneEquations(const btAlignedObjectArray<btVector3>& planeEquations , btAlignedObjectArray<btVector3>& verticesOut ); - static bool isInside(const std::vector<btVector3>& vertices, const btVector3& planeNormal, float margin); + static bool isInside(const btAlignedObjectArray<btVector3>& vertices, const btVector3& planeNormal, float margin); - static bool isPointInsidePlanes(const std::vector<btVector3>& planeEquations, const btVector3& point, float margin); + static bool isPointInsidePlanes(const btAlignedObjectArray<btVector3>& planeEquations, const btVector3& point, float margin); - static bool areVerticesBehindPlane(const btVector3& planeNormal, const std::vector<btVector3>& vertices, float margin); + static bool areVerticesBehindPlane(const btVector3& planeNormal, const btAlignedObjectArray<btVector3>& vertices, float margin); }; diff --git a/extern/bullet2/src/LinearMath/btQuadWord.h b/extern/bullet2/src/LinearMath/btQuadWord.h index 28bb2051dea..4331b668210 100644 --- a/extern/bullet2/src/LinearMath/btQuadWord.h +++ b/extern/bullet2/src/LinearMath/btQuadWord.h @@ -21,11 +21,10 @@ subject to the following restrictions: - -class btQuadWord +ATTRIBUTE_ALIGNED16 (class btQuadWord) { protected: - ATTRIBUTE_ALIGNED16 (btScalar m_x); + btScalar m_x; btScalar m_y; btScalar m_z; btScalar m_unusedW; diff --git a/extern/bullet2/src/LinearMath/btScalar.h b/extern/bullet2/src/LinearMath/btScalar.h index 46b8145a766..dd76fb2de1a 100644 --- a/extern/bullet2/src/LinearMath/btScalar.h +++ b/extern/bullet2/src/LinearMath/btScalar.h @@ -27,15 +27,15 @@ subject to the following restrictions: #if defined(__MINGW32__) || defined(__CYGWIN__) #define SIMD_FORCE_INLINE inline + #define ATTRIBUTE_ALIGNED16(a) a #else #pragma warning(disable:4530) #pragma warning(disable:4996) #pragma warning(disable:4786) #define SIMD_FORCE_INLINE __forceinline + #define ATTRIBUTE_ALIGNED16(a) __declspec(align(16)) a #endif //__MINGW32__ - - //#define ATTRIBUTE_ALIGNED16(a) __declspec(align(16)) a - #define ATTRIBUTE_ALIGNED16(a) a + #include <assert.h> #define btAssert assert #else @@ -54,8 +54,10 @@ subject to the following restrictions: typedef float btScalar; -#if defined (__sun) || defined (__sun__) || defined (__sparc) || defined (__APPLE__) -//use double float precision operation on those platforms for Blender +///older compilers (gcc 3.x) and Sun needs double versions of srqt etc. +///exclude Apple Intel (it's assumed to be a Macbook or newer Intel Dual Core processor) +#if defined (__sun) || defined (__sun__) || defined (__sparc) || (defined (__APPLE__) && ! defined (__i386__)) +//use slow double float precision operation on those platforms SIMD_FORCE_INLINE btScalar btSqrt(btScalar x) { return sqrt(x); } SIMD_FORCE_INLINE btScalar btFabs(btScalar x) { return fabs(x); } |