Exemplo n.º 1
0
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;
}
Exemplo n.º 2
0
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;
}
Exemplo n.º 3
0
void Entity::removeComponent(ComponentPtr component) {
  unsigned int thetype = component->getType();
  m_components.erase(thetype);
}
Exemplo n.º 4
0
void Entity::addComponent(ComponentPtr component) {
  unsigned int thetype = component->getType();
  m_components[thetype] = component;
}