refactor(input): adjusted to recent changes
This commit is contained in:
parent
b6834310a7
commit
d924d14ab0
3 changed files with 34 additions and 13 deletions
|
@ -14,7 +14,7 @@ System::System(Ref<ecs::Registry> registry): m_registry(std::move(registry))
|
||||||
ensure(m_registry, "Failed to initialize input system: null registry");
|
ensure(m_registry, "Failed to initialize input system: null registry");
|
||||||
}
|
}
|
||||||
|
|
||||||
auto System::tick() -> bool
|
void System::tick(app::TickInfo tick)
|
||||||
{
|
{
|
||||||
for (auto &[entity, surface] : m_registry->view<surface::SurfaceComponent>())
|
for (auto &[entity, surface] : m_registry->view<surface::SurfaceComponent>())
|
||||||
{
|
{
|
||||||
|
@ -51,7 +51,12 @@ auto System::tick() -> bool
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
const auto now = std::chrono::steady_clock::now();
|
||||||
|
m_last_tick_result = app::TickResult {
|
||||||
|
.info = tick,
|
||||||
|
.duration = now - tick.start_time,
|
||||||
|
.end_time = now,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
void System::on_register()
|
void System::on_register()
|
||||||
|
|
|
@ -18,6 +18,15 @@ using test::expect_throw;
|
||||||
using test::Suite;
|
using test::Suite;
|
||||||
// NOLINTEND
|
// NOLINTEND
|
||||||
|
|
||||||
|
[[nodiscard]] auto tick_info() -> app::TickInfo
|
||||||
|
{
|
||||||
|
return {
|
||||||
|
.delta_time = std::chrono::milliseconds { 16 },
|
||||||
|
.budget = std::chrono::milliseconds { 10 },
|
||||||
|
.start_time = std::chrono::steady_clock::now(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
class Fixture
|
class Fixture
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -26,7 +35,7 @@ public:
|
||||||
return m_registry;
|
return m_registry;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto add_input_component() -> ecs::Entity
|
auto add_input_component() -> ecs::EntityId
|
||||||
{
|
{
|
||||||
auto entity = m_registry->create_entity();
|
auto entity = m_registry->create_entity();
|
||||||
m_registry->add<InputComponent>(entity, {});
|
m_registry->add<InputComponent>(entity, {});
|
||||||
|
@ -34,7 +43,7 @@ public:
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto add_surface_component() -> ecs::Entity
|
auto add_surface_component() -> ecs::EntityId
|
||||||
{
|
{
|
||||||
auto entity = m_registry->create_entity();
|
auto entity = m_registry->create_entity();
|
||||||
m_registry->add<surface::SurfaceComponent>(
|
m_registry->add<surface::SurfaceComponent>(
|
||||||
|
@ -124,7 +133,7 @@ Suite tick = [] {
|
||||||
auto registry = fixture.registry();
|
auto registry = fixture.registry();
|
||||||
auto system = System { fixture.registry() };
|
auto system = System { fixture.registry() };
|
||||||
|
|
||||||
expect_false(system.tick());
|
system.tick(tick_info());
|
||||||
};
|
};
|
||||||
|
|
||||||
Case { "Tick triggers input action" } = [] {
|
Case { "Tick triggers input action" } = [] {
|
||||||
|
@ -146,23 +155,23 @@ Suite tick = [] {
|
||||||
);
|
);
|
||||||
|
|
||||||
expect_eq(input.get_action(action_key).state, input::InputAction::State::inactive);
|
expect_eq(input.get_action(action_key).state, input::InputAction::State::inactive);
|
||||||
system.tick();
|
system.tick(tick_info());
|
||||||
expect_eq(input.get_action(action_key).state, input::InputAction::State::inactive);
|
expect_eq(input.get_action(action_key).state, input::InputAction::State::inactive);
|
||||||
|
|
||||||
surface.push_event(surface::KeyPressedEvent(69));
|
surface.push_event(surface::KeyPressedEvent(69));
|
||||||
system.tick();
|
system.tick(tick_info());
|
||||||
expect_eq(input.get_action(action_key).state, input::InputAction::State::triggered);
|
expect_eq(input.get_action(action_key).state, input::InputAction::State::triggered);
|
||||||
|
|
||||||
system.tick();
|
system.tick(tick_info());
|
||||||
expect_eq(input.get_action(action_key).state, input::InputAction::State::active);
|
expect_eq(input.get_action(action_key).state, input::InputAction::State::active);
|
||||||
|
|
||||||
system.tick();
|
system.tick(tick_info());
|
||||||
system.tick();
|
system.tick(tick_info());
|
||||||
system.tick();
|
system.tick(tick_info());
|
||||||
expect_eq(input.get_action(action_key).state, input::InputAction::State::active);
|
expect_eq(input.get_action(action_key).state, input::InputAction::State::active);
|
||||||
|
|
||||||
surface.push_event(surface::KeyReleasedEvent(69));
|
surface.push_event(surface::KeyReleasedEvent(69));
|
||||||
system.tick();
|
system.tick(tick_info());
|
||||||
expect_eq(input.get_action(action_key).state, input::InputAction::State::inactive);
|
expect_eq(input.get_action(action_key).state, input::InputAction::State::inactive);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -13,12 +13,17 @@ class System: public app::ISystem
|
||||||
public:
|
public:
|
||||||
System(Ref<ecs::Registry> registry);
|
System(Ref<ecs::Registry> registry);
|
||||||
|
|
||||||
auto tick() -> bool override;
|
void tick(app::TickInfo tick) override;
|
||||||
|
|
||||||
void on_register() override;
|
void on_register() override;
|
||||||
|
|
||||||
void on_unregister() override;
|
void on_unregister() override;
|
||||||
|
|
||||||
|
[[nodiscard]] auto get_last_tick_result() const -> const app::TickResult & override
|
||||||
|
{
|
||||||
|
return m_last_tick_result;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void handle_event(const surface::SurfaceComponent::Event &event);
|
void handle_event(const surface::SurfaceComponent::Event &event);
|
||||||
|
|
||||||
|
@ -41,6 +46,8 @@ private:
|
||||||
std::array<bool, 512> m_buttons {};
|
std::array<bool, 512> m_buttons {};
|
||||||
|
|
||||||
math::vec2 m_pointer_position;
|
math::vec2 m_pointer_position;
|
||||||
|
|
||||||
|
app::TickResult m_last_tick_result {};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue