SuperTuxKart
Public Types | Public Member Functions | Protected Attributes | Private Member Functions | Private Attributes | List of all members
WorldStatus Class Reference

A class that manages the clock (countdown, chrono, etc.) Also manages stuff like the 'ready/set/go' text at the beginning or the delay at the end of a race. More...

#include <world_status.hpp>

Inheritance diagram for WorldStatus:
Inheritance graph
[legend]

Public Types

enum  ClockType { CLOCK_NONE, CLOCK_CHRONO, CLOCK_COUNTDOWN }
 Different clock types for a race. More...
 
enum  Phase {
  TRACK_INTRO_PHASE, SETUP_PHASE, WAIT_FOR_SERVER_PHASE, SERVER_READY_PHASE,
  READY_PHASE, SET_PHASE, GO_PHASE, MUSIC_PHASE,
  RACE_PHASE, DELAY_FINISH_PHASE, RESULT_DISPLAY_PHASE, FINISH_PHASE,
  IN_GAME_MENU_PHASE, UNDEFINED_PHASE
}
 

Public Member Functions

virtual ~WorldStatus ()
 Destructor of WorldStatus.
 
virtual void reset (bool restart)
 Resets all status information, used when starting a new race.
 
virtual void updateTime (int ticks)
 Updates the world time and clock (which might be running backwards), and all status information, called once per frame at the end of the main loop. More...
 
virtual void update (int ticks)
 Update, called once per frame. More...
 
void startReadySetGo ()
 
virtual void pause (Phase phase)
 Pauses the game and switches to the specified phase. More...
 
virtual void unpause ()
 Switches back from a pause state to the previous state.
 
virtual void enterRaceOverState ()
 Called when the race is finished, but it still leaves some time for an end of race animation, and potentially let some more AI karts finish the race.
 
virtual void terminateRace ()
 Called when it's really over (delay over if any). More...
 
void setTime (const float time)
 Sets the time for the clock. More...
 
void setTicks (int ticks)
 Sets a new time for the world time, measured in ticks. More...
 
void setTicksForRewind (int ticks)
 Sets a new time for the world time (used by rewind), measured in ticks. More...
 
bool isStartPhase () const
 
bool isRacePhase () const
 
bool isActiveRacePhase () const
 
bool isFinishPhase () const
 While the race menu is being displayed, m_phase is limbo, and m_previous_phase is finish. More...
 
const Phase getPhase () const
 Returns the current race phase. More...
 
void setPhase (Phase phase)
 Sets the current race phase. More...
 
void setClockMode (const ClockType mode, const float initial_time=0.0f)
 Call to specify what kind of clock you want. More...
 
int getClockMode () const
 Returns the current clock mode. More...
 
float getTime () const
 Returns the current race time. More...
 
