Gamecontroller API questions

Hello. I am porting my code to use SDL2 and I of course want to use the Gamecontroller API. I have some questions about how to use this. I think i’ve kinda figured out some of these answers but I just wanted to get a solid yes/no. My questions:

  1. I notice that Hats and Balls are both gone in the Gamecontroller interface. I notice that Hats have been merged into Buttons. What about balls? Does Gamecontroller simply not support controllers with trackballs?

  2. What happens if I call SDL_GameControllerOpen on a joystick for which SDL_IsGameController is false? Does it return NULL?

  3. For which gamepads is SDL_IsGameController false? I assume SDL_IsGameController is true iff the controller does not have a loaded binding?

  4. Is it safe and acceptable to call SDL_JoystickOpen and SDL_GameControllerOpen on a single joystick ID at the same time?

  5. What is the meaning of the Game Controller “string” for axis and button? I suppose the idea is the string is “whatever it says in the mappings file”. However, the “recommended” gamecontrollerdb.txt on the wiki seems to have consistent and specific values for all buttons. Strings like “dpdown” and “rightshoulder” show up consistently. Are these strings standardized? Are they documented somewhere? They all seem to kind of make sense just from the names (x is a face button, rightx is the right analog stick, “guide” is the ps3 logo button… “back” is select?) but it would be nice to have an explicit list (as is one simply has to guess which face buttons a,b,x,y correspond to).

5a. Would I be correct to surmise that gamecontrollerdb.txt corresponds to the XBox 360 controller buttons and nothing else? Right and left analog stick depress are not meant to be represented? Fighting sticks are not meant to be represented?

  1. Who maintains this mysterious “community sourced” gamecontrollerdb.txt linked on the wiki ( https://wiki.libsdl.org/SDL_GameControllerAddMappingsFromFile?highlight=(\bCategoryGameController\b)|(CategoryEnum) )? Do they take pull requests?

  2. The “strings” in gamecontrollerdb.txt all seem to be semantic-- “Y” means (again assuming these are 360 buttons) “top” diamond. However if I present a UI, I will want to at some point describe the buttons to the player using the actual symbols they see on the gamepad, like “Triangle” if it’s a PS3 controller. Am I correct this “human-readable name” information is not tracked by SDL2 at all? Has there been any community attempt to gather such information?

  3. Would I be correct to assume that the “device index” used for any one device (used by e.g. SDL_JoystickOpen) could potentially change anytime a joystick is plugged in or removed?

  4. Is “device index” the same thing as “instance ID”? The doc for SDL_JoyDeviceEvent ( https://wiki.libsdl.org/SDL_JoyDeviceEvent?highlight=(\bCategoryStruct\b)|(SDLStructTemplate) ) implies they are two things (“the joystick device index for the SDL_JOYDEVICEADDED event or the instance id for the SDL_JOYDEVICEREMOVED event”) but the doc for SDL_JoystickInstanceID seems to use the two terms interchangeably.

  5. If I have opened a joystick, and then I open the same joystick again, will it return a new SDL_Joystick object or return the previously allocated SDL_Joystick object?

  6. If I have opened a joystick, and I receive a corresponding SDL_JOYDEVICEREMOVED, am I obligated to call SDL_JoystickClose or will this be done for me?

mcc wrote:

  1. For which gamepads is SDL_IsGameController false? I assume SDL_IsGameController is true iff the controller does not have a loaded binding?

Yes

mcc wrote:

  1. What is the meaning of the Game Controller “string” for axis and button? I suppose the idea is the string is “whatever it says in the mappings file”. However, the “recommended” gamecontrollerdb.txt on the wiki seems to have consistent and specific values for all buttons. Strings like “dpdown” and “rightshoulder” show up consistently. Are these strings standardized? Are they documented somewhere? They all seem to kind of make sense just from the names (x is a face button, rightx is the right analog stick, “guide” is the ps3 logo button… “back” is select?) but it would be nice to have an explicit list (as is one simply has to guess which face buttons a,b,x,y correspond to).

5a. Would I be correct to surmise that gamecontrollerdb.txt corresponds to the XBox 360 controller buttons and nothing else? Right and left analog stick depress are not meant to be represented? Fighting sticks are not meant to be represented?

The GameController API Assumes a Xbox 360 controller layout and maps other controllers to its corresponding buttons.
Other layouts should use the joystick api.
Nothing prevents the user from mapping any usable controller using Steam, though…

mcc wrote:

  1. The “strings” in gamecontrollerdb.txt all seem to be semantic-- “Y” means (again assuming these are 360 buttons) “top” diamond. However if I present a UI, I will want to at some point describe the buttons to the player using the actual symbols they see on the gamepad, like “Triangle” if it’s a PS3 controller. Am I correct this “human-readable name” information is not tracked by SDL2 at all? Has there been any community attempt to gather such information?

I never saw anyone doing anything like that in the community.
This bothers me a bit, I want to create a “button prompt database” someday, with button images, etc. someday…
Putting readable labels for controllers would work too.

Are you interested in working on something like that?

mcc wrote:

  1. Would I be correct to assume that the “device index” used for any one device (used by e.g. SDL_JoystickOpen) could potentially change anytime a joystick is plugged in or removed?

Yes! It changes sometimes. Always get it after openning.

mcc wrote:

  1. Is “device index” the same thing as “instance ID”? The doc for SDL_JoyDeviceEvent ( https://wiki.libsdl.org/SDL_JoyDeviceEvent?highlight=(\bCategoryStruct\b)|(SDLStructTemplate) ) implies they are two things (“the joystick device index for the SDL_JOYDEVICEADDED event or the instance id for the SDL_JOYDEVICEREMOVED event”) but the doc for SDL_JoystickInstanceID seems to use the two terms interchangeably.

  2. If I have opened a joystick, and I receive a corresponding SDL_JOYDEVICEREMOVED, am I obligated to call SDL_JoystickClose or will this be done for me?

Always keep the instance id and use it to close the joystick when SDL_JOYDEVICEREMOVED arrives.

And yeah, this device index/instance id is confusing, and the “which” field in joystick events means different things in some events to add in the confusion.

I hope I was helpful------------------------
Rodrigo Cardoso Rocha
@RodrigoRodrigoR - twitter.com/RodrigoRodrigoR
Chibata Creations - chibatacreations.com