Make gnu stop playing flute when he's abducted

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@11449 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria 2012-07-29 19:16:59 +00:00
parent 1ae417fcb2
commit 5f0f8e0346
4 changed files with 55 additions and 5 deletions

View File

@ -91,6 +91,21 @@ void CutsceneWorld::init()
float FPS = 25.0f; // for now we assume the cutscene is saved at 25 FPS
m_sounds_to_trigger[frame / FPS].push_back(curr);
}
else if (StringUtils::startsWith(condition, "until "))
{
std::string frameStr = condition.substr(6); // remove 'until ' prefix
int frame;
if (!StringUtils::fromString(frameStr, frame))
{
fprintf(stderr, "[CutsceneWorld] Invalid condition '%s'\n", condition.c_str());
continue;
}
float FPS = 25.0f; // for now we assume the cutscene is saved at 25 FPS
m_sounds_to_stop[frame / FPS].push_back(curr);
curr->triggerSound(true);
}
}
if (dynamic_cast<AnimationBase*>(curr) != NULL)
@ -212,6 +227,24 @@ void CutsceneWorld::update(float dt)
it++;
}
}
for (std::map<float, std::vector<TrackObject*> >::iterator it = m_sounds_to_stop.begin();
it != m_sounds_to_stop.end(); )
{
if (m_time >= it->first)
{
std::vector<TrackObject*> objects = it->second;
for (unsigned int i = 0; i < objects.size(); i++)
{
objects[i]->stopSound();
}
m_sounds_to_stop.erase(it++);
}
else
{
it++;
}
}
} // update
//-----------------------------------------------------------------------------

View File

@ -39,7 +39,8 @@ class CutsceneWorld : public World
scene::ICameraSceneNode* m_camera;
std::map<float, std::vector<TrackObject*> > m_sounds_to_trigger;
std::map<float, std::vector<TrackObject*> > m_sounds_to_stop;
float m_duration;
void abortCutscene()

View File

@ -456,7 +456,22 @@ void TrackObject::onTriggerItemApproached(Item* who)
// ----------------------------------------------------------------------------
/** if this is a sound object, play the object */
void TrackObject::triggerSound()
void TrackObject::triggerSound(bool loop)
{
if (m_sound != NULL) m_sound->play();
}
if (m_sound != NULL)
{
m_sound->setLoop(loop);
m_sound->play();
}
}
// ----------------------------------------------------------------------------
/** if this is a sound object, stop the object */
void TrackObject::stopSound()
{
if (m_sound != NULL) m_sound->stop();
}
// ----------------------------------------------------------------------------

View File

@ -154,7 +154,8 @@ public:
/** Currently used for sound effects only, in cutscenes only atm */
const std::string& getTriggerCondition() const { return m_trigger_condition; }
void triggerSound();
void triggerSound(bool loop=false);
void stopSound();
virtual void onTriggerItemApproached(Item* who);