Skip to content

Commit 1ba1e68

Browse files
Fix multiple game controllers interfering each other (#3369)
GameControllerManager shared one button/stick state between all connected game controllers. This led to one controller interfering with other controllers in multiplayer mode.
1 parent b4424e9 commit 1ba1e68

File tree

2 files changed

+4
-15
lines changed

2 files changed

+4
-15
lines changed

src/control/game_controller_manager.cpp

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@
2929
GameControllerManager::GameControllerManager(InputManager* parent) :
3030
m_parent(parent),
3131
m_deadzone(8000),
32-
m_game_controllers(),
33-
m_stick_state(),
34-
m_button_state()
32+
m_game_controllers()
3533
{
3634
}
3735

@@ -61,8 +59,8 @@ GameControllerManager::process_button_event(const SDL_ControllerButtonEvent& ev)
6159
Controller& controller = m_parent->get_controller(player_id);
6260
auto set_control = [this, &controller](Control control, Uint8 value)
6361
{
64-
m_button_state[static_cast<int>(control)] = (value != 0);
65-
controller.set_control(control, m_button_state[static_cast<int>(control)] == SDL_PRESSED || m_stick_state[static_cast<int>(control)] == SDL_PRESSED);
62+
const bool pressed = (value == SDL_PRESSED);
63+
controller.set_control(control, pressed);
6664
};
6765
switch (ev.button)
6866
{
@@ -149,14 +147,7 @@ GameControllerManager::process_axis_event(const SDL_ControllerAxisEvent& ev)
149147
Controller& controller = m_parent->get_controller(player_id);
150148
auto set_control = [this, &controller](Control control, bool value)
151149
{
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-
}
150+
controller.set_control(control, value);
160151
};
161152

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

src/control/game_controller_manager.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ class GameControllerManager final
5959
InputManager* m_parent;
6060
int m_deadzone;
6161
std::unordered_map<SDL_GameController*, int> m_game_controllers;
62-
std::array<bool, static_cast<int>(Control::CONTROLCOUNT)> m_stick_state;
63-
std::array<bool, static_cast<int>(Control::CONTROLCOUNT)> m_button_state;
6462

6563
private:
6664
GameControllerManager(const GameControllerManager&) = delete;

0 commit comments

Comments
 (0)