From c392443728a77fbcc0ac28c8ff9985653599bc01 Mon Sep 17 00:00:00 2001 From: sguionni Date: Thu, 10 Oct 2024 19:23:06 +0200 Subject: [PATCH] ecs: merge registry and registry_manager --- .../app/application/ecs/registry_manager.hpp | 138 ------------------ .../app/application/system/ecs_system.hpp | 8 +- lib/app/include/app/core/ecs/registry.hpp | 1 + lib/app/src/app/application/scene_utility.cpp | 1 - .../application/selection/molecule_data.cpp | 1 - .../selection/molecule_granularity.cpp | 1 - .../app/application/selection/selection.cpp | 1 - .../application/selection/selection_data.cpp | 1 - .../src/app/component/chemistry/molecule.cpp | 1 - .../app/component/chemistry/trajectory.cpp | 1 - .../app/component/scene/aabb_component.cpp | 1 - .../component/scene/scene_item_component.cpp | 1 - .../src/app/component/scene/selectable.cpp | 1 - .../src/app/controller/picker/selection.cpp | 1 - .../app/entity/application/scene_entity.cpp | 1 - .../src/app/entity/scene/camera_entity.cpp | 1 - .../src/app/entity/scene/molecule_entity.cpp | 1 - .../src/app/entity/scene/viewpoint_entity.cpp | 1 - lib/app/src/app/vtx_app.cpp | 1 - lib/app/test/entt.cpp | 1 - lib/app/test/molecule.cpp | 1 - lib/app/test/scene.cpp | 1 - lib/app/test/selection.cpp | 1 - lib/app/test/trajectories.cpp | 1 - 24 files changed, 4 insertions(+), 164 deletions(-) delete mode 100644 lib/app/include/app/application/ecs/registry_manager.hpp diff --git a/lib/app/include/app/application/ecs/registry_manager.hpp b/lib/app/include/app/application/ecs/registry_manager.hpp deleted file mode 100644 index 943a225de..000000000 --- a/lib/app/include/app/application/ecs/registry_manager.hpp +++ /dev/null @@ -1,138 +0,0 @@ -#ifndef __VTX_APP_APPLICATION_ECS_REGISTRY_MANAGER__ -#define __VTX_APP_APPLICATION_ECS_REGISTRY_MANAGER__ - -#include "app/core/ecs/registry.hpp" - -namespace VTX::App::Application::ECS -{ - class RegistryManager - { - private: - using BaseEntity = Core::ECS::BaseEntity; - using BaseComponent = Core::ECS::BaseComponent; - - public: - RegistryManager() = default; - - template - E createEntity( Args &&... p_args ) - { - E createdEntity = _registry.createEntity( std::forward( p_args )... ); - createdEntity.setup(); - - return createdEntity; - } - - BaseEntity createEntity() - { - BaseEntity createdEntity = _registry.createEntity(); - - return createdEntity; - } - - template - inline BaseEntity getEntity( const C & p_component ) const - { - return _registry.getEntity( p_component ); - } - - bool isValid( const BaseEntity p_entity ) { return _registry.isValid( p_entity ); } - - template - C & addComponent( const BaseEntity & p_entity ) - { - C & res = _registry.addComponent( p_entity ); - - return res; - } - template - C & addComponent( const BaseEntity & p_entity, Args &&... p_args ) - { - C & res = _registry.addComponent( p_entity, std::forward( p_args... ) ); - - return res; - } - - template - void removeComponent( const BaseEntity & p_entity ) - { - _registry.removeComponent( p_entity ); - } - - template - C & getComponent( const BaseEntity & p_entity ) - { - return _registry.getComponent( p_entity ); - } - - template - const C & getComponent( const BaseEntity & p_entity ) const - { - return _registry.getComponent( p_entity ); - } - - template - C & getComponent( const CFrom & p_component ) - { - BaseEntity entity = getEntity( p_component ); - return _registry.getComponent( entity ); - } - template - const C & getComponent( const CFrom & p_component ) const - { - BaseEntity entity = getEntity( p_component ); - return _registry.getComponent( entity ); - } - - template - Type & findComponent() - { - Core::ECS::View view = _registry.findComponents(); - return getComponent( *( view.begin() ) ); - } - template - const Type & findComponent() const - { - Core::ECS::View view = _registry.findComponents(); - return getComponent( *( view.begin() ) ); - } - - template - Core::ECS::View findComponents() const - { - return _registry.findComponents(); - } - - template - bool hasComponent( const BaseEntity & p_entity ) const - { - return _registry.hasComponent( p_entity ); - } - template - bool hasComponent( const C2 & p_component ) const - { - const BaseEntity entity = getEntity( p_component ); - return _registry.hasComponent( p_component ); - } - - bool isEmpty() const { return _registry.isEmpty(); } - - template - void connectSignal( const App::Core::ECS::SIGNAL p_signal, Receiver * const p_receiver ) - { - _registry.connectSignal( p_signal, p_receiver ); - } - - template - void deleteAll() - { - _registry.deleteAll(); - } - void clear() { _registry.clear(); } - - private: - Core::ECS::Registry _registry = Core::ECS::Registry(); - }; -} // namespace VTX::App::Application::ECS - -#endif diff --git a/lib/app/include/app/application/system/ecs_system.hpp b/lib/app/include/app/application/system/ecs_system.hpp index fc5ac1169..a6c0f40e3 100644 --- a/lib/app/include/app/application/system/ecs_system.hpp +++ b/lib/app/include/app/application/system/ecs_system.hpp @@ -1,7 +1,7 @@ #ifndef __VTX_APP_APPLICATION_SYSTEM_ECS_SYSTEM__ #define __VTX_APP_APPLICATION_SYSTEM_ECS_SYSTEM__ -#include "app/application/ecs/registry_manager.hpp" +#include "app/core/ecs/registry.hpp" #include namespace VTX::App::Application::System @@ -9,16 +9,14 @@ namespace VTX::App::Application::System class ECSSystem { public: - Application::ECS::RegistryManager registryManager; + Core::ECS::Registry registry; }; } // namespace VTX::App::Application::System namespace VTX::App { inline Application::System::ECSSystem & ECS() { return Util::Singleton::get(); } - - // MAIN_REGISTRY give access to the registry to create / get / delete entities and components - inline Application::ECS::RegistryManager & MAIN_REGISTRY() { return ECS().registryManager; } + inline Core::ECS::Registry & MAIN_REGISTRY() { return ECS().registry; } } // namespace VTX::App #endif diff --git a/lib/app/include/app/core/ecs/registry.hpp b/lib/app/include/app/core/ecs/registry.hpp index 01fd91a52..ea691412b 100644 --- a/lib/app/include/app/core/ecs/registry.hpp +++ b/lib/app/include/app/core/ecs/registry.hpp @@ -28,6 +28,7 @@ namespace VTX::App::Core::ECS { E entity = E( std::forward( p_args )... ); entity._setEntityID( _enttRegistry.create() ); + entity.setup(); return entity; } diff --git a/lib/app/src/app/application/scene_utility.cpp b/lib/app/src/app/application/scene_utility.cpp index feace86c3..44c210388 100644 --- a/lib/app/src/app/application/scene_utility.cpp +++ b/lib/app/src/app/application/scene_utility.cpp @@ -1,5 +1,4 @@ #include "app/application/scene_utility.hpp" -#include "app/application/ecs/registry_manager.hpp" #include "app/application/scene.hpp" #include "app/component/scene/uid_component.hpp" #include "app/vtx_app.hpp" diff --git a/lib/app/src/app/application/selection/molecule_data.cpp b/lib/app/src/app/application/selection/molecule_data.cpp index 392818423..902cab468 100644 --- a/lib/app/src/app/application/selection/molecule_data.cpp +++ b/lib/app/src/app/application/selection/molecule_data.cpp @@ -1,5 +1,4 @@ #include "app/application/selection/molecule_data.hpp" -#include "app/application/ecs/registry_manager.hpp" #include "app/component/scene/selectable.hpp" #include "app/component/scene/transform_component.hpp" #include "app/helper/math.hpp" diff --git a/lib/app/src/app/application/selection/molecule_granularity.cpp b/lib/app/src/app/application/selection/molecule_granularity.cpp index 944da50f5..ff0780056 100644 --- a/lib/app/src/app/application/selection/molecule_granularity.cpp +++ b/lib/app/src/app/application/selection/molecule_granularity.cpp @@ -1,6 +1,5 @@ #include "app/application/selection/molecule_granularity.hpp" #include "app/action/selection.hpp" -#include "app/application/ecs/registry_manager.hpp" #include "app/application/selection/selection_manager.hpp" #include "app/component/chemistry/atom.hpp" #include "app/component/chemistry/chain.hpp" diff --git a/lib/app/src/app/application/selection/selection.cpp b/lib/app/src/app/application/selection/selection.cpp index 88e310914..4c45de3ee 100644 --- a/lib/app/src/app/application/selection/selection.cpp +++ b/lib/app/src/app/application/selection/selection.cpp @@ -1,5 +1,4 @@ #include "app/application/selection/selection.hpp" -#include "app/application/ecs/registry_manager.hpp" #include "app/vtx_app.hpp" #include #include diff --git a/lib/app/src/app/application/selection/selection_data.cpp b/lib/app/src/app/application/selection/selection_data.cpp index 6fca0edb6..e1418e84b 100644 --- a/lib/app/src/app/application/selection/selection_data.cpp +++ b/lib/app/src/app/application/selection/selection_data.cpp @@ -1,5 +1,4 @@ #include "app/application/selection/selection_data.hpp" -#include "app/application/ecs/registry_manager.hpp" #include "app/component/scene/scene_item_component.hpp" #include "app/component/scene/selectable.hpp" #include "app/vtx_app.hpp" diff --git a/lib/app/src/app/component/chemistry/molecule.cpp b/lib/app/src/app/component/chemistry/molecule.cpp index e6818fc04..fcf5a4ada 100644 --- a/lib/app/src/app/component/chemistry/molecule.cpp +++ b/lib/app/src/app/component/chemistry/molecule.cpp @@ -1,5 +1,4 @@ #include "app/component/chemistry/molecule.hpp" -#include "app/application/ecs/registry_manager.hpp" #include "app/component/chemistry/atom.hpp" #include "app/component/chemistry/bond.hpp" #include "app/component/chemistry/chain.hpp" diff --git a/lib/app/src/app/component/chemistry/trajectory.cpp b/lib/app/src/app/component/chemistry/trajectory.cpp index 247c3efc5..4b046cc6e 100644 --- a/lib/app/src/app/component/chemistry/trajectory.cpp +++ b/lib/app/src/app/component/chemistry/trajectory.cpp @@ -1,5 +1,4 @@ #include "app/component/chemistry/trajectory.hpp" -#include "app/application/ecs/registry_manager.hpp" #include "app/component/chemistry/molecule.hpp" #include "app/component/scene/scene_item_component.hpp" #include "app/vtx_app.hpp" diff --git a/lib/app/src/app/component/scene/aabb_component.cpp b/lib/app/src/app/component/scene/aabb_component.cpp index cf075c099..9226bbf5a 100644 --- a/lib/app/src/app/component/scene/aabb_component.cpp +++ b/lib/app/src/app/component/scene/aabb_component.cpp @@ -1,5 +1,4 @@ #include "app/component/scene/aabb_component.hpp" -#include "app/application/ecs/registry_manager.hpp" #include "app/component/scene/transform_component.hpp" #include "app/core/ecs/base_entity.hpp" #include "app/helper/math.hpp" diff --git a/lib/app/src/app/component/scene/scene_item_component.cpp b/lib/app/src/app/component/scene/scene_item_component.cpp index 9a57dcde8..1ee755e68 100644 --- a/lib/app/src/app/component/scene/scene_item_component.cpp +++ b/lib/app/src/app/component/scene/scene_item_component.cpp @@ -1,5 +1,4 @@ #include "app/component/scene/scene_item_component.hpp" -#include "app/application/ecs/registry_manager.hpp" #include "app/component/scene/updatable.hpp" #include "app/core/ecs/base_entity.hpp" #include "app/vtx_app.hpp" diff --git a/lib/app/src/app/component/scene/selectable.cpp b/lib/app/src/app/component/scene/selectable.cpp index 6fdb3a4ce..b231eba35 100644 --- a/lib/app/src/app/component/scene/selectable.cpp +++ b/lib/app/src/app/component/scene/selectable.cpp @@ -1,5 +1,4 @@ #include "app/component/scene/selectable.hpp" -#include "app/application/ecs/registry_manager.hpp" #include "app/application/selection/selection.hpp" #include "app/application/selection/selection_manager.hpp" #include "app/vtx_app.hpp" diff --git a/lib/app/src/app/controller/picker/selection.cpp b/lib/app/src/app/controller/picker/selection.cpp index 4b3bbe59f..4b1b7cb32 100644 --- a/lib/app/src/app/controller/picker/selection.cpp +++ b/lib/app/src/app/controller/picker/selection.cpp @@ -1,6 +1,5 @@ #include "app/controller/picker/selection.hpp" #include "app/core/input/input_manager.hpp" -#include #include #include #include diff --git a/lib/app/src/app/entity/application/scene_entity.cpp b/lib/app/src/app/entity/application/scene_entity.cpp index 672d9c1bb..ce8c70897 100644 --- a/lib/app/src/app/entity/application/scene_entity.cpp +++ b/lib/app/src/app/entity/application/scene_entity.cpp @@ -1,5 +1,4 @@ #include "app/entity/application/scene_entity.hpp" -#include "app/application/ecs/registry_manager.hpp" #include "app/application/scene.hpp" #include "app/component/io/scene_file_info.hpp" #include "app/vtx_app.hpp" diff --git a/lib/app/src/app/entity/scene/camera_entity.cpp b/lib/app/src/app/entity/scene/camera_entity.cpp index 974ca3d21..d4bcdfa9e 100644 --- a/lib/app/src/app/entity/scene/camera_entity.cpp +++ b/lib/app/src/app/entity/scene/camera_entity.cpp @@ -1,5 +1,4 @@ #include "app/entity/scene/camera_entity.hpp" -#include "app/application/ecs/registry_manager.hpp" #include "app/application/system/ecs_system.hpp" #include "app/component/render/camera.hpp" #include "app/component/scene/transform_component.hpp" diff --git a/lib/app/src/app/entity/scene/molecule_entity.cpp b/lib/app/src/app/entity/scene/molecule_entity.cpp index 7f9e2805d..0b02b6af4 100644 --- a/lib/app/src/app/entity/scene/molecule_entity.cpp +++ b/lib/app/src/app/entity/scene/molecule_entity.cpp @@ -1,5 +1,4 @@ #include "app/entity/scene/molecule_entity.hpp" -#include "app/application/ecs/registry_manager.hpp" #include "app/application/scene.hpp" #include "app/application/selection/molecule_data.hpp" #include "app/application/selection/molecule_granularity.hpp" diff --git a/lib/app/src/app/entity/scene/viewpoint_entity.cpp b/lib/app/src/app/entity/scene/viewpoint_entity.cpp index 3517fa9ae..d6de1f1f9 100644 --- a/lib/app/src/app/entity/scene/viewpoint_entity.cpp +++ b/lib/app/src/app/entity/scene/viewpoint_entity.cpp @@ -1,5 +1,4 @@ #include "app/entity/scene/viewpoint_entity.hpp" -#include "app/application/ecs/registry_manager.hpp" #include "app/application/scene.hpp" #include "app/component/render/viewpoint.hpp" #include "app/component/scene/selectable.hpp" diff --git a/lib/app/src/app/vtx_app.cpp b/lib/app/src/app/vtx_app.cpp index 95a7d6857..16b9b858e 100644 --- a/lib/app/src/app/vtx_app.cpp +++ b/lib/app/src/app/vtx_app.cpp @@ -2,7 +2,6 @@ #include "app/action/animation.hpp" #include "app/action/application.hpp" #include "app/action/scene.hpp" -#include "app/application/ecs/registry_manager.hpp" #include "app/application/scene.hpp" #include "app/application/selection/selection_manager.hpp" #include "app/component/io/scene_file_info.hpp" diff --git a/lib/app/test/entt.cpp b/lib/app/test/entt.cpp index 4bc5f6564..e25dabcae 100644 --- a/lib/app/test/entt.cpp +++ b/lib/app/test/entt.cpp @@ -1,7 +1,6 @@ #include "util/app.hpp" // #include #include -#include #include #include #include diff --git a/lib/app/test/molecule.cpp b/lib/app/test/molecule.cpp index 8586c9bfd..eb604cd8f 100644 --- a/lib/app/test/molecule.cpp +++ b/lib/app/test/molecule.cpp @@ -1,5 +1,4 @@ #include "util/app.hpp" -#include #include #include #include diff --git a/lib/app/test/scene.cpp b/lib/app/test/scene.cpp index 7366fe328..55e189f68 100644 --- a/lib/app/test/scene.cpp +++ b/lib/app/test/scene.cpp @@ -1,5 +1,4 @@ #include "util/app.hpp" -#include #include #include #include diff --git a/lib/app/test/selection.cpp b/lib/app/test/selection.cpp index 688e88f04..66d8fc53c 100644 --- a/lib/app/test/selection.cpp +++ b/lib/app/test/selection.cpp @@ -1,5 +1,4 @@ #include "util/app.hpp" -#include #include #include #include diff --git a/lib/app/test/trajectories.cpp b/lib/app/test/trajectories.cpp index 15941721e..b3bb5cacc 100644 --- a/lib/app/test/trajectories.cpp +++ b/lib/app/test/trajectories.cpp @@ -1,5 +1,4 @@ #include "util/app.hpp" -#include #include #include #include