From 43d092c26c3da376700d47da9cc4c4687043a7e4 Mon Sep 17 00:00:00 2001 From: auria Date: Sat, 4 Oct 2008 18:50:45 +0000 Subject: [PATCH] better encapsulation of on-screen messages so they are independant of what mode is in use, and are also independant of the type of clock used (for instance there's a few ones that in FTL counted backwards). switched to alternate timers independant of the game mode's timer + more cleanup on previous commit (clock merge) git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@2326 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- src/gui/race_gui.cpp | 30 ++++++++++++++++-------------- src/gui/race_gui.hpp | 19 +++++++++---------- src/modes/clock.cpp | 9 +++++++-- src/modes/clock.hpp | 14 ++++++++------ src/modes/follow_the_leader.cpp | 3 +-- src/modes/standard_race.cpp | 4 +--- src/modes/standard_race.hpp | 1 - src/modes/world.cpp | 2 +- src/modes/world.hpp | 5 ++--- 9 files changed, 45 insertions(+), 42 deletions(-) diff --git a/src/gui/race_gui.cpp b/src/gui/race_gui.cpp index f071e697f..047c0e45e 100644 --- a/src/gui/race_gui.cpp +++ b/src/gui/race_gui.cpp @@ -233,7 +233,7 @@ RaceGUI::handle(GameAction ga, int value) void RaceGUI::update(float dt) { drawStatusText(dt); - cleanupMessages(); + cleanupMessages(dt); BaseGUI::update( dt ); } // update @@ -759,16 +759,16 @@ void RaceGUI::drawLap(const KartIconDisplayInfo* info, Kart* kart, int offset_x, //----------------------------------------------------------------------------- /** Removes messages which have been displayed long enough. This function - * must be called after drawAllMessages, otherwise messages which are onlu + * must be called after drawAllMessages, otherwise messages which are only * displayed once will not be drawn! **/ -void RaceGUI::cleanupMessages() +void RaceGUI::cleanupMessages(const float dt) { AllMessageType::iterator p =m_messages.begin(); while(p!=m_messages.end()) { - if((*p).done()) + if((*p).done(dt)) { p = m_messages.erase(p); } @@ -989,20 +989,22 @@ void RaceGUI::drawStatusText(const float dt) split_screen_ratio_x, split_screen_ratio_y ); drawAllMessages (player_kart, offset_x, offset_y, split_screen_ratio_x, split_screen_ratio_y ); - } // for pla - drawTimer (); - if(RaceManager::getWorld()->getTime()getMinorMode() != RaceManager::MINOR_MODE_FOLLOW_LEADER) + } // next player + + drawTimer(); + + if(RaceManager::getWorld()->getPhase() == GO_PHASE || + RaceManager::getWorld()->getPhase() == MUSIC_PHASE) { drawMusicDescription(); } - else if (RaceManager::getWorld()->getTime()>stk_config->m_leader_intervals[0]-TIME_MUSIC_DESCRIPTION - && race_manager->getMinorMode()== RaceManager::MINOR_MODE_FOLLOW_LEADER) - drawMusicDescription(); + - drawMap (); - if ( user_config->m_display_fps ) drawFPS (); - drawPlayerIcons (info); + drawMap(); + if ( user_config->m_display_fps ) drawFPS(); + + drawPlayerIcons(info); + } // if RACE_PHASE glPopAttrib () ; diff --git a/src/gui/race_gui.hpp b/src/gui/race_gui.hpp index 438cea34b..b19abcb9d 100644 --- a/src/gui/race_gui.hpp +++ b/src/gui/race_gui.hpp @@ -57,7 +57,7 @@ class RaceGUI: public BaseGUI { public: std::string m_message; // message to display - float m_end_time; // end time for the message (-1 if once only) + float m_remaining_time; // time remaining before removing this message from screen int m_red,m_blue,m_green; // colour int m_font_size; // size Kart *m_kart; @@ -71,20 +71,19 @@ class RaceGUI: public BaseGUI m_message = message; m_font_size = size; m_kart = kart; - World* world = RaceManager::getWorld(); - if( time < 0.0f ) m_end_time = -1.0f; + if( time < 0.0f ) m_remaining_time = -1.0f; else { - m_end_time = race_manager->getMinorMode()==RaceManager::MINOR_MODE_FOLLOW_LEADER ? - world->getTime()-time : world->getTime()+time; + m_remaining_time = time; } m_red=red; m_blue=blue; m_green=green; } // in follow leader the clock counts backwards - bool done() const { const int time = (int)RaceManager::getWorld()->getTime(); // work around gcc bug (doesn't accept :: in a ?) - return m_end_time<0.0f || - (race_manager->getMinorMode()==RaceManager::MINOR_MODE_FOLLOW_LEADER ? - timem_end_time); } + bool done(const float dt) + { + m_remaining_time -= dt; + return m_remaining_time < 0; + } }; public: @@ -125,7 +124,7 @@ private: void drawTimer (); void drawFPS (); void drawMusicDescription (); - void cleanupMessages (); + void cleanupMessages (const float dt); /* Text drawing */ /** Draw text to screen. diff --git a/src/modes/clock.cpp b/src/modes/clock.cpp index 1be3a8d7a..81dca41e2 100644 --- a/src/modes/clock.cpp +++ b/src/modes/clock.cpp @@ -54,7 +54,7 @@ TimedRace::~TimedRace() sfx_manager->deleteSFX(m_start_sound); } //----------------------------------------------------------------------------- -void TimedRace::setMode(const ClockType mode, const float initial_time) +void TimedRace::setClockMode(const ClockType mode, const float initial_time) { m_mode = mode; m_time = initial_time; @@ -113,7 +113,12 @@ void TimedRace::update(const float dt) return; case GO_PHASE : if(m_auxiliary_timer>3.0) // how long to display the 'go' message - m_phase=RACE_PHASE; + m_phase=MUSIC_PHASE; + m_auxiliary_timer += dt; + break; + case MUSIC_PHASE: + if(m_auxiliary_timer>TIME_MUSIC_DESCRIPTION) // how long to display the 'music' message + m_phase=RACE_PHASE; m_auxiliary_timer += dt; break; case DELAY_FINISH_PHASE : diff --git a/src/modes/clock.hpp b/src/modes/clock.hpp index 474454683..bfb4f2ec2 100644 --- a/src/modes/clock.hpp +++ b/src/modes/clock.hpp @@ -36,6 +36,8 @@ enum Phase { SET_PHASE, // 'Go' is displayed, but this is already race phase GO_PHASE, + // Race is started, 'go' is gone, but music name is still there + MUSIC_PHASE, // the actual race has started, no ready/set/go is displayed anymore RACE_PHASE, // All players have finished, now wait a certain amount of time for AI @@ -85,21 +87,21 @@ public: // Note: GO_PHASE is both: start phase and race phase bool isStartPhase() const { return m_phase=GO_PHASE && - m_phasem_leader_intervals; - TimedRace::setMode(COUNTDOWN, m_leader_intervals[0]); + TimedRace::setClockMode(COUNTDOWN, m_leader_intervals[0]); } //----------------------------------------------------------------------------- @@ -115,7 +115,6 @@ void FollowTheLeaderRace::terminateRace() void FollowTheLeaderRace::update(float delta) { LinearWorld::update(delta); - if(!TimedRace::isRacePhase()) return; } //----------------------------------------------------------------------------- void FollowTheLeaderRace::restartRace() diff --git a/src/modes/standard_race.cpp b/src/modes/standard_race.cpp index 503dc966c..57d67c1ac 100644 --- a/src/modes/standard_race.cpp +++ b/src/modes/standard_race.cpp @@ -23,7 +23,7 @@ //----------------------------------------------------------------------------- StandardRace::StandardRace() : LinearWorld() { - TimedRace::setMode(CHRONO); + TimedRace::setClockMode(CHRONO); } //----------------------------------------------------------------------------- @@ -36,8 +36,6 @@ StandardRace::~StandardRace() #pragma mark clock events #endif -//----------------------------------------------------------------------------- -void StandardRace::countdownReachedZero() { } //----------------------------------------------------------------------------- void StandardRace::onGo() { diff --git a/src/modes/standard_race.hpp b/src/modes/standard_race.hpp index 61bd7c77c..c442eda9e 100644 --- a/src/modes/standard_race.hpp +++ b/src/modes/standard_race.hpp @@ -31,7 +31,6 @@ public: virtual ~StandardRace(); // clock events - virtual void countdownReachedZero(); virtual void onGo(); virtual void terminateRace(); diff --git a/src/modes/world.cpp b/src/modes/world.cpp index d0721e155..69f6f93a8 100644 --- a/src/modes/world.cpp +++ b/src/modes/world.cpp @@ -66,7 +66,7 @@ World::World() : TimedRace() m_eliminated_karts = 0; m_eliminated_players = 0; - TimedRace::setMode( CHRONO ); + TimedRace::setClockMode( CHRONO ); m_use_highscores = true; // Grab the track file diff --git a/src/modes/world.hpp b/src/modes/world.hpp index 02fa59d26..9937169cb 100644 --- a/src/modes/world.hpp +++ b/src/modes/world.hpp @@ -173,9 +173,8 @@ public: * The code that draws the timer should call this first to know * whether the game mode wants a timer drawn */ - bool shouldDrawTimer() const { return ((TimedRace::getPhase() == RACE_PHASE || - TimedRace::getPhase() == DELAY_FINISH_PHASE) && - TimedRace::getMode() != CLOCK_NONE); } + bool shouldDrawTimer() const { return TimedRace::isRacePhase() && + TimedRace::getClockMode() != CLOCK_NONE; } /** Called by the code that draws the list of karts on the race GUI * to know what needs to be drawn in the current mode