Skip to content

Commit 68f4717

Browse files
committed
Fix weird "input spasm" bug
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.
1 parent aaebb80 commit 68f4717

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/control/game_controller_manager.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,14 @@ GameControllerManager::process_axis_event(const SDL_ControllerAxisEvent& ev)
149149
Controller& controller = m_parent->get_controller(player_id);
150150
auto set_control = [this, &controller](Control control, bool value)
151151
{
152-
m_stick_state[static_cast<int>(control)] = value;
153-
controller.set_control(control, m_button_state[static_cast<int>(control)] || m_stick_state[static_cast<int>(control)]);
152+
// Check if the input hasn't been changed by anything else like the keyboard.
153+
if (controller.hold(control) == m_stick_state[static_cast<int>(control)] &&
154+
controller.hold(control) != value)
155+
{
156+
m_stick_state[static_cast<int>(control)] = value;
157+
bool newstate = m_button_state[static_cast<int>(control)] || m_stick_state[static_cast<int>(control)];
158+
controller.set_control(control, newstate);
159+
}
154160
};
155161

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

0 commit comments

Comments
 (0)