diff --git a/data/stk_config.data b/data/stk_config.data index 0cbc88ff4..2770f1113 100644 --- a/data/stk_config.data +++ b/data/stk_config.data @@ -8,6 +8,7 @@ (grid-order 1 ) ;; order for grand prix, 1 is most ;; points 1st, 0 is least points ;; 1st + (title-music "oggs/main_theme.ogg") ;; Attachment related parameters ;; ----------------------------- diff --git a/oggs/main_theme.ogg b/oggs/main_theme.ogg new file mode 100644 index 000000000..8699f7e14 Binary files /dev/null and b/oggs/main_theme.ogg differ diff --git a/oggs/main_theme.readme b/oggs/main_theme.readme new file mode 100644 index 000000000..fec8a4ff1 --- /dev/null +++ b/oggs/main_theme.readme @@ -0,0 +1,2 @@ +SuperTuxKart Main Theme +Michael Tedstone diff --git a/src/game_manager.cpp b/src/game_manager.cpp index e76a8a9e4..cdc024b56 100644 --- a/src/game_manager.cpp +++ b/src/game_manager.cpp @@ -62,6 +62,8 @@ void GameManager::run() { const GLuint TITLE_SCREEN_TEXTURE = material_manager->getMaterial("st_title_screen.rgb")->getIndex(); + + bool music_on = false; while(!m_abort) { sdl_input(); @@ -76,6 +78,12 @@ void GameManager::run() } m_curr_time = SDL_GetTicks(); + + if (!music_on && !race_manager->raceIsActive()) + { + sound_manager->playMusic(stk_config->m_title_music); + music_on = true; + } if (race_manager->raceIsActive()) { diff --git a/src/music.hpp b/src/music.hpp index ded7c1843..cb89b40cb 100644 --- a/src/music.hpp +++ b/src/music.hpp @@ -20,10 +20,12 @@ #ifndef HEADER_MUSIC_H #define HEADER_MUSIC_H +#include + class Music { public: - virtual bool load(const char* filename)= 0; + virtual bool load(const std::string& filename)= 0; virtual bool playMusic()= 0; virtual bool stopMusic()= 0; diff --git a/src/music_ogg.cpp b/src/music_ogg.cpp index 186a65aee..713f97cf8 100644 --- a/src/music_ogg.cpp +++ b/src/music_ogg.cpp @@ -50,7 +50,7 @@ MusicOggStream::~MusicOggStream() } //----------------------------------------------------------------------------- -bool MusicOggStream::load(const char* filename) +bool MusicOggStream::load(const std::string& filename) { if(!release()) { diff --git a/src/music_ogg.hpp b/src/music_ogg.hpp index 2a352fae7..affa4a053 100644 --- a/src/music_ogg.hpp +++ b/src/music_ogg.hpp @@ -43,7 +43,7 @@ public: virtual void update(); - virtual bool load(const char* filename); + virtual bool load(const std::string& filename); virtual bool playMusic(); virtual bool stopMusic(); diff --git a/src/sound_manager.cpp b/src/sound_manager.cpp index b57f29baf..9565f7dab 100644 --- a/src/sound_manager.cpp +++ b/src/sound_manager.cpp @@ -148,7 +148,7 @@ void SoundManager::playSfx(unsigned int id) } // playSfx //----------------------------------------------------------------------------- -void SoundManager::playMusic(const char* filename) +void SoundManager::playMusic(const std::string& filename) { m_description.clear(); if(!user_config->doMusic() || !m_initialized) return; @@ -159,31 +159,32 @@ void SoundManager::playMusic(const char* filename) m_current_music = NULL; } - if (filename == NULL || strlen(filename) == 0) + if (filename == "" || strlen(filename.c_str()) == 0) { // nothing to play return; } #if USE_PLIB_SOUND - if (!strcasecmp(".mod", filename+strlen(filename)-4)) + if (!strcasecmp(".mod", filename.c_str()+filename.size()-4)) m_current_music= new MusicPlib(); #endif #if HAVE_OGGVORBIS - if (!strcasecmp(".ogg", filename+strlen(filename)-4)) + if (!strcasecmp(".ogg", filename.c_str()+filename.size()-4)) m_current_music= new MusicOggStream(); #endif if(m_current_music == NULL) // no support for file { - fprintf(stderr, "WARNING: music file %s format not recognized.\n", filename); + fprintf(stderr, "WARNING: music file %s format not recognized.\n", filename.c_str()); return; } if((m_current_music->load(filename)) == false) { delete m_current_music; - m_current_music=0; - fprintf(stderr, "WARNING: Unabled to load music %s, not supported or not found.\n", filename); + m_current_music=0; + fprintf(stderr, "WARNING: Unabled to load music %s, not supported or not found.\n", + filename.c_str()); return; } diff --git a/src/sound_manager.hpp b/src/sound_manager.hpp index 49b8bda2c..2ac44f564 100644 --- a/src/sound_manager.hpp +++ b/src/sound_manager.hpp @@ -45,7 +45,7 @@ public: void playSfx(unsigned int id); - void playMusic(const char* filename); + void playMusic(const std::string& filename); void stopMusic(); void pauseMusic(); void resumeMusic(); diff --git a/src/stk_config.cpp b/src/stk_config.cpp index 650d716f3..57e30f113 100644 --- a/src/stk_config.cpp +++ b/src/stk_config.cpp @@ -116,6 +116,7 @@ void STKConfig::load(const std::string filename) } // load +// ----------------------------------------------------------------------------- /** Init all values with invalid defaults, which are tested later. This * guarantees that all parameters will indeed be initialised, and helps * finding typos. @@ -144,6 +145,7 @@ void STKConfig::init_defaults() m_max_karts = -100; m_grid_order = -100; m_air_res_reduce[0] = 1.0f; + m_title_music = ""; } // init_defaults //----------------------------------------------------------------------------- @@ -171,6 +173,7 @@ void STKConfig::getAllData(const lisp::Lisp* lisp) lisp->get("explosion-impulse-objects", m_explosion_impulse_objects); lisp->get("max-karts", m_max_karts ); lisp->get("grid-order", m_grid_order ); + lisp->get("title-music", m_title_music ); // Get the default KartProperties // ------------------------------ diff --git a/src/stk_config.hpp b/src/stk_config.hpp index 1960e1216..ca26ecff0 100644 --- a/src/stk_config.hpp +++ b/src/stk_config.hpp @@ -45,6 +45,7 @@ public: float m_explosion_impulse_objects;// impulse of explosion on moving objects, e.g. road cones, ... int m_max_karts; // maximum number of karts int m_grid_order; // whether grand prix grid is in point order or reverse point order + std::string m_title_music; // filename of the title music to play STKConfig() : KartProperties() {}; void init_defaults (); diff --git a/src/world.cpp b/src/world.cpp index 094f3a00d..d28c88bed 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -156,7 +156,7 @@ World::World(const RaceSetup& raceSetup_) : m_race_setup(raceSetup_) menu_manager->switchToRace(); const std::string& MUSIC_NAME= track_manager->getTrack(m_race_setup.m_track)->getMusic(); - if (MUSIC_NAME.size()>0) sound_manager->playMusic(MUSIC_NAME.c_str()); + if (MUSIC_NAME.size()>0) sound_manager->playMusic(MUSIC_NAME); if(user_config->m_profile) {