Re-remade component and system ids
Former-commit-id: 98b76695cca904c55c7333801c3cdf693da15086
This commit is contained in:
@@ -7,4 +7,7 @@
|
||||
namespace Ndk
|
||||
{
|
||||
BaseComponent::~BaseComponent() = default;
|
||||
|
||||
std::vector<BaseComponent::ComponentEntry> BaseComponent::s_entries;
|
||||
std::unordered_map<ComponentId, ComponentIndex> BaseComponent::s_idToIndex;
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace Ndk
|
||||
BaseSystem::~BaseSystem()
|
||||
{
|
||||
for (const EntityHandle& entity : m_entities)
|
||||
entity->UnregisterSystem(m_systemId);
|
||||
entity->UnregisterSystem(m_systemIndex);
|
||||
}
|
||||
|
||||
bool BaseSystem::Filters(const Entity* entity) const
|
||||
@@ -17,19 +17,17 @@ namespace Ndk
|
||||
if (!entity)
|
||||
return false;
|
||||
|
||||
for (ComponentId component : m_requiredComponents)
|
||||
{
|
||||
if (!entity->HasComponent(component))
|
||||
return false; // Au moins un component requis n'est pas présent
|
||||
}
|
||||
const NzBitset<>& components = entity->GetComponentBits();
|
||||
|
||||
for (ComponentId component : m_excludedComponents)
|
||||
{
|
||||
if (entity->HasComponent(component))
|
||||
return false; // Au moins un component exclu est présent
|
||||
}
|
||||
m_filterResult.PerformsAND(m_requiredComponents, components);
|
||||
if (m_filterResult != m_requiredComponents)
|
||||
return false; // Au moins un component requis n'est pas présent
|
||||
|
||||
return true;
|
||||
m_filterResult.PerformsAND(m_excludedComponents, components);
|
||||
if (m_filterResult.TestAny())
|
||||
return false; // Au moins un component exclu est présent
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void BaseSystem::OnEntityAdded(Entity* entity)
|
||||
@@ -41,4 +39,6 @@ namespace Ndk
|
||||
{
|
||||
NazaraUnused(entity);
|
||||
}
|
||||
|
||||
SystemIndex BaseSystem::s_nextIndex = 0;
|
||||
}
|
||||
|
||||
@@ -27,15 +27,20 @@ namespace Ndk
|
||||
{
|
||||
NazaraAssert(component, "Component must be valid");
|
||||
|
||||
ComponentId componentId = component->GetId();
|
||||
ComponentIndex index = component->GetIndex();
|
||||
|
||||
// Nous nous assurons que le vecteur de component est suffisamment grand pour contenir le nouveau component
|
||||
if (index >= m_components.size())
|
||||
m_components.resize(index + 1);
|
||||
|
||||
// Affectation et retour du component
|
||||
m_components[componentId] = std::move(component);
|
||||
m_components[index] = std::move(component);
|
||||
m_componentBits.UnboundedSet(index);
|
||||
|
||||
// On informe le monde que nous avons besoin d'une mise à jour
|
||||
m_world->MarkAsDirty(m_id);
|
||||
|
||||
return *m_components[componentId].get();
|
||||
return *m_components[index].get();
|
||||
}
|
||||
|
||||
EntityHandle Entity::CreateHandle()
|
||||
@@ -56,17 +61,19 @@ namespace Ndk
|
||||
void Entity::RemoveAllComponents()
|
||||
{
|
||||
m_components.clear();
|
||||
m_componentBits.Clear();
|
||||
|
||||
// On informe le monde que nous avons besoin d'une mise à jour
|
||||
m_world->MarkAsDirty(m_id);
|
||||
}
|
||||
|
||||
void Entity::RemoveComponent(ComponentId componentId)
|
||||
void Entity::RemoveComponent(ComponentIndex index)
|
||||
{
|
||||
///DOC: N'a aucun effet si le component n'est pas présent
|
||||
if (HasComponent(componentId))
|
||||
if (HasComponent(index))
|
||||
{
|
||||
m_components[componentId].reset();
|
||||
m_components[index].reset();
|
||||
m_componentBits.Reset(index);
|
||||
|
||||
// On informe le monde que nous avons besoin d'une mise à jour
|
||||
m_world->MarkAsDirty(m_id);
|
||||
@@ -83,15 +90,15 @@ namespace Ndk
|
||||
m_valid = false;
|
||||
|
||||
// On informe chaque système
|
||||
for (SystemId systemId : m_systems)
|
||||
for (SystemIndex index = m_systemBits.FindFirst(); index != m_systemBits.npos; index = m_systemBits.FindNext(index))
|
||||
{
|
||||
if (m_world->HasSystem(systemId))
|
||||
if (m_world->HasSystem(index))
|
||||
{
|
||||
BaseSystem& system = m_world->GetSystem(systemId);
|
||||
BaseSystem& system = m_world->GetSystem(index);
|
||||
system.RemoveEntity(this);
|
||||
}
|
||||
}
|
||||
m_systems.clear();
|
||||
m_systemBits.Clear();
|
||||
|
||||
// On informe chaque handle de notre destruction pour éviter qu'il ne continue de pointer sur nous
|
||||
for (EntityHandle* handle : m_handles)
|
||||
|
||||
@@ -116,10 +116,8 @@ namespace Ndk
|
||||
// Aucun intérêt de traiter une entité n'existant plus
|
||||
if (entity.IsValid())
|
||||
{
|
||||
for (auto& systemPair : m_systems)
|
||||
for (auto& system : m_systems)
|
||||
{
|
||||
BaseSystem* system = systemPair.second.get();
|
||||
|
||||
// L'entité est-elle enregistrée comme faisant partie du système ?
|
||||
bool partOfSystem = system->HasEntity(&entity);
|
||||
if (system->Filters(&entity))
|
||||
|
||||
Reference in New Issue
Block a user