-
-
Notifications
You must be signed in to change notification settings - Fork 23.1k
Introduce new joypad features provided by SDL3 #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! |
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! |
Thank you for testing, Calinou! May I ask if you can somehow check the C++ stacktrace when the error happens? I would like to fix this issue, but I'm still confused on how |
Actually, I realized features work when not using game embedding (due to input working differently with macOS game embedding - it uses an IPC approach instead of fake window embedding). In this case, it works with all 3 controllers, although gyro stops working after hotplugging, even if I try to calibrate sensors again (LED control still works). I'm not sure what it would take to make the new features work with macOS game embedding. @stuartcarnie Any ideas? |
I'm not a macOS developer, so I'm not sure how to fix the features being missing when the window is embedded 😅 But I'll look into the hotplugging issue later and see if I can fix it! Actually, I will try to reproduce the first issue and see if I can fix it too |
f0f6feb
to
8471453
Compare
By the way, DualSense adaptive triggers should now be fixed! I used a piece of code from an older SDL2 test with adaptive triggers testing and this library (I also added it to COPYRIGHT.txt) to generate the DualSense packets. Also, should SDL_SendJoystickEffect be exposed to the users? It was also used for DualSense adaptive triggers functionality here |
Also, now that I look at the button labels, may I ask what button presses trigger the Misc1 and paddles on DualSense and DualSense Edge? In other words, what should the code report instead of having these generic names for these controllers? |
8471453
to
d11b64f
Compare
I'm happy to also corroborate that when disabling the embedded game window, the DualSense is now mostly working on my end as well! 🥳 Godot.DualSense.demo.working.mp4The "Misc1" button is the microphone mute button (button M in the "Front" diagram here). If by "paddles" you mean L2 and R2 (buttons B and E in the "Top" diagram here), I don't see that they are mapped to a button - instead, they're on an axis. When I press the "Rumble triggers" button in verbose mode, I get an SDL debug message:
|
Thank you for testing, Meorge! At the moment I haven't added adaptive triggers to the test project, and rumble triggers is a feature exclusive to Xbox One controllers, so that's why the operation is not supported. |
Ahh alright, that definitely sounds like a valid reason for rumble triggers not working 😅 |
Using IPC for embedded process SDL joypad input is pretty much pointless, it should work directly - here's a PR - #109603 (in combination with this PR embedded process input and new features seems to work fine, no additional changes required). |
05cb260
to
431d03c
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.
431d03c
to
16c2fbf
Compare
Good news, the PR is basically done! :) |
I'm not a Godot contributor, but looking at the patch it looks great, except SDL_error.c where the logging of errors is uncommented, and it says right over it that many errors are recoverable and would never be seen in the public api, maybe logging them in the release of godot might not be a good idea. |
True, but these errors are only printed if the engine was ran with |
Note for myself (or anyone else who's willing to test it, thanks :) ): check if #78805 is resolved by this PR or in newer 4.5 betas |
Testing on macOS Sequoia 15.6.1 and a Joy-Con (R), with no Joy-Con (L) connected:
For a Joy-Con (L) connected and no Joy-Con (R) connected:
When both Joy-Con are connected:
TL;DR: every Joy-Con button is recognized 🙂 However, in testing this, I did find that it seems to struggle with Joy-Con controllers. The test project doesn't indicate that a controller is connected ("Gamepad connected" is unchecked, "Gamepad name" is empty, etc) although the Input Map menu does register inputs from them. Additionally, if I connect the Joy-Cons to my computer while Godot is running, I often get an error like
|
Thank you for testing, Meorge!
Oh, that's interesting, I will have to look into it.
I also get an error like this when I connect both joycon controllers on Windows, but after that they work just fine, the test project recognizes them too. |
Closes godotengine/godot-proposals#2829
Closes godotengine/godot-proposals#8519
Closes godotengine/godot-proposals#6930
Closes godotengine/godot-proposals#3799
Fixes #78805
Potentially addresses #98008
Partially addresses godotengine/godot-proposals#12087
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:
Input.send_joy_packet()
.There are other more complex features that can be done with SDL functionality, but I decided to move them to separate PRs (see "TODO for separate PRs" section below).
There are some SDL functions that may not be necessary in Godot, so I think they need some discussion before they can be implemented (see "Features that need to be discussed whether they should be implemented or not" section below).
Roadmap and TODO
Input.get_joy_model()
(because JoyType enum already exists) andInput.get_joy_scheme()
(see SDL_GetGamepadType)SDL_GetJoystickVendor, SDL_GetJoystickProduct forMoved to FixInput.get_joy_info()
(see Get joypad's vendor ID, product ID and name on Windows for XInput devices. #98861 )Input.get_joy_info()
regression after the SDL input driver PR #108214Input.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()
Input.get_joy_gravity()
(see https://developer.android.com/reference/android/hardware/SensorEvent#values )Input.get_joy_touchpad_pressure()
SDL_ENABLED
being not definedget_joy_scheme()
override feature, and reflect that inget_joy_model_axis/button_name()
(note for myself: I have an 8BitDo Wireless Adapter that can work in PlayStation Classic Controller mode, so at least an override for this one should exist so it actually reports as having PlayStation scheme)DualSense advanced haptic feedback? https://controllers.fandom.com/wiki/Sony_DualSense Output report Add support for DualSense adaptive triggers and haptic feedback godot-proposals#12087DualSense advanced haptic feedback is audio-based, I assume DualSense is exposing this features as an audio device on Windows (Sources: https://www.pcgamingwiki.com/wiki/Controller:DualSense#:~:text=audio%2Dbased%20haptic%20feedback%20are%20natively%20supported%20(see%20support%20in%20games)%2C%20though%20the%20latter%20is%20only%20supported%20with%20a%20wired%20connection and https://www.reddit.com/r/PS5/comments/jnp8tu/heres_how_to_get_audio_haptic_feedback_with/ ), so I assume it's already possible to use in Godot (see https://docs.godotengine.org/en/stable/classes/class_audioserver.html#class-audioserver-property-output-device ), but to make it work better multiple output devices are required, so this feature essentially depends on Add ability to output sound from different buses to different physical devices godot-proposals#11288Input.send_joy_packet()
SDL_SendJoystickEffectDocumentation:
SDL_JoystickType
): https://learn.microsoft.com/en-us/windows/win32/xinput/xinput-and-controller-subtypes(BTW Horizontal joycons' yaw and roll axes are swapped, needs to be reported to SDL github)Just checked again, they're notInput.get_joy_accelerometer() + Input.get_joy_gravity()
)Input.get_joy_model_axis/button_name()
may not work exactly as expected if the gamepad is not a first-party gamepad from PlayStation, Xbox or Nintendo because SDL cannot otherwise check what the labels on the controller areTODO when Godot gets SDL input support for other platforms
TODO for separate PRs
Input.get_pov_hat_vector()
(see AddInputEventJoypadHat
godot-proposals#9850 )InputEventJoypadHat
godot-proposals#9850 ) and ball eventsBattery/power eventsThat's not something the player can control, so no need to add these eventsInputEventJoypadAccelerometer
,InputEventJoypadGyroscope
)Features that need to be discussed whether they should be implemented or not
SDL_GetGamepadSteamHandle (for https://godotsteam.com/classes/input/ ?)Handled by FixInput.get_joy_info()
regression after the SDL input driver PR #108214TODO 2:
Here's a small project to test new joypad features:
JoypadTest.zip