Helios Engine
A modular ECS based data-oriented C++23 game engine framework
Loading...
Searching...
No Matches
builtin_commands.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <helios/assert.hpp>
11
12#include <concepts>
13#include <ranges>
14#include <tuple>
15#include <type_traits>
16#include <utility>
17#include <vector>
18
19namespace helios::ecs {
20
21/**
22 * @brief Command that executes a function with `World` reference.
23 * @details Wraps arbitrary functions for deferred execution during
24 * `World::Update()`. The function must be invocable with a `World&` parameter.
25 * @tparam F Function type that accepts `World&`
26 */
27template <typename F>
28 requires std::invocable<F, World&>
30public:
31 /**
32 * @brief Constructs function command from an lvalue callable.
33 * @param func Function to copy, must accept `World&` parameter
34 */
35 explicit constexpr FunctionCmd(const F& func) noexcept(
36 std::is_nothrow_copy_constructible_v<F>)
37 : func_(func) {}
38
39 /**
40 * @brief Constructs function command from an rvalue callable.
41 * @param func Function to move, must accept `World&` parameter
42 */
43 explicit constexpr FunctionCmd(F&& func) noexcept(
44 std::is_nothrow_move_constructible_v<F>)
45 : func_(std::move(func)) {}
46
47 constexpr FunctionCmd(const FunctionCmd&) noexcept(
48 std::is_nothrow_copy_constructible_v<F>) = default;
49 constexpr FunctionCmd(FunctionCmd&&) noexcept(
50 std::is_nothrow_move_constructible_v<F>) = default;
51 constexpr ~FunctionCmd() noexcept(std::is_nothrow_destructible_v<F>) =
52 default;
53
54 constexpr FunctionCmd& operator=(const FunctionCmd&) noexcept(
55 std::is_nothrow_copy_assignable_v<F>) = default;
56 constexpr FunctionCmd& operator=(FunctionCmd&&) noexcept(
57 std::is_nothrow_move_assignable_v<F>) = default;
58
59 /**
60 * @brief Executes the wrapped function.
61 * @param world World reference to pass to the function
62 */
63 void Execute(World& world) noexcept(std::is_nothrow_invocable_v<F, World&>) {
64 func_(world);
65 }
66
67private:
68 F func_; ///< Stored function to execute
69};
70
71template <typename G>
73
74/**
75 * @brief Command to destroy a single entity.
76 * @details Removes entity and all its components from the world during
77 * execution.
78 * @warning Will trigger assertion if the world does not own (entity
79 * index/generation mismatch) the entity.
80 */
82public:
83 /**
84 * @brief Constructs destroy entity command.
85 * @warning Triggers assertion if entity is invalid.
86 * @param entity Entity to destroy
87 */
88 explicit constexpr DestroyEntityCmd(Entity entity) noexcept
89 : entity_(entity) {
90 HELIOS_ASSERT(entity.Valid(), "Entity '{}' is invalid!", entity);
91 }
92
93 constexpr DestroyEntityCmd(const DestroyEntityCmd&) noexcept = default;
94 constexpr DestroyEntityCmd(DestroyEntityCmd&&) noexcept = default;
95 constexpr ~DestroyEntityCmd() noexcept = default;
96
97 constexpr DestroyEntityCmd& operator=(const DestroyEntityCmd&) noexcept =
98 default;
99 constexpr DestroyEntityCmd& operator=(DestroyEntityCmd&&) noexcept = default;
100
101 /**
102 * @brief Executes entity destruction.
103 * @warning Triggers assertion if the world does not own the entity.
104 * @param world World to remove entity from
105 */
106 void Execute(World& world) { world.DestroyEntity(entity_); }
107
108private:
109 Entity entity_; ///< Entity to destroy
110};
111
112/**
113 * @brief Command to destroy multiple entities.
114 * @details Efficiently destroys multiple entities in a single operation.
115 * @warning Will assertion if any of the entities do not exist in the world
116 * (when world updated).
117 * @tparam Alloc Allocator type
118 */
119template <typename Alloc = std::allocator<Entity>>
121public:
122 /**
123 * @brief Constructs destroy entities command from vector of entities.
124 * @warning Triggers assertion if any entity is invalid.
125 * @param entities Vector of entities to destroy
126 */
127 explicit constexpr DestroyEntitiesCmd(std::vector<Entity, Alloc> entities)
128 : entities_(std::move(entities)) {
129 HELIOS_ASSERT(std::ranges::all_of(
130 entities_, [](Entity entity) { return entity.Valid(); }),
131 "One or more entities are invalid!");
132 }
133
134 constexpr DestroyEntitiesCmd(const DestroyEntitiesCmd&) noexcept = default;
135 constexpr DestroyEntitiesCmd(DestroyEntitiesCmd&&) noexcept = default;
136 constexpr ~DestroyEntitiesCmd() noexcept = default;
137
138 constexpr DestroyEntitiesCmd& operator=(const DestroyEntitiesCmd&) noexcept =
139 default;
140 constexpr DestroyEntitiesCmd& operator=(DestroyEntitiesCmd&&) noexcept =
141 default;
142
143 /**
144 * @brief Executes entities destruction.
145 * @warning Triggers assertion if any entity does not exist in the world.
146 * @param world World to remove entities from
147 */
148 void Execute(World& world) { world.DestroyEntities(entities_); }
149
150private:
151 std::vector<Entity, Alloc> entities_; ///< Entities to destroy
152};
153
154/**
155 * @brief Command to try destroy a single entity.
156 * @details Will destroy the entity only if it exists in the world.
157 */
159public:
160 /**
161 * @brief Constructs try destroy entity command.
162 * @warning Triggers assertion if entity is invalid.
163 * @param entity Entity to destroy
164 */
165 explicit constexpr TryDestroyEntityCmd(Entity entity) noexcept
166 : entity_(entity) {
167 HELIOS_ASSERT(entity.Valid(), "Entity '{}' is invalid!", entity);
168 }
169
170 constexpr TryDestroyEntityCmd(const TryDestroyEntityCmd&) noexcept = default;
171 constexpr TryDestroyEntityCmd(TryDestroyEntityCmd&&) noexcept = default;
172 constexpr ~TryDestroyEntityCmd() noexcept = default;
173
174 constexpr TryDestroyEntityCmd& operator=(
175 const TryDestroyEntityCmd&) noexcept = default;
176 constexpr TryDestroyEntityCmd& operator=(TryDestroyEntityCmd&&) noexcept =
177 default;
178
179 /**
180 * @brief Executes entity destruction if it exists.
181 * @param world World to remove entity from
182 */
183 void Execute(World& world) { world.TryDestroyEntity(entity_); }
184
185private:
186 Entity entity_;
187};
188
189/**
190 * @brief Command to try destroy multiple entities.
191 * @details Will destroy entities only if they exist in the world.
192 * @tparam Alloc Allocator type
193 */
194template <typename Alloc = std::allocator<Entity>>
196public:
197 /**
198 * @brief Constructs try destroy entities command from vector of entities.
199 * @warning Triggers assertion if any entity is invalid.
200 * @param entities Vector of entities to destroy
201 */
202 explicit constexpr TryDestroyEntitiesCmd(std::vector<Entity, Alloc> entities)
203 : entities_(std::move(entities)) {
205 std::ranges::all_of(
206 entities_, [](const Entity& entity) { return entity.Valid(); }),
207 "One or more entities are invalid!");
208 }
209
210 constexpr TryDestroyEntitiesCmd(const TryDestroyEntitiesCmd&) noexcept =
211 default;
212 constexpr TryDestroyEntitiesCmd(TryDestroyEntitiesCmd&&) noexcept = default;
213 constexpr ~TryDestroyEntitiesCmd() noexcept = default;
214
215 constexpr TryDestroyEntitiesCmd& operator=(
216 const TryDestroyEntitiesCmd&) noexcept = default;
217 constexpr TryDestroyEntitiesCmd& operator=(TryDestroyEntitiesCmd&&) noexcept =
218 default;
219
220 /**
221 * @brief Executes entities destruction if they exist.
222 * @param world World to remove entities from
223 */
224 void Execute(World& world) { world.TryDestroyEntities(entities_); }
225
226private:
227 std::vector<Entity, Alloc> entities_;
228};
229
230/**
231 * @brief Command to add multiple components to an entity.
232 * @details Efficiently adds multiple components in a single operation.
233 * If entity already has any of the components, they will be replaced.
234 * @warning Will trigger assertion if the entity does not exist in the world
235 * (when world updated).
236 * @tparam Ts Component types to add (must be unique)
237 */
238template <ComponentTrait... Ts>
239 requires utils::UniqueTypes<Ts...> && (sizeof...(Ts) > 0)
241public:
242 /**
243 * @brief Constructs add components command.
244 * @warning Triggers assertion if entity is invalid.
245 * @tparam Us Component types to add (must match `Ts`)
246 * @param entity Entity to add components to
247 * @param components Components to add
248 */
249 template <ComponentTrait... Us>
250 requires(sizeof...(Us) == sizeof...(Ts)) &&
251 (std::same_as<Ts, std::remove_cvref_t<Us>> && ...)
252 constexpr AddComponentsCmd(Entity entity, Us&&... components) noexcept(
253 noexcept(std::tuple<Us...>(std::forward<Us>(components)...)))
254 : entity_(entity), components_(std::forward<Us>(components)...) {
255 HELIOS_ASSERT(entity.Valid(), "Entity '{}' is invalid!", entity);
256 }
257
258 constexpr AddComponentsCmd(const AddComponentsCmd&) noexcept = default;
259 constexpr AddComponentsCmd(AddComponentsCmd&&) noexcept = default;
260 constexpr ~AddComponentsCmd() noexcept = default;
261
262 constexpr AddComponentsCmd& operator=(const AddComponentsCmd&) noexcept =
263 default;
264 constexpr AddComponentsCmd& operator=(AddComponentsCmd&&) noexcept = default;
265
266 /**
267 * @brief Executes components addition.
268 * @warning Triggers assertion if the entity does not exist in the world.
269 * @param world World to add components in
270 */
271 void Execute(World& world) {
272 std::apply(
273 [&world, this](auto&&... args) {
274 world.AddComponents(entity_, std::forward<decltype(args)>(args)...);
275 },
276 std::move(components_));
277 }
278
279private:
280 Entity entity_; ///< Entity to add components to
281 std::tuple<Ts...> components_; ///< Components to add
282};
283
284template <ComponentTrait... Us>
287
288/**
289 * @brief Command to try add multiple components (only missing ones).
290 * @details Adds multiple components to the specified entity during execution
291 * only if it doesn't already have them. If entity already has any of the
292 * components, they will be left unchanged.
293 * @warning Will trigger assertion if the entity does not exist in the world
294 * (when world updated).
295 * @tparam Ts Component types (must be unique)
296 */
297template <ComponentTrait... Ts>
298 requires utils::UniqueTypes<Ts...> && (sizeof...(Ts) > 0)
300public:
301 /**
302 * @brief Constructs try add components command.
303 * @warning Triggers assertion if entity is invalid.
304 * @tparam Us Component types to add (must match `Ts`)
305 * @param entity Entity to add components to
306 * @param components Components to add
307 */
308 template <ComponentTrait... Us>
309 requires(sizeof...(Us) == sizeof...(Ts)) &&
310 (std::same_as<Ts, std::remove_cvref_t<Us>> && ...)
311 constexpr TryAddComponentsCmd(Entity entity, Us&&... components) noexcept
312 : entity_(entity), components_(std::forward<Us>(components)...) {
313 HELIOS_ASSERT(entity.Valid(), "Entity '{}' is invalid!", entity);
314 }
315
316 constexpr TryAddComponentsCmd(const TryAddComponentsCmd&) noexcept = default;
317 constexpr TryAddComponentsCmd(TryAddComponentsCmd&&) noexcept = default;
318 constexpr ~TryAddComponentsCmd() noexcept = default;
319
320 constexpr TryAddComponentsCmd& operator=(
321 const TryAddComponentsCmd&) noexcept = default;
322 constexpr TryAddComponentsCmd& operator=(TryAddComponentsCmd&&) noexcept =
323 default;
324
325 /**
326 * @brief Executes components addition if entity is missing them.
327 * @warning Triggers assertion if the entity does not exist in the world.
328 * @param world World to add components in
329 */
330 void Execute(World& world) {
331 std::apply(
332 [&world, this](auto&&... args) {
333 world.TryAddComponents(entity_,
334 std::forward<decltype(args)>(args)...);
335 },
336 std::move(components_));
337 }
338
339private:
340 Entity entity_;
341 std::tuple<Ts...> components_;
342};
343
344template <ComponentTrait... Us>
347
348/**
349 * @brief Command to remove multiple components from an entity.
350 * @details Efficiently removes multiple components in a single operation.
351 * @warning Will trigger assertion if the entity does not exist in the world
352 * (when world updated).
353 * @tparam Ts Component types to remove (must be unique)
354 */
355template <ComponentTrait... Ts>
356 requires utils::UniqueTypes<Ts...> && (sizeof...(Ts) > 0)
358public:
359 /**
360 * @brief Constructs remove components command.
361 * @warning Triggers assertion if entity is invalid.
362 * @param entity Entity to remove components from
363 */
364 explicit constexpr RemoveComponentsCmd(Entity entity) noexcept
365 : entity_(entity) {
366 HELIOS_ASSERT(entity.Valid(), "Entity '{}' is invalid!", entity);
367 }
368 constexpr RemoveComponentsCmd(const RemoveComponentsCmd&) noexcept = default;
369 constexpr RemoveComponentsCmd(RemoveComponentsCmd&&) noexcept = default;
370 constexpr ~RemoveComponentsCmd() noexcept = default;
371
372 constexpr RemoveComponentsCmd& operator=(
373 const RemoveComponentsCmd&) noexcept = default;
374 constexpr RemoveComponentsCmd& operator=(RemoveComponentsCmd&&) noexcept =
375 default;
376
377 /**
378 * @brief Executes components removal.
379 * @warning Triggers assertion if the entity does not exist in the world.
380 * @param world World to remove components from
381 */
382 void Execute(World& world) { world.RemoveComponents<Ts...>(entity_); }
383
384private:
385 Entity entity_; ///< Entity to remove components from
386};
387
388/**
389 * @brief Command to try remove multiple components (only those present).
390 * @details Removes multiple components from the specified entity during
391 * execution only if they exist.
392 * @warning Will trigger assertion if the entity does not exist in the world
393 * (when world updated).
394 * @tparam Ts Component types (must be unique)
395 */
396template <ComponentTrait... Ts>
397 requires utils::UniqueTypes<Ts...> && (sizeof...(Ts) > 0)
399public:
400 /**
401 * @brief Constructs try remove components command.
402 * @warning Triggers assertion if entity is invalid.
403 * @param entity Entity to remove components from
404 */
405 explicit constexpr TryRemoveComponentsCmd(Entity entity) noexcept
406 : entity_(entity) {
407 HELIOS_ASSERT(entity.Valid(), "Entity '{}' is invalid!", entity);
408 }
409
411 default;
412 constexpr TryRemoveComponentsCmd(TryRemoveComponentsCmd&&) noexcept = default;
413 constexpr ~TryRemoveComponentsCmd() noexcept = default;
414
415 constexpr TryRemoveComponentsCmd& operator=(
416 const TryRemoveComponentsCmd&) noexcept = default;
417 constexpr TryRemoveComponentsCmd& operator=(
418 TryRemoveComponentsCmd&&) noexcept = default;
419
420 /**
421 * @brief Executes components removal if entity has them.
422 * @warning Triggers assertion if the entity does not exist in the world.
423 * @param world World to remove components from
424 */
425 void Execute(World& world) { world.TryRemoveComponents<Ts...>(entity_); }
426
427private:
428 Entity entity_; ///< Entity to remove components from
429};
430
431/**
432 * @brief Command to clear all components from an entity.
433 * @details Removes all components from the specified entity during execution.
434 * @warning Will trigger assertion if the entity does not exist in the world
435 * (when world updated).
436 */
438public:
439 /**
440 * @brief Constructs clear components command.
441 * @warning Triggers assertion if entity is invalid.
442 * @param entity Entity to clear components from
443 */
444 explicit constexpr ClearComponentsCmd(Entity entity) noexcept
445 : entity_(entity) {
446 HELIOS_ASSERT(entity.Valid(), "Entity '{}' is invalid!", entity);
447 }
448
449 constexpr ClearComponentsCmd(const ClearComponentsCmd&) noexcept = default;
450 constexpr ClearComponentsCmd(ClearComponentsCmd&&) noexcept = default;
451 constexpr ~ClearComponentsCmd() noexcept = default;
452
453 constexpr ClearComponentsCmd& operator=(const ClearComponentsCmd&) noexcept =
454 default;
455 constexpr ClearComponentsCmd& operator=(ClearComponentsCmd&&) noexcept =
456 default;
457
458 /**
459 * @brief Executes component clearing.
460 * @warning Triggers assertion if the entity does not exist in the world.
461 * @param world World to clear components in
462 */
463 void Execute(World& world) { world.ClearComponents(entity_); }
464
465private:
466 Entity entity_; ///< Entity to clear components from
467};
468
469/**
470 * @brief Command to insert a resource into the world.
471 * @details Inserts resource of type `T` into the world during execution.
472 * If resource already exists, it will be replaced.
473 * @tparam T Resource type to insert
474 */
475template <ResourceTrait T>
477public:
478 /**
479 * @brief Constructs insert resource command from an lvalue.
480 * @param resource Resource to copy
481 */
482 explicit constexpr InsertResourceCmd(const T& resource) noexcept(
483 std::is_nothrow_copy_constructible_v<T>)
484 : resource_(resource) {}
485
486 /**
487 * @brief Constructs insert resource command from an rvalue.
488 * @param resource Resource to move
489 */
490 explicit constexpr InsertResourceCmd(T&& resource) noexcept(
491 std::is_nothrow_move_constructible_v<T>)
492 : resource_(std::move(resource)) {}
493
494 constexpr InsertResourceCmd(const InsertResourceCmd&) noexcept(
495 std::is_nothrow_copy_constructible_v<T>) = default;
497 std::is_nothrow_move_constructible_v<T>) = default;
498 constexpr ~InsertResourceCmd() noexcept(std::is_nothrow_destructible_v<T>) =
499 default;
500
501 constexpr InsertResourceCmd& operator=(const InsertResourceCmd&) noexcept(
502 std::is_nothrow_copy_assignable_v<T>) = default;
503
504 constexpr InsertResourceCmd& operator=(InsertResourceCmd&&) noexcept(
505 std::is_nothrow_move_assignable_v<T>) = default;
506
507 /**
508 * @brief Executes resource insertion.
509 * @param world World to insert resource into
510 */
511 void Execute(World& world) { world.InsertResources(std::move(resource_)); }
512
513private:
514 T resource_; ///< Resource to insert
515};
516
517/**
518 * @brief Command to try insert a resource (only if missing).
519 * @details Inserts resource of type `T` into the world during execution only if
520 * it doesn't already exist. If resource already exists, it will be left
521 * unchanged.
522 * @tparam T Resource type
523 */
524template <ResourceTrait T>
526public:
527 /**
528 * @brief Constructs try insert resource command from an lvalue.
529 * @param resource Resource to copy
530 */
531 explicit constexpr TryInsertResourceCmd(const T& resource) noexcept(
532 std::is_nothrow_copy_constructible_v<T>)
533 : resource_(resource) {}
534
535 /**
536 * @brief Constructs try insert resource command from an rvalue.
537 * @param resource Resource to move
538 */
539 explicit constexpr TryInsertResourceCmd(T&& resource) noexcept(
540 std::is_nothrow_move_constructible_v<T>)
541 : resource_(std::move(resource)) {}
542
543 constexpr TryInsertResourceCmd(const TryInsertResourceCmd&) noexcept =
544 default;
545 constexpr TryInsertResourceCmd(TryInsertResourceCmd&&) noexcept = default;
546 constexpr ~TryInsertResourceCmd() noexcept = default;
547
548 constexpr TryInsertResourceCmd& operator=(
549 const TryInsertResourceCmd&) noexcept = default;
550 constexpr TryInsertResourceCmd& operator=(TryInsertResourceCmd&&) noexcept =
551 default;
552
553 /**
554 * @brief Executes resource insertion if it doesn't exist.
555 * @param world World to insert resource into
556 */
557 void Execute(World& world) { world.TryInsertResources(std::move(resource_)); }
558
559private:
560 T resource_; ///< Resource to insert
561};
562
563/**
564 * @brief Command to remove resource from the world.
565 * @details Removes resource from the world during execution.
566 * @warning Will trigger assertion if the resource does not exist in the world
567 * (when world updated).
568 * @tparam T Resource type to remove
569 */
570template <ResourceTrait T>
572 /**
573 * @brief Executes resource removal.
574 * @warning Triggers assertion if the resource does not exist in the world.
575 * @param world World to remove resource from
576 */
577 static void Execute(World& world) { world.RemoveResources<T>(); }
578};
579
580/**
581 * @brief Command to try remove resource (only if present).
582 * @details Removes resource from the world during execution only if
583 * it exists.
584 * @tparam T Resource type to remove
585 */
586template <ResourceTrait T>
588 /**
589 * @brief Executes resource removal if it exists.
590 * @param world World to remove resource from
591 */
592 static void Execute(World& world) { world.TryRemoveResources<T>(); }
593};
594
595/**
596 * @brief Command to clear all messages of a specific type from the queue.
597 * @details Clears all messages of type `T` from the message queue during
598 * execution without removing registration.
599 * @tparam T Message type to clear
600 */
601template <AnyMessageTrait T>
603 /**
604 * @brief Executes the command to clear messages of type `T`.
605 * @param world Reference to the world
606 */
607 static void Execute(World& world) { world.ClearMessages<T>(); }
608};
609
610/**
611 * @brief Command to clear all message queues without removing registration.
612 * @details Clears all messages of all types from their respective queues during
613 * execution.
614 */
616 /**
617 * @brief Executes the command to clear all message queues.
618 * @param world Reference to the world
619 */
620 static void Execute(World& world) { world.ClearMessages(); }
621};
622
623} // namespace helios::ecs
#define HELIOS_ASSERT(condition,...)
Assertion macro that aborts execution in debug builds.
Definition assert.hpp:259
Command to add multiple components to an entity.
void Execute(World &world)
Executes components addition.
constexpr AddComponentsCmd(Entity entity, Us &&... components) noexcept(noexcept(std::tuple< Us... >(std::forward< Us >(components)...)))
Constructs add components command.
constexpr AddComponentsCmd(const AddComponentsCmd &) noexcept=default
constexpr AddComponentsCmd(AddComponentsCmd &&) noexcept=default
constexpr ClearComponentsCmd(Entity entity) noexcept
Constructs clear components command.
void Execute(World &world)
Executes component clearing.
constexpr ClearComponentsCmd(ClearComponentsCmd &&) noexcept=default
constexpr ClearComponentsCmd(const ClearComponentsCmd &) noexcept=default
constexpr DestroyEntitiesCmd(std::vector< Entity, Alloc > entities)
Constructs destroy entities command from vector of entities.
constexpr DestroyEntitiesCmd(DestroyEntitiesCmd &&) noexcept=default
constexpr DestroyEntitiesCmd(const DestroyEntitiesCmd &) noexcept=default
void Execute(World &world)
Executes entities destruction.
constexpr DestroyEntityCmd(const DestroyEntityCmd &) noexcept=default
constexpr DestroyEntityCmd(DestroyEntityCmd &&) noexcept=default
void Execute(World &world)
Executes entity destruction.
constexpr DestroyEntityCmd(Entity entity) noexcept
Constructs destroy entity command.
Unique identifier for entities with generation counter to handle recycling.
Definition entity.hpp:22
constexpr bool Valid() const noexcept
Checks if the entity is valid.
Definition entity.hpp:64
Command that executes a function with World reference.
constexpr FunctionCmd(const FunctionCmd &) noexcept(std::is_nothrow_copy_constructible_v< F >)=default
constexpr FunctionCmd(FunctionCmd &&) noexcept(std::is_nothrow_move_constructible_v< F >)=default
void Execute(World &world) noexcept(std::is_nothrow_invocable_v< F, World & >)
Executes the wrapped function.
constexpr FunctionCmd(const F &func) noexcept(std::is_nothrow_copy_constructible_v< F >)
Constructs function command from an lvalue callable.
constexpr FunctionCmd(F &&func) noexcept(std::is_nothrow_move_constructible_v< F >)
Constructs function command from an rvalue callable.
constexpr InsertResourceCmd(const InsertResourceCmd &) noexcept(std::is_nothrow_copy_constructible_v< T >)=default
constexpr InsertResourceCmd(const T &resource) noexcept(std::is_nothrow_copy_constructible_v< T >)
Constructs insert resource command from an lvalue.
void Execute(World &world)
Executes resource insertion.
constexpr InsertResourceCmd(T &&resource) noexcept(std::is_nothrow_move_constructible_v< T >)
Constructs insert resource command from an rvalue.
constexpr InsertResourceCmd(InsertResourceCmd &&) noexcept(std::is_nothrow_move_constructible_v< T >)=default
constexpr RemoveComponentsCmd(RemoveComponentsCmd &&) noexcept=default
constexpr RemoveComponentsCmd(Entity entity) noexcept
Constructs remove components command.
void Execute(World &world)
Executes components removal.
constexpr RemoveComponentsCmd(const RemoveComponentsCmd &) noexcept=default
Command to try add multiple components (only missing ones).
constexpr TryAddComponentsCmd(const TryAddComponentsCmd &) noexcept=default
constexpr TryAddComponentsCmd(Entity entity, Us &&... components) noexcept
Constructs try add components command.
constexpr TryAddComponentsCmd(TryAddComponentsCmd &&) noexcept=default
void Execute(World &world)
Executes components addition if entity is missing them.
constexpr TryDestroyEntitiesCmd(const TryDestroyEntitiesCmd &) noexcept=default
constexpr TryDestroyEntitiesCmd(TryDestroyEntitiesCmd &&) noexcept=default
void Execute(World &world)
Executes entities destruction if they exist.
constexpr TryDestroyEntitiesCmd(std::vector< Entity, Alloc > entities)
Constructs try destroy entities command from vector of entities.
constexpr TryDestroyEntityCmd(Entity entity) noexcept
Constructs try destroy entity command.
void Execute(World &world)
Executes entity destruction if it exists.
constexpr TryDestroyEntityCmd(TryDestroyEntityCmd &&) noexcept=default
constexpr TryDestroyEntityCmd(const TryDestroyEntityCmd &) noexcept=default
constexpr TryInsertResourceCmd(const TryInsertResourceCmd &) noexcept=default
void Execute(World &world)
Executes resource insertion if it doesn't exist.
constexpr TryInsertResourceCmd(TryInsertResourceCmd &&) noexcept=default
constexpr TryInsertResourceCmd(const T &resource) noexcept(std::is_nothrow_copy_constructible_v< T >)
Constructs try insert resource command from an lvalue.
constexpr TryInsertResourceCmd(T &&resource) noexcept(std::is_nothrow_move_constructible_v< T >)
Constructs try insert resource command from an rvalue.
constexpr TryRemoveComponentsCmd(TryRemoveComponentsCmd &&) noexcept=default
constexpr TryRemoveComponentsCmd(Entity entity) noexcept
Constructs try remove components command.
constexpr TryRemoveComponentsCmd(const TryRemoveComponentsCmd &) noexcept=default
void Execute(World &world)
Executes components removal if entity has them.
The World class manages entities with their components and systems.
Definition world.hpp:39
bool TryRemoveResources()
Tries to remove resource.
Definition world.hpp:1204
void ClearMessages() noexcept
Clears all messages without removing registration.
Definition world.hpp:608
void RemoveResources()
Removes resources from the world.
Definition world.hpp:1175
Concept to check if a type can be used as a component.
Definition component.hpp:31
Concept that checks if all types in a pack are unique (after removing cv/ref qualifiers).
AddComponentsCmd(Entity, Us &&...) -> AddComponentsCmd< std::remove_cvref_t< Us >... >
FunctionCmd(G &&) -> FunctionCmd< std::remove_cvref_t< G > >
TryAddComponentsCmd(Entity, Us &&...) -> TryAddComponentsCmd< std::remove_cvref_t< Us >... >
STL namespace.
Command to clear all message queues without removing registration.
static void Execute(World &world)
Executes the command to clear all message queues.
Command to clear all messages of a specific type from the queue.
static void Execute(World &world)
Executes the command to clear messages of type T.
Command to remove resource from the world.
static void Execute(World &world)
Executes resource removal.
Command to try remove resource (only if present).
static void Execute(World &world)
Executes resource removal if it exists.