Skip to content

Commit

Permalink
Fix weird "input spasm" bug
Browse files Browse the repository at this point in the history
If a connected SDL GameController compatible device sends faulty axis
inputs, even if those inputs are below the deadzone, they will overwrite
the inputs sent by the keyboard, creating an odd "spasm effect" when
holding a directional input in the keyboard.

Here, in the GameControllerManager, I check the proposed input and the
current stick state, so that I can confirm that the GameController is
free to send inputs without interrupting anything else.
  • Loading branch information
MatusGuy committed Feb 1, 2025
1 parent aaebb80 commit 68f4717
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/control/game_controller_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,14 @@ GameControllerManager::process_axis_event(const SDL_ControllerAxisEvent& ev)
Controller& controller = m_parent->get_controller(player_id);
auto set_control = [this, &controller](Control control, bool value)
{
m_stick_state[static_cast<int>(control)] = value;
controller.set_control(control, m_button_state[static_cast<int>(control)] || m_stick_state[static_cast<int>(control)]);
// Check if the input hasn't been changed by anything else like the keyboard.
if (controller.hold(control) == m_stick_state[static_cast<int>(control)] &&
controller.hold(control) != value)
{
m_stick_state[static_cast<int>(control)] = value;
bool newstate = m_button_state[static_cast<int>(control)] || m_stick_state[static_cast<int>(control)];
controller.set_control(control, newstate);
}
};

auto axis2button = [this, &set_control](int value, Control control_left, Control control_right)
Expand Down

0 comments on commit 68f4717

Please sign in to comment.