godot
godot copied to clipboard
Add support for SDL3 joystick input driver for Windows, Linux and MacOS
Based on https://github.com/godotengine/godot/pull/87925, https://github.com/xsellier/godot/commit/2139868a5c6f986d0ce05235b0f506551c3a725b and https://github.com/xsellier/godot/commit/734322b1c64edf0f607448f09e79cb91502064f9 .
Closes https://github.com/godotengine/godot-proposals/issues/9000 . Fixes #106618 Fixes https://github.com/godotengine/godot/issues/47874 Fixes https://github.com/godotengine/godot/issues/81191 Fixes https://github.com/godotengine/godot/issues/37675 Bugs that were reported to be fixed by the previous SDL input PR: Fixes https://github.com/godotengine/godot/issues/90795 Fixes https://github.com/godotengine/godot/issues/50273
This PR is based on an earlier PR made by EIREXE and several commits made by xsellier (I hope they wouldn't mind...). The mentioned PR was made to work on Linux distributions, and commits by xsellier inspired me to implement support for Windows and MacOS and make SDL3 compile statically inside the Godot's build system.
This PR includes statically linked SDL3 library and it was tested on Windows, Linux and MacOS. On Windows before this PR Godot would print "030000004c050000cc09000000000000" as the GUID for my Dualshock 4 gamepad, after this PR it prints ~~"50533420436f6e74726f6c6c6572"~~ (EDIT: that was a hex version of the gamepad's name, now the code should print its actual GUID).
SDL3 was setup to only build the required subsystems ~~while using dummy code for subsystems that are not going to be used in this PR (for example, GPU, audio, video, etc.),~~ (EDIT: now the dummy subsystems are not included either) and the SDL joystick driver code, alongside with SDL's source code, is ignored on platforms that aren't implemented yet (those are Android, iOS and Web platforms).
This would be my first contribution to Godot. I really like this software and would like it to become even better every day! :)
EDIT: TODO:
- [x] remove unused SDL files ~~remove dummy SDL systems if possible~~ Not sure it's possible to do practically
- [x] make the windows implementation code consistent with other platforms
- [x] improve the code of JoypadSDL class
I will push the changes once I'm done with the tasks
EDIT 2: TODO:
- [x] Implement code fixes from AThousandShips
- [x] Remove # LIBS += ["version", "setupapi", "Cfgmgr32"] and # env.Append(LIBS=["version", "setupapi", "Cfgmgr32"]) from "platform/windows/detect.py" file (I think those are only used if full SDL library is compiled without using dummy systems)
- [x] Implement notes from bruvzg
- [x] Remove the "Input *in" parameter from JoypadSDL's constructor (Why is that parameter even there? Is it slower to use Input::get_singleton() directly?)
- [x] Remove old desktop joypad systems
- [x] Change the #else branch in SDL private build config header to throw an error for unsupported platforms ("No SDL build config was found for this platform. Setup one before compiling the engine.")
- [x] Improve the code for removing a joypad (use JoypadSDL's method to check if the joypad is a gamepad or a joystick), same fix for SKIP_EVENT_FOR_GAMEPAD macro
- [x] Potentially adapt the code to work in a single thread, just like older joypad implementations
- [x] remove unneeded subsystems by using flags like SDL_VIDEO_DISABLED instead of using dummy systems
- [x] test generic controller support on MacOS
- [x] Cleanup the include/ folder from unnecessary files
- [x] thirdparty/sdl/hidapi/windows/test, thirdparty/sdl/hidapi/windows/pp_data_dump (and hidapi makefiles) likely can be removed.
- [x] check for other issue fixes from joypad tracker
- [x] create a new issue for SDL to make the gamepads have the same name on all platforms
TODO 3:
- [ ] fix incorrect mappings when hotplugging
- [ ] check for defines I missed for SDL_build_config_private.h