[Opal-commits] opal/src Sensor.cpp,NONE,1.1 Sensor.h,NONE,1.1 Defines.h,1.46,1.47 DesiredPosMotor.cp
Status: Inactive
Brought to you by:
tylerstreeter
From: tylerstreeter <tyl...@us...> - 2005-02-08 21:55:35
|
Update of /cvsroot/opal/opal/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18602/src Modified Files: Defines.h DesiredPosMotor.cpp Motor.cpp Motor.h SConscript Simulator.cpp Simulator.h Solid.cpp Solid.h Added Files: Sensor.cpp Sensor.h Log Message: added a Sensor class --- NEW FILE: Sensor.h --- /************************************************************************* * * * Open Physics Abstraction Layer * * Copyright (C) 2004-2005 * * Alan Fischer ala...@gm... * * Andres Reinot an...@re... * * Tyler Streeter tyl...@gm... * * All rights reserved. * * Web: opal.sourceforge.net * * * * This library is free software; you can redistribute it and/or * * modify it under the terms of EITHER: * * (1) The GNU Lesser General Public License as published by the Free * * Software Foundation; either version 2.1 of the License, or (at * * your option) any later version. The text of the GNU Lesser * * General Public License is included with this library in the * * file license-LGPL.txt. * * (2) The BSD-style license that is included with this library in * * the file license-BSD.txt. * * * * This library is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files * * license-LGPL.txt and license-BSD.txt for more details. * * * *************************************************************************/ #ifndef OPAL_SENSOR_H #define OPAL_SENSOR_H #include "Defines.h" namespace opal { class Sensor { public: Sensor(); virtual ~Sensor(); /// Called regularly to update the Sensor. virtual void OPAL_CALL internal_update() = 0; /// Returns true if the Motor is enabled. virtual bool OPAL_CALL isEnabled()const; /// Sets whether the Motor can affect anything. virtual void OPAL_CALL setEnabled(bool e); /// Returns true if this Sensor depends on the given Solid. virtual bool OPAL_CALL internal_dependsOn(Solid* solid); protected: bool mEnabled; private: }; } #endif Index: Solid.cpp =================================================================== RCS file: /cvsroot/opal/opal/src/Solid.cpp,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** Solid.cpp 8 Feb 2005 04:59:05 -0000 1.13 --- Solid.cpp 8 Feb 2005 21:54:21 -0000 1.14 *************** *** 35,42 **** mEventHandler = NULL; setUserData(NULL); ! mPrevGlobalLinearVel.set(0.0, 0.0, 0.0); ! mPrevGlobalAngularVel.set(0.0, 0.0, 0.0); ! mGlobalLinearAccel.set(0.0, 0.0, 0.0); ! mGlobalAngularAccel.set(0.0, 0.0, 0.0); setLinearDamping(defaults::linearDamping); setAngularDamping(defaults::linearDamping); --- 35,42 ---- mEventHandler = NULL; setUserData(NULL); ! //mPrevGlobalLinearVel.set(0.0, 0.0, 0.0); ! //mPrevGlobalAngularVel.set(0.0, 0.0, 0.0); ! //mGlobalLinearAccel.set(0.0, 0.0, 0.0); ! //mGlobalAngularAccel.set(0.0, 0.0, 0.0); setLinearDamping(defaults::linearDamping); setAngularDamping(defaults::linearDamping); *************** *** 58,82 **** //} ! void Solid::internal_updateAcceleration(real dt) ! { ! Vec3r currentGlobalLinearVel = getGlobalLinearVel(); ! Vec3r currentGlobalAngularVel = getGlobalAngularVel(); ! mGlobalLinearAccel = (currentGlobalLinearVel - ! mPrevGlobalLinearVel) / dt; ! mGlobalAngularAccel = (currentGlobalAngularVel - ! mPrevGlobalAngularVel) / dt; ! mPrevGlobalLinearVel = currentGlobalLinearVel; ! mPrevGlobalAngularVel = currentGlobalAngularVel; ! } ! Vec3r Solid::getGlobalLinearAccel()const ! { ! return mGlobalLinearAccel; ! } ! Vec3r Solid::getGlobalAngularAccel()const ! { ! return mGlobalAngularAccel; ! } bool Solid::getStatic() --- 58,82 ---- //} ! //void Solid::internal_updateAcceleration(real dt) ! //{ ! // Vec3r currentGlobalLinearVel = getGlobalLinearVel(); ! // Vec3r currentGlobalAngularVel = getGlobalAngularVel(); ! // mGlobalLinearAccel = (currentGlobalLinearVel - ! // mPrevGlobalLinearVel) / dt; ! // mGlobalAngularAccel = (currentGlobalAngularVel - ! // mPrevGlobalAngularVel) / dt; ! // mPrevGlobalLinearVel = currentGlobalLinearVel; ! // mPrevGlobalAngularVel = currentGlobalAngularVel; ! //} ! //Vec3r Solid::getGlobalLinearAccel()const ! //{ ! // return mGlobalLinearAccel; ! //} ! //Vec3r Solid::getGlobalAngularAccel()const ! //{ ! // return mGlobalAngularAccel; ! //} bool Solid::getStatic() Index: Motor.h =================================================================== RCS file: /cvsroot/opal/opal/src/Motor.h,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** Motor.h 8 Feb 2005 04:59:05 -0000 1.26 --- Motor.h 8 Feb 2005 21:54:19 -0000 1.27 *************** *** 47,50 **** --- 47,51 ---- //bool getGlobal(); + /// Called regularly to update the Motor. virtual void OPAL_CALL internal_update() = 0; *************** *** 52,56 **** virtual bool OPAL_CALL isEnabled()const; ! /// Set whether the Motor can affect anything. virtual void OPAL_CALL setEnabled(bool e); --- 53,57 ---- virtual bool OPAL_CALL isEnabled()const; ! /// Sets whether the Motor can affect anything. virtual void OPAL_CALL setEnabled(bool e); *************** *** 61,68 **** --- 62,77 ---- virtual bool OPAL_CALL internal_dependsOn(Joint* joint); + /// Sets whether this is a custom Motor. Used internally to + /// track custom Motors which must not be destroyed by OPAL. + virtual void OPAL_CALL internal_setCustom(bool c); + + /// Returns true if this is a custom Motor. + virtual bool OPAL_CALL internal_isCustom(); + protected: virtual ~Motor(); bool mEnabled; + bool mIsCustom; private: Index: SConscript =================================================================== RCS file: /cvsroot/opal/opal/src/SConscript,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** SConscript 4 Feb 2005 04:52:29 -0000 1.4 --- SConscript 8 Feb 2005 21:54:19 -0000 1.5 *************** *** 8,20 **** Blueprint.h BlueprintManager.h - ConstForceMotor.h Defines.h DesiredPosMotor.h EventHandler.h FixedJoint.h Hinge2Joint.h HingeJoint.h Joint.h - LimitedForceMotor.h Matrix44r.h Motor.h --- 8,19 ---- Blueprint.h BlueprintManager.h Defines.h DesiredPosMotor.h EventHandler.h FixedJoint.h + GearedMotor.h Hinge2Joint.h HingeJoint.h Joint.h Matrix44r.h Motor.h *************** *** 25,28 **** --- 24,28 ---- Quaternion.h Rayr.h + Sensor.h ServoMotor.h Simulator.h *************** *** 31,34 **** --- 31,35 ---- Solid.h Space.h + ThrusterMotor.h UniversalJoint.h Vec3r.h *************** *** 40,51 **** Blueprint.cpp BlueprintManager.cpp - ConstForceMotor.cpp DesiredPosMotor.cpp Joint.cpp - LimitedForceMotor.cpp Motor.cpp ServoMotor.cpp Simulator.cpp Solid.cpp """) --- 41,53 ---- Blueprint.cpp BlueprintManager.cpp DesiredPosMotor.cpp + GearedMotor.cpp Joint.cpp Motor.cpp + Sensor.cpp ServoMotor.cpp Simulator.cpp Solid.cpp + ThrusterMotor.cpp """) Index: DesiredPosMotor.cpp =================================================================== RCS file: /cvsroot/opal/opal/src/DesiredPosMotor.cpp,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** DesiredPosMotor.cpp 8 Feb 2005 04:59:05 -0000 1.10 --- DesiredPosMotor.cpp 8 Feb 2005 21:54:18 -0000 1.11 *************** *** 54,57 **** --- 54,58 ---- mSolid = solid; mMode = m; + mEnabled = true; } Index: Simulator.h =================================================================== RCS file: /cvsroot/opal/opal/src/Simulator.h,v retrieving revision 1.64 retrieving revision 1.65 diff -C2 -d -r1.64 -r1.65 *** Simulator.h 8 Feb 2005 04:59:05 -0000 1.64 --- Simulator.h 8 Feb 2005 21:54:21 -0000 1.65 *************** *** 45,48 **** --- 45,49 ---- #include "DesiredPosMotor.h" #include "Blueprint.h" + #include "Sensor.h" namespace opal *************** *** 109,119 **** virtual void OPAL_CALL setMaxLinearVel(real max); ! virtual real OPAL_CALL getMaxLinearVel(); virtual void OPAL_CALL setMaxAngularVel(real max); ! virtual real OPAL_CALL getMaxAngularVel(); ! // solids virtual Solid* OPAL_CALL createSolid( const Matrix44r& transform=Matrix44r(), --- 110,122 ---- virtual void OPAL_CALL setMaxLinearVel(real max); ! virtual real OPAL_CALL getMaxLinearVel()const; virtual void OPAL_CALL setMaxAngularVel(real max); ! virtual real OPAL_CALL getMaxAngularVel()const; ! // SOLIDS ! ! /// Creates and returns a pointer to a Solid. virtual Solid* OPAL_CALL createSolid( const Matrix44r& transform=Matrix44r(), *************** *** 121,125 **** /// Marks the given Solid as garbage. ! virtual void OPAL_CALL destroySolid(Solid * solid); /// Marks all Solids in the Simulator as garbage. --- 124,128 ---- /// Marks the given Solid as garbage. ! virtual void OPAL_CALL destroySolid(Solid* s); /// Marks all Solids in the Simulator as garbage. *************** *** 128,135 **** virtual const std::vector<Solid*>& OPAL_CALL getSolids()const; ! // spaces ! virtual Space* OPAL_CALL createSpace(Space* parentSpace = NULL) = 0; - // joints virtual HingeJoint* OPAL_CALL createHingeJoint(Solid* solid1, Solid* solid2,const Point3r& anchor, const Vec3r& axis) = 0; --- 131,136 ---- virtual const std::vector<Solid*>& OPAL_CALL getSolids()const; ! // JOINTS virtual HingeJoint* OPAL_CALL createHingeJoint(Solid* solid1, Solid* solid2,const Point3r& anchor, const Vec3r& axis) = 0; *************** *** 154,163 **** /// Marks the given Joint as garbage. ! virtual void OPAL_CALL destroyJoint(Joint * joint); /// Marks all Joints in the Simulator as garbage. virtual void OPAL_CALL destroyAllJoints(); ! //motors virtual ThrusterMotor* OPAL_CALL createThrusterMotor(); --- 155,165 ---- /// Marks the given Joint as garbage. ! virtual void OPAL_CALL destroyJoint(Joint* j); /// Marks all Joints in the Simulator as garbage. virtual void OPAL_CALL destroyAllJoints(); ! // MOTORS ! virtual ThrusterMotor* OPAL_CALL createThrusterMotor(); *************** *** 170,202 **** virtual DesiredPosMotor* OPAL_CALL createDesiredPosMotor(); ! // custom motors must be created in a special way that uses this ! // function ! virtual void OPAL_CALL addCustomMotor(Motor* motor); /// Marks the given Motor as garbage. ! virtual void OPAL_CALL destroyMotor(Motor* motor); /// Marks all Motors in the Simulator as garbage. virtual void OPAL_CALL destroyAllMotors(); protected: virtual ~Simulator(); ! void addSolid(Solid * s); ! void removeSolid(Solid * s); ! void addJoint(Joint * j); ! void removeJoint(Joint * j); ! void addMotor(Motor * m); ! void removeMotor(Motor * m); ! void addSpace(Space * s); ! /// Destroys all objects in the Simulator marked as garbage. ! void collectGarbage(); real mStepSize; --- 172,222 ---- virtual DesiredPosMotor* OPAL_CALL createDesiredPosMotor(); ! /// Inform the Simulator of a custom Motor. Custom Motors are ! /// allocated and deallocated by the user ! virtual void OPAL_CALL registerCustomMotor(Motor* m); /// Marks the given Motor as garbage. ! virtual void OPAL_CALL destroyMotor(Motor* m); /// Marks all Motors in the Simulator as garbage. virtual void OPAL_CALL destroyAllMotors(); + // SENSORS + + /// Creates and returns a pointer to a Sensor. + virtual Solid* OPAL_CALL createSensor(); + + /// Marks the given Sensor as garbage. + virtual void OPAL_CALL destroySensor(Sensor* s); + + /// Marks all Sensors in the Simulator as garbage. + virtual void OPAL_CALL destroyAllSensors(); + + // SPACES + virtual Space* OPAL_CALL createSpace(Space* parentSpace = NULL) = 0; + protected: virtual ~Simulator(); ! /// Destroys all objects in the Simulator marked as garbage. ! void internal_collectGarbage(); ! void addSolid(Solid* s); ! void removeSolid(Solid* s); ! void addJoint(Joint* j); ! void removeJoint(Joint* j); ! void addMotor(Motor* m); ! void removeMotor(Motor* m); ! void addSensor(Sensor* s); ! ! void removeSensor(Sensor* s); ! ! void addSpace(Space* s); real mStepSize; *************** *** 214,228 **** std::vector<Joint*> mJointList; std::vector<Motor*> mMotorList; std::vector<Solid*> mSolidGarbageList; std::vector<Joint*> mJointGarbageList; std::vector<Motor*> mMotorGarbageList; ! /// Spaces are stored so the user doesn't have to destroy them; they ! /// get destroyed in Simulator::destroy. std::vector<Space*> mSpaceList; private: - }; } --- 234,249 ---- std::vector<Joint*> mJointList; std::vector<Motor*> mMotorList; + std::vector<Sensor*> mSensorList; std::vector<Solid*> mSolidGarbageList; std::vector<Joint*> mJointGarbageList; std::vector<Motor*> mMotorGarbageList; + std::vector<Sensor*> mSensorGarbageList; ! /// Spaces are stored here so the user doesn't have to destroy them; ! /// they get destroyed in Simulator::destroy. std::vector<Space*> mSpaceList; private: }; } --- NEW FILE: Sensor.cpp --- /************************************************************************* * * * Open Physics Abstraction Layer * * Copyright (C) 2004-2005 * * Alan Fischer ala...@gm... * * Andres Reinot an...@re... * * Tyler Streeter tyl...@gm... * * All rights reserved. * * Web: opal.sourceforge.net * * * * This library is free software; you can redistribute it and/or * * modify it under the terms of EITHER: * * (1) The GNU Lesser General Public License as published by the Free * * Software Foundation; either version 2.1 of the License, or (at * * your option) any later version. The text of the GNU Lesser * * General Public License is included with this library in the * * file license-LGPL.txt. * * (2) The BSD-style license that is included with this library in * * the file license-BSD.txt. * * * * This library is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files * * license-LGPL.txt and license-BSD.txt for more details. * * * *************************************************************************/ #include "Sensor.h" namespace opal { Sensor::Sensor() { mEnabled = false; } Sensor::~Sensor() { } bool Sensor::isEnabled()const { return mEnabled; } void Sensor::setEnabled(bool e) { mEnabled = e; } bool Sensor::internal_dependsOn(Solid* solid) { return false; } } Index: Defines.h =================================================================== RCS file: /cvsroot/opal/opal/src/Defines.h,v retrieving revision 1.46 retrieving revision 1.47 diff -C2 -d -r1.46 -r1.47 *** Defines.h 8 Feb 2005 04:59:05 -0000 1.46 --- Defines.h 8 Feb 2005 21:54:09 -0000 1.47 *************** *** 85,88 **** --- 85,89 ---- }; + // TODO: replace with SolidDesc struct struct BodyState { Index: Solid.h =================================================================== RCS file: /cvsroot/opal/opal/src/Solid.h,v retrieving revision 1.65 retrieving revision 1.66 diff -C2 -d -r1.65 -r1.66 *** Solid.h 8 Feb 2005 04:59:05 -0000 1.65 --- Solid.h 8 Feb 2005 21:54:21 -0000 1.66 *************** *** 57,65 **** virtual void OPAL_CALL internal_uploadTransformChanges() = 0; ! virtual void OPAL_CALL internal_updateAcceleration(real dt); ! virtual Vec3r OPAL_CALL getGlobalLinearAccel()const; ! virtual Vec3r OPAL_CALL getGlobalAngularAccel()const; virtual bool OPAL_CALL getStatic(); --- 57,65 ---- virtual void OPAL_CALL internal_uploadTransformChanges() = 0; ! //virtual void OPAL_CALL internal_updateAcceleration(real dt); ! //virtual Vec3r OPAL_CALL getGlobalLinearAccel()const; ! //virtual Vec3r OPAL_CALL getGlobalAngularAccel()const; virtual bool OPAL_CALL getStatic(); *************** *** 233,240 **** void* mUserData; ! Vec3r mPrevGlobalLinearVel; ! Vec3r mPrevGlobalAngularVel; ! Vec3r mGlobalLinearAccel; ! Vec3r mGlobalAngularAccel; real mLinearDamping; --- 233,240 ---- void* mUserData; ! //Vec3r mPrevGlobalLinearVel; ! //Vec3r mPrevGlobalAngularVel; ! //Vec3r mGlobalLinearAccel; ! //Vec3r mGlobalAngularAccel; real mLinearDamping; Index: Simulator.cpp =================================================================== RCS file: /cvsroot/opal/opal/src/Simulator.cpp,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** Simulator.cpp 8 Feb 2005 04:59:05 -0000 1.20 --- Simulator.cpp 8 Feb 2005 21:54:20 -0000 1.21 *************** *** 60,64 **** } ! collectGarbage(); while (!mSpaceList.empty()) --- 60,69 ---- } ! for (size_t i=0; i<mSensorList.size(); ++i) ! { ! mSensorGarbageList.push_back(mSensorList[i]); ! } ! ! internal_collectGarbage(); while (!mSpaceList.empty()) *************** *** 72,77 **** bool Simulator::simulate(real dt) { ! // go through all solids and see if their transforms have been ! // changed manually; if so, upload the changes to the system. for (size_t i = 0; i < mSolidList.size(); ++i) { --- 77,83 ---- bool Simulator::simulate(real dt) { ! // Go through all Solids and see if their transforms have been ! // changed manually; if so, upload the changes to the physics ! // engine. for (size_t i = 0; i < mSolidList.size(); ++i) { *************** *** 85,88 **** --- 91,95 ---- mTimeBuffer += dt; + // Use this to return true if at least one step occurred. bool stepOccurred = false; if (mTimeBuffer >= mStepSize) *************** *** 100,104 **** // TODO: Call some user-defined function here... ! // Update motors std::vector<Motor*>::iterator motorIter; for (motorIter = mMotorList.begin(); --- 107,119 ---- // TODO: Call some user-defined function here... ! // Update sensors. ! std::vector<Sensor*>::iterator sensorIter; ! for (sensorIter = mSensorList.begin(); ! sensorIter != mSensorList.end(); ++sensorIter) ! { ! (*sensorIter)->internal_update(); ! } ! ! // Update motors. std::vector<Motor*>::iterator motorIter; for (motorIter = mMotorList.begin(); *************** *** 108,112 **** } ! // Apply forces/torques std::vector<Solid*>::iterator solidIter; for (solidIter = mSolidList.begin(); --- 123,127 ---- } ! // Apply forces/torques to Solids. std::vector<Solid*>::iterator solidIter; for (solidIter = mSolidList.begin(); *************** *** 116,120 **** } ! // Update joints, check for broken joints std::vector<Joint*>::iterator jointIter; for (jointIter = mJointList.begin(); --- 131,135 ---- } ! // Update joints, check for broken joints. std::vector<Joint*>::iterator jointIter; for (jointIter = mJointList.begin(); *************** *** 126,130 **** if (j->internal_isBroken()) { ! // send joint break event j->internal_handleJointBreakEvent(); --- 141,145 ---- if (j->internal_isBroken()) { ! // Send a Joint break event. j->internal_handleJointBreakEvent(); *************** *** 152,156 **** internal_stepPhysics(); ! // loop over solids again for (solidIter = mSolidList.begin(); solidIter != mSolidList.end(); ++solidIter) --- 167,171 ---- internal_stepPhysics(); ! // Loop over Solids again. for (solidIter = mSolidList.begin(); solidIter != mSolidList.end(); ++solidIter) *************** *** 158,162 **** Solid* solid = *solidIter; ! // cap velocities Vec3r linearVel = solid->getGlobalLinearVel(); if (linearVel[0] > mMaxLinearVel) --- 173,177 ---- Solid* solid = *solidIter; ! // Cap velocities. Vec3r linearVel = solid->getGlobalLinearVel(); if (linearVel[0] > mMaxLinearVel) *************** *** 189,197 **** solid->setGlobalAngularVel(angularVel); ! // get each solid's new transform from the physics engine solid->internal_updateTransform(); ! // update accelerations ! solid->internal_updateAcceleration(dt); } --- 204,212 ---- solid->setGlobalAngularVel(angularVel); ! // Get each solid's new transform from the physics engine. solid->internal_updateTransform(); ! //// Update accelerations ! //solid->internal_updateAcceleration(dt); } *************** *** 315,318 **** --- 330,334 ---- Vec3r axis2 = (*jointIter).second.axis2; + // TODO: finish this... switch((*jointIter).second.type) { *************** *** 415,419 **** } ! real Simulator::getMaxLinearVel() { return mMaxLinearVel; --- 431,435 ---- } ! real Simulator::getMaxLinearVel()const { return mMaxLinearVel; *************** *** 426,437 **** } ! real Simulator::getMaxAngularVel() { return mMaxAngularVel; } ! void Simulator::destroySolid(Solid * solid) { ! mSolidGarbageList.push_back(solid); } --- 442,453 ---- } ! real Simulator::getMaxAngularVel()const { return mMaxAngularVel; } ! void Simulator::destroySolid(Solid* s) { ! mSolidGarbageList.push_back(s); } *************** *** 452,458 **** } ! void Simulator::destroyJoint(Joint * joint) { ! mJointGarbageList.push_back(joint); } --- 468,474 ---- } ! void Simulator::destroyJoint(Joint* j) { ! mJointGarbageList.push_back(j); } *************** *** 496,508 **** } ! //custom motors must be created in a special way that uses this function ! void Simulator::addCustomMotor(Motor* motor) { ! addMotor(motor); } ! void Simulator::destroyMotor(Motor* motor) { ! mMotorGarbageList.push_back(motor); } --- 512,523 ---- } ! void Simulator::registerCustomMotor(Motor* m) { ! addMotor(m); } ! void Simulator::destroyMotor(Motor* m) { ! mMotorGarbageList.push_back(m); } *************** *** 518,521 **** --- 533,562 ---- } + Solid* Simulator::createSensor() + { + //Sensor* newSensor = new Sensor(); + //addSensor(newSensor); + //return newSensor; + + // Temporary... + return NULL; + } + + void Simulator::destroySensor(Sensor* s) + { + mSensorGarbageList.push_back(s); + } + + void Simulator::destroyAllSensors() + { + // Just mark everything as garbage; it'll get destroyed at the end of + // the current step. + + for (size_t i=0; i<mSensorList.size(); ++i) + { + mSensorGarbageList.push_back(mSensorList[i]); + } + } + void Simulator::setSleepiness(real value) { *************** *** 538,547 **** } ! void Simulator::addSolid(Solid * s) { mSolidList.push_back(s); } ! void Simulator::removeSolid(Solid * s) { // TODO: make this more efficient by not iterating through all Motors --- 579,588 ---- } ! void Simulator::addSolid(Solid* s) { mSolidList.push_back(s); } ! void Simulator::removeSolid(Solid* s) { // TODO: make this more efficient by not iterating through all Motors *************** *** 569,572 **** --- 610,623 ---- } + // Disable Sensors that depend on the given Solid. + std::vector<Sensor*>::iterator iter3; + for (iter3 = mSensorList.begin(); iter3 != mSensorList.end(); ++iter3) + { + if ((*iter3)->internal_dependsOn(s)) + { + (*iter3)->setEnabled(false); + } + } + // Now remove the Solid. for(size_t i = 0; i<mSolidList.size(); ++i) *************** *** 584,593 **** } ! void Simulator::addJoint(Joint * j) { mJointList.push_back(j); } ! void Simulator::removeJoint(Joint * j) { // TODO: make this more efficient by not iterating through all Motors --- 635,644 ---- } ! void Simulator::addJoint(Joint* j) { mJointList.push_back(j); } ! void Simulator::removeJoint(Joint* j) { // TODO: make this more efficient by not iterating through all Motors *************** *** 620,629 **** } ! void Simulator::addMotor(Motor * m) { mMotorList.push_back(m); } ! void Simulator::removeMotor(Motor * m) { for(size_t i = 0; i<mMotorList.size(); ++i) --- 671,680 ---- } ! void Simulator::addMotor(Motor* m) { mMotorList.push_back(m); } ! void Simulator::removeMotor(Motor* m) { for(size_t i = 0; i<mMotorList.size(); ++i) *************** *** 631,636 **** if(mMotorList[i] == m) { ! //delete m; ! m->internal_destroy(); mMotorList[i] = mMotorList.back(); mMotorList.pop_back(); --- 682,690 ---- if(mMotorList[i] == m) { ! if (!m->internal_isCustom()) ! { ! //delete m; ! m->internal_destroy(); ! } mMotorList[i] = mMotorList.back(); mMotorList.pop_back(); *************** *** 641,650 **** } ! void Simulator::addSpace(Space * s) { mSpaceList.push_back(s); } ! void Simulator::collectGarbage() { for (size_t i=0; i<mSolidGarbageList.size(); ++i) --- 695,725 ---- } ! void Simulator::addSensor(Sensor* s) ! { ! mSensorList.push_back(s); ! } ! ! void Simulator::removeSensor(Sensor* s) ! { ! for(size_t i = 0; i<mSensorList.size(); ++i) ! { ! if(mSensorList[i] == s) ! { ! delete s; ! //s->internal_destroy(); ! mSensorList[i] = mSensorList.back(); ! mSensorList.pop_back(); ! ! return; ! } ! } ! } ! ! void Simulator::addSpace(Space* s) { mSpaceList.push_back(s); } ! void Simulator::internal_collectGarbage() { for (size_t i=0; i<mSolidGarbageList.size(); ++i) Index: Motor.cpp =================================================================== RCS file: /cvsroot/opal/opal/src/Motor.cpp,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** Motor.cpp 8 Feb 2005 04:59:05 -0000 1.8 --- Motor.cpp 8 Feb 2005 21:54:18 -0000 1.9 *************** *** 32,37 **** Motor::Motor() { - //mGlobal = isGlobal; mEnabled = false; } --- 32,37 ---- Motor::Motor() { mEnabled = false; + mIsCustom = false; } *************** *** 59,61 **** --- 59,71 ---- return false; } + + void Motor::internal_setCustom(bool c) + { + mIsCustom = c; + } + + bool Motor::internal_isCustom() + { + return mIsCustom; + } } |