diff --git a/apps/openmw/mwmechanics/character.cpp b/apps/openmw/mwmechanics/character.cpp index 262945c024..ea934a2841 100644 --- a/apps/openmw/mwmechanics/character.cpp +++ b/apps/openmw/mwmechanics/character.cpp @@ -65,29 +65,24 @@ static void getStateInfo(CharacterState state, std::string *group, Ogre::Vector3 CharacterController::CharacterController(const MWWorld::Ptr &ptr, MWRender::Animation *anim, CharacterState state, bool loop) : mPtr(ptr), mAnimation(anim), mDirection(Ogre::Vector3::ZERO), mState(state), mSkipAnim(false), mLoop(loop) { - if(mAnimation) - mAnimNames = mAnimation->getAnimationNames(); - if(mAnimNames.size() == 0) - { - mAnimation = NULL; + if(!mAnimation) return; - } mAnimation->setController(this); Ogre::Vector3 accum; getStateInfo(mState, &mCurrentGroup, &accum); mAnimation->setAccumulation(accum); - mAnimation->play(mCurrentGroup, "stop"); + if(mAnimation->hasAnimation(mCurrentGroup)) + mAnimation->play(mCurrentGroup, "stop"); } CharacterController::CharacterController(const CharacterController &rhs) - : mPtr(rhs.mPtr), mAnimation(rhs.mAnimation), mAnimNames(rhs.mAnimNames) - , mAnimQueue(rhs.mAnimQueue), mCurrentGroup(rhs.mCurrentGroup) - , mDirection(rhs.mDirection), mState(rhs.mState), mSkipAnim(rhs.mSkipAnim) - , mLoop(rhs.mLoop) + : mPtr(rhs.mPtr), mAnimation(rhs.mAnimation), mAnimQueue(rhs.mAnimQueue) + , mCurrentGroup(rhs.mCurrentGroup), mDirection(rhs.mDirection) + , mState(rhs.mState), mSkipAnim(rhs.mSkipAnim), mLoop(rhs.mLoop) { - if(mAnimNames.size() == 0) + if(!mAnimation) return; /* We've been copied. Update the animation with the new controller. */ mAnimation->setController(this); @@ -186,7 +181,7 @@ Ogre::Vector3 CharacterController::update(float duration) void CharacterController::playGroup(const std::string &groupname, int mode, int count) { - if(std::find(mAnimNames.begin(), mAnimNames.end(), groupname) != mAnimNames.end()) + if(mAnimation && mAnimation->hasAnimation(groupname)) { count = std::max(count, 1); if(mode != 0 || mAnimQueue.size() == 0) @@ -230,14 +225,19 @@ void CharacterController::setState(CharacterState state, bool loop) mLoop = loop; } - if(mAnimNames.size() == 0) + if(!mAnimation) return; mAnimQueue.clear(); + std::string anim; Ogre::Vector3 accum; - getStateInfo(mState, &mCurrentGroup, &accum); - mAnimation->setAccumulation(accum); - mAnimation->play(mCurrentGroup, "start"); + getStateInfo(mState, &anim, &accum); + if(mAnimation->hasAnimation(anim)) + { + mCurrentGroup = anim; + mAnimation->setAccumulation(accum); + mAnimation->play(mCurrentGroup, "start"); + } } } diff --git a/apps/openmw/mwmechanics/character.hpp b/apps/openmw/mwmechanics/character.hpp index 6d8b3386c1..43ff21dfb2 100644 --- a/apps/openmw/mwmechanics/character.hpp +++ b/apps/openmw/mwmechanics/character.hpp @@ -30,8 +30,6 @@ class CharacterController MWWorld::Ptr mPtr; MWRender::Animation *mAnimation; - std::vector mAnimNames; - typedef std::deque AnimationQueue; AnimationQueue mAnimQueue; diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index a86e14c83b..67be0bf0c5 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -100,17 +100,9 @@ void Animation::createEntityList(Ogre::SceneNode *node, const std::string &model } -std::vector Animation::getAnimationNames() +bool Animation::hasAnimation(const std::string &anim) { - std::vector anims; - if(mEntityList.mSkelBase) - { - Ogre::AnimationStateSet *as = mEntityList.mSkelBase->getAllAnimationStates(); - Ogre::AnimationStateIterator ai = as->getAnimationStateIterator(); - while(ai.hasMoreElements()) - anims.push_back(ai.getNext()->getAnimationName()); - } - return anims; + return mEntityList.mSkelBase && mEntityList.mSkelBase->hasAnimationState(anim); } @@ -188,13 +180,9 @@ float Animation::findStart(const std::string &groupname, const std::string &star void Animation::play(const std::string &groupname, const std::string &start) { try { - if(!mEntityList.mSkelBase) - throw std::runtime_error("Attempting to animate an inanimate object"); - - Ogre::AnimationState *newstate = mEntityList.mSkelBase->getAnimationState(groupname); if(mAnimState) mAnimState->setEnabled(false); - mAnimState = newstate; + mAnimState = mEntityList.mSkelBase->getAnimationState(groupname); mAnimState->setEnabled(true); mCurrentKeys = &mTextKeys[groupname]; diff --git a/apps/openmw/mwrender/animation.hpp b/apps/openmw/mwrender/animation.hpp index 6c8357d59e..50ddc34d5c 100644 --- a/apps/openmw/mwrender/animation.hpp +++ b/apps/openmw/mwrender/animation.hpp @@ -48,7 +48,8 @@ public: virtual ~Animation(); void setController(MWMechanics::CharacterController *controller); - std::vector getAnimationNames(); + + bool hasAnimation(const std::string &anim); // Specifies the axis' to accumulate on. Non-accumulated axis will just // move visually, but not affect the actual movement. Each x/y/z value