Improved interface
EntityHandle are no longer required to pass Entity as arguments World::CreateEntity() now returns a const EntityHandle& Former-commit-id: 6fc53ce5759a2a508094bdc61b4471f13f0844ec
This commit is contained in:
@@ -27,13 +27,13 @@ namespace Ndk
|
||||
|
||||
virtual BaseSystem* Clone() const = 0;
|
||||
|
||||
bool Filters(const EntityHandle& entity) const;
|
||||
bool Filters(const Entity* entity) const;
|
||||
|
||||
const std::vector<EntityHandle>& GetEntities() const;
|
||||
SystemId GetId() const;
|
||||
World& GetWorld() const;
|
||||
|
||||
bool HasEntity(const EntityHandle& entity) const;
|
||||
bool HasEntity(const Entity* entity) const;
|
||||
|
||||
protected:
|
||||
template<typename ComponentType> void Excludes();
|
||||
@@ -45,12 +45,12 @@ namespace Ndk
|
||||
void RequiresComponent(ComponentId componentId);
|
||||
|
||||
private:
|
||||
void AddEntity(const EntityHandle& entity);
|
||||
void AddEntity(Entity* entity);
|
||||
|
||||
virtual void OnEntityAdded(const EntityHandle& entity);
|
||||
virtual void OnEntityRemoved(const EntityHandle& entity);
|
||||
virtual void OnEntityAdded(Entity* entity);
|
||||
virtual void OnEntityRemoved(Entity* entity);
|
||||
|
||||
void RemoveEntity(const EntityHandle& entity);
|
||||
void RemoveEntity(Entity* entity);
|
||||
|
||||
void SetWorld(World& world);
|
||||
|
||||
|
||||
@@ -27,8 +27,11 @@ namespace Ndk
|
||||
return *m_world;
|
||||
}
|
||||
|
||||
inline bool BaseSystem::HasEntity(const EntityHandle& entity) const
|
||||
inline bool BaseSystem::HasEntity(const Entity* entity) const
|
||||
{
|
||||
if (!entity)
|
||||
return false;
|
||||
|
||||
return m_entityBits.UnboundedTest(entity->GetId());
|
||||
}
|
||||
|
||||
@@ -72,9 +75,11 @@ namespace Ndk
|
||||
m_requiredComponents.insert(componentId);
|
||||
}
|
||||
|
||||
inline void BaseSystem::AddEntity(const EntityHandle& entity)
|
||||
inline void BaseSystem::AddEntity(Entity* entity)
|
||||
{
|
||||
m_entities.push_back(entity);
|
||||
NazaraAssert(entity, "Invalid entity");
|
||||
|
||||
m_entities.push_back(entity->CreateHandle());
|
||||
m_entityBits.UnboundedSet(entity->GetId(), true);
|
||||
|
||||
entity->RegisterSystem(m_systemId);
|
||||
@@ -82,9 +87,11 @@ namespace Ndk
|
||||
OnEntityAdded(entity);
|
||||
}
|
||||
|
||||
inline void BaseSystem::RemoveEntity(const EntityHandle& entity)
|
||||
inline void BaseSystem::RemoveEntity(Entity* entity)
|
||||
{
|
||||
auto it = std::find(m_entities.begin(), m_entities.end(), entity);
|
||||
NazaraAssert(entity, "Invalid entity");
|
||||
|
||||
auto it = std::find(m_entities.begin(), m_entities.end(), *entity);
|
||||
NazaraAssert(it != m_entities.end(), "Entity is not part of this system");
|
||||
|
||||
// Pour éviter de déplacer beaucoup de handles, on swap le dernier avec celui à supprimer
|
||||
|
||||
@@ -44,11 +44,28 @@ namespace Ndk
|
||||
friend std::ostream& operator<<(std::ostream& out, const EntityHandle& handle);
|
||||
|
||||
friend bool operator==(const EntityHandle& lhs, const EntityHandle& rhs);
|
||||
friend bool operator==(const Entity& lhs, const EntityHandle& rhs);
|
||||
friend bool operator==(const EntityHandle& lhs, const Entity& rhs);
|
||||
|
||||
friend bool operator!=(const EntityHandle& lhs, const EntityHandle& rhs);
|
||||
friend bool operator!=(const Entity& lhs, const EntityHandle& rhs);
|
||||
friend bool operator!=(const EntityHandle& lhs, const Entity& rhs);
|
||||
|
||||
friend bool operator<(const EntityHandle& lhs, const EntityHandle& rhs);
|
||||
friend bool operator<(const Entity& lhs, const EntityHandle& rhs);
|
||||
friend bool operator<(const EntityHandle& lhs, const Entity& rhs);
|
||||
|
||||
friend bool operator<=(const EntityHandle& lhs, const EntityHandle& rhs);
|
||||
friend bool operator<=(const Entity& lhs, const EntityHandle& rhs);
|
||||
friend bool operator<=(const EntityHandle& lhs, const Entity& rhs);
|
||||
|
||||
friend bool operator>(const EntityHandle& lhs, const EntityHandle& rhs);
|
||||
friend bool operator>(const Entity& lhs, const EntityHandle& rhs);
|
||||
friend bool operator>(const EntityHandle& lhs, const Entity& rhs);
|
||||
|
||||
friend bool operator>=(const EntityHandle& lhs, const EntityHandle& rhs);
|
||||
friend bool operator>=(const Entity& lhs, const EntityHandle& rhs);
|
||||
friend bool operator>=(const EntityHandle& lhs, const Entity& rhs);
|
||||
|
||||
private:
|
||||
void OnEntityDestroyed();
|
||||
|
||||
@@ -149,30 +149,90 @@ namespace Ndk
|
||||
return lhs.m_entity == rhs.m_entity;
|
||||
}
|
||||
|
||||
inline bool operator==(const Entity& lhs, const EntityHandle& rhs)
|
||||
{
|
||||
return &lhs == rhs.m_entity;
|
||||
}
|
||||
|
||||
inline bool operator==(const EntityHandle& lhs, const Entity& rhs)
|
||||
{
|
||||
return lhs.m_entity == &rhs;
|
||||
}
|
||||
|
||||
inline bool operator!=(const EntityHandle& lhs, const EntityHandle& rhs)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
inline bool operator!=(const Entity& lhs, const EntityHandle& rhs)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
inline bool operator!=(const EntityHandle& lhs, const Entity& rhs)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
inline bool operator<(const EntityHandle& lhs, const EntityHandle& rhs)
|
||||
{
|
||||
return lhs.m_entity < rhs.m_entity;
|
||||
}
|
||||
|
||||
inline bool operator<(const Entity& lhs, const EntityHandle& rhs)
|
||||
{
|
||||
return &lhs < rhs.m_entity;
|
||||
}
|
||||
|
||||
inline bool operator<(const EntityHandle& lhs, const Entity& rhs)
|
||||
{
|
||||
return lhs.m_entity < &rhs;
|
||||
}
|
||||
|
||||
inline bool operator<=(const EntityHandle& lhs, const EntityHandle& rhs)
|
||||
{
|
||||
return !(lhs > rhs);
|
||||
}
|
||||
|
||||
inline bool operator<=(const Entity& lhs, const EntityHandle& rhs)
|
||||
{
|
||||
return !(lhs > rhs);
|
||||
}
|
||||
|
||||
inline bool operator<=(const EntityHandle& lhs, const Entity& rhs)
|
||||
{
|
||||
return !(lhs > rhs);
|
||||
}
|
||||
|
||||
inline bool operator>(const EntityHandle& lhs, const EntityHandle& rhs)
|
||||
{
|
||||
return rhs < lhs;
|
||||
}
|
||||
|
||||
inline bool operator>(const Entity& lhs, const EntityHandle& rhs)
|
||||
{
|
||||
return rhs < lhs;
|
||||
}
|
||||
|
||||
inline bool operator>(const EntityHandle& lhs, const Entity& rhs)
|
||||
{
|
||||
return rhs < lhs;
|
||||
}
|
||||
|
||||
inline bool operator>=(const EntityHandle& lhs, const EntityHandle& rhs)
|
||||
{
|
||||
return !(lhs < rhs);
|
||||
}
|
||||
|
||||
inline bool operator>=(const Entity& lhs, const EntityHandle& rhs)
|
||||
{
|
||||
return !(lhs < rhs);
|
||||
}
|
||||
|
||||
inline bool operator>=(const EntityHandle& lhs, const Entity& rhs)
|
||||
{
|
||||
return !(lhs < rhs);
|
||||
}
|
||||
}
|
||||
|
||||
namespace std
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace Ndk
|
||||
BaseSystem& AddSystem(std::unique_ptr<BaseSystem>&& system);
|
||||
template<typename SystemType, typename... Args> SystemType& AddSystem(Args&&... args);
|
||||
|
||||
EntityHandle CreateEntity();
|
||||
const EntityHandle& CreateEntity();
|
||||
EntityList CreateEntities(unsigned int count);
|
||||
|
||||
void Clear();
|
||||
@@ -44,10 +44,10 @@ namespace Ndk
|
||||
bool HasSystem(SystemId systemId) const;
|
||||
template<typename SystemType> bool HasSystem() const;
|
||||
|
||||
void KillEntity(const EntityHandle& entity);
|
||||
void KillEntity(Entity* entity);
|
||||
void KillEntities(const EntityList& list);
|
||||
|
||||
bool IsEntityValid(const EntityHandle& entity) const;
|
||||
bool IsEntityValid(const Entity* entity) const;
|
||||
bool IsEntityIdValid(EntityId id) const;
|
||||
|
||||
void RemoveAllSystems();
|
||||
|
||||
@@ -84,9 +84,9 @@ namespace Ndk
|
||||
KillEntity(entity);
|
||||
}
|
||||
|
||||
inline bool World::IsEntityValid(const EntityHandle& entity) const
|
||||
inline bool World::IsEntityValid(const Entity* entity) const
|
||||
{
|
||||
return entity.IsValid() && entity->GetWorld() == this && IsEntityIdValid(entity->GetId());
|
||||
return entity && entity->GetWorld() == this && IsEntityIdValid(entity->GetId());
|
||||
}
|
||||
|
||||
inline bool World::IsEntityIdValid(EntityId id) const
|
||||
|
||||
Reference in New Issue
Block a user