From 610a22a85249c2eefb5e53badc7ea55a89c87c29 Mon Sep 17 00:00:00 2001 From: cat Date: Fri, 30 Jan 2026 10:12:14 +0200 Subject: [PATCH] Moved base component from ECS.hpp and added Enabled --- headers/Systems/ECS/BuiltinComponents.hpp | 37 +++++++++++++++++++++-- source/Systems/ECS/Components.cpp | 16 ++++++++++ 2 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 source/Systems/ECS/Components.cpp diff --git a/headers/Systems/ECS/BuiltinComponents.hpp b/headers/Systems/ECS/BuiltinComponents.hpp index f60aa74..3f18d45 100644 --- a/headers/Systems/ECS/BuiltinComponents.hpp +++ b/headers/Systems/ECS/BuiltinComponents.hpp @@ -7,11 +7,44 @@ * obtain one at http://mozilla.org/MPL/2.0/. */ -#include "../ECS.hpp" +#ifndef GUARD_TOURMALINE_BUILTIN_COMPONENTS_H +#define GUARD_TOURMALINE_BUILTIN_COMPONENTS_H + +#include + +namespace Tourmaline::Systems::ECS { +class World; +} namespace Tourmaline::Systems::Components { -struct Position : public Tourmaline::Systems::ECS::BaseComponent { +// Base +struct BaseComponent { +public: + virtual ~BaseComponent() = default; + +private: + friend class World; +}; + +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(Tourmaline::Systems::ECS::World *world) : ownerWorld(world) {} + + [[nodiscard]] + bool isEnabled(); + void setEnabled(bool enable = true); + +private: + bool enabled = true; + Tourmaline::Systems::ECS::World *ownerWorld; +}; } // namespace Tourmaline::Systems::Components +#endif diff --git a/source/Systems/ECS/Components.cpp b/source/Systems/ECS/Components.cpp new file mode 100644 index 0000000..d354dc0 --- /dev/null +++ b/source/Systems/ECS/Components.cpp @@ -0,0 +1,16 @@ +/* + * SPDX-FileCopyrightText: Dora "cat" + * SPDX-License-Identifier: MPL-2.0 + * + * This Source Code Form is subject to the terms of the Mozilla Public License, + * v. 2.0. If a copy of the MPL was not distributed with this file, You can + * obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include +#include + +bool Tourmaline::Systems::Components::Enabled::isEnabled() { return enabled; } +void Tourmaline::Systems::Components::Enabled::setEnabled(bool enable) { + ownerWorld->entitiesToDisable.push_back({this, enable}); +}