Added basic gather/scatter to simulation island (for ParallelIslandDispatcher/ParallelPhysicsEnvironment.
This commit is contained in:
@@ -82,7 +82,7 @@ const int maxOverlap = 65535;
|
||||
|
||||
|
||||
#ifdef _DEBUG
|
||||
const int numObjects = 20;
|
||||
const int numObjects = 120;
|
||||
#else
|
||||
const int numObjects = 120;
|
||||
#endif
|
||||
@@ -314,7 +314,7 @@ int main(int argc,char** argv)
|
||||
clientResetScene();
|
||||
physicsEnvironmentPtr->SyncMotionStates(0.f);
|
||||
|
||||
|
||||
if (createConstraint)
|
||||
{
|
||||
//physObjects[i]->SetAngularVelocity(0,0,-2,true);
|
||||
int constraintId;
|
||||
|
||||
@@ -49,12 +49,14 @@ class CcdPhysicsEnvironment : public PHY_IPhysicsEnvironment
|
||||
SimdVector3 m_gravity;
|
||||
|
||||
IDebugDraw* m_debugDrawer;
|
||||
|
||||
protected:
|
||||
//solver iterations
|
||||
int m_numIterations;
|
||||
|
||||
//timestep subdivisions
|
||||
int m_numTimeSubSteps;
|
||||
protected:
|
||||
|
||||
|
||||
int m_ccdMode;
|
||||
int m_solverType;
|
||||
|
||||
@@ -40,9 +40,12 @@ ParallelPhysicsEnvironment::~ParallelPhysicsEnvironment()
|
||||
/// Perform an integration step of duration 'timeStep'.
|
||||
bool ParallelPhysicsEnvironment::proceedDeltaTimeOneStep(float timeStep)
|
||||
{
|
||||
// Make sure the broadphase / overlapping AABB paircache is up-to-date
|
||||
OverlappingPairCache* scene = m_collisionWorld->GetPairCache();
|
||||
scene->RefreshOverlappingPairs();
|
||||
|
||||
// Find the connected sets that can be simulated in parallel
|
||||
// Using union find
|
||||
|
||||
#ifdef USE_QUICKPROF
|
||||
Profiler::beginBlock("IslandUnionFind");
|
||||
@@ -73,6 +76,7 @@ bool ParallelPhysicsEnvironment::proceedDeltaTimeOneStep(float timeStep)
|
||||
}
|
||||
}
|
||||
|
||||
//Store the island id in each body
|
||||
GetSimulationIslandManager()->StoreIslandActivationState(GetCollisionWorld());
|
||||
|
||||
#ifdef USE_QUICKPROF
|
||||
@@ -80,7 +84,8 @@ bool ParallelPhysicsEnvironment::proceedDeltaTimeOneStep(float timeStep)
|
||||
#endif //USE_QUICKPROF
|
||||
|
||||
|
||||
///calculate simulation islands
|
||||
|
||||
///build simulation islands
|
||||
|
||||
#ifdef USE_QUICKPROF
|
||||
Profiler::beginBlock("BuildIslands");
|
||||
@@ -103,9 +108,9 @@ bool ParallelPhysicsEnvironment::proceedDeltaTimeOneStep(float timeStep)
|
||||
Dispatcher* dispatcher = GetCollisionWorld()->GetDispatcher();
|
||||
|
||||
|
||||
|
||||
//this is a brute force approach, will rethink later about more subtle ways
|
||||
int i;
|
||||
for (int i=0;i< scene->GetNumOverlappingPairs();i++)
|
||||
for (i=0;i< scene->GetNumOverlappingPairs();i++)
|
||||
{
|
||||
BroadphasePair* pair = &scene->GetOverlappingPair(i);
|
||||
|
||||
@@ -114,13 +119,27 @@ bool ParallelPhysicsEnvironment::proceedDeltaTimeOneStep(float timeStep)
|
||||
|
||||
if (col0->m_islandTag1 > col1->m_islandTag1)
|
||||
{
|
||||
simulationIslands[col0->m_islandTag1].m_overlappingPairs.push_back(*pair);
|
||||
simulationIslands[col0->m_islandTag1].m_overlappingPairIndices.push_back(i);
|
||||
} else
|
||||
{
|
||||
simulationIslands[col1->m_islandTag1].m_overlappingPairs.push_back(*pair);
|
||||
simulationIslands[col1->m_islandTag1].m_overlappingPairIndices.push_back(i);
|
||||
}
|
||||
}
|
||||
|
||||
//store constraint indices for each island
|
||||
for (i=0;i<m_constraints.size();i++)
|
||||
{
|
||||
TypedConstraint& constraint = *m_constraints[i];
|
||||
if (constraint.GetRigidBodyA().m_islandTag1 > constraint.GetRigidBodyB().m_islandTag1)
|
||||
{
|
||||
simulationIslands[constraint.GetRigidBodyA().m_islandTag1].m_constraintIndices.push_back(i);
|
||||
} else
|
||||
{
|
||||
simulationIslands[constraint.GetRigidBodyB().m_islandTag1].m_constraintIndices.push_back(i);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//add all overlapping pairs for each island
|
||||
|
||||
for (i=0;i<dispatcher->GetNumManifolds();i++)
|
||||
@@ -142,17 +161,34 @@ bool ParallelPhysicsEnvironment::proceedDeltaTimeOneStep(float timeStep)
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef USE_QUICKPROF
|
||||
Profiler::endBlock("BuildIslands");
|
||||
#endif //USE_QUICKPROF
|
||||
|
||||
|
||||
#ifdef USE_QUICKPROF
|
||||
Profiler::beginBlock("SimulateIsland");
|
||||
#endif //USE_QUICKPROF
|
||||
|
||||
TypedConstraint** constraintBase = 0;
|
||||
if (m_constraints.size())
|
||||
constraintBase = &m_constraints[0];
|
||||
|
||||
|
||||
|
||||
//Each simulation island can be processed in parallel
|
||||
//Each simulation island can be processed in parallel (will be put on a job queue)
|
||||
for (k=0;k<simulationIslands.size();k++)
|
||||
{
|
||||
if (simulationIslands[k].m_controllers.size())
|
||||
{
|
||||
simulationIslands[k].Simulate(dispatcher,GetBroadphase(),m_solver,timeStep);
|
||||
simulationIslands[k].Simulate(m_numIterations, constraintBase ,&scene->GetOverlappingPair(0),dispatcher,GetBroadphase(),m_solver,timeStep);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef USE_QUICKPROF
|
||||
Profiler::endBlock("SimulateIsland");
|
||||
#endif //USE_QUICKPROF
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
@@ -37,6 +37,7 @@ class ParallelPhysicsEnvironment : public CcdPhysicsEnvironment
|
||||
/// Perform an integration step of duration 'timeStep'.
|
||||
virtual bool proceedDeltaTimeOneStep(float timeStep);
|
||||
|
||||
//void BuildSimulationIslands();
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -21,51 +21,15 @@ subject to the following restrictions:
|
||||
#include "BroadphaseCollision/Dispatcher.h"
|
||||
#include "ConstraintSolver/ContactSolverInfo.h"
|
||||
#include "ConstraintSolver/ConstraintSolver.h"
|
||||
#include "ConstraintSolver/TypedConstraint.h"
|
||||
|
||||
extern float gContactBreakingTreshold;
|
||||
|
||||
bool SimulationIsland::Simulate(Dispatcher* dispatcher,BroadphaseInterface* broadphase,class ConstraintSolver* solver,float timeStep)
|
||||
bool SimulationIsland::Simulate(int numSolverIterations,TypedConstraint** constraintsBaseAddress,BroadphasePair* overlappingPairBaseAddress, Dispatcher* dispatcher,BroadphaseInterface* broadphase,class ConstraintSolver* solver,float timeStep)
|
||||
{
|
||||
//then execute all stuff below for each simulation island
|
||||
|
||||
|
||||
#ifdef USE_QUICKPROF
|
||||
Profiler::endBlock("BuildIslands");
|
||||
#endif //USE_QUICKPROF
|
||||
|
||||
|
||||
|
||||
|
||||
///build simulation islands, and add them to a job queue, which can be processed in parallel
|
||||
///or on the GPU
|
||||
|
||||
|
||||
//printf("CcdPhysicsEnvironment::proceedDeltaTime\n");
|
||||
|
||||
if (SimdFuzzyZero(timeStep))
|
||||
return true;
|
||||
|
||||
// if (m_debugDrawer)
|
||||
// {
|
||||
// gDisableDeactivation = (m_debugDrawer->GetDebugMode() & IDebugDraw::DBG_NoDeactivation);
|
||||
// }
|
||||
|
||||
|
||||
#ifdef USE_QUICKPROF
|
||||
Profiler::beginBlock("SyncMotionStates");
|
||||
#endif //USE_QUICKPROF
|
||||
|
||||
|
||||
//this is needed because scaling is not known in advance, and scaling has to propagate to the shape
|
||||
//if (!m_scalingPropagated)
|
||||
//{
|
||||
// SyncMotionStates(timeStep);
|
||||
// m_scalingPropagated = true;
|
||||
//}
|
||||
|
||||
|
||||
#ifdef USE_QUICKPROF
|
||||
Profiler::endBlock("SyncMotionStates");
|
||||
|
||||
Profiler::beginBlock("predictIntegratedTransform");
|
||||
#endif //USE_QUICKPROF
|
||||
@@ -119,10 +83,28 @@ bool SimulationIsland::Simulate(Dispatcher* dispatcher,BroadphaseInterface* broa
|
||||
dispatchInfo.m_stepCount = 0;
|
||||
dispatchInfo.m_enableSatConvex = false;//m_enableSatCollisionDetection;
|
||||
|
||||
//pairCache->RefreshOverlappingPairs();
|
||||
if (m_overlappingPairs.size())
|
||||
std::vector<BroadphasePair> overlappingPairs;
|
||||
overlappingPairs.resize(this->m_overlappingPairIndices.size());
|
||||
|
||||
//gather overlapping pair info
|
||||
int i;
|
||||
for (i=0;i<m_overlappingPairIndices.size();i++)
|
||||
{
|
||||
dispatcher->DispatchAllCollisionPairs(&m_overlappingPairs[0],m_overlappingPairs.size(),dispatchInfo);///numsubstep,g);
|
||||
overlappingPairs[i] = overlappingPairBaseAddress[m_overlappingPairIndices[i]];
|
||||
}
|
||||
|
||||
|
||||
//pairCache->RefreshOverlappingPairs();
|
||||
if (overlappingPairs.size())
|
||||
{
|
||||
dispatcher->DispatchAllCollisionPairs(&overlappingPairs[0],overlappingPairs.size(),dispatchInfo);///numsubstep,g);
|
||||
}
|
||||
|
||||
//scatter overlapping pair info, mainly the created algorithms/contact caches
|
||||
|
||||
for (i=0;i<m_overlappingPairIndices.size();i++)
|
||||
{
|
||||
overlappingPairBaseAddress[m_overlappingPairIndices[i]] = overlappingPairs[i];
|
||||
}
|
||||
|
||||
|
||||
@@ -130,7 +112,7 @@ bool SimulationIsland::Simulate(Dispatcher* dispatcher,BroadphaseInterface* broa
|
||||
Profiler::endBlock("DispatchAllCollisionPairs");
|
||||
#endif //USE_QUICKPROF
|
||||
|
||||
/*
|
||||
|
||||
|
||||
|
||||
int numRigidBodies = m_controllers.size();
|
||||
@@ -146,21 +128,19 @@ bool SimulationIsland::Simulate(Dispatcher* dispatcher,BroadphaseInterface* broa
|
||||
|
||||
//solve the regular constraints (point 2 point, hinge, etc)
|
||||
|
||||
for (int g=0;g<numsubstep;g++)
|
||||
for (int g=0;g<numSolverIterations;g++)
|
||||
{
|
||||
//
|
||||
// constraint solving
|
||||
//
|
||||
|
||||
|
||||
int i;
|
||||
int numConstraints = m_constraints.size();
|
||||
int numConstraints = m_constraintIndices.size();
|
||||
|
||||
//point to point constraints
|
||||
for (i=0;i< numConstraints ; i++ )
|
||||
{
|
||||
TypedConstraint* constraint = m_constraints[i];
|
||||
|
||||
TypedConstraint* constraint = constraintsBaseAddress[m_constraintIndices[i]];
|
||||
constraint->BuildJacobian();
|
||||
constraint->SolveConstraint( timeStep );
|
||||
|
||||
@@ -173,6 +153,8 @@ bool SimulationIsland::Simulate(Dispatcher* dispatcher,BroadphaseInterface* broa
|
||||
Profiler::endBlock("SolveConstraint");
|
||||
#endif //USE_QUICKPROF
|
||||
|
||||
/*
|
||||
|
||||
//solve the vehicles
|
||||
|
||||
#ifdef NEW_BULLET_VEHICLE_SUPPORT
|
||||
@@ -185,53 +167,9 @@ bool SimulationIsland::Simulate(Dispatcher* dispatcher,BroadphaseInterface* broa
|
||||
vehicle->UpdateVehicle( timeStep);
|
||||
}
|
||||
#endif //NEW_BULLET_VEHICLE_SUPPORT
|
||||
*/
|
||||
|
||||
|
||||
struct InplaceSolverIslandCallback : public ParallelIslandDispatcher::IslandCallback
|
||||
{
|
||||
|
||||
ContactSolverInfo& m_solverInfo;
|
||||
ConstraintSolver* m_solver;
|
||||
IDebugDraw* m_debugDrawer;
|
||||
|
||||
InplaceSolverIslandCallback(
|
||||
ContactSolverInfo& solverInfo,
|
||||
ConstraintSolver* solver,
|
||||
IDebugDraw* debugDrawer)
|
||||
:m_solverInfo(solverInfo),
|
||||
m_solver(solver),
|
||||
m_debugDrawer(debugDrawer)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
virtual void ProcessIsland(PersistentManifold** manifolds,int numManifolds)
|
||||
{
|
||||
m_solver->SolveGroup( manifolds, numManifolds,m_solverInfo,m_debugDrawer);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
m_solverInfo.m_friction = 0.9f;
|
||||
m_solverInfo.m_numIterations = m_numIterations;
|
||||
m_solverInfo.m_timeStep = timeStep;
|
||||
m_solverInfo.m_restitution = 0.f;//m_restitution;
|
||||
|
||||
InplaceSolverIslandCallback solverCallback(
|
||||
m_solverInfo,
|
||||
m_solver,
|
||||
m_debugDrawer);
|
||||
|
||||
#ifdef USE_QUICKPROF
|
||||
Profiler::beginBlock("BuildAndProcessIslands");
|
||||
#endif //USE_QUICKPROF
|
||||
|
||||
/// solve all the contact points and contact friction
|
||||
GetDispatcher()->BuildAndProcessIslands(m_collisionWorld->GetCollisionObjectArray(),&solverCallback);
|
||||
|
||||
#ifdef USE_QUICKPROF
|
||||
Profiler::endBlock("BuildAndProcessIslands");
|
||||
/*
|
||||
|
||||
Profiler::beginBlock("CallbackTriggers");
|
||||
#endif //USE_QUICKPROF
|
||||
@@ -249,7 +187,7 @@ bool SimulationIsland::Simulate(Dispatcher* dispatcher,BroadphaseInterface* broa
|
||||
ContactSolverInfo solverInfo;
|
||||
|
||||
solverInfo.m_friction = 0.9f;
|
||||
solverInfo.m_numIterations = 10;//m_numIterations;
|
||||
solverInfo.m_numIterations = numSolverIterations;
|
||||
solverInfo.m_timeStep = timeStep;
|
||||
solverInfo.m_restitution = 0.f;//m_restitution;
|
||||
|
||||
@@ -275,7 +213,7 @@ bool SimulationIsland::Simulate(Dispatcher* dispatcher,BroadphaseInterface* broa
|
||||
|
||||
float toi = 1.f;
|
||||
|
||||
|
||||
//experimental continuous collision detection
|
||||
|
||||
/* if (m_ccdMode == 3)
|
||||
{
|
||||
@@ -386,7 +324,6 @@ bool SimulationIsland::Simulate(Dispatcher* dispatcher,BroadphaseInterface* broa
|
||||
#ifdef USE_QUICKPROF
|
||||
Profiler::endBlock("SyncMotionStates");
|
||||
|
||||
Profiler::endProfilingCycle();
|
||||
#endif //USE_QUICKPROF
|
||||
|
||||
|
||||
|
||||
@@ -30,9 +30,11 @@ class SimulationIsland
|
||||
public:
|
||||
std::vector<class CcdPhysicsController*> m_controllers;
|
||||
std::vector<class PersistentManifold*> m_manifolds;
|
||||
std::vector<class BroadphasePair> m_overlappingPairs;
|
||||
|
||||
bool Simulate(Dispatcher* dispatcher,BroadphaseInterface* broadphase, class ConstraintSolver* solver, float timeStep);
|
||||
std::vector<int> m_overlappingPairIndices;
|
||||
std::vector<int> m_constraintIndices;
|
||||
|
||||
bool Simulate(int numSolverIterations,class TypedConstraint** constraintsBaseAddress,struct BroadphasePair* overlappingPairBaseAddress, Dispatcher* dispatcher,BroadphaseInterface* broadphase, class ConstraintSolver* solver, float timeStep);
|
||||
|
||||
|
||||
int GetNumControllers()
|
||||
|
||||
Reference in New Issue
Block a user