SuperTuxKart
Loading...
Searching...
No Matches
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.
 
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.
 
virtual void update (int ticks)
 Update, called once per frame.
 
void startReadySetGo ()
 
virtual void pause (Phase phase)
 Pauses the game and switches to the specified phase.
 
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).
 
void setTime (const float time)
 Sets the time for the clock.
 
void setTicks (int ticks)
 Sets a new time for the world time, measured in ticks.
 
void setTicksForRewind (int ticks)
 Sets a new time for the world time (used by rewind), measured in ticks.
 
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.
 
const Phase getPhase () const
 Returns the current race phase.
 
void setPhase (Phase phase)
 Sets the current race phase.
 
void setClockMode (const ClockType mode, const float initial_time=0.0f)
 Call to specify what kind of clock you want.
 
int getClockMode () const
 Returns the current clock mode.
 
float getTime () const
 Returns the current race time.
 
uint64_t getStart () const
 Returns the start time.
 
int getTimeTicks () const
 Returns the current race time in time ticks (i.e.
 
virtual void countdownReachedZero ()
 Will be called to notify your derived class that the clock, which is in COUNTDOWN mode, has reached zero.
 
virtual void onGo ()
 Called when the race actually starts.
 
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.
 
int m_time_ticks
 Time in number of ticks (in terms of physics time steps).
 
bool m_play_racestart_sounds
 If the start race should be played, disabled in cutscenes.
 
const ProcessType m_process_type
 Process type of this world (main or child).
 
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.
 
SFXBasem_prestart_sound
 Sound used for the first two 'beeps' in ready, set, go.
 
SFXBasem_start_sound
 The third sound to be played in ready, set, go.
 
uint64_t m_started_at
 (Unix) time when we started
 
ClockType m_clock_mode
 The clock mode: normal counting forwards, or countdown.
 
Phase m_previous_phase
 Remember previous phase e.g.
 
int m_auxiliary_ticks
 Counts time during the initial 'ready/set/go' phase, or at the end of a race.
 
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).
 
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 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 FollowTheLeaderRace, FreeForAll, LapTrial, and SoccerWorld.

◆ enterRaceOverState()

void WorldStatus::enterRaceOverState ( )
virtual

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.

Reimplemented in ProfileWorld, CutsceneWorld, DemoWorld, SoccerWorld, and ThreeStrikesBattle.

◆ 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.

Reimplemented in World.

◆ reset()

void WorldStatus::reset ( bool  restart)
virtual

Resets all status information, used when starting a new race.

Reimplemented in CaptureTheFlag, CutsceneWorld, EasterEggHunt, FollowTheLeaderRace, FreeForAll, LapTrial, LinearWorld, SoccerWorld, ThreeStrikesBattle, World, and WorldWithRank.

◆ 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 EasterEggHunt, FollowTheLeaderRace, FreeForAll, LapTrial, SoccerWorld, ThreeStrikesBattle, and World.

◆ unpause()

void WorldStatus::unpause ( )
virtual

Switches back from a pause state to the previous state.

Reimplemented in World.

◆ update()

void WorldStatus::update ( int  ticks)
virtual

Update, called once per frame.

Called early on before physics are updated.

Parameters
dtTime step.

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

◆ 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_previous_phase

Phase WorldStatus::m_previous_phase
private

Remember previous phase e.g.

on pause


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