(World) Optimized entities handling a lot

Former-commit-id: f05f3bb7bf321d30fd51f504ace95aa0ea9f7f8d
This commit is contained in:
Lynix
2015-03-16 22:14:18 +01:00
parent b30298b6ab
commit 3694857d30
3 changed files with 55 additions and 36 deletions

View File

@@ -7,9 +7,11 @@
#ifndef NDK_WORLD_HPP
#define NDK_WORLD_HPP
#include <Nazara/Core/Bitset.hpp>
#include <Nazara/Core/NonCopyable.hpp>
#include <NDK/Entity.hpp>
#include <NDK/EntityHandle.hpp>
#include <algorithm>
#include <vector>
namespace Ndk
@@ -27,21 +29,32 @@ namespace Ndk
void Clear();
EntityHandle GetEntity(Entity::Id id);
void KillEntity(const EntityHandle& entity);
void KillEntities(const EntityList& list);
EntityHandle GetEntity(Entity::Id id);
bool IsEntityValid(const EntityHandle& entity) const;
bool IsEntityIdValid(Entity::Id id) const;
void Update();
private:
struct EntityBlock
{
EntityBlock(Entity&& e) :
entity(std::move(e))
{
}
Entity entity;
unsigned int aliveIndex;
};
std::vector<Entity::Id> m_freeIdList;
std::vector<Entity> m_entities;
std::vector<EntityBlock> m_entities;
EntityList m_aliveEntities;
EntityList m_killedEntities;
NzBitset<nzUInt64> m_killedEntities;
};
}

View File

@@ -2,6 +2,8 @@
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
#include <Nazara/Core/Error.hpp>
namespace Ndk
{
inline World::EntityList World::CreateEntities(unsigned int count)
@@ -17,7 +19,6 @@ namespace Ndk
inline void World::KillEntities(const EntityList& list)
{
m_killedEntities.reserve(m_killedEntities.size() + list.size());
for (const EntityHandle& entity : list)
KillEntity(entity);
}
@@ -29,6 +30,6 @@ namespace Ndk
inline bool World::IsEntityIdValid(Entity::Id id) const
{
return id < m_entities.size() && m_entities[id].IsValid();
return id < m_entities.size() && m_entities[id].entity.IsValid();
}
}