diff --git a/apps/openmw/mwmechanics/character.cpp b/apps/openmw/mwmechanics/character.cpp index 4679cdadf..6a97dcfef 100644 --- a/apps/openmw/mwmechanics/character.cpp +++ b/apps/openmw/mwmechanics/character.cpp @@ -338,18 +338,20 @@ void CharacterController::update(float duration, Movement &movement) else if(rot.z < 0.0f) setState(CharState_TurnLeft, true); } - else if(getState() != CharState_SpecialIdle) + else if(mAnimQueue.size() > 0) { - if(mAnimQueue.size() == 0) - setState((inwater ? CharState_IdleSwim : (sneak ? CharState_IdleSneak : CharState_Idle)), true); - else + if(mAnimation->isPlaying(mAnimQueue.front().first) == false) { - mAnimation->play(mAnimQueue.front().first, MWRender::Animation::Priority_Default, - MWRender::Animation::Group_All, false, - "start", "stop", 0.0f, mAnimQueue.front().second); mAnimQueue.pop_front(); + if(mAnimQueue.size() > 0) + mAnimation->play(mAnimQueue.front().first, + MWRender::Animation::Priority_Default, + MWRender::Animation::Group_All, false, + "start", "stop", 0.0f, mAnimQueue.front().second); } } + else if(getState() != CharState_SpecialIdle) + setState((inwater ? CharState_IdleSwim : (sneak ? CharState_IdleSneak : CharState_Idle)), true); movement.mRotation[0] += rot.x * duration; movement.mRotation[1] += rot.y * duration; @@ -387,9 +389,11 @@ void CharacterController::playGroup(const std::string &groupname, int mode, int else { count = std::max(count, 1); - if(mode != 0 || getState() != CharState_SpecialIdle) + if(mode != 0 || mAnimQueue.size() == 0) { mAnimQueue.clear(); + mAnimQueue.push_back(std::make_pair(groupname, count-1)); + mCharState = CharState_SpecialIdle; mLooping = false; mAnimation->play(groupname, MWRender::Animation::Priority_Default, @@ -398,7 +402,7 @@ void CharacterController::playGroup(const std::string &groupname, int mode, int } else if(mode == 0) { - mAnimQueue.clear(); + mAnimQueue.resize(1); mAnimQueue.push_back(std::make_pair(groupname, count-1)); } } diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index 972410903..7ca7c5d7a 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -531,6 +531,14 @@ void Animation::play(const std::string &groupname, Priority priority, int groups resetActiveGroups(); } +bool Animation::isPlaying(const std::string &groupname) const +{ + AnimStateMap::const_iterator state(mStates.find(groupname)); + if(state != mStates.end()) + return state->second.mPlaying; + return false; +} + void Animation::resetActiveGroups() { for(size_t grp = 0;grp < sNumGroups;grp++) diff --git a/apps/openmw/mwrender/animation.hpp b/apps/openmw/mwrender/animation.hpp index 117a30d2a..d03e72df3 100644 --- a/apps/openmw/mwrender/animation.hpp +++ b/apps/openmw/mwrender/animation.hpp @@ -177,6 +177,9 @@ public: const std::string &start, const std::string &stop, float startpoint, size_t loops); + /** Returns true if the named animation group is playing. */ + bool isPlaying(const std::string &groupname) const; + /** Gets info about the given animation group. * \param groupname Animation group to check. * \param complete Stores completion amount (0 = at start key, 0.5 = half way between start and stop keys), etc.