#include <tb_game_timer.h>
Public Types | |
typedef tbCore::uint32 | Milliseconds |
Public Member Functions | |
GameTimer (void) | |
GameTimer (const Milliseconds &valueMilliseconds) | |
GameTimer (const GameTimer &other) | |
~GameTimer (void) | |
GameTimer & | operator= (const GameTimer &other) |
bool | DecrementStep (void) |
bool | IncrementStep (const GameTimer &maximumValue=Infinity()) |
bool | IsZero (void) const |
const Milliseconds & | GetElapsedTime (void) const |
const Milliseconds & | GetRemainingTime (void) const |
float | GetPercentageOf (const GameTimer &timeValue) const |
TurtleBrains::Game::GameTimer | operator+ (const TurtleBrains::Game::GameTimer &right) const |
TurtleBrains::Game::GameTimer & | operator+= (const TurtleBrains::Game::GameTimer &right) |
TurtleBrains::Game::GameTimer | operator- (const TurtleBrains::Game::GameTimer &right) const |
TurtleBrains::Game::GameTimer & | operator-= (const TurtleBrains::Game::GameTimer &right) |
Static Public Member Functions | |
static GameTimer | Zero (void) |
static GameTimer | Infinity (void) |
static float | ToSeconds (const Milliseconds &valueMilliseconds) |
static Milliseconds | ToMilliseconds (const float &valueSeconds) |
static void | SetMillisecondsPerStep (const Milliseconds &millisecondsPerStep) |
static Milliseconds | GetMillisecondsPerStep (void) |
static float | GetSecondsPerStep (void) |
The GameTimer provides a simple interface for creating a timer to manually increment and decrement each Simulate() step for game logic. Internally milliseconds are stored and can be greater than or equal to zero allowing use cases to count the elapsed time since an event (by setting the timer to zero and incrementing each step), or to count down to some event.
The storage type of the milliseconds used internally in the GameTimer.
TurtleBrains::Game::GameTimer::GameTimer | ( | void | ) |
Constructs a GameTimer object with an internal value of 0 milliseconds elapsed/remaining.
TurtleBrains::Game::GameTimer::GameTimer | ( | const Milliseconds & | valueMilliseconds | ) |
Constructs a GameTimer object with the desired value in milliseconds.
valueMilliseconds | The initial value of the timer object, in milliseconds, to track time from. |
TurtleBrains::Game::GameTimer::GameTimer | ( | const GameTimer & | other | ) |
Copy constructor to create a GameTimer object from another object, copying all internal values.
TurtleBrains::Game::GameTimer::~GameTimer | ( | void | ) |
Destructs a GameTimer object, which is minimal since the timer does not need to release any resources.
bool TurtleBrains::Game::GameTimer::DecrementStep | ( | void | ) |
Decrement the value of the timer by the milliseconds in a single Simulate step and returns true if the internal value is now at 0, including if it was already at 0.
const Milliseconds& TurtleBrains::Game::GameTimer::GetElapsedTime | ( | void | ) | const |
Returns the value of the timer in milliseconds, typically used with a timer object that is counting upwards using IncrementStep() for clarity that some amount of time has passed.
|
static |
Returns the number of milliseconds per Simulate step in TurtleBrains as set by SetMillisecondsPerStep().
float TurtleBrains::Game::GameTimer::GetPercentageOf | ( | const GameTimer & | timeValue | ) | const |
Computes a percentage value from 0.0f to 1.0f where the timer object is between 0 and the timeValue passed in. If the internal milliseconds value is larger than that of the timeValue parameter, the returned percentage may be greater than 1.0f.
timeValue | The range of milliseconds representing "100 percent" or a return value of 1.0f. |
const Milliseconds& TurtleBrains::Game::GameTimer::GetRemainingTime | ( | void | ) | const |
Returns the value of the timer in milliseconds, typically used with a timer object that is counting down towards zero using DecrementStep() for clarity that some amount of time may be remaining.
|
static |
Returns the partial seconds per Simulate step in TurtleBrains as set by SetMillisecondsPerStep().
Increments the value of the timer by the milliseconds in a single Simulate step so that GetElapsedTime() can be used to track how long the timer has been running for. This will also prevent the timer from overflowing should it ever get large enough, or approach a value greater than maximumValue supplied. Returns true if the increment reached or stopped at the maximumValue during the call, false otherwise.
maximumValue | The highest value the timer can increment to, defaults to kInfinity, the maximum value possible. |
|
static |
A constant GameTimer object representing the maximum value for the timer, infinity.
bool TurtleBrains::Game::GameTimer::IsZero | ( | void | ) | const |
Checks if the timer is at zero returning true if it is or false it if the value is greater than 0.
Set the value of the GameTimer to the time value of another timer object.
|
static |
Changes the number of milliseconds per Simulate step in TurtleBrains.
millisecondsPerStep | The number of milliseconds that pass for each simulate step. 10 milliseconds is the default per step and results in Simulate being called at roughly 100hz. |
|
static |
Converts a time value from partial seconds to milliseconds, being returned as an integer type.
|
static |
Converts a value in milliseconds to a value in partial seconds, being returned as a floating point.