SDK/Entity: Delay component removal until world update

Allows system to freely remove components while updating


Former-commit-id: f567d3344f764a0909abc2c4a8f69a580aa585b3 [formerly 77379f40a7773443420058a342dec4c02e563053] [formerly 1313a164a686c915c8c54e1dfb367757499b45e9 [formerly f69b0a2a5fd0c3a640c19409baa3f467d231b566]]
Former-commit-id: 19aeaebcb33056b67e788d5ef485179ed17b2fd8 [formerly fe85c2fcf3851834f70d0573617a15be31e02e50]
Former-commit-id: 527c9fd9571f405b0963123c158ef1e4b42f28ad
This commit is contained in:
Lynix
2016-08-11 01:02:40 +02:00
parent b0de2364a5
commit e22355db19
4 changed files with 53 additions and 36 deletions

View File

@@ -52,8 +52,8 @@ namespace Ndk
inline bool IsEnabled() const;
inline bool IsValid() const;
void RemoveAllComponents();
void RemoveComponent(ComponentIndex index);
inline void RemoveAllComponents();
inline void RemoveComponent(ComponentIndex index);
template<typename ComponentType> void RemoveComponent();
inline Nz::String ToString() const;
@@ -67,6 +67,10 @@ namespace Ndk
void Create();
void Destroy();
void DestroyComponent(ComponentIndex index);
inline Nz::Bitset<>& GetRemovedComponentBits();
inline void RegisterSystem(SystemIndex index);
inline void SetWorld(World* world) noexcept;
@@ -75,6 +79,7 @@ namespace Ndk
std::vector<std::unique_ptr<BaseComponent>> m_components;
Nz::Bitset<> m_componentBits;
Nz::Bitset<> m_removedComponentBits;
Nz::Bitset<> m_systemBits;
EntityId m_id;
World* m_world;

View File

@@ -103,12 +103,31 @@ namespace Ndk
RemoveComponent(index);
}
inline void Entity::RemoveAllComponents()
{
m_removedComponentBits = m_componentBits;
Invalidate();
}
inline void Entity::RemoveComponent(ComponentIndex index)
{
m_removedComponentBits.UnboundedSet(index);
Invalidate();
}
inline Nz::String Entity::ToString() const
{
Nz::StringStream ss;
return ss << "Entity(" << GetId() << ')';
}
inline Nz::Bitset<>& Entity::GetRemovedComponentBits()
{
return m_removedComponentBits;
}
inline void Entity::RegisterSystem(SystemIndex index)
{
m_systemBits.UnboundedSet(index);