From 3fc4f3ec8435f3a5b637fc306610dc365e9f2fa1 Mon Sep 17 00:00:00 2001 From: cat Date: Fri, 30 Jan 2026 15:58:53 +0200 Subject: [PATCH] Added basics of the ECS world's life cycle --- headers/Systems/ECS.hpp | 10 +++++++++- source/Systems/ECS/World.cpp | 20 ++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/headers/Systems/ECS.hpp b/headers/Systems/ECS.hpp index a450689..d2cf0ee 100644 --- a/headers/Systems/ECS.hpp +++ b/headers/Systems/ECS.hpp @@ -11,6 +11,7 @@ #define GUARD_TOURMALINE_ECS_H #include #include +#include #include #include "../Containers/DualkeyMap.hpp" @@ -24,6 +25,9 @@ class World; class World { public: + // ====== World controls ====== + void Step(); + // ======== Entities ======== [[nodiscard]] Entity CreateEntity(); @@ -75,9 +79,13 @@ private: // All of this is done so entities are not disabled during the // run of the systems - std::vector> entitiesToDisable; + std::stack> entitiesToDisable; // Oh here comes the jank friend void Components::Enabled::setEnabled(bool); + + // ======== Life-cycle ======== + void preSystems(); + void postSystems(); }; } // namespace Tourmaline::Systems::ECS #endif diff --git a/source/Systems/ECS/World.cpp b/source/Systems/ECS/World.cpp index 70dd1a1..0abc649 100644 --- a/source/Systems/ECS/World.cpp +++ b/source/Systems/ECS/World.cpp @@ -15,6 +15,26 @@ using namespace Tourmaline::Systems; using namespace ECS; +void World::Step() { + preSystems(); + // Actual systems will happen here + postSystems(); +} + +void World::preSystems() { + // Defined for future use +} + +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(); + } +} + +// Entities Entity World::CreateEntity() { auto newEntity = Random::GenerateUUID();