- Added serialization to btBvhTriangleMeshShape/btOptimizedBvh. See ConcaveDemo for example usage.

- added bt32BitAxisSweep3, which co-exists without recompilation, using template class. This broadphase is recommended for large worlds with many objects (> 16384), until btMultiSwap is finished.
- Fixed some recent issues in Bullet 2.57 related to compound (thanks Proctoid) and memory allocations
This commit is contained in:
ejcoumans
2007-09-10 01:14:42 +00:00
parent e1c037b4c2
commit b054f375bc
20 changed files with 1585 additions and 810 deletions

View File

@@ -50,6 +50,8 @@ class btAlignedObjectArray
int m_size;
int m_capacity;
T* m_data;
//PCK: added this line
bool m_ownsMemory;
protected:
SIMD_FORCE_INLINE int allocSize(int size)
@@ -69,6 +71,8 @@ class btAlignedObjectArray
SIMD_FORCE_INLINE void init()
{
//PCK: added this line
m_ownsMemory = true;
m_data = 0;
m_size = 0;
m_capacity = 0;
@@ -92,7 +96,11 @@ class btAlignedObjectArray
SIMD_FORCE_INLINE void deallocate()
{
if(m_data) {
m_allocator.deallocate(m_data);
//PCK: enclosed the deallocation in this block
if (m_ownsMemory)
{
m_allocator.deallocate(m_data);
}
m_data = 0;
}
}
@@ -223,6 +231,9 @@ class btAlignedObjectArray
destroy(0,size());
deallocate();
//PCK: added this line
m_ownsMemory = true;
m_data = s;
@@ -360,8 +371,16 @@ class btAlignedObjectArray
}
}
//PCK: whole function
void initializeFromBuffer(void *buffer, int size, int capacity)
{
clear();
m_ownsMemory = false;
m_data = (T*)buffer;
m_size = size;
m_capacity = capacity;
}
};
#endif //BT_OBJECT_ARRAY__

View File

