Skip to main content

TypedCommandBuffer Class Template

Compile-time typed command buffer with per-type queues and handler routing. More...

Declaration

template <typename... CommandTypes> class helios::engine::runtime::messaging::command::TypedCommandBuffer<CommandTypes> { ... }

Public Member Typedefs Index

template <typename... CommandTypes>
usingEngineRoleTag = helios::engine::runtime::world::tags::CommandBufferRole

Public Member Functions Index

template <typename T, typename... Args>
voidadd (Args &&... args)

Enqueues a command of the specified type. More...

template <typename... CommandTypes>
voidinit (CommandHandlerRegistry &commandHandlerRegistry, TimerManager &timerManager) noexcept
template <typename... CommandTypes>
voidclear () noexcept

Discards all queued commands without executing them. More...

template <typename... CommandTypes>
voidflush (UpdateContext &updateContext) noexcept

Flushes all command queues in template parameter order. More...

Private Member Functions Index

template <typename CommandType>
auto commandQueue () noexcept -> std::vector< CommandType > &

Returns the queue for a specific command type. More...

template <typename CommandType>
auto delayedQueue () noexcept -> std::vector< CommandType > &

Returns the delayed scratch queue for a specific command type. More...

template <typename... CommandTypes>
boolshouldDelayCommand (const TimerState state) const noexcept

Determines whether a delayed command should be deferred. More...

template <typename... CommandTypes>
boolshouldDiscardCommand (const TimerState state) const noexcept

Determines whether a delayed command should be discarded. More...

template <typename... CommandTypes>
boolisDelayedCommandReady (const TimerState state) const noexcept

Determines whether a delayed command is ready for dispatch. More...

template <typename CommandType>
voidflushCommandQueue (UpdateContext &updateContext) noexcept

Flushes a single command queue. More...

Private Member Attributes Index

template <typename... CommandTypes>
TimerManager *timerManager_
template <typename... CommandTypes>
CommandHandlerRegistry *commandHandlerRegistry_
template <typename... CommandTypes>
std::tuple< std::vector< CommandTypes >... >commandQueues_

Per-type command queues stored as a tuple of vectors. More...

template <typename... CommandTypes>
std::tuple< std::vector< CommandTypes >... >delayedQueues_

Scratch queues for timer-gated commands surviving a flush cycle. More...

Description

Compile-time typed command buffer with per-type queues and handler routing.

TypedCommandBuffer stores commands in separate std::vector queues, one per command type, packed into a std::tuple. This provides:

  • Zero-overhead dispatch: Command types are known at compile time, eliminating virtual dispatch for queue access.
  • Deterministic ordering: Commands are flushed in the order of the template parameter list, ensuring reproducible execution.
  • Handler-or-execute routing: During flush, each command is either routed to a registered handler or executed directly via its execute() method (if it satisfies ExecutableCommand).

Definition at line 94 of file TypedCommandBuffer.ixx.

Public Member Typedefs

EngineRoleTag

template <typename... CommandTypes>
using helios::engine::runtime::messaging::command::TypedCommandBuffer< CommandTypes >::EngineRoleTag = helios::engine::runtime::world::tags::CommandBufferRole

Public Member Functions

add()

template <typename T, typename... Args>
void helios::engine::runtime::messaging::command::TypedCommandBuffer< CommandTypes >::add (Args &&... args)
inline

Enqueues a command of the specified type.

Template Parameters
T

The command type. Must be one of the CommandTypes.

Args

Constructor argument types.

Parameters
args

Arguments forwarded to the command constructor.

Definition at line 300 of file TypedCommandBuffer.ixx.

300 void add(Args&&... args) {
301 auto& queue = std::get<std::vector<T>>(commandQueues_);
302 queue.emplace_back(std::forward<Args>(args)...);
303 }

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

clear()

template <typename... CommandTypes>
void helios::engine::runtime::messaging::command::TypedCommandBuffer< CommandTypes >::clear ()
inline noexcept

Discards all queued commands without executing them.

Definition at line 313 of file TypedCommandBuffer.ixx.

313 void clear() noexcept {
314 std::apply([](auto&... queue) { (queue.clear(), ...); }, commandQueues_);
315 }

flush()

template <typename... CommandTypes>
void helios::engine::runtime::messaging::command::TypedCommandBuffer< CommandTypes >::flush (UpdateContext & updateContext)
inline noexcept

Flushes all command queues in template parameter order.

Iterates through each command type using a fold expression, flushing queues in the order specified by the template parameters.

Parameters
gameWorld

The game world for which the queue should be flushed.

updateContext

The current frame's update context.

Definition at line 326 of file TypedCommandBuffer.ixx.

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

init()

template <typename... CommandTypes>
void helios::engine::runtime::messaging::command::TypedCommandBuffer< CommandTypes >::init (CommandHandlerRegistry & commandHandlerRegistry, TimerManager & timerManager)
inline noexcept

Definition at line 305 of file TypedCommandBuffer.ixx.

305 void init(CommandHandlerRegistry& commandHandlerRegistry, TimerManager& timerManager) noexcept {
306 commandHandlerRegistry_ = &commandHandlerRegistry;
307 timerManager_ = &timerManager;
308 }

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

Private Member Functions

commandQueue()

template <typename CommandType>
std::vector< CommandType > & helios::engine::runtime::messaging::command::TypedCommandBuffer< CommandTypes >::commandQueue ()
inline noexcept

Returns the queue for a specific command type.

Template Parameters
CommandType

The command type.

Returns

Reference to the command queue.

Definition at line 122 of file TypedCommandBuffer.ixx.

122 std::vector<CommandType>& commandQueue() noexcept {
123 return std::get<std::vector<CommandType>>(commandQueues_);
124 }

delayedQueue()

template <typename CommandType>
std::vector< CommandType > & helios::engine::runtime::messaging::command::TypedCommandBuffer< CommandTypes >::delayedQueue ()
inline noexcept

Returns the delayed scratch queue for a specific command type.

Template Parameters
CommandType

The command type.

Returns

Reference to the delayed scratch queue.

Definition at line 134 of file TypedCommandBuffer.ixx.

134 std::vector<CommandType>& delayedQueue() noexcept {
135 return std::get<std::vector<CommandType>>(delayedQueues_);
136 }

flushCommandQueue()

template <typename CommandType>
void helios::engine::runtime::messaging::command::TypedCommandBuffer< CommandTypes >::flushCommandQueue (UpdateContext & updateContext)
inline noexcept

Flushes a single command queue.

Processing follows two branches depending on whether a handler is registered for CommandType:

Handler registered (CommandHandlerRegistry::has<CommandType>()):

  • Each command is forwarded via commandHandlerRegistry.submit<CommandType>(cmd).

No handler registered (fallback):

  • The command must satisfy ExecutableCommand; otherwise an assertion fires at runtime.
  • Each command is dispatched via cmd.execute(updateContext).

In both branches, if CommandType satisfies DelayedCommandLike, an additional timer check is performed per command:

  1. The associated Timer is looked up via the command's timerId().
  2. If the timer is still running (shouldDelayCommand returns true), the command is moved into the scratch queue and survives the current flush cycle.
  3. If the timer has finished (isDelayedCommandReady returns true), the command is dispatched normally.
  4. If the timer state is Undefined (e.g. timer was removed), the command is silently dropped.

After all commands have been processed the primary queue is cleared, the scratch queue contents are swapped back in as the new primary queue, and the scratch queue is cleared.

Template Parameters
CommandType

The command type to flush.

Parameters
gameWorld

The game world providing the CommandHandlerRegistry and TimerManager.

updateContext

The current frame's update context.

Definition at line 214 of file TypedCommandBuffer.ixx.

214 void flushCommandQueue(UpdateContext& updateContext) noexcept {
215
216 //auto& timerManager = gameWorld.manager<TimerManager>();
217
218 auto& queue = commandQueue<CommandType>();
220 delayed.clear();
221
222 if (queue.empty()) {
223 return;
224 }
225
226 if (commandHandlerRegistry_->has<CommandType>()) {
227
228 for (auto& cmd : queue) {
229 if constexpr (DelayedCommandLike<CommandType>) {
230 auto* timer = timerManager_->getTimer(cmd.timerId());
231 if (!timer) {
232 assert(timer && "Unexpected null game timer");
233 commandHandlerRegistry_->submit<CommandType>(cmd);
234 continue;
235 }
236
237 if (shouldDelayCommand(timer->state())) {
238 delayed.push_back(std::move(cmd));
239 } else if (isDelayedCommandReady(timer->state())) {
240 commandHandlerRegistry_->submit<CommandType>(cmd);
241 } else if (shouldDiscardCommand(timer->state())) {
242 // cancelled? Discard! intentionally noop
243 }
244 } else {
245 commandHandlerRegistry_->submit<CommandType>(cmd);
246 }
247 }
248
249
250 } else {
251 if constexpr (ExecutableCommand<CommandType>) {
252
253 for (auto& cmd : queue) {
254 if constexpr (DelayedCommandLike<CommandType>) {
255 auto* timer = timerManager_->getTimer(cmd.timerId());
256 if (!timer) {
257 assert(timer && "Unexpected null game timer");
258 cmd.execute(updateContext);
259 continue;
260 }
261
262 if (shouldDelayCommand(timer->state())) {
263 delayed.push_back(std::move(cmd));
264 } else if (isDelayedCommandReady(timer->state())) {
265 cmd.execute(updateContext);
266 } else if (shouldDiscardCommand(timer->state())) {
267 // cancelled? Discard! intentionally noop
268 }
269 } else {
270 cmd.execute(updateContext);
271 }
272
273 }
274
275 } else {
276 std::cerr << "Command type is not executable" << HELIOS_FUNCTION_SIGNATURE << std::endl;
277 assert(false && "Command type is not executable");
278 }
279
280 }
281
282 queue.clear();
283 queue.swap(delayed);
284 delayed.clear();
285 }

isDelayedCommandReady()

template <typename... CommandTypes>
bool helios::engine::runtime::messaging::command::TypedCommandBuffer< CommandTypes >::isDelayedCommandReady (const TimerState state)
inline noexcept

Determines whether a delayed command is ready for dispatch.

Parameters
state

The current timer state.

Returns

True if the associated timer has finished.

Definition at line 172 of file TypedCommandBuffer.ixx.

172 [[nodiscard]] bool isDelayedCommandReady(const TimerState state) const noexcept {
173 return state == TimerState::Finished;
174 }

shouldDelayCommand()

template <typename... CommandTypes>
bool helios::engine::runtime::messaging::command::TypedCommandBuffer< CommandTypes >::shouldDelayCommand (const TimerState state)
inline noexcept

Determines whether a delayed command should be deferred.

Returns true when the timer is still running - i.e. its state is neither Finished nor Undefined.

Parameters
state

The current timer state.

Returns

True if the command must remain in the scratch queue.

Definition at line 148 of file TypedCommandBuffer.ixx.

148 [[nodiscard]] bool shouldDelayCommand(const TimerState state) const noexcept {
149 return state == TimerState::Running;
150 }

shouldDiscardCommand()

template <typename... CommandTypes>
bool helios::engine::runtime::messaging::command::TypedCommandBuffer< CommandTypes >::shouldDiscardCommand (const TimerState state)
inline noexcept

Determines whether a delayed command should be discarded.

Returns true when the timer is not in state Running or Finished..

Parameters
state

The current timer state.

Returns

True if the command should be discarded.

Definition at line 161 of file TypedCommandBuffer.ixx.

161 [[nodiscard]] bool shouldDiscardCommand(const TimerState state) const noexcept {
162 return state != TimerState::Running && state != TimerState::Finished;;
163 }

Private Member Attributes

commandHandlerRegistry_

template <typename... CommandTypes>
CommandHandlerRegistry* helios::engine::runtime::messaging::command::TypedCommandBuffer< CommandTypes >::commandHandlerRegistry_

Definition at line 98 of file TypedCommandBuffer.ixx.

98 CommandHandlerRegistry* commandHandlerRegistry_;

commandQueues_

template <typename... CommandTypes>
std::tuple<std::vector<CommandTypes>...> helios::engine::runtime::messaging::command::TypedCommandBuffer< CommandTypes >::commandQueues_

Per-type command queues stored as a tuple of vectors.

Definition at line 103 of file TypedCommandBuffer.ixx.

103 std::tuple<std::vector<CommandTypes>...> commandQueues_;

delayedQueues_

template <typename... CommandTypes>
std::tuple<std::vector<CommandTypes>...> helios::engine::runtime::messaging::command::TypedCommandBuffer< CommandTypes >::delayedQueues_

Scratch queues for timer-gated commands surviving a flush cycle.

Commands satisfying DelayedCommandLike whose timer has not yet finished are moved here during flush and swapped back into the primary queues afterwards.

Definition at line 112 of file TypedCommandBuffer.ixx.

112 std::tuple<std::vector<CommandTypes>...> delayedQueues_;

timerManager_

template <typename... CommandTypes>
TimerManager* helios::engine::runtime::messaging::command::TypedCommandBuffer< CommandTypes >::timerManager_

Definition at line 96 of file TypedCommandBuffer.ixx.

96 TimerManager* timerManager_;

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


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.