From 05f8b8c28383dd21eb60d1042a0ba353c6503830 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Tue, 22 Jan 2013 00:31:45 -0800 Subject: [PATCH] Specify the text key to reset animations to --- apps/openmw/mwrender/animation.cpp | 45 ++++++++++-------------------- apps/openmw/mwrender/animation.hpp | 6 ++-- 2 files changed, 17 insertions(+), 34 deletions(-) diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index 45f7ab2e44..5a5761faa3 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -134,14 +134,20 @@ Ogre::Vector3 Animation::updatePosition(float time) return posdiff; } -void Animation::resetPosition(float time) +void Animation::reset(const std::string &marker) { - mAnimState->setTimePosition(time); - mNextKey = mCurrentKeys->begin(); - while(mNextKey != mCurrentKeys->end() && mNextKey->first < time) + while(mNextKey != mCurrentKeys->end() && mNextKey->second != marker) mNextKey++; + if(mNextKey != mCurrentKeys->end()) + mAnimState->setTimePosition(mNextKey->first); + else + { + mNextKey = mCurrentKeys->begin(); + mAnimState->setTimePosition(0.0f); + } + if(mNonAccumRoot) { mEntityList.mSkelBase->getSkeleton()->setAnimationState(*mAnimState->getParent()); @@ -151,29 +157,6 @@ void Animation::resetPosition(float time) } -float Animation::findStart(const std::string &groupname, const std::string &start) -{ - mNextKey = mCurrentKeys->end(); - if(mCurrentKeys->size() == 0) - return 0.0f; - - if(groupname == "all") - { - mNextKey = mCurrentKeys->begin(); - return 0.0f; - } - - std::string startmarker = groupname+": "+start; - NifOgre::TextKeyMap::const_iterator iter; - for(iter = mCurrentKeys->begin();iter != mCurrentKeys->end();iter++) - { - if(iter->second == startmarker) - return iter->first; - } - return 0.0f; -} - - void Animation::play(const std::string &groupname, const std::string &start, bool loop) { try { @@ -181,10 +164,10 @@ void Animation::play(const std::string &groupname, const std::string &start, boo mAnimState->setEnabled(false); mAnimState = mEntityList.mSkelBase->getAnimationState(groupname); mAnimState->setEnabled(true); + mCurrentKeys = &mTextKeys[groupname]; mLooping = loop; - - resetPosition(findStart(groupname, start)); + reset(start); } catch(std::exception &e) { std::cerr<< e.what() <getAnimationName(), "loop start")); + reset("loop start"); if(mAnimState->getTimePosition() >= time) break; } @@ -230,7 +213,7 @@ Ogre::Vector3 Animation::runAnimation(float timepassed) { if(mLooping) { - resetPosition(findStart(mAnimState->getAnimationName(), "loop start")); + reset("loop start"); if(mAnimState->getTimePosition() >= time) break; } diff --git a/apps/openmw/mwrender/animation.hpp b/apps/openmw/mwrender/animation.hpp index 8398135764..ed9c6eb192 100644 --- a/apps/openmw/mwrender/animation.hpp +++ b/apps/openmw/mwrender/animation.hpp @@ -38,10 +38,10 @@ protected: /* Updates the animation to the specified time, and returns the movement * vector since the last update or reset. */ Ogre::Vector3 updatePosition(float time); - /* Updates the animation to the specified time, without moving anything. */ - void resetPosition(float time); - float findStart(const std::string &groupname, const std::string &start); + /* Resets the animation to the time of the specified marker, without moving + * anything. If the marker is not found, it resets to the beginning. */ + void reset(const std::string &marker); void createEntityList(Ogre::SceneNode *node, const std::string &model);