From 2d80bae6e3c80b9aceea4fb4138d7352f949b156 Mon Sep 17 00:00:00 2001 From: ejcoumans Date: Sat, 1 Jul 2006 00:22:15 +0000 Subject: [PATCH] fairly large refactoring of dispatcher/simulation island management, to allow for parallel simulation. --- Bullet/BroadphaseCollision/Dispatcher.h | 8 + .../CollisionDispatch/CollisionDispatcher.cpp | 117 ---------- .../CollisionDispatch/CollisionDispatcher.h | 25 +-- Bullet/CollisionDispatch/CollisionWorld.cpp | 55 +---- Bullet/CollisionDispatch/CollisionWorld.h | 10 +- .../SimulationIslandManager.cpp | 200 ++++++++++++++++++ .../SimulationIslandManager.h | 58 +++++ Demos/CcdPhysicsDemo/CcdPhysicsDemo.cpp | 6 + .../CollisionInterfaceDemo.cpp | 7 +- .../CcdPhysics/CcdPhysicsEnvironment.cpp | 47 ++-- .../CcdPhysics/CcdPhysicsEnvironment.h | 24 ++- .../CcdPhysics/ParallelIslandDispatcher.cpp | 33 +-- .../CcdPhysics/ParallelIslandDispatcher.h | 3 + .../CcdPhysics/ParallelPhysicsEnvironment.cpp | 68 +++--- .../CcdPhysics/SimulationIsland.cpp | 17 ++ .../CcdPhysics/SimulationIsland.h | 29 +++ 16 files changed, 424 insertions(+), 283 deletions(-) create mode 100644 Bullet/CollisionDispatch/SimulationIslandManager.cpp create mode 100644 Bullet/CollisionDispatch/SimulationIslandManager.h create mode 100644 Extras/PhysicsInterface/CcdPhysics/SimulationIsland.cpp create mode 100644 Extras/PhysicsInterface/CcdPhysics/SimulationIsland.h diff --git a/Bullet/BroadphaseCollision/Dispatcher.h b/Bullet/BroadphaseCollision/Dispatcher.h index 7f8351bcd..47a006f69 100644 --- a/Bullet/BroadphaseCollision/Dispatcher.h +++ b/Bullet/BroadphaseCollision/Dispatcher.h @@ -21,6 +21,7 @@ struct BroadphaseProxy; class RigidBody; struct CollisionObject; class ManifoldResult; +class OverlappingPairCache; enum CollisionDispatcherId { @@ -80,10 +81,17 @@ public: virtual bool NeedsCollision(BroadphaseProxy& proxy0,BroadphaseProxy& proxy1) = 0; + virtual bool NeedsResponse(const CollisionObject& colObj0,const CollisionObject& colObj1)=0; + virtual ManifoldResult* GetNewManifoldResult(CollisionObject* obj0,CollisionObject* obj1,PersistentManifold* manifold) =0; virtual void ReleaseManifoldResult(ManifoldResult*)=0; + virtual void DispatchAllCollisionPairs(OverlappingPairCache* pairCache,DispatcherInfo& dispatchInfo)=0; + + virtual int GetNumManifolds() const = 0; + + virtual PersistentManifold* GetManifoldByIndexInternal(int index) = 0; }; diff --git a/Bullet/CollisionDispatch/CollisionDispatcher.cpp b/Bullet/CollisionDispatch/CollisionDispatcher.cpp index 6e8c0696c..3fe8f4760 100644 --- a/Bullet/CollisionDispatch/CollisionDispatcher.cpp +++ b/Bullet/CollisionDispatch/CollisionDispatcher.cpp @@ -28,34 +28,7 @@ subject to the following restrictions: int gNumManifold = 0; -void CollisionDispatcher::FindUnions() -{ - if (m_useIslands) - { - for (int i=0;iGetManifoldByIndexInternal(i); - //static objects (invmass 0.f) don't merge ! - const CollisionObject* colObj0 = static_cast(manifold->GetBody0()); - const CollisionObject* colObj1 = static_cast(manifold->GetBody1()); - - if (colObj0 && colObj1 && NeedsResponse(*colObj0,*colObj1)) - { - if (((colObj0) && ((colObj0)->mergesSimulationIslands())) && - ((colObj1) && ((colObj1)->mergesSimulationIslands()))) - { - - m_unionFind.unite((colObj0)->m_islandTag1, - (colObj1)->m_islandTag1); - } - } - - - } - } - -} @@ -122,96 +95,6 @@ void CollisionDispatcher::ReleaseManifold(PersistentManifold* manifold) } -// -// todo: this is random access, it can be walked 'cache friendly'! -// -void CollisionDispatcher::BuildAndProcessIslands(CollisionObjectArray& collisionObjects, IslandCallback* callback) -{ - int numBodies = collisionObjects.size(); - - for (int islandId=0;islandId islandmanifold; - - //int numSleeping = 0; - - bool allSleeping = true; - - int i; - for (i=0;im_islandTag1 == islandId) - { - if (colObj0->GetActivationState()== ACTIVE_TAG) - { - allSleeping = false; - } - if (colObj0->GetActivationState()== DISABLE_DEACTIVATION) - { - allSleeping = false; - } - } - } - - - for (i=0;iGetManifoldByIndexInternal(i); - - //filtering for response - - CollisionObject* colObj0 = static_cast(manifold->GetBody0()); - CollisionObject* colObj1 = static_cast(manifold->GetBody1()); - { - if (((colObj0) && (colObj0)->m_islandTag1 == (islandId)) || - ((colObj1) && (colObj1)->m_islandTag1 == (islandId))) - { - - if (NeedsResponse(*colObj0,*colObj1)) - islandmanifold.push_back(manifold); - } - } - } - if (allSleeping) - { - int i; - for (i=0;im_islandTag1 == islandId) - { - colObj0->SetActivationState( ISLAND_SLEEPING ); - } - } - - - } else - { - - int i; - for (i=0;im_islandTag1 == islandId) - { - if ( colObj0->GetActivationState() == ISLAND_SLEEPING) - { - colObj0->SetActivationState( WANTS_DEACTIVATION); - } - } - } - - /// Process the actual simulation, only if not sleeping/deactivated - if (islandmanifold.size()) - { - callback->ProcessIsland(&islandmanifold[0],islandmanifold.size()); - } - - } - } -} diff --git a/Bullet/CollisionDispatch/CollisionDispatcher.h b/Bullet/CollisionDispatch/CollisionDispatcher.h index c9b70ce8c..b99130297 100644 --- a/Bullet/CollisionDispatch/CollisionDispatcher.h +++ b/Bullet/CollisionDispatch/CollisionDispatcher.h @@ -18,7 +18,7 @@ subject to the following restrictions: #include "BroadphaseCollision/Dispatcher.h" #include "NarrowPhaseCollision/PersistentManifold.h" -#include "CollisionDispatch/UnionFind.h" + #include "CollisionDispatch/ManifoldResult.h" #include "BroadphaseCollision/BroadphaseProxy.h" @@ -40,7 +40,7 @@ class CollisionDispatcher : public Dispatcher std::vector m_manifoldsPtr; - UnionFind m_unionFind; + bool m_useIslands; @@ -50,14 +50,9 @@ class CollisionDispatcher : public Dispatcher public: - UnionFind& GetUnionFind() { return m_unionFind;} + - struct IslandCallback - { - virtual ~IslandCallback() {}; - - virtual void ProcessIsland(PersistentManifold** manifolds,int numManifolds) = 0; - }; + int GetNumManifolds() const @@ -75,14 +70,6 @@ public: return m_manifoldsPtr[index]; } - void InitUnionFind(int n) - { - if (m_useIslands) - m_unionFind.reset(n); - } - - void FindUnions(); - int m_count; CollisionDispatcher (); @@ -93,8 +80,6 @@ public: virtual void ReleaseManifold(PersistentManifold* manifold); - virtual void BuildAndProcessIslands(CollisionObjectArray& collisionObjects, IslandCallback* callback); - ///allows the user to get contact point callbacks virtual ManifoldResult* GetNewManifoldResult(CollisionObject* obj0,CollisionObject* obj1,PersistentManifold* manifold); @@ -120,6 +105,8 @@ public: virtual void DispatchAllCollisionPairs(OverlappingPairCache* pairCache,DispatcherInfo& dispatchInfo); + + }; #endif //COLLISION__DISPATCHER_H diff --git a/Bullet/CollisionDispatch/CollisionWorld.cpp b/Bullet/CollisionDispatch/CollisionWorld.cpp index 36cdceabf..d1eb4122e 100644 --- a/Bullet/CollisionDispatch/CollisionWorld.cpp +++ b/Bullet/CollisionDispatch/CollisionWorld.cpp @@ -52,61 +52,10 @@ CollisionWorld::~CollisionWorld() } -void CollisionWorld::UpdateActivationState() -{ - m_dispatcher->InitUnionFind(m_collisionObjects.size()); - - // put the index into m_controllers into m_tag - { - std::vector::iterator i; - - int index = 0; - for (i=m_collisionObjects.begin(); - !(i==m_collisionObjects.end()); i++) - { - - CollisionObject* collisionObject= (*i); - collisionObject->m_islandTag1 = index; - collisionObject->m_hitFraction = 1.f; - index++; - - } - } - // do the union find - - m_dispatcher->FindUnions(); - - - -} -void CollisionWorld::StoreIslandActivationState() -{ - // put the islandId ('find' value) into m_tag - { - UnionFind& unionFind = m_dispatcher->GetUnionFind(); - - std::vector::iterator i; - - int index = 0; - for (i=m_collisionObjects.begin(); - !(i==m_collisionObjects.end()); i++) - { - CollisionObject* collisionObject= (*i); - - if (collisionObject->mergesSimulationIslands()) - { - collisionObject->m_islandTag1 = unionFind.find(index); - } else - { - collisionObject->m_islandTag1 = -1; - } - index++; - } - } -} + @@ -153,7 +102,7 @@ void CollisionWorld::PerformDiscreteCollisionDetection() m_pairCache->SetAabb(m_collisionObjects[i]->m_broadphaseHandle,aabbMin,aabbMax); } - CollisionDispatcher* dispatcher = GetDispatcher(); + Dispatcher* dispatcher = GetDispatcher(); if (dispatcher) dispatcher->DispatchAllCollisionPairs(m_pairCache,dispatchInfo); diff --git a/Bullet/CollisionDispatch/CollisionWorld.h b/Bullet/CollisionDispatch/CollisionWorld.h index 8b662e61f..29d641602 100644 --- a/Bullet/CollisionDispatch/CollisionWorld.h +++ b/Bullet/CollisionDispatch/CollisionWorld.h @@ -84,7 +84,7 @@ class CollisionWorld std::vector m_collisionObjects; - CollisionDispatcher* m_dispatcher; + CollisionDispatcher* m_dispatcher1; OverlappingPairCache* m_pairCache; @@ -92,15 +92,13 @@ class CollisionWorld public: CollisionWorld(CollisionDispatcher* dispatcher,OverlappingPairCache* pairCache) - :m_dispatcher(dispatcher), + :m_dispatcher1(dispatcher), m_pairCache(pairCache) { } virtual ~CollisionWorld(); - virtual void UpdateActivationState(); - virtual void StoreIslandActivationState(); BroadphaseInterface* GetBroadphase() { @@ -113,9 +111,9 @@ public: } - CollisionDispatcher* GetDispatcher() + Dispatcher* GetDispatcher() { - return m_dispatcher; + return m_dispatcher1; } ///LocalShapeInfo gives extra information for complex shapes diff --git a/Bullet/CollisionDispatch/SimulationIslandManager.cpp b/Bullet/CollisionDispatch/SimulationIslandManager.cpp new file mode 100644 index 000000000..6e791fc5c --- /dev/null +++ b/Bullet/CollisionDispatch/SimulationIslandManager.cpp @@ -0,0 +1,200 @@ + +#include "SimulationIslandManager.h" +#include "BroadphaseCollision/Dispatcher.h" +#include "NarrowPhaseCollision/PersistentManifold.h" +#include "CollisionDispatch/CollisionObject.h" +#include "CollisionDispatch/CollisionWorld.h" + + + +SimulationIslandManager::SimulationIslandManager() +{ +} + +void SimulationIslandManager::InitUnionFind(int n) +{ + m_unionFind.reset(n); +} + + +void SimulationIslandManager::FindUnions(Dispatcher* dispatcher) +{ + + { + for (int i=0;iGetNumManifolds();i++) + { + const PersistentManifold* manifold = dispatcher->GetManifoldByIndexInternal(i); + //static objects (invmass 0.f) don't merge ! + + const CollisionObject* colObj0 = static_cast(manifold->GetBody0()); + const CollisionObject* colObj1 = static_cast(manifold->GetBody1()); + + if (colObj0 && colObj1 && dispatcher->NeedsResponse(*colObj0,*colObj1)) + { + if (((colObj0) && ((colObj0)->mergesSimulationIslands())) && + ((colObj1) && ((colObj1)->mergesSimulationIslands()))) + { + + m_unionFind.unite((colObj0)->m_islandTag1, + (colObj1)->m_islandTag1); + } + } + + + } + } + +} + + +void SimulationIslandManager::UpdateActivationState(CollisionWorld* colWorld,Dispatcher* dispatcher) +{ + + InitUnionFind(colWorld->GetCollisionObjectArray().size()); + + // put the index into m_controllers into m_tag + { + std::vector::iterator i; + + int index = 0; + for (i=colWorld->GetCollisionObjectArray().begin(); + !(i==colWorld->GetCollisionObjectArray().end()); i++) + { + + CollisionObject* collisionObject= (*i); + collisionObject->m_islandTag1 = index; + collisionObject->m_hitFraction = 1.f; + index++; + + } + } + // do the union find + + FindUnions(dispatcher); + + + +} + + + + +void SimulationIslandManager::StoreIslandActivationState(CollisionWorld* colWorld) +{ + // put the islandId ('find' value) into m_tag + { + + + std::vector::iterator i; + + int index = 0; + for (i=colWorld->GetCollisionObjectArray().begin(); + !(i==colWorld->GetCollisionObjectArray().end()); i++) + { + CollisionObject* collisionObject= (*i); + + if (collisionObject->mergesSimulationIslands()) + { + collisionObject->m_islandTag1 = m_unionFind.find(index); + } else + { + collisionObject->m_islandTag1 = -1; + } + index++; + } + } +} + + + + +// +// todo: this is random access, it can be walked 'cache friendly'! +// +void SimulationIslandManager::BuildAndProcessIslands(Dispatcher* dispatcher,CollisionObjectArray& collisionObjects, IslandCallback* callback) +{ + int numBodies = collisionObjects.size(); + + for (int islandId=0;islandId islandmanifold; + + //int numSleeping = 0; + + bool allSleeping = true; + + int i; + for (i=0;im_islandTag1 == islandId) + { + if (colObj0->GetActivationState()== ACTIVE_TAG) + { + allSleeping = false; + } + if (colObj0->GetActivationState()== DISABLE_DEACTIVATION) + { + allSleeping = false; + } + } + } + + + for (i=0;iGetNumManifolds();i++) + { + PersistentManifold* manifold = dispatcher->GetManifoldByIndexInternal(i); + + //filtering for response + + CollisionObject* colObj0 = static_cast(manifold->GetBody0()); + CollisionObject* colObj1 = static_cast(manifold->GetBody1()); + { + if (((colObj0) && (colObj0)->m_islandTag1 == (islandId)) || + ((colObj1) && (colObj1)->m_islandTag1 == (islandId))) + { + + if (dispatcher->NeedsResponse(*colObj0,*colObj1)) + islandmanifold.push_back(manifold); + } + } + } + if (allSleeping) + { + int i; + for (i=0;im_islandTag1 == islandId) + { + colObj0->SetActivationState( ISLAND_SLEEPING ); + } + } + + + } else + { + + int i; + for (i=0;im_islandTag1 == islandId) + { + if ( colObj0->GetActivationState() == ISLAND_SLEEPING) + { + colObj0->SetActivationState( WANTS_DEACTIVATION); + } + } + } + + /// Process the actual simulation, only if not sleeping/deactivated + if (islandmanifold.size()) + { + callback->ProcessIsland(&islandmanifold[0],islandmanifold.size()); + } + + } + } +} diff --git a/Bullet/CollisionDispatch/SimulationIslandManager.h b/Bullet/CollisionDispatch/SimulationIslandManager.h new file mode 100644 index 000000000..5c50d06cd --- /dev/null +++ b/Bullet/CollisionDispatch/SimulationIslandManager.h @@ -0,0 +1,58 @@ +/* +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_MANAGER_H +#define SIMULATION_ISLAND_MANAGER_H + +#include "CollisionDispatch/UnionFind.h" +#include "CollisionCreateFunc.h" + +class CollisionWorld; +class Dispatcher; + +///SimulationIslandManager creates and handles simulation islands, using UnionFind +class SimulationIslandManager +{ + UnionFind m_unionFind; + +public: + SimulationIslandManager(); + + + void InitUnionFind(int n); + + + UnionFind& GetUnionFind() { return m_unionFind;} + + virtual void UpdateActivationState(CollisionWorld* colWorld,Dispatcher* dispatcher); + virtual void StoreIslandActivationState(CollisionWorld* world); + + + void FindUnions(Dispatcher* dispatcher); + + + + struct IslandCallback + { + virtual ~IslandCallback() {}; + + virtual void ProcessIsland(class PersistentManifold** manifolds,int numManifolds) = 0; + }; + + void BuildAndProcessIslands(Dispatcher* dispatcher,CollisionObjectArray& collisionObjects, IslandCallback* callback); + +}; + +#endif //SIMULATION_ISLAND_MANAGER_H diff --git a/Demos/CcdPhysicsDemo/CcdPhysicsDemo.cpp b/Demos/CcdPhysicsDemo/CcdPhysicsDemo.cpp index 5a25c84e3..9312445f8 100644 --- a/Demos/CcdPhysicsDemo/CcdPhysicsDemo.cpp +++ b/Demos/CcdPhysicsDemo/CcdPhysicsDemo.cpp @@ -13,6 +13,9 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ +//#define USE_PARALLEL_DISPATCHER 1 + + #include "CcdPhysicsEnvironment.h" #include "ParallelPhysicsEnvironment.h" @@ -89,6 +92,7 @@ const int maxNumObjects = 32760; MyMotionState ms[maxNumObjects]; CcdPhysicsController* physObjects[maxNumObjects] = {0,0,0,0}; int shapeIndex[maxNumObjects]; + #ifdef USE_PARALLEL_DISPATCHER ParallelPhysicsEnvironment* physicsEnvironmentPtr = 0; #else @@ -308,6 +312,8 @@ int main(int argc,char** argv) clientResetScene(); + physicsEnvironmentPtr->SyncMotionStates(0.f); + { //physObjects[i]->SetAngularVelocity(0,0,-2,true); diff --git a/Demos/CollisionInterfaceDemo/CollisionInterfaceDemo.cpp b/Demos/CollisionInterfaceDemo/CollisionInterfaceDemo.cpp index b90f3a25f..3535e2eb5 100644 --- a/Demos/CollisionInterfaceDemo/CollisionInterfaceDemo.cpp +++ b/Demos/CollisionInterfaceDemo/CollisionInterfaceDemo.cpp @@ -120,9 +120,11 @@ void clientDisplay(void) { if (collisionWorld) collisionWorld->PerformDiscreteCollisionDetection(); - - ///one way to draw all the contact points is iterating over contact manifolds / points: + int i; +/* + ///one way to draw all the contact points is iterating over contact manifolds / points: + int numManifolds = collisionWorld->GetDispatcher()->GetNumManifolds(); for (i=0;iDispatchAllCollisionPairs(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() } +*/ } diff --git a/Extras/PhysicsInterface/CcdPhysics/CcdPhysicsEnvironment.h b/Extras/PhysicsInterface/CcdPhysics/CcdPhysicsEnvironment.h index f6c724b36..f546248ce 100644 --- a/Extras/PhysicsInterface/CcdPhysics/CcdPhysicsEnvironment.h +++ b/Extras/PhysicsInterface/CcdPhysics/CcdPhysicsEnvironment.h @@ -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 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 m_controllers; diff --git a/Extras/PhysicsInterface/CcdPhysics/ParallelIslandDispatcher.cpp b/Extras/PhysicsInterface/CcdPhysics/ParallelIslandDispatcher.cpp index 21400338f..7d9d93e2d 100644 --- a/Extras/PhysicsInterface/CcdPhysics/ParallelIslandDispatcher.cpp +++ b/Extras/PhysicsInterface/CcdPhysics/ParallelIslandDispatcher.cpp @@ -27,34 +27,7 @@ subject to the following restrictions: static int gNumManifold2 = 0; -void ParallelIslandDispatcher::FindUnions() -{ - if (m_useIslands) - { - for (int i=0;iGetManifoldByIndexInternal(i); - //static objects (invmass 0.f) don't merge ! - const CollisionObject* colObj0 = static_cast(manifold->GetBody0()); - const CollisionObject* colObj1 = static_cast(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) +{ + +} + diff --git a/Extras/PhysicsInterface/CcdPhysics/ParallelIslandDispatcher.h b/Extras/PhysicsInterface/CcdPhysics/ParallelIslandDispatcher.h index 0d904a344..01e1fe947 100644 --- a/Extras/PhysicsInterface/CcdPhysics/ParallelIslandDispatcher.h +++ b/Extras/PhysicsInterface/CcdPhysics/ParallelIslandDispatcher.h @@ -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); + diff --git a/Extras/PhysicsInterface/CcdPhysics/ParallelPhysicsEnvironment.cpp b/Extras/PhysicsInterface/CcdPhysics/ParallelPhysicsEnvironment.cpp index 7e765d5fb..5a0f0c03f 100644 --- a/Extras/PhysicsInterface/CcdPhysics/ParallelPhysicsEnvironment.cpp +++ b/Extras/PhysicsInterface/CcdPhysics/ParallelPhysicsEnvironment.cpp @@ -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 diff --git a/Extras/PhysicsInterface/CcdPhysics/SimulationIsland.cpp b/Extras/PhysicsInterface/CcdPhysics/SimulationIsland.cpp new file mode 100644 index 000000000..3d78a2df6 --- /dev/null +++ b/Extras/PhysicsInterface/CcdPhysics/SimulationIsland.cpp @@ -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" + diff --git a/Extras/PhysicsInterface/CcdPhysics/SimulationIsland.h b/Extras/PhysicsInterface/CcdPhysics/SimulationIsland.h new file mode 100644 index 000000000..a59737fbf --- /dev/null +++ b/Extras/PhysicsInterface/CcdPhysics/SimulationIsland.h @@ -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 \ No newline at end of file