You can subscribe to this list here.
| 2006 |
Jan
|
Feb
|
Mar
|
Apr
(24) |
May
(5) |
Jun
(11) |
Jul
(17) |
Aug
(1) |
Sep
(11) |
Oct
|
Nov
|
Dec
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2007 |
Jan
|
Feb
|
Mar
(2) |
Apr
(1) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2008 |
Jan
(2) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|
From: <st...@us...> - 2006-07-20 00:58:21
|
Revision: 445 Author: stenyak Date: 2006-07-19 17:57:58 -0700 (Wed, 19 Jul 2006) ViewCVS: http://svn.sourceforge.net/motorsport/?rev=445&view=rev Log Message: ----------- Refactored some Vehicle methods and properties into WorldObject class. Modified Paths: -------------- trunk/src/common/camera.cpp trunk/src/common/worldObject.cpp trunk/src/vehicle/body.cpp trunk/src/vehicle/driveJoint.cpp trunk/src/vehicle/engine.cpp trunk/src/vehicle/finalDrive.cpp trunk/src/vehicle/suspension.cpp trunk/src/vehicle/suspension.hpp trunk/src/vehicle/vehicle.cpp trunk/src/vehicle/vehicle.hpp trunk/src/vehicle/wheel.cpp trunk/src/world/area.cpp trunk/src/world/part.cpp trunk/src/world/world.cpp trunk/src/world/world.hpp Modified: trunk/src/common/camera.cpp =================================================================== --- trunk/src/common/camera.cpp 2006-07-20 00:00:33 UTC (rev 444) +++ trunk/src/common/camera.cpp 2006-07-20 00:57:58 UTC (rev 445) @@ -143,6 +143,7 @@ void Camera::stepPhysics () { + WorldObject::stepPhysics(); if (World::get()->isActiveCamera(boost::dynamic_pointer_cast<Camera>(shared_from_this()))) { static bool wasPressed = false; Modified: trunk/src/common/worldObject.cpp =================================================================== --- trunk/src/common/worldObject.cpp 2006-07-20 00:00:33 UTC (rev 444) +++ trunk/src/common/worldObject.cpp 2006-07-20 00:57:58 UTC (rev 445) @@ -52,13 +52,22 @@ { std::string oldName = getFullName(); this->container = container; - this->path = container->getPath(); - this->xmlPath = container->getPath(); + //if container == NULL then this is the root container, and its paths have already been set. + if (container != NULL) + { + this->path = container->getPath(); + this->xmlPath = container->getPath(); + } OdeObjectsIt j = odeObjects.begin(); for(;j != odeObjects.end(); j++) { dBodySetData (j->second->getBodyID(), (void*) container.get()); } + pWorldObject t = shared_from_this(); + for (WorldObjectsIt i = objects.begin(); i != objects.end(); i++) + { + if (i->second) i->second->setContainer(t); + } log->setName(this->getFullName()); log->__format(LOG_CCREATOR, "New container! Old full name: %s. New full name: %s", oldName.c_str(), getFullName().c_str()); @@ -112,7 +121,6 @@ else if (dynamic_cast<World *> (this)) type = "world"; else if (dynamic_cast<Camera *> (this)) type = "camera"; else if (dynamic_cast<WorldObject *> (this)) type = "worldobject"; - else log->__format(LOG_ERROR, "Couldn't find out object #%s type. This should *NOT* have happened.", getId().c_str()); return "(" + type + ")" + name; } void WorldObject::setName(std::string name) @@ -161,9 +169,19 @@ void WorldObject::stepPhysics () { WorldObjectsIt i = objects.begin(); - for (; i != objects.end(); i++) + //step torque transfer objects first + for (i = objects.begin(); i != objects.end(); i++) { if (0); + else if (pGear tmp = boost::dynamic_pointer_cast<Gear >(i->second)) tmp->stepPhysics(); + else if (pLSD tmp = boost::dynamic_pointer_cast<LSD >(i->second)) tmp->stepPhysics(); + else if (pClutch tmp = boost::dynamic_pointer_cast<Clutch >(i->second)) tmp->stepPhysics(); + else if (pDriveJoint tmp = boost::dynamic_pointer_cast<DriveJoint >(i->second)) tmp->stepPhysics(); + } + //step the rest of objects + for (i = objects.begin(); i != objects.end(); i++) + { + if (0); else if (pDoubleWishbone tmp = boost::dynamic_pointer_cast<DoubleWishbone>(i->second)) tmp->stepPhysics(); else if (pFixed tmp = boost::dynamic_pointer_cast<Fixed >(i->second)) tmp->stepPhysics(); else if (pUnidimensional tmp = boost::dynamic_pointer_cast<Unidimensional>(i->second)) tmp->stepPhysics(); @@ -173,10 +191,6 @@ else if (pWheel tmp = boost::dynamic_pointer_cast<Wheel >(i->second)) tmp->stepPhysics(); else if (pFinalDrive tmp = boost::dynamic_pointer_cast<FinalDrive >(i->second)) tmp->stepPhysics(); else if (pDriveMass tmp = boost::dynamic_pointer_cast<DriveMass >(i->second)) tmp->stepPhysics(); - else if (pGear tmp = boost::dynamic_pointer_cast<Gear >(i->second)) tmp->stepPhysics(); - else if (pLSD tmp = boost::dynamic_pointer_cast<LSD >(i->second)) tmp->stepPhysics(); - else if (pClutch tmp = boost::dynamic_pointer_cast<Clutch >(i->second)) tmp->stepPhysics(); - else if (pDriveJoint tmp = boost::dynamic_pointer_cast<DriveJoint >(i->second)) tmp->stepPhysics(); else if (pGearboxGear tmp = boost::dynamic_pointer_cast<GearboxGear >(i->second)) tmp->stepPhysics(); else if (pBody tmp = boost::dynamic_pointer_cast<Body >(i->second)) tmp->stepPhysics(); else if (pPedal tmp = boost::dynamic_pointer_cast<Pedal >(i->second)) tmp->stepPhysics(); @@ -186,7 +200,6 @@ else if (pWorld tmp = boost::dynamic_pointer_cast<World >(i->second)) tmp->stepPhysics(); else if (pCamera tmp = boost::dynamic_pointer_cast<Camera >(i->second)) tmp->stepPhysics(); else if (pWorldObject tmp = boost::dynamic_pointer_cast<WorldObject >(i->second)) tmp->stepPhysics(); - else log->__format(LOG_ERROR, "Couldn't find out object #%s (%s) type. This should *NOT* have happened.", i->second->getId().c_str(), i->first.c_str()); } } void WorldObject::stepGraphics () @@ -222,7 +235,6 @@ else if (pWorld tmp = boost::dynamic_pointer_cast<World >(i->second)) tmp->stepGraphics(); else if (pCamera tmp = boost::dynamic_pointer_cast<Camera >(i->second)) tmp->stepGraphics(); else if (pWorldObject tmp = boost::dynamic_pointer_cast<WorldObject >(i->second)) tmp->stepGraphics(); - else log->__format(LOG_ERROR, "Couldn't find out object #%s (%s) type. This should *NOT* have happened.", i->second->getId().c_str(), i->first.c_str()); } } void WorldObject::setPosition (Vector3d position) Modified: trunk/src/vehicle/body.cpp =================================================================== --- trunk/src/vehicle/body.cpp 2006-07-20 00:00:33 UTC (rev 444) +++ trunk/src/vehicle/body.cpp 2006-07-20 00:57:58 UTC (rev 445) @@ -79,6 +79,7 @@ void Body::stepPhysics () { + WorldObject::stepPhysics(); dBodyID bodyID = getMainOdeObject()->getBodyID(); if (userDriver) { Modified: trunk/src/vehicle/driveJoint.cpp =================================================================== --- trunk/src/vehicle/driveJoint.cpp 2006-07-20 00:00:33 UTC (rev 444) +++ trunk/src/vehicle/driveJoint.cpp 2006-07-20 00:57:58 UTC (rev 445) @@ -166,6 +166,7 @@ void Clutch::stepPhysics () { + WorldObject::stepPhysics(); if(enabled) { double clutch = clutchPedal->getNormalizedAngle(); if(clutch) { @@ -196,59 +197,61 @@ void Gear::stepPhysics () { - if(enabled) { - double dt; - dt = System::get()->getDesiredPhysicsTimestep(); - prevRelAngle = relAngle; - prevRelAngularVel = relAngularVel; + WorldObject::stepPhysics(); + if(enabled) { + double dt; + dt = System::get()->getDesiredPhysicsTimestep(); + prevRelAngle = relAngle; + prevRelAngularVel = relAngularVel; - relAngularVel = inputDrive->getOutputAngularVel()/ratio - outputDrive->getInputAngularVel(); + relAngularVel = inputDrive->getOutputAngularVel()/ratio - outputDrive->getInputAngularVel(); - // trapezoidal integration - relAngle = prevRelAngle + dt / 2 * (prevRelAngularVel + relAngularVel); + // trapezoidal integration + relAngle = prevRelAngle + dt / 2 * (prevRelAngularVel + relAngularVel); -// relAngle = relAngle + inputDrive->getOutputAngularVel()*dt/ratio - outputDrive->getInputAngularVel()*dt; - - outputTorqueTransfer = springConstant*relAngle+dampConstant*relAngularVel; - - inputTorqueTransfer = -1*outputTorqueTransfer/ratio; - - inputDrive->addOutputTorque(inputTorqueTransfer); - outputDrive->addInputTorque(outputTorqueTransfer); - - //log->__format(LOG_DEVELOPER, "inTorque=%f outTorque=%f relVel=%f relAngle=%f", inputTorqueTransfer, outputTorqueTransfer,relAngularVel,relAngle); - } - else { - relAngle = 0; - } + // relAngle = relAngle + inputDrive->getOutputAngularVel()*dt/ratio - outputDrive->getInputAngularVel()*dt; + + outputTorqueTransfer = springConstant*relAngle+dampConstant*relAngularVel; + + inputTorqueTransfer = -1*outputTorqueTransfer/ratio; + + inputDrive->addOutputTorque(inputTorqueTransfer); + outputDrive->addInputTorque(outputTorqueTransfer); + + //log->__format(LOG_DEVELOPER, "inTorque=%f outTorque=%f relVel=%f relAngle=%f", inputTorqueTransfer, outputTorqueTransfer,relAngularVel,relAngle); + } + else { + relAngle = 0; + } } void LSD::stepPhysics () { - if(enabled) { - double dt; - dt = System::get()->getDesiredPhysicsTimestep(); - prevRelAngle = relAngle; - prevRelAngularVel = relAngularVel; + WorldObject::stepPhysics(); + if(enabled) { + double dt; + dt = System::get()->getDesiredPhysicsTimestep(); + prevRelAngle = relAngle; + prevRelAngularVel = relAngularVel; - relAngularVel = inputDrive->getOutputAngularVel()/ratio - (outputDrive->getInputAngularVel()+outputDrive2->getInputAngularVel())/2; + relAngularVel = inputDrive->getOutputAngularVel()/ratio - (outputDrive->getInputAngularVel()+outputDrive2->getInputAngularVel())/2; - // trapezoidal integration - relAngle = prevRelAngle + dt / 2 * (prevRelAngularVel + relAngularVel); + // trapezoidal integration + relAngle = prevRelAngle + dt / 2 * (prevRelAngularVel + relAngularVel); -// relAngle = relAngle + inputDrive->getOutputAngularVel()*dt/ratio - outputDrive->getInputAngularVel()*dt; - - outputTorqueTransfer = springConstant*relAngle+dampConstant*relAngularVel; - - inputTorqueTransfer = -1*outputTorqueTransfer/ratio; - - inputDrive->addOutputTorque(inputTorqueTransfer); - outputDrive->addInputTorque(outputTorqueTransfer/2); - outputDrive2->addInputTorque(outputTorqueTransfer/2); - - //log->__format(LOG_DEVELOPER, "inTorque=%f outTorque=%f relVel=%f relAngle=%f", inputTorqueTransfer, outputTorqueTransfer,relAngularVel,relAngle); - } - else { - relAngle = 0; - } + // relAngle = relAngle + inputDrive->getOutputAngularVel()*dt/ratio - outputDrive->getInputAngularVel()*dt; + + outputTorqueTransfer = springConstant*relAngle+dampConstant*relAngularVel; + + inputTorqueTransfer = -1*outputTorqueTransfer/ratio; + + inputDrive->addOutputTorque(inputTorqueTransfer); + outputDrive->addInputTorque(outputTorqueTransfer/2); + outputDrive2->addInputTorque(outputTorqueTransfer/2); + + //log->__format(LOG_DEVELOPER, "inTorque=%f outTorque=%f relVel=%f relAngle=%f", inputTorqueTransfer, outputTorqueTransfer,relAngularVel,relAngle); + } + else { + relAngle = 0; + } } Modified: trunk/src/vehicle/engine.cpp =================================================================== --- trunk/src/vehicle/engine.cpp 2006-07-20 00:00:33 UTC (rev 444) +++ trunk/src/vehicle/engine.cpp 2006-07-20 00:57:58 UTC (rev 445) @@ -50,7 +50,8 @@ void Engine::stepPhysics () { -// double dtoverJe; + WorldObject::stepPhysics(); + // double dtoverJe; double engineTorque; double gas = gasPedal->getNormalizedAngle(); @@ -60,24 +61,24 @@ } else { engineTorque = ((torqueLinearMultiplier/2) + (inputAngularVel * (torqueLinearMultiplier/2) / angularVelLimit)) * gas; } - + double dt; double torqueSum; - + dt = System::get()->getDesiredPhysicsTimestep(); prevAngularVel = inputAngularVel; -// inputTorqueTransfer = inputJoint->getOutputTorque(); -// outputTorqueTransfer += outputJoint->getInputTorque(); + // inputTorqueTransfer = inputJoint->getOutputTorque(); + // outputTorqueTransfer += outputJoint->getInputTorque(); torqueSum = outputTorqueTransfer + engineTorque; angularAcc = (torqueSum - friction * prevAngularVel)/inertia; - + // improved Euler ODE solve inputAngularVel = prevAngularVel + dt / 2 * (angularAcc + (torqueSum - friction*(prevAngularVel + angularAcc*dt))/inertia); outputAngularVel = inputAngularVel; -/* dtoverJe=dt/inertia; - inputAngularVel = (dtoverJe*(engineTorque+outputJoint->getInputTorque())+prevAngularVel)/(1+(dtoverJe*friction)); - angularAcc = (inputAngularVel-prevAngularVel)/ dt; - outputAngularVel = inputAngularVel; */ + /* dtoverJe=dt/inertia; + inputAngularVel = (dtoverJe*(engineTorque+outputJoint->getInputTorque())+prevAngularVel)/(1+(dtoverJe*friction)); + angularAcc = (inputAngularVel-prevAngularVel)/ dt; + outputAngularVel = inputAngularVel; */ //log->__format(LOG_DEVELOPER, "engineTorque=%f(Nm) angAcc=%f engspeed=%f(rad/s)", engineTorque, angularAcc, inputAngularVel); telemetryTorque = engineTorque; inputTorqueTransfer = 0; Modified: trunk/src/vehicle/finalDrive.cpp =================================================================== --- trunk/src/vehicle/finalDrive.cpp 2006-07-20 00:00:33 UTC (rev 444) +++ trunk/src/vehicle/finalDrive.cpp 2006-07-20 00:57:58 UTC (rev 445) @@ -46,6 +46,7 @@ void FinalDrive::stepPhysics () { + WorldObject::stepPhysics(); double dt; double torqueSum; Modified: trunk/src/vehicle/suspension.cpp =================================================================== --- trunk/src/vehicle/suspension.cpp 2006-07-20 00:00:33 UTC (rev 444) +++ trunk/src/vehicle/suspension.cpp 2006-07-20 00:57:58 UTC (rev 445) @@ -162,6 +162,7 @@ } void Unidimensional::stepPhysics() { + WorldObject::stepPhysics(); double angle = getSteeringAngle(); // Set wheel steering limits. one needs to be done before the other, can't recall which one, so it's dupped dJointSetHinge2Param (jointID, dParamHiStop, angle+0.0000001); @@ -228,10 +229,6 @@ jointID = dJointCreateHinge (World::get()->worldID, 0); dJointAttach (jointID, 0, 0); } -void Fixed::stepPhysics() -{ - // Empty... -} Fixed::~Fixed() { dJointDestroy (jointID); @@ -429,6 +426,7 @@ } void DoubleWishbone::stepPhysics() { + WorldObject::stepPhysics(); //compute steering double angle = getSteeringAngle(); //if (right) angle *= -1; Modified: trunk/src/vehicle/suspension.hpp =================================================================== --- trunk/src/vehicle/suspension.hpp 2006-07-20 00:00:33 UTC (rev 444) +++ trunk/src/vehicle/suspension.hpp 2006-07-20 00:57:58 UTC (rev 445) @@ -39,7 +39,6 @@ void setPosition (Vector3d position); Vector3d getPosition(); - virtual void stepPhysics ()=0; virtual double getRate()=0; virtual Vector3d getAxis()=0; virtual void setVelocity(double velocity)=0; @@ -77,7 +76,6 @@ static pFixed create(XmlTag * tag); ~Fixed(); - void stepPhysics(); double getRate(); Vector3d getAxis(); void setVelocity(double velocity); Modified: trunk/src/vehicle/vehicle.cpp =================================================================== --- trunk/src/vehicle/vehicle.cpp 2006-07-20 00:00:33 UTC (rev 444) +++ trunk/src/vehicle/vehicle.cpp 2006-07-20 00:57:58 UTC (rev 445) @@ -49,12 +49,12 @@ Vehicle::~Vehicle () { - log->__format(LOG_DEVELOPER, "Deleting components"); - for (WorldObjectsIt i = components.begin(); i != components.end(); i++) + log->__format(LOG_DEVELOPER, "Deleting objects"); + for (WorldObjectsIt i = objects.begin(); i != objects.end(); i++) { delete (i->second); } - components.clear(); + objects.clear(); } void Vehicle::setUserDriver () @@ -67,7 +67,7 @@ getGearbox("main")->setGear(2); // spread the news to the necessary (input-able) vehicle parts - for (WorldObjectsIt i = components.begin(); i != components.end(); i++) + for (WorldObjectsIt i = objects.begin(); i != objects.end(); i++) { pBody tmpBody; if ( (tmpBody = boost::dynamic_pointer_cast<Body>(i->second))) tmpBody->setUserDriver(); @@ -90,37 +90,37 @@ contact = tag->getAttribute("contact"); license = tag->getAttribute("license"); - pLSD lsd = LSD::create(); lsd->setName("rear diff"); components[lsd->getName()] = lsd; - pGear gear = Gear::create(); gear->setName("transfer"); components[gear->getName()] = gear; + pLSD lsd = LSD::create(); lsd->setName("rear diff"); objects[lsd->getName()] = lsd; + pGear gear = Gear::create(); gear->setName("transfer"); objects[gear->getName()] = gear; XmlTag * t = tag->getTag(0); for (int i = 0; i < tag->nTags(); t = tag->getTag(++i)) { bool u=false; //update graphics display; render one frame if (t->getName() == "body") - { pBody tmp = Body::create(t); components[tmp->getName()]=tmp; } + { pBody tmp = Body::create(t); objects[tmp->getName()]=tmp; } if (t->getName() == "engine") - { pEngine tmp = Engine::create(t); components[tmp->getName()]=tmp; } + { pEngine tmp = Engine::create(t); objects[tmp->getName()]=tmp; } if (t->getName() == "clutch") - { pClutch tmp = Clutch::create(t); components[tmp->getName()]=tmp; } + { pClutch tmp = Clutch::create(t); objects[tmp->getName()]=tmp; } if (t->getName() == "gearbox") - { pGearbox tmp = Gearbox::create(t); components[tmp->getName()]=tmp; } + { pGearbox tmp = Gearbox::create(t); objects[tmp->getName()]=tmp; } if (t->getName() == "finalDrive") - { pFinalDrive tmp = FinalDrive::create(t); components[tmp->getName()]=tmp; } + { pFinalDrive tmp = FinalDrive::create(t); objects[tmp->getName()]=tmp; } if (t->getName() == "pedal") - { pPedal tmp = Pedal::create(t); components[tmp->getName()]=tmp; } + { pPedal tmp = Pedal::create(t); objects[tmp->getName()]=tmp; } if (t->getName() == "wheel") - { pWheel tmp = Wheel::create(t); components[tmp->getName()]=tmp; u=true;} + { pWheel tmp = Wheel::create(t); objects[tmp->getName()]=tmp; u=true;} if (t->getName() == "suspension.unidimensional") - { pUnidimensional tmp = Unidimensional::create(t); components[tmp->getName()]=tmp; u=true;} + { pUnidimensional tmp = Unidimensional::create(t); objects[tmp->getName()]=tmp; u=true;} if (t->getName() == "suspension.fixed") - { pFixed tmp = Fixed::create(t); components[tmp->getName()]=tmp; u=true;} + { pFixed tmp = Fixed::create(t); objects[tmp->getName()]=tmp; u=true;} if (t->getName() == "suspension.doublewishbone") - { pDoubleWishbone tmp = DoubleWishbone::create(t); components[tmp->getName()]=tmp; u=true;} + { pDoubleWishbone tmp = DoubleWishbone::create(t); objects[tmp->getName()]=tmp; u=true;} if (t->getName() == "camera") - { pCamera tmp = Camera::create(t); cameras[tmp->getName()]=tmp; u=true;} + { pCamera tmp = Camera::create(t); objects[tmp->getName()]=tmp; u=true;} if (u) System::get()->ogreWindow->update (); } } - //initialize cameras... + //initialize objects... pointCameras(); // spread the news to the necessary (input-able) vehicle parts log->__format(LOG_DEVELOPER, "Setting some drive joint pointers..."); @@ -142,7 +142,7 @@ getEngine("main")->setGasPedal(getPedal("gas")); getClutch("main")->setClutchPedal(getPedal("clutch")); - for (WorldObjectsIt i = components.begin(); i != components.end(); i++) + for (WorldObjectsIt i = objects.begin(); i != objects.end(); i++) { pWheel tmpWheel; if ((tmpWheel = boost::dynamic_pointer_cast<Wheel>(i->second))) @@ -159,41 +159,10 @@ // this helps brake the vehicle (since it's not user-controlled by default and would roll around freely otherwise) getGearbox("main")->setGear(2); + //update all objects positions stepGraphics(); } -void Vehicle::setContainer (pWorldObject container) -{ - WorldObject::setContainer(container); - // tell all the objects who's the boss. - pWorldObject t = shared_from_this(); - for (WorldObjectsIt i = components.begin(); i != components.end(); i++) - { - if (i->second) i->second->setContainer(t); - } - getGearbox("main")->setContainer(shared_from_this()); - for (CamerasIt i = cameras.begin(); i != cameras.end(); i++) - { - i->second->setContainer(shared_from_this()); - } -} - -void Vehicle::stepGraphics () -{ - base->stepGraphics(); - - CamerasIt i = cameras.begin(); - for (;i != cameras.end(); i++) - { - if (i->second == NULL) log->__format(LOG_ERROR, "Camera %s doesn't exist", i->first.c_str()); - i->second->stepGraphics(); - } - for (WorldObjectsIt i = components.begin(); i != components.end(); i++) - { - i->second->stepGraphics(); - } -} - pOdeObject Vehicle::getMainOdeObject() { return getBody("main")->getMainOdeObject(); @@ -204,7 +173,7 @@ Vector3d posDiff = position - getPosition(); log->__format (LOG_DEVELOPER,"Difference in vehicle position: (%f, %f, %f).", posDiff.x, posDiff.y, posDiff.z); getBody("main")->setPosition ( getBody("main")->getPosition() + posDiff ); - for (WorldObjectsIt i = components.begin(); i != components.end(); i++) + for (WorldObjectsIt i = objects.begin(); i != objects.end(); i++) { pWheel tmpWheel; if ( (tmpWheel = boost::dynamic_pointer_cast<Wheel>(i->second))) @@ -223,7 +192,7 @@ void Vehicle::applyRotation (Quaternion rotation) { // apply rotation to wheels - for (WorldObjectsIt i = components.begin(); i != components.end(); i++) + for (WorldObjectsIt i = objects.begin(); i != objects.end(); i++) { pWheel tmpWheel; if ( (tmpWheel = boost::dynamic_pointer_cast<Wheel>(i->second))) tmpWheel->applyRotation (rotation); @@ -261,19 +230,7 @@ void Vehicle::stepPhysics () { - for(CamerasIt c = cameras.begin() ;c !=cameras.end();c++) - { - c->second->stepPhysics(); - } - - for (WorldObjectsIt i = components.begin(); i != components.end(); i++) - { - pPedal tmpPedal; - if ( (tmpPedal = boost::dynamic_pointer_cast<Pedal>(i->second))) - { - tmpPedal->stepPhysics(); - } - } + WorldObject::stepPhysics(); if ( userDriver ) { // check the gearshift levers @@ -287,24 +244,6 @@ } } - // step torque transfer components first - getClutch("main")->stepPhysics(); - getGear("transfer")->stepPhysics(); - getLSD("rear diff")->stepPhysics(); - - // step rigid bodies - getEngine("main")->stepPhysics(); - getGearbox("main")->stepPhysics(); - getFinalDrive("main")->stepPhysics(); - getBody("main")->stepPhysics(); - for (WorldObjectsIt i = components.begin(); i != components.end(); i++) - { - pSuspension tmpSusp; - if ((tmpSusp = boost::dynamic_pointer_cast<Suspension>(i->second))) tmpSusp->stepPhysics(); - pWheel tmpWheel; - if ((tmpWheel = boost::dynamic_pointer_cast<Wheel>(i->second))) tmpWheel->stepPhysics(); - } - // print telemetry data if ( userDriver ) { @@ -319,7 +258,7 @@ pBody Vehicle::getBody (std::string name) { pBody tmp; - for (WorldObjectsIt i = components.begin(); i != components.end(); i++) + for (WorldObjectsIt i = objects.begin(); i != objects.end(); i++) { if (i->first == ("(body)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<Body>(i->second)) break; } @@ -329,7 +268,7 @@ pDriveMass Vehicle::getDriveMass (std::string name) { pDriveMass tmp; - for (WorldObjectsIt i = components.begin(); i != components.end(); i++) + for (WorldObjectsIt i = objects.begin(); i != objects.end(); i++) { if (i->first == ("(drivemass)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<DriveMass>(i->second)) break; if (i->first == ("(engine)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<DriveMass>(i->second)) break; @@ -343,7 +282,7 @@ pDriveJoint Vehicle::getDriveJoint (std::string name) { pDriveJoint tmp; - for (WorldObjectsIt i = components.begin(); i != components.end(); i++) + for (WorldObjectsIt i = objects.begin(); i != objects.end(); i++) { if (i->first == ("(drivejoint)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<DriveJoint>(i->second)) break; if (i->first == ("(clutch)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<Clutch>(i->second)) break; @@ -356,7 +295,7 @@ pClutch Vehicle::getClutch (std::string name) { pClutch tmp; - for (WorldObjectsIt i = components.begin(); i != components.end(); i++) + for (WorldObjectsIt i = objects.begin(); i != objects.end(); i++) { if (i->first == ("(clutch)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<Clutch>(i->second)) break; } @@ -366,7 +305,7 @@ pGear Vehicle::getGear (std::string name) { pGear tmp; - for (WorldObjectsIt i = components.begin(); i != components.end(); i++) + for (WorldObjectsIt i = objects.begin(); i != objects.end(); i++) { if (i->first == ("(gear)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<Gear>(i->second)) break; } @@ -376,7 +315,7 @@ pLSD Vehicle::getLSD (std::string name) { pLSD tmp; - for (WorldObjectsIt i = components.begin(); i != components.end(); i++) + for (WorldObjectsIt i = objects.begin(); i != objects.end(); i++) { if (i->first == ("(lsd)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<LSD>(i->second)) break; } @@ -386,7 +325,7 @@ pEngine Vehicle::getEngine (std::string name) { pEngine tmp; - for (WorldObjectsIt i = components.begin(); i != components.end(); i++) + for (WorldObjectsIt i = objects.begin(); i != objects.end(); i++) { if (i->first == ("(engine)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<Engine>(i->second)) break; } @@ -396,7 +335,7 @@ pFinalDrive Vehicle::getFinalDrive (std::string name) { pFinalDrive tmp; - for (WorldObjectsIt i = components.begin(); i != components.end(); i++) + for (WorldObjectsIt i = objects.begin(); i != objects.end(); i++) { if (i->first == ("(finaldrive)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<FinalDrive>(i->second)) break; } @@ -406,7 +345,7 @@ pGearbox Vehicle::getGearbox (std::string name) { pGearbox tmp; - for (WorldObjectsIt i = components.begin(); i != components.end(); i++) + for (WorldObjectsIt i = objects.begin(); i != objects.end(); i++) { if (i->first == ("(gearbox)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<Gearbox>(i->second)) break; } @@ -416,7 +355,7 @@ pGearboxGear Vehicle::getGearboxGear (std::string name) { pGearboxGear tmp; - for (WorldObjectsIt i = components.begin(); i != components.end(); i++) + for (WorldObjectsIt i = objects.begin(); i != objects.end(); i++) { if (i->first == ("(gearboxgear)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<GearboxGear>(i->second)) break; } @@ -426,7 +365,7 @@ pPedal Vehicle::getPedal (std::string name) { pPedal tmp; - for (WorldObjectsIt i = components.begin(); i != components.end(); i++) + for (WorldObjectsIt i = objects.begin(); i != objects.end(); i++) { if (i->first == ("(pedal)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<Pedal>(i->second)) break; } @@ -436,7 +375,7 @@ pSuspension Vehicle::getSuspension (std::string name) { pSuspension tmp; - for (WorldObjectsIt i = components.begin(); i != components.end(); i++) + for (WorldObjectsIt i = objects.begin(); i != objects.end(); i++) { if (i->first == ("(suspension)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<Suspension>(i->second)) break; if (i->first == ("(doublewishbone)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<DoubleWishbone>(i->second)) break; @@ -449,7 +388,7 @@ pWheel Vehicle::getWheel (std::string name) { pWheel tmp; - for (WorldObjectsIt i = components.begin(); i != components.end(); i++) + for (WorldObjectsIt i = objects.begin(); i != objects.end(); i++) { if (i->first == ("(wheel)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<Wheel>(i->second)) break; } @@ -458,14 +397,14 @@ } pWorldObject Vehicle::getObject (std::string name) { - if (components.find(name) == components.end()) + if (objects.find(name) == objects.end()) log->__format(LOG_ERROR, "Tried to access non-existent world object \"%s\" from generic type \"%s\"", name.c_str(), "WorldObject"); - return components[name]; + return objects[name]; } pWorldObject Vehicle::getWorldObject (std::string name) { pWorldObject tmp; - for (WorldObjectsIt i = components.begin(); i != components.end(); i++) + for (WorldObjectsIt i = objects.begin(); i != objects.end(); i++) { if (i->first == ("(worldobject)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<WorldObject>(i->second)) break; } @@ -475,7 +414,7 @@ pCamera Vehicle::getCamera (std::string name) { pCamera tmp; - for (CamerasIt i = cameras.begin(); i != cameras.end(); i++) + for (WorldObjectsIt i = objects.begin(); i != objects.end(); i++) { if (i->first == (name) && i->second) if (tmp = boost::dynamic_pointer_cast<Camera>(i->second)) break; if (i->first == ("(camera)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<Camera>(i->second)) break; @@ -486,30 +425,44 @@ pCamera Vehicle::switchNextCamera() { - CamerasIt i = cameras.begin(); - pCamera nextCam = i->second; + WorldObjectsIt i = objects.begin(); + pCamera tmp; + pCamera nextCam; + bool first = false; bool found = false; - for (;i != cameras.end(); i++) + for (;i != objects.end(); i++) { - if (found == true) + if (tmp = boost::dynamic_pointer_cast<Camera>(i->second)) { - nextCam = i->second; - found = false; + if (first == false) + { + nextCam = tmp; + first = true; + } + if (found == true) + { + nextCam = tmp; + found = false; + } + if (activeCamera == tmp) + { + found = true; + } } - if (activeCamera == i->second) - { - found = true; - } } activeCamera = nextCam; return activeCamera; } void Vehicle::pointCameras() { - CamerasIt i = cameras.begin(); - for(;i != cameras.end(); i++) + WorldObjectsIt i = objects.begin(); + pCamera tmp; + for(;i != objects.end(); i++) { - i->second->setPositionID( getMainOdeObject()->getBodyID()); - i->second->setTarget( getMainOdeObject()); + if (tmp = boost::dynamic_pointer_cast<Camera>(i->second)) + { + tmp->setPositionID( getMainOdeObject()->getBodyID()); + tmp->setTarget( getMainOdeObject()); + } } } Modified: trunk/src/vehicle/vehicle.hpp =================================================================== --- trunk/src/vehicle/vehicle.hpp 2006-07-20 00:00:33 UTC (rev 444) +++ trunk/src/vehicle/vehicle.hpp 2006-07-20 00:57:58 UTC (rev 445) @@ -47,8 +47,6 @@ void placeWheelsOnSuspensions(); void boltWheelsToSuspensions(); void stopGraphics (); - WorldObjects components; - Cameras cameras; pCamera activeCamera; void pointCameras(); Vehicle (std::string vehicleName); @@ -83,6 +81,5 @@ Quaternion getRotation (); double getOutputTorque (); pOdeObject getMainOdeObject(); - void stepGraphics (); }; #endif Modified: trunk/src/vehicle/wheel.cpp =================================================================== --- trunk/src/vehicle/wheel.cpp 2006-07-20 00:00:33 UTC (rev 444) +++ trunk/src/vehicle/wheel.cpp 2006-07-20 00:57:58 UTC (rev 445) @@ -88,6 +88,7 @@ } void Wheel::stepPhysics () { + WorldObject::stepPhysics(); prevAngularVel = inputAngularVel; // use hinge's angular rate as angular velocity of wheel (rad/s) Modified: trunk/src/world/area.cpp =================================================================== --- trunk/src/world/area.cpp 2006-07-20 00:00:33 UTC (rev 444) +++ trunk/src/world/area.cpp 2006-07-20 00:57:58 UTC (rev 445) @@ -363,6 +363,7 @@ void Area::stepPhysics() { + WorldObject::stepPhysics(); PartsIt k = parts.begin(); for (; k != parts.end(); k++) { Modified: trunk/src/world/part.cpp =================================================================== --- trunk/src/world/part.cpp 2006-07-20 00:00:33 UTC (rev 444) +++ trunk/src/world/part.cpp 2006-07-20 00:57:58 UTC (rev 445) @@ -96,6 +96,7 @@ void Part::stepPhysics () { + WorldObject::stepPhysics(); dBodyID partID = odeObjects.begin()->second->getBodyID(); // //////////////simplified air friction (test)(should be forces!) dBodySetAngularVel (partID, (*(dReal *) (dBodyGetAngularVel (partID) + 0)) * (dReal) (0.999), (*(dReal *) (dBodyGetAngularVel (partID) + 1)) * (dReal) (0.999), (*(dReal *) (dBodyGetAngularVel (partID) + 2)) * (dReal) (0.999)); Modified: trunk/src/world/world.cpp =================================================================== --- trunk/src/world/world.cpp 2006-07-20 00:00:33 UTC (rev 444) +++ trunk/src/world/world.cpp 2006-07-20 00:57:58 UTC (rev 445) @@ -41,7 +41,8 @@ newWorld = "default"; } new World(World::newWorld); - world->setContainer(); + pWorldObject container; + world->setContainer(container); } return (world); } @@ -236,17 +237,6 @@ log->__format (LOG_ENDUSER, "Changed camera..."); } -void World::setContainer() -{ - //NOTE: world is hardcoded not to have a parent, therefore we don't run this line: - //WorldObject::setContainer(container); - WorldObjectsIt i = objects.begin(); - for(;i != objects.end(); i++) - { - i->second->setContainer(shared_from_this()); - } -} - void World::stepGraphics() { base->stepGraphics(); Modified: trunk/src/world/world.hpp =================================================================== --- trunk/src/world/world.hpp 2006-07-20 00:00:33 UTC (rev 444) +++ trunk/src/world/world.hpp 2006-07-20 00:57:58 UTC (rev 445) @@ -39,7 +39,6 @@ static pWorld get(); static void setNewWorld(std::string name); static void destroy(); - void setContainer(); ~World (); dWorldID worldID; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <st...@us...> - 2006-07-20 00:00:45
|
Revision: 444 Author: stenyak Date: 2006-07-19 17:00:33 -0700 (Wed, 19 Jul 2006) ViewCVS: http://svn.sourceforge.net/motorsport/?rev=444&view=rev Log Message: ----------- Refactored some World functions into WorldObject class. Modified Paths: -------------- trunk/src/common/worldObject.cpp trunk/src/common/worldObject.hpp trunk/src/makefile trunk/src/world/world.cpp trunk/src/world/world.hpp Modified: trunk/src/common/worldObject.cpp =================================================================== --- trunk/src/common/worldObject.cpp 2006-07-19 23:34:48 UTC (rev 443) +++ trunk/src/common/worldObject.cpp 2006-07-20 00:00:33 UTC (rev 444) @@ -26,7 +26,6 @@ #include "engine.hpp" #include "camera.hpp" - unsigned int WorldObject::instancesCount = 0; WorldObjectsC WorldObject::worldObjects; @@ -159,13 +158,72 @@ //if (odeObjects.empty()) return NULL; return odeObjects.begin()->second; } +void WorldObject::stepPhysics () +{ + WorldObjectsIt i = objects.begin(); + for (; i != objects.end(); i++) + { + if (0); + else if (pDoubleWishbone tmp = boost::dynamic_pointer_cast<DoubleWishbone>(i->second)) tmp->stepPhysics(); + else if (pFixed tmp = boost::dynamic_pointer_cast<Fixed >(i->second)) tmp->stepPhysics(); + else if (pUnidimensional tmp = boost::dynamic_pointer_cast<Unidimensional>(i->second)) tmp->stepPhysics(); + else if (pSuspension tmp = boost::dynamic_pointer_cast<Suspension >(i->second)) tmp->stepPhysics(); + else if (pEngine tmp = boost::dynamic_pointer_cast<Engine >(i->second)) tmp->stepPhysics(); + else if (pGearbox tmp = boost::dynamic_pointer_cast<Gearbox >(i->second)) tmp->stepPhysics(); + else if (pWheel tmp = boost::dynamic_pointer_cast<Wheel >(i->second)) tmp->stepPhysics(); + else if (pFinalDrive tmp = boost::dynamic_pointer_cast<FinalDrive >(i->second)) tmp->stepPhysics(); + else if (pDriveMass tmp = boost::dynamic_pointer_cast<DriveMass >(i->second)) tmp->stepPhysics(); + else if (pGear tmp = boost::dynamic_pointer_cast<Gear >(i->second)) tmp->stepPhysics(); + else if (pLSD tmp = boost::dynamic_pointer_cast<LSD >(i->second)) tmp->stepPhysics(); + else if (pClutch tmp = boost::dynamic_pointer_cast<Clutch >(i->second)) tmp->stepPhysics(); + else if (pDriveJoint tmp = boost::dynamic_pointer_cast<DriveJoint >(i->second)) tmp->stepPhysics(); + else if (pGearboxGear tmp = boost::dynamic_pointer_cast<GearboxGear >(i->second)) tmp->stepPhysics(); + else if (pBody tmp = boost::dynamic_pointer_cast<Body >(i->second)) tmp->stepPhysics(); + else if (pPedal tmp = boost::dynamic_pointer_cast<Pedal >(i->second)) tmp->stepPhysics(); + else if (pPart tmp = boost::dynamic_pointer_cast<Part >(i->second)) tmp->stepPhysics(); + else if (pVehicle tmp = boost::dynamic_pointer_cast<Vehicle >(i->second)) tmp->stepPhysics(); + else if (pArea tmp = boost::dynamic_pointer_cast<Area >(i->second)) tmp->stepPhysics(); + else if (pWorld tmp = boost::dynamic_pointer_cast<World >(i->second)) tmp->stepPhysics(); + else if (pCamera tmp = boost::dynamic_pointer_cast<Camera >(i->second)) tmp->stepPhysics(); + else if (pWorldObject tmp = boost::dynamic_pointer_cast<WorldObject >(i->second)) tmp->stepPhysics(); + else log->__format(LOG_ERROR, "Couldn't find out object #%s (%s) type. This should *NOT* have happened.", i->second->getId().c_str(), i->first.c_str()); + } +} void WorldObject::stepGraphics () { - OgreObjectsIt i = ogreObjects.begin(); - for(;i != ogreObjects.end(); i++) + OgreObjectsIt o = ogreObjects.begin(); + for(;o != ogreObjects.end(); o++) { - i->second->stepGraphics(); + o->second->stepGraphics(); } + WorldObjectsIt i = objects.begin(); + for (; i != objects.end(); i++) + { + if (0); + else if (pDoubleWishbone tmp = boost::dynamic_pointer_cast<DoubleWishbone>(i->second)) tmp->stepGraphics(); + else if (pFixed tmp = boost::dynamic_pointer_cast<Fixed >(i->second)) tmp->stepGraphics(); + else if (pUnidimensional tmp = boost::dynamic_pointer_cast<Unidimensional>(i->second)) tmp->stepGraphics(); + else if (pSuspension tmp = boost::dynamic_pointer_cast<Suspension >(i->second)) tmp->stepGraphics(); + else if (pEngine tmp = boost::dynamic_pointer_cast<Engine >(i->second)) tmp->stepGraphics(); + else if (pGearbox tmp = boost::dynamic_pointer_cast<Gearbox >(i->second)) tmp->stepGraphics(); + else if (pWheel tmp = boost::dynamic_pointer_cast<Wheel >(i->second)) tmp->stepGraphics(); + else if (pFinalDrive tmp = boost::dynamic_pointer_cast<FinalDrive >(i->second)) tmp->stepGraphics(); + else if (pDriveMass tmp = boost::dynamic_pointer_cast<DriveMass >(i->second)) tmp->stepGraphics(); + else if (pGear tmp = boost::dynamic_pointer_cast<Gear >(i->second)) tmp->stepGraphics(); + else if (pLSD tmp = boost::dynamic_pointer_cast<LSD >(i->second)) tmp->stepGraphics(); + else if (pClutch tmp = boost::dynamic_pointer_cast<Clutch >(i->second)) tmp->stepGraphics(); + else if (pDriveJoint tmp = boost::dynamic_pointer_cast<DriveJoint >(i->second)) tmp->stepGraphics(); + else if (pGearboxGear tmp = boost::dynamic_pointer_cast<GearboxGear >(i->second)) tmp->stepGraphics(); + else if (pBody tmp = boost::dynamic_pointer_cast<Body >(i->second)) tmp->stepGraphics(); + else if (pPedal tmp = boost::dynamic_pointer_cast<Pedal >(i->second)) tmp->stepGraphics(); + else if (pPart tmp = boost::dynamic_pointer_cast<Part >(i->second)) tmp->stepGraphics(); + else if (pVehicle tmp = boost::dynamic_pointer_cast<Vehicle >(i->second)) tmp->stepGraphics(); + else if (pArea tmp = boost::dynamic_pointer_cast<Area >(i->second)) tmp->stepGraphics(); + else if (pWorld tmp = boost::dynamic_pointer_cast<World >(i->second)) tmp->stepGraphics(); + else if (pCamera tmp = boost::dynamic_pointer_cast<Camera >(i->second)) tmp->stepGraphics(); + else if (pWorldObject tmp = boost::dynamic_pointer_cast<WorldObject >(i->second)) tmp->stepGraphics(); + else log->__format(LOG_ERROR, "Couldn't find out object #%s (%s) type. This should *NOT* have happened.", i->second->getId().c_str(), i->first.c_str()); + } } void WorldObject::setPosition (Vector3d position) { @@ -201,3 +259,24 @@ j->second->setRotation (finalRotation); } } +pArea WorldObject::getArea(std::string name) +{ + pArea tmp; + for (WorldObjectsIt i = objects.begin(); i != objects.end(); i++) + { + if (i->first == ("(area)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<Area>(i->second)) break; + } + if (tmp == NULL) log->__format(LOG_ERROR, "Tried to access non-existent world object \"%s\" using type \"%s\"", name.c_str(), "Area"); + return tmp; +} + +pVehicle WorldObject::getVehicle(std::string name) +{ + pVehicle tmp; + for (WorldObjectsIt i = objects.begin(); i != objects.end(); i++) + { + if (i->first == ("(vehicle)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<Vehicle>(i->second)) break; + } + if (tmp == NULL) log->__format(LOG_ERROR, "Tried to access non-existent world object \"%s\" using type \"%s\"", name.c_str(), "Vehicle"); + return tmp; +} Modified: trunk/src/common/worldObject.hpp =================================================================== --- trunk/src/common/worldObject.hpp 2006-07-19 23:34:48 UTC (rev 443) +++ trunk/src/common/worldObject.hpp 2006-07-20 00:00:33 UTC (rev 444) @@ -25,6 +25,11 @@ typedef std::map <std::string, WorldObject *> WorldObjectsC; typedef std::map <std::string, WorldObject *>::iterator WorldObjectsCIt; +SHARED_PTR_MAP(Camera, pCamera, Cameras, CamerasIt, wCamera); +SHARED_PTR_MAP(Vehicle, pVehicle, Vehicles, VehiclesIt, wVehicle); +SHARED_PTR_MAP(Area, pArea, Areas, AreasIt, wArea); +SHARED_PTR_MAP(Location, pLocation, Locations, LocationsIt, wLocation); + class WorldObject: public boost::enable_shared_from_this <WorldObject> { private: @@ -60,6 +65,7 @@ pLogEngine getLog(); void stepGraphics (); + void stepPhysics (); pOdeObject getMainOdeObject(); @@ -68,5 +74,8 @@ void setPosition (Vector3d position); void setRotation (Quaternion rotation); void applyRotation (Quaternion rotation); + + pArea getArea(std::string name); + pVehicle getVehicle(std::string name); }; #endif Modified: trunk/src/makefile =================================================================== --- trunk/src/makefile 2006-07-19 23:34:48 UTC (rev 443) +++ trunk/src/makefile 2006-07-20 00:00:33 UTC (rev 444) @@ -48,10 +48,10 @@ ifeq ("$(PLATFORM)", "LINUX") TYPE := EXE_EXT := -BASE_INCLUDE_DIR := /usr/include -BASE_LIBRARY_DIR := /usr/lib -#BASE_INCLUDE_DIR := $(PWD)/../3pl/linux/include -#BASE_LIBRARY_DIR := $(PWD)/../3pl/linux/lib +#BASE_INCLUDE_DIR := /usr/include +#BASE_LIBRARY_DIR := /usr/lib +BASE_INCLUDE_DIR := $(PWD)/../3pl/linux/include +BASE_LIBRARY_DIR := $(PWD)/../3pl/linux/lib PLATFORM_CFLAGS := LD_FLAGS:= endif Modified: trunk/src/world/world.cpp =================================================================== --- trunk/src/world/world.cpp 2006-07-19 23:34:48 UTC (rev 443) +++ trunk/src/world/world.cpp 2006-07-20 00:00:33 UTC (rev 444) @@ -22,20 +22,6 @@ #include "location.hpp" #include "SDL.h" -#include "area.hpp" -#include "part.hpp" -#include "world.hpp" -#include "driveMass.hpp" -#include "body.hpp" -#include "finalDrive.hpp" -#include "gearbox.hpp" -#include "pedal.hpp" -#include "suspension.hpp" -#include "vehicle.hpp" -#include "wheel.hpp" -#include "driveJoint.hpp" -#include "engine.hpp" -#include "camera.hpp" pWorld World::world; std::string World::newWorld = ""; @@ -261,28 +247,6 @@ } } -pArea World::getArea(std::string name) -{ - pArea tmp; - for (WorldObjectsIt i = objects.begin(); i != objects.end(); i++) - { - if (i->first == ("(area)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<Area>(i->second)) break; - } - if (tmp == NULL) log->__format(LOG_ERROR, "Tried to access non-existent world object \"%s\" using type \"%s\"", name.c_str(), "Area"); - return tmp; -} - -pVehicle World::getVehicle(std::string name) -{ - pVehicle tmp; - for (WorldObjectsIt i = objects.begin(); i != objects.end(); i++) - { - if (i->first == ("(vehicle)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<Vehicle>(i->second)) break; - } - if (tmp == NULL) log->__format(LOG_ERROR, "Tried to access non-existent world object \"%s\" using type \"%s\"", name.c_str(), "Vehicle"); - return tmp; -} - void World::stepGraphics() { base->stepGraphics(); @@ -290,66 +254,7 @@ { setActiveCamera( getArea("main")->getClosestCamera(getVehicle("main")->getPosition())); } - WorldObjectsIt i = objects.begin(); - for (; i != objects.end(); i++) - { - if (0); - else if (pDoubleWishbone tmp = boost::dynamic_pointer_cast<DoubleWishbone>(i->second)) tmp->stepGraphics(); - else if (pFixed tmp = boost::dynamic_pointer_cast<Fixed >(i->second)) tmp->stepGraphics(); - else if (pUnidimensional tmp = boost::dynamic_pointer_cast<Unidimensional>(i->second)) tmp->stepGraphics(); - else if (pSuspension tmp = boost::dynamic_pointer_cast<Suspension >(i->second)) tmp->stepGraphics(); - else if (pEngine tmp = boost::dynamic_pointer_cast<Engine >(i->second)) tmp->stepGraphics(); - else if (pGearbox tmp = boost::dynamic_pointer_cast<Gearbox >(i->second)) tmp->stepGraphics(); - else if (pWheel tmp = boost::dynamic_pointer_cast<Wheel >(i->second)) tmp->stepGraphics(); - else if (pFinalDrive tmp = boost::dynamic_pointer_cast<FinalDrive >(i->second)) tmp->stepGraphics(); - else if (pDriveMass tmp = boost::dynamic_pointer_cast<DriveMass >(i->second)) tmp->stepGraphics(); - else if (pGear tmp = boost::dynamic_pointer_cast<Gear >(i->second)) tmp->stepGraphics(); - else if (pLSD tmp = boost::dynamic_pointer_cast<LSD >(i->second)) tmp->stepGraphics(); - else if (pClutch tmp = boost::dynamic_pointer_cast<Clutch >(i->second)) tmp->stepGraphics(); - else if (pDriveJoint tmp = boost::dynamic_pointer_cast<DriveJoint >(i->second)) tmp->stepGraphics(); - else if (pGearboxGear tmp = boost::dynamic_pointer_cast<GearboxGear >(i->second)) tmp->stepGraphics(); - else if (pBody tmp = boost::dynamic_pointer_cast<Body >(i->second)) tmp->stepGraphics(); - else if (pPedal tmp = boost::dynamic_pointer_cast<Pedal >(i->second)) tmp->stepGraphics(); - else if (pPart tmp = boost::dynamic_pointer_cast<Part >(i->second)) tmp->stepGraphics(); - else if (pVehicle tmp = boost::dynamic_pointer_cast<Vehicle >(i->second)) tmp->stepGraphics(); - else if (pArea tmp = boost::dynamic_pointer_cast<Area >(i->second)) tmp->stepGraphics(); - else if (pWorld tmp = boost::dynamic_pointer_cast<World >(i->second)) tmp->stepGraphics(); - else if (pCamera tmp = boost::dynamic_pointer_cast<Camera >(i->second)) tmp->stepGraphics(); - else if (pWorldObject tmp = boost::dynamic_pointer_cast<WorldObject >(i->second)) tmp->stepGraphics(); - else log->__format(LOG_ERROR, "Couldn't find out object #%s (%s) type. This should *NOT* have happened.", i->second->getId().c_str(), i->first.c_str()); - } } -void World::stepPhysics() -{ - WorldObjectsIt i = objects.begin(); - for (; i != objects.end(); i++) - { - if (0); - else if (pDoubleWishbone tmp = boost::dynamic_pointer_cast<DoubleWishbone>(i->second)) tmp->stepPhysics(); - else if (pFixed tmp = boost::dynamic_pointer_cast<Fixed >(i->second)) tmp->stepPhysics(); - else if (pUnidimensional tmp = boost::dynamic_pointer_cast<Unidimensional>(i->second)) tmp->stepPhysics(); - else if (pSuspension tmp = boost::dynamic_pointer_cast<Suspension >(i->second)) tmp->stepPhysics(); - else if (pEngine tmp = boost::dynamic_pointer_cast<Engine >(i->second)) tmp->stepPhysics(); - else if (pGearbox tmp = boost::dynamic_pointer_cast<Gearbox >(i->second)) tmp->stepPhysics(); - else if (pWheel tmp = boost::dynamic_pointer_cast<Wheel >(i->second)) tmp->stepPhysics(); - else if (pFinalDrive tmp = boost::dynamic_pointer_cast<FinalDrive >(i->second)) tmp->stepPhysics(); - //else if (pDriveMass tmp = boost::dynamic_pointer_cast<DriveMass >(i->second)) tmp->stepPhysics(); - else if (pGear tmp = boost::dynamic_pointer_cast<Gear >(i->second)) tmp->stepPhysics(); - else if (pLSD tmp = boost::dynamic_pointer_cast<LSD >(i->second)) tmp->stepPhysics(); - else if (pClutch tmp = boost::dynamic_pointer_cast<Clutch >(i->second)) tmp->stepPhysics(); - //else if (pDriveJoint tmp = boost::dynamic_pointer_cast<DriveJoint >(i->second)) tmp->stepPhysics(); - //else if (pGearboxGear tmp = boost::dynamic_pointer_cast<GearboxGear >(i->second)) tmp->stepPhysics(); - else if (pBody tmp = boost::dynamic_pointer_cast<Body >(i->second)) tmp->stepPhysics(); - else if (pPedal tmp = boost::dynamic_pointer_cast<Pedal >(i->second)) tmp->stepPhysics(); - else if (pPart tmp = boost::dynamic_pointer_cast<Part >(i->second)) tmp->stepPhysics(); - else if (pVehicle tmp = boost::dynamic_pointer_cast<Vehicle >(i->second)) tmp->stepPhysics(); - else if (pArea tmp = boost::dynamic_pointer_cast<Area >(i->second)) tmp->stepPhysics(); - else if (pWorld tmp = boost::dynamic_pointer_cast<World >(i->second)) tmp->stepPhysics(); - else if (pCamera tmp = boost::dynamic_pointer_cast<Camera >(i->second)) tmp->stepPhysics(); - //else if (pWorldObject tmp = boost::dynamic_pointer_cast<WorldObject >(i->second)) tmp->stepPhysics(); - else log->__format(LOG_ERROR, "Couldn't find out object #%s (%s) type. This should *NOT* have happened.", i->second->getId().c_str(), i->first.c_str()); - } -} void World::switchNextAreaCamera() { setActiveCamera (getArea("main")->switchNextCamera()); Modified: trunk/src/world/world.hpp =================================================================== --- trunk/src/world/world.hpp 2006-07-19 23:34:48 UTC (rev 443) +++ trunk/src/world/world.hpp 2006-07-20 00:00:33 UTC (rev 444) @@ -26,8 +26,6 @@ static pWorld world; static std::string newWorld; std::string description; - Areas areas; - Vehicles vehicles; pCamera activeCamera; bool cameraDirector; void setActiveCamera(pCamera camera); @@ -49,15 +47,12 @@ dSpaceID spaceID; dJointGroupID jointGroupID; - pArea getArea(std::string name); - pVehicle getVehicle(std::string name); void switchCameraDirector(); void switchNextAreaCamera(); void switchNextVehicleCamera(); bool isActiveCamera(pCamera camera); void stepGraphics(); - void stepPhysics(); }; #endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <st...@us...> - 2006-07-19 23:35:20
|
Revision: 443 Author: stenyak Date: 2006-07-19 16:34:48 -0700 (Wed, 19 Jul 2006) ViewCVS: http://svn.sourceforge.net/motorsport/?rev=443&view=rev Log Message: ----------- Added MospPath namespace, for handling xml relationships specified in the Unified Mosp XML Format. Removed a lot of debug telemetry logging. Refactored World class a bit, now using "objects" container for vehicles and areas (not separate containers). Changed nomenclature of internal data format: now it's all lower case (gearboxgear instead of GearboxGear, for example). Modified Paths: -------------- trunk/data/vehicles/mosp1/vehicle.xml trunk/data/worlds/default.xml trunk/src/common/worldObject.cpp trunk/src/common/worldObject.hpp trunk/src/makefile trunk/src/vehicle/body.cpp trunk/src/vehicle/driveJoint.cpp trunk/src/vehicle/engine.cpp trunk/src/vehicle/finalDrive.cpp trunk/src/vehicle/gearbox.cpp trunk/src/vehicle/pedal.cpp trunk/src/vehicle/suspension.cpp trunk/src/vehicle/vehicle.cpp trunk/src/vehicle/wheel.cpp trunk/src/world/area.cpp trunk/src/world/world.cpp trunk/src/world/world.hpp Added Paths: ----------- trunk/src/tools/mospPath.cpp trunk/src/tools/mospPath.hpp Modified: trunk/data/vehicles/mosp1/vehicle.xml =================================================================== --- trunk/data/vehicles/mosp1/vehicle.xml 2006-07-19 20:00:20 UTC (rev 442) +++ trunk/data/vehicles/mosp1/vehicle.xml 2006-07-19 23:34:48 UTC (rev 443) @@ -335,7 +335,7 @@ > </camera> <camera - name = "chase" + name = "main" position = "-10 0 2" target = "2 0 0" > Modified: trunk/data/worlds/default.xml =================================================================== --- trunk/data/worlds/default.xml 2006-07-19 20:00:20 UTC (rev 442) +++ trunk/data/worlds/default.xml 2006-07-19 23:34:48 UTC (rev 443) @@ -1,70 +1,21 @@ <?xml version="1.0" encoding="ISO-8859-1"?> -<world - name = "Test" - description = "Drive the Mosp1 car in the testing grounds!" - useAreaCamera = "false" - gravityX = "0.0" - gravityY = "0.0" - gravityZ = "-9.8" - > - <vehicleList> - <!-- explanation - <vehicle - directory = "mosp1" vehicle dir, located in data/vehicles. - driver = "none" type of driver. functional: "none" and "user". planned in the future: "ai", "net", "replay", maybe more. - startPosition = "grid01" reference to a position, which must be defined in the current area xml file. - > - </vehicle> - --> - <vehicle - directory = "mosp1" - _directory = "quattros1" - driver = "user" - startPosition = "paceCar" - > - </vehicle> - <!-- - <vehicle - directory = "mosp1" - driver = "none" - startPosition = "grid01" - > - </vehicle> - <vehicle - directory = "mosp1" - driver = "none" - startPosition = "grid02" - > - </vehicle> - <vehicle - directory = "mosp1" - driver = "none" - startPosition = "grid03" - > - </vehicle> - <vehicle - directory = "mosp1" - driver = "none" - startPosition = "grid04" - > - </vehicle> - <vehicle - directory = "mosp1" - driver = "none" - startPosition = "grid05" - > - </vehicle> - <vehicle - directory = "mosp1" - driver = "none" - startPosition = "grid06" - > - </vehicle> - --> - </vehicleList> - <area - directory = "mospland" - _directory = "mospland2006.r7" +<world xmlns:xi="http://www.w3.org/2001/XInclude"> + <customData + description = "Drive the Mosp1 car in the testing grounds!" + useAreaCamera ="false" + gravityX = "0.0" gravityY = "0.0" gravityZ = "-9.8" > - </area> + </customData> + <sharedobject name="main"><area + model="mospland" + _model="mospland2006.r7" + > + </area></sharedobject> + <sharedobject name="main"><vehicle + model="mosp1" + _model="quattros1" + > + </vehicle></sharedobject> + <location-vehicle first="(area)main/paceCar" second="(vehicle)main" /> + <vehicle-driver first="(vehicle)main" second="user" /> </world> Modified: trunk/src/common/worldObject.cpp =================================================================== --- trunk/src/common/worldObject.cpp 2006-07-19 20:00:20 UTC (rev 442) +++ trunk/src/common/worldObject.cpp 2006-07-19 23:34:48 UTC (rev 443) @@ -91,28 +91,28 @@ { std::string type; if (0) type.clear(); - else if (dynamic_cast<DoubleWishbone *>(this)) type = "DoubleWishbone"; - else if (dynamic_cast<Fixed *>(this)) type = "Fixed"; - else if (dynamic_cast<Unidimensional *>(this)) type = "Unidimensional"; - else if (dynamic_cast<Suspension *>(this)) type = "Suspension"; - else if (dynamic_cast<Engine *>(this)) type = "Engine"; - else if (dynamic_cast<Gearbox *>(this)) type = "Gearbox"; - else if (dynamic_cast<Wheel *>(this)) type = "Wheel"; - else if (dynamic_cast<FinalDrive *>(this)) type = "FinalDrive"; - else if (dynamic_cast<DriveMass *>(this)) type = "DriveMass"; - else if (dynamic_cast<Gear *>(this)) type = "Gear"; - else if (dynamic_cast<LSD *>(this)) type = "LSD"; - else if (dynamic_cast<Clutch *>(this)) type = "Clutch"; - else if (dynamic_cast<DriveJoint *>(this)) type = "DriveJoint"; - else if (dynamic_cast<GearboxGear *>(this)) type = "GearboxGear"; - else if (dynamic_cast<Body *>(this)) type = "Body"; - else if (dynamic_cast<Pedal *>(this)) type = "Pedal"; - else if (dynamic_cast<Part *>(this)) type = "Part"; - else if (dynamic_cast<Vehicle *>(this)) type = "Vehicle"; - else if (dynamic_cast<Area *>(this)) type = "Area"; - else if (dynamic_cast<World *>(this)) type = "World"; - else if (dynamic_cast<Camera *>(this)) type = "Camera"; - else if (dynamic_cast<WorldObject *>(this)) type = "WorldObject"; + else if (dynamic_cast<DoubleWishbone *>(this)) type = "doublewishbone"; + else if (dynamic_cast<Fixed *>(this)) type = "fixed"; + else if (dynamic_cast<Unidimensional *>(this)) type = "unidimensional"; + else if (dynamic_cast<Suspension *> (this)) type = "suspension"; + else if (dynamic_cast<Engine *>(this)) type = "engine"; + else if (dynamic_cast<Gearbox *>(this)) type = "gearbox"; + else if (dynamic_cast<Wheel *>(this)) type = "wheel"; + else if (dynamic_cast<FinalDrive *>(this)) type = "finaldrive"; + else if (dynamic_cast<DriveMass *> (this)) type = "drivemass"; + else if (dynamic_cast<Gear *>(this)) type = "gear"; + else if (dynamic_cast<LSD *>(this)) type = "lsd"; + else if (dynamic_cast<Clutch *>(this)) type = "clutch"; + else if (dynamic_cast<DriveJoint *> (this)) type = "drivejoint"; + else if (dynamic_cast<GearboxGear *> (this)) type = "gearboxgear"; + else if (dynamic_cast<Body *> (this)) type = "body"; + else if (dynamic_cast<Pedal *> (this)) type = "pedal"; + else if (dynamic_cast<Part *> (this)) type = "part"; + else if (dynamic_cast<Vehicle *> (this)) type = "vehicle"; + else if (dynamic_cast<Area *> (this)) type = "area"; + else if (dynamic_cast<World *> (this)) type = "world"; + else if (dynamic_cast<Camera *> (this)) type = "camera"; + else if (dynamic_cast<WorldObject *> (this)) type = "worldobject"; else log->__format(LOG_ERROR, "Couldn't find out object #%s type. This should *NOT* have happened.", getId().c_str()); return "(" + type + ")" + name; } Modified: trunk/src/common/worldObject.hpp =================================================================== --- trunk/src/common/worldObject.hpp 2006-07-19 20:00:20 UTC (rev 442) +++ trunk/src/common/worldObject.hpp 2006-07-19 23:34:48 UTC (rev 443) @@ -41,6 +41,7 @@ wWorldObject container; OgreObjects ogreObjects; OdeObjects odeObjects; + WorldObjects objects; WorldObject (const std::string & name); public: virtual ~WorldObject (); Modified: trunk/src/makefile =================================================================== --- trunk/src/makefile 2006-07-19 20:00:20 UTC (rev 442) +++ trunk/src/makefile 2006-07-19 23:34:48 UTC (rev 443) @@ -217,6 +217,7 @@ ########################################### #Sources SOURCES := \ + tools/mospPath.cpp \ tools/xmlTag.cpp \ common/worldObject.cpp \ common/ogreObject.cpp \ Added: trunk/src/tools/mospPath.cpp =================================================================== --- trunk/src/tools/mospPath.cpp (rev 0) +++ trunk/src/tools/mospPath.cpp 2006-07-19 23:34:48 UTC (rev 443) @@ -0,0 +1,101 @@ +/*****************************************************************************\ +|* Copyright (C) 2003, 2006 "Motorsport" developers (*) *| +|* Part of the "Motorsport" project (http://motorsport.sourceforge.net) *| +|* Licensed under the GNU General Public License (*) *| +|* *| +|* (*) Complete information is provided at the following URL: *| +|* [ http://motorsport-sim.org/svn/trunk/doc/LICENSE ] *| +\*****************************************************************************/ + +#include <iostream> +#include "mospPath.hpp" + +std::string MospPath::getType(std::string fullname) +{ + std::string type; + bool error = false; + std::string errorMessage; + if (fullname.find_first_of('(') == 0) + { + //( + unsigned int typeend; + if ((typeend = fullname.find_first_of(')',0)) != std::string::npos) + { + //(type) + type = fullname.substr(1,typeend-1); + } else { + //(type + error = true; errorMessage = "')' not found"; + } + } else { + //name + error = true; errorMessage = "'(' not found"; + } + if (error) std::cout << std::endl << "Error! Mosp path syntax error \"" << fullname << "\": " << errorMessage; + //if (error) log->__format (LOG_ERROR, "Mosp object location syntax error \"%s\": %s", fullname.c_str(), errorMessage.c_str()); + return type; +} +std::string MospPath::getName(std::string fullname) +{ + std::string name; + bool error = false; + std::string errorMessage = ""; + if (fullname.find_first_of('(') == 0) + { + //( + unsigned int typeend; + if ((typeend = fullname.find_first_of(')',0)) != std::string::npos) + { + //(type) + unsigned int nameend; + if ((nameend = fullname.find_first_of('/',typeend)) != std::string::npos) + { + //(type)name/ + name = fullname.substr(typeend+1,nameend-(typeend+1)); + } else { + //(type)name + name = fullname.substr(typeend+1); + } + } else { + //(type + error = true; errorMessage = "')' not found"; + } + } else { + //name + name = fullname; + } + if (error) std::cout << std::endl << "Error! Mosp path syntax error \"" << fullname << "\": " << errorMessage; + return name; +} +std::string MospPath::getSubFullname(std::string fullname) +{ + std::string subfullname; + bool error = false; + std::string errorMessage = ""; + if (fullname.find_first_of('(') == 0) + { + //( + unsigned int typeend; + if ((typeend = fullname.find_first_of(')',0)) != std::string::npos) + { + //(type) + unsigned int nameend; + if ((nameend = fullname.find_first_of('/',typeend)) != std::string::npos) + { + //(type)name/ + subfullname = fullname.substr(nameend+1); + } else { + //(type)name + error = true; errorMessage = "'/' not found"; + } + } else { + //(type + error = true; errorMessage = "')' not found"; + } + } else { + //name + subfullname = fullname; + } + if (error) std::cout << std::endl << "Error! Mosp path syntax error \"" << fullname << "\": " << errorMessage; + return subfullname; +} Added: trunk/src/tools/mospPath.hpp =================================================================== --- trunk/src/tools/mospPath.hpp (rev 0) +++ trunk/src/tools/mospPath.hpp 2006-07-19 23:34:48 UTC (rev 443) @@ -0,0 +1,21 @@ +/*****************************************************************************\ +|* Copyright (C) 2003, 2006 "Motorsport" developers (*) *| +|* Part of the "Motorsport" project (http://motorsport.sourceforge.net) *| +|* Licensed under the GNU General Public License (*) *| +|* *| +|* (*) Complete information is provided at the following URL: *| +|* [ http://motorsport-sim.org/svn/trunk/doc/LICENSE ] *| +\*****************************************************************************/ + +#ifndef MOSPPATH_HPP +#define MOSPPATH_HPP +#include <string> + +namespace MospPath +{ + std::string getType(std::string fullname); + std::string getName(std::string fullname); + std::string getSubFullname(std::string fullname); +} + +#endif Modified: trunk/src/vehicle/body.cpp =================================================================== --- trunk/src/vehicle/body.cpp 2006-07-19 20:00:20 UTC (rev 442) +++ trunk/src/vehicle/body.cpp 2006-07-19 23:34:48 UTC (rev 443) @@ -83,6 +83,7 @@ if (userDriver) { double moveZ = System::get()->axisMap[getIDKeyboardKey(SDLK_BACKSPACE)]->getValue() * 50000; + log->__format(LOG_DEVELOPER,"Physics of body..............%f", moveZ); moveZ += System::get()->axisMap[getIDKeyboardKey(SDLK_RETURN)]->getValue() * 12200; moveZ -= System::get()->axisMap[getIDKeyboardKey(SDLK_RSHIFT)]->getValue() * 10000; dBodyAddForce (bodyID, 0, 0, moveZ); @@ -102,9 +103,10 @@ dBodyAddForce (bodyID, force.x, force.y, force.z); - log->__format(LOG_DEVELOPER, "Body air drag force = (%f, %f, %f)", force.x, force.y, force.z); + //log->__format(LOG_DEVELOPER, "Body air drag force = (%f, %f, %f)", force.x, force.y, force.z); } void Body::setUserDriver () { + log->__format(LOG_ENDUSER, "Body %s will now be driven by a human.", getName().c_str()); userDriver = true; } Modified: trunk/src/vehicle/driveJoint.cpp =================================================================== --- trunk/src/vehicle/driveJoint.cpp 2006-07-19 20:00:20 UTC (rev 442) +++ trunk/src/vehicle/driveJoint.cpp 2006-07-19 23:34:48 UTC (rev 443) @@ -174,7 +174,7 @@ } else { outputTorqueTransfer = lockedParam*(inputDrive->getOutputAngularVel()-outputDrive->getInputAngularVel()); - log->__format(LOG_DEVELOPER, "torqueTransfer=%f", outputTorqueTransfer); + //log->__format(LOG_DEVELOPER, "torqueTransfer=%f", outputTorqueTransfer); if(outputTorqueTransfer > maxTorqueTransfer) { @@ -190,7 +190,7 @@ outputDrive->addInputTorque(outputTorqueTransfer); // rotationalVelocity = pOutTorque->getInputAngularVel(); - log->__format(LOG_DEVELOPER, "inputTorque=%f outputTorque=%f inputVel=%f outputVel=%f", inputTorqueTransfer, outputTorqueTransfer,inputDrive->getOutputAngularVel(),outputDrive->getInputAngularVel()); + //log->__format(LOG_DEVELOPER, "inputTorque=%f outputTorque=%f inputVel=%f outputVel=%f", inputTorqueTransfer, outputTorqueTransfer,inputDrive->getOutputAngularVel(),outputDrive->getInputAngularVel()); } } @@ -216,7 +216,7 @@ inputDrive->addOutputTorque(inputTorqueTransfer); outputDrive->addInputTorque(outputTorqueTransfer); - log->__format(LOG_DEVELOPER, "inTorque=%f outTorque=%f relVel=%f relAngle=%f", inputTorqueTransfer, outputTorqueTransfer,relAngularVel,relAngle); + //log->__format(LOG_DEVELOPER, "inTorque=%f outTorque=%f relVel=%f relAngle=%f", inputTorqueTransfer, outputTorqueTransfer,relAngularVel,relAngle); } else { relAngle = 0; @@ -246,7 +246,7 @@ outputDrive->addInputTorque(outputTorqueTransfer/2); outputDrive2->addInputTorque(outputTorqueTransfer/2); - log->__format(LOG_DEVELOPER, "inTorque=%f outTorque=%f relVel=%f relAngle=%f", inputTorqueTransfer, outputTorqueTransfer,relAngularVel,relAngle); + //log->__format(LOG_DEVELOPER, "inTorque=%f outTorque=%f relVel=%f relAngle=%f", inputTorqueTransfer, outputTorqueTransfer,relAngularVel,relAngle); } else { relAngle = 0; Modified: trunk/src/vehicle/engine.cpp =================================================================== --- trunk/src/vehicle/engine.cpp 2006-07-19 20:00:20 UTC (rev 442) +++ trunk/src/vehicle/engine.cpp 2006-07-19 23:34:48 UTC (rev 443) @@ -78,7 +78,7 @@ inputAngularVel = (dtoverJe*(engineTorque+outputJoint->getInputTorque())+prevAngularVel)/(1+(dtoverJe*friction)); angularAcc = (inputAngularVel-prevAngularVel)/ dt; outputAngularVel = inputAngularVel; */ - log->__format(LOG_DEVELOPER, "engineTorque=%f(Nm) angAcc=%f engspeed=%f(rad/s)", engineTorque, angularAcc, inputAngularVel); + //log->__format(LOG_DEVELOPER, "engineTorque=%f(Nm) angAcc=%f engspeed=%f(rad/s)", engineTorque, angularAcc, inputAngularVel); telemetryTorque = engineTorque; inputTorqueTransfer = 0; outputTorqueTransfer = 0; Modified: trunk/src/vehicle/finalDrive.cpp =================================================================== --- trunk/src/vehicle/finalDrive.cpp 2006-07-19 20:00:20 UTC (rev 442) +++ trunk/src/vehicle/finalDrive.cpp 2006-07-19 23:34:48 UTC (rev 443) @@ -80,7 +80,7 @@ angularAcc = (inputAngularVel-prevAngularVel)/System::get()->getDesiredPhysicsTimestep(); outputAngularVel = inputAngularVel/finalDriveRatio; */ - log->__format(LOG_DEVELOPER, "angVel=%f angAcc=%f torque=%f", inputAngularVel, angularAcc, outputTorqueTransfer); + //log->__format(LOG_DEVELOPER, "angVel=%f angAcc=%f torque=%f", inputAngularVel, angularAcc, outputTorqueTransfer); inputTorqueTransfer = 0; outputTorqueTransfer = 0; } Modified: trunk/src/vehicle/gearbox.cpp =================================================================== --- trunk/src/vehicle/gearbox.cpp 2006-07-19 20:00:20 UTC (rev 442) +++ trunk/src/vehicle/gearbox.cpp 2006-07-19 23:34:48 UTC (rev 443) @@ -116,7 +116,7 @@ outputAngularVel = outputAngularVel + dt / 2 * (outputAngularAcc + (outputTorqueTransfer - 0.1*(outputAngularVel+outputAngularAcc*dt))/0.1); } - log->__format(LOG_DEVELOPER, "inputTorque=%f outputTorque=%f inputVel=%f outputVel=%f", inputTorqueTransfer, outputTorqueTransfer, inputAngularVel, outputAngularVel); + //log->__format(LOG_DEVELOPER, "inputTorque=%f outputTorque=%f inputVel=%f outputVel=%f", inputTorqueTransfer, outputTorqueTransfer, inputAngularVel, outputAngularVel); inputTorqueTransfer = 0; outputTorqueTransfer = 0; } Modified: trunk/src/vehicle/pedal.cpp =================================================================== --- trunk/src/vehicle/pedal.cpp 2006-07-19 20:00:20 UTC (rev 442) +++ trunk/src/vehicle/pedal.cpp 2006-07-19 23:34:48 UTC (rev 443) @@ -40,6 +40,7 @@ void Pedal::setUserDriver () { + log->__format(LOG_ENDUSER, "Pedal %s will now be driven by a human.", getName().c_str()); userDriver = true; } @@ -48,7 +49,7 @@ currentAngle = 0; if ( userDriver ) { - if (getName() == "(Pedal)gas") + if (getName() == "(pedal)gas") { currentAngle = 1 - System::get()->axisMap[getIDJoyAxis(0,2)]->getValue(); if (currentAngle == 0) { @@ -60,7 +61,7 @@ if (currentAngle == 0) { currentAngle = System::get()->axisMap[getIDKeyboardKey(SDLK_UP)]->getValue() * 3 / 3; } } } } - } else if (getName() == "(Pedla)brake") + } else if (getName() == "(pedal)brake") { currentAngle = 1 - System::get()->axisMap[getIDJoyAxis(0,1)]->getValue(); if (currentAngle == 0) { @@ -72,7 +73,7 @@ if (currentAngle == 0) { currentAngle = System::get()->axisMap[getIDKeyboardKey(SDLK_DOWN)]->getValue() * 3 / 3; } } } } - } else if (getName() == "(Pedal)clutch") + } else if (getName() == "(pedal)clutch") { currentAngle = System::get()->axisMap[getIDKeyboardKey(SDLK_KP7)]->getValue() * 3 / 3; if (currentAngle == 0) { @@ -89,6 +90,5 @@ double Pedal::getNormalizedAngle() { - log->__format (LOG_CCREATOR, "Reading pedal \"%s\" angle: %f", getName().c_str(), currentAngle ); return (currentAngle / angleRange); } Modified: trunk/src/vehicle/suspension.cpp =================================================================== --- trunk/src/vehicle/suspension.cpp 2006-07-19 20:00:20 UTC (rev 442) +++ trunk/src/vehicle/suspension.cpp 2006-07-19 23:34:48 UTC (rev 443) @@ -35,6 +35,7 @@ void Suspension::setUserDriver () { + log->__format(LOG_ENDUSER, "Suspension %s will now be driven by a human.", getName().c_str()); userDriver = true; } Modified: trunk/src/vehicle/vehicle.cpp =================================================================== --- trunk/src/vehicle/vehicle.cpp 2006-07-19 20:00:20 UTC (rev 442) +++ trunk/src/vehicle/vehicle.cpp 2006-07-19 23:34:48 UTC (rev 443) @@ -60,6 +60,7 @@ void Vehicle::setUserDriver () { userDriver = true; + log->__format(LOG_ENDUSER, "Vehicle %s will now be driven by a human.", getName().c_str()); log->log (LOG_ENDUSER, LOG_TELEMETRY, "VehSpeed EngineSpeed DiffAngularVel RRWhAngulVel RLWhAngulVel Gear Distance"); // engage neutral gear @@ -189,12 +190,7 @@ } for (WorldObjectsIt i = components.begin(); i != components.end(); i++) { - pDoubleWishbone tmpSusp; - if ( (tmpSusp = boost::dynamic_pointer_cast<DoubleWishbone>(i->second))) tmpSusp->stepGraphics(); - pWheel tmpWheel; - if ( (tmpWheel = boost::dynamic_pointer_cast<Wheel>(i->second))) tmpWheel->stepGraphics(); - pBody tmpBody; - if ( (tmpBody = boost::dynamic_pointer_cast<Body>(i->second))) tmpBody->stepGraphics(); + i->second->stepGraphics(); } } @@ -325,7 +321,7 @@ pBody tmp; for (WorldObjectsIt i = components.begin(); i != components.end(); i++) { - if (i->first == ("(Body)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<Body>(i->second)) break; + if (i->first == ("(body)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<Body>(i->second)) break; } if (tmp == NULL) log->__format(LOG_ERROR, "Tried to access non-existent world object \"%s\" using type \"%s\"", name.c_str(), "Body"); return tmp; @@ -335,11 +331,11 @@ pDriveMass tmp; for (WorldObjectsIt i = components.begin(); i != components.end(); i++) { - if (i->first == ("(DriveMass)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<DriveMass>(i->second)) break; - if (i->first == ("(Engine)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<DriveMass>(i->second)) break; - if (i->first == ("(FinalDrive)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<DriveMass>(i->second)) break; - if (i->first == ("(Gearbox)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<DriveMass>(i->second)) break; - if (i->first == ("(Wheel)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<DriveMass>(i->second)) break; + if (i->first == ("(drivemass)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<DriveMass>(i->second)) break; + if (i->first == ("(engine)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<DriveMass>(i->second)) break; + if (i->first == ("(finaldrive)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<DriveMass>(i->second)) break; + if (i->first == ("(gearbox)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<DriveMass>(i->second)) break; + if (i->first == ("(wheel)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<DriveMass>(i->second)) break; } if (tmp == NULL) log->__format(LOG_ERROR, "Tried to access non-existent world object \"%s\" using type \"%s\"", name.c_str(), "DriveMass"); return tmp; @@ -349,10 +345,10 @@ pDriveJoint tmp; for (WorldObjectsIt i = components.begin(); i != components.end(); i++) { - if (i->first == ("(DriveJoint)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<DriveJoint>(i->second)) break; - if (i->first == ("(Clutch)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<Clutch>(i->second)) break; - if (i->first == ("(Gear)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<Gear>(i->second)) break; - if (i->first == ("(LSD)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<LSD>(i->second)) break; + if (i->first == ("(drivejoint)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<DriveJoint>(i->second)) break; + if (i->first == ("(clutch)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<Clutch>(i->second)) break; + if (i->first == ("(gear)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<Gear>(i->second)) break; + if (i->first == ("(lsd)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<LSD>(i->second)) break; } if (tmp == NULL) log->__format(LOG_ERROR, "Tried to access non-existent world object \"%s\" using type \"%s\"", name.c_str(), "DriveJoint"); return tmp; @@ -362,7 +358,7 @@ pClutch tmp; for (WorldObjectsIt i = components.begin(); i != components.end(); i++) { - if (i->first == ("(Clutch)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<Clutch>(i->second)) break; + if (i->first == ("(clutch)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<Clutch>(i->second)) break; } if (tmp == NULL) log->__format(LOG_ERROR, "Tried to access non-existent world object \"%s\" using type \"%s\"", name.c_str(), "Clutch"); return tmp; @@ -372,7 +368,7 @@ pGear tmp; for (WorldObjectsIt i = components.begin(); i != components.end(); i++) { - if (i->first == ("(Gear)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<Gear>(i->second)) break; + if (i->first == ("(gear)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<Gear>(i->second)) break; } if (tmp == NULL) log->__format(LOG_ERROR, "Tried to access non-existent world object \"%s\" using type \"%s\"", name.c_str(), "Gear"); return tmp; @@ -382,7 +378,7 @@ pLSD tmp; for (WorldObjectsIt i = components.begin(); i != components.end(); i++) { - if (i->first == ("(LSD)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<LSD>(i->second)) break; + if (i->first == ("(lsd)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<LSD>(i->second)) break; } if (tmp == NULL) log->__format(LOG_ERROR, "Tried to access non-existent world object \"%s\" using type \"%s\"", name.c_str(), "LSD"); return tmp; @@ -392,7 +388,7 @@ pEngine tmp; for (WorldObjectsIt i = components.begin(); i != components.end(); i++) { - if (i->first == ("(Engine)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<Engine>(i->second)) break; + if (i->first == ("(engine)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<Engine>(i->second)) break; } if (tmp == NULL) log->__format(LOG_ERROR, "Tried to access non-existent world object \"%s\" using type \"%s\"", name.c_str(), "Engine"); return tmp; @@ -402,7 +398,7 @@ pFinalDrive tmp; for (WorldObjectsIt i = components.begin(); i != components.end(); i++) { - if (i->first == ("(FinalDrive)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<FinalDrive>(i->second)) break; + if (i->first == ("(finaldrive)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<FinalDrive>(i->second)) break; } if (tmp == NULL) log->__format(LOG_ERROR, "Tried to access non-existent world object \"%s\" using type \"%s\"", name.c_str(), "FinalDrive"); return tmp; @@ -412,7 +408,7 @@ pGearbox tmp; for (WorldObjectsIt i = components.begin(); i != components.end(); i++) { - if (i->first == ("(Gearbox)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<Gearbox>(i->second)) break; + if (i->first == ("(gearbox)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<Gearbox>(i->second)) break; } if (tmp == NULL) log->__format(LOG_ERROR, "Tried to access non-existent world object \"%s\" using type \"%s\"", name.c_str(), "Gearbox"); return tmp; @@ -422,7 +418,7 @@ pGearboxGear tmp; for (WorldObjectsIt i = components.begin(); i != components.end(); i++) { - if (i->first == ("(GearboxGear)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<GearboxGear>(i->second)) break; + if (i->first == ("(gearboxgear)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<GearboxGear>(i->second)) break; } if (tmp == NULL) log->__format(LOG_ERROR, "Tried to access non-existent world object \"%s\" using type \"%s\"", name.c_str(), "GearboxGear"); return tmp; @@ -432,7 +428,7 @@ pPedal tmp; for (WorldObjectsIt i = components.begin(); i != components.end(); i++) { - if (i->first == ("(Pedal)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<Pedal>(i->second)) break; + if (i->first == ("(pedal)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<Pedal>(i->second)) break; } if (tmp == NULL) log->__format(LOG_ERROR, "Tried to access non-existent world object \"%s\" using type \"%s\"", name.c_str(), "Pedal"); return tmp; @@ -442,10 +438,10 @@ pSuspension tmp; for (WorldObjectsIt i = components.begin(); i != components.end(); i++) { - if (i->first == ("(Suspension)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<Suspension>(i->second)) break; - if (i->first == ("(DoubleWishbone)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<DoubleWishbone>(i->second)) break; - if (i->first == ("(Fixed)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<Fixed>(i->second)) break; - if (i->first == ("(Unidimensional)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<Unidimensional>(i->second)) break; + if (i->first == ("(suspension)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<Suspension>(i->second)) break; + if (i->first == ("(doublewishbone)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<DoubleWishbone>(i->second)) break; + if (i->first == ("(fixed)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<Fixed>(i->second)) break; + if (i->first == ("(unidimensional)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<Unidimensional>(i->second)) break; } if (tmp == NULL) log->__format(LOG_ERROR, "Tried to access non-existent world object \"%s\" using type \"%s\"", name.c_str(), "Suspension"); return tmp; @@ -455,7 +451,7 @@ pWheel tmp; for (WorldObjectsIt i = components.begin(); i != components.end(); i++) { - if (i->first == ("(Wheel)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<Wheel>(i->second)) break; + if (i->first == ("(wheel)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<Wheel>(i->second)) break; } if (tmp == NULL) log->__format(LOG_ERROR, "Tried to access non-existent world object \"%s\" using type \"%s\"", name.c_str(), "Wheel"); return tmp; @@ -471,7 +467,7 @@ pWorldObject tmp; for (WorldObjectsIt i = components.begin(); i != components.end(); i++) { - if (i->first == ("(WorldObject)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<WorldObject>(i->second)) break; + if (i->first == ("(worldobject)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<WorldObject>(i->second)) break; } if (tmp == NULL) log->__format(LOG_ERROR, "Tried to access non-existent world object \"%s\" using type \"%s\"", name.c_str(), "WorldObject"); return tmp; @@ -482,7 +478,7 @@ for (CamerasIt i = cameras.begin(); i != cameras.end(); i++) { if (i->first == (name) && i->second) if (tmp = boost::dynamic_pointer_cast<Camera>(i->second)) break; - if (i->first == ("(Camera)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<Camera>(i->second)) break; + if (i->first == ("(camera)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<Camera>(i->second)) break; } if (tmp == NULL) log->__format(LOG_ERROR, "Tried to access non-existent world object \"%s\" using type \"%s\"", name.c_str(), "Camera"); return tmp; Modified: trunk/src/vehicle/wheel.cpp =================================================================== --- trunk/src/vehicle/wheel.cpp 2006-07-19 20:00:20 UTC (rev 442) +++ trunk/src/vehicle/wheel.cpp 2006-07-19 23:34:48 UTC (rev 443) @@ -83,6 +83,7 @@ void Wheel::setUserDriver () { + log->__format(LOG_ENDUSER, "Wheel %s will now be driven by a human.", getName().c_str()); userDriver = true; } void Wheel::stepPhysics () @@ -120,7 +121,7 @@ // finally, apply the torques dBodyAddTorque (getMainOdeObject()->getBodyID(), tAxis.x, tAxis.y, tAxis.z); - log->__format(LOG_DEVELOPER, "%s:angVel=%f angAcc=%f torque=%f powered=%f axis=(%f,%f,%f)",getName().c_str(), inputAngularVel, angularAcc, inputTorqueTransfer, powered, tAxis.x, tAxis.y, tAxis.z); + //log->__format(LOG_DEVELOPER, "%s:angVel=%f angAcc=%f torque=%f powered=%f axis=(%f,%f,%f)",getName().c_str(), inputAngularVel, angularAcc, inputTorqueTransfer, powered, tAxis.x, tAxis.y, tAxis.z); // zero the accumulators inputTorqueTransfer = 0; Modified: trunk/src/world/area.cpp =================================================================== --- trunk/src/world/area.cpp 2006-07-19 20:00:20 UTC (rev 442) +++ trunk/src/world/area.cpp 2006-07-19 23:34:48 UTC (rev 443) @@ -379,7 +379,7 @@ pCamera tmp; for (CamerasIt i = cameras.begin(); i != cameras.end(); i++) { - if (i->first == ("(Camera)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<Camera>(i->second)) break; + if (i->first == ("(camera)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<Camera>(i->second)) break; } if (tmp == NULL) log->__format(LOG_ERROR, "Tried to access non-existent world object \"%s\" using type \"%s\"", name.c_str(), "Camera"); return tmp; Modified: trunk/src/world/world.cpp =================================================================== --- trunk/src/world/world.cpp 2006-07-19 20:00:20 UTC (rev 442) +++ trunk/src/world/world.cpp 2006-07-19 23:34:48 UTC (rev 443) @@ -12,6 +12,7 @@ #include "Ogre.h" #include "OgreNoMemoryMacros.h" #include "xmlTag.hpp" +#include "mospPath.hpp" #include "area.hpp" #include "log/logEngine.hpp" #include "ode/ode.h" @@ -21,7 +22,20 @@ #include "location.hpp" #include "SDL.h" -//pWorld World::world = NULL; +#include "area.hpp" +#include "part.hpp" +#include "world.hpp" +#include "driveMass.hpp" +#include "body.hpp" +#include "finalDrive.hpp" +#include "gearbox.hpp" +#include "pedal.hpp" +#include "suspension.hpp" +#include "vehicle.hpp" +#include "wheel.hpp" +#include "driveJoint.hpp" +#include "engine.hpp" +#include "camera.hpp" pWorld World::world; std::string World::newWorld = ""; @@ -81,8 +95,8 @@ activeCamera.reset(); //shouldn't be necessary, but vehicle and area geoms can't be deleted after ode world so we must make sure! - vehicles.clear(); - areas.clear(); + objects.clear(); + objects.clear(); log->__format (LOG_DEVELOPER, "Destroying ODE world"); dSpaceDestroy (spaceID); @@ -93,104 +107,41 @@ dJointGroupDestroy (jointGroupID); } + pLocation World::getLocationObject(std::string fullname) { - pLocation location; - - std::string type; - std::string name; - std::string locname; - bool error = false; - std::string errorMessage = ""; - - if (fullname.find_first_of('(') == 0) + pLocation tmp; + if (MospPath::getType(fullname) == "area") { - //( - unsigned int typeend; - if ((typeend = fullname.find_first_of(')',0)) != std::string::npos) - { - //(type) - type = fullname.substr(1,typeend-1); - unsigned int nameend; - if ((nameend = fullname.find_first_of('/')) != std::string::npos) - { - //(type)name/ - name = fullname.substr(typeend+1,nameend-(typeend+1)); - locname = fullname.substr(nameend+1); - } else { - //(type)name - error = true; - errorMessage = "'/' not found"; - } - } else { - //(type - error = true; - errorMessage = "')' not found"; - } - } else { - //name - log->__format (LOG_DEVELOPER, "Not found '('!"); + pArea a = getArea(MospPath::getName(fullname)); + log->__format(LOG_DEVELOPER, "Area name=%s", a->getName().c_str()); + tmp = a->getLocation(MospPath::getName(MospPath::getSubFullname(fullname))); } - if (error) - { - log->__format (LOG_ERROR, "XML mosp object location syntax error \"%s\": %s", fullname.c_str(), errorMessage.c_str()); - } else { - log->__format (LOG_DEVELOPER, "Type: '%s', Name: '%s'. LocationName: '%s'", type.c_str(), name.c_str(), locname.c_str()); - if (type == "area") - { - pArea tmp = getArea(name); - location = tmp->getLocation(locname); - } - } - return location; + log->__format(LOG_DEVELOPER, "Location name=%s", tmp->getName().c_str()); + return tmp; } pVehicle World::getVehicleObject(std::string fullname) { - pVehicle vehicle; - - std::string type; - std::string name; - bool error = false; - std::string errorMessage = ""; - - if (fullname.find_first_of('(') == 0) - { - //( - unsigned int typeend; - if ((typeend = fullname.find_first_of(')',0)) != std::string::npos) - { - //(type) - type = fullname.substr(1,typeend-1); - unsigned int nameend; - if ((nameend = fullname.find_first_of('/')) != std::string::npos) - { - //(type)name/ - name = fullname.substr(typeend+1,nameend-(typeend+1)); - } else { - //(type)name - name = fullname.substr(typeend+1); - } - } else { - //(type - error = true; - errorMessage = "')' not found"; - } - } else { - //name - log->__format (LOG_DEVELOPER, "Not found '('!"); - } - if (error) - { - log->__format (LOG_ERROR, "XML mosp object location syntax error \"%s\": %s", fullname.c_str(), errorMessage.c_str()); - } else { - log->__format (LOG_DEVELOPER, "Type: '%s', Name: '%s'.", type.c_str(), name.c_str()); - if (type == "vehicle") - { - vehicle = getVehicle(name); - } - } - return vehicle; + pVehicle tmp; + if ((tmp = boost::dynamic_pointer_cast<Vehicle>(getFirstObject(fullname))) == NULL) + log->__format(LOG_ERROR, "Tried to access non-existent world object \"%s\" using type \"%s\"", fullname.c_str(), "Vehicle"); + log->__format(LOG_DEVELOPER, "Vehicle name=%s", tmp->getName().c_str()); + return tmp; } +pWorldObject World::getFirstObject(std::string fullname) +{ + std::string type = MospPath::getType(fullname); + std::string name = MospPath::getName(fullname); + pWorldObject tmp = getObject("(" + type + ")" + name); + log->__format(LOG_DEVELOPER, "Object name=%s", tmp->getName().c_str()); + return tmp; +} +pWorldObject World::getObject (std::string name) +{ + if (objects.find(name) == objects.end()) + log->__format(LOG_ERROR, "Tried to access non-existent world object \"%s\" from generic type \"%s\"", name.c_str(), "WorldObject"); + return objects[name]; +} void World::processXmlRootNode (XmlTag * tag) { @@ -241,7 +192,7 @@ std::string model = o->getAttribute("model"); pVehicle tmp= Vehicle::create(model); tmp->setName(sobjname); - vehicles[tmp->getName()] = tmp; + objects[tmp->getName()] = tmp; } if (o->getName() == "area") { @@ -249,7 +200,7 @@ std::string model = o->getAttribute("model"); pArea tmp = Area::create (model); tmp->setName(sobjname); - areas[tmp->getName()] = tmp; + objects[tmp->getName()] = tmp; } } } @@ -268,7 +219,7 @@ } if (t->getName() == "vehicle-driver") { - log->__format (LOG_CCREATOR, "Setting vehicle ver"); + log->__format (LOG_CCREATOR, "Setting vehicle driver"); std::string f= t->getAttribute("first"); std::string s= t->getAttribute("second"); pVehicle tmp = getVehicleObject(f); @@ -303,25 +254,19 @@ { //NOTE: world is hardcoded not to have a parent, therefore we don't run this line: //WorldObject::setContainer(container); - - AreasIt i = areas.begin(); - for(;i != areas.end(); i++) + WorldObjectsIt i = objects.begin(); + for(;i != objects.end(); i++) { i->second->setContainer(shared_from_this()); } - VehiclesIt v = vehicles.begin(); - for(;v != vehicles.end(); v++) - { - v->second->setContainer(shared_from_this()); - } } pArea World::getArea(std::string name) { pArea tmp; - for (AreasIt i = areas.begin(); i != areas.end(); i++) + for (WorldObjectsIt i = objects.begin(); i != objects.end(); i++) { - if (i->first == ("(Area)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<Area>(i->second)) break; + if (i->first == ("(area)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<Area>(i->second)) break; } if (tmp == NULL) log->__format(LOG_ERROR, "Tried to access non-existent world object \"%s\" using type \"%s\"", name.c_str(), "Area"); return tmp; @@ -330,9 +275,9 @@ pVehicle World::getVehicle(std::string name) { pVehicle tmp; - for (VehiclesIt i = vehicles.begin(); i != vehicles.end(); i++) + for (WorldObjectsIt i = objects.begin(); i != objects.end(); i++) { - if (i->first == ("(Vehicle)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<Vehicle>(i->second)) break; + if (i->first == ("(vehicle)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<Vehicle>(i->second)) break; } if (tmp == NULL) log->__format(LOG_ERROR, "Tried to access non-existent world object \"%s\" using type \"%s\"", name.c_str(), "Vehicle"); return tmp; @@ -341,37 +286,69 @@ void World::stepGraphics() { base->stepGraphics(); - - // Update Ogre's vehicles positions with Ode's positions. - VehiclesIt j = vehicles.begin(); - for (; j != vehicles.end(); j++) - { - j->second->stepGraphics(); - } - AreasIt i = areas.begin(); - for (; i != areas.end(); i++) - { - i->second->stepGraphics(); - } if (cameraDirector == true) { setActiveCamera( getArea("main")->getClosestCamera(getVehicle("main")->getPosition())); } + WorldObjectsIt i = objects.begin(); + for (; i != objects.end(); i++) + { + if (0); + else if (pDoubleWishbone tmp = boost::dynamic_pointer_cast<DoubleWishbone>(i->second)) tmp->stepGraphics(); + else if (pFixed tmp = boost::dynamic_pointer_cast<Fixed >(i->second)) tmp->stepGraphics(); + else if (pUnidimensional tmp = boost::dynamic_pointer_cast<Unidimensional>(i->second)) tmp->stepGraphics(); + else if (pSuspension tmp = boost::dynamic_pointer_cast<Suspension >(i->second)) tmp->stepGraphics(); + else if (pEngine tmp = boost::dynamic_pointer_cast<Engine >(i->second)) tmp->stepGraphics(); + else if (pGearbox tmp = boost::dynamic_pointer_cast<Gearbox >(i->second)) tmp->stepGraphics(); + else if (pWheel tmp = boost::dynamic_pointer_cast<Wheel >(i->second)) tmp->stepGraphics(); + else if (pFinalDrive tmp = boost::dynamic_pointer_cast<FinalDrive >(i->second)) tmp->stepGraphics(); + else if (pDriveMass tmp = boost::dynamic_pointer_cast<DriveMass >(i->second)) tmp->stepGraphics(); + else if (pGear tmp = boost::dynamic_pointer_cast<Gear >(i->second)) tmp->stepGraphics(); + else if (pLSD tmp = boost::dynamic_pointer_cast<LSD >(i->second)) tmp->stepGraphics(); + else if (pClutch tmp = boost::dynamic_pointer_cast<Clutch >(i->second)) tmp->stepGraphics(); + else if (pDriveJoint tmp = boost::dynamic_pointer_cast<DriveJoint >(i->second)) tmp->stepGraphics(); + else if (pGearboxGear tmp = boost::dynamic_pointer_cast<GearboxGear >(i->second)) tmp->stepGraphics(); + else if (pBody tmp = boost::dynamic_pointer_cast<Body >(i->second)) tmp->stepGraphics(); + else if (pPedal tmp = boost::dynamic_pointer_cast<Pedal >(i->second)) tmp->stepGraphics(); + else if (pPart tmp = boost::dynamic_pointer_cast<Part >(i->second)) tmp->stepGraphics(); + else if (pVehicle tmp = boost::dynamic_pointer_cast<Vehicle >(i->second)) tmp->stepGraphics(); + else if (pArea tmp = boost::dynamic_pointer_cast<Area >(i->second)) tmp->stepGraphics(); + else if (pWorld tmp = boost::dynamic_pointer_cast<World >(i->second)) tmp->stepGraphics(); + else if (pCamera tmp = boost::dynamic_pointer_cast<Camera >(i->second)) tmp->stepGraphics(); + else if (pWorldObject tmp = boost::dynamic_pointer_cast<WorldObject >(i->second)) tmp->stepGraphics(); + else log->__format(LOG_ERROR, "Couldn't find out object #%s (%s) type. This should *NOT* have happened.", i->second->getId().c_str(), i->first.c_str()); + } } void World::stepPhysics() { - // Update Ogre's vehicles positions with Ode's positions. - VehiclesIt j = vehicles.begin(); - for (; j != vehicles.end(); j++) + WorldObjectsIt i = objects.begin(); + for (; i != objects.end(); i++) { - j->second->stepPhysics(); + if (0); + else if (pDoubleWishbone tmp = boost::dynamic_pointer_cast<DoubleWishbone>(i->second)) tmp->stepPhysics(); + else if (pFixed tmp = boost::dynamic_pointer_cast<Fixed >(i->second)) tmp->stepPhysics(); + else if (pUnidimensional tmp = boost::dynamic_pointer_cast<Unidimensional>(i->second)) tmp->stepPhysics(); + else if (pSuspension tmp = boost::dynamic_pointer_cast<Suspension >(i->second)) tmp->stepPhysics(); + else if (pEngine tmp = boost::dynamic_pointer_cast<Engine >(i->second)) tmp->stepPhysics(); + else if (pGearbox tmp = boost::dynamic_pointer_cast<Gearbox >(i->second)) tmp->stepPhysics(); + else if (pWheel tmp = boost::dynamic_pointer_cast<Wheel >(i->second)) tmp->stepPhysics(); + else if (pFinalDrive tmp = boost::dynamic_pointer_cast<FinalDrive >(i->second)) tmp->stepPhysics(); + //else if (pDriveMass tmp = boost::dynamic_pointer_cast<DriveMass >(i->second)) tmp->stepPhysics(); + else if (pGear tmp = boost::dynamic_pointer_cast<Gear >(i->second)) tmp->stepPhysics(); + else if (pLSD tmp = boost::dynamic_pointer_cast<LSD >(i->second)) tmp->stepPhysics(); + else if (pClutch tmp = boost::dynamic_pointer_cast<Clutch >(i->second)) tmp->stepPhysics(); + //else if (pDriveJoint tmp = boost::dynamic_pointer_cast<DriveJoint >(i->second)) tmp->stepPhysics(); + //else if (pGearboxGear tmp = boost::dynamic_pointer_cast<GearboxGear >(i->second)) tmp->stepPhysics(); + else if (pBody tmp = boost::dynamic_pointer_cast<Body >(i->second)) tmp->stepPhysics(); + else if (pPedal tmp = boost::dynamic_pointer_cast<Pedal >(i->second)) tmp->stepPhysics(); + else if (pPart tmp = boost::dynamic_pointer_cast<Part >(i->second)) tmp->stepPhysics(); + else if (pVehicle tmp = boost::dynamic_pointer_cast<Vehicle >(i->second)) tmp->stepPhysics(); + else if (pArea tmp = boost::dynamic_pointer_cast<Area >(i->second)) tmp->stepPhysics(); + else if (pWorld tmp = boost::dynamic_pointer_cast<World >(i->second)) tmp->stepPhysics(); + else if (pCamera tmp = boost::dynamic_pointer_cast<Camera >(i->second)) tmp->stepPhysics(); + //else if (pWorldObject tmp = boost::dynamic_pointer_cast<WorldObject >(i->second)) tmp->stepPhysics(); + else log->__format(LOG_ERROR, "Couldn't find out object #%s (%s) type. This should *NOT* have happened.", i->second->getId().c_str(), i->first.c_str()); } - AreasIt i = areas.begin(); - for (; i != areas.end(); i++) - { - i->second->stepPhysics(); - } - } void World::switchNextAreaCamera() { Modified: trunk/src/world/world.hpp =================================================================== --- trunk/src/world/world.hpp 2006-07-19 20:00:20 UTC (rev 442) +++ trunk/src/world/world.hpp 2006-07-19 23:34:48 UTC (rev 443) @@ -35,6 +35,8 @@ World (std::string name); pLocation getLocationObject(std::string fullname); pVehicle getVehicleObject(std::string fullname); + pWorldObject getFirstObject(std::string fullname); + pWorldObject getObject (std::string name); public: static pWorld get(); static void setNewWorld(std::string name); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <st...@us...> - 2006-07-19 20:00:49
|
Revision: 442 Author: stenyak Date: 2006-07-19 13:00:20 -0700 (Wed, 19 Jul 2006) ViewCVS: http://svn.sourceforge.net/motorsport/?rev=442&view=rev Log Message: ----------- Reworked cameras code. Added a layer of abstraction for internal components of each object. Modified code improving support for multiple areas. Modified World xml format, now using the Unified XML Format. The parser still isn't recursive though. Bugfixed some code that referenced objects by their old format (preventing proper control of the vehicle), not the new one that was introduced in last revision. Lots of other things i can't remember now... :) Modified Paths: -------------- trunk/src/common/camera.cpp trunk/src/graphics.cpp trunk/src/main.cpp trunk/src/physics.cpp trunk/src/system.cpp trunk/src/system.hpp trunk/src/vehicle/body.cpp trunk/src/vehicle/body.hpp trunk/src/vehicle/pedal.cpp trunk/src/vehicle/suspension.cpp trunk/src/vehicle/vehicle.cpp trunk/src/vehicle/vehicle.hpp trunk/src/vehicle/wheel.cpp trunk/src/world/area.cpp trunk/src/world/area.hpp trunk/src/world/part.cpp trunk/src/world/world.cpp trunk/src/world/world.hpp Modified: trunk/src/common/camera.cpp =================================================================== --- trunk/src/common/camera.cpp 2006-07-19 03:32:57 UTC (rev 441) +++ trunk/src/common/camera.cpp 2006-07-19 20:00:20 UTC (rev 442) @@ -143,7 +143,7 @@ void Camera::stepPhysics () { - if (this == World::get()->getActiveCamera().get() ) + if (World::get()->isActiveCamera(boost::dynamic_pointer_cast<Camera>(shared_from_this()))) { static bool wasPressed = false; if (System::get()->axisMap[getIDKeyboardKey(SDLK_x)]->getValue() == 1) Modified: trunk/src/graphics.cpp =================================================================== --- trunk/src/graphics.cpp 2006-07-19 03:32:57 UTC (rev 441) +++ trunk/src/graphics.cpp 2006-07-19 20:00:20 UTC (rev 442) @@ -150,107 +150,34 @@ // change camera if needed if (System::get()->axisMap[getIDKeyboardKey(SDLK_c)]->getValue() == 1) { - CamerasIt i = World::get()->areas.begin()->second->cameras.begin(); - pCamera nextCam = i->second; - bool found = false; - for (;i != World::get()->areas.begin()->second->cameras.end(); i++) - { - if (found == true) - { - nextCam = i->second; - found = false; - } - if (World::get()->getActiveAreaCamera()->getName() == i->second->getName()) - { - found = true; - } - } - World::get()->setActiveCamera(nextCam); - World::get()->activeAreaCamera = nextCam; + World::get()->switchNextAreaCamera(); } if (System::get()->axisMap[getIDKeyboardKey(SDLK_v)]->getValue() == 1) { - CamerasIt i = World::get()->vehicles.begin()->second->cameras.begin(); - pCamera nextCam = i->second; - bool found = false; - for (;i != World::get()->vehicles.begin()->second->cameras.end(); i++) - { - if (found == true) - { - nextCam = i->second; - found = false; - } - if (World::get()->getActiveVehicleCamera()->getName() == i->second->getName()) - { - found = true; - } - } - World::get()->setActiveCamera(nextCam); - World::get()->activeVehicleCamera = nextCam; + World::get()->switchNextVehicleCamera(); } - if (System::get()->cameraDirector) + if (System::get()->axisMap[getIDKeyboardKey(SDLK_b)]->getValue() == 1) { - log->__format(LOG_DEVELOPER, "Finding closest camera"); - Vector3d vPos = World::get()->vehicles.begin()->second->getPosition(); - double closestDistance = 99999999999.0; - CamerasIt i = World::get()->areas.begin()->second->cameras.begin(); - pCamera closestCam = i->second; - for (;i != World::get()->areas.begin()->second->cameras.end(); i++) - { - log->__format(LOG_DEVELOPER, "Checking cam id: %s", i->second->getName().c_str()); - Ogre::Vector3 p = i->second->ogreCamera->getPosition(); - Vector3d cPos (p.x, p.y, p.z); - double distance = cPos.distance(vPos); - if (distance < closestDistance) - { - closestDistance = distance; - closestCam = i->second; - } - - } - World::get()->setActiveCamera(closestCam); - World::get()->activeAreaCamera = closestCam; + World::get()->switchCameraDirector(); + System::get()->axisMap[getIDKeyboardKey(SDLK_b)]->setNewRawValue(0); } - // Update Ogre's vehicles positions with Ode's positions. - VehiclesIt j = World::get()->vehicles.begin(); - for (; j != World::get()->vehicles.end(); j++) - { - j->second->stepGraphics(); - } - // Update Ogre's parts positions with Ode's positions. - PartsIt k = World::get()->areas.begin()->second->parts.begin(); - for (; k != World::get()->areas.begin()->second->parts.end(); k++) - { - k->second->stepGraphics(); - } + World::get()->stepGraphics(); - // Update cameras positions (should be done in the fsx engine FIXME - CamerasIt i = World::get()->areas.begin()->second->cameras.begin(); - for (;i != World::get()->areas.begin()->second->cameras.end(); i++) - { - i->second->stepGraphics(); - } - i = World::get()->vehicles.begin()->second->cameras.begin(); - for (;i != World::get()->vehicles.begin()->second->cameras.end(); i++) - { - i->second->stepGraphics(); - } - // Update infinite plane position according to vehicle position - Ogre::Vector3 areaPos (World::get()->areas.begin()->second->planeNode->getPosition()); - Vector3d vehiclePos (World::get()->vehicles.begin()->second->getPosition()); + Ogre::Vector3 areaPos (World::get()->getArea("main")->planeNode->getPosition()); + Vector3d vehiclePos (World::get()->getVehicle("main")->getPosition()); Vector3d diff (areaPos.x - vehiclePos.x, areaPos.y - vehiclePos.y, areaPos.z - vehiclePos.z); const double tile = 1000.0 / 20.0; if (diff.x > tile || diff.x < -tile) areaPos.x -= int ((diff.x) / (tile)) * (tile); if (diff.y > tile || diff.y < -tile) areaPos.y -= int ((diff.y) / (tile)) * (tile); - World::get()->areas.begin()->second->planeNode->setPosition(areaPos); + World::get()->getArea("main")->planeNode->setPosition(areaPos); // Update area shadows state - World::get()->areas.begin()->second->setCastShadows(castAreaShadows); + World::get()->getArea("main")->setCastShadows(castAreaShadows); // Update area render mode - World::get()->areas.begin()->second->setRenderDetail(areaRenderMode); + World::get()->getArea("main")->setRenderDetail(areaRenderMode); // Let the listener frames be started and ended: they are needed for particle System::get()s. ogreRoot->_fireFrameStarted (); Modified: trunk/src/main.cpp =================================================================== --- trunk/src/main.cpp 2006-07-19 03:32:57 UTC (rev 441) +++ trunk/src/main.cpp 2006-07-19 20:00:20 UTC (rev 442) @@ -206,11 +206,6 @@ log->__format (LOG_DEVELOPER, "Processing a SDLK_KP_PLUS keypress..."); system->increaseDesiredPhysicsRate(); } - if (system->axisMap[getIDKeyboardKey(SDLK_b)]->getValue() == 1) - { - system->cameraDirector = !(system->cameraDirector); - system->axisMap[getIDKeyboardKey(SDLK_b)]->setNewRawValue(0); - } } void recordVideoFrames () Modified: trunk/src/physics.cpp =================================================================== --- trunk/src/physics.cpp 2006-07-19 03:32:57 UTC (rev 441) +++ trunk/src/physics.cpp 2006-07-19 20:00:20 UTC (rev 442) @@ -126,28 +126,9 @@ } int Physics::computeStep (void) -//makes the graphics engine draw one frame { - // mega-verbosity - log->__format (LOG_DEVELOPER, "Doing an step: calculating a physics step"); + World::get()->stepPhysics(); - PartsIt k = World::get()->areas.begin()->second->parts.begin(); - for (; k != World::get()->areas.begin()->second->parts.end(); k++) - { - k->second->stepPhysics(); - } - - CamerasIt i = World::get()->areas.begin()->second->cameras.begin(); - for(;i != World::get()->areas.begin()->second->cameras.end();i++) - { - i->second->stepPhysics(); - } - i = World::get()->vehicles.begin()->second->cameras.begin(); - for(;i != World::get()->vehicles.begin()->second->cameras.end();i++) - { - i->second->stepPhysics(); - } - checkpointPassed = false; dSpaceCollide (World::get()->spaceID, 0, &nearCallback); switch (stepType) @@ -162,12 +143,6 @@ dWorldStepFast1 (World::get()->worldID, system->getDesiredPhysicsTimestep(), dWorldStepFast1MaxIterations); break; } - VehiclesIt j = World::get()->vehicles.begin(); - for (; j != World::get()->vehicles.end(); j++) - { - j->second->stepPhysics(); - } - dJointGroupEmpty (World::get()->jointGroupID); // check if a car has passed the checkpoint Modified: trunk/src/system.cpp =================================================================== --- trunk/src/system.cpp 2006-07-19 03:32:57 UTC (rev 441) +++ trunk/src/system.cpp 2006-07-19 20:00:20 UTC (rev 442) @@ -66,7 +66,6 @@ height = 1; width = 1; videoRecordTimestep = 0; - cameraDirector = false; } } Modified: trunk/src/system.hpp =================================================================== --- trunk/src/system.hpp 2006-07-19 03:32:57 UTC (rev 441) +++ trunk/src/system.hpp 2006-07-19 20:00:20 UTC (rev 442) @@ -219,8 +219,6 @@ Ogre::RenderWindow * ogreWindow; Ogre::SceneManager * ogreSceneManager; std::map <int, Axis * > axisMap; - - bool cameraDirector; }; #endif Modified: trunk/src/vehicle/body.cpp =================================================================== --- trunk/src/vehicle/body.cpp 2006-07-19 03:32:57 UTC (rev 441) +++ trunk/src/vehicle/body.cpp 2006-07-19 20:00:20 UTC (rev 442) @@ -26,6 +26,7 @@ Body::Body (XmlTag * tag) :WorldObject("body") { + userDriver = false; dragCoefficient = 0.3; frontalArea = 0; pBodyOdeData data(new BodyOdeData); @@ -79,7 +80,7 @@ void Body::stepPhysics () { dBodyID bodyID = getMainOdeObject()->getBodyID(); - if (this == World::get()->vehicles.begin()->second->getObject("(Body)main").get()) + if (userDriver) { double moveZ = System::get()->axisMap[getIDKeyboardKey(SDLK_BACKSPACE)]->getValue() * 50000; moveZ += System::get()->axisMap[getIDKeyboardKey(SDLK_RETURN)]->getValue() * 12200; @@ -103,3 +104,7 @@ log->__format(LOG_DEVELOPER, "Body air drag force = (%f, %f, %f)", force.x, force.y, force.z); } +void Body::setUserDriver () +{ + userDriver = true; +} Modified: trunk/src/vehicle/body.hpp =================================================================== --- trunk/src/vehicle/body.hpp 2006-07-19 03:32:57 UTC (rev 441) +++ trunk/src/vehicle/body.hpp 2006-07-19 20:00:20 UTC (rev 442) @@ -23,6 +23,7 @@ class Body : public WorldObject { private: + bool userDriver; double dragCoefficient; double frontalArea; void stopPhysics (); @@ -32,5 +33,6 @@ static pBody create (XmlTag * tag); ~Body (); void stepPhysics (); + void setUserDriver (); }; #endif Modified: trunk/src/vehicle/pedal.cpp =================================================================== --- trunk/src/vehicle/pedal.cpp 2006-07-19 03:32:57 UTC (rev 441) +++ trunk/src/vehicle/pedal.cpp 2006-07-19 20:00:20 UTC (rev 442) @@ -25,12 +25,12 @@ log->__format (LOG_CCREATOR, "Starting to parse a pedal node"); angleRange = 180; currentAngle = 0.0; + userDriver = false; if (tag->getName() == "pedal") { setName ( tag->getAttribute("name")); angleRange = stod (tag->getAttribute("angleRange")); } - userDriver = false; } Pedal::~Pedal () @@ -48,7 +48,7 @@ currentAngle = 0; if ( userDriver ) { - if (getName() == "gasPedal") + if (getName() == "(Pedal)gas") { currentAngle = 1 - System::get()->axisMap[getIDJoyAxis(0,2)]->getValue(); if (currentAngle == 0) { @@ -60,7 +60,7 @@ if (currentAngle == 0) { currentAngle = System::get()->axisMap[getIDKeyboardKey(SDLK_UP)]->getValue() * 3 / 3; } } } } - } else if (getName() == "brakePedal") + } else if (getName() == "(Pedla)brake") { currentAngle = 1 - System::get()->axisMap[getIDJoyAxis(0,1)]->getValue(); if (currentAngle == 0) { @@ -72,7 +72,7 @@ if (currentAngle == 0) { currentAngle = System::get()->axisMap[getIDKeyboardKey(SDLK_DOWN)]->getValue() * 3 / 3; } } } } - } else if (getName() == "clutchPedal") + } else if (getName() == "(Pedal)clutch") { currentAngle = System::get()->axisMap[getIDKeyboardKey(SDLK_KP7)]->getValue() * 3 / 3; if (currentAngle == 0) { Modified: trunk/src/vehicle/suspension.cpp =================================================================== --- trunk/src/vehicle/suspension.cpp 2006-07-19 03:32:57 UTC (rev 441) +++ trunk/src/vehicle/suspension.cpp 2006-07-19 20:00:20 UTC (rev 442) @@ -26,6 +26,7 @@ { position = Vector3d (0, 0, 0); rotation = Quaternion (1, 0, 0, 0); + userDriver = false; } Suspension::~Suspension () Modified: trunk/src/vehicle/vehicle.cpp =================================================================== --- trunk/src/vehicle/vehicle.cpp 2006-07-19 03:32:57 UTC (rev 441) +++ trunk/src/vehicle/vehicle.cpp 2006-07-19 20:00:20 UTC (rev 442) @@ -68,12 +68,14 @@ // spread the news to the necessary (input-able) vehicle parts for (WorldObjectsIt i = components.begin(); i != components.end(); i++) { - Pedal * tmpPedal; - if ( (tmpPedal = dynamic_cast<Pedal*>(i->second.get())) != 0) tmpPedal->setUserDriver(); - Wheel * tmpWheel; - if ( (tmpWheel = dynamic_cast<Wheel*>(i->second.get())) != 0) tmpWheel->setUserDriver(); - Suspension * tmpSusp; - if ( (tmpSusp = dynamic_cast<Suspension*>(i->second.get())) != 0) tmpSusp->setUserDriver(); + pBody tmpBody; + if ( (tmpBody = boost::dynamic_pointer_cast<Body>(i->second))) tmpBody->setUserDriver(); + pPedal tmpPedal; + if ( (tmpPedal = boost::dynamic_pointer_cast<Pedal>(i->second))) tmpPedal->setUserDriver(); + pWheel tmpWheel; + if ( (tmpWheel = boost::dynamic_pointer_cast<Wheel>(i->second))) tmpWheel->setUserDriver(); + pSuspension tmpSusp; + if ( (tmpSusp = boost::dynamic_pointer_cast<Suspension>(i->second))) tmpSusp->setUserDriver(); } } @@ -117,6 +119,8 @@ if (u) System::get()->ogreWindow->update (); } } + //initialize cameras... + pointCameras(); // spread the news to the necessary (input-able) vehicle parts log->__format(LOG_DEVELOPER, "Setting some drive joint pointers..."); getClutch("main")->setOutputPointer(getGearbox("main")); @@ -139,8 +143,8 @@ getClutch("main")->setClutchPedal(getPedal("clutch")); for (WorldObjectsIt i = components.begin(); i != components.end(); i++) { - Wheel * tmpWheel; - if ( (tmpWheel = dynamic_cast<Wheel*>(i->second.get())) != 0) + pWheel tmpWheel; + if ((tmpWheel = boost::dynamic_pointer_cast<Wheel>(i->second))) { tmpWheel->setBrakePedal(getPedal("brake")); } @@ -177,42 +181,47 @@ { base->stepGraphics(); - std::map < std::string, Suspension * >::const_iterator suspIter; + CamerasIt i = cameras.begin(); + for (;i != cameras.end(); i++) + { + if (i->second == NULL) log->__format(LOG_ERROR, "Camera %s doesn't exist", i->first.c_str()); + i->second->stepGraphics(); + } for (WorldObjectsIt i = components.begin(); i != components.end(); i++) { - DoubleWishbone * tmpSusp; - if ( (tmpSusp = dynamic_cast<DoubleWishbone*>(i->second.get())) != 0) tmpSusp->stepGraphics(); - Wheel * tmpWheel; - if ( (tmpWheel = dynamic_cast<Wheel*>(i->second.get())) != 0) tmpWheel->stepGraphics(); - Body * tmpBody; - if ( (tmpBody = dynamic_cast<Body*>(i->second.get())) != 0) tmpBody->stepGraphics(); + pDoubleWishbone tmpSusp; + if ( (tmpSusp = boost::dynamic_pointer_cast<DoubleWishbone>(i->second))) tmpSusp->stepGraphics(); + pWheel tmpWheel; + if ( (tmpWheel = boost::dynamic_pointer_cast<Wheel>(i->second))) tmpWheel->stepGraphics(); + pBody tmpBody; + if ( (tmpBody = boost::dynamic_pointer_cast<Body>(i->second))) tmpBody->stepGraphics(); } } pOdeObject Vehicle::getMainOdeObject() { - return getObject("(Body)main")->getMainOdeObject(); + return getBody("main")->getMainOdeObject(); } void Vehicle::setPosition (Vector3d position) { Vector3d posDiff = position - getPosition(); log->__format (LOG_DEVELOPER,"Difference in vehicle position: (%f, %f, %f).", posDiff.x, posDiff.y, posDiff.z); - getObject("(Body)main")->setPosition ( getObject("(Body)main")->getPosition() + posDiff ); + getBody("main")->setPosition ( getBody("main")->getPosition() + posDiff ); for (WorldObjectsIt i = components.begin(); i != components.end(); i++) { - Wheel * tmpWheel; - if ( (tmpWheel = dynamic_cast<Wheel*>(i->second.get())) != 0) + pWheel tmpWheel; + if ( (tmpWheel = boost::dynamic_pointer_cast<Wheel>(i->second))) tmpWheel->getMainOdeObject()->setPosition ( tmpWheel->getMainOdeObject()->getPosition() + posDiff ); - Suspension * tmpSusp; - if ( (tmpSusp = dynamic_cast<Suspension*>(i->second.get())) != 0) + pSuspension tmpSusp; + if ( (tmpSusp = boost::dynamic_pointer_cast<Suspension>(i->second))) tmpSusp->setPosition ( tmpSusp->getPosition() + posDiff ); } } Vector3d Vehicle::getPosition () { - return getObject("(Body)main")->getPosition(); + return getBody("main")->getPosition(); } void Vehicle::applyRotation (Quaternion rotation) @@ -220,48 +229,51 @@ // apply rotation to wheels for (WorldObjectsIt i = components.begin(); i != components.end(); i++) { - Wheel * tmpWheel; - if ( (tmpWheel = dynamic_cast<Wheel*>(i->second.get())) != 0) - tmpWheel->applyRotation (rotation); - Suspension * tmpSusp; - if ( (tmpSusp = dynamic_cast<Suspension*>(i->second.get())) != 0) - tmpSusp->applyRotation (rotation); + pWheel tmpWheel; + if ( (tmpWheel = boost::dynamic_pointer_cast<Wheel>(i->second))) tmpWheel->applyRotation (rotation); + pSuspension tmpSusp; + if ( (tmpSusp = boost::dynamic_pointer_cast<Suspension>(i->second))) tmpSusp->applyRotation (rotation); } // apply rotation to body - getObject("(Body)main")->applyRotation (rotation); + getBody("main")->applyRotation (rotation); } Quaternion Vehicle::getRotation () { - return getObject("(Body)main")->getRotation(); + return getBody("main")->getRotation(); } void Vehicle::placeWheelsOnSuspensions() { getWheel("fr")->applyRotation(getSuspension("fr")->getSecondLinkRotation()); - getWheel("fr")->setPosition(getSuspension("fr")->getSecondLinkPosition()); + getWheel("fr")->setPosition (getSuspension("fr")->getSecondLinkPosition()); getWheel("fl")->applyRotation(getSuspension("fl")->getSecondLinkRotation()); - getWheel("fl")->setPosition(getSuspension("fl")->getSecondLinkPosition()); + getWheel("fl")->setPosition (getSuspension("fl")->getSecondLinkPosition()); getWheel("rr")->applyRotation(getSuspension("rr")->getSecondLinkRotation()); - getWheel("rr")->setPosition(getSuspension("rr")->getSecondLinkPosition()); + getWheel("rr")->setPosition (getSuspension("rr")->getSecondLinkPosition()); getWheel("rl")->applyRotation(getSuspension("rl")->getSecondLinkRotation()); - getWheel("rl")->setPosition(getSuspension("rl")->getSecondLinkPosition()); + getWheel("rl")->setPosition (getSuspension("rl")->getSecondLinkPosition()); } void Vehicle::boltWheelsToSuspensions() { - getSuspension("fr")->attach(getObject("(Body)main"), getObject("(Wheel)fr")); - getSuspension("fl")->attach(getObject("(Body)main"), getObject("(Wheel)fl")); - getSuspension("rr")->attach(getObject("(Body)main"), getObject("(Wheel)rr")); - getSuspension("rl")->attach(getObject("(Body)main"), getObject("(Wheel)rl")); + getSuspension("fr")->attach(getBody("main"), getWheel("fr")); + getSuspension("fl")->attach(getBody("main"), getWheel("fl")); + getSuspension("rr")->attach(getBody("main"), getWheel("rr")); + getSuspension("rl")->attach(getBody("main"), getWheel("rl")); } void Vehicle::stepPhysics () { + for(CamerasIt c = cameras.begin() ;c !=cameras.end();c++) + { + c->second->stepPhysics(); + } + for (WorldObjectsIt i = components.begin(); i != components.end(); i++) { - Pedal * tmpPedal; - if ( (tmpPedal = dynamic_cast<Pedal*>(i->second.get())) != 0) + pPedal tmpPedal; + if ( (tmpPedal = boost::dynamic_pointer_cast<Pedal>(i->second))) { tmpPedal->stepPhysics(); } @@ -289,21 +301,20 @@ getGearbox("main")->stepPhysics(); getFinalDrive("main")->stepPhysics(); getBody("main")->stepPhysics(); - std::map < std::string, Suspension * >::const_iterator suspIter; for (WorldObjectsIt i = components.begin(); i != components.end(); i++) { - Suspension * tmpSusp; - if ( (tmpSusp = dynamic_cast<Suspension*>(i->second.get())) != 0) tmpSusp->stepPhysics(); - Wheel * tmpWheel; - if ( (tmpWheel = dynamic_cast<Wheel*>(i->second.get())) != 0) tmpWheel->stepPhysics(); + pSuspension tmpSusp; + if ((tmpSusp = boost::dynamic_pointer_cast<Suspension>(i->second))) tmpSusp->stepPhysics(); + pWheel tmpWheel; + if ((tmpWheel = boost::dynamic_pointer_cast<Wheel>(i->second))) tmpWheel->stepPhysics(); } // print telemetry data if ( userDriver ) { - const dReal * tmp = dBodyGetLinearVel(getObject("(Body)main")->getMainOdeObject()->getBodyID()); + const dReal * tmp = dBodyGetLinearVel(getBody("main")->getMainOdeObject()->getBodyID()); double velocity = sqrt(tmp[0]*tmp[0]+tmp[1]*tmp[1]+tmp[2]*tmp[2]); - tmp = dBodyGetPosition(getObject("(Body)main")->getMainOdeObject()->getBodyID()); + tmp = dBodyGetPosition(getBody("main")->getMainOdeObject()->getBodyID()); double distance = sqrt(tmp[0]*tmp[0]+tmp[1]*tmp[1]+tmp[2]*tmp[2]); log->log (LOG_ENDUSER, LOG_TELEMETRY | LOG_FILE, "%9.5f %12.8f %12.8f %12.8f %12.8f %s %12.8f", velocity, getEngine("main")->getOutputAngularVel(), getFinalDrive("main")->getInputAngularVel(), getWheel("rr")->getInputAngularVel(), getWheel("rl")->getInputAngularVel(), getGearbox("main")->getCurrentGearName().c_str(), distance); } @@ -465,3 +476,44 @@ if (tmp == NULL) log->__format(LOG_ERROR, "Tried to access non-existent world object \"%s\" using type \"%s\"", name.c_str(), "WorldObject"); return tmp; } +pCamera Vehicle::getCamera (std::string name) +{ + pCamera tmp; + for (CamerasIt i = cameras.begin(); i != cameras.end(); i++) + { + if (i->first == (name) && i->second) if (tmp = boost::dynamic_pointer_cast<Camera>(i->second)) break; + if (i->first == ("(Camera)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<Camera>(i->second)) break; + } + if (tmp == NULL) log->__format(LOG_ERROR, "Tried to access non-existent world object \"%s\" using type \"%s\"", name.c_str(), "Camera"); + return tmp; +} + +pCamera Vehicle::switchNextCamera() +{ + CamerasIt i = cameras.begin(); + pCamera nextCam = i->second; + bool found = false; + for (;i != cameras.end(); i++) + { + if (found == true) + { + nextCam = i->second; + found = false; + } + if (activeCamera == i->second) + { + found = true; + } + } + activeCamera = nextCam; + return activeCamera; +} +void Vehicle::pointCameras() +{ + CamerasIt i = cameras.begin(); + for(;i != cameras.end(); i++) + { + i->second->setPositionID( getMainOdeObject()->getBodyID()); + i->second->setTarget( getMainOdeObject()); + } +} Modified: trunk/src/vehicle/vehicle.hpp =================================================================== --- trunk/src/vehicle/vehicle.hpp 2006-07-19 03:32:57 UTC (rev 441) +++ trunk/src/vehicle/vehicle.hpp 2006-07-19 20:00:20 UTC (rev 442) @@ -48,13 +48,16 @@ void boltWheelsToSuspensions(); void stopGraphics (); WorldObjects components; + Cameras cameras; + pCamera activeCamera; + void pointCameras(); Vehicle (std::string vehicleName); public: static pVehicle create(std::string vehicleName); void setContainer (pWorldObject container); ~Vehicle (); - Cameras cameras; + pCamera getCamera (std::string name); pBody getBody (std::string name); pDriveJoint getDriveJoint (std::string name); pDriveMass getDriveMass (std::string name); @@ -71,6 +74,7 @@ pWorldObject getObject (std::string name); pWorldObject getWorldObject (std::string name); + pCamera switchNextCamera(); void setUserDriver (); void stepPhysics (); void setPosition (Vector3d position); Modified: trunk/src/vehicle/wheel.cpp =================================================================== --- trunk/src/vehicle/wheel.cpp 2006-07-19 03:32:57 UTC (rev 441) +++ trunk/src/vehicle/wheel.cpp 2006-07-19 20:00:20 UTC (rev 442) @@ -31,6 +31,7 @@ log->__format (LOG_DEVELOPER, "Starting to parse a wheel node"); pWheelOdeData data(new WheelOdeData); pOgreObjectData ogreData(new OgreObjectData); + userDriver = false; powered = 0; inputAngularVel = 0.0; outputAngularVel = 0.0; Modified: trunk/src/world/area.cpp =================================================================== --- trunk/src/world/area.cpp 2006-07-19 03:32:57 UTC (rev 441) +++ trunk/src/world/area.cpp 2006-07-19 20:00:20 UTC (rev 442) @@ -14,6 +14,7 @@ #include "system.hpp" #include "camera.hpp" #include "part.hpp" +#include "vehicle.hpp" #include "ode/ode.h" #include "location.hpp" #include "world.hpp" @@ -186,6 +187,15 @@ i->second->setContainer(shared_from_this()); } } +void Area::pointCameras(pVehicle target) +{ + CamerasIt i = cameras.begin(); + for(;i != cameras.end(); i++) + { + i->second->setPositionID(areaBodyID); + i->second->setTarget(target->getMainOdeObject()); + } +} void Area::setCastShadows(bool castShadows) { planeEntity->setCastShadows(castShadows); @@ -323,3 +333,96 @@ current_offset = next_offset; } } + +pLocation Area::getLocation (std::string name) +{ + pLocation tmp; + for (LocationsIt i = locations.begin(); i != locations.end(); i++) + { + if (i->first == name && i->second) if (tmp = boost::dynamic_pointer_cast<Location>(i->second)) break; + } + if (tmp == NULL) log->__format(LOG_ERROR, "Tried to access non-existent world object \"%s\" using type \"%s\"", name.c_str(), "Location"); + return tmp; +} + +void Area::stepGraphics() +{ + base->stepGraphics(); + + PartsIt k = parts.begin(); + for (; k != parts.end(); k++) + { + k->second->stepGraphics(); + } + CamerasIt i = cameras.begin(); + for (;i != cameras.end(); i++) + { + i->second->stepGraphics(); + } +} + +void Area::stepPhysics() +{ + PartsIt k = parts.begin(); + for (; k != parts.end(); k++) + { + k->second->stepPhysics(); + } + CamerasIt i = cameras.begin(); + for (;i != cameras.end(); i++) + { + i->second->stepPhysics(); + } +} +pCamera Area::getCamera (std::string name) +{ + pCamera tmp; + for (CamerasIt i = cameras.begin(); i != cameras.end(); i++) + { + if (i->first == ("(Camera)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<Camera>(i->second)) break; + } + if (tmp == NULL) log->__format(LOG_ERROR, "Tried to access non-existent world object \"%s\" using type \"%s\"", name.c_str(), "Camera"); + return tmp; +} +pCamera Area::switchNextCamera() +{ + CamerasIt i = cameras.begin(); + pCamera nextCam = i->second; + bool found = false; + for (;i != cameras.end(); i++) + { + if (found == true) + { + nextCam = i->second; + found = false; + } + if (activeCamera == i->second) + { + found = true; + } + } + activeCamera = nextCam; + return activeCamera; +} + +pCamera Area::getClosestCamera(Vector3d location) +{ + log->__format(LOG_DEVELOPER, "Finding closest camera"); + double closestDistance = 99999999999.0; + CamerasIt i = cameras.begin(); + pCamera closestCam = i->second; + for (;i != cameras.end(); i++) + { + log->__format(LOG_DEVELOPER, "Checking cam id: %s", i->second->getName().c_str()); + Ogre::Vector3 p = i->second->ogreCamera->getPosition(); + Vector3d cPos (p.x, p.y, p.z); + double distance = cPos.distance(location); + if (distance < closestDistance) + { + closestDistance = distance; + closestCam = i->second; + } + } + activeCamera = closestCam; + return activeCamera; +} Modified: trunk/src/world/area.hpp =================================================================== --- trunk/src/world/area.hpp 2006-07-19 03:32:57 UTC (rev 441) +++ trunk/src/world/area.hpp 2006-07-19 20:00:20 UTC (rev 442) @@ -23,6 +23,7 @@ SHARED_PTR_MAP(Camera, pCamera, Cameras, CameraIt, wCamera); SHARED_PTR_MAP(Part, pPart, Parts, PartsIt, wPart); SHARED_PTR_MAP(Area, pArea, Areas, AreasIt, wArea); +SHARED_PTR(Vehicle, pVehicle, wVehicle); class Area : public WorldObject { @@ -31,6 +32,9 @@ std::string author; std::string contact; std::string license; + Locations locations; + Cameras cameras; + pCamera activeCamera; void construct (XmlTag * tag); Area (std::string areaName); public: @@ -38,11 +42,16 @@ void setContainer(pWorldObject worldObject); ~Area (); - Locations locations; + pLocation getLocation (std::string name); + pCamera getCamera (std::string name); + void pointCameras(pVehicle target); Parts parts; - Cameras cameras; dBodyID areaBodyID; + void stepGraphics(); + void stepPhysics(); + pCamera switchNextCamera(); + pCamera getClosestCamera(Vector3d location); Ogre::SceneNode * planeNode; Ogre::Entity * planeEntity; Modified: trunk/src/world/part.cpp =================================================================== --- trunk/src/world/part.cpp 2006-07-19 03:32:57 UTC (rev 441) +++ trunk/src/world/part.cpp 2006-07-19 20:00:20 UTC (rev 442) @@ -101,7 +101,7 @@ dBodySetAngularVel (partID, (*(dReal *) (dBodyGetAngularVel (partID) + 0)) * (dReal) (0.999), (*(dReal *) (dBodyGetAngularVel (partID) + 1)) * (dReal) (0.999), (*(dReal *) (dBodyGetAngularVel (partID) + 2)) * (dReal) (0.999)); // ////////////////////////////////////simplified air friction // applying user input [forces] - if (this == World::get()->areas.begin()->second->parts.begin()->second.get()) + if (this == World::get()->getArea("main")->parts.begin()->second.get()) { float moveX = System::get()->axisMap[getIDKeyboardKey(SDLK_l)]->getValue(); float moveY = System::get()->axisMap[getIDKeyboardKey(SDLK_i)]->getValue(); Modified: trunk/src/world/world.cpp =================================================================== --- trunk/src/world/world.cpp 2006-07-19 03:32:57 UTC (rev 441) +++ trunk/src/world/world.cpp 2006-07-19 20:00:20 UTC (rev 442) @@ -67,6 +67,7 @@ pWorld tmp(this); world = tmp; setPath(Paths::world(name)); + setName(name); setXmlPath(Paths::worldXml(name)); log->loadscreen (LOG_ENDUSER, "Starting to load the world (%s)", getXmlPath().c_str()); XmlTag * tag = new XmlTag (getXmlPath().c_str()); @@ -78,8 +79,6 @@ World::~World () { activeCamera.reset(); - activeAreaCamera.reset(); - activeVehicleCamera.reset(); //shouldn't be necessary, but vehicle and area geoms can't be deleted after ode world so we must make sure! vehicles.clear(); @@ -94,38 +93,107 @@ dJointGroupDestroy (jointGroupID); } - -void World::processXmlRootNode (XmlTag * tag) +pLocation World::getLocationObject(std::string fullname) { - description = "none"; - double gravityX = 0.0; - double gravityY = 0.0; - double gravityZ = 0.0; - XmlTag * vehiclesTag = NULL; - bool useAreaCamera = true; //if false, use vehicle camera - std::string areaDirectory = "testingGround"; + pLocation location; - if (tag->getName() == "world") + std::string type; + std::string name; + std::string locname; + bool error = false; + std::string errorMessage = ""; + + if (fullname.find_first_of('(') == 0) { - setName(tag->getAttribute("name")); - description = tag->getAttribute("description"); - useAreaCamera = stob(tag->getAttribute("useAreaCamera")); - gravityX = stod(tag->getAttribute("gravityX")); - gravityY = stod(tag->getAttribute("gravityY")); - gravityZ = stod(tag->getAttribute("gravityZ")); - XmlTag * t = tag->getTag(0); for (int i = 0; i < tag->nTags(); t = tag->getTag(++i)) + //( + unsigned int typeend; + if ((typeend = fullname.find_first_of(')',0)) != std::string::npos) { - if (t->getName() == "vehicleList") + //(type) + type = fullname.substr(1,typeend-1); + unsigned int nameend; + if ((nameend = fullname.find_first_of('/')) != std::string::npos) { - vehiclesTag = t; + //(type)name/ + name = fullname.substr(typeend+1,nameend-(typeend+1)); + locname = fullname.substr(nameend+1); + } else { + //(type)name + error = true; + errorMessage = "'/' not found"; } - if (t->getName() == "area") + } else { + //(type + error = true; + errorMessage = "')' not found"; + } + } else { + //name + log->__format (LOG_DEVELOPER, "Not found '('!"); + } + if (error) + { + log->__format (LOG_ERROR, "XML mosp object location syntax error \"%s\": %s", fullname.c_str(), errorMessage.c_str()); + } else { + log->__format (LOG_DEVELOPER, "Type: '%s', Name: '%s'. LocationName: '%s'", type.c_str(), name.c_str(), locname.c_str()); + if (type == "area") + { + pArea tmp = getArea(name); + location = tmp->getLocation(locname); + } + } + return location; +} +pVehicle World::getVehicleObject(std::string fullname) +{ + pVehicle vehicle; + + std::string type; + std::string name; + bool error = false; + std::string errorMessage = ""; + + if (fullname.find_first_of('(') == 0) + { + //( + unsigned int typeend; + if ((typeend = fullname.find_first_of(')',0)) != std::string::npos) + { + //(type) + type = fullname.substr(1,typeend-1); + unsigned int nameend; + if ((nameend = fullname.find_first_of('/')) != std::string::npos) { - areaDirectory = t->getAttribute("directory"); + //(type)name/ + name = fullname.substr(typeend+1,nameend-(typeend+1)); + } else { + //(type)name + name = fullname.substr(typeend+1); } + } else { + //(type + error = true; + errorMessage = "')' not found"; } + } else { + //name + log->__format (LOG_DEVELOPER, "Not found '('!"); } - + if (error) + { + log->__format (LOG_ERROR, "XML mosp object location syntax error \"%s\": %s", fullname.c_str(), errorMessage.c_str()); + } else { + log->__format (LOG_DEVELOPER, "Type: '%s', Name: '%s'.", type.c_str(), name.c_str()); + if (type == "vehicle") + { + vehicle = getVehicle(name); + } + } + return vehicle; +} + +void World::processXmlRootNode (XmlTag * tag) +{ log->__format (LOG_DEVELOPER, "Temporary parsing data already loaded into memory..."); log->loadscreen (LOG_DEVELOPER, "Creating ODE world"); dRandSetSeed(0); @@ -133,7 +201,7 @@ ghostWorldID = dWorldCreate (); spaceID = dHashSpaceCreate (0); jointGroupID = dJointGroupCreate (0); - + if (System::get()->getCfmValue() != -1) { log->__format (LOG_DEVELOPER, "Setting ODE cfm value to %f", System::get()->getCfmValue()); @@ -145,47 +213,82 @@ dWorldSetERP (worldID, System::get()->getErpValue()); } - log->__format ( LOG_DEVELOPER, "Setting ODE world gravity"); - dWorldSetGravity (worldID, gravityX, gravityY, gravityZ); - dWorldSetGravity (ghostWorldID, 0, 0, 0); + bool useAreaCamera = true; //if false, use vehicle camera + if (tag->getName() == "world") + { + XmlTag * t = tag->getTag(0); for (int i = 0; i < tag->nTags(); t = tag->getTag(++i)) + { + if (t->getName() == "customData") + { + description = t->getAttribute("description"); + useAreaCamera = stob(t->getAttribute("useAreaCamera")); - // load area (and its cameras) - log->loadscreen (LOG_CCREATOR, "Creating a area"); - pArea area = Area::create (areaDirectory); - //FIXME shared ptr container set?? - //area->setPosition (0.0, 0.0, 0.0); //evo2 maybe... ;) - areas[area->getName()] = area; + double gravityX = stod(t->getAttribute("gravityX")); + double gravityY = stod(t->getAttribute("gravityY")); + double gravityZ = stod(t->getAttribute("gravityZ")); + log->__format ( LOG_DEVELOPER, "Setting ODE world gravity"); + dWorldSetGravity (worldID, gravityX, gravityY, gravityZ); + dWorldSetGravity (ghostWorldID, 0, 0, 0); + } + if (t->getName() == "sharedobject") + { + std::string sobjname = t->getAttribute("name"); + XmlTag * o = t->getTag(0); for (int i = 0; i < t->nTags(); o = t->getTag(++i)) + { + if (o->getName() == "vehicle") + { + log->loadscreen (LOG_CCREATOR, "Creating a vehicle"); + std::string model = o->getAttribute("model"); + pVehicle tmp= Vehicle::create(model); + tmp->setName(sobjname); + vehicles[tmp->getName()] = tmp; + } + if (o->getName() == "area") + { + log->loadscreen (LOG_CCREATOR, "Creating an area"); + std::string model = o->getAttribute("model"); + pArea tmp = Area::create (model); + tmp->setName(sobjname); + areas[tmp->getName()] = tmp; + } + } + } + if (t->getName() == "location-vehicle") + { + log->__format (LOG_CCREATOR, "Setting vehicle location"); + std::string f= t->getAttribute("first"); + std::string s= t->getAttribute("second"); + pLocation first = getLocationObject(f); + pVehicle second = getVehicleObject(s); - // load all vehicles - log->loadscreen (LOG_CCREATOR, "Creating all vehicles"); - processXmlVehicleListNode (vehiclesTag); - + second->setPosition(Vector3d(0, 0, 0)); + second->applyRotation(first->getRotation()); + second->setPosition(first->getPosition()); + log->__format(LOG_DEVELOPER, "Rotation: x%f, y%f, z%f, w%f. Rotation: %f, %f, %f", first->getRotation().x,first->getRotation().y,first->getRotation().z,first->getRotation().w,first->getPosition().x,first->getPosition().y,first->getPosition().z); + } + if (t->getName() == "vehicle-driver") + { + log->__format (LOG_CCREATOR, "Setting vehicle ver"); + std::string f= t->getAttribute("first"); + std::string s= t->getAttribute("second"); + pVehicle tmp = getVehicleObject(f); + if (s == "user" ) tmp->setUserDriver(); + } + } + } // initialize cameras (pointing to car 0 by default) - CamerasIt i = areas.begin()->second->cameras.begin(); - for(;i != areas.begin()->second->cameras.end(); i++) - { - i->second->setPositionID( areas.begin()->second->areaBodyID ); - i->second->setTarget( vehicles.begin()->second->getMainOdeObject()); - } - i = vehicles.begin()->second->cameras.begin(); - for(;i != vehicles.begin()->second->cameras.end(); i++) - { - i->second->setPositionID( vehicles.begin()->second->getMainOdeObject()->getBodyID()); - i->second->setTarget( vehicles.begin()->second->getMainOdeObject() ); - } + getArea("main")->pointCameras(getVehicle("main")); // set active camera log->loadscreen (LOG_DEVELOPER, "Setting camera viewport"); if (useAreaCamera) { //err... use... area camera, i guess. - setActiveCamera (areas.begin()->second->cameras.begin()->second); + setActiveCamera (getArea("main")->getCamera("main")); } else { //don't use area camera: use vehicle camera - setActiveCamera (vehicles.begin()->second->cameras.begin()->second); + setActiveCamera (getVehicle("main")->getCamera("main")); } - activeAreaCamera = areas.begin()->second->cameras.begin()->second; - activeVehicleCamera = vehicles.begin()->second->cameras.begin()->second; } void World::setActiveCamera (pCamera camera) @@ -196,72 +299,95 @@ log->__format (LOG_ENDUSER, "Changed camera..."); } -pCamera World::getActiveCamera (void) +void World::setContainer() { - return activeCamera; -} + //NOTE: world is hardcoded not to have a parent, therefore we don't run this line: + //WorldObject::setContainer(container); -pCamera World::getActiveAreaCamera() -{ - return areas.begin()->second->cameras[activeAreaCamera->getName()]; + AreasIt i = areas.begin(); + for(;i != areas.end(); i++) + { + i->second->setContainer(shared_from_this()); + } + VehiclesIt v = vehicles.begin(); + for(;v != vehicles.end(); v++) + { + v->second->setContainer(shared_from_this()); + } } -pCamera World::getActiveVehicleCamera() +pArea World::getArea(std::string name) { - return vehicles.begin()->second->cameras[activeVehicleCamera->getName()]; + pArea tmp; + for (AreasIt i = areas.begin(); i != areas.end(); i++) + { + if (i->first == ("(Area)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<Area>(i->second)) break; + } + if (tmp == NULL) log->__format(LOG_ERROR, "Tried to access non-existent world object \"%s\" using type \"%s\"", name.c_str(), "Area"); + return tmp; } -void World::processXmlVehicleListNode (XmlTag * tag) +pVehicle World::getVehicle(std::string name) { - if (tag->getName() == "vehicleList") + pVehicle tmp; + for (VehiclesIt i = vehicles.begin(); i != vehicles.end(); i++) { - XmlTag * t = tag->getTag(0); for (int i = 0; i < tag->nTags(); t = tag->getTag(++i)) - { - if (t->getName() == "vehicle") - { - std::string vehicleDirectory = "mosp1"; - std::string vehicleStartPosition = "grid01"; //first 'grid' position - std::string driver = "user"; //still no other option, but in the future: ai, net, user, replay, ghostReplay, none, etc... - vehicleDirectory = t->getAttribute("directory"); - driver = t->getAttribute("driver"); - vehicleStartPosition = t->getAttribute("startPosition"); - - log->loadscreen (LOG_CCREATOR, "Creating a vehicle"); - pVehicle tmpVehicle = Vehicle::create(vehicleDirectory); - if (driver == "user" ) - { - tmpVehicle->setUserDriver(); - } - vehicles[tmpVehicle->getName()] = tmpVehicle; - //FIXME setcontainer?? - - log->__format (LOG_CCREATOR, "Setting vehicle starting relative rotation"); - if (areas.begin()->second->locations.count(vehicleStartPosition) == 0) - { - log->__format(LOG_ERROR, "Vehicle start position \"%s\" hasn't been defined in the area!", vehicleStartPosition.c_str()); - } - tmpVehicle->setPosition (Vector3d(0, 0, 0)); - tmpVehicle->applyRotation ( areas.begin()->second->locations[vehicleStartPosition]->getRotation() ); - - log->__format (LOG_CCREATOR, "Setting vehicle starting position"); - tmpVehicle->setPosition (areas.begin()->second->locations[vehicleStartPosition]->getPosition()); - } - } + if (i->first == ("(Vehicle)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<Vehicle>(i->second)) break; } + if (tmp == NULL) log->__format(LOG_ERROR, "Tried to access non-existent world object \"%s\" using type \"%s\"", name.c_str(), "Vehicle"); + return tmp; } -void World::setContainer() + +void World::stepGraphics() { - //NOTE: world is hardcoded not to have a parent, therefore we don't run this line: - //WorldObject::setContainer(container); + base->stepGraphics(); + // Update Ogre's vehicles positions with Ode's positions. + VehiclesIt j = vehicles.begin(); + for (; j != vehicles.end(); j++) + { + j->second->stepGraphics(); + } AreasIt i = areas.begin(); - for(;i != areas.end(); i++) + for (; i != areas.end(); i++) { - i->second->setContainer(shared_from_this()); + i->second->stepGraphics(); } - VehiclesIt v = vehicles.begin(); - for(;v != vehicles.end(); v++) + if (cameraDirector == true) { - v->second->setContainer(shared_from_this()); + setActiveCamera( getArea("main")->getClosestCamera(getVehicle("main")->getPosition())); } } +void World::stepPhysics() +{ + // Update Ogre's vehicles positions with Ode's positions. + VehiclesIt j = vehicles.begin(); + for (; j != vehicles.end(); j++) + { + j->second->stepPhysics(); + } + AreasIt i = areas.begin(); + for (; i != areas.end(); i++) + { + i->second->stepPhysics(); + } + +} +void World::switchNextAreaCamera() +{ + setActiveCamera (getArea("main")->switchNextCamera()); + cameraDirector = false; +} +void World::switchNextVehicleCamera() +{ + setActiveCamera (getVehicle("main")->switchNextCamera()); + cameraDirector = false; +} +void World::switchCameraDirector() +{ + cameraDirector = !cameraDirector; +} +bool World::isActiveCamera(pCamera camera) +{ + return activeCamera == camera; +} Modified: trunk/src/world/world.hpp =================================================================== --- trunk/src/world/world.hpp 2006-07-19 03:32:57 UTC (rev 441) +++ trunk/src/world/world.hpp 2006-07-19 20:00:20 UTC (rev 442) @@ -17,6 +17,7 @@ SHARED_PTR_MAP(Camera, pCamera, Cameras, CamerasIt, wCamera); SHARED_PTR_MAP(Vehicle, pVehicle, Vehicles, VehiclesIt, wVehicle); SHARED_PTR_MAP(Area, pArea, Areas, AreasIt, wArea); +SHARED_PTR_MAP(Location, pLocation, Locations, LocationsIt, wLocation); SHARED_PTR(World,pWorld, wWorld); class World : public WorldObject @@ -25,10 +26,15 @@ static pWorld world; static std::string newWorld; std::string description; + Areas areas; + Vehicles vehicles; pCamera activeCamera; - void processXmlVehicleListNode (XmlTag * tag); + bool cameraDirector; + void setActiveCamera(pCamera camera); void processXmlRootNode (XmlTag * tag); World (std::string name); + pLocation getLocationObject(std::string fullname); + pVehicle getVehicleObject(std::string fullname); public: static pWorld get(); static void setNewWorld(std::string name); @@ -41,15 +47,15 @@ dSpaceID spaceID; dJointGroupID jointGroupID; - Areas areas; - Vehicles vehicles; + pArea getArea(std::string name); + pVehicle getVehicle(std::string name); + void switchCameraDirector(); + void switchNextAreaCamera(); + void switchNextVehicleCamera(); + bool isActiveCamera(pCamera camera); - void setActiveCamera (pCamera camera); - pCamera getActiveCamera(); - pCamera activeAreaCamera; - pCamera activeVehicleCamera; - pCamera getActiveAreaCamera(); - pCamera getActiveVehicleCamera(); + void stepGraphics(); + void stepPhysics(); }; #endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <st...@us...> - 2006-07-19 03:33:23
|
Revision: 441 Author: stenyak Date: 2006-07-18 20:32:57 -0700 (Tue, 18 Jul 2006) ViewCVS: http://svn.sourceforge.net/motorsport/?rev=441&view=rev Log Message: ----------- Modified a couple log messages. Bufixed vehicle getter methods; they were previously creating null pointers when looking for them. Modified fullname nomenclature. Ex.: - "Test World.Mosp1.Gearbox" becomes "(World)Test/(Vehicle)Mosp1/(Gearbox)main". - "Test World.Mosp1.rr suspension" becomes "(World)Test/(Vehicle)Mosp1/(Suspension)rr". - "Test World.Mosp1.rr wheel" becomes "(World)Test/(Vehicle)Mosp1/(Wheel)rr". Modified default vehicle and world to reflect the nomenclature changes. Bugfixed 3pl mklinks.sh script: now also links to boost libs. Modified Paths: -------------- trunk/3pl/linux/mklinks.sh trunk/cfg/graphicsConfig.xml trunk/data/vehicles/mosp1/vehicle.xml trunk/data/worlds/default.xml trunk/src/common/worldObject.cpp trunk/src/todo trunk/src/tools/xmlTag.cpp trunk/src/vehicle/body.cpp trunk/src/vehicle/vehicle.cpp trunk/src/vehicle/vehicle.hpp Modified: trunk/3pl/linux/mklinks.sh =================================================================== --- trunk/3pl/linux/mklinks.sh 2006-07-18 23:13:58 UTC (rev 440) +++ trunk/3pl/linux/mklinks.sh 2006-07-19 03:32:57 UTC (rev 441) @@ -8,6 +8,7 @@ ln -s $d/OGRE ln -s $d/SDL ln -s $d/xercesc + ln -s $d/boost cd .. cd lib Modified: trunk/cfg/graphicsConfig.xml =================================================================== --- trunk/cfg/graphicsConfig.xml 2006-07-18 23:13:58 UTC (rev 440) +++ trunk/cfg/graphicsConfig.xml 2006-07-19 03:32:57 UTC (rev 441) @@ -10,8 +10,8 @@ areaRenderMode = "solid" > <ogre - _linuxPluginsDir = "../3pl/linux/lib/OGRE" - linuxPluginsDir = "/usr/lib/OGRE" + linuxPluginsDir = "../3pl/linux/lib/OGRE" + _linuxPluginsDir = "/usr/lib/OGRE" windowsPluginsDir = "plugins" sceneManager = "ST_GENERIC" anisotropy = "1" Modified: trunk/data/vehicles/mosp1/vehicle.xml =================================================================== --- trunk/data/vehicles/mosp1/vehicle.xml 2006-07-18 23:13:58 UTC (rev 440) +++ trunk/data/vehicles/mosp1/vehicle.xml 2006-07-19 03:32:57 UTC (rev 441) @@ -24,7 +24,7 @@ wheel-pedal wheel pedal = brakePedal </links> <body - name = "body" + name = "main" length = "4.66" width = "2.08" height = "1.2" @@ -42,23 +42,23 @@ </mesh> </body> <pedal - name = "clutchPedal" + name = "clutch" angleRange = "1.047975" _angleRange = "radians = degrees * 2 * PI / 360" > </pedal> <pedal - name = "gasPedal" + name = "gas" angleRange = "0.6981317" > </pedal> <pedal - name = "brakePedal" + name = "brake" angleRange = "0.6981317" > </pedal> <engine - name = "v8 engine" + name = "main" torqueLinearMultiplier = "246" engineInertia = "0.4" engineFriction = "0.1" @@ -67,7 +67,7 @@ > </engine> <clutch - name = "clutch" + name = "main" coeffStaticFriction = "1" coeffDynamicFriction = "0.8" maxTorqueTransfer = "260" @@ -82,7 +82,7 @@ > </shiftDownPaddle> <gearbox - name = "gearbox" + name = "main" gearboxFriction = "0.01" gearboxInertia = "0.2" > @@ -130,7 +130,7 @@ </gear> </gearbox> <finalDrive - name = "final drive" + name = "main" diffInertia = "0.1" diffFriction = "0.001" finalDriveRatio = "3.6" @@ -143,7 +143,7 @@ </steeringWheel> <!-- <suspension.unidimensional - name = "fr suspension" + name = "fr" springConstant = "80500" dampingConstant = "2000" position = "+1.44 +0.857 -0.45" @@ -152,7 +152,7 @@ > </suspension.unidimensional> <suspension.unidimensional - name = "fl suspension" + name = "fl" springConstant = "80500" dampingConstant = "2000" position = "+1.44 -0.857 -0.45" @@ -162,7 +162,7 @@ </suspension.unidimensional> --> <suspension.doublewishbone - name = "fl suspension" + name = "fl" springStiffness = "80500" springLengthAtEase = "0.5" damperFastBump = "2000" @@ -178,7 +178,7 @@ > </suspension.doublewishbone> <suspension.doublewishbone - name = "fr suspension" + name = "fr" springStiffness = "80500" springLengthAtEase = "0.5" damperFastBump = "2000" @@ -194,7 +194,7 @@ > </suspension.doublewishbone> <suspension.doublewishbone - name = "rl suspension" + name = "rl" springStiffness = "80900" springLengthAtEase = "0.5" damperFastBump = "2000" @@ -210,7 +210,7 @@ > </suspension.doublewishbone> <suspension.doublewishbone - name = "rr suspension" + name = "rr" springStiffness = "80900" springLengthAtEase = "0.5" damperFastBump = "2000" @@ -227,7 +227,7 @@ </suspension.doublewishbone> <!-- <suspension.unidimensional - name = "rr suspension" + name = "rr" springConstant = "80900" dampingConstant = "2000" position = "-1.35 +0.88 -0.45" @@ -236,7 +236,7 @@ > </suspension.unidimensional> <suspension.unidimensional - name = "rl suspension" + name = "rl" springConstant = "80900" dampingConstant = "2000" position = "-1.35 -0.88 -0.45" @@ -245,13 +245,13 @@ > </suspension.unidimensional> <suspension.fixed - name = "rr suspension" + name = "rr" position = "-1.35 +0.88 -0.45" rotation = "-90 0 0" > </suspension.fixed> <suspension.fixed - name = "rl suspension" + name = "rl" position = "-1.35 -0.88 -0.45" rotation = "+90 0 0" steeringAngle = "0" @@ -259,7 +259,7 @@ </suspension.fixed> --> <wheel - name = "fr wheel" + name = "fr" mass = "15.1" radius = "0.34" width = "0.125" @@ -275,7 +275,7 @@ </mesh> </wheel> <wheel - name = "fl wheel" + name = "fl" mass = "15.1" radius = "0.34" width = "0.125" @@ -291,7 +291,7 @@ </mesh> </wheel> <wheel - name = "rr wheel" + name = "rr" mass = "15.0" radius = "0.34" width = "0.125" @@ -307,7 +307,7 @@ </mesh> </wheel> <wheel - name = "rl wheel" + name = "rl" mass = "15.0" radius = "0.34" width = "0.125" Modified: trunk/data/worlds/default.xml =================================================================== --- trunk/data/worlds/default.xml 2006-07-18 23:13:58 UTC (rev 440) +++ trunk/data/worlds/default.xml 2006-07-19 03:32:57 UTC (rev 441) @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="ISO-8859-1"?> <world - name = "Test World" + name = "Test" description = "Drive the Mosp1 car in the testing grounds!" useAreaCamera = "false" gravityX = "0.0" @@ -64,7 +64,7 @@ </vehicleList> <area directory = "mospland" - _directory = "mospland2006.r6" + _directory = "mospland2006.r7" > </area> </world> Modified: trunk/src/common/worldObject.cpp =================================================================== --- trunk/src/common/worldObject.cpp 2006-07-18 23:13:58 UTC (rev 440) +++ trunk/src/common/worldObject.cpp 2006-07-19 03:32:57 UTC (rev 441) @@ -11,6 +11,22 @@ #include "quaternion.hpp" #include "vector3d.hpp" +#include "area.hpp" +#include "part.hpp" +#include "world.hpp" +#include "driveMass.hpp" +#include "body.hpp" +#include "finalDrive.hpp" +#include "gearbox.hpp" +#include "pedal.hpp" +#include "suspension.hpp" +#include "vehicle.hpp" +#include "wheel.hpp" +#include "driveJoint.hpp" +#include "engine.hpp" +#include "camera.hpp" + + unsigned int WorldObject::instancesCount = 0; WorldObjectsC WorldObject::worldObjects; @@ -28,6 +44,7 @@ instancesCount++; //FIXME what to use, id# or name? + //log = LogEngine::create (LOG_DEVELOPER, this->getId()); log = LogEngine::create (LOG_DEVELOPER, this->getFullName()); log->__format(LOG_CCREATOR, "New world object! Id #%s.", id.c_str()); worldObjects[this->id] = this; @@ -44,7 +61,7 @@ dBodySetData (j->second->getBodyID(), (void*) container.get()); } log->setName(this->getFullName()); - log->__format(LOG_CCREATOR, "New container! Old full name: %s. New full name: %s", id.c_str(), oldName.c_str(), getFullName().c_str()); + log->__format(LOG_CCREATOR, "New container! Old full name: %s. New full name: %s", oldName.c_str(), getFullName().c_str()); } @@ -69,9 +86,35 @@ { return id; } + std::string WorldObject::getName() { - return name; + std::string type; + if (0) type.clear(); + else if (dynamic_cast<DoubleWishbone *>(this)) type = "DoubleWishbone"; + else if (dynamic_cast<Fixed *>(this)) type = "Fixed"; + else if (dynamic_cast<Unidimensional *>(this)) type = "Unidimensional"; + else if (dynamic_cast<Suspension *>(this)) type = "Suspension"; + else if (dynamic_cast<Engine *>(this)) type = "Engine"; + else if (dynamic_cast<Gearbox *>(this)) type = "Gearbox"; + else if (dynamic_cast<Wheel *>(this)) type = "Wheel"; + else if (dynamic_cast<FinalDrive *>(this)) type = "FinalDrive"; + else if (dynamic_cast<DriveMass *>(this)) type = "DriveMass"; + else if (dynamic_cast<Gear *>(this)) type = "Gear"; + else if (dynamic_cast<LSD *>(this)) type = "LSD"; + else if (dynamic_cast<Clutch *>(this)) type = "Clutch"; + else if (dynamic_cast<DriveJoint *>(this)) type = "DriveJoint"; + else if (dynamic_cast<GearboxGear *>(this)) type = "GearboxGear"; + else if (dynamic_cast<Body *>(this)) type = "Body"; + else if (dynamic_cast<Pedal *>(this)) type = "Pedal"; + else if (dynamic_cast<Part *>(this)) type = "Part"; + else if (dynamic_cast<Vehicle *>(this)) type = "Vehicle"; + else if (dynamic_cast<Area *>(this)) type = "Area"; + else if (dynamic_cast<World *>(this)) type = "World"; + else if (dynamic_cast<Camera *>(this)) type = "Camera"; + else if (dynamic_cast<WorldObject *>(this)) type = "WorldObject"; + else log->__format(LOG_ERROR, "Couldn't find out object #%s type. This should *NOT* have happened.", getId().c_str()); + return "(" + type + ")" + name; } void WorldObject::setName(std::string name) { @@ -81,8 +124,8 @@ std::string WorldObject::getFullName() { pWorldObject pcontainer = container.lock(); - if (pcontainer == NULL) return name; - return pcontainer->getFullName() + "." + name; + if (pcontainer == NULL) return getName(); + return pcontainer->getFullName() + "." + getName(); } std::string WorldObject::getPath() { Modified: trunk/src/todo =================================================================== --- trunk/src/todo 2006-07-18 23:13:58 UTC (rev 440) +++ trunk/src/todo 2006-07-19 03:32:57 UTC (rev 441) @@ -4,7 +4,6 @@ finish suspension rotations thing rename mosp window check what happens when getName() of root nodes... doesn't exist.. you know waht i mean, the xmlTag-using code.. -check if vehicle map thingies are right, o replaced while constructed, or whatever. name clashing, double destruction, etc... refactorize the world and area (ground, sky, ...) redefine vehicle.xml format, so that it allows links between objects. allow objects to be created from an xml file, not just xml tag Modified: trunk/src/tools/xmlTag.cpp =================================================================== --- trunk/src/tools/xmlTag.cpp 2006-07-18 23:13:58 UTC (rev 440) +++ trunk/src/tools/xmlTag.cpp 2006-07-19 03:32:57 UTC (rev 441) @@ -109,7 +109,7 @@ { if (!(i->second)) { - if (i->first != "xmlns" && i->first != "xmlns:xsi" && i->first != "xsi:schemaLocation") + if (i->first != "xmlns" && i->first != "xmlns:xsi" && i->first != "xsi:schemaLocation" && i->first[0] != '_') { if (log) log->__format(LOG_WARNING, "Attribute \"%s\" in \"%s\" has not been used!", i->first.c_str(), getFullName().c_str()); else std::cout << "Warning! Attribute \"" << i->first << "\" in \"" << getFullName() << "\" has not been used!" << std::endl; Modified: trunk/src/vehicle/body.cpp =================================================================== --- trunk/src/vehicle/body.cpp 2006-07-18 23:13:58 UTC (rev 440) +++ trunk/src/vehicle/body.cpp 2006-07-19 03:32:57 UTC (rev 441) @@ -79,7 +79,7 @@ void Body::stepPhysics () { dBodyID bodyID = getMainOdeObject()->getBodyID(); - if (this == World::get()->vehicles.begin()->second->getObject("body").get()) + if (this == World::get()->vehicles.begin()->second->getObject("(Body)main").get()) { double moveZ = System::get()->axisMap[getIDKeyboardKey(SDLK_BACKSPACE)]->getValue() * 50000; moveZ += System::get()->axisMap[getIDKeyboardKey(SDLK_RETURN)]->getValue() * 12200; Modified: trunk/src/vehicle/vehicle.cpp =================================================================== --- trunk/src/vehicle/vehicle.cpp 2006-07-18 23:13:58 UTC (rev 440) +++ trunk/src/vehicle/vehicle.cpp 2006-07-19 03:32:57 UTC (rev 441) @@ -63,7 +63,7 @@ log->log (LOG_ENDUSER, LOG_TELEMETRY, "VehSpeed EngineSpeed DiffAngularVel RRWhAngulVel RLWhAngulVel Gear Distance"); // engage neutral gear - getGearbox("gearbox")->setGear(2); + getGearbox("main")->setGear(2); // spread the news to the necessary (input-able) vehicle parts for (WorldObjectsIt i = components.begin(); i != components.end(); i++) @@ -87,60 +87,44 @@ contact = tag->getAttribute("contact"); license = tag->getAttribute("license"); - components["rearDiff"] = LSD::create(); - components["transfer"] = Gear::create(); + pLSD lsd = LSD::create(); lsd->setName("rear diff"); components[lsd->getName()] = lsd; + pGear gear = Gear::create(); gear->setName("transfer"); components[gear->getName()] = gear; XmlTag * t = tag->getTag(0); for (int i = 0; i < tag->nTags(); t = tag->getTag(++i)) { - if (t->getName() == "body") components["body"] = Body::create (t); - if (t->getName() == "engine") components["engine"] = Engine::create (t); - if (t->getName() == "clutch") components["clutch"] = Clutch::create (t); - if (t->getName() == "gearbox") components["gearbox"] = Gearbox::create (t); - if (t->getName() == "finalDrive") components["finalDrive"] = FinalDrive::create (t); + bool u=false; //update graphics display; render one frame + if (t->getName() == "body") + { pBody tmp = Body::create(t); components[tmp->getName()]=tmp; } + if (t->getName() == "engine") + { pEngine tmp = Engine::create(t); components[tmp->getName()]=tmp; } + if (t->getName() == "clutch") + { pClutch tmp = Clutch::create(t); components[tmp->getName()]=tmp; } + if (t->getName() == "gearbox") + { pGearbox tmp = Gearbox::create(t); components[tmp->getName()]=tmp; } + if (t->getName() == "finalDrive") + { pFinalDrive tmp = FinalDrive::create(t); components[tmp->getName()]=tmp; } if (t->getName() == "pedal") - { - pPedal tmp = Pedal::create (t); - components[tmp->getName()] = tmp; - } + { pPedal tmp = Pedal::create(t); components[tmp->getName()]=tmp; } if (t->getName() == "wheel") - { - pWheel tmp = Wheel::create (t); - components[tmp->getName()] = tmp; - System::get()->ogreWindow->update (); - } + { pWheel tmp = Wheel::create(t); components[tmp->getName()]=tmp; u=true;} if (t->getName() == "suspension.unidimensional") - { - pUnidimensional tmp = Unidimensional::create (t); - components[tmp->getName()] = tmp; - System::get()->ogreWindow->update (); - } + { pUnidimensional tmp = Unidimensional::create(t); components[tmp->getName()]=tmp; u=true;} if (t->getName() == "suspension.fixed") - { - pFixed tmp = Fixed::create (t); - components[tmp->getName()] = tmp; - System::get()->ogreWindow->update (); - } + { pFixed tmp = Fixed::create(t); components[tmp->getName()]=tmp; u=true;} if (t->getName() == "suspension.doublewishbone") - { - pDoubleWishbone tmp = DoubleWishbone::create (t); - components[tmp->getName()] = tmp; - System::get()->ogreWindow->update (); - } + { pDoubleWishbone tmp = DoubleWishbone::create(t); components[tmp->getName()]=tmp; u=true;} if (t->getName() == "camera") - { - pCamera tmp = Camera::create (t); - cameras[tmp->getName()] = tmp; - } + { pCamera tmp = Camera::create(t); cameras[tmp->getName()]=tmp; u=true;} + if (u) System::get()->ogreWindow->update (); } } - // spread the news to the necessary (input-able) vehicle parts log->__format(LOG_DEVELOPER, "Setting some drive joint pointers..."); - getDriveJoint("clutch")->setOutputPointer(getDriveMass("gearbox")); - getDriveJoint("transfer")->setOutputPointer(getDriveMass("finalDrive")); + getClutch("main")->setOutputPointer(getGearbox("main")); + getDriveJoint("transfer")->setOutputPointer(getFinalDrive("main")); - getDriveJoint("clutch")->setInputPointer(getDriveMass("engine")); - getDriveJoint("transfer")->setInputPointer(getDriveMass("gearbox")); - getDriveJoint("rearDiff")->setInputPointer(getDriveMass("finalDrive")); + getClutch("main")->setInputPointer(getEngine("main")); + getDriveJoint("transfer")->setInputPointer(getGearbox("main")); + getDriveJoint("rear diff")->setInputPointer(getFinalDrive("main")); log->__format(LOG_DEVELOPER, "Placing wheels on suspensions..."); placeWheelsOnSuspensions(); @@ -148,27 +132,27 @@ boltWheelsToSuspensions(); log->__format(LOG_DEVELOPER, "Setting some more drive joint pointers..."); - getDriveJoint("rearDiff")->setOutputPointer(getDriveMass("rr wheel")); - getLSD("rearDiff")->setOutputPointer2(getDriveMass("rl wheel")); + getDriveJoint("rear diff")->setOutputPointer(getWheel("rr")); + getLSD("rear diff")->setOutputPointer2(getWheel("rl")); - getEngine("engine")->setGasPedal(getPedal("gasPedal")); - getClutch("clutch")->setClutchPedal(getPedal("clutchPedal")); + getEngine("main")->setGasPedal(getPedal("gas")); + getClutch("main")->setClutchPedal(getPedal("clutch")); for (WorldObjectsIt i = components.begin(); i != components.end(); i++) { Wheel * tmpWheel; if ( (tmpWheel = dynamic_cast<Wheel*>(i->second.get())) != 0) { - tmpWheel->setBrakePedal(getPedal("brakePedal")); + tmpWheel->setBrakePedal(getPedal("brake")); } } - getDriveJoint("clutch")->enable(); + getClutch("main")->enable(); getDriveJoint("transfer")->enable(); - getDriveJoint("rearDiff")->enable(); + getDriveJoint("rear diff")->enable(); //start in 1st gear (hardcoded to 2) // this helps brake the vehicle (since it's not user-controlled by default and would roll around freely otherwise) - getGearbox("gearbox")->setGear(2); + getGearbox("main")->setGear(2); stepGraphics(); } @@ -177,11 +161,12 @@ { WorldObject::setContainer(container); // tell all the objects who's the boss. + pWorldObject t = shared_from_this(); for (WorldObjectsIt i = components.begin(); i != components.end(); i++) { - i->second->setContainer(shared_from_this()); + if (i->second) i->second->setContainer(t); } - getGearbox("gearbox")->setContainer(shared_from_this()); + getGearbox("main")->setContainer(shared_from_this()); for (CamerasIt i = cameras.begin(); i != cameras.end(); i++) { i->second->setContainer(shared_from_this()); @@ -206,14 +191,14 @@ pOdeObject Vehicle::getMainOdeObject() { - return getObject("body")->getMainOdeObject(); + return getObject("(Body)main")->getMainOdeObject(); } void Vehicle::setPosition (Vector3d position) { Vector3d posDiff = position - getPosition(); log->__format (LOG_DEVELOPER,"Difference in vehicle position: (%f, %f, %f).", posDiff.x, posDiff.y, posDiff.z); - getObject("body")->setPosition ( getObject("body")->getPosition() + posDiff ); + getObject("(Body)main")->setPosition ( getObject("(Body)main")->getPosition() + posDiff ); for (WorldObjectsIt i = components.begin(); i != components.end(); i++) { Wheel * tmpWheel; @@ -227,7 +212,7 @@ Vector3d Vehicle::getPosition () { - return getObject("body")->getPosition(); + return getObject("(Body)main")->getPosition(); } void Vehicle::applyRotation (Quaternion rotation) @@ -243,32 +228,32 @@ tmpSusp->applyRotation (rotation); } // apply rotation to body - getObject("body")->applyRotation (rotation); + getObject("(Body)main")->applyRotation (rotation); } Quaternion Vehicle::getRotation () { - return getObject("body")->getRotation(); + return getObject("(Body)main")->getRotation(); } void Vehicle::placeWheelsOnSuspensions() { - getWheel("fr wheel")->applyRotation(getSuspension("fr suspension")->getSecondLinkRotation()); - getWheel("fr wheel")->setPosition(getSuspension("fr suspension")->getSecondLinkPosition()); - getWheel("fl wheel")->applyRotation(getSuspension("fl suspension")->getSecondLinkRotation()); - getWheel("fl wheel")->setPosition(getSuspension("fl suspension")->getSecondLinkPosition()); - getWheel("rr wheel")->applyRotation(getSuspension("rr suspension")->getSecondLinkRotation()); - getWheel("rr wheel")->setPosition(getSuspension("rr suspension")->getSecondLinkPosition()); - getWheel("rl wheel")->applyRotation(getSuspension("rl suspension")->getSecondLinkRotation()); - getWheel("rl wheel")->setPosition(getSuspension("rl suspension")->getSecondLinkPosition()); + getWheel("fr")->applyRotation(getSuspension("fr")->getSecondLinkRotation()); + getWheel("fr")->setPosition(getSuspension("fr")->getSecondLinkPosition()); + getWheel("fl")->applyRotation(getSuspension("fl")->getSecondLinkRotation()); + getWheel("fl")->setPosition(getSuspension("fl")->getSecondLinkPosition()); + getWheel("rr")->applyRotation(getSuspension("rr")->getSecondLinkRotation()); + getWheel("rr")->setPosition(getSuspension("rr")->getSecondLinkPosition()); + getWheel("rl")->applyRotation(getSuspension("rl")->getSecondLinkRotation()); + getWheel("rl")->setPosition(getSuspension("rl")->getSecondLinkPosition()); } void Vehicle::boltWheelsToSuspensions() { - getSuspension("fr suspension")->attach(getObject("body"), getObject("fr wheel")); - getSuspension("fl suspension")->attach(getObject("body"), getObject("fl wheel")); - getSuspension("rr suspension")->attach(getObject("body"), getObject("rr wheel")); - getSuspension("rl suspension")->attach(getObject("body"), getObject("rl wheel")); + getSuspension("fr")->attach(getObject("(Body)main"), getObject("(Wheel)fr")); + getSuspension("fl")->attach(getObject("(Body)main"), getObject("(Wheel)fl")); + getSuspension("rr")->attach(getObject("(Body)main"), getObject("(Wheel)rr")); + getSuspension("rl")->attach(getObject("(Body)main"), getObject("(Wheel)rl")); } void Vehicle::stepPhysics () @@ -286,24 +271,24 @@ // check the gearshift levers if(System::get()->axisMap[getIDKeyboardKey(SDLK_a)]->getValue() == 1) { - getGearbox("gearbox")->gearUp(); + getGearbox("main")->gearUp(); } if(System::get()->axisMap[getIDKeyboardKey(SDLK_z)]->getValue() == 1) { - getGearbox("gearbox")->gearDown(); + getGearbox("main")->gearDown(); } } // step torque transfer components first - getClutch("clutch")->stepPhysics(); + getClutch("main")->stepPhysics(); getGear("transfer")->stepPhysics(); - getLSD("rearDiff")->stepPhysics(); + getLSD("rear diff")->stepPhysics(); // step rigid bodies - getEngine("engine")->stepPhysics(); - getGearbox("gearbox")->stepPhysics(); - getFinalDrive("finalDrive")->stepPhysics(); - getBody("body")->stepPhysics(); + getEngine("main")->stepPhysics(); + getGearbox("main")->stepPhysics(); + getFinalDrive("main")->stepPhysics(); + getBody("main")->stepPhysics(); std::map < std::string, Suspension * >::const_iterator suspIter; for (WorldObjectsIt i = components.begin(); i != components.end(); i++) { @@ -316,96 +301,167 @@ // print telemetry data if ( userDriver ) { - const dReal * tmp = dBodyGetLinearVel(getObject("body")->getMainOdeObject()->getBodyID()); + const dReal * tmp = dBodyGetLinearVel(getObject("(Body)main")->getMainOdeObject()->getBodyID()); double velocity = sqrt(tmp[0]*tmp[0]+tmp[1]*tmp[1]+tmp[2]*tmp[2]); - tmp = dBodyGetPosition(getObject("body")->getMainOdeObject()->getBodyID()); + tmp = dBodyGetPosition(getObject("(Body)main")->getMainOdeObject()->getBodyID()); double distance = sqrt(tmp[0]*tmp[0]+tmp[1]*tmp[1]+tmp[2]*tmp[2]); - log->log (LOG_ENDUSER, LOG_TELEMETRY | LOG_FILE, "%9.5f %12.8f %12.8f %12.8f %12.8f %s %12.8f", velocity, getDriveMass("engine")->getOutputAngularVel(), getDriveMass("finalDrive")->getInputAngularVel(), getWheel("rr wheel")->getInputAngularVel(), getWheel("rl wheel")->getInputAngularVel(), getGearbox("gearbox")->getCurrentGearName().c_str(), distance); + log->log (LOG_ENDUSER, LOG_TELEMETRY | LOG_FILE, "%9.5f %12.8f %12.8f %12.8f %12.8f %s %12.8f", velocity, getEngine("main")->getOutputAngularVel(), getFinalDrive("main")->getInputAngularVel(), getWheel("rr")->getInputAngularVel(), getWheel("rl")->getInputAngularVel(), getGearbox("main")->getCurrentGearName().c_str(), distance); } } pBody Vehicle::getBody (std::string name) { - pBody tmp = boost::dynamic_pointer_cast<Body>(components[name]); + pBody tmp; + for (WorldObjectsIt i = components.begin(); i != components.end(); i++) + { + if (i->first == ("(Body)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<Body>(i->second)) break; + } if (tmp == NULL) log->__format(LOG_ERROR, "Tried to access non-existent world object \"%s\" using type \"%s\"", name.c_str(), "Body"); - return (tmp); - //return (components[name]); + return tmp; } pDriveMass Vehicle::getDriveMass (std::string name) { - pDriveMass tmp = boost::dynamic_pointer_cast<DriveMass>(components[name]); + pDriveMass tmp; + for (WorldObjectsIt i = components.begin(); i != components.end(); i++) + { + if (i->first == ("(DriveMass)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<DriveMass>(i->second)) break; + if (i->first == ("(Engine)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<DriveMass>(i->second)) break; + if (i->first == ("(FinalDrive)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<DriveMass>(i->second)) break; + if (i->first == ("(Gearbox)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<DriveMass>(i->second)) break; + if (i->first == ("(Wheel)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<DriveMass>(i->second)) break; + } if (tmp == NULL) log->__format(LOG_ERROR, "Tried to access non-existent world object \"%s\" using type \"%s\"", name.c_str(), "DriveMass"); - return (tmp); + return tmp; } pDriveJoint Vehicle::getDriveJoint (std::string name) { - pDriveJoint tmp = boost::dynamic_pointer_cast<DriveJoint>(components[name]); + pDriveJoint tmp; + for (WorldObjectsIt i = components.begin(); i != components.end(); i++) + { + if (i->first == ("(DriveJoint)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<DriveJoint>(i->second)) break; + if (i->first == ("(Clutch)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<Clutch>(i->second)) break; + if (i->first == ("(Gear)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<Gear>(i->second)) break; + if (i->first == ("(LSD)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<LSD>(i->second)) break; + } if (tmp == NULL) log->__format(LOG_ERROR, "Tried to access non-existent world object \"%s\" using type \"%s\"", name.c_str(), "DriveJoint"); - return (tmp); + return tmp; } pClutch Vehicle::getClutch (std::string name) { - pClutch tmp = boost::dynamic_pointer_cast<Clutch>(components[name]); + pClutch tmp; + for (WorldObjectsIt i = components.begin(); i != components.end(); i++) + { + if (i->first == ("(Clutch)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<Clutch>(i->second)) break; + } if (tmp == NULL) log->__format(LOG_ERROR, "Tried to access non-existent world object \"%s\" using type \"%s\"", name.c_str(), "Clutch"); - return (tmp); + return tmp; } pGear Vehicle::getGear (std::string name) { - pGear tmp = boost::dynamic_pointer_cast<Gear>(components[name]); + pGear tmp; + for (WorldObjectsIt i = components.begin(); i != components.end(); i++) + { + if (i->first == ("(Gear)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<Gear>(i->second)) break; + } if (tmp == NULL) log->__format(LOG_ERROR, "Tried to access non-existent world object \"%s\" using type \"%s\"", name.c_str(), "Gear"); - return (tmp); + return tmp; } pLSD Vehicle::getLSD (std::string name) { - pLSD tmp = boost::dynamic_pointer_cast<LSD>(components[name]); + pLSD tmp; + for (WorldObjectsIt i = components.begin(); i != components.end(); i++) + { + if (i->first == ("(LSD)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<LSD>(i->second)) break; + } if (tmp == NULL) log->__format(LOG_ERROR, "Tried to access non-existent world object \"%s\" using type \"%s\"", name.c_str(), "LSD"); - return (tmp); + return tmp; } pEngine Vehicle::getEngine (std::string name) { - pEngine tmp = boost::dynamic_pointer_cast<Engine>(components[name]); + pEngine tmp; + for (WorldObjectsIt i = components.begin(); i != components.end(); i++) + { + if (i->first == ("(Engine)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<Engine>(i->second)) break; + } if (tmp == NULL) log->__format(LOG_ERROR, "Tried to access non-existent world object \"%s\" using type \"%s\"", name.c_str(), "Engine"); - return (tmp); + return tmp; } pFinalDrive Vehicle::getFinalDrive (std::string name) { - pFinalDrive tmp = boost::dynamic_pointer_cast<FinalDrive>(components[name]); + pFinalDrive tmp; + for (WorldObjectsIt i = components.begin(); i != components.end(); i++) + { + if (i->first == ("(FinalDrive)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<FinalDrive>(i->second)) break; + } if (tmp == NULL) log->__format(LOG_ERROR, "Tried to access non-existent world object \"%s\" using type \"%s\"", name.c_str(), "FinalDrive"); - return (tmp); + return tmp; } pGearbox Vehicle::getGearbox (std::string name) { - pGearbox tmp = boost::dynamic_pointer_cast<Gearbox>(components[name]); + pGearbox tmp; + for (WorldObjectsIt i = components.begin(); i != components.end(); i++) + { + if (i->first == ("(Gearbox)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<Gearbox>(i->second)) break; + } if (tmp == NULL) log->__format(LOG_ERROR, "Tried to access non-existent world object \"%s\" using type \"%s\"", name.c_str(), "Gearbox"); - return (tmp); + return tmp; } pGearboxGear Vehicle::getGearboxGear (std::string name) { - pGearboxGear tmp = boost::dynamic_pointer_cast<GearboxGear>(components[name]); + pGearboxGear tmp; + for (WorldObjectsIt i = components.begin(); i != components.end(); i++) + { + if (i->first == ("(GearboxGear)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<GearboxGear>(i->second)) break; + } if (tmp == NULL) log->__format(LOG_ERROR, "Tried to access non-existent world object \"%s\" using type \"%s\"", name.c_str(), "GearboxGear"); - return (tmp); + return tmp; } pPedal Vehicle::getPedal (std::string name) { - pPedal tmp = boost::dynamic_pointer_cast<Pedal>(components[name]); + pPedal tmp; + for (WorldObjectsIt i = components.begin(); i != components.end(); i++) + { + if (i->first == ("(Pedal)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<Pedal>(i->second)) break; + } if (tmp == NULL) log->__format(LOG_ERROR, "Tried to access non-existent world object \"%s\" using type \"%s\"", name.c_str(), "Pedal"); - return (tmp); + return tmp; } pSuspension Vehicle::getSuspension (std::string name) { - pSuspension tmp = boost::dynamic_pointer_cast<Suspension>(components[name]); + pSuspension tmp; + for (WorldObjectsIt i = components.begin(); i != components.end(); i++) + { + if (i->first == ("(Suspension)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<Suspension>(i->second)) break; + if (i->first == ("(DoubleWishbone)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<DoubleWishbone>(i->second)) break; + if (i->first == ("(Fixed)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<Fixed>(i->second)) break; + if (i->first == ("(Unidimensional)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<Unidimensional>(i->second)) break; + } if (tmp == NULL) log->__format(LOG_ERROR, "Tried to access non-existent world object \"%s\" using type \"%s\"", name.c_str(), "Suspension"); - return (tmp); + return tmp; } pWheel Vehicle::getWheel (std::string name) { - pWheel tmp = boost::dynamic_pointer_cast<Wheel>(components[name]); + pWheel tmp; + for (WorldObjectsIt i = components.begin(); i != components.end(); i++) + { + if (i->first == ("(Wheel)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<Wheel>(i->second)) break; + } if (tmp == NULL) log->__format(LOG_ERROR, "Tried to access non-existent world object \"%s\" using type \"%s\"", name.c_str(), "Wheel"); - return (tmp); + return tmp; } pWorldObject Vehicle::getObject (std::string name) { if (components.find(name) == components.end()) - log->__format(LOG_ERROR, "Tried to access non-existent world object \"%s\" using type \"%s\"", name.c_str(), "WorldObject"); + log->__format(LOG_ERROR, "Tried to access non-existent world object \"%s\" from generic type \"%s\"", name.c_str(), "WorldObject"); return components[name]; } +pWorldObject Vehicle::getWorldObject (std::string name) +{ + pWorldObject tmp; + for (WorldObjectsIt i = components.begin(); i != components.end(); i++) + { + if (i->first == ("(WorldObject)" + name) && i->second) if (tmp = boost::dynamic_pointer_cast<WorldObject>(i->second)) break; + } + if (tmp == NULL) log->__format(LOG_ERROR, "Tried to access non-existent world object \"%s\" using type \"%s\"", name.c_str(), "WorldObject"); + return tmp; +} Modified: trunk/src/vehicle/vehicle.hpp =================================================================== --- trunk/src/vehicle/vehicle.hpp 2006-07-18 23:13:58 UTC (rev 440) +++ trunk/src/vehicle/vehicle.hpp 2006-07-19 03:32:57 UTC (rev 441) @@ -69,6 +69,7 @@ pSuspension getSuspension (std::string name); pWheel getWheel (std::string name); pWorldObject getObject (std::string name); + pWorldObject getWorldObject (std::string name); void setUserDriver (); void stepPhysics (); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <st...@us...> - 2006-07-18 23:15:02
|
Revision: 440 Author: stenyak Date: 2006-07-18 16:13:58 -0700 (Tue, 18 Jul 2006) ViewCVS: http://svn.sourceforge.net/motorsport/?rev=440&view=rev Log Message: ----------- Finished converting all world objects to shared pointers. Weak pointers used when keeping track of parents. Modified Paths: -------------- trunk/src/common/camera.cpp trunk/src/common/camera.hpp trunk/src/common/location.hpp trunk/src/common/odeObject.cpp trunk/src/common/odeObject.hpp trunk/src/common/ogreObject.hpp trunk/src/common/shared.hpp trunk/src/common/worldObject.cpp trunk/src/common/worldObject.hpp trunk/src/graphics.hpp trunk/src/gui.hpp trunk/src/input.hpp trunk/src/log/logEngine.cpp trunk/src/log/logEngine.hpp trunk/src/main.hpp trunk/src/physics.hpp trunk/src/system.cpp trunk/src/system.hpp trunk/src/vehicle/body.cpp trunk/src/vehicle/body.hpp trunk/src/vehicle/driveJoint.cpp trunk/src/vehicle/driveJoint.hpp trunk/src/vehicle/driveMass.cpp trunk/src/vehicle/driveMass.hpp trunk/src/vehicle/engine.cpp trunk/src/vehicle/engine.hpp trunk/src/vehicle/finalDrive.cpp trunk/src/vehicle/finalDrive.hpp trunk/src/vehicle/gearbox.cpp trunk/src/vehicle/gearbox.hpp trunk/src/vehicle/pedal.cpp trunk/src/vehicle/pedal.hpp trunk/src/vehicle/suspension.cpp trunk/src/vehicle/suspension.hpp trunk/src/vehicle/vehicle.cpp trunk/src/vehicle/vehicle.hpp trunk/src/vehicle/wheel.cpp trunk/src/vehicle/wheel.hpp trunk/src/world/area.cpp trunk/src/world/area.hpp trunk/src/world/part.cpp trunk/src/world/part.hpp trunk/src/world/world.cpp trunk/src/world/world.hpp Modified: trunk/src/common/camera.cpp =================================================================== --- trunk/src/common/camera.cpp 2006-07-18 17:57:15 UTC (rev 439) +++ trunk/src/common/camera.cpp 2006-07-18 23:13:58 UTC (rev 440) @@ -21,14 +21,14 @@ #include "area.hpp" #include "vector3d.hpp" -pCamera Camera::create(WorldObject * container, XmlTag * tag) +pCamera Camera::create(XmlTag * tag) { - pCamera p (new Camera(container, tag)); + pCamera p (new Camera(tag)); return p; } -Camera::Camera (WorldObject * container, XmlTag * tag) - :WorldObject(container, "camera") +Camera::Camera (XmlTag * tag) + :WorldObject("camera") { ogreCamera = System::get()->ogreSceneManager->createCamera (getId()); ogreCamera->setFixedYawAxis (true, Ogre::Vector3 (0, 0, 1)); Modified: trunk/src/common/camera.hpp =================================================================== --- trunk/src/common/camera.hpp 2006-07-18 17:57:15 UTC (rev 439) +++ trunk/src/common/camera.hpp 2006-07-18 23:13:58 UTC (rev 440) @@ -19,7 +19,7 @@ class Vector3d; -SHARED_PTR_MAP(Camera, pCamera, Cameras, CamerasIt); +SHARED_PTR_MAP(Camera, pCamera, Cameras, CamerasIt, wCamera); class Camera : public WorldObject { @@ -30,9 +30,9 @@ dBodyID targetID; Vector3d * targetOffset; void stopPhysics(); - Camera (WorldObject * container, XmlTag * tag); + Camera (XmlTag * tag); public: - static pCamera create(WorldObject * container, XmlTag * tag); + static pCamera create(XmlTag * tag); ~Camera (); void updateOgreRotation (); Vector3d updateOgrePosition (); Modified: trunk/src/common/location.hpp =================================================================== --- trunk/src/common/location.hpp 2006-07-18 17:57:15 UTC (rev 439) +++ trunk/src/common/location.hpp 2006-07-18 23:13:58 UTC (rev 440) @@ -15,7 +15,7 @@ #include "xmlTag.hpp" #include <common/shared.hpp> -SHARED_PTR_MAP(Location, pLocation, Locations, LocationsIt); +SHARED_PTR_MAP(Location, pLocation, Locations, LocationsIt, wLocation); class Location { Modified: trunk/src/common/odeObject.cpp =================================================================== --- trunk/src/common/odeObject.cpp 2006-07-18 17:57:15 UTC (rev 439) +++ trunk/src/common/odeObject.cpp 2006-07-18 23:13:58 UTC (rev 440) @@ -39,7 +39,7 @@ dBodySetAutoDisableSteps (bodyID, 1); //*/ - dBodySetData (bodyID, static_cast<void*>(worldObject->getContainer())); + dBodySetData (bodyID, static_cast<void*>(worldObject->getContainer().get())); dMass dmass; if (data->shape == "box") { @@ -67,7 +67,7 @@ bodyID = NULL; // create dBody bodyID = dBodyCreate (World::get()->worldID); - dBodySetData (bodyID, static_cast<void*>(worldObject->getContainer())); + dBodySetData (bodyID, static_cast<void*>(worldObject->getContainer().get())); // create transform spaces (in order to be able to 'offset' the collision geoms geomIDs["GeomSpace(A)"] = dCreateGeomTransform (World::get()->spaceID); @@ -114,7 +114,7 @@ this->name = name; bodyID = NULL; bodyID = dBodyCreate (World::get()->worldID); - dBodySetData (bodyID, static_cast<void*>(worldObject->getContainer())); + dBodySetData (bodyID, static_cast<void*>(worldObject->getContainer().get())); dMass dmass; dMassSetParameters (&dmass, data->mass, 0., 0., 0., @@ -134,7 +134,7 @@ bodyID = NULL; bodyID = dBodyCreate (World::get()->worldID); - dBodySetData (bodyID, static_cast<void*>(worldObject->getContainer())); + dBodySetData (bodyID, static_cast<void*>(worldObject->getContainer().get())); dMass dmass; if (data->useMass) { Modified: trunk/src/common/odeObject.hpp =================================================================== --- trunk/src/common/odeObject.hpp 2006-07-18 17:57:15 UTC (rev 439) +++ trunk/src/common/odeObject.hpp 2006-07-18 23:13:58 UTC (rev 440) @@ -18,11 +18,11 @@ class Quaternion; class WorldObject; -SHARED_PTR_MAP(OdeObject, pOdeObject, OdeObjects, OdeObjectsIt); -SHARED_PTR(PartOdeData, pPartOdeData); -SHARED_PTR(BodyOdeData, pBodyOdeData); -SHARED_PTR(WheelOdeData, pWheelOdeData); -SHARED_PTR(BoneOdeData, pBoneOdeData); +SHARED_PTR_MAP(OdeObject, pOdeObject, OdeObjects, OdeObjectsIt, wOdeObject); +SHARED_PTR(PartOdeData, pPartOdeData, wPartOdeData); +SHARED_PTR(BodyOdeData, pBodyOdeData, wBodyOdeData); +SHARED_PTR(WheelOdeData, pWheelOdeData, wWheelOdeData); +SHARED_PTR(BoneOdeData, pBoneOdeData, wBoneOdeData); SHARED_MAP(dGeomID, GeomIDs, GeomIDsIt); Modified: trunk/src/common/ogreObject.hpp =================================================================== --- trunk/src/common/ogreObject.hpp 2006-07-18 17:57:15 UTC (rev 439) +++ trunk/src/common/ogreObject.hpp 2006-07-18 23:13:58 UTC (rev 440) @@ -21,9 +21,9 @@ class Quaternion; class Vector3d; -SHARED_PTR_MAP(OdeObject, pOdeObject, OdeObjects, OdeObjectsIt); -SHARED_PTR_MAP(OgreObject, pOgreObject, OgreObjects, OgreObjectsIt); -SHARED_PTR(OgreObjectData, pOgreObjectData); +SHARED_PTR_MAP(OdeObject, pOdeObject, OdeObjects, OdeObjectsIt, wOdeObject); +SHARED_PTR_MAP(OgreObject, pOgreObject, OgreObjects, OgreObjectsIt, wOgreObject); +SHARED_PTR(OgreObjectData, pOgreObjectData, wOgreObjectData); class OgreObject { Modified: trunk/src/common/shared.hpp =================================================================== --- trunk/src/common/shared.hpp 2006-07-18 17:57:15 UTC (rev 439) +++ trunk/src/common/shared.hpp 2006-07-18 23:13:58 UTC (rev 440) @@ -15,13 +15,15 @@ #include <string> // Shared pointer -#define SHARED_PTR(X,Y) class X; typedef boost::shared_ptr<X> Y +#define SHARED_PTR(X,Y,W) class X; typedef boost::shared_ptr<X> Y; typedef boost::weak_ptr<X> W // String-indexed map and iterator #define SHARED_MAP(X,Y,Z) typedef std::map <std::string, X> Y; typedef std::map <std::string, X>::iterator Z // Shared pointer, string-indexed map and iterator -#define SHARED_PTR_MAP(X,Y,Z,T) class X; typedef boost::shared_ptr<X> Y; typedef std::map <std::string, Y> Z; typedef std::map <std::string, Y>::iterator T -#define SHARED_MAP_PTR(X,Y,Z,T) class X; typedef boost::shared_ptr<X> Y; typedef std::map <std::string, Y> Z; typedef std::map <std::string, Y>::iterator T +#define SHARED_PTR_MAP(X,Y,Z,T,W) SHARED_PTR(X,Y,W); SHARED_MAP(Y,Z,T) +#define SHARED_MAP_PTR(X,Y,Z,T,W) SHARED_PTR_MAP(X,Y,Z,T,W) +//#define SHARED_PTR_MAP(X,Y,Z,T) class X; typedef boost::shared_ptr<X> Y; typedef std::map <std::string, Y> Z; typedef std::map <std::string, Y>::iterator T +//#define SHARED_MAP_PTR(X,Y,Z,T) class X; typedef boost::shared_ptr<X> Y; typedef std::map <std::string, Y> Z; typedef std::map <std::string, Y>::iterator T #endif Modified: trunk/src/common/worldObject.cpp =================================================================== --- trunk/src/common/worldObject.cpp 2006-07-18 17:57:15 UTC (rev 439) +++ trunk/src/common/worldObject.cpp 2006-07-18 23:13:58 UTC (rev 440) @@ -14,21 +14,12 @@ unsigned int WorldObject::instancesCount = 0; WorldObjectsC WorldObject::worldObjects; -WorldObject::WorldObject (WorldObject * container, const std::string & name) +WorldObject::WorldObject (const std::string & name) { this->base = dynamic_cast<WorldObject *>(this); this->name = name; - this->container = container; - if (container == NULL) - { - this->path = "/unknownPath/"; - this->xmlPath = path + "unknownFilepath"; - } - else - { - this->path = container->getPath(); - this->xmlPath = container->getPath(); - } + this->path = "/unknownPath/"; + this->xmlPath = path + "unknownFilepath"; const int numberStringSize = 64; char numberString[numberStringSize]; @@ -38,13 +29,29 @@ //FIXME what to use, id# or name? log = LogEngine::create (LOG_DEVELOPER, this->getFullName()); - log->__format(LOG_CCREATOR, "Id #%s. Full Name: %s", id.c_str(), getFullName().c_str()); + log->__format(LOG_CCREATOR, "New world object! Id #%s.", id.c_str()); worldObjects[this->id] = this; } +void WorldObject::setContainer(pWorldObject container) +{ + std::string oldName = getFullName(); + this->container = container; + this->path = container->getPath(); + this->xmlPath = container->getPath(); + OdeObjectsIt j = odeObjects.begin(); + for(;j != odeObjects.end(); j++) + { + dBodySetData (j->second->getBodyID(), (void*) container.get()); + } + log->setName(this->getFullName()); + log->__format(LOG_CCREATOR, "New container! Old full name: %s. New full name: %s", id.c_str(), oldName.c_str(), getFullName().c_str()); + +} + WorldObject::~WorldObject () { - log->__format(LOG_CCREATOR, "Deleting myself. Id #%s. Full Name: %s", id.c_str(), getFullName().c_str()); - + log->__format(LOG_CCREATOR, "Deleting myself. Id #%s.", id.c_str()); + container.reset(); worldObjects.erase(this->id); base = NULL; } @@ -73,16 +80,18 @@ } std::string WorldObject::getFullName() { - if (container == NULL) return name; - return container->getFullName() + "." + name; + pWorldObject pcontainer = container.lock(); + if (pcontainer == NULL) return name; + return pcontainer->getFullName() + "." + name; } std::string WorldObject::getPath() { + if (path == "/unknownPath/") return System::get()->getCurrentPath(); return path; } void WorldObject::setPath(std::string path) { - this->path = path;; + this->path = path; } std::string WorldObject::getXmlPath() { @@ -96,9 +105,10 @@ { return log; } -WorldObject * WorldObject::getContainer() +pWorldObject WorldObject::getContainer() { - return container; + pWorldObject pcontainer = container.lock(); + return pcontainer; } pOdeObject WorldObject::getMainOdeObject() { Modified: trunk/src/common/worldObject.hpp =================================================================== --- trunk/src/common/worldObject.hpp 2006-07-18 17:57:15 UTC (rev 439) +++ trunk/src/common/worldObject.hpp 2006-07-18 23:13:58 UTC (rev 440) @@ -9,6 +9,7 @@ #ifndef WORLDOBJECT_HPP #define WORLDOBJECT_HPP +#include "system.hpp" #include "logEngine.hpp" #include "ogreObject.hpp" #include "odeObject.hpp" @@ -18,13 +19,13 @@ //forward declatations class Quaternion; class Vector3d; -SHARED_PTR_MAP(OgreObject, pOgreObject, OgreObjects, OgreObjectsIt); -SHARED_PTR_MAP(OdeObject, pOdeObject, OdeObjects, OdeObjectsIt); -SHARED_PTR_MAP(WorldObject, pWorldObject, WorldObjects, WorldObjectsIt); +SHARED_PTR_MAP(OgreObject, pOgreObject, OgreObjects, OgreObjectsIt, wOgreObject); +SHARED_PTR_MAP(OdeObject, pOdeObject, OdeObjects, OdeObjectsIt, wOdeObject); +SHARED_PTR_MAP(WorldObject, pWorldObject, WorldObjects, WorldObjectsIt, wWorldObject); typedef std::map <std::string, WorldObject *> WorldObjectsC; typedef std::map <std::string, WorldObject *>::iterator WorldObjectsCIt; -class WorldObject +class WorldObject: public boost::enable_shared_from_this <WorldObject> { private: virtual void hack(){}; @@ -37,13 +38,14 @@ protected: pLogEngine log; WorldObject * base; - WorldObject * container; + wWorldObject container; OgreObjects ogreObjects; OdeObjects odeObjects; - WorldObject (WorldObject * container, const std::string & name); + WorldObject (const std::string & name); public: virtual ~WorldObject (); - WorldObject * getContainer(); + void setContainer(pWorldObject container); + pWorldObject getContainer(); std::string getId(); std::string getName(); std::string getFullName(); Modified: trunk/src/graphics.hpp =================================================================== --- trunk/src/graphics.hpp 2006-07-18 17:57:15 UTC (rev 439) +++ trunk/src/graphics.hpp 2006-07-18 23:13:58 UTC (rev 440) @@ -11,8 +11,8 @@ // Forward declarations namespace Ogre { class Root; } -SHARED_PTR_MAP(LogEngine, pLogEngine, LogEngines, LogEnginesIt); -SHARED_PTR(Graphics,pGraphics); +SHARED_PTR_MAP(LogEngine, pLogEngine, LogEngines, LogEnginesIt, wLogEngine); +SHARED_PTR(Graphics,pGraphics, wGraphics); /** Manages everything related to the process of world data graphics rendering on screen. The menues and similar gadgets are not rendered by this engine; only world data is handled here (cars, area, etc...). * @brief Manages everything related to the rendering process. Modified: trunk/src/gui.hpp =================================================================== --- trunk/src/gui.hpp 2006-07-18 17:57:15 UTC (rev 439) +++ trunk/src/gui.hpp 2006-07-18 23:13:58 UTC (rev 440) @@ -15,9 +15,9 @@ class Camera; }; -SHARED_PTR_MAP(LogEngine, pLogEngine, LogEngines, LogEnginesIt); -SHARED_PTR(System,pSystem); -SHARED_PTR(Gui,pGui); +SHARED_PTR_MAP(LogEngine, pLogEngine, LogEngines, LogEnginesIt, wLogEngine); +SHARED_PTR(System,pSystem, wSystem); +SHARED_PTR(Gui,pGui, wGui); /// Manages everything related to the gui rendering process. /** Manages everything related to the process of system data (graphical user interface) graphics rendering on screen (menues and similar gadgets) Modified: trunk/src/input.hpp =================================================================== --- trunk/src/input.hpp 2006-07-18 17:57:15 UTC (rev 439) +++ trunk/src/input.hpp 2006-07-18 23:13:58 UTC (rev 440) @@ -10,9 +10,9 @@ #include <common/shared.hpp> // Forward declatation -SHARED_PTR_MAP(LogEngine, pLogEngine, LogEngines, LogEnginesIt); -SHARED_PTR(System,pSystem); -SHARED_PTR(Input,pInput); +SHARED_PTR_MAP(LogEngine, pLogEngine, LogEngines, LogEnginesIt, wLogEngine); +SHARED_PTR(System,pSystem, wSystem); +SHARED_PTR(Input,pInput, wInput); /// Manages everything related to user input. /** Manages everything related to user input, such as keyboard keypresses, mouse movement, steering wheel movement, joystick, etc... Essentially, it's the interface between the end-user and the simulated world, allowing the user to transparently make changes in this simulated world. Input devices calibration issues and many other things are handled by this engine. Modified: trunk/src/log/logEngine.cpp =================================================================== --- trunk/src/log/logEngine.cpp 2006-07-18 17:57:15 UTC (rev 439) +++ trunk/src/log/logEngine.cpp 2006-07-18 23:13:58 UTC (rev 440) @@ -100,6 +100,7 @@ } } logEngines.erase(d); + //d->second.reset(); //Check if this is the last log engine in the map.If it is, since we're gonna delete it, we close the log file. if (logEngines.size() <= 1) { Modified: trunk/src/log/logEngine.hpp =================================================================== --- trunk/src/log/logEngine.hpp 2006-07-18 17:57:15 UTC (rev 439) +++ trunk/src/log/logEngine.hpp 2006-07-18 23:13:58 UTC (rev 440) @@ -49,7 +49,7 @@ // Forward declarations class GuiEngine; -SHARED_PTR_MAP(LogEngine, pLogEngine, LogEngines, LogEnginesIt); +SHARED_PTR_MAP(LogEngine, pLogEngine, LogEngines, LogEnginesIt, wLogEngine); /// Allows to automate the recording of log messages to a file. /** Allows to automate the recording of log messages to a plain-text file. Every log engine has its own level of verbosity, meaning it can display only messages of a certain level of importance (discarding the less important messages). Modified: trunk/src/main.hpp =================================================================== --- trunk/src/main.hpp 2006-07-18 17:57:15 UTC (rev 439) +++ trunk/src/main.hpp 2006-07-18 23:13:58 UTC (rev 440) @@ -12,8 +12,8 @@ #include <shared.hpp> //forward declarations -SHARED_PTR_MAP(LogEngine, pLogEngine, LogEngines, LogEnginesIt); -SHARED_PTR(Graphics,pGraphics); +SHARED_PTR_MAP(LogEngine, pLogEngine, LogEngines, LogEnginesIt, wLogEngine); +SHARED_PTR(Graphics,pGraphics, wGraphics); /** * @brief Stops all SDL subsystems. Modified: trunk/src/physics.hpp =================================================================== --- trunk/src/physics.hpp 2006-07-18 17:57:15 UTC (rev 439) +++ trunk/src/physics.hpp 2006-07-18 23:13:58 UTC (rev 440) @@ -15,9 +15,9 @@ */ // Forward declarations -SHARED_PTR_MAP(LogEngine, pLogEngine, LogEngines, LogEnginesIt); -SHARED_PTR(System,pSystem); -SHARED_PTR(Physics,pPhysics); +SHARED_PTR_MAP(LogEngine, pLogEngine, LogEngines, LogEnginesIt, wLogEngine); +SHARED_PTR(System,pSystem, wSystem); +SHARED_PTR(Physics,pPhysics, wPhysics); class Physics { Modified: trunk/src/system.cpp =================================================================== --- trunk/src/system.cpp 2006-07-18 17:57:15 UTC (rev 439) +++ trunk/src/system.cpp 2006-07-18 23:13:58 UTC (rev 440) @@ -119,3 +119,12 @@ } +std::string System::getCurrentPath() +{ + return currentPath; +} + +void System::setCurrentPath(std::string path) +{ + currentPath = path; +} Modified: trunk/src/system.hpp =================================================================== --- trunk/src/system.hpp 2006-07-18 17:57:15 UTC (rev 439) +++ trunk/src/system.hpp 2006-07-18 23:13:58 UTC (rev 440) @@ -15,7 +15,7 @@ // Forward declarations namespace Ogre { class RenderWindow; class SceneManager; } -SHARED_PTR(System,pSystem); +SHARED_PTR(System,pSystem, wSystem); /** * @brief Contains a lot of data, generally needed in many places. It's a singleton. @@ -51,6 +51,7 @@ * @brief Initializes the instance some default hardcoded values. */ System(); + std::string currentPath; public: /** * @brief Returns the SystemData singleton instance. @@ -212,6 +213,8 @@ * @brief Notifies the sytem that the main loop should be stopped. */ void disableMainLoop (void); // allows the program to stop running + std::string getCurrentPath(); + void setCurrentPath(std::string path); Ogre::RenderWindow * ogreWindow; Ogre::SceneManager * ogreSceneManager; Modified: trunk/src/vehicle/body.cpp =================================================================== --- trunk/src/vehicle/body.cpp 2006-07-18 17:57:15 UTC (rev 439) +++ trunk/src/vehicle/body.cpp 2006-07-18 23:13:58 UTC (rev 440) @@ -18,13 +18,13 @@ #include "SDL/SDL_keysym.h" #include "vehicle.hpp" -pBody Body::create (WorldObject * container, XmlTag * tag) +pBody Body::create (XmlTag * tag) { - pBody tmp (new Body(container, tag)); + pBody tmp (new Body(tag)); return tmp; } -Body::Body (WorldObject * container, XmlTag * tag) - :WorldObject(container, "body") +Body::Body (XmlTag * tag) + :WorldObject("body") { dragCoefficient = 0.3; frontalArea = 0; Modified: trunk/src/vehicle/body.hpp =================================================================== --- trunk/src/vehicle/body.hpp 2006-07-18 17:57:15 UTC (rev 439) +++ trunk/src/vehicle/body.hpp 2006-07-18 23:13:58 UTC (rev 440) @@ -18,7 +18,7 @@ class Quaternion; class Vehicle; -SHARED_PTR(Body, pBody); +SHARED_PTR(Body, pBody, wBody); class Body : public WorldObject { @@ -27,9 +27,9 @@ double frontalArea; void stopPhysics (); void stopGraphics (); - Body (WorldObject * container, XmlTag * tag); + Body (XmlTag * tag); public: - static pBody create (WorldObject * container, XmlTag * tag); + static pBody create (XmlTag * tag); ~Body (); void stepPhysics (); }; Modified: trunk/src/vehicle/driveJoint.cpp =================================================================== --- trunk/src/vehicle/driveJoint.cpp 2006-07-18 17:57:15 UTC (rev 439) +++ trunk/src/vehicle/driveJoint.cpp 2006-07-18 23:13:58 UTC (rev 440) @@ -13,27 +13,27 @@ #include "SDL/SDL_keysym.h" #include "pedal.hpp" -DriveJoint::DriveJoint (WorldObject * container, std::string name) - :WorldObject(container, name) +DriveJoint::DriveJoint (std::string name) + :WorldObject(name) { } DriveJoint::~DriveJoint () { } -pClutch Clutch::create (WorldObject * container, XmlTag * tag) +pClutch Clutch::create (XmlTag * tag) { - pClutch tmp(new Clutch(container, tag)); + pClutch tmp(new Clutch(tag)); return tmp; } -pClutch Clutch::create (WorldObject * container) +pClutch Clutch::create () { - pClutch tmp(new Clutch(container)); + pClutch tmp(new Clutch()); return tmp; } -Clutch::Clutch (WorldObject * container, XmlTag * tag) - :DriveJoint(container, "clutch") +Clutch::Clutch (XmlTag * tag) + :DriveJoint("clutch") { outputTorqueTransfer = 0.0; inputTorqueTransfer = 0.0; @@ -48,8 +48,8 @@ } } -Clutch::Clutch (WorldObject * container) - :DriveJoint(container, "clutch") +Clutch::Clutch () + :DriveJoint("clutch") { outputTorqueTransfer = 0.0; inputTorqueTransfer = 0.0; @@ -67,19 +67,19 @@ } -pGear Gear::create (WorldObject * container, XmlTag * tag) +pGear Gear::create (XmlTag * tag) { - pGear tmp (new Gear(container, tag)); + pGear tmp (new Gear(tag)); return tmp; } -pGear Gear::create (WorldObject * container) +pGear Gear::create () { - pGear tmp (new Gear(container)); + pGear tmp (new Gear()); return tmp; } -Gear::Gear (WorldObject * container, XmlTag * tag) - :DriveJoint(container, "gear") +Gear::Gear (XmlTag * tag) + :DriveJoint("gear") { outputTorqueTransfer = 0.0; inputTorqueTransfer = 0.0; @@ -96,8 +96,8 @@ } } -Gear::Gear (WorldObject * container) - :DriveJoint(container, "gear") +Gear::Gear () + :DriveJoint("gear") { ratio = 1.0; springConstant = 300.0; @@ -114,18 +114,18 @@ { } -pLSD LSD::create (WorldObject * container, XmlTag * tag) +pLSD LSD::create (XmlTag * tag) { - pLSD tmp (new LSD(container, tag)); + pLSD tmp (new LSD(tag)); return tmp; } -pLSD LSD::create (WorldObject * container) +pLSD LSD::create () { - pLSD tmp (new LSD(container)); + pLSD tmp (new LSD()); return tmp; } -LSD::LSD (WorldObject * container, XmlTag * tag) - :DriveJoint(container, "lsd") +LSD::LSD (XmlTag * tag) + :DriveJoint("lsd") { outputTorqueTransfer = 0.0; inputTorqueTransfer = 0.0; @@ -142,8 +142,8 @@ } } -LSD::LSD (WorldObject * container) - :DriveJoint(container, "lsd") +LSD::LSD () + :DriveJoint("lsd") { ratio = 1.0; springConstant = 300.0; Modified: trunk/src/vehicle/driveJoint.hpp =================================================================== --- trunk/src/vehicle/driveJoint.hpp 2006-07-18 17:57:15 UTC (rev 439) +++ trunk/src/vehicle/driveJoint.hpp 2006-07-18 23:13:58 UTC (rev 440) @@ -13,10 +13,10 @@ #include "worldObject.hpp" // Forward declarations -SHARED_PTR(Pedal, pPedal); -SHARED_PTR(DriveMass, pDriveMass); +SHARED_PTR(Pedal, pPedal, wPedal); +SHARED_PTR(DriveMass, pDriveMass, wDriveMass); -SHARED_PTR(DriveJoint, pDriveJoint); +SHARED_PTR(DriveJoint, pDriveJoint, wDriveJoint); class DriveJoint : public WorldObject { protected: @@ -33,7 +33,7 @@ pDriveMass outputDrive; bool enabled; public: - DriveJoint (WorldObject * container, std::string name); + DriveJoint (std::string name); ~DriveJoint (); void enable () { enabled = 1; } ; void disable () { enabled = 0; } ; @@ -45,7 +45,7 @@ void setInputPointer (pDriveMass input) { inputDrive = input; } ; }; -SHARED_PTR(Clutch, pClutch); +SHARED_PTR(Clutch, pClutch, wClutch); class Clutch : public DriveJoint { private: @@ -55,17 +55,17 @@ double maxTorqueTransfer; double lockedParam; bool locked; - Clutch (WorldObject * container, XmlTag * tag); - Clutch (WorldObject * container); + Clutch (XmlTag * tag); + Clutch (); public: - static pClutch create (WorldObject * container, XmlTag * tag); - static pClutch create (WorldObject * container); + static pClutch create (XmlTag * tag); + static pClutch create (); ~Clutch (); void setClutchPedal(pPedal pedal); void stepPhysics (); }; -SHARED_PTR(Gear, pGear); +SHARED_PTR(Gear, pGear, wGear); class Gear : public DriveJoint { private: @@ -73,17 +73,17 @@ double springConstant; double dampConstant; void startPhysics (XmlTag * tag); - Gear (WorldObject * container, XmlTag * tag); - Gear (WorldObject * container); + Gear (XmlTag * tag); + Gear (); public: - static pGear create (WorldObject * container, XmlTag * tag); - static pGear create (WorldObject * container); + static pGear create (XmlTag * tag); + static pGear create (); ~Gear (); void processXmlRootNode (XmlTag * tag); void stepPhysics (); }; -SHARED_PTR(LSD, pLSD); +SHARED_PTR(LSD, pLSD, wLSD); class LSD : public DriveJoint { private: @@ -97,11 +97,11 @@ double dampConstant; double limitedSlipClutchFriction; void startPhysics (XmlTag * tag); - LSD (WorldObject * container, XmlTag * tag); - LSD (WorldObject * container); + LSD (XmlTag * tag); + LSD (); public: - static pLSD create (WorldObject * container, XmlTag * tag); - static pLSD create (WorldObject * container); + static pLSD create (XmlTag * tag); + static pLSD create (); ~LSD (); void processXmlRootNode (XmlTag * tag); void setOutputPointer2 (pDriveMass output) { outputDrive2 = output; } ; Modified: trunk/src/vehicle/driveMass.cpp =================================================================== --- trunk/src/vehicle/driveMass.cpp 2006-07-18 17:57:15 UTC (rev 439) +++ trunk/src/vehicle/driveMass.cpp 2006-07-18 23:13:58 UTC (rev 440) @@ -9,8 +9,8 @@ #include "driveMass.hpp" -DriveMass::DriveMass (WorldObject * container, std::string name) - :WorldObject(container, name) +DriveMass::DriveMass (std::string name) + :WorldObject(name) { inertia = 0.0; friction = 0.0; Modified: trunk/src/vehicle/driveMass.hpp =================================================================== --- trunk/src/vehicle/driveMass.hpp 2006-07-18 17:57:15 UTC (rev 439) +++ trunk/src/vehicle/driveMass.hpp 2006-07-18 23:13:58 UTC (rev 440) @@ -27,7 +27,7 @@ double outputTorqueTransfer; double inputTorqueTransfer; public: - DriveMass (WorldObject * container, std::string name); + DriveMass (std::string name); ~DriveMass (); double getInputTorque () { return inputTorqueTransfer; } ; double getOutputTorque () { return outputTorqueTransfer; } ; Modified: trunk/src/vehicle/engine.cpp =================================================================== --- trunk/src/vehicle/engine.cpp 2006-07-18 17:57:15 UTC (rev 439) +++ trunk/src/vehicle/engine.cpp 2006-07-18 23:13:58 UTC (rev 440) @@ -13,14 +13,14 @@ #include "SDL/SDL_keysym.h" #include "pedal.hpp" -pEngine Engine::create(WorldObject * container, XmlTag * tag) +pEngine Engine::create(XmlTag * tag) { - pEngine tmp(new Engine(container, tag)); + pEngine tmp(new Engine(tag)); return tmp; } -Engine::Engine (WorldObject * container, XmlTag * tag) - :DriveMass(container, "engine") +Engine::Engine (XmlTag * tag) + :DriveMass("engine") { inputAngularVel = 0.0; prevAngularVel = 0.0; Modified: trunk/src/vehicle/engine.hpp =================================================================== --- trunk/src/vehicle/engine.hpp 2006-07-18 17:57:15 UTC (rev 439) +++ trunk/src/vehicle/engine.hpp 2006-07-18 23:13:58 UTC (rev 440) @@ -13,9 +13,9 @@ #include "driveJoint.hpp" // Forward declarations -SHARED_PTR(Pedal, pPedal); +SHARED_PTR(Pedal, pPedal, wPedal); -SHARED_PTR(Engine, pEngine); +SHARED_PTR(Engine, pEngine, wEngine); class Engine : public DriveMass { private: @@ -23,9 +23,9 @@ double telemetryTorque; double angularVelLimit; pPedal gasPedal; - Engine (WorldObject * container, XmlTag * tag); + Engine (XmlTag * tag); public: - static pEngine create (WorldObject * container, XmlTag * tag); + static pEngine create (XmlTag * tag); ~Engine (); void setGasPedal (pPedal pedal); void stepPhysics (); Modified: trunk/src/vehicle/finalDrive.cpp =================================================================== --- trunk/src/vehicle/finalDrive.cpp 2006-07-18 17:57:15 UTC (rev 439) +++ trunk/src/vehicle/finalDrive.cpp 2006-07-18 23:13:58 UTC (rev 440) @@ -13,14 +13,14 @@ #include "ode/ode.h" #include "SDL/SDL_keysym.h" -pFinalDrive FinalDrive::create(WorldObject * container, XmlTag * tag) +pFinalDrive FinalDrive::create(XmlTag * tag) { - pFinalDrive tmp(new FinalDrive(container, tag)); + pFinalDrive tmp(new FinalDrive(tag)); return tmp; } -FinalDrive::FinalDrive (WorldObject * container, XmlTag * tag) - :DriveMass(container, "finalDrive") +FinalDrive::FinalDrive (XmlTag * tag) + :DriveMass("finalDrive") { outputTorqueTransfer = 0.0; inputTorqueTransfer = 0.0; Modified: trunk/src/vehicle/finalDrive.hpp =================================================================== --- trunk/src/vehicle/finalDrive.hpp 2006-07-18 17:57:15 UTC (rev 439) +++ trunk/src/vehicle/finalDrive.hpp 2006-07-18 23:13:58 UTC (rev 440) @@ -11,15 +11,15 @@ #define FINALDRIVE_HPP #include "driveMass.hpp" -SHARED_PTR(FinalDrive, pFinalDrive); +SHARED_PTR(FinalDrive, pFinalDrive, wFinalDrive); class FinalDrive : public DriveMass { private: double finalDriveRatio; DriveJoint *outputJoint2; - FinalDrive (WorldObject * container, XmlTag * tag); + FinalDrive (XmlTag * tag); public: - static pFinalDrive create (WorldObject * container, XmlTag * tag); + static pFinalDrive create (XmlTag * tag); ~FinalDrive (); void stepPhysics (); }; Modified: trunk/src/vehicle/gearbox.cpp =================================================================== --- trunk/src/vehicle/gearbox.cpp 2006-07-18 17:57:15 UTC (rev 439) +++ trunk/src/vehicle/gearbox.cpp 2006-07-18 23:13:58 UTC (rev 440) @@ -12,14 +12,14 @@ #include "system.hpp" #include "SDL/SDL_keysym.h" -pGearbox Gearbox::create(WorldObject * container, XmlTag * tag) +pGearbox Gearbox::create(XmlTag * tag) { - pGearbox tmp(new Gearbox(container, tag)); + pGearbox tmp(new Gearbox(tag)); return tmp; } -Gearbox::Gearbox (WorldObject * container, XmlTag * tag) - :DriveMass(container, "gearbox") +Gearbox::Gearbox (XmlTag * tag) + :DriveMass("gearbox") { log->__format (LOG_CCREATOR, "Starting to parse a gearbox node"); outputTorqueTransfer = 0.0; @@ -42,7 +42,7 @@ { if (t->getName() == "gear") { - GearboxGear * tmp = new GearboxGear (this, t); + pGearboxGear tmp = GearboxGear::create(t); gearMap[tmp->getNumber()] = tmp; } } @@ -51,17 +51,26 @@ Gearbox::~Gearbox () { - for(std::map<int,GearboxGear*>::iterator i = gearMap.begin(); i != gearMap.end(); i++) +} + +void Gearbox::setContainer(pWorldObject container) +{ + DriveMass::setContainer(container); + for(std::map<int,pGearboxGear>::iterator i = gearMap.begin(); i != gearMap.end(); i++) { - delete (i->second); + i->second->setContainer(shared_from_this()); } - gearMap.clear(); } -GearboxGear::GearboxGear (WorldObject * container, XmlTag * tag) - :WorldObject(container, "gearboxGear") +pGearboxGear GearboxGear::create(XmlTag * tag) { + pGearboxGear tmp(new GearboxGear(tag)); + return tmp; +} +GearboxGear::GearboxGear (XmlTag * tag) + :WorldObject("gearboxGear") +{ log->__format (LOG_CCREATOR, "Starting to parse a gearbox gear node"); ratio = 1.0; number = 0; Modified: trunk/src/vehicle/gearbox.hpp =================================================================== --- trunk/src/vehicle/gearbox.hpp 2006-07-18 17:57:15 UTC (rev 439) +++ trunk/src/vehicle/gearbox.hpp 2006-07-18 23:13:58 UTC (rev 440) @@ -12,29 +12,32 @@ #include "driveMass.hpp" #include "wheel.hpp" -SHARED_PTR(GearboxGear, pGearboxgear); +SHARED_PTR(GearboxGear, pGearboxGear, wGearboxGear); class GearboxGear : public WorldObject { + private: + GearboxGear (XmlTag * tag); public: + static pGearboxGear create(XmlTag * tag); bool enabled; double ratio; int number; - GearboxGear (WorldObject * container, XmlTag * tag); ~GearboxGear (); int getNumber() { return number; } ; double getRatio() { return ratio; } ; bool isEnabled() { return enabled; } ; }; -SHARED_PTR(Gearbox, pGearbox); +SHARED_PTR(Gearbox, pGearbox, wGearbox); class Gearbox : public DriveMass { private: - std::map < int, GearboxGear *> gearMap; + std::map < int, pGearboxGear> gearMap; int currentGear; double gearRatio; - Gearbox (WorldObject * container, XmlTag * tag); + Gearbox (XmlTag * tag); public: - static pGearbox create(WorldObject * container, XmlTag * tag); + static pGearbox create(XmlTag * tag); + void setContainer(pWorldObject container); ~Gearbox (); void setGear (int inputGear) { currentGear = inputGear; }; double getGearRatio() { return gearMap[currentGear]->ratio; }; Modified: trunk/src/vehicle/pedal.cpp =================================================================== --- trunk/src/vehicle/pedal.cpp 2006-07-18 17:57:15 UTC (rev 439) +++ trunk/src/vehicle/pedal.cpp 2006-07-18 23:13:58 UTC (rev 440) @@ -13,14 +13,14 @@ #include "system.hpp" #include "SDL/SDL_keysym.h" -pPedal Pedal::create(WorldObject * container, XmlTag * tag) +pPedal Pedal::create(XmlTag * tag) { - pPedal tmp(new Pedal(container, tag)); + pPedal tmp(new Pedal(tag)); return tmp; } -Pedal::Pedal (WorldObject * container, XmlTag * tag) - :WorldObject(container, "pedal") +Pedal::Pedal (XmlTag * tag) + :WorldObject("pedal") { log->__format (LOG_CCREATOR, "Starting to parse a pedal node"); angleRange = 180; Modified: trunk/src/vehicle/pedal.hpp =================================================================== --- trunk/src/vehicle/pedal.hpp 2006-07-18 17:57:15 UTC (rev 439) +++ trunk/src/vehicle/pedal.hpp 2006-07-18 23:13:58 UTC (rev 440) @@ -11,16 +11,16 @@ #define PEDAL_HPP #include "worldObject.hpp" -SHARED_PTR(Pedal, pPedal); +SHARED_PTR(Pedal, pPedal, wPedal); class Pedal : public WorldObject { private: bool userDriver; double angleRange; double currentAngle; - Pedal (WorldObject * container, XmlTag * tag); + Pedal (XmlTag * tag); public: - static pPedal create(WorldObject * container, XmlTag * tag); + static pPedal create(XmlTag * tag); ~Pedal (); void setUserDriver (); void stepPhysics (); Modified: trunk/src/vehicle/suspension.cpp =================================================================== --- trunk/src/vehicle/suspension.cpp 2006-07-18 17:57:15 UTC (rev 439) +++ trunk/src/vehicle/suspension.cpp 2006-07-18 23:13:58 UTC (rev 440) @@ -21,8 +21,8 @@ #include "SDL/SDL_keysym.h" #include <cmath> -Suspension::Suspension (WorldObject * container, std::string name) - : WorldObject(container, name) +Suspension::Suspension (std::string name) + : WorldObject(name) { position = Vector3d (0, 0, 0); rotation = Quaternion (1, 0, 0, 0); @@ -133,13 +133,13 @@ dJointSetHinge2Param(jointID, dParamVel, 0); } -pUnidimensional Unidimensional::create (WorldObject * container, XmlTag * tag) +pUnidimensional Unidimensional::create (XmlTag * tag) { - pUnidimensional tmp(new Unidimensional(container, tag)); + pUnidimensional tmp(new Unidimensional(tag)); return tmp; } -Unidimensional::Unidimensional (WorldObject * container, XmlTag * tag) - :Suspension(container, "suspension.unidimensional") +Unidimensional::Unidimensional (XmlTag * tag) + :Suspension("suspension.unidimensional") { userDriver = false; springConstant = 0; @@ -184,7 +184,7 @@ //pWheel wheel = boost::dynamic_pointer_cast<pWheel>(object); if (wheel == NULL) log->__format(LOG_ERROR, "Trying to attach a non-wheel object to the suspension!"); if (base->getMainOdeObject() == NULL) log->__format(LOG_ERROR, "Trying to attach a wheel object to an object with no physics!"); - wheel->setSusp(shared_from_this()); + wheel->setSusp(boost::dynamic_pointer_cast<Suspension>(shared_from_this())); //wheel->setSusp(this); dJointAttach (jointID, base->getMainOdeObject()->getBodyID(), object->getMainOdeObject()->getBodyID()); @@ -207,14 +207,14 @@ } -pFixed Fixed::create(WorldObject * container, XmlTag * tag) +pFixed Fixed::create(XmlTag * tag) { - pFixed tmp(new Fixed(container, tag)); + pFixed tmp(new Fixed(tag)); return tmp; } -Fixed::Fixed (WorldObject * container, XmlTag * tag) - :Suspension(container, "suspension.unidimensional") +Fixed::Fixed (XmlTag * tag) + :Suspension("suspension.unidimensional") { userDriver = false; if (tag->getName() == "suspension.fixed") @@ -240,7 +240,7 @@ pWheel wheel = boost::dynamic_pointer_cast<Wheel>(object); if (wheel == NULL) log->__format(LOG_ERROR, "Trying to attach a non-wheel object to the suspension!"); if (base->getMainOdeObject() == NULL) log->__format(LOG_ERROR, "Trying to attach a wheel object to an object with no physics!"); - wheel->setSusp(shared_from_this()); + wheel->setSusp(boost::dynamic_pointer_cast<Suspension>(shared_from_this())); dJointAttach (jointID, base->getMainOdeObject()->getBodyID(), object->getMainOdeObject()->getBodyID()); // finite rotation on wheels helps avoid explosions, FIXME prolly needs to be relative to suspension axis @@ -270,14 +270,14 @@ dJointSetHingeParam(jointID, dParamVel, 0); } -pDoubleWishbone DoubleWishbone::create(WorldObject * container, XmlTag * tag) +pDoubleWishbone DoubleWishbone::create(XmlTag * tag) { - pDoubleWishbone tmp(new DoubleWishbone(container, tag)); + pDoubleWishbone tmp(new DoubleWishbone(tag)); return tmp; } -DoubleWishbone::DoubleWishbone(WorldObject * container, XmlTag * tag) - :Suspension(container, "suspension.doublewishbone") +DoubleWishbone::DoubleWishbone(XmlTag * tag) + :Suspension("suspension.doublewishbone") { pOgreObjectData upperBoneOData(new OgreObjectData); pOgreObjectData lowerBoneOData(new OgreObjectData); @@ -318,7 +318,6 @@ upperBoneData->length = upperBoneLength = 0.3; upperBoneData->mass = 2.0; odeObjects["upperBone"] = pOdeObject(new OdeObject(this, upperBoneData, "upperBone")); - dBodySetData (odeObjects["upperBone"]->getBodyID(), (void*) container); Quaternion upperBoneRot (90, 0, 0); odeObjects["upperBone"]->setRotation(upperBoneRot); Vector3d upperBonePos (firstPosition.x, firstPosition.y+(dirMult*upperBoneLength*0.5) , firstPosition.z+(uprightBoneLength*0.5)); @@ -335,7 +334,6 @@ lowerBoneData->length = lowerBoneLength = 0.3; lowerBoneData->mass = 2.0; odeObjects["lowerBone"] = pOdeObject(new OdeObject(this, lowerBoneData, "lowerBone")); - dBodySetData (odeObjects["lowerBone"]->getBodyID(), (void*) container); Quaternion lowerBoneRot (90, 0, 0); odeObjects["lowerBone"]->setRotation(lowerBoneRot); Vector3d lowerBonePos (firstPosition.x, firstPosition.y+(dirMult*lowerBoneLength*0.5) , firstPosition.z-(uprightBoneLength*0.5)); @@ -352,7 +350,6 @@ uprightBoneData->length = uprightBoneLength; uprightBoneData->mass = 2.0; odeObjects["uprightBone"] = pOdeObject(new OdeObject(this, uprightBoneData, "uprightBone")); - dBodySetData (odeObjects["uprightBone"]->getBodyID(), (void*) container); Quaternion uprightBoneRot (0, 0, 0); odeObjects["uprightBone"]->setRotation(uprightBoneRot); Vector3d uprightBonePos (firstPosition.x, firstPosition.y+(dirMult*upperBoneData->length), firstPosition.z); @@ -392,7 +389,7 @@ pWheel wheel = boost::dynamic_pointer_cast<Wheel>(object); if (wheel == NULL) log->__format(LOG_ERROR, "Trying to attach a non-wheel object to the suspension!"); if (base->getMainOdeObject() == NULL) log->__format(LOG_ERROR, "Trying to attach a wheel object to an object with no physics!"); - wheel->setSusp(shared_from_this()); + wheel->setSusp(boost::dynamic_pointer_cast<Suspension>(shared_from_this())); double dirMult = 1.0; if (!right) dirMult *= -1; Modified: trunk/src/vehicle/suspension.hpp =================================================================== --- trunk/src/vehicle/suspension.hpp 2006-07-18 17:57:15 UTC (rev 439) +++ trunk/src/vehicle/suspension.hpp 2006-07-18 23:13:58 UTC (rev 440) @@ -24,10 +24,10 @@ class SceneNode; } -class Suspension : public boost::enable_shared_from_this <Suspension> , public WorldObject +class Suspension : public WorldObject { protected: - Suspension (WorldObject * container, std::string name); + Suspension (std::string name); ~Suspension (); Quaternion rotation; Vector3d position; @@ -46,7 +46,7 @@ virtual void attach(pWorldObject base, pWorldObject object)=0; }; -SHARED_PTR(Unidimensional, pUnidimensional); +SHARED_PTR(Unidimensional, pUnidimensional, wUnidimensional); class Unidimensional : public Suspension { protected: @@ -55,9 +55,9 @@ double dampingConstant; double maxSteeringAngle; double getSteeringAngle(); - Unidimensional (WorldObject * container, XmlTag * tag); + Unidimensional (XmlTag * tag); public: - static pUnidimensional create(WorldObject * container, XmlTag * tag); + static pUnidimensional create(XmlTag * tag); ~Unidimensional(); void stepPhysics(); @@ -67,14 +67,14 @@ void attach(pWorldObject base, pWorldObject object); }; -SHARED_PTR(Fixed, pFixed); +SHARED_PTR(Fixed, pFixed, wFixed); class Fixed : public Suspension { protected: dJointID jointID; - Fixed (WorldObject * container, XmlTag * tag); + Fixed (XmlTag * tag); public: - static pFixed create(WorldObject * container, XmlTag * tag); + static pFixed create(XmlTag * tag); ~Fixed(); void stepPhysics(); @@ -83,7 +83,7 @@ void setVelocity(double velocity); void attach(pWorldObject base, pWorldObject object); }; -SHARED_PTR(DoubleWishbone, pDoubleWishbone); +SHARED_PTR(DoubleWishbone, pDoubleWishbone, wDoubleWishbone); class DoubleWishbone : public Suspension { protected: @@ -112,9 +112,9 @@ Vector3d getFirstLinkPosition (){return firstPosition;}; Quaternion getFirstLinkRotation (){return firstRotation;}; - DoubleWishbone (WorldObject * container, XmlTag * tag); + DoubleWishbone (XmlTag * tag); public: - static pDoubleWishbone create(WorldObject * container, XmlTag * tag); + static pDoubleWishbone create(XmlTag * tag); ~DoubleWishbone(); void stepPhysics(); Modified: trunk/src/vehicle/vehicle.cpp =================================================================== --- trunk/src/vehicle/vehicle.cpp 2006-07-18 17:57:15 UTC (rev 439) +++ trunk/src/vehicle/vehicle.cpp 2006-07-18 23:13:58 UTC (rev 440) @@ -25,15 +25,16 @@ #include "SDL/SDL_keysym.h" #include "quaternion.hpp" -pVehicle Vehicle::create(WorldObject * container, std::string vehicleName) +pVehicle Vehicle::create(std::string vehicleName) { - pVehicle vehicle(new Vehicle(container, vehicleName)); + pVehicle vehicle(new Vehicle(vehicleName)); return vehicle; } -Vehicle::Vehicle (WorldObject * container, std::string vehicleName) - :WorldObject(container, vehicleName) +Vehicle::Vehicle (std::string vehicleName) + :WorldObject(vehicleName) { setPath(Paths::vehicle(vehicleName)); + System::get()->setCurrentPath(Paths::vehicle(vehicleName)); setXmlPath(Paths::vehicleXml(vehicleName)); Ogre::ResourceGroupManager::getSingleton().addResourceLocation(getPath(), "FileSystem", "vehicles." + vehicleName); Ogre::ResourceGroupManager::getSingleton().addResourceLocation(getPath()+"skybox.zip","Zip","vehicles."+vehicleName); @@ -55,6 +56,7 @@ } components.clear(); } + void Vehicle::setUserDriver () { userDriver = true; @@ -85,52 +87,53 @@ contact = tag->getAttribute("contact"); license = tag->getAttribute("license"); - components["rearDiff"] = LSD::create(this); - components["transfer"] = Gear::create(this); + components["rearDiff"] = LSD::create(); + components["transfer"] = Gear::create(); XmlTag * t = tag->getTag(0); for (int i = 0; i < tag->nTags(); t = tag->getTag(++i)) { - if (t->getName() == "body") components["body"] = Body::create (this, t); - if (t->getName() == "engine") components["engine"] = Engine::create (this, t); - if (t->getName() == "clutch") components["clutch"] = Clutch::create (this, t); - if (t->getName() == "gearbox") components["gearbox"] = Gearbox::create (this, t); - if (t->getName() == "finalDrive") components["finalDrive"] = FinalDrive::create (this, t); + if (t->getName() == "body") components["body"] = Body::create (t); + if (t->getName() == "engine") components["engine"] = Engine::create (t); + if (t->getName() == "clutch") components["clutch"] = Clutch::create (t); + if (t->getName() == "gearbox") components["gearbox"] = Gearbox::create (t); + if (t->getName() == "finalDrive") components["finalDrive"] = FinalDrive::create (t); if (t->getName() == "pedal") { - pPedal tmp = Pedal::create (this, t); + pPedal tmp = Pedal::create (t); components[tmp->getName()] = tmp; } if (t->getName() == "wheel") { - pWheel tmp = Wheel::create (this, t); + pWheel tmp = Wheel::create (t); components[tmp->getName()] = tmp; System::get()->ogreWindow->update (); } if (t->getName() == "suspension.unidimensional") { - pUnidimensional tmp = Unidimensional::create (this, t); + pUnidimensional tmp = Unidimensional::create (t); components[tmp->getName()] = tmp; System::get()->ogreWindow->update (); } if (t->getName() == "suspension.fixed") { - pFixed tmp = Fixed::create (this, t); + pFixed tmp = Fixed::create (t); components[tmp->getName()] = tmp; System::get()->ogreWindow->update (); } if (t->getName() == "suspension.doublewishbone") { - pDoubleWishbone tmp = DoubleWishbone::create (this, t); + pDoubleWishbone tmp = DoubleWishbone::create (t); components[tmp->getName()] = tmp; System::get()->ogreWindow->update (); } if (t->getName() == "camera") { - pCamera tmp = Camera::create (this, t); + pCamera tmp = Camera::create (t); cameras[tmp->getName()] = tmp; } } } + // spread the news to the necessary (input-able) vehicle parts log->__format(LOG_DEVELOPER, "Setting some drive joint pointers..."); getDriveJoint("clutch")->setOutputPointer(getDriveMass("gearbox")); getDriveJoint("transfer")->setOutputPointer(getDriveMass("finalDrive")); @@ -170,6 +173,21 @@ stepGraphics(); } +void Vehicle::setContainer (pWorldObject container) +{ + WorldObject::setContainer(container); + // tell all the objects who's the boss. + for (WorldObjectsIt i = components.begin(); i != components.end(); i++) + { + i->second->setContainer(shared_from_this()); + } + getGearbox("gearbox")->setContainer(shared_from_this()); + for (CamerasIt i = cameras.begin(); i != cameras.end(); i++) + { + i->second->setContainer(shared_from_this()); + } +} + void Vehicle::stepGraphics () { base->stepGraphics(); Modified: trunk/src/vehicle/vehicle.hpp =================================================================== --- trunk/src/vehicle/vehicle.hpp 2006-07-18 17:57:15 UTC (rev 439) +++ trunk/src/vehicle/vehicle.hpp 2006-07-18 23:13:58 UTC (rev 440) @@ -14,25 +14,25 @@ #include "xmlTag.hpp" // Forward declarations -SHARED_PTR(Body, pBody); -SHARED_PTR(Engine, pEngine); -SHARED_PTR(Clutch, pClutch); -SHARED_PTR(Gear, pGear); -SHARED_PTR(Gearbox, pGearbox); -SHARED_PTR(GearboxGear, pGearboxGear); -SHARED_PTR(FinalDrive, pFinalDrive); -SHARED_PTR(DriveJoint, pDriveJoint); -SHARED_PTR(DriveMass, pDriveMass); -SHARED_PTR(LSD, pLSD); -SHARED_PTR(Wheel, pWheel); -SHARED_PTR(Pedal, pPedal); -SHARED_PTR(Suspension, pSuspension); +SHARED_PTR(Body, pBody, wBody); +SHARED_PTR(Engine, pEngine, wEngine); +SHARED_PTR(Clutch, pClutch, wClutch); +SHARED_PTR(Gear, pGear, wGear); +SHARED_PTR(Gearbox, pGearbox, wGearbox); +SHARED_PTR(GearboxGear, pGearboxGear, wGearboxGear); +SHARED_PTR(FinalDrive, pFinalDrive, wFinalDrive); +SHARED_PTR(DriveJoint, pDriveJoint, wDriveJoint); +SHARED_PTR(DriveMass, pDriveMass, wDriveMass); +SHARED_PTR(LSD, pLSD, wLSD); +SHARED_PTR(Wheel, pWheel, wWheel); +SHARED_PTR(Pedal, pPedal, wPedal); +SHARED_PTR(Suspension, pSuspension, wSuspension); class Vector3d; class Quaternion; class CameraPosition; -SHARED_PTR_MAP(Camera, pCamera, Cameras, CameraIt); -SHARED_PTR_MAP(Vehicle, pVehicle, Vehicles, VehiclesIt); +SHARED_PTR_MAP(Vehicle, pVehicle, Vehicles, VehiclesIt, wVehicle); +SHARED_PTR_MAP(Camera, pCamera, Cameras, CameraIt, wCamera); class Vehicle : public WorldObject { @@ -48,9 +48,10 @@ void boltWheelsToSuspensions(); void stopGraphics (); WorldObjects components; - Vehicle (WorldObject * container, std::string vehicleName); + Vehicle (std::string vehicleName); public: - static pVehicle create(WorldObject * container, std::string vehicleName); + static pVehicle create(std::string vehicleName); + void setContainer (pWorldObject container); ~Vehicle (); Cameras cameras; Modified: trunk/src/vehicle/wheel.cpp =================================================================== --- trunk/src/vehicle/wheel.cpp 2006-07-18 17:57:15 UTC (rev 439) +++ trunk/src/vehicle/wheel.cpp 2006-07-18 23:13:58 UTC (rev 440) @@ -19,14 +19,14 @@ #include "vehicle.hpp" #include "suspension.hpp" -pWheel Wheel::create(WorldObject * container, XmlTag * tag) +pWheel Wheel::create(XmlTag * tag) { - pWheel tmp(new Wheel(container, tag)); + pWheel tmp(new Wheel(tag)); return tmp; } -Wheel::Wheel (WorldObject * container, XmlTag * tag) - :DriveMass(container, "wheel") +Wheel::Wheel (XmlTag * tag) + :DriveMass("wheel") { log->__format (LOG_DEVELOPER, "Starting to parse a wheel node"); pWheelOdeData data(new WheelOdeData); Modified: trunk/src/vehicle/wheel.hpp =================================================================== --- trunk/src/vehicle/wheel.hpp 2006-07-18 17:57:15 UTC (rev 439) +++ trunk/src/vehicle/wheel.hpp 2006-07-18 23:13:58 UTC (rev 440) @@ -21,9 +21,8 @@ class Entity; class SceneNode; } -SHARED_PTR(Suspension, pSuspension); - -SHARED_PTR(Wheel, pWheel); +SHARED_PTR(Suspension, pSuspension, wSuspension); +SHARED_PTR(Wheel, pWheel, wWheel); class Wheel : public DriveMass { private: @@ -31,9 +30,9 @@ double powered; pSuspension baseSuspension; pPedal brakePedal; - Wheel (WorldObject * container, XmlTag * tag); + Wheel (XmlTag * tag); public: - static pWheel create(WorldObject * container, XmlTag * tag); + static pWheel create(XmlTag * tag); ~Wheel (); void setSusp(pSuspension suspension) { baseSuspension = suspension; }; void setUserDriver (); Modified: trunk/src/world/area.cpp =================================================================== --- trunk/src/world/area.cpp 2006-07-18 17:57:15 UTC (rev 439) +++ trunk/src/world/area.cpp 2006-07-18 23:13:58 UTC (rev 440) @@ -21,13 +21,13 @@ void getMeshInformation (Ogre::MeshPtr mesh, size_t & vertex_count, dVector3 * &vertices, size_t & index_count, unsigned *&indices, const Ogre::Vector3 & position = Ogre::Vector3::ZERO, const Ogre::Quaternion & orient = Ogre::Quaternion::IDENTITY, const Ogre::Vector3 & scale = Ogre::Vector3::UNIT_SCALE); -pArea Area::create (WorldObject * container, std::string areaName) +pArea Area::create (std::string areaName) { - pArea area(new Area(container, areaName)); + pArea area(new Area(areaName)); return area; } -Area::Area (WorldObject * container, std::string areaName) - :WorldObject(container, areaName) +Area::Area (std::string areaName) + :WorldObject(areaName) { setPath(Paths::area(areaName)); setXmlPath(Paths::areaXml(areaName)); @@ -120,7 +120,7 @@ { position = Vector3d (u->getAttribute("position")); rotation = Quaternion (u->getAttribute("rotation")); - pPart tmp = Part::create (this, u->getName()); + pPart tmp = Part::create (u->getName()); tmp->setPosition (position); tmp->setRotation (rotation); parts[tmp->getName()] = tmp; @@ -135,7 +135,7 @@ } if (t->getName() == "camera") { - pCamera tmp = Camera::create (this, t); + pCamera tmp = Camera::create (t); cameras[tmp->getName()] = tmp; } } @@ -172,6 +172,20 @@ dGeomSetPosition (checkpointID, checkpointPosition.x, checkpointPosition.y, checkpointPosition.z); } +void Area::setContainer(pWorldObject container) +{ + WorldObject::setContainer(container); + PartsIt p = parts.begin(); + for(;p != parts.end(); p++) + { + p->second->setContainer(shared_from_this()); + } + CamerasIt i = cameras.begin(); + for(;i != cameras.end(); i++) + { + i->second->setContainer(shared_from_this()); + } +} void Area::setCastShadows(bool castShadows) { planeEntity->setCastShadows(castShadows); Modified: trunk/src/world/area.hpp =================================================================== --- trunk/src/world/area.hpp 2006-07-18 17:57:15 UTC (rev 439) +++ trunk/src/world/area.hpp 2006-07-18 23:13:58 UTC (rev 440) @@ -19,10 +19,10 @@ class SceneNode; }; -SHARED_PTR_MAP(Location, pLocation, Locations, LocationsIt); -SHARED_PTR_MAP(Camera, pCamera, Cameras, CameraIt); -SHARED_PTR_MAP(Part, pPart, Parts, PartsIt); -SHARED_PTR_MAP(Area, pArea, Areas, AreasIt); +SHARED_PTR_MAP(Location, pLocation, Locations, LocationsIt, wLocation); +SHARED_PTR_MAP(Camera, pCamera, Cameras, CameraIt, wCamera); +SHARED_PTR_MAP(Part, pPart, Parts, PartsIt, wPart); +SHARED_PTR_MAP(Area, pArea, Areas, AreasIt, wArea); class Area : public WorldObject { @@ -32,9 +32,10 @@ std::string contact; std::string license; void construct (XmlTag * tag); - Area (WorldObject * container, std::string areaName); + Area (std::string areaName); public: - static pArea create(WorldObject * container, std::string areaName); + static pArea create(std::string areaName); + void setContainer(pWorldObject worldObject); ~Area (); Locations locations; Modified: trunk/src/world/part.cpp =================================================================== --- trunk/src/world/part.cpp 2006-07-18 17:57:15 UTC (rev 439) +++ trunk/src/world/part.cpp 2006-07-18 23:13:58 UTC (rev 440) @@ -19,14 +19,14 @@ #include "SDL/SDL_keysym.h" -pPart Part::create(WorldObject * container, const std::string & name) +pPart Part::create(const std::string & name) { - pPart part(new Part(container, name)); + pPart part(new Part(name)); return part; } -Part::Part (WorldObject * container, const std::string & name) - :WorldObject(container, name) +Part::Part (const std::string & name) + :WorldObject(name) { setPath(Paths::part(name)); setXmlPath(Paths::partXml(name)); Modified: trunk/src/world/part.hpp =================================================================== --- trunk/src/world/part.hpp 2006-07-18 17:57:15 UTC (rev 439) +++ trunk/src/world/part.hpp 2006-07-18 23:13:58 UTC (rev 440) @@ -22,7 +22,7 @@ class SceneNode; } -SHARED_PTR_MAP(Part, pPart, Parts, PartsIt); +SHARED_PTR_MAP(Part, pPart, Parts, PartsIt, wPart); class Part : public WorldObject { @@ -30,9 +30,9 @@ void processXmlRootNode (XERCES_CPP_NAMESPACE::DOMNode * n); void startPhysics (XERCES_CPP_NAMESPACE::DOMNode * n); void startGraphics (XERCES_CPP_NAMESPACE::DOMNode * n); - Part (WorldObject * container, const std::string & name); + Part (const std::string & name); public: - static pPart create (WorldObject * container, const std::string & name); + static pPart create (const std::string & name); ~Part (); void stepPhysics (); }; Modified: trunk/src/world/world.cpp =================================================================== --- trunk/src/world/world.cpp 2006-07-18 17:57:15 UTC (rev 439) +++ trunk/src/world/world.cpp 2006-07-18 23:13:58 UTC (rev 440) @@ -41,6 +41,7 @@ newWorld = "default"; } new World(World::newWorld); + world->setContainer(); } return (world); } @@ -57,7 +58,7 @@ } World::World (std::string name) - :WorldObject(NULL, name) + :WorldObject(name) { if (world) { @@ -150,7 +151,8 @@ // load area (and its cameras) log->loadscreen (LOG_CCREATOR, "Creating a area"); - pArea area = Area::create (this, areaDirectory); + pArea area = Area::create (areaDirectory); + //FIXME shared ptr container set?? //area->setPosition (0.0, 0.0, 0.0); //evo2 maybe... ;) areas[area->getName()] = area; @@ -225,12 +227,13 @@ vehicleStartPosition = t->getAttribute("startPosition"); log->loadscreen (LOG_CCREATOR, "Creating a vehicle"); - pVehicle tmpVehicle = Vehicle::create(this, vehicleDirectory); + pVehicle tmpVehicle = Vehicle::create(vehicleDirectory); if (driver == "user" ) { tmpVehicle->setUserDriver(); } vehicles[tmpVehicle->getName()] = tmpVehicle; + //FIXME setcontainer?? log->__format (LOG_CCREATOR, "Setting vehicle starting relative rotation"); if (areas.begin()->second->locations.count(vehicleStartPosition) == 0) @@ -246,3 +249,19 @@ } } } +void World::setContainer() +{ + //NOTE: world is h... [truncated message content] |
|
From: <st...@us...> - 2006-07-18 17:57:51
|
Revision: 439 Author: stenyak Date: 2006-07-18 10:57:15 -0700 (Tue, 18 Jul 2006) ViewCVS: http://svn.sourceforge.net/motorsport/?rev=439&view=rev Log Message: ----------- Ported most of the world objects to shared pointers. Added the necessary boost include line to makefile. Modified Paths: -------------- trunk/src/common/shared.hpp trunk/src/common/worldObject.cpp trunk/src/common/worldObject.hpp trunk/src/makefile trunk/src/vehicle/body.cpp trunk/src/vehicle/body.hpp trunk/src/vehicle/driveJoint.cpp trunk/src/vehicle/driveJoint.hpp trunk/src/vehicle/engine.cpp trunk/src/vehicle/engine.hpp trunk/src/vehicle/finalDrive.cpp trunk/src/vehicle/finalDrive.hpp trunk/src/vehicle/gearbox.cpp trunk/src/vehicle/gearbox.hpp trunk/src/vehicle/pedal.cpp trunk/src/vehicle/pedal.hpp trunk/src/vehicle/suspension.cpp trunk/src/vehicle/suspension.hpp trunk/src/vehicle/vehicle.cpp trunk/src/vehicle/vehicle.hpp trunk/src/vehicle/wheel.cpp trunk/src/vehicle/wheel.hpp Modified: trunk/src/common/shared.hpp =================================================================== --- trunk/src/common/shared.hpp 2006-07-06 12:38:22 UTC (rev 438) +++ trunk/src/common/shared.hpp 2006-07-18 17:57:15 UTC (rev 439) @@ -11,6 +11,7 @@ #define SHARED_HPP #include <map> #include <boost/shared_ptr.hpp> +#include <boost/enable_shared_from_this.hpp> #include <string> // Shared pointer Modified: trunk/src/common/worldObject.cpp =================================================================== --- trunk/src/common/worldObject.cpp 2006-07-06 12:38:22 UTC (rev 438) +++ trunk/src/common/worldObject.cpp 2006-07-18 17:57:15 UTC (rev 439) @@ -12,7 +12,7 @@ #include "vector3d.hpp" unsigned int WorldObject::instancesCount = 0; -WorldObjects WorldObject::worldObjects; +WorldObjectsC WorldObject::worldObjects; WorldObject::WorldObject (WorldObject * container, const std::string & name) { @@ -51,7 +51,7 @@ void WorldObject::logAll() { pLogEngine log (LogEngine::create(LOG_DEVELOPER, "WorldObjects")); - WorldObjectsIt i = worldObjects.begin(); + WorldObjectsCIt i = worldObjects.begin(); for(;i != worldObjects.end(); i++) { if (i->second != NULL) Modified: trunk/src/common/worldObject.hpp =================================================================== --- trunk/src/common/worldObject.hpp 2006-07-06 12:38:22 UTC (rev 438) +++ trunk/src/common/worldObject.hpp 2006-07-18 17:57:15 UTC (rev 439) @@ -20,16 +20,16 @@ class Vector3d; SHARED_PTR_MAP(OgreObject, pOgreObject, OgreObjects, OgreObjectsIt); SHARED_PTR_MAP(OdeObject, pOdeObject, OdeObjects, OdeObjectsIt); -class WorldObject; -typedef std::map <std::string, WorldObject *> WorldObjects; -typedef std::map <std::string, WorldObject *>::iterator WorldObjectsIt; +SHARED_PTR_MAP(WorldObject, pWorldObject, WorldObjects, WorldObjectsIt); +typedef std::map <std::string, WorldObject *> WorldObjectsC; +typedef std::map <std::string, WorldObject *>::iterator WorldObjectsCIt; class WorldObject { private: virtual void hack(){}; static unsigned int instancesCount; - static WorldObjects worldObjects; + static WorldObjectsC worldObjects; std::string id; std::string name; std::string path; @@ -40,8 +40,8 @@ WorldObject * container; OgreObjects ogreObjects; OdeObjects odeObjects; + WorldObject (WorldObject * container, const std::string & name); public: - WorldObject (WorldObject * container, const std::string & name); virtual ~WorldObject (); WorldObject * getContainer(); std::string getId(); Modified: trunk/src/makefile =================================================================== --- trunk/src/makefile 2006-07-06 12:38:22 UTC (rev 438) +++ trunk/src/makefile 2006-07-18 17:57:15 UTC (rev 439) @@ -141,6 +141,7 @@ $(BASE_INCLUDE_DIR)/SDL \ $(BASE_INCLUDE_DIR)/OGRE \ $(BASE_INCLUDE_DIR)/xercesc \ + $(BASE_INCLUDE_DIR)/boost \ $(BASE_INCLUDE_DIR)/../local/include/ode \ $(BASE_INCLUDE_DIR)/freetype2 \ $(BASE_INCLUDE_DIR)/SDL \ Modified: trunk/src/vehicle/body.cpp =================================================================== --- trunk/src/vehicle/body.cpp 2006-07-06 12:38:22 UTC (rev 438) +++ trunk/src/vehicle/body.cpp 2006-07-18 17:57:15 UTC (rev 439) @@ -18,6 +18,11 @@ #include "SDL/SDL_keysym.h" #include "vehicle.hpp" +pBody Body::create (WorldObject * container, XmlTag * tag) +{ + pBody tmp (new Body(container, tag)); + return tmp; +} Body::Body (WorldObject * container, XmlTag * tag) :WorldObject(container, "body") { @@ -74,7 +79,7 @@ void Body::stepPhysics () { dBodyID bodyID = getMainOdeObject()->getBodyID(); - if (this == World::get()->vehicles.begin()->second->getObject("body")) + if (this == World::get()->vehicles.begin()->second->getObject("body").get()) { double moveZ = System::get()->axisMap[getIDKeyboardKey(SDLK_BACKSPACE)]->getValue() * 50000; moveZ += System::get()->axisMap[getIDKeyboardKey(SDLK_RETURN)]->getValue() * 12200; Modified: trunk/src/vehicle/body.hpp =================================================================== --- trunk/src/vehicle/body.hpp 2006-07-06 12:38:22 UTC (rev 438) +++ trunk/src/vehicle/body.hpp 2006-07-18 17:57:15 UTC (rev 439) @@ -13,14 +13,13 @@ #include "vector3d.hpp" #include "paths.hpp" -//forward declarations -namespace Ogre { - class Entity; - class SceneNode; -} +// Forward declarations +namespace Ogre { class Entity; class SceneNode; } class Quaternion; class Vehicle; +SHARED_PTR(Body, pBody); + class Body : public WorldObject { private: @@ -28,8 +27,9 @@ double frontalArea; void stopPhysics (); void stopGraphics (); + Body (WorldObject * container, XmlTag * tag); public: - Body (WorldObject * container, XmlTag * tag); + static pBody create (WorldObject * container, XmlTag * tag); ~Body (); void stepPhysics (); }; Modified: trunk/src/vehicle/driveJoint.cpp =================================================================== --- trunk/src/vehicle/driveJoint.cpp 2006-07-06 12:38:22 UTC (rev 438) +++ trunk/src/vehicle/driveJoint.cpp 2006-07-18 17:57:15 UTC (rev 439) @@ -20,6 +20,18 @@ DriveJoint::~DriveJoint () { } +pClutch Clutch::create (WorldObject * container, XmlTag * tag) +{ + pClutch tmp(new Clutch(container, tag)); + return tmp; +} + +pClutch Clutch::create (WorldObject * container) +{ + pClutch tmp(new Clutch(container)); + return tmp; +} + Clutch::Clutch (WorldObject * container, XmlTag * tag) :DriveJoint(container, "clutch") { @@ -49,12 +61,22 @@ { } -void Clutch::setClutchPedal(Pedal * pedal) +void Clutch::setClutchPedal(pPedal pedal) { clutchPedal = pedal; } +pGear Gear::create (WorldObject * container, XmlTag * tag) +{ + pGear tmp (new Gear(container, tag)); + return tmp; +} +pGear Gear::create (WorldObject * container) +{ + pGear tmp (new Gear(container)); + return tmp; +} Gear::Gear (WorldObject * container, XmlTag * tag) :DriveJoint(container, "gear") @@ -92,6 +114,16 @@ { } +pLSD LSD::create (WorldObject * container, XmlTag * tag) +{ + pLSD tmp (new LSD(container, tag)); + return tmp; +} +pLSD LSD::create (WorldObject * container) +{ + pLSD tmp (new LSD(container)); + return tmp; +} LSD::LSD (WorldObject * container, XmlTag * tag) :DriveJoint(container, "lsd") { @@ -126,7 +158,6 @@ prevOutputsRelAngle = 0.0; outputsRelAngularVel = 0.0; prevOutputsRelAngularVel = 0.0; - } LSD::~LSD () Modified: trunk/src/vehicle/driveJoint.hpp =================================================================== --- trunk/src/vehicle/driveJoint.hpp 2006-07-06 12:38:22 UTC (rev 438) +++ trunk/src/vehicle/driveJoint.hpp 2006-07-18 17:57:15 UTC (rev 439) @@ -12,9 +12,11 @@ #include "driveMass.hpp" #include "worldObject.hpp" -class DriveMass; -class Pedal; +// Forward declarations +SHARED_PTR(Pedal, pPedal); +SHARED_PTR(DriveMass, pDriveMass); +SHARED_PTR(DriveJoint, pDriveJoint); class DriveJoint : public WorldObject { protected: @@ -27,8 +29,8 @@ double prevRelAngle; double relAngularVel; double prevRelAngularVel; - DriveMass *inputDrive; - DriveMass *outputDrive; + pDriveMass inputDrive; + pDriveMass outputDrive; bool enabled; public: DriveJoint (WorldObject * container, std::string name); @@ -39,27 +41,31 @@ double getOutputTorque () { return outputTorqueTransfer; } ; double getInputTorque () { return inputTorqueTransfer; } ; double getRelAngle () { return relAngle; } ; - void setOutputPointer (DriveMass *output) { outputDrive = output; } ; - void setInputPointer (DriveMass *input) { inputDrive = input; } ; + void setOutputPointer (pDriveMass output) { outputDrive = output; } ; + void setInputPointer (pDriveMass input) { inputDrive = input; } ; }; +SHARED_PTR(Clutch, pClutch); class Clutch : public DriveJoint { private: - Pedal * clutchPedal; + pPedal clutchPedal; double coeffStaticFriction; double coeffDynamicFriction; double maxTorqueTransfer; double lockedParam; bool locked; - public: Clutch (WorldObject * container, XmlTag * tag); Clutch (WorldObject * container); + public: + static pClutch create (WorldObject * container, XmlTag * tag); + static pClutch create (WorldObject * container); ~Clutch (); - void setClutchPedal(Pedal * pedal); + void setClutchPedal(pPedal pedal); void stepPhysics (); }; +SHARED_PTR(Gear, pGear); class Gear : public DriveJoint { private: @@ -67,18 +73,21 @@ double springConstant; double dampConstant; void startPhysics (XmlTag * tag); - public: Gear (WorldObject * container, XmlTag * tag); Gear (WorldObject * container); + public: + static pGear create (WorldObject * container, XmlTag * tag); + static pGear create (WorldObject * container); ~Gear (); void processXmlRootNode (XmlTag * tag); void stepPhysics (); }; +SHARED_PTR(LSD, pLSD); class LSD : public DriveJoint { private: - DriveMass *outputDrive2; + pDriveMass outputDrive2; double outputsRelAngle; double prevOutputsRelAngle; double outputsRelAngularVel; @@ -88,12 +97,14 @@ double dampConstant; double limitedSlipClutchFriction; void startPhysics (XmlTag * tag); - public: LSD (WorldObject * container, XmlTag * tag); LSD (WorldObject * container); + public: + static pLSD create (WorldObject * container, XmlTag * tag); + static pLSD create (WorldObject * container); ~LSD (); void processXmlRootNode (XmlTag * tag); - void setOutputPointer2 (DriveMass *output) { outputDrive2 = output; } ; + void setOutputPointer2 (pDriveMass output) { outputDrive2 = output; } ; void stepPhysics (); }; Modified: trunk/src/vehicle/engine.cpp =================================================================== --- trunk/src/vehicle/engine.cpp 2006-07-06 12:38:22 UTC (rev 438) +++ trunk/src/vehicle/engine.cpp 2006-07-18 17:57:15 UTC (rev 439) @@ -13,9 +13,12 @@ #include "SDL/SDL_keysym.h" #include "pedal.hpp" +pEngine Engine::create(WorldObject * container, XmlTag * tag) +{ + pEngine tmp(new Engine(container, tag)); + return tmp; +} -class Pedal; - Engine::Engine (WorldObject * container, XmlTag * tag) :DriveMass(container, "engine") { @@ -40,7 +43,7 @@ } -void Engine::setGasPedal (Pedal * pedal) +void Engine::setGasPedal (pPedal pedal) { gasPedal = pedal; } Modified: trunk/src/vehicle/engine.hpp =================================================================== --- trunk/src/vehicle/engine.hpp 2006-07-06 12:38:22 UTC (rev 438) +++ trunk/src/vehicle/engine.hpp 2006-07-18 17:57:15 UTC (rev 439) @@ -12,19 +12,22 @@ #include "driveMass.hpp" #include "driveJoint.hpp" -class Pedal; +// Forward declarations +SHARED_PTR(Pedal, pPedal); +SHARED_PTR(Engine, pEngine); class Engine : public DriveMass { private: double torqueLinearMultiplier; double telemetryTorque; double angularVelLimit; - Pedal * gasPedal; + pPedal gasPedal; + Engine (WorldObject * container, XmlTag * tag); public: - Engine (WorldObject * container, XmlTag * tag); + static pEngine create (WorldObject * container, XmlTag * tag); ~Engine (); - void setGasPedal (Pedal * pedal); + void setGasPedal (pPedal pedal); void stepPhysics (); double getOutputTorque(); }; Modified: trunk/src/vehicle/finalDrive.cpp =================================================================== --- trunk/src/vehicle/finalDrive.cpp 2006-07-06 12:38:22 UTC (rev 438) +++ trunk/src/vehicle/finalDrive.cpp 2006-07-18 17:57:15 UTC (rev 439) @@ -13,6 +13,12 @@ #include "ode/ode.h" #include "SDL/SDL_keysym.h" +pFinalDrive FinalDrive::create(WorldObject * container, XmlTag * tag) +{ + pFinalDrive tmp(new FinalDrive(container, tag)); + return tmp; +} + FinalDrive::FinalDrive (WorldObject * container, XmlTag * tag) :DriveMass(container, "finalDrive") { Modified: trunk/src/vehicle/finalDrive.hpp =================================================================== --- trunk/src/vehicle/finalDrive.hpp 2006-07-06 12:38:22 UTC (rev 438) +++ trunk/src/vehicle/finalDrive.hpp 2006-07-18 17:57:15 UTC (rev 439) @@ -11,13 +11,15 @@ #define FINALDRIVE_HPP #include "driveMass.hpp" +SHARED_PTR(FinalDrive, pFinalDrive); class FinalDrive : public DriveMass { private: double finalDriveRatio; DriveJoint *outputJoint2; + FinalDrive (WorldObject * container, XmlTag * tag); public: - FinalDrive (WorldObject * container, XmlTag * tag); + static pFinalDrive create (WorldObject * container, XmlTag * tag); ~FinalDrive (); void stepPhysics (); }; Modified: trunk/src/vehicle/gearbox.cpp =================================================================== --- trunk/src/vehicle/gearbox.cpp 2006-07-06 12:38:22 UTC (rev 438) +++ trunk/src/vehicle/gearbox.cpp 2006-07-18 17:57:15 UTC (rev 439) @@ -12,6 +12,12 @@ #include "system.hpp" #include "SDL/SDL_keysym.h" +pGearbox Gearbox::create(WorldObject * container, XmlTag * tag) +{ + pGearbox tmp(new Gearbox(container, tag)); + return tmp; +} + Gearbox::Gearbox (WorldObject * container, XmlTag * tag) :DriveMass(container, "gearbox") { Modified: trunk/src/vehicle/gearbox.hpp =================================================================== --- trunk/src/vehicle/gearbox.hpp 2006-07-06 12:38:22 UTC (rev 438) +++ trunk/src/vehicle/gearbox.hpp 2006-07-18 17:57:15 UTC (rev 439) @@ -12,6 +12,7 @@ #include "driveMass.hpp" #include "wheel.hpp" +SHARED_PTR(GearboxGear, pGearboxgear); class GearboxGear : public WorldObject { public: @@ -24,14 +25,16 @@ double getRatio() { return ratio; } ; bool isEnabled() { return enabled; } ; }; +SHARED_PTR(Gearbox, pGearbox); class Gearbox : public DriveMass { private: std::map < int, GearboxGear *> gearMap; int currentGear; double gearRatio; + Gearbox (WorldObject * container, XmlTag * tag); public: - Gearbox (WorldObject * container, XmlTag * tag); + static pGearbox create(WorldObject * container, XmlTag * tag); ~Gearbox (); void setGear (int inputGear) { currentGear = inputGear; }; double getGearRatio() { return gearMap[currentGear]->ratio; }; Modified: trunk/src/vehicle/pedal.cpp =================================================================== --- trunk/src/vehicle/pedal.cpp 2006-07-06 12:38:22 UTC (rev 438) +++ trunk/src/vehicle/pedal.cpp 2006-07-18 17:57:15 UTC (rev 439) @@ -13,6 +13,12 @@ #include "system.hpp" #include "SDL/SDL_keysym.h" +pPedal Pedal::create(WorldObject * container, XmlTag * tag) +{ + pPedal tmp(new Pedal(container, tag)); + return tmp; +} + Pedal::Pedal (WorldObject * container, XmlTag * tag) :WorldObject(container, "pedal") { Modified: trunk/src/vehicle/pedal.hpp =================================================================== --- trunk/src/vehicle/pedal.hpp 2006-07-06 12:38:22 UTC (rev 438) +++ trunk/src/vehicle/pedal.hpp 2006-07-18 17:57:15 UTC (rev 439) @@ -11,14 +11,16 @@ #define PEDAL_HPP #include "worldObject.hpp" +SHARED_PTR(Pedal, pPedal); class Pedal : public WorldObject { private: bool userDriver; double angleRange; double currentAngle; + Pedal (WorldObject * container, XmlTag * tag); public: - Pedal (WorldObject * container, XmlTag * tag); + static pPedal create(WorldObject * container, XmlTag * tag); ~Pedal (); void setUserDriver (); void stepPhysics (); Modified: trunk/src/vehicle/suspension.cpp =================================================================== --- trunk/src/vehicle/suspension.cpp 2006-07-06 12:38:22 UTC (rev 438) +++ trunk/src/vehicle/suspension.cpp 2006-07-18 17:57:15 UTC (rev 439) @@ -22,7 +22,7 @@ #include <cmath> Suspension::Suspension (WorldObject * container, std::string name) - :WorldObject(container, name) + : WorldObject(container, name) { position = Vector3d (0, 0, 0); rotation = Quaternion (1, 0, 0, 0); @@ -133,6 +133,11 @@ dJointSetHinge2Param(jointID, dParamVel, 0); } +pUnidimensional Unidimensional::create (WorldObject * container, XmlTag * tag) +{ + pUnidimensional tmp(new Unidimensional(container, tag)); + return tmp; +} Unidimensional::Unidimensional (WorldObject * container, XmlTag * tag) :Suspension(container, "suspension.unidimensional") { @@ -170,12 +175,17 @@ { dJointDestroy (jointID); } -void Unidimensional::attach(WorldObject * base, WorldObject * object) +void Unidimensional::attach(pWorldObject base, pWorldObject object) { - Wheel * wheel = dynamic_cast<Wheel*>(object); + //FIXME: remove all unnecessary comments + //Wheel * wheel = dynamic_cast<Wheel*>(object); + pWheel wheel = boost::dynamic_pointer_cast<Wheel>(object); + //pWheel wheel ( boost::dynamic_pointer_cast<pWheel>(object) ); + //pWheel wheel = boost::dynamic_pointer_cast<pWheel>(object); if (wheel == NULL) log->__format(LOG_ERROR, "Trying to attach a non-wheel object to the suspension!"); if (base->getMainOdeObject() == NULL) log->__format(LOG_ERROR, "Trying to attach a wheel object to an object with no physics!"); - wheel->setSusp(this); + wheel->setSusp(shared_from_this()); + //wheel->setSusp(this); dJointAttach (jointID, base->getMainOdeObject()->getBodyID(), object->getMainOdeObject()->getBodyID()); // finite rotation on wheels helps avoid explosions, FIXME prolly needs to be relative to suspension axis, and updated every frame @@ -197,8 +207,12 @@ } +pFixed Fixed::create(WorldObject * container, XmlTag * tag) +{ + pFixed tmp(new Fixed(container, tag)); + return tmp; +} - Fixed::Fixed (WorldObject * container, XmlTag * tag) :Suspension(container, "suspension.unidimensional") { @@ -220,12 +234,13 @@ { dJointDestroy (jointID); } -void Fixed::attach(WorldObject * base, WorldObject * object) +void Fixed::attach(pWorldObject base, pWorldObject object) { - Wheel * wheel = dynamic_cast<Wheel*>(object); + //Wheel * wheel = dynamic_cast<Wheel*>(object.get()); + pWheel wheel = boost::dynamic_pointer_cast<Wheel>(object); if (wheel == NULL) log->__format(LOG_ERROR, "Trying to attach a non-wheel object to the suspension!"); if (base->getMainOdeObject() == NULL) log->__format(LOG_ERROR, "Trying to attach a wheel object to an object with no physics!"); - wheel->setSusp(this); + wheel->setSusp(shared_from_this()); dJointAttach (jointID, base->getMainOdeObject()->getBodyID(), object->getMainOdeObject()->getBodyID()); // finite rotation on wheels helps avoid explosions, FIXME prolly needs to be relative to suspension axis @@ -255,6 +270,12 @@ dJointSetHingeParam(jointID, dParamVel, 0); } +pDoubleWishbone DoubleWishbone::create(WorldObject * container, XmlTag * tag) +{ + pDoubleWishbone tmp(new DoubleWishbone(container, tag)); + return tmp; +} + DoubleWishbone::DoubleWishbone(WorldObject * container, XmlTag * tag) :Suspension(container, "suspension.doublewishbone") { @@ -365,12 +386,13 @@ //empty } -void DoubleWishbone::attach(WorldObject * base, WorldObject * object) +void DoubleWishbone::attach(pWorldObject base, pWorldObject object) { - Wheel * wheel = dynamic_cast<Wheel*>(object); + //Wheel * wheel = dynamic_cast<Wheel*>(object.get()); + pWheel wheel = boost::dynamic_pointer_cast<Wheel>(object); if (wheel == NULL) log->__format(LOG_ERROR, "Trying to attach a non-wheel object to the suspension!"); if (base->getMainOdeObject() == NULL) log->__format(LOG_ERROR, "Trying to attach a wheel object to an object with no physics!"); - wheel->setSusp(this); + wheel->setSusp(shared_from_this()); double dirMult = 1.0; if (!right) dirMult *= -1; Modified: trunk/src/vehicle/suspension.hpp =================================================================== --- trunk/src/vehicle/suspension.hpp 2006-07-06 12:38:22 UTC (rev 438) +++ trunk/src/vehicle/suspension.hpp 2006-07-18 17:57:15 UTC (rev 439) @@ -24,7 +24,7 @@ class SceneNode; } -class Suspension : public WorldObject +class Suspension : public boost::enable_shared_from_this <Suspension> , public WorldObject { protected: Suspension (WorldObject * container, std::string name); @@ -43,9 +43,10 @@ virtual double getRate()=0; virtual Vector3d getAxis()=0; virtual void setVelocity(double velocity)=0; - virtual void attach(WorldObject * base, WorldObject * object)=0; + virtual void attach(pWorldObject base, pWorldObject object)=0; }; +SHARED_PTR(Unidimensional, pUnidimensional); class Unidimensional : public Suspension { protected: @@ -54,30 +55,35 @@ double dampingConstant; double maxSteeringAngle; double getSteeringAngle(); + Unidimensional (WorldObject * container, XmlTag * tag); public: - Unidimensional (WorldObject * container, XmlTag * tag); + static pUnidimensional create(WorldObject * container, XmlTag * tag); ~Unidimensional(); void stepPhysics(); double getRate(); Vector3d getAxis(); void setVelocity(double velocity); - void attach(WorldObject * base, WorldObject * object); + void attach(pWorldObject base, pWorldObject object); }; + +SHARED_PTR(Fixed, pFixed); class Fixed : public Suspension { protected: dJointID jointID; + Fixed (WorldObject * container, XmlTag * tag); public: - Fixed (WorldObject * container, XmlTag * tag); + static pFixed create(WorldObject * container, XmlTag * tag); ~Fixed(); void stepPhysics(); double getRate(); Vector3d getAxis(); void setVelocity(double velocity); - void attach(WorldObject * base, WorldObject * object); + void attach(pWorldObject base, pWorldObject object); }; +SHARED_PTR(DoubleWishbone, pDoubleWishbone); class DoubleWishbone : public Suspension { protected: @@ -106,14 +112,16 @@ Vector3d getFirstLinkPosition (){return firstPosition;}; Quaternion getFirstLinkRotation (){return firstRotation;}; + DoubleWishbone (WorldObject * container, XmlTag * tag); public: - DoubleWishbone (WorldObject * container, XmlTag * tag); + static pDoubleWishbone create(WorldObject * container, XmlTag * tag); ~DoubleWishbone(); + void stepPhysics(); double getRate(); Vector3d getAxis(); void setVelocity(double velocity); - void attach(WorldObject * base, WorldObject * object); + void attach(pWorldObject base, pWorldObject object); }; #endif Modified: trunk/src/vehicle/vehicle.cpp =================================================================== --- trunk/src/vehicle/vehicle.cpp 2006-07-06 12:38:22 UTC (rev 438) +++ trunk/src/vehicle/vehicle.cpp 2006-07-18 17:57:15 UTC (rev 439) @@ -67,11 +67,11 @@ for (WorldObjectsIt i = components.begin(); i != components.end(); i++) { Pedal * tmpPedal; - if ( (tmpPedal = dynamic_cast<Pedal*>(i->second)) != 0) tmpPedal->setUserDriver(); + if ( (tmpPedal = dynamic_cast<Pedal*>(i->second.get())) != 0) tmpPedal->setUserDriver(); Wheel * tmpWheel; - if ( (tmpWheel = dynamic_cast<Wheel*>(i->second)) != 0) tmpWheel->setUserDriver(); + if ( (tmpWheel = dynamic_cast<Wheel*>(i->second.get())) != 0) tmpWheel->setUserDriver(); Suspension * tmpSusp; - if ( (tmpSusp = dynamic_cast<Suspension*>(i->second)) != 0) tmpSusp->setUserDriver(); + if ( (tmpSusp = dynamic_cast<Suspension*>(i->second.get())) != 0) tmpSusp->setUserDriver(); } } @@ -85,41 +85,41 @@ contact = tag->getAttribute("contact"); license = tag->getAttribute("license"); - components["rearDiff"] = new LSD (this); - components["transfer"] = new Gear(this); + components["rearDiff"] = LSD::create(this); + components["transfer"] = Gear::create(this); XmlTag * t = tag->getTag(0); for (int i = 0; i < tag->nTags(); t = tag->getTag(++i)) { - if (t->getName() == "body") components["body"] = new Body (this, t); - if (t->getName() == "engine") components["engine"] = new Engine (this, t); - if (t->getName() == "clutch") components["clutch"] = new Clutch (this, t); - if (t->getName() == "gearbox") components["gearbox"] = new Gearbox (this, t); - if (t->getName() == "finalDrive") components["finalDrive"] = new FinalDrive (this, t); + if (t->getName() == "body") components["body"] = Body::create (this, t); + if (t->getName() == "engine") components["engine"] = Engine::create (this, t); + if (t->getName() == "clutch") components["clutch"] = Clutch::create (this, t); + if (t->getName() == "gearbox") components["gearbox"] = Gearbox::create (this, t); + if (t->getName() == "finalDrive") components["finalDrive"] = FinalDrive::create (this, t); if (t->getName() == "pedal") { - Pedal * tmp = new Pedal (this, t); + pPedal tmp = Pedal::create (this, t); components[tmp->getName()] = tmp; } if (t->getName() == "wheel") { - Wheel * tmp = new Wheel (this, t); + pWheel tmp = Wheel::create (this, t); components[tmp->getName()] = tmp; System::get()->ogreWindow->update (); } if (t->getName() == "suspension.unidimensional") { - Unidimensional * tmp = new Unidimensional (this, t); + pUnidimensional tmp = Unidimensional::create (this, t); components[tmp->getName()] = tmp; System::get()->ogreWindow->update (); } if (t->getName() == "suspension.fixed") { - Fixed * tmp = new Fixed (this, t); + pFixed tmp = Fixed::create (this, t); components[tmp->getName()] = tmp; System::get()->ogreWindow->update (); } if (t->getName() == "suspension.doublewishbone") { - DoubleWishbone * tmp = new DoubleWishbone (this, t); + pDoubleWishbone tmp = DoubleWishbone::create (this, t); components[tmp->getName()] = tmp; System::get()->ogreWindow->update (); } @@ -153,7 +153,7 @@ for (WorldObjectsIt i = components.begin(); i != components.end(); i++) { Wheel * tmpWheel; - if ( (tmpWheel = dynamic_cast<Wheel*>(i->second)) != 0) + if ( (tmpWheel = dynamic_cast<Wheel*>(i->second.get())) != 0) { tmpWheel->setBrakePedal(getPedal("brakePedal")); } @@ -178,11 +178,11 @@ for (WorldObjectsIt i = components.begin(); i != components.end(); i++) { DoubleWishbone * tmpSusp; - if ( (tmpSusp = dynamic_cast<DoubleWishbone*>(i->second)) != 0) tmpSusp->stepGraphics(); + if ( (tmpSusp = dynamic_cast<DoubleWishbone*>(i->second.get())) != 0) tmpSusp->stepGraphics(); Wheel * tmpWheel; - if ( (tmpWheel = dynamic_cast<Wheel*>(i->second)) != 0) tmpWheel->stepGraphics(); + if ( (tmpWheel = dynamic_cast<Wheel*>(i->second.get())) != 0) tmpWheel->stepGraphics(); Body * tmpBody; - if ( (tmpBody = dynamic_cast<Body*>(i->second)) != 0) tmpBody->stepGraphics(); + if ( (tmpBody = dynamic_cast<Body*>(i->second.get())) != 0) tmpBody->stepGraphics(); } } @@ -199,10 +199,10 @@ for (WorldObjectsIt i = components.begin(); i != components.end(); i++) { Wheel * tmpWheel; - if ( (tmpWheel = dynamic_cast<Wheel*>(i->second)) != 0) + if ( (tmpWheel = dynamic_cast<Wheel*>(i->second.get())) != 0) tmpWheel->getMainOdeObject()->setPosition ( tmpWheel->getMainOdeObject()->getPosition() + posDiff ); Suspension * tmpSusp; - if ( (tmpSusp = dynamic_cast<Suspension*>(i->second)) != 0) + if ( (tmpSusp = dynamic_cast<Suspension*>(i->second.get())) != 0) tmpSusp->setPosition ( tmpSusp->getPosition() + posDiff ); } } @@ -218,10 +218,10 @@ for (WorldObjectsIt i = components.begin(); i != components.end(); i++) { Wheel * tmpWheel; - if ( (tmpWheel = dynamic_cast<Wheel*>(i->second)) != 0) + if ( (tmpWheel = dynamic_cast<Wheel*>(i->second.get())) != 0) tmpWheel->applyRotation (rotation); Suspension * tmpSusp; - if ( (tmpSusp = dynamic_cast<Suspension*>(i->second)) != 0) + if ( (tmpSusp = dynamic_cast<Suspension*>(i->second.get())) != 0) tmpSusp->applyRotation (rotation); } // apply rotation to body @@ -258,7 +258,7 @@ for (WorldObjectsIt i = components.begin(); i != components.end(); i++) { Pedal * tmpPedal; - if ( (tmpPedal = dynamic_cast<Pedal*>(i->second)) != 0) + if ( (tmpPedal = dynamic_cast<Pedal*>(i->second.get())) != 0) { tmpPedal->stepPhysics(); } @@ -290,9 +290,9 @@ for (WorldObjectsIt i = components.begin(); i != components.end(); i++) { Suspension * tmpSusp; - if ( (tmpSusp = dynamic_cast<Suspension*>(i->second)) != 0) tmpSusp->stepPhysics(); + if ( (tmpSusp = dynamic_cast<Suspension*>(i->second.get())) != 0) tmpSusp->stepPhysics(); Wheel * tmpWheel; - if ( (tmpWheel = dynamic_cast<Wheel*>(i->second)) != 0) tmpWheel->stepPhysics(); + if ( (tmpWheel = dynamic_cast<Wheel*>(i->second.get())) != 0) tmpWheel->stepPhysics(); } // print telemetry data @@ -306,87 +306,88 @@ } } -Body * Vehicle::getBody (std::string name) +pBody Vehicle::getBody (std::string name) { - Body * tmp = dynamic_cast<Body*>(components[name]); - if (tmp == NULL) log->__format(LOG_ERROR, "Tried to access non-existent world object \"%s\" using type \"%s\"", name.c_str(), "Body"); - return tmp; + pBody tmp = boost::dynamic_pointer_cast<Body>(components[name]); + if (tmp == NULL) log->__format(LOG_ERROR, "Tried to access non-existent world object \"%s\" using type \"%s\"", name.c_str(), "Body"); + return (tmp); + //return (components[name]); } -DriveMass * Vehicle::getDriveMass (std::string name) +pDriveMass Vehicle::getDriveMass (std::string name) { - DriveMass * tmp = dynamic_cast<DriveMass*>(components[name]); - if (tmp == NULL) log->__format(LOG_ERROR, "Tried to access non-existent world object \"%s\" using type \"%s\"", name.c_str(), "DriveMass"); - return tmp; + pDriveMass tmp = boost::dynamic_pointer_cast<DriveMass>(components[name]); + if (tmp == NULL) log->__format(LOG_ERROR, "Tried to access non-existent world object \"%s\" using type \"%s\"", name.c_str(), "DriveMass"); + return (tmp); } -DriveJoint * Vehicle::getDriveJoint (std::string name) +pDriveJoint Vehicle::getDriveJoint (std::string name) { - DriveJoint * tmp = dynamic_cast<DriveJoint*>(components[name]); - if (tmp == NULL) log->__format(LOG_ERROR, "Tried to access non-existent world object \"%s\" using type \"%s\"", name.c_str(), "DriveJoint"); - return tmp; + pDriveJoint tmp = boost::dynamic_pointer_cast<DriveJoint>(components[name]); + if (tmp == NULL) log->__format(LOG_ERROR, "Tried to access non-existent world object \"%s\" using type \"%s\"", name.c_str(), "DriveJoint"); + return (tmp); } -Clutch * Vehicle::getClutch (std::string name) +pClutch Vehicle::getClutch (std::string name) { - Clutch * tmp = dynamic_cast<Clutch*>(components[name]); - if (tmp == NULL) log->__format(LOG_ERROR, "Tried to access non-existent world object \"%s\" using type \"%s\"", name.c_str(), "Clutch"); - return tmp; + pClutch tmp = boost::dynamic_pointer_cast<Clutch>(components[name]); + if (tmp == NULL) log->__format(LOG_ERROR, "Tried to access non-existent world object \"%s\" using type \"%s\"", name.c_str(), "Clutch"); + return (tmp); } -Gear * Vehicle::getGear (std::string name) +pGear Vehicle::getGear (std::string name) { - Gear * tmp = dynamic_cast<Gear*>(components[name]); - if (tmp == NULL) log->__format(LOG_ERROR, "Tried to access non-existent world object \"%s\" using type \"%s\"", name.c_str(), "Gear"); - return tmp; + pGear tmp = boost::dynamic_pointer_cast<Gear>(components[name]); + if (tmp == NULL) log->__format(LOG_ERROR, "Tried to access non-existent world object \"%s\" using type \"%s\"", name.c_str(), "Gear"); + return (tmp); } -LSD * Vehicle::getLSD (std::string name) +pLSD Vehicle::getLSD (std::string name) { - LSD * tmp = dynamic_cast<LSD*>(components[name]); - if (tmp == NULL) log->__format(LOG_ERROR, "Tried to access non-existent world object \"%s\" using type \"%s\"", name.c_str(), "LSD"); - return tmp; + pLSD tmp = boost::dynamic_pointer_cast<LSD>(components[name]); + if (tmp == NULL) log->__format(LOG_ERROR, "Tried to access non-existent world object \"%s\" using type \"%s\"", name.c_str(), "LSD"); + return (tmp); } -Engine * Vehicle::getEngine (std::string name) +pEngine Vehicle::getEngine (std::string name) { - Engine * tmp = dynamic_cast<Engine*>(components[name]); - if (tmp == NULL) log->__format(LOG_ERROR, "Tried to access non-existent world object \"%s\" using type \"%s\"", name.c_str(), "Engine"); - return tmp; + pEngine tmp = boost::dynamic_pointer_cast<Engine>(components[name]); + if (tmp == NULL) log->__format(LOG_ERROR, "Tried to access non-existent world object \"%s\" using type \"%s\"", name.c_str(), "Engine"); + return (tmp); } -FinalDrive * Vehicle::getFinalDrive (std::string name) +pFinalDrive Vehicle::getFinalDrive (std::string name) { - FinalDrive * tmp = dynamic_cast<FinalDrive*>(components[name]); - if (tmp == NULL) log->__format(LOG_ERROR, "Tried to access non-existent world object \"%s\" using type \"%s\"", name.c_str(), "FinalDrive"); - return tmp; + pFinalDrive tmp = boost::dynamic_pointer_cast<FinalDrive>(components[name]); + if (tmp == NULL) log->__format(LOG_ERROR, "Tried to access non-existent world object \"%s\" using type \"%s\"", name.c_str(), "FinalDrive"); + return (tmp); } -Gearbox * Vehicle::getGearbox (std::string name) +pGearbox Vehicle::getGearbox (std::string name) { - Gearbox * tmp = dynamic_cast<Gearbox*>(components[name]); - if (tmp == NULL) log->__format(LOG_ERROR, "Tried to access non-existent world object \"%s\" using type \"%s\"", name.c_str(), "Gearbox"); - return tmp; + pGearbox tmp = boost::dynamic_pointer_cast<Gearbox>(components[name]); + if (tmp == NULL) log->__format(LOG_ERROR, "Tried to access non-existent world object \"%s\" using type \"%s\"", name.c_str(), "Gearbox"); + return (tmp); } -GearboxGear * Vehicle::getGearboxGear (std::string name) +pGearboxGear Vehicle::getGearboxGear (std::string name) { - GearboxGear * tmp = dynamic_cast<GearboxGear*>(components[name]); - if (tmp == NULL) log->__format(LOG_ERROR, "Tried to access non-existent world object \"%s\" using type \"%s\"", name.c_str(), "GearboxGear"); - return tmp; + pGearboxGear tmp = boost::dynamic_pointer_cast<GearboxGear>(components[name]); + if (tmp == NULL) log->__format(LOG_ERROR, "Tried to access non-existent world object \"%s\" using type \"%s\"", name.c_str(), "GearboxGear"); + return (tmp); } -Pedal * Vehicle::getPedal (std::string name) +pPedal Vehicle::getPedal (std::string name) { - Pedal * tmp = dynamic_cast<Pedal*>(components[name]); - if (tmp == NULL) log->__format(LOG_ERROR, "Tried to access non-existent world object \"%s\" using type \"%s\"", name.c_str(), "Pedal"); - return tmp; + pPedal tmp = boost::dynamic_pointer_cast<Pedal>(components[name]); + if (tmp == NULL) log->__format(LOG_ERROR, "Tried to access non-existent world object \"%s\" using type \"%s\"", name.c_str(), "Pedal"); + return (tmp); } -Suspension * Vehicle::getSuspension (std::string name) +pSuspension Vehicle::getSuspension (std::string name) { - Suspension * tmp = dynamic_cast<Suspension*>(components[name]); - if (tmp == NULL) log->__format(LOG_ERROR, "Tried to access non-existent world object \"%s\" using type \"%s\"", name.c_str(), "Suspension"); - return tmp; + pSuspension tmp = boost::dynamic_pointer_cast<Suspension>(components[name]); + if (tmp == NULL) log->__format(LOG_ERROR, "Tried to access non-existent world object \"%s\" using type \"%s\"", name.c_str(), "Suspension"); + return (tmp); } -Wheel * Vehicle::getWheel (std::string name) +pWheel Vehicle::getWheel (std::string name) { - Wheel * tmp = dynamic_cast<Wheel*>(components[name]); - if (tmp == NULL) log->__format(LOG_ERROR, "Tried to access non-existent world object \"%s\" using type \"%s\"", name.c_str(), "Wheel"); - return tmp; + pWheel tmp = boost::dynamic_pointer_cast<Wheel>(components[name]); + if (tmp == NULL) log->__format(LOG_ERROR, "Tried to access non-existent world object \"%s\" using type \"%s\"", name.c_str(), "Wheel"); + return (tmp); } -WorldObject * Vehicle::getObject (std::string name) +pWorldObject Vehicle::getObject (std::string name) { - if (components.find(name) == components.end()) - log->__format(LOG_ERROR, "Tried to access non-existent world object \"%s\" using type \"%s\"", name.c_str(), "WorldObject"); - return components[name]; + if (components.find(name) == components.end()) + log->__format(LOG_ERROR, "Tried to access non-existent world object \"%s\" using type \"%s\"", name.c_str(), "WorldObject"); + return components[name]; } Modified: trunk/src/vehicle/vehicle.hpp =================================================================== --- trunk/src/vehicle/vehicle.hpp 2006-07-06 12:38:22 UTC (rev 438) +++ trunk/src/vehicle/vehicle.hpp 2006-07-18 17:57:15 UTC (rev 439) @@ -13,20 +13,20 @@ #include "ode/objects.h" #include "xmlTag.hpp" -//forward declarations -class Body; -class Engine; -class Clutch; -class Gear; -class Gearbox; -class GearboxGear; -class FinalDrive; -class DriveJoint; -class DriveMass; -class LSD; -class Wheel; -class Pedal; -class Suspension; +// Forward declarations +SHARED_PTR(Body, pBody); +SHARED_PTR(Engine, pEngine); +SHARED_PTR(Clutch, pClutch); +SHARED_PTR(Gear, pGear); +SHARED_PTR(Gearbox, pGearbox); +SHARED_PTR(GearboxGear, pGearboxGear); +SHARED_PTR(FinalDrive, pFinalDrive); +SHARED_PTR(DriveJoint, pDriveJoint); +SHARED_PTR(DriveMass, pDriveMass); +SHARED_PTR(LSD, pLSD); +SHARED_PTR(Wheel, pWheel); +SHARED_PTR(Pedal, pPedal); +SHARED_PTR(Suspension, pSuspension); class Vector3d; class Quaternion; class CameraPosition; @@ -53,20 +53,22 @@ static pVehicle create(WorldObject * container, std::string vehicleName); ~Vehicle (); Cameras cameras; - Body * getBody (std::string name); - DriveJoint * getDriveJoint (std::string name); - DriveMass * getDriveMass (std::string name); - Clutch * getClutch (std::string name); - Gear * getGear (std::string name); - LSD * getLSD (std::string name); - Engine * getEngine (std::string name); - FinalDrive * getFinalDrive (std::string name); - Gearbox * getGearbox (std::string name); - GearboxGear * getGearboxGear (std::string name); - Pedal * getPedal (std::string name); - Suspension * getSuspension (std::string name); - Wheel * getWheel (std::string name); - WorldObject * getObject (std::string name); + + pBody getBody (std::string name); + pDriveJoint getDriveJoint (std::string name); + pDriveMass getDriveMass (std::string name); + pClutch getClutch (std::string name); + pGear getGear (std::string name); + pLSD getLSD (std::string name); + pEngine getEngine (std::string name); + pFinalDrive getFinalDrive (std::string name); + pGearbox getGearbox (std::string name); + pGearboxGear getGearboxGear (std::string name); + pPedal getPedal (std::string name); + pSuspension getSuspension (std::string name); + pWheel getWheel (std::string name); + pWorldObject getObject (std::string name); + void setUserDriver (); void stepPhysics (); void setPosition (Vector3d position); Modified: trunk/src/vehicle/wheel.cpp =================================================================== --- trunk/src/vehicle/wheel.cpp 2006-07-06 12:38:22 UTC (rev 438) +++ trunk/src/vehicle/wheel.cpp 2006-07-18 17:57:15 UTC (rev 439) @@ -19,6 +19,12 @@ #include "vehicle.hpp" #include "suspension.hpp" +pWheel Wheel::create(WorldObject * container, XmlTag * tag) +{ + pWheel tmp(new Wheel(container, tag)); + return tmp; +} + Wheel::Wheel (WorldObject * container, XmlTag * tag) :DriveMass(container, "wheel") { @@ -69,7 +75,7 @@ { } -void Wheel::setBrakePedal (Pedal * pedal) +void Wheel::setBrakePedal (pPedal pedal) { brakePedal = pedal; } Modified: trunk/src/vehicle/wheel.hpp =================================================================== --- trunk/src/vehicle/wheel.hpp 2006-07-06 12:38:22 UTC (rev 438) +++ trunk/src/vehicle/wheel.hpp 2006-07-18 17:57:15 UTC (rev 439) @@ -14,28 +14,30 @@ #include "worldObject.hpp" #include "paths.hpp" -//forward declarations +// Forward declarations class Vector3d; class Quaternion; namespace Ogre { class Entity; class SceneNode; } -class Suspension; +SHARED_PTR(Suspension, pSuspension); +SHARED_PTR(Wheel, pWheel); class Wheel : public DriveMass { private: bool userDriver; double powered; - Suspension * baseSuspension; - Pedal * brakePedal; + pSuspension baseSuspension; + pPedal brakePedal; + Wheel (WorldObject * container, XmlTag * tag); public: - Wheel (WorldObject * container, XmlTag * tag); + static pWheel create(WorldObject * container, XmlTag * tag); ~Wheel (); - void setSusp(Suspension * suspension) { baseSuspension = suspension; }; + void setSusp(pSuspension suspension) { baseSuspension = suspension; }; void setUserDriver (); - void setBrakePedal (Pedal * pedal); + void setBrakePedal (pPedal pedal); void stepPhysics (); double getInputAngularVel(); }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <st...@us...> - 2006-07-06 12:38:45
|
Revision: 438 Author: stenyak Date: 2006-07-06 05:38:22 -0700 (Thu, 06 Jul 2006) ViewCVS: http://svn.sourceforge.net/motorsport/?rev=438&view=rev Log Message: ----------- Created a temporary branch for aparaske's AI tests. Added Paths: ----------- branches/tmp/ai/ Copied: branches/tmp/ai (from rev 437, trunk) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <st...@us...> - 2006-07-06 12:37:25
|
Revision: 437 Author: stenyak Date: 2006-07-06 05:37:13 -0700 (Thu, 06 Jul 2006) ViewCVS: http://svn.sourceforge.net/motorsport/?rev=437&view=rev Log Message: ----------- Added directory for test branches. Added Paths: ----------- branches/tmp/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <st...@us...> - 2006-06-23 12:53:40
|
Revision: 436 Author: stenyak Date: 2006-06-23 05:52:52 -0700 (Fri, 23 Jun 2006) ViewCVS: http://svn.sourceforge.net/motorsport/?rev=436&view=rev Log Message: ----------- Renamed GraphicsEngine, InputEnine, GuiEngine and PhysicsEngine to Graphics, Input, Gui and Physics. Converted Graphics, Input, Gui and Physics pointers to shared pointers. Modified Paths: -------------- trunk/src/log/logEngine.cpp trunk/src/log/logEngine.hpp trunk/src/main.cpp trunk/src/main.hpp trunk/src/makefile trunk/src/system.hpp Added Paths: ----------- trunk/src/graphics.cpp trunk/src/graphics.hpp trunk/src/gui.cpp trunk/src/gui.hpp trunk/src/input.cpp trunk/src/input.hpp trunk/src/physics.cpp trunk/src/physics.hpp Removed Paths: ------------- trunk/src/graphicsEngine.cpp trunk/src/graphicsEngine.hpp trunk/src/guiEngine.cpp trunk/src/guiEngine.hpp trunk/src/inputEngine.cpp trunk/src/inputEngine.hpp trunk/src/physicsEngine.cpp trunk/src/physicsEngine.hpp Copied: trunk/src/graphics.cpp (from rev 435, trunk/src/graphicsEngine.cpp) =================================================================== --- trunk/src/graphics.cpp (rev 0) +++ trunk/src/graphics.cpp 2006-06-23 12:52:52 UTC (rev 436) @@ -0,0 +1,445 @@ +/*****************************************************************************\ +|* Copyright (C) 2003, 2006 "Motorsport" developers (*) *| +|* Part of the "Motorsport" project (http://motorsport.sourceforge.net) *| +|* Licensed under the GNU General Public License (*) *| +|* *| +|* (*) Complete information is provided at the following URL: *| +|* [ http://motorsport-sim.org/svn/trunk/doc/LICENSE ] *| +\*****************************************************************************/ + +#ifdef WIN32 +# define WIN32_LEAN_AND_MEAN +# include <windows.h> +#endif +#include "OgreNoMemoryMacros.h" +#include "graphics.hpp" +#include "system.hpp" +#include "Ogre.h" +#include "OgreConfigFile.h" +#include "SDL/SDL_keysym.h" +#include "world.hpp" +#include "area.hpp" +#include "camera.hpp" +#include "part.hpp" +#include "vehicle.hpp" +#include "logEngine.hpp" +#include "paths.hpp" + +void Graphics::manualInitialize (const std::string & renderer) +{ + Ogre::RenderSystem * renderSystem; + bool ok = false; + + log->__format (LOG_DEVELOPER, "Loading Ogre renderers list into memory."); + Ogre::RenderSystemList * renderers = Ogre::Root::getSingleton ().getAvailableRenderers (); + if (renderers->empty ()) + { + log->__format (LOG_ERROR, "No Ogre renderers available!"); + } + for (Ogre::RenderSystemList::iterator it = renderers->begin (); it != renderers->end (); it++) + { + renderSystem = (*it); + log->__format (LOG_DEVELOPER, "Locating desired renderer (%s).", renderer.c_str()); + if (renderSystem->getName() == renderer) + { + log->__format (LOG_DEVELOPER, "Ok, desired renderer found."); + ok = true; + break; + } + } + if (!ok) + { + log->__format (LOG_WARNING, "Desired renderer not found. Using first available one."); + renderSystem = (*renderers->begin ()); + } + Ogre::Root::getSingleton ().setRenderSystem (renderSystem); + + char resolution[32]; + sprintf (resolution, "%i x %i", width, height); + log->__format (LOG_ENDUSER, "Setting screen resolution and bpp: %s", resolution); + renderSystem->setConfigOption ("Video Mode", resolution); +} + +void Graphics::setupResources () +{ + //load some default constant resources + Ogre::ResourceGroupManager::getSingleton().addResourceLocation("./", "FileSystem", "General"); + Ogre::ResourceGroupManager::getSingleton().addResourceLocation(Paths::data(), "FileSystem", "General"); + Ogre::ResourceGroupManager::getSingleton().addResourceLocation(Paths::gui(), "FileSystem", "General"); + Ogre::ResourceGroupManager::getSingleton().addResourceLocation(Paths::vehicles(), "FileSystem", "General"); + Ogre::ResourceGroupManager::getSingleton().addResourceLocation(Paths::areas(), "FileSystem", "General"); + Ogre::ResourceGroupManager::getSingleton().addResourceLocation(Paths::parts(), "FileSystem", "General"); + Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup("General"); +} + +int Graphics::computeStep (void) +{ + Vector3d rotAngles (0, 0, 0); + // Sun controller. FIXME the sun should be a class, physically behaved. */ + if (System::get()->axisMap[getIDKeyboardKey(SDLK_o)]->getValue() == 1) + { + // Increase degree by degree, in Y axis. + rotAngles.y++; + } + if (System::get()->axisMap[getIDKeyboardKey(SDLK_p)]->getValue() == 1) + { + // Increase degree by degree, in Y axis. + rotAngles.y--; + } + if (rotAngles.y != 0) + { + Quaternion rotation (rotAngles.x, rotAngles.y, rotAngles.z); + + // Calculate and set the new direction of the sun light rays. + Ogre::Light * light = System::get()->ogreSceneManager->getLight("Sun"); + Vector3d direction (light->getDirection().x, light->getDirection().y, light->getDirection().z); + direction = rotation.rotateObject(direction); + light->setDirection(direction.x, direction.y, direction.z); + + // Predefined values for ambient light, depending on height of sun (max, med, min height) + Vector3d maxa (0.87, 0.97, 1.00); + Vector3d meda (0.53, 0.27, 0.61); + Vector3d mina (0.20, 0.24, 0.38); + + // Predefined values for sun light, depending on height of sun (max, med, min height) + Vector3d maxl (0.98, 1.00, 0.76); + Vector3d medl (0.88, 0.58, 0.40); + Vector3d minl (0.20, 0.24, 0.38); + + // Cache some values + double zm = -direction.z; + Vector3d z (zm, zm, zm); + const double zx = 1, zd = 0.00001, zn = 0; + const Vector3d max(zx,zx,zx), med(zd,zd,zd), min(zn,zn,zn); + Vector3d r; + + // Check if the sun is low (sunset) + if (zm>=zn && zm<zd) + { + // Linearly interpolate light values. + r = mina - ( ( ( z - min ) / ( med - min ) ) * (mina - meda) ); + System::get()->ogreSceneManager->setAmbientLight(Ogre::ColourValue(r.x, r.y, r.z)); + + r = minl - ( ( ( z - min ) / ( med - min ) ) * (minl - medl) ); + light->setDiffuseColour (r.x, r.y, r.z); + light->setSpecularColour(r.x, r.y, r.z); + } + // Check if the sun is high (midday) + if (zm>=zd && zm<zx) + { + // Linearly interpolate light values. + r = meda - ( ( ( z - med ) / ( max - med ) ) * (meda - maxa) ); + System::get()->ogreSceneManager->setAmbientLight(Ogre::ColourValue(r.x, r.y, r.z)); + + r = medl - ( ( ( z - med ) / ( max - med ) ) * (medl - maxl) ); + light->setDiffuseColour (r.x, r.y, r.z); + light->setSpecularColour(r.x, r.y, r.z); + } + } + + // take a screenshot if neededa + if (System::get()->axisMap[getIDKeyboardKey(SDLK_PRINT)]->getValue() == 1) + { + static unsigned int count = initialFrame; + static char tmpName[64]; + sprintf (tmpName, screenshotFilename.c_str(), count++); + log->__format (LOG_ENDUSER, "Taking a screenshot in %s.", tmpName); + System::get()->ogreWindow->writeContentsToFile (tmpName); + } + + // change camera if needed + if (System::get()->axisMap[getIDKeyboardKey(SDLK_c)]->getValue() == 1) + { + CamerasIt i = World::get()->areas.begin()->second->cameras.begin(); + pCamera nextCam = i->second; + bool found = false; + for (;i != World::get()->areas.begin()->second->cameras.end(); i++) + { + if (found == true) + { + nextCam = i->second; + found = false; + } + if (World::get()->getActiveAreaCamera()->getName() == i->second->getName()) + { + found = true; + } + } + World::get()->setActiveCamera(nextCam); + World::get()->activeAreaCamera = nextCam; + } + if (System::get()->axisMap[getIDKeyboardKey(SDLK_v)]->getValue() == 1) + { + CamerasIt i = World::get()->vehicles.begin()->second->cameras.begin(); + pCamera nextCam = i->second; + bool found = false; + for (;i != World::get()->vehicles.begin()->second->cameras.end(); i++) + { + if (found == true) + { + nextCam = i->second; + found = false; + } + if (World::get()->getActiveVehicleCamera()->getName() == i->second->getName()) + { + found = true; + } + } + World::get()->setActiveCamera(nextCam); + World::get()->activeVehicleCamera = nextCam; + } + if (System::get()->cameraDirector) + { + log->__format(LOG_DEVELOPER, "Finding closest camera"); + Vector3d vPos = World::get()->vehicles.begin()->second->getPosition(); + double closestDistance = 99999999999.0; + CamerasIt i = World::get()->areas.begin()->second->cameras.begin(); + pCamera closestCam = i->second; + for (;i != World::get()->areas.begin()->second->cameras.end(); i++) + { + log->__format(LOG_DEVELOPER, "Checking cam id: %s", i->second->getName().c_str()); + Ogre::Vector3 p = i->second->ogreCamera->getPosition(); + Vector3d cPos (p.x, p.y, p.z); + double distance = cPos.distance(vPos); + if (distance < closestDistance) + { + closestDistance = distance; + closestCam = i->second; + } + + } + World::get()->setActiveCamera(closestCam); + World::get()->activeAreaCamera = closestCam; + } + // Update Ogre's vehicles positions with Ode's positions. + VehiclesIt j = World::get()->vehicles.begin(); + for (; j != World::get()->vehicles.end(); j++) + { + j->second->stepGraphics(); + } + + // Update Ogre's parts positions with Ode's positions. + PartsIt k = World::get()->areas.begin()->second->parts.begin(); + for (; k != World::get()->areas.begin()->second->parts.end(); k++) + { + k->second->stepGraphics(); + } + + // Update cameras positions (should be done in the fsx engine FIXME + CamerasIt i = World::get()->areas.begin()->second->cameras.begin(); + for (;i != World::get()->areas.begin()->second->cameras.end(); i++) + { + i->second->stepGraphics(); + } + i = World::get()->vehicles.begin()->second->cameras.begin(); + for (;i != World::get()->vehicles.begin()->second->cameras.end(); i++) + { + i->second->stepGraphics(); + } + + // Update infinite plane position according to vehicle position + Ogre::Vector3 areaPos (World::get()->areas.begin()->second->planeNode->getPosition()); + Vector3d vehiclePos (World::get()->vehicles.begin()->second->getPosition()); + Vector3d diff (areaPos.x - vehiclePos.x, areaPos.y - vehiclePos.y, areaPos.z - vehiclePos.z); + const double tile = 1000.0 / 20.0; + if (diff.x > tile || diff.x < -tile) areaPos.x -= int ((diff.x) / (tile)) * (tile); + if (diff.y > tile || diff.y < -tile) areaPos.y -= int ((diff.y) / (tile)) * (tile); + World::get()->areas.begin()->second->planeNode->setPosition(areaPos); + + // Update area shadows state + World::get()->areas.begin()->second->setCastShadows(castAreaShadows); + + // Update area render mode + World::get()->areas.begin()->second->setRenderDetail(areaRenderMode); + + // Let the listener frames be started and ended: they are needed for particle System::get()s. + ogreRoot->_fireFrameStarted (); + System::get()->ogreWindow->update (); + ogreRoot->_fireFrameEnded (); + + return (0); +} + +Graphics::~Graphics (void) +{ + log->__format (LOG_DEVELOPER, "Unloading ogre window data from memory..."); + delete (System::get()->ogreWindow); +} + +Graphics::Graphics () +{ +#ifdef MACOSX + XmlTag * tag = new XmlTag ("motorsport.app/Contents/Resources/graphicsConfig.xml"); +#else + XmlTag * tag = new XmlTag ("../cfg/graphicsConfig.xml"); +#endif + LOG_LEVEL localLogLevel = LOG_DEVELOPER; + std::string localLogName = "GFX"; + screenshotFilename.assign ("frame%i.jpg"); + initialFrame = 0; + castAreaShadows = true; + vehicleRenderMode = Ogre::PM_SOLID; + areaRenderMode = Ogre::PM_SOLID; + #ifdef WIN32 + std::string ogrePluginsDir = "plugins"; + #else + std::string ogrePluginsDir = "/usr/lib/OGRE"; + #endif + Ogre::SceneType sceneManager = Ogre::ST_GENERIC; + int anisotropy = 1; + Ogre::TextureFilterOptions filtering = Ogre::TFO_NONE; + Ogre::ShadowTechnique shadowTechnique = Ogre::SHADOWTYPE_NONE; + width = 800; + height = 600; + bpp = 0; + std::string renderer = "OpenGL"; + int defaultNumMipMaps = 5; + fullScreen = false; + + log = LogEngine::create (LOG_DEVELOPER, "Graphics"); + + if (tag->getName() == "graphicsConfig") + { + screenshotFilename = tag->getAttribute("screenshotFile"); + initialFrame = stoi(tag->getAttribute("initialScreenshotFileNumber")); + castAreaShadows = stob(tag->getAttribute("castAreaShadows")); + if ( tag->getAttribute("vehicleRenderMode") == "points") vehicleRenderMode = 1; + if ( tag->getAttribute("vehicleRenderMode") == "wireframe") vehicleRenderMode = 2; + if ( tag->getAttribute("vehicleRenderMode") == "solid") vehicleRenderMode = 3; + if ( tag->getAttribute("areaRenderMode") == "points") areaRenderMode = 1; + if ( tag->getAttribute("areaRenderMode") == "wireframe") areaRenderMode = 2; + if ( tag->getAttribute("areaRenderMode") == "solid") areaRenderMode = 3; + XmlTag * t = tag->getTag(0); for (int i = 0; i < tag->nTags(); t = tag->getTag(++i)) + { + if (t->getName() == "ogre") + { + #ifdef WIN32 + ogrePluginsDir = t->getAttribute("windowsPluginsDir"); + #else + ogrePluginsDir = t->getAttribute("linuxPluginsDir"); + #endif + anisotropy = stoi(t->getAttribute("anisotropy")); + width = stoi(t->getAttribute("width")); + height = stoi(t->getAttribute("height")); + bpp = stoi(t->getAttribute("bpp")); + renderer = t->getAttribute("renderer"); + defaultNumMipMaps = stoi(t->getAttribute("defaultNumMipmaps")); + fullScreen = stob(t->getAttribute("fullScreen")); + if (t->getAttribute("sceneManager") == "ST_GENERIC") sceneManager = Ogre::ST_GENERIC; + if (t->getAttribute("sceneManager") == "ST_EXTERIOR_CLOSE") sceneManager = Ogre::ST_EXTERIOR_CLOSE; + if (t->getAttribute("sceneManager") == "ST_EXTERIOR_FAR") sceneManager = Ogre::ST_EXTERIOR_FAR; + if (t->getAttribute("sceneManager") == "ST_EXTERIOR_REAL_FAR") sceneManager = Ogre::ST_EXTERIOR_REAL_FAR; + if (t->getAttribute("sceneManager") == "ST_INTERIOR") sceneManager = Ogre::ST_INTERIOR; + if (t->getAttribute("filtering") == "TFO_NONE") filtering = Ogre::TFO_NONE; + if (t->getAttribute("filtering") == "TFO_BILINEAR") filtering = Ogre::TFO_BILINEAR; + if (t->getAttribute("filtering") == "TFO_TRILINEAR") filtering = Ogre::TFO_TRILINEAR; + if (t->getAttribute("filtering") == "TFO_ANISOTROPIC") filtering = Ogre::TFO_ANISOTROPIC; + if (t->getAttribute("shadowTechnique") == "SHADOWTYPE_NONE") shadowTechnique = Ogre::SHADOWTYPE_NONE; + if (t->getAttribute("shadowTechnique") == "SHADOWTYPE_STENCIL_MODULATIVE") shadowTechnique = Ogre::SHADOWTYPE_STENCIL_MODULATIVE; + if (t->getAttribute("shadowTechnique") == "SHADOWTYPE_STENCIL_ADDITIVE") shadowTechnique = Ogre::SHADOWTYPE_STENCIL_ADDITIVE; + if (t->getAttribute("shadowTechnique") == "SHADOWTYPE_TEXTURE_MODULATIVE") shadowTechnique = Ogre::SHADOWTYPE_TEXTURE_MODULATIVE; + } + } + } + delete tag; + + + log = LogEngine::create (localLogLevel, localLogName.c_str()); + log->__format (LOG_DEVELOPER, "Temporary parsing data already loaded into memory..."); + + // get the direction of the graphics data + log->__format (LOG_DEVELOPER, "Setting up data pointers..."); + System::get() = System::get(); + + System::get()->height = height; + System::get()->width = width; + log->__format (LOG_DEVELOPER, "Graphics data initialized to %ix%i@%ibpp", width, height, bpp); + + log->__format (LOG_DEVELOPER, "Creating temporary ogre plugins config file (plugins.cfg)"); + FILE *ogrePluginsConfig = fopen("plugins.cfg", "w"); + if (ogrePluginsConfig == NULL) + { + log->__format(LOG_ERROR, "Error opening ogre plugins config file!!"); + } + log->__format (LOG_DEVELOPER, "Writing configuration to plugins.cfg"); + fprintf(ogrePluginsConfig, "# IMPORTANT NOTE #" + "\n#Everything you write in this file will be ignored and overwriten next time you run motorsport. You can therefore safely delete this file.\n\n" + "\n# Define plugins folder" +#ifdef MACOSX + "\n#PluginFolder=%s" +#else + "\nPluginFolder=%s" +#endif + "\n# Define plugins" + "\nPlugin=RenderSystem_GL" +#ifdef WIN32 + "\n#Plugin=RenderSystem_Direct3D9" +#endif + "\n#Plugin=Plugin_FileSystem" + "\n#Plugin=Plugin_ParticleFX" + "\n#Plugin=Plugin_BSPSceneManager" + "\n#Plugin=Plugin_OctreeSceneManager" + "\n#Plugin=Plugin_GuiElements" + "\n#Plugin=Plugin_NatureSceneManager" + "\n#Plugin=Plugin_CgProgramManager" + ,ogrePluginsDir.c_str()); + log->__format (LOG_DEVELOPER, "Closing temporary ogre plugins config file (plugins.cfg)"); + fclose(ogrePluginsConfig); + + log->__format (LOG_DEVELOPER, "Creating Ogre root element"); + ogreRoot = new Ogre::Root ("plugins.cfg", "removeme.cfg", "motorsport-ogre.log"); + + // select renderer and set resolution and bpp + manualInitialize (renderer); + + log->__format (LOG_DEVELOPER, "Setting up fullscreen/windowed mode"); + ogreRoot->getRenderSystem ()->setConfigOption ("Full Screen", fullScreen ? "Yes" : "No"); + log->__format (LOG_DEVELOPER, "Saving config file to removeme.cfg"); + ogreRoot->saveConfig(); + + // Here we choose to let the System::get() create a default rendering window + log->__format (LOG_DEVELOPER, "Initializing ogre root element"); + System::get()->ogreWindow = ogreRoot->initialise (true); + setupResources (); +#ifdef WIN32 + + char tmp[64]; + // New method: As proposed by Sinbad. + // This method always works. + HWND hWnd; + System::get()->ogreWindow->getCustomAttribute("HWND", &hWnd); + sprintf(tmp, "SDL_WINDOWID=%d", hWnd); + _putenv(tmp); + +#endif + log->__format (LOG_DEVELOPER, "Getting ogre scene manager"); + // Set shadowing System::get() + System::get()->ogreSceneManager = ogreRoot->createSceneManager (sceneManager); + System::get()->ogreSceneManager->setShadowTechnique(shadowTechnique); + System::get()->ogreSceneManager->setAmbientLight(Ogre::ColourValue(0.67, 0.94, 1.00)); + System::get()->ogreSceneManager->setShadowColour(Ogre::ColourValue(0.5, 0.5, 0.5)); + // Set default mipmap level (NB some APIs ignore this) + log->__format (LOG_ENDUSER, "Setting up default number of mipmap levels"); + Ogre::TextureManager::getSingleton ().setDefaultNumMipmaps (defaultNumMipMaps); + + // Set some graphics settings + log->__format (LOG_ENDUSER, "Setting up anisotropy and filtering parameters"); + Ogre::MaterialManager::getSingleton ().setDefaultAnisotropy (anisotropy); + Ogre::MaterialManager::getSingleton ().setDefaultTextureFiltering (filtering); + + Ogre::Light * light = System::get()->ogreSceneManager->createLight("Sun"); + //light->setType(Ogre::Light::LT_SPOTLIGHT); + //light->setType(Ogre::Light::LT_POINT); + light->setType(Ogre::Light::LT_DIRECTIONAL); + light->setDirection(0.16,0.2,-1); + //light->setPosition(50, 50, 1); + light->setDiffuseColour(1, 1, 1); + light->setSpecularColour(1, 1, 1); + System::get()->ogreSceneManager->getRootSceneNode()->attachObject (light); + + log->__format (LOG_DEVELOPER, "Removing temporary ogre plugins config file (plugins.cfg)"); + remove("plugins.cfg"); + log->__format (LOG_DEVELOPER, "Removing temporary ogre file"); + remove("removeme.cfg"); +} + Copied: trunk/src/graphics.hpp (from rev 435, trunk/src/graphicsEngine.hpp) =================================================================== --- trunk/src/graphics.hpp (rev 0) +++ trunk/src/graphics.hpp 2006-06-23 12:52:52 UTC (rev 436) @@ -0,0 +1,92 @@ +/*****************************************************************************\ +|* Copyright (C) 2003, 2006 "Motorsport" developers (*) *| +|* Part of the "Motorsport" project (http://motorsport.sourceforge.net) *| +|* Licensed under the GNU General Public License (*) *| +|* *| +|* (*) Complete information is provided at the following URL: *| +|* [ http://motorsport-sim.org/svn/trunk/doc/LICENSE ] *| +\*****************************************************************************/ + +#include <common/shared.hpp> + +// Forward declarations +namespace Ogre { class Root; } +SHARED_PTR_MAP(LogEngine, pLogEngine, LogEngines, LogEnginesIt); +SHARED_PTR(Graphics,pGraphics); + +/** Manages everything related to the process of world data graphics rendering on screen. The menues and similar gadgets are not rendered by this engine; only world data is handled here (cars, area, etc...). + * @brief Manages everything related to the rendering process. + */ +class Graphics +{ + private: + /** This log engine allows the graphics engine to write data in the log file, allowing to be differenciated from other engines. + * @brief Log engine used by the graphics engine. + */ + pLogEngine log; + /** + * @brief Name of the file were screenshots will be saved. + */ + std::string screenshotFilename; + /** + * @brief Specifies the number where the screenshot filename numbering starts. + */ + int initialFrame; + public: + /** + * @brief Stores the horizontal resolution of the screen. + */ + int width; + /** + * @brief Stores the vertical resolution of the screen. + */ + int height; + /** + * @brief Stores the bits per pixel of depth. + */ + int bpp; + /** + * @brief Specifies whether to use fullScreen mode, or windowed mode. + */ + bool fullScreen; + /** + * @brief Specifies whether the area will cast shadows or not. + */ + bool castAreaShadows; + /** + * @brief Specifies how the vehicle will be rendered: 1=points, 2=wireframe, 3=solid. + */ + int vehicleRenderMode; + /** + * @brief Specifies how the area will be rendered: 1=points, 2=wireframe, 3=solid. + */ + int areaRenderMode; + /** + * @brief The OGRE root element. + */ + Ogre::Root * ogreRoot; + /** Creates a new graphics engine, with its associated own log engine. It initializes all necessary related data, such as initial graphics representation of world data (meshes, textures...), and sets up the underlying rendering libray (Ogre). + * @brief Creates a new graphics engine. + */ + Graphics (); + /** Deletes de graphics engine, as well as its associated log engine. It also removes all the related data from memory, and shuts down Ogre if necessary. + * @brief Deletes the graphics engine. + */ + ~Graphics (void); + /** Renders on screen all the world data for this frame. + * @brief Renders all the world data on screen. + * + * @return 0 on success. + */ + int computeStep (void); + /** Selects a renderer and switches to the chosen resolution. If the desired render (OpenGL) is not found, the first available one is then chosen. + * @brief Selects a renderer and switches to the chosen resolution. + * + * @param renderer What renderer to use. For example "OpenGL". Case sensitive. + */ + void manualInitialize (const std::string & renderer); + /** Tells Ogre where to find resources via the resources.cfg file. This allows Ogre to know where all the data (meshes, materials, textures...) can be found, not needing to explicitly indicate it. + * @brief Tells Ogre where to find resources. + */ + void setupResources (); +}; Deleted: trunk/src/graphicsEngine.cpp =================================================================== --- trunk/src/graphicsEngine.cpp 2006-06-23 11:48:21 UTC (rev 435) +++ trunk/src/graphicsEngine.cpp 2006-06-23 12:52:52 UTC (rev 436) @@ -1,445 +0,0 @@ -/*****************************************************************************\ -|* Copyright (C) 2003, 2006 "Motorsport" developers (*) *| -|* Part of the "Motorsport" project (http://motorsport.sourceforge.net) *| -|* Licensed under the GNU General Public License (*) *| -|* *| -|* (*) Complete information is provided at the following URL: *| -|* [ http://motorsport-sim.org/svn/trunk/doc/LICENSE ] *| -\*****************************************************************************/ - -#ifdef WIN32 -# define WIN32_LEAN_AND_MEAN -# include <windows.h> -#endif -#include "OgreNoMemoryMacros.h" -#include "graphicsEngine.hpp" -#include "area.hpp" -#include "camera.hpp" -#include "part.hpp" -#include "system.hpp" -#include "Ogre.h" -#include "OgreConfigFile.h" -#include "world.hpp" -#include "SDL/SDL_keysym.h" -#include "vehicle.hpp" -#include "logEngine.hpp" -#include "paths.hpp" - -void GraphicsEngine::manualInitialize (const std::string & renderer) -{ - Ogre::RenderSystem * renderSystem; - bool ok = false; - - log->__format (LOG_DEVELOPER, "Loading Ogre renderers list into memory."); - Ogre::RenderSystemList * renderers = Ogre::Root::getSingleton ().getAvailableRenderers (); - if (renderers->empty ()) - { - log->__format (LOG_ERROR, "No Ogre renderers available!"); - } - for (Ogre::RenderSystemList::iterator it = renderers->begin (); it != renderers->end (); it++) - { - renderSystem = (*it); - log->__format (LOG_DEVELOPER, "Locating desired renderer (%s).", renderer.c_str()); - if (renderSystem->getName() == renderer) - { - log->__format (LOG_DEVELOPER, "Ok, desired renderer found."); - ok = true; - break; - } - } - if (!ok) - { - log->__format (LOG_WARNING, "Desired renderer not found. Using first available one."); - renderSystem = (*renderers->begin ()); - } - Ogre::Root::getSingleton ().setRenderSystem (renderSystem); - - char resolution[32]; - sprintf (resolution, "%i x %i", width, height); - log->__format (LOG_ENDUSER, "Setting screen resolution and bpp: %s", resolution); - renderSystem->setConfigOption ("Video Mode", resolution); -} - -void GraphicsEngine::setupResources () -{ - //load some default constant resources - Ogre::ResourceGroupManager::getSingleton().addResourceLocation("./", "FileSystem", "General"); - Ogre::ResourceGroupManager::getSingleton().addResourceLocation(Paths::data(), "FileSystem", "General"); - Ogre::ResourceGroupManager::getSingleton().addResourceLocation(Paths::gui(), "FileSystem", "General"); - Ogre::ResourceGroupManager::getSingleton().addResourceLocation(Paths::vehicles(), "FileSystem", "General"); - Ogre::ResourceGroupManager::getSingleton().addResourceLocation(Paths::areas(), "FileSystem", "General"); - Ogre::ResourceGroupManager::getSingleton().addResourceLocation(Paths::parts(), "FileSystem", "General"); - Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup("General"); -} - -int GraphicsEngine::computeStep (void) -{ - Vector3d rotAngles (0, 0, 0); - // Sun controller. FIXME the sun should be a class, physically behaved. */ - if (system->axisMap[getIDKeyboardKey(SDLK_o)]->getValue() == 1) - { - // Increase degree by degree, in Y axis. - rotAngles.y++; - } - if (system->axisMap[getIDKeyboardKey(SDLK_p)]->getValue() == 1) - { - // Increase degree by degree, in Y axis. - rotAngles.y--; - } - if (rotAngles.y != 0) - { - Quaternion rotation (rotAngles.x, rotAngles.y, rotAngles.z); - - // Calculate and set the new direction of the sun light rays. - Ogre::Light * light = System::get()->ogreSceneManager->getLight("Sun"); - Vector3d direction (light->getDirection().x, light->getDirection().y, light->getDirection().z); - direction = rotation.rotateObject(direction); - light->setDirection(direction.x, direction.y, direction.z); - - // Predefined values for ambient light, depending on height of sun (max, med, min height) - Vector3d maxa (0.87, 0.97, 1.00); - Vector3d meda (0.53, 0.27, 0.61); - Vector3d mina (0.20, 0.24, 0.38); - - // Predefined values for sun light, depending on height of sun (max, med, min height) - Vector3d maxl (0.98, 1.00, 0.76); - Vector3d medl (0.88, 0.58, 0.40); - Vector3d minl (0.20, 0.24, 0.38); - - // Cache some values - double zm = -direction.z; - Vector3d z (zm, zm, zm); - const double zx = 1, zd = 0.00001, zn = 0; - const Vector3d max(zx,zx,zx), med(zd,zd,zd), min(zn,zn,zn); - Vector3d r; - - // Check if the sun is low (sunset) - if (zm>=zn && zm<zd) - { - // Linearly interpolate light values. - r = mina - ( ( ( z - min ) / ( med - min ) ) * (mina - meda) ); - system->ogreSceneManager->setAmbientLight(Ogre::ColourValue(r.x, r.y, r.z)); - - r = minl - ( ( ( z - min ) / ( med - min ) ) * (minl - medl) ); - light->setDiffuseColour (r.x, r.y, r.z); - light->setSpecularColour(r.x, r.y, r.z); - } - // Check if the sun is high (midday) - if (zm>=zd && zm<zx) - { - // Linearly interpolate light values. - r = meda - ( ( ( z - med ) / ( max - med ) ) * (meda - maxa) ); - system->ogreSceneManager->setAmbientLight(Ogre::ColourValue(r.x, r.y, r.z)); - - r = medl - ( ( ( z - med ) / ( max - med ) ) * (medl - maxl) ); - light->setDiffuseColour (r.x, r.y, r.z); - light->setSpecularColour(r.x, r.y, r.z); - } - } - - // take a screenshot if neededa - if (system->axisMap[getIDKeyboardKey(SDLK_PRINT)]->getValue() == 1) - { - static unsigned int count = initialFrame; - static char tmpName[64]; - sprintf (tmpName, screenshotFilename.c_str(), count++); - log->__format (LOG_ENDUSER, "Taking a screenshot in %s.", tmpName); - system->ogreWindow->writeContentsToFile (tmpName); - } - - // change camera if needed - if (system->axisMap[getIDKeyboardKey(SDLK_c)]->getValue() == 1) - { - CamerasIt i = World::get()->areas.begin()->second->cameras.begin(); - pCamera nextCam = i->second; - bool found = false; - for (;i != World::get()->areas.begin()->second->cameras.end(); i++) - { - if (found == true) - { - nextCam = i->second; - found = false; - } - if (World::get()->getActiveAreaCamera()->getName() == i->second->getName()) - { - found = true; - } - } - World::get()->setActiveCamera(nextCam); - World::get()->activeAreaCamera = nextCam; - } - if (system->axisMap[getIDKeyboardKey(SDLK_v)]->getValue() == 1) - { - CamerasIt i = World::get()->vehicles.begin()->second->cameras.begin(); - pCamera nextCam = i->second; - bool found = false; - for (;i != World::get()->vehicles.begin()->second->cameras.end(); i++) - { - if (found == true) - { - nextCam = i->second; - found = false; - } - if (World::get()->getActiveVehicleCamera()->getName() == i->second->getName()) - { - found = true; - } - } - World::get()->setActiveCamera(nextCam); - World::get()->activeVehicleCamera = nextCam; - } - if (system->cameraDirector) - { - log->__format(LOG_DEVELOPER, "Finding closest camera"); - Vector3d vPos = World::get()->vehicles.begin()->second->getPosition(); - double closestDistance = 99999999999.0; - CamerasIt i = World::get()->areas.begin()->second->cameras.begin(); - pCamera closestCam = i->second; - for (;i != World::get()->areas.begin()->second->cameras.end(); i++) - { - log->__format(LOG_DEVELOPER, "Checking cam id: %s", i->second->getName().c_str()); - Ogre::Vector3 p = i->second->ogreCamera->getPosition(); - Vector3d cPos (p.x, p.y, p.z); - double distance = cPos.distance(vPos); - if (distance < closestDistance) - { - closestDistance = distance; - closestCam = i->second; - } - - } - World::get()->setActiveCamera(closestCam); - World::get()->activeAreaCamera = closestCam; - } - // Update Ogre's vehicles positions with Ode's positions. - VehiclesIt j = World::get()->vehicles.begin(); - for (; j != World::get()->vehicles.end(); j++) - { - j->second->stepGraphics(); - } - - // Update Ogre's parts positions with Ode's positions. - PartsIt k = World::get()->areas.begin()->second->parts.begin(); - for (; k != World::get()->areas.begin()->second->parts.end(); k++) - { - k->second->stepGraphics(); - } - - // Update cameras positions (should be done in the fsx engine FIXME - CamerasIt i = World::get()->areas.begin()->second->cameras.begin(); - for (;i != World::get()->areas.begin()->second->cameras.end(); i++) - { - i->second->stepGraphics(); - } - i = World::get()->vehicles.begin()->second->cameras.begin(); - for (;i != World::get()->vehicles.begin()->second->cameras.end(); i++) - { - i->second->stepGraphics(); - } - - // Update infinite plane position according to vehicle position - Ogre::Vector3 areaPos (World::get()->areas.begin()->second->planeNode->getPosition()); - Vector3d vehiclePos (World::get()->vehicles.begin()->second->getPosition()); - Vector3d diff (areaPos.x - vehiclePos.x, areaPos.y - vehiclePos.y, areaPos.z - vehiclePos.z); - const double tile = 1000.0 / 20.0; - if (diff.x > tile || diff.x < -tile) areaPos.x -= int ((diff.x) / (tile)) * (tile); - if (diff.y > tile || diff.y < -tile) areaPos.y -= int ((diff.y) / (tile)) * (tile); - World::get()->areas.begin()->second->planeNode->setPosition(areaPos); - - // Update area shadows state - World::get()->areas.begin()->second->setCastShadows(castAreaShadows); - - // Update area render mode - World::get()->areas.begin()->second->setRenderDetail(areaRenderMode); - - // Let the listener frames be started and ended: they are needed for particle systems. - ogreRoot->_fireFrameStarted (); - system->ogreWindow->update (); - ogreRoot->_fireFrameEnded (); - - return (0); -} - -GraphicsEngine::~GraphicsEngine (void) -{ - log->__format (LOG_DEVELOPER, "Unloading ogre window data from memory..."); - delete (system->ogreWindow); -} - -GraphicsEngine::GraphicsEngine () -{ -#ifdef MACOSX - XmlTag * tag = new XmlTag ("motorsport.app/Contents/Resources/graphicsConfig.xml"); -#else - XmlTag * tag = new XmlTag ("../cfg/graphicsConfig.xml"); -#endif - LOG_LEVEL localLogLevel = LOG_DEVELOPER; - std::string localLogName = "GFX"; - screenshotFilename.assign ("frame%i.jpg"); - initialFrame = 0; - castAreaShadows = true; - vehicleRenderMode = Ogre::PM_SOLID; - areaRenderMode = Ogre::PM_SOLID; - #ifdef WIN32 - std::string ogrePluginsDir = "plugins"; - #else - std::string ogrePluginsDir = "/usr/lib/OGRE"; - #endif - Ogre::SceneType sceneManager = Ogre::ST_GENERIC; - int anisotropy = 1; - Ogre::TextureFilterOptions filtering = Ogre::TFO_NONE; - Ogre::ShadowTechnique shadowTechnique = Ogre::SHADOWTYPE_NONE; - width = 800; - height = 600; - bpp = 0; - std::string renderer = "OpenGL"; - int defaultNumMipMaps = 5; - fullScreen = false; - - log = LogEngine::create (LOG_DEVELOPER, "GraphicsEngine"); - - if (tag->getName() == "graphicsConfig") - { - screenshotFilename = tag->getAttribute("screenshotFile"); - initialFrame = stoi(tag->getAttribute("initialScreenshotFileNumber")); - castAreaShadows = stob(tag->getAttribute("castAreaShadows")); - if ( tag->getAttribute("vehicleRenderMode") == "points") vehicleRenderMode = 1; - if ( tag->getAttribute("vehicleRenderMode") == "wireframe") vehicleRenderMode = 2; - if ( tag->getAttribute("vehicleRenderMode") == "solid") vehicleRenderMode = 3; - if ( tag->getAttribute("areaRenderMode") == "points") areaRenderMode = 1; - if ( tag->getAttribute("areaRenderMode") == "wireframe") areaRenderMode = 2; - if ( tag->getAttribute("areaRenderMode") == "solid") areaRenderMode = 3; - XmlTag * t = tag->getTag(0); for (int i = 0; i < tag->nTags(); t = tag->getTag(++i)) - { - if (t->getName() == "ogre") - { - #ifdef WIN32 - ogrePluginsDir = t->getAttribute("windowsPluginsDir"); - #else - ogrePluginsDir = t->getAttribute("linuxPluginsDir"); - #endif - anisotropy = stoi(t->getAttribute("anisotropy")); - width = stoi(t->getAttribute("width")); - height = stoi(t->getAttribute("height")); - bpp = stoi(t->getAttribute("bpp")); - renderer = t->getAttribute("renderer"); - defaultNumMipMaps = stoi(t->getAttribute("defaultNumMipmaps")); - fullScreen = stob(t->getAttribute("fullScreen")); - if (t->getAttribute("sceneManager") == "ST_GENERIC") sceneManager = Ogre::ST_GENERIC; - if (t->getAttribute("sceneManager") == "ST_EXTERIOR_CLOSE") sceneManager = Ogre::ST_EXTERIOR_CLOSE; - if (t->getAttribute("sceneManager") == "ST_EXTERIOR_FAR") sceneManager = Ogre::ST_EXTERIOR_FAR; - if (t->getAttribute("sceneManager") == "ST_EXTERIOR_REAL_FAR") sceneManager = Ogre::ST_EXTERIOR_REAL_FAR; - if (t->getAttribute("sceneManager") == "ST_INTERIOR") sceneManager = Ogre::ST_INTERIOR; - if (t->getAttribute("filtering") == "TFO_NONE") filtering = Ogre::TFO_NONE; - if (t->getAttribute("filtering") == "TFO_BILINEAR") filtering = Ogre::TFO_BILINEAR; - if (t->getAttribute("filtering") == "TFO_TRILINEAR") filtering = Ogre::TFO_TRILINEAR; - if (t->getAttribute("filtering") == "TFO_ANISOTROPIC") filtering = Ogre::TFO_ANISOTROPIC; - if (t->getAttribute("shadowTechnique") == "SHADOWTYPE_NONE") shadowTechnique = Ogre::SHADOWTYPE_NONE; - if (t->getAttribute("shadowTechnique") == "SHADOWTYPE_STENCIL_MODULATIVE") shadowTechnique = Ogre::SHADOWTYPE_STENCIL_MODULATIVE; - if (t->getAttribute("shadowTechnique") == "SHADOWTYPE_STENCIL_ADDITIVE") shadowTechnique = Ogre::SHADOWTYPE_STENCIL_ADDITIVE; - if (t->getAttribute("shadowTechnique") == "SHADOWTYPE_TEXTURE_MODULATIVE") shadowTechnique = Ogre::SHADOWTYPE_TEXTURE_MODULATIVE; - } - } - } - delete tag; - - - log = LogEngine::create (localLogLevel, localLogName.c_str()); - log->__format (LOG_DEVELOPER, "Temporary parsing data already loaded into memory..."); - - // get the direction of the graphics data - log->__format (LOG_DEVELOPER, "Setting up data pointers..."); - system = System::get(); - - system->height = height; - system->width = width; - log->__format (LOG_DEVELOPER, "Graphics data initialized to %ix%i@%ibpp", width, height, bpp); - - log->__format (LOG_DEVELOPER, "Creating temporary ogre plugins config file (plugins.cfg)"); - FILE *ogrePluginsConfig = fopen("plugins.cfg", "w"); - if (ogrePluginsConfig == NULL) - { - log->__format(LOG_ERROR, "Error opening ogre plugins config file!!"); - } - log->__format (LOG_DEVELOPER, "Writing configuration to plugins.cfg"); - fprintf(ogrePluginsConfig, "# IMPORTANT NOTE #" - "\n#Everything you write in this file will be ignored and overwriten next time you run motorsport. You can therefore safely delete this file.\n\n" - "\n# Define plugins folder" -#ifdef MACOSX - "\n#PluginFolder=%s" -#else - "\nPluginFolder=%s" -#endif - "\n# Define plugins" - "\nPlugin=RenderSystem_GL" -#ifdef WIN32 - "\n#Plugin=RenderSystem_Direct3D9" -#endif - "\n#Plugin=Plugin_FileSystem" - "\n#Plugin=Plugin_ParticleFX" - "\n#Plugin=Plugin_BSPSceneManager" - "\n#Plugin=Plugin_OctreeSceneManager" - "\n#Plugin=Plugin_GuiElements" - "\n#Plugin=Plugin_NatureSceneManager" - "\n#Plugin=Plugin_CgProgramManager" - ,ogrePluginsDir.c_str()); - log->__format (LOG_DEVELOPER, "Closing temporary ogre plugins config file (plugins.cfg)"); - fclose(ogrePluginsConfig); - - log->__format (LOG_DEVELOPER, "Creating Ogre root element"); - ogreRoot = new Ogre::Root ("plugins.cfg", "removeme.cfg", "motorsport-ogre.log"); - - // select renderer and set resolution and bpp - manualInitialize (renderer); - - log->__format (LOG_DEVELOPER, "Setting up fullscreen/windowed mode"); - ogreRoot->getRenderSystem ()->setConfigOption ("Full Screen", fullScreen ? "Yes" : "No"); - log->__format (LOG_DEVELOPER, "Saving config file to removeme.cfg"); - ogreRoot->saveConfig(); - - // Here we choose to let the system create a default rendering window - log->__format (LOG_DEVELOPER, "Initializing ogre root element"); - system->ogreWindow = ogreRoot->initialise (true); - setupResources (); -#ifdef WIN32 - - char tmp[64]; - // New method: As proposed by Sinbad. - // This method always works. - HWND hWnd; - system->ogreWindow->getCustomAttribute("HWND", &hWnd); - sprintf(tmp, "SDL_WINDOWID=%d", hWnd); - _putenv(tmp); - -#endif - log->__format (LOG_DEVELOPER, "Getting ogre scene manager"); - // Set shadowing system - system->ogreSceneManager = ogreRoot->createSceneManager (sceneManager); - system->ogreSceneManager->setShadowTechnique(shadowTechnique); - system->ogreSceneManager->setAmbientLight(Ogre::ColourValue(0.67, 0.94, 1.00)); - system->ogreSceneManager->setShadowColour(Ogre::ColourValue(0.5, 0.5, 0.5)); - // Set default mipmap level (NB some APIs ignore this) - log->__format (LOG_ENDUSER, "Setting up default number of mipmap levels"); - Ogre::TextureManager::getSingleton ().setDefaultNumMipmaps (defaultNumMipMaps); - - // Set some graphics settings - log->__format (LOG_ENDUSER, "Setting up anisotropy and filtering parameters"); - Ogre::MaterialManager::getSingleton ().setDefaultAnisotropy (anisotropy); - Ogre::MaterialManager::getSingleton ().setDefaultTextureFiltering (filtering); - - Ogre::Light * light = System::get()->ogreSceneManager->createLight("Sun"); - //light->setType(Ogre::Light::LT_SPOTLIGHT); - //light->setType(Ogre::Light::LT_POINT); - light->setType(Ogre::Light::LT_DIRECTIONAL); - light->setDirection(0.16,0.2,-1); - //light->setPosition(50, 50, 1); - light->setDiffuseColour(1, 1, 1); - light->setSpecularColour(1, 1, 1); - system->ogreSceneManager->getRootSceneNode()->attachObject (light); - - log->__format (LOG_DEVELOPER, "Removing temporary ogre plugins config file (plugins.cfg)"); - remove("plugins.cfg"); - log->__format (LOG_DEVELOPER, "Removing temporary ogre file"); - remove("removeme.cfg"); -} - Deleted: trunk/src/graphicsEngine.hpp =================================================================== --- trunk/src/graphicsEngine.hpp 2006-06-23 11:48:21 UTC (rev 435) +++ trunk/src/graphicsEngine.hpp 2006-06-23 12:52:52 UTC (rev 436) @@ -1,101 +0,0 @@ -/*****************************************************************************\ -|* Copyright (C) 2003, 2006 "Motorsport" developers (*) *| -|* Part of the "Motorsport" project (http://motorsport.sourceforge.net) *| -|* Licensed under the GNU General Public License (*) *| -|* *| -|* (*) Complete information is provided at the following URL: *| -|* [ http://motorsport-sim.org/svn/trunk/doc/LICENSE ] *| -\*****************************************************************************/ - -#include <common/shared.hpp> - -//forward declarations -class LogEngine; -namespace Ogre { - class Root; -} - -SHARED_PTR_MAP(LogEngine, pLogEngine, LogEngines, LogEnginesIt); -SHARED_PTR(System,pSystem); - -/** Manages everything related to the process of world data graphics rendering on screen. The menues and similar gadgets are not rendered by this engine; only world data is handled here (cars, area, etc...). - * @brief Manages everything related to the rendering process. - */ -class GraphicsEngine -{ - private: - /** This log engine allows the graphics engine to write data in the log file, allowing to be differenciated from other engines. - * @brief Log engine used by the graphics engine. - */ - pLogEngine log; - /** - * @brief Pointer to the system data, used by different engines in order to store common data. - */ - pSystem system; - - /** - * @brief Name of the file were screenshots will be saved. - */ - std::string screenshotFilename; - /** - * @brief Specifies the number where the screenshot filename numbering starts. - */ - int initialFrame; - public: - /** - * @brief Stores the horizontal resolution of the screen. - */ - int width; - /** - * @brief Stores the vertical resolution of the screen. - */ - int height; - /** - * @brief Stores the bits per pixel of depth. - */ - int bpp; - /** - * @brief Specifies whether to use fullScreen mode, or windowed mode. - */ - bool fullScreen; - /** - * @brief Specifies whether the area will cast shadows or not. - */ - bool castAreaShadows; - /** - * @brief Specifies how the vehicle will be rendered: 1=points, 2=wireframe, 3=solid. - */ - int vehicleRenderMode; - /** - * @brief Specifies how the area will be rendered: 1=points, 2=wireframe, 3=solid. - */ - int areaRenderMode; - /** - * @brief The OGRE root element. - */ - Ogre::Root * ogreRoot; - /** Creates a new graphics engine, with its associated own log engine. It initializes all necessary related data, such as initial graphics representation of world data (meshes, textures...), and sets up the underlying rendering libray (Ogre). - * @brief Creates a new graphics engine. - */ - GraphicsEngine (); - /** Deletes de graphics engine, as well as its associated log engine. It also removes all the related data from memory, and shuts down Ogre if necessary. - * @brief Deletes the graphics engine. - */ - ~GraphicsEngine (void); - /** Renders on screen all the world data for this frame. - * @brief Renders all the world data on screen. - * - * @return 0 on success. - */ - int computeStep (void); - /** Selects a renderer and switches to the chosen resolution. If the desired render (OpenGL) is not found, the first available one is then chosen. - * @brief Selects a renderer and switches to the chosen resolution. - * - * @param renderer What renderer to use. For example "OpenGL". Case sensitive. - */ - void manualInitialize (const std::string & renderer); - /** Tells Ogre where to find resources via the resources.cfg file. This allows Ogre to know where all the data (meshes, materials, textures...) can be found, not needing to explicitly indicate it. - * @brief Tells Ogre where to find resources. - */ - void setupResources (); -}; Copied: trunk/src/gui.cpp (from rev 435, trunk/src/guiEngine.cpp) =================================================================== --- trunk/src/gui.cpp (rev 0) +++ trunk/src/gui.cpp 2006-06-23 12:52:52 UTC (rev 436) @@ -0,0 +1,259 @@ +/*****************************************************************************\ +|* Copyright (C) 2003, 2006 "Motorsport" developers (*) *| +|* Part of the "Motorsport" project (http://motorsport.sourceforge.net) *| +|* Licensed under the GNU General Public License (*) *| +|* *| +|* (*) Complete information is provided at the following URL: *| +|* [ http://motorsport-sim.org/svn/trunk/doc/LICENSE ] *| +\*****************************************************************************/ + +#include "gui.hpp" +#include "SDL/SDL.h" +#include "system.hpp" +#include "logEngine.hpp" +#include "Ogre.h" +#include "OgreNoMemoryMacros.h" +#include "xmlTag.hpp" +using namespace Ogre; + +pGui Gui::gui; + +pGui Gui::get() +{ + if (!gui) + { + new Gui(); + } + return (gui); +} +void Gui::destroy() +{ + if (!gui) + { + std::cout << "WARNING: There's no gui to be destroyed!" << std::endl; + } + else + { + gui.reset(); + } +} + +Gui::Gui () +{ + if (gui) + { + gui->log->__format(LOG_ERROR, "Tried to create another gui. This shouldn't have happened."); + } else { + pGui tmp(this); + gui = tmp; +#ifdef MACOSX + XmlTag * tag = new XmlTag ("motorsport.app/Contents/Resources/guiConfig.xml"); +#else + XmlTag * tag = new XmlTag ("../cfg/guiConfig.xml"); +#endif + showStatistics = true; + log = LogEngine::create (LOG_DEVELOPER, "Gui"); + + if (tag->getName() == "guiConfig") + { + showStatistics = stob(tag->getAttribute("showStatistics")); + telemetryLines = stoi(tag->getAttribute("telemetryLines")); + } + delete tag; + + // updating singleton pointer + tmpOgreCamera = 0; + loadscreenText = ""; + lapTime = "Lap Time: n/a"; + time = "Time: n/a"; + } +} + +int Gui::computeStep (void) +//makes the graphics engine draw one frame +{ + log->__format (LOG_DEVELOPER, "Doing an step..."); + //update all statistics every second + static double lastRefreshTime = 0; + if (SDL_GetTicks ()/1000.0 - lastRefreshTime >= 1) + { + updateStatistics (); + lastRefreshTime += 1; + } + //update last telemetry line every frame + OverlayElement *telText = OverlayManager::getSingleton ().getOverlayElement ("telemetry/text"); + telText->setCaption (telemetryText + tempLine); + + Overlay *overlay = (Overlay *) OverlayManager::getSingleton ().getByName ("gui"); + if (!overlay) + { + OGRE_EXCEPT (Exception::ERR_ITEM_NOT_FOUND, "Could not find gui overlay", "statusPanel"); + } + Overlay *telemetryOverlay = (Overlay *) OverlayManager::getSingleton ().getByName ("telemetry"); + if (!telemetryOverlay) + { + OGRE_EXCEPT (Exception::ERR_ITEM_NOT_FOUND, "Could not find telemetry overlay", "statusPanel"); + } + + if (System::get()->axisMap[getIDKeyboardKey(SDLK_g)]->getValue() == 1) + { + log->__format (LOG_ENDUSER, "Showing/hiding statistics on screen."); + showStatistics = !showStatistics; + System::get()->axisMap[getIDKeyboardKey(SDLK_g)]->setNewRawValue(0); //no setRawValues should be out of the input engine; this must be done via filters that convert axis variations into 'events' FIXME + } + if (showStatistics) + { + if (telemetryText.size() != 0) + { + telemetryOverlay->show(); + } + overlay->show (); + } else { + overlay->hide (); + telemetryOverlay->hide (); + } + return (0); +} + +void Gui::showLoadscreen () +{ + OverlayElement *loadscreenHeader = OverlayManager::getSingleton ().getOverlayElement ("loadscreen/header"); + loadscreenHeader->setCaption ("Loading contents and engines. Please wait..."); + + tmpOgreCamera = System::get()->ogreSceneManager->createCamera ("Loadscreen camera"); + tmpOgreCamera->setFixedYawAxis (true, Ogre::Vector3 (0, 0, 1)); + tmpOgreCamera->setPosition (Ogre::Vector3 (-3, 3, 1)); + tmpOgreCamera->lookAt (Ogre::Vector3 (0, 0, 0)); + tmpOgreCamera->setNearClipDistance (0.100); + System::get()->ogreWindow->removeAllViewports (); + System::get()->ogreWindow->addViewport (tmpOgreCamera, -1); + + Overlay *loadscreenOverlay = (Overlay *) OverlayManager::getSingleton ().getByName ("loadscreen"); + if (!loadscreenOverlay) + { + Exception (Exception::ERR_ITEM_NOT_FOUND, "Could not find loadscreen overlay", "statusPanel"); + } + loadscreenOverlay->show(); +} +void Gui::hideLoadscreen () +{ + Overlay *loadscreenOverlay = (Overlay *) OverlayManager::getSingleton ().getByName ("loadscreen"); + if (!loadscreenOverlay) + { + Exception (Exception::ERR_ITEM_NOT_FOUND, "Could not find loadscreen overlay", "statusPanel"); + } + loadscreenOverlay->hide(); + delete tmpOgreCamera; + tmpOgreCamera = NULL; + System::get()->ogreWindow->removeViewport (-1); +} + +void Gui::updateStatistics (void) +{ + OverlayElement *guiAvg = OverlayManager::getSingleton ().getOverlayElement ("gui/AverageFps"); + OverlayElement *guiCurr = OverlayManager::getSingleton ().getOverlayElement ("gui/CurrFps"); + OverlayElement *guiScaledPhysics = OverlayManager::getSingleton ().getOverlayElement ("gui/ScaledPhysicsRate"); + OverlayElement *guiPhysics = OverlayManager::getSingleton ().getOverlayElement ("gui/PhysicsRate"); + const RenderTarget::FrameStats & stats = System::get()->ogreWindow->getStatistics (); + guiAvg->setCaption ("Average Graphics Rate: " + StringConverter::toString (stats.avgFPS) + " fps"); + guiCurr->setCaption ("Current Graphics Rate: " + StringConverter::toString ((float)System::get()->graphicsFrequency) + " fps"); + guiScaledPhysics->setCaption ("Current Physics Rate: " + StringConverter::toString (float(System::get()->getCurrentPhysicsFrequency())) + " Hz (" + StringConverter::toString (float(System::get()->getCurrentPhysicsTimestep() * 1000.0)) + " ms)"); + guiPhysics->setCaption ("Desired Physics Rate: " + StringConverter::toString (float(System::get()->getDesiredPhysicsFrequency())) + " Hz (" + StringConverter::toString (float(System::get()->getDesiredPhysicsTimestep() * 1000.0)) + " ms)" ); + OverlayElement *guiTris = OverlayManager::getSingleton ().getOverlayElement ("gui/NumTris"); + guiTris->setCaption ("Triangle Count: " + StringConverter::toString (stats.triangleCount)); + if (telemetryLines > 0) + { + OverlayElement *telText = OverlayManager::getSingleton ().getOverlayElement ("telemetry/text"); + telemetryText.append (tempLine); + if (telemetryText.size() == 0) + { + telText->setCaption ("Telemetry not active."); + } else { + telemetryText.append ("\n"); + int num = 0; + int lastLineEnd = telemetryText.rfind ('\n', telemetryText.size()-1); + while (lastLineEnd >= 0) + { + num++; + if (num > telemetryLines-1) + { + telemetryText.erase (0, lastLineEnd+1); + lastLineEnd = -1; + } else { + lastLineEnd = telemetryText.rfind ('\n', lastLineEnd-1); + } + } + telText->setCaption (telemetryText + tempLine); + } + } +} + +void Gui::addTelemetryLine (const std::string & line) +{ + if (telemetryLines > 0) + { + if (telemetryText.size() == 0) + { + Overlay *telemetryOverlay = (Overlay *) OverlayManager::getSingleton ().getByName ("telemetry"); + telemetryOverlay->show(); + OverlayElement *telHeader = OverlayManager::getSingleton ().getOverlayElement ("telemetry/header"); + telHeader->setCaption (line); + telemetryText.append (line); + telemetryText.append ("\n"); + } + tempLine.assign (line); + } +} + +void Gui::addLoadscreenLine (const std::string & line) +{ + static unsigned lines = 0; + const unsigned int nchars = 85; + const unsigned int nlines = 26; + std::string tmp = loadscreenText; + loadscreenText.clear(); + std::string tmpline = line; + while (tmpline.size() > nchars) + { + int cutPosition = tmpline.rfind(' ', nchars); + if ( cutPosition < 1) + { + cutPosition = nchars; + } + loadscreenText.append (tmpline.substr(0, cutPosition)); + loadscreenText.append ("\n "); + lines++; + tmpline = tmpline.substr(cutPosition); + } + loadscreenText.append (tmpline); + loadscreenText.append ("\n"); + lines++; + loadscreenText.append (tmp); + OverlayElement *loadText = OverlayManager::getSingleton ().getOverlayElement ("loadscreen/text"); + loadText->setCaption (loadscreenText); + while (lines > nlines) + { + int lastline = loadscreenText.rfind ('\n'); + loadscreenText = loadscreenText.substr(0, lastline); + lines--; + } + System::get()->ogreWindow->update (); +} +void Gui::updateLapTime (double time) +{ + OverlayElement *guiLapTime = OverlayManager::getSingleton ().getOverlayElement ("gui/LapTime"); + double tmpTime = time; + int minutes = int (tmpTime / 60); + tmpTime = tmpTime - (minutes * 60); + guiLapTime->setCaption ("Lap Time: " + StringConverter::toString(float(time)) + " s (" + StringConverter::toString(minutes) + "' " + StringConverter::toString(float(tmpTime)) + "\")"); +} +void Gui::updateTime (double time) +{ + OverlayElement *guiLapTime = OverlayManager::getSingleton ().getOverlayElement ("gui/Time"); + guiLapTime->setCaption ("Time: " + StringConverter::toString (float(time)) + " s"); +} + + +Gui::~Gui (void) +{ +} Copied: trunk/src/gui.hpp (from rev 435, trunk/src/guiEngine.hpp) =================================================================== --- trunk/src/gui.hpp (rev 0) +++ trunk/src/gui.hpp 2006-06-23 12:52:52 UTC (rev 436) @@ -0,0 +1,71 @@ +/*****************************************************************************\ +|* Copyright (C) 2003, 2006 "Motorsport" developers (*) *| +|* Part of the "Motorsport" project (http://motorsport.sourceforge.net) *| +|* Licensed under the GNU General Public License (*) *| +|* *| +|* (*) Complete information is provided at the following URL: *| +|* [ http://motorsport-sim.org/svn/trunk/doc/LICENSE ] *| +\*****************************************************************************/ + +#include "SDL/SDL.h" +#include <common/shared.hpp> + +//forward declaration +namespace Ogre { + class Camera; +}; + +SHARED_PTR_MAP(LogEngine, pLogEngine, LogEngines, LogEnginesIt); +SHARED_PTR(System,pSystem); +SHARED_PTR(Gui,pGui); + +/// Manage... [truncated message content] |
|
From: <st...@us...> - 2006-06-23 11:48:58
|
Revision: 435 Author: stenyak Date: 2006-06-23 04:48:21 -0700 (Fri, 23 Jun 2006) ViewCVS: http://svn.sourceforge.net/motorsport/?rev=435&view=rev Log Message: ----------- Renamed SystemData to System. Ported System pointers to shared pointers. Modified Paths: -------------- trunk/src/common/camera.cpp trunk/src/common/ogreObject.cpp trunk/src/common/worldObject.cpp trunk/src/graphicsEngine.cpp trunk/src/graphicsEngine.hpp trunk/src/guiEngine.cpp trunk/src/guiEngine.hpp trunk/src/inputEngine.cpp trunk/src/inputEngine.hpp trunk/src/log/logEngine.cpp trunk/src/main.cpp trunk/src/physicsEngine.cpp trunk/src/physicsEngine.hpp trunk/src/system.cpp trunk/src/system.hpp trunk/src/todo trunk/src/vehicle/body.cpp trunk/src/vehicle/driveJoint.cpp trunk/src/vehicle/engine.cpp trunk/src/vehicle/finalDrive.cpp trunk/src/vehicle/gearbox.cpp trunk/src/vehicle/pedal.cpp trunk/src/vehicle/suspension.cpp trunk/src/vehicle/vehicle.cpp trunk/src/vehicle/wheel.cpp trunk/src/world/area.cpp trunk/src/world/part.cpp trunk/src/world/world.cpp Modified: trunk/src/common/camera.cpp =================================================================== --- trunk/src/common/camera.cpp 2006-06-23 02:22:08 UTC (rev 434) +++ trunk/src/common/camera.cpp 2006-06-23 11:48:21 UTC (rev 435) @@ -30,7 +30,7 @@ Camera::Camera (WorldObject * container, XmlTag * tag) :WorldObject(container, "camera") { - ogreCamera = SystemData::getSystemDataPointer ()->ogreSceneManager->createCamera (getId()); + ogreCamera = System::get()->ogreSceneManager->createCamera (getId()); ogreCamera->setFixedYawAxis (true, Ogre::Vector3 (0, 0, 1)); ogreCamera->setNearClipDistance (0.100); // ogreCamera->setAutoAspectRatio(true); @@ -146,7 +146,7 @@ if (this == World::get()->getActiveCamera().get() ) { static bool wasPressed = false; - if (SystemData::getSystemDataPointer()->axisMap[getIDKeyboardKey(SDLK_x)]->getValue() == 1) + if (System::get()->axisMap[getIDKeyboardKey(SDLK_x)]->getValue() == 1) { if (!wasPressed) { @@ -160,47 +160,47 @@ { // Move the camera Ogre::Vector3 test; - float moveX = SystemData::getSystemDataPointer()->axisMap[getIDKeyboardKey(SDLK_f)]->getValue(); - float moveY = SystemData::getSystemDataPointer()->axisMap[getIDKeyboardKey(SDLK_e)]->getValue(); - float moveZ = SystemData::getSystemDataPointer()->axisMap[getIDKeyboardKey(SDLK_r)]->getValue(); - moveX *= SystemData::getSystemDataPointer()->getDesiredPhysicsTimestep() * 1000; - moveY *= SystemData::getSystemDataPointer()->getDesiredPhysicsTimestep() * 1000; - moveZ *= SystemData::getSystemDataPointer()->getDesiredPhysicsTimestep() * 1000; + float moveX = System::get()->axisMap[getIDKeyboardKey(SDLK_f)]->getValue(); + float moveY = System::get()->axisMap[getIDKeyboardKey(SDLK_e)]->getValue(); + float moveZ = System::get()->axisMap[getIDKeyboardKey(SDLK_r)]->getValue(); + moveX *= System::get()->getDesiredPhysicsTimestep() * 1000; + moveY *= System::get()->getDesiredPhysicsTimestep() * 1000; + moveZ *= System::get()->getDesiredPhysicsTimestep() * 1000; ogreCamera->moveRelative (Ogre::Vector3 (moveX / 200, moveZ / 500, -moveY / 200)); - moveX = -SystemData::getSystemDataPointer()->axisMap[getIDKeyboardKey(SDLK_s)]->getValue(); - moveY = -SystemData::getSystemDataPointer()->axisMap[getIDKeyboardKey(SDLK_d)]->getValue(); - moveZ = -SystemData::getSystemDataPointer()->axisMap[getIDKeyboardKey(SDLK_w)]->getValue(); - moveX *= SystemData::getSystemDataPointer()->getDesiredPhysicsTimestep() * 1000; - moveY *= SystemData::getSystemDataPointer()->getDesiredPhysicsTimestep() * 1000; - moveZ *= SystemData::getSystemDataPointer()->getDesiredPhysicsTimestep() * 1000; + moveX = -System::get()->axisMap[getIDKeyboardKey(SDLK_s)]->getValue(); + moveY = -System::get()->axisMap[getIDKeyboardKey(SDLK_d)]->getValue(); + moveZ = -System::get()->axisMap[getIDKeyboardKey(SDLK_w)]->getValue(); + moveX *= System::get()->getDesiredPhysicsTimestep() * 1000; + moveY *= System::get()->getDesiredPhysicsTimestep() * 1000; + moveZ *= System::get()->getDesiredPhysicsTimestep() * 1000; ogreCamera->moveRelative (Ogre::Vector3 (moveX / 200, moveZ / 500, -moveY / 200)); // Rotate the camera - float rotX = -SystemData::getSystemDataPointer()->axisMap[getIDMouseAxis(0)]->getValue() + 0.5; - float rotY = SystemData::getSystemDataPointer()->axisMap[getIDMouseAxis(1)]->getValue() - 0.5; + float rotX = -System::get()->axisMap[getIDMouseAxis(0)]->getValue() + 0.5; + float rotY = System::get()->axisMap[getIDMouseAxis(1)]->getValue() - 0.5; if (rotX < 0.05 && rotX > -0.05) rotX = 0; if (rotY < 0.05 && rotY > -0.05) rotY = 0; - rotX *= SystemData::getSystemDataPointer()->getDesiredPhysicsTimestep() * 1000; - rotY *= SystemData::getSystemDataPointer()->getDesiredPhysicsTimestep() * 1000; + rotX *= System::get()->getDesiredPhysicsTimestep() * 1000; + rotY *= System::get()->getDesiredPhysicsTimestep() * 1000; ogreCamera->yaw (Ogre::Radian(rotX / 500)); ogreCamera->pitch(Ogre::Radian(rotY / 500)); } else { // Move the camera - float moveX = SystemData::getSystemDataPointer()->axisMap[getIDKeyboardKey(SDLK_w)]->getValue(); - float moveY = SystemData::getSystemDataPointer()->axisMap[getIDKeyboardKey(SDLK_s)]->getValue(); - float moveZ = SystemData::getSystemDataPointer()->axisMap[getIDKeyboardKey(SDLK_r)]->getValue(); - moveX *= SystemData::getSystemDataPointer()->getDesiredPhysicsTimestep() * 1000; - moveY *= SystemData::getSystemDataPointer()->getDesiredPhysicsTimestep() * 1000; - moveZ *= SystemData::getSystemDataPointer()->getDesiredPhysicsTimestep() * 1000; + float moveX = System::get()->axisMap[getIDKeyboardKey(SDLK_w)]->getValue(); + float moveY = System::get()->axisMap[getIDKeyboardKey(SDLK_s)]->getValue(); + float moveZ = System::get()->axisMap[getIDKeyboardKey(SDLK_r)]->getValue(); + moveX *= System::get()->getDesiredPhysicsTimestep() * 1000; + moveY *= System::get()->getDesiredPhysicsTimestep() * 1000; + moveZ *= System::get()->getDesiredPhysicsTimestep() * 1000; *positionOffset += Vector3d(moveX/1000, moveY/1000, moveZ/1000); - moveX = -SystemData::getSystemDataPointer()->axisMap[getIDKeyboardKey(SDLK_d)]->getValue(); - moveY = -SystemData::getSystemDataPointer()->axisMap[getIDKeyboardKey(SDLK_e)]->getValue(); - moveZ = -SystemData::getSystemDataPointer()->axisMap[getIDKeyboardKey(SDLK_f)]->getValue(); - moveX *= SystemData::getSystemDataPointer()->getDesiredPhysicsTimestep() * 1000; - moveY *= SystemData::getSystemDataPointer()->getDesiredPhysicsTimestep() * 1000; - moveZ *= SystemData::getSystemDataPointer()->getDesiredPhysicsTimestep() * 1000; + moveX = -System::get()->axisMap[getIDKeyboardKey(SDLK_d)]->getValue(); + moveY = -System::get()->axisMap[getIDKeyboardKey(SDLK_e)]->getValue(); + moveZ = -System::get()->axisMap[getIDKeyboardKey(SDLK_f)]->getValue(); + moveX *= System::get()->getDesiredPhysicsTimestep() * 1000; + moveY *= System::get()->getDesiredPhysicsTimestep() * 1000; + moveZ *= System::get()->getDesiredPhysicsTimestep() * 1000; *positionOffset += Vector3d(moveX/1000, moveY/1000, moveZ/1000); } Modified: trunk/src/common/ogreObject.cpp =================================================================== --- trunk/src/common/ogreObject.cpp 2006-06-23 02:22:08 UTC (rev 434) +++ trunk/src/common/ogreObject.cpp 2006-06-23 11:48:21 UTC (rev 435) @@ -40,14 +40,14 @@ if (useMesh) { - entity = SystemData::getSystemDataPointer ()->ogreSceneManager->createEntity (id, meshPath); + entity = System::get()->ogreSceneManager->createEntity (id, meshPath); entity->setCastShadows(true); for(unsigned int i = 0; i < entity->getNumSubEntities(); i++) { worldObject->getLog()->__format(LOG_CCREATOR, "Entity submesh #%i material: %s.", i, entity->getSubEntity(i)->getMaterialName().c_str() ); } } - node = static_cast<Ogre::SceneNode*>(SystemData::getSystemDataPointer()->ogreSceneManager->getRootSceneNode()->createChild()); + node = static_cast<Ogre::SceneNode*>(System::get()->ogreSceneManager->getRootSceneNode()->createChild()); if (useMesh) { node->attachObject (entity); @@ -61,12 +61,12 @@ worldObject->getLog()->__format (LOG_DEVELOPER, "Removing entity id=%s", entity->getName().c_str()); node->detachObject(entity); if (entity->isAttached()) worldObject->getLog()->__format(LOG_WARNING, "Entity \"%s\" (%s) still attached somewhere!.", name.c_str(), entity->getName().c_str()); - SystemData::getSystemDataPointer()->ogreSceneManager->destroyEntity (entity); + System::get()->ogreSceneManager->destroyEntity (entity); entity = NULL; } worldObject->getLog()->__format (LOG_DEVELOPER, "Removing node id=%s", node->getName().c_str()); - SystemData::getSystemDataPointer()->ogreSceneManager->destroySceneNode (node->getName()); + System::get()->ogreSceneManager->destroySceneNode (node->getName()); node = NULL; this->worldObject = NULL; @@ -78,7 +78,7 @@ void OgreObject::setOgreReference(pOgreObject ogreObject, Quaternion rotationDiff, Vector3d positionDiff, Vector3d scale) { - static_cast<Ogre::SceneNode*>(SystemData::getSystemDataPointer()->ogreSceneManager->getRootSceneNode())->removeChild(node); + static_cast<Ogre::SceneNode*>(System::get()->ogreSceneManager->getRootSceneNode())->removeChild(node); ogreObject->getNode()->addChild(node); Ogre::Vector3 * pd = new Ogre::Vector3(positionDiff.x, positionDiff.y, positionDiff.z); Ogre::Quaternion * rd = new Ogre::Quaternion (rotationDiff.w, rotationDiff.x, rotationDiff.y, rotationDiff.z); Modified: trunk/src/common/worldObject.cpp =================================================================== --- trunk/src/common/worldObject.cpp 2006-06-23 02:22:08 UTC (rev 434) +++ trunk/src/common/worldObject.cpp 2006-06-23 11:48:21 UTC (rev 435) @@ -38,7 +38,6 @@ //FIXME what to use, id# or name? log = LogEngine::create (LOG_DEVELOPER, this->getFullName()); - //log = new LogEngine (LOG_DEVELOPER, this->id); log->__format(LOG_CCREATOR, "Id #%s. Full Name: %s", id.c_str(), getFullName().c_str()); worldObjects[this->id] = this; } Modified: trunk/src/graphicsEngine.cpp =================================================================== --- trunk/src/graphicsEngine.cpp 2006-06-23 02:22:08 UTC (rev 434) +++ trunk/src/graphicsEngine.cpp 2006-06-23 11:48:21 UTC (rev 435) @@ -76,12 +76,12 @@ { Vector3d rotAngles (0, 0, 0); // Sun controller. FIXME the sun should be a class, physically behaved. */ - if (systemData->axisMap[getIDKeyboardKey(SDLK_o)]->getValue() == 1) + if (system->axisMap[getIDKeyboardKey(SDLK_o)]->getValue() == 1) { // Increase degree by degree, in Y axis. rotAngles.y++; } - if (systemData->axisMap[getIDKeyboardKey(SDLK_p)]->getValue() == 1) + if (system->axisMap[getIDKeyboardKey(SDLK_p)]->getValue() == 1) { // Increase degree by degree, in Y axis. rotAngles.y--; @@ -91,7 +91,7 @@ Quaternion rotation (rotAngles.x, rotAngles.y, rotAngles.z); // Calculate and set the new direction of the sun light rays. - Ogre::Light * light = SystemData::getSystemDataPointer ()->ogreSceneManager->getLight("Sun"); + Ogre::Light * light = System::get()->ogreSceneManager->getLight("Sun"); Vector3d direction (light->getDirection().x, light->getDirection().y, light->getDirection().z); direction = rotation.rotateObject(direction); light->setDirection(direction.x, direction.y, direction.z); @@ -118,7 +118,7 @@ { // Linearly interpolate light values. r = mina - ( ( ( z - min ) / ( med - min ) ) * (mina - meda) ); - systemData->ogreSceneManager->setAmbientLight(Ogre::ColourValue(r.x, r.y, r.z)); + system->ogreSceneManager->setAmbientLight(Ogre::ColourValue(r.x, r.y, r.z)); r = minl - ( ( ( z - min ) / ( med - min ) ) * (minl - medl) ); light->setDiffuseColour (r.x, r.y, r.z); @@ -129,7 +129,7 @@ { // Linearly interpolate light values. r = meda - ( ( ( z - med ) / ( max - med ) ) * (meda - maxa) ); - systemData->ogreSceneManager->setAmbientLight(Ogre::ColourValue(r.x, r.y, r.z)); + system->ogreSceneManager->setAmbientLight(Ogre::ColourValue(r.x, r.y, r.z)); r = medl - ( ( ( z - med ) / ( max - med ) ) * (medl - maxl) ); light->setDiffuseColour (r.x, r.y, r.z); @@ -138,17 +138,17 @@ } // take a screenshot if neededa - if (systemData->axisMap[getIDKeyboardKey(SDLK_PRINT)]->getValue() == 1) + if (system->axisMap[getIDKeyboardKey(SDLK_PRINT)]->getValue() == 1) { static unsigned int count = initialFrame; static char tmpName[64]; sprintf (tmpName, screenshotFilename.c_str(), count++); log->__format (LOG_ENDUSER, "Taking a screenshot in %s.", tmpName); - systemData->ogreWindow->writeContentsToFile (tmpName); + system->ogreWindow->writeContentsToFile (tmpName); } // change camera if needed - if (systemData->axisMap[getIDKeyboardKey(SDLK_c)]->getValue() == 1) + if (system->axisMap[getIDKeyboardKey(SDLK_c)]->getValue() == 1) { CamerasIt i = World::get()->areas.begin()->second->cameras.begin(); pCamera nextCam = i->second; @@ -168,7 +168,7 @@ World::get()->setActiveCamera(nextCam); World::get()->activeAreaCamera = nextCam; } - if (systemData->axisMap[getIDKeyboardKey(SDLK_v)]->getValue() == 1) + if (system->axisMap[getIDKeyboardKey(SDLK_v)]->getValue() == 1) { CamerasIt i = World::get()->vehicles.begin()->second->cameras.begin(); pCamera nextCam = i->second; @@ -188,7 +188,7 @@ World::get()->setActiveCamera(nextCam); World::get()->activeVehicleCamera = nextCam; } - if (systemData->cameraDirector) + if (system->cameraDirector) { log->__format(LOG_DEVELOPER, "Finding closest camera"); Vector3d vPos = World::get()->vehicles.begin()->second->getPosition(); @@ -254,7 +254,7 @@ // Let the listener frames be started and ended: they are needed for particle systems. ogreRoot->_fireFrameStarted (); - systemData->ogreWindow->update (); + system->ogreWindow->update (); ogreRoot->_fireFrameEnded (); return (0); @@ -263,7 +263,7 @@ GraphicsEngine::~GraphicsEngine (void) { log->__format (LOG_DEVELOPER, "Unloading ogre window data from memory..."); - delete (systemData->ogreWindow); + delete (system->ogreWindow); } GraphicsEngine::GraphicsEngine () @@ -349,10 +349,10 @@ // get the direction of the graphics data log->__format (LOG_DEVELOPER, "Setting up data pointers..."); - systemData = SystemData::getSystemDataPointer (); + system = System::get(); - systemData->height = height; - systemData->width = width; + system->height = height; + system->width = width; log->__format (LOG_DEVELOPER, "Graphics data initialized to %ix%i@%ibpp", width, height, bpp); log->__format (LOG_DEVELOPER, "Creating temporary ogre plugins config file (plugins.cfg)"); @@ -399,7 +399,7 @@ // Here we choose to let the system create a default rendering window log->__format (LOG_DEVELOPER, "Initializing ogre root element"); - systemData->ogreWindow = ogreRoot->initialise (true); + system->ogreWindow = ogreRoot->initialise (true); setupResources (); #ifdef WIN32 @@ -407,17 +407,17 @@ // New method: As proposed by Sinbad. // This method always works. HWND hWnd; - systemData->ogreWindow->getCustomAttribute("HWND", &hWnd); + system->ogreWindow->getCustomAttribute("HWND", &hWnd); sprintf(tmp, "SDL_WINDOWID=%d", hWnd); _putenv(tmp); #endif log->__format (LOG_DEVELOPER, "Getting ogre scene manager"); // Set shadowing system - systemData->ogreSceneManager = ogreRoot->createSceneManager (sceneManager); - systemData->ogreSceneManager->setShadowTechnique(shadowTechnique); - systemData->ogreSceneManager->setAmbientLight(Ogre::ColourValue(0.67, 0.94, 1.00)); - systemData->ogreSceneManager->setShadowColour(Ogre::ColourValue(0.5, 0.5, 0.5)); + system->ogreSceneManager = ogreRoot->createSceneManager (sceneManager); + system->ogreSceneManager->setShadowTechnique(shadowTechnique); + system->ogreSceneManager->setAmbientLight(Ogre::ColourValue(0.67, 0.94, 1.00)); + system->ogreSceneManager->setShadowColour(Ogre::ColourValue(0.5, 0.5, 0.5)); // Set default mipmap level (NB some APIs ignore this) log->__format (LOG_ENDUSER, "Setting up default number of mipmap levels"); Ogre::TextureManager::getSingleton ().setDefaultNumMipmaps (defaultNumMipMaps); @@ -427,7 +427,7 @@ Ogre::MaterialManager::getSingleton ().setDefaultAnisotropy (anisotropy); Ogre::MaterialManager::getSingleton ().setDefaultTextureFiltering (filtering); - Ogre::Light * light = SystemData::getSystemDataPointer ()->ogreSceneManager->createLight("Sun"); + Ogre::Light * light = System::get()->ogreSceneManager->createLight("Sun"); //light->setType(Ogre::Light::LT_SPOTLIGHT); //light->setType(Ogre::Light::LT_POINT); light->setType(Ogre::Light::LT_DIRECTIONAL); @@ -435,7 +435,7 @@ //light->setPosition(50, 50, 1); light->setDiffuseColour(1, 1, 1); light->setSpecularColour(1, 1, 1); - systemData->ogreSceneManager->getRootSceneNode()->attachObject (light); + system->ogreSceneManager->getRootSceneNode()->attachObject (light); log->__format (LOG_DEVELOPER, "Removing temporary ogre plugins config file (plugins.cfg)"); remove("plugins.cfg"); Modified: trunk/src/graphicsEngine.hpp =================================================================== --- trunk/src/graphicsEngine.hpp 2006-06-23 02:22:08 UTC (rev 434) +++ trunk/src/graphicsEngine.hpp 2006-06-23 11:48:21 UTC (rev 435) @@ -7,17 +7,17 @@ |* [ http://motorsport-sim.org/svn/trunk/doc/LICENSE ] *| \*****************************************************************************/ -#include <string> -#include <boost/shared_ptr.hpp> +#include <common/shared.hpp> //forward declarations -class SystemData; class LogEngine; -typedef boost::shared_ptr<LogEngine> pLogEngine; namespace Ogre { class Root; } +SHARED_PTR_MAP(LogEngine, pLogEngine, LogEngines, LogEnginesIt); +SHARED_PTR(System,pSystem); + /** Manages everything related to the process of world data graphics rendering on screen. The menues and similar gadgets are not rendered by this engine; only world data is handled here (cars, area, etc...). * @brief Manages everything related to the rendering process. */ @@ -31,7 +31,7 @@ /** * @brief Pointer to the system data, used by different engines in order to store common data. */ - SystemData *systemData; + pSystem system; /** * @brief Name of the file were screenshots will be saved. Modified: trunk/src/guiEngine.cpp =================================================================== --- trunk/src/guiEngine.cpp 2006-06-23 02:22:08 UTC (rev 434) +++ trunk/src/guiEngine.cpp 2006-06-23 11:48:21 UTC (rev 435) @@ -46,7 +46,7 @@ // get the direction of the graphics data log->__format (LOG_DEVELOPER, "Setting up data pointers..."); - systemData = SystemData::getSystemDataPointer (); + system = System::get(); // updating singleton pointer guiEnginePointer = this; @@ -83,11 +83,11 @@ OGRE_EXCEPT (Exception::ERR_ITEM_NOT_FOUND, "Could not find telemetry overlay", "statusPanel"); } - if (systemData->axisMap[getIDKeyboardKey(SDLK_g)]->getValue() == 1) + if (system->axisMap[getIDKeyboardKey(SDLK_g)]->getValue() == 1) { log->__format (LOG_ENDUSER, "Showing/hiding statistics on screen."); showStatistics = !showStatistics; - systemData->axisMap[getIDKeyboardKey(SDLK_g)]->setNewRawValue(0); //no setRawValues should be out of the input engine; this must be done via filters that convert axis variations into 'events' FIXME + system->axisMap[getIDKeyboardKey(SDLK_g)]->setNewRawValue(0); //no setRawValues should be out of the input engine; this must be done via filters that convert axis variations into 'events' FIXME } if (showStatistics) { @@ -108,13 +108,13 @@ OverlayElement *loadscreenHeader = OverlayManager::getSingleton ().getOverlayElement ("loadscreen/header"); loadscreenHeader->setCaption ("Loading contents and engines. Please wait..."); - tmpOgreCamera = SystemData::getSystemDataPointer ()->ogreSceneManager->createCamera ("Loadscreen camera"); + tmpOgreCamera = System::get()->ogreSceneManager->createCamera ("Loadscreen camera"); tmpOgreCamera->setFixedYawAxis (true, Ogre::Vector3 (0, 0, 1)); tmpOgreCamera->setPosition (Ogre::Vector3 (-3, 3, 1)); tmpOgreCamera->lookAt (Ogre::Vector3 (0, 0, 0)); tmpOgreCamera->setNearClipDistance (0.100); - SystemData::getSystemDataPointer()->ogreWindow->removeAllViewports (); - SystemData::getSystemDataPointer()->ogreWindow->addViewport (tmpOgreCamera, -1); + System::get()->ogreWindow->removeAllViewports (); + System::get()->ogreWindow->addViewport (tmpOgreCamera, -1); Overlay *loadscreenOverlay = (Overlay *) OverlayManager::getSingleton ().getByName ("loadscreen"); if (!loadscreenOverlay) @@ -133,7 +133,7 @@ loadscreenOverlay->hide(); delete tmpOgreCamera; tmpOgreCamera = NULL; - SystemData::getSystemDataPointer()->ogreWindow->removeViewport (-1); + System::get()->ogreWindow->removeViewport (-1); } void GuiEngine::updateStatistics (void) @@ -142,11 +142,11 @@ OverlayElement *guiCurr = OverlayManager::getSingleton ().getOverlayElement ("gui/CurrFps"); OverlayElement *guiScaledPhysics = OverlayManager::getSingleton ().getOverlayElement ("gui/ScaledPhysicsRate"); OverlayElement *guiPhysics = OverlayManager::getSingleton ().getOverlayElement ("gui/PhysicsRate"); - const RenderTarget::FrameStats & stats = systemData->ogreWindow->getStatistics (); + const RenderTarget::FrameStats & stats = system->ogreWindow->getStatistics (); guiAvg->setCaption ("Average Graphics Rate: " + StringConverter::toString (stats.avgFPS) + " fps"); - guiCurr->setCaption ("Current Graphics Rate: " + StringConverter::toString ((float)systemData->graphicsFrequency) + " fps"); - guiScaledPhysics->setCaption ("Current Physics Rate: " + StringConverter::toString (float(systemData->getCurrentPhysicsFrequency())) + " Hz (" + StringConverter::toString (float(systemData->getCurrentPhysicsTimestep() * 1000.0)) + " ms)"); - guiPhysics->setCaption ("Desired Physics Rate: " + StringConverter::toString (float(systemData->getDesiredPhysicsFrequency())) + " Hz (" + StringConverter::toString (float(systemData->getDesiredPhysicsTimestep() * 1000.0)) + " ms)" ); + guiCurr->setCaption ("Current Graphics Rate: " + StringConverter::toString ((float)system->graphicsFrequency) + " fps"); + guiScaledPhysics->setCaption ("Current Physics Rate: " + StringConverter::toString (float(system->getCurrentPhysicsFrequency())) + " Hz (" + StringConverter::toString (float(system->getCurrentPhysicsTimestep() * 1000.0)) + " ms)"); + guiPhysics->setCaption ("Desired Physics Rate: " + StringConverter::toString (float(system->getDesiredPhysicsFrequency())) + " Hz (" + StringConverter::toString (float(system->getDesiredPhysicsTimestep() * 1000.0)) + " ms)" ); OverlayElement *guiTris = OverlayManager::getSingleton ().getOverlayElement ("gui/NumTris"); guiTris->setCaption ("Triangle Count: " + StringConverter::toString (stats.triangleCount)); if (telemetryLines > 0) @@ -225,7 +225,7 @@ loadscreenText = loadscreenText.substr(0, lastline); lines--; } - SystemData::getSystemDataPointer()->ogreWindow->update (); + System::get()->ogreWindow->update (); } void GuiEngine::updateLapTime (double time) { Modified: trunk/src/guiEngine.hpp =================================================================== --- trunk/src/guiEngine.hpp 2006-06-23 02:22:08 UTC (rev 434) +++ trunk/src/guiEngine.hpp 2006-06-23 11:48:21 UTC (rev 435) @@ -8,15 +8,16 @@ \*****************************************************************************/ #include "SDL/SDL.h" -#include <shared.hpp> +#include <common/shared.hpp> //forward declaration -class SystemData; -SHARED_PTR_MAP(LogEngine, pLogEngine, LogEngines, LogEnginesIt); namespace Ogre { class Camera; }; +SHARED_PTR_MAP(LogEngine, pLogEngine, LogEngines, LogEnginesIt); +SHARED_PTR(System,pSystem); + /// Manages everything related to the gui rendering process. /** Manages everything related to the process of system data (graphical user interface) graphics rendering on screen (menues and similar gadgets) */ @@ -29,7 +30,7 @@ */ pLogEngine log; // / Pointer to the system data, used by different engines in order to store common data. - SystemData *systemData; + pSystem system; // / Allows or disallows to show statistics on screen bool showStatistics; std::string telemetryText; Modified: trunk/src/inputEngine.cpp =================================================================== --- trunk/src/inputEngine.cpp 2006-06-23 02:22:08 UTC (rev 434) +++ trunk/src/inputEngine.cpp 2006-06-23 11:48:21 UTC (rev 435) @@ -30,32 +30,32 @@ log = LogEngine::create (LOG_DEVELOPER, "InputEngine"); log->__format (LOG_DEVELOPER, "Setting up data pointers..."); - systemData = SystemData::getSystemDataPointer (); + system = System::get(); log->__format (LOG_DEVELOPER, "Initializing mouse axis"); - systemData->axisMap[getIDMouseAxis (0)] = new Axis; //axis X, mouse #1 - systemData->axisMap[getIDMouseAxis (1)] = new Axis; //axis Y, mouse #1 - systemData->axisMap[getIDMouseAxis (0)]->setNewRawValue (systemData->width); - systemData->axisMap[getIDMouseAxis (0)]->setNewRawValue (0); - systemData->axisMap[getIDMouseAxis (1)]->setNewRawValue (-systemData->height); - systemData->axisMap[getIDMouseAxis (1)]->setNewRawValue (0); + system->axisMap[getIDMouseAxis (0)] = new Axis; //axis X, mouse #1 + system->axisMap[getIDMouseAxis (1)] = new Axis; //axis Y, mouse #1 + system->axisMap[getIDMouseAxis (0)]->setNewRawValue (system->width); + system->axisMap[getIDMouseAxis (0)]->setNewRawValue (0); + system->axisMap[getIDMouseAxis (1)]->setNewRawValue (-system->height); + system->axisMap[getIDMouseAxis (1)]->setNewRawValue (0); log->__format (LOG_DEVELOPER, "Initializing keyboard axis"); for (int i=SDLK_FIRST; i<SDLK_LAST; i++) { - systemData->axisMap[getIDKeyboardKey (i)] = new Axis; - systemData->axisMap[getIDKeyboardKey (i)]->setNewRawValue (1); - systemData->axisMap[getIDKeyboardKey (i)]->setNewRawValue (0); + system->axisMap[getIDKeyboardKey (i)] = new Axis; + system->axisMap[getIDKeyboardKey (i)]->setNewRawValue (1); + system->axisMap[getIDKeyboardKey (i)]->setNewRawValue (0); } log->__format (LOG_DEVELOPER, "Initializing dummy joystick devices"); - systemData->axisMap[getIDJoyAxis (0, 0)] = new Axis; - systemData->axisMap[getIDJoyAxis (0, 1)] = new Axis; - systemData->axisMap[getIDJoyAxis (0, 1)]->setNewRawValue (0); - systemData->axisMap[getIDJoyAxis (0, 1)]->setNewRawValue (1); - systemData->axisMap[getIDJoyAxis (0, 2)] = new Axis; - systemData->axisMap[getIDJoyAxis (0, 2)]->setNewRawValue (0); - systemData->axisMap[getIDJoyAxis (0, 2)]->setNewRawValue (1); + system->axisMap[getIDJoyAxis (0, 0)] = new Axis; + system->axisMap[getIDJoyAxis (0, 1)] = new Axis; + system->axisMap[getIDJoyAxis (0, 1)]->setNewRawValue (0); + system->axisMap[getIDJoyAxis (0, 1)]->setNewRawValue (1); + system->axisMap[getIDJoyAxis (0, 2)] = new Axis; + system->axisMap[getIDJoyAxis (0, 2)]->setNewRawValue (0); + system->axisMap[getIDJoyAxis (0, 2)]->setNewRawValue (1); log->__format (LOG_DEVELOPER, "Initializing real joystick devices"); int nJoysticks = SDL_NumJoysticks(); @@ -69,20 +69,20 @@ { if (!( (joy == 0) && ((axis == 0)||(axis==1)||(axis==2)) )) { - systemData->axisMap[getIDJoyAxis (joy, axis)] = new Axis; + system->axisMap[getIDJoyAxis (joy, axis)] = new Axis; } if (axis == 1 || axis == 2) { - systemData->axisMap[getIDJoyAxis (joy, axis)]->setNewRawValue (0); - systemData->axisMap[getIDJoyAxis (joy, axis)]->setNewRawValue (1); + system->axisMap[getIDJoyAxis (joy, axis)]->setNewRawValue (0); + system->axisMap[getIDJoyAxis (joy, axis)]->setNewRawValue (1); } - log->__format (LOG_DEVELOPER, "Joystick axis #%i initialized. %f", getIDJoyAxis(joy, axis), SystemData::getSystemDataPointer()->axisMap[getIDJoyAxis (joy, axis)]->getValue()); + log->__format (LOG_DEVELOPER, "Joystick axis #%i initialized. %f", getIDJoyAxis(joy, axis), System::get()->axisMap[getIDJoyAxis (joy, axis)]->getValue()); } for (int button = 0; button < nButtons; button++) { - systemData->axisMap[getIDJoyButton (joy, button)] = new Axis; - SystemData::getSystemDataPointer()->axisMap[getIDJoyButton (joy, button)]->setNewRawValue (1); - SystemData::getSystemDataPointer()->axisMap[getIDJoyButton (joy, button)]->setNewRawValue (0); + system->axisMap[getIDJoyButton (joy, button)] = new Axis; + System::get()->axisMap[getIDJoyButton (joy, button)]->setNewRawValue (1); + System::get()->axisMap[getIDJoyButton (joy, button)]->setNewRawValue (0); log->__format (LOG_DEVELOPER, "Joystick axis #%i initialized.", getIDJoyButton(joy, button)); } } @@ -100,20 +100,20 @@ void InputEngine::clearLogicEventAxis () { - SystemData::getSystemDataPointer()->axisMap[getIDKeyboardKey (SDLK_HOME)]->setNewRawValue(0); - SystemData::getSystemDataPointer()->axisMap[getIDKeyboardKey (SDLK_END)]->setNewRawValue(0); - SystemData::getSystemDataPointer()->axisMap[getIDKeyboardKey (SDLK_KP_MINUS)]->setNewRawValue(0); - SystemData::getSystemDataPointer()->axisMap[getIDKeyboardKey (SDLK_KP_PLUS)]->setNewRawValue(0); - SystemData::getSystemDataPointer()->axisMap[getIDKeyboardKey (SDLK_a)]->setNewRawValue(0); - SystemData::getSystemDataPointer()->axisMap[getIDKeyboardKey (SDLK_z)]->setNewRawValue(0); + System::get()->axisMap[getIDKeyboardKey (SDLK_HOME)]->setNewRawValue(0); + System::get()->axisMap[getIDKeyboardKey (SDLK_END)]->setNewRawValue(0); + System::get()->axisMap[getIDKeyboardKey (SDLK_KP_MINUS)]->setNewRawValue(0); + System::get()->axisMap[getIDKeyboardKey (SDLK_KP_PLUS)]->setNewRawValue(0); + System::get()->axisMap[getIDKeyboardKey (SDLK_a)]->setNewRawValue(0); + System::get()->axisMap[getIDKeyboardKey (SDLK_z)]->setNewRawValue(0); } void InputEngine::clearGraphicsEventAxis () { - SystemData::getSystemDataPointer()->axisMap[getIDKeyboardKey (SDLK_PRINT)]->setNewRawValue(0); - SystemData::getSystemDataPointer()->axisMap[getIDKeyboardKey (SDLK_c)]->setNewRawValue(0); - SystemData::getSystemDataPointer()->axisMap[getIDKeyboardKey (SDLK_v)]->setNewRawValue(0); - SystemData::getSystemDataPointer()->axisMap[getIDKeyboardKey (SDLK_b)]->setNewRawValue(0); + System::get()->axisMap[getIDKeyboardKey (SDLK_PRINT)]->setNewRawValue(0); + System::get()->axisMap[getIDKeyboardKey (SDLK_c)]->setNewRawValue(0); + System::get()->axisMap[getIDKeyboardKey (SDLK_v)]->setNewRawValue(0); + System::get()->axisMap[getIDKeyboardKey (SDLK_b)]->setNewRawValue(0); } int InputEngine::computeStep (void) @@ -127,45 +127,45 @@ { case SDL_QUIT: log->__format (LOG_DEVELOPER, "New SDL_QUIT event: User wants to exit. Notifying to stop mainLoop..."); - systemData->disableMainLoop (); + system->disableMainLoop (); break; case SDL_KEYUP: axisIDtoStr(getIDKeyboardKey (event.key.keysym.sym), tmpString); log->__format (LOG_DEVELOPER, "New SDL_KEYUP event: %s", tmpString.c_str()); - SystemData::getSystemDataPointer()->axisMap[getIDKeyboardKey (event.key.keysym.sym)]->setNewRawValue(0); + System::get()->axisMap[getIDKeyboardKey (event.key.keysym.sym)]->setNewRawValue(0); break; case SDL_KEYDOWN: axisIDtoStr(getIDKeyboardKey (event.key.keysym.sym), tmpString); log->__format (LOG_DEVELOPER, "New SDL_KEYDOWN event: %s", tmpString.c_str()); - SystemData::getSystemDataPointer()->axisMap[getIDKeyboardKey (event.key.keysym.sym)]->setNewRawValue(1); + System::get()->axisMap[getIDKeyboardKey (event.key.keysym.sym)]->setNewRawValue(1); break; case SDL_MOUSEMOTION: axisIDtoStr(getIDMouseAxis (0), tmpString); log->__format (LOG_DEVELOPER, "New SDL_MOUSEMOTION event: %s", tmpString.c_str()); axisIDtoStr(getIDMouseAxis (1), tmpString); log->__format (LOG_DEVELOPER, "New SDL_MOUSEMOTION event: %s", tmpString.c_str()); - SystemData::getSystemDataPointer()->axisMap[getIDMouseAxis (0)]->setNewRawValue (event.motion.x); - SystemData::getSystemDataPointer()->axisMap[getIDMouseAxis (1)]->setNewRawValue (-event.motion.y); + System::get()->axisMap[getIDMouseAxis (0)]->setNewRawValue (event.motion.x); + System::get()->axisMap[getIDMouseAxis (1)]->setNewRawValue (-event.motion.y); log->__format (LOG_DEVELOPER, "Mouse movement: (%i, %i)", event.motion.x, -event.motion.y); break; case SDL_JOYAXISMOTION: id = getIDJoyAxis (event.jaxis.which, event.jaxis.axis); axisIDtoStr(id, tmpString); log->__format (LOG_DEVELOPER, "New SDL_JOYAXISMOTION event: %s", tmpString.c_str()); - SystemData::getSystemDataPointer()->axisMap[id]->setNewRawValue (event.jaxis.value); + System::get()->axisMap[id]->setNewRawValue (event.jaxis.value); log->__format (LOG_DEVELOPER, "Joystick axis movement: (%i)", event.jaxis.value); break; case SDL_JOYBUTTONDOWN: id = getIDJoyButton (event.jbutton.which, event.jbutton.button); axisIDtoStr(id, tmpString); log->__format (LOG_DEVELOPER, "New SDL_JOYBUTTONDOWN event: %s", tmpString.c_str()); - SystemData::getSystemDataPointer()->axisMap[id]->setNewRawValue (1); + System::get()->axisMap[id]->setNewRawValue (1); break; case SDL_JOYBUTTONUP: id = getIDJoyButton (event.jbutton.which, event.jbutton.button); axisIDtoStr(id, tmpString); log->__format (LOG_DEVELOPER, "New SDL_JOYBUTTONUP event: %s", tmpString.c_str()); - SystemData::getSystemDataPointer()->axisMap[id]->setNewRawValue (0); + System::get()->axisMap[id]->setNewRawValue (0); break; default: break; @@ -182,18 +182,18 @@ /* Be careful with this debugging code!! you need to have created all the axis you're going to debug! log->telemetry (LOG_ENDUSER, "%5.4f %5.4f %5.4f %5.4f %5.4f %5.4f %5.4f %5.4f %5.4f %5.4f %5.4f %5.4f", - SystemData::getSystemDataPointer()->axisMap[getIDJoyAxis(0,0)]->getValue(), - SystemData::getSystemDataPointer()->axisMap[getIDJoyAxis(0,1)]->getValue(), - SystemData::getSystemDataPointer()->axisMap[getIDJoyAxis(0,2)]->getValue(), - SystemData::getSystemDataPointer()->axisMap[getIDJoyAxis(0,3)]->getValue(), - SystemData::getSystemDataPointer()->axisMap[getIDJoyAxis(0,4)]->getValue(), - SystemData::getSystemDataPointer()->axisMap[getIDJoyAxis(0,5)]->getValue(), - SystemData::getSystemDataPointer()->axisMap[getIDJoyButton(0,0)]->getValue(), - SystemData::getSystemDataPointer()->axisMap[getIDJoyButton(0,1)]->getValue(), - SystemData::getSystemDataPointer()->axisMap[getIDJoyButton(0,2)]->getValue(), - SystemData::getSystemDataPointer()->axisMap[getIDJoyButton(0,3)]->getValue(), - SystemData::getSystemDataPointer()->axisMap[getIDJoyButton(0,4)]->getValue(), - SystemData::getSystemDataPointer()->axisMap[getIDJoyButton(0,5)]->getValue()); + System::get()->axisMap[getIDJoyAxis(0,0)]->getValue(), + System::get()->axisMap[getIDJoyAxis(0,1)]->getValue(), + System::get()->axisMap[getIDJoyAxis(0,2)]->getValue(), + System::get()->axisMap[getIDJoyAxis(0,3)]->getValue(), + System::get()->axisMap[getIDJoyAxis(0,4)]->getValue(), + System::get()->axisMap[getIDJoyAxis(0,5)]->getValue(), + System::get()->axisMap[getIDJoyButton(0,0)]->getValue(), + System::get()->axisMap[getIDJoyButton(0,1)]->getValue(), + System::get()->axisMap[getIDJoyButton(0,2)]->getValue(), + System::get()->axisMap[getIDJoyButton(0,3)]->getValue(), + System::get()->axisMap[getIDJoyButton(0,4)]->getValue(), + System::get()->axisMap[getIDJoyButton(0,5)]->getValue()); log->telemetry (LOG_ENDUSER, " A0 A1 A2 A3 A4 A5 B0 B1 B2 B3 B4 B5");*/ return (0); @@ -201,7 +201,7 @@ InputEngine::~InputEngine (void) { - log->__format (LOG_DEVELOPER, "Steering wheel: %i, %i.",systemData->axisMap[getIDJoyAxis (0, 0)]->getMinRawValue(), systemData->axisMap[getIDJoyAxis (0, 0)]->getMaxRawValue()); - log->__format (LOG_DEVELOPER, "Gas pedal: %i, %i.",systemData->axisMap[getIDJoyAxis (0, 2)]->getMinRawValue(), systemData->axisMap[getIDJoyAxis (0, 2)]->getMaxRawValue()); - log->__format (LOG_DEVELOPER, "Brake pedal: %i, %i.",systemData->axisMap[getIDJoyAxis (0, 1)]->getMinRawValue(), systemData->axisMap[getIDJoyAxis (0, 1)]->getMaxRawValue()); + log->__format (LOG_DEVELOPER, "Steering wheel: %i, %i.",system->axisMap[getIDJoyAxis (0, 0)]->getMinRawValue(), system->axisMap[getIDJoyAxis (0, 0)]->getMaxRawValue()); + log->__format (LOG_DEVELOPER, "Gas pedal: %i, %i.",system->axisMap[getIDJoyAxis (0, 2)]->getMinRawValue(), system->axisMap[getIDJoyAxis (0, 2)]->getMaxRawValue()); + log->__format (LOG_DEVELOPER, "Brake pedal: %i, %i.",system->axisMap[getIDJoyAxis (0, 1)]->getMinRawValue(), system->axisMap[getIDJoyAxis (0, 1)]->getMaxRawValue()); } Modified: trunk/src/inputEngine.hpp =================================================================== --- trunk/src/inputEngine.hpp 2006-06-23 02:22:08 UTC (rev 434) +++ trunk/src/inputEngine.hpp 2006-06-23 11:48:21 UTC (rev 435) @@ -7,10 +7,11 @@ |* [ http://motorsport-sim.org/svn/trunk/doc/LICENSE ] *| \*****************************************************************************/ -#include <shared.hpp> +#include <common/shared.hpp> + //forward declatation -class SystemData; SHARED_PTR_MAP(LogEngine, pLogEngine, LogEngines, LogEnginesIt); +SHARED_PTR(System,pSystem); /// Manages everything related to user input. /** Manages everything related to user input, such as keyboard keypresses, mouse movement, steering wheel movement, joystick, etc... Essentially, it's the interface between the end-user and the simulated world, allowing the user to transparently make changes in this simulated world. Input devices calibration issues and many other things are handled by this engine. @@ -23,7 +24,7 @@ */ pLogEngine log; // / Pointer to the system data, used by different engines in order to store common data. - SystemData *systemData; + pSystem system; public: // / Creates a new input engine. /** Creates a new input engine, with its associated own log engine. It initializes all necessary related data. Modified: trunk/src/log/logEngine.cpp =================================================================== --- trunk/src/log/logEngine.cpp 2006-06-23 02:22:08 UTC (rev 434) +++ trunk/src/log/logEngine.cpp 2006-06-23 11:48:21 UTC (rev 435) @@ -16,7 +16,6 @@ #include <string> #include <sstream> #include <xmlTag.hpp> -#include "system.hpp" //TODO use iostreams for file management/writing @@ -107,7 +106,7 @@ format (LOG_ENDUSER, "Closing logFile"); logFile.close (); } - //format (LOG_ENDUSER, "--------------------------LogFile size: %i", logEngines.size()); + format (LOG_ENDUSER, "--------------------------LogFile size: %i", logEngines.size()); } void LogEngine::logAll() Modified: trunk/src/main.cpp =================================================================== --- trunk/src/main.cpp 2006-06-23 02:22:08 UTC (rev 434) +++ trunk/src/main.cpp 2006-06-23 11:48:21 UTC (rev 435) @@ -44,17 +44,18 @@ XmlTag * tag = new XmlTag ("../cfg/mainConfig.xml"); #endif pLogEngine log = LogEngine::create (LOG_DEVELOPER, "MainProgram"); + log->__format (LOG_ENDUSER, "( 1 ): Loading engines and libraries..."); + log->__format (LOG_DEVELOPER, "Creating system data"); + System::get(); + if (tag->getName() == "mainConfig") { - SystemData::getSystemDataPointer ()->videoRecordTimestep = stoi (tag->getAttribute("videoRecordTimestep")); + System::get()->videoRecordTimestep = stoi (tag->getAttribute("videoRecordTimestep")); Paths::setCustomDataDir(tag->getAttribute("dataDir")); } delete tag; // We declare the 'global' data and engines. - log->__format (LOG_ENDUSER, "( 1 ): Loading engines and libraries..."); - log->__format (LOG_DEVELOPER, "Creating system data"); - new SystemData (); log->__format (LOG_DEVELOPER, "Creating graphics engine"); GraphicsEngine *graphicsEngine = new GraphicsEngine (); log->__format (LOG_DEVELOPER, "Creating gui engine"); @@ -69,7 +70,7 @@ InputEngine *inputEngine = new InputEngine (); log->loadscreen (LOG_DEVELOPER, "Getting system data pointer..."); - SystemData *systemData = SystemData::getSystemDataPointer (); + pSystem system = System::get(); // We load the world data from hdd into memory. log->__format (LOG_ENDUSER, "( 2 ): Loading world data..."); @@ -79,56 +80,56 @@ // We start the main loop. log->__format (LOG_ENDUSER, "( 3 ): Starting simulation..."); log->loadscreen (LOG_DEVELOPER, "Initializating main loop"); - systemData->statisticsTime = systemData->simulationTime = SDL_GetTicks() / 1000.0; + system->statisticsTime = system->simulationTime = SDL_GetTicks() / 1000.0; log->loadscreen (LOG_DEVELOPER, "Enabling main loop"); - systemData->enableMainLoop (); + system->enableMainLoop (); log->loadscreen (LOG_ENDUSER, "Hiding load screen"); guiEngine->hideLoadscreen(); log->__format (LOG_DEVELOPER, "Starting main loop"); - while (systemData->isMainLoopEnabled ()) + while (system->isMainLoopEnabled ()) { // Update current real loop time. - systemData->realTime = SDL_GetTicks () / 1000.0; + system->realTime = SDL_GetTicks () / 1000.0; // Update statistics data every second. - if (systemData->simulationTime - systemData->statisticsTime >= 1) + if (system->simulationTime - system->statisticsTime >= 1) { - systemData->graphicsFrequency = systemData->graphicsSteps; - systemData->setCurrentPhysicsFrequency (systemData->physicsSteps); - systemData->graphicsSteps = systemData->physicsSteps = 0; - systemData->statisticsTime += 1; - log->__format (LOG_DEVELOPER, "Main Loop Stats: graphicsFps=%i - physicsFps=%i", systemData->graphicsFrequency, systemData->getCurrentPhysicsFrequency()); + system->graphicsFrequency = system->graphicsSteps; + system->setCurrentPhysicsFrequency (system->physicsSteps); + system->graphicsSteps = system->physicsSteps = 0; + system->statisticsTime += 1; + log->__format (LOG_DEVELOPER, "Main Loop Stats: graphicsFps=%i - physicsFps=%i", system->graphicsFrequency, system->getCurrentPhysicsFrequency()); } inputEngine->computeStep (); // Run the gui engine. guiEngine->computeStep (); // Run the graphics engine. graphicsEngine->computeStep (); - systemData->graphicsSteps++; + system->graphicsSteps++; // Clear all event-like behaving axis. This must be moved to the input engine as axis filters asap. TODO inputEngine->clearGraphicsEventAxis (); // Run the physics engine until the game time is in sync with the real loop time. - while (((systemData->realTime - systemData->simulationTime) >= systemData->getDesiredPhysicsTimestep()) && (systemData->isMainLoopEnabled ())) + while (((system->realTime - system->simulationTime) >= system->getDesiredPhysicsTimestep()) && (system->isMainLoopEnabled ())) { - systemData->simulationTime += systemData->getDesiredPhysicsTimestep(); - static int step = systemData->timeScale; + system->simulationTime += system->getDesiredPhysicsTimestep(); + static int step = system->timeScale; step--; if (!step) { - systemData->physicsSteps++; + system->physicsSteps++; static int steps = 1; - if ((systemData->pauseStep != 0 && steps < systemData->pauseStep) || (systemData->pauseStep == 0)) + if ((system->pauseStep != 0 && steps < system->pauseStep) || (system->pauseStep == 0)) { computeLogic (log); inputEngine->clearLogicEventAxis (); inputEngine->computeStep (); physicsEngine->computeStep (); steps++; - if (SystemData::getSystemDataPointer ()->videoRecordTimestep > 0) + if (System::get()->videoRecordTimestep > 0) { recordVideoFrames (); } } - step = systemData->timeScale; + step = system->timeScale; } } } @@ -149,6 +150,8 @@ delete inputEngine; log->__format (LOG_DEVELOPER, "Deleting gui engine"); delete guiEngine; + system.reset(); + System::destroy(); stopSdl (); @@ -177,36 +180,36 @@ void computeLogic (pLogEngine log) { - SystemData *systemData = SystemData::getSystemDataPointer (); - if (SystemData::getSystemDataPointer ()->axisMap[getIDKeyboardKey (SDLK_ESCAPE)]->getValue () == 1) + pSystem system = System::get(); + if (System::get()->axisMap[getIDKeyboardKey (SDLK_ESCAPE)]->getValue () == 1) { log->__format (LOG_DEVELOPER, "Processing a SDLK_ESCAPE keypress: User wants to exit. Notifying to stop mainLoop..."); - systemData->disableMainLoop (); + system->disableMainLoop (); } - if (systemData->axisMap[getIDKeyboardKey (SDLK_HOME)]->getValue () == 1) + if (system->axisMap[getIDKeyboardKey (SDLK_HOME)]->getValue () == 1) { log->__format (LOG_DEVELOPER, "Processing a SDLK_HOME keypress..."); - systemData->setDesiredPhysicsFrequency(150.0); + system->setDesiredPhysicsFrequency(150.0); } - if (systemData->axisMap[getIDKeyboardKey (SDLK_END)]->getValue () == 1) + if (system->axisMap[getIDKeyboardKey (SDLK_END)]->getValue () == 1) { log->__format (LOG_DEVELOPER, "Processing a SDLK_END keypress..."); - systemData->setDesiredPhysicsFrequency(300.0); + system->setDesiredPhysicsFrequency(300.0); } - if (systemData->axisMap[getIDKeyboardKey (SDLK_KP_MINUS)]->getValue () == 1) + if (system->axisMap[getIDKeyboardKey (SDLK_KP_MINUS)]->getValue () == 1) { log->__format (LOG_DEVELOPER, "Processing a SDLK_KP_MINUS keypress..."); - systemData->decreaseDesiredPhysicsRate(); + system->decreaseDesiredPhysicsRate(); } - if (systemData->axisMap[getIDKeyboardKey (SDLK_KP_PLUS)]->getValue () == 1) + if (system->axisMap[getIDKeyboardKey (SDLK_KP_PLUS)]->getValue () == 1) { log->__format (LOG_DEVELOPER, "Processing a SDLK_KP_PLUS keypress..."); - systemData->increaseDesiredPhysicsRate(); + system->increaseDesiredPhysicsRate(); } - if (systemData->axisMap[getIDKeyboardKey(SDLK_b)]->getValue() == 1) + if (system->axisMap[getIDKeyboardKey(SDLK_b)]->getValue() == 1) { - systemData->cameraDirector = !(systemData->cameraDirector); - systemData->axisMap[getIDKeyboardKey(SDLK_b)]->setNewRawValue(0); + system->cameraDirector = !(system->cameraDirector); + system->axisMap[getIDKeyboardKey(SDLK_b)]->setNewRawValue(0); } } @@ -214,15 +217,15 @@ { static double time = 0; int takeShot = 0; - if ((int) time >= SystemData::getSystemDataPointer ()->videoRecordTimestep) + if ((int) time >= System::get()->videoRecordTimestep) { takeShot++; - time -= SystemData::getSystemDataPointer()->getDesiredPhysicsTimestep(); + time -= System::get()->getDesiredPhysicsTimestep(); } - if ((takeShot > 0) && (SystemData::getSystemDataPointer ()->axisMap[getIDKeyboardKey (SDLK_PRINT)]->getValue () == 0)) + if ((takeShot > 0) && (System::get()->axisMap[getIDKeyboardKey (SDLK_PRINT)]->getValue () == 0)) { - SystemData::getSystemDataPointer ()->axisMap[getIDKeyboardKey (SDLK_PRINT)]->setNewRawValue (1); + System::get()->axisMap[getIDKeyboardKey (SDLK_PRINT)]->setNewRawValue (1); takeShot--; } - time += SystemData::getSystemDataPointer()->getDesiredPhysicsTimestep(); + time += System::get()->getDesiredPhysicsTimestep(); } Modified: trunk/src/physicsEngine.cpp =================================================================== --- trunk/src/physicsEngine.cpp 2006-06-23 02:22:08 UTC (rev 434) +++ trunk/src/physicsEngine.cpp 2006-06-23 11:48:21 UTC (rev 435) @@ -37,8 +37,8 @@ double frequency = 250.0; int timeScale = 1; int pauseStep = 0; - SystemData::getSystemDataPointer()->setCfmValue (-1); - SystemData::getSystemDataPointer()->setErpValue (-1); + System::get()->setCfmValue (-1); + System::get()->setErpValue (-1); int stepType = 1; int dWorldStepFast1MaxIterations = 100; @@ -52,8 +52,8 @@ { if (t->getName() == "ode") { - if (t->getAttribute("cfmValue") != "default") SystemData::getSystemDataPointer()->setCfmValue(stod(t->getAttribute("cfmValue"))); - if (t->getAttribute("erpValue") != "default") SystemData::getSystemDataPointer()->setErpValue(stod(t->getAttribute("erpValue"))); + if (t->getAttribute("cfmValue") != "default") System::get()->setCfmValue(stod(t->getAttribute("cfmValue"))); + if (t->getAttribute("erpValue") != "default") System::get()->setErpValue(stod(t->getAttribute("erpValue"))); if (t->getAttribute("stepType") == "dWorldStep") stepType = 1; if (t->getAttribute("stepType") == "dWorldStepFast1") stepType = 2; dWorldStepFast1MaxIterations = stoi (t->getAttribute("dWorldStepFast1MaxIterations")); @@ -62,13 +62,13 @@ } // get the direction of the graphics data log->__format (LOG_DEVELOPER, "Setting up data pointers..."); - systemData = SystemData::getSystemDataPointer (); + system = System::get(); log->__format (LOG_DEVELOPER, "Setting physics data"); - systemData->setDesiredPhysicsFrequency(frequency); - systemData->timeScale = timeScale; - systemData->pauseStep = pauseStep; - log->__format (LOG_ENDUSER, "Physics rate set @ %f Hz (%f ms)", systemData->getDesiredPhysicsFrequency(), systemData->getDesiredPhysicsTimestep() * 1000); + system->setDesiredPhysicsFrequency(frequency); + system->timeScale = timeScale; + system->pauseStep = pauseStep; + log->__format (LOG_ENDUSER, "Physics rate set @ %f Hz (%f ms)", system->getDesiredPhysicsFrequency(), system->getDesiredPhysicsTimestep() * 1000); delete tag; } @@ -155,11 +155,11 @@ default: case 1: // traditional (x^y), theorycally slowest, and most accurate physics calculations: - dWorldStep (World::get()->worldID, systemData->getDesiredPhysicsTimestep()); + dWorldStep (World::get()->worldID, system->getDesiredPhysicsTimestep()); break; case 2: // alternative (x*y), fastest and less accurate physics calculations: - dWorldStepFast1 (World::get()->worldID, systemData->getDesiredPhysicsTimestep(), dWorldStepFast1MaxIterations); + dWorldStepFast1 (World::get()->worldID, system->getDesiredPhysicsTimestep(), dWorldStepFast1MaxIterations); break; } VehiclesIt j = World::get()->vehicles.begin(); Modified: trunk/src/physicsEngine.hpp =================================================================== --- trunk/src/physicsEngine.hpp 2006-06-23 02:22:08 UTC (rev 434) +++ trunk/src/physicsEngine.hpp 2006-06-23 11:48:21 UTC (rev 435) @@ -7,7 +7,7 @@ |* [ http://motorsport-sim.org/svn/trunk/doc/LICENSE ] *| \*****************************************************************************/ -#include <shared.hpp> +#include <common/shared.hpp> #include "ode/objects.h" /// Manages everything related to the simulated world data. @@ -15,7 +15,7 @@ */ -class SystemData; +SHARED_PTR(System,pSystem); SHARED_PTR_MAP(LogEngine, pLogEngine, LogEngines, LogEnginesIt); class PhysicsEngine @@ -26,7 +26,7 @@ */ pLogEngine log; // / Pointer to the system data, used by different engines in order to store common data. - SystemData *systemData; + pSystem system; // / Callback function for collisions detection. /** Callback function used with ODE. It processes the physic entities in the simulated world, generating the necessary forces according to the detected collisions. */ Modified: trunk/src/system.cpp =================================================================== --- trunk/src/system.cpp 2006-06-23 02:22:08 UTC (rev 434) +++ trunk/src/system.cpp 2006-06-23 11:48:21 UTC (rev 435) @@ -9,15 +9,32 @@ #include "system.hpp" #include "SDL/begin_code.h" +#include <iostream> -SystemData SystemData::systemDataObject = SystemData(); +pSystem System::system; -SystemData *SystemData::getSystemDataPointer () +pSystem System::get() { - return (&systemDataObject); + if (!system) + { + std::cout << "Auto-creating a default system!" << std::endl; + new System(); + } + return (system); } - -SystemData::SystemData () +void System::destroy() +{ + if (!system) + { + std::cout << "WARNING: There's no world to be destroyed!" << std::endl; + } + else + { + system.reset(); + } +} +System::System () +/*/ : cfmValue(-1), erpValue(-1), currentPhysicsFrequency(0), @@ -30,35 +47,54 @@ width(1), videoRecordTimestep(0), cameraDirector(false) +//*/ { - //empty + if (system) + { + std::cout << "ERROR: Tried to create another system. This shouldn't have happened!" << std::endl; + } else { + pSystem tmp(this); + system = tmp; + cfmValue = -1; + erpValue = -1; + currentPhysicsFrequency = 0; + physicsSteps = 0; + graphicsSteps = 0; + graphicsFrequency = 0; + timeScale = 1; + pauseStep = 0; + height = 1; + width = 1; + videoRecordTimestep = 0; + cameraDirector = false; + } } -SystemData::~SystemData () +System::~System () { - //empty + //empty } -bool SystemData::isMainLoopEnabled (void) { return mainLoopEnabled; } -void SystemData::enableMainLoop (void) { mainLoopEnabled = true; } -void SystemData::disableMainLoop (void) { mainLoopEnabled = false;} +bool System::isMainLoopEnabled (void) { return mainLoopEnabled; } +void System::enableMainLoop (void) { mainLoopEnabled = true; } +void System::disableMainLoop (void) { mainLoopEnabled = false;} -double SystemData::getCfmValue() { return cfmValue; } -double SystemData::getErpValue() { return erpValue; } -void SystemData::setCfmValue(const double & value) { cfmValue = value;} -void SystemData::setErpValue(const double & value) { erpValue = value;} +double System::getCfmValue() { return cfmValue; } +double System::getErpValue() { return erpValue; } +void System::setCfmValue(const double & value) { cfmValue = value;} +void System::setErpValue(const double & value) { erpValue = value;} -double SystemData::getCurrentPhysicsFrequency() { return currentPhysicsFrequency; } -double SystemData::getCurrentPhysicsTimestep() { return 1.0/currentPhysicsFrequency; } -void SystemData::setCurrentPhysicsFrequency(double frequency) { currentPhysicsFrequency = frequency; } -void SystemData::setCurrentPhysicsTimestep(double timestep) { currentPhysicsFrequency = 1.0/timestep;} +double System::getCurrentPhysicsFrequency() { return currentPhysicsFrequency; } +double System::getCurrentPhysicsTimestep() { return 1.0/currentPhysicsFrequency; } +void System::setCurrentPhysicsFrequency(double frequency) { currentPhysicsFrequency = frequency; } +void System::setCurrentPhysicsTimestep(double timestep) { currentPhysicsFrequency = 1.0/timestep;} -double SystemData::getDesiredPhysicsFrequency() { return desiredPhysicsFrequency; } -double SystemData::getDesiredPhysicsTimestep() { return 1.0/desiredPhysicsFrequency; } -void SystemData::setDesiredPhysicsFrequency(double frequency) { desiredPhysicsFrequency = frequency; } -void SystemData::setDesiredPhysicsTimestep(double timestep) { desiredPhysicsFrequency = 1.0/timestep;} +double System::getDesiredPhysicsFrequency() { return desiredPhysicsFrequency; } +double System::getDesiredPhysicsTimestep() { return 1.0/desiredPhysicsFrequency; } +void System::setDesiredPhysicsFrequency(double frequency) { desiredPhysicsFrequency = frequency; } +void System::setDesiredPhysicsTimestep(double timestep) { desiredPhysicsFrequency = 1.0/timestep;} -void SystemData::increaseDesiredPhysicsRate() +void System::increaseDesiredPhysicsRate() { if (desiredPhysicsFrequency < 1) setDesiredPhysicsFrequency (1); else if (desiredPhysicsFrequency < 10) setDesiredPhysicsFrequency (desiredPhysicsFrequency + 1); @@ -70,7 +106,7 @@ else ... [truncated message content] |
|
From: <st...@us...> - 2006-06-23 02:22:26
|
Revision: 434 Author: stenyak Date: 2006-06-22 19:22:08 -0700 (Thu, 22 Jun 2006) ViewCVS: http://svn.sourceforge.net/motorsport/?rev=434&view=rev Log Message: ----------- Converted World pointers to shared pointers. Modified Paths: -------------- trunk/src/common/camera.cpp trunk/src/common/odeObject.cpp trunk/src/graphicsEngine.cpp trunk/src/main.cpp trunk/src/physicsEngine.cpp trunk/src/vehicle/body.cpp trunk/src/vehicle/suspension.cpp trunk/src/world/area.cpp trunk/src/world/part.cpp trunk/src/world/world.cpp trunk/src/world/world.hpp Modified: trunk/src/common/camera.cpp =================================================================== --- trunk/src/common/camera.cpp 2006-06-23 01:09:51 UTC (rev 433) +++ trunk/src/common/camera.cpp 2006-06-23 02:22:08 UTC (rev 434) @@ -143,7 +143,7 @@ void Camera::stepPhysics () { - if (this == World::getWorldPointer()->getActiveCamera().get() ) + if (this == World::get()->getActiveCamera().get() ) { static bool wasPressed = false; if (SystemData::getSystemDataPointer()->axisMap[getIDKeyboardKey(SDLK_x)]->getValue() == 1) Modified: trunk/src/common/odeObject.cpp =================================================================== --- trunk/src/common/odeObject.cpp 2006-06-23 01:09:51 UTC (rev 433) +++ trunk/src/common/odeObject.cpp 2006-06-23 02:22:08 UTC (rev 434) @@ -29,7 +29,7 @@ this->worldObject = worldObject; this->name = name; bodyID = NULL; - bodyID = dBodyCreate (World::getWorldPointer ()->worldID); + bodyID = dBodyCreate (World::get()->worldID); //TODO make this optional via xml or something similar /*/set autodisable @@ -43,17 +43,17 @@ dMass dmass; if (data->shape == "box") { - geomIDs[name] = dCreateBox (World::getWorldPointer ()->spaceID, data->size.x, data->size.y, data->size.z); + geomIDs[name] = dCreateBox (World::get()->spaceID, data->size.x, data->size.y, data->size.z); dMassSetBoxTotal (&dmass, data->mass, data->size.x, data->size.y, data->size.z); } if (data->shape == "sphere") { - geomIDs[name] = dCreateSphere (World::getWorldPointer ()->spaceID, data->radius); + geomIDs[name] = dCreateSphere (World::get()->spaceID, data->radius); dMassSetSphereTotal (&dmass, data->mass, data->radius); } if (data->shape == "cappedCylinder") { - geomIDs[name] = dCreateCCylinder (World::getWorldPointer ()->spaceID, data->radius, data->length); + geomIDs[name] = dCreateCCylinder (World::get()->spaceID, data->radius, data->length); dMassSetCappedCylinderTotal (&dmass, data->mass, data->directionAxis, data->radius, data->length); } dGeomSetBody (geomIDs[name], bodyID); @@ -66,12 +66,12 @@ this->name = name; bodyID = NULL; // create dBody - bodyID = dBodyCreate (World::getWorldPointer ()->worldID); + bodyID = dBodyCreate (World::get()->worldID); dBodySetData (bodyID, static_cast<void*>(worldObject->getContainer())); // create transform spaces (in order to be able to 'offset' the collision geoms - geomIDs["GeomSpace(A)"] = dCreateGeomTransform (World::getWorldPointer ()->spaceID); - geomIDs["GeomSpace(B)"] = dCreateGeomTransform (World::getWorldPointer ()->spaceID); + geomIDs["GeomSpace(A)"] = dCreateGeomTransform (World::get()->spaceID); + geomIDs["GeomSpace(B)"] = dCreateGeomTransform (World::get()->spaceID); // avoid ODE removing objects itself. transform geoms now must be manually removed dGeomTransformSetCleanup (geomIDs["GeomSpace(A)"], 0); @@ -113,14 +113,14 @@ this->worldObject = worldObject; this->name = name; bodyID = NULL; - bodyID = dBodyCreate (World::getWorldPointer ()->worldID); + bodyID = dBodyCreate (World::get()->worldID); dBodySetData (bodyID, static_cast<void*>(worldObject->getContainer())); dMass dmass; dMassSetParameters (&dmass, data->mass, 0., 0., 0., 0.237f, 0.237f, 0.409f, 0., 0., 0.); - geomIDs[name] = dCreateCCylinder (World::getWorldPointer ()->spaceID, data->radius, data->width); + geomIDs[name] = dCreateCCylinder (World::get()->spaceID, data->radius, data->width); dBodySetLinearVel (bodyID, 0, 0, 0); dBodySetAngularVel (bodyID, 0, 0, 0); dGeomSetBody (geomIDs[name], bodyID); @@ -133,7 +133,7 @@ this->name = name; bodyID = NULL; - bodyID = dBodyCreate (World::getWorldPointer ()->worldID); + bodyID = dBodyCreate (World::get()->worldID); dBodySetData (bodyID, static_cast<void*>(worldObject->getContainer())); dMass dmass; if (data->useMass) @@ -146,7 +146,7 @@ } dBodySetMass (bodyID, &dmass); - geomIDs[name] = dCreateBox (World::getWorldPointer ()->spaceID, data->radius, data->radius, data->length); + geomIDs[name] = dCreateBox (World::get()->spaceID, data->radius, data->radius, data->length); dBodySetLinearVel (bodyID, 0, 0, 0); dBodySetAngularVel (bodyID, 0, 0, 0); dGeomSetBody (geomIDs[name], bodyID); Modified: trunk/src/graphicsEngine.cpp =================================================================== --- trunk/src/graphicsEngine.cpp 2006-06-23 01:09:51 UTC (rev 433) +++ trunk/src/graphicsEngine.cpp 2006-06-23 02:22:08 UTC (rev 434) @@ -150,52 +150,52 @@ // change camera if needed if (systemData->axisMap[getIDKeyboardKey(SDLK_c)]->getValue() == 1) { - CamerasIt i = World::getWorldPointer()->areas.begin()->second->cameras.begin(); + CamerasIt i = World::get()->areas.begin()->second->cameras.begin(); pCamera nextCam = i->second; bool found = false; - for (;i != World::getWorldPointer()->areas.begin()->second->cameras.end(); i++) + for (;i != World::get()->areas.begin()->second->cameras.end(); i++) { if (found == true) { nextCam = i->second; found = false; } - if (World::getWorldPointer()->getActiveAreaCamera()->getName() == i->second->getName()) + if (World::get()->getActiveAreaCamera()->getName() == i->second->getName()) { found = true; } } - World::getWorldPointer()->setActiveCamera(nextCam); - World::getWorldPointer()->activeAreaCamera = nextCam; + World::get()->setActiveCamera(nextCam); + World::get()->activeAreaCamera = nextCam; } if (systemData->axisMap[getIDKeyboardKey(SDLK_v)]->getValue() == 1) { - CamerasIt i = World::getWorldPointer()->vehicles.begin()->second->cameras.begin(); + CamerasIt i = World::get()->vehicles.begin()->second->cameras.begin(); pCamera nextCam = i->second; bool found = false; - for (;i != World::getWorldPointer()->vehicles.begin()->second->cameras.end(); i++) + for (;i != World::get()->vehicles.begin()->second->cameras.end(); i++) { if (found == true) { nextCam = i->second; found = false; } - if (World::getWorldPointer()->getActiveVehicleCamera()->getName() == i->second->getName()) + if (World::get()->getActiveVehicleCamera()->getName() == i->second->getName()) { found = true; } } - World::getWorldPointer()->setActiveCamera(nextCam); - World::getWorldPointer()->activeVehicleCamera = nextCam; + World::get()->setActiveCamera(nextCam); + World::get()->activeVehicleCamera = nextCam; } if (systemData->cameraDirector) { log->__format(LOG_DEVELOPER, "Finding closest camera"); - Vector3d vPos = World::getWorldPointer()->vehicles.begin()->second->getPosition(); + Vector3d vPos = World::get()->vehicles.begin()->second->getPosition(); double closestDistance = 99999999999.0; - CamerasIt i = World::getWorldPointer()->areas.begin()->second->cameras.begin(); + CamerasIt i = World::get()->areas.begin()->second->cameras.begin(); pCamera closestCam = i->second; - for (;i != World::getWorldPointer()->areas.begin()->second->cameras.end(); i++) + for (;i != World::get()->areas.begin()->second->cameras.end(); i++) { log->__format(LOG_DEVELOPER, "Checking cam id: %s", i->second->getName().c_str()); Ogre::Vector3 p = i->second->ogreCamera->getPosition(); @@ -208,49 +208,49 @@ } } - World::getWorldPointer()->setActiveCamera(closestCam); - World::getWorldPointer()->activeAreaCamera = closestCam; + World::get()->setActiveCamera(closestCam); + World::get()->activeAreaCamera = closestCam; } // Update Ogre's vehicles positions with Ode's positions. - VehiclesIt j = World::getWorldPointer()->vehicles.begin(); - for (; j != World::getWorldPointer()->vehicles.end(); j++) + VehiclesIt j = World::get()->vehicles.begin(); + for (; j != World::get()->vehicles.end(); j++) { j->second->stepGraphics(); } // Update Ogre's parts positions with Ode's positions. - PartsIt k = World::getWorldPointer()->areas.begin()->second->parts.begin(); - for (; k != World::getWorldPointer()->areas.begin()->second->parts.end(); k++) + PartsIt k = World::get()->areas.begin()->second->parts.begin(); + for (; k != World::get()->areas.begin()->second->parts.end(); k++) { k->second->stepGraphics(); } // Update cameras positions (should be done in the fsx engine FIXME - CamerasIt i = World::getWorldPointer ()->areas.begin()->second->cameras.begin(); - for (;i != World::getWorldPointer()->areas.begin()->second->cameras.end(); i++) + CamerasIt i = World::get()->areas.begin()->second->cameras.begin(); + for (;i != World::get()->areas.begin()->second->cameras.end(); i++) { i->second->stepGraphics(); } - i = World::getWorldPointer ()->vehicles.begin()->second->cameras.begin(); - for (;i != World::getWorldPointer()->vehicles.begin()->second->cameras.end(); i++) + i = World::get()->vehicles.begin()->second->cameras.begin(); + for (;i != World::get()->vehicles.begin()->second->cameras.end(); i++) { i->second->stepGraphics(); } // Update infinite plane position according to vehicle position - Ogre::Vector3 areaPos (World::getWorldPointer()->areas.begin()->second->planeNode->getPosition()); - Vector3d vehiclePos (World::getWorldPointer()->vehicles.begin()->second->getPosition()); + Ogre::Vector3 areaPos (World::get()->areas.begin()->second->planeNode->getPosition()); + Vector3d vehiclePos (World::get()->vehicles.begin()->second->getPosition()); Vector3d diff (areaPos.x - vehiclePos.x, areaPos.y - vehiclePos.y, areaPos.z - vehiclePos.z); const double tile = 1000.0 / 20.0; if (diff.x > tile || diff.x < -tile) areaPos.x -= int ((diff.x) / (tile)) * (tile); if (diff.y > tile || diff.y < -tile) areaPos.y -= int ((diff.y) / (tile)) * (tile); - World::getWorldPointer()->areas.begin()->second->planeNode->setPosition(areaPos); + World::get()->areas.begin()->second->planeNode->setPosition(areaPos); // Update area shadows state - World::getWorldPointer()->areas.begin()->second->setCastShadows(castAreaShadows); + World::get()->areas.begin()->second->setCastShadows(castAreaShadows); // Update area render mode - World::getWorldPointer ()->areas.begin()->second->setRenderDetail(areaRenderMode); + World::get()->areas.begin()->second->setRenderDetail(areaRenderMode); // Let the listener frames be started and ended: they are needed for particle systems. ogreRoot->_fireFrameStarted (); Modified: trunk/src/main.cpp =================================================================== --- trunk/src/main.cpp 2006-06-23 01:09:51 UTC (rev 433) +++ trunk/src/main.cpp 2006-06-23 02:22:08 UTC (rev 434) @@ -74,7 +74,7 @@ // We load the world data from hdd into memory. log->__format (LOG_ENDUSER, "( 2 ): Loading world data..."); log->loadscreen (LOG_CCREATOR, "Loading initial world data..."); - new World (NULL, "default"); + World::setNewWorld("default"); // We start the main loop. log->__format (LOG_ENDUSER, "( 3 ): Starting simulation..."); @@ -137,7 +137,7 @@ // We unload the world data from memory. log->__format (LOG_ENDUSER, "( 4 ): Unloading world data..."); log->__format (LOG_CCREATOR, "Unloading world data"); - delete World::getWorldPointer (); + World::destroy(); // We delete the 'global' data and engines. log->__format (LOG_ENDUSER, "( 5 ): Unloading engines and libraries..."); Modified: trunk/src/physicsEngine.cpp =================================================================== --- trunk/src/physicsEngine.cpp 2006-06-23 01:09:51 UTC (rev 433) +++ trunk/src/physicsEngine.cpp 2006-06-23 02:22:08 UTC (rev 434) @@ -119,7 +119,7 @@ contact[i].surface.soft_erp = 0.8; contact[i].surface.soft_cfm = 0.00000001; - dJointID c = dJointCreateContact (World::getWorldPointer ()->worldID, World::getWorldPointer ()->jointGroupID, contact + i); + dJointID c = dJointCreateContact (World::get()->worldID, World::get()->jointGroupID, contact + i); dJointAttach (c, dGeomGetBody (o1), dGeomGetBody (o2)); } } @@ -131,44 +131,44 @@ // mega-verbosity log->__format (LOG_DEVELOPER, "Doing an step: calculating a physics step"); - PartsIt k = World::getWorldPointer()->areas.begin()->second->parts.begin(); - for (; k != World::getWorldPointer()->areas.begin()->second->parts.end(); k++) + PartsIt k = World::get()->areas.begin()->second->parts.begin(); + for (; k != World::get()->areas.begin()->second->parts.end(); k++) { k->second->stepPhysics(); } - CamerasIt i = World::getWorldPointer()->areas.begin()->second->cameras.begin(); - for(;i != World::getWorldPointer()->areas.begin()->second->cameras.end();i++) + CamerasIt i = World::get()->areas.begin()->second->cameras.begin(); + for(;i != World::get()->areas.begin()->second->cameras.end();i++) { i->second->stepPhysics(); } - i = World::getWorldPointer()->vehicles.begin()->second->cameras.begin(); - for(;i != World::getWorldPointer()->vehicles.begin()->second->cameras.end();i++) + i = World::get()->vehicles.begin()->second->cameras.begin(); + for(;i != World::get()->vehicles.begin()->second->cameras.end();i++) { i->second->stepPhysics(); } checkpointPassed = false; - dSpaceCollide (World::getWorldPointer ()->spaceID, 0, &nearCallback); + dSpaceCollide (World::get()->spaceID, 0, &nearCallback); switch (stepType) { default: case 1: // traditional (x^y), theorycally slowest, and most accurate physics calculations: - dWorldStep (World::getWorldPointer ()->worldID, systemData->getDesiredPhysicsTimestep()); + dWorldStep (World::get()->worldID, systemData->getDesiredPhysicsTimestep()); break; case 2: // alternative (x*y), fastest and less accurate physics calculations: - dWorldStepFast1 (World::getWorldPointer ()->worldID, systemData->getDesiredPhysicsTimestep(), dWorldStepFast1MaxIterations); + dWorldStepFast1 (World::get()->worldID, systemData->getDesiredPhysicsTimestep(), dWorldStepFast1MaxIterations); break; } - VehiclesIt j = World::getWorldPointer()->vehicles.begin(); - for (; j != World::getWorldPointer()->vehicles.end(); j++) + VehiclesIt j = World::get()->vehicles.begin(); + for (; j != World::get()->vehicles.end(); j++) { j->second->stepPhysics(); } - dJointGroupEmpty (World::getWorldPointer ()->jointGroupID); + dJointGroupEmpty (World::get()->jointGroupID); // check if a car has passed the checkpoint static bool checkpointWasPassed = false; Modified: trunk/src/vehicle/body.cpp =================================================================== --- trunk/src/vehicle/body.cpp 2006-06-23 01:09:51 UTC (rev 433) +++ trunk/src/vehicle/body.cpp 2006-06-23 02:22:08 UTC (rev 434) @@ -74,7 +74,7 @@ void Body::stepPhysics () { dBodyID bodyID = getMainOdeObject()->getBodyID(); - if (this == World::getWorldPointer ()->vehicles.begin()->second->getObject("body")) + if (this == World::get()->vehicles.begin()->second->getObject("body")) { double moveZ = SystemData::getSystemDataPointer()->axisMap[getIDKeyboardKey(SDLK_BACKSPACE)]->getValue() * 50000; moveZ += SystemData::getSystemDataPointer()->axisMap[getIDKeyboardKey(SDLK_RETURN)]->getValue() * 12200; Modified: trunk/src/vehicle/suspension.cpp =================================================================== --- trunk/src/vehicle/suspension.cpp 2006-06-23 01:09:51 UTC (rev 433) +++ trunk/src/vehicle/suspension.cpp 2006-06-23 02:22:08 UTC (rev 434) @@ -149,8 +149,8 @@ dampingConstant = stod(tag->getAttribute("dampingConstant")); maxSteeringAngle = stod(tag->getAttribute("steeringAngle")); } -// jointID = dJointCreateHinge (World::getWorldPointer()->worldID, 0); - jointID = dJointCreateHinge2 (World::getWorldPointer()->worldID, 0); +// jointID = dJointCreateHinge (World::get()->worldID, 0); + jointID = dJointCreateHinge2 (World::get()->worldID, 0); dJointAttach (jointID, 0, 0); } void Unidimensional::stepPhysics() @@ -209,7 +209,7 @@ position = Vector3d (tag->getAttribute("position")); rotation = Quaternion (tag->getAttribute("rotation")); } - jointID = dJointCreateHinge (World::getWorldPointer()->worldID, 0); + jointID = dJointCreateHinge (World::get()->worldID, 0); dJointAttach (jointID, 0, 0); } void Fixed::stepPhysics() @@ -343,7 +343,7 @@ ogreObjects["uprightBone"]->setOdeReference(odeObjects["uprightBone"]); //create upper joint - upperJoint = dJointCreateHinge( World::getWorldPointer()->worldID, 0 ); + upperJoint = dJointCreateHinge( World::get()->worldID, 0 ); dJointAttach ( upperJoint, odeObjects["uprightBone"]->getBodyID(), odeObjects["upperBone"]->getBodyID() ); dJointSetHingeAnchor( upperJoint , firstPosition.x , firstPosition.y+(dirMult*upperBoneData->length), firstPosition.z+(uprightBoneLength*0.5) ); dJointSetHingeAxis( upperJoint , 1.0, 0.0, 0.0 ); @@ -352,7 +352,7 @@ dJointSetHingeParam ( upperJoint, dParamHiStop, 2.0 ); //create lower joint - lowerJoint = dJointCreateHinge( World::getWorldPointer()->worldID, 0 ); + lowerJoint = dJointCreateHinge( World::get()->worldID, 0 ); dJointAttach ( lowerJoint, odeObjects["uprightBone"]->getBodyID(), odeObjects["lowerBone"]->getBodyID() ); dJointSetHingeAnchor( lowerJoint , firstPosition.x , firstPosition.y+(dirMult*upperBoneData->length), firstPosition.z-(uprightBoneLength*0.5) ); dJointSetHingeAxis( lowerJoint , 1.0, 0.0, 0.0 ); @@ -377,19 +377,19 @@ //create chassisUpper joint Vector3d pos = getFirstLinkPosition(); - chassisUpperJoint = dJointCreateHinge( World::getWorldPointer()->worldID, 0 ); + chassisUpperJoint = dJointCreateHinge( World::get()->worldID, 0 ); dJointAttach( chassisUpperJoint, base->getMainOdeObject()->getBodyID() , odeObjects["upperBone"]->getBodyID() ); dJointSetHingeAxis( chassisUpperJoint, 1,0,0 ); dJointSetHingeAnchor( chassisUpperJoint, firstPosition.x, firstPosition.y, firstPosition.z+(uprightBoneLength*0.5)); //create chassisLower joint - chassisLowerJoint = dJointCreateHinge( World::getWorldPointer()->worldID, 0 ); + chassisLowerJoint = dJointCreateHinge( World::get()->worldID, 0 ); dJointAttach( chassisLowerJoint, base->getMainOdeObject()->getBodyID() , odeObjects["lowerBone"]->getBodyID() ); dJointSetHingeAxis( chassisLowerJoint, 1,0,0 ); dJointSetHingeAnchor( chassisLowerJoint, firstPosition.x, firstPosition.y, firstPosition.z-(uprightBoneLength*0.5)); //create axis&steering joint - axisJoint = dJointCreateHinge2( World::getWorldPointer()->worldID, 0 ); + axisJoint = dJointCreateHinge2( World::get()->worldID, 0 ); dJointAttach ( axisJoint, odeObjects["uprightBone"]->getBodyID(), object->getMainOdeObject()->getBodyID() ); dJointSetHinge2Anchor( axisJoint, firstPosition.x, firstPosition.y+(upperBoneLength*dirMult), firstPosition.z); @@ -401,7 +401,7 @@ log->__format (LOG_DEVELOPER, "Axis2 = %f, %f, %f.", rAxis2.x, rAxis2.y, rAxis2.z); //create spring-damper joint - // sdamper = dJointCreateSlider(World::getWorldPointer()->worldID, 0); + // sdamper = dJointCreateSlider(World::get()->worldID, 0); //dJointAttach( sdamper, base->getMainOdeObject()->getBodyID(), odeObjects["uprightBone"]->getBodyID() ); //dJointSetSliderAxis (sdamper, 0,dirMult*0.66,0.66); //dJointSetSliderAxis (sdamper, forceDirection[0], forceDirection[1], forceDirection[2]); Modified: trunk/src/world/area.cpp =================================================================== --- trunk/src/world/area.cpp 2006-06-23 01:09:51 UTC (rev 433) +++ trunk/src/world/area.cpp 2006-06-23 02:22:08 UTC (rev 434) @@ -90,7 +90,7 @@ ogreChild->setOgreReference(ogreObjects[ogreObject->getId()], rotDiff, posDiff, scale); // declare ode mesh dTriMeshDataID ground = dGeomTriMeshDataCreate (); - dGeomSetBody (dCreateTriMesh (World::getWorldPointer ()->spaceID, ground, 0, 0, 0), 0); + dGeomSetBody (dCreateTriMesh (World::get()->spaceID, ground, 0, 0, 0), 0); size_t vertex_count, index_count; dVector3 * vertices; @@ -144,7 +144,7 @@ log->loadscreen (LOG_CCREATOR, "Creating the area ground"); log->__format (LOG_DEVELOPER, "Creating the ode plane"); - dCreatePlane (World::getWorldPointer()->spaceID, 0, 0, 1, groundHeight); + dCreatePlane (World::get()->spaceID, 0, 0, 1, groundHeight); log->__format (LOG_DEVELOPER, "Creating the ogre plane"); Ogre::Plane plane; @@ -156,7 +156,7 @@ planeEntity->setMaterialName(groundMaterialName.c_str()); planeNode = pOgreSceneManager->getRootSceneNode()->createChildSceneNode(); planeNode->attachObject(planeEntity); - areaBodyID = dBodyCreate (World::getWorldPointer ()->ghostWorldID); + areaBodyID = dBodyCreate (World::get()->ghostWorldID); SystemData::getSystemDataPointer()->ogreWindow->update (); // FIXME should be part of the world, not the area @@ -167,7 +167,7 @@ SystemData::getSystemDataPointer()->ogreWindow->update (); // create the checkpoint sphere - dGeomID checkpointID = dCreateSphere (World::getWorldPointer()->spaceID, checkpointRadius); + dGeomID checkpointID = dCreateSphere (World::get()->spaceID, checkpointRadius); dGeomSetBody (checkpointID, 0); dGeomSetPosition (checkpointID, checkpointPosition.x, checkpointPosition.y, checkpointPosition.z); } Modified: trunk/src/world/part.cpp =================================================================== --- trunk/src/world/part.cpp 2006-06-23 01:09:51 UTC (rev 433) +++ trunk/src/world/part.cpp 2006-06-23 02:22:08 UTC (rev 434) @@ -101,7 +101,7 @@ dBodySetAngularVel (partID, (*(dReal *) (dBodyGetAngularVel (partID) + 0)) * (dReal) (0.999), (*(dReal *) (dBodyGetAngularVel (partID) + 1)) * (dReal) (0.999), (*(dReal *) (dBodyGetAngularVel (partID) + 2)) * (dReal) (0.999)); // ////////////////////////////////////simplified air friction // applying user input [forces] - if (this == World::getWorldPointer ()->areas.begin()->second->parts.begin()->second.get()) + if (this == World::get()->areas.begin()->second->parts.begin()->second.get()) { float moveX = SystemData::getSystemDataPointer()->axisMap[getIDKeyboardKey(SDLK_l)]->getValue(); float moveY = SystemData::getSystemDataPointer()->axisMap[getIDKeyboardKey(SDLK_i)]->getValue(); Modified: trunk/src/world/world.cpp =================================================================== --- trunk/src/world/world.cpp 2006-06-23 01:09:51 UTC (rev 433) +++ trunk/src/world/world.cpp 2006-06-23 02:22:08 UTC (rev 434) @@ -21,26 +21,50 @@ #include "location.hpp" #include "SDL.h" -World *World::worldPointer = NULL; +//pWorld World::world = NULL; +pWorld World::world; +std::string World::newWorld = ""; -World *World::getWorldPointer () +void World::setNewWorld(std::string name) { - if (worldPointer == 0) + world.reset(); + World::newWorld = name; + World::get(); +} +pWorld World::get() +{ + if (!world) { - std::cout << "WARNING: Auto-creating a default world!" << std::endl; - worldPointer = new World(NULL, "default"); + if (newWorld == "") + { + std::cout << "WARNING: Auto-creating a default world!" << std::endl; + newWorld = "default"; + } + new World(World::newWorld); } - return (worldPointer); + return (world); } +void World::destroy() +{ + if (!world) + { + std::cout << "WARNING: There's no world to be destroyed!" << std::endl; + } + else + { + world.reset(); + } +} -World::World (WorldObject * container, std::string name) - :WorldObject(container, name) +World::World (std::string name) + :WorldObject(NULL, name) { - if (worldPointer != 0) + if (world) { - delete this; + world->log->__format(LOG_ERROR, "Tried to create another world, named \"%s\". This shouldn't have happened.", name.c_str()); } else { - worldPointer = this; + pWorld tmp(this); + world = tmp; setPath(Paths::world(name)); setXmlPath(Paths::worldXml(name)); log->loadscreen (LOG_ENDUSER, "Starting to load the world (%s)", getXmlPath().c_str()); @@ -67,8 +91,6 @@ dWorldDestroy (ghostWorldID); log->__format (LOG_DEVELOPER, "Destroying ODE joints group"); dJointGroupDestroy (jointGroupID); - - worldPointer = NULL; } Modified: trunk/src/world/world.hpp =================================================================== --- trunk/src/world/world.hpp 2006-06-23 01:09:51 UTC (rev 433) +++ trunk/src/world/world.hpp 2006-06-23 02:22:08 UTC (rev 434) @@ -17,18 +17,22 @@ SHARED_PTR_MAP(Camera, pCamera, Cameras, CamerasIt); SHARED_PTR_MAP(Vehicle, pVehicle, Vehicles, VehiclesIt); SHARED_PTR_MAP(Area, pArea, Areas, AreasIt); +SHARED_PTR(World,pWorld); class World : public WorldObject { private: - static World *worldPointer; + static pWorld world; + static std::string newWorld; std::string description; pCamera activeCamera; void processXmlVehicleListNode (XmlTag * tag); void processXmlRootNode (XmlTag * tag); + World (std::string name); public: - static World *getWorldPointer (); - World (WorldObject * container, std::string name); + static pWorld get(); + static void setNewWorld(std::string name); + static void destroy(); ~World (); dWorldID worldID; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <st...@us...> - 2006-06-23 01:11:04
|
Revision: 433 Author: stenyak Date: 2006-06-22 18:09:51 -0700 (Thu, 22 Jun 2006) ViewCVS: http://svn.sourceforge.net/motorsport/?rev=433&view=rev Log Message: ----------- Converted Location pointers to shared pointers. Modified Paths: -------------- trunk/src/common/location.cpp trunk/src/common/location.hpp trunk/src/world/area.cpp trunk/src/world/area.hpp trunk/src/world/world.cpp Modified: trunk/src/common/location.cpp =================================================================== --- trunk/src/common/location.cpp 2006-06-23 00:59:23 UTC (rev 432) +++ trunk/src/common/location.cpp 2006-06-23 01:09:51 UTC (rev 433) @@ -10,6 +10,16 @@ #include "location.hpp" #include "logEngine.hpp" +pLocation Location::create(XmlTag * tag) +{ + pLocation loc(new Location(tag)); + return loc; +} +pLocation Location::create(std::string name, Vector3d position, Quaternion rotation) +{ + pLocation loc(new Location(name, position, rotation)); + return loc; +} Location::Location (XmlTag * tag) { pLogEngine log (LogEngine::create (LOG_DEVELOPER, "Location")); Modified: trunk/src/common/location.hpp =================================================================== --- trunk/src/common/location.hpp 2006-06-23 00:59:23 UTC (rev 432) +++ trunk/src/common/location.hpp 2006-06-23 01:09:51 UTC (rev 433) @@ -13,16 +13,21 @@ #include <string> #include "quaternion.hpp" #include "xmlTag.hpp" +#include <common/shared.hpp> +SHARED_PTR_MAP(Location, pLocation, Locations, LocationsIt); + class Location { private: Vector3d position; Quaternion rotation; std::string name; - public: Location (XmlTag * tag); Location (std::string name, Vector3d position, Quaternion rotation); + public: + static pLocation create(XmlTag * tag); + static pLocation create(std::string name, Vector3d position, Quaternion rotation); ~Location (); Vector3d getPosition(); Quaternion getRotation(); Modified: trunk/src/world/area.cpp =================================================================== --- trunk/src/world/area.cpp 2006-06-23 00:59:23 UTC (rev 432) +++ trunk/src/world/area.cpp 2006-06-23 01:09:51 UTC (rev 433) @@ -130,8 +130,8 @@ } if (t->getName() == "vehicleLocation") { - Location * tmp = new Location (t); - vehiclePositionMap[tmp->getName()] = tmp; + pLocation tmp = Location::create (t); + locations[tmp->getName()] = tmp; } if (t->getName() == "camera") { Modified: trunk/src/world/area.hpp =================================================================== --- trunk/src/world/area.hpp 2006-06-23 00:59:23 UTC (rev 432) +++ trunk/src/world/area.hpp 2006-06-23 01:09:51 UTC (rev 433) @@ -18,8 +18,8 @@ class Entity; class SceneNode; }; -class Location; +SHARED_PTR_MAP(Location, pLocation, Locations, LocationsIt); SHARED_PTR_MAP(Camera, pCamera, Cameras, CameraIt); SHARED_PTR_MAP(Part, pPart, Parts, PartsIt); SHARED_PTR_MAP(Area, pArea, Areas, AreasIt); @@ -36,7 +36,8 @@ public: static pArea create(WorldObject * container, std::string areaName); ~Area (); - std::map <std::string, Location * > vehiclePositionMap; + + Locations locations; Parts parts; Cameras cameras; Modified: trunk/src/world/world.cpp =================================================================== --- trunk/src/world/world.cpp 2006-06-23 00:59:23 UTC (rev 432) +++ trunk/src/world/world.cpp 2006-06-23 01:09:51 UTC (rev 433) @@ -211,15 +211,15 @@ vehicles[tmpVehicle->getName()] = tmpVehicle; log->__format (LOG_CCREATOR, "Setting vehicle starting relative rotation"); - if (areas.begin()->second->vehiclePositionMap.count(vehicleStartPosition) == 0) + if (areas.begin()->second->locations.count(vehicleStartPosition) == 0) { log->__format(LOG_ERROR, "Vehicle start position \"%s\" hasn't been defined in the area!", vehicleStartPosition.c_str()); } tmpVehicle->setPosition (Vector3d(0, 0, 0)); - tmpVehicle->applyRotation ( areas.begin()->second->vehiclePositionMap[vehicleStartPosition]->getRotation() ); + tmpVehicle->applyRotation ( areas.begin()->second->locations[vehicleStartPosition]->getRotation() ); log->__format (LOG_CCREATOR, "Setting vehicle starting position"); - tmpVehicle->setPosition (areas.begin()->second->vehiclePositionMap[vehicleStartPosition]->getPosition()); + tmpVehicle->setPosition (areas.begin()->second->locations[vehicleStartPosition]->getPosition()); } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <st...@us...> - 2006-06-23 01:00:46
|
Revision: 432 Author: stenyak Date: 2006-06-22 17:59:23 -0700 (Thu, 22 Jun 2006) ViewCVS: http://svn.sourceforge.net/motorsport/?rev=432&view=rev Log Message: ----------- Converted Part pointers to shared pointers. Modified Paths: -------------- trunk/src/graphicsEngine.cpp trunk/src/makefile trunk/src/physicsEngine.cpp trunk/src/world/area.cpp trunk/src/world/area.hpp trunk/src/world/part.cpp trunk/src/world/part.hpp Modified: trunk/src/graphicsEngine.cpp =================================================================== --- trunk/src/graphicsEngine.cpp 2006-06-23 00:46:55 UTC (rev 431) +++ trunk/src/graphicsEngine.cpp 2006-06-23 00:59:23 UTC (rev 432) @@ -211,7 +211,7 @@ World::getWorldPointer()->setActiveCamera(closestCam); World::getWorldPointer()->activeAreaCamera = closestCam; } - // Update Ogre's bodies positions with Ode's positions. + // Update Ogre's vehicles positions with Ode's positions. VehiclesIt j = World::getWorldPointer()->vehicles.begin(); for (; j != World::getWorldPointer()->vehicles.end(); j++) { @@ -219,10 +219,10 @@ } // Update Ogre's parts positions with Ode's positions. - int numberOfCubes = World::getWorldPointer ()->areas.begin()->second->partList.size (); - for (int currentCube = 0; currentCube < numberOfCubes; currentCube++) + PartsIt k = World::getWorldPointer()->areas.begin()->second->parts.begin(); + for (; k != World::getWorldPointer()->areas.begin()->second->parts.end(); k++) { - World::getWorldPointer ()->areas.begin()->second->partList[currentCube]->stepGraphics (); + k->second->stepGraphics(); } // Update cameras positions (should be done in the fsx engine FIXME Modified: trunk/src/makefile =================================================================== --- trunk/src/makefile 2006-06-23 00:46:55 UTC (rev 431) +++ trunk/src/makefile 2006-06-23 00:59:23 UTC (rev 432) @@ -48,10 +48,10 @@ ifeq ("$(PLATFORM)", "LINUX") TYPE := EXE_EXT := -#BASE_INCLUDE_DIR := /usr/include -#BASE_LIBRARY_DIR := /usr/lib -BASE_INCLUDE_DIR := $(PWD)/../3pl/linux/include -BASE_LIBRARY_DIR := $(PWD)/../3pl/linux/lib +BASE_INCLUDE_DIR := /usr/include +BASE_LIBRARY_DIR := /usr/lib +#BASE_INCLUDE_DIR := $(PWD)/../3pl/linux/include +#BASE_LIBRARY_DIR := $(PWD)/../3pl/linux/lib PLATFORM_CFLAGS := LD_FLAGS:= endif Modified: trunk/src/physicsEngine.cpp =================================================================== --- trunk/src/physicsEngine.cpp 2006-06-23 00:46:55 UTC (rev 431) +++ trunk/src/physicsEngine.cpp 2006-06-23 00:59:23 UTC (rev 432) @@ -131,10 +131,10 @@ // mega-verbosity log->__format (LOG_DEVELOPER, "Doing an step: calculating a physics step"); - int size = World::getWorldPointer ()->areas.begin()->second->partList.size (); - for (int i = 0; i < size; i++) + PartsIt k = World::getWorldPointer()->areas.begin()->second->parts.begin(); + for (; k != World::getWorldPointer()->areas.begin()->second->parts.end(); k++) { - World::getWorldPointer()->areas.begin()->second->partList[i]->stepPhysics (); + k->second->stepPhysics(); } CamerasIt i = World::getWorldPointer()->areas.begin()->second->cameras.begin(); Modified: trunk/src/world/area.cpp =================================================================== --- trunk/src/world/area.cpp 2006-06-23 00:46:55 UTC (rev 431) +++ trunk/src/world/area.cpp 2006-06-23 00:59:23 UTC (rev 432) @@ -41,14 +41,6 @@ Area::~Area () { - // unload the parts from memory - log->__format (LOG_DEVELOPER, "Unloading parts from memory..."); - int size = partList.size (); - for (int i = 0; i < size; i++) - { - delete partList[i]; - } - partList.clear (); } void Area::construct (XmlTag * tag) @@ -128,10 +120,10 @@ { position = Vector3d (u->getAttribute("position")); rotation = Quaternion (u->getAttribute("rotation")); - Part * tmp = new Part (this, u->getName()); + pPart tmp = Part::create (this, u->getName()); tmp->setPosition (position); tmp->setRotation (rotation); - partList.push_back (tmp); + parts[tmp->getName()] = tmp; tmp->stepGraphics(); SystemData::getSystemDataPointer()->ogreWindow->update (); } Modified: trunk/src/world/area.hpp =================================================================== --- trunk/src/world/area.hpp 2006-06-23 00:46:55 UTC (rev 431) +++ trunk/src/world/area.hpp 2006-06-23 00:59:23 UTC (rev 432) @@ -11,7 +11,6 @@ #define AREA_HPP #include "ode/objects.h" #include "worldObject.hpp" -#include <vector> #include "paths.hpp" //forward declatation @@ -19,10 +18,10 @@ class Entity; class SceneNode; }; -class Part; class Location; SHARED_PTR_MAP(Camera, pCamera, Cameras, CameraIt); +SHARED_PTR_MAP(Part, pPart, Parts, PartsIt); SHARED_PTR_MAP(Area, pArea, Areas, AreasIt); class Area : public WorldObject @@ -38,7 +37,7 @@ static pArea create(WorldObject * container, std::string areaName); ~Area (); std::map <std::string, Location * > vehiclePositionMap; - std::vector < Part * > partList; + Parts parts; Cameras cameras; dBodyID areaBodyID; Modified: trunk/src/world/part.cpp =================================================================== --- trunk/src/world/part.cpp 2006-06-23 00:46:55 UTC (rev 431) +++ trunk/src/world/part.cpp 2006-06-23 00:59:23 UTC (rev 432) @@ -18,6 +18,13 @@ #include "area.hpp" #include "SDL/SDL_keysym.h" + +pPart Part::create(WorldObject * container, const std::string & name) +{ + pPart part(new Part(container, name)); + return part; +} + Part::Part (WorldObject * container, const std::string & name) :WorldObject(container, name) { @@ -94,7 +101,7 @@ dBodySetAngularVel (partID, (*(dReal *) (dBodyGetAngularVel (partID) + 0)) * (dReal) (0.999), (*(dReal *) (dBodyGetAngularVel (partID) + 1)) * (dReal) (0.999), (*(dReal *) (dBodyGetAngularVel (partID) + 2)) * (dReal) (0.999)); // ////////////////////////////////////simplified air friction // applying user input [forces] - if (this == World::getWorldPointer ()->areas.begin()->second->partList[0]) + if (this == World::getWorldPointer ()->areas.begin()->second->parts.begin()->second.get()) { float moveX = SystemData::getSystemDataPointer()->axisMap[getIDKeyboardKey(SDLK_l)]->getValue(); float moveY = SystemData::getSystemDataPointer()->axisMap[getIDKeyboardKey(SDLK_i)]->getValue(); Modified: trunk/src/world/part.hpp =================================================================== --- trunk/src/world/part.hpp 2006-06-23 00:46:55 UTC (rev 431) +++ trunk/src/world/part.hpp 2006-06-23 00:59:23 UTC (rev 432) @@ -22,14 +22,17 @@ class SceneNode; } +SHARED_PTR_MAP(Part, pPart, Parts, PartsIt); + class Part : public WorldObject { private: void processXmlRootNode (XERCES_CPP_NAMESPACE::DOMNode * n); void startPhysics (XERCES_CPP_NAMESPACE::DOMNode * n); void startGraphics (XERCES_CPP_NAMESPACE::DOMNode * n); + Part (WorldObject * container, const std::string & name); public: - Part (WorldObject * container, const std::string & name); + static pPart create (WorldObject * container, const std::string & name); ~Part (); void stepPhysics (); }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <st...@us...> - 2006-06-23 00:47:26
|
Revision: 431 Author: stenyak Date: 2006-06-22 17:46:55 -0700 (Thu, 22 Jun 2006) ViewCVS: http://svn.sourceforge.net/motorsport/?rev=431&view=rev Log Message: ----------- Converted Area pointers to shared pointers. Modified Paths: -------------- trunk/src/graphicsEngine.cpp trunk/src/makefile trunk/src/physicsEngine.cpp trunk/src/world/area.cpp trunk/src/world/area.hpp trunk/src/world/part.cpp trunk/src/world/world.cpp trunk/src/world/world.hpp Modified: trunk/src/graphicsEngine.cpp =================================================================== --- trunk/src/graphicsEngine.cpp 2006-06-23 00:25:18 UTC (rev 430) +++ trunk/src/graphicsEngine.cpp 2006-06-23 00:46:55 UTC (rev 431) @@ -150,10 +150,10 @@ // change camera if needed if (systemData->axisMap[getIDKeyboardKey(SDLK_c)]->getValue() == 1) { - CamerasIt i = World::getWorldPointer()->areaList[0]->cameras.begin(); + CamerasIt i = World::getWorldPointer()->areas.begin()->second->cameras.begin(); pCamera nextCam = i->second; bool found = false; - for (;i != World::getWorldPointer()->areaList[0]->cameras.end(); i++) + for (;i != World::getWorldPointer()->areas.begin()->second->cameras.end(); i++) { if (found == true) { @@ -193,9 +193,9 @@ log->__format(LOG_DEVELOPER, "Finding closest camera"); Vector3d vPos = World::getWorldPointer()->vehicles.begin()->second->getPosition(); double closestDistance = 99999999999.0; - CamerasIt i = World::getWorldPointer()->areaList[0]->cameras.begin(); + CamerasIt i = World::getWorldPointer()->areas.begin()->second->cameras.begin(); pCamera closestCam = i->second; - for (;i != World::getWorldPointer()->areaList[0]->cameras.end(); i++) + for (;i != World::getWorldPointer()->areas.begin()->second->cameras.end(); i++) { log->__format(LOG_DEVELOPER, "Checking cam id: %s", i->second->getName().c_str()); Ogre::Vector3 p = i->second->ogreCamera->getPosition(); @@ -219,15 +219,15 @@ } // Update Ogre's parts positions with Ode's positions. - int numberOfCubes = World::getWorldPointer ()->areaList[0]->partList.size (); + int numberOfCubes = World::getWorldPointer ()->areas.begin()->second->partList.size (); for (int currentCube = 0; currentCube < numberOfCubes; currentCube++) { - World::getWorldPointer ()->areaList[0]->partList[currentCube]->stepGraphics (); + World::getWorldPointer ()->areas.begin()->second->partList[currentCube]->stepGraphics (); } // Update cameras positions (should be done in the fsx engine FIXME - CamerasIt i = World::getWorldPointer ()->areaList[0]->cameras.begin(); - for (;i != World::getWorldPointer()->areaList[0]->cameras.end(); i++) + CamerasIt i = World::getWorldPointer ()->areas.begin()->second->cameras.begin(); + for (;i != World::getWorldPointer()->areas.begin()->second->cameras.end(); i++) { i->second->stepGraphics(); } @@ -238,19 +238,19 @@ } // Update infinite plane position according to vehicle position - Ogre::Vector3 areaPos (World::getWorldPointer()->areaList[0]->planeNode->getPosition()); + Ogre::Vector3 areaPos (World::getWorldPointer()->areas.begin()->second->planeNode->getPosition()); Vector3d vehiclePos (World::getWorldPointer()->vehicles.begin()->second->getPosition()); Vector3d diff (areaPos.x - vehiclePos.x, areaPos.y - vehiclePos.y, areaPos.z - vehiclePos.z); const double tile = 1000.0 / 20.0; if (diff.x > tile || diff.x < -tile) areaPos.x -= int ((diff.x) / (tile)) * (tile); if (diff.y > tile || diff.y < -tile) areaPos.y -= int ((diff.y) / (tile)) * (tile); - World::getWorldPointer()->areaList[0]->planeNode->setPosition(areaPos); + World::getWorldPointer()->areas.begin()->second->planeNode->setPosition(areaPos); // Update area shadows state - World::getWorldPointer()->areaList[0]->setCastShadows(castAreaShadows); + World::getWorldPointer()->areas.begin()->second->setCastShadows(castAreaShadows); // Update area render mode - World::getWorldPointer ()->areaList[0]->setRenderDetail(areaRenderMode); + World::getWorldPointer ()->areas.begin()->second->setRenderDetail(areaRenderMode); // Let the listener frames be started and ended: they are needed for particle systems. ogreRoot->_fireFrameStarted (); Modified: trunk/src/makefile =================================================================== --- trunk/src/makefile 2006-06-23 00:25:18 UTC (rev 430) +++ trunk/src/makefile 2006-06-23 00:46:55 UTC (rev 431) @@ -48,10 +48,10 @@ ifeq ("$(PLATFORM)", "LINUX") TYPE := EXE_EXT := -BASE_INCLUDE_DIR := /usr/include -BASE_LIBRARY_DIR := /usr/lib -#BASE_INCLUDE_DIR := $(PWD)/../3pl/linux/include -#BASE_LIBRARY_DIR := $(PWD)/../3pl/linux/lib +#BASE_INCLUDE_DIR := /usr/include +#BASE_LIBRARY_DIR := /usr/lib +BASE_INCLUDE_DIR := $(PWD)/../3pl/linux/include +BASE_LIBRARY_DIR := $(PWD)/../3pl/linux/lib PLATFORM_CFLAGS := LD_FLAGS:= endif Modified: trunk/src/physicsEngine.cpp =================================================================== --- trunk/src/physicsEngine.cpp 2006-06-23 00:25:18 UTC (rev 430) +++ trunk/src/physicsEngine.cpp 2006-06-23 00:46:55 UTC (rev 431) @@ -131,14 +131,14 @@ // mega-verbosity log->__format (LOG_DEVELOPER, "Doing an step: calculating a physics step"); - int size = World::getWorldPointer ()->areaList[0]->partList.size (); + int size = World::getWorldPointer ()->areas.begin()->second->partList.size (); for (int i = 0; i < size; i++) { - World::getWorldPointer()->areaList[0]->partList[i]->stepPhysics (); + World::getWorldPointer()->areas.begin()->second->partList[i]->stepPhysics (); } - CamerasIt i = World::getWorldPointer()->areaList[0]->cameras.begin(); - for(;i != World::getWorldPointer()->areaList[0]->cameras.end();i++) + CamerasIt i = World::getWorldPointer()->areas.begin()->second->cameras.begin(); + for(;i != World::getWorldPointer()->areas.begin()->second->cameras.end();i++) { i->second->stepPhysics(); } Modified: trunk/src/world/area.cpp =================================================================== --- trunk/src/world/area.cpp 2006-06-23 00:25:18 UTC (rev 430) +++ trunk/src/world/area.cpp 2006-06-23 00:46:55 UTC (rev 431) @@ -21,6 +21,11 @@ void getMeshInformation (Ogre::MeshPtr mesh, size_t & vertex_count, dVector3 * &vertices, size_t & index_count, unsigned *&indices, const Ogre::Vector3 & position = Ogre::Vector3::ZERO, const Ogre::Quaternion & orient = Ogre::Quaternion::IDENTITY, const Ogre::Vector3 & scale = Ogre::Vector3::UNIT_SCALE); +pArea Area::create (WorldObject * container, std::string areaName) +{ + pArea area(new Area(container, areaName)); + return area; +} Area::Area (WorldObject * container, std::string areaName) :WorldObject(container, areaName) { Modified: trunk/src/world/area.hpp =================================================================== --- trunk/src/world/area.hpp 2006-06-23 00:25:18 UTC (rev 430) +++ trunk/src/world/area.hpp 2006-06-23 00:46:55 UTC (rev 431) @@ -23,6 +23,7 @@ class Location; SHARED_PTR_MAP(Camera, pCamera, Cameras, CameraIt); +SHARED_PTR_MAP(Area, pArea, Areas, AreasIt); class Area : public WorldObject { @@ -32,8 +33,9 @@ std::string contact; std::string license; void construct (XmlTag * tag); + Area (WorldObject * container, std::string areaName); public: - Area (WorldObject * container, std::string areaName); + static pArea create(WorldObject * container, std::string areaName); ~Area (); std::map <std::string, Location * > vehiclePositionMap; std::vector < Part * > partList; Modified: trunk/src/world/part.cpp =================================================================== --- trunk/src/world/part.cpp 2006-06-23 00:25:18 UTC (rev 430) +++ trunk/src/world/part.cpp 2006-06-23 00:46:55 UTC (rev 431) @@ -94,7 +94,7 @@ dBodySetAngularVel (partID, (*(dReal *) (dBodyGetAngularVel (partID) + 0)) * (dReal) (0.999), (*(dReal *) (dBodyGetAngularVel (partID) + 1)) * (dReal) (0.999), (*(dReal *) (dBodyGetAngularVel (partID) + 2)) * (dReal) (0.999)); // ////////////////////////////////////simplified air friction // applying user input [forces] - if (this == World::getWorldPointer ()->areaList[0]->partList[0]) + if (this == World::getWorldPointer ()->areas.begin()->second->partList[0]) { float moveX = SystemData::getSystemDataPointer()->axisMap[getIDKeyboardKey(SDLK_l)]->getValue(); float moveY = SystemData::getSystemDataPointer()->axisMap[getIDKeyboardKey(SDLK_i)]->getValue(); Modified: trunk/src/world/world.cpp =================================================================== --- trunk/src/world/world.cpp 2006-06-23 00:25:18 UTC (rev 430) +++ trunk/src/world/world.cpp 2006-06-23 00:46:55 UTC (rev 431) @@ -56,18 +56,10 @@ activeAreaCamera.reset(); activeVehicleCamera.reset(); - //shouldn't be necessary, but vehicle geoms can't be deleted after ode world so we must make sure! + //shouldn't be necessary, but vehicle and area geoms can't be deleted after ode world so we must make sure! vehicles.clear(); + areas.clear(); - log->__format (LOG_DEVELOPER, "Unloading areas from memory..."); - int size = areaList.size (); - for (int i = 0; i < size; i++) - { - delete areaList[i]; - areaList[i] = 0; - } - areaList.clear (); - log->__format (LOG_DEVELOPER, "Destroying ODE world"); dSpaceDestroy (spaceID); log->__format (LOG_DEVELOPER, "Destroying ODE main collision space"); @@ -136,19 +128,19 @@ // load area (and its cameras) log->loadscreen (LOG_CCREATOR, "Creating a area"); - Area * area = new Area (this, areaDirectory); + pArea area = Area::create (this, areaDirectory); //area->setPosition (0.0, 0.0, 0.0); //evo2 maybe... ;) - areaList.push_back (area); + areas[area->getName()] = area; // load all vehicles log->loadscreen (LOG_CCREATOR, "Creating all vehicles"); processXmlVehicleListNode (vehiclesTag); // initialize cameras (pointing to car 0 by default) - CamerasIt i = areaList[0]->cameras.begin(); - for(;i != areaList[0]->cameras.end(); i++) + CamerasIt i = areas.begin()->second->cameras.begin(); + for(;i != areas.begin()->second->cameras.end(); i++) { - i->second->setPositionID( areaList[0]->areaBodyID ); + i->second->setPositionID( areas.begin()->second->areaBodyID ); i->second->setTarget( vehicles.begin()->second->getMainOdeObject()); } i = vehicles.begin()->second->cameras.begin(); @@ -163,12 +155,12 @@ if (useAreaCamera) { //err... use... area camera, i guess. - setActiveCamera (areaList[0]->cameras.begin()->second); + setActiveCamera (areas.begin()->second->cameras.begin()->second); } else { //don't use area camera: use vehicle camera setActiveCamera (vehicles.begin()->second->cameras.begin()->second); } - activeAreaCamera = areaList[0]->cameras.begin()->second; + activeAreaCamera = areas.begin()->second->cameras.begin()->second; activeVehicleCamera = vehicles.begin()->second->cameras.begin()->second; } @@ -187,7 +179,7 @@ pCamera World::getActiveAreaCamera() { - return areaList[0]->cameras[activeAreaCamera->getName()]; + return areas.begin()->second->cameras[activeAreaCamera->getName()]; } pCamera World::getActiveVehicleCamera() @@ -219,15 +211,15 @@ vehicles[tmpVehicle->getName()] = tmpVehicle; log->__format (LOG_CCREATOR, "Setting vehicle starting relative rotation"); - if (areaList[0]->vehiclePositionMap.count(vehicleStartPosition) == 0) + if (areas.begin()->second->vehiclePositionMap.count(vehicleStartPosition) == 0) { log->__format(LOG_ERROR, "Vehicle start position \"%s\" hasn't been defined in the area!", vehicleStartPosition.c_str()); } tmpVehicle->setPosition (Vector3d(0, 0, 0)); - tmpVehicle->applyRotation ( areaList[0]->vehiclePositionMap[vehicleStartPosition]->getRotation() ); + tmpVehicle->applyRotation ( areas.begin()->second->vehiclePositionMap[vehicleStartPosition]->getRotation() ); log->__format (LOG_CCREATOR, "Setting vehicle starting position"); - tmpVehicle->setPosition (areaList[0]->vehiclePositionMap[vehicleStartPosition]->getPosition()); + tmpVehicle->setPosition (areas.begin()->second->vehiclePositionMap[vehicleStartPosition]->getPosition()); } } } Modified: trunk/src/world/world.hpp =================================================================== --- trunk/src/world/world.hpp 2006-06-23 00:25:18 UTC (rev 430) +++ trunk/src/world/world.hpp 2006-06-23 00:46:55 UTC (rev 431) @@ -11,16 +11,12 @@ #define WORLD_HPP #include "SDL/SDL_types.h" #include "ode/objects.h" -#include <vector> -#include <string> #include "worldObject.hpp" //forward declaration -class Area; -class Vehicle; - SHARED_PTR_MAP(Camera, pCamera, Cameras, CamerasIt); SHARED_PTR_MAP(Vehicle, pVehicle, Vehicles, VehiclesIt); +SHARED_PTR_MAP(Area, pArea, Areas, AreasIt); class World : public WorldObject { @@ -40,7 +36,7 @@ dSpaceID spaceID; dJointGroupID jointGroupID; - std::vector < Area * > areaList; + Areas areas; Vehicles vehicles; void setActiveCamera (pCamera camera); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <st...@us...> - 2006-06-23 00:25:56
|
Revision: 430 Author: stenyak Date: 2006-06-22 17:25:18 -0700 (Thu, 22 Jun 2006) ViewCVS: http://svn.sourceforge.net/motorsport/?rev=430&view=rev Log Message: ----------- Converted Vehicle pointers to shared pointers. Modified Paths: -------------- trunk/src/graphicsEngine.cpp trunk/src/log/logEngine.cpp trunk/src/physicsEngine.cpp trunk/src/vehicle/body.cpp trunk/src/vehicle/vehicle.cpp trunk/src/vehicle/vehicle.hpp trunk/src/world/world.cpp trunk/src/world/world.hpp Modified: trunk/src/graphicsEngine.cpp =================================================================== --- trunk/src/graphicsEngine.cpp 2006-06-22 23:08:05 UTC (rev 429) +++ trunk/src/graphicsEngine.cpp 2006-06-23 00:25:18 UTC (rev 430) @@ -170,10 +170,10 @@ } if (systemData->axisMap[getIDKeyboardKey(SDLK_v)]->getValue() == 1) { - CamerasIt i = World::getWorldPointer()->vehicleList[0]->cameras.begin(); + CamerasIt i = World::getWorldPointer()->vehicles.begin()->second->cameras.begin(); pCamera nextCam = i->second; bool found = false; - for (;i != World::getWorldPointer()->vehicleList[0]->cameras.end(); i++) + for (;i != World::getWorldPointer()->vehicles.begin()->second->cameras.end(); i++) { if (found == true) { @@ -191,7 +191,7 @@ if (systemData->cameraDirector) { log->__format(LOG_DEVELOPER, "Finding closest camera"); - Vector3d vPos = World::getWorldPointer()->vehicleList[0]->getPosition(); + Vector3d vPos = World::getWorldPointer()->vehicles.begin()->second->getPosition(); double closestDistance = 99999999999.0; CamerasIt i = World::getWorldPointer()->areaList[0]->cameras.begin(); pCamera closestCam = i->second; @@ -212,10 +212,10 @@ World::getWorldPointer()->activeAreaCamera = closestCam; } // Update Ogre's bodies positions with Ode's positions. - int numberOfVehicles = World::getWorldPointer ()->vehicleList.size (); - for (int currentVehicle = 0; currentVehicle < numberOfVehicles; currentVehicle++) + VehiclesIt j = World::getWorldPointer()->vehicles.begin(); + for (; j != World::getWorldPointer()->vehicles.end(); j++) { - World::getWorldPointer ()->vehicleList[currentVehicle]->stepGraphics (); + j->second->stepGraphics(); } // Update Ogre's parts positions with Ode's positions. @@ -231,15 +231,15 @@ { i->second->stepGraphics(); } - i = World::getWorldPointer ()->vehicleList[0]->cameras.begin(); - for (;i != World::getWorldPointer()->vehicleList[0]->cameras.end(); i++) + i = World::getWorldPointer ()->vehicles.begin()->second->cameras.begin(); + for (;i != World::getWorldPointer()->vehicles.begin()->second->cameras.end(); i++) { i->second->stepGraphics(); } // Update infinite plane position according to vehicle position Ogre::Vector3 areaPos (World::getWorldPointer()->areaList[0]->planeNode->getPosition()); - Vector3d vehiclePos (World::getWorldPointer()->vehicleList[0]->getPosition()); + Vector3d vehiclePos (World::getWorldPointer()->vehicles.begin()->second->getPosition()); Vector3d diff (areaPos.x - vehiclePos.x, areaPos.y - vehiclePos.y, areaPos.z - vehiclePos.z); const double tile = 1000.0 / 20.0; if (diff.x > tile || diff.x < -tile) areaPos.x -= int ((diff.x) / (tile)) * (tile); Modified: trunk/src/log/logEngine.cpp =================================================================== --- trunk/src/log/logEngine.cpp 2006-06-22 23:08:05 UTC (rev 429) +++ trunk/src/log/logEngine.cpp 2006-06-23 00:25:18 UTC (rev 430) @@ -74,7 +74,7 @@ snprintf (numberString, numberStringSize, "%i", instancesCount); logEngines[std::string("LOG#") + numberString + "#." + name] = log; - return pLogEngine(log); + return log; } LogEngine::LogEngine (LOG_LEVEL localLevel, const std::string & name):logLevel (localLevel), logName (name) { Modified: trunk/src/physicsEngine.cpp =================================================================== --- trunk/src/physicsEngine.cpp 2006-06-22 23:08:05 UTC (rev 429) +++ trunk/src/physicsEngine.cpp 2006-06-23 00:25:18 UTC (rev 430) @@ -142,8 +142,8 @@ { i->second->stepPhysics(); } - i = World::getWorldPointer()->vehicleList[0]->cameras.begin(); - for(;i != World::getWorldPointer()->vehicleList[0]->cameras.end();i++) + i = World::getWorldPointer()->vehicles.begin()->second->cameras.begin(); + for(;i != World::getWorldPointer()->vehicles.begin()->second->cameras.end();i++) { i->second->stepPhysics(); } @@ -162,10 +162,10 @@ dWorldStepFast1 (World::getWorldPointer ()->worldID, systemData->getDesiredPhysicsTimestep(), dWorldStepFast1MaxIterations); break; } - size = World::getWorldPointer ()->vehicleList.size (); - for (int i = 0; i < size; i++) + VehiclesIt j = World::getWorldPointer()->vehicles.begin(); + for (; j != World::getWorldPointer()->vehicles.end(); j++) { - World::getWorldPointer ()->vehicleList[i]->stepPhysics (); + j->second->stepPhysics(); } dJointGroupEmpty (World::getWorldPointer ()->jointGroupID); Modified: trunk/src/vehicle/body.cpp =================================================================== --- trunk/src/vehicle/body.cpp 2006-06-22 23:08:05 UTC (rev 429) +++ trunk/src/vehicle/body.cpp 2006-06-23 00:25:18 UTC (rev 430) @@ -74,7 +74,7 @@ void Body::stepPhysics () { dBodyID bodyID = getMainOdeObject()->getBodyID(); - if (this == World::getWorldPointer ()->vehicleList[0]->getObject("body")) + if (this == World::getWorldPointer ()->vehicles.begin()->second->getObject("body")) { double moveZ = SystemData::getSystemDataPointer()->axisMap[getIDKeyboardKey(SDLK_BACKSPACE)]->getValue() * 50000; moveZ += SystemData::getSystemDataPointer()->axisMap[getIDKeyboardKey(SDLK_RETURN)]->getValue() * 12200; Modified: trunk/src/vehicle/vehicle.cpp =================================================================== --- trunk/src/vehicle/vehicle.cpp 2006-06-22 23:08:05 UTC (rev 429) +++ trunk/src/vehicle/vehicle.cpp 2006-06-23 00:25:18 UTC (rev 430) @@ -25,6 +25,11 @@ #include "SDL/SDL_keysym.h" #include "quaternion.hpp" +pVehicle Vehicle::create(WorldObject * container, std::string vehicleName) +{ + pVehicle vehicle(new Vehicle(container, vehicleName)); + return vehicle; +} Vehicle::Vehicle (WorldObject * container, std::string vehicleName) :WorldObject(container, vehicleName) { Modified: trunk/src/vehicle/vehicle.hpp =================================================================== --- trunk/src/vehicle/vehicle.hpp 2006-06-22 23:08:05 UTC (rev 429) +++ trunk/src/vehicle/vehicle.hpp 2006-06-23 00:25:18 UTC (rev 430) @@ -32,6 +32,7 @@ class CameraPosition; SHARED_PTR_MAP(Camera, pCamera, Cameras, CameraIt); +SHARED_PTR_MAP(Vehicle, pVehicle, Vehicles, VehiclesIt); class Vehicle : public WorldObject { @@ -47,9 +48,9 @@ void boltWheelsToSuspensions(); void stopGraphics (); WorldObjects components; + Vehicle (WorldObject * container, std::string vehicleName); public: - Vehicle (WorldObject * container, std::string vehicleName); - Vehicle (WorldObject * container, XmlTag * tag); + static pVehicle create(WorldObject * container, std::string vehicleName); ~Vehicle (); Cameras cameras; Body * getBody (std::string name); Modified: trunk/src/world/world.cpp =================================================================== --- trunk/src/world/world.cpp 2006-06-22 23:08:05 UTC (rev 429) +++ trunk/src/world/world.cpp 2006-06-23 00:25:18 UTC (rev 430) @@ -56,18 +56,11 @@ activeAreaCamera.reset(); activeVehicleCamera.reset(); - // unload the bodies from memory - log->__format (LOG_DEVELOPER, "Unloading vehicles from memory..."); - int size = vehicleList.size (); - for (int i = 0; i < size; i++) - { - delete vehicleList[i]; - vehicleList[i] = NULL; - } - vehicleList.clear (); + //shouldn't be necessary, but vehicle geoms can't be deleted after ode world so we must make sure! + vehicles.clear(); log->__format (LOG_DEVELOPER, "Unloading areas from memory..."); - size = areaList.size (); + int size = areaList.size (); for (int i = 0; i < size; i++) { delete areaList[i]; @@ -93,7 +86,7 @@ double gravityX = 0.0; double gravityY = 0.0; double gravityZ = 0.0; - XmlTag * vehicleListTag = NULL; + XmlTag * vehiclesTag = NULL; bool useAreaCamera = true; //if false, use vehicle camera std::string areaDirectory = "testingGround"; @@ -109,7 +102,7 @@ { if (t->getName() == "vehicleList") { - vehicleListTag = t; + vehiclesTag = t; } if (t->getName() == "area") { @@ -149,20 +142,20 @@ // load all vehicles log->loadscreen (LOG_CCREATOR, "Creating all vehicles"); - processXmlVehicleListNode (vehicleListTag); + processXmlVehicleListNode (vehiclesTag); // initialize cameras (pointing to car 0 by default) CamerasIt i = areaList[0]->cameras.begin(); for(;i != areaList[0]->cameras.end(); i++) { i->second->setPositionID( areaList[0]->areaBodyID ); - i->second->setTarget( vehicleList[0]->getMainOdeObject()); + i->second->setTarget( vehicles.begin()->second->getMainOdeObject()); } - i = vehicleList[0]->cameras.begin(); - for(;i != vehicleList[0]->cameras.end(); i++) + i = vehicles.begin()->second->cameras.begin(); + for(;i != vehicles.begin()->second->cameras.end(); i++) { - i->second->setPositionID( vehicleList[0]->getMainOdeObject()->getBodyID()); - i->second->setTarget( vehicleList[0]->getMainOdeObject() ); + i->second->setPositionID( vehicles.begin()->second->getMainOdeObject()->getBodyID()); + i->second->setTarget( vehicles.begin()->second->getMainOdeObject() ); } // set active camera @@ -173,10 +166,10 @@ setActiveCamera (areaList[0]->cameras.begin()->second); } else { //don't use area camera: use vehicle camera - setActiveCamera (vehicleList[0]->cameras.begin()->second); + setActiveCamera (vehicles.begin()->second->cameras.begin()->second); } activeAreaCamera = areaList[0]->cameras.begin()->second; - activeVehicleCamera = vehicleList[0]->cameras.begin()->second; + activeVehicleCamera = vehicles.begin()->second->cameras.begin()->second; } void World::setActiveCamera (pCamera camera) @@ -199,7 +192,7 @@ pCamera World::getActiveVehicleCamera() { - return vehicleList[0]->cameras[activeVehicleCamera->getName()]; + return vehicles.begin()->second->cameras[activeVehicleCamera->getName()]; } void World::processXmlVehicleListNode (XmlTag * tag) @@ -218,12 +211,12 @@ vehicleStartPosition = t->getAttribute("startPosition"); log->loadscreen (LOG_CCREATOR, "Creating a vehicle"); - Vehicle * tmpVehicle = new Vehicle (this, vehicleDirectory); + pVehicle tmpVehicle = Vehicle::create(this, vehicleDirectory); if (driver == "user" ) { tmpVehicle->setUserDriver(); } - vehicleList.push_back (tmpVehicle); + vehicles[tmpVehicle->getName()] = tmpVehicle; log->__format (LOG_CCREATOR, "Setting vehicle starting relative rotation"); if (areaList[0]->vehiclePositionMap.count(vehicleStartPosition) == 0) Modified: trunk/src/world/world.hpp =================================================================== --- trunk/src/world/world.hpp 2006-06-22 23:08:05 UTC (rev 429) +++ trunk/src/world/world.hpp 2006-06-23 00:25:18 UTC (rev 430) @@ -20,6 +20,7 @@ class Vehicle; SHARED_PTR_MAP(Camera, pCamera, Cameras, CamerasIt); +SHARED_PTR_MAP(Vehicle, pVehicle, Vehicles, VehiclesIt); class World : public WorldObject { @@ -40,7 +41,7 @@ dJointGroupID jointGroupID; std::vector < Area * > areaList; - std::vector < Vehicle * > vehicleList; + Vehicles vehicles; void setActiveCamera (pCamera camera); pCamera getActiveCamera(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <st...@us...> - 2006-06-22 23:08:36
|
Revision: 429 Author: stenyak Date: 2006-06-22 16:08:05 -0700 (Thu, 22 Jun 2006) ViewCVS: http://svn.sourceforge.net/motorsport/?rev=429&view=rev Log Message: ----------- Converted all camera pointers to shared pointers. Converted all camera vectors to camera maps (string index). Removed unused variables in camera class. Fixed minor memory leak in camera constructor. Added static deleteAll() method to LogEngine, unused atm. Modified Paths: -------------- trunk/src/common/camera.cpp trunk/src/common/camera.hpp trunk/src/graphicsEngine.cpp trunk/src/inputEngine.cpp trunk/src/log/logEngine.cpp trunk/src/log/logEngine.hpp trunk/src/main.cpp trunk/src/makefile trunk/src/physicsEngine.cpp trunk/src/vehicle/vehicle.cpp trunk/src/vehicle/vehicle.hpp trunk/src/world/area.cpp trunk/src/world/area.hpp trunk/src/world/world.cpp trunk/src/world/world.hpp Modified: trunk/src/common/camera.cpp =================================================================== --- trunk/src/common/camera.cpp 2006-06-22 15:43:57 UTC (rev 428) +++ trunk/src/common/camera.cpp 2006-06-22 23:08:05 UTC (rev 429) @@ -21,6 +21,12 @@ #include "area.hpp" #include "vector3d.hpp" +pCamera Camera::create(WorldObject * container, XmlTag * tag) +{ + pCamera p (new Camera(container, tag)); + return p; +} + Camera::Camera (WorldObject * container, XmlTag * tag) :WorldObject(container, "camera") { @@ -37,11 +43,13 @@ if (tag->getName() == "camera") { setName ( tag->getAttribute("name")); - *positionOffset = Vector3d (tag->getAttribute("position")); + delete positionOffset; + positionOffset = new Vector3d (tag->getAttribute("position")); std::string t = ""; if ( (t = tag->getAttribute("target")) != "") { - *targetOffset = Vector3d (t); + delete targetOffset; + targetOffset = new Vector3d (t); } /* else @@ -135,7 +143,7 @@ void Camera::stepPhysics () { - if (this == World::getWorldPointer()->getActiveCamera() ) + if (this == World::getWorldPointer()->getActiveCamera().get() ) { static bool wasPressed = false; if (SystemData::getSystemDataPointer()->axisMap[getIDKeyboardKey(SDLK_x)]->getValue() == 1) Modified: trunk/src/common/camera.hpp =================================================================== --- trunk/src/common/camera.hpp 2006-06-22 15:43:57 UTC (rev 428) +++ trunk/src/common/camera.hpp 2006-06-22 23:08:05 UTC (rev 429) @@ -19,6 +19,8 @@ class Vector3d; +SHARED_PTR_MAP(Camera, pCamera, Cameras, CamerasIt); + class Camera : public WorldObject { private: @@ -28,8 +30,9 @@ dBodyID targetID; Vector3d * targetOffset; void stopPhysics(); + Camera (WorldObject * container, XmlTag * tag); public: - Camera (WorldObject * container, XmlTag * tag); + static pCamera create(WorldObject * container, XmlTag * tag); ~Camera (); void updateOgreRotation (); Vector3d updateOgrePosition (); Modified: trunk/src/graphicsEngine.cpp =================================================================== --- trunk/src/graphicsEngine.cpp 2006-06-22 15:43:57 UTC (rev 428) +++ trunk/src/graphicsEngine.cpp 2006-06-22 23:08:05 UTC (rev 429) @@ -150,49 +150,66 @@ // change camera if needed if (systemData->axisMap[getIDKeyboardKey(SDLK_c)]->getValue() == 1) { - int nextCam; - nextCam = World::getWorldPointer()->getActiveAreaCameraIndex()+1; - int maxCams = World::getWorldPointer()->areaList[0]->cameraList.size(); - if (nextCam >= maxCams ) + CamerasIt i = World::getWorldPointer()->areaList[0]->cameras.begin(); + pCamera nextCam = i->second; + bool found = false; + for (;i != World::getWorldPointer()->areaList[0]->cameras.end(); i++) { - nextCam = 0; + if (found == true) + { + nextCam = i->second; + found = false; + } + if (World::getWorldPointer()->getActiveAreaCamera()->getName() == i->second->getName()) + { + found = true; + } } - World::getWorldPointer()->setActiveCamera(World::getWorldPointer ()->areaList[0]->cameraList[nextCam]); - World::getWorldPointer()->activeAreaCamera = World::getWorldPointer()->areaList[0]->cameraList[nextCam]; + World::getWorldPointer()->setActiveCamera(nextCam); + World::getWorldPointer()->activeAreaCamera = nextCam; } if (systemData->axisMap[getIDKeyboardKey(SDLK_v)]->getValue() == 1) { - int nextCam = World::getWorldPointer()->getActiveVehicleCameraIndex()+1; - int maxCams = World::getWorldPointer()->vehicleList[0]->cameraList.size(); - if (nextCam >= maxCams ) + CamerasIt i = World::getWorldPointer()->vehicleList[0]->cameras.begin(); + pCamera nextCam = i->second; + bool found = false; + for (;i != World::getWorldPointer()->vehicleList[0]->cameras.end(); i++) { - nextCam = 0; + if (found == true) + { + nextCam = i->second; + found = false; + } + if (World::getWorldPointer()->getActiveVehicleCamera()->getName() == i->second->getName()) + { + found = true; + } } - World::getWorldPointer()->setActiveCamera(World::getWorldPointer ()->vehicleList[0]->cameraList[nextCam]); - World::getWorldPointer()->activeVehicleCamera = World::getWorldPointer()->vehicleList[0]->cameraList[nextCam]; + World::getWorldPointer()->setActiveCamera(nextCam); + World::getWorldPointer()->activeVehicleCamera = nextCam; } if (systemData->cameraDirector) { log->__format(LOG_DEVELOPER, "Finding closest camera"); Vector3d vPos = World::getWorldPointer()->vehicleList[0]->getPosition(); - int closestCam = 0; double closestDistance = 99999999999.0; - for (unsigned int i = 0; i<World::getWorldPointer()->areaList[0]->cameraList.size(); i++) + CamerasIt i = World::getWorldPointer()->areaList[0]->cameras.begin(); + pCamera closestCam = i->second; + for (;i != World::getWorldPointer()->areaList[0]->cameras.end(); i++) { - log->__format(LOG_DEVELOPER, "Checking cam#%i",i); - Ogre::Vector3 p = World::getWorldPointer()->areaList[0]->cameraList[i]->ogreCamera->getPosition(); + log->__format(LOG_DEVELOPER, "Checking cam id: %s", i->second->getName().c_str()); + Ogre::Vector3 p = i->second->ogreCamera->getPosition(); Vector3d cPos (p.x, p.y, p.z); double distance = cPos.distance(vPos); if (distance < closestDistance) { closestDistance = distance; - closestCam = i; + closestCam = i->second; } + } - log->__format(LOG_DEVELOPER, "Closest camera: %i. Distance: %f", closestCam, closestDistance); - - World::getWorldPointer()->setActiveCamera(World::getWorldPointer ()->areaList[0]->cameraList[closestCam]); - World::getWorldPointer()->activeAreaCamera = World::getWorldPointer()->areaList[0]->cameraList[closestCam]; + World::getWorldPointer()->setActiveCamera(closestCam); + World::getWorldPointer()->activeAreaCamera = closestCam; } // Update Ogre's bodies positions with Ode's positions. int numberOfVehicles = World::getWorldPointer ()->vehicleList.size (); @@ -208,16 +225,16 @@ World::getWorldPointer ()->areaList[0]->partList[currentCube]->stepGraphics (); } - // Update cameras positions (should be done in the fsx engine FIXME. - int numberOfCameras = World::getWorldPointer ()->areaList[0]->cameraList.size (); - for (int currentCamera = 0; currentCamera < numberOfCameras; currentCamera++) + // Update cameras positions (should be done in the fsx engine FIXME + CamerasIt i = World::getWorldPointer ()->areaList[0]->cameras.begin(); + for (;i != World::getWorldPointer()->areaList[0]->cameras.end(); i++) { - World::getWorldPointer ()->areaList[0]->cameraList[currentCamera]->stepGraphics (); + i->second->stepGraphics(); } - numberOfCameras = World::getWorldPointer ()->vehicleList[0]->cameraList.size (); - for (int currentCamera = 0; currentCamera < numberOfCameras; currentCamera++) + i = World::getWorldPointer ()->vehicleList[0]->cameras.begin(); + for (;i != World::getWorldPointer()->vehicleList[0]->cameras.end(); i++) { - World::getWorldPointer ()->vehicleList[0]->cameraList[currentCamera]->stepGraphics (); + i->second->stepGraphics(); } // Update infinite plane position according to vehicle position Modified: trunk/src/inputEngine.cpp =================================================================== --- trunk/src/inputEngine.cpp 2006-06-22 15:43:57 UTC (rev 428) +++ trunk/src/inputEngine.cpp 2006-06-22 23:08:05 UTC (rev 429) @@ -172,11 +172,13 @@ } } - int numAreaCams = World::getWorldPointer()->areaList[0]->cameraList.size(); + /*/TODO: convert to shared poinetrs code if/when necessary + int numAreaCams = World::getWorldPointer()->areaList[0]->cameras.size(); for (int i=0; i < numAreaCams; i++) { //World::getWorldPointer()->areaList[0]->cameraList[i]->stepInput(); } + //*/ /* Be careful with this debugging code!! you need to have created all the axis you're going to debug! log->telemetry (LOG_ENDUSER, "%5.4f %5.4f %5.4f %5.4f %5.4f %5.4f %5.4f %5.4f %5.4f %5.4f %5.4f %5.4f", Modified: trunk/src/log/logEngine.cpp =================================================================== --- trunk/src/log/logEngine.cpp 2006-06-22 15:43:57 UTC (rev 428) +++ trunk/src/log/logEngine.cpp 2006-06-22 23:08:05 UTC (rev 429) @@ -27,6 +27,13 @@ unsigned int LogEngine::instancesCount = 0; LogEngines LogEngine::logEngines; +void LogEngine::deleteAll() +{ + while( !logEngines.empty() ) + { + logEngines.erase( logEngines.begin() ); + } +} pLogEngine LogEngine::create(LOG_LEVEL localLevel, const std::string & name) { // open the file for writing in rewrite mode if necessary. @@ -80,15 +87,27 @@ LogEngine::~LogEngine () { LogEnginesIt i = logEngines.begin(); + LogEnginesIt d; for(;i != logEngines.end(); i++) { - if (this == i->second.get()) logEngines.erase(i); + if (this == i->second.get()) + { + d = i; + //d->second->format(LOG_ENDUSER, "I'm gonna be deleted! :D"); + } + else + { + //i->second->format(LOG_ENDUSER, "I'm still left! :D"); + } } - if (logEngines.empty()) + logEngines.erase(d); + //Check if this is the last log engine in the map.If it is, since we're gonna delete it, we close the log file. + if (logEngines.size() <= 1) { format (LOG_ENDUSER, "Closing logFile"); logFile.close (); } + //format (LOG_ENDUSER, "--------------------------LogFile size: %i", logEngines.size()); } void LogEngine::logAll() @@ -96,7 +115,7 @@ LogEnginesIt i = logEngines.begin(); for(;i != logEngines.end(); i++) { - i->second->__format(LOG_DEVELOPER, "LogEngine Id: %s\t Instances: %i", i->first.c_str(), i->second.use_count()); + i->second->__format(LOG_DEVELOPER, "LogEngine Id: %s\t References #: %i", i->first.c_str(), i->second.use_count()); } } Modified: trunk/src/log/logEngine.hpp =================================================================== --- trunk/src/log/logEngine.hpp 2006-06-22 15:43:57 UTC (rev 428) +++ trunk/src/log/logEngine.hpp 2006-06-22 23:08:05 UTC (rev 429) @@ -92,6 +92,7 @@ */ LogEngine (LOG_LEVEL localLevel, const std::string & name); public: + static void deleteAll(); static pLogEngine create(LOG_LEVEL localLevel, const std::string & name); // / Deletes the log engine, closing the log file if needed. /** Deletes the log engine and associated data. If there's no other log engines left, the log file will be closed. Modified: trunk/src/main.cpp =================================================================== --- trunk/src/main.cpp 2006-06-22 15:43:57 UTC (rev 428) +++ trunk/src/main.cpp 2006-06-22 23:08:05 UTC (rev 429) @@ -155,7 +155,9 @@ //FIXME: uncomment later on //WorldObject::logAll(); LogEngine::logAll(); + //LogEngine::deleteAll(); + log->__format (LOG_DEVELOPER, "About to exit motorsport"); // We go back to the OS. return (0); } Modified: trunk/src/makefile =================================================================== Modified: trunk/src/physicsEngine.cpp =================================================================== --- trunk/src/physicsEngine.cpp 2006-06-22 15:43:57 UTC (rev 428) +++ trunk/src/physicsEngine.cpp 2006-06-22 23:08:05 UTC (rev 429) @@ -137,17 +137,16 @@ World::getWorldPointer()->areaList[0]->partList[i]->stepPhysics (); } - int numberOfCameras = World::getWorldPointer ()->areaList[0]->cameraList.size (); - for (int currentCamera = 0; currentCamera < numberOfCameras; currentCamera++) + CamerasIt i = World::getWorldPointer()->areaList[0]->cameras.begin(); + for(;i != World::getWorldPointer()->areaList[0]->cameras.end();i++) { - World::getWorldPointer ()->areaList[0]->cameraList[currentCamera]->stepPhysics (); + i->second->stepPhysics(); } - numberOfCameras = World::getWorldPointer ()->vehicleList[0]->cameraList.size (); - for (int currentCamera = 0; currentCamera < numberOfCameras; currentCamera++) + i = World::getWorldPointer()->vehicleList[0]->cameras.begin(); + for(;i != World::getWorldPointer()->vehicleList[0]->cameras.end();i++) { - World::getWorldPointer ()->vehicleList[0]->cameraList[currentCamera]->stepPhysics (); + i->second->stepPhysics(); } - checkpointPassed = false; dSpaceCollide (World::getWorldPointer ()->spaceID, 0, &nearCallback); Modified: trunk/src/vehicle/vehicle.cpp =================================================================== --- trunk/src/vehicle/vehicle.cpp 2006-06-22 15:43:57 UTC (rev 428) +++ trunk/src/vehicle/vehicle.cpp 2006-06-22 23:08:05 UTC (rev 429) @@ -120,8 +120,8 @@ } if (t->getName() == "camera") { - Camera * tmp = new Camera(this, t); - cameraList.push_back(tmp); + pCamera tmp = Camera::create (this, t); + cameras[tmp->getName()] = tmp; } } } Modified: trunk/src/vehicle/vehicle.hpp =================================================================== --- trunk/src/vehicle/vehicle.hpp 2006-06-22 15:43:57 UTC (rev 428) +++ trunk/src/vehicle/vehicle.hpp 2006-06-22 23:08:05 UTC (rev 429) @@ -9,7 +9,6 @@ #ifndef VEHICLE_HPP #define VEHICLE_HPP -#include <vector> #include "worldObject.hpp" #include "ode/objects.h" #include "xmlTag.hpp" @@ -30,9 +29,10 @@ class Suspension; class Vector3d; class Quaternion; -class Camera; class CameraPosition; +SHARED_PTR_MAP(Camera, pCamera, Cameras, CameraIt); + class Vehicle : public WorldObject { private: @@ -51,7 +51,7 @@ Vehicle (WorldObject * container, std::string vehicleName); Vehicle (WorldObject * container, XmlTag * tag); ~Vehicle (); - std::vector < Camera * > cameraList; + Cameras cameras; Body * getBody (std::string name); DriveJoint * getDriveJoint (std::string name); DriveMass * getDriveMass (std::string name); Modified: trunk/src/world/area.cpp =================================================================== --- trunk/src/world/area.cpp 2006-06-22 15:43:57 UTC (rev 428) +++ trunk/src/world/area.cpp 2006-06-22 23:08:05 UTC (rev 429) @@ -44,15 +44,6 @@ delete partList[i]; } partList.clear (); - - // unload the cameras from memory - log->__format (LOG_DEVELOPER, "Unloading cameras from memory..."); - size = cameraList.size (); - for (int i = 0; i < size; i++) - { - delete cameraList[i]; - } - cameraList.clear (); } void Area::construct (XmlTag * tag) @@ -147,8 +138,8 @@ } if (t->getName() == "camera") { - Camera * tmp = new Camera (this, t); - cameraList.push_back(tmp); + pCamera tmp = Camera::create (this, t); + cameras[tmp->getName()] = tmp; } } } @@ -206,10 +197,10 @@ mode = Ogre::PM_SOLID; break; } - int size = cameraList.size (); - for (int i = 0; i < size; i++) + CamerasIt i = cameras.begin(); + for(;i != cameras.end(); i++) { - cameraList[i]->ogreCamera->setPolygonMode(mode); + i->second->ogreCamera->setPolygonMode(mode); } } Modified: trunk/src/world/area.hpp =================================================================== --- trunk/src/world/area.hpp 2006-06-22 15:43:57 UTC (rev 428) +++ trunk/src/world/area.hpp 2006-06-22 23:08:05 UTC (rev 429) @@ -11,8 +11,6 @@ #define AREA_HPP #include "ode/objects.h" #include "worldObject.hpp" -#include <map> -#include <string> #include <vector> #include "paths.hpp" @@ -23,8 +21,9 @@ }; class Part; class Location; -class Camera; +SHARED_PTR_MAP(Camera, pCamera, Cameras, CameraIt); + class Area : public WorldObject { private: @@ -38,7 +37,7 @@ ~Area (); std::map <std::string, Location * > vehiclePositionMap; std::vector < Part * > partList; - std::vector < Camera * > cameraList; + Cameras cameras; dBodyID areaBodyID; Modified: trunk/src/world/world.cpp =================================================================== --- trunk/src/world/world.cpp 2006-06-22 15:43:57 UTC (rev 428) +++ trunk/src/world/world.cpp 2006-06-22 23:08:05 UTC (rev 429) @@ -52,6 +52,10 @@ World::~World () { + activeCamera.reset(); + activeAreaCamera.reset(); + activeVehicleCamera.reset(); + // unload the bodies from memory log->__format (LOG_DEVELOPER, "Unloading vehicles from memory..."); int size = vehicleList.size (); @@ -148,15 +152,17 @@ processXmlVehicleListNode (vehicleListTag); // initialize cameras (pointing to car 0 by default) - for (unsigned int i=0; i< areaList[0]->cameraList.size(); i++) + CamerasIt i = areaList[0]->cameras.begin(); + for(;i != areaList[0]->cameras.end(); i++) { - areaList[0]->cameraList[i]->setPositionID( areaList[0]->areaBodyID ); - areaList[0]->cameraList[i]->setTarget( vehicleList[0]->getMainOdeObject()); + i->second->setPositionID( areaList[0]->areaBodyID ); + i->second->setTarget( vehicleList[0]->getMainOdeObject()); } - for (unsigned int i=0; i< vehicleList[0]->cameraList.size(); i++) + i = vehicleList[0]->cameras.begin(); + for(;i != vehicleList[0]->cameras.end(); i++) { - vehicleList[0]->cameraList[i]->setPositionID( vehicleList[0]->getMainOdeObject()->getBodyID()); - vehicleList[0]->cameraList[i]->setTarget( vehicleList[0]->getMainOdeObject() ); + i->second->setPositionID( vehicleList[0]->getMainOdeObject()->getBodyID()); + i->second->setTarget( vehicleList[0]->getMainOdeObject() ); } // set active camera @@ -164,16 +170,16 @@ if (useAreaCamera) { //err... use... area camera, i guess. - setActiveCamera (areaList[0]->cameraList[0]); + setActiveCamera (areaList[0]->cameras.begin()->second); } else { //don't use area camera: use vehicle camera - setActiveCamera (vehicleList[0]->cameraList[0]); + setActiveCamera (vehicleList[0]->cameras.begin()->second); } - activeAreaCamera = areaList[0]->cameraList[0]; - activeVehicleCamera = vehicleList[0]->cameraList[0]; + activeAreaCamera = areaList[0]->cameras.begin()->second; + activeVehicleCamera = vehicleList[0]->cameras.begin()->second; } -void World::setActiveCamera (Camera * camera) +void World::setActiveCamera (pCamera camera) { activeCamera = camera; SystemData::getSystemDataPointer()->ogreWindow->removeAllViewports (); @@ -181,29 +187,19 @@ log->__format (LOG_ENDUSER, "Changed camera..."); } -Camera * World::getActiveCamera (void) +pCamera World::getActiveCamera (void) { return activeCamera; } -int World::getActiveAreaCameraIndex() +pCamera World::getActiveAreaCamera() { - int camNumber = 0; - while ( activeAreaCamera != areaList[0]->cameraList[camNumber] ) - { - camNumber++; - } - return camNumber; + return areaList[0]->cameras[activeAreaCamera->getName()]; } -int World::getActiveVehicleCameraIndex() +pCamera World::getActiveVehicleCamera() { - int camNumber = 0; - while ( activeVehicleCamera != vehicleList[0]->cameraList[camNumber] ) - { - camNumber++; - } - return camNumber; + return vehicleList[0]->cameras[activeVehicleCamera->getName()]; } void World::processXmlVehicleListNode (XmlTag * tag) Modified: trunk/src/world/world.hpp =================================================================== --- trunk/src/world/world.hpp 2006-06-22 15:43:57 UTC (rev 428) +++ trunk/src/world/world.hpp 2006-06-22 23:08:05 UTC (rev 429) @@ -16,18 +16,17 @@ #include "worldObject.hpp" //forward declaration -class Camera; class Area; class Vehicle; +SHARED_PTR_MAP(Camera, pCamera, Cameras, CamerasIt); + class World : public WorldObject { private: static World *worldPointer; std::string description; - Camera * activeCamera; - int activeAreaCameraIndex; - int activeVehicleCameraIndex; + pCamera activeCamera; void processXmlVehicleListNode (XmlTag * tag); void processXmlRootNode (XmlTag * tag); public: @@ -43,12 +42,12 @@ std::vector < Area * > areaList; std::vector < Vehicle * > vehicleList; - void setActiveCamera (Camera * camera); - Camera * getActiveCamera (); - Camera * activeAreaCamera; - Camera * activeVehicleCamera; - int getActiveAreaCameraIndex(); - int getActiveVehicleCameraIndex(); + void setActiveCamera (pCamera camera); + pCamera getActiveCamera(); + pCamera activeAreaCamera; + pCamera activeVehicleCamera; + pCamera getActiveAreaCamera(); + pCamera getActiveVehicleCamera(); }; #endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <st...@us...> - 2006-06-22 15:51:27
|
Revision: 428 Author: stenyak Date: 2006-06-22 08:43:57 -0700 (Thu, 22 Jun 2006) ViewCVS: http://svn.sourceforge.net/motorsport/?rev=428&view=rev Log Message: ----------- Several classes are now always referenced with boost::shared_ptr (*OdeData, *ObjectData, LogEngine). Therefore a lot of "delete"s have been removed from code. Enabled logEngines count test at program exit. Added static constructor for LogEngines, made default one private. Added a few macros in order to speed up declaration of object maps, iterators and shared pointers (new file, src/common/shared.hpp). Makefile target "all" now updates motorsport.tags file *before* attempting to compile. Modified Paths: -------------- trunk/data/areas/mospland/area.xml trunk/src/common/camera.cpp trunk/src/common/camera.hpp trunk/src/common/location.cpp trunk/src/common/odeObject.cpp trunk/src/common/odeObject.hpp trunk/src/common/ogreObject.cpp trunk/src/common/ogreObject.hpp trunk/src/common/worldObject.cpp trunk/src/common/worldObject.hpp trunk/src/graphicsEngine.cpp trunk/src/graphicsEngine.hpp trunk/src/guiEngine.cpp trunk/src/guiEngine.hpp trunk/src/inputEngine.cpp trunk/src/inputEngine.hpp trunk/src/log/logEngine.cpp trunk/src/log/logEngine.hpp trunk/src/main.cpp trunk/src/main.hpp trunk/src/makefile trunk/src/physicsEngine.cpp trunk/src/physicsEngine.hpp trunk/src/tools/xmlTag.cpp trunk/src/tools/xmlTag.hpp trunk/src/vehicle/body.cpp trunk/src/vehicle/suspension.cpp trunk/src/vehicle/vehicle.cpp trunk/src/vehicle/vehicle.hpp trunk/src/vehicle/wheel.cpp trunk/src/world/area.cpp trunk/src/world/part.cpp Added Paths: ----------- trunk/data/areas/mospland/ground.material trunk/data/areas/mospland/ground.png trunk/src/common/shared.hpp Removed Paths: ------------- trunk/data/areas/mospland/road_test.png Modified: trunk/data/areas/mospland/area.xml =================================================================== --- trunk/data/areas/mospland/area.xml 2006-06-08 22:47:38 UTC (rev 427) +++ trunk/data/areas/mospland/area.xml 2006-06-22 15:43:57 UTC (rev 428) @@ -21,7 +21,6 @@ name="ground" position="3.000000 0.000000 0.000000" rotation="1.000000 0.000000 0.000000 0.000000" - scale="1.000000 1.000000 1.000000" height="-10.0" > <mesh Added: trunk/data/areas/mospland/ground.material =================================================================== --- trunk/data/areas/mospland/ground.material (rev 0) +++ trunk/data/areas/mospland/ground.material 2006-06-22 15:43:57 UTC (rev 428) @@ -0,0 +1,18 @@ +material groundMaterial +{ + receive_shadows on + technique + { + pass + { + ambient 0.5 0.5 0.5 + diffuse 0.756191 0.756115 0.756115 + specular 0.500000 0.500000 0.500000 50.000000 + emissive 0.000000 0.000000 0.000000 + texture_unit + { + texture ground.png + } + } + } +} Added: trunk/data/areas/mospland/ground.png =================================================================== (Binary files differ) Property changes on: trunk/data/areas/mospland/ground.png ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Deleted: trunk/data/areas/mospland/road_test.png =================================================================== (Binary files differ) Modified: trunk/src/common/camera.cpp =================================================================== --- trunk/src/common/camera.cpp 2006-06-08 22:47:38 UTC (rev 427) +++ trunk/src/common/camera.cpp 2006-06-22 15:43:57 UTC (rev 428) @@ -204,7 +204,7 @@ this->positionID = positionID; } -void Camera::setTarget (OdeObject * odeObject) +void Camera::setTarget (pOdeObject odeObject) { this->targetID = odeObject->getBodyID(); } Modified: trunk/src/common/camera.hpp =================================================================== --- trunk/src/common/camera.hpp 2006-06-08 22:47:38 UTC (rev 427) +++ trunk/src/common/camera.hpp 2006-06-22 15:43:57 UTC (rev 428) @@ -36,7 +36,7 @@ Vector3d updateOgreTarget (); void stepPhysics(); void setPositionID (dBodyID positionID); - void setTarget (OdeObject * odeObject); + void setTarget (pOdeObject odeObject); void startGraphics (); void stepGraphics (); Ogre::Camera * ogreCamera; Modified: trunk/src/common/location.cpp =================================================================== --- trunk/src/common/location.cpp 2006-06-08 22:47:38 UTC (rev 427) +++ trunk/src/common/location.cpp 2006-06-22 15:43:57 UTC (rev 428) @@ -12,14 +12,13 @@ Location::Location (XmlTag * tag) { - LogEngine * log = new LogEngine (LOG_DEVELOPER, "Location"); + pLogEngine log (LogEngine::create (LOG_DEVELOPER, "Location")); // if (tag->getName() == "location") { name = tag->getAttribute("name"); position = Vector3d(tag->getAttribute("position")); rotation = Quaternion(tag->getAttribute("rotation")); } - delete log; } Location::Location (std::string name, Vector3d position, Quaternion rotation) { Modified: trunk/src/common/odeObject.cpp =================================================================== --- trunk/src/common/odeObject.cpp 2006-06-08 22:47:38 UTC (rev 427) +++ trunk/src/common/odeObject.cpp 2006-06-22 15:43:57 UTC (rev 428) @@ -23,7 +23,7 @@ this->id = std::string(numberString); instancesCount++; } -OdeObject::OdeObject (WorldObject * worldObject, PartOdeData data, std::string name) +OdeObject::OdeObject (WorldObject * worldObject, pPartOdeData data, std::string name) { updateId(); this->worldObject = worldObject; @@ -41,25 +41,25 @@ dBodySetData (bodyID, static_cast<void*>(worldObject->getContainer())); dMass dmass; - if (data.shape == "box") + if (data->shape == "box") { - geomIDs[name] = dCreateBox (World::getWorldPointer ()->spaceID, data.size.x, data.size.y, data.size.z); - dMassSetBoxTotal (&dmass, data.mass, data.size.x, data.size.y, data.size.z); + geomIDs[name] = dCreateBox (World::getWorldPointer ()->spaceID, data->size.x, data->size.y, data->size.z); + dMassSetBoxTotal (&dmass, data->mass, data->size.x, data->size.y, data->size.z); } - if (data.shape == "sphere") + if (data->shape == "sphere") { - geomIDs[name] = dCreateSphere (World::getWorldPointer ()->spaceID, data.radius); - dMassSetSphereTotal (&dmass, data.mass, data.radius); + geomIDs[name] = dCreateSphere (World::getWorldPointer ()->spaceID, data->radius); + dMassSetSphereTotal (&dmass, data->mass, data->radius); } - if (data.shape == "cappedCylinder") + if (data->shape == "cappedCylinder") { - geomIDs[name] = dCreateCCylinder (World::getWorldPointer ()->spaceID, data.radius, data.length); - dMassSetCappedCylinderTotal (&dmass, data.mass, data.directionAxis, data.radius, data.length); + geomIDs[name] = dCreateCCylinder (World::getWorldPointer ()->spaceID, data->radius, data->length); + dMassSetCappedCylinderTotal (&dmass, data->mass, data->directionAxis, data->radius, data->length); } dGeomSetBody (geomIDs[name], bodyID); dBodySetMass (bodyID, &dmass); } -OdeObject::OdeObject (WorldObject * worldObject, BodyOdeData data, std::string name) +OdeObject::OdeObject (WorldObject * worldObject, pBodyOdeData data, std::string name) { updateId(); this->worldObject = worldObject; @@ -78,16 +78,16 @@ dGeomTransformSetCleanup (geomIDs["GeomSpace(B)"], 0); // create collision geoms - geomIDs["Geom(A)"] = dCreateBox (0, data.length, data.width, data.height / 2.0f); - geomIDs["Geom(B)"] = dCreateBox (0, data.length / 2.0f, data.width / 2.0f, data.height / 2.0f); + geomIDs["Geom(A)"] = dCreateBox (0, data->length, data->width, data->height / 2.0f); + geomIDs["Geom(B)"] = dCreateBox (0, data->length / 2.0f, data->width / 2.0f, data->height / 2.0f); // insert collision geoms into transformation spaces dGeomTransformSetGeom (geomIDs["GeomSpace(A)"], geomIDs["Geom(A)"]); dGeomTransformSetGeom (geomIDs["GeomSpace(B)"], geomIDs["Geom(B)"]); // apply offsets to the collision geoms - dGeomSetPosition (geomIDs["Geom(A)"], 0.f, 0.f, - data.height / 4.0f); - dGeomSetPosition (geomIDs["Geom(B)"], -data.width / 6.f, 0.f, (data.height / 4.0f) + 0.1f); + dGeomSetPosition (geomIDs["Geom(A)"], 0.f, 0.f, - data->height / 4.0f); + dGeomSetPosition (geomIDs["Geom(B)"], -data->width / 6.f, 0.f, (data->height / 4.0f) + 0.1f); // associate the dBody with the 2 collision geoms via the transformation spaces dGeomSetBody (geomIDs["GeomSpace(A)"], bodyID); @@ -95,7 +95,7 @@ // set dBody mass dMass tmpMass; - dMassSetBoxTotal (&tmpMass, data.mass, data.length, data.width, data.height); + dMassSetBoxTotal (&tmpMass, data->mass, data->length, data->width, data->height); dBodySetMass (bodyID, &tmpMass); // make sure it's initialized with correct values. @@ -107,7 +107,7 @@ dBodySetLinearVel (bodyID, 0, 0, 0); dBodySetAngularVel (bodyID, 0, 0, 0); } -OdeObject::OdeObject (WorldObject * worldObject, WheelOdeData data, std::string name) +OdeObject::OdeObject (WorldObject * worldObject, pWheelOdeData data, std::string name) { updateId(); this->worldObject = worldObject; @@ -116,17 +116,17 @@ bodyID = dBodyCreate (World::getWorldPointer ()->worldID); dBodySetData (bodyID, static_cast<void*>(worldObject->getContainer())); dMass dmass; - dMassSetParameters (&dmass, data.mass, + dMassSetParameters (&dmass, data->mass, 0., 0., 0., 0.237f, 0.237f, 0.409f, 0., 0., 0.); - geomIDs[name] = dCreateCCylinder (World::getWorldPointer ()->spaceID, data.radius, data.width); + geomIDs[name] = dCreateCCylinder (World::getWorldPointer ()->spaceID, data->radius, data->width); dBodySetLinearVel (bodyID, 0, 0, 0); dBodySetAngularVel (bodyID, 0, 0, 0); dGeomSetBody (geomIDs[name], bodyID); dBodySetMass (bodyID, &dmass); } -OdeObject::OdeObject (WorldObject * worldObject, BoneOdeData data, std::string name) +OdeObject::OdeObject (WorldObject * worldObject, pBoneOdeData data, std::string name) { updateId(); this->worldObject = worldObject; @@ -136,17 +136,17 @@ bodyID = dBodyCreate (World::getWorldPointer ()->worldID); dBodySetData (bodyID, static_cast<void*>(worldObject->getContainer())); dMass dmass; - if (data.useMass) + if (data->useMass) { - dMassSetBoxTotal(&dmass, data.mass, data.radius, data.radius, data.length); + dMassSetBoxTotal(&dmass, data->mass, data->radius, data->radius, data->length); } else { - dMassSetBox(&dmass, data.density, data.radius, data.radius, data.length); + dMassSetBox(&dmass, data->density, data->radius, data->radius, data->length); } dBodySetMass (bodyID, &dmass); - geomIDs[name] = dCreateBox (World::getWorldPointer ()->spaceID, data.radius, data.radius, data.length); + geomIDs[name] = dCreateBox (World::getWorldPointer ()->spaceID, data->radius, data->radius, data->length); dBodySetLinearVel (bodyID, 0, 0, 0); dBodySetAngularVel (bodyID, 0, 0, 0); dGeomSetBody (geomIDs[name], bodyID); Modified: trunk/src/common/odeObject.hpp =================================================================== --- trunk/src/common/odeObject.hpp 2006-06-08 22:47:38 UTC (rev 427) +++ trunk/src/common/odeObject.hpp 2006-06-22 15:43:57 UTC (rev 428) @@ -12,22 +12,20 @@ #include "log/logEngine.hpp" #include "worldObject.hpp" #include "ode/objects.h" -#include <map> +#include <shared.hpp> #include "vector3d.hpp" -class OdeObject; -class PartOdeData; -class BodyOdeData; -class WheelOdeData; -class BoneOdeData; class Quaternion; class WorldObject; -typedef std::map <std::string, OdeObject *> OdeObjects; -typedef std::map <std::string, OdeObject *>::iterator OdeObjectsIt; -typedef std::map <std::string, dGeomID> GeomIDs; -typedef std::map <std::string, dGeomID>::iterator GeomIDsIt; +SHARED_PTR_MAP(OdeObject, pOdeObject, OdeObjects, OdeObjectsIt); +SHARED_PTR(PartOdeData, pPartOdeData); +SHARED_PTR(BodyOdeData, pBodyOdeData); +SHARED_PTR(WheelOdeData, pWheelOdeData); +SHARED_PTR(BoneOdeData, pBoneOdeData); +SHARED_MAP(dGeomID, GeomIDs, GeomIDsIt); + class OdeObject { protected: @@ -40,10 +38,10 @@ std::string id; public: - OdeObject (WorldObject * worldObject, PartOdeData data, std::string name); - OdeObject (WorldObject * worldObject, BodyOdeData data, std::string name); - OdeObject (WorldObject * worldObject, WheelOdeData data, std::string name); - OdeObject (WorldObject * worldObject, BoneOdeData data, std::string name); + OdeObject (WorldObject * worldObject, pPartOdeData data, std::string name); + OdeObject (WorldObject * worldObject, pBodyOdeData data, std::string name); + OdeObject (WorldObject * worldObject, pWheelOdeData data, std::string name); + OdeObject (WorldObject * worldObject, pBoneOdeData data, std::string name); ~OdeObject (); Vector3d getPosition(); Quaternion getRotation(); Modified: trunk/src/common/ogreObject.cpp =================================================================== --- trunk/src/common/ogreObject.cpp 2006-06-08 22:47:38 UTC (rev 427) +++ trunk/src/common/ogreObject.cpp 2006-06-22 15:43:57 UTC (rev 428) @@ -28,16 +28,15 @@ { return id; } -OgreObject::OgreObject (WorldObject * worldObject, OgreObjectData data, std::string name, bool useMesh) +OgreObject::OgreObject (WorldObject * worldObject, pOgreObjectData data, std::string name, bool useMesh) { updateId(); this->worldObject = worldObject; this->name = name; this->useMesh = useMesh; - std::string meshPath = data.meshPath; + std::string meshPath = data->meshPath; entity = NULL; node = NULL; - odeObject = NULL; if (useMesh) { @@ -70,15 +69,14 @@ SystemData::getSystemDataPointer()->ogreSceneManager->destroySceneNode (node->getName()); node = NULL; - odeObject = NULL; this->worldObject = NULL; } -void OgreObject::setOdeReference(OdeObject * odeObject) +void OgreObject::setOdeReference(pOdeObject odeObject) { this->odeObject = odeObject; } -void OgreObject::setOgreReference(OgreObject * ogreObject, Quaternion rotationDiff, Vector3d positionDiff, Vector3d scale) +void OgreObject::setOgreReference(pOgreObject ogreObject, Quaternion rotationDiff, Vector3d positionDiff, Vector3d scale) { static_cast<Ogre::SceneNode*>(SystemData::getSystemDataPointer()->ogreSceneManager->getRootSceneNode())->removeChild(node); ogreObject->getNode()->addChild(node); Modified: trunk/src/common/ogreObject.hpp =================================================================== --- trunk/src/common/ogreObject.hpp 2006-06-08 22:47:38 UTC (rev 427) +++ trunk/src/common/ogreObject.hpp 2006-06-22 15:43:57 UTC (rev 428) @@ -11,21 +11,19 @@ #define OGREOBJECT_HPP #include "log/logEngine.hpp" #include "worldObject.hpp" -#include <map> +#include <shared.hpp> namespace Ogre { class Entity; class SceneNode; } -class OdeObject; -class OgreObject; -class OgreObjectData; class WorldObject; class Quaternion; class Vector3d; -typedef std::map <std::string, OgreObject *> OgreObjects; -typedef std::map <std::string, OgreObject *>::iterator OgreObjectsIt; +SHARED_PTR_MAP(OdeObject, pOdeObject, OdeObjects, OdeObjectsIt); +SHARED_PTR_MAP(OgreObject, pOgreObject, OgreObjects, OgreObjectsIt); +SHARED_PTR(OgreObjectData, pOgreObjectData); class OgreObject { @@ -37,15 +35,15 @@ Ogre::Entity * entity; bool useMesh; Ogre::SceneNode * node; - OdeObject * odeObject; + pOdeObject odeObject; WorldObject * worldObject; std::string id; public: - OgreObject (WorldObject * worldObject, OgreObjectData data, std::string name, bool useMesh = true); + OgreObject (WorldObject * worldObject, pOgreObjectData data, std::string name, bool useMesh = true); ~OgreObject (); std::string getId(); - void setOdeReference(OdeObject * odeObject); - void setOgreReference(OgreObject * ogreObject, Quaternion rotationDiff, Vector3d positionDiff, Vector3d scale); + void setOdeReference(pOdeObject odeObject); + void setOgreReference(pOgreObject ogreObject, Quaternion rotationDiff, Vector3d positionDiff, Vector3d scale); void stepGraphics(); Ogre::SceneNode * getNode(); Ogre::Entity * getEntity(); Added: trunk/src/common/shared.hpp =================================================================== --- trunk/src/common/shared.hpp (rev 0) +++ trunk/src/common/shared.hpp 2006-06-22 15:43:57 UTC (rev 428) @@ -0,0 +1,26 @@ +/*****************************************************************************\ +|* Copyright (C) 2003, 2006 "Motorsport" developers (*) *| +|* Part of the "Motorsport" project (http://motorsport.sourceforge.net) *| +|* Licensed under the GNU General Public License (*) *| +|* *| +|* (*) Complete information is provided at the following URL: *| +|* [ http://motorsport-sim.org/svn/trunk/doc/LICENSE ] *| +\*****************************************************************************/ + +#ifndef SHARED_HPP +#define SHARED_HPP +#include <map> +#include <boost/shared_ptr.hpp> +#include <string> + +// Shared pointer +#define SHARED_PTR(X,Y) class X; typedef boost::shared_ptr<X> Y + +// String-indexed map and iterator +#define SHARED_MAP(X,Y,Z) typedef std::map <std::string, X> Y; typedef std::map <std::string, X>::iterator Z + +// Shared pointer, string-indexed map and iterator +#define SHARED_PTR_MAP(X,Y,Z,T) class X; typedef boost::shared_ptr<X> Y; typedef std::map <std::string, Y> Z; typedef std::map <std::string, Y>::iterator T +#define SHARED_MAP_PTR(X,Y,Z,T) class X; typedef boost::shared_ptr<X> Y; typedef std::map <std::string, Y> Z; typedef std::map <std::string, Y>::iterator T + +#endif Modified: trunk/src/common/worldObject.cpp =================================================================== --- trunk/src/common/worldObject.cpp 2006-06-08 22:47:38 UTC (rev 427) +++ trunk/src/common/worldObject.cpp 2006-06-22 15:43:57 UTC (rev 428) @@ -37,7 +37,7 @@ instancesCount++; //FIXME what to use, id# or name? - log = new LogEngine (LOG_DEVELOPER, this->getFullName()); + log = LogEngine::create (LOG_DEVELOPER, this->getFullName()); //log = new LogEngine (LOG_DEVELOPER, this->id); log->__format(LOG_CCREATOR, "Id #%s. Full Name: %s", id.c_str(), getFullName().c_str()); worldObjects[this->id] = this; @@ -45,33 +45,18 @@ WorldObject::~WorldObject () { log->__format(LOG_CCREATOR, "Deleting myself. Id #%s. Full Name: %s", id.c_str(), getFullName().c_str()); - OgreObjectsIt i = ogreObjects.begin(); - for(;i != ogreObjects.end(); i++) - { - delete i->second; - i->second = NULL; - } - ogreObjects.clear(); - OdeObjectsIt j = odeObjects.begin(); - for(;j != odeObjects.end(); j++) - { - delete j->second; - j->second = NULL; - } - odeObjects.clear(); + worldObjects.erase(this->id); - delete log; - log = NULL; base = NULL; } void WorldObject::logAll() { - LogEngine log (LOG_DEVELOPER, "WorldObjects"); + pLogEngine log (LogEngine::create(LOG_DEVELOPER, "WorldObjects")); WorldObjectsIt i = worldObjects.begin(); for(;i != worldObjects.end(); i++) { if (i->second != NULL) - log.__format(LOG_DEVELOPER, "WorldObject id#%s.\t Full name: %s", i->second->getId().c_str(), i->second->getFullName().c_str()); + log->__format(LOG_DEVELOPER, "WorldObject id#%s.\t Full name: %s", i->second->getId().c_str(), i->second->getFullName().c_str()); } } std::string WorldObject::getId() @@ -108,7 +93,7 @@ { this->xmlPath = xmlPath; } -LogEngine * WorldObject::getLog() +pLogEngine WorldObject::getLog() { return log; } @@ -116,9 +101,10 @@ { return container; } -OdeObject * WorldObject::getMainOdeObject() +pOdeObject WorldObject::getMainOdeObject() { - if (odeObjects.empty()) return NULL; + //TODO: check what is returned when odeObjects is empty. prolly a reset shared pointer, but i'm not sure + //if (odeObjects.empty()) return NULL; return odeObjects.begin()->second; } void WorldObject::stepGraphics () Modified: trunk/src/common/worldObject.hpp =================================================================== --- trunk/src/common/worldObject.hpp 2006-06-08 22:47:38 UTC (rev 427) +++ trunk/src/common/worldObject.hpp 2006-06-22 15:43:57 UTC (rev 428) @@ -13,18 +13,13 @@ #include "ogreObject.hpp" #include "odeObject.hpp" #include "xmlTag.hpp" -#include <string> -#include <map> +#include <shared.hpp> //forward declatations class Quaternion; class Vector3d; -class OgreObject; -typedef std::map <std::string, OgreObject *> OgreObjects; -typedef std::map <std::string, OgreObject *>::iterator OgreObjectsIt; -class OdeObject; -typedef std::map <std::string, OdeObject *> OdeObjects; -typedef std::map <std::string, OdeObject *>::iterator OdeObjectsIt; +SHARED_PTR_MAP(OgreObject, pOgreObject, OgreObjects, OgreObjectsIt); +SHARED_PTR_MAP(OdeObject, pOdeObject, OdeObjects, OdeObjectsIt); class WorldObject; typedef std::map <std::string, WorldObject *> WorldObjects; typedef std::map <std::string, WorldObject *>::iterator WorldObjectsIt; @@ -40,7 +35,7 @@ std::string path; std::string xmlPath; protected: - LogEngine * log; + pLogEngine log; WorldObject * base; WorldObject * container; OgreObjects ogreObjects; @@ -59,11 +54,11 @@ void setXmlPath(std::string xmlPath); static void logAll(); - LogEngine * getLog(); + pLogEngine getLog(); void stepGraphics (); - OdeObject * getMainOdeObject(); + pOdeObject getMainOdeObject(); Vector3d getPosition (); Quaternion getRotation (); Modified: trunk/src/graphicsEngine.cpp =================================================================== --- trunk/src/graphicsEngine.cpp 2006-06-08 22:47:38 UTC (rev 427) +++ trunk/src/graphicsEngine.cpp 2006-06-22 15:43:57 UTC (rev 428) @@ -247,9 +247,6 @@ { log->__format (LOG_DEVELOPER, "Unloading ogre window data from memory..."); delete (systemData->ogreWindow); - - // finally stop the log engine - delete log; } GraphicsEngine::GraphicsEngine () @@ -282,7 +279,7 @@ int defaultNumMipMaps = 5; fullScreen = false; - log = new LogEngine (LOG_DEVELOPER, "GraphicsEngine"); + log = LogEngine::create (LOG_DEVELOPER, "GraphicsEngine"); if (tag->getName() == "graphicsConfig") { @@ -329,7 +326,8 @@ } delete tag; - log = new LogEngine (localLogLevel, localLogName.c_str()); + + log = LogEngine::create (localLogLevel, localLogName.c_str()); log->__format (LOG_DEVELOPER, "Temporary parsing data already loaded into memory..."); // get the direction of the graphics data Modified: trunk/src/graphicsEngine.hpp =================================================================== --- trunk/src/graphicsEngine.hpp 2006-06-08 22:47:38 UTC (rev 427) +++ trunk/src/graphicsEngine.hpp 2006-06-22 15:43:57 UTC (rev 428) @@ -8,10 +8,12 @@ \*****************************************************************************/ #include <string> +#include <boost/shared_ptr.hpp> //forward declarations class SystemData; class LogEngine; +typedef boost::shared_ptr<LogEngine> pLogEngine; namespace Ogre { class Root; } @@ -25,7 +27,7 @@ /** This log engine allows the graphics engine to write data in the log file, allowing to be differenciated from other engines. * @brief Log engine used by the graphics engine. */ - LogEngine * log; + pLogEngine log; /** * @brief Pointer to the system data, used by different engines in order to store common data. */ Modified: trunk/src/guiEngine.cpp =================================================================== --- trunk/src/guiEngine.cpp 2006-06-08 22:47:38 UTC (rev 427) +++ trunk/src/guiEngine.cpp 2006-06-22 15:43:57 UTC (rev 428) @@ -35,7 +35,7 @@ XmlTag * tag = new XmlTag ("../cfg/guiConfig.xml"); #endif showStatistics = true; - log = new LogEngine (LOG_DEVELOPER, "GuiEngine"); + log = LogEngine::create (LOG_DEVELOPER, "GuiEngine"); if (tag->getName() == "guiConfig") { @@ -244,6 +244,4 @@ GuiEngine::~GuiEngine (void) { - // finally stop the log engine - delete log; } Modified: trunk/src/guiEngine.hpp =================================================================== --- trunk/src/guiEngine.hpp 2006-06-08 22:47:38 UTC (rev 427) +++ trunk/src/guiEngine.hpp 2006-06-22 15:43:57 UTC (rev 428) @@ -8,11 +8,11 @@ \*****************************************************************************/ #include "SDL/SDL.h" -#include <string> +#include <shared.hpp> //forward declaration class SystemData; -class LogEngine; +SHARED_PTR_MAP(LogEngine, pLogEngine, LogEngines, LogEnginesIt); namespace Ogre { class Camera; }; @@ -27,7 +27,7 @@ // / Log engine used by the gui engine. /** This log engine allows the gui engine to write data in the log file, allowing to be differenciated from other engines. */ - LogEngine * log; + pLogEngine log; // / Pointer to the system data, used by different engines in order to store common data. SystemData *systemData; // / Allows or disallows to show statistics on screen Modified: trunk/src/inputEngine.cpp =================================================================== --- trunk/src/inputEngine.cpp 2006-06-08 22:47:38 UTC (rev 427) +++ trunk/src/inputEngine.cpp 2006-06-22 15:43:57 UTC (rev 428) @@ -27,7 +27,7 @@ XmlTag * tag = new XmlTag ("../cfg/inputConfig.xml"); #endif delete tag; - log = new LogEngine (LOG_DEVELOPER, "InputEngine"); + log = LogEngine::create (LOG_DEVELOPER, "InputEngine"); log->__format (LOG_DEVELOPER, "Setting up data pointers..."); systemData = SystemData::getSystemDataPointer (); @@ -202,6 +202,4 @@ log->__format (LOG_DEVELOPER, "Steering wheel: %i, %i.",systemData->axisMap[getIDJoyAxis (0, 0)]->getMinRawValue(), systemData->axisMap[getIDJoyAxis (0, 0)]->getMaxRawValue()); log->__format (LOG_DEVELOPER, "Gas pedal: %i, %i.",systemData->axisMap[getIDJoyAxis (0, 2)]->getMinRawValue(), systemData->axisMap[getIDJoyAxis (0, 2)]->getMaxRawValue()); log->__format (LOG_DEVELOPER, "Brake pedal: %i, %i.",systemData->axisMap[getIDJoyAxis (0, 1)]->getMinRawValue(), systemData->axisMap[getIDJoyAxis (0, 1)]->getMaxRawValue()); - // finally stop the log engine - delete log; } Modified: trunk/src/inputEngine.hpp =================================================================== --- trunk/src/inputEngine.hpp 2006-06-08 22:47:38 UTC (rev 427) +++ trunk/src/inputEngine.hpp 2006-06-22 15:43:57 UTC (rev 428) @@ -7,9 +7,10 @@ |* [ http://motorsport-sim.org/svn/trunk/doc/LICENSE ] *| \*****************************************************************************/ +#include <shared.hpp> //forward declatation class SystemData; -class LogEngine; +SHARED_PTR_MAP(LogEngine, pLogEngine, LogEngines, LogEnginesIt); /// Manages everything related to user input. /** Manages everything related to user input, such as keyboard keypresses, mouse movement, steering wheel movement, joystick, etc... Essentially, it's the interface between the end-user and the simulated world, allowing the user to transparently make changes in this simulated world. Input devices calibration issues and many other things are handled by this engine. @@ -20,7 +21,7 @@ // / Log engine used by the input engine. /** This log engine allows the input engine to write data in the log file, allowing to be differenciated from other engines. */ - LogEngine * log; + pLogEngine log; // / Pointer to the system data, used by different engines in order to store common data. SystemData *systemData; public: Modified: trunk/src/log/logEngine.cpp =================================================================== --- trunk/src/log/logEngine.cpp 2006-06-08 22:47:38 UTC (rev 427) +++ trunk/src/log/logEngine.cpp 2006-06-22 15:43:57 UTC (rev 428) @@ -27,7 +27,7 @@ unsigned int LogEngine::instancesCount = 0; LogEngines LogEngine::logEngines; -LogEngine::LogEngine (LOG_LEVEL localLevel, const std::string & name):logLevel (localLevel), logName (name) +pLogEngine LogEngine::create(LOG_LEVEL localLevel, const std::string & name) { // open the file for writing in rewrite mode if necessary. if ((instancesCount == 0) || (!logFile.is_open ())) @@ -54,18 +54,27 @@ if (!logFile.good ()) { std::cerr << "ERROR: Log file \"" << fileName << "\" could not be opened!\n"; - return; + //FIXME: exit program? + //return; } - format (LOG_ENDUSER, "Start of logs."); delete tag; } + pLogEngine log (new LogEngine(localLevel, name)); // increase logEngines counter instancesCount++; - const int numberStringSize = 64; char numberString[numberStringSize]; snprintf (numberString, numberStringSize, "%i", instancesCount); - logEngines.insert( std::pair< std::string, LogEngine* >(std::string("LOG#") + numberString + "#." + name, this) ); + logEngines[std::string("LOG#") + numberString + "#." + name] = log; + + return pLogEngine(log); +} +LogEngine::LogEngine (LOG_LEVEL localLevel, const std::string & name):logLevel (localLevel), logName (name) +{ + if ((instancesCount == 0) || (!logFile.is_open ())) + { + format (LOG_ENDUSER, "Start of logs."); + } return; } LogEngine::~LogEngine () @@ -73,10 +82,8 @@ LogEnginesIt i = logEngines.begin(); for(;i != logEngines.end(); i++) { - if (this == i->second) i->second = NULL;; - if (this == i->second) logEngines.erase(i); + if (this == i->second.get()) logEngines.erase(i); } - //TODO: replace with if map.empty() if (logEngines.empty()) { format (LOG_ENDUSER, "Closing logFile"); @@ -86,11 +93,10 @@ void LogEngine::logAll() { - LogEngine log (LOG_DEVELOPER, "LogEngines"); LogEnginesIt i = logEngines.begin(); for(;i != logEngines.end(); i++) { - i->second->__format(LOG_DEVELOPER, "LogEngine Id: %s", i->first.c_str()); + i->second->__format(LOG_DEVELOPER, "LogEngine Id: %s\t Instances: %i", i->first.c_str(), i->second.use_count()); } } Modified: trunk/src/log/logEngine.hpp =================================================================== --- trunk/src/log/logEngine.hpp 2006-06-08 22:47:38 UTC (rev 427) +++ trunk/src/log/logEngine.hpp 2006-06-22 15:43:57 UTC (rev 428) @@ -9,8 +9,7 @@ #ifndef LOG_ENGINE_HPP #define LOG_ENGINE_HPP -#include <string> -#include <map> +#include <shared.hpp> #include <fstream> #ifdef _MSC_VER @@ -51,9 +50,7 @@ LOG_MASK mask; // !< Where should we send the log }; -class LogEngine; -typedef std::map <std::string, LogEngine *> LogEngines; -typedef std::map <std::string, LogEngine *>::iterator LogEnginesIt; +SHARED_PTR_MAP(LogEngine, pLogEngine, LogEngines, LogEnginesIt); /// Allows to automate the recording of log messages to a file. /** Allows to automate the recording of log messages to a plain-text file. Every log engine has its own level of verbosity, meaning it can display only messages of a certain level of importance (discarding the less important messages). */ @@ -88,19 +85,21 @@ @return code as a short c-string. */ const std::string GetLogLevelCode (LOG_LEVEL level); - public: - static void logAll(); // / Creates a new log engine, creating the log file if needed. /** Creates a new log engine, and Initializes the pertinent data in order to allow logging. If it's the first log engine to be created, the log file will be opened/created. @param localLevel level of verbosity of this log. @param name 3 characters with an id for the log. */ LogEngine (LOG_LEVEL localLevel, const std::string & name); + public: + static pLogEngine create(LOG_LEVEL localLevel, const std::string & name); // / Deletes the log engine, closing the log file if needed. /** Deletes the log engine and associated data. If there's no other log engines left, the log file will be closed. */ ~LogEngine (void); + static void logAll(); + // / Writes a log message to the log file. /** Writes a log message to the log file, provided its level is low enough (compared to the level of the log engine). It's possible to avoid writing a newline before the message. @param level level of the log message. Modified: trunk/src/main.cpp =================================================================== --- trunk/src/main.cpp 2006-06-08 22:47:38 UTC (rev 427) +++ trunk/src/main.cpp 2006-06-22 15:43:57 UTC (rev 428) @@ -43,7 +43,7 @@ #else XmlTag * tag = new XmlTag ("../cfg/mainConfig.xml"); #endif - LogEngine * log = new LogEngine (LOG_DEVELOPER, "MainProgram"); + pLogEngine log = LogEngine::create (LOG_DEVELOPER, "MainProgram"); if (tag->getName() == "mainConfig") { SystemData::getSystemDataPointer ()->videoRecordTimestep = stoi (tag->getAttribute("videoRecordTimestep")); @@ -149,19 +149,18 @@ delete inputEngine; log->__format (LOG_DEVELOPER, "Deleting gui engine"); delete guiEngine; - log->__format (LOG_DEVELOPER, "Deleting log engine"); - delete log; + stopSdl (); //FIXME: uncomment later on //WorldObject::logAll(); - //LogEngine::logAll(); + LogEngine::logAll(); // We go back to the OS. return (0); } -void startSdl (LogEngine * log) +void startSdl (pLogEngine log) { if (SDL_Init (SDL_INIT_EVERYTHING) < 0) { @@ -174,7 +173,7 @@ SDL_Quit (); } -void computeLogic (LogEngine * log) +void computeLogic (pLogEngine log) { SystemData *systemData = SystemData::getSystemDataPointer (); if (SystemData::getSystemDataPointer ()->axisMap[getIDKeyboardKey (SDLK_ESCAPE)]->getValue () == 1) Modified: trunk/src/main.hpp =================================================================== --- trunk/src/main.hpp 2006-06-08 22:47:38 UTC (rev 427) +++ trunk/src/main.hpp 2006-06-22 15:43:57 UTC (rev 428) @@ -9,9 +9,10 @@ #ifndef MAIN_HPP #define MAIN_HPP +#include <shared.hpp> //forward declarations -class LogEngine; +SHARED_PTR_MAP(LogEngine, pLogEngine, LogEngines, LogEnginesIt); /** * @brief Stops all SDL subsystems. @@ -22,13 +23,13 @@ * * @param log A correctly initialized log engine. */ -void startSdl (LogEngine * log); +void startSdl (pLogEngine log); /** * @brief Process all input events related to game logic (such as petition to exit, or to modify physic engine rates, etc... * * @param log A correctly initialized log engine. */ -void computeLogic (LogEngine * log); +void computeLogic (pLogEngine log); /** * @brief If video recording is enabled, it checks whether the screen should be recorded to hard disk and does it if necessary. */ Modified: trunk/src/makefile =================================================================== --- trunk/src/makefile 2006-06-08 22:47:38 UTC (rev 427) +++ trunk/src/makefile 2006-06-22 15:43:57 UTC (rev 428) @@ -276,7 +276,7 @@ #Phony targets definitions .PHONY: all -all: $(TARGET) tags +all: tags $(TARGET) .PHONY: tags tags: $(SYSTAGS) Modified: trunk/src/physicsEngine.cpp =================================================================== --- trunk/src/physicsEngine.cpp 2006-06-08 22:47:38 UTC (rev 427) +++ trunk/src/physicsEngine.cpp 2006-06-22 15:43:57 UTC (rev 428) @@ -42,7 +42,7 @@ int stepType = 1; int dWorldStepFast1MaxIterations = 100; - log = new LogEngine (LOG_DEVELOPER, "PhysicsEngine"); + log = LogEngine::create (LOG_DEVELOPER, "PhysicsEngine"); if (tag->getName() == "physicsConfig") { frequency = stod(tag->getAttribute("frequency")); @@ -190,7 +190,4 @@ PhysicsEngine::~PhysicsEngine (void) { dCloseODE (); - - // finally stop the log engine - delete log; } Modified: trunk/src/physicsEngine.hpp =================================================================== --- trunk/src/physicsEngine.hpp 2006-06-08 22:47:38 UTC (rev 427) +++ trunk/src/physicsEngine.hpp 2006-06-22 15:43:57 UTC (rev 428) @@ -7,7 +7,7 @@ |* [ http://motorsport-sim.org/svn/trunk/doc/LICENSE ] *| \*****************************************************************************/ -class LogEngine; +#include <shared.hpp> #include "ode/objects.h" /// Manages everything related to the simulated world data. @@ -16,6 +16,7 @@ class SystemData; +SHARED_PTR_MAP(LogEngine, pLogEngine, LogEngines, LogEnginesIt); class PhysicsEngine { @@ -23,7 +24,7 @@ // / Log engine used by the physics engine. /** This log engine allows the physics engine to write data in the log file, allowing to be differenciated from other engines. */ - LogEngine * log; + pLogEngine log; // / Pointer to the system data, used by different engines in order to store common data. SystemData *systemData; // / Callback function for collisions detection. Modified: trunk/src/tools/xmlTag.cpp =================================================================== --- trunk/src/tools/xmlTag.cpp 2006-06-08 22:47:38 UTC (rev 427) +++ trunk/src/tools/xmlTag.cpp 2006-06-22 15:43:57 UTC (rev 428) @@ -42,8 +42,11 @@ this->name = "unknown"; if (parent == NULL) { - if (logging) this->log = new LogEngine (LOG_DEVELOPER, "XmlTag"); - else this->log = NULL; + if (logging) + { + pLogEngine l (LogEngine::create (LOG_DEVELOPER, "XmlTag")); + this->log = l; + } } else { @@ -53,7 +56,7 @@ if (n == NULL) { if (logging) log->__format(LOG_ERROR, "Empty tag (%s)!", getFullName().c_str()); - return; + return; } if (n->getNodeType() != DOMNode::ELEMENT_NODE) { @@ -93,6 +96,7 @@ if (n) if (n->getNodeType() == DOMNode::ELEMENT_NODE) { assignXmlString (childTagName, n->getNodeName()); + //XmlTag * tmpTag = new XmlTag(this, n, logging); XmlTag * tmpTag = new XmlTag(this, n); tags.push_back(tmpTag); } @@ -123,10 +127,8 @@ if (log) { log->__format(LOG_ENDUSER, "\"%s\" parsed in %f seconds.", filePath.c_str(), SDL_GetTicks()/1000.0 - initTime); - delete log; } } - log = NULL; parent = NULL; } std::string XmlTag::getAttribute(std::string attributeName) Modified: trunk/src/tools/xmlTag.hpp =================================================================== --- trunk/src/tools/xmlTag.hpp 2006-06-08 22:47:38 UTC (rev 427) +++ trunk/src/tools/xmlTag.hpp 2006-06-22 15:43:57 UTC (rev 428) @@ -33,7 +33,7 @@ XmlAttributes attributes; XmlAttributesBool attributesRead; Tags tags; - LogEngine * log; + pLogEngine log; double initTime; public: XmlTag (std::string xmlFilePath); Modified: trunk/src/vehicle/body.cpp =================================================================== --- trunk/src/vehicle/body.cpp 2006-06-08 22:47:38 UTC (rev 427) +++ trunk/src/vehicle/body.cpp 2006-06-22 15:43:57 UTC (rev 428) @@ -23,36 +23,36 @@ { dragCoefficient = 0.3; frontalArea = 0; - BodyOdeData data; - OgreObjectData ogreData; + pBodyOdeData data(new BodyOdeData); + pOgreObjectData ogreData(new OgreObjectData); if (tag->getName() == "body") { setName ( tag->getAttribute("name")); - data.length = stod (tag->getAttribute("length")); - data.width = stod (tag->getAttribute("width")); - data.height = stod (tag->getAttribute("height")); - data.mass = stod (tag->getAttribute("mass")); + data->length = stod (tag->getAttribute("length")); + data->width = stod (tag->getAttribute("width")); + data->height = stod (tag->getAttribute("height")); + data->mass = stod (tag->getAttribute("mass")); frontalArea = stod (tag->getAttribute("frontalArea")); dragCoefficient = stod (tag->getAttribute("dragCoefficient")); - ogreData.meshPath = ""; + ogreData->meshPath = ""; //create main mesh - ogreData.meshPath = getPath() + ogreData.meshPath; - OgreObject * ogreObject = new OgreObject(this, ogreData, getId(), false); + ogreData->meshPath = getPath() + ogreData->meshPath; + pOgreObject ogreObject (new OgreObject(this, ogreData, getId(), false)); ogreObjects[ogreObject->getId()] = ogreObject; - odeObjects[getName()] = new OdeObject(this, data, getName()); + odeObjects[getName()] = pOdeObject(new OdeObject(this, data, getName())); ogreObjects[ogreObject->getId()]->setOdeReference(getMainOdeObject()); //create child meshes XmlTag * t = tag->getTag(0); for (int i = 0; i < tag->nTags(); t = tag->getTag(++i)) { if (t->getName() == "mesh") { - OgreObjectData childData; - childData.meshPath = getPath() + t->getAttribute("file"); + pOgreObjectData childData(new OgreObjectData); + childData->meshPath = getPath() + t->getAttribute("file"); Vector3d posDiff (t->getAttribute("position")); Vector3d scale (t->getAttribute("scale")); Quaternion rotDiff (t->getAttribute("rotation")); - OgreObject * ogreChild = new OgreObject(this, childData, getId()); + pOgreObject ogreChild (new OgreObject(this, childData, getId())); ogreObjects[ogreChild->getId()] = ogreChild; ogreChild->setOgreReference(ogreObjects[ogreObject->getId()], rotDiff, posDiff, scale); SystemData::getSystemDataPointer()->ogreWindow->update (); @@ -63,7 +63,7 @@ // set the air drag variables correctly if (frontalArea == 0) { - frontalArea = data.width * data.height * 0.6; + frontalArea = data->width * data->height * 0.6; } } Modified: trunk/src/vehicle/suspension.cpp =================================================================== --- trunk/src/vehicle/suspension.cpp 2006-06-08 22:47:38 UTC (rev 427) +++ trunk/src/vehicle/suspension.cpp 2006-06-22 15:43:57 UTC (rev 428) @@ -258,9 +258,9 @@ DoubleWishbone::DoubleWishbone(WorldObject * container, XmlTag * tag) :Suspension(container, "suspension.doublewishbone") { - OgreObjectData upperBoneOData; - OgreObjectData lowerBoneOData; - OgreObjectData uprightBoneOData; + pOgreObjectData upperBoneOData(new OgreObjectData); + pOgreObjectData lowerBoneOData(new OgreObjectData); + pOgreObjectData uprightBoneOData(new OgreObjectData); userDriver = false; maxSteeringAngle = 0.0; if (tag->getName() == "suspension.doublewishbone") @@ -275,9 +275,9 @@ springLengthAtEase = stod(tag->getAttribute("springLengthAtEase")); damperFastBump = stod(tag->getAttribute("damperFastBump")); damperFastRebound = stod(tag->getAttribute("damperFastRebound")); - upperBoneOData.meshPath = tag->getAttribute("upperBoneMesh"); - lowerBoneOData.meshPath = tag->getAttribute("lowerBoneMesh"); - uprightBoneOData.meshPath = tag->getAttribute("uprightBoneMesh"); + upperBoneOData->meshPath = tag->getAttribute("upperBoneMesh"); + lowerBoneOData->meshPath = tag->getAttribute("lowerBoneMesh"); + uprightBoneOData->meshPath = tag->getAttribute("uprightBoneMesh"); } else { @@ -292,60 +292,60 @@ //create upperWishbone body - BoneOdeData upperBoneData; - upperBoneData.radius = 0.05; - upperBoneData.length = upperBoneLength = 0.3; - upperBoneData.mass = 2.0; - odeObjects["upperBone"] = new OdeObject(this, upperBoneData, "upperBone"); + pBoneOdeData upperBoneData(new BoneOdeData); + upperBoneData->radius = 0.05; + upperBoneData->length = upperBoneLength = 0.3; + upperBoneData->mass = 2.0; + odeObjects["upperBone"] = pOdeObject(new OdeObject(this, upperBoneData, "upperBone")); dBodySetData (odeObjects["upperBone"]->getBodyID(), (void*) container); Quaternion upperBoneRot (90, 0, 0); odeObjects["upperBone"]->setRotation(upperBoneRot); Vector3d upperBonePos (firstPosition.x, firstPosition.y+(dirMult*upperBoneLength*0.5) , firstPosition.z+(uprightBoneLength*0.5)); odeObjects["upperBone"]->setPosition(upperBonePos); //and its graphics - upperBoneOData.meshPath = getPath() + upperBoneOData.meshPath; - OgreObject * upperOgreObject = new OgreObject(this, upperBoneOData, getId()); + upperBoneOData->meshPath = getPath() + upperBoneOData->meshPath; + pOgreObject upperOgreObject (new OgreObject(this, upperBoneOData, getId())); ogreObjects["upperBone"] = upperOgreObject; ogreObjects["upperBone"]->setOdeReference(odeObjects["upperBone"]); //create lowerWishbone body - BoneOdeData lowerBoneData; - lowerBoneData.radius = 0.05; - lowerBoneData.length = lowerBoneLength = 0.3; - lowerBoneData.mass = 2.0; - odeObjects["lowerBone"] = new OdeObject(this, lowerBoneData, "lowerBone"); + pBoneOdeData lowerBoneData(new BoneOdeData); + lowerBoneData->radius = 0.05; + lowerBoneData->length = lowerBoneLength = 0.3; + lowerBoneData->mass = 2.0; + odeObjects["lowerBone"] = pOdeObject(new OdeObject(this, lowerBoneData, "lowerBone")); dBodySetData (odeObjects["lowerBone"]->getBodyID(), (void*) container); Quaternion lowerBoneRot (90, 0, 0); odeObjects["lowerBone"]->setRotation(lowerBoneRot); Vector3d lowerBonePos (firstPosition.x, firstPosition.y+(dirMult*lowerBoneLength*0.5) , firstPosition.z-(uprightBoneLength*0.5)); odeObjects["lowerBone"]->setPosition(lowerBonePos); //and its graphics - lowerBoneOData.meshPath = getPath() + lowerBoneOData.meshPath; - OgreObject * lowerOgreObject = new OgreObject(this, lowerBoneOData, getId()); + lowerBoneOData->meshPath = getPath() + lowerBoneOData->meshPath; + pOgreObject lowerOgreObject (new OgreObject(this, lowerBoneOData, getId())); ogreObjects["lowerBone"] = lowerOgreObject; ogreObjects["lowerBone"]->setOdeReference(odeObjects["lowerBone"]); //create upright bone body - BoneOdeData uprightBoneData; - uprightBoneData.radius = 0.05; - uprightBoneData.length = uprightBoneLength; - uprightBoneData.mass = 2.0; - odeObjects["uprightBone"] = new OdeObject(this, uprightBoneData, "uprightBone"); + pBoneOdeData uprightBoneData(new BoneOdeData); + uprightBoneData->radius = 0.05; + uprightBoneData->length = uprightBoneLength; + uprightBoneData->mass = 2.0; + odeObjects["uprightBone"] = pOdeObject(new OdeObject(this, uprightBoneData, "uprightBone")); dBodySetData (odeObjects["uprightBone"]->getBodyID(), (void*) container); Quaternion uprightBoneRot (0, 0, 0); odeObjects["uprightBone"]->setRotation(uprightBoneRot); - Vector3d uprightBonePos (firstPosition.x, firstPosition.y+(dirMult*upperBoneData.length), firstPosition.z); + Vector3d uprightBonePos (firstPosition.x, firstPosition.y+(dirMult*upperBoneData->length), firstPosition.z); odeObjects["uprightBone"]->setPosition(uprightBonePos); //and its graphics - uprightBoneOData.meshPath = getPath() + uprightBoneOData.meshPath; - OgreObject * uprightOgreObject = new OgreObject(this, uprightBoneOData, getId()); + uprightBoneOData->meshPath = getPath() + uprightBoneOData->meshPath; + pOgreObject uprightOgreObject (new OgreObject(this, uprightBoneOData, getId())); ogreObjects["uprightBone"] = uprightOgreObject; ogreObjects["uprightBone"]->setOdeReference(odeObjects["uprightBone"]); //create upper joint upperJoint = dJointCreateHinge( World::getWorldPointer()->worldID, 0 ); dJointAttach ( upperJoint, odeObjects["uprightBone"]->getBodyID(), odeObjects["upperBone"]->getBodyID() ); - dJointSetHingeAnchor( upperJoint , firstPosition.x , firstPosition.y+(dirMult*upperBoneData.length), firstPosition.z+(uprightBoneLength*0.5) ); + dJointSetHingeAnchor( upperJoint , firstPosition.x , firstPosition.y+(dirMult*upperBoneData->length), firstPosition.z+(uprightBoneLength*0.5) ); dJointSetHingeAxis( upperJoint , 1.0, 0.0, 0.0 ); //limit its rotation dJointSetHingeParam ( upperJoint, dParamLoStop, -2.0 ); @@ -354,7 +354,7 @@ //create lower joint lowerJoint = dJointCreateHinge( World::getWorldPointer()->worldID, 0 ); dJointAttach ( lowerJoint, odeObjects["uprightBone"]->getBodyID(), odeObjects["lowerBone"]->getBodyID() ); - dJointSetHingeAnchor( lowerJoint , firstPosition.x , firstPosition.y+(dirMult*upperBoneData.length), firstPosition.z-(uprightBoneLength*0.5) ); + dJointSetHingeAnchor( lowerJoint , firstPosition.x , firstPosition.y+(dirMult*upperBoneData->length), firstPosition.z-(uprightBoneLength*0.5) ); dJointSetHingeAxis( lowerJoint , 1.0, 0.0, 0.0 ); //limit its rotation dJointSetHingeParam ( lowerJoint, dParamLoStop, -2.0 ); Modified: trunk/src/vehicle/vehicle.cpp =================================================================== --- trunk/src/vehicle/vehicle.cpp 2006-06-08 22:47:38 UTC (rev 427) +++ trunk/src/vehicle/vehicle.cpp 2006-06-22 15:43:57 UTC (rev 428) @@ -181,7 +181,7 @@ } } -OdeObject * Vehicle::getMainOdeObject() +pOdeObject Vehicle::getMainOdeObject() { return getObject("body")->getMainOdeObject(); } Modified: trunk/src/vehicle/vehicle.hpp =================================================================== --- trunk/src/vehicle/vehicle.hpp 2006-06-08 22:47:38 UTC (rev 427) +++ trunk/src/vehicle/vehicle.hpp 2006-06-22 15:43:57 UTC (rev 428) @@ -73,7 +73,7 @@ Vector3d getPosition (); Quaternion getRotation (); double getOutputTorque (); - OdeObject * getMainOdeObject(); + pOdeObject getMainOdeObject(); void stepGraphics (); }; #endif Modified: trunk/src/vehicle/wheel.cpp =================================================================== --- trunk/src/vehicle/wheel.cpp 2006-06-08 22:47:38 UTC (rev 427) +++ trunk/src/vehicle/wheel.cpp 2006-06-22 15:43:57 UTC (rev 428) @@ -23,8 +23,8 @@ :DriveMass(container, "wheel") { log->__format (LOG_DEVELOPER, "Starting to parse a wheel node"); - WheelOdeData data; - OgreObjectData ogreData; + pWheelOdeData data(new WheelOdeData); + pOgreObjectData ogreData(new OgreObjectData); powered = 0; inputAngularVel = 0.0; outputAngularVel = 0.0; @@ -37,27 +37,27 @@ if (tag->getName() == "wheel") { setName ( tag->getAttribute("name")); - data.radius = stod(tag->getAttribute("radius")); - data.width = stod(tag->getAttribute("width")); - data.mass = stod(tag->getAttribute("mass")); + data->radius = stod(tag->getAttribute("radius")); + data->width = stod(tag->getAttribute("width")); + data->mass = stod(tag->getAttribute("mass")); powered = stod(tag->getAttribute("powered")); //create main mesh - ogreData.meshPath = getPath() + ogreData.meshPath; - OgreObject * ogreObject = new OgreObject(this, ogreData, getId(), false); + ogreData->meshPath = getPath() + ogreData->meshPath; + pOgreObject ogreObject (new OgreObject(this, ogreData, getId(), false)); ogreObjects[ogreObject->getId()] = ogreObject; - odeObjects[getId()] = new OdeObject(this, data, getId()); + odeObjects[getId()] = pOdeObject(new OdeObject(this, data, getId())); ogreObjects[ogreObject->getId()]->setOdeReference(getMainOdeObject()); //create child meshes XmlTag * t = tag->getTag(0); for (int i = 0; i < tag->nTags(); t = tag->getTag(++i)) { if (t->getName() == "mesh") { - OgreObjectData childData; - childData.meshPath = getPath() + t->getAttribute("file"); + pOgreObjectData childData(new OgreObjectData); + childData->meshPath = getPath() + t->getAttribute("file"); Vector3d posDiff (t->getAttribute("position")); Vector3d scale (t->getAttribute("scale")); Quaternion rotDiff (t->getAttribute("rotation")); - OgreObject * ogreChild = new OgreObject(this, childData, getId()); + pOgreObject ogreChild (new OgreObject(this, childData, getId())); ogreObjects[ogreChild->getId()] = ogreChild; ogreChild->setOgreReference(ogreObjects[ogreObject->getId()], rotDiff, posDiff, scale); } Modified: trunk/src/world/area.cpp =================================================================== --- trunk/src/world/area.cpp 2006-06-08 22:47:38 UTC (rev 427) +++ trunk/src/world/area.cpp 2006-06-22 15:43:57 UTC (rev 428) @@ -80,11 +80,11 @@ if (t->getName() == "ground") { groundHeight = stod (t->getAttribute("height")); - OgreObjectData ogreData; - ogreData.meshPath = ""; + pOgreObjectData ogreData(new OgreObjectData); + ogreData->meshPath = ""; //create main mesh - ogreData.meshPath = getPath() + ogreData.meshPath; - OgreObject * ogreObject = new OgreObject(this, ogreData, getId(), false); + ogreData->meshPath = getPath() + ogreData->meshPath; + pOgreObject ogreObject (new OgreObject(this, ogreData, getId(), false)); ogreObjects[ogreObject->getId()] = ogreObject; //create child meshes XmlTag * u = t->getTag(0); for (int i = 0; i < t->nTags(); u = t->getTag(++i)) @@ -92,12 +92,12 @@ if (u->getName() == "mesh") { log->__format (LOG_CCREATOR, "Creating an ogre mesh for the ground"); - OgreObjectData childData; - childData.meshPath = getPath() + u->getAttribute("file"); + pOgreObjectData childData (new OgreObjectData); + childData->meshPath = getPath() + u->getAttribute("file"); Vector3d posDiff (u->getAttribute("position")); Vector3d scale (u->getAttribute("scale")); Quaternion rotDiff (u->getAttribute("rotation")); - OgreObject * ogreChild = new OgreObject(this, childData, getId()); + pOgreObject ogreChild (new OgreObject(this, childData, getId())); ogreObjects[ogreChild->getId()] = ogreChild; ogreChild->setOgreReference(ogreObjects[ogreObject->getId()], rotDiff, posDiff, scale); // declare ode mesh Modified: trunk/src/world/part.cpp =================================================================== --- trunk/src/world/part.cpp 2006-06-08 22:47:38 UTC (rev 427) +++ trunk/src/world/part.cpp 2006-06-22 15:43:57 UTC (rev 428) @@ -26,53 +26,53 @@ Ogre::ResourceGroupManager::getSingleton().addResourceLocation(getPath(), "FileSystem", "parts." + name); Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup("parts." + name); XmlTag * tag = new XmlTag (getXmlPath().c_str()); - OgreObjectData ogreData; - PartOdeData data; + pOgreObjectData ogreData(new OgreObjectData); + pPartOdeData data(new PartOdeData); std::string shape = "none"; if (tag->getName() == "part") { setName(tag->getAttribute("name")); - data.mass = stod(tag->getAttribute("mass")); + data->mass = stod(tag->getAttribute("mass")); XmlTag * t = tag->getTag(0); for (int i = 0; i < tag->nTags(); t = tag->getTag(++i)) { - data.shape = t->getName(); - if (data.shape == "box") + data->shape = t->getName(); + if (data->shape == "box") { - data.size = Vector3d(t->getAttribute("size")); + data->size = Vector3d(t->getAttribute("size")); } - if (data.shape == "sphere") + if (data->shape == "sphere") { - data.radius = stod(t->getAttribute("radius")); + data->radius = stod(t->getAttribute("radius")); } - if (data.shape == "cappedCylinder") + if (data->shape == "cappedCylinder") { - data.radius = stod(t->getAttribute("radius")); - data.length = stod(t->getAttribute("length")); - if (t->getAttribute("directionAxis") == "x") data.directionAxis = 1; - if (t->getAttribute("directionAxis") == "y") data.directionAxis = 2; - if (t->getAttribute("directionAxis") == "z") data.directionAxis = 3; + data->radius = stod(t->getAttribute("radius")); + data->length = stod(t->getAttribute("length")); + if (t->getAttribute("directionAxis") == "x") data->directionAxis = 1; + if (t->getAttribute("directionAxis") == "y") data->directionAxis = 2; + if (t->getAttribute("directionAxis") == "z") data->directionAxis = 3; } } - if (data.shape == "none") log->__format(LOG_ERROR, "No physics shape specified for this part."); - odeObjects[getId()] = new OdeObject(this, data, getId()); + if (data->shape == "none") log->__format(LOG_ERROR, "No physics shape specified for this part."); + odeObjects[getId()] = pOdeObject(new OdeObject(this, data, getId())); //create main mesh - ogreData.meshPath = getPath() + ogreData.meshPath; - OgreObject * ogreObject = new OgreObject(this, ogreData, getId(), false); + ogreData->meshPath = getPath() + ogreData->meshPath; + pOgreObject ogreObject (new OgreObject(this, ogreData, getId(), false)); ogreObjects[ogreObject->getId()] = ogreObject; - odeObjects[getName()] = new OdeObject(this, data, getName()); + odeObjects[getName()] = pOdeObject(new OdeObject(this, data, getName())); ogreObjects[ogreObject->getId()]->setOdeReference(getMainOdeObject()); //create child meshes t = tag->getTag(0); for (int i = 0; i < tag->nTags(); t = tag->getTag(++i)) { if (t->getName() == "mesh") { - OgreObjectData childData; - childData.meshPath = getPath() + t->getAttribute("file"); + pOgreObjectData childData(new OgreObjectData); + childData->meshPath = getPath() + t->getAttribute("file"); Vector3d posDiff (t->getAttribute("position")); Vector3d scale (t->getAttribute("scale")); Quaternion rotDiff (t->getAttribute("rotation")); - OgreObject * ogreChild = new OgreObject(this, childData, getId()); + pOgreObject ogreChild (new OgreObject(this, childData, getId())); ogreObjects[ogreChild->getId()] = ogreChild; ogreChild->setOgreReference(ogreObjects[ogreObject->getId()], rotDiff, posDiff, scale); SystemData::getSystemDataPointer()->ogreWindow->update (); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <st...@us...> - 2006-06-08 22:50:54
|
Revision: 427 Author: stenyak Date: 2006-06-08 15:47:38 -0700 (Thu, 08 Jun 2006) ViewCVS: http://svn.sourceforge.net/motorsport/?rev=427&view=rev Log Message: ----------- New attribute add to all <mesh> tags, which allows to (graphically only) scale meshes. Blend2Mosp* exporters need no changes, they've been writing this attribute since the beginning, only now Motorsport actually reads it. Added support for several graphic meshes for common parts too (as well as the aforementioned scale attribute). Fixed makefile, system.tags filename is easily modifiable now. Modified Mosp1 vehicle: now using appropriate 'scale' attributes wherever needed. Modified Mosp1 vehicle: removed the funny 5th wheel from back window. Fixed Mosp1 vehicle: now using double wishbone suspensions everywhere. Modified default world: now using vehicle cameras by default (instead of area cameras). Modified Paths: -------------- trunk/cfg/graphicsConfig.xml trunk/cfg/logConfig.xml trunk/data/areas/mospland/road.tga trunk/data/parts/cone/part.xml trunk/data/parts/cube/part.xml trunk/data/parts/metalStand/part.xml trunk/data/vehicles/mosp1/vehicle.xml trunk/data/worlds/default.xml trunk/src/common/ogreObject.cpp trunk/src/common/ogreObject.hpp trunk/src/makefile trunk/src/vehicle/body.cpp trunk/src/vehicle/wheel.cpp trunk/src/world/area.cpp trunk/src/world/part.cpp Modified: trunk/cfg/graphicsConfig.xml =================================================================== Modified: trunk/cfg/logConfig.xml =================================================================== Modified: trunk/data/areas/mospland/road.tga =================================================================== (Binary files differ) Modified: trunk/data/parts/cone/part.xml =================================================================== --- trunk/data/parts/cone/part.xml 2006-06-08 16:26:24 UTC (rev 426) +++ trunk/data/parts/cone/part.xml 2006-06-08 22:47:38 UTC (rev 427) @@ -5,9 +5,15 @@ author = "Angelos Anadilinos (aka vagos)" contact = "aggnos1 AT yahoo DOT com" license = "Creative Commons Attribution-NonCommercial-ShareAlike License. For more info, read the readme.txt file." - mesh = "cone.mesh" mass = "3" > + <mesh + file = "cone.mesh" + scale = "1 1 1" + position = "0 0 0" + rotation = "0 0 0" + > + </mesh> <box size = "0.5 0.5 0.8" > Modified: trunk/data/parts/cube/part.xml =================================================================== --- trunk/data/parts/cube/part.xml 2006-06-08 16:26:24 UTC (rev 426) +++ trunk/data/parts/cube/part.xml 2006-06-08 22:47:38 UTC (rev 427) @@ -5,9 +5,15 @@ author = "Bruno Gonzalez Campo (STenyaK)" contact = "stenyak AT gmx DOT net" license = "Creative Commons Attribution-NonCommercial-ShareAlike License" - mesh = "cube.mesh" mass = "2000" > + <mesh + file = "cube.mesh" + scale = "1 1 1" + position = "0 0 0" + rotation = "0 0 0" + > + </mesh> <box size = "2 2 2" > Modified: trunk/data/parts/metalStand/part.xml =================================================================== --- trunk/data/parts/metalStand/part.xml 2006-06-08 16:26:24 UTC (rev 426) +++ trunk/data/parts/metalStand/part.xml 2006-06-08 22:47:38 UTC (rev 427) @@ -5,9 +5,15 @@ author = "David Goodman" contact = " david DOT n DOT goodman AT max-realms DOT com" license = "The artist who created the model in this zip file retains all rights. If you want to use this model for any purpose other than personal, non-commercial use, you must contact the artist directly. Read Max-Realms_License.htm for more info." - mesh = "metalstand.mesh" mass = "5000" > + <mesh + file = "metalstand.mesh" + scale = "1 1 1" + position = "0 0 0" + rotation = "0 0 0" + > + </mesh> <box size = "20 8 8" > Modified: trunk/data/vehicles/mosp1/vehicle.xml =================================================================== --- trunk/data/vehicles/mosp1/vehicle.xml 2006-06-08 16:26:24 UTC (rev 426) +++ trunk/data/vehicles/mosp1/vehicle.xml 2006-06-08 22:47:38 UTC (rev 427) @@ -35,16 +35,11 @@ > <mesh file= "body.mesh" + scale = "1 1 1" position = "0 0 0" rotation = "0 0 0" > </mesh> - <mesh - file= "wheel_front.mesh" - position = "-1.5 0 0.6" - rotation = "0 15 0" - > - </mesh> </body> <pedal name = "clutchPedal" @@ -156,6 +151,16 @@ steeringAngle = "+80" > </suspension.unidimensional> + <suspension.unidimensional + name = "fl suspension" + springConstant = "80500" + dampingConstant = "2000" + position = "+1.44 -0.857 -0.45" + rotation = "+92.5 0 0" + steeringAngle = "-80" + > + </suspension.unidimensional> +--> <suspension.doublewishbone name = "fl suspension" springStiffness = "80500" @@ -172,38 +177,22 @@ uprightBoneMesh = "susp/Cube.001.mesh" > </suspension.doublewishbone> ---> - <suspension.unidimensional - name = "fl suspension" - springConstant = "80500" - dampingConstant = "2000" - position = "+1.44 -0.857 -0.45" - rotation = "+92.5 0 0" - steeringAngle = "-80" - > - </suspension.unidimensional> <suspension.doublewishbone name = "fr suspension" springStiffness = "80500" springLengthAtEase = "0.5" damperFastBump = "2000" damperFastRebound = "2100" - firstPosition = "+1.44 +0.57 -0.45" + firstPosition = "+1.44 +0.557 -0.45" firstRotation = "0 0 0" position = "+1.44 +0.857 -0.45" rotation = "-90 0 0" - steeringAngle = "+80" + steeringAngle = "+50" upperBoneMesh = "susp/Cube.mesh" lowerBoneMesh = "susp/Cube.mesh" uprightBoneMesh = "susp/Cube.001.mesh" > </suspension.doublewishbone> - <suspension.fixed - name = "rr suspension" - position = "-1.35 +0.88 -0.45" - rotation = "-90 0 0" - > - </suspension.fixed> <suspension.doublewishbone name = "rl suspension" springStiffness = "80900" @@ -214,22 +203,12 @@ firstRotation = "0 0 0" position = "-1.35 -0.88 -0.45" rotation = "+90 0 0" - steeringAngle = "0" + steeringAngle = "+0" upperBoneMesh = "susp/Cube.mesh" lowerBoneMesh = "susp/Cube.mesh" uprightBoneMesh = "susp/Cube.001.mesh" > </suspension.doublewishbone> -<!-- - <suspension.unidimensional - name = "rr suspension" - springConstant = "80900" - dampingConstant = "2000" - position = "-1.35 +0.88 -0.45" - rotation = "-91 0 0" - steeringAngle = "0" - > - </suspension.unidimensional> <suspension.doublewishbone name = "rr suspension" springStiffness = "80900" @@ -240,13 +219,23 @@ firstRotation = "0 0 0" position = "-1.35 +0.88 -0.45" rotation = "-90 0 0" - steeringAngle = "0" + steeringAngle = "-0" upperBoneMesh = "susp/Cube.mesh" lowerBoneMesh = "susp/Cube.mesh" uprightBoneMesh = "susp/Cube.001.mesh" > </suspension.doublewishbone> +<!-- <suspension.unidimensional + name = "rr suspension" + springConstant = "80900" + dampingConstant = "2000" + position = "-1.35 +0.88 -0.45" + rotation = "-91 0 0" + steeringAngle = "0" + > + </suspension.unidimensional> + <suspension.unidimensional name = "rl suspension" springConstant = "80900" dampingConstant = "2000" @@ -256,6 +245,12 @@ > </suspension.unidimensional> <suspension.fixed + name = "rr suspension" + position = "-1.35 +0.88 -0.45" + rotation = "-90 0 0" + > + </suspension.fixed> + <suspension.fixed name = "rl suspension" position = "-1.35 -0.88 -0.45" rotation = "+90 0 0" @@ -273,6 +268,7 @@ > <mesh file = "wheel_front.mesh" + scale = "1 1 1" position = "0 0 0" rotation = "0 0 0" > @@ -288,6 +284,7 @@ > <mesh file = "wheel_front.mesh" + scale = "1 1 1" position = "0 0 0" rotation = "0 0 0" > @@ -303,6 +300,7 @@ > <mesh file= "wheel_rear.mesh" + scale = "1 1 1" position = "0 0 0" rotation = "0 0 0" > @@ -318,6 +316,7 @@ > <mesh file = "wheel_rear.mesh" + scale = "1 1 1" position = "0 0 0" rotation = "0 0 0" > Modified: trunk/data/worlds/default.xml =================================================================== --- trunk/data/worlds/default.xml 2006-06-08 16:26:24 UTC (rev 426) +++ trunk/data/worlds/default.xml 2006-06-08 22:47:38 UTC (rev 427) @@ -2,7 +2,7 @@ <world name = "Test World" description = "Drive the Mosp1 car in the testing grounds!" - useAreaCamera = "true" + useAreaCamera = "false" gravityX = "0.0" gravityY = "0.0" gravityZ = "-9.8" @@ -18,6 +18,7 @@ --> <vehicle directory = "mosp1" + _directory = "quattros1" driver = "user" startPosition = "paceCar" > @@ -63,6 +64,7 @@ </vehicleList> <area directory = "mospland" + _directory = "mospland2006.r6" > </area> </world> Modified: trunk/src/common/ogreObject.cpp =================================================================== --- trunk/src/common/ogreObject.cpp 2006-06-08 16:26:24 UTC (rev 426) +++ trunk/src/common/ogreObject.cpp 2006-06-08 22:47:38 UTC (rev 427) @@ -78,7 +78,7 @@ this->odeObject = odeObject; } -void OgreObject::setOgreReference(OgreObject * ogreObject, Quaternion rotationDiff, Vector3d positionDiff) +void OgreObject::setOgreReference(OgreObject * ogreObject, Quaternion rotationDiff, Vector3d positionDiff, Vector3d scale) { static_cast<Ogre::SceneNode*>(SystemData::getSystemDataPointer()->ogreSceneManager->getRootSceneNode())->removeChild(node); ogreObject->getNode()->addChild(node); @@ -86,6 +86,7 @@ Ogre::Quaternion * rd = new Ogre::Quaternion (rotationDiff.w, rotationDiff.x, rotationDiff.y, rotationDiff.z); node->setPosition(*pd); node->setOrientation(*rd); + node->setScale(scale.x, scale.y, scale.z); } Modified: trunk/src/common/ogreObject.hpp =================================================================== --- trunk/src/common/ogreObject.hpp 2006-06-08 16:26:24 UTC (rev 426) +++ trunk/src/common/ogreObject.hpp 2006-06-08 22:47:38 UTC (rev 427) @@ -45,7 +45,7 @@ ~OgreObject (); std::string getId(); void setOdeReference(OdeObject * odeObject); - void setOgreReference(OgreObject * ogreObject, Quaternion rotationDiff, Vector3d positionDiff); + void setOgreReference(OgreObject * ogreObject, Quaternion rotationDiff, Vector3d positionDiff, Vector3d scale); void stepGraphics(); Ogre::SceneNode * getNode(); Ogre::Entity * getEntity(); Modified: trunk/src/makefile =================================================================== --- trunk/src/makefile 2006-06-08 16:26:24 UTC (rev 426) +++ trunk/src/makefile 2006-06-08 22:47:38 UTC (rev 427) @@ -292,7 +292,7 @@ fi $(SYSTAGS) : - @ctags -IR --c++-kinds=+p --fields=+iaS --extra=+q -f system.tags $(patsubst %,%/*.h*,$(SYSTEM_INCLUDE_DIRS)) + @ctags -IR --c++-kinds=+p --fields=+iaS --extra=+q -f $(SYSTAGS) $(patsubst %,%/*.h*,$(SYSTEM_INCLUDE_DIRS)) .PHONY: configure configure: Modified: trunk/src/vehicle/body.cpp =================================================================== --- trunk/src/vehicle/body.cpp 2006-06-08 16:26:24 UTC (rev 426) +++ trunk/src/vehicle/body.cpp 2006-06-08 22:47:38 UTC (rev 427) @@ -50,10 +50,11 @@ OgreObjectData childData; childData.meshPath = getPath() + t->getAttribute("file"); Vector3d posDiff (t->getAttribute("position")); + Vector3d scale (t->getAttribute("scale")); Quaternion rotDiff (t->getAttribute("rotation")); OgreObject * ogreChild = new OgreObject(this, childData, getId()); ogreObjects[ogreChild->getId()] = ogreChild; - ogreChild->setOgreReference(ogreObjects[ogreObject->getId()], rotDiff, posDiff); + ogreChild->setOgreReference(ogreObjects[ogreObject->getId()], rotDiff, posDiff, scale); SystemData::getSystemDataPointer()->ogreWindow->update (); } } Modified: trunk/src/vehicle/wheel.cpp =================================================================== --- trunk/src/vehicle/wheel.cpp 2006-06-08 16:26:24 UTC (rev 426) +++ trunk/src/vehicle/wheel.cpp 2006-06-08 22:47:38 UTC (rev 427) @@ -55,10 +55,11 @@ OgreObjectData childData; childData.meshPath = getPath() + t->getAttribute("file"); Vector3d posDiff (t->getAttribute("position")); + Vector3d scale (t->getAttribute("scale")); Quaternion rotDiff (t->getAttribute("rotation")); OgreObject * ogreChild = new OgreObject(this, childData, getId()); ogreObjects[ogreChild->getId()] = ogreChild; - ogreChild->setOgreReference(ogreObjects[ogreObject->getId()], rotDiff, posDiff); + ogreChild->setOgreReference(ogreObjects[ogreObject->getId()], rotDiff, posDiff, scale); } } } Modified: trunk/src/world/area.cpp =================================================================== --- trunk/src/world/area.cpp 2006-06-08 16:26:24 UTC (rev 426) +++ trunk/src/world/area.cpp 2006-06-08 22:47:38 UTC (rev 427) @@ -95,10 +95,11 @@ OgreObjectData childData; childData.meshPath = getPath() + u->getAttribute("file"); Vector3d posDiff (u->getAttribute("position")); + Vector3d scale (u->getAttribute("scale")); Quaternion rotDiff (u->getAttribute("rotation")); OgreObject * ogreChild = new OgreObject(this, childData, getId()); ogreObjects[ogreChild->getId()] = ogreChild; - ogreChild->setOgreReference(ogreObjects[ogreObject->getId()], rotDiff, posDiff); + ogreChild->setOgreReference(ogreObjects[ogreObject->getId()], rotDiff, posDiff, scale); // declare ode mesh dTriMeshDataID ground = dGeomTriMeshDataCreate (); dGeomSetBody (dCreateTriMesh (World::getWorldPointer ()->spaceID, ground, 0, 0, 0), 0); Modified: trunk/src/world/part.cpp =================================================================== --- trunk/src/world/part.cpp 2006-06-08 16:26:24 UTC (rev 426) +++ trunk/src/world/part.cpp 2006-06-08 22:47:38 UTC (rev 427) @@ -32,7 +32,6 @@ if (tag->getName() == "part") { setName(tag->getAttribute("name")); - ogreData.meshPath = tag->getAttribute("mesh"); data.mass = stod(tag->getAttribute("mass")); XmlTag * t = tag->getTag(0); for (int i = 0; i < tag->nTags(); t = tag->getTag(++i)) { @@ -54,14 +53,33 @@ if (t->getAttribute("directionAxis") == "z") data.directionAxis = 3; } } + if (data.shape == "none") log->__format(LOG_ERROR, "No physics shape specified for this part."); + odeObjects[getId()] = new OdeObject(this, data, getId()); + + //create main mesh + ogreData.meshPath = getPath() + ogreData.meshPath; + OgreObject * ogreObject = new OgreObject(this, ogreData, getId(), false); + ogreObjects[ogreObject->getId()] = ogreObject; + odeObjects[getName()] = new OdeObject(this, data, getName()); + ogreObjects[ogreObject->getId()]->setOdeReference(getMainOdeObject()); + //create child meshes + t = tag->getTag(0); for (int i = 0; i < tag->nTags(); t = tag->getTag(++i)) + { + if (t->getName() == "mesh") + { + OgreObjectData childData; + childData.meshPath = getPath() + t->getAttribute("file"); + Vector3d posDiff (t->getAttribute("position")); + Vector3d scale (t->getAttribute("scale")); + Quaternion rotDiff (t->getAttribute("rotation")); + OgreObject * ogreChild = new OgreObject(this, childData, getId()); + ogreObjects[ogreChild->getId()] = ogreChild; + ogreChild->setOgreReference(ogreObjects[ogreObject->getId()], rotDiff, posDiff, scale); + SystemData::getSystemDataPointer()->ogreWindow->update (); + } + } } - ogreData.meshPath = getPath() + ogreData.meshPath; - OgreObject * ogreObject = new OgreObject(this, ogreData, getId()); - ogreObjects[getId()] = ogreObject; - if (data.shape == "none") log->__format(LOG_ERROR, "No physics shape specified for this part."); - odeObjects[getId()] = new OdeObject(this, data, getId()); - ogreObjects.begin()->second->setOdeReference(odeObjects.begin()->second); delete tag; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <st...@us...> - 2006-06-08 16:27:06
|
Revision: 426 Author: stenyak Date: 2006-06-08 09:26:24 -0700 (Thu, 08 Jun 2006) ViewCVS: http://svn.sourceforge.net/motorsport/?rev=426&view=rev Log Message: ----------- Modified makefile: now tags creation is optional, so 'make' won't stop when ctags isn't found. Added commented lines for custom 3rd party linux libs in makefile. Modified Paths: -------------- trunk/src/makefile Modified: trunk/src/makefile =================================================================== --- trunk/src/makefile 2006-05-31 15:40:11 UTC (rev 425) +++ trunk/src/makefile 2006-06-08 16:26:24 UTC (rev 426) @@ -50,6 +50,8 @@ EXE_EXT := BASE_INCLUDE_DIR := /usr/include BASE_LIBRARY_DIR := /usr/lib +#BASE_INCLUDE_DIR := $(PWD)/../3pl/linux/include +#BASE_LIBRARY_DIR := $(PWD)/../3pl/linux/lib PLATFORM_CFLAGS := LD_FLAGS:= endif @@ -278,11 +280,15 @@ .PHONY: tags tags: $(SYSTAGS) - @ctags -I --c++-kinds=+p --fields=+iaS --extra=+q -f $(MOSPTAGS) $(SOURCES) $(patsubst %,%/*.h*,$(MOTORSPORT_INCLUDE_DIRS)) - @if [ -f $(SYSTAGS) ]; then \ - cat $(MOSPTAGS) $(SYSTAGS) |sort|uniq >$(TAGS); \ + @if ctags -I --c++-kinds=+p --fields=+iaS --extra=+q -f $(MOSPTAGS) $(SOURCES) $(patsubst %,%/*.h*,$(MOTORSPORT_INCLUDE_DIRS)); \ + then \ + if [ -f $(SYSTAGS) ]; then \ + cat $(MOSPTAGS) $(SYSTAGS) |sort|uniq >$(TAGS); \ + else \ + mv $(MOSPTAGS) $(TAGS); \ + fi; \ else \ - mv $(MOSPTAGS) $(TAGS); \ + echo Failed creating tags!; \ fi $(SYSTAGS) : This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <st...@us...> - 2006-05-31 15:40:23
|
Revision: 425 Author: stenyak Date: 2006-05-31 08:40:11 -0700 (Wed, 31 May 2006) ViewCVS: http://svn.sourceforge.net/motorsport/?rev=425&view=rev Log Message: ----------- Fixed once and for all the doublewishbone left<->right selector bug! Added support for profiling with gprof. Command line usage: PROFILE=1 make all <enter> Modified Paths: -------------- trunk/src/makefile trunk/src/vehicle/suspension.cpp Modified: trunk/src/makefile =================================================================== --- trunk/src/makefile 2006-05-28 21:54:17 UTC (rev 424) +++ trunk/src/makefile 2006-05-31 15:40:11 UTC (rev 425) @@ -64,6 +64,9 @@ #CXX := ccache g++ CFLAGS := -fmessage-length=0 -c -Wall -g -O0 -DGCC_3_1 -DEXT_HASH $(PLATFORM_CFLAGS) CXXFLAGS := $(CFLAGS) +ifdef PROFILE +PROFILEFLAGS := -pg +endif ########################################### @@ -264,10 +267,10 @@ #Compiling instructions %.o : %.cpp - $(CXX) $(CXXFLAGS) $(patsubst %,-D%,$(DEFINES)) $(patsubst %,-I%,$(INCLUDE_DIRS)) -o $@ $< + $(CXX) $(PROFILEFLAGS) $(CXXFLAGS) $(patsubst %,-D%,$(DEFINES)) $(patsubst %,-I%,$(INCLUDE_DIRS)) -o $@ $< %.o : %.c - $(CC) $(CFLAGS) $(patsubst %,-D%,$(DEFINES)) $(patsubst %,-I%,$(INCLUDE_DIRS)) -o $@ $< + $(CC) $(PROFILEFLAGS) $(CFLAGS) $(patsubst %,-D%,$(DEFINES)) $(patsubst %,-I%,$(INCLUDE_DIRS)) -o $@ $< #Phony targets definitions .PHONY: all @@ -300,7 +303,7 @@ .PHONY: clobber clobber : clean @echo "---Clobber...---------------------------------" - rm -f *~ */*~ .*[hc]pp.swp */.*[hc]pp.swp *.log screenframe*.jpg $(SYSTAGS) + rm -f *~ */*~ .*[hc]pp.swp */.*[hc]pp.swp *.log screenframe*.jpg gmon.out $(SYSTAGS) @echo "----------------------------------------------" .PHONY: run @@ -310,7 +313,7 @@ @echo "----------------------------------------------" $(TARGET) :$(OBJECTS) - $(LD) $(LD_FLAGS) $(patsubst %,-L%,$(LIBRARY_DIRS)) -o $@ $^ $(patsubst %,-l%,$(LIBRARIES)) + $(LD) $(PROFILEFLAGS) $(LD_FLAGS) $(patsubst %,-L%,$(LIBRARY_DIRS)) -o $@ $^ $(patsubst %,-l%,$(LIBRARIES)) @chmod +x $@ @echo "---Exec...------------------------------------" @echo -n "Motorsport successfully compiled!: " Modified: trunk/src/vehicle/suspension.cpp =================================================================== --- trunk/src/vehicle/suspension.cpp 2006-05-28 21:54:17 UTC (rev 424) +++ trunk/src/vehicle/suspension.cpp 2006-05-31 15:40:11 UTC (rev 425) @@ -284,7 +284,7 @@ log->__format(LOG_ERROR, "Suspension was supposed to be a double wishbone suspension, but tag name is different!"); } springOldx = springLengthAtEase; - right = (firstPosition.y > 0)? right : false; + right = firstPosition.y > 0; uprightBoneLength = 0.4; //-------------------------------------------- double dirMult = 1.0; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <st...@us...> - 2006-05-28 21:54:29
|
Revision: 424 Author: stenyak Date: 2006-05-28 14:54:17 -0700 (Sun, 28 May 2006) ViewCVS: http://svn.sourceforge.net/motorsport/?rev=424&view=rev Log Message: ----------- Fixed makefile: now 'tags' target also reads .cpp files (not just headers). Modified Paths: -------------- trunk/src/makefile Modified: trunk/src/makefile =================================================================== --- trunk/src/makefile 2006-05-21 15:32:44 UTC (rev 423) +++ trunk/src/makefile 2006-05-28 21:54:17 UTC (rev 424) @@ -275,7 +275,7 @@ .PHONY: tags tags: $(SYSTAGS) - @ctags -I --c++-kinds=+p --fields=+iaS --extra=+q -f $(MOSPTAGS) $(patsubst %,%/*.h*,$(MOTORSPORT_INCLUDE_DIRS)) + @ctags -I --c++-kinds=+p --fields=+iaS --extra=+q -f $(MOSPTAGS) $(SOURCES) $(patsubst %,%/*.h*,$(MOTORSPORT_INCLUDE_DIRS)) @if [ -f $(SYSTAGS) ]; then \ cat $(MOSPTAGS) $(SYSTAGS) |sort|uniq >$(TAGS); \ else \ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <st...@us...> - 2006-05-21 15:32:55
|
Revision: 423 Author: stenyak Date: 2006-05-21 08:32:44 -0700 (Sun, 21 May 2006) ViewCVS: http://svn.sourceforge.net/motorsport/?rev=423&view=rev Log Message: ----------- Modified makefile: now uses separate INCLUDE_DIRS for mosp dirs and 3pl dirs. Modified makefile: tags will now also generate 3pl tags (only if necessary). Added new target to makefile: you can now generate 3pl tags with <make system.tags> Modified Paths: -------------- trunk/src/makefile Modified: trunk/src/makefile =================================================================== --- trunk/src/makefile 2006-05-14 19:22:35 UTC (rev 422) +++ trunk/src/makefile 2006-05-21 15:32:44 UTC (rev 423) @@ -55,6 +55,9 @@ endif DEFINES := $(PLATFORM) $(TYPE) TARGET := motorsport$(EXE_EXT) +TAGS := tags +MOSPTAGS := motorsport.tags +SYSTAGS := system.tags LD := g++ CC := gcc CXX := g++ @@ -116,28 +119,34 @@ /usr/local/include/OGRE \ /usr/local/include/SDL endif -#All paths... -INCLUDE_DIRS := \ +#Motorsport paths... +MOTORSPORT_INCLUDE_DIRS := \ + vehicle \ + world \ + log \ + tools \ + common \ + . +#System paths... +SYSTEM_INCLUDE_DIRS := \ $(PLATFORM_INCLUDE_DIRS) \ - $(BASE_INCLUDE_DIR)/ \ + $(BASE_INCLUDE_DIR) \ $(BASE_INCLUDE_DIR)/ode \ $(BASE_INCLUDE_DIR)/freetype2 \ $(BASE_INCLUDE_DIR)/SDL \ $(BASE_INCLUDE_DIR)/OGRE \ $(BASE_INCLUDE_DIR)/xercesc \ - vehicle \ - world \ - log \ - tools \ - common \ $(BASE_INCLUDE_DIR)/../local/include/ode \ $(BASE_INCLUDE_DIR)/freetype2 \ $(BASE_INCLUDE_DIR)/SDL \ $(BASE_INCLUDE_DIR)/OGRE \ $(BASE_INCLUDE_DIR)/xercesc \ $(BASE_INCLUDE_DIR)/../local/include/OGRE \ - $(BASE_INCLUDE_DIR)/../local/include/SDL \ - ./ + $(BASE_INCLUDE_DIR)/../local/include/SDL +#All paths... +INCLUDE_DIRS := \ + $(SYSTEM_INCLUDE_DIRS) \ + $(MOTORSPORT_INCLUDE_DIRS) ########################################### @@ -262,8 +271,20 @@ #Phony targets definitions .PHONY: all -all: $(TARGET) +all: $(TARGET) tags +.PHONY: tags +tags: $(SYSTAGS) + @ctags -I --c++-kinds=+p --fields=+iaS --extra=+q -f $(MOSPTAGS) $(patsubst %,%/*.h*,$(MOTORSPORT_INCLUDE_DIRS)) + @if [ -f $(SYSTAGS) ]; then \ + cat $(MOSPTAGS) $(SYSTAGS) |sort|uniq >$(TAGS); \ + else \ + mv $(MOSPTAGS) $(TAGS); \ + fi + +$(SYSTAGS) : + @ctags -IR --c++-kinds=+p --fields=+iaS --extra=+q -f system.tags $(patsubst %,%/*.h*,$(SYSTEM_INCLUDE_DIRS)) + .PHONY: configure configure: @echo "---Configure...-------------------------------" @@ -273,13 +294,13 @@ .PHONY: clean clean: @echo "---Clean...-----------------------------------" - rm -f $(TARGET) $(OBJECTS) $(TEST_EXE) + rm -f $(TARGET) $(OBJECTS) $(TEST_EXE) $(MOSPTAGS) $(TAGS) @echo "----------------------------------------------" .PHONY: clobber clobber : clean @echo "---Clobber...---------------------------------" - rm -f *~ */*~ .*[hc]pp.swp */.*[hc]pp.swp *.log + rm -f *~ */*~ .*[hc]pp.swp */.*[hc]pp.swp *.log screenframe*.jpg $(SYSTAGS) @echo "----------------------------------------------" .PHONY: run @@ -288,10 +309,6 @@ LD_LIBRARY_PATH=$(LD_LIBRARY_PATH)$(subst $(Pat_space),$(Pat_empty),$(patsubst %,:%,$(LIBRARY_DIRS))); ./motorsport 2>stdout.log @echo "----------------------------------------------" -.PHONY: tags -tags: - ctags --c-types=+px **/*.[ch]pp - $(TARGET) :$(OBJECTS) $(LD) $(LD_FLAGS) $(patsubst %,-L%,$(LIBRARY_DIRS)) -o $@ $^ $(patsubst %,-l%,$(LIBRARIES)) @chmod +x $@ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <st...@us...> - 2006-05-14 19:22:54
|
Revision: 422 Author: stenyak Date: 2006-05-14 12:22:35 -0700 (Sun, 14 May 2006) ViewCVS: http://svn.sourceforge.net/motorsport/?rev=422&view=rev Log Message: ----------- Fixed double wishbone constructor: left suspension would not be properly created 50% of the times (due to an uninitialized bool variable). Fixed camera director enabling/disabling code (i think). Should always be disabled by pressing 'b' again. Modified Paths: -------------- trunk/src/main.cpp trunk/src/vehicle/suspension.cpp trunk/src/vehicle/suspension.hpp Modified: trunk/src/main.cpp =================================================================== --- trunk/src/main.cpp 2006-05-09 16:48:19 UTC (rev 421) +++ trunk/src/main.cpp 2006-05-14 19:22:35 UTC (rev 422) @@ -204,7 +204,8 @@ } if (systemData->axisMap[getIDKeyboardKey(SDLK_b)]->getValue() == 1) { - systemData->cameraDirector = !systemData->cameraDirector; + systemData->cameraDirector = !(systemData->cameraDirector); + systemData->axisMap[getIDKeyboardKey(SDLK_b)]->setNewRawValue(0); } } Modified: trunk/src/vehicle/suspension.cpp =================================================================== --- trunk/src/vehicle/suspension.cpp 2006-05-09 16:48:19 UTC (rev 421) +++ trunk/src/vehicle/suspension.cpp 2006-05-14 19:22:35 UTC (rev 422) @@ -275,14 +275,16 @@ springLengthAtEase = stod(tag->getAttribute("springLengthAtEase")); damperFastBump = stod(tag->getAttribute("damperFastBump")); damperFastRebound = stod(tag->getAttribute("damperFastRebound")); - springStiffness = stod(tag->getAttribute("springStiffness")); - springStiffness = stod(tag->getAttribute("springStiffness")); upperBoneOData.meshPath = tag->getAttribute("upperBoneMesh"); lowerBoneOData.meshPath = tag->getAttribute("lowerBoneMesh"); uprightBoneOData.meshPath = tag->getAttribute("uprightBoneMesh"); } + else + { + log->__format(LOG_ERROR, "Suspension was supposed to be a double wishbone suspension, but tag name is different!"); + } springOldx = springLengthAtEase; - if (firstPosition.y > 0) right = true; + right = (firstPosition.y > 0)? right : false; uprightBoneLength = 0.4; //-------------------------------------------- double dirMult = 1.0; Modified: trunk/src/vehicle/suspension.hpp =================================================================== --- trunk/src/vehicle/suspension.hpp 2006-05-09 16:48:19 UTC (rev 421) +++ trunk/src/vehicle/suspension.hpp 2006-05-14 19:22:35 UTC (rev 422) @@ -83,8 +83,6 @@ protected: Quaternion firstRotation; Vector3d firstPosition; - Vector3d getFirstLinkPosition (){return firstPosition;}; - Quaternion getFirstLinkRotation (){return firstRotation;}; double maxSteeringAngle; double getSteeringAngle(); bool right; @@ -106,6 +104,8 @@ double damperFastBump; double damperFastRebound; + Vector3d getFirstLinkPosition (){return firstPosition;}; + Quaternion getFirstLinkRotation (){return firstRotation;}; public: DoubleWishbone (WorldObject * container, XmlTag * tag); ~DoubleWishbone(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <st...@us...> - 2006-05-09 16:48:30
|
Revision: 421 Author: stenyak Date: 2006-05-09 09:48:19 -0700 (Tue, 09 May 2006) ViewCVS: http://svn.sourceforge.net/motorsport/?rev=421&view=rev Log Message: ----------- Removed a vim swap file that was unintentionally committed. Removed Paths: ------------- trunk/tools/blend2mosparea/mospland/export/.area.xml.swp Deleted: trunk/tools/blend2mosparea/mospland/export/.area.xml.swp =================================================================== (Binary files differ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |