renaming CameraSystem to ComponentsSystem

Now handles all editor components
This commit is contained in:
SweetId 2023-11-29 17:20:08 +05:30
parent bc18b5ef5d
commit dd7cdbdc8f
5 changed files with 104 additions and 79 deletions

View File

@ -1,39 +0,0 @@
#pragma once
#include <NazaraEditor/Core/Config.hpp>
#include <Nazara/Core/Time.hpp>
#include <entt/entt.hpp>
#include <unordered_set>
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<entt::entity> m_cameraEntities;
};
}

View File

@ -0,0 +1,43 @@
#pragma once
#include <NazaraEditor/Core/Config.hpp>
#include <Nazara/Core/Time.hpp>
#include <entt/entt.hpp>
#include <unordered_set>
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<entt::entity> m_cameraEntities;
std::unordered_set<entt::entity> m_entities;
};
}

View File

@ -115,7 +115,7 @@ namespace Nz
if (bRes)
{
RenderSystem& system = m_level.GetEnttWorld()->AddSystem<RenderSystem>();
m_level.GetEnttWorld()->AddSystem<EditorCameraSystem>();
m_level.GetEnttWorld()->AddSystem<EditorComponentsSystem>();
system.AttachExternalSwapchain(*m_windowSwapchain);
system.GetFramePipeline().RegisterViewer(m_editorCamera.get(), 2);

View File

@ -1,39 +0,0 @@
#include <NazaraEditor/Core/Systems/CameraSystem.hpp>
#include <NazaraEditor/Core/Components/CameraComponent.hpp>
#include <Nazara/Utility/Components/NodeComponent.hpp>
namespace Nz
{
EditorCameraSystem::EditorCameraSystem(entt::registry& registry)
: m_registry(registry)
, m_cameraConstructObserver(registry, entt::collector.group<EditorCameraComponent, NodeComponent>())
{
m_cameraDestroyConnection = registry.on_destroy<EditorCameraComponent>().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<EditorCameraComponent>(entity);
NodeComponent& transform = m_registry.get<NodeComponent>(entity);
camera.Update(elapsedTime, transform);
}
}
void EditorCameraSystem::OnCameraDestroy(entt::registry& registry, entt::entity entity)
{
m_cameraEntities.erase(entity);
}
}

View File

@ -0,0 +1,60 @@
#include <NazaraEditor/Core/Systems/ComponentsSystem.hpp>
#include <NazaraEditor/Core/Components/CameraComponent.hpp>
#include <NazaraEditor/Core/Components/NameComponent.hpp>
#include <Nazara/Utility/Components/NodeComponent.hpp>
namespace Nz
{
EditorComponentsSystem::EditorComponentsSystem(entt::registry& registry)
: m_registry(registry)
, m_cameraConstructObserver(registry, entt::collector.group<EditorCameraComponent, NodeComponent>())
, m_entityConstructObserver(registry, entt::collector.group<EditorNameComponent, NodeComponent>())
{
m_cameraDestroyConnection = registry.on_destroy<EditorCameraComponent>().connect<&EditorComponentsSystem::OnCameraDestroy>(this);
m_entityDestroyConnection = registry.on_destroy<EditorNameComponent>().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<EditorCameraComponent>(entity);
NodeComponent& transform = m_registry.get<NodeComponent>(entity);
camera.Update(elapsedTime, transform);
}
for (auto entity : m_entities)
{
EditorNameComponent& component = m_registry.get<EditorNameComponent>(entity);
NodeComponent& transform = m_registry.get<NodeComponent>(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);
}
}