Skip to main content

TimerManager Class

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

Declaration

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

Public Member Typedefs Index

usingEngineRoleTag = helios::engine::runtime::world::tags::ManagerRole

Public Member Functions Index

Timer &addTimer (TimerId timerId) noexcept

Registers a new game timer. More...

Timer *getTimer (const TimerId timerId)

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

std::span< Timer >timers () 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::messaging::command::CommandHandlerRegistry &commandHandlerRegistry)

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 TimerId timerId) noexcept

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

Timer &add (const TimerId timerId) noexcept

Creates and appends a new timer. More...

Private Member Attributes Index

std::vector< Timer >timers_

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

Timer

See Also

TimerCommandHandler

See Also

Manager

Definition at line 47 of file TimerManager.ixx.

Public Member Typedefs

EngineRoleTag

using helios::engine::runtime::timing::TimerManager::EngineRoleTag = helios::engine::runtime::world::tags::ManagerRole

Public Member Functions

addTimer()

Timer & helios::engine::runtime::timing::TimerManager::addTimer (TimerId timerId)
inline noexcept

Registers a new game timer.

Asserts that no timer with the given id already exists.

Parameters
timerId

The unique id for the new timer.

Returns

Reference to the newly created Timer.

Definition at line 96 of file TimerManager.ixx.

96 Timer& addTimer(TimerId timerId) noexcept {
97 assert(!has(timerId) && "Timer with TimerId already registered");
98
99 return add(timerId);
100 }

Reference helios::engine::runtime::registerComponents.

flush()

void helios::engine::runtime::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 140 of file TimerManager.ixx.

140 void flush(
142 ) noexcept {
143
144 for (const auto& controlContext : pendingControlContexts_) {
145 auto* timer = getTimer(controlContext.timerId);
146 if (timer) {
147 if (controlContext.resetElapsed) {
148 timer->reset(controlContext.timerState);
149 } else {
150 timer->setState(controlContext.timerState);
151 }
152 }
153 }
154 pendingControlContexts_.clear();
155 }

References getTimer and helios::engine::runtime::registerComponents.

getTimer()

Timer * helios::engine::runtime::timing::TimerManager::getTimer (const TimerId 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 109 of file TimerManager.ixx.

109 Timer* getTimer(const TimerId timerId) {
110 const auto timerIt = std::ranges::find_if(
111 timers_,
112 [&](const auto& timer) {
113 return timer.timerId() == timerId;
114 });
115
116 if (timerIt == timers_.end()) {
117 return nullptr;
118 }
119 return &*timerIt;
120 }

Reference helios::engine::runtime::registerComponents.

Referenced by flush.

init()

void helios::engine::runtime::timing::TimerManager::init (helios::engine::runtime::messaging::command::CommandHandlerRegistry & commandHandlerRegistry)
inline

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

Parameters
gameWorld

The game world to register with.

Definition at line 174 of file TimerManager.ixx.

175 commandHandlerRegistry.registerHandler<TimerControlCommand>(*this);
176 }

Reference helios::engine::runtime::messaging::command::CommandHandlerRegistry::registerHandler.

reset()

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

Resets all managed timers.

Definition at line 181 of file TimerManager.ixx.

181 void reset() {
182 for (auto& timer : timers_) {
183 timer.reset();
184 }
185 }

Reference helios::engine::runtime::registerComponents.

submit()

bool helios::engine::runtime::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 164 of file TimerManager.ixx.

165 pendingControlContexts_.push_back(timerControlCommand.timerControlContext());
166 return true;
167 };

Reference helios::engine::runtime::registerComponents.

timers()

std::span< Timer > helios::engine::runtime::timing::TimerManager::timers ()
inline noexcept

Returns a span over all registered timers.

Returns

A span of Timer instances.

Definition at line 127 of file TimerManager.ixx.

127 [[nodiscard]] std::span<Timer> timers() noexcept {
128 return timers_;
129 }

Referenced by helios::engine::runtime::timing::systems::TimerClearSystem::update and helios::engine::runtime::timing::systems::TimerUpdateSystem< TCommandBuffer >::update.

Private Member Functions

add()

Timer & helios::engine::runtime::timing::TimerManager::add (const TimerId timerId)
inline noexcept

Creates and appends a new timer.

Parameters
timerId

The id for the new timer.

Returns

Reference to the newly created timer.

Definition at line 78 of file TimerManager.ixx.

78 Timer& add(const TimerId timerId) noexcept {
79 timers_.emplace_back(Timer(timerId));
80
81 return timers_.back();
82 }

has()

bool helios::engine::runtime::timing::TimerManager::has (const TimerId timerId)
inline 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 66 of file TimerManager.ixx.

66 [[nodiscard]] bool has(const TimerId timerId) noexcept {
67 return getTimer(timerId) != nullptr;
68 }

Private Member Attributes

pendingControlContexts_

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

Pending timer control contexts to be applied during flush.

Definition at line 57 of file TimerManager.ixx.

57 std::vector<TimerControlContext> pendingControlContexts_;

timers_

std::vector<Timer> helios::engine::runtime::timing::TimerManager::timers_

Collection of game timers managed by this manager.

Definition at line 52 of file TimerManager.ixx.

52 std::vector<Timer> timers_;

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


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.