Skip to content

Improve Gamepad / Refactor Input Api #2752

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

Merged
merged 16 commits into from
May 28, 2022

Conversation

Ghabry
Copy link
Member

@Ghabry Ghabry commented Mar 21, 2022

  • 3ds: Add Input buttons
  • 3ds: Fix Analog handling
  • libretro: Fix Analog handling
  • PS Vita: Add input buttons
  • PS Vita: Fix Analog handling
  • Switch: Add Input buttons
  • Switch: Fix Analog handling
  • SDL: Fix Analog handling

This rewrites parts of the input API related to gamepads based on how most Gamepads these days are:

When the initial API was designed it was inspired by SDL Joystick. These use 32 arbitrary keys that and are very low level: You can handle any kind of controller with it.

These days the typical controller is usually:

  • 2x Analog Sticks
  • Every Analog Stick can be pressed down
  • 1x Dpad
  • 4 Buttons (A,B,X,Y)
  • Start, Select
  • 2 Left and 2 Right Triggers (one analog)

This is an assumption made by Microsoft (XInput), SDL2 (Game Controller), HTML5 Gamepad API and libretro (Retropad).

I also removed the keyboard input in libretro. They do not forward all keyboard input anymore except if you are in "Focus Mode" which disables the RetroPad. Libretro wants exclusive access to the keyboard, so I fulfill this wish... Is kinda crap but nothing we can do here.


Changes for SDL1.0:

I kinda hacked this in. We must really drop this :/

  • Invented some constants as is not possible to use the Gamepad constants properly here
  • HAT is mapped to right analog stick
  • This makes it still work for the Wii

New default mapping for Game Controllers to make them usable. (Custom remapping in settings PR)

(Note: Does not work on Linux in Browsers, works everywhere else)

  • Dpad: Directions
  • Left Stick: Directions
  • Right Stick: Numbers matching directions on Numpad
  • Left Stick Pressed: 0
  • Right Stick Pressed: 5
  • A: Decision
  • B: Cancel
  • X: Cancel
  • Y: Shift
  • Left Trigger: Debug Through + Debug Menu (Full press)
  • Right Trigger: Fast Forward x3 + x10 (Full press) (same as "accelerate in racing games" xD)
  • Shoulder Left: Debug event abort
  • Shoulder Right: Toggle FPS
  • Back: Reset
  • Start: Settings Menu (Not used yet)
  • 4 Rear Buttons (Almost no controller, Steamdeck has them): +, -, *, /

@Ghabry Ghabry added Refactor libretro Libretro port related, including RetroArch, RetroPie and related projects Input Input related (gamepads, keyboard mappings, mouse support). For KeyInputProc, add event/interpreter labels Mar 21, 2022
@Ghabry Ghabry added this to the 0.7.1 milestone Mar 21, 2022
@Ghabry
Copy link
Member Author

Ghabry commented Mar 21, 2022

For more flexibility (mapping 1-9 on one stick) maybe could also add diagonal support for the sticks 🤔.

And "semi down trigger" for X3 FF and "full down" for X10 FF 😁

@carstene1ns
Copy link
Member

Looks really good so far! Nice workaround to support wii (uses hat) by emulating joystick.

What is missing yet is a way to rename buttons. Currently we have forced keyboard keys for homebrew platforms (which is wrong, but was easy). Wii is a little better, as it has custom mapping, however still using "joy other 4" as name instead of "Button 2". That will break as soon as we have custom mapping scene. I need this for the custom WiiUI.

@Ghabry
Copy link
Member Author

Ghabry commented Mar 21, 2022

Currently we have forced keyboard keys for homebrew platforms (which is wrong, but was easy)

Yeah that was a lazy solution that must be fixed for the Input Settings scene.

Wii is a little better, as it has custom mapping, however still using "joy other 4" as name instead of "Button 2".

Yeah, this was a quick workaround.

The lack of button renaming is already bad at the PC. When remapping the user will currently see stuff like "JOY_STICK_LEFT_Y_UP" instead of "Joy Left Y+" in the WIP remapping scene.

We need a new data structure, something like:

Array_Of_Struct {
  int8_t key,
  char* internal_name,
  char* readable_name
}

Then on startup a port can overwrite the relevant strings in readable_name.


btw, do you want to have individual mappings for the different Wii-Accessoires or will you make "Minus on Wiimote is same as Minus on CC"?

If you want to support individual could ues the provided JOY things for the Classic Controller (as this is the closest to a controller ^^) and then just 10 OTHER fields for the Wiimote.

When they can be renamed it doesn't really matter that they are called OTHER in code.

@carstene1ns
Copy link
Member

I want to allow using all buttons individually.

@Ghabry Ghabry marked this pull request as draft March 24, 2022 19:45
@Ghabry
Copy link
Member Author

Ghabry commented Apr 5, 2022

I was talking about 8 direction support for the "secondary" analog stick so more numbers can be mapped to it easily.

Here a picture to make my life easier ;)

Values in degrees for atan2(y, x)

a

EDIT: Well and the circle must be rotated a bit to have the right segments so it would be:

  • Right: -22 - 22
  • Up Right: 23 - 67
  • Up: 68 - 112
  • Up Left: 113 - 157
  • Left: > 158 or < -158
  • Down Left: -113 - (-157)
  • Down: -112 - (-68)
  • Down Right: -67 - (-23)

@Ghabry Ghabry force-pushed the input-controller branch 2 times, most recently from 62ca99b to 4996772 Compare April 5, 2022 18:48
@Ghabry
Copy link
Member Author

