Skip to content
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

Android: improved default mappings for controller axis input #23

Merged
merged 3 commits into from
Aug 4, 2022

Conversation

00-Evan
Copy link
Contributor

@00-Evan 00-Evan commented Aug 1, 2022

While this isn't a complete replacement to the 'prompt the user to map their controller manually' advice, I've made some adjustments to axis logic that should allow for Android controllers to work with the default mapping in a bunch more cases. These changes are based on Android's guide for handling controller actions: https://developer.android.com/training/game-controllers/controller-input.html#button

  • now tries to ensure that AXIS_X, AXIS_Y, AXIS_R, and AXIS_RZ are mapped to ids 0,1,2, and 3 regardless of where they appear in the motion range list. This ensures consistency with iOS and Desktop in most cases.
  • identifies if the L2 and R2 buttons are using an axis, and automatically maps them to button inputs just like it already does with the POV axis. If they do have an axis then the buttons themselves are ignored

On my Android 11 device this totally fixed default mapping issues for a PS4 and Xbox One controller. A Switch pro controller already worked before and after. Lastly there were improvements with a PS5 controller and a 3rd party Switch controller, but button mappings were still wrong. The button mappings apparently are an Android 11 issue which is fixed in 12 though: https://stackoverflow.com/questions/68190869/dualshock-5-and-android

This should probably be considered a breaking change, as existing customized mappings might be incorrect with these axis changes.

@MrStahlfelge
Copy link
Member

Can you add a configuration flag for the new behaviour? This way we won't have a problem with existing persisted mappings.
But only if the code won't get too ugly 😉

@00-Evan
Copy link
Contributor Author

00-Evan commented Aug 1, 2022

Sure, shouldn't be too cumbersome, though some of the if-statements will get a little long. I'll see if there are some ways to make the code in AndroidController() a bit neater.

Would you like it to be a static boolean in AndroidControllers, like ignoreNoGamepadButtons? I might call it useNewAxisLogic. Perhaps have it default to true as well, as I imagine any new application would want it, and the flag would mean old applications could easily keep the old logic.

@MrStahlfelge
Copy link
Member

Would you like it to be a static boolean in AndroidControllers, like ignoreNoGamepadButtons? I might call it useNewAxisLogic. Perhaps have it default to true as well,

That are good suggestions!

@00-Evan
Copy link
Contributor Author

00-Evan commented Aug 1, 2022

There we go, I've added the flag and switched to using arraylist while setting up AndroidController before its converted to an array.

Sorry for the extra commit (forgot about int vs Integer), maybe squash the commits before merging if you want.

@MrStahlfelge MrStahlfelge merged commit 4de5d14 into libgdx:master Aug 4, 2022
@MrStahlfelge
Copy link
Member

Done, let me know when your test players confirm everything's working well.

@00-Evan
Copy link
Contributor Author

00-Evan commented Aug 18, 2022

Based on comments at 00-Evan/shattered-pixel-dungeon#1034 , this PR does resolve axis input errors, but there are still button mapping issues. I might look into that and see if there's anything that can be done to automatically improve that too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants