some pair management changes, allow to choose pair cache at run-time.

This commit is contained in:
erwin.coumans
2008-03-13 23:57:07 +00:00
parent fde2551637
commit 06a9b3dfc9
6 changed files with 150 additions and 46 deletions

View File

@@ -20,13 +20,13 @@ subject to the following restrictions:
#include "btBroadphaseInterface.h"
#include "btBroadphaseProxy.h"
#include "btOverlappingPairCallback.h"
#include "LinearMath/btPoint3.h"
#include "LinearMath/btAlignedObjectArray.h"
class btDispatcher;
///disable the USE_HASH_PAIRCACHE define to use a pair manager that sorts the pairs to find duplicates/non-overlap
#define USE_HASH_PAIRCACHE 1
typedef btAlignedObjectArray<btBroadphasePair> btBroadphasePairArray;
struct btOverlapCallback
{
@@ -34,6 +34,7 @@ struct btOverlapCallback
{}
//return true for deletion of the pair
virtual bool processOverlap(btBroadphasePair& pair) = 0;
};
struct btOverlapFilterCallback
@@ -44,9 +45,9 @@ struct btOverlapFilterCallback
virtual bool needBroadphaseCollision(btBroadphaseProxy* proxy0,btBroadphaseProxy* proxy1) const = 0;
};
typedef btAlignedObjectArray<btBroadphasePair> btBroadphasePairArray;
#ifdef USE_HASH_PAIRCACHE
/// Hash-space based Pair Cache, thanks to Erin Catto, Box2D, http://www.box2d.org, and Pierre Terdiman, Codercorner, http://codercorner.com
@@ -57,7 +58,31 @@ extern int gFindPairs;
const int BT_NULL_PAIR=0xffffffff;
class btOverlappingPairCache
class btOverlappingPairCache : public btOverlappingPairCallback
{
public:
virtual btBroadphasePair* getOverlappingPairArrayPtr() = 0;
virtual const btBroadphasePair* getOverlappingPairArrayPtr() const = 0;
virtual btBroadphasePairArray& getOverlappingPairArray() = 0;
virtual void cleanOverlappingPair(btBroadphasePair& pair,btDispatcher* dispatcher) = 0;
virtual int getNumOverlappingPairs() const = 0;
virtual void cleanProxyFromPairs(btBroadphaseProxy* proxy,btDispatcher* dispatcher) = 0;
virtual void setOverlapFilterCallback(btOverlapFilterCallback* callback) = 0;
virtual void processAllOverlappingPairs(btOverlapCallback*,btDispatcher* dispatcher) = 0;
virtual btBroadphasePair* findPair(btBroadphaseProxy* proxy0, btBroadphaseProxy* proxy1) = 0;
};
class btHashedOverlappingPairCache : public btOverlappingPairCache
{
btBroadphasePairArray m_overlappingPairArray;
btOverlapFilterCallback* m_overlapFilterCallback;
@@ -65,13 +90,13 @@ class btOverlappingPairCache
public:
btOverlappingPairCache();
virtual ~btOverlappingPairCache();
btHashedOverlappingPairCache();
virtual ~btHashedOverlappingPairCache();
void removeOverlappingPairsContainingProxy(btBroadphaseProxy* proxy,btDispatcher* dispatcher);
void* removeOverlappingPair(btBroadphaseProxy* proxy0,btBroadphaseProxy* proxy1,btDispatcher* dispatcher);
virtual void* removeOverlappingPair(btBroadphaseProxy* proxy0,btBroadphaseProxy* proxy1,btDispatcher* dispatcher);
SIMD_FORCE_INLINE bool needsBroadphaseCollision(btBroadphaseProxy* proxy0,btBroadphaseProxy* proxy1) const
{
@@ -86,7 +111,7 @@ public:
// Add a pair and return the new pair. If the pair already exists,
// no new pair is created and the old one is returned.
SIMD_FORCE_INLINE btBroadphasePair* addOverlappingPair(btBroadphaseProxy* proxy0,btBroadphaseProxy* proxy1)
virtual btBroadphasePair* addOverlappingPair(btBroadphaseProxy* proxy0,btBroadphaseProxy* proxy1)
{
gAddedPairs++;
@@ -103,7 +128,7 @@ public:
virtual void processAllOverlappingPairs(btOverlapCallback*,btDispatcher* dispatcher);
btBroadphasePair* getOverlappingPairArrayPtr()
virtual btBroadphasePair* getOverlappingPairArrayPtr()
{
return &m_overlappingPairArray[0];
}
@@ -227,13 +252,13 @@ public:
#else//USE_HASH_PAIRCACHE
#define USE_LAZY_REMOVAL 1
///btOverlappingPairCache maintains the objects with overlapping AABB
///Typically managed by the Broadphase, Axis3Sweep or btSimpleBroadphase
class btOverlappingPairCache
class btSortedOverlappingPairCache : public btOverlappingPairCache
{
protected:
//avoid brute-force finding all the time
@@ -247,8 +272,8 @@ class btOverlappingPairCache
public:
btOverlappingPairCache();
virtual ~btOverlappingPairCache();
btSortedOverlappingPairCache();
virtual ~btSortedOverlappingPairCache();
virtual void processAllOverlappingPairs(btOverlapCallback*,btDispatcher* dispatcher);
@@ -316,7 +341,6 @@ class btOverlappingPairCache
}
};
#endif //USE_HASH_PAIRCACHE
#endif //OVERLAPPING_PAIR_CACHE_H