From f760cfd6588b476e9ae90d271ea7a6460308b035 Mon Sep 17 00:00:00 2001 From: cat Date: Wed, 28 Jan 2026 14:29:47 +0200 Subject: [PATCH] Added EntityExists and HasComponent --- headers/Systems/ECS.hpp | 3 +-- source/Systems/ECS/World.cpp | 13 +++++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/headers/Systems/ECS.hpp b/headers/Systems/ECS.hpp index 9e177a8..654a3b0 100644 --- a/headers/Systems/ECS.hpp +++ b/headers/Systems/ECS.hpp @@ -69,8 +69,7 @@ public: template [[nodiscard("Discarding an expensive operation's result!")]] bool HasComponent(const Entity &entity) { - // TO BE IMPLEMENTED - return true; + return entityComponentMap.query(entity, typeid(component)).size(); } template diff --git a/source/Systems/ECS/World.cpp b/source/Systems/ECS/World.cpp index 394bcfe..70b1341 100644 --- a/source/Systems/ECS/World.cpp +++ b/source/Systems/ECS/World.cpp @@ -25,8 +25,17 @@ Entity World::CreateEntity() { } bool World::EntityExists(const Entity &entity) noexcept { - // TO BE IMPLEMENTED - return true; + bool exists = false; + entityComponentMap.scan( + [&exists, entity](const Tourmaline::Type::UUID ¤tEntity, + const std::type_index &, std::any &) -> bool { + if (currentEntity == entity) { + exists = true; + return true; + } + return false; + }); + return exists; } bool World::DestroyEntity(Entity entity) {