From c18c4e4804da3b36d44daaa6e70d2ceb242839fb Mon Sep 17 00:00:00 2001 From: mlangkabel Date: Fri, 22 May 2026 07:55:43 +0200 Subject: [PATCH] implement claude feedback for EntityAdmin --- src/lib/core/EntityAdmin.cpp | 32 +++---- src/lib/core/EntityAdmin.h | 158 ++++++++--------------------------- 2 files changed, 44 insertions(+), 146 deletions(-) diff --git a/src/lib/core/EntityAdmin.cpp b/src/lib/core/EntityAdmin.cpp index e7fecac..29bda65 100644 --- a/src/lib/core/EntityAdmin.cpp +++ b/src/lib/core/EntityAdmin.cpp @@ -1,33 +1,21 @@ #include "EntityAdmin.h" -std::shared_ptr EntityAdmin::getInstance() +entt::entity EntityAdmin::createEntity() { - if (!s_instance) - { - s_instance = std::shared_ptr(new EntityAdmin()); - } - return s_instance; + return m_registry.create(); } -std::shared_ptr EntityAdmin::s_instance; - -bool EntityAdmin::isValid(const entt::entity &entity) +bool EntityAdmin::isValid(entt::entity entity) { - return m_registry->valid(entity); + return m_registry.valid(entity); +} + +void EntityAdmin::destroy(entt::entity entity) +{ + m_registry.destroy(entity); } void EntityAdmin::clear() { - m_registry->clear(); + m_registry.clear(); } - -void EntityAdmin::destroy(entt::entity &entity) -{ - m_registry->destroy(entity); -} - -EntityAdmin::EntityAdmin() - : m_registry(std::make_shared()) -{ -} - diff --git a/src/lib/core/EntityAdmin.h b/src/lib/core/EntityAdmin.h index 572e26c..973a5fb 100644 --- a/src/lib/core/EntityAdmin.h +++ b/src/lib/core/EntityAdmin.h @@ -3,151 +3,61 @@ #include "entt/entity/registry.hpp" -#include - class EntityAdmin { public: - static std::shared_ptr getInstance(); -private: - static std::shared_ptr s_instance; + EntityAdmin() = default; + EntityAdmin(const EntityAdmin&) = delete; + EntityAdmin& operator=(const EntityAdmin&) = delete; -public: - template - T1 &add(const entt::entity &entity); - void clear(); + template + void forEach(Func&& f); - template - void forEach(std::function f); - template - void forEach(std::function f); - template - void forEach(std::function f); - template - void forEach(std::function f); - template - void forEach(std::function f); + template + bool hasAll(entt::entity entity); - template - bool hasAll(const entt::entity &entity); - template - bool hasAll(const entt::entity &entity); - template - bool hasAll(const entt::entity &entity); - template - bool hasAll(const entt::entity &entity); + template + T& get(entt::entity entity); - template - T &get(const entt::entity &entity); + bool isValid(entt::entity entity); + void destroy(entt::entity entity); + void clear(); - bool isValid(const entt::entity &entity); - - /* - factory methods (like spawnShip, spawnScrap, etc shall go here) - */ - - void destroy(entt::entity &entity); + /* + factory methods (like spawnShip, spawnScrap, etc shall go here) + */ private: - EntityAdmin(); - EntityAdmin(const EntityAdmin&) = delete; - EntityAdmin& operator=(const EntityAdmin&) = delete; + entt::entity createEntity(); - std::shared_ptr m_registry; + template + T& add(entt::entity entity, Args&&... args); + + entt::registry m_registry; }; -template -T1 &EntityAdmin::add(const entt::entity &entity) +template +void EntityAdmin::forEach(Func&& f) { - return m_registry->emplace(entity); + m_registry.view().each(std::forward(f)); } -template -void EntityAdmin::forEach(std::function f) +template +bool EntityAdmin::hasAll(entt::entity entity) { - auto view = m_registry->view(); - for (auto ae : view) - { - f(ae, view.get(ae)); - } -} - -template -void EntityAdmin::forEach(std::function f) -{ - auto view = m_registry->view(); - for (auto[ae, a1, a2] : view.each()) - { - f(ae, a1, a2); - } -} - -template -void EntityAdmin::forEach(std::function f) -{ - auto view = m_registry->view(); - for (auto[ae, a1, a2, a3] : view.each()) - { - f(ae, a1, a2, a3); - } -} - -template -void EntityAdmin::forEach(std::function f) -{ - auto view = m_registry->view(); - for (auto[ae, a1, a2, a3, a4] : view.each()) - { - f(ae, a1, a2, a3, a4); - } -} - -template -void EntityAdmin::forEach(std::function f) -{ - auto view = m_registry->view(); - for (auto[ae, a1, a2, a3, a4, a5] : view.each()) - { - f(ae, a1, a2, a3, a4, a5); - } -} - -template -bool EntityAdmin::hasAll(const entt::entity &entity) -{ - if (m_registry->all_of(entity)) - return true; - return false; -} - -template -bool EntityAdmin::hasAll(const entt::entity &entity) -{ - if (m_registry->all_of(entity)) - return true; - return false; -} - -template -bool EntityAdmin::hasAll(const entt::entity &entity) -{ - if (m_registry->all_of(entity)) - return true; - return false; -} - -template -bool EntityAdmin::hasAll(const entt::entity &entity) -{ - if (m_registry->all_of(entity)) - return true; - return false; + return m_registry.all_of(entity); } template -T &EntityAdmin::get(const entt::entity &entity) +T& EntityAdmin::get(entt::entity entity) { - return m_registry->get(entity); + return m_registry.get(entity); +} + +template +T& EntityAdmin::add(entt::entity entity, Args&&... args) +{ + return m_registry.emplace(entity, std::forward(args)...); } #endif // ENTITY_ADMIN_H