Engine²
Open-source game engine written in C++.
Loading...
Searching...
No Matches
Engine::EntityId Struct Reference

Represents a unique identifier for an entity in the Engine's entity-component system. An EntityId is just Id with utility methods to manage components associated with the entity but not the core. More...

#include <EntityId.hpp>

Inheritance diagram for Engine::EntityId:
Engine::Id Engine::BasicId< Id, entt::id_type >

Public Types

using ValueType = Id::ValueType
 The underlying value type of the EntityId, which is the same as Engine::Id::ValueType.
Public Types inherited from Engine::Id
using ValueType = entt::id_type

Public Member Functions

constexpr EntityId (ValueType value_=NullValue())
 Constructs an EntityId with the given value. By default, it constructs a null EntityId.
constexpr EntityId (Id id)
 Constructs an EntityId from an Engine::Id. This allows for implicit conversion from Engine::Id to EntityId.
bool IsValid (const Engine::Core &core) const
 Checks if the EntityId is valid. An EntityId is considered valid if it corresponds to an existing entity in the Core's registry.
template<typename TComponent>
decltype(auto) AddComponent (Engine::Core &core, TComponent &&component)
 Add a component to an entity.
template<typename TComponent, typename... TArgs>
decltype(auto) AddComponent (Engine::Core &core, TArgs &&...args)
 Add a component to an entity.
template<typename TComponent, typename... TArgs>
decltype(auto) AddComponentIfNotExists (Engine::Core &core, TArgs &&...args)
 Add a component to an entity if it does not already exist.
template<typename... TComponent>
bool HasComponents (const Engine::Core &core) const
 Check if entity have one or multiple component's type.
template<typename TTempComponent, typename... TArgs>
decltype(auto) AddTemporaryComponent (Engine::Core &core, TArgs &&...args)
 Add a temporary component to an entity. Temporary component are removed when calling RemoveTemporaryComponents system.
template<typename... TComponent>
decltype(auto) GetComponents (Engine::Core &core)
 Get components of type TComponent from an entity.
template<typename... TComponent>
decltype(auto) GetComponents (Engine::Core &core) const
 Get components of type TComponent from the entity.
template<typename TComponent>
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 it exists, or nullptr if it does not exist.
template<typename TComponent>
void RemoveComponent (Engine::Core &core)
 Remove a component from an entity.
Public Member Functions inherited from Engine::Id
constexpr Id (ValueType value_=NullValue())
 Constructor for Id.
constexpr operator ValueType () const
 Implicit conversion operator to the underlying entt::id_type, allowing seamless use of Id instances where entt::id_type is expected.
Public Member Functions inherited from Engine::BasicId< Id, entt::id_type >
constexpr bool IsNull (void) const
 Checks if the ID is null/invalid by comparing its value to the null value defined by the derived class.

Static Public Member Functions

static constexpr EntityId Null ()
 Returns a null EntityId. A null EntityId is an EntityId that does not correspond to any valid entity in the registry.
static void RemoveTemporaryComponents (Core &core)
 Remove all temporary components from the registry. This system should be called at the end of each loop to ensure that temporary components are removed after they have been used.
Static Public Member Functions inherited from Engine::Id
static constexpr ValueType NullValue (void)
 Get the null value for this ID type. This returns the null value defined by EnTT's id_type, which is typically.
static constexpr Id Null (void)
 Get a null instance of Id, which has its value set to the null value defined by NullValue().
Static Public Member Functions inherited from Engine::BasicId< Id, entt::id_type >
static constexpr Id Null (void)
 Get the null value for this ID type. This should be defined by the derived class to specify what constitutes a null/invalid ID.

Static Private Attributes

static std::unordered_map< std::type_index, std::function< void(Core &)> > temporaryComponent = {}

Additional Inherited Members

Public Attributes inherited from Engine::BasicId< Id, entt::id_type >
entt::id_type value
 The underlying value of the ID.

Detailed Description

Represents a unique identifier for an entity in the Engine's entity-component system. An EntityId is just Id with utility methods to manage components associated with the entity but not the core.

Note
EntityId maintains the same memory footprint as its underlying ValueType (Engine::Id).
See also
Engine::Id
Engine::Core

Member Typedef Documentation

◆ ValueType

The underlying value type of the EntityId, which is the same as Engine::Id::ValueType.

Constructor & Destructor Documentation

◆ EntityId() [1/2]

Engine::EntityId::EntityId ( ValueType value_ = NullValue())
constexpr

Constructs an EntityId with the given value. By default, it constructs a null EntityId.

Parameters
vThe value to initialize the EntityId with. If not provided, it defaults to the null value defined by Engine::Id.

◆ EntityId() [2/2]

Engine::EntityId::EntityId ( Id id)
constexpr

Constructs an EntityId from an Engine::Id. This allows for implicit conversion from Engine::Id to EntityId.

Parameters
idThe Engine::Id to convert.

Member Function Documentation

◆ AddComponent() [1/2]

