-
-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Backends: SDL2: Implement multiple gamepad support
This makes the SDL2 backend work correctly with multiple gamepads. Instead of hard-coding gamepad index 0, we keep a list of all currently available gamepads. When gamepads are added or removed, we update the list accordingly. When processing gamepad input, we then iterate over this list and combine the button and axis state of all gamepads. Note that it's not necessary to enumerate gamepads during initialization of the backend, because SDL automatically sends a `SDL_CONTROLLERDEVICEADDED` event for every gamepad that was already present during initialization of SDL. The main motivation for this change is that I can have multiple gamepads connected to my system and grab any one of them at random, and have ImGui recognize my inputs. Previously, this was not guaranteed, because the gamepad I grabbed might not have index 0. It's also possible now to (for example) use the D-pad on one gamepad and and buttons on another one at the same time, although that seems less useful in practice :) Additionally, we now properly close all previously opened gamepads when shutting down the backend.
- Loading branch information
1 parent
2b3e3b5
commit dae475e
Showing
1 changed file
with
67 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters