From 396db5ae2b99d0be9a069ee50bd1d4e0952f8e42 Mon Sep 17 00:00:00 2001 From: hikerstk Date: Tue, 6 Jul 2010 23:10:47 +0000 Subject: [PATCH] Added intro sfx to be played before ready-set-go. git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@5663 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- src/audio/music_manager.cpp | 5 +++- src/config/user_config.cpp | 1 + src/karts/kart.cpp | 12 +++++++-- src/karts/kart.hpp | 1 + src/modes/world.cpp | 2 -- src/modes/world_status.cpp | 49 +++++++++++++++++++++++++------------ src/modes/world_status.hpp | 8 ++++++ src/tracks/quad_set.hpp | 14 ++++++----- 8 files changed, 66 insertions(+), 26 deletions(-) diff --git a/src/audio/music_manager.cpp b/src/audio/music_manager.cpp index c8e21ca3f..8c1e02975 100644 --- a/src/audio/music_manager.cpp +++ b/src/audio/music_manager.cpp @@ -135,7 +135,10 @@ void MusicManager::addMusicToTracks() void MusicManager::startMusic(MusicInformation* mi) { // If this music is already playing, ignore this call. - if (m_current_music != NULL && m_current_music == mi && m_current_music->isPlaying()) return; + if (m_current_music != NULL && + m_current_music == mi && + m_current_music->isPlaying()) + return; // It is possible here that startMusic() will be called without first calling stopMusic(). // This would cause a memory leak by overwriting m_current_music without first releasing its resources. diff --git a/src/config/user_config.cpp b/src/config/user_config.cpp index e534c07f6..004a43931 100644 --- a/src/config/user_config.cpp +++ b/src/config/user_config.cpp @@ -412,6 +412,7 @@ bool UserConfig::loadConfig() if(!root || root->getName() != "stkconfig") { std::cerr << "Could not read user config file file " << filename.c_str() << std::endl; + if(root) delete root; return false; } diff --git a/src/karts/kart.cpp b/src/karts/kart.cpp index 993f0c861..981ba52e5 100644 --- a/src/karts/kart.cpp +++ b/src/karts/kart.cpp @@ -264,14 +264,20 @@ void Kart::createPhysics() m_uprightConstraint->setDamping(0.0f); World::getWorld()->getPhysics()->addKart(this); - //create the engine sound +} // createPhysics + +// ---------------------------------------------------------------------------- +/** Starts the engine sound effect. Called once the track intro phase is over. + */ +void Kart::startEngineSFX() +{ if(m_engine_sound) { m_engine_sound->speed(0.6f); m_engine_sound->setLoop(true); m_engine_sound->play(); } -} // createPhysics +} // startEngineSFX // ---------------------------------------------------------------------------- /** The destructor frees the memory of this kart, but note that the actual kart @@ -413,6 +419,8 @@ void Kart::reset() { sfx_manager->deleteSFX(m_previous_terrain_sound); } + if(m_engine_sound) + m_engine_sound->stop(); m_controls.m_steer = 0.0f; m_controls.m_accel = 0.0f; diff --git a/src/karts/kart.hpp b/src/karts/kart.hpp index f1cf77df2..e49b0e0b8 100644 --- a/src/karts/kart.hpp +++ b/src/karts/kart.hpp @@ -367,6 +367,7 @@ public: bool isEliminated () const {return m_eliminated;} void eliminate (); void resetBrakes (); + void startEngineSFX (); void adjustSpeed (float f); void updatedWeight (); /** Returns a name to be displayed for this kart. */ diff --git a/src/modes/world.cpp b/src/modes/world.cpp index 35b2d3eff..b0ec3d077 100644 --- a/src/modes/world.cpp +++ b/src/modes/world.cpp @@ -147,7 +147,6 @@ void World::init() // objects need to allocate data structures depending on the number // of karts. m_track->reset(); - m_track->startMusic(); if(!history->replayHistory()) history->initRecording(); network_manager->worldLoaded(); @@ -645,7 +644,6 @@ void World::restartRace() // Start music from beginning music_manager->stopMusic(); m_track->reset(); - m_track->startMusic(); // Enable SFX again sfx_manager->resumeAll(); diff --git a/src/modes/world_status.cpp b/src/modes/world_status.cpp index 8ce0701a0..22ecdbe1c 100644 --- a/src/modes/world_status.cpp +++ b/src/modes/world_status.cpp @@ -17,25 +17,30 @@ #include "modes/world_status.hpp" +#include "audio/music_manager.hpp" #include "audio/sfx_manager.hpp" #include "audio/sfx_base.hpp" #include "config/stk_config.hpp" #include "guiengine/modaldialog.hpp" +#include "modes/world.hpp" +#include "tracks/track.hpp" #include "network/network_manager.hpp" #include "states_screens/dialogs/race_over_dialog.hpp" //----------------------------------------------------------------------------- WorldStatus::WorldStatus() { - m_clock_mode = CLOCK_CHRONO; - m_time = 0.0f; - m_auxiliary_timer = 0.0f; - m_phase = SETUP_PHASE; - m_previous_phase = UNDEFINED_PHASE; // initialise it just in case + m_clock_mode = CLOCK_CHRONO; + m_time = 0.0f; + m_auxiliary_timer = 0.0f; + m_phase = SETUP_PHASE; + m_previous_phase = UNDEFINED_PHASE; // initialise it just in case - // FIXME - is it a really good idea to reload and delete the sound every race?? - m_prestart_sound = sfx_manager->createSoundSource("prestart"); - m_start_sound = sfx_manager->createSoundSource("start"); + m_prestart_sound = sfx_manager->createSoundSource("prestart"); + m_start_sound = sfx_manager->createSoundSource("start"); + m_track_intro_sound = sfx_manager->createSoundSource("track_intro"); + + music_manager->stopMusic(); } // WorldStatus //----------------------------------------------------------------------------- @@ -45,8 +50,12 @@ void WorldStatus::reset() { m_time = 0.0f; m_auxiliary_timer = 0.0f; - m_phase = READY_PHASE; // FIXME - unsure + // Using SETUP_PHASE will play the track into sfx first, and has no + // other side effects. + m_phase = SETUP_PHASE; m_previous_phase = UNDEFINED_PHASE; + // Just in case that the game is reset during the intro phase + m_track_intro_sound->stop(); } // reset //----------------------------------------------------------------------------- @@ -112,14 +121,23 @@ void WorldStatus::update(const float dt) // simplifies this handling case SETUP_PHASE: m_auxiliary_timer = 0.0f; - m_phase = READY_PHASE; + m_phase = TRACK_INTRO_PHASE; + m_track_intro_sound->play(); + return; + case TRACK_INTRO_PHASE: + if(m_track_intro_sound->getStatus()==SFXManager::SFX_PLAYING) + return; m_prestart_sound->play(); - return; // loading time, don't play sound yet + m_phase = READY_PHASE; + for(unsigned int i=0; igetNumKarts(); i++) + World::getWorld()->getKart(i)->startEngineSFX(); + + break; case READY_PHASE: if(m_auxiliary_timer>1.0) { - m_phase=SET_PHASE; m_prestart_sound->play(); + m_phase=SET_PHASE; } m_auxiliary_timer += dt; return; @@ -127,8 +145,7 @@ void WorldStatus::update(const float dt) if(m_auxiliary_timer>2.0) { // set phase is over, go to the next one - m_phase=GO_PHASE; - + m_phase=GO_PHASE; m_start_sound->play(); // event @@ -137,7 +154,9 @@ void WorldStatus::update(const float dt) m_auxiliary_timer += dt; return; case GO_PHASE : - if(m_auxiliary_timer>3.0) // how long to display the 'go' message + if(m_auxiliary_timer>2.5f) + World::getWorld()->getTrack()->startMusic(); + if(m_auxiliary_timer>3.0f) // how long to display the 'go' message m_phase=MUSIC_PHASE; m_auxiliary_timer += dt; break; diff --git a/src/modes/world_status.hpp b/src/modes/world_status.hpp index eab2bc482..20d50868b 100644 --- a/src/modes/world_status.hpp +++ b/src/modes/world_status.hpp @@ -37,6 +37,9 @@ public: }; enum Phase { + // Time for a camera movement, and introductory song + TRACK_INTRO_PHASE, + // Game setup, e.g. track loading SETUP_PHASE, @@ -75,7 +78,12 @@ public: UNDEFINED_PHASE }; protected: + /** Sound to play at the beginning of a race, during which a + * a camera intro of the track can be shown. */ + SFXBase *m_track_intro_sound; + /** Sound used for the first two 'beeps' in ready, set, go. */ SFXBase *m_prestart_sound; + /** The third sound to be played in ready, set, go. */ SFXBase *m_start_sound; /** diff --git a/src/tracks/quad_set.hpp b/src/tracks/quad_set.hpp index 52b5806a5..98726e1c4 100644 --- a/src/tracks/quad_set.hpp +++ b/src/tracks/quad_set.hpp @@ -46,18 +46,20 @@ private: public: static const int QUAD_NONE=-1; - QuadSet (const std::string& filename); - const Quad& getQuad(int n) const {return *(m_all_quads[n]); } - int getCurrentQuad(const Vec3& p, int oldQuad) const; + QuadSet (const std::string& filename); + int getCurrentQuad(const Vec3& p, int oldQuad) const; + const Quad& getQuad(int n) const {return *(m_all_quads[n]); } + /** Return the minimum and maximum coordinates of this quad set. */ - void getBoundingBox(Vec3 *min, Vec3 *max) { *min=m_min; *max=m_max; } + void getBoundingBox(Vec3 *min, Vec3 *max) + { *min=m_min; *max=m_max; } /** Returns the number of quads. */ unsigned int getNumberOfQuads() const {return (unsigned int)m_all_quads.size(); } /** Returns the center of quad n. */ - const Vec3& getCenterOfQuad(int n) const + const Vec3& getCenterOfQuad(int n) const {return m_all_quads[n]->getCenter(); } /** Returns the n-th. quad. */ - const Quad& getQuad(int n) {return *(m_all_quads[n]); } + const Quad& getQuad(int n) {return *(m_all_quads[n]); } }; // QuadSet #endif