58 Log::Debug(fmt::format(
"[EntityID:{}] AddComponent: {}",
value,
typeid(TComponent).name()));
59 return core.
GetRegistry().emplace<TComponent>(
value, std::forward<TComponent>(component));
69 template <
typename TComponent,
typename... TArgs>
73 Log::Debug(fmt::format(
"[EntityID:{}] AddComponent: {}",
value,
typeid(TComponent).name()));
74 return core.
GetRegistry().emplace<TComponent>(
value, std::forward<TArgs>(args)...);
84 template <
typename TComponent,
typename... TArgs>
112 template <
typename TTempComponent,
typename... TArgs>
118 Log::Debug(fmt::format(
"RemoveTemporaryComponent: {}",
typeid(TTempComponent).name()));
119 c.GetRegistry().clear<TTempComponent>();
164 Log::Debug(fmt::format(
"[EntityID:{}] RemoveComponent: {}",
value,
typeid(TComponent).name()));
194static_assert(
sizeof(EntityId) ==
sizeof(
EntityId::ValueType),
"EntityId size must be equal to Id size");
200template <>
struct std::hash<
Engine::EntityId> {
208 return std::hash<entt::id_type>{}(entityId.value);
214template <>
struct fmt::formatter<
Engine::EntityId> : fmt::formatter<std::string> {
225 if (entityId.IsNull())
227 return fmt::formatter<std::string>::format(
"null_entity", ctx);
The core is the place where all the data of the engine is stored. It contains the registry (entities)...
Definition Core.hpp:33
bool IsEntityValid(Id entity) const
Check if entity is valid in the context of the registry. It check if the id of the entity exist.
Definition Core.cpp:95
Registry & GetRegistry()
Get the entt::registry that contains all components. It should be used to update component through sy...
Definition Core.hpp:50
std::string EntityToDebugString(const T &entity)
Definition EntityToIDString.hpp:12
void Debug(const T &msg) noexcept
Definition Logger.hpp:45
entt::id_type value
Definition Id.hpp:20
Represents a unique identifier for an entity in the Engine's entity-component system....
Definition EntityId.hpp:14
Id::ValueType ValueType
The underlying value type of the EntityId, which is the same as Engine::Id::ValueType.
Definition EntityId.hpp:16
decltype(auto) AddComponentIfNotExists(Engine::Core &core, TArgs &&...args)
Add a component to an entity if it does not already exist.
Definition EntityId.hpp:85
bool IsValid(const Engine::Core &core) const
Checks if the EntityId is valid. An EntityId is considered valid if it corresponds to an existing ent...
Definition EntityId.hpp:47
decltype(auto) AddComponent(Engine::Core &core, TArgs &&...args)
Add a component to an entity.
Definition EntityId.hpp:70
constexpr EntityId(Id id)
Constructs an EntityId from an Engine::Id. This allows for implicit conversion from Engine::Id to Ent...
Definition EntityId.hpp:29
decltype(auto) AddTemporaryComponent(Engine::Core &core, TArgs &&...args)
Add a temporary component to an entity. Temporary component are removed when calling RemoveTemporaryC...
Definition EntityId.hpp:113
static constexpr EntityId Null()
Returns a null EntityId. A null EntityId is an EntityId that does not correspond to any valid entity ...
Definition EntityId.hpp:40
void RemoveComponent(Engine::Core &core)
Remove a component from an entity.
Definition EntityId.hpp:162
bool HasComponents(const Engine::Core &core) const
Check if entity have one or multiple component's type.
Definition EntityId.hpp:98
decltype(auto) GetComponents(Engine::Core &core) const
Get components of type TComponent from the entity.
Definition EntityId.hpp:141
constexpr EntityId(ValueType v=NullValue())
Constructs an EntityId with the given value. By default, it constructs a null EntityId.
Definition EntityId.hpp:23
decltype(auto) TryGetComponent(Engine::Core &core)
Try to get a component of type TComponent from the entity. It returns a pointer to the component if i...
Definition EntityId.hpp:153
decltype(auto) GetComponents(Engine::Core &core)
Get components of type TComponent from an entity.
Definition EntityId.hpp:131
decltype(auto) AddComponent(Engine::Core &core, TComponent &&component)
Add a component to an entity.
Definition EntityId.hpp:55
static void RemoveTemporaryComponents(Core &core)
Remove all temporary components from the registry. This system should be called at the end of each lo...
Definition EntityId.hpp:173
static std::unordered_map< std::type_index, std::function< void(Core &)> > temporaryComponent
Definition EntityId.hpp:187
static constexpr ValueType NullValue()
Get the null value for this ID type. This returns the null value defined by EnTT's id_type,...
Definition Id.hpp:66
constexpr Id(ValueType v=NullValue())
Constructor for Id.
Definition Id.hpp:56
entt::id_type ValueType
Definition Id.hpp:50
std::size_t operator()(const Engine::EntityId &entityId) const noexcept
Hash function for EntityId. It uses the hash of the underlying ValueType to compute the hash of the E...
Definition EntityId.hpp:206