Helios Engine
A modular ECS based data-oriented C++23 game engine framework
Loading...
Searching...
No Matches
builtin_messages.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <helios/assert.hpp>
8
9#include <string_view>
10
11namespace helios::ecs {
12
13/// @brief Message sent when an entity is added.
15public:
16 static constexpr std::string_view kName = "EntityAddedMsg";
18 static constexpr bool kConsumable = false;
19 static constexpr bool kAsync = false;
20
21 /**
22 * @brief Constructs entity added message.
23 * @warning Triggers assertion if entity is invalid.
24 * @param entity Destroyed entity
25 */
26 explicit constexpr EntityAddedMsg(Entity entity) noexcept : entity_(entity) {
27 HELIOS_ASSERT(entity.Valid(), "Entity '{}' is invalid!", entity);
28 }
29
30 constexpr EntityAddedMsg(const EntityAddedMsg&) noexcept = default;
31 constexpr EntityAddedMsg(EntityAddedMsg&&) noexcept = default;
32 constexpr ~EntityAddedMsg() noexcept = default;
33
34 constexpr EntityAddedMsg& operator=(const EntityAddedMsg&) noexcept = default;
35 constexpr EntityAddedMsg& operator=(EntityAddedMsg&&) noexcept = default;
36
37 /**
38 * @brief Gets the entity that was added.
39 * @return Entity that was added
40 */
41 [[nodiscard]] constexpr Entity GetEntity() const noexcept { return entity_; }
42
43private:
44 Entity entity_; ///< The entity that was added
45};
46
47/// @brief Message sent when an entity is destroyed.
49public:
50 static constexpr std::string_view kName = "EntityDestroyedMsg";
52 static constexpr bool kConsumable = false;
53 static constexpr bool kAsync = false;
54
55 /**
56 * @brief Constructs entity destroyed message.
57 * @warning Triggers assertion if entity is invalid.
58 * @param entity Destroyed entity
59 */
60 explicit constexpr EntityDestroyedMsg(Entity entity) noexcept
61 : entity_(entity) {
62 HELIOS_ASSERT(entity.Valid(), "Entity '{}' is invalid!", entity);
63 }
64
65 constexpr EntityDestroyedMsg(const EntityDestroyedMsg&) noexcept = default;
66 constexpr EntityDestroyedMsg(EntityDestroyedMsg&&) noexcept = default;
67 constexpr ~EntityDestroyedMsg() noexcept = default;
68
69 constexpr EntityDestroyedMsg& operator=(const EntityDestroyedMsg&) noexcept =
70 default;
71 constexpr EntityDestroyedMsg& operator=(EntityDestroyedMsg&&) noexcept =
72 default;
73
74 /**
75 * @brief Gets the entity that was destroyed.
76 * @return Entity that was destroyed
77 */
78 [[nodiscard]] constexpr Entity GetEntity() const noexcept { return entity_; }
79
80private:
81 Entity entity_; ///< The entity that was destroyed
82};
83
84/// @brief Message sent when a component is added.
85template <ComponentTrait T>
87public:
88 static constexpr std::string_view kName = "ComponentAddedMsg";
90 static constexpr bool kConsumable = false;
91 static constexpr bool kAsync = false;
92
93 /**
94 * @brief Constructs component added message.
95 * @warning Triggers assertion if entity is invalid.
96 * @param entity Entity that component was added to
97 */
98 explicit constexpr ComponentAddedMsg(Entity entity) noexcept
99 : entity_(entity) {
100 HELIOS_ASSERT(entity.Valid(), "Entity '{}' is invalid!", entity);
101 }
102
103 constexpr ComponentAddedMsg(const ComponentAddedMsg&) noexcept = default;
104 constexpr ComponentAddedMsg(ComponentAddedMsg&&) noexcept = default;
105 constexpr ~ComponentAddedMsg() noexcept = default;
106
107 constexpr ComponentAddedMsg& operator=(const ComponentAddedMsg&) noexcept =
108 default;
109 constexpr ComponentAddedMsg& operator=(ComponentAddedMsg&&) noexcept =
110 default;
111
112 /**
113 * @brief Gets the entity that the component was added to.
114 * @return Entity that the component was added to
115 */
116 [[nodiscard]] constexpr Entity GetEntity() const noexcept { return entity_; }
117
118private:
119 Entity entity_; ///< The entity that the component was added to
120};
121
122/// @brief Message sent when a component is removed.
123template <ComponentTrait T>
125public:
126 static constexpr std::string_view kName = "ComponentRemovedMsg";
128 static constexpr bool kConsumable = false;
129 static constexpr bool kAsync = false;
130
131 /**
132 * @brief Constructs component removed message.
133 * @warning Triggers assertion if entity is invalid.
134 * @param entity Entity that component was removed from
135 */
136 explicit constexpr ComponentRemovedMsg(Entity entity) noexcept
137 : entity_(entity) {
138 HELIOS_ASSERT(entity.Valid(), "Entity '{}' is invalid!", entity);
139 }
140
141 constexpr ComponentRemovedMsg(const ComponentRemovedMsg&) noexcept = default;
142 constexpr ComponentRemovedMsg(ComponentRemovedMsg&&) noexcept = default;
143 constexpr ~ComponentRemovedMsg() noexcept = default;
144
145 constexpr ComponentRemovedMsg& operator=(
146 const ComponentRemovedMsg&) noexcept = default;
147 constexpr ComponentRemovedMsg& operator=(ComponentRemovedMsg&&) noexcept =
148 default;
149
150 /**
151 * @brief Gets the entity that the component was removed from.
152 * @return Entity that the component was removed from
153 */
154 [[nodiscard]] constexpr Entity GetEntity() const noexcept { return entity_; }
155
156private:
157 Entity entity_; ///< The entity that the component was removed from
158};
159
160/// @brief Message sent when all components are cleared from an entity.
162public:
163 static constexpr std::string_view kName = "ComponentsClearedMsg";
165 static constexpr bool kConsumable = false;
166 static constexpr bool kAsync = false;
167
168 /**
169 * @brief Constructs components cleared message.
170 * @warning Triggers assertion if entity is invalid.
171 * @param entity Entity that components were cleared from
172 */
173 explicit constexpr ComponentsClearedMsg(Entity entity) noexcept
174 : entity_(entity) {
175 HELIOS_ASSERT(entity.Valid(), "Entity '{}' is invalid!", entity);
176 }
177
178 constexpr ComponentsClearedMsg(const ComponentsClearedMsg&) noexcept =
179 default;
180 constexpr ComponentsClearedMsg(ComponentsClearedMsg&&) noexcept = default;
181 constexpr ~ComponentsClearedMsg() noexcept = default;
182
183 constexpr ComponentsClearedMsg& operator=(
184 const ComponentsClearedMsg&) noexcept = default;
185 constexpr ComponentsClearedMsg& operator=(ComponentsClearedMsg&&) noexcept =
186 default;
187
188 /**
189 * @brief Gets the entity that the components were cleared from.
190 * @return Entity that the components were cleared from
191 */
192 [[nodiscard]] constexpr Entity GetEntity() const noexcept { return entity_; }
193
194private:
195 Entity entity_; ///< The entity that the components were cleared from
196};
197
198/// @brief Message sent when a resource is inserted.
199template <ResourceTrait T>
201 static constexpr std::string_view kName = "ResourceInsertedMsg";
203 static constexpr bool kConsumable = false;
204 static constexpr bool kAsync = false;
205};
206
207/// @brief Message sent when a resource is removed.
208template <ResourceTrait T>
210 static constexpr std::string_view kName = "ResourceRemovedMsg";
212 static constexpr bool kConsumable = false;
213 static constexpr bool kAsync = false;
214};
215
216} // namespace helios::ecs
#define HELIOS_ASSERT(condition,...)
Assertion macro that aborts execution in debug builds.
Definition assert.hpp:259
static constexpr bool kConsumable
constexpr ComponentAddedMsg(const ComponentAddedMsg &) noexcept=default
static constexpr auto kClearPolicy
constexpr ComponentAddedMsg(Entity entity) noexcept
Constructs component added message.
constexpr Entity GetEntity() const noexcept
Gets the entity that the component was added to.
constexpr ComponentAddedMsg(ComponentAddedMsg &&) noexcept=default
static constexpr std::string_view kName
static constexpr std::string_view kName
constexpr ComponentRemovedMsg(const ComponentRemovedMsg &) noexcept=default
constexpr ComponentRemovedMsg(ComponentRemovedMsg &&) noexcept=default
constexpr Entity GetEntity() const noexcept
Gets the entity that the component was removed from.
constexpr ComponentRemovedMsg(Entity entity) noexcept
Constructs component removed message.
static constexpr std::string_view kName
constexpr ComponentsClearedMsg(Entity entity) noexcept
Constructs components cleared message.
constexpr Entity GetEntity() const noexcept
Gets the entity that the components were cleared from.
constexpr ComponentsClearedMsg(const ComponentsClearedMsg &) noexcept=default
constexpr ComponentsClearedMsg(ComponentsClearedMsg &&) noexcept=default
static constexpr auto kClearPolicy
constexpr EntityAddedMsg(Entity entity) noexcept
Constructs entity added message.
constexpr EntityAddedMsg(const EntityAddedMsg &) noexcept=default
static constexpr bool kConsumable
static constexpr bool kAsync
constexpr Entity GetEntity() const noexcept
Gets the entity that was added.
static constexpr std::string_view kName
constexpr EntityAddedMsg(EntityAddedMsg &&) noexcept=default
constexpr EntityDestroyedMsg(const EntityDestroyedMsg &) noexcept=default
static constexpr std::string_view kName
constexpr EntityDestroyedMsg(EntityDestroyedMsg &&) noexcept=default
constexpr Entity GetEntity() const noexcept
Gets the entity that was destroyed.
constexpr EntityDestroyedMsg(Entity entity) noexcept
Constructs entity destroyed message.
Unique identifier for entities with generation counter to handle recycling.
Definition entity.hpp:22
@ kAutomatic
Messages are automatically cleared after double buffer cycle.
Definition message.hpp:18
Message sent when a resource is inserted.
static constexpr std::string_view kName
Message sent when a resource is removed.
static constexpr std::string_view kName