|
Cogs.Foundation
|
Container for components, providing composition of dynamic entities. More...
#include <Entity.h>
Public Member Functions | |
| void | addComponent (ComponentHandle component) |
| void | removeComponent (ComponentHandle component) |
| template<typename T > | |
| T * | getComponent () const |
| Get a pointer to the first component implementing the given type in the entity. | |
| template<typename T > | |
| void | getComponents (ComponentCollection< T > &collection) const |
| Get all the components implementing the templated type. | |
| Component * | getComponent (const Reflection::Name &typeName) const |
| Get a pointer to the first component implementing the type with the given typeName in the entity. Note Component is movable object. | |
| Component * | getComponent (const Reflection::TypeId &id) const |
| Get a pointer to the first component implementing the type with the given id in the entity. Note Component is movable object. | |
| void | getComponents (const Reflection::Name &typeName, ComponentCollectionBase &collection) const |
| Get all the components implementing the type with the given typeName. | |
| template<typename T > | |
| T * | getComponent (const Reflection::Type &type) const |
| Get a pointer to the first component implementing the given type. Note T and type represented by type must match. Note Component is movable object. | |
| Component * | getComponentPtr (const Reflection::Type &type) const |
| Get a pointer to the first component implementing the given type. | |
| template<typename T > | |
| ComponentHandle | getComponentHandle () const |
| Get a component handle to the first component implementing the given type. | |
| ComponentHandle | getComponentHandle (const Reflection::Name &componentName) const |
| Get a component handle to the first component implementing the given type with the given componentName. | |
| ComponentHandle | getComponentHandle (const Reflection::Type &type) const |
| Get a component handle to the first component implementing the given type. | |
| ComponentHandle | getComponentHandle (const Reflection::TypeId &id) const |
| Get a component handle to the first component implementing the type with the given id. | |
| constexpr size_t | getId () const noexcept |
| Get the unique identifier of this entity. | |
| constexpr void | setId (const size_t id) noexcept |
| const std::string & | getName () const noexcept |
| Get the name of this entity. | |
| void | setName (const StringView &name) |
| const ComponentCollectionBase & | getComponents () const |
| Get the collection of Component instances owned by this entity. | |
| constexpr void | setUserData (void *userData) noexcept |
| void | setUserData (intptr_t userData) |
| Deprecated use void*. Delete when Usage removed. | |
| constexpr void * | getUserData () const noexcept |
| Get user data. | |
Static Public Member Functions | |
| static void | registerType () |
| Register the Entity type in the global type database. | |
Private Attributes | |
| ComponentCollectionBase | components |
| Handles to components attached to this entity. | |
| std::string | name |
| Name of the entity. | |
| size_t | id = static_cast<size_t>(-1) |
| Unique identifier. | |
| void * | userData = nullptr |
| User data storage. | |
Container for components, providing composition of dynamic entities.
| void Cogs::ComponentModel::Entity::addComponent | ( | ComponentHandle | component | ) |
Add the component held by the given handle to the Entity, taking ownership of the Component instance. Internal: Use Cogs::Core::EntityStore.
References Cogs::ComponentModel::ComponentHandle::resolve().
| Cogs::ComponentModel::Component * Cogs::ComponentModel::Entity::getComponent | ( | const Reflection::Name & | typeName | ) | const |
Get a pointer to the first component implementing the type with the given typeName in the entity. Note Component is movable object.
References Cogs::Reflection::TypeDatabase::getType().
|
inline |
| Cogs::ComponentModel::Component * Cogs::ComponentModel::Entity::getComponent | ( | const Reflection::TypeId & | id | ) | const |
Get a pointer to the first component implementing the type with the given id in the entity. Note Component is movable object.
|
inline |
Get a component handle to the first component implementing the given type.
| Cogs::ComponentModel::ComponentHandle Cogs::ComponentModel::Entity::getComponentHandle | ( | const Reflection::Name & | componentName | ) | const |
Get a component handle to the first component implementing the given type with the given componentName.
References Cogs::Reflection::TypeDatabase::getType().
| Cogs::ComponentModel::ComponentHandle Cogs::ComponentModel::Entity::getComponentHandle | ( | const Reflection::Type & | type | ) | const |
Get a component handle to the first component implementing the given type.
References Cogs::Reflection::Type::getTypeId().
| Cogs::ComponentModel::ComponentHandle Cogs::ComponentModel::Entity::getComponentHandle | ( | const Reflection::TypeId & | id | ) | const |
Get a component handle to the first component implementing the type with the given id.
References Cogs::ComponentModel::ComponentHandle::Empty(), and Cogs::Reflection::TypeDatabase::getType().
| Cogs::ComponentModel::Component * Cogs::ComponentModel::Entity::getComponentPtr | ( | const Reflection::Type & | type | ) | const |
Get a pointer to the first component implementing the given type.
|
inline |
Get the collection of Component instances owned by this entity.
|
inline |
Get all the components implementing the templated type.
The components are all stored in the given collection.
| collection | A component collection of the specified template type. Any existing content in the collection will be cleared. |
| void Cogs::ComponentModel::Entity::getComponents | ( | const Reflection::Name & | typeName, |
| ComponentCollectionBase & | collection | ||
| ) | const |
Get all the components implementing the type with the given typeName.
| typeName | Name of the component type to retrieve. All components either of this type or deriving from this type will be included. |
| collection | Component collection to store untyped component handles in. Any existing content in the collection will be cleared. |
References Cogs::ComponentModel::ComponentCollectionBase::add(), Cogs::ComponentModel::ComponentCollectionBase::clear(), and Cogs::Reflection::TypeDatabase::getType().
|
inlineconstexprnoexcept |
Get the unique identifier of this entity.
|
inlinenoexcept |
Get the name of this entity.
|
inlineconstexprnoexcept |
Get user data.
|
static |
| void Cogs::ComponentModel::Entity::removeComponent | ( | ComponentHandle | component | ) |
Remove the given component from the entity. Internal: Use Cogs::Core::EntityStore.
References Cogs::ComponentModel::ComponentHandle::resolve().
|
inlineconstexprnoexcept |
Set the unique identifier of this entity. Internal: Use Cogs::Core::EntityStore.
| void Cogs::ComponentModel::Entity::setName | ( | const StringView & | name | ) |
Set the name of this entity. Internal: Use Cogs::Core::EntityStore.
|
inline |
Deprecated use void*. Delete when Usage removed.
|
inlineconstexprnoexcept |
Set user data. Can be used to e.g store a pointer to per-entity data. Internal: Owned by Cogs::Core::EntityStore
|
private |
Handles to components attached to this entity.
|
private |
Unique identifier.
Referenced by registerType().
|
private |
Name of the entity.
|
private |
User data storage.