pygame-community / pygame-ce

🐍🎮 pygame - Community Edition is a FOSS Python library for multimedia applications (like games). Built on top of the excellent SDL library.
https://pyga.me
933 stars 155 forks source link

Smart default mapping for controller #3088

Open bilhox opened 2 months ago

bilhox commented 2 months ago

Hello,

While playing with _sdl2.controller, I found that for all controllers I had, default mapping was wrong. Okay, we propose a way for users to set their mapping, but wouldn't be ideal for the comfort of users to propose smart default mapping that matches the button/axis constants proposed by the controller module ?

What I can propose is to do like some people in the SDL community do, keeping a database of the most used controllers in the world with their default mapping.

What do you think ?

damusss commented 2 months ago

why not, yeah. maybe enabled by some flag

Starbuck5 commented 2 months ago

Wdym it was wrong? Isn’t the whole point of SDLs controller system to map everything to be like an Xbox controller?

bilhox commented 2 months ago

Wdym it was wrong? Isn’t the whole point of SDLs controller system to map everything to be like an Xbox controller?

Yes! Sorry for the misunderstanding also, I thought it would also take in account controllers like SNES Controller which looks like this : image

It just doesn't have sticks and shoulders button/trigger.

The button A and B are inverted on my nintendo joycons as well. (when they are combined*) (zoldalma inverted the 2 buttons in his test code)

bilhox commented 2 months ago

Someone shared me this on the SDL discord, it might be worth taking a look at it : https://github.com/mdqinc/SDL_GameControllerDB/tree/master

zoldalma999 commented 1 month ago

While playing with _sdl2.controller, I found that for all controllers I had, default mapping was wrong. Okay, we propose a way for users to set their mapping, but wouldn't be ideal for the comfort of users to propose smart default mapping that matches the button/axis constants proposed by the controller module ?

That is the point of the SDL_Controller (or SDL_Gamepad in sdl3) module. We should not need to keep our own database of controller layouts. It should just work. And if it does not, we make a PR to sdl.

With that said, we could vendor in the one you linked (https://github.com/mdqinc/SDL_GameControllerDB/tree/master). Or mention it in the docs.

bilhox commented 1 month ago

Looks like SDL has a function for loading mappings from a file, could be interesting to implement it. (Which would close this issue)

JiffyRob commented 2 weeks ago

I actually requested that the mapping adding function be bound in the contributing discord. My use case is that I have a USB gamepad that I found buried in a closet that looks like a PS2 controller but doesn't register as an SDL2 controller. I'd like to be able to test using it.