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

Gamepad API #393

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Gamepad API #393

wants to merge 2 commits into from

Conversation

albertofustinoni
Copy link
Contributor

@albertofustinoni albertofustinoni commented Sep 28, 2020

Proposal for a sokol gamepad API

@floooh sorry it took this long to get back to you. This is the gamepad API I made and have been using.
The only annoyance is that Android only handles input via events and I had to hook into sokol_app to get it working there - for the other platforms this is standalone.

I kept changes to sokol_app as minimal as I could to get things working.

@prime31
Copy link
Contributor

prime31 commented Oct 4, 2020

This looks great! Really well done. Can’t wait to give it a go.

@Manuzor Manuzor mentioned this pull request Nov 29, 2020
@meshula
Copy link

meshula commented Dec 5, 2020

Hi, I've successfully incorporated your proposed API into my app, but I had to make a few additions to match my use case, which requires detecting whether or not a controller is connected. I've submitted a PR here: Aftnet#1

@Querijn
Copy link

Querijn commented Nov 22, 2021

Darn, was hoping this was something that I could use, but the windows version seems to rely on xinput, which disallows you to use gamepads that aren't xbox controllers.

@meshula
Copy link

meshula commented Nov 23, 2021

I've been looking at this dinput implementation, but haven't had time to move forward yet. https://github.com/Kode/Kinc/blob/d153bf0642e7d56b1fa056f01005e979f0ce6267/Backends/System/Windows/Sources/kinc/backend/system.cpp

My current implementation is here - https://github.com/meshula/LabCamera/blob/main/examples/Navigator/sokol_gamepad.h - it's moved forward compared to the OP, but hasn't got dinput yet.

@Querijn
Copy link

Querijn commented Nov 23, 2021

I've found out that XInput is the best simple approach, which allows just Xbox Controllers to work, and controllers that act like those. But I've also been looking at Raw Input, which is what seems to be what the web Gamepad API is based on.

I've come across a couple of issues while investigating this myself. :

  • On Windows, Raw Input requires access to the message loop to catch WM_INPUT messages. This would mean hooking the WndProc pointer via SetWindowLongPtr
  • The web's gamepad API leaves something to be desired. On Firefox, it decides to just convert every HID control value into an axis, which means the D-Pad is one messed up float for my PS5 controller. Chrome seems to convert these to buttons. The way vendors and products are indicated is also non-standard, whereas Firefox prepends the name with them, and Chrome just states them as human readable values. (Note: All of this comes from https://gamepad-tester.com/, which might have preprocessed the data)

Left Chrome, right Firefox.
image

@floooh
Copy link
Owner

floooh commented Nov 23, 2021

Not sure if it's useful for the discussion, but in Oryol I had a mapping layer over the gamepad input because axis and button indices are not standardized in some APIs. The mapping layer is basically a dictionary of device id strings (or some sort of string pattern?) which maps raw axis and button indices to "semantic" names. Oryol came with builtin mappings for Xbox and PS4 controllers but user code could add additional mappings:

https://github.com/floooh/oryol/tree/master/code/Modules/Input#gamepad-input

(the Windows side also simply used XInput though, IFIR I had ripped the code from GLFW)

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

5 participants