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 SetWorld(World& world);
|
||||
inline void SetWorld(World* world) noexcept;
|
||||
|
||||
inline void ValidateEntity(Entity* entity, bool justAdded);
|
||||
|
||||
|
||||
@@ -172,9 +172,9 @@ namespace Ndk
|
||||
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()
|
||||
@@ -186,6 +186,6 @@ namespace Ndk
|
||||
|
||||
inline void BaseSystem::Uninitialize()
|
||||
{
|
||||
// Rien à faire
|
||||
// Nothing to do
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,13 +60,16 @@ namespace Ndk
|
||||
Entity& operator=(Entity&&) = delete;
|
||||
|
||||
private:
|
||||
Entity(World& world, EntityId id);
|
||||
Entity(World* world, EntityId id);
|
||||
|
||||
void Create();
|
||||
void Destroy();
|
||||
|
||||
inline void RegisterHandle(EntityHandle* handle);
|
||||
inline void RegisterSystem(SystemIndex index);
|
||||
|
||||
inline void SetWorld(World* world) noexcept;
|
||||
|
||||
inline void UnregisterHandle(EntityHandle* handle);
|
||||
inline void UnregisterSystem(SystemIndex index);
|
||||
|
||||
|
||||
@@ -113,6 +113,13 @@ namespace Ndk
|
||||
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)
|
||||
{
|
||||
///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);
|
||||
World(const World&) = delete;
|
||||
World(World&&) = delete; ///TODO
|
||||
~World();
|
||||
inline World(World&& world) noexcept;
|
||||
~World() noexcept;
|
||||
|
||||
void AddDefaultSystems();
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace Ndk
|
||||
const EntityHandle& CreateEntity();
|
||||
inline EntityList CreateEntities(unsigned int count);
|
||||
|
||||
void Clear();
|
||||
void Clear() noexcept;
|
||||
|
||||
const EntityHandle& GetEntity(EntityId id);
|
||||
inline const EntityList& GetEntities();
|
||||
@@ -62,7 +62,7 @@ namespace Ndk
|
||||
inline void Update(float elapsedTime);
|
||||
|
||||
World& operator=(const World&) = delete;
|
||||
World& operator=(World&&) = delete; ///TODO
|
||||
inline World& operator=(World&& world) noexcept;
|
||||
|
||||
private:
|
||||
inline void Invalidate();
|
||||
|
||||
@@ -13,6 +13,11 @@ namespace Ndk
|
||||
AddDefaultSystems();
|
||||
}
|
||||
|
||||
inline World::World(World&& world) noexcept
|
||||
{
|
||||
operator=(std::move(world));
|
||||
}
|
||||
|
||||
inline BaseSystem& World::AddSystem(std::unique_ptr<BaseSystem>&& system)
|
||||
{
|
||||
NazaraAssert(system, "System must be valid");
|
||||
@@ -25,7 +30,7 @@ namespace Ndk
|
||||
|
||||
// Affectation et retour du système
|
||||
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
|
||||
|
||||
@@ -152,4 +157,22 @@ namespace Ndk
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user