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
This commit is contained in:
parent
940f1a4702
commit
43d092c26c
@ -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()<TIME_MUSIC_DESCRIPTION
|
||||
&& race_manager->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 () ;
|
||||
|
@ -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 ?
|
||||
time<m_end_time : time>m_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.
|
||||
|
@ -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 :
|
||||
|
@ -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; }
|
||||
bool isRacePhase() const { return m_phase>=GO_PHASE &&
|
||||
m_phase<LIMBO_PHASE; }
|
||||
m_phase<FINISH_PHASE; }
|
||||
/** While the race menu is being displayed, m_phase is limbo, and
|
||||
* m_previous_phase is finish. So we have to test this case, too. */
|
||||
bool isFinishPhase() const { return m_phase==FINISH_PHASE ||
|
||||
(m_phase==LIMBO_PHASE &&
|
||||
m_previous_phase==FINISH_PHASE);}
|
||||
(m_phase==LIMBO_PHASE &&
|
||||
m_previous_phase==FINISH_PHASE);}
|
||||
const Phase getPhase() const { return m_phase; }
|
||||
|
||||
/**
|
||||
* Call to specify what kind of clock you want. The second argument
|
||||
* Call to specify what kind of clock you want. The second argument
|
||||
* can be used to specify the initial time value (especially useful
|
||||
* for countdowns)
|
||||
*/
|
||||
void setMode(const ClockType mode, const float initial_time=0.0f);
|
||||
int getMode() const { return m_mode; }
|
||||
void setClockMode(const ClockType mode, const float initial_time=0.0f);
|
||||
int getClockMode() const { return m_mode; }
|
||||
/**
|
||||
* Call each frame, with the elapsed time as argument.
|
||||
*/
|
||||
|
@ -27,7 +27,7 @@ FollowTheLeaderRace::FollowTheLeaderRace() : LinearWorld()
|
||||
{
|
||||
m_leader_intervals = stk_config->m_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()
|
||||
|
@ -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()
|
||||
{
|
||||
|
@ -31,7 +31,6 @@ public:
|
||||
virtual ~StandardRace();
|
||||
|
||||
// clock events
|
||||
virtual void countdownReachedZero();
|
||||
virtual void onGo();
|
||||
virtual void terminateRace();
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user