diff --git a/headers/Systems/ECS.hpp b/headers/Systems/ECS.hpp index d2cf0ee..b3b7ad0 100644 --- a/headers/Systems/ECS.hpp +++ b/headers/Systems/ECS.hpp @@ -11,7 +11,6 @@ #define GUARD_TOURMALINE_ECS_H #include #include -#include #include #include "../Containers/DualkeyMap.hpp" @@ -31,15 +30,13 @@ public: // ======== Entities ======== [[nodiscard]] Entity CreateEntity(); - const Components::Enabled &EntityEnable(const Entity &entity) noexcept; bool EntityExists(const Entity &entity) noexcept; [[nodiscard("It is not guaranteed that an entity can always be destroyed, " "please make sure by checking the returned bool")]] bool DestroyEntity(Entity entity); // ======== Components ======== - template + template component &AddComponent(const Entity &entity, Args &&...constructionArguments) { auto newComponent = entityComponentMap.insert( @@ -48,7 +45,7 @@ public: return std::any_cast(std::get<2>(newComponent)); } - template + template [[nodiscard("Discarding an expensive operation's result!")]] component &GetComponent(const Entity &entity) { auto result = entityComponentMap.query(entity, typeid(component)); @@ -60,13 +57,13 @@ public: return std::any_cast(result.begin()->second); } - template + template [[nodiscard("Discarding an expensive operation's result!")]] bool HasComponent(const Entity &entity) { return entityComponentMap.query(entity, typeid(component)).size(); } - template + template [[nodiscard("It is not guaranteed that a component can always be removed, " "please make sure by checking the returned bool")]] bool RemoveComponent(const Entity &entity) { @@ -77,12 +74,6 @@ private: Tourmaline::Containers::DualkeyMap entityComponentMap{}; - // All of this is done so entities are not disabled during the - // run of the systems - std::stack> entitiesToDisable; - // Oh here comes the jank - friend void Components::Enabled::setEnabled(bool); - // ======== Life-cycle ======== void preSystems(); void postSystems(); diff --git a/headers/Systems/ECS/BuiltinComponents.hpp b/headers/Systems/ECS/BuiltinComponents.hpp index 82b3eef..341c448 100644 --- a/headers/Systems/ECS/BuiltinComponents.hpp +++ b/headers/Systems/ECS/BuiltinComponents.hpp @@ -13,36 +13,18 @@ #include namespace Tourmaline::Systems::ECS { -class World; -} +struct Component { +public: + virtual ~Component() = default; +}; +template +concept isAComponent = std::derived_from; +} // namespace Tourmaline::Systems::ECS namespace Tourmaline::Systems::Components { -// Base -struct BaseComponent { -public: - virtual ~BaseComponent() = default; -}; - -template -concept Component = std::derived_from; - // Builtin -struct Position : public BaseComponent { - Position(double x = 0, double y = 0, double z = 0) : x(x), y(y), z(z) {} - double x, y, z; -}; - -struct Enabled : public BaseComponent { - Enabled(ECS::World *world) : ownerWorld(world) {} - - [[nodiscard]] - bool isEnabled(); - void setEnabled(bool enable = true); - -private: - bool enabled = true; - ECS::World *ownerWorld; - friend ECS::World; +struct Base : public ECS::Component { + Base() {} }; } // namespace Tourmaline::Systems::Components #endif diff --git a/source/Systems/ECS/Components.cpp b/source/Systems/ECS/Components.cpp index 3e2ab94..1c5612b 100644 --- a/source/Systems/ECS/Components.cpp +++ b/source/Systems/ECS/Components.cpp @@ -9,9 +9,5 @@ #include #include -#include -bool Tourmaline::Systems::Components::Enabled::isEnabled() { return enabled; } -void Tourmaline::Systems::Components::Enabled::setEnabled(bool enable) { - ownerWorld->entitiesToDisable.emplace(std::pair{this, enable}); -} +// Empty until future use diff --git a/source/Systems/ECS/World.cpp b/source/Systems/ECS/World.cpp index 0abc649..11b7a34 100644 --- a/source/Systems/ECS/World.cpp +++ b/source/Systems/ECS/World.cpp @@ -26,12 +26,7 @@ void World::preSystems() { } void World::postSystems() { - // Can't do a foreach with a std::stack - while (!entitiesToDisable.empty()) { - std::pair &request = entitiesToDisable.top(); - request.first->enabled = request.second; - entitiesToDisable.pop(); - } + // Defined for future use } // Entities @@ -39,18 +34,12 @@ Entity World::CreateEntity() { auto newEntity = Random::GenerateUUID(); // Default components - entityComponentMap.insert(newEntity, typeid(Components::Position), - Components::Position()); - entityComponentMap.insert(newEntity, typeid(Components::Enabled), - Components::Enabled(this)); + entityComponentMap.insert(newEntity, typeid(Components::Base), + Components::Base()); return newEntity; } -const Components::Enabled &World::EntityEnable(const Entity &entity) noexcept { - return this->GetComponent(entity); -} - bool World::EntityExists(const Entity &entity) noexcept { bool exists = false; entityComponentMap.scan(