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
This commit is contained in:
hikerstk
2008-02-10 23:17:25 +00:00
parent b507825bec
commit 85490b5f8e
12 changed files with 98 additions and 55 deletions

View File

@@ -0,0 +1,2 @@
Boom boom boom
Matt Thomas

View File

@@ -0,0 +1,2 @@
Ethereal Spectrum
???

View File

@@ -0,0 +1,2 @@
Lava Lagoon 2
????

2
oggs/tk2.readme Normal file
View File

@@ -0,0 +1,2 @@
Tuxkart 2
Matt Thomas

2
oggs/tk5a.readme Normal file
View File

@@ -0,0 +1,2 @@
Tuxkart 5a
Matt Thomas

2
oggs/tk7.readme Normal file
View File

@@ -0,0 +1,2 @@
Tuxkart 7
Matt Thomas

2
oggs/tuxr.readme Normal file
View File

@@ -0,0 +1,2 @@
TuxR
Matt Thomas

View File

@@ -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).

View File

@@ -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<std::string>& 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 i<m_description.size()
} // drawMusicDescription
//-----------------------------------------------------------------------------
void RaceGUI::drawStatusText (const RaceSetup& raceSetup, const float dt)
{
@@ -992,10 +1009,11 @@ void RaceGUI::drawStatusText (const RaceSetup& raceSetup, const float dt)
drawAllMessages (player_kart, offset_x, offset_y,
split_screen_ratio_x, split_screen_ratio_y );
} // for pla
drawTimer ();
drawMap ();
drawTimer ();
if(world->getTime()<TIME_MUSIC_DESCRIPTION) drawMusicDescription();
drawMap ();
if ( user_config->m_display_fps ) drawFPS ();
drawPlayerIcons() ;
drawPlayerIcons ();
} // if RACE_PHASE
glPopAttrib () ;

View File

@@ -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 */

View File

@@ -18,11 +18,14 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <assert.h>
#include <fstream>
#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

View File

@@ -21,6 +21,8 @@
#define HEADER_SOUNDMANAGER_H
#include <map>
#include <vector>
#include <string>
#include "music.hpp"
#include "sfx.hpp"
@@ -47,6 +49,7 @@ public:
void stopMusic();
void pauseMusic();
void resumeMusic();
const std::vector<std::string>& getDescription() {return m_description;}
private:
@@ -54,7 +57,8 @@ private:
SFXsType m_sfxs;
Music* m_current_music;
std::vector<std::string> 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.