Sdk/Entity: Add enable/disable mechanism

Former-commit-id: 09884bdacf2b573bef516936d2580942cc5d4f66
This commit is contained in:
Lynix 2015-12-10 23:50:09 +01:00
parent 4a71fb2922
commit 8adc0097df
4 changed files with 20 additions and 0 deletions

View File

@ -34,6 +34,8 @@ namespace Ndk
EntityHandle CreateHandle(); EntityHandle CreateHandle();
inline void Enable(bool enable);
inline BaseComponent& GetComponent(ComponentIndex index); inline BaseComponent& GetComponent(ComponentIndex index);
template<typename ComponentType> ComponentType& GetComponent(); template<typename ComponentType> ComponentType& GetComponent();
inline const Nz::Bitset<>& GetComponentBits() const; inline const Nz::Bitset<>& GetComponentBits() const;
@ -47,6 +49,7 @@ namespace Ndk
void Kill(); void Kill();
void Invalidate(); void Invalidate();
inline bool IsEnabled() const;
inline bool IsValid() const; inline bool IsValid() const;
void RemoveAllComponents(); void RemoveAllComponents();
@ -73,6 +76,7 @@ namespace Ndk
Nz::Bitset<> m_systemBits; Nz::Bitset<> m_systemBits;
EntityId m_id; EntityId m_id;
World* m_world; World* m_world;
bool m_enabled;
bool m_valid; bool m_valid;
}; };
} }

View File

@ -19,6 +19,15 @@ namespace Ndk
return static_cast<ComponentType&>(AddComponent(std::move(ptr))); return static_cast<ComponentType&>(AddComponent(std::move(ptr)));
} }
inline void Entity::Enable(bool enable)
{
if (m_enabled != enable)
{
m_enabled = enable;
Invalidate();
}
}
inline BaseComponent& Entity::GetComponent(ComponentIndex index) inline BaseComponent& Entity::GetComponent(ComponentIndex index)
{ {
///DOC: Le component doit être présent ///DOC: Le component doit être présent
@ -74,6 +83,11 @@ namespace Ndk
return HasComponent(index); return HasComponent(index);
} }
inline bool Entity::IsEnabled() const
{
return m_enabled;
}
inline bool Entity::IsValid() const inline bool Entity::IsValid() const
{ {
return m_valid; return m_valid;

View File

@ -114,6 +114,7 @@ namespace Ndk
void Entity::Create() void Entity::Create()
{ {
m_enabled = true;
m_valid = true; m_valid = true;
} }

View File

@ -141,6 +141,7 @@ namespace Ndk
// Doit-elle en faire partie ? // Doit-elle en faire partie ?
if (system->Filters(entity)) if (system->Filters(entity))
if (entity->IsEnabled() && system->Filters(entity))
{ {
// L'entité doit faire partie du système, revalidons-là (événement système) ou ajoutons-la au système // L'entité doit faire partie du système, revalidons-là (événement système) ou ajoutons-la au système
if (!partOfSystem) if (!partOfSystem)