GameController configuration

Hi everyone,

I’ve been poking at SDL2 basically as a means to blow off some steam, and I got to looking at the game controller API. If you haven’t played with this yet, it basically gives you clean access to an XBox360 style controller. Since Microsoft has decreed this the standard controller for Windows, and the DualShock-style controllers have effectively the same layout, it effectively is a good one.

The issue is controller support and mapping.

  1. SDL cannot reasonably contain every controller mapping of the past, present, and future, and having to recompile SDL to update the list isn’t going to hold up.
  2. GameController GUIDs are not unique, and it’s accidental at best that two such devices share the same button mapping.
  3. Running Steam, reading machine-generated config files, and setting environment variables only documented in the SDL source code is hardly a solution to these problems. :wink:

What we need is a way to configure a GameController given an arbitrary Joystick that works using SDL. I mentioned this to Sam this weekend, and he commented that this problem was just discussed at Valve quite recently. It’s a deceptively deceptively simple problem to solve. That is, it seems deceptively simple, but isn’t. :slight_smile:

If your Joystick is not recognized, it’s easy enough. Just use SDL’s joystick interface, tell the user to press each button in sequence, produce the appropriate mapping string at the end. That duplicates a small amount of SDL’s internal code, but nothing major, and it’d be sufficient to throw into the tests folder.

But I’ve always viewed the tests folder as demonstrations of how to do simple things and hopefully do them correctly. There’s enough examples of how NOT to do it for beginners to copy without understanding as it is. :wink:

Doing it right probably requires reading any existing GameController config and either parsing it (duplicates a lot of SDL functionality) exposing some SDL internals. Then proceed as above, having the user enter bindings for each button and axis. The difference is you can’t just run through the list once, because you’re going to have to check for conflicts. That means at least a loop until all functions are bound or any remaining cannot be (Guide button in my case) or, more ideally, a menu.


Seems like the next step is probably for me to produce something that works, duplicating or exposing what I have to, and post it for you all to ponder. :slight_smile: But I figured I’d seek input before I take up my sword and embark upon this dangerous quest to save the world with a party of unlikely adventurers with an average age of 17. Oh wait, that’s something else. :slight_smile: