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

Joystick mapping support for MacOS using SDL2 #175

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ScrelliCopter
Copy link

This PR adds the ability to map joystick inputs on MacOS by adding an SDL2 backend to match Mednafen.

The base implementation uses SDL_Joystick like Mednafen does but I also have a somewhat experimental path that opportunistically uses SDL_GameController when a mapping is available, this is mainly to work around having no real way to identify triggers and as a side benefit mappings can trivially have nice names that adapt to whichever controller type the gamecontroller subsystem identifies.
In spite of that the gamecontroller path is relatively complex due to having to parse the mapping manually (all of the real functionality for exploring mappings is all private) and also currently makes a few assumptions such as the polarity of the triggers and devices marked as mapped not having more buttons and/or axes than gamecontroller can express.

A better option with SDL_Joystick may be to store initial axis positions when the user starts mapping and deduce triggers and polarity from there. Currently there is no hook as far as I can tell for a joystick impl to know when the user begins mapping and I didn't look into hacking one in, OTOH SDL_JoystickGetAxisInitialState is unreliable because it just records the state of axes on launch and when the user starts the program accidentally depressing a trigger or twiddling a stick they're going to be in for a nasty surprise.

This has been tested on Mac with a handful of different PS and Xbox controllers and they all seem to be mappable, the code should work on other Unix though it wouldn't be useful on platforms like Linux that already have a provider. I'd appreciate all the testing this can get though especially with more exotic controllers than I have access to.

@AmatCoder
Copy link
Owner

Wow thanks for this!

I barely have time for this project but I try to review it.
Also this could be useful for BSD distributions!

@AmatCoder AmatCoder self-assigned this Apr 14, 2024
@AmatCoder AmatCoder self-requested a review April 14, 2024 09:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants