From 5c3a7f7d523192c95380f9ec92e51ea25eb09213 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Wed, 30 Jan 2013 07:34:07 -0800 Subject: [PATCH] Avoid handling animation states We don't need them anymore --- apps/openmw/mwrender/animation.cpp | 41 ++++++++++++++++-------------- apps/openmw/mwrender/animation.hpp | 4 ++- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index 03bc92e96..73780a7f0 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -25,8 +25,10 @@ Animation::Animation(const MWWorld::Ptr &ptr) , mStartPosition(0.0f) , mLastPosition(0.0f) , mCurrentKeys(NULL) - , mAnimState(NULL) + , mCurrentAnim(NULL) + , mCurrentTime(0.0f) , mPlaying(false) + , mLooping(false) , mAnimSpeedMult(1.0f) { } @@ -106,7 +108,7 @@ void Animation::createEntityList(Ogre::SceneNode *node, const std::string &model bool Animation::hasAnimation(const std::string &anim) { - return mEntityList.mSkelBase && mEntityList.mSkelBase->hasAnimationState(anim); + return mEntityList.mSkelBase && mEntityList.mSkelBase->getSkeleton()->hasAnimation(anim); } @@ -147,9 +149,11 @@ void Animation::applyAnimation(const Ogre::Animation *anim, float time, Ogre::Sk Ogre::Vector3 Animation::updatePosition(float time) { - Ogre::SkeletonInstance *skel = mEntityList.mSkelBase->getSkeleton(); - mAnimState->setTimePosition(time); - applyAnimation(skel->getAnimation(mAnimState->getAnimationName()), mAnimState->getTimePosition(), skel); + if(mLooping) + mCurrentTime = std::fmod(std::max(time, 0.0f), mCurrentAnim->getLength()); + else + mCurrentTime = std::min(mCurrentAnim->getLength(), std::max(time, 0.0f)); + applyAnimation(mCurrentAnim, mCurrentTime, mEntityList.mSkelBase->getSkeleton()); Ogre::Vector3 posdiff = Ogre::Vector3::ZERO; if(mNonAccumRoot) @@ -170,15 +174,14 @@ void Animation::reset(const std::string &marker) while(mNextKey != mCurrentKeys->end() && mNextKey->second != marker) mNextKey++; - Ogre::SkeletonInstance *skel = mEntityList.mSkelBase->getSkeleton(); if(mNextKey != mCurrentKeys->end()) - mAnimState->setTimePosition(mNextKey->first); + mCurrentTime = mNextKey->first; else { mNextKey = mCurrentKeys->begin(); - mAnimState->setTimePosition(0.0f); + mCurrentTime = 0.0f; } - applyAnimation(skel->getAnimation(mAnimState->getAnimationName()), mAnimState->getTimePosition(), skel); + applyAnimation(mCurrentAnim, mCurrentTime, mEntityList.mSkelBase->getSkeleton()); if(mNonAccumRoot) { @@ -191,12 +194,12 @@ void Animation::reset(const std::string &marker) void Animation::play(const std::string &groupname, const std::string &start, bool loop) { try { - mAnimState = mEntityList.mSkelBase->getAnimationState(groupname); - mAnimState->setLoop(loop); - + mCurrentAnim = mEntityList.mSkelBase->getSkeleton()->getAnimation(groupname); mCurrentKeys = &mTextKeys[groupname]; + reset(start); mPlaying = true; + mLooping = loop; } catch(std::exception &e) { std::cerr<< e.what() < 0.0f) + while(mCurrentAnim && mPlaying && timepassed > 0.0f) { - float targetTime = mAnimState->getTimePosition() + timepassed; + float targetTime = mCurrentTime + timepassed; if(mNextKey == mCurrentKeys->end() || mNextKey->first > targetTime) { movement += updatePosition(targetTime); - mPlaying = (mAnimState->getLoop() || mAnimState->getLength() >= targetTime); + mPlaying = (mLooping || mCurrentAnim->getLength() >= targetTime); break; } @@ -232,20 +235,20 @@ Ogre::Vector3 Animation::runAnimation(float timepassed) } if(evt == "loop stop") { - if(mAnimState->getLoop()) + if(mLooping) { reset("loop start"); - if(mAnimState->getTimePosition() >= time) + if(mCurrentTime >= time) break; } continue; } if(evt == "stop") { - if(mAnimState->getLoop()) + if(mLooping) { reset("loop start"); - if(mAnimState->getTimePosition() >= time) + if(mCurrentTime >= time) break; } else diff --git a/apps/openmw/mwrender/animation.hpp b/apps/openmw/mwrender/animation.hpp index c281551c7..886d967ab 100644 --- a/apps/openmw/mwrender/animation.hpp +++ b/apps/openmw/mwrender/animation.hpp @@ -30,8 +30,10 @@ protected: NifOgre::TextKeyMap *mCurrentKeys; NifOgre::TextKeyMap::const_iterator mNextKey; - Ogre::AnimationState *mAnimState; + Ogre::Animation *mCurrentAnim; + float mCurrentTime; bool mPlaying; + bool mLooping; float mAnimSpeedMult;