start with input

This commit is contained in:
2025-04-13 21:16:10 +02:00
parent ecad49ee32
commit 82ddc88246
10 changed files with 106 additions and 58 deletions

View File

@@ -4,22 +4,22 @@
namespace Input {
void KeyListener::key_event(KeyInput const& key_input_event)
{
auto& key_state = registry.ctx().get<State<KeyCode>>();
// void KeyListener::key_event(KeyInput const& key_input_event)
// {
// auto& key_state = registry.ctx().get<State<KeyCode>>();
if (key_input_event.action == static_cast<Action>(GLFW_PRESS)) {
key_state.press(key_input_event.key_code);
} else if (key_input_event.action == static_cast<Action>(GLFW_RELEASE)) {
key_state.release(key_input_event.key_code);
}
}
// if (key_input_event.action == static_cast<Action>(GLFW_PRESS)) {
// key_state.press(key_input_event.key_code);
// } else if (key_input_event.action == static_cast<Action>(GLFW_RELEASE)) {
// key_state.release(key_input_event.key_code);
// }
// }
void CursorListener::cursor_event(MouseMotion const& mouse_motion_event)
{
auto& mouse_motion = registry.ctx().get<MouseMotion>();
mouse_motion.delta += mouse_motion_event.delta;
}
// void CursorListener::cursor_event(MouseMotion const& mouse_motion_event)
// {
// auto& mouse_motion = registry.ctx().get<MouseMotion>();
// mouse_motion.delta += mouse_motion_event.delta;
// }
void reset_mouse_motion(entt::registry& registry)
{
@@ -27,11 +27,11 @@ void reset_mouse_motion(entt::registry& registry)
mouse_motion = {};
}
template <typename T> void State<T>::update_state(entt::registry& registry)
template <typename T> void State<T>::update_state(flecs::entity window_entity)
{
auto& state = registry.ctx().get<State<T>>();
state.just_pressed_keys.clear();
state.just_released_keys.clear();
auto* state = window_entity.get_mut<State<T>>();
state->just_pressed_keys.clear();
state->just_released_keys.clear();
}
template class State<KeyCode>;