From 0a2f92f67901c06c80d9750cf40b197fd173a51d Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Wed, 16 Jan 2013 11:57:08 -0800 Subject: [PATCH] Keep track of the current text key in the animation --- apps/openmw/mwrender/animation.cpp | 27 +++++++++++++++++++++++++-- apps/openmw/mwrender/animation.hpp | 7 +++++-- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index 4f32de3647..69bd01e2bb 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -130,6 +130,11 @@ void Animation::updatePosition(float time) void Animation::resetPosition(float time) { mCurGroup.mAnimState->setTimePosition(time); + + mCurGroup.mNext = mCurGroup.mStart; + while(mCurGroup.mNext->first < time) + mCurGroup.mNext++; + if(mNonAccumRoot) { mEntityList.mSkelBase->getSkeleton()->setAnimationState(*mCurGroup.mAnimState->getParent()); @@ -141,7 +146,8 @@ void Animation::resetPosition(float time) bool Animation::findGroupTimes(const std::string &groupname, Animation::GroupTimes *times) { - const NifOgre::TextKeyMap &textkeys = mTextKeys[groupname]; + times->mTextKeys = &mTextKeys[groupname]; + const NifOgre::TextKeyMap &textkeys = *times->mTextKeys; if(textkeys.size() == 0) return false; @@ -202,6 +208,7 @@ void Animation::playGroup(std::string groupname, int mode, int loops) std::cerr<< e.what() < 0) mNextGroup = times; @@ -211,7 +218,7 @@ void Animation::playGroup(std::string groupname, int mode, int loops) mCurGroup.mAnimState->setEnabled(false); mCurGroup = times; mNextGroup = GroupTimes(); - mTime = ((mode==2) ? mCurGroup.mLoopStart : mCurGroup.mStart)->first; + mTime = mCurGroup.mNext->first; mCurGroup.mAnimState->setEnabled(true); resetPosition(mTime); } @@ -230,6 +237,12 @@ void Animation::runAnimation(float timepassed) recheck: if(mTime >= mCurGroup.mLoopStop->first) { + while(mCurGroup.mNext != mCurGroup.mTextKeys->end() && + mCurGroup.mNext->first <= mCurGroup.mLoopStop->first) + { + mCurGroup.mNext++; + } + if(mCurGroup.mLoops > 1) { mCurGroup.mLoops--; @@ -240,6 +253,11 @@ void Animation::runAnimation(float timepassed) } else if(mTime >= mCurGroup.mStop->first) { + while(mCurGroup.mNext != mCurGroup.mTextKeys->end() && + mCurGroup.mNext->first <= mCurGroup.mStop->first) + { + mCurGroup.mNext++; + } if(mNextGroup.mLoops > 0) { updatePosition(mCurGroup.mStop->first); @@ -254,6 +272,11 @@ void Animation::runAnimation(float timepassed) mTime = mCurGroup.mStop->first; } } + while(mCurGroup.mNext != mCurGroup.mTextKeys->end() && + mCurGroup.mNext->first <= mTime) + { + mCurGroup.mNext++; + } updatePosition(mTime); } diff --git a/apps/openmw/mwrender/animation.hpp b/apps/openmw/mwrender/animation.hpp index ed9e4f5855..43cce0c028 100644 --- a/apps/openmw/mwrender/animation.hpp +++ b/apps/openmw/mwrender/animation.hpp @@ -16,16 +16,19 @@ namespace MWRender class Animation { struct GroupTimes { + NifOgre::TextKeyMap *mTextKeys; + NifOgre::TextKeyMap::const_iterator mStart; NifOgre::TextKeyMap::const_iterator mStop; NifOgre::TextKeyMap::const_iterator mLoopStart; NifOgre::TextKeyMap::const_iterator mLoopStop; + NifOgre::TextKeyMap::const_iterator mNext; + Ogre::AnimationState *mAnimState; size_t mLoops; - GroupTimes() - : mAnimState(NULL), mLoops(0) + GroupTimes() : mTextKeys(NULL), mAnimState(NULL), mLoops(0) { } };