Skip to main content

TimerManager Class

Manager that owns game timers and processes timer control commands. More...

Declaration

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

Public Member Typedefs Index

usingEngineRoleTag = helios::engine::common::tags::ManagerRole

Public Member Functions Index

GameTimer &addGameTimer (GameTimerId gameTimerId) noexcept

Registers a new game timer. More...

GameTimer *gameTimer (const GameTimerId gameTimerId) noexcept

Returns a pointer to the timer with the given id. More...

std::span< GameTimer >gameTimers () noexcept

Returns a span over all registered timers. More...

voidflush (helios::engine::runtime::world::UpdateContext &updateContext) noexcept

Applies all pending timer control contexts. More...

boolsubmit (const TimerControlCommand timerControlCommand) noexcept

Enqueues a timer control command for deferred processing. More...

voidinit (helios::engine::runtime::world::GameWorld &gameWorld)

Registers this manager as the timer command handler in the game world. More...

voidreset ()

Resets all managed timers. More...

Private Member Functions Index

boolhas (const GameTimerId timerId) noexcept

Checks whether a timer with the given id exists. More...

GameTimer *getGameTimer (const GameTimerId timerId)

Looks up a timer by its id. More...

GameTimer &add (const GameTimerId gameTimerId) noexcept

Creates and appends a new timer. More...

Private Member Attributes Index

std::vector< GameTimer >gameTimers_

Collection of game timers managed by this manager. More...

std::vector< TimerControlContext >pendingControlContexts_

Pending timer control contexts to be applied during flush. More...

Description

Manager that owns game timers and processes timer control commands.

Pending control commands are collected via submit() and applied during flush() at the beginning of each frame.

See Also

GameTimer

See Also

TimerCommandHandler

See Also

Manager

Definition at line 50 of file TimerManager.ixx.

Public Member Typedefs

EngineRoleTag

using helios::engine::mechanics::timing::TimerManager::EngineRoleTag = helios::engine::common::tags::ManagerRole

Public Member Functions

addGameTimer()

GameTimer & helios::engine::mechanics::timing::TimerManager::addGameTimer (GameTimerId gameTimerId)
inline noexcept

Registers a new game timer.

Asserts that no timer with the given id already exists.

Parameters
gameTimerId

The unique id for the new timer.

Returns

Reference to the newly created GameTimer.

Definition at line 118 of file TimerManager.ixx.

118 GameTimer& addGameTimer(GameTimerId gameTimerId) noexcept {
119 assert(!has(gameTimerId) && "GameTimer with GameTimerId already registered");
120
121 return add(gameTimerId);
122 }

flush()

void helios::engine::mechanics::timing::TimerManager::flush (helios::engine::runtime::world::UpdateContext & updateContext)
inline noexcept

Applies all pending timer control contexts.

For each pending context, the corresponding timer's state is updated. The pending list is cleared after processing.

Parameters
gameWorld

Reference to the game world.

updateContext

Reference to the current update context.

Definition at line 153 of file TimerManager.ixx.

153 void flush(
155 ) noexcept {
156
157 for (const auto& controlContext : pendingControlContexts_) {
158 auto* timer = gameTimer(controlContext.gameTimerId);
159 if (timer) {
160 if (controlContext.resetElapsed) {
161 timer->reset(controlContext.timerState);
162 } else {
163 timer->setState(controlContext.timerState);
164 }
165 }
166 }
167 pendingControlContexts_.clear();
168 }

Reference gameTimer.

gameTimer()

GameTimer * helios::engine::mechanics::timing::TimerManager::gameTimer (const GameTimerId gameTimerId)
inline nodiscard noexcept

Returns a pointer to the timer with the given id.

Parameters
gameTimerId

The id to look up.

Returns

Pointer to the GameTimer, or nullptr if not found.

Definition at line 131 of file TimerManager.ixx.

131 [[nodiscard]] GameTimer* gameTimer(const GameTimerId gameTimerId) noexcept {
132 return getGameTimer(gameTimerId);
133 }

