(Entity) Added components bits

Moved [Add/Remove]Component implementation to .cpp


Former-commit-id: e61e8c57911c2e106e6c0959b692a006b8f58c40
This commit is contained in:
Lynix
2015-03-17 12:34:03 +01:00
parent 99e0912163
commit 0ba034f7e9
3 changed files with 44 additions and 31 deletions

View File

@@ -23,6 +23,26 @@ namespace Ndk
Destroy();
}
BaseComponent& Entity::AddComponent(std::unique_ptr<BaseComponent>&& component)
{
NazaraAssert(component, "Component must be valid");
nzUInt32 componentId = component->GetId();
// Nous supprimons l'ancien component, s'il existe
RemoveComponent(componentId);
// Nous nous assurons que le vecteur de component est suffisamment grand pour contenir le nouveau component
if (m_components.size() <= componentId)
m_components.resize(componentId + 1);
// Affectation et retour du component
m_components[componentId] = std::move(component);
m_componentBits.UnboundedSet(componentId);
return *m_components[componentId].get();
}
EntityHandle Entity::CreateHandle()
{
return EntityHandle(this);
@@ -38,6 +58,22 @@ namespace Ndk
return m_valid;
}
void Entity::RemoveAllComponents()
{
m_components.clear();
m_componentBits.Clear();
}
void Entity::RemoveComponent(nzUInt32 componentId)
{
///DOC: N'a aucun effet si le component n'est pas présent
if (HasComponent(componentId))
{
m_components[componentId].reset();
m_componentBits.Reset(componentId);
}
}
void Entity::Create()
{
m_valid = true;