Gamepad mappings and SDL_GameControllerDB

The current gamepad mapping system (based on SDL_GameControllerDB) expresses everything in terms of the buttons of an XBox controller. In my opinion that is not fit-for-purpose, as not all controllers are congruent to XBox controllers.

Wouldn’t it be so much better for the mapping system to be able to differentiate between at least the major players, saying “this is XBox-like”, “this is DualShock-like”, or “this is Nintendo-like”, and exposing the appropriate button labels?

I want my program to be able to automatically choose between “Press Triangle” and “Press Y” when displaying a prompt to the user according to what type of controller they are using. Unless I’m missing something obvious, there’s currently no way to do that without asking the user what type of controller they have on startup.

How does anyone else handle this? Thoughts?

The gamepad input mappings represent a simple way for developers to pre-configure their action to controller mappings, based on the SDL_GameControllerDB database.

The database is queried using an SDL compatible GUID, which you can query using glfwGetJoystickGUID. If you want to create your own mappings to different gamepad types then you can use this to match to your gamepad type, for example the Sony DualShock 4 V2 on Mac OS X is 030000004c050000cc09000000000000:

These mappings are based of the generic Joystick Input and you can also query the Joystick Name to get the name, or use glfwGetGamePadName which returns the name from the SDL gamepad list - both these names may depend on the OS as SDL database has different names for the same controller GUID on different platforms.

So I think there’s enough information available to the developer using GLFW to create a mapping table of their own, and to detect if a controller is ‘XBox-like’, ‘Nintendo-like’, or ‘DualShock-like’ etc. The biggest problem is that you may need access to controllers to perfect the mappings, which is why the SDL database was crowdsourced.

I guess I’ll be making a database of button labels then… perhaps in a few years when/if it becomes a higher priority!

Fortunately it should be possible to find out most controllers’ button labels through Google DuckDuckGo rather than having to buy them all. :wink:

It just seems such wasted opportunity that the de-facto SDL standard didn’t include fields for button labels as well as mappings. It wouldn’t have been too hard to add an extra field or two to indicate each button’s colour and label, e.g. a:b1:g:A (green, labelled with ‘A’), b:b2:r:Square (red, labelled with Square).

It might be worth getting in touch with the SDL_GameControllerDB maintainers and asking about this, they might be willing to help.

A database of these controller buttons (name, colour) would be useful, and it should be possible to write a simple library to handle the information which developers could use on top of GLFW or SDL.

1 Like