confusion about memory management, and removed obsolete PhysicsInterface code.todo: updated the demos that still use this code
This commit is contained in:
@@ -21,13 +21,33 @@ subject to the following restrictions:
|
||||
#include "BulletCollision/CollisionShapes/btTriangleMeshShape.h" //for raycasting
|
||||
#include "BulletCollision/NarrowPhaseCollision/btRaycastCallback.h"
|
||||
#include "BulletCollision/CollisionShapes/btCompoundShape.h"
|
||||
|
||||
#include "BulletCollision/NarrowPhaseCollision/btSubSimplexConvexCast.h"
|
||||
#include "BulletCollision/BroadphaseCollision/btBroadphaseInterface.h"
|
||||
#include "LinearMath/btAabbUtil2.h"
|
||||
|
||||
//When the user doesn't provide dispatcher or broadphase, create basic versions (and delete them in destructor)
|
||||
#include "BulletCollision/CollisionDispatch/btCollisionDispatcher.h"
|
||||
#include "BulletCollision/BroadphaseCollision/btSimpleBroadphase.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
btCollisionWorld::btCollisionWorld(btDispatcher* dispatcher,btOverlappingPairCache* pairCache)
|
||||
:m_dispatcher1(dispatcher),
|
||||
m_broadphasePairCache(pairCache),
|
||||
m_ownsDispatcher(false),
|
||||
m_ownsBroadphasePairCache(false)
|
||||
{
|
||||
}
|
||||
|
||||
btCollisionWorld::btCollisionWorld()
|
||||
: m_dispatcher1(new btCollisionDispatcher()),
|
||||
m_broadphasePairCache(new btSimpleBroadphase()),
|
||||
m_ownsDispatcher(true),
|
||||
m_ownsBroadphasePairCache(true)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
btCollisionWorld::~btCollisionWorld()
|
||||
{
|
||||
//clean up remaining objects
|
||||
@@ -50,6 +70,11 @@ btCollisionWorld::~btCollisionWorld()
|
||||
}
|
||||
}
|
||||
|
||||
if (m_ownsDispatcher)
|
||||
delete m_dispatcher1;
|
||||
if (m_ownsBroadphasePairCache)
|
||||
delete m_broadphasePairCache;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -100,14 +125,14 @@ void btCollisionWorld::performDiscreteCollisionDetection()
|
||||
{
|
||||
m_collisionObjects[i]->m_cachedInvertedWorldTransform = m_collisionObjects[i]->m_worldTransform.inverse();
|
||||
m_collisionObjects[i]->m_collisionShape->getAabb(m_collisionObjects[i]->m_worldTransform,aabbMin,aabbMax);
|
||||
m_pairCache->setAabb(m_collisionObjects[i]->m_broadphaseHandle,aabbMin,aabbMax);
|
||||
m_broadphasePairCache->setAabb(m_collisionObjects[i]->m_broadphaseHandle,aabbMin,aabbMax);
|
||||
}
|
||||
|
||||
m_pairCache->refreshOverlappingPairs();
|
||||
m_broadphasePairCache->refreshOverlappingPairs();
|
||||
|
||||
btDispatcher* dispatcher = getDispatcher();
|
||||
if (dispatcher)
|
||||
dispatcher->dispatchAllCollisionPairs(m_pairCache,dispatchInfo);
|
||||
dispatcher->dispatchAllCollisionPairs(m_broadphasePairCache,dispatchInfo);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -88,28 +88,30 @@ protected:
|
||||
|
||||
btDispatcher* m_dispatcher1;
|
||||
|
||||
btOverlappingPairCache* m_pairCache;
|
||||
btOverlappingPairCache* m_broadphasePairCache;
|
||||
|
||||
bool m_ownsDispatcher;
|
||||
bool m_ownsBroadphasePairCache;
|
||||
|
||||
public:
|
||||
|
||||
btCollisionWorld(btDispatcher* dispatcher,btOverlappingPairCache* pairCache)
|
||||
:m_dispatcher1(dispatcher),
|
||||
m_pairCache(pairCache)
|
||||
{
|
||||
//this constructor will create and own a dispatcher and paircache and delete it at destruction
|
||||
btCollisionWorld();
|
||||
|
||||
//this constructor doesn't own the dispatcher and paircache/broadphase
|
||||
btCollisionWorld(btDispatcher* dispatcher,btOverlappingPairCache* pairCache);
|
||||
|
||||
}
|
||||
virtual ~btCollisionWorld();
|
||||
|
||||
|
||||
btBroadphaseInterface* getBroadphase()
|
||||
{
|
||||
return m_pairCache;
|
||||
return m_broadphasePairCache;
|
||||
}
|
||||
|
||||
btOverlappingPairCache* getPairCache()
|
||||
{
|
||||
return m_pairCache;
|
||||
return m_broadphasePairCache;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -36,10 +36,13 @@ subject to the following restrictions:
|
||||
#include <algorithm>
|
||||
|
||||
btDiscreteDynamicsWorld::btDiscreteDynamicsWorld()
|
||||
:btDynamicsWorld(new btCollisionDispatcher(),new btSimpleBroadphase()),
|
||||
:btDynamicsWorld(),
|
||||
m_constraintSolver(new btSequentialImpulseConstraintSolver)
|
||||
{
|
||||
m_islandManager = new btSimulationIslandManager();
|
||||
m_ownsIslandManager = true;
|
||||
m_ownsConstraintSolver = true;
|
||||
|
||||
}
|
||||
|
||||
btDiscreteDynamicsWorld::btDiscreteDynamicsWorld(btDispatcher* dispatcher,btOverlappingPairCache* pairCache,btConstraintSolver* constraintSolver)
|
||||
@@ -47,20 +50,18 @@ btDiscreteDynamicsWorld::btDiscreteDynamicsWorld(btDispatcher* dispatcher,btOver
|
||||
m_constraintSolver(constraintSolver)
|
||||
{
|
||||
m_islandManager = new btSimulationIslandManager();
|
||||
m_ownsIslandManager = true;
|
||||
m_ownsConstraintSolver = false;
|
||||
}
|
||||
|
||||
|
||||
btDiscreteDynamicsWorld::~btDiscreteDynamicsWorld()
|
||||
{
|
||||
delete m_islandManager ;
|
||||
|
||||
delete m_constraintSolver;
|
||||
|
||||
//delete the dispatcher and paircache
|
||||
delete m_dispatcher1;
|
||||
m_dispatcher1 = 0;
|
||||
delete m_pairCache;
|
||||
m_pairCache = 0;
|
||||
//only delete it when we created it
|
||||
if (m_ownsIslandManager)
|
||||
delete m_islandManager;
|
||||
if (m_ownsConstraintSolver)
|
||||
delete m_constraintSolver;
|
||||
}
|
||||
|
||||
void btDiscreteDynamicsWorld::stepSimulation(float timeStep)
|
||||
@@ -291,7 +292,7 @@ void btDiscreteDynamicsWorld::updateAabbs()
|
||||
{
|
||||
btPoint3 minAabb,maxAabb;
|
||||
colObj->m_collisionShape->getAabb(colObj->m_worldTransform, minAabb,maxAabb);
|
||||
btSimpleBroadphase* bp = (btSimpleBroadphase*)m_pairCache;
|
||||
btSimpleBroadphase* bp = (btSimpleBroadphase*)m_broadphasePairCache;
|
||||
bp->setAabb(body->m_broadphaseHandle,minAabb,maxAabb);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,6 +40,9 @@ protected:
|
||||
|
||||
std::vector<btTypedConstraint*> m_constraints;
|
||||
|
||||
bool m_ownsIslandManager;
|
||||
bool m_ownsConstraintSolver;
|
||||
|
||||
std::vector<btRaycastVehicle*> m_vehicles;
|
||||
|
||||
void predictUnconstraintMotion(float timeStep);
|
||||
@@ -61,8 +64,10 @@ protected:
|
||||
public:
|
||||
|
||||
|
||||
///this btDiscreteDynamicsWorld constructor gets created objects from the user, and will not delete those
|
||||
btDiscreteDynamicsWorld(btDispatcher* dispatcher,btOverlappingPairCache* pairCache,btConstraintSolver* constraintSolver);
|
||||
|
||||
///this btDiscreteDynamicsWorld will create and own dispatcher, pairCache and constraintSolver, and deletes it in the destructor.
|
||||
btDiscreteDynamicsWorld();
|
||||
|
||||
virtual ~btDiscreteDynamicsWorld();
|
||||
|
||||
@@ -24,11 +24,15 @@ class btDynamicsWorld : public btCollisionWorld
|
||||
{
|
||||
public:
|
||||
|
||||
btDynamicsWorld()
|
||||
{
|
||||
}
|
||||
|
||||
btDynamicsWorld(btDispatcher* dispatcher,btOverlappingPairCache* pairCache)
|
||||
:btCollisionWorld(dispatcher,pairCache)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
virtual ~btDynamicsWorld()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -23,15 +23,15 @@ subject to the following restrictions:
|
||||
|
||||
|
||||
btSimpleDynamicsWorld::btSimpleDynamicsWorld()
|
||||
:btDynamicsWorld(new btCollisionDispatcher(),new btSimpleBroadphase()),
|
||||
m_constraintSolver(new btSequentialImpulseConstraintSolver)
|
||||
:m_constraintSolver(new btSequentialImpulseConstraintSolver),
|
||||
m_ownsConstraintSolver(true)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
btSimpleDynamicsWorld::btSimpleDynamicsWorld(btDispatcher* dispatcher,btOverlappingPairCache* pairCache,btConstraintSolver* constraintSolver)
|
||||
:btDynamicsWorld(dispatcher,pairCache),
|
||||
m_constraintSolver(constraintSolver)
|
||||
m_constraintSolver(constraintSolver),
|
||||
m_ownsConstraintSolver(false)
|
||||
{
|
||||
|
||||
}
|
||||
@@ -39,13 +39,8 @@ m_constraintSolver(constraintSolver)
|
||||
|
||||
btSimpleDynamicsWorld::~btSimpleDynamicsWorld()
|
||||
{
|
||||
delete m_constraintSolver;
|
||||
|
||||
//delete the dispatcher and paircache
|
||||
delete m_dispatcher1;
|
||||
m_dispatcher1 = 0;
|
||||
delete m_pairCache;
|
||||
m_pairCache = 0;
|
||||
if (m_ownsConstraintSolver)
|
||||
delete m_constraintSolver;
|
||||
}
|
||||
|
||||
void btSimpleDynamicsWorld::stepSimulation(float timeStep)
|
||||
@@ -86,7 +81,7 @@ void btSimpleDynamicsWorld::updateAabbs()
|
||||
{
|
||||
btPoint3 minAabb,maxAabb;
|
||||
colObj->m_collisionShape->getAabb(colObj->m_worldTransform, minAabb,maxAabb);
|
||||
btSimpleBroadphase* bp = (btSimpleBroadphase*)m_pairCache;
|
||||
btBroadphaseInterface* bp = getBroadphase();
|
||||
bp->setAabb(body->m_broadphaseHandle,minAabb,maxAabb);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,8 @@ protected:
|
||||
|
||||
btConstraintSolver* m_constraintSolver;
|
||||
|
||||
bool m_ownsConstraintSolver;
|
||||
|
||||
void predictUnconstraintMotion(float timeStep);
|
||||
|
||||
void integrateTransforms(float timeStep);
|
||||
@@ -42,10 +44,12 @@ protected:
|
||||
public:
|
||||
|
||||
|
||||
btSimpleDynamicsWorld(btDispatcher* dispatcher,btOverlappingPairCache* pairCache,btConstraintSolver* constraintSolver);
|
||||
|
||||
///this btSimpleDynamicsWorld constructor creates and owns dispatcher, broadphase pairCache and constraintSolver
|
||||
btSimpleDynamicsWorld();
|
||||
|
||||
///this btSimpleDynamicsWorld constructor creates dispatcher, broadphase pairCache and constraintSolver
|
||||
btSimpleDynamicsWorld(btDispatcher* dispatcher,btOverlappingPairCache* pairCache,btConstraintSolver* constraintSolver);
|
||||
|
||||
virtual ~btSimpleDynamicsWorld();
|
||||
|
||||
virtual void stepSimulation( float timeStep);
|
||||
|
||||
Reference in New Issue
Block a user