1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-25 06:35:30 +00:00

Use a separate method to handle animation events

This commit is contained in:
Chris Robinson 2013-02-23 14:39:01 -08:00
parent d77d035d3a
commit 8e59ea4941
2 changed files with 52 additions and 42 deletions

View File

@ -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;

View File

@ -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<std::string> &names);