Sdk: Make World moveable
Former-commit-id: 285cb9da4cbafd3da0c0859eb9d366bb2fb978a3
This commit is contained in:
@@ -71,7 +71,7 @@ namespace Ndk
|
|||||||
|
|
||||||
inline void RemoveEntity(Entity* entity);
|
inline void RemoveEntity(Entity* entity);
|
||||||
|
|
||||||
inline void SetWorld(World& world);
|
inline void SetWorld(World* world) noexcept;
|
||||||
|
|
||||||
inline void ValidateEntity(Entity* entity, bool justAdded);
|
inline void ValidateEntity(Entity* entity, bool justAdded);
|
||||||
|
|
||||||
|
|||||||
@@ -172,9 +172,9 @@ namespace Ndk
|
|||||||
OnEntityValidation(entity, justAdded);
|
OnEntityValidation(entity, justAdded);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void BaseSystem::SetWorld(World& world)
|
inline void BaseSystem::SetWorld(World* world) noexcept
|
||||||
{
|
{
|
||||||
m_world = &world;
|
m_world = world;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool BaseSystem::Initialize()
|
inline bool BaseSystem::Initialize()
|
||||||
@@ -186,6 +186,6 @@ namespace Ndk
|
|||||||
|
|
||||||
inline void BaseSystem::Uninitialize()
|
inline void BaseSystem::Uninitialize()
|
||||||
{
|
{
|
||||||
// Rien à faire
|
// Nothing to do
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,13 +60,16 @@ namespace Ndk
|
|||||||
Entity& operator=(Entity&&) = delete;
|
Entity& operator=(Entity&&) = delete;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Entity(World& world, EntityId id);
|
Entity(World* world, EntityId id);
|
||||||
|
|
||||||
void Create();
|
void Create();
|
||||||
void Destroy();
|
void Destroy();
|
||||||
|
|
||||||
inline void RegisterHandle(EntityHandle* handle);
|
inline void RegisterHandle(EntityHandle* handle);
|
||||||
inline void RegisterSystem(SystemIndex index);
|
inline void RegisterSystem(SystemIndex index);
|
||||||
|
|
||||||
|
inline void SetWorld(World* world) noexcept;
|
||||||
|
|
||||||
inline void UnregisterHandle(EntityHandle* handle);
|
inline void UnregisterHandle(EntityHandle* handle);
|
||||||
inline void UnregisterSystem(SystemIndex index);
|
inline void UnregisterSystem(SystemIndex index);
|
||||||
|
|
||||||
|
|||||||
@@ -113,6 +113,13 @@ namespace Ndk
|
|||||||
m_systemBits.UnboundedSet(index);
|
m_systemBits.UnboundedSet(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void Entity::SetWorld(World* world) noexcept
|
||||||
|
{
|
||||||
|
NazaraAssert(world, "An entity must be attached to a world at any time");
|
||||||
|
|
||||||
|
m_world = world;
|
||||||
|
}
|
||||||
|
|
||||||
inline void Entity::UnregisterHandle(EntityHandle* handle)
|
inline void Entity::UnregisterHandle(EntityHandle* handle)
|
||||||
{
|
{
|
||||||
///DOC: Un handle ne doit être libéré qu'une fois, et doit faire partie de la liste, sous peine de crash
|
///DOC: Un handle ne doit être libéré qu'une fois, et doit faire partie de la liste, sous peine de crash
|
||||||
|
|||||||
@@ -27,8 +27,8 @@ namespace Ndk
|
|||||||
|
|
||||||
inline World(bool addDefaultSystems = true);
|
inline World(bool addDefaultSystems = true);
|
||||||
World(const World&) = delete;
|
World(const World&) = delete;
|
||||||
World(World&&) = delete; ///TODO
|
inline World(World&& world) noexcept;
|
||||||
~World();
|
~World() noexcept;
|
||||||
|
|
||||||
void AddDefaultSystems();
|
void AddDefaultSystems();
|
||||||
|
|
||||||
@@ -38,7 +38,7 @@ namespace Ndk
|
|||||||
const EntityHandle& CreateEntity();
|
const EntityHandle& CreateEntity();
|
||||||
inline EntityList CreateEntities(unsigned int count);
|
inline EntityList CreateEntities(unsigned int count);
|
||||||
|
|
||||||
void Clear();
|
void Clear() noexcept;
|
||||||
|
|
||||||
const EntityHandle& GetEntity(EntityId id);
|
const EntityHandle& GetEntity(EntityId id);
|
||||||
inline const EntityList& GetEntities();
|
inline const EntityList& GetEntities();
|
||||||
@@ -62,7 +62,7 @@ namespace Ndk
|
|||||||
inline void Update(float elapsedTime);
|
inline void Update(float elapsedTime);
|
||||||
|
|
||||||
World& operator=(const World&) = delete;
|
World& operator=(const World&) = delete;
|
||||||
World& operator=(World&&) = delete; ///TODO
|
inline World& operator=(World&& world) noexcept;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
inline void Invalidate();
|
inline void Invalidate();
|
||||||
|
|||||||
@@ -13,6 +13,11 @@ namespace Ndk
|
|||||||
AddDefaultSystems();
|
AddDefaultSystems();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline World::World(World&& world) noexcept
|
||||||
|
{
|
||||||
|
operator=(std::move(world));
|
||||||
|
}
|
||||||
|
|
||||||
inline BaseSystem& World::AddSystem(std::unique_ptr<BaseSystem>&& system)
|
inline BaseSystem& World::AddSystem(std::unique_ptr<BaseSystem>&& system)
|
||||||
{
|
{
|
||||||
NazaraAssert(system, "System must be valid");
|
NazaraAssert(system, "System must be valid");
|
||||||
@@ -25,7 +30,7 @@ namespace Ndk
|
|||||||
|
|
||||||
// Affectation et retour du système
|
// Affectation et retour du système
|
||||||
m_systems[index] = std::move(system);
|
m_systems[index] = std::move(system);
|
||||||
m_systems[index]->SetWorld(*this);
|
m_systems[index]->SetWorld(this);
|
||||||
|
|
||||||
Invalidate(); // On force une mise à jour de toutes les entités
|
Invalidate(); // On force une mise à jour de toutes les entités
|
||||||
|
|
||||||
@@ -152,4 +157,22 @@ namespace Ndk
|
|||||||
{
|
{
|
||||||
m_dirtyEntities.UnboundedSet(id, true);
|
m_dirtyEntities.UnboundedSet(id, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline World& World::operator=(World&& world) noexcept
|
||||||
|
{
|
||||||
|
m_aliveEntities = std::move(world.m_aliveEntities);
|
||||||
|
m_dirtyEntities = std::move(world.m_dirtyEntities);
|
||||||
|
m_freeIdList = std::move(world.m_freeIdList);
|
||||||
|
m_killedEntities = std::move(world.m_killedEntities);
|
||||||
|
|
||||||
|
m_entities = std::move(world.m_entities);
|
||||||
|
for (EntityBlock& block : m_entities)
|
||||||
|
block.entity.SetWorld(this);
|
||||||
|
|
||||||
|
m_systems = std::move(world.m_systems);
|
||||||
|
for (const auto& systemPtr : m_systems)
|
||||||
|
systemPtr->SetWorld(this);
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,9 +23,9 @@ namespace Ndk
|
|||||||
handle->OnEntityMoved(this);
|
handle->OnEntityMoved(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Entity::Entity(World& world, EntityId id) :
|
Entity::Entity(World* world, EntityId id) :
|
||||||
m_id(id),
|
m_id(id),
|
||||||
m_world(&world)
|
m_world(world)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ namespace Ndk
|
|||||||
id = m_entities.size();
|
id = m_entities.size();
|
||||||
|
|
||||||
// Impossible d'utiliser emplace_back à cause de la portée
|
// Impossible d'utiliser emplace_back à cause de la portée
|
||||||
m_entities.push_back(Entity(*this, id));
|
m_entities.push_back(Entity(this, id));
|
||||||
}
|
}
|
||||||
|
|
||||||
// On initialise l'entité et on l'ajoute à la liste des entités vivantes
|
// On initialise l'entité et on l'ajoute à la liste des entités vivantes
|
||||||
@@ -59,7 +59,7 @@ namespace Ndk
|
|||||||
return m_aliveEntities.back();
|
return m_aliveEntities.back();
|
||||||
}
|
}
|
||||||
|
|
||||||
void World::Clear()
|
void World::Clear() noexcept
|
||||||
{
|
{
|
||||||
///DOC: Tous les handles sont correctement invalidés
|
///DOC: Tous les handles sont correctement invalidés
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user