fixed broadphases after performance optimizations

This commit is contained in:
ejcoumans
2006-09-19 06:08:54 +00:00
parent d78d0b3055
commit d375a474b3
5 changed files with 85 additions and 68 deletions

View File

@@ -388,12 +388,9 @@ void AxisSweep3::SortMinUp(int axis, unsigned short edge, bool updateOverlaps)
{
Handle* handle0 = GetHandle(pEdge->m_handle);
Handle* handle1 = GetHandle(pNext->m_handle);
BroadphasePair* pair = FindPair(handle0,handle1);
//assert(pair);
if (pair)
{
RemoveOverlappingPair(*pair);
}
BroadphasePair tmpPair(*handle0,*handle1);
RemoveOverlappingPair(tmpPair);
}
// update edge reference in other handle

View File

@@ -40,8 +40,12 @@ void OverlappingPairCache::RemoveOverlappingPair(BroadphasePair& pair)
{
CleanOverlappingPair(pair);
std::set<BroadphasePair>::iterator it = m_overlappingPairSet.find(pair);
assert(it != m_overlappingPairSet.end());
m_overlappingPairSet.erase(pair);
// assert(it != m_overlappingPairSet.end());
if (it != m_overlappingPairSet.end())
{
m_overlappingPairSet.erase(it);
}
}
@@ -76,21 +80,6 @@ void OverlappingPairCache::AddOverlappingPair(BroadphaseProxy* proxy0,Broadphase
m_overlappingPairSet.insert(pair);
#ifdef _DEBUG
/*
BroadphasePair& pr = (*newElem);
int i;
for (i=0;i<SIMPLE_MAX_ALGORITHMS;i++)
{
assert(!m_OverlappingPairs[m_NumOverlapBroadphasePair].m_algorithms[i]);
//m_OverlappingPairs[m_NumOverlapBroadphasePair].m_algorithms[i] = 0;
}
*/
#endif _DEBUG
}
///this FindPair becomes really slow. Either sort the list to speedup the query, or
@@ -114,41 +103,66 @@ void OverlappingPairCache::AddOverlappingPair(BroadphaseProxy* proxy0,Broadphase
void OverlappingPairCache::CleanProxyFromPairs(BroadphaseProxy* proxy)
{
assert(0);
/*
for (int i=0;i<m_NumOverlapBroadphasePair;i++)
class CleanPairCallback : public OverlapCallback
{
BroadphasePair& pair = m_OverlappingPairs[i];
if (pair.m_pProxy0 == proxy ||
pair.m_pProxy1 == proxy)
BroadphaseProxy* m_cleanProxy;
OverlappingPairCache* m_pairCache;
public:
CleanPairCallback(BroadphaseProxy* cleanProxy,OverlappingPairCache* pairCache)
:m_cleanProxy(cleanProxy),
m_pairCache(pairCache)
{
CleanOverlappingPair(pair);
}
}
*/
virtual bool ProcessOverlap(BroadphasePair& pair)
{
if ((pair.m_pProxy0 == m_cleanProxy) ||
(pair.m_pProxy1 == m_cleanProxy))
{
m_pairCache->CleanOverlappingPair(pair);
}
return false;
}
};
CleanPairCallback cleanPairs(proxy,this);
ProcessAllOverlappingPairs(&cleanPairs);
}
void OverlappingPairCache::RemoveOverlappingPairsContainingProxy(BroadphaseProxy* proxy)
{
assert(0);
/*
int i;
for ( i=m_NumOverlapBroadphasePair-1;i>=0;i--)
class RemovePairCallback : public OverlapCallback
{
BroadphasePair& pair = m_OverlappingPairs[i];
if (pair.m_pProxy0 == proxy ||
pair.m_pProxy1 == proxy)
{
RemoveOverlappingPair(pair);
}
}
*/
BroadphaseProxy* m_obsoleteProxy;
public:
RemovePairCallback(BroadphaseProxy* obsoleteProxy)
:m_obsoleteProxy(obsoleteProxy)
{
}
virtual bool ProcessOverlap(BroadphasePair& pair)
{
return ((pair.m_pProxy0 == m_obsoleteProxy) ||
(pair.m_pProxy1 == m_obsoleteProxy));
}
};
RemovePairCallback removeCallback(proxy);
ProcessAllOverlappingPairs(&removeCallback);
}
@@ -156,14 +170,16 @@ void OverlappingPairCache::RemoveOverlappingPairsContainingProxy(BroadphaseProxy
void OverlappingPairCache::ProcessAllOverlappingPairs(OverlapCallback* callback)
{
std::set<BroadphasePair>::iterator it = m_overlappingPairSet.begin();
for (; !(it==m_overlappingPairSet.end());it++)
for (; !(it==m_overlappingPairSet.end());)
{
BroadphasePair* pair = (BroadphasePair*)(&(*it));
if (callback->ProcessOverlap(*pair))
{
assert(0);
m_overlappingPairSet.erase(it);
it = m_overlappingPairSet.erase(it);
} else
{
it++;
}
}
}

View File

@@ -184,6 +184,19 @@ bool SimpleBroadphase::AabbOverlap(SimpleBroadphaseProxy* proxy0,SimpleBroadphas
proxy0->m_min[2] <= proxy1->m_max[2] && proxy1->m_min[2] <= proxy0->m_max[2];
}
//then remove non-overlapping ones
class CheckOverlapCallback : public OverlapCallback
{
public:
virtual bool ProcessOverlap(BroadphasePair& pair)
{
return (!SimpleBroadphase::AabbOverlap(static_cast<SimpleBroadphaseProxy*>(pair.m_pProxy0),static_cast<SimpleBroadphaseProxy*>(pair.m_pProxy1)));
}
};
void SimpleBroadphase::RefreshOverlappingPairs()
{
//first check for new overlapping pairs
@@ -209,22 +222,10 @@ void SimpleBroadphase::RefreshOverlappingPairs()
}
}
assert(0);
/*
//then remove non-overlapping ones
for (i=0;i<GetNumOverlappingPairs();i++)
{
BroadphasePair& pair = GetOverlappingPair(i);
SimpleBroadphaseProxy* proxy0 = GetSimpleProxyFromProxy(pair.m_pProxy0);
SimpleBroadphaseProxy* proxy1 = GetSimpleProxyFromProxy(pair.m_pProxy1);
if (!AabbOverlap(proxy0,proxy1))
{
RemoveOverlappingPair(pair);
}
}
CheckOverlapCallback checkOverlap;
*/
ProcessAllOverlappingPairs(&checkOverlap);
}

View File

@@ -58,7 +58,6 @@ class SimpleBroadphase : public OverlappingPairCache
return proxy0;
}
bool AabbOverlap(SimpleBroadphaseProxy* proxy0,SimpleBroadphaseProxy* proxy1);
void validate();
@@ -71,6 +70,9 @@ public:
virtual ~SimpleBroadphase();
static bool AabbOverlap(SimpleBroadphaseProxy* proxy0,SimpleBroadphaseProxy* proxy1);
virtual BroadphaseProxy* CreateProxy( const SimdVector3& min, const SimdVector3& max,int shapeType,void* userPtr ,short int collisionFilterGroup,short int collisionFilterMask);

View File

@@ -76,9 +76,9 @@ bool useCompound = false;//true;//false;
#ifdef _DEBUG
const int numObjects = 250;
const int numObjects = 120;
#else
const int numObjects = 250;
const int numObjects = 120;//try this in release mode: 3000. never go above 4095, unless you increate maxNumObjects value in DemoApplication.cp
#endif
const int maxNumObjects = 32760;
@@ -251,13 +251,14 @@ void CcdPhysicsDemo::initPhysics()
CollisionDispatcher* dispatcher = new CollisionDispatcher();
ParallelIslandDispatcher* dispatcher2 = new ParallelIslandDispatcher();
SimdVector3 worldAabbMin(-30000,-30000,-30000);
SimdVector3 worldAabbMax(30000,30000,30000);
SimdVector3 worldAabbMin(-10000,-10000,-10000);
SimdVector3 worldAabbMax(10000,10000,10000);
OverlappingPairCache* broadphase = new AxisSweep3(worldAabbMin,worldAabbMax,maxProxies,maxOverlap);
// OverlappingPairCache* broadphase = new SimpleBroadphase;
dispatcher->RegisterCollisionCreateFunc(SPHERE_SHAPE_PROXYTYPE,SPHERE_SHAPE_PROXYTYPE,new SphereSphereCollisionAlgorithm::CreateFunc);
//OverlappingPairCache* broadphase = new SimpleBroadphase(maxProxies,maxOverlap);
#ifdef USE_PARALLEL_DISPATCHER
m_physicsEnvironmentPtr = new ParallelPhysicsEnvironment(dispatcher2,broadphase);