24 #if DBVT_BP_PROFILE||DBVT_BP_ENABLE_BENCHMARK
31 __forceinline ProfileScope(
btClock& clock,
unsigned long& value) :
32 m_clock(&clock),m_value(&value),m_base(clock.getTimeMicroseconds())
35 __forceinline ~ProfileScope()
37 (*m_value)+=m_clock->getTimeMicroseconds()-m_base;
40 unsigned long* m_value;
43 #define SPC(_value_) ProfileScope spc_scope(m_clock,_value_)
58 if(list) list->links[0]=item;
66 if(item->links[0]) item->links[0]->links[1]=item->links[1];
else list=item->links[1];
67 if(item->links[1]) item->links[1]->links[0]=item->links[0];
75 while(root) { ++n;root=root->links[1]; }
81 static inline void clear(T& value)
83 static const struct ZeroDummy : T {} zerodummy;
103 #if DBVT_BP_SORTPAIRS
165 short int collisionFilterGroup,
166 short int collisionFilterMask,
171 collisionFilterGroup,
172 collisionFilterMask);
184 collider.
proxy=proxy;
289 #if DBVT_BP_PREVENTFALSEUPDATE
293 bool docollide=
false;
308 if(delta[0]<0) velocity[0]=-velocity[0];
309 if(delta[1]<0) velocity[1]=-velocity[1];
310 if(delta[2]<0) velocity[2]=-velocity[2];
357 bool docollide=
false;
394 if(0==(
m_pid%DBVT_BP_PROFILING_RATE))
397 unsigned int total=m_profiling.m_total;
398 if(total<=0) total=1;
399 printf(
"ddcollide: %u%% (%uus)\r\n",(50+m_profiling.m_ddcollide*100)/total,m_profiling.m_ddcollide/DBVT_BP_PROFILING_RATE);
400 printf(
"fdcollide: %u%% (%uus)\r\n",(50+m_profiling.m_fdcollide*100)/total,m_profiling.m_fdcollide/DBVT_BP_PROFILING_RATE);
401 printf(
"cleanup: %u%% (%uus)\r\n",(50+m_profiling.m_cleanup*100)/total,m_profiling.m_cleanup/DBVT_BP_PROFILING_RATE);
402 printf(
"total: %uus\r\n",total/DBVT_BP_PROFILING_RATE);
403 const unsigned long sum=m_profiling.m_ddcollide+
404 m_profiling.m_fdcollide+
405 m_profiling.m_cleanup;
406 printf(
"leaked: %u%% (%uus)\r\n",100-((50+sum*100)/total),(total-sum)/DBVT_BP_PROFILING_RATE);
439 for (i=0;i<overlappingPairArray.
size();i++)
444 bool isDuplicate = (pair == previousPair);
448 bool needsRemoval =
false;
459 needsRemoval =
false;
485 overlappingPairArray.
resize(overlappingPairArray.
size() - invalidPair);
509 SPC(m_profiling.m_total);
528 #if DBVT_BP_ACCURATESLEEPING
530 collider.
proxy=current;
548 SPC(m_profiling.m_fdcollide);
553 SPC(m_profiling.m_ddcollide);
560 SPC(m_profiling.m_cleanup);
566 for(
int i=0;i<ni;++i)
573 #if DBVT_BP_SORTPAIRS
669 #if DBVT_BP_ENABLE_BENCHMARK
671 struct btBroadphaseBenchmark
693 btSin(time)*amplitude/2;
695 btSin(time)*amplitude;
697 pbi->
setAabb(proxy,center-extents,center+extents,0);
700 static int UnsignedRand(
int range=RAND_MAX-1) {
return(rand()%(range+1)); }
702 static void OutputTime(
const char* name,
btClock& c,
unsigned count=0)
705 const unsigned long ms=(us+500)/1000;
708 printf(
"%s : %u us (%u ms), %.2f/s\r\n",name,us,ms,count/sec);
710 printf(
"%s : %u us (%u ms)\r\n",name,us,ms);
716 static const btBroadphaseBenchmark::Experiment experiments[]=
722 static const int nexperiments=
sizeof(experiments)/
sizeof(experiments[0]);
726 for(
int iexp=0;iexp<nexperiments;++iexp)
728 const btBroadphaseBenchmark::Experiment& experiment=experiments[iexp];
729 const int object_count=experiment.object_count;
730 const int update_count=(object_count*experiment.update_count)/100;
731 const int spawn_count=(object_count*experiment.spawn_count)/100;
732 const btScalar speed=experiment.speed;
733 const btScalar amplitude=experiment.amplitude;
734 printf(
"Experiment #%u '%s':\r\n",iexp,experiment.name);
735 printf(
"\tObjects: %u\r\n",object_count);
736 printf(
"\tUpdate: %u\r\n",update_count);
737 printf(
"\tSpawn: %u\r\n",spawn_count);
738 printf(
"\tSpeed: %f\r\n",speed);
739 printf(
"\tAmplitude: %f\r\n",amplitude);
744 for(
int i=0;i<object_count;++i)
746 btBroadphaseBenchmark::Object* po=
new btBroadphaseBenchmark::Object();
747 po->center[0]=btBroadphaseBenchmark::UnitRand()*50;
748 po->center[1]=btBroadphaseBenchmark::UnitRand()*50;
749 po->center[2]=btBroadphaseBenchmark::UnitRand()*50;
750 po->extents[0]=btBroadphaseBenchmark::UnitRand()*2+2;
751 po->extents[1]=btBroadphaseBenchmark::UnitRand()*2+2;
752 po->extents[2]=btBroadphaseBenchmark::UnitRand()*2+2;
753 po->time=btBroadphaseBenchmark::UnitRand()*2000;
754 po->proxy=pbi->
createProxy(po->center-po->extents,po->center+po->extents,0,po,1,1,0,0);
757 btBroadphaseBenchmark::OutputTime(
"\tInitialization",wallclock);
760 for(
int i=0;i<objects.
size();++i)
762 objects[i]->update(speed,amplitude,pbi);
764 btBroadphaseBenchmark::OutputTime(
"\tFirst update",wallclock);
767 for(
int i=0;i<experiment.iterations;++i)
769 for(
int j=0;j<update_count;++j)
771 objects[j]->update(speed,amplitude,pbi);
775 btBroadphaseBenchmark::OutputTime(
"\tUpdate",wallclock,experiment.iterations);
778 for(
int i=0;i<objects.
size();++i)
784 btBroadphaseBenchmark::OutputTime(
"\tRelease",wallclock);
virtual void aabbTest(const btVector3 &aabbMin, const btVector3 &aabbMax, btBroadphaseAabbCallback &callback)
static T sum(const btAlignedObjectArray< T > &items)
DBVT_INLINE void Merge(const btDbvtAabbMm &a, const btDbvtAabbMm &b, btDbvtAabbMm &r)
void push_back(const T &_Val)
btBroadphaseProxy * createProxy(const btVector3 &aabbMin, const btVector3 &aabbMax, int shapeType, void *userPtr, short int collisionFilterGroup, short int collisionFilterMask, btDispatcher *dispatcher, void *multiSapProxy)
static void benchmark(btBroadphaseInterface *)
virtual void cleanOverlappingPair(btBroadphasePair &pair, btDispatcher *dispatcher)=0
btBroadphaseRayCallback & m_rayCallback
static void listappend(T *item, T *&list)
virtual void resetPool(btDispatcher *dispatcher)
reset broadphase internal structures, to ensure determinism/reproducability
virtual bool hasDeferredRemoval()=0
btScalar btSin(btScalar x)
btOverlappingPairCache * m_paircache
void Process(const btDbvtNode *na, const btDbvtNode *nb)
DBVT_PREFIX void rayTestInternal(const btDbvtNode *root, const btVector3 &rayFrom, const btVector3 &rayTo, const btVector3 &rayDirectionInverse, unsigned int signs[3], btScalar lambda_max, const btVector3 &aabbMin, const btVector3 &aabbMax, DBVT_IPOLICY) const
rayTestInternal is faster than rayTest, because it uses a persistent stack (to reduce dynamic memory ...
btDbvtNode * insert(const btDbvtVolume &box, void *data)
unsigned long int getTimeMicroseconds()
Returns the time in us since the last call to reset or since the Clock was created.
The btClock is a portable basic clock that measures accurate time in seconds, use for profiling...
The btDbvtBroadphase implements a broadphase using two dynamic AABB bounding volume hierarchies/trees...
void reset()
Resets the initial reference time.
void performDeferredRemoval(btDispatcher *dispatcher)
void collide(btDispatcher *dispatcher)
The btOverlappingPairCache provides an interface for overlapping pair management (add, remove, storage), used by the btBroadphaseInterface broadphases.
void Process(const btDbvtNode *leaf)
void update(btDbvtNode *leaf, int lookahead=-1)
btDbvtProxy * m_stageRoots[STAGECOUNT+1]
btDbvtBroadphase(btOverlappingPairCache *paircache=0)
void Process(const btDbvtNode *n)
int size() const
return the number of elements in the array
virtual void setAabb(btBroadphaseProxy *proxy, const btVector3 &aabbMin, const btVector3 &aabbMax, btDispatcher *dispatcher)
void optimizeIncremental(int passes)
virtual btBroadphasePairArray & getOverlappingPairArray()=0
#define SPC(_value_)
btDbvtBroadphase implementation by Nathanael Presson
virtual btOverlappingPairCache * getOverlappingPairCache()
static btDbvtAabbMm FromMM(const btVector3 &mi, const btVector3 &mx)
virtual void destroyProxy(btBroadphaseProxy *proxy, btDispatcher *dispatcher)
virtual void rayTest(const btVector3 &rayFrom, const btVector3 &rayTo, btBroadphaseRayCallback &rayCallback, const btVector3 &aabbMin=btVector3(0, 0, 0), const btVector3 &aabbMax=btVector3(0, 0, 0))
virtual btBroadphaseProxy * createProxy(const btVector3 &aabbMin, const btVector3 &aabbMax, int shapeType, void *userPtr, short int collisionFilterGroup, short int collisionFilterMask, btDispatcher *dispatcher, void *multiSapProxy)=0
static void listremove(T *item, T *&list)
#define btAlignedFree(ptr)
static int listcount(T *root)
virtual void printStats()
virtual void removeOverlappingPairsContainingProxy(btBroadphaseProxy *proxy0, btDispatcher *dispatcher)=0
static btDbvtAabbMm FromCR(const btVector3 &c, btScalar r)
The btBroadphaseInterface class provides an interface to detect aabb-overlapping object pairs...
virtual int getNumOverlappingPairs() const =0
void optimizeTopDown(int bu_treshold=128)
virtual ~btOverlappingPairCache()
The btBroadphaseProxy is the main class that can be used with the Bullet broadphases.
btBroadphaseProxy * m_pProxy1
btCollisionAlgorithm * m_algorithm
btVector3 can be used to represent 3D points and vectors.
#define ATTRIBUTE_ALIGNED16(a)
DBVT_PREFIX void collideTTpersistentStack(const btDbvtNode *root0, const btDbvtNode *root1, DBVT_IPOLICY)
virtual bool process(const btBroadphaseProxy *proxy)=0
DBVT_INLINE const btVector3 & Maxs() const
btBroadphaseAabbCallback & m_aabbCallback
btBroadphaseProxy * m_pProxy0
void setAabbForceUpdate(btBroadphaseProxy *absproxy, const btVector3 &aabbMin, const btVector3 &aabbMax, btDispatcher *)
this setAabbForceUpdate is similar to setAabb but always forces the aabb update.
btDbvtTreeCollider(btDbvtBroadphase *p)
BroadphaseRayTester(btBroadphaseRayCallback &orgCallback)
virtual btBroadphasePair * addOverlappingPair(btBroadphaseProxy *proxy0, btBroadphaseProxy *proxy1)=0
static void clear(T &value)
virtual void getBroadphaseAabb(btVector3 &aabbMin, btVector3 &aabbMax) const
getAabb returns the axis aligned bounding box in the 'global' coordinate frame will add some transfor...
void resize(int newsize, const T &fillData=T())
btVector3 m_rayDirectionInverse
added some cached data to accelerate ray-AABB tests
DBVT_INLINE bool Intersect(const btDbvtAabbMm &a, const btDbvtAabbMm &b)
virtual void setAabb(btBroadphaseProxy *proxy, const btVector3 &aabbMin, const btVector3 &aabbMax, btDispatcher *dispatcher)=0
#define btAlignedAlloc(size, alignment)
virtual void calculateOverlappingPairs(btDispatcher *dispatcher)
calculateOverlappingPairs is optional: incremental algorithms (sweep and prune) might do it during th...
virtual void getAabb(btBroadphaseProxy *proxy, btVector3 &aabbMin, btVector3 &aabbMax) const
DBVT_INLINE const btVector3 & Mins() const
The btDispatcher interface class can be used in combination with broadphase to dispatch calculations ...
const T & btMin(const T &a, const T &b)
DBVT_PREFIX void collideTV(const btDbvtNode *root, const btDbvtVolume &volume, DBVT_IPOLICY) const
BroadphaseAabbTester(btBroadphaseAabbCallback &orgCallback)
virtual void destroyProxy(btBroadphaseProxy *proxy, btDispatcher *dispatcher)=0
Hash-space based Pair Cache, thanks to Erin Catto, Box2D, http://www.box2d.org, and Pierre Terdiman...
void remove(btDbvtNode *leaf)
virtual void calculateOverlappingPairs(btDispatcher *dispatcher)=0
calculateOverlappingPairs is optional: incremental algorithms (sweep and prune) might do it during th...
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
void quickSort(const L &CompareFunc)
virtual void * removeOverlappingPair(btBroadphaseProxy *proxy0, btBroadphaseProxy *proxy1, btDispatcher *dispatcher)=0
btScalar btCos(btScalar x)
static btDbvtVolume bounds(const tNodeArray &leaves)
DBVT_INLINE bool NotEqual(const btDbvtAabbMm &a, const btDbvtAabbMm &b)
void Process(const btDbvtNode *leaf)
The btBroadphasePair class contains a pair of aabb-overlapping objects.