From a608d1ad4743b01c71ea8a5c212cd5faa00add57 Mon Sep 17 00:00:00 2001 From: ejcoumans Date: Wed, 13 Jun 2007 05:12:01 +0000 Subject: [PATCH] Added sample code to enable parallel (multi threaded) dispatcher (disabled by default, see #define USE_PARALLEL_DISPATCHER) --- Demos/BasicDemo/BasicDemo.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Demos/BasicDemo/BasicDemo.cpp b/Demos/BasicDemo/BasicDemo.cpp index 3e88e45c9..59ca25d05 100644 --- a/Demos/BasicDemo/BasicDemo.cpp +++ b/Demos/BasicDemo/BasicDemo.cpp @@ -17,6 +17,8 @@ subject to the following restrictions: //#define USE_GROUND_BOX 1 //#define PRINT_CONTACT_STATISTICS 1 //#define CHECK_MEMORY_LEAKS 1 +//#define USE_PARALLEL_DISPATCHER 1 + int gNumObjects = 120; #define HALF_EXTENTS btScalar(1.) @@ -30,6 +32,11 @@ btScalar gCollisionMargin = btScalar(0.05); #include "GL_ShapeDrawer.h" #include "GlutStuff.h" +#ifdef USE_PARALLEL_DISPATCHER +#include "SpuGatheringCollisionDispatcher.h" +#endif//USE_PARALLEL_DISPATCHER + + #include //////////////////////////////////// @@ -115,8 +122,12 @@ void BasicDemo::displayCallback(void) { void BasicDemo::initPhysics() { - +#ifdef USE_PARALLEL_DISPATCHER + m_dispatcher = new SpuGatheringCollisionDispatcher(); +#else m_dispatcher = new btCollisionDispatcher(true); +#endif //USE_PARALLEL_DISPATCHER + //#define USE_SWEEP_AND_PRUNE 1 #ifdef USE_SWEEP_AND_PRUNE #define maxProxies 8192 @@ -127,6 +138,7 @@ void BasicDemo::initPhysics() m_overlappingPairCache = new btSimpleBroadphase; #endif //USE_SWEEP_AND_PRUNE +#ifndef USE_PARALLEL_DISPATCHER m_sphereSphereCF = new btSphereSphereCollisionAlgorithm::CreateFunc; m_dispatcher->registerCollisionCreateFunc(SPHERE_SHAPE_PROXYTYPE,SPHERE_SHAPE_PROXYTYPE,m_sphereSphereCF); @@ -136,12 +148,15 @@ void BasicDemo::initPhysics() m_boxSphereCF->m_swapped = true; m_dispatcher->registerCollisionCreateFunc(SPHERE_SHAPE_PROXYTYPE,BOX_SHAPE_PROXYTYPE,m_sphereBoxCF); m_dispatcher->registerCollisionCreateFunc(BOX_SHAPE_PROXYTYPE,SPHERE_SHAPE_PROXYTYPE,m_boxSphereCF); +#endif //USE_PARALLEL_DISPATCHER m_solver = new btSequentialImpulseConstraintSolver; //m_dynamicsWorld = new btSimpleDynamicsWorld(m_dispatcher,m_overlappingPairCache,m_solver); m_dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher,m_overlappingPairCache,m_solver); + m_dynamicsWorld->getDispatchInfo().m_enableSPU = true; + m_dynamicsWorld->setGravity(btVector3(0,-10,0)); m_dynamicsWorld->setDebugDrawer(&debugDrawer); @@ -164,6 +179,7 @@ void BasicDemo::initPhysics() localCreateRigidBody(btScalar(0.),groundTransform,groundShape); //create a few dynamic sphere rigidbodies (re-using the same sphere shape) + //btCollisionShape* sphereShape = new btBoxShape(btVector3(1,1,1)); btCollisionShape* sphereShape = new btSphereShape(btScalar(1.)); m_collisionShapes.push_back(sphereShape);