From 85490b5f8ea07f5f19e41fa1f124f6d5092f880d Mon Sep 17 00:00:00 2001 From: hikerstk Date: Sun, 10 Feb 2008 23:17:25 +0000 Subject: [PATCH] Added a very simple display to show information about the music currently being played (first two lines from the *readme files, should be title of music and composer/musician). git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@1454 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- oggs/Boom_boom_boom.readme | 2 + oggs/Ethereal Spectrum (ver loop).readme | 2 + oggs/Lava Lagoon_2.readme | 2 + oggs/tk2.readme | 2 + oggs/tk5a.readme | 2 + oggs/tk7.readme | 2 + oggs/tuxr.readme | 2 + src/constants.hpp | 5 +- src/gui/race_gui.cpp | 30 ++++++-- src/gui/race_gui.hpp | 2 +- src/sound_manager.cpp | 96 +++++++++++++----------- src/sound_manager.hpp | 6 +- 12 files changed, 98 insertions(+), 55 deletions(-) create mode 100644 oggs/Boom_boom_boom.readme create mode 100644 oggs/Ethereal Spectrum (ver loop).readme create mode 100644 oggs/Lava Lagoon_2.readme create mode 100644 oggs/tk2.readme create mode 100644 oggs/tk5a.readme create mode 100644 oggs/tk7.readme create mode 100644 oggs/tuxr.readme diff --git a/oggs/Boom_boom_boom.readme b/oggs/Boom_boom_boom.readme new file mode 100644 index 000000000..5aeced1fb --- /dev/null +++ b/oggs/Boom_boom_boom.readme @@ -0,0 +1,2 @@ +Boom boom boom +Matt Thomas diff --git a/oggs/Ethereal Spectrum (ver loop).readme b/oggs/Ethereal Spectrum (ver loop).readme new file mode 100644 index 000000000..1d37a7d99 --- /dev/null +++ b/oggs/Ethereal Spectrum (ver loop).readme @@ -0,0 +1,2 @@ +Ethereal Spectrum +??? diff --git a/oggs/Lava Lagoon_2.readme b/oggs/Lava Lagoon_2.readme new file mode 100644 index 000000000..22c7bb125 --- /dev/null +++ b/oggs/Lava Lagoon_2.readme @@ -0,0 +1,2 @@ +Lava Lagoon 2 +???? diff --git a/oggs/tk2.readme b/oggs/tk2.readme new file mode 100644 index 000000000..ad3c3b6eb --- /dev/null +++ b/oggs/tk2.readme @@ -0,0 +1,2 @@ +Tuxkart 2 +Matt Thomas diff --git a/oggs/tk5a.readme b/oggs/tk5a.readme new file mode 100644 index 000000000..b6bc3bef4 --- /dev/null +++ b/oggs/tk5a.readme @@ -0,0 +1,2 @@ +Tuxkart 5a +Matt Thomas diff --git a/oggs/tk7.readme b/oggs/tk7.readme new file mode 100644 index 000000000..a8f4026e1 --- /dev/null +++ b/oggs/tk7.readme @@ -0,0 +1,2 @@ +Tuxkart 7 +Matt Thomas diff --git a/oggs/tuxr.readme b/oggs/tuxr.readme new file mode 100644 index 000000000..a7a5e6003 --- /dev/null +++ b/oggs/tuxr.readme @@ -0,0 +1,2 @@ +TuxR +Matt Thomas diff --git a/src/constants.hpp b/src/constants.hpp index de9756e48..ca5c65538 100644 --- a/src/constants.hpp +++ b/src/constants.hpp @@ -21,8 +21,9 @@ #define HEADER_CONSTANTS_H -#define MAX_HISTORY 50000 /* number of history events */ -#define TIME_DELAY_TILL_FINISH 10.0f /* time after all player karts finish */ +#define MAX_HISTORY 50000 /* number of history events */ +#define TIME_DELAY_TILL_FINISH 10.0f /* time after all player karts finish */ +#define TIME_MUSIC_DESCRIPTION 10.0f /* duration music description is displayed */ /* All final units are in meters (or meters/sec or meters/sec^2) and degrees (or degrees/sec). diff --git a/src/gui/race_gui.cpp b/src/gui/race_gui.cpp index 4061d3973..f31fb4925 100644 --- a/src/gui/race_gui.cpp +++ b/src/gui/race_gui.cpp @@ -28,6 +28,7 @@ #include "track.hpp" #include "material_manager.hpp" #include "menu_manager.hpp" +#include "sound_manager.hpp" #undef USE_WIDGET_MANAGER #ifdef USE_WIDGET_MANAGER @@ -80,7 +81,7 @@ enum WidgetTokens }; #endif -RaceGUI::RaceGUI(): m_time_left(0.0) +RaceGUI::RaceGUI() { // FIXME: translation problem m_pos_string[0] = "?!?"; @@ -263,9 +264,8 @@ void RaceGUI::drawTimer () char str[256]; assert(world != NULL); - m_time_left = world->getTime(); - TimeToString(m_time_left, str); + TimeToString(world->getTime(), str); #ifdef USE_WIDGET_MANAGER widget_manager->showWgtText( WTOK_CLOCK ); widget_manager->setWgtText( WTOK_CLOCK, str ); @@ -865,6 +865,23 @@ void RaceGUI::addMessage(const char *msg, Kart *kart, float time, m_messages.push_back(TimedMessage(msg, kart, time, font_size, red, green, blue)); } // addMessage +//----------------------------------------------------------------------------- +// Displays the description given for the music currently being played - +// usually the title and composer. +void RaceGUI::drawMusicDescription() +{ + const std::vector& description = sound_manager->getDescription(); + int y=0; + for(int i=(int)description.size()-1; i>=0; i--) + { + font_race->Print( description[i].c_str(), 25, + Font::CENTER_OF_SCREEN, y, + 255, 255, 255); + y+=20; + } // for igetTime()m_display_fps ) drawFPS (); - drawPlayerIcons() ; + drawPlayerIcons (); } // if RACE_PHASE glPopAttrib () ; diff --git a/src/gui/race_gui.hpp b/src/gui/race_gui.hpp index b7fe1823b..0f923494b 100644 --- a/src/gui/race_gui.hpp +++ b/src/gui/race_gui.hpp @@ -75,7 +75,6 @@ private: ulClock m_fps_timer; int m_fps_counter; char m_fps_string[10]; - double m_time_left ; const char* m_pos_string [11]; Material* m_steering_wheel_icon; Material* m_speed_back_icon; @@ -100,6 +99,7 @@ private: void drawMap (); void drawTimer (); void drawFPS (); + void drawMusicDescription (); void cleanupMessages (); /* Text drawing */ diff --git a/src/sound_manager.cpp b/src/sound_manager.cpp index 8b366dcae..b57f29baf 100644 --- a/src/sound_manager.cpp +++ b/src/sound_manager.cpp @@ -18,11 +18,14 @@ // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include +#include #include "sound_manager.hpp" #include "user_config.hpp" +#include "string_utils.hpp" +#include "gui/font.hpp" -#define USE_PLIB_SOUND !((HAVE_OPENAL && (HAVE_MIKMOD || HAVE_OGGVORBIS))) +#define USE_PLIB_SOUND !(HAVE_OPENAL && HAVE_OGGVORBIS) #if USE_PLIB_SOUND # include "sound_plib.hpp" #else //We use OpenAL @@ -36,9 +39,6 @@ # if HAVE_OGGVORBIS # include "music_ogg.hpp" # endif -# if HAVE_MIKMOD -# include "music_mikmod.hpp" -# endif # include "sfx_openal.hpp" #endif // USE_PLIB_SOUND @@ -101,7 +101,7 @@ SoundManager::SoundManager() sfx = new SFXImpl("wavs/tintagel/start_race.wav"); m_sfxs[SOUND_START] = sfx; sfx = new SFXImpl("wavs/radio/radarping.wav"); m_sfxs[SOUND_MISSILE_LOCK] = sfx; } -} +} // SoundManager //----------------------------------------------------------------------------- SoundManager::~SoundManager() @@ -129,7 +129,7 @@ SoundManager::~SoundManager() #endif } -} +} // ~SoundManager //----------------------------------------------------------------------------- void SoundManager::playSfx(unsigned int id) @@ -145,24 +145,25 @@ void SoundManager::playSfx(unsigned int id) SFX* sfx= it->second; sfx->play(); } -} +} // playSfx //----------------------------------------------------------------------------- void SoundManager::playMusic(const char* filename) { - if(user_config->doMusic() && m_initialized) - { - if (m_current_music != NULL) - { - delete m_current_music; - m_current_music = NULL; - } + m_description.clear(); + if(!user_config->doMusic() || !m_initialized) return; - if (filename == NULL || strlen(filename) == 0) - { - // nothing to play - return; - } + if (m_current_music != NULL) + { + delete m_current_music; + m_current_music = NULL; + } + + if (filename == NULL || strlen(filename) == 0) + { + // nothing to play + return; + } #if USE_PLIB_SOUND if (!strcasecmp(".mod", filename+strlen(filename)-4)) @@ -172,29 +173,33 @@ void SoundManager::playMusic(const char* filename) if (!strcasecmp(".ogg", filename+strlen(filename)-4)) m_current_music= new MusicOggStream(); #endif -#if HAVE_MIKMOD - if (!strcasecmp(".mod", filename+strlen(filename)-4)) - m_current_music= new MusicMikMod(); - -#endif - if(m_current_music == NULL) // no support for file - { - fprintf(stderr, "WARNING: music file %s format not recognized.\n", filename); - 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); - } - else - { - m_current_music->playMusic(); - } + if(m_current_music == NULL) // no support for file + { + fprintf(stderr, "WARNING: music file %s format not recognized.\n", filename); + 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); + return; + } + + // Read up to two lines from the corresponding .readme file: first one + // the title, second the composer. This is then displayed by the race gui + std::string name_readme = StringUtils::without_extension(filename)+".readme"; + std::ifstream f(name_readme.c_str()); + if(f) + { + std::string s; + std::getline(f,s); if(!f.eof()) m_description.push_back(s); + std::getline(f,s); if(!f.eof()) m_description.push_back(s); + f.close(); + } + m_current_music->playMusic(); +} // playMusic //----------------------------------------------------------------------------- void SoundManager::stopMusic() @@ -203,7 +208,8 @@ void SoundManager::stopMusic() { m_current_music->stopMusic(); } -} + m_description.clear(); +} // stopMusic //----------------------------------------------------------------------------- void SoundManager::pauseMusic() @@ -213,7 +219,7 @@ void SoundManager::pauseMusic() m_current_music->pauseMusic(); } -} +} // pauseMusic //----------------------------------------------------------------------------- void SoundManager::resumeMusic() @@ -222,7 +228,7 @@ void SoundManager::resumeMusic() { m_current_music->resumeMusic(); } -} +} // resumeMusic //----------------------------------------------------------------------------- void SoundManager::update() @@ -231,5 +237,5 @@ void SoundManager::update() { m_current_music->update(); } -} +} // update diff --git a/src/sound_manager.hpp b/src/sound_manager.hpp index 0bad9db16..49b8bda2c 100644 --- a/src/sound_manager.hpp +++ b/src/sound_manager.hpp @@ -21,6 +21,8 @@ #define HEADER_SOUNDMANAGER_H #include +#include +#include #include "music.hpp" #include "sfx.hpp" @@ -47,6 +49,7 @@ public: void stopMusic(); void pauseMusic(); void resumeMusic(); + const std::vector& getDescription() {return m_description;} private: @@ -54,7 +57,8 @@ private: SFXsType m_sfxs; Music* m_current_music; - + std::vector m_description; + bool m_initialized; //If the sound could not be initialized, for example, //if the player doesn't has a sound card, we want //to avoid anything sound related so we crash the game.