Skip to main content

System.ixx File

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

Included Headers

Namespaces Index

namespacehelios
namespaceengine
namespaceruntime
namespaceworld

Classes Index

classSystem

Type-erased wrapper for game logic processors. More...

classConcept

Internal virtual interface for type erasure. More...

classModel<T>

Typed wrapper that adapts a concrete system to the Concept interface. More...

Description

Type-erased system 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.world.System;
11
12
13import helios.engine.runtime.world.UpdateContext;
14import helios.engine.runtime.world.GameWorld;
15
16import helios.engine.runtime.world.concepts;
17
19using namespace helios::engine::runtime::world::concepts;
20export namespace helios::engine::runtime::world {
21
22
44 class System {
45
46 private:
50 class Concept {
51 public:
52
53 virtual ~Concept() = default;
54 virtual void update(UpdateContext& updateContext) noexcept = 0;
55 virtual void* underlying() noexcept = 0;
56 virtual const void* underlying() const noexcept = 0;
57 };
58
64 template<typename T>
65 class Model final : public Concept {
66 T system_;
67 void* injectedBuffer_{nullptr};
68 public:
69
70 explicit Model(T sys, void* buffer = nullptr)
71 : system_(std::move(sys)), injectedBuffer_(buffer) {}
72
73 void update(UpdateContext& ctx) noexcept override {
74 if constexpr (requires { typename T::CommandBuffer_type; }) {
75 using BufT = typename T::CommandBuffer_type;
76 system_.update(ctx, *static_cast<BufT*>(injectedBuffer_));
77 } else {
78 system_.update(ctx);
79 }
80 }
81
82 void* underlying() noexcept override {
83 return &system_;
84 }
85
86 const void* underlying() const noexcept override {
87 return &system_;
88 }
89 };
90
91 std::unique_ptr<Concept> pimpl_;
92
93 public:
94
98 System() = default;
99
109 template<typename T>
110 requires IsSystemLike<T>
111 explicit System(T system, void* buffer = nullptr)
112 : pimpl_(std::make_unique<Model<T>>(std::move(system), buffer))
113 {}
114
115 System(const System&) = delete;
116 System& operator=(const System&) = delete;
117
118 System& operator=(System&&) = default;
120
121
122
131 assert(pimpl_ && "System not initialized");
132 pimpl_->update(updateContext);
133 }
134
135
144 assert(pimpl_ && "System not initialized");
145 return pimpl_->underlying();
146 }
147
151 [[nodiscard]] const void* underlying() const noexcept {
152 assert(pimpl_ && "System not initialized");
153 return pimpl_->underlying();
154 }
155
156 };
157
158
159}

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.