renaming CameraSystem to ComponentsSystem
Now handles all editor components
This commit is contained in:
parent
bc18b5ef5d
commit
dd7cdbdc8f
|
|
@ -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;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
@ -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;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
@ -115,7 +115,7 @@ namespace Nz
|
||||||
if (bRes)
|
if (bRes)
|
||||||
{
|
{
|
||||||
RenderSystem& system = m_level.GetEnttWorld()->AddSystem<RenderSystem>();
|
RenderSystem& system = m_level.GetEnttWorld()->AddSystem<RenderSystem>();
|
||||||
m_level.GetEnttWorld()->AddSystem<EditorCameraSystem>();
|
m_level.GetEnttWorld()->AddSystem<EditorComponentsSystem>();
|
||||||
|
|
||||||
system.AttachExternalSwapchain(*m_windowSwapchain);
|
system.AttachExternalSwapchain(*m_windowSwapchain);
|
||||||
system.GetFramePipeline().RegisterViewer(m_editorCamera.get(), 2);
|
system.GetFramePipeline().RegisterViewer(m_editorCamera.get(), 2);
|
||||||
|
|
|
||||||
|
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue