Skip to main content

CommandBuffer.ixx File

Type-erased command buffer wrapper using the Concept/Model pattern. More...

Included Headers

Namespaces Index

namespacehelios
namespaceengine
namespaceruntime
namespacemessaging
namespacecommand

Classes Index

classCommandBuffer

Type-erased wrapper for command buffers using the Concept/Model pattern. More...

classConcept

Internal virtual interface for type-erased dispatch. More...

classModel<T>

Typed model that adapts a concrete buffer to the Concept interface. More...

Description

Type-erased command buffer wrapper using the Concept/Model pattern.

File Listing

The file content with the documentation metadata removed is:

1
5module;
6
7#include <cassert>
8#include <memory>
9
10export module helios.engine.runtime.messaging.command.CommandBuffer;
11
12import helios.engine.runtime.world.UpdateContext;
13
14import helios.engine.runtime.messaging.command.concepts.IsCommandBufferLike;
15
16import helios.engine.runtime.timing.TimerManager;
17import helios.engine.runtime.messaging.command.CommandHandlerRegistry;
18
20using namespace helios::engine::runtime::messaging::command::concepts;
23
51
52 private:
53
57 class Concept {
58 public:
59 virtual ~Concept() = default;
60 virtual void flush(UpdateContext& updateContext) noexcept = 0;
61 virtual void clear() noexcept = 0;
62 virtual void init(CommandHandlerRegistry& commandHandlerRegistry, TimerManager& timerManager) noexcept = 0;
63
64 [[nodiscard]] virtual void* underlying() noexcept = 0;
65 [[nodiscard]] virtual const void* underlying() const noexcept = 0;
66 };
67
73 template<typename T>
74 class Model final : public Concept {
75
79 T cmdBuffer_;
80
81 public:
82
83 explicit Model(T cmdBuffer) : cmdBuffer_(std::move(cmdBuffer)) {}
84
85 void flush(UpdateContext& updateContext) noexcept override {
86 cmdBuffer_.flush(updateContext);
87 }
88
89 void init(CommandHandlerRegistry& commandHandlerRegistry, TimerManager& timerManager) noexcept override {
90 cmdBuffer_.init(commandHandlerRegistry, timerManager);
91 }
92
93 void clear() noexcept override {
94 cmdBuffer_.clear();
95 }
96
97 void* underlying() noexcept override {
98 return &cmdBuffer_;
99 }
100
101 const void* underlying() const noexcept override {
102 return &cmdBuffer_;
103 }
104 };
105
109 std::unique_ptr<Concept> pimpl_;
110
111 public:
112
113 CommandBuffer() = default;
114
125 template<typename T>
127 explicit CommandBuffer(T cmdBuffer) : pimpl_(std::make_unique<Model<T>>(std::move(cmdBuffer))) {}
128
129 CommandBuffer(const CommandBuffer&) = delete;
131
134
148 assert(pimpl_ && "CommandBuffer not initialized");
149 pimpl_->flush(updateContext);
150 }
151
157 void clear() noexcept {
158 assert(pimpl_ && "CommandBuffer not initialized");
159 pimpl_->clear();
160 }
161
162 void init(CommandHandlerRegistry& commandHandlerRegistry, TimerManager& timerManager) noexcept {
163 assert(pimpl_ && "CommandBuffer not initialized");
164 pimpl_->init(commandHandlerRegistry, timerManager);
165 }
166
175 assert(pimpl_ && "CommandBuffer not initialized");
176 return pimpl_->underlying();
177 }
178
182 [[nodiscard]] const void* underlying() const noexcept {
183 assert(pimpl_ && "CommandBuffer not initialized");
184 return pimpl_->underlying();
185 }
186
187 };
188
189
190}
191

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.