Based on feedback from another professional game company, there are several improvements, including some API change...
Some dynamic memory allocations have been replace by pool allocation or stack allocations. quantized aabb versus quantized aabb overlap check is made branch-free (helps a lot on consoles PS3/XBox 360) Collision algorithms are now created through a new btDefaultCollisionConfiguration, to decouple dependency (this is the API change): Example: btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration(); m_dispatcher = new btCollisionDispatcher(collisionConfiguration);
This commit is contained in:
@@ -21,11 +21,14 @@ subject to the following restrictions:
|
||||
#include <malloc.h>
|
||||
void* btAlignedAlloc (int size, int alignment)
|
||||
{
|
||||
return _aligned_malloc(size,alignment);
|
||||
void* ptr = _aligned_malloc(size,alignment);
|
||||
// printf("btAlignedAlloc %d, %x\n",size,ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void btAlignedFree (void* ptr)
|
||||
{
|
||||
// printf("btAlignedFree %x\n",ptr);
|
||||
_aligned_free(ptr);
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,51 @@ subject to the following restrictions:
|
||||
#include <cfloat>
|
||||
#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
|
||||
|
||||
#if defined(__MINGW32__) || defined(__CYGWIN__) || (defined (_MSC_VER) && _MSC_VER < 1300)
|
||||
@@ -163,14 +208,6 @@ SIMD_FORCE_INLINE bool btGreaterEqual (btScalar a, btScalar eps) {
|
||||
return (!((a) <= eps));
|
||||
}
|
||||
|
||||
/*SIMD_FORCE_INLINE btScalar btCos(btScalar x) { return cosf(x); }
|
||||
SIMD_FORCE_INLINE btScalar btSin(btScalar x) { return sinf(x); }
|
||||
SIMD_FORCE_INLINE btScalar btTan(btScalar x) { return tanf(x); }
|
||||
SIMD_FORCE_INLINE btScalar btAcos(btScalar x) { return acosf(x); }
|
||||
SIMD_FORCE_INLINE btScalar btAsin(btScalar x) { return asinf(x); }
|
||||
SIMD_FORCE_INLINE btScalar btAtan(btScalar x) { return atanf(x); }
|
||||
SIMD_FORCE_INLINE btScalar btAtan2(btScalar x, btScalar y) { return atan2f(x, y); }
|
||||
*/
|
||||
|
||||
SIMD_FORCE_INLINE int btIsNegative(btScalar x) {
|
||||
return x < btScalar(0.0) ? 1 : 0;
|
||||
@@ -189,4 +226,33 @@ SIMD_FORCE_INLINE btScalar btFsel(btScalar a, btScalar b, btScalar c)
|
||||
#endif
|
||||
#define btFsels(a,b,c) (btScalar)btFsel(a,b,c)
|
||||
|
||||
|
||||
///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)
|
||||
{
|
||||
// Set testNz to 0xFFFFFFFF if condition is nonzero, 0x00000000 if condition is zero
|
||||
// Rely on positive value or'ed with its negative having sign bit on
|
||||
// and zero value or'ed with its negative (which is still zero) having sign bit off
|
||||
// Use arithmetic shift right, shifting the sign bit through all 32 bits
|
||||
unsigned testNz = (unsigned)(((int)condition | -(int)condition) >> 31);
|
||||
unsigned testEqz = ~testNz;
|
||||
return ((valueIfConditionNonZero & testNz) | (valueIfConditionZero & testEqz));
|
||||
}
|
||||
SIMD_FORCE_INLINE int btSelect(unsigned condition, int valueIfConditionNonZero, int valueIfConditionZero)
|
||||
{
|
||||
unsigned testNz = (unsigned)(((int)condition | -(int)condition) >> 31);
|
||||
unsigned testEqz = ~testNz;
|
||||
return ((valueIfConditionNonZero & testNz) | (valueIfConditionZero & testEqz));
|
||||
}
|
||||
SIMD_FORCE_INLINE float btSelect(unsigned condition, float valueIfConditionNonZero, float valueIfConditionZero)
|
||||
{
|
||||
#ifdef BT_HAVE_NATIVE_FSEL
|
||||
return (float)btFsel((btScalar)condition - btScalar(1.0f), valueIfConditionNonZero, valueIfConditionZero);
|
||||
#else
|
||||
return (condition != 0) ? valueIfConditionNonZero : valueIfConditionZero;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#endif //SIMD___SCALAR_H
|
||||
|
||||
Reference in New Issue
Block a user