diff --git a/src/input/controller.h b/src/input/controller.h index a45e71d77..bbaed75ea 100644 --- a/src/input/controller.h +++ b/src/input/controller.h @@ -60,7 +60,7 @@ inline int GetAxis(int min, int max, int value) { return std::clamp((255 * (value - min)) / (max - min), 0, 255); } -constexpr u32 MAX_STATES = 64; +constexpr u32 MAX_STATES = 32; class GameController { public: diff --git a/src/input/input_handler.cpp b/src/input/input_handler.cpp index 9c51ec8be..38a310324 100644 --- a/src/input/input_handler.cpp +++ b/src/input/input_handler.cpp @@ -448,7 +448,6 @@ void ControllerOutput::ResetUpdate() { *new_param = 0; // bruh } void ControllerOutput::AddUpdate(InputEvent event) { - state_changed = true; if (button == KEY_TOGGLE) { if (event.active) { ToggleKeyInList(event.input); @@ -465,24 +464,14 @@ void ControllerOutput::AddUpdate(InputEvent event) { } } else if (axis != SDL_GAMEPAD_AXIS_INVALID) { - switch (axis) { - case SDL_GAMEPAD_AXIS_LEFT_TRIGGER: - case SDL_GAMEPAD_AXIS_RIGHT_TRIGGER: - // if it's a button input, then we know the value to set, so the param is 0. - // if it's an analog input, then the param isn't 0 - *new_param = (event.active ? event.axis_value : 0) + *new_param; - break; - default: - *new_param = (event.active ? event.axis_value : 0) + *new_param; - break; - } + *new_param = (event.active ? event.axis_value : 0) + *new_param; } } void ControllerOutput::FinalizeUpdate() { + state_changed = old_button_state != new_button_state || old_param != *new_param; if (!state_changed) { - // return; + return; } - old_button_state = new_button_state; old_param = *new_param; float touchpad_x = 0; @@ -511,8 +500,6 @@ void ControllerOutput::FinalizeUpdate() { } } else if (axis != SDL_GAMEPAD_AXIS_INVALID && positive_axis) { // avoid double-updating axes, but don't skip directional button bindings - float multiplier = 1.0; - int deadzone = 0; auto ApplyDeadzone = [](s16* value, std::pair deadzone) { if (std::abs(*value) <= deadzone.first || deadzone.first == deadzone.second) { *value = 0; @@ -523,6 +510,7 @@ void ControllerOutput::FinalizeUpdate() { 0, 128); } }; + float multiplier = 1.0; Axis c_axis = GetAxisFromSDLAxis(axis); switch (c_axis) { case Axis::LeftX: @@ -572,6 +560,10 @@ bool UpdatePressedKeys(InputEvent event) { pressed_keys.insert(it, {event, false}); LOG_DEBUG(Input, "Added axis {} to the input list", event.input.sdl_id); } else { + // noise filter + if (std::abs(it->first.axis_value - event.axis_value) <= 1) { + return false; + } it->first.axis_value = event.axis_value; } return true;