|
Engine²
Open-source game engine written in C++.
|
Wrapper class providing a convenient interface for entity manipulation with the Core. Entity acts as a handle to an entity in the registry, combining a Core reference with an EntityId. It provides utility methods to add, remove, and query components, and maintains context relative to the Core it belongs to. More...
#include <Entity.hpp>
Public Member Functions | |
| Entity (Core &core, EntityId entityId) | |
| Create an Entity from EntityId and the Core it belongs to. | |
| ~Entity ()=default | |
| Default destructor for Entity. It does not perform any special cleanup, as the Core is responsible for managing the entity's lifecycle. | |
| bool | IsAlive () const |
| Check if the entity is alive. | |
| EntityId | Id () const |
| Get the EntityId associated with this Entity. | |
| explicit (false) inline operator EntityId() const | |
| Implicit conversion operator to EntityId. | |
| void | Kill () |
| Kill the entity, removing all components and making it invalid. After calling this method, the EntityId will no longer correspond to a valid entity in the Core's registry, and the Entity will be considered dead. | |
| template<typename TComponent> | |
| decltype(auto) | AddComponent (TComponent &&component) |
| Add a component to an entity. | |
| template<typename TComponent, typename... TArgs> | |
| decltype(auto) | AddComponent (TArgs &&...args) |
| Add a component to an entity. | |
| template<typename TComponent, typename... TArgs> | |
| decltype(auto) | AddComponentIfNotExists (TArgs &&...args) |
| Add a component to an entity if it does not already exist. | |
| template<typename TTempComponent, typename... TArgs> | |
| decltype(auto) | AddTemporaryComponent (TArgs &&...args) |
| Add a temporary component to an entity. Temporary component are removed when calling RemoveTemporaryComponents system. | |
| template<typename TComponent> | |
| void | RemoveComponent () |
| Remove a component from an entity. | |
| template<typename... TComponent> | |
| bool | HasComponents () const |
| Check if entity have one or multiple component's type. | |
| template<typename... TComponent> | |
| decltype(auto) | GetComponents () |
| Get components of type TComponent from the entity. | |
| template<typename... TComponent> | |
| decltype(auto) | GetComponents () const |
| Get components of type TComponent from the entity. | |
| template<typename TComponent> | |
| decltype(auto) | TryGetComponent () |
| 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. | |
| bool | operator== (const Entity &rhs) const |
| Equality operator for Entity. It compares the underlying EntityId values to determine if two Entity instances refer to the same entity in the registry. | |
| bool | operator== (const EntityId &rhs) const |
| Equality operator for Entity and EntityId. It compares the underlying EntityId value of the Entity with the EntityId to determine if they refer to the same entity in the registry. | |
Static Public Member Functions | |
| static void | RemoveTemporaryComponents (Core &core) |
| Remove all temporary components from the registry. | |
Private Member Functions | |
| constexpr Core & | GetCore () const |
| Get a reference to the Core instance that this Entity belongs to. This is used internally to access the registry and other resources when manipulating components. | |
Private Attributes | |
| std::reference_wrapper< Core > | _core |
| A reference to the Core instance that this Entity belongs to. | |
| EntityId | _entityId |
| The EntityId that identifies the entity in the Core's registry. This is the underlying identifier for the entity that this Entity class wraps around, and is used for all operations that manipulate the entity in the registry. | |
Wrapper class providing a convenient interface for entity manipulation with the Core. Entity acts as a handle to an entity in the registry, combining a Core reference with an EntityId. It provides utility methods to add, remove, and query components, and maintains context relative to the Core it belongs to.
|
default |
|
inline |
Add a component to an entity.
| TComponent | The type of the component to add to the registry. |
| TArgs | The types of the arguments to construct the component in-place in the registry. |
| args | The arguments to construct the component in-place in the registry. |
|
inline |
|
inline |
Add a component to an entity if it does not already exist.
| TComponent | type to add to registry. |
| TArgs | type used to create the component. |
| args | parameters used to instanciate component directly in registry memory. |
|
inline |
Add a temporary component to an entity. Temporary component are removed when calling RemoveTemporaryComponents system.
| TTempComponent | type to add to registry |
| TArgs | type used to create the component |
| args | parameters used to instanciate component directly in registry memory |
|
inline |
|
inline |
Get components of type TComponent from the entity.
| TComponent | components to get. |
|
inline |
Get components of type TComponent from the entity.
| TComponent | components to get. |
|
inlineconstexprprivate |
|
inline |
Check if entity have one or multiple component's type.
| TComponent | components to check. |
|
inline |
| bool Engine::Entity::IsAlive | ( | ) | const |
Check if the entity is alive.
| void Engine::Entity::Kill | ( | ) |
|
inline |
|
inline |
|
inline |
Remove a component from an entity.
| TComponent | The type of the component to remove from the registry. |
|
inlinestatic |
|
inline |
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.
| TComponent | The type of the component to get from the entity. |
|
private |
|
private |