Ndk/BaseSystem: Added "one of" style requirement

Former-commit-id: ce4399561f4198290d639d001a6a56665baa0714
This commit is contained in:
Lynix 2015-05-03 19:50:42 +02:00
parent 9bffaaaa84
commit 3ebf967f30
3 changed files with 33 additions and 1 deletions

View File

@ -51,6 +51,10 @@ namespace Ndk
template<typename ComponentType1, typename ComponentType2, typename... Rest> void Requires();
void RequiresComponent(ComponentIndex index);
template<typename ComponentType> void RequiresAny();
template<typename ComponentType1, typename ComponentType2, typename... Rest> void RequiresAny();
void RequiresAnyComponent(ComponentIndex index);
private:
void AddEntity(Entity* entity);
@ -68,6 +72,7 @@ namespace Ndk
NzBitset<nzUInt64> m_entityBits;
NzBitset<> m_excludedComponents;
mutable NzBitset<> m_filterResult;
NzBitset<> m_requiredAnyComponents;
NzBitset<> m_requiredComponents;
SystemIndex m_systemIndex;
World* m_world;

View File

@ -87,11 +87,31 @@ namespace Ndk
m_requiredComponents.UnboundedSet(index);
}
template<typename ComponentType>
void BaseSystem::RequiresAny()
{
static_assert(std::is_base_of<BaseComponent, ComponentType>(), "ComponentType is not a component");
RequiresAnyComponent(GetComponentIndex<ComponentType>());
}
template<typename ComponentType1, typename ComponentType2, typename... Rest>
void BaseSystem::RequiresAny()
{
RequiresAny<ComponentType1>();
RequiresAny<ComponentType2, Rest...>();
}
inline void BaseSystem::RequiresAnyComponent(ComponentIndex index)
{
m_requiredAnyComponents.UnboundedSet(index);
}
inline void BaseSystem::AddEntity(Entity* entity)
{
NazaraAssert(entity, "Invalid entity");
m_entities.push_back(entity->CreateHandle());
m_entities.emplace_back(entity);
m_entityBits.UnboundedSet(entity->GetId(), true);
entity->RegisterSystem(m_systemIndex);

View File

@ -27,6 +27,13 @@ namespace Ndk
if (m_filterResult.TestAny())
return false; // Au moins un component exclu est présent
// Si nous avons une liste de composants nécessaires
if (m_requiredAnyComponents.TestAny())
{
if (!m_requiredAnyComponents.Intersects(components))
return false;
}
return true;
}