9 #include "imstkEventObject.h" 10 #include "imstkLogger.h" 16 using EntityID = std::uint32_t;
29 Entity(
const std::string& name =
"Entity");
30 ~
Entity()
override =
default;
42 virtual const std::string getTypeName()
const {
return "Entity"; }
48 void setName(
const std::string& name) {
m_name = name; }
57 auto component = std::make_shared<T>();
65 auto component = std::make_shared<T>(name);
78 std::shared_ptr<Component>
getComponent(
const unsigned int index)
const;
86 for (
const auto& component : m_components)
88 if (
auto compT = std::dynamic_pointer_cast<T>(component))
103 for (
auto comp : m_components)
105 if (
auto castComp = std::dynamic_pointer_cast<T>(comp))
133 std::vector<std::shared_ptr<T>> components;
134 for (
const auto& component : m_components)
136 if (
auto compT = std::dynamic_pointer_cast<T>(component))
138 components.push_back(compT);
144 const std::vector<std::shared_ptr<Component>>&
getComponents() {
return m_components; }
152 std::vector<std::shared_ptr<Component>> m_components;
std::shared_ptr< T > getComponentN(const int index) const
Get's the Nth component of type T.
void removeComponent(std::shared_ptr< Component > component)
Remove component if it exists.
std::vector< std::shared_ptr< T > > getComponents() const
Get all components of type T.
const std::string & getName() const
Get/Set the name of the entity.
std::shared_ptr< T > getComponent() const
Get the first component of type T.
static std::atomic< EntityID > m_count
current count of entities
Top-level class for entities. Entities contain a collection of components which define how to be used...
EventObject is the base class for all objects in iMSTK that can receive and emit events. It supports direct and queued observer functions. Direct observers receive events immediately on the same thread This can either be posted on an object or be a function pointer Queued observers receive events within their queue which they can process whenever they like. These can be connected with the connect/queuedConnect/disconnect functions Lambda recievers cannot be disconnected unless all receivers to a signal are removed.
EntityID getID() const
Get ID (ALWAYS query the ID in your code, DO NOT hardcode it)
EntityID m_ID
unique ID of entity
std::shared_ptr< T > addComponent()
Create and return a component on this entity.
bool containsComponent() const
Check if contains component of type T.
std::string m_name
Not unique name.