diff --git a/apps/openmw/mwmechanics/actors.cpp b/apps/openmw/mwmechanics/actors.cpp index 27b7ad14e9..2466b8a864 100644 --- a/apps/openmw/mwmechanics/actors.cpp +++ b/apps/openmw/mwmechanics/actors.cpp @@ -211,8 +211,7 @@ namespace MWMechanics float totalDuration = mDuration; mDuration = 0; - PtrControllerMap::iterator iter(mActors.begin()); - while(iter != mActors.end()) + for(PtrControllerMap::iterator iter(mActors.begin());iter != mActors.end();iter++) { if(!MWWorld::Class::get(iter->first).getCreatureStats(iter->first).isDead()) { @@ -224,10 +223,7 @@ namespace MWMechanics updateNpc(iter->first, totalDuration, paused); if(!MWWorld::Class::get(iter->first).getCreatureStats(iter->first).isDead()) - { - iter++; continue; - } } // workaround: always keep player alive for now @@ -244,18 +240,14 @@ namespace MWMechanics } MWWorld::Class::get(iter->first).getCreatureStats(iter->first).resurrect(); - ++iter; continue; } if(iter->second.getState() == CharState_Dead) - { - iter++; continue; - } + iter->second.setMovementVector(Ogre::Vector3::ZERO); iter->second.setState(CharState_Dead, false); - iter->second.setDirection(Ogre::Vector3::ZERO); ++mDeathCount[MWWorld::Class::get(iter->first).getId(iter->first)]; @@ -272,26 +264,8 @@ namespace MWMechanics if(iter->second.getState() == CharState_Dead) continue; - Ogre::Vector3 dir = MWWorld::Class::get(iter->first).getMovementVector(iter->first); - CharacterState newstate = CharState_Idle; - - if(dir.length() >= 0.1f) - { - if(std::abs(dir.x/2.0f) > std::abs(dir.y)) - { - if(dir.x > 0.0f) - newstate = CharState_WalkRight; - else if(dir.x < 0.0f) - newstate = CharState_WalkLeft; - } - else if(dir.y < 0.0f) - newstate = CharState_WalkBack; - else - newstate = CharState_WalkForward; - } - - iter->second.setState(newstate, true); - iter->second.setDirection(dir); + Ogre::Vector3 movement = MWWorld::Class::get(iter->first).getMovementVector(iter->first); + iter->second.setMovementVector(movement); } std::vector > movement; diff --git a/apps/openmw/mwmechanics/character.cpp b/apps/openmw/mwmechanics/character.cpp index 6e78adfa4f..677ffcf239 100644 --- a/apps/openmw/mwmechanics/character.cpp +++ b/apps/openmw/mwmechanics/character.cpp @@ -127,14 +127,31 @@ void CharacterController::markerEvent(float time, const std::string &evt) } -void CharacterController::setDirection(const Ogre::Vector3 &dir) +void CharacterController::setMovementVector(const Ogre::Vector3 &vec) { - // HACK: The direction length we get is too large. - float mult = dir.length() / 32.0f; - mult = std::max(1.0f, mult); + // HACK: The length we get is too large. + float speed = std::max(1.0f, vec.length() / 32.0f); + + if(vec.length() >= 0.1f) + { + if(std::abs(vec.x/2.0f) > std::abs(vec.y)) + { + if(vec.x > 0.0f) + setState(CharState_WalkRight, true); + else if(vec.x < 0.0f) + setState(CharState_WalkLeft, true); + } + else if(vec.y < 0.0f) + setState(CharState_WalkBack, true); + else + setState(CharState_WalkForward, true); + } + else + setState(CharState_Idle, true); + if(mAnimation) - mAnimation->setSpeedMult(mult); - mDirection = dir.normalisedCopy(); + mAnimation->setSpeedMult(speed); + mDirection = vec.normalisedCopy(); } diff --git a/apps/openmw/mwmechanics/character.hpp b/apps/openmw/mwmechanics/character.hpp index 53349c841e..e5c7a4b8c0 100644 --- a/apps/openmw/mwmechanics/character.hpp +++ b/apps/openmw/mwmechanics/character.hpp @@ -53,7 +53,7 @@ public: void playGroup(const std::string &groupname, int mode, int count); void skipAnim(); - void setDirection(const Ogre::Vector3 &dir); + void setMovementVector(const Ogre::Vector3 &vec); void setState(CharacterState state, bool loop); CharacterState getState() const