// Copyright (C) 2017 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 #pragma once #ifndef NDK_WORLD_HPP #define NDK_WORLD_HPP #include #include #include #include #include #include #include #include namespace Ndk { class World; using WorldHandle = Nz::ObjectHandle; class NDK_API World : public Nz::HandledObject { friend BaseSystem; friend Entity; public: using EntityList = std::vector; inline World(bool addDefaultSystems = true); World(const World&) = delete; inline World(World&& world) noexcept; ~World() noexcept; void AddDefaultSystems(); inline BaseSystem& AddSystem(std::unique_ptr&& system); template SystemType& AddSystem(Args&&... args); const EntityHandle& CreateEntity(); inline EntityList CreateEntities(unsigned int count); void Clear() noexcept; const EntityHandle& CloneEntity(EntityId id); const EntityHandle& GetEntity(EntityId id); inline const EntityList& GetEntities(); inline BaseSystem& GetSystem(SystemIndex index); template SystemType& GetSystem(); inline bool HasSystem(SystemIndex index) const; template bool HasSystem() const; void KillEntity(Entity* entity); inline void KillEntities(const EntityList& list); inline bool IsEntityValid(const Entity* entity) const; inline bool IsEntityIdValid(EntityId id) const; inline void RemoveAllSystems(); inline void RemoveSystem(SystemIndex index); template void RemoveSystem(); void Update(); inline void Update(float elapsedTime); World& operator=(const World&) = delete; inline World& operator=(World&& world) noexcept; private: inline void Invalidate(); inline void Invalidate(EntityId id); inline void InvalidateSystemOrder(); void ReorderSystems(); struct EntityBlock { EntityBlock(Entity&& e) : entity(std::move(e)) { } EntityBlock(EntityBlock&& block) = default; Entity entity; std::size_t aliveIndex; }; std::vector> m_systems; std::vector m_orderedSystems; std::vector m_entities; std::vector m_freeIdList; EntityList m_aliveEntities; Nz::Bitset m_dirtyEntities; Nz::Bitset m_killedEntities; bool m_orderedSystemsUpdated; }; } #include #endif // NDK_WORLD_HPP