SDL icon indicating copy to clipboard operation
SDL copied to clipboard

gdk: GameInput Joystick backend

Open nkrapivin opened this issue 2 years ago • 3 comments

The recommended gamepad API to use on GDK is GameInput, although Microsoft do provide a wrapper XInputOnGameInput, it's still a wrapper, SDL should be able to handle GameInput natively.

Description

This is an implementation of the joystick backend through native GameInput, currently it only supports Gamepad-like or Controller-like devices.

If the device's family is reported as Xbox360 or XboxOne then it mimics the xinputjoystick backend and provides a built-in mapping, allowing it to act as a drop-in replacement for xinputjoystick most of the time.

I'm free to any suggestions because currently this backend is a bit messy and I'd like to improve it.

The GameInput docs are public, no partner access is required: https://learn.microsoft.com/en-us/gaming/gdk/_content/gc/input/overviews/input-overview

Existing Issue(s)

nkrapivin avatar May 20 '23 22:05 nkrapivin

Fixed the PR for SDL3.

nkrapivin avatar May 28 '23 13:05 nkrapivin

Can you squash for review? Thanks!

slouken avatar May 28 '23 17:05 slouken

I'm currently thinking about whether to implement GameInput mouse, keyboard & touch support as well. Are there any GDKX developers that want this stuff in SDL for GDK and can test that?

nkrapivin avatar May 29 '23 15:05 nkrapivin

We're going to need GameInput for our upcoming game, so if this could make it into the 2.30.0 release it would be much appreciated! 🙏

RustyMoyher avatar Jan 23 '24 14:01 RustyMoyher

We're about to ship 2.30, and this hasn't had any cleanup or testing, but we can add this to the 2.32 milestone.

@nkrapivin, can you please squash this PR for review, and resolve conflicts?

slouken avatar Jan 23 '24 15:01 slouken

Hi @RustyMoyher ,

I'm very sorry about that. I have some errands here and there, what parts of GameInput do you want implemented?

Right now I only have the GameController backend which should work fine, the keyboard & mouse backends are not implemented however, and you're supposed to use the UI TextInput code (which was merged a long time ago) on Xbox anyway.

- Nikita Krapivin, Valkyrie Initiative LLP.

nkrapivin avatar Jan 23 '24 16:01 nkrapivin

Hi @nkrapivin

No worries! We only need the GameController backend.

RustyMoyher avatar Jan 23 '24 16:01 RustyMoyher

Okie! Then I'll finish up the GameController backend, expect weird and quirky force pushes today-tomorrow...

nkrapivin avatar Jan 23 '24 16:01 nkrapivin

When you're done, please squash the changes for review. You can do that by running git rebase -i origin and then choosing f for all commits except the first one.

slouken avatar Jan 23 '24 16:01 slouken

There's a current problem with the backend is that I don't know how to implement the mappings (like SDL-switch has a hardcoded mapping string). I tried to simulate the "new" XInput backend as much as possible so it should be similar, but I don't know how to make such a string.

nkrapivin avatar Jan 24 '24 20:01 nkrapivin

Does the implementation need to be C++? Normally we've left everything C unless it specifically needs to be C++ for platform reasons.

slouken avatar Jan 24 '24 20:01 slouken

Does the implementation need to be C++? Normally we've left everything C unless it specifically needs to be C++ for platform reasons.

Most GDK headers require at least C++11, technically GameInput doesn't have that check but GDK does imply C++. (For example XUser and it's device association API does require C++11, and a game will probably use this to associate players <-> gamepads, which is why devicePath is set to the APP_LOCAL_DEVICE_ID)

nkrapivin avatar Jan 24 '24 20:01 nkrapivin

I'll go ahead and merge this and we can address the feedback from @chrism-MSFT via followup commits.

Thanks!

slouken avatar Feb 17 '24 19:02 slouken

This has been merged and I've updated it with the feedback from @chrism-MSFT.

slouken avatar Feb 18 '24 06:02 slouken