Simulator::cGameTimeManager class

This class controls game time speed and pauses.

You can use it to pause/resume the game, and you can also use it to control the game speed.

This class is organized in different "pause types" that pause the game and optionally, effects and audio. Calls to Pause() and Resume() are "stacked", that is, if you call Pause() twice, then you have to call Resume() twice in order to actually resume the game.

Example usage:

if (!GameTimeManager.IsPaused()) {
    GameTimeManager.Pause(TimeManagerPause::UserToggle);
}

This is a singleton class, so use GameTimeManager to access it.

Base classes

class cStrategy

Public types

struct PauseType
enum PauseFlags { kPauseFlag = 0x1, kPauseFlagEffects = 0x2, kPauseFlagAudio = 0x4 }

Public static functions

static auto Get() -> cGameTimeManager*

Public functions

auto Pause(TimeManagerPause pauseType) -> int
Tries to pause the game with the given pause type (which might also pause effects or audio).
auto Resume(TimeManagerPause pauseType) -> int
Tries to resume the game by cancelling the given pause type.
auto Toggle(TimeManagerPause pauseType) -> bool
Pauses the given pause type if it is running, resumes it if it is paused.
auto GetPauseCount(TimeManagerPause pauseType) -> int
Returns how many Pause() have been called on the given pause type; returns 0 if game is running, greather than 0 if it is paused.
auto GetTimeAtStartOfFrame() -> LARGE_INTEGER
Returns the time that was registered at the start of the frame.
auto IsPaused() -> bool
Returns true if the game is paused, false if the game is running.
auto IsPausedEffects() -> bool
Returns true if effects are paused, false otherwise.
auto IsPausedAudio() -> bool
Returns true if audio is paused, false otherwise.
auto ConvertDeltaTime(int deltaMilliseconds) -> int
Called by the master Simulator system and Simulator game modes (creature, tribe, civ and space stage), to calculate the correct delta time.
auto SetSpeedFactors(float speed0, float speed1, float speed2, float speed3) -> void
Sets the different possible game speeds (but does not change the current speed!).
auto SetSpeed(int speedIndex) -> void
Changes the game speed to one of 4 possible values, which are specified by SetSpeedFactors().
auto GetSpeed() -> float
Returns the current game speed, a factor that is multiplied by the elapsed time every frame.

Public variables

float mSpeedFactors
The possible speed factors, set with SetSpeedFactors()
LARGE_INTEGER mBaseTimeElapsed
LARGE_INTEGER mTimeAtStartOfFrame
float mCurrentSpeed
int mCurrentSpeedIndex
int mFlags
A combination of current PauseFlags. If 0, game is unpaused; otherwise, use logical AND with PauseFlags.
eastl::map<TimeManagerPause, int> mPauseMaps
Maps each TimeManagerIdentifier to its index in mPauseTypes.
eastl::vector<PauseType> mPauseTypes
Keeps track of the different pause types.

Enum documentation

enum Simulator::cGameTimeManager::PauseFlags

Enumerators
kPauseFlag

Pauses game time if enabled.

kPauseFlagEffects

Pauses effects if enabled.

kPauseFlagAudio

Pauses audio if enabled.

Function documentation

int Simulator::cGameTimeManager::Pause(TimeManagerPause pauseType)

Tries to pause the game with the given pause type (which might also pause effects or audio).

Parameters
pauseType
Returns Current counter of pauseType pauses, 0 if still running, greather than 0 if paused

Internally, this increases the counter of how many times that type has been paused, so this does not necessarily pause the game (for example if Resume() has been called many times). Returns 0 if game is still running, or greater than 0 if game is paused.

int Simulator::cGameTimeManager::Resume(TimeManagerPause pauseType)

Tries to resume the game by cancelling the given pause type.

Parameters
pauseType
Returns Current counter of pauseType pauses, 0 if resumed, greather than 0 if still paused

Internally, this decreases the counter of how many times that type has been paused, so this does not necessarily resume the game (for example if Pause() has been called many times). Returns 0 if game was resumed.

bool Simulator::cGameTimeManager::Toggle(TimeManagerPause pauseType)

Pauses the given pause type if it is running, resumes it if it is paused.

Parameters
pauseType
Returns True if game is paused, false otherwise

If the internal pause count is not 0 or 1 (for example, Pause() has been called many times) it does nothing.

int Simulator::cGameTimeManager::ConvertDeltaTime(int deltaMilliseconds)

Called by the master Simulator system and Simulator game modes (creature, tribe, civ and space stage), to calculate the correct delta time.

Parameters
deltaMilliseconds Real elapsed time since the last frame, in milliseconds
Returns The simulated elapsed time

At the start of each frame there is an update method, with a parameter that specifies the elapsed time since the last frame in milliseconds; that's the delta time. ConvertDeltaTime() returns 0 if the game is paused, otherwise it returns the given time multiplied by the current game time speed.

void Simulator::cGameTimeManager::SetSpeedFactors(float speed0, float speed1, float speed2, float speed3)

Sets the different possible game speeds (but does not change the current speed!).

Parameters
speed0
speed1
speed2
speed3

By default, these are 1.0, 2.0, 4.0, 8.0

void Simulator::cGameTimeManager::SetSpeed(int speedIndex)

Changes the game speed to one of 4 possible values, which are specified by SetSpeedFactors().

Parameters
speedIndex A number from 0 to 3

By default, 0 sets the normal speed, 1 is 2.0x speed (so twice as fast), 2 is 4.0x speed, 3 is 8.0x speed.