Fix gamepads weirdness by remapping to Xbox-like layout in lwjgl3 backend #2579
+351
−95
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
JME already does some remapping to make sense of different gamepad layouts. However, this isn't always enough: mappings can be broken by the driver itself or differ across platforms.
This PR addresses that by implementing input handling via
GLFWGamepadState.When a controller is recognized by GLFW,
GLFWGamepadStateautomatically remaps it to an Xbox-like layout. If the controller isn't recognized, the code falls back to the previous behavior (raw mapping + JME's own remapping).This behavior is controlled by two new
AppSettings:TriggerToButtonThreshold: how much you need to press an analog trigger to fire a button press (-1 disable, default 0.5)XboxLikeControllerLayout: if false: never use GLFWGamepadState (default true)To avoid breaking existing code, I also added an extra remapping layer so the new inputs match the layout used by
TestJoystick.Finally, I added Xbox-named aliases to both
JoystickAxisandJoystickButton, making bindings more intuitive going forward.Tested on
Needs more testing with different platforms and controllers
Rumble
Rumble still doesn't work because GLFW doesn't support it. I explored a few workarounds, and the most promising option is to switch to SDL for input (which includes haptics). SDL support should be available via LWJGL 3.4 once that release is stable.