fairly large refactoring of dispatcher/simulation island management, to allow for parallel simulation.
This commit is contained in:
@@ -30,8 +30,7 @@ subject to the following restrictions:
|
||||
|
||||
#include "CollisionShapes/ConvexShape.h"
|
||||
#include "CollisionShapes/ConeShape.h"
|
||||
|
||||
|
||||
#include "CollisionDispatch/SimulationIslandManager.h"
|
||||
|
||||
#include "BroadphaseCollision/Dispatcher.h"
|
||||
#include "NarrowPhaseCollision/PersistentManifold.h"
|
||||
@@ -55,7 +54,7 @@ subject to the following restrictions:
|
||||
#include "PHY_IMotionState.h"
|
||||
|
||||
#include "CollisionDispatch/EmptyCollisionAlgorithm.h"
|
||||
#include "CollisionDispatch/UnionFind.h"
|
||||
|
||||
|
||||
|
||||
#include "CollisionShapes/SphereShape.h"
|
||||
@@ -360,6 +359,8 @@ m_enableSatCollisionDetection(false)
|
||||
m_debugDrawer = 0;
|
||||
m_gravity = SimdVector3(0.f,-10.f,0.f);
|
||||
|
||||
m_islandManager = new SimulationIslandManager();
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -675,7 +676,7 @@ bool CcdPhysicsEnvironment::proceedDeltaTimeOneStep(float timeStep)
|
||||
dispatchInfo.m_stepCount = 0;
|
||||
dispatchInfo.m_enableSatConvex = m_enableSatCollisionDetection;
|
||||
|
||||
GetDispatcher()->DispatchAllCollisionPairs(scene,dispatchInfo);
|
||||
GetCollisionWorld()->GetDispatcher()->DispatchAllCollisionPairs(scene,dispatchInfo);
|
||||
|
||||
|
||||
#ifdef USE_QUICKPROF
|
||||
@@ -685,7 +686,8 @@ bool CcdPhysicsEnvironment::proceedDeltaTimeOneStep(float timeStep)
|
||||
|
||||
int numRigidBodies = m_controllers.size();
|
||||
|
||||
m_collisionWorld->UpdateActivationState();
|
||||
|
||||
m_islandManager->UpdateActivationState(GetCollisionWorld(),GetCollisionWorld()->GetDispatcher());
|
||||
|
||||
{
|
||||
int i;
|
||||
@@ -702,15 +704,15 @@ bool CcdPhysicsEnvironment::proceedDeltaTimeOneStep(float timeStep)
|
||||
{
|
||||
if (colObj0->IsActive() || colObj1->IsActive())
|
||||
{
|
||||
GetDispatcher()->GetUnionFind().unite((colObj0)->m_islandTag1,
|
||||
|
||||
m_islandManager->GetUnionFind().unite((colObj0)->m_islandTag1,
|
||||
(colObj1)->m_islandTag1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_collisionWorld->StoreIslandActivationState();
|
||||
|
||||
m_islandManager->StoreIslandActivationState(GetCollisionWorld());
|
||||
|
||||
|
||||
//contacts
|
||||
@@ -762,7 +764,7 @@ bool CcdPhysicsEnvironment::proceedDeltaTimeOneStep(float timeStep)
|
||||
#endif //NEW_BULLET_VEHICLE_SUPPORT
|
||||
|
||||
|
||||
struct InplaceSolverIslandCallback : public CollisionDispatcher::IslandCallback
|
||||
struct InplaceSolverIslandCallback : public SimulationIslandManager::IslandCallback
|
||||
{
|
||||
|
||||
ContactSolverInfo& m_solverInfo;
|
||||
@@ -803,7 +805,7 @@ bool CcdPhysicsEnvironment::proceedDeltaTimeOneStep(float timeStep)
|
||||
#endif //USE_QUICKPROF
|
||||
|
||||
/// solve all the contact points and contact friction
|
||||
GetDispatcher()->BuildAndProcessIslands(m_collisionWorld->GetCollisionObjectArray(),&solverCallback);
|
||||
m_islandManager->BuildAndProcessIslands(GetCollisionWorld()->GetDispatcher(),m_collisionWorld->GetCollisionObjectArray(),&solverCallback);
|
||||
|
||||
#ifdef USE_QUICKPROF
|
||||
Profiler::endBlock("BuildAndProcessIslands");
|
||||
@@ -842,7 +844,7 @@ bool CcdPhysicsEnvironment::proceedDeltaTimeOneStep(float timeStep)
|
||||
dispatchInfo.m_stepCount = 0;
|
||||
dispatchInfo.m_dispatchFunc = DispatcherInfo::DISPATCH_CONTINUOUS;
|
||||
|
||||
GetDispatcher()->DispatchAllCollisionPairs(scene,dispatchInfo);
|
||||
GetCollisionWorld()->GetDispatcher()->DispatchAllCollisionPairs(scene,dispatchInfo);
|
||||
|
||||
toi = dispatchInfo.m_timeOfImpact;
|
||||
|
||||
@@ -1426,15 +1428,6 @@ BroadphaseInterface* CcdPhysicsEnvironment::GetBroadphase()
|
||||
|
||||
|
||||
|
||||
const CollisionDispatcher* CcdPhysicsEnvironment::GetDispatcher() const
|
||||
{
|
||||
return m_collisionWorld->GetDispatcher();
|
||||
}
|
||||
|
||||
CollisionDispatcher* CcdPhysicsEnvironment::GetDispatcher()
|
||||
{
|
||||
return m_collisionWorld->GetDispatcher();
|
||||
}
|
||||
|
||||
CcdPhysicsEnvironment::~CcdPhysicsEnvironment()
|
||||
{
|
||||
@@ -1449,6 +1442,8 @@ CcdPhysicsEnvironment::~CcdPhysicsEnvironment()
|
||||
//first delete scene, then dispatcher, because pairs have to release manifolds on the dispatcher
|
||||
//delete m_dispatcher;
|
||||
delete m_collisionWorld;
|
||||
|
||||
delete m_islandManager;
|
||||
|
||||
}
|
||||
|
||||
@@ -1465,15 +1460,9 @@ CcdPhysicsController* CcdPhysicsEnvironment::GetPhysicsController( int index)
|
||||
}
|
||||
|
||||
|
||||
int CcdPhysicsEnvironment::GetNumManifolds() const
|
||||
{
|
||||
return GetDispatcher()->GetNumManifolds();
|
||||
}
|
||||
|
||||
const PersistentManifold* CcdPhysicsEnvironment::GetManifold(int index) const
|
||||
{
|
||||
return GetDispatcher()->GetManifoldByIndexInternal(index);
|
||||
}
|
||||
|
||||
|
||||
|
||||
TypedConstraint* CcdPhysicsEnvironment::getConstraintById(int constraintId)
|
||||
{
|
||||
@@ -1566,6 +1555,7 @@ void CcdPhysicsEnvironment::requestCollisionCallback(PHY_IPhysicsController* ctr
|
||||
|
||||
void CcdPhysicsEnvironment::CallbackTriggers()
|
||||
{
|
||||
/*
|
||||
CcdPhysicsController* ctrl0=0,*ctrl1=0;
|
||||
|
||||
if (m_triggerCallbacks[PHY_OBJECT_RESPONSE])
|
||||
@@ -1603,6 +1593,7 @@ void CcdPhysicsEnvironment::CallbackTriggers()
|
||||
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ class CcdPhysicsController;
|
||||
|
||||
|
||||
class TypedConstraint;
|
||||
|
||||
class SimulationIslandManager;
|
||||
class CollisionDispatcher;
|
||||
class Dispatcher;
|
||||
//#include "BroadphaseInterface.h"
|
||||
@@ -61,6 +61,7 @@ class CcdPhysicsEnvironment : public PHY_IPhysicsEnvironment
|
||||
|
||||
ContactSolverInfo m_solverInfo;
|
||||
|
||||
SimulationIslandManager* m_islandManager;
|
||||
|
||||
public:
|
||||
CcdPhysicsEnvironment(CollisionDispatcher* dispatcher=0, OverlappingPairCache* pairCache=0);
|
||||
@@ -160,9 +161,9 @@ class CcdPhysicsEnvironment : public PHY_IPhysicsEnvironment
|
||||
|
||||
BroadphaseInterface* GetBroadphase();
|
||||
|
||||
CollisionDispatcher* GetDispatcher();
|
||||
|
||||
const CollisionDispatcher* GetDispatcher() const;
|
||||
|
||||
|
||||
|
||||
bool IsSatCollisionDetectionEnabled() const
|
||||
{
|
||||
@@ -180,16 +181,29 @@ class CcdPhysicsEnvironment : public PHY_IPhysicsEnvironment
|
||||
|
||||
CcdPhysicsController* GetPhysicsController( int index);
|
||||
|
||||
int GetNumManifolds() const;
|
||||
|
||||
|
||||
const PersistentManifold* GetManifold(int index) const;
|
||||
|
||||
std::vector<TypedConstraint*> m_constraints;
|
||||
|
||||
void SyncMotionStates(float timeStep);
|
||||
|
||||
|
||||
class CollisionWorld* GetCollisionWorld()
|
||||
{
|
||||
return m_collisionWorld;
|
||||
}
|
||||
|
||||
const class CollisionWorld* GetCollisionWorld() const
|
||||
{
|
||||
return m_collisionWorld;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
|
||||
void SyncMotionStates(float timeStep);
|
||||
|
||||
|
||||
std::vector<CcdPhysicsController*> m_controllers;
|
||||
|
||||
|
||||
@@ -27,34 +27,7 @@ subject to the following restrictions:
|
||||
|
||||
static int gNumManifold2 = 0;
|
||||
|
||||
void ParallelIslandDispatcher::FindUnions()
|
||||
{
|
||||
if (m_useIslands)
|
||||
{
|
||||
for (int i=0;i<GetNumManifolds();i++)
|
||||
{
|
||||
const PersistentManifold* manifold = this->GetManifoldByIndexInternal(i);
|
||||
//static objects (invmass 0.f) don't merge !
|
||||
|
||||
const CollisionObject* colObj0 = static_cast<const CollisionObject*>(manifold->GetBody0());
|
||||
const CollisionObject* colObj1 = static_cast<const CollisionObject*>(manifold->GetBody1());
|
||||
|
||||
if (colObj0 && colObj1 && NeedsResponse(*colObj0,*colObj1))
|
||||
{
|
||||
if (((colObj0) && ((colObj0)->mergesSimulationIslands())) &&
|
||||
((colObj1) && ((colObj1)->mergesSimulationIslands())))
|
||||
{
|
||||
|
||||
m_unionFind.unite((colObj0)->m_islandTag1,
|
||||
(colObj1)->m_islandTag1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -293,3 +266,9 @@ void ParallelIslandDispatcher::ReleaseManifoldResult(ManifoldResult*)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ParallelIslandDispatcher::DispatchAllCollisionPairs(OverlappingPairCache* pairCache,DispatcherInfo& dispatchInfo)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -117,6 +117,9 @@ public:
|
||||
virtual bool NeedsResponse(const CollisionObject& colObj0,const CollisionObject& colObj1);
|
||||
|
||||
virtual int GetUniqueId() { return RIGIDBODY_DISPATCHER;}
|
||||
|
||||
virtual void DispatchAllCollisionPairs(OverlappingPairCache* pairCache,DispatcherInfo& dispatchInfo);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -18,6 +18,9 @@ subject to the following restrictions:
|
||||
#include "ParallelPhysicsEnvironment.h"
|
||||
#include "CcdPhysicsController.h"
|
||||
#include "ParallelIslandDispatcher.h"
|
||||
#include "CollisionDispatch/CollisionWorld.h"
|
||||
#include "ConstraintSolver/TypedConstraint.h"
|
||||
|
||||
|
||||
|
||||
ParallelPhysicsEnvironment::ParallelPhysicsEnvironment(ParallelIslandDispatcher* dispatcher, OverlappingPairCache* pairCache):
|
||||
@@ -37,6 +40,44 @@ ParallelPhysicsEnvironment::~ParallelPhysicsEnvironment()
|
||||
bool ParallelPhysicsEnvironment::proceedDeltaTimeOneStep(float timeStep)
|
||||
{
|
||||
|
||||
#ifdef USE_QUICKPROF
|
||||
Profiler::beginBlock("CalcSimulationIslands");
|
||||
#endif //USE_QUICKPROF
|
||||
|
||||
/*
|
||||
GetCollisionWorld()->UpdateActivationState();
|
||||
|
||||
{
|
||||
int i;
|
||||
int numConstraints = m_constraints.size();
|
||||
for (i=0;i< numConstraints ; i++ )
|
||||
{
|
||||
TypedConstraint* constraint = m_constraints[i];
|
||||
|
||||
const RigidBody* colObj0 = &constraint->GetRigidBodyA();
|
||||
const RigidBody* colObj1 = &constraint->GetRigidBodyB();
|
||||
|
||||
if (((colObj0) && ((colObj0)->mergesSimulationIslands())) &&
|
||||
((colObj1) && ((colObj1)->mergesSimulationIslands())))
|
||||
{
|
||||
if (colObj0->IsActive() || colObj1->IsActive())
|
||||
{
|
||||
GetDispatcher()->GetUnionFind().unite((colObj0)->m_islandTag1,
|
||||
(colObj1)->m_islandTag1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GetCollisionWorld()->StoreIslandActivationState();
|
||||
*/
|
||||
|
||||
#ifdef USE_QUICKPROF
|
||||
Profiler::endBlock("CalcSimulationIslands");
|
||||
#endif //USE_QUICKPROF
|
||||
|
||||
|
||||
|
||||
/*
|
||||
//printf("CcdPhysicsEnvironment::proceedDeltaTime\n");
|
||||
|
||||
@@ -127,32 +168,7 @@ bool ParallelPhysicsEnvironment::proceedDeltaTimeOneStep(float timeStep)
|
||||
|
||||
int numRigidBodies = m_controllers.size();
|
||||
|
||||
m_collisionWorld->UpdateActivationState();
|
||||
|
||||
{
|
||||
int i;
|
||||
int numConstraints = m_constraints.size();
|
||||
for (i=0;i< numConstraints ; i++ )
|
||||
{
|
||||
TypedConstraint* constraint = m_constraints[i];
|
||||
|
||||
const RigidBody* colObj0 = &constraint->GetRigidBodyA();
|
||||
const RigidBody* colObj1 = &constraint->GetRigidBodyB();
|
||||
|
||||
if (((colObj0) && ((colObj0)->mergesSimulationIslands())) &&
|
||||
((colObj1) && ((colObj1)->mergesSimulationIslands())))
|
||||
{
|
||||
if (colObj0->IsActive() || colObj1->IsActive())
|
||||
{
|
||||
GetDispatcher()->GetUnionFind().unite((colObj0)->m_islandTag1,
|
||||
(colObj1)->m_islandTag1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_collisionWorld->StoreIslandActivationState();
|
||||
|
||||
|
||||
|
||||
|
||||
//contacts
|
||||
|
||||
17
Extras/PhysicsInterface/CcdPhysics/SimulationIsland.cpp
Normal file
17
Extras/PhysicsInterface/CcdPhysics/SimulationIsland.cpp
Normal file
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
#include "SimulationIsland.h"
|
||||
|
||||
29
Extras/PhysicsInterface/CcdPhysics/SimulationIsland.h
Normal file
29
Extras/PhysicsInterface/CcdPhysics/SimulationIsland.h
Normal file
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
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 SIMULATION_ISLAND_H
|
||||
#define SIMULATION_ISLAND_H
|
||||
|
||||
///SimulationIsland groups all computations and data (for collision detection and dynamics) that can execute in parallel with other SimulationIsland's
|
||||
///The ParallelPhysicsEnvironment and ParallelIslandDispatcher will dispatch SimulationIsland's
|
||||
///At the start of the simulation timestep the simulation islands are re-calculated
|
||||
///During one timestep there is no merging or splitting of Simulation Islands
|
||||
class SimulationIsland
|
||||
{
|
||||
public:
|
||||
|
||||
};
|
||||
|
||||
#endif //SIMULATION_ISLAND_H
|
||||
Reference in New Issue
Block a user