Helios Engine
A modular ECS based data-oriented C++23 game engine framework
Loading...
Searching...
No Matches
system_set_handle.hpp
Go to the documentation of this file.
1#pragma once
2
7
8#include <functional>
9#include <string>
10
11namespace helios::ecs {
12
13class Schedule;
14class SystemHandle;
16
17/// @brief Handle returned by Schedule::Set for configuring a named system set.
19public:
20 /**
21 * @brief Constructs a `SystemSetHandle` with the given system set id and
22 * schedule.
23 * @param id The system set id
24 * @param schedule The schedule that the system set belongs to
25 */
26 constexpr SystemSetHandle(SystemSetId id, Schedule& schedule) noexcept
27 : id_(id), schedule_(schedule) {}
28
30 constexpr SystemSetHandle(SystemSetHandle&&) noexcept = default;
31 constexpr ~SystemSetHandle() noexcept = default;
32
33 SystemSetHandle& operator=(const SystemSetHandle&) = delete;
34 constexpr SystemSetHandle& operator=(SystemSetHandle&&) noexcept = default;
35
36 /**
37 * @brief Adds an ordering constraint: all members of this set must run before
38 * the given system.
39 * @param target System id that this set must precede
40 * @return Reference to this handle for chaining
41 */
42 constexpr auto Before(this auto&& self, SystemId target)
43 -> decltype(std::forward<decltype(self)>(self));
44
45 /**
46 * @brief Adds an ordering constraint: all members of this set must run
47 * before the given system type.
48 * @tparam T System type satisfying `SystemTrait`
49 * @return Reference to this handle for chaining
50 */
51 template <SystemTrait T>
52 constexpr auto Before(this auto&& self)
53 -> decltype(std::forward<decltype(self)>(self)) {
54 return std::forward<decltype(self)>(self).Before(SystemId::From<T>());
55 }
56
57 /**
58 * @brief Adds an ordering constraint: all members of this set must run before
59 * the given system handle.
60 * @param target System handle that this set must precede
61 * @return Reference to this handle for chaining
62 */
63 constexpr auto Before(this auto&& self, const SystemHandle& target)
64 -> decltype(std::forward<decltype(self)>(self)) {
65 return std::forward<decltype(self)>(self).Before(target.Id().id);
66 }
67
68 /**
69 * @brief Adds an ordering constraint: all members of this set must run
70 * before all members of the given set.
71 * @param target Set id that this set must precede
72 * @return Reference to this handle for chaining
73 */
74 constexpr auto Before(this auto&& self, SystemSetId target)
75 -> decltype(std::forward<decltype(self)>(self));
76
77 /**
78 * @brief Adds an ordering constraint: all members of this set must run before
79 * all members of the given set type.
80 * @tparam T Set type satisfying `SystemSetTrait`
81 * @return Reference to this handle for chaining
82 */
83 template <SystemSetTrait T>
84 constexpr auto BeforeSet(this auto&& self)
85 -> decltype(std::forward<decltype(self)>(self)) {
86 return std::forward<decltype(self)>(self).Before(SystemSetId::From<T>());
87 }
88
89 /**
90 * @brief Adds an ordering constraint: all members of this set must run before
91 * the given system set handle.
92 * @param target System set handle that this set must precede
93 * @return Reference to this handle for chaining
94 */
95 constexpr auto Before(this auto&& self, const SystemSetHandle& target)
96 -> decltype(std::forward<decltype(self)>(self)) {
97 return std::forward<decltype(self)>(self).Before(target.Id());
98 }
99
100 /**
101 * @brief Adds an ordering constraint: all members of this set must run before
102 * all members of the given system group.
103 * @param target System group handle that this set must precede
104 * @return Reference to this handle for chaining
105 */
106 constexpr auto Before(this auto&& self, const SystemGroupHandle& target)
107 -> decltype(std::forward<decltype(self)>(self));
108
109 /**
110 * @brief Adds an ordering constraint: all members of this set must run after
111 * the given system.
112 * @param target System id that this set must follow
113 * @return Reference to this handle for chaining
114 */
115 constexpr auto After(this auto&& self, SystemId target)
116 -> decltype(std::forward<decltype(self)>(self));
117
118 /**
119 * @brief Adds an ordering constraint: all members of this set must run after
120 * the given system type.
121 * @tparam T System type satisfying `SystemTrait`
122 * @return Reference to this handle for chaining
123 */
124 template <SystemTrait T>
125 constexpr auto After(this auto&& self)
126 -> decltype(std::forward<decltype(self)>(self)) {
127 return std::forward<decltype(self)>(self).After(SystemId::From<T>());
128 }
129
130 /**
131 * @brief Adds an ordering constraint: all members of this set must run after
132 * the given system handle.
133 * @param target System handle that this set must follow
134 * @return Reference to this handle for chaining
135 */
136 constexpr auto After(this auto&& self, const SystemHandle& target)
137 -> decltype(std::forward<decltype(self)>(self)) {
138 return std::forward<decltype(self)>(self).After(target.Id().id);
139 }
140
141 /**
142 * @brief Adds an ordering constraint: all members of this set must run after
143 * all members of the given set.
144 * @param target Set id that this set must follow
145 * @return Reference to this handle for chaining
146 */
147 constexpr auto After(this auto&& self, SystemSetId target)
148 -> decltype(std::forward<decltype(self)>(self));
149
150 /**
151 * @brief Adds an ordering constraint: all members of this set must run after
152 * all members of the given set type.
153 * @tparam T Set type satisfying `SystemSetTrait`
154 * @return Reference to this handle for chaining
155 */
156 template <SystemSetTrait T>
157 constexpr auto AfterSet(this auto&& self)
158 -> decltype(std::forward<decltype(self)>(self)) {
159 return std::forward<decltype(self)>(self).After(SystemSetId::From<T>());
160 }
161
162 /**
163 * @brief Adds an ordering constraint: all members of this set must run after
164 * the given system set handle.
165 * @param target System set handle that this set must follow
166 * @return Reference to this handle for chaining
167 */
168 constexpr auto After(this auto&& self, const SystemSetHandle& target)
169 -> decltype(std::forward<decltype(self)>(self)) {
170 return std::forward<decltype(self)>(self).After(target.Id());
171 }
172
173 /**
174 * @brief Adds an ordering constraint: all members of this set must run after
175 * all members of the given system group.
176 * @param target System group handle that this set must follow
177 * @return Reference to this handle for chaining
178 */
179 constexpr auto After(this auto&& self, const SystemGroupHandle& target)
180 -> decltype(std::forward<decltype(self)>(self));
181
182 /**
183 * @brief Adds a run condition predicate that applies to all members.
184 * @param condition Predicate evaluated before any member runs
185 * @param policy Access policy for the run condition
186 * @param options Options for run condition local data construction
187 * @return Reference to this handle for chaining
188 */
189 constexpr auto RunIf(this auto&& self, RunCondition condition,
190 AccessPolicy policy = {},
191 SystemLocalDataOptions options = {})
192 -> decltype(std::forward<decltype(self)>(self));
193
194 /**
195 * @brief Adds a run condition functor that applies to all members.
196 * @details Lambdas are rejected; use `RunIf(std::string, T&&)`.
197 * @tparam T Run condition type satisfying `FunctorSystemTrait`
198 * @param condition Functor with declared access policy
199 * @return Reference to this handle for chaining
200 */
201 template <FunctorSystemTrait T>
202 constexpr auto RunIf(this auto&& self, T&& condition)
203 -> decltype(std::forward<decltype(self)>(self));
204
205 /**
206 * @brief Adds a run condition to all set members with an explicit name.
207 * @details Required for lambdas.
208 * @tparam T Run condition type satisfying `SystemTrait`
209 * @param name Human-readable name
210 * @param condition Functor with declared access policy
211 * @return Reference to this handle for chaining
212 */
213 template <SystemTrait T>
214 constexpr auto RunIf(this auto&& self, std::string name, T&& condition)
215 -> decltype(std::forward<decltype(self)>(self));
216
217 /**
218 * @brief Marks this set as a sequence: systems run in insertion order.
219 * @return Reference to this handle for chaining
220 */
221 constexpr auto Sequence(this auto&& self)
222 -> decltype(std::forward<decltype(self)>(self));
223
224 /**
225 * @brief Finishes configuration and returns a reference to the parent
226 * schedule.
227 * @return Reference to the parent schedule for continued configuration
228 */
229 constexpr Schedule& Done() noexcept { return schedule_.get(); }
230
231 /**
232 * @brief Gets the identifier for this system set.
233 * @return System set id
234 */
235 [[nodiscard]] constexpr SystemSetId Id() const noexcept { return id_; }
236
237private:
238 SystemSetId id_;
239 std::reference_wrapper<Schedule> schedule_;
240};
241
242} // namespace helios::ecs
Stores data access requirements for a system at compile time.
A collection of systems, sets, and run conditions with ordering constraints.
Definition schedule.hpp:182
Handle returned by variadic Schedule::Add for configuring a batch of systems added together.
Handle returned by Schedule::Add for configuring a system.
constexpr auto After(this auto &&self, SystemId target) -> decltype(std::forward< decltype(self)>(self))
Adds an ordering constraint: all members of this set must run after the given system.
Definition schedule.hpp:832
constexpr auto AfterSet(this auto &&self) -> decltype(std::forward< decltype(self)>(self))
Adds an ordering constraint: all members of this set must run after all members of the given set type...
constexpr auto After(this auto &&self, const SystemSetHandle &target) -> decltype(std::forward< decltype(self)>(self))
Adds an ordering constraint: all members of this set must run after the given system set handle.
constexpr auto Before(this auto &&self, SystemId target) -> decltype(std::forward< decltype(self)>(self))
Adds an ordering constraint: all members of this set must run before the given system.
Definition schedule.hpp:804
constexpr SystemSetHandle(SystemSetId id, Schedule &schedule) noexcept
Constructs a SystemSetHandle with the given system set id and schedule.
constexpr auto BeforeSet(this auto &&self) -> decltype(std::forward< decltype(self)>(self))
Adds an ordering constraint: all members of this set must run before all members of the given set typ...
constexpr auto After(this auto &&self, const SystemHandle &target) -> decltype(std::forward< decltype(self)>(self))
Adds an ordering constraint: all members of this set must run after the given system handle.
constexpr auto After(this auto &&self) -> decltype(std::forward< decltype(self)>(self))
Adds an ordering constraint: all members of this set must run after the given system type.
constexpr Schedule & Done() noexcept
Finishes configuration and returns a reference to the parent schedule.
constexpr SystemSetHandle(SystemSetHandle &&) noexcept=default
constexpr auto Before(this auto &&self, const SystemHandle &target) -> decltype(std::forward< decltype(self)>(self))
Adds an ordering constraint: all members of this set must run before the given system handle.
constexpr auto Sequence(this auto &&self) -> decltype(std::forward< decltype(self)>(self))
Marks this set as a sequence: systems run in insertion order.
Definition schedule.hpp:900
SystemSetHandle(const SystemSetHandle &)=delete
constexpr SystemSetId Id() const noexcept
Gets the identifier for this system set.
constexpr auto Before(this auto &&self, const SystemSetHandle &target) -> decltype(std::forward< decltype(self)>(self))
Adds an ordering constraint: all members of this set must run before the given system set handle.
constexpr auto RunIf(this auto &&self, RunCondition condition, AccessPolicy policy={}, SystemLocalDataOptions options={}) -> decltype(std::forward< decltype(self)>(self))
Adds a run condition predicate that applies to all members.
Definition schedule.hpp:860
Concept for systems that declare all data access via parameter types.
Definition system.hpp:87
std::function< bool(World &, SystemLocalData &)> RunCondition
Type-erased run condition: returns bool, receives World& + local data.
STL namespace.
Id for systems.
Definition system.hpp:146
static constexpr SystemId From(std::string_view name) noexcept
Creates system id from a name.
Definition system.hpp:154
Identifier for a system set.
static constexpr SystemSetId From(SystemSetTypeIndex index) noexcept
Creates system set id from a system set type index.