From 09fc50948bff04e319dedc646c17e92be0f16ae5 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Thu, 25 Apr 2013 00:03:27 -0700 Subject: [PATCH] Add methods to disable and get info for a layer --- apps/openmw/mwrender/animation.cpp | 54 ++++++++++++++++++++++-------- apps/openmw/mwrender/animation.hpp | 16 ++++++++- 2 files changed, 55 insertions(+), 15 deletions(-) diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index 5838b1ff3..36fa1197d 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -225,6 +225,8 @@ void Animation::updateActiveControllers() break; } } + if(ctrls == NULL) + continue; /* Check if any objectlists are active on subsequent layers. Include * those layers if not. @@ -239,7 +241,6 @@ void Animation::updateActiveControllers() } } - assert(ctrls != NULL); std::vector >::const_iterator ctrl(ctrls->begin()); for(;ctrl != ctrls->end();ctrl++) { @@ -525,21 +526,9 @@ bool Animation::play(const std::string &groupname, const std::string &start, con bool movinganim = false; bool foundanim = false; - if(groupname.empty()) - { - // Do not allow layer 0 to be disabled - assert(layeridx != 0); - mLayer[layeridx].mGroupName.clear(); - mLayer[layeridx].mTextKeys = NULL; - mLayer[layeridx].mControllers = NULL; - mLayer[layeridx].mLoopCount = 0; - mLayer[layeridx].mPlaying = false; - - foundanim = true; - } /* Look in reverse; last-inserted source has priority. */ - else for(std::vector::reverse_iterator iter(mObjects.rbegin());iter != mObjects.rend();iter++) + for(std::vector::reverse_iterator iter(mObjects.rbegin());iter != mObjects.rend();iter++) { NifOgre::ObjectList &objlist = iter->mObjectList; if(objlist.mTextKeys.size() == 0) @@ -602,6 +591,43 @@ bool Animation::play(const std::string &groupname, const std::string &start, con return movinganim; } +void Animation::disable(size_t layeridx) +{ + if(mLayer[layeridx].mGroupName.empty()) + return; + + for(std::vector::iterator iter(mObjects.begin());iter != mObjects.end();iter++) + iter->mActiveLayers &= ~(1<first) / + (mLayer[layeridx].mStopKey->first - mLayer[layeridx].mStartKey->first); + if(groupname) *groupname = mLayer[layeridx].mGroupName; + if(start) *start = mLayer[layeridx].mStartKey->second.substr(mLayer[layeridx].mGroupName.size()+2); + if(stop) *stop = mLayer[layeridx].mStopKey->second.substr(mLayer[layeridx].mGroupName.size()+2); + return true; +} + + Ogre::Vector3 Animation::runAnimation(float duration) { Ogre::Vector3 movement(0.0f); diff --git a/apps/openmw/mwrender/animation.hpp b/apps/openmw/mwrender/animation.hpp index f349dd71f..4d342e0b1 100644 --- a/apps/openmw/mwrender/animation.hpp +++ b/apps/openmw/mwrender/animation.hpp @@ -141,8 +141,22 @@ public: */ bool play(const std::string &groupname, const std::string &start, const std::string &stop, float startpoint, size_t loops); - virtual Ogre::Vector3 runAnimation(float timepassed); + /** Stops and removes the animation from the given layer. */ + void disable(size_t layeridx); + /** Gets info about the given animation layer. + * \param layeridx Layer index to get info about. + * \param complete Stores completion amount (0 = at start key, 0.5 = half way between start and stop keys), etc. + * \param groupname Stores animation group being played. + * \param start Stores the start key + * \param stop Stores the stop key + * \return True if an animation is active on the layer, false otherwise. + */ + bool getInfo(size_t layeridx, float *complete=NULL, std::string *groupname=NULL, std::string *start=NULL, std::string *stop=NULL) const; + + virtual Ogre::Vector3 runAnimation(float duration); + + /* Returns if there's an animation playing on the given layer. */ bool isPlaying(size_t layeridx) const { return mLayer[layeridx].mPlaying; }