Merge pull request #404 from donggas90/master

Improve Compound Shape Construction.
This commit is contained in:
erwincoumans
2015-08-03 08:49:30 -07:00
3 changed files with 11 additions and 17 deletions

View File

@@ -18,7 +18,7 @@ subject to the following restrictions:
#include "BulletCollision/BroadphaseCollision/btDbvt.h" #include "BulletCollision/BroadphaseCollision/btDbvt.h"
#include "LinearMath/btSerializer.h" #include "LinearMath/btSerializer.h"
btCompoundShape::btCompoundShape(bool enableDynamicAabbTree) btCompoundShape::btCompoundShape(bool enableDynamicAabbTree, const int initialChildCapacity)
: m_localAabbMin(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT)), : m_localAabbMin(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT)),
m_localAabbMax(btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT)), m_localAabbMax(btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT)),
m_dynamicAabbTree(0), m_dynamicAabbTree(0),
@@ -34,6 +34,8 @@ m_localScaling(btScalar(1.),btScalar(1.),btScalar(1.))
m_dynamicAabbTree = new(mem) btDbvt(); m_dynamicAabbTree = new(mem) btDbvt();
btAssert(mem==m_dynamicAabbTree); btAssert(mem==m_dynamicAabbTree);
} }
m_children.reserve(initialChildCapacity);
} }

View File

@@ -70,7 +70,7 @@ protected:
public: public:
BT_DECLARE_ALIGNED_ALLOCATOR(); BT_DECLARE_ALIGNED_ALLOCATOR();
btCompoundShape(bool enableDynamicAabbTree = true); explicit btCompoundShape(bool enableDynamicAabbTree = true, const int initialChildCapacity = 0);
virtual ~btCompoundShape(); virtual ~btCompoundShape();

View File

@@ -202,24 +202,16 @@ protected:
///when the new number of elements is smaller, the destructor will be called, but memory will not be freed, to reduce performance overhead of run-time memory (de)allocations. ///when the new number of elements is smaller, the destructor will be called, but memory will not be freed, to reduce performance overhead of run-time memory (de)allocations.
SIMD_FORCE_INLINE void resizeNoInitialize(int newsize) SIMD_FORCE_INLINE void resizeNoInitialize(int newsize)
{ {
int curSize = size(); if (newsize > size())
if (newsize < curSize)
{ {
} else reserve(newsize);
{
if (newsize > size())
{
reserve(newsize);
}
//leave this uninitialized
} }
m_size = newsize; m_size = newsize;
} }
SIMD_FORCE_INLINE void resize(int newsize, const T& fillData=T()) SIMD_FORCE_INLINE void resize(int newsize, const T& fillData=T())
{ {
int curSize = size(); const register int curSize = size();
if (newsize < curSize) if (newsize < curSize)
{ {
@@ -229,7 +221,7 @@ protected:
} }
} else } else
{ {
if (newsize > size()) if (newsize > curSize)
{ {
reserve(newsize); reserve(newsize);
} }
@@ -246,7 +238,7 @@ protected:
} }
SIMD_FORCE_INLINE T& expandNonInitializing( ) SIMD_FORCE_INLINE T& expandNonInitializing( )
{ {
int sz = size(); const register int sz = size();
if( sz == capacity() ) if( sz == capacity() )
{ {
reserve( allocSize(size()) ); reserve( allocSize(size()) );
@@ -259,7 +251,7 @@ protected:
SIMD_FORCE_INLINE T& expand( const T& fillValue=T()) SIMD_FORCE_INLINE T& expand( const T& fillValue=T())
{ {
int sz = size(); const register int sz = size();
if( sz == capacity() ) if( sz == capacity() )
{ {
reserve( allocSize(size()) ); reserve( allocSize(size()) );
@@ -275,7 +267,7 @@ protected:
SIMD_FORCE_INLINE void push_back(const T& _Val) SIMD_FORCE_INLINE void push_back(const T& _Val)
{ {
int sz = size(); const register int sz = size();
if( sz == capacity() ) if( sz == capacity() )
{ {
reserve( allocSize(size()) ); reserve( allocSize(size()) );