Enabled for entities is now a friend of ECS::World

This commit is contained in:
2026-01-30 15:58:13 +02:00
parent d21bc60024
commit cd59ed656a
2 changed files with 5 additions and 6 deletions

View File

@@ -21,9 +21,6 @@ namespace Tourmaline::Systems::Components {
struct BaseComponent { struct BaseComponent {
public: public:
virtual ~BaseComponent() = default; virtual ~BaseComponent() = default;
private:
friend class World;
}; };
template <typename T> template <typename T>
@@ -36,7 +33,7 @@ struct Position : public BaseComponent {
}; };
struct Enabled : public BaseComponent { struct Enabled : public BaseComponent {
Enabled(Tourmaline::Systems::ECS::World *world) : ownerWorld(world) {} Enabled(ECS::World *world) : ownerWorld(world) {}
[[nodiscard]] [[nodiscard]]
bool isEnabled(); bool isEnabled();
@@ -44,7 +41,8 @@ struct Enabled : public BaseComponent {
private: private:
bool enabled = true; bool enabled = true;
Tourmaline::Systems::ECS::World *ownerWorld; ECS::World *ownerWorld;
friend ECS::World;
}; };
} // namespace Tourmaline::Systems::Components } // namespace Tourmaline::Systems::Components
#endif #endif

View File

@@ -9,8 +9,9 @@
#include <Systems/ECS.hpp> #include <Systems/ECS.hpp>
#include <Systems/ECS/BuiltinComponents.hpp> #include <Systems/ECS/BuiltinComponents.hpp>
#include <utility>
bool Tourmaline::Systems::Components::Enabled::isEnabled() { return enabled; } bool Tourmaline::Systems::Components::Enabled::isEnabled() { return enabled; }
void Tourmaline::Systems::Components::Enabled::setEnabled(bool enable) { void Tourmaline::Systems::Components::Enabled::setEnabled(bool enable) {
ownerWorld->entitiesToDisable.push_back({this, enable}); ownerWorld->entitiesToDisable.emplace(std::pair{this, enable});
} }