int getTimeTicks () const
 Returns the current race time in time ticks (i.e. More...
 
virtual void countdownReachedZero ()
 Will be called to notify your derived class that the clock, which is in COUNTDOWN mode, has reached zero. More...
 
virtual void onGo ()
 Called when the race actually starts. More...
 
int getTicksSinceStart () const
 Get the ticks since start regardless of which way the clock counts.
 
int getAuxiliaryTicks () const
 
bool isLiveJoinWorld () const
 
void setLiveJoinWorld (bool val)
 
int getMusicDescriptionTicks () const
 
void endLiveJoinWorld (int ticks_now)
 Base on the network timer set current world count up ticks to tick_now.
 

Protected Attributes

double m_time
 Elasped/remaining time in seconds. More...
 
int m_time_ticks
 Time in number of ticks (in terms of physics time steps). More...
 
bool m_play_racestart_sounds
 If the start race should be played, disabled in cutscenes. More...
 
bool m_play_track_intro_sound
 
bool m_play_ready_set_go_sounds
 
std::atomic< Phase > m_phase
 

Private Member Functions

void startEngines ()
 Starts the kart engines.
 

Private Attributes

SFXBasem_track_intro_sound
 Sound to play at the beginning of a race, during which a a camera intro of the track can be shown. More...
 
SFXBasem_prestart_sound
 Sound used for the first two 'beeps' in ready, set, go. More...
 
SFXBasem_start_sound
 The third sound to be played in ready, set, go. More...
 
ClockType m_clock_mode
 The clock mode: normal counting forwards, or countdown.
 
Phase m_previous_phase
 Remember previous phase e.g. More...
 
int m_auxiliary_ticks
 Counts time during the initial 'ready/set/go' phase, or at the end of a race. More...
 
int m_start_music_ticks
 
int m_race_ticks
 
int m_live_join_ticks
 
int m_count_up_ticks
 Special counter to count ticks since start (in terms of physics timestep size). More...
 
bool m_engines_started
 
bool m_live_join_world
 

Detailed Description

A class that manages the clock (countdown, chrono, etc.) Also manages stuff like the 'ready/set/go' text at the beginning or the delay at the end of a race.

Member Enumeration Documentation

◆ ClockType

Different clock types for a race.

Member Function Documentation

◆ countdownReachedZero()

virtual void WorldStatus::countdownReachedZero ( )
inlinevirtual

Will be called to notify your derived class that the clock, which is in COUNTDOWN mode, has reached zero.

Reimplemented in SoccerWorld, FreeForAll, and FollowTheLeaderRace.

◆ getClockMode()

int WorldStatus::getClockMode ( ) const
inline

Returns the current clock mode.

◆ getPhase()

const Phase WorldStatus::getPhase ( ) const
inline

Returns the current race phase.

◆ getTime()

float WorldStatus::getTime ( ) const
inline

Returns the current race time.

◆ getTimeTicks()

int WorldStatus::getTimeTicks ( ) const
inline

Returns the current race time in time ticks (i.e.

based on the physics time step size).

◆ isFinishPhase()

bool WorldStatus::isFinishPhase ( ) const
inline

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.

◆ onGo()

virtual void WorldStatus::onGo ( )
inlinevirtual

Called when the race actually starts.

Reimplemented in SoccerWorld, and World.

◆ pause()

void WorldStatus::pause ( Phase  phase)
virtual

Pauses the game and switches to the specified phase.

Parameters
phasePhase to switch to.

◆ setClockMode()

void WorldStatus::setClockMode ( const ClockType  mode,
const float  initial_time = 0.0f 
)

Call to specify what kind of clock you want.

Sets the clock mode and the initial time of the world clock.

The second argument can be used to specify the initial time value (especially useful for countdowns).

Parameters
modeThe new clock mode.
initial_timeThe new initial time for the world clock.

◆ setPhase()

void WorldStatus::setPhase ( Phase  phase)
inline

Sets the current race phase.

Canbe used to e.g. avoid the count down etc.

◆ setTicks()

void WorldStatus::setTicks ( int  ticks)

Sets a new time for the world time, measured in ticks.

Parameters
ticksNew time in ticks to set.

◆ setTicksForRewind()

void WorldStatus::setTicksForRewind ( int  ticks)

Sets a new time for the world time (used by rewind), measured in ticks.

Parameters
ticksNew time in ticks to set (always count upwards).

◆ setTime()

void WorldStatus::setTime ( const float  time)

Sets the time for the clock.

Parameters
timeNew time to set.

◆ terminateRace()

void WorldStatus::terminateRace ( )
virtual

Called when it's really over (delay over if any).

This function must be called after all stats were updated from the different modes!

Reimplemented in SoccerWorld, World, ThreeStrikesBattle, FreeForAll, EasterEggHunt, and FollowTheLeaderRace.

◆ update()

void WorldStatus::update ( int  ticks)
virtual

Update, called once per frame.

Called early on before physics are updated.

Parameters
dtTime step.

Reimplemented in SoccerWorld, World, LinearWorld, ThreeStrikesBattle, ProfileWorld, CaptureTheFlag, CutsceneWorld, EasterEggHunt, DemoWorld, FreeForAll, and OverWorld.

◆ updateTime()

void WorldStatus::updateTime ( int  ticks)
virtual

Updates the world time and clock (which might be running backwards), and all status information, called once per frame at the end of the main loop.

Parameters
ticksNumber of ticks (physics time steps) - should be 1.

Member Data Documentation

◆ m_auxiliary_ticks

int WorldStatus::m_auxiliary_ticks
private

Counts time during the initial 'ready/set/go' phase, or at the end of a race.

This timer basically kicks in when we need to calculate non-race time like labels.

◆ m_count_up_ticks

int WorldStatus::m_count_up_ticks
private

Special counter to count ticks since start (in terms of physics timestep size).

◆ m_play_racestart_sounds

bool WorldStatus::m_play_racestart_sounds
protected

If the start race should be played, disabled in cutscenes.

◆ m_prestart_sound

SFXBase* WorldStatus::m_prestart_sound
private

Sound used for the first two 'beeps' in ready, set, go.

◆ m_previous_phase

Phase WorldStatus::m_previous_phase
private

Remember previous phase e.g.

on pause

◆ m_start_sound

SFXBase* WorldStatus::m_start_sound
private

The third sound to be played in ready, set, go.

◆ m_time

double WorldStatus::m_time
protected

Elasped/remaining time in seconds.

◆ m_time_ticks

int WorldStatus::m_time_ticks
protected

Time in number of ticks (in terms of physics time steps).

◆ m_track_intro_sound

SFXBase* WorldStatus::m_track_intro_sound
private

Sound to play at the beginning of a race, during which a a camera intro of the track can be shown.


The documentation for this class was generated from the following files: