From 39cf7b0b42f32e98e9cb2864eb7361d30a4ad979 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Mon, 4 Feb 2013 11:17:48 -0800 Subject: [PATCH] Pass the Ptr of the object being moved to the move method This prevents having to store another copy of it, which risks getting out of sync. --- apps/openmw/mwmechanics/character.cpp | 8 +++----- apps/openmw/mwmechanics/movementsolver.cpp | 20 ++++++++++++++------ apps/openmw/mwmechanics/movementsolver.hpp | 22 +++++++++++++++------- 3 files changed, 32 insertions(+), 18 deletions(-) diff --git a/apps/openmw/mwmechanics/character.cpp b/apps/openmw/mwmechanics/character.cpp index 8eb0caf58a..b98a863ae2 100644 --- a/apps/openmw/mwmechanics/character.cpp +++ b/apps/openmw/mwmechanics/character.cpp @@ -79,7 +79,7 @@ static void getStateInfo(CharacterState state, std::string *group) CharacterController::CharacterController(const MWWorld::Ptr &ptr, MWRender::Animation *anim, CharacterState state, bool loop) : mPtr(ptr), mAnimation(anim), mState(state), mSkipAnim(false) { - mMovementSolver = new MovementSolver(mPtr); + mMovementSolver = new MovementSolver(); if(!mAnimation) return; @@ -98,7 +98,7 @@ CharacterController::CharacterController(const CharacterController &rhs) , mCurrentGroup(rhs.mCurrentGroup), mState(rhs.mState) , mSkipAnim(rhs.mSkipAnim) { - mMovementSolver = new MovementSolver(mPtr); + mMovementSolver = new MovementSolver(); if(!mAnimation) return; /* We've been copied. Update the animation with the new controller. */ @@ -191,10 +191,8 @@ Ogre::Vector3 CharacterController::update(float duration) Ogre::Quaternion(Ogre::Radian(-refpos.rot[2]), Ogre::Vector3::UNIT_Z)) * movement; - Ogre::Vector3 pos(refpos.pos); - // FIXME: Get the actual radius for the object. Maybe this should go into mwworld to replace pmove? - Ogre::Vector3 res = mMovementSolver->move(pos, movement, duration, Ogre::Vector3(15,15,30)); + Ogre::Vector3 res = mMovementSolver->move(mPtr, movement, duration, Ogre::Vector3(15,15,30)); MWBase::Environment::get().getWorld()->moveObject(mPtr, res.x, res.y, res.z); } diff --git a/apps/openmw/mwmechanics/movementsolver.cpp b/apps/openmw/mwmechanics/movementsolver.cpp index a758c76f34..4a7a59cb31 100644 --- a/apps/openmw/mwmechanics/movementsolver.cpp +++ b/apps/openmw/mwmechanics/movementsolver.cpp @@ -1,14 +1,20 @@ #include "movementsolver.hpp" +#include "libs/openengine/bullet/trace.h" +#include "libs/openengine/bullet/physic.hpp" + +#include "../mwworld/ptr.hpp" #include "../mwbase/environment.hpp" #include "../mwbase/world.hpp" +#include + + namespace MWMechanics { -MovementSolver::MovementSolver(const MWWorld::Ptr &ptr) - : mPtr(ptr) - , mEngine(MWBase::Environment::get().getWorld()->getPhysicEngine()) +MovementSolver::MovementSolver() + : mEngine(MWBase::Environment::get().getWorld()->getPhysicEngine()) , verticalVelocity(0.0f) { } @@ -70,10 +76,12 @@ float MovementSolver::getSlope(const Ogre::Vector3 &normal) } -Ogre::Vector3 MovementSolver::move(const Ogre::Vector3 &position, const Ogre::Vector3 &movement, float time, const Ogre::Vector3 &halfExtents) +Ogre::Vector3 MovementSolver::move(const MWWorld::Ptr &ptr, const Ogre::Vector3 &movement, float time, const Ogre::Vector3 &halfExtents) { + Ogre::Vector3 position(ptr.getRefData().getPosition().pos); + /* Anything to collide with? */ - mPhysicActor = mEngine->getCharacter(mPtr.getRefData().getHandle()); + mPhysicActor = mEngine->getCharacter(ptr.getRefData().getHandle()); if(!mPhysicActor || !mPhysicActor->getCollisionMode()) return position + movement; @@ -86,7 +94,7 @@ Ogre::Vector3 MovementSolver::move(const Ogre::Vector3 &position, const Ogre::Ve Ogre::Vector3 clippedVelocity(horizontalVelocity.x, horizontalVelocity.y, verticalVelocity); float remainingTime = time; - bool isInterior = !mPtr.getCell()->isExterior(); + bool isInterior = !ptr.getCell()->isExterior(); float verticalRotation = mPhysicActor->getRotation().getYaw().valueDegrees(); Ogre::Vector3 lastNormal(0.0f); diff --git a/apps/openmw/mwmechanics/movementsolver.hpp b/apps/openmw/mwmechanics/movementsolver.hpp index 8bd05fa15e..450bc055ed 100644 --- a/apps/openmw/mwmechanics/movementsolver.hpp +++ b/apps/openmw/mwmechanics/movementsolver.hpp @@ -1,22 +1,31 @@ #ifndef GAME_MWMECHANICS_MOVEMENTSOLVER_H #define GAME_MWMECHANICS_MOVEMENTSOLVER_H -#include "libs/openengine/bullet/trace.h" -#include "libs/openengine/bullet/physic.hpp" +#include -#include "../mwworld/ptr.hpp" +namespace MWWorld +{ + class Ptr; +} -#include +namespace OEngine +{ + namespace Physic + { + class PhysicEngine; + class PhysicActor; + } +} namespace MWMechanics { class MovementSolver { public: - MovementSolver(const MWWorld::Ptr &ptr); + MovementSolver(); virtual ~MovementSolver(); - Ogre::Vector3 move(const Ogre::Vector3 &position, const Ogre::Vector3 &movement, float time, const Ogre::Vector3 &halfExtents); + Ogre::Vector3 move(const MWWorld::Ptr &ptr, const Ogre::Vector3 &movement, float time, const Ogre::Vector3 &halfExtents); private: bool stepMove(Ogre::Vector3& position, const Ogre::Vector3 &velocity, float remainingTime, float verticalRotation, const Ogre::Vector3 &halfExtents, bool isInterior); @@ -26,7 +35,6 @@ namespace MWMechanics float getSlope(const Ogre::Vector3 &normal); - MWWorld::Ptr mPtr; OEngine::Physic::PhysicEngine *mEngine; OEngine::Physic::PhysicActor *mPhysicActor;