-
-
Notifications
You must be signed in to change notification settings - Fork 23.1k
Add support for SDL3 joystick input driver for Android, iOS, visionOS and Web #109645
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
a4474f6
to
4f21671
Compare
4f21671
to
4e9de1a
Compare
Web seems to be extremely buggy:
Android is crashing instantly, in
Will check iOS later. |
Thank you for testing, bruvzg! That's weird, for me on Windows on web I didn't have problems with dpad, face buttons, vibration and input lag with Dualshock 4 (the other problems did happen, I will try to fix them), and I didn't have crashes on Android. May I ask if there's any other information about the Android crash you're experiencing? |
Some extra info:
|
On iOS, linking fails due to following missing symbols:
|
Oh, that's also strange, because the check in this PR for iOS export template passed. |
CI only build a static library, linking is done when project is exported. |
It's crashing on start, tested with "Joypads" demo on Pixel 8 Pro (Android 16) and POCO F3 (LineageOS, Android 15). |
Hm, is there any exception thrown or a JNI error shown? |
Here's full logcat output - https://gist.github.com/bruvzg/9822262842e885170289d40572fc4002 |
I see, thank you! I will try to fix it |
A fix for iOS: diff --git a/drivers/sdl/SCsub b/drivers/sdl/SCsub
index 3cd3761c4b..8bed438fe6 100644
--- a/drivers/sdl/SCsub
+++ b/drivers/sdl/SCsub
@@ -217,6 +217,7 @@ if env["builtin_sdl"]:
thirdparty_sources += [
"core/unix/SDL_appid.c",
"core/unix/SDL_poll.c",
+ "haptic/dummy/SDL_syshaptic.c",
"joystick/apple/SDL_mfijoystick.m",
"thread/pthread/SDL_syscond.c",
"thread/pthread/SDL_sysmutex.c",
diff --git a/drivers/sdl/SDL_build_config_private.h b/drivers/sdl/SDL_build_config_private.h
index 54c60f32a5..512894146e 100644
--- a/drivers/sdl/SDL_build_config_private.h
+++ b/drivers/sdl/SDL_build_config_private.h
@@ -155,6 +155,7 @@
#define HAVE_STDIO_H 1
#define HAVE_LIBC 1
#define SDL_JOYSTICK_MFI 1
+#define SDL_HAPTIC_DUMMY 1
#define SDL_TIMER_UNIX 1
#define SDL_THREAD_PTHREAD 1 With this fix, everything seems to work. |
Thank you! Also, may I ask if the Android crash happened while running the editor build of Godot on your devices or the exported games? I just realized that I only initialize SDL in |
4e9de1a
to
ddf3952
Compare
Exported game, I have not checked the editor. |
Tested Android editor, and most stuff seems to be working. Vibration works with XBox One controller, but not with Dual Sense. |
ddf3952
to
6e8c7d4
Compare
This commit adds support for SDL joystick input for the rest of the platforms Godot Engine supports. Previously it was only available on desktop platforms (Windows, Linux and macOS). This commit also adds joystick vibration feature to the web platform in browsers that support this feature.
6e8c7d4
to
79300b5
Compare
Follow-up to #106218
Closes #47656
Closes #96985
This PR adds support for SDL joystick input for the rest of the platforms Godot Engine supports. Previously it was only available on desktop platforms (Windows, Linux and macOS).
I also decided to refactor
joypad_sdl.cpp
a little bit and add joystick vibration feature to the web platform in this PR :DI have tested this PR on Android and web, I haven't tested it on iOS and visionOS, but judging by how SDL input was integrated on macOS I hope this approach works for iOS and visionOS too.
I haven't made Android use HIDAPI yet (which was used for new joypad features in my other PR: #107967 ), I'm not sure I can, because I'm not an Android developer and it was tiring to make SDL's Android Java code work properly in Godot's build system 😅
(EDIT: It can't be done properly: libsdl-org/SDL@e3cf2e4 https://github.com/libsdl-org/SDL/blob/main/src/hidapi/android/hid.cpp#L1052 )
This PR also fixes 3 issues on Android (tested with my DualShock 4 on the master branch using this script):
1. Trigger axes values were not reset after the user stops pressing on them;
I'm not pressing any buttons on the screenshot:

Relevant issues #79263 #108982
The same situation after my PR:

2. Pressing the left trigger caused the Share button (or JoyButton::BACK) to be pressed as well;
I'm only pressing the left and right triggers on the screenshot:


Pressing Share on the controller didn't trigger anything, but after releasing the left trigger the BACK button stopped being red.
After my PR Godot can properly detect the Share button being pressed:
3. Fingerpring scanners were recognized as joypads.
Relevant issue: #47656


Before my PR:
After my PR:
There's also another Android issue ( #56181 ), but I can't reproduce it on master with my DualShock 4, so I can't test if it was fixed by my PR.
There's another problem, I haven't tested it on master yet but after this PR the joypad triggers are now digital (just 0.0 or 1.0) on web(EDIT: I hope it's now fixed), related SDL issue: libsdl-org/SDL#13051TODO:
SDL_ShouldIgnoreJoystick
to ignore unnecessary gamepads ( Allow Android to ignore unnecessary joysticks (like fingerprint sensors) libsdl-org/SDL#13759 )Input.get_joy_info()
regression after the SDL input driver PR #108214 is merged:Input.get_joy_info()
fields for new platforms