testbed: bare minimal input system

This commit is contained in:
skypjack
2025-04-30 16:06:55 +02:00
parent cb10854bc8
commit 57a6c6b238

View File

@@ -1,9 +1,20 @@
#include <application/context.h>
#include <component/input_listener_component.h>
#include <entt/entity/registry.hpp>
#include <system/input_system.h>
namespace testbed {
namespace internal {
static void update_listeners(entt::registry &registry, input_listener_component::type command) {
for([[maybe_unused]] auto [entt, elem]: registry.view<input_listener_component>().each()) {
elem.command = command;
}
}
} // namespace internal
void input_system(entt::registry &registry, const SDL_Event &event, bool &quit) {
switch(event.type) {
case SDL_EVENT_QUIT:
@@ -14,6 +25,18 @@ void input_system(entt::registry &registry, const SDL_Event &event, bool &quit)
case SDLK_ESCAPE:
quit = true;
break;
case SDLK_UP:
internal::update_listeners(registry, input_listener_component::type::UP);
break;
case SDLK_DOWN:
internal::update_listeners(registry, input_listener_component::type::DOWN);
break;
case SDLK_LEFT:
internal::update_listeners(registry, input_listener_component::type::LEFT);
break;
case SDLK_RIGHT:
internal::update_listeners(registry, input_listener_component::type::RIGHT);
break;
}
break;
}