Cogs.Core
|
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.
Definition at line 18 of file Entity.cpp.
References Cogs::ComponentModel::ComponentHandle::resolve().
Referenced by Cogs::Core::EntityStore::addComponent(), and Cogs::Core::AddComponentCommand::apply().
|
inline |
Get a pointer to the first component implementing the given type in the entity.
Note Component is movable object.
Definition at line 35 of file Entity.h.
Referenced by Cogs::Core::EntityStore::addChild(), Cogs::Core::TranslateCommand::apply(), Cogs::Core::RotateCommand::apply(), Cogs::Core::ScaleCommand::apply(), Cogs::Core::ScaleToUnitCubeCommand::apply(), Cogs::Core::ExportCommand::apply(), Cogs::Core::SetFieldCommand< T >::apply(), Cogs::Core::RemapMaterialCommand::apply(), Cogs::Core::MergeMaterialCommand::apply(), Cogs::Core::applyFieldValues(), Cogs::Core::applyRecursiveFieldChange(), Cogs::Core::EntityStore::dumpHierarchy(), Cogs::Core::EntityStore::findEntity(), Cogs::Core::findHierarchyWithMatch(), Cogs::Core::Image360::Bounds::getBounds(), Cogs::Core::VectorField::VectorFieldBounds::getBounds(), Cogs::Core::OGC3DTilesBounds::getBounds(), Cogs::Core::PotreeBounds::getBounds(), Cogs::Core::SeaCurrentsBounds::getBounds(), Cogs::Core::AssetBounds::getBounds(), Cogs::Core::InstancedMeshRenderBounds::getBounds(), Cogs::Core::EntityStore::getEntityParent(), Cogs::Core::Editor::getLayerVisibility(), Cogs::Core::Editor::isStandardEntity(), Cogs::Core::EchoSounder::UniformGridSystem::preUpdate(), Cogs::Core::EntityStore::removeChild(), Cogs::Core::EntityStore::removeChildren(), Cogs::Core::Editor::selectFurthestAway(), Cogs::Core::Editor::showAll(), Cogs::Core::Editor::showHide(), Cogs::Core::AssetSystem::update(), Cogs::Core::AdaptivePlanarGridSystem::update(), Cogs::Core::EditorState::updateSelectedInfo(), and Cogs::Core::writeEntity().
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.
Definition at line 67 of file Entity.cpp.
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.
Definition at line 72 of file Entity.cpp.
|
inline |
Get a component handle to the first component implementing the given type.
Definition at line 90 of file Entity.h.
Referenced by Cogs::Core::applyFieldValues().
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.
Definition at line 93 of file Entity.cpp.
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.
Definition at line 45 of file Entity.cpp.
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.
Definition at line 50 of file Entity.cpp.
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.
Definition at line 38 of file Entity.cpp.
|
inline |
|
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. |
Definition at line 52 of file Entity.h.
Referenced by Cogs::Core::applyRecursiveFieldChange(), Cogs::Core::EntityStore::dumpHierarchy(), Cogs::Core::findHierarchyWithMatch(), and Cogs::Core::writeEntity().
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. |
Definition at line 79 of file Entity.cpp.
References Cogs::ComponentModel::ComponentCollectionBase::add(), Cogs::ComponentModel::ComponentCollectionBase::clear(), and Cogs::Reflection::TypeDatabase::getType().
|
inlineconstexprnoexcept |
Get the unique identifier of this entity.
Definition at line 113 of file Entity.h.
Referenced by Cogs::Core::EntityStore::addChild(), Cogs::Core::CreateEntityCommand::apply(), Cogs::Core::DestroyCommand::apply(), Cogs::Core::EntityStore::destroyEntity(), Cogs::Core::EntityStore::getEntityPtr(), Cogs::Core::Engine::invokeComponentNotifyCallback(), Cogs::Core::RayPicking::RayPickHit::RayPickHit(), Cogs::Core::EntityStore::renameEntity(), Cogs::Core::Editor::selectFurthestAway(), Cogs::Core::EntityStore::setEntityParent(), and Cogs::Core::EditorState::updateSelectedInfo().
|
inlinenoexcept |
Get the name of this entity.
Definition at line 120 of file Entity.h.
Referenced by Cogs::Core::EntityStore::addChild(), Cogs::Core::ExportCommand::apply(), Cogs::Core::EntityStore::destroyEntity(), Cogs::Core::EntityStore::dumpHierarchy(), Cogs::Core::findHierarchyWithMatch(), Cogs::Core::EntityStore::renameEntity(), Cogs::Core::EntityStore::setEntityParent(), Cogs::Core::ShapeSystem::update(), Cogs::Core::EditorState::updateSelectedInfo(), and Cogs::Core::writeEntity().
|
inlineconstexprnoexcept |
Get user data.
Definition at line 137 of file Entity.h.
Referenced by Cogs::Core::EntityStore::createEntities(), Cogs::Core::EntityStore::createEntity(), Cogs::Core::RayPicking::RayPickFilter::isUnwantedType(), and Cogs::Core::writeEntity().
|
static |
Register the Entity type in the global type database.
Definition at line 9 of file Entity.cpp.
References id.
void Cogs::ComponentModel::Entity::removeComponent | ( | ComponentHandle | component | ) |
Remove the given component from the entity. Internal: Use Cogs::Core::EntityStore.
Definition at line 29 of file Entity.cpp.
References Cogs::ComponentModel::ComponentHandle::resolve().
|
inlineconstexprnoexcept |
Set the unique identifier of this entity. Internal: Use Cogs::Core::EntityStore.
Definition at line 117 of file Entity.h.
Referenced by Cogs::Core::EntityStore::createEntities(), and Cogs::Core::EntityStore::createEntity().
void Cogs::ComponentModel::Entity::setName | ( | const StringView & | name | ) |
Set the name of this entity. Internal: Use Cogs::Core::EntityStore.
Definition at line 98 of file Entity.cpp.
Referenced by Cogs::Core::EntityStore::renameEntity().
|
inline |
|
inlineconstexprnoexcept |
Set user data. Can be used to e.g store a pointer to per-entity data. Internal: Owned by Cogs::Core::EntityStore
|
private |
|
private |
|
private |
|
private |