Ghabry commented Apr 5, 2022

As asked by carstene1ns added a stub-api for adding platform specific names that can be queried by the Input Scene:

Example usage (in PLATFORM_input_buttons.cpp):

Input::ButtonNamesArray Input::GetInputKeyNames() {
	return {
		{Keys::JOY_DPAD_DOWN, "Dpad Down"},
		{Keys::JOY_A, "Classic Controller A"},
		{Keys::JOY_Z, "Nunchuck Z"},
		{Keys::JOY_TRIGGER_RIGHT_FULL, "Right Trigger Down"},
		{Keys::JOY_OTHER_10, "Balance Board Left"},
		{Keys::JOY_OTHER_20, "Bongo Right"}
	};
}

@Ghabry Ghabry force-pushed the input-controller branch from 4996772 to 8fec8c2 Compare May 7, 2022 13:57
@Ghabry
Copy link
Member Author

Ghabry commented May 7, 2022

Wow this was a suuuuper boring task. Moved now all our ports to use a dedicated "Input buttons" instead of depending on input_buttons_desktop.

Also attempted to add suitable input layouts based on the desktop gamepad layout.

Likely broken and has tons of compile errors. Not tested yet but at least the boring part is done...

@Ghabry Ghabry force-pushed the input-controller branch 2 times, most recently from 398f1fe to 0a846d2 Compare May 7, 2022 14:53
@Ghabry
Copy link
Member Author

Ghabry commented May 8, 2022

Hm this will be hard to test on most ports. There is also other breakage it seems:

  • 3ds build throws an assert in AudioSeCache (must be older, not by this build)
  • Vita3k freezes with "No device for ."
  • Wii build has now completely borked input :/
  • Yuzu does not run on my device anymore (too old?)

@Ghabry
Copy link
Member Author

Ghabry commented May 8, 2022

Small test case (Input test on the village)

input.zip

Grab the last working PR build for the system from Jenkins.

For Vita please test:

  • Touch buttons are all properly detected (Logo is cancel)
  • D-Pad and left stick for walk
  • Right stick (all axis incl diag) for 1-9 without 5 (that would be press stick down, not possible on Vita)
  • Other buttons according to psp2_input_buttons.cpp file

For Switch please test:

  • Touch buttons are all properly detected (Logo is cancel)
  • D-Pad and left stick for walk
  • Pressing Left stick is 0
  • Pressing Right stick is 5
  • Right stick (all axis incl diag) for 1-9
  • Other buttons according to switch_input_buttons.cpp file

@Ghabry
Copy link
Member Author

Ghabry commented May 8, 2022

Should now work everywhere, except:

  • Untested: Vita (no working emulator available)
  • Wii: Semi-broken. sdl_wii has weird button mappings not matching with wiibrew. carstene1ns will replace this with a wii_ui. Then SDL1 can be removed completely.

@Ghabry Ghabry force-pushed the input-controller branch 3 times, most recently from 15f265b to 76ed97d Compare May 25, 2022 17:59
@Ghabry Ghabry marked this pull request as ready for review May 25, 2022 18:02
@Ghabry
Copy link
Member Author

Ghabry commented May 25, 2022

This is now ready.

The Semi-broken Wii input is already a problem in master and some ports have additional features on the shoulder triggers. I will move them to the config scene in the next PR.

@Ghabry Ghabry force-pushed the input-controller branch from 76ed97d to 424191a Compare May 25, 2022 18:12
Ghabry added 3 commits May 27, 2022 17:10
… layouts

JOY_HAT was removed as this is untypical for controller input (and not supported by SDL GameController API)
Ghabry added 13 commits May 27, 2022 17:10
…keys as callbacks making this unusable and confusing.
…ondary

Motivation here is to provide an option to swap which joystick is for movement, so left/right terminology is confusing.
…ys based on them.

This reduces code duplication and makes the code less error prone.
Redid button mapping again now that more buttons are available.
…sktop

Likely partially broken and has some FIXME depending on the settings scene.
Fix Cross and Circle mapping
@Ghabry Ghabry force-pushed the input-controller branch from 424191a to 4ae48f6 Compare May 27, 2022 15:10
Copy link
Member

@carstene1ns carstene1ns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@@ -120,6 +116,13 @@ CtrUi::CtrUi(int width, int height, const Game_ConfigVideo& cfg) : BaseUi(cfg)
top_image.tex = tex;
top_image.subtex = &subt3x;

// FIXME: Add option to settings Ui
if (cfg.stretch_width.Get()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has nearly no effect, since you disable stretching in UpdateDisplay().
The idea here was to handle this like fullscreen for other platforms. So, no real need for config option here. Same is true for switch and vita, where you only made this a FIXME without option.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this change makes no sense currently because there must be a function for toggling this. This is similiar to a "keep aspect ratio" setting. Could be even provided for SDL2 in case somebody likes it to have everything stretched... (that's why it is not the same as fullscreen)

Wanted to finish this as part of the Settings PR as I cannot do it in this PR properly (And breaking that feature for a while isn't toooo bad)

@carstene1ns
Copy link
Member

The only problem I have with it is that it completely breaks Wii input.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Input Input related (gamepads, keyboard mappings, mouse support). For KeyInputProc, add event/interpreter libretro Libretro port related, including RetroArch, RetroPie and related projects Refactor
Development

Successfully merging this pull request may close these issues.

3 participants