[Opal-commits] opal/src CollisionEventHandler.h,1.2,1.3 Simulator.cpp,1.56,1.57 Simulator.h,1.94,1.9
Status: Inactive
Brought to you by:
tylerstreeter
|
From: tylerstreeter <tyl...@us...> - 2005-04-08 20:46:10
|
Update of /cvsroot/opal/opal/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23067/src Modified Files: CollisionEventHandler.h Simulator.cpp Simulator.h Log Message: added a fix to make solid and joint destruction (even more) safe during event handling Index: CollisionEventHandler.h =================================================================== RCS file: /cvsroot/opal/opal/src/CollisionEventHandler.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** CollisionEventHandler.h 21 Mar 2005 05:52:09 -0000 1.2 --- CollisionEventHandler.h 8 Apr 2005 20:46:00 -0000 1.3 *************** *** 68,72 **** }; ! /// A listener that gets notified when two Solids touch. class CollisionEventHandler : public EventHandler { --- 68,75 ---- }; ! /// A listener that gets notified when two Solids touch. These events ! /// get handled at the end of the time step, which is necessary because ! /// some physics engines cannot update objects in the middle of a time ! /// step (e.g. in the middle of collision detection). class CollisionEventHandler : public EventHandler { Index: Simulator.cpp =================================================================== RCS file: /cvsroot/opal/opal/src/Simulator.cpp,v retrieving revision 1.56 retrieving revision 1.57 diff -C2 -d -r1.56 -r1.57 *** Simulator.cpp 6 Apr 2005 04:48:44 -0000 1.56 --- Simulator.cpp 8 Apr 2005 20:46:00 -0000 1.57 *************** *** 53,56 **** --- 53,58 ---- setUserData(NULL); setPostStepEventHandler(NULL); + mIsSolidDestructionSafe = true; + mIsJointDestructionSafe = true; int i=0; *************** *** 73,76 **** --- 75,81 ---- mSpaceList.pop_back(); } + + mSolidGarbageList.clear(); + mJointGarbageList.clear(); } *************** *** 172,175 **** --- 177,181 ---- // Update Joints. + mIsJointDestructionSafe = false; std::vector<Joint*>::iterator jointIter; for (jointIter = mJointList.begin(); *************** *** 181,184 **** --- 187,191 ---- (*jointIter)->internal_update(); } + mIsJointDestructionSafe = true; // Now do physics engine-specific stuff; collision events will *************** *** 187,190 **** --- 194,198 ---- // Loop over Solids again to handle a few more things... + mIsSolidDestructionSafe = false; for (solidIter = mSolidList.begin(); solidIter != mSolidList.end(); ++solidIter) *************** *** 206,209 **** --- 214,218 ---- } } + mIsSolidDestructionSafe = true; // Fire an event to the PostStepEventHandler, if one exists. *************** *** 213,216 **** --- 222,228 ---- } + // Destroy garbage now that it's safe. + destroyGarbage(); + //Decrement the time buffer mTimeBuffer -= mStepSize; *************** *** 751,755 **** void Simulator::destroySolid(Solid* s) { ! removeSolid(s); } --- 763,774 ---- void Simulator::destroySolid(Solid* s) { ! if (mIsSolidDestructionSafe) ! { ! removeSolid(s); ! } ! else ! { ! mSolidGarbageList.push_back(s); ! } } *************** *** 764,768 **** void Simulator::destroyJoint(Joint* j) { ! removeJoint(j); } --- 783,794 ---- void Simulator::destroyJoint(Joint* j) { ! if (mIsJointDestructionSafe) ! { ! removeJoint(j); ! } ! else ! { ! mJointGarbageList.push_back(j); ! } } *************** *** 1018,1020 **** --- 1044,1063 ---- mSpaceList.push_back(s); } + + void Simulator::destroyGarbage() + { + // Destroy garbage Solids. + while (!mSolidGarbageList.empty()) + { + destroySolid(mSolidGarbageList.back()); + mSolidGarbageList.pop_back(); + } + + // Destroy garbage Joints. + while (!mJointGarbageList.empty()) + { + destroyJoint(mJointGarbageList.back()); + mJointGarbageList.pop_back(); + } + } } Index: Simulator.h =================================================================== RCS file: /cvsroot/opal/opal/src/Simulator.h,v retrieving revision 1.94 retrieving revision 1.95 diff -C2 -d -r1.94 -r1.95 *** Simulator.h 6 Apr 2005 04:48:44 -0000 1.94 --- Simulator.h 8 Apr 2005 20:46:00 -0000 1.95 *************** *** 300,303 **** --- 300,307 ---- void addSpace(Space* s); + /// Destroys all objects marked as garbage. Useful for destroying + /// objects at safe times. + void destroyGarbage(); + /// The constant step size used to break arbitrary simulation dt /// values into constant chunks. *************** *** 337,340 **** --- 341,358 ---- std::vector<Sensor*> mSensorList; + /// True when it is safe to destroy a Solid (e.g. not in the middle + /// of looping over all the Solid). + bool mIsSolidDestructionSafe; + + /// True when it is safe to destroy a Joint (e.g. not in the middle + /// of looping over all the Joint). + bool mIsJointDestructionSafe; + + /// An internal list of Solids marked as garbage. + std::vector<Solid*> mSolidGarbageList; + + /// An internal list of Joints marked as garbage. + std::vector<Joint*> mJointGarbageList; + /// Spaces are stored here so the user doesn't have to destroy them; /// they get destroyed when the Simulator is destroyed. |