|
wPlot2D version: 0.1.0
A lightweight C++ library for clear and customizable 2D scientific plots.
|
Represents an entity in the ECS (Entity-Component System) architecture. More...
#include <wEntity.hpp>

Public Member Functions | |
| Entity () | |
| virtual | ~Entity () |
| unsigned int | getEntityID () const |
| Returns the unique ID associated with this entity. | |
| void | clearComponents () |
| Removes all components currently attached to the entity. | |
| template<typename T, typename... Args> | |
| std::shared_ptr< T > | addComponent (Args &&... args) |
| Adds a new component of type T to the entity. | |
| template<typename T> | |
| void | removeComponent () |
| Removes the component of type T from the entity. | |
| template<typename T> | |
| bool | hasComponent () const noexcept |
| Checks whether the entity has a component of type T. | |
| template<typename T> | |
| std::shared_ptr< T > | getComponent () const |
| Retrieves the component of type T attached to the entity. | |
| template<typename T> | |
| std::shared_ptr< T > | requireComponent (const std::string &context="") const |
| Retrieves the component of type T and throws if it's missing. | |
| template<typename Interface> | |
| std::shared_ptr< Interface > | getInterfaceComponent () const |
| Returns the first component that implements the specified interface. | |
Static Public Member Functions | |
| static void | resetEntityIDCounter () |
| Resets the global entity ID counter to zero. | |
Represents an entity in the ECS (Entity-Component System) architecture.
Each entity is uniquely identified and can dynamically manage a collection of components. Components are stored in a type-safe map and accessed by type.
The class provides utility methods to add, remove, retrieve and query components, as well as retrieve components through interfaces.
| wEngine::Entity::Entity | ( | ) |
|
virtual |
|
nodiscard |
Returns the unique ID associated with this entity.
| void wEngine::Entity::clearComponents | ( | ) |
Removes all components currently attached to the entity.
|
static |
Resets the global entity ID counter to zero.
This affects all subsequently created entities. Use with caution, especially in multi-entity systems.
|
inline |
Adds a new component of type T to the entity.
Constructs the component using the provided arguments and attaches it to the entity.
| T | Component type, must inherit from wEngine::Component. |
| Args | Variadic arguments used to construct the component. |
| args | Constructor arguments forwarded to the component. |
| std::runtime_error | if a component of the same type already exists in the entity. |
|
inline |
Removes the component of type T from the entity.
If no such component exists, this operation does nothing.
| T | Component type to remove. |
|
inlinenodiscardnoexcept |
Checks whether the entity has a component of type T.
| T | Component type to check. |
|
inlinenodiscard |
Retrieves the component of type T attached to the entity.
| T | Component type to retrieve. |
|
inlinenodiscard |
Retrieves the component of type T and throws if it's missing.
This method is similar to getComponent( ), but throws a std::runtime_error if the component is not found. Useful for critical systems where components must be present.
| T | The type of the component. |
| context | Optional string to specify the context of the call (e.g., method name). |
| std::runtime_error | if the component is not found. |
|
inlinenodiscard |
Returns the first component that implements the specified interface.
Checks all components attached to the entity using dynamic casting. If a component matches the given interface type, it is returned.
| Interface | The desired interface type. |