Helios Engine
A modular ECS based data-oriented C++23 game engine framework
Loading...
Searching...
No Matches
system_group_handle.hpp
Go to the documentation of this file.
1#pragma once
2
8
9#include <functional>
10#include <string>
11
12namespace helios::ecs {
13
14class Schedule;
15class SystemHandle;
16class SystemSetHandle;
17
18/**
19 * @brief Handle returned by variadic Schedule::Add for configuring a batch of
20 * systems added together.
21 * @details Each variadic `Add` call creates a unique anonymous group so
22 * configuration such as `Sequence()` does not leak between batches with the
23 * same system types. Use `InSet` to assign every member of the batch to a named
24 * set in one call.
25 */
27public:
28 /**
29 * @brief Constructs a `SystemGroupHandle` with the given group id and
30 * schedule.
31 * @param id The anonymous group id
32 * @param schedule The schedule that the group belongs to
33 */
34 constexpr SystemGroupHandle(SystemSetId id, Schedule& schedule) noexcept
35 : id_(id), schedule_(schedule) {}
36
38 constexpr SystemGroupHandle(SystemGroupHandle&&) noexcept = default;
39 constexpr ~SystemGroupHandle() noexcept = default;
40
41 SystemGroupHandle& operator=(const SystemGroupHandle&) = delete;
42 constexpr SystemGroupHandle& operator=(SystemGroupHandle&&) noexcept =
43 default;
44
45 /**
46 * @brief Adds an ordering constraint: all members of this group must run
47 * before the given system.
48 * @param target System id that this group must precede
49 * @return Reference to this handle for chaining
50 */
51 constexpr auto Before(this auto&& self, SystemId target)
52 -> decltype(std::forward<decltype(self)>(self));
53
54 /**
55 * @brief Adds an ordering constraint: all members of this group must run
56 * before the given system type.
57 * @tparam T System type satisfying `SystemTrait`
58 * @return Reference to this handle for chaining
59 */
60 template <SystemTrait T>
61 constexpr auto Before(this auto&& self)
62 -> decltype(std::forward<decltype(self)>(self)) {
63 return std::forward<decltype(self)>(self).Before(SystemId::From<T>());
64 }
65
66 /**
67 * @brief Adds an ordering constraint: all members of this group must run
68 * before the given system handle.
69 * @param target System handle that this group must precede
70 * @return Reference to this handle for chaining
71 */
72 constexpr auto Before(this auto&& self, const SystemHandle& target)
73 -> decltype(std::forward<decltype(self)>(self)) {
74 return std::forward<decltype(self)>(self).Before(target.Id().id);
75 }
76
77 /**
78 * @brief Adds an ordering constraint: all members of this group must run
79 * before all members of the given set.
80 * @param target Set id that this group must precede
81 * @return Reference to this handle for chaining
82 */
83 constexpr auto Before(this auto&& self, SystemSetId target)
84 -> decltype(std::forward<decltype(self)>(self));
85
86 /**
87 * @brief Adds an ordering constraint: all members of this group must run
88 * before all members of the given set type.
89 * @tparam T Set type satisfying `SystemSetTrait`
90 * @return Reference to this handle for chaining
91 */
92 template <SystemSetTrait T>
93 constexpr auto BeforeSet(this auto&& self)
94 -> decltype(std::forward<decltype(self)>(self)) {
95 return std::forward<decltype(self)>(self).Before(SystemSetId::From<T>());
96 }
97
98 /**
99 * @brief Adds an ordering constraint: all members of this group must run
100 * before the given system set handle.
101 * @param target System set handle that this group must precede
102 * @return Reference to this handle for chaining
103 */
104 constexpr auto Before(this auto&& self, const SystemSetHandle& target)
105 -> decltype(std::forward<decltype(self)>(self)) {
106 return std::forward<decltype(self)>(self).Before(target.Id());
107 }
108
109 /**
110 * @brief Adds an ordering constraint: all members of this group must run
111 * before all members of the given system group.
112 * @param target System group handle that this group must precede
113 * @return Reference to this handle for chaining
114 */
115 constexpr auto Before(this auto&& self, const SystemGroupHandle& target)
116 -> decltype(std::forward<decltype(self)>(self)) {
117 return std::forward<decltype(self)>(self).Before(target.Id());
118 }
119
120 /**
121 * @brief Adds an ordering constraint: all members of this group must run
122 * after the given system.
123 * @param target System id that this group must follow
124 * @return Reference to this handle for chaining
125 */
126 constexpr auto After(this auto&& self, SystemId target)
127 -> decltype(std::forward<decltype(self)>(self));
128
129 /**
130 * @brief Adds an ordering constraint: all members of this group must run
131 * after the given system type.
132 * @tparam T System type satisfying `SystemTrait`
133 * @return Reference to this handle for chaining
134 */
135 template <SystemTrait T>
136 constexpr auto After(this auto&& self)
137 -> decltype(std::forward<decltype(self)>(self)) {
138 return std::forward<decltype(self)>(self).After(SystemId::From<T>());
139 }
140
141 /**
142 * @brief Adds an ordering constraint: all members of this group must run
143 * after the given system handle.
144 * @param target System handle that this group must follow
145 * @return Reference to this handle for chaining
146 */
147 constexpr auto After(this auto&& self, const SystemHandle& target)
148 -> decltype(std::forward<decltype(self)>(self)) {
149 return std::forward<decltype(self)>(self).After(target.Id().id);
150 }
151
152 /**
153 * @brief Adds an ordering constraint: all members of this group must run
154 * after all members of the given set.
155 * @param target Set id that this group must follow
156 * @return Reference to this handle for chaining
157 */
158 constexpr auto After(this auto&& self, SystemSetId target)
159 -> decltype(std::forward<decltype(self)>(self));
160
161 /**
162 * @brief Adds an ordering constraint: all members of this group must run
163 * after all members of the given set type.
164 * @tparam T Set type satisfying `SystemSetTrait`
165 * @return Reference to this handle for chaining
166 */
167 template <SystemSetTrait T>
168 constexpr auto AfterSet(this auto&& self)
169 -> decltype(std::forward<decltype(self)>(self)) {
170 return std::forward<decltype(self)>(self).After(SystemSetId::From<T>());
171 }
172
173 /**
174 * @brief Adds an ordering constraint: all members of this group must run
175 * after the given system set handle.
176 * @param target System set handle that this group must follow
177 * @return Reference to this handle for chaining
178 */
179 constexpr auto After(this auto&& self, const SystemSetHandle& target)
180 -> decltype(std::forward<decltype(self)>(self)) {
181 return std::forward<decltype(self)>(self).After(target.Id());
182 }
183
184 /**
185 * @brief Adds an ordering constraint: all members of this group must run
186 * after all members of the given system group.
187 * @param target System group handle that this group must follow
188 * @return Reference to this handle for chaining
189 */
190 constexpr auto After(this auto&& self, const SystemGroupHandle& target)
191 -> decltype(std::forward<decltype(self)>(self)) {
192 return std::forward<decltype(self)>(self).After(target.Id());
193 }
194
195 /**
196 * @brief Adds a run condition predicate that applies to all group members.
197 * @param condition Predicate evaluated before any member runs
198 * @param policy Access policy for the run condition
199 * @param options Options for run condition local data construction
200 * @return Reference to this handle for chaining
201 */
202 constexpr auto RunIf(this auto&& self, RunCondition condition,
203 AccessPolicy policy = {},
204 SystemLocalDataOptions options = {})
205 -> decltype(std::forward<decltype(self)>(self));
206
207 /**
208 * @brief Adds a run condition functor that applies to all group members.
209 * @details Lambdas are rejected; use `RunIf(std::string, T&&)`.
210 * @tparam T Run condition type satisfying `FunctorSystemTrait`
211 * @param condition Functor with declared access policy
212 * @return Reference to this handle for chaining
213 */
214 template <FunctorSystemTrait T>
215 constexpr auto RunIf(this auto&& self, T&& condition)
216 -> decltype(std::forward<decltype(self)>(self));
217
218 /**
219 * @brief Adds a run condition to all group members with an explicit name.
220 * @details Required for lambdas.
221 * @tparam T Run condition type satisfying `SystemTrait`
222 * @param name Human-readable name
223 * @param condition Functor with declared access policy
224 * @return Reference to this handle for chaining
225 */
226 template <SystemTrait T>
227 constexpr auto RunIf(this auto&& self, std::string name, T&& condition)
228 -> decltype(std::forward<decltype(self)>(self));
229
230 /**
231 * @brief Assigns every member of this group to the given named set.
232 * @details Creates the target set if needed. Members inherit the target set's
233 * ordering constraints and run conditions. Repeated calls with the same set
234 * id are ignored for each member.
235 * @param target Named set to assign group members to
236 * @return Reference to this handle for chaining
237 * @code
238 * schedule.Add(SystemA{}, SystemB{}).InSet(MovementSet{}).Sequence();
239 * @endcode
240 */
241 constexpr auto InSet(this auto&& self, SystemSetId target)
242 -> decltype(std::forward<decltype(self)>(self));
243
244 /**
245 * @brief Assigns every member of this group to the given named set type.
246 * @tparam T Set type satisfying `SystemSetTrait`
247 * @return Reference to this handle for chaining
248 */
249 template <SystemSetTrait T>
250 constexpr auto InSet(this auto&& self, const T& /*set*/ = {})
251 -> decltype(std::forward<decltype(self)>(self)) {
252 return std::forward<decltype(self)>(self).InSet(SystemSetId::From<T>());
253 }
254
255 /**
256 * @brief Marks this group as a sequence: members run in insertion order.
257 * @return Reference to this handle for chaining
258 */
259 constexpr auto Sequence(this auto&& self)
260 -> decltype(std::forward<decltype(self)>(self));
261
262 /**
263 * @brief Finishes configuration and returns a reference to the parent
264 * schedule.
265 * @return Reference to the parent schedule for continued configuration
266 */
267 constexpr Schedule& Done() noexcept { return schedule_.get(); }
268
269 /**
270 * @brief Gets the identifier for this anonymous group.
271 * @return Anonymous group id
272 */
273 [[nodiscard]] constexpr SystemSetId Id() const noexcept { return id_; }
274
275private:
276 SystemSetId id_;
277 std::reference_wrapper<Schedule> schedule_;
278};
279
280} // 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
constexpr auto Before(this auto &&self, const SystemGroupHandle &target) -> decltype(std::forward< decltype(self)>(self))
Adds an ordering constraint: all members of this group must run before all members of the given syste...
constexpr auto BeforeSet(this auto &&self) -> decltype(std::forward< decltype(self)>(self))
Adds an ordering constraint: all members of this group must run before all members of the given set t...
constexpr auto Before(this auto &&self, const SystemHandle &target) -> decltype(std::forward< decltype(self)>(self))
Adds an ordering constraint: all members of this group must run before the given system handle.
constexpr auto Before(this auto &&self, const SystemSetHandle &target) -> decltype(std::forward< decltype(self)>(self))
Adds an ordering constraint: all members of this group must run before the given system set handle.
constexpr auto InSet(this auto &&self, const T &={}) -> decltype(std::forward< decltype(self)>(self))
Assigns every member of this group to the given named set type.
constexpr auto After(this auto &&self, const SystemHandle &target) -> decltype(std::forward< decltype(self)>(self))
Adds an ordering constraint: all members of this group must run after the given system handle.
constexpr auto After(this auto &&self, const SystemSetHandle &target) -> decltype(std::forward< decltype(self)>(self))
Adds an ordering constraint: all members of this group must run after the given system set handle.
constexpr SystemSetId Id() const noexcept
Gets the identifier for this anonymous group.
constexpr SystemGroupHandle(SystemGroupHandle &&) noexcept=default
constexpr auto Sequence(this auto &&self) -> decltype(std::forward< decltype(self)>(self))
Marks this group as a sequence: members run in insertion order.
SystemGroupHandle(const SystemGroupHandle &)=delete
constexpr auto After(this auto &&self, const SystemGroupHandle &target) -> decltype(std::forward< decltype(self)>(self))
Adds an ordering constraint: all members of this group must run after all members of the given system...
constexpr auto Before(this auto &&self, SystemId target) -> decltype(std::forward< decltype(self)>(self))
Adds an ordering constraint: all members of this group must run before the given system.
Definition schedule.hpp:911
constexpr auto After(this auto &&self) -> decltype(std::forward< decltype(self)>(self))
Adds an ordering constraint: all members of this group must run after the given system type.
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 group members.
Definition schedule.hpp:955
constexpr auto After(this auto &&self, SystemId target) -> decltype(std::forward< decltype(self)>(self))
Adds an ordering constraint: all members of this group must run after the given system.
Definition schedule.hpp:933
constexpr auto InSet(this auto &&self, SystemSetId target) -> decltype(std::forward< decltype(self)>(self))
Assigns every member of this group to the given named set.
Definition schedule.hpp:996
constexpr SystemGroupHandle(SystemSetId id, Schedule &schedule) noexcept
Constructs a SystemGroupHandle with the given group id and schedule.
constexpr Schedule & Done() noexcept
Finishes configuration and returns a reference to the parent schedule.
constexpr auto AfterSet(this auto &&self) -> decltype(std::forward< decltype(self)>(self))
Adds an ordering constraint: all members of this group must run after all members of the given set ty...
Handle returned by Schedule::Add for configuring a system.
Handle returned by Schedule::Set for configuring a named system set.
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.