From: Markus R. <rol...@us...> - 2007-02-15 21:00:33
|
Update of /cvsroot/simspark/simspark/spark/oxygen/physicsserver In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv23683 Modified Files: Tag: WIN32 body.cpp body.h bodycontroller.cpp bodycontroller.h collider.cpp collider.h joint.cpp joint.h space.cpp space.h world.cpp world.h Log Message: - implement DestroyODEObject() Index: world.h =================================================================== RCS file: /cvsroot/simspark/simspark/spark/oxygen/physicsserver/world.h,v retrieving revision 1.2.2.1 retrieving revision 1.2.2.2 diff -C2 -d -r1.2.2.1 -r1.2.2.2 *** world.h 12 Feb 2007 19:33:54 -0000 1.2.2.1 --- world.h 15 Feb 2007 21:00:19 -0000 1.2.2.2 *************** *** 97,105 **** zero. Increasing this to some small value (e.g. 0.001) can help prevent jittering problems due to contacts being repeatedly made ! and broken. */ ! void SetContactSurfaceLayer(float depth); float GetContactSurfaceLayer() const; protected: /** creates them managed ODE world */ --- 97,108 ---- zero. Increasing this to some small value (e.g. 0.001) can help prevent jittering problems due to contacts being repeatedly made ! and broken. */ ! void SetContactSurfaceLayer(float depth); float GetContactSurfaceLayer() const; + /** destroy the managed ODE object */ + virtual void DestroyODEObject(); + protected: /** creates them managed ODE world */ Index: body.cpp =================================================================== RCS file: /cvsroot/simspark/simspark/spark/oxygen/physicsserver/body.cpp,v retrieving revision 1.2 retrieving revision 1.2.2.1 diff -C2 -d -r1.2 -r1.2.2.1 *** body.cpp 14 Apr 2006 16:27:27 -0000 1.2 --- body.cpp 15 Feb 2007 21:00:18 -0000 1.2.2.1 *************** *** 35,43 **** Body::~Body() { - if (mODEBody) - { - dBodyDestroy(mODEBody); - mODEBody = 0; - } } --- 35,38 ---- *************** *** 106,109 **** --- 101,115 ---- } + void Body::DestroyODEObject() + { + if (mODEBody == 0) + { + return; + } + + dBodyDestroy(mODEBody); + mODEBody = 0; + } + void Body::OnLink() { Index: body.h =================================================================== RCS file: /cvsroot/simspark/simspark/spark/oxygen/physicsserver/body.h,v retrieving revision 1.2 retrieving revision 1.2.2.1 diff -C2 -d -r1.2 -r1.2.2.1 *** body.h 14 Apr 2006 16:27:26 -0000 1.2 --- body.h 15 Feb 2007 21:00:18 -0000 1.2.2.1 *************** *** 176,179 **** --- 176,182 ---- salt::Vector3f GetPosition() const; + /** destroy the managed ODE object */ + virtual void DestroyODEObject(); + protected: /** creates the managed ODE body and moves it to the position of Index: collider.h =================================================================== RCS file: /cvsroot/simspark/simspark/spark/oxygen/physicsserver/collider.h,v retrieving revision 1.2 retrieving revision 1.2.2.1 diff -C2 -d -r1.2 -r1.2.2.1 *** collider.h 14 Apr 2006 16:27:27 -0000 1.2 --- collider.h 15 Feb 2007 21:00:18 -0000 1.2.2.1 *************** *** 128,131 **** --- 128,134 ---- virtual void PrePhysicsUpdateInternal(float deltaTime); + /** destroy the managed ODE object */ + virtual void DestroyODEObject(); + // // Members Index: collider.cpp =================================================================== RCS file: /cvsroot/simspark/simspark/spark/oxygen/physicsserver/collider.cpp,v retrieving revision 1.2 retrieving revision 1.2.2.1 diff -C2 -d -r1.2 -r1.2.2.1 *** collider.cpp 14 Apr 2006 16:27:27 -0000 1.2 --- collider.cpp 15 Feb 2007 21:00:18 -0000 1.2.2.1 *************** *** 38,46 **** Collider::~Collider() { - if (mODEGeom) - { - dGeomDestroy(mODEGeom); - mODEGeom = 0; - } } --- 38,41 ---- *************** *** 252,253 **** --- 247,258 ---- } + void Collider::DestroyODEObject() + { + if (! mODEGeom) + { + return; + } + + dGeomDestroy(mODEGeom); + mODEGeom = 0; + } Index: bodycontroller.h =================================================================== RCS file: /cvsroot/simspark/simspark/spark/oxygen/physicsserver/bodycontroller.h,v retrieving revision 1.1 retrieving revision 1.1.2.1 diff -C2 -d -r1.1 -r1.1.2.1 *** bodycontroller.h 5 Dec 2005 21:16:49 -0000 1.1 --- bodycontroller.h 15 Feb 2007 21:00:18 -0000 1.1.2.1 *************** *** 38,41 **** --- 38,44 ---- virtual ~BodyController() {} + /** update variables from a script */ + virtual void UpdateCached(); + protected: /** sets up the reference to the controlled body */ Index: bodycontroller.cpp =================================================================== RCS file: /cvsroot/simspark/simspark/spark/oxygen/physicsserver/bodycontroller.cpp,v retrieving revision 1.1 retrieving revision 1.1.2.1 diff -C2 -d -r1.1 -r1.1.2.1 *** bodycontroller.cpp 5 Dec 2005 21:16:49 -0000 1.1 --- bodycontroller.cpp 15 Feb 2007 21:00:18 -0000 1.1.2.1 *************** *** 30,33 **** --- 30,45 ---- void BodyController::OnLink() { + UpdateCached(); + } + + void BodyController::OnUnlink() + { + mBody.reset(); + } + + void BodyController::UpdateCached() + { + mBody.reset(); + mBody = shared_dynamic_cast<Body> (make_shared(GetParentSupportingClass("Body"))); *************** *** 39,45 **** } } - - void BodyController::OnUnlink() - { - mBody.reset(); - } --- 51,52 ---- Index: joint.cpp =================================================================== RCS file: /cvsroot/simspark/simspark/spark/oxygen/physicsserver/joint.cpp,v retrieving revision 1.4.2.1 retrieving revision 1.4.2.2 diff -C2 -d -r1.4.2.1 -r1.4.2.2 *** joint.cpp 9 Feb 2007 20:11:56 -0000 1.4.2.1 --- joint.cpp 15 Feb 2007 21:00:18 -0000 1.4.2.2 *************** *** 33,42 **** Joint::~Joint() { - EnableFeedback(false); - if (mODEJoint) - { - dJointDestroy(mODEJoint); - mODEJoint = 0; - } } --- 33,36 ---- *************** *** 424,429 **** } ! ! ! --- 418,430 ---- } + void Joint::DestroyODEObject() + { + if (! mODEJoint) + { + return; + } ! EnableFeedback(false); ! dJointDestroy(mODEJoint); ! mODEJoint = 0; ! } Index: space.h =================================================================== RCS file: /cvsroot/simspark/simspark/spark/oxygen/physicsserver/space.h,v retrieving revision 1.1 retrieving revision 1.1.2.1 diff -C2 -d -r1.1 -r1.1.2.1 *** space.h 5 Dec 2005 21:16:49 -0000 1.1 --- space.h 15 Feb 2007 21:00:19 -0000 1.1.2.1 *************** *** 65,68 **** --- 65,71 ---- virtual void HandleCollide(dGeomID obj1, dGeomID obj2); + /** destroy the managed ODE object */ + virtual void DestroyODEObject(); + protected: /** creates them managed ODE space and a contact joint group */ *************** *** 72,75 **** --- 75,83 ---- virtual void PostPhysicsUpdateInternal(); + /** destroys the ODE bodies managed by all Body objects that are + registered to this Space + */ + void DestroySpaceObjects(); + // // Members Index: joint.h =================================================================== RCS file: /cvsroot/simspark/simspark/spark/oxygen/physicsserver/joint.h,v retrieving revision 1.2 retrieving revision 1.2.2.1 diff -C2 -d -r1.2 -r1.2.2.1 *** joint.h 12 Feb 2006 11:36:52 -0000 1.2 --- joint.h 15 Feb 2007 21:00:19 -0000 1.2.2.1 *************** *** 66,69 **** --- 66,72 ---- virtual ~Joint(); + /** destroy the managed ODE object */ + virtual void DestroyODEObject(); + /** attaches the joint to some new bodies. If the joint is already attached, it will be detached from the old bodies first. To Index: space.cpp =================================================================== RCS file: /cvsroot/simspark/simspark/spark/oxygen/physicsserver/space.cpp,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -C2 -d -r1.1.2.1 -r1.1.2.2 *** space.cpp 12 Feb 2007 19:32:54 -0000 1.1.2.1 --- space.cpp 15 Feb 2007 21:00:19 -0000 1.1.2.2 *************** *** 35,39 **** } ! Space::Space() : mODESpace(0), mODEContactGroup(0) { } --- 35,39 ---- } ! Space::Space() : ODEObject(), mODESpace(0), mODEContactGroup(0) { } *************** *** 46,56 **** mODEContactGroup = 0; } - - // release the ODE space - if (mODESpace) - { - dSpaceDestroy(mODESpace); - mODESpace = 0; - } } --- 46,49 ---- *************** *** 141,142 **** --- 134,188 ---- } + void Space::DestroySpaceObjects() + { + shared_ptr<Scene> scene = GetScene(); + if (scene.get() == 0) + { + return; + } + + TLeafList objects; + + const bool recursive = true; + scene->ListChildrenSupportingClass<ODEObject>(objects, recursive); + + for ( + TLeafList::iterator iter = objects.begin(); + iter != objects.end(); + ++iter + ) + { + shared_ptr<ODEObject> object = shared_static_cast<ODEObject>(*iter); + if (object->GetSpaceID() != mODESpace) + { + continue; + } + + object->DestroyODEObject(); + } + } + + void Space::DestroyODEObject() + { + static bool recurseLock = false; + + if ( + (recurseLock) || + (! mODESpace) + ) + { + return; + } + + recurseLock = true; + + // make sure that all objects registered to this space are destroyed + // before this space. Any other order provokes a segfault in ODE. + DestroySpaceObjects(); + + // release the ODE space + dSpaceDestroy(mODESpace); + mODESpace = 0; + + recurseLock = false; + } Index: world.cpp =================================================================== RCS file: /cvsroot/simspark/simspark/spark/oxygen/physicsserver/world.cpp,v retrieving revision 1.2.2.2 retrieving revision 1.2.2.3 diff -C2 -d -r1.2.2.2 -r1.2.2.3 *** world.cpp 13 Feb 2007 19:39:35 -0000 1.2.2.2 --- world.cpp 15 Feb 2007 21:00:19 -0000 1.2.2.3 *************** *** 21,29 **** #include "world.h" using namespace oxygen; using namespace salt; ! World::World() : mODEWorld(0) { } --- 21,32 ---- #include "world.h" + #include "space.h" + #include <oxygen/sceneserver/scene.h> + using namespace boost; using namespace oxygen; using namespace salt; ! World::World() : ODEObject(), mODEWorld(0) { } *************** *** 31,40 **** World::~World() { - // release the ODE world - if (mODEWorld) - { - dWorldDestroy(mODEWorld); - mODEWorld = 0; - } } --- 34,37 ---- *************** *** 112,113 **** --- 109,138 ---- return (mODEWorld != 0); } + + void World::DestroyODEObject() + { + static bool recurseLock = false; + if (recurseLock) + { + return; + } + + recurseLock = true; + + shared_ptr<Space> space = GetSpace(); + if (space.get() != 0) + { + space->DestroyODEObject(); + } + + if (mODEWorld == 0) + { + return; + } + + // release the ODE world + dWorldDestroy(mODEWorld); + mODEWorld = 0; + + recurseLock = false; + } |