33 if (event.type == SDL_EVENT_KEY_DOWN || event.type == SDL_EVENT_KEY_UP) {
34 bool isPressed = (
event.type == SDL_EVENT_KEY_DOWN);
35 SDL_Scancode scancode =
event.key.scancode;
37 auto& keyState = keyStates[scancode];
38 bool wasPressed = keyState.isPressed;
40 keyState.isPressed = isPressed;
41 if (isPressed && !wasPressed) {
42 keyState.wasProcessedAsPressed =
false;
46 for (
const auto& binding : inputComp.bindings) {
47 if (binding.scancode == scancode) {
48 if (isPressed && binding.state == InputActionState::Pressed && !wasPressed && !keyStates[scancode].wasProcessedAsPressed) {
49 binding.action(deltaTime);
50 keyStates[scancode].wasProcessedAsPressed =
true;
51 }
else if (!isPressed && binding.state == InputActionState::Released) {
52 binding.action(deltaTime);
53 }
else if (!isPressed && binding.state == InputActionState::Held) {
59 }
else if (event.type == SDL_EVENT_MOUSE_MOTION && m_inputMode != InputMode::UI) {
61 for (
const auto& binding : inputComp.mouseAxisBindings) {
62 float delta = (binding.axis == MouseAxis::X) ? event.motion.xrel :
event.motion.yrel;
63 binding.action(delta);
66 }
else if (event.type == SDL_EVENT_GAMEPAD_BUTTON_DOWN || event.type == SDL_EVENT_GAMEPAD_BUTTON_UP) {
67 bool isPressed = (
event.type == SDL_EVENT_GAMEPAD_BUTTON_DOWN);
68 SDL_GamepadButton button = (SDL_GamepadButton)event.gbutton.button;
70 gamepadButtonStates[button].isPressed = isPressed;
73 for (
const auto& binding : inputComp.gamepadButtonBindings) {
74 if (binding.button == button) {
75 if (isPressed && binding.state == InputActionState::Pressed) {
76 binding.action(deltaTime);
77 }
else if (!isPressed && binding.state == InputActionState::Released) {
78 binding.action(deltaTime);
83 }
else if (event.type == SDL_EVENT_GAMEPAD_AXIS_MOTION) {
84 float normalizedValue =
event.gaxis.value / 32767.0f;
85 gamepadAxisStates[(SDL_GamepadAxis)event.gaxis.axis] = normalizedValue;
91 for (
const auto& binding : inputComp.gamepadAxisBindings) {
92 float currentValue = gamepadAxisStates[binding.axis];
93 binding.action(currentValue);
95 for (
const auto& binding : inputComp.gamepadButtonBindings) {
96 if (binding.state == InputActionState::Held && gamepadButtonStates[binding.button].isPressed) {
97 binding.action(deltaTime);
100 for (
const auto& binding : inputComp.bindings) {
101 if (binding.state == InputActionState::Held && keyStates[binding.scancode].isPressed) {
102 binding.action(deltaTime);