fixed broadphases after performance optimizations
This commit is contained in:
@@ -388,12 +388,9 @@ void AxisSweep3::SortMinUp(int axis, unsigned short edge, bool updateOverlaps)
|
|||||||
{
|
{
|
||||||
Handle* handle0 = GetHandle(pEdge->m_handle);
|
Handle* handle0 = GetHandle(pEdge->m_handle);
|
||||||
Handle* handle1 = GetHandle(pNext->m_handle);
|
Handle* handle1 = GetHandle(pNext->m_handle);
|
||||||
BroadphasePair* pair = FindPair(handle0,handle1);
|
BroadphasePair tmpPair(*handle0,*handle1);
|
||||||
//assert(pair);
|
RemoveOverlappingPair(tmpPair);
|
||||||
if (pair)
|
|
||||||
{
|
|
||||||
RemoveOverlappingPair(*pair);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// update edge reference in other handle
|
// update edge reference in other handle
|
||||||
|
|||||||
@@ -40,8 +40,12 @@ void OverlappingPairCache::RemoveOverlappingPair(BroadphasePair& pair)
|
|||||||
{
|
{
|
||||||
CleanOverlappingPair(pair);
|
CleanOverlappingPair(pair);
|
||||||
std::set<BroadphasePair>::iterator it = m_overlappingPairSet.find(pair);
|
std::set<BroadphasePair>::iterator it = m_overlappingPairSet.find(pair);
|
||||||
assert(it != m_overlappingPairSet.end());
|
// assert(it != m_overlappingPairSet.end());
|
||||||
m_overlappingPairSet.erase(pair);
|
|
||||||
|
if (it != m_overlappingPairSet.end())
|
||||||
|
{
|
||||||
|
m_overlappingPairSet.erase(it);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -76,21 +80,6 @@ void OverlappingPairCache::AddOverlappingPair(BroadphaseProxy* proxy0,Broadphase
|
|||||||
|
|
||||||
m_overlappingPairSet.insert(pair);
|
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
|
///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)
|
void OverlappingPairCache::CleanProxyFromPairs(BroadphaseProxy* proxy)
|
||||||
{
|
{
|
||||||
assert(0);
|
|
||||||
/*
|
class CleanPairCallback : public OverlapCallback
|
||||||
for (int i=0;i<m_NumOverlapBroadphasePair;i++)
|
|
||||||
{
|
{
|
||||||
BroadphasePair& pair = m_OverlappingPairs[i];
|
BroadphaseProxy* m_cleanProxy;
|
||||||
if (pair.m_pProxy0 == proxy ||
|
OverlappingPairCache* m_pairCache;
|
||||||
pair.m_pProxy1 == proxy)
|
|
||||||
|
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)
|
void OverlappingPairCache::RemoveOverlappingPairsContainingProxy(BroadphaseProxy* proxy)
|
||||||
{
|
{
|
||||||
|
|
||||||
assert(0);
|
class RemovePairCallback : public OverlapCallback
|
||||||
/*
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for ( i=m_NumOverlapBroadphasePair-1;i>=0;i--)
|
|
||||||
{
|
{
|
||||||
BroadphasePair& pair = m_OverlappingPairs[i];
|
BroadphaseProxy* m_obsoleteProxy;
|
||||||
if (pair.m_pProxy0 == proxy ||
|
|
||||||
pair.m_pProxy1 == proxy)
|
|
||||||
{
|
|
||||||
RemoveOverlappingPair(pair);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
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)
|
void OverlappingPairCache::ProcessAllOverlappingPairs(OverlapCallback* callback)
|
||||||
{
|
{
|
||||||
std::set<BroadphasePair>::iterator it = m_overlappingPairSet.begin();
|
std::set<BroadphasePair>::iterator it = m_overlappingPairSet.begin();
|
||||||
for (; !(it==m_overlappingPairSet.end());it++)
|
for (; !(it==m_overlappingPairSet.end());)
|
||||||
{
|
{
|
||||||
|
|
||||||
BroadphasePair* pair = (BroadphasePair*)(&(*it));
|
BroadphasePair* pair = (BroadphasePair*)(&(*it));
|
||||||
if (callback->ProcessOverlap(*pair))
|
if (callback->ProcessOverlap(*pair))
|
||||||
{
|
{
|
||||||
assert(0);
|
it = m_overlappingPairSet.erase(it);
|
||||||
m_overlappingPairSet.erase(it);
|
} else
|
||||||
|
{
|
||||||
|
it++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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];
|
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()
|
void SimpleBroadphase::RefreshOverlappingPairs()
|
||||||
{
|
{
|
||||||
//first check for new overlapping pairs
|
//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);
|
CheckOverlapCallback checkOverlap;
|
||||||
SimpleBroadphaseProxy* proxy1 = GetSimpleProxyFromProxy(pair.m_pProxy1);
|
|
||||||
if (!AabbOverlap(proxy0,proxy1))
|
|
||||||
{
|
|
||||||
RemoveOverlappingPair(pair);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
*/
|
ProcessAllOverlappingPairs(&checkOverlap);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,7 +58,6 @@ class SimpleBroadphase : public OverlappingPairCache
|
|||||||
return proxy0;
|
return proxy0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AabbOverlap(SimpleBroadphaseProxy* proxy0,SimpleBroadphaseProxy* proxy1);
|
|
||||||
|
|
||||||
void validate();
|
void validate();
|
||||||
|
|
||||||
@@ -71,6 +70,9 @@ public:
|
|||||||
virtual ~SimpleBroadphase();
|
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);
|
virtual BroadphaseProxy* CreateProxy( const SimdVector3& min, const SimdVector3& max,int shapeType,void* userPtr ,short int collisionFilterGroup,short int collisionFilterMask);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -76,9 +76,9 @@ bool useCompound = false;//true;//false;
|
|||||||
|
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
const int numObjects = 250;
|
const int numObjects = 120;
|
||||||
#else
|
#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
|
#endif
|
||||||
|
|
||||||
const int maxNumObjects = 32760;
|
const int maxNumObjects = 32760;
|
||||||
@@ -251,13 +251,14 @@ void CcdPhysicsDemo::initPhysics()
|
|||||||
CollisionDispatcher* dispatcher = new CollisionDispatcher();
|
CollisionDispatcher* dispatcher = new CollisionDispatcher();
|
||||||
ParallelIslandDispatcher* dispatcher2 = new ParallelIslandDispatcher();
|
ParallelIslandDispatcher* dispatcher2 = new ParallelIslandDispatcher();
|
||||||
|
|
||||||
SimdVector3 worldAabbMin(-30000,-30000,-30000);
|
SimdVector3 worldAabbMin(-10000,-10000,-10000);
|
||||||
SimdVector3 worldAabbMax(30000,30000,30000);
|
SimdVector3 worldAabbMax(10000,10000,10000);
|
||||||
|
|
||||||
OverlappingPairCache* broadphase = new AxisSweep3(worldAabbMin,worldAabbMax,maxProxies,maxOverlap);
|
OverlappingPairCache* broadphase = new AxisSweep3(worldAabbMin,worldAabbMax,maxProxies,maxOverlap);
|
||||||
|
// OverlappingPairCache* broadphase = new SimpleBroadphase;
|
||||||
|
|
||||||
dispatcher->RegisterCollisionCreateFunc(SPHERE_SHAPE_PROXYTYPE,SPHERE_SHAPE_PROXYTYPE,new SphereSphereCollisionAlgorithm::CreateFunc);
|
dispatcher->RegisterCollisionCreateFunc(SPHERE_SHAPE_PROXYTYPE,SPHERE_SHAPE_PROXYTYPE,new SphereSphereCollisionAlgorithm::CreateFunc);
|
||||||
|
|
||||||
//OverlappingPairCache* broadphase = new SimpleBroadphase(maxProxies,maxOverlap);
|
|
||||||
|
|
||||||
#ifdef USE_PARALLEL_DISPATCHER
|
#ifdef USE_PARALLEL_DISPATCHER
|
||||||
m_physicsEnvironmentPtr = new ParallelPhysicsEnvironment(dispatcher2,broadphase);
|
m_physicsEnvironmentPtr = new ParallelPhysicsEnvironment(dispatcher2,broadphase);
|
||||||
|
|||||||
Reference in New Issue
Block a user