7 #include "imstkEntity.h" 8 #include "imstkComponent.h" 14 Entity::Entity(
const std::string& name) : m_name(name)
23 CHECK(component !=
nullptr) <<
"Tried to add nullptr component";
24 auto iter = std::find(m_components.begin(), m_components.end(), component);
25 if (iter != m_components.end())
27 LOG(FATAL) <<
"Tried to add component to entity twice";
30 m_components.push_back(component);
31 component->m_entity = shared_from_this();
32 this->postEvent(
Event(modified()));
38 auto iter = std::find(m_components.begin(), m_components.end(), component);
39 return iter != m_components.end();
42 std::shared_ptr<Component>
45 CHECK(index >= 0 && index < m_components.size()) <<
46 "Component with index does not exist, index out of range";
47 return m_components[index];
53 auto iter = std::find(m_components.begin(), m_components.end(), component);
54 if (iter != m_components.end())
56 (*iter)->m_entity = std::weak_ptr<Entity>();
57 m_components.erase(iter);
61 LOG(FATAL) <<
"Failed to remove component on entity, could not find " << m_ID;
63 this->postEvent(
Event(modified()));
Base class for events which contain a type, priority, and data priority defaults to 0 and uses a grea...
void removeComponent(std::shared_ptr< Component > component)
Remove component if it exists.
std::shared_ptr< T > getComponent() const
Get the first component of type T.
static std::atomic< EntityID > m_count
current count of entities
std::shared_ptr< T > addComponent()
Create and return a component on this entity.
bool containsComponent() const
Check if contains component of type T.