(World) Inlined some methods
Former-commit-id: eab086bdde8b11cc261faf2cb5d161bbfcebdc73
This commit is contained in:
parent
d5a8bdca12
commit
32951deed8
|
|
@ -20,7 +20,7 @@ namespace Ndk
|
||||||
using EntityList = std::vector<Entity>;
|
using EntityList = std::vector<Entity>;
|
||||||
|
|
||||||
World();
|
World();
|
||||||
~World();
|
~World() = default;
|
||||||
|
|
||||||
Entity CreateEntity();
|
Entity CreateEntity();
|
||||||
EntityList CreateEntities(unsigned int count);
|
EntityList CreateEntities(unsigned int count);
|
||||||
|
|
@ -46,4 +46,6 @@ namespace Ndk
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#include <NDK/World.inl>
|
||||||
|
|
||||||
#endif // NDK_WORLD_HPP
|
#endif // NDK_WORLD_HPP
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,41 @@
|
||||||
|
// Copyright (C) 2015 Jérôme Leclercq
|
||||||
|
// This file is part of the "Nazara Development Kit"
|
||||||
|
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||||
|
|
||||||
|
namespace Ndk
|
||||||
|
{
|
||||||
|
inline World::World() :
|
||||||
|
m_nextIndex(0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
inline World::EntityList World::CreateEntities(unsigned int count)
|
||||||
|
{
|
||||||
|
EntityList list;
|
||||||
|
for (unsigned int i = 0; i < count; ++i)
|
||||||
|
list.push_back(CreateEntity());
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void World::KillEntities(EntityList& list)
|
||||||
|
{
|
||||||
|
m_killedEntities.reserve(m_killedEntities.size() + list.size());
|
||||||
|
for (Entity& entity : list)
|
||||||
|
KillEntity(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool World::IsEntityValid(const Entity& entity) const
|
||||||
|
{
|
||||||
|
///DOC: Cette méthode vérifie également l'appartenance de l'entité au monde (et est donc plus sûre)
|
||||||
|
return entity.GetWorld() == this && IsEntityIdValid(entity.GetId());
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool World::IsEntityIdValid(Entity::Id id) const
|
||||||
|
{
|
||||||
|
///DOC: Il est possible que si l'identifiant vienne d'un autre monde, il soit considéré valide
|
||||||
|
/// alors qu'aucune entité de ce monde-ci ne l'utilise (encore)
|
||||||
|
|
||||||
|
return m_entitiesCounter[id.part.index] == id.part.counter;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -5,13 +5,6 @@
|
||||||
|
|
||||||
namespace Ndk
|
namespace Ndk
|
||||||
{
|
{
|
||||||
World::World() :
|
|
||||||
m_nextIndex(0)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
World::~World() = default;
|
|
||||||
|
|
||||||
Entity World::CreateEntity()
|
Entity World::CreateEntity()
|
||||||
{
|
{
|
||||||
Entity::Id id;
|
Entity::Id id;
|
||||||
|
|
@ -41,15 +34,6 @@ namespace Ndk
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
World::EntityList World::CreateEntities(unsigned int count)
|
|
||||||
{
|
|
||||||
EntityList list;
|
|
||||||
for (unsigned int i = 0; i < count; ++i)
|
|
||||||
list.push_back(CreateEntity());
|
|
||||||
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
void World::Clear()
|
void World::Clear()
|
||||||
{
|
{
|
||||||
///DOC: Les handles existants avant Clear ne sont plus garantis de ne pas être réutilisés
|
///DOC: Les handles existants avant Clear ne sont plus garantis de ne pas être réutilisés
|
||||||
|
|
@ -71,13 +55,6 @@ namespace Ndk
|
||||||
m_killedEntities.push_back(entity);
|
m_killedEntities.push_back(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
void World::KillEntities(EntityList& list)
|
|
||||||
{
|
|
||||||
m_killedEntities.reserve(m_killedEntities.size() + list.size());
|
|
||||||
for (Entity& entity : list)
|
|
||||||
KillEntity(entity);
|
|
||||||
}
|
|
||||||
|
|
||||||
Entity World::GetEntity(Entity::Id id)
|
Entity World::GetEntity(Entity::Id id)
|
||||||
{
|
{
|
||||||
if (IsEntityIdValid(id))
|
if (IsEntityIdValid(id))
|
||||||
|
|
@ -89,20 +66,6 @@ namespace Ndk
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool World::IsEntityValid(const Entity& entity) const
|
|
||||||
{
|
|
||||||
///DOC: Cette méthode vérifie également l'appartenance de l'entité au monde (et est donc plus sûre)
|
|
||||||
return entity.GetWorld() == this && IsEntityIdValid(entity.GetId());
|
|
||||||
}
|
|
||||||
|
|
||||||
bool World::IsEntityIdValid(Entity::Id id) const
|
|
||||||
{
|
|
||||||
///DOC: Il est possible que si l'identifiant vienne d'un autre monde, il soit considéré valide
|
|
||||||
/// alors qu'aucune entité de ce monde-ci ne l'utilise (encore)
|
|
||||||
|
|
||||||
return m_entitiesCounter[id.part.index] == id.part.counter;
|
|
||||||
}
|
|
||||||
|
|
||||||
void World::Update()
|
void World::Update()
|
||||||
{
|
{
|
||||||
if (!m_killedEntities.empty())
|
if (!m_killedEntities.empty())
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue