TypedCommandBuffer.ixx File
Compile-time typed command buffer with handler routing. More...
Included Headers
#include "helios-engine-config.h"
#include <cassert>
#include <iostream>
#include <ostream>
#include <tuple>
#include <utility>
#include <vector>
#include <helios.engine.runtime.messaging.command.tags.CommandBufferRole>
#include <helios.engine.runtime.timing.TimerManager>
#include <helios.engine.runtime.messaging.command.CommandHandlerRegistry>
#include <helios.engine.state.commands.DelayedStateCommand>
#include <helios.engine.runtime.world.UpdateContext>
#include <helios.engine.runtime.timing.types>
#include <helios.engine.state.components>
Namespaces Index
| namespace | helios |
| namespace | engine |
| namespace | runtime |
| namespace | messaging |
| namespace | command |
Classes Index
| class | TypedCommandBuffer<CommandTypes> |
|
Compile-time typed command buffer with per-type queues and handler routing. More... | |
Description
Compile-time typed command buffer with handler routing.
File Listing
The file content with the documentation metadata removed is:
7#include "helios-engine-config.h"
29using namespace helios::engine::runtime::world;
30using namespace helios::engine::state::commands;
31using namespace helios::engine::runtime::timing;
32using namespace helios::engine::runtime::timing::types;
34export namespace helios::engine::runtime::messaging::command {
46 concept ExecutableCommand = requires(Cmd const& c, UpdateContext& updateContext) {
47 {c.execute(updateContext) } noexcept;
62 {c.timerId() } noexcept;
93 template <typename... CommandTypes>
94 class TypedCommandBuffer {
96 TimerManager* timerManager_;
98 CommandHandlerRegistry* commandHandlerRegistry_;
148 [[nodiscard]] bool shouldDelayCommand(const TimerState state) const noexcept {
161 [[nodiscard]] bool shouldDiscardCommand(const TimerState state) const noexcept {
172 [[nodiscard]] bool isDelayedCommandReady(const TimerState state) const noexcept {
214 void flushCommandQueue(UpdateContext& updateContext) noexcept {
218 auto& queue = commandQueue<CommandType>();
219 auto& delayed = delayedQueue<CommandType>();
220 delayed.clear();
226 if (commandHandlerRegistry_->has<CommandType>()) {
228 for (auto& cmd : queue) {
231 if (!timer) {
233 commandHandlerRegistry_->submit<CommandType>(cmd);
237 if (shouldDelayCommand(timer->state())) {
239 } else if (isDelayedCommandReady(timer->state())) {
240 commandHandlerRegistry_->submit<CommandType>(cmd);
241 } else if (shouldDiscardCommand(timer->state())) {
245 commandHandlerRegistry_->submit<CommandType>(cmd);
253 for (auto& cmd : queue) {
256 if (!timer) {
258 cmd.execute(updateContext);
262 if (shouldDelayCommand(timer->state())) {
264 } else if (isDelayedCommandReady(timer->state())) {
265 cmd.execute(updateContext);
266 } else if (shouldDiscardCommand(timer->state())) {
270 cmd.execute(updateContext);
276 std::cerr << "Command type is not executable" << HELIOS_FUNCTION_SIGNATURE << std::endl;
277 assert(false && "Command type is not executable");
283 queue.swap(delayed);
284 delayed.clear();
299 template<typename T, typename... Args>
302 queue.emplace_back(std::forward<Args>(args)...);
305 void init(CommandHandlerRegistry& commandHandlerRegistry, TimerManager& timerManager) noexcept {
307 timerManager_ = &timerManager;
326 void flush(UpdateContext& updateContext) noexcept {
327 (flushCommandQueue<CommandTypes>(updateContext), ...);
Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.