Referenced by flush and reset.

gameTimers()

std::span< GameTimer > helios::engine::mechanics::timing::TimerManager::gameTimers ()
inline nodiscard noexcept

Returns a span over all registered timers.

Returns

A span of GameTimer instances.

Definition at line 140 of file TimerManager.ixx.

140 [[nodiscard]] std::span<GameTimer> gameTimers() noexcept {
141 return gameTimers_;
142 }

init()

void helios::engine::mechanics::timing::TimerManager::init (helios::engine::runtime::world::GameWorld & gameWorld)
inline

Registers this manager as the timer command handler in the game world.

Parameters
gameWorld

The game world to register with.

Definition at line 187 of file TimerManager.ixx.

188 gameWorld.template registerCommandHandler<TimerControlCommand>(*this);
189 }

reset()

void helios::engine::mechanics::timing::TimerManager::reset ()
inline

Resets all managed timers.

Definition at line 194 of file TimerManager.ixx.

194 void reset() {
195 for (auto& gameTimer : gameTimers_) {
196 gameTimer.reset();
197 }
198 }

Reference gameTimer.

submit()

bool helios::engine::mechanics::timing::TimerManager::submit (const TimerControlCommand timerControlCommand)
inline noexcept

Enqueues a timer control command for deferred processing.

Parameters
timerControlCommand

The command to enqueue.

Returns

True if the command was accepted.

Definition at line 177 of file TimerManager.ixx.

177 bool submit(const TimerControlCommand timerControlCommand) noexcept {
178 pendingControlContexts_.push_back(timerControlCommand.timerControlContext());
179 return true;
180 };

Private Member Functions

add()

GameTimer & helios::engine::mechanics::timing::TimerManager::add (const GameTimerId gameTimerId)
inline noexcept

Creates and appends a new timer.

Parameters
gameTimerId

The id for the new timer.

Returns

Reference to the newly created timer.

Definition at line 100 of file TimerManager.ixx.

100 GameTimer& add(const GameTimerId gameTimerId) noexcept {
101 gameTimers_.emplace_back(GameTimer(gameTimerId));
102
103 return gameTimers_.back();
104 }

getGameTimer()

GameTimer * helios::engine::mechanics::timing::TimerManager::getGameTimer (const GameTimerId timerId)
inline

Looks up a timer by its id.

Parameters
timerId

The id to search for.

Returns

Pointer to the timer, or nullptr if not found.

Definition at line 80 of file TimerManager.ixx.

80 GameTimer* getGameTimer(const GameTimerId timerId) {
81 const auto timer = std::ranges::find_if(
82 gameTimers_,
83 [&](const auto& gameTimer) {
84 return gameTimer.gameTimerId() == timerId;
85 });
86
87 if (timer == gameTimers_.end()) {
88 return nullptr;
89 }
90 return &*timer;
91 }

has()

bool helios::engine::mechanics::timing::TimerManager::has (const GameTimerId timerId)
inline nodiscard noexcept

Checks whether a timer with the given id exists.

Parameters
timerId

The id to look up.

Returns

True if a timer with the given id is registered.

Definition at line 69 of file TimerManager.ixx.

69 [[nodiscard]] bool has(const GameTimerId timerId) noexcept {
70 return getGameTimer(timerId) != nullptr;
71 }

Private Member Attributes

gameTimers_

std::vector<GameTimer> helios::engine::mechanics::timing::TimerManager::gameTimers_

Collection of game timers managed by this manager.

Definition at line 55 of file TimerManager.ixx.

55 std::vector<GameTimer> gameTimers_;

pendingControlContexts_

std::vector<TimerControlContext> helios::engine::mechanics::timing::TimerManager::pendingControlContexts_

Pending timer control contexts to be applied during flush.

Definition at line 60 of file TimerManager.ixx.

60 std::vector<TimerControlContext> pendingControlContexts_;

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


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.