@@ -22,10 +22,17 @@ subject to the following restrictions:
class btQuadWordStorage
{
protected:
btScalar m_x;
btScalar m_y;
btScalar m_z;
btScalar m_unusedW;
#ifdef BT_USE_DOUBLE_PRECISION
union { btScalar m_x; unsigned long long int m_intx; unsigned char m_charx[8] ;};
union { btScalar m_y; unsigned long long int m_inty; unsigned char m_chary[8] ; };
union { btScalar m_z; unsigned long long int m_intz; unsigned char m_charz[8] ; };
union { btScalar m_unusedW; unsigned long long int m_intw; unsigned char m_charw[8] ; };
#else
union { btScalar m_x; unsigned int m_intx; unsigned char m_charx[4] ;};
union { btScalar m_y; unsigned int m_inty; unsigned char m_chary[4] ; };
union { btScalar m_z; unsigned int m_intz; unsigned char m_charz[4] ; };
union { btScalar m_unusedW; unsigned int m_intw; unsigned char m_charw[4] ; };
#endif //BT_USE_DOUBLE_PRECISION
};
@@ -63,6 +70,79 @@ class btQuadWord : public btQuadWordStorage
SIMD_FORCE_INLINE operator btScalar *() { return &m_x; }
SIMD_FORCE_INLINE operator const btScalar *() const { return &m_x; }
#ifdef BT_USE_DOUBLE_PRECISION
SIMD_FORCE_INLINE unsigned long long int getLongIntXValue() const
{
return m_intx;
}
SIMD_FORCE_INLINE unsigned long long int getLongIntYValue() const
{
return m_inty;
}
SIMD_FORCE_INLINE unsigned long long int getLongIntZValue() const
{
return m_intz;
}
SIMD_FORCE_INLINE unsigned long long int getLongIntWValue() const
{
return m_intw;
}
SIMD_FORCE_INLINE void setXValueByLongInt(unsigned long long int intval)
{
m_intx = intval;
}
SIMD_FORCE_INLINE void setYValueByLongInt(unsigned long long int intval)
{
m_inty = intval;
}
SIMD_FORCE_INLINE void setZValueByLongInt(unsigned long long int intval)
{
m_intz = intval;
}
SIMD_FORCE_INLINE void setWValueByLongInt(unsigned long long int intval)
{
m_intz = intval;
}
#else
SIMD_FORCE_INLINE unsigned int getIntXValue() const
{
return m_intx;
}
SIMD_FORCE_INLINE unsigned int getIntYValue() const
{
return m_inty;
}
SIMD_FORCE_INLINE unsigned int getIntZValue() const
{
return m_intz;
}
SIMD_FORCE_INLINE unsigned int getIntWValue() const
{
return m_intw;
}
SIMD_FORCE_INLINE void setXValueByInt(unsigned int intval)
{
m_intx = intval;
}
SIMD_FORCE_INLINE void setYValueByInt(unsigned int intval)
{
m_inty = intval;
}
SIMD_FORCE_INLINE void setZValueByInt(unsigned int intval)
{
m_intz = intval;
}
SIMD_FORCE_INLINE void setWValueByInt(unsigned int intval)
{
m_intw = intval;
}
#endif//BT_USE_DOUBLE_PRECISION
SIMD_FORCE_INLINE void setValue(const btScalar& x, const btScalar& y, const btScalar& z)
{
m_x=x;

View File

@@ -24,49 +24,6 @@ subject to the following restrictions:
#include <float.h>
#ifdef WIN32
//added __cdecl, thanks Jack
// default new and delete overrides that guarantee 16 byte alignment and zero allocated memory
void* __cdecl operator new(size_t sz) throw();
void* __cdecl operator new[](size_t sz) throw();
void __cdecl operator delete(void* m) throw();
void __cdecl operator delete[](void* m) throw();
#include <malloc.h>
#include <stdio.h>
#define BULLET_ALIGNED_NEW_AND_DELETE \
\
inline void* operator new(size_t sz) throw() \
{ \
printf("new %d\n",sz); \
void* mem = _aligned_malloc(sz + 64, 16); \
return mem; \
} \
\
inline void* operator new[](size_t sz) throw() \
{ \
printf("new[] %d\n",sz); \
void* mem = _aligned_malloc(sz + 64, 16); \
return mem; \
} \
\
inline void operator delete(void* m) throw() \
{ \
printf("delete %x\n",m); \
if (m == 0) \
return; \
_aligned_free(m); \
} \
\
inline void operator delete[](void* m) throw() \
{ \
printf("delete[] %x\n",m); \
_aligned_free(m); \
} \
#endif
#ifdef WIN32
@@ -227,6 +184,18 @@ SIMD_FORCE_INLINE btScalar btFsel(btScalar a, btScalar b, btScalar c)
#define btFsels(a,b,c) (btScalar)btFsel(a,b,c)
SIMD_FORCE_INLINE bool btMachineIsLittleEndian()
{
long int i = 1;
const char *p = (const char *) &i;
if (p[0] == 1) // Lowest address contains the least significant byte
return true;
else
return false;
}
///btSelect avoids branches, which makes performance much better for consoles like Playstation 3 and XBox 360
///Thanks Phil Knight. See also http://www.cellperformance.com/articles/2006/04/more_techniques_for_eliminatin_1.html
SIMD_FORCE_INLINE unsigned btSelect(unsigned condition, unsigned valueIfConditionNonZero, unsigned valueIfConditionZero)
@@ -255,4 +224,99 @@ SIMD_FORCE_INLINE float btSelect(unsigned condition, float valueIfConditionNonZe
}
//PCK: endian swapping functions
SIMD_FORCE_INLINE unsigned btSwapEndian(unsigned val)
{
return (((val & 0xff000000) >> 24) | ((val & 0x00ff0000) >> 8) | ((val & 0x0000ff00) << 8) | ((val & 0x000000ff) << 24));
}
SIMD_FORCE_INLINE unsigned short btSwapEndian(unsigned short val)
{
return (((val & 0xff00) >> 8) | ((val & 0x00ff) << 8));
}
SIMD_FORCE_INLINE unsigned btSwapEndian(int val)
{
return btSwapEndian((unsigned)val);
}
SIMD_FORCE_INLINE unsigned short btSwapEndian(short val)
{
return btSwapEndian((unsigned short) val);
}
///btSwapFloat uses using char pointers to swap the endianness
////btSwapFloat/btSwapDouble will NOT return a float, because the machine might 'correct' invalid floating point values
///Not all values of sign/exponent/mantissa are valid floating point numbers according to IEEE 754.
///When a floating point unit is faced with an invalid value, it may actually change the value, or worse, throw an exception.
///In most systems, running user mode code, you wouldn't get an exception, but instead the hardware/os/runtime will 'fix' the number for you.
///so instead of returning a float/double, we return integer/long long integer
SIMD_FORCE_INLINE unsigned int btSwapEndianFloat(float d)
{
unsigned int a;
unsigned char *dst = (unsigned char *)&a;
unsigned char *src = (unsigned char *)&d;
dst[0] = src[3];
dst[1] = src[2];
dst[2] = src[1];
dst[3] = src[0];
return a;
}
// unswap using char pointers
SIMD_FORCE_INLINE float btUnswapEndianFloat(unsigned int a)
{
float d;
unsigned char *src = (unsigned char *)&a;
unsigned char *dst = (unsigned char *)&d;
dst[0] = src[3];
dst[1] = src[2];
dst[2] = src[1];
dst[3] = src[0];
return d;
}
// swap using char pointers
SIMD_FORCE_INLINE unsigned long long btSwapEndianDouble(double d)
{
unsigned long long a;
unsigned char *dst = (unsigned char *)&a;
unsigned char *src = (unsigned char *)&d;
dst[0] = src[7];
dst[1] = src[6];
dst[2] = src[5];
dst[3] = src[4];
dst[4] = src[3];
dst[5] = src[2];
dst[6] = src[1];
dst[7] = src[0];
return a;
}
// unswap using char pointers
SIMD_FORCE_INLINE double btUnswapEndianDouble(unsigned long long a)
{
double d;
unsigned char *src = (unsigned char *)&a;
unsigned char *dst = (unsigned char *)&d;
dst[0] = src[7];
dst[1] = src[6];
dst[2] = src[5];
dst[3] = src[4];
dst[4] = src[3];
dst[5] = src[2];
dst[6] = src[1];
dst[7] = src[0];
return d;
}
#endif //SIMD___SCALAR_H

View File

@@ -55,6 +55,12 @@ public:
}
}
int getAvailableMemory() const
{
return totalsize - usedsize;
}
unsigned char* allocate(unsigned int size)
{
const unsigned int nus(usedsize+size);

View File

@@ -403,4 +403,58 @@ public:
};
///btSwapVector3Endian swaps vector endianness, useful for network and cross-platform serialization
SIMD_FORCE_INLINE void btSwapVector3Endian(const btVector3& source, btVector3& dest)
{
#ifdef BT_USE_DOUBLE_PRECISION
unsigned long long int tmp;
tmp = btSwapDouble(source.getX());
dest.setXValueByLongInt(tmp);
tmp = btSwapDouble(source.getY());
dest.setYValueByLongInt(tmp);
tmp = btSwapDouble(source.getZ());
dest.setZValueByLongInt(tmp);
tmp = btSwapDouble(source[3]);
dest.setWValueByLongInt(tmp);
#else
unsigned int tmp;
tmp = btSwapEndianFloat(source.getX());
dest.setXValueByInt(tmp);
tmp = btSwapEndianFloat(source.getY());
dest.setYValueByInt(tmp);
tmp = btSwapEndianFloat(source.getZ());
dest.setZValueByInt(tmp);
tmp = btSwapEndianFloat(source[3]);
dest.setWValueByInt(tmp);
#endif //BT_USE_DOUBLE_PRECISION
}
///btUnSwapVector3Endian swaps vector endianness, useful for network and cross-platform serialization
SIMD_FORCE_INLINE void btUnSwapVector3Endian(btVector3& vector)
{
#ifdef BT_USE_DOUBLE_PRECISION
unsigned long long int tmp;
tmp = vector.getLongIntXValue();
vector.setX( btUnswapDouble(tmp));
tmp = vector.getLongIntYValue();
vector.setY( btUnswapDouble(tmp));
tmp = vector.getLongIntZValue();
vector.setZ( btUnswapDouble(tmp));
tmp = vector.getLongIntWValue();
vector[3] = btUnswapDouble(tmp);
#else
unsigned int tmp;
tmp = vector.getIntXValue();
vector.setX( btUnswapEndianFloat(tmp));
tmp = vector.getIntYValue();
vector.setY( btUnswapEndianFloat(tmp));
tmp = vector.getIntZValue();
vector.setZ( btUnswapEndianFloat(tmp));
tmp = vector.getIntWValue();
vector[3] = btUnswapEndianFloat(tmp);
#endif //BT_USE_DOUBLE_PRECISION
}
#endif //SIMD__VECTOR3_H