Skip to main content

GameTimer Class

A game timer identified by a GameTimerId. More...

Declaration

class helios::engine::mechanics::timing::GameTimer { ... }

Public Constructors Index

GameTimer (const helios::engine::core::data::GameTimerId gameTimerId)

Constructs a GameTimer with the given identifier. More...

Public Member Functions Index

helios::engine::core::data::GameTimerIdgameTimerId () const noexcept

Returns the timer identifier. More...

voidreset () noexcept

Resets the elapsed time to zero. More...

voidsetDuration (float duration)

Sets the duration limit. More...

floatduration () const noexcept

Returns the duration limit. More...

floatelapsed () const noexcept

Returns the accumulated elapsed time. More...

TimerStatestate () const noexcept

Returns the current timer state. More...

voidsetState (const TimerState state) noexcept

Sets the timer state. More...

boolshouldUpdate () const noexcept

Returns whether this timer should accumulate time. More...

TimerRevisiontimerRevision () const noexcept

Returns the current revision counter. More...

voidupdate (const float ft)

Advances the timer by the given frame time. More...

Private Member Attributes Index

TimerRevisiontimerRevision_ {}

Monotonically increasing revision counter, incremented on each update. More...

GameTimerIdgameTimerId_

Unique identifier for this timer. More...

floatelapsed_ {}

Accumulated elapsed time in seconds. More...

TimerStatetimerState_ {}

Current state of the timer. More...

floatduration_ = 0.0f

Optional duration limit in seconds. More...

Description

A game timer identified by a GameTimerId.

Tracks elapsed time while in the Started state. Each update increments a revision counter that observers can use to detect changes.

See Also

TimerManager

See Also

GameTimerBindingComponent

Definition at line 27 of file GameTimer.ixx.

Public Constructors

GameTimer()

helios::engine::mechanics::timing::GameTimer::GameTimer (const helios::engine::core::data::GameTimerId gameTimerId)
inline explicit

Constructs a GameTimer with the given identifier.

Parameters
gameTimerId

The unique identifier for this timer.

Definition at line 61 of file GameTimer.ixx.

Reference gameTimerId.

Public Member Functions

duration()

float helios::engine::mechanics::timing::GameTimer::duration ()
inline nodiscard noexcept

Returns the duration limit.

Returns

The duration in seconds.

Definition at line 94 of file GameTimer.ixx.

94 [[nodiscard]] float duration() const noexcept {
95 return duration_;
96 }

Referenced by setDuration.

elapsed()

float helios::engine::mechanics::timing::GameTimer::elapsed ()
inline nodiscard noexcept

Returns the accumulated elapsed time.

Returns

Elapsed time in seconds.

Definition at line 103 of file GameTimer.ixx.

103 [[nodiscard]] float elapsed() const noexcept {
104 return elapsed_;
105 }

gameTimerId()

helios::engine::core::data::GameTimerId helios::engine::mechanics::timing::GameTimer::gameTimerId ()
inline nodiscard noexcept

Returns the timer identifier.

Returns

The GameTimerId assigned to this timer.

Definition at line 69 of file GameTimer.ixx.

69 [[nodiscard]] helios::engine::core::data::GameTimerId gameTimerId() const noexcept {
70 return gameTimerId_;
71 }

Referenced by GameTimer.

reset()

void helios::engine::mechanics::timing::GameTimer::reset ()
inline noexcept

Resets the elapsed time to zero.

Definition at line 76 of file GameTimer.ixx.

76 void reset() noexcept {
77 elapsed_ = 0.0f;
78 }

setDuration()

void helios::engine::mechanics::timing::GameTimer::setDuration (float duration)
inline

Sets the duration limit.

Parameters
duration

Duration in seconds.

Definition at line 85 of file GameTimer.ixx.

85 void setDuration(float duration) {
86 duration_ = duration;
87 }

Reference duration.

setState()

void helios::engine::mechanics::timing::GameTimer::setState (const TimerState state)
inline noexcept

Sets the timer state.

Parameters
state

The new TimerState.

Definition at line 121 of file GameTimer.ixx.

121 void setState(const TimerState state) noexcept {
122 timerState_ = state;
123 }

Reference state.

shouldUpdate()

bool helios::engine::mechanics::timing::GameTimer::shouldUpdate ()
inline nodiscard noexcept

Returns whether this timer should accumulate time.

Returns

True if the timer is in the Started state.

Definition at line 130 of file GameTimer.ixx.

130 [[nodiscard]] bool shouldUpdate() const noexcept {
131 return (timerState_ == TimerState::Started);
132 }

Reference helios::engine::mechanics::timing::types::Started.

Referenced by update.

state()

TimerState helios::engine::mechanics::timing::GameTimer::state ()
inline nodiscard noexcept

Returns the current timer state.

Returns

The current TimerState.

Definition at line 112 of file GameTimer.ixx.

112 [[nodiscard]] TimerState state() const noexcept {
113 return timerState_;
114 }

Referenced by setState.

timerRevision()

TimerRevision helios::engine::mechanics::timing::GameTimer::timerRevision ()
inline nodiscard noexcept

Returns the current revision counter.

Returns

The TimerRevision value.

Definition at line 139 of file GameTimer.ixx.

139 [[nodiscard]] TimerRevision timerRevision() const noexcept {
140 return timerRevision_;
141 }

update()

void helios::engine::mechanics::timing::GameTimer::update (const float ft)
inline

Advances the timer by the given frame time.

Only accumulates time when the timer is in the Started state. Increments the revision counter on each successful update.

Parameters
ft

Frame time in seconds.

Definition at line 151 of file GameTimer.ixx.

151 void update(const float ft) {
152 if (!shouldUpdate() || ft == 0.0f) {
153 return;
154 }
155 timerRevision_++;
156 elapsed_ += ft;
157 }

Reference shouldUpdate.

Private Member Attributes

duration_

float helios::engine::mechanics::timing::GameTimer::duration_ = 0.0f

Optional duration limit in seconds.

Definition at line 52 of file GameTimer.ixx.

52 float duration_ = 0.0f;

elapsed_

float helios::engine::mechanics::timing::GameTimer::elapsed_ {}

Accumulated elapsed time in seconds.

Definition at line 42 of file GameTimer.ixx.

42 float elapsed_{};

gameTimerId_

GameTimerId helios::engine::mechanics::timing::GameTimer::gameTimerId_

Unique identifier for this timer.

Definition at line 37 of file GameTimer.ixx.

37 GameTimerId gameTimerId_;

timerRevision_

TimerRevision helios::engine::mechanics::timing::GameTimer::timerRevision_ {}

Monotonically increasing revision counter, incremented on each update.

Definition at line 32 of file GameTimer.ixx.

32 TimerRevision timerRevision_{};

timerState_

TimerState helios::engine::mechanics::timing::GameTimer::timerState_ {}

Current state of the timer.

Definition at line 47 of file GameTimer.ixx.

47 TimerState timerState_{};

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


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.