From dd7cdbdc8fe547bc7155d02bbe25e99b9b1fffac Mon Sep 17 00:00:00 2001 From: SweetId <2630750+SweetId@users.noreply.github.com> Date: Wed, 29 Nov 2023 17:20:08 +0530 Subject: [PATCH] renaming CameraSystem to ComponentsSystem Now handles all editor components --- .../Core/Systems/CameraSystem.hpp | 39 ------------ .../Core/Systems/ComponentsSystem.hpp | 43 +++++++++++++ .../Core/Application/BaseApplication.cpp | 2 +- .../Core/Systems/CameraSystem.cpp | 39 ------------ .../Core/Systems/ComponentsSystem.cpp | 60 +++++++++++++++++++ 5 files changed, 104 insertions(+), 79 deletions(-) delete mode 100644 include/NazaraEditor/Core/Systems/CameraSystem.hpp create mode 100644 include/NazaraEditor/Core/Systems/ComponentsSystem.hpp delete mode 100644 src/NazaraEditor/Core/Systems/CameraSystem.cpp create mode 100644 src/NazaraEditor/Core/Systems/ComponentsSystem.cpp diff --git a/include/NazaraEditor/Core/Systems/CameraSystem.hpp b/include/NazaraEditor/Core/Systems/CameraSystem.hpp deleted file mode 100644 index 6678483..0000000 --- a/include/NazaraEditor/Core/Systems/CameraSystem.hpp +++ /dev/null @@ -1,39 +0,0 @@ -#pragma once - -#include - -#include - -#include -#include - -namespace Nz -{ - class NAZARAEDITOR_CORE_API EditorCameraSystem - { - public: - static constexpr bool AllowConcurrent = false; - static constexpr Int64 ExecutionOrder = 1'001; - - EditorCameraSystem(entt::registry& registry); - ~EditorCameraSystem(); - - EditorCameraSystem(const EditorCameraSystem&) = delete; - EditorCameraSystem& operator=(const EditorCameraSystem&) = delete; - - EditorCameraSystem(EditorCameraSystem&&) = delete; - EditorCameraSystem& operator=(EditorCameraSystem&&) = delete; - - void Update(Time elapsedTime); - - private: - void OnCameraDestroy(entt::registry& registry, entt::entity entity); - - entt::registry& m_registry; - - entt::observer m_cameraConstructObserver; - entt::scoped_connection m_cameraDestroyConnection; - - std::unordered_set m_cameraEntities; - }; -} \ No newline at end of file diff --git a/include/NazaraEditor/Core/Systems/ComponentsSystem.hpp b/include/NazaraEditor/Core/Systems/ComponentsSystem.hpp new file mode 100644 index 0000000..c157d76 --- /dev/null +++ b/include/NazaraEditor/Core/Systems/ComponentsSystem.hpp @@ -0,0 +1,43 @@ +#pragma once + +#include + +#include + +#include +#include + +namespace Nz +{ + class NAZARAEDITOR_CORE_API EditorComponentsSystem + { + public: + static constexpr bool AllowConcurrent = false; + static constexpr Int64 ExecutionOrder = 1'001; + + EditorComponentsSystem(entt::registry& registry); + ~EditorComponentsSystem(); + + EditorComponentsSystem(const EditorComponentsSystem&) = delete; + EditorComponentsSystem& operator=(const EditorComponentsSystem&) = delete; + + EditorComponentsSystem(EditorComponentsSystem&&) = delete; + EditorComponentsSystem& operator=(EditorComponentsSystem&&) = delete; + + void Update(Time elapsedTime); + + private: + void OnCameraDestroy(entt::registry& registry, entt::entity entity); + void OnEntityDestroy(entt::registry& registry, entt::entity entity); + + entt::registry& m_registry; + + entt::observer m_cameraConstructObserver; + entt::observer m_entityConstructObserver; + entt::scoped_connection m_cameraDestroyConnection; + entt::scoped_connection m_entityDestroyConnection; + + std::unordered_set m_cameraEntities; + std::unordered_set m_entities; + }; +} \ No newline at end of file diff --git a/src/NazaraEditor/Core/Application/BaseApplication.cpp b/src/NazaraEditor/Core/Application/BaseApplication.cpp index 40eb495..b59d7e9 100644 --- a/src/NazaraEditor/Core/Application/BaseApplication.cpp +++ b/src/NazaraEditor/Core/Application/BaseApplication.cpp @@ -115,7 +115,7 @@ namespace Nz if (bRes) { RenderSystem& system = m_level.GetEnttWorld()->AddSystem(); - m_level.GetEnttWorld()->AddSystem(); + m_level.GetEnttWorld()->AddSystem(); system.AttachExternalSwapchain(*m_windowSwapchain); system.GetFramePipeline().RegisterViewer(m_editorCamera.get(), 2); diff --git a/src/NazaraEditor/Core/Systems/CameraSystem.cpp b/src/NazaraEditor/Core/Systems/CameraSystem.cpp deleted file mode 100644 index 8adf71d..0000000 --- a/src/NazaraEditor/Core/Systems/CameraSystem.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include -#include - -#include - -namespace Nz -{ - EditorCameraSystem::EditorCameraSystem(entt::registry& registry) - : m_registry(registry) - , m_cameraConstructObserver(registry, entt::collector.group()) - { - m_cameraDestroyConnection = registry.on_destroy().connect<&EditorCameraSystem::OnCameraDestroy>(this); - } - - EditorCameraSystem::~EditorCameraSystem() - { - m_cameraConstructObserver.disconnect(); - } - - void EditorCameraSystem::Update(Time elapsedTime) - { - m_cameraConstructObserver.each([&](entt::entity entity) { - m_cameraEntities.insert(entity); - }); - - for (auto entity : m_cameraEntities) - { - EditorCameraComponent& camera = m_registry.get(entity); - NodeComponent& transform = m_registry.get(entity); - - camera.Update(elapsedTime, transform); - } - } - - void EditorCameraSystem::OnCameraDestroy(entt::registry& registry, entt::entity entity) - { - m_cameraEntities.erase(entity); - } -} \ No newline at end of file diff --git a/src/NazaraEditor/Core/Systems/ComponentsSystem.cpp b/src/NazaraEditor/Core/Systems/ComponentsSystem.cpp new file mode 100644 index 0000000..a2b1cc3 --- /dev/null +++ b/src/NazaraEditor/Core/Systems/ComponentsSystem.cpp @@ -0,0 +1,60 @@ +#include +#include +#include + +#include + +namespace Nz +{ + EditorComponentsSystem::EditorComponentsSystem(entt::registry& registry) + : m_registry(registry) + , m_cameraConstructObserver(registry, entt::collector.group()) + , m_entityConstructObserver(registry, entt::collector.group()) + { + m_cameraDestroyConnection = registry.on_destroy().connect<&EditorComponentsSystem::OnCameraDestroy>(this); + m_entityDestroyConnection = registry.on_destroy().connect<&EditorComponentsSystem::OnEntityDestroy>(this); + } + + EditorComponentsSystem::~EditorComponentsSystem() + { + m_cameraConstructObserver.disconnect(); + } + + void EditorComponentsSystem::Update(Time elapsedTime) + { + m_cameraConstructObserver.each([&](entt::entity entity) { + m_cameraEntities.insert(entity); + }); + + m_entityConstructObserver.each([&](entt::entity entity) { + m_entities.insert(entity); + }); + + for (auto entity : m_cameraEntities) + { + EditorCameraComponent& camera = m_registry.get(entity); + NodeComponent& transform = m_registry.get(entity); + + camera.Update(elapsedTime, transform); + } + + + for (auto entity : m_entities) + { + EditorNameComponent& component = m_registry.get(entity); + NodeComponent& transform = m_registry.get(entity); + + component.Update(elapsedTime, transform); + } + } + + void EditorComponentsSystem::OnCameraDestroy(entt::registry& registry, entt::entity entity) + { + m_cameraEntities.erase(entity); + } + + void EditorComponentsSystem::OnEntityDestroy(entt::registry& registry, entt::entity entity) + { + m_entities.erase(entity); + } +} \ No newline at end of file