floooh / sokol

minimal cross-platform standalone C headers
https://floooh.github.io/sokol-html5
zlib License
6.54k stars 469 forks source link

sokol_app Gamepads #200

Open alex-rass-88 opened 4 years ago

alex-rass-88 commented 4 years ago

Will there be gamepad support? It would be nice to support gamepads on desktop platforms.

floooh commented 4 years ago

Gamepad support is not planned for sokol_app.h, but there will most likely be a separate header at some point (I need this for my 8-bit emulators too). The API will probably be similar to the Oryol gamepad functions:

https://github.com/floooh/oryol/blob/043683dcb3181beb64ae1c85ea76e4a4eb71c124/code/Modules/Input/Input.h#L78-L105

alex-rass-88 commented 4 years ago

I'll try to write myself. Then add to the collection of sokol libraries.

floooh commented 4 years ago

That's fine, but note that I haven't made up my mind whether it makes sense for me to accept PRs for entirely new headers, that may result in too much work for reviewing and discussing the API and code. So please don't be upset when you're doing all the work and I'm not accepting the PR :)

TheSpydog commented 4 years ago

I'm curious why you don't plan to support gamepads in the sokol_app header? Especially since it already supports mouse/keyboard/touch input, it seems like game controllers would belong there too. :)

floooh commented 4 years ago

@TheSpydog it basically depends on how closely the gamepad code is to the window system glue code (e.g. if a platforms needs a window handle to obtain gamepad status it would make sense to put it into sokol_app.h, otherwise not).

When I tinkered with gamepad support in Oryol, that was surprisingly complicated, because of "raw buttons" versus "mapped buttons". There isn't agreement between gamepads between button and axis indices (so "button 0" on one gamepad might be an entirely different button than "button 0" on another gamepad). So some sort of of gamepad-specific mapping is required which makes the API around gamepads non-trivial, unless only a handful standard gamepads should be supported (like PS4 and Xbox gamepads). So basically because a gamepad API would have to be more complex than just "GetButton(int index)" and "GetAxis(int index)" I think a separate header would make more sense.

MikeHart66 commented 3 years ago

Hi Floooh, any progress on this?

floooh commented 3 years ago

Nope, next feature on my list is pointer-lock / mouse-capture in sokol_app.h.

Maybe something like Gainput (http://gainput.johanneskuhlmann.de/) could help out in the meantime?

MikeHart66 commented 3 years ago

Yes, I saw that but was concerned that there was not update since 2018. Will give it a try.

Edit: I think I will pass. Saw the issues list and no activity from the author.

nephewtom commented 2 years ago

It is a shame... It would be great to play your pacmac clone with gamepad. Sokol rocks!

roig commented 1 month ago

This is the only thing I miss from SDL2 when I changed to sokol. Gamepad support. The rest was perfect, PERFECT. Sokol rules.

void256 commented 6 days ago

What we all could use in the meantime is this lib: https://github.com/ThemsAllTook/libstem_gamepad (Gamepad C API wrapper for OS X, Windows, and Linux).

I just spend a couple of days with it and it works just great! It has a straightforward and IMHO very nice minimal Gamepad API. (I only tested it on macOS so far but I assume that Linux and Windows work equally good).

It does not do any mapping of buttons and axis so you only get the raw data (basically everything what floooh mentioned above). So you need to do some kind of "I know this specific vendor and product id and axis 0 on this device is the left analog stick horizontal movement" but it's not too bad to add that on your own or add some kind of UI for people to add their own controllers.

From an API perspective it matches Sokol quite nicely. It would be nice to have it as a header only version tho. I guess it could be made into one but for now I'm fine of linking statically with it.

Sokol indeed rocks very hard! Lots of Kudos to master floooh for creating it! 🙇‍♂️