NagyD / SDLPoP

An open-source port of Prince of Persia, based on the disassembly of the DOS version.
GNU General Public License v3.0
1.1k stars 140 forks source link

Register quick key presses update: Fixed dropping of gamepad input and made all of this a toggle #294

Closed FluffyQuack closed 1 year ago

FluffyQuack commented 1 year ago

Update to the previous PR to finish the feature.

dstarosta commented 1 year ago

How come the "joy_axis_max" is only applied to the legacy "SDL_JOYAXISMOTION" event and not the "SDL_CONTROLLERAXISMOTION"?

On a related topic, in legacy joystick mode, which can be tested by setting the "using_sdl_joystick_interface" variable, X and Y buttons are swapped on my controller and conflict with the controller events causing both of them to act like the Y button was pressed. Unless legacy joysticks are different, the values in the "config.h" for the buttons should be swapped. A and B buttons can also be mapped there with values of 0 (A) and 1 (B).

FluffyQuack commented 1 year ago

How come the "joy_axis_max" is only applied to the legacy "SDL_JOYAXISMOTION" event and not the "SDL_CONTROLLERAXISMOTION"?

On a related topic, in legacy joystick mode, which can be tested by setting the "using_sdl_joystick_interface" variable, X and Y buttons are swapped on my controller and conflict with the controller events causing both of them to act like the Y button was pressed. Unless legacy joysticks are different, the values in the "config.h" for the buttons should be swapped. A and B buttons can also be mapped there with values of 0 (A) and 1 (B).

Not setting joy_axis_max during SDL_CONTROLLERAXISMOTION was a mistake. I somehow missed that when working on gamepad/joystick support. I've got that fixed now.

About legacy joysticks, is it possible the current mapping works with some controllers but not others? This reminds me of using DirectInput (I assume that's also the API that's used for "legacy joystick mode" in the Windows build) where you can't know for sure where an axis or button physically exists on the controller, as it varies greatly on the controller. I just tested using my DualSense in SDL-PoP and the left stick works fine for movement, but everything else does nothing or is mapped to awkward buttons.

I think the ideal solution would be to implement a mapping function where the user can define what each button and axis is mapped to.

dstarosta commented 1 year ago

I have done some research. There is a way to map buttons the same way for different controllers in SDL2. This library used to do that. https://github.com/gabomdq/SDL_GameControllerDB There is a text file with mapping and also images of controllers such as Nintendo that have X and Y buttons swapped which explains the issue.

SDL2 does not even need that library. It can load the file from that library (there is even a badly named link to it on the page) with the native method. https://wiki.libsdl.org/SDL_GameControllerAddMappingsFromFile

Once the mappings are correct, the right way to map the buttons in both modes is A=0, B=1, X=2, Y=3.

FluffyQuack commented 1 year ago

I have done some research. There is a way to map buttons the same way for different controllers in SDL2. This library used to do that. https://github.com/gabomdq/SDL_GameControllerDB There is a text file with mapping and also images of controllers such as Nintendo that have X and Y buttons swapped which explains the issue.

SDL2 does not even need that library. It can load the file from that library (there is even a badly named link to it on the page) with the native method. https://wiki.libsdl.org/SDL_GameControllerAddMappingsFromFile

Once the mappings are correct, the right way to map the buttons in both modes is A=0, B=1, X=2, Y=3.

I'm thinking the above might not be necessary. I'm imagining something along the lines of what a lot of emulators or fighting games do, where you have an UI where the program presents you a list of actions, and then you press the button you want to map to that action.

For the heck of it, I programmed a partial implementation of this idea. I imagine something along these lines would be good for getting any controller work. It would also give people the chance to map controls to something else than the default: https://www.youtube.com/watch?v=otow4sBTzA4