refactor(surface): adjust to new ecs
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
parent
120b6c24d9
commit
9badcddeae
4 changed files with 40 additions and 52 deletions
|
@ -40,40 +40,32 @@ System::System(Ref<ecs::Registry> registry): m_registry(std::move(registry))
|
|||
ensure(m_registry, "Failed to initialize surface system: null registry");
|
||||
|
||||
ensure(
|
||||
m_registry->view<SurfaceComponent>().size() == 0,
|
||||
m_registry->view<SurfaceComponent>().get_size() == 0,
|
||||
"Failed to initialize surface system: registry has surface component(s)"
|
||||
);
|
||||
|
||||
m_registry->get_entt_registry()
|
||||
.on_construct<SurfaceComponent>()
|
||||
.connect<&System::on_surface_construct>(this);
|
||||
m_registry->connect_on_construct<SurfaceComponent>(
|
||||
[this](ecs::Registry ®istry, ecs::Entity entity) {
|
||||
on_surface_construct(registry, entity);
|
||||
}
|
||||
);
|
||||
|
||||
m_registry->get_entt_registry()
|
||||
.on_update<SurfaceComponent>()
|
||||
.connect<&System::on_surface_update>(this);
|
||||
|
||||
m_registry->get_entt_registry()
|
||||
.on_destroy<SurfaceComponent>()
|
||||
.connect<&System::on_surface_destroy>(this);
|
||||
m_registry->connect_on_destruct<SurfaceComponent>(
|
||||
[this](ecs::Registry ®istry, ecs::Entity entity) {
|
||||
on_surface_destruct(registry, entity);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
System::~System()
|
||||
{
|
||||
m_registry->view<SurfaceComponent>().each([&](const entt::entity entity, SurfaceComponent &) {
|
||||
m_registry->get_entt_registry().remove<SurfaceComponent>(entity);
|
||||
});
|
||||
for (auto &[entity, surface] : m_registry->view<SurfaceComponent>())
|
||||
{
|
||||
m_registry->remove<SurfaceComponent>(entity);
|
||||
}
|
||||
|
||||
m_registry->get_entt_registry()
|
||||
.on_construct<SurfaceComponent>()
|
||||
.disconnect<&System::on_surface_construct>(this);
|
||||
|
||||
m_registry->get_entt_registry()
|
||||
.on_update<SurfaceComponent>()
|
||||
.connect<&System::on_surface_update>(this);
|
||||
|
||||
m_registry->get_entt_registry()
|
||||
.on_destroy<SurfaceComponent>()
|
||||
.disconnect<&System::on_surface_destroy>(this);
|
||||
m_registry->disconnect_on_construct<SurfaceComponent>();
|
||||
m_registry->disconnect_on_destruct<SurfaceComponent>();
|
||||
}
|
||||
|
||||
void System::on_register()
|
||||
|
@ -84,7 +76,7 @@ void System::on_unregister()
|
|||
{
|
||||
}
|
||||
|
||||
void System::on_surface_construct(entt::registry ®istry, entt::entity entity)
|
||||
void System::on_surface_construct(ecs::Registry ®istry, ecs::Entity entity)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -173,12 +165,7 @@ void System::on_surface_construct(entt::registry ®istry, entt::entity entity)
|
|||
}
|
||||
}
|
||||
|
||||
void System::on_surface_update(entt::registry ®istry, entt::entity entity)
|
||||
{
|
||||
auto &surface = registry.get<SurfaceComponent>(entity);
|
||||
}
|
||||
|
||||
void System::on_surface_destroy(entt::registry ®istry, entt::entity entity)
|
||||
void System::on_surface_destruct(ecs::Registry ®istry, ecs::Entity entity)
|
||||
{
|
||||
const auto &[display, window, _] = registry.get<SurfaceComponent>(entity).get_native_data();
|
||||
if (!display)
|
||||
|
@ -374,11 +361,12 @@ void System::modify_visiblity(SurfaceComponent &surface, const ModifyVisibilityR
|
|||
|
||||
auto System::tick() -> bool
|
||||
{
|
||||
m_registry->view<SurfaceComponent>().each([this](SurfaceComponent &surface) {
|
||||
for (auto &dense : m_registry->view<SurfaceComponent>())
|
||||
{
|
||||
auto &surface = dense.second;
|
||||
handle_requests(surface);
|
||||
|
||||
handle_events(surface);
|
||||
});
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#include <ecs/entity.hpp>
|
||||
#include <ecs/scene.hpp>
|
||||
#include <ecs/registry.hpp>
|
||||
#include <surface/components.hpp>
|
||||
#include <surface/system.hpp>
|
||||
#include <test/fuzz.hpp>
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include <ecs/entity.hpp>
|
||||
#include <ranges>
|
||||
#include <surface/components.hpp>
|
||||
#include <surface/requests/surface.hpp>
|
||||
#include <surface/system.hpp>
|
||||
|
@ -45,8 +46,8 @@ public:
|
|||
}
|
||||
) -> SurfaceComponent &
|
||||
{
|
||||
auto entity = m_registry->create_entity("");
|
||||
return entity.add_component<SurfaceComponent>(info);
|
||||
auto entity = m_registry->create_entity();
|
||||
return m_registry->add<SurfaceComponent>(entity, info);
|
||||
}
|
||||
|
||||
void check_values(const SurfaceComponent &component)
|
||||
|
@ -92,7 +93,7 @@ Suite raii = [] {
|
|||
Case { "post construct has correct state" } = [] {
|
||||
auto fixture = Fixture {};
|
||||
auto system = System { fixture.registry() };
|
||||
expect_eq(fixture.registry()->view<SurfaceComponent>()->size(), 0);
|
||||
expect_eq(fixture.registry()->view<SurfaceComponent>().get_size(), 0);
|
||||
};
|
||||
|
||||
Case { "post destruct has correct state" } = [] {
|
||||
|
@ -100,10 +101,10 @@ Suite raii = [] {
|
|||
auto system = create_scope<System>(fixture.registry());
|
||||
|
||||
fixture.add_surface_component();
|
||||
expect_eq(fixture.registry()->view<SurfaceComponent>()->size(), 1);
|
||||
expect_eq(fixture.registry()->view<SurfaceComponent>().get_size(), 1);
|
||||
|
||||
system.reset();
|
||||
expect_eq(fixture.registry()->view<SurfaceComponent>()->size(), 0);
|
||||
expect_eq(fixture.registry()->view<SurfaceComponent>().get_size(), 0);
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -113,7 +114,7 @@ Suite system_events = [] {
|
|||
auto system = System { fixture.registry() };
|
||||
|
||||
system.on_register();
|
||||
expect_eq(fixture.registry()->view<SurfaceComponent>().size(), 0);
|
||||
expect_eq(fixture.registry()->view<SurfaceComponent>().get_size(), 0);
|
||||
};
|
||||
|
||||
Case { "on_unregister won't throw" } = [] {
|
||||
|
@ -122,7 +123,7 @@ Suite system_events = [] {
|
|||
|
||||
system.on_register();
|
||||
system.on_unregister();
|
||||
expect_eq(fixture.registry()->view<SurfaceComponent>().size(), 0);
|
||||
expect_eq(fixture.registry()->view<SurfaceComponent>().get_size(), 0);
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -132,7 +133,7 @@ Suite registry_events = [] {
|
|||
auto system = System { fixture.registry() };
|
||||
|
||||
const auto &component = fixture.add_surface_component();
|
||||
expect_eq(fixture.registry()->view<SurfaceComponent>().size(), 1);
|
||||
expect_eq(fixture.registry()->view<SurfaceComponent>().get_size(), 1);
|
||||
fixture.check_values(component);
|
||||
};
|
||||
|
||||
|
@ -168,7 +169,7 @@ Suite registry_events = [] {
|
|||
auto system = System { fixture.registry() };
|
||||
|
||||
expect_throw([&] { fixture.add_surface_component({ .resolution = { width, 0 } }); });
|
||||
expect_eq(fixture.registry()->view<SurfaceComponent>().size(), 0);
|
||||
expect_eq(fixture.registry()->view<SurfaceComponent>().get_size(), 0);
|
||||
};
|
||||
|
||||
Case { "on_destrroy<SurfaceComponent> cleans up component" } = [] {
|
||||
|
@ -176,11 +177,11 @@ Suite registry_events = [] {
|
|||
auto system = create_scope<System>(fixture.registry());
|
||||
|
||||
const auto &component = fixture.add_surface_component();
|
||||
expect_eq(fixture.registry()->view<SurfaceComponent>().size(), 1);
|
||||
expect_eq(fixture.registry()->view<SurfaceComponent>().get_size(), 1);
|
||||
fixture.check_values(component);
|
||||
|
||||
system.reset();
|
||||
expect_eq(fixture.registry()->view<SurfaceComponent>().size(), 0);
|
||||
expect_eq(fixture.registry()->view<SurfaceComponent>().get_size(), 0);
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
#pragma once
|
||||
|
||||
#include <app/system.hpp>
|
||||
#include <ecs/scene.hpp>
|
||||
#include <ecs/registry.hpp>
|
||||
#include <math/vec2.hpp>
|
||||
|
||||
namespace lt::surface {
|
||||
|
||||
|
@ -27,11 +28,9 @@ public:
|
|||
auto tick() -> bool override;
|
||||
|
||||
private:
|
||||
void on_surface_construct(entt::registry ®istry, entt::entity entity);
|
||||
void on_surface_construct(ecs::Registry ®istry, ecs::Entity entity);
|
||||
|
||||
void on_surface_update(entt::registry ®istry, entt::entity entity);
|
||||
|
||||
void on_surface_destroy(entt::registry ®istry, entt::entity entity);
|
||||
void on_surface_destruct(ecs::Registry ®istry, ecs::Entity entity);
|
||||
|
||||
void handle_requests(struct SurfaceComponent &surface);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue