|
CeresEngine 0.2.0
A game development framework
|
The base entity class. More...
#include <CeresEngine/Entity/Entity.hpp>
Public Member Functions | |
| Entity () noexcept=default | |
| Creates a new empty entity. | |
| Entity (EntityManager &entityManager, EntityID id) noexcept | |
| Creates a new entity attached to a entity manager. | |
| Entity (std::nullptr_t) noexcept | |
| Creates a new empty entity. | |
| Entity & | operator= (std::nullptr_t) noexcept |
Empties a EntityObject. The entity is not deallocated. | |
| Entity (const Entity &other) noexcept=default | |
| Creates a new entity by copying another. | |
| Entity & | operator= (const Entity &other) noexcept=default |
| Assing the contents of the entity by copying the contents of another. | |
| bool | valid () const noexcept |
| Checks if the entity is still valid. | |
| Entity | copy () const |
| Copies the entity and all its components. | |
| template<typename Block > | |
| Entity | copy (Block &&block) const |
Copies the entity and all its components. Executes block as. | |
| void | destroy () const |
| Destroys the entity. | |
| AbstractComponent & | add (const ComponentType &type, const Box &initialValue=nullptr) const |
Adds a new component of the given type. | |
| template<CComponent C, typename... Args> | |
| C & | add (Args &&... args) const noexcept(std::is_nothrow_constructible_v< C, Args... >) |
| Adds a new component. | |
| template<CComponent C, typename Block , typename... Args> | |
| C & | addWith (Block &&block, Args &&... args) const noexcept(std::is_nothrow_constructible_v< C, Args... >) |
Adds a new component and calls block with the added component. | |
| template<CComponent C, typename... Args> | |
| C & | set (Args &&... args) const noexcept(std::is_nothrow_constructible_v< C, Args... >) |
| Sets a component. | |
| void | remove (const ComponentType &type) const |
Removes a component of the given type from the entity. | |
| template<CComponent C> | |
| void | remove () const noexcept(std::is_nothrow_destructible_v< C >) |
Removes a component of type C from the entity. | |
| AbstractComponent & | get (const ComponentType &type) const |
Gets a component of the given type. | |
| template<CComponent C> | |
| C & | get () const noexcept |
Gets a component of type C. | |
| template<CComponent C0, CComponent C1, CComponent... Cs> | |
| Tuple< C0 &, C1 &, Cs &... > | get () const noexcept |
Gets a set of components of types C0, C1 and Cs. | |
| AbstractComponent & | getOr (const ComponentType &type) const |
Gets a component of the given type. | |
| template<CComponent C> | |
| C & | getOr () const noexcept(std::is_nothrow_constructible_v< C >) |
Gets a component of type C. | |
| template<CComponent C0, CComponent C1, CComponent... Cs> | |
| Tuple< C0 &, C1 &, Cs &... > | getOr () const noexcept |
Gets a set of components of types C0, C1 and Cs. | |
| AbstractComponent * | getIf (const ComponentType &type) const |
Gets a component of the given type. | |
| template<CComponent C> | |
| C * | getIf () const noexcept |
Gets a component of type C. | |
| template<CComponent C0, CComponent C1, CComponent... Cs> | |
| Tuple< C0 *, C1 *, Cs *... > | getIf () const noexcept |
Gets a set of components of types C0, C1 and Cs. | |
| Vector< AbstractComponent * > | getComponents () const |
| bool | has (const ComponentType &type) const noexcept |
Checks if the entity has all components of the given type. | |
| template<CComponent C, CComponent... Cs> | |
| bool | has () const noexcept |
Checks if the entity has all components of types Cs. | |
| void | clear () const |
| Removes all components attached to the entity, without destroying the entity itself. | |
| bool | empty () const noexcept |
| Checks if the entity is empty (i.e. | |
| template<typename E > | |
| bool | is () const noexcept |
Checks if the entity matches the criteria to be considered a E entity object. | |
| template<typename E > | |
| E | as () const |
Converts the entity handle type into a E entity object. | |
| template<typename... Cs> | |
| EntityObject< Cs... > | having () const |
Converts the entity handle type into a EntityObject<Cs...> object. | |
| template<typename E > | |
| E | being () const noexcept |
Converts the entity handle type into a E entity object. | |
| Entity | getParent () const noexcept |
| Gets the parent entity. | |
| template<typename P > | |
| P | getParent () const noexcept |
Gets the parent entity of type T. | |
| void | setParent (Entity parent) const |
| Sets the parent entity. | |
| const Vector< Entity > & | getChildren () const noexcept |
| Gets the list of children entities. | |
| template<typename T > | |
| Generator< T > | getChildren () const noexcept |
| Gets the list of children entities. | |
| void | setChildren (const Vector< Entity > &children) |
| Sets all entities as children of this entity. | |
| StringView | getName () const noexcept |
| Gets the name for the entity. | |
| void | setName (String name) const |
| Sets the name for the entity. | |
| template<CEntityEvent E, typename... Args> | |
| void | emit (Args &&... args) const |
Emits a event of type E to all event listeners. | |
| template<CEntityEvent E> | |
| void | emit (const E &event) const |
Emits a event of type E to all event listeners. | |
| template<CEntityEvent E, typename Listener > | |
| WeakEventConnection | on (Listener &&listener) const |
| Subscribes a listener that waits for events from the entity. | |
| template<CEntityAction A, typename... Args> | |
| bool | canAct (Args &&... args) const |
Checks if the the entity is capable of acting on the given action A. | |
| template<CEntityAction A, typename... Args> | |
| decltype(auto) | act (Args &&... args) const |
Orders the entity to act on the action A. | |
| template<typename T , CComponent Component> | |
| auto | mutate (T Component::*ptr) const |
Accesses an element from an existing Component. | |
| template<typename MutateFunc , typename T , CComponent Component> | |
| decltype(auto) | mutate (MutateFunc &&func, T Component::*ptr) const |
Accesses an element from an existing Component. | |
| template<typename T , CComponent Component> | |
| const T & | read (const T Component::*ptr) const |
Accesses an element from an existing Component. | |
| EntityID | getEntityID () const noexcept |
| EntityManager & | getEntityManager () const noexcept |
| operator bool () const noexcept | |
| Checks if the entity is still valid. | |
| Entity | operator[] (const EntityIndex childIndex) const |
| Entity | operator[] (const StringView childName) const |
Public Attributes | |
| EntityManager * | entityManager = nullptr |
| The owning entity manager. | |
| EntityID | entityID = {} |
| The entity ID. | |
Friends | |
| template<typename T , typename Component > | |
| struct | ComponentFieldMutator |
| bool | operator== (const Entity &a, const Entity &b) noexcept |
| Compares two entities for equality. | |
| bool | operator!= (const Entity &a, const Entity &b) noexcept |
| Compares two entities for inequality. | |
| bool | operator== (const Entity &a, const EntityID &b) noexcept |
| Compares two entities for equality. | |
| bool | operator!= (const Entity &a, const EntityID &b) noexcept |
| Compares two entities for inequality. | |
| bool | operator== (const Entity &a, std::nullptr_t b) noexcept |
| Checks if a entity is empty. | |
| bool | operator!= (const Entity &a, std::nullptr_t b) noexcept |
| Checks if a entity is not empty. | |
| std::ostream & | operator<< (std::ostream &os, const Entity &entity) |
| Prints a string representation of the Entity. | |
| template<typename E > | |
| E | unsafeCastEntityObject (EntityManager &entityManager, EntityID entityID) noexcept |
The base entity class.
The entity acts as an identifier that can be used as an entrypoint for querying data from a set of components stored in an entity manager.
Typically you don't interact directly with the Entity class and instead use the typed EntityObject or aliases provided by the engine like Light, Camera and SceneObject.
|
defaultnoexcept |
Creates a new empty entity.
|
noexcept |
Creates a new entity attached to a entity manager.
| entityManager | The entity manager that owns the entity |
| id | The entity ID |
|
noexcept |
Creates a new empty entity.
Creates a new entity by copying another.
NOTE: this will only copy the entity handle, the components and the entity ID will still be the same.
| other | The entity to copy from |
|
inline |
Orders the entity to act on the action A.
| A | the action type |
| Args | the action constructor argument types |
| args | The action constructor arguments |
|
inlinenoexcept |
Adds a new component.
If a component of type C is already present, this method throws.
| C | the component type to be added |
| Args | the component constructor argument types |
| args | The component constructor arguments |
| AbstractComponent & CeresEngine::Entity::add | ( | const ComponentType & | type, |
| const Box & | initialValue = nullptr |
||
| ) | const |
Adds a new component of the given type.
If a component of the given type is already present, this method throws.
| type | The component type to be added. |
Adds a new component and calls block with the added component.
If a component of type C is already present, this method throws.
| C | the component type to be added |
| Block | the block type |
| Args | the component constructor argument types |
| block | The block to be called |
| args | The component constructor arguments |
Converts the entity handle type into a E entity object.
| E | the entity object type |
E Converts the entity handle type into a E entity object.
This method is similar to as but instead of throwing in case the entity cannot be E, it returns a nullptr entity.
| E | the entity object type |
E
|
inline |
Checks if the the entity is capable of acting on the given action A.
| A | the action type |
| Args | the action constructor argument types |
| args | The action constructor arguments |
true if act can be called, false otherwise. | void CeresEngine::Entity::clear | ( | ) | const |
Removes all components attached to the entity, without destroying the entity itself.
| Entity CeresEngine::Entity::copy | ( | ) | const |
Copies the entity and all its components.
Copies the entity and all its components. Executes block as.
| Block | the block type |
| block | The block to be executed after copying |
| void CeresEngine::Entity::destroy | ( | ) | const |
Destroys the entity.
|
inline |
Emits a event of type E to all event listeners.
The event E is constructed by forwarding args to the event constructor.
| E | the event type to be emitted |
| Args | the event constructor argument types |
| args | The event constructor arguments |
Emits a event of type E to all event listeners.
| E | the event type to be emitted |
| event | The event to be emitted |
|
noexcept |
Checks if the entity is empty (i.e.
has no components attached).
|
inlinenoexcept |
Gets a component of type C.
If a component of type C is not present, this method throws.
| C | the component type to be retrieved |
|
inlinenoexcept |
Gets a set of components of types C0, C1 and Cs.
If any of the components are not present, this method throws.
| C0 | The type of the first component to be retrieved |
| C1 | The type of the second component to be retrieved |
| Cs | The remaining types of the components to be retrieved |
| AbstractComponent & CeresEngine::Entity::get | ( | const ComponentType & | type | ) | const |
Gets a component of the given type.
If a component of the given type is not present, this method throws.
| type | The component type to be retrieved. |
Gets the list of children entities.
Gets the list of children entities.
| Vector< AbstractComponent * > CeresEngine::Entity::getComponents | ( | ) | const |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
Gets a component of type C.
If a component of type C is not present, nullptr is returned
| C | the component type to be retrieved |
|
inlinenoexcept |
Gets a set of components of types C0, C1 and Cs.
If any of the components are not present, nullptr is returned.
| C0 | The type of the first component to be retrieved |
| C1 | The type of the second component to be retrieved |
| Cs | The remaining types of the components to be retrieved |
| AbstractComponent * CeresEngine::Entity::getIf | ( | const ComponentType & | type | ) | const |
Gets a component of the given type.
If a component of the given type is not present, nullptr is returned.
| type | The component type to be retrieved. |
|
noexcept |
Gets the name for the entity.
|
inlinenoexcept |
Gets a set of components of types C0, C1 and Cs.
If any of the components are not present, a new component is created.
| C0 | The type of the first component to be retrieved |
| C1 | The type of the second component to be retrieved |
| Cs | The remaining types of the components to be retrieved |
|
inlinenoexcept |
Gets a component of type C.
If a component of type C is not present, a new component is created.
| C | the component type to be retrieved |
| AbstractComponent & CeresEngine::Entity::getOr | ( | const ComponentType & | type | ) | const |
Gets a component of the given type.
If a component of the given type is not present, a new component is created and returned.
| type | The component type to be retrieved. |
|
noexcept |
Gets the parent entity.
If the entity has not parent, a nullptr entity is returned.
Gets the parent entity of type T.
If the entity has no parent of type T, a nullptr entity is returned.
| P | the entity parent type |
|
inlinenoexcept |
Checks if the entity has all components of types Cs.
| Cs | the component types to be checked |
|
noexcept |
Checks if the entity has all components of the given type.
| type | The component type to be checked. |
true if the components are present, false otherwise.
|
inline |
Converts the entity handle type into a EntityObject<Cs...> object.
| Cs | the component types |
EntityObject<Cs...> Checks if the entity matches the criteria to be considered a E entity object.
| E | the entity object type |
E entity object. | decltype(auto) CeresEngine::Entity::mutate | ( | MutateFunc && | func, |
| T Component::* | ptr | ||
| ) | const |
Accesses an element from an existing Component.
If the component does not exists, it is undefined behavior.
| MutateFunc | A function to be called with the component property. |
| T | The component member type. |
| Component | The component type. |
| func | A function to be called with the component property. |
| ptr | The component element pointer to member. |
|
inline |
Subscribes a listener that waits for events from the entity.
| E | the event type to be subscribed |
| Listener | the listener type |
| listener | The listener |
disconnect on the connection will cancel further event calls.
|
inlineexplicitnoexcept |
Checks if the entity is still valid.
Assing the contents of the entity by copying the contents of another.
NOTE: this will only copy the entity handle, the components and the entity ID will still be the same.
| other | The entity to copy from |
|
noexcept |
Empties a EntityObject. The entity is not deallocated.
|
inline |
| childIndex | The child index (from 0) |
childIndex
|
inline |
| childName | The child name |
childName
|
inlinenoexcept |
Removes a component of type C from the entity.
| C | the component type to be removed |
| void CeresEngine::Entity::remove | ( | const ComponentType & | type | ) | const |
Removes a component of the given type from the entity.
| type | The component type to be removed. |
|
inlinenoexcept |
Sets a component.
If a component of type C is already present, a new component is created and added. If the component already exists, its contents are replaced.
| C | the component type to be set |
| Args | the component constructor argument types |
| args | the component constructor arguments |
Sets all entities as children of this entity.
All entities must belong to the same entity manager.
Sets the name for the entity.
| name | The entity name |
Sets the parent entity.
Setting the parent entity will automatically add *this entity as a children of parent.
| parent | The parent to be set |
|
noexcept |
Checks if the entity is still valid.
Compares two entities for inequality.
Two entity are considered equal iff their index and version match and they are managed by the same entity manager.
| a | The left hand side operator argument |
| b | The right hand side operator argument |
Compares two entities for inequality.
Two entity are considered equal iff their index and version match and they are managed by the same entity manager.
| a | The left hand side operator argument |
| b | The right hand side operator argument |
Checks if a entity is not empty.
| a | The left hand side operator argument |
| b | The right hand side operator argument |
Prints a string representation of the Entity.
| os | The output stream to print to |
| entity | The entity ID to be printed |
os Compares two entities for equality.
Two entity are considered equal iff their index and version match and they are managed by the same entity manager.
| a | The left hand side operator argument |
| b | The right hand side operator argument |
Compares two entities for equality.
Two entity are considered equal iff their index and version match and they are managed by the same entity manager.
| a | The left hand side operator argument |
| b | The right hand side operator argument |
Checks if a entity is empty.
| a | The left hand side operator argument |
| b | The right hand side operator argument |
|
friend |
| EntityID CeresEngine::Entity::entityID = {} |
The entity ID.
| EntityManager* CeresEngine::Entity::entityManager = nullptr |
The owning entity manager.