Remade component ids

No longer based on incrementing counter


Former-commit-id: b875e17781d8bcda48ea9ada523adf0823b22a8b
This commit is contained in:
Lynix
2015-03-17 19:53:59 +01:00
parent 0ba034f7e9
commit bc40fbb02f
14 changed files with 83 additions and 69 deletions

View File

@@ -7,6 +7,4 @@
namespace Ndk
{
BaseComponent::~BaseComponent() = default;
nzUInt32 BaseComponent::s_nextId = 0;
}

View File

@@ -27,18 +27,10 @@ namespace Ndk
{
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);
ComponentId componentId = component->GetId();
// Affectation et retour du component
m_components[componentId] = std::move(component);
m_componentBits.UnboundedSet(componentId);
return *m_components[componentId].get();
}
@@ -61,17 +53,13 @@ namespace Ndk
void Entity::RemoveAllComponents()
{
m_components.clear();
m_componentBits.Clear();
}
void Entity::RemoveComponent(nzUInt32 componentId)
void Entity::RemoveComponent(ComponentId 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()

View File

@@ -15,7 +15,7 @@ namespace Ndk
EntityHandle World::CreateEntity()
{
Entity::Id id;
EntityId id;
if (!m_freeIdList.empty())
{
// On récupère un identifiant
@@ -62,7 +62,7 @@ namespace Ndk
m_killedEntities.UnboundedSet(entity->GetId(), true);
}
const EntityHandle& World::GetEntity(Entity::Id id)
const EntityHandle& World::GetEntity(EntityId id)
{
if (IsEntityIdValid(id))
return m_aliveEntities[m_entities[id].aliveIndex];