template<typename TComponent, typename... TArgs>
decltype(auto) Engine::EntityId::AddComponent ( Engine::Core & core,
TArgs &&... args )

Add a component to an entity.

Template Parameters
TComponentThe type of the component to add to the registry.
TArgsThe types of the arguments to construct the component in-place in the registry.
Parameters
coreThe Core instance whose registry is used to store the component.
argsThe arguments to construct the component in-place in the registry.
Returns
A reference to the added component.
Todo
put the log in the core emplace

◆ AddComponent() [2/2]

template<typename TComponent>
decltype(auto) Engine::EntityId::AddComponent ( Engine::Core & core,
TComponent && component )

Add a component to an entity.

Template Parameters
TComponentThe type of the component to add to the registry.
Parameters
coreThe Core instance whose registry is used to store the component.
componentThe rvalue of the component to add to the registry.
Returns
A reference to the added component.
Todo
put the log in the core emplace

◆ AddComponentIfNotExists()

template<typename TComponent, typename... TArgs>
decltype(auto) Engine::EntityId::AddComponentIfNotExists ( Engine::Core & core,
TArgs &&... args )

Add a component to an entity if it does not already exist.

Template Parameters
TComponenttype to add to registry.
TArgstype used to create the component.
Parameters
coreregistry used to store the component.
argsparameters used to instanciate component directly in registry memory.
Returns
reference of the added component.

◆ AddTemporaryComponent()

template<typename TTempComponent, typename... TArgs>
decltype(auto) Engine::EntityId::AddTemporaryComponent ( Engine::Core & core,
TArgs &&... args )

Add a temporary component to an entity. Temporary component are removed when calling RemoveTemporaryComponents system.

Template Parameters
TTempComponenttype to add to registry
TArgstype used to create the component
Parameters
coreregistry used to store the component
argsparameters used to instanciate component directly in registry memory
Returns
reference of the added component
See also
Engine::EntityId::RemoveTemporaryComponents

◆ GetComponents() [1/2]

template<typename... TComponent>
decltype(auto) Engine::EntityId::GetComponents ( Engine::Core & core)

Get components of type TComponent from an entity.

Template Parameters
TComponentThe type of the component to get from the registry.
Parameters
coreThe Core instance whose registry is used to store the component.
Returns
The components of type TComponent from the entity.

◆ GetComponents() [2/2]

template<typename... TComponent>
decltype(auto) Engine::EntityId::GetComponents ( Engine::Core & core) const

Get components of type TComponent from the entity.

Template Parameters
TComponentThe type of the component to get from the registry.
Parameters
coreThe Core instance whose registry is used to store the component.
Returns
The components of type TComponent from the entity.

◆ HasComponents()

template<typename... TComponent>
bool Engine::EntityId::HasComponents ( const Engine::Core & core) const

Check if entity have one or multiple component's type.

Template Parameters
TComponentcomponents to check.
Parameters
corecontext used to check if the entity have the component in the core's registry.
Returns
true if entity have all requested component, false otherwise.

◆ IsValid()

bool Engine::EntityId::IsValid ( const Engine::Core & core) const
inline

Checks if the EntityId is valid. An EntityId is considered valid if it corresponds to an existing entity in the Core's registry.

Parameters
coreThe Core instance to check the validity against.
Returns
true if the EntityId is valid, false otherwise.

◆ Null()

EntityId Engine::EntityId::Null ( void )
staticconstexpr

Returns a null EntityId. A null EntityId is an EntityId that does not correspond to any valid entity in the registry.

Returns
A null EntityId.

◆ RemoveComponent()

template<typename TComponent>
void Engine::EntityId::RemoveComponent ( Engine::Core & core)

Remove a component from an entity.

Template Parameters
TComponentThe type of the component to remove from the registry.
Parameters
coreThe Core instance whose registry is used to store the component.
Todo
put the log in the core emplace

◆ RemoveTemporaryComponents()

void Engine::EntityId::RemoveTemporaryComponents ( Core & core)
inlinestatic

Remove all temporary components from the registry. This system should be called at the end of each loop to ensure that temporary components are removed after they have been used.

Parameters
coreThe Core instance whose registry is used to store the components.
See also
Engine::EntityId::AddTemporaryComponent

◆ TryGetComponent()

template<typename TComponent>
decltype(auto) Engine::EntityId::TryGetComponent ( Engine::Core & core)

Try to get a component of type TComponent from the entity. It returns a pointer to the component if it exists, or nullptr if it does not exist.

Template Parameters
TComponentThe type of the component to get from the registry.
Parameters
coreThe Core instance whose registry is used to store the component.
Returns
A pointer to the component of type TComponent from the entity if it exists, or nullptr if it does not exist.

Member Data Documentation

◆ temporaryComponent

std::unordered_map<std::type_index, std::function<void(Core &)> > Engine::EntityId::temporaryComponent = {}
inlinestaticprivate

The documentation for this struct was generated from the following files: