bool Entity::addComponent( const ComponentPtr& component ) { if( !component ) return false; Class* type = component->getType(); if( componentsMap.Find(type) != componentsMap.End() ) { LogWarn( "Component '%s' already exists in '%s'", type->name, name.CString() ); return false; } componentsMap[type] = component; component->setEntity(this); onComponentAdded(component); sendEvents(); if( IsGroup(parent) ) { Group* group = (Group*) parent; group->onEntityComponentAdded(component); } components.Push(component); return true; }
bool Entity::removeComponent(const ComponentPtr& component) { if (!component) return false; Class* type = component->getType(); ComponentMap::Iterator it = componentsMap.Find(type); if( it == componentsMap.End() ) return false; componentsMap.Erase(it); onComponentRemoved(component); sendEvents(); if (IsGroup(parent)) { Group* group = (Group*) parent; group->onEntityComponentRemoved(component); } if (type->inherits(GeometryGetType())) getTransform()->markBoundingVolumeDirty(); return true; }
void Entity::removeComponent(ComponentPtr component) { unsigned int thetype = component->getType(); m_components.erase(thetype); }
void Entity::addComponent(ComponentPtr component) { unsigned int thetype = component->getType(); m_components[thetype] = component; }