Hello, everyone!
Everyone who ever dealt with gamepad input, probably knows how hard it is. Gamepads are extremely inconsistent - even the same device can work inconsistenly on different systems.
Currently, we have sf::Joystick, which is not easy to deal with, when you try to support different gamepads. Not only axes and buttons get identified differently - even the direction of axes is hard to predict.
For example, we have
this issue which is causes by gamepad drivers. But what if we could hide all that inconsistency behind a pretty interface?
Here's what SDL does. It has a Gamepad interface built on top of Joystick interface. It allows users to get a wide range of gamepads working without hardcoding everything manually. It allows them to get "Left stick" state, instead of "X" axis state. It allows them to get "A" button, instead of "button 0". ("A" button is "Cross" on Playstation-style gamepads, usually). Another solution would be to call "ABXY" buttons as "North, West, South, East" buttons, to support gamepads which have "A" and "B" (also "X" and "Y") switched.
This works by storing a community-driven database of gamepads and how they work on different systems. We can do the same too!
The interface can look like this, for example:
bool isPressed = sf::Gamepad::isButtonPressed(gamepadId, sf::Gamepad::Button::A);
float pos = sf::Gamepad::getAxisPosition(gamepadId, sf::Gamepad::Axis::LeftStick);
Won't it be wonderful to have?
So, here's what I'm proposing. Let's build a Gamepad interface on top of Joystick interface. We won't deprecate any current behaviour by this. We'll just add a nice interface for developers to use. I think we can agree, that most people want "Joystick" mostly for gamepads, not for steering wheels or, well, joysticks.
I think that I'll be able to provide Windows and Linux implementation if everything is agreed upon. There'll be need for Mac OS X and Android/iOS implementations, as they treat gamepads differently too.
Some things to consider as well:
* XInput. SDL supports XInput, and we can have it too. There are currently a bunch of gamepads supporting it, not just an Xbox 360 one. We need it for letting the developers properly use it with gamepad triggers (right now they are one axis in SFML).
This was a huge deal-breaker for some professional developers that I know. They went to SDL, because SFML couldn't handle this properly. We don't want to lose developers like this.
XInput will also allow us to make gamepad vibration (force feedback) available.
* D-pad should be interpreted as 4 buttons, even though drivers usually have them as axes.
* SDL Gamepad DB. It's huge. We need to ask SDL devs if it's okay to reuse it for SFML and see if it can be used at all. Yes, we may create our own database from scratch. But Valve has a lot more resources to get all the info about gamepads, and this is shown by the huge db that was partly made using help of Steam users.