(Entity) Changed handle storage from a set to a vector
For performances reasons (creating handles no longer require any memory allocation) Former-commit-id: 76d705997c7fa3be78b063c6d602b09c7c20b2fd
This commit is contained in:
parent
86fbb310c3
commit
924d10e61c
|
|
@ -8,7 +8,7 @@
|
|||
#define NDK_ENTITY_HPP
|
||||
|
||||
#include <NDK/Prerequesites.hpp>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
|
|
@ -48,7 +48,7 @@ namespace Ndk
|
|||
void RegisterHandle(EntityHandle* handle);
|
||||
void UnregisterHandle(EntityHandle* handle);
|
||||
|
||||
std::set<EntityHandle*> m_handles;
|
||||
std::vector<EntityHandle*> m_handles;
|
||||
Id m_id;
|
||||
World* m_world;
|
||||
bool m_valid;
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@
|
|||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <NDK/World.hpp>
|
||||
#include <algorithm>
|
||||
#include <utility>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
|
|
@ -24,11 +26,17 @@ namespace Ndk
|
|||
|
||||
inline void Entity::RegisterHandle(EntityHandle* handle)
|
||||
{
|
||||
m_handles.insert(handle);
|
||||
///DOC: Un handle ne doit être enregistré qu'une fois, des erreurs se produisent s'il l'est plus d'une fois
|
||||
m_handles.push_back(handle);
|
||||
}
|
||||
|
||||
inline void Entity::UnregisterHandle(EntityHandle* handle)
|
||||
{
|
||||
m_handles.erase(handle);
|
||||
///DOC: Un handle ne doit être libéré qu'une fois, et doit faire partie de la liste, sous peine de crash
|
||||
auto it = std::find(m_handles.begin(), m_handles.end(), handle);
|
||||
|
||||
// On échange cet élément avec le dernier, et on diminue la taille du vector de 1
|
||||
std::swap(*it, m_handles.back());
|
||||
m_handles.pop_back();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue