The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
Default mapping for controllers (SDL_GameControllerOpen)
AntTheAlchemist


Joined: 13 Feb 2015
Posts: 60
Location: UK
Is there any way to set default mapping for a joystick that doesn't have one?

Presently SDL_GameControllerOpen() returns NULL and errors if !SDL_IsGameController(), so one has to use SDL_JoystickOpen() instead.

If we are to handle both SDL_Joystick, and SDL_GameController we need to double-up the code because they each come with their own set of events and functions.

If there was a default map for SDL_GameControllerOpen so that it never fails, we could use one set of code to handle all joysticks universally.

Thoughts?
A Shot in the Dark
trevor.shawn.williams


Joined: 07 Nov 2014
Posts: 6
Haven't run into this problem myself - I have one controller and it's an XBox 360 PC USB model - but since no one has come up with a solution for you yet, I'll give this a shot.

Checkout the SDL2-2.0.3 SDL_gamecontroller.h header file. Specifically, lines 86 - 148. There's a multi-line comment with example code on lines 86 - 110 that explains creating mappings for controllers SDL is unaware of. The rest is a collection of Macros and functions that may be used to actually do it. Don't miss the part about settings hints in the comment. Also, if SDL_IsGameController is throwing errors, it's not exactly mandatory to call it. You can probably work around that crash(?) just by skipping that step. Since you're 100% certain what you have is a controller, you don't need the system to tell you it's a controller. You can probably get away with telling it the device is a controller.

Best of luck.