Refactoring for parallel processing of islands, collision detection and constraint solving.
This commit is contained in:
@@ -33,7 +33,7 @@ public:
|
||||
virtual void DestroyProxy(BroadphaseProxy* proxy)=0;
|
||||
virtual void SetAabb(BroadphaseProxy* proxy,const SimdVector3& aabbMin,const SimdVector3& aabbMax)=0;
|
||||
virtual void CleanProxyFromPairs(BroadphaseProxy* proxy)=0;
|
||||
virtual void DispatchAllCollisionPairs(Dispatcher& dispatcher,DispatcherInfo& dispatchInfo)=0;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -147,67 +147,4 @@ void OverlappingPairCache::RemoveOverlappingPairsContainingProxy(BroadphaseProxy
|
||||
}
|
||||
|
||||
|
||||
void OverlappingPairCache::DispatchAllCollisionPairs(Dispatcher& dispatcher,DispatcherInfo& dispatchInfo)
|
||||
{
|
||||
m_blockedForChanges = true;
|
||||
|
||||
int i;
|
||||
|
||||
int dispatcherId = dispatcher.GetUniqueId();
|
||||
|
||||
RefreshOverlappingPairs();
|
||||
|
||||
for (i=0;i<m_NumOverlapBroadphasePair;i++)
|
||||
{
|
||||
|
||||
BroadphasePair& pair = m_OverlappingPairs[i];
|
||||
|
||||
if (dispatcherId>= 0)
|
||||
{
|
||||
//dispatcher will keep algorithms persistent in the collision pair
|
||||
if (!pair.m_algorithms[dispatcherId])
|
||||
{
|
||||
pair.m_algorithms[dispatcherId] = dispatcher.FindAlgorithm(
|
||||
*pair.m_pProxy0,
|
||||
*pair.m_pProxy1);
|
||||
}
|
||||
|
||||
if (pair.m_algorithms[dispatcherId])
|
||||
{
|
||||
if (dispatchInfo.m_dispatchFunc == DispatcherInfo::DISPATCH_DISCRETE)
|
||||
{
|
||||
pair.m_algorithms[dispatcherId]->ProcessCollision(pair.m_pProxy0,pair.m_pProxy1,dispatchInfo);
|
||||
} else
|
||||
{
|
||||
float toi = pair.m_algorithms[dispatcherId]->CalculateTimeOfImpact(pair.m_pProxy0,pair.m_pProxy1,dispatchInfo);
|
||||
if (dispatchInfo.m_timeOfImpact > toi)
|
||||
dispatchInfo.m_timeOfImpact = toi;
|
||||
|
||||
}
|
||||
}
|
||||
} else
|
||||
{
|
||||
//non-persistent algorithm dispatcher
|
||||
CollisionAlgorithm* algo = dispatcher.FindAlgorithm(
|
||||
*pair.m_pProxy0,
|
||||
*pair.m_pProxy1);
|
||||
|
||||
if (algo)
|
||||
{
|
||||
if (dispatchInfo.m_dispatchFunc == DispatcherInfo::DISPATCH_DISCRETE)
|
||||
{
|
||||
algo->ProcessCollision(pair.m_pProxy0,pair.m_pProxy1,dispatchInfo);
|
||||
} else
|
||||
{
|
||||
float toi = algo->CalculateTimeOfImpact(pair.m_pProxy0,pair.m_pProxy1,dispatchInfo);
|
||||
if (dispatchInfo.m_timeOfImpact > toi)
|
||||
dispatchInfo.m_timeOfImpact = toi;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
m_blockedForChanges = false;
|
||||
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ class OverlappingPairCache : public BroadphaseInterface
|
||||
return collides;
|
||||
}
|
||||
|
||||
void DispatchAllCollisionPairs(Dispatcher& dispatcher,DispatcherInfo& dispatchInfo);
|
||||
|
||||
|
||||
virtual void RefreshOverlappingPairs() =0;
|
||||
|
||||
|
||||
42
Bullet/CollisionDispatch/CollisionCreateFunc.h
Normal file
42
Bullet/CollisionDispatch/CollisionCreateFunc.h
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef COLLISION_CREATE_FUNC
|
||||
#define COLLISION_CREATE_FUNC
|
||||
|
||||
#include <vector>
|
||||
|
||||
typedef std::vector<struct CollisionObject*> CollisionObjectArray;
|
||||
class CollisionAlgorithm;
|
||||
struct BroadphaseProxy;
|
||||
|
||||
|
||||
|
||||
struct CollisionAlgorithmCreateFunc
|
||||
{
|
||||
bool m_swapped;
|
||||
|
||||
CollisionAlgorithmCreateFunc()
|
||||
:m_swapped(false)
|
||||
{
|
||||
}
|
||||
virtual ~CollisionAlgorithmCreateFunc(){};
|
||||
|
||||
virtual CollisionAlgorithm* CreateCollisionAlgorithm(BroadphaseProxy& proxy0,BroadphaseProxy& proxy1)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
#endif //COLLISION_CREATE_FUNC
|
||||
@@ -24,6 +24,7 @@ subject to the following restrictions:
|
||||
#include "CollisionShapes/CollisionShape.h"
|
||||
#include "CollisionDispatch/CollisionObject.h"
|
||||
#include <algorithm>
|
||||
#include "BroadphaseCollision/OverlappingPairCache.h"
|
||||
|
||||
int gNumManifold = 0;
|
||||
|
||||
@@ -293,3 +294,69 @@ void CollisionDispatcher::ReleaseManifoldResult(ManifoldResult*)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void CollisionDispatcher::DispatchAllCollisionPairs(OverlappingPairCache* pairCache,DispatcherInfo& dispatchInfo)
|
||||
{
|
||||
//m_blockedForChanges = true;
|
||||
|
||||
int i;
|
||||
|
||||
int dispatcherId = GetUniqueId();
|
||||
|
||||
pairCache->RefreshOverlappingPairs();
|
||||
|
||||
for (i=0;i<pairCache->GetNumOverlappingPairs();i++)
|
||||
{
|
||||
|
||||
BroadphasePair& pair = pairCache->GetOverlappingPair(i);
|
||||
|
||||
if (dispatcherId>= 0)
|
||||
{
|
||||
//dispatcher will keep algorithms persistent in the collision pair
|
||||
if (!pair.m_algorithms[dispatcherId])
|
||||
{
|
||||
pair.m_algorithms[dispatcherId] = FindAlgorithm(
|
||||
*pair.m_pProxy0,
|
||||
*pair.m_pProxy1);
|
||||
}
|
||||
|
||||
if (pair.m_algorithms[dispatcherId])
|
||||
{
|
||||
if (dispatchInfo.m_dispatchFunc == DispatcherInfo::DISPATCH_DISCRETE)
|
||||
{
|
||||
pair.m_algorithms[dispatcherId]->ProcessCollision(pair.m_pProxy0,pair.m_pProxy1,dispatchInfo);
|
||||
} else
|
||||
{
|
||||
float toi = pair.m_algorithms[dispatcherId]->CalculateTimeOfImpact(pair.m_pProxy0,pair.m_pProxy1,dispatchInfo);
|
||||
if (dispatchInfo.m_timeOfImpact > toi)
|
||||
dispatchInfo.m_timeOfImpact = toi;
|
||||
|
||||
}
|
||||
}
|
||||
} else
|
||||
{
|
||||
//non-persistent algorithm dispatcher
|
||||
CollisionAlgorithm* algo = FindAlgorithm(
|
||||
*pair.m_pProxy0,
|
||||
*pair.m_pProxy1);
|
||||
|
||||
if (algo)
|
||||
{
|
||||
if (dispatchInfo.m_dispatchFunc == DispatcherInfo::DISPATCH_DISCRETE)
|
||||
{
|
||||
algo->ProcessCollision(pair.m_pProxy0,pair.m_pProxy1,dispatchInfo);
|
||||
} else
|
||||
{
|
||||
float toi = algo->CalculateTimeOfImpact(pair.m_pProxy0,pair.m_pProxy1,dispatchInfo);
|
||||
if (dispatchInfo.m_timeOfImpact > toi)
|
||||
dispatchInfo.m_timeOfImpact = toi;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//m_blockedForChanges = false;
|
||||
|
||||
}
|
||||
@@ -22,28 +22,15 @@ subject to the following restrictions:
|
||||
#include "CollisionDispatch/ManifoldResult.h"
|
||||
|
||||
#include "BroadphaseCollision/BroadphaseProxy.h"
|
||||
#include <vector>
|
||||
|
||||
|
||||
class IDebugDraw;
|
||||
|
||||
typedef std::vector<struct CollisionObject*> CollisionObjectArray;
|
||||
class OverlappingPairCache;
|
||||
|
||||
|
||||
struct CollisionAlgorithmCreateFunc
|
||||
{
|
||||
bool m_swapped;
|
||||
|
||||
CollisionAlgorithmCreateFunc()
|
||||
:m_swapped(false)
|
||||
{
|
||||
}
|
||||
virtual ~CollisionAlgorithmCreateFunc(){};
|
||||
#include "CollisionCreateFunc.h"
|
||||
|
||||
|
||||
virtual CollisionAlgorithm* CreateCollisionAlgorithm(BroadphaseProxy& proxy0,BroadphaseProxy& proxy1)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
///CollisionDispatcher supports algorithms that handle ConvexConvex and ConvexConcave collision pairs.
|
||||
@@ -131,7 +118,7 @@ public:
|
||||
|
||||
virtual int GetUniqueId() { return RIGIDBODY_DISPATCHER;}
|
||||
|
||||
|
||||
virtual void DispatchAllCollisionPairs(OverlappingPairCache* pairCache,DispatcherInfo& dispatchInfo);
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -150,10 +150,13 @@ void CollisionWorld::PerformDiscreteCollisionDetection()
|
||||
for (size_t i=0;i<m_collisionObjects.size();i++)
|
||||
{
|
||||
m_collisionObjects[i]->m_collisionShape->GetAabb(m_collisionObjects[i]->m_worldTransform,aabbMin,aabbMax);
|
||||
m_broadphase->SetAabb(m_collisionObjects[i]->m_broadphaseHandle,aabbMin,aabbMax);
|
||||
m_pairCache->SetAabb(m_collisionObjects[i]->m_broadphaseHandle,aabbMin,aabbMax);
|
||||
}
|
||||
|
||||
m_broadphase->DispatchAllCollisionPairs(*GetDispatcher(),dispatchInfo);
|
||||
CollisionDispatcher* dispatcher = GetDispatcher();
|
||||
if (dispatcher)
|
||||
dispatcher->DispatchAllCollisionPairs(m_pairCache,dispatchInfo);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -70,6 +70,7 @@ class BroadphaseInterface;
|
||||
#include "SimdTransform.h"
|
||||
#include "CollisionObject.h"
|
||||
#include "CollisionDispatcher.h" //for definition of CollisionObjectArray
|
||||
#include "BroadphaseCollision/OverlappingPairCache.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
@@ -85,13 +86,14 @@ class CollisionWorld
|
||||
|
||||
CollisionDispatcher* m_dispatcher;
|
||||
|
||||
BroadphaseInterface* m_broadphase;
|
||||
OverlappingPairCache* m_pairCache;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
CollisionWorld(CollisionDispatcher* dispatcher,BroadphaseInterface* broadphase)
|
||||
CollisionWorld(CollisionDispatcher* dispatcher,OverlappingPairCache* pairCache)
|
||||
:m_dispatcher(dispatcher),
|
||||
m_broadphase(broadphase)
|
||||
m_pairCache(pairCache)
|
||||
{
|
||||
|
||||
}
|
||||
@@ -102,9 +104,15 @@ public:
|
||||
|
||||
BroadphaseInterface* GetBroadphase()
|
||||
{
|
||||
return m_broadphase;
|
||||
return m_pairCache;
|
||||
}
|
||||
|
||||
OverlappingPairCache* GetPairCache()
|
||||
{
|
||||
return m_pairCache;
|
||||
}
|
||||
|
||||
|
||||
CollisionDispatcher* GetDispatcher()
|
||||
{
|
||||
return m_dispatcher;
|
||||
|
||||
@@ -21,6 +21,10 @@ subject to the following restrictions:
|
||||
struct CollisionObject;
|
||||
class PersistentManifold;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
///ManifoldResult is a helper class to manage contact results.
|
||||
class ManifoldResult : public DiscreteCollisionDetectorInterface::Result
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user