From 8e59ea494171740fb7b80d0e8f87ee7a24536f77 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sat, 23 Feb 2013 14:39:01 -0800 Subject: [PATCH] Use a separate method to handle animation events --- apps/openmw/mwrender/animation.cpp | 92 ++++++++++++++++-------------- apps/openmw/mwrender/animation.hpp | 2 + 2 files changed, 52 insertions(+), 42 deletions(-) diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index f453e6a740..394e25b504 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -346,6 +346,54 @@ void Animation::reset(const std::string &start, const std::string &stop) } +bool Animation::handleEvent(float time, const std::string &evt) +{ + if(evt == "start" || evt == "loop start") + { + /* Do nothing */ + return true; + } + + if(evt.compare(0, 7, "sound: ") == 0) + { + MWBase::SoundManager *sndMgr = MWBase::Environment::get().getSoundManager(); + sndMgr->playSound3D(mPtr, evt.substr(7), 1.0f, 1.0f); + return true; + } + if(evt.compare(0, 10, "soundgen: ") == 0) + { + // FIXME: Lookup the SoundGen (SNDG) for the specified sound that corresponds + // to this actor type + return true; + } + + if(evt == "loop stop") + { + if(mLooping) + { + reset("loop start", ""); + if(mCurrentTime >= time) + return false; + } + return true; + } + if(evt == "stop") + { + if(mLooping) + { + reset("loop start", ""); + if(mCurrentTime >= time) + return false; + return true; + } + // fall-through + } + if(mController) + mController->markerEvent(time, evt); + return true; +} + + void Animation::play(const std::string &groupname, const std::string &start, const std::string &stop, bool loop) { try { @@ -402,48 +450,8 @@ Ogre::Vector3 Animation::runAnimation(float timepassed) timepassed = targetTime - time; - if(evt == "start" || evt == "loop start") - { - /* Do nothing */ - continue; - } - - if(evt.compare(0, 7, "sound: ") == 0) - { - MWBase::SoundManager *sndMgr = MWBase::Environment::get().getSoundManager(); - sndMgr->playSound3D(mPtr, evt.substr(7), 1.0f, 1.0f); - continue; - } - if(evt.compare(0, 10, "soundgen: ") == 0) - { - // FIXME: Lookup the SoundGen (SNDG) for the specified sound that corresponds - // to this actor type - continue; - } - - if(evt == "loop stop") - { - if(mLooping) - { - reset("loop start", ""); - if(mCurrentTime >= time) - break; - } - continue; - } - if(evt == "stop") - { - if(mLooping) - { - reset("loop start", ""); - if(mCurrentTime >= time) - break; - continue; - } - // fall-through - } - if(mController) - mController->markerEvent(time, evt); + if(!handleEvent(time, evt)) + break; } return movement; diff --git a/apps/openmw/mwrender/animation.hpp b/apps/openmw/mwrender/animation.hpp index b8323cb895..810ca869f5 100644 --- a/apps/openmw/mwrender/animation.hpp +++ b/apps/openmw/mwrender/animation.hpp @@ -59,6 +59,8 @@ protected: */ void reset(const std::string &start, const std::string &stop); + bool handleEvent(float time, const std::string &evt); + /* Specifies a list of skeleton names to use as animation sources. */ void setAnimationSources(const std::vector &names);