From 5f0f8e03467cf4f1307788b368d8433f248275db Mon Sep 17 00:00:00 2001 From: auria Date: Sun, 29 Jul 2012 19:16:59 +0000 Subject: [PATCH] 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 --- src/modes/cutscene_world.cpp | 33 +++++++++++++++++++++++++++++++++ src/modes/cutscene_world.hpp | 3 ++- src/tracks/track_object.cpp | 21 ++++++++++++++++++--- src/tracks/track_object.hpp | 3 ++- 4 files changed, 55 insertions(+), 5 deletions(-) diff --git a/src/modes/cutscene_world.cpp b/src/modes/cutscene_world.cpp index ebd7bd80e..1dec98380 100644 --- a/src/modes/cutscene_world.cpp +++ b/src/modes/cutscene_world.cpp @@ -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(curr) != NULL) @@ -212,6 +227,24 @@ void CutsceneWorld::update(float dt) it++; } } + + for (std::map >::iterator it = m_sounds_to_stop.begin(); + it != m_sounds_to_stop.end(); ) + { + if (m_time >= it->first) + { + std::vector objects = it->second; + for (unsigned int i = 0; i < objects.size(); i++) + { + objects[i]->stopSound(); + } + m_sounds_to_stop.erase(it++); + } + else + { + it++; + } + } } // update //----------------------------------------------------------------------------- diff --git a/src/modes/cutscene_world.hpp b/src/modes/cutscene_world.hpp index 17aeeeba9..4619b2d45 100644 --- a/src/modes/cutscene_world.hpp +++ b/src/modes/cutscene_world.hpp @@ -39,7 +39,8 @@ class CutsceneWorld : public World scene::ICameraSceneNode* m_camera; std::map > m_sounds_to_trigger; - + std::map > m_sounds_to_stop; + float m_duration; void abortCutscene() diff --git a/src/tracks/track_object.cpp b/src/tracks/track_object.cpp index 922d87d3c..32309a954 100644 --- a/src/tracks/track_object.cpp +++ b/src/tracks/track_object.cpp @@ -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(); -} \ No newline at end of file + 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(); +} + +// ---------------------------------------------------------------------------- + diff --git a/src/tracks/track_object.hpp b/src/tracks/track_object.hpp index fe87725f6..5fa94ad8b 100644 --- a/src/tracks/track_object.hpp +++ b/src/tracks/track_object.hpp @@ -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);