-
-
Notifications
You must be signed in to change notification settings - Fork 22.8k
Introduce new joypad features provided by SDL3 (WIP) #107967
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
I'm especially excited to see Joy-Con support listed here. I think those are really fun little controllers, so much so that I started making my own C++ library for interfacing with them and a Godot GDExtension based off of that - however, obviously being a GDExtension, it doesn't mesh very well with Godot's built-in APIs. Having the support be more built-in to the engine would be awesome! I'm not sure how much overlap there is between SDL's Joy-Con support and what my library does, but if a lot of the Joy-Con-specific features don't have SDL APIs, I may be able to help on that front 😄 |
9940d41
to
9e6d7d8
Compare
I made a list of features that need discussion before implementing, so if you think any of the listed features are important to have built into the engine, you can let me know! |
b39eef9
to
e70bbb5
Compare
Feature request for a separate PR: querying for separate keyboards and mice (SDL_GetKeyboards and SDL_GetMice respectively) |
Multi-keyboard/mouse support seems subpar in SDL 3 from what I've heard, so it may not be worth the effort. This is based on what I've seen in the Perfect Dark PC port Discord (people have tried implementing it there, but quickly regretted it). |
Will the gamepad type for GameCube controllers be included? It seems to be the only one not added from |
I'm still very excited for Joy-Con support and would love to contribute where I can, but thinking about it more, I think specialized support for its features would fit better as a separate PR (if not some kind of plugin/addon). 😅 Maintainers should have more of a say in this of course, but I could see it being helpful to split this up into multiple smaller PRs so that each individual one is easier to test and verify. That all being said, for this PR (whether it ends up being split later or not) I can certainly test its functionality on macOS. Let me know if/when you'd like me to give that a shot! 😄 |
Godot is currently using the latest stable release of SDL (3.2.16), which doesn't support GameCube controllers :( https://github.com/libsdl-org/SDL/blob/c9a6709bd21750f1ad9597be21abace78c6378c9/include/SDL3/SDL_gamepad.h |
That's a shame. Maybe in the future then! |
e70bbb5
to
f891f14
Compare
I know this is still marked as a draft, so these may be things you're aware of and are planning on fixing, but just in case: I got excited and decided to pull it to test on macOS, and ran into some compilation errors. In
If I add default cases to those switch statements, I get errors about the parameters in
|
f891f14
to
3a143d4
Compare
I haven't tried to compile on macOS yet, but I think I fixed these 2 errors, I hope it should now compile! |
Thanks! It compiles now, but unfortunately I get a segmentation fault immediately upon starting Godot... I may be able to look further into that soon LLDB is giving this output for the location of the segfault:
The backtrace seems to give an infinite loop?
|
This PR should likely fix your issue: #107963 EDIT: Decided to rebase now! |
bf6dd95
to
0e453aa
Compare
This commit adds support for new SDL joypad features that weren't previously possible due to older custom joypad implementations. These features include accelerometer, gyroscope, LED lights, touchpads and more.
0e453aa
to
898c22f
Compare
Thanks for the rebase! With that, the editor is now building, and I'm able to run the demo project. It looks like the instance of
Note that after That's my hypothesis for what's going on at the moment, at least. I know you may still be working on putting together the core functionality for the PR, but please let me know if there's anything else I can test or results I can provide to help with the macOS support! |
That's weird, because I haven't changed the "joystick added" event functionality in this PR, so it should work just fine. Do you have this bug if you test Godot 4.5 beta 2? |
If I run commit efb40c1 (the commit on which this PR appears to currently be based) and comment out most of the code in the test project's No errors appear, and the gamepad does show up as connected: With this PR's commit, I get the error again:
Note that it's including line 4 of I'm expecting to be busy this weekend, so I don't know how much time I'll have for it the next few days, but soon after I should hopefully be able to dive deeper into it. |
Let's hope I will encounter this bug on macOS myself so I can try to fix it 😅 |
Indeed, that may well be more efficient 😅 But please don't hesitate to let me know if there are any specific tests or things you'd like me to take a look at, and I'll do so as soon as I can! I'm really looking forward to having this rich controller support 😄 |
Partially based on #88590
Closes godotengine/godot-proposals#2829
Closes godotengine/godot-proposals#8519
Closes godotengine/godot-proposals#6930
Closes godotengine/godot-proposals#3799
Potentially closes #98008
Supersedes #88590
Supersedes #89193
Since SDL joypad driver was merged recently ( #106218 ), this PR adds support for new SDL joypad features that weren't previously possible due to older custom joypad implementations. These features include accelerometer, gyroscope, LED lights, touchpads and more.
The features that need to be done before this PR is ready for review/merge, i.e. the roadmap:
Input.get_joy_model()
(because JoyType enum already exists) andInput.get_joy_scheme()
(see SDL_GetGamepadType)SDL_GetJoystickVendor, SDL_GetJoystickProduct forMoved to Fix Input.get_joy_info() regression after the SDL input driver PR #108214Input.get_joy_info()
(see Get joypad's vendor ID, product ID and name on Windows for XInput devices. #98861 )Input.start_joy_motion_calibration()
,Input.step_joy_motion_calibration()
,Input.stop_joy_motion_calibration()
,Input.clear_joy_motion_calibration()
)SDL_SetJoystickPlayerIndex to set the physical joypad's player indication (LED light count for Switch and Wii controllers, LED color for PlayStation, no action for other controllers)Didn't work for my joycon controllers and my Dualshock 4, even though the method returned trueInput.get/set_joy_motion_calibration()
to save/load calibration settings, uses Dictionary to do thatInput.get_joy_model_axis/button_name()
SDL_JoystickType
): https://learn.microsoft.com/en-us/windows/win32/xinput/xinput-and-controller-subtypesInput.get_joy_info()
fields(BTW Horizontal joycons' yaw and roll axes are swapped, needs to be reported to SDL github)Just checked again, they're notTODO when Godot starts supporting SDL for other platforms:
TODO for separate PRs:
Input.get_pov_hat_vector()
(see AddInputEventJoypadHat
godot-proposals#9850 )InputEventJoypadHat
godot-proposals#9850 ) and ball eventsGodot events for accelerometer/gyroscope (Sensor events don't exist for mobile devices, so I don't think they should exist for joypadsInputEventJoypadAccelerometer
,InputEventJoypadGyroscope
)Battery/power eventsThat's not something the player can control, so no need to add these eventsFeatures that need to be discussed whether they should be implemented or not:
SDL_GetGamepadSteamHandle (for https://godotsteam.com/classes/input/ ?)Handled by Fix Input.get_joy_info() regression after the SDL input driver PR #108214Input.send_joy_packet()
SDL_SendJoystickEffectHere's a small project to test new joypad features (in case someone might build this WIP PR from scratch) :
JoypadTest.zip
(P.S. I opened this PR so early, because I want to let people know that this is being worked on and that I'm working on it :D)