BraveSirAndrew's picture

Gamepad button mappings are wrong when using SDL

Hi there

I've recently switched our engine over to use SDL2 instead of the default windows platform layer and now gamepad mappings, at least on an Xbox 360 wired PC controller, are all sorts of wacky:) I know there's a long history of quirky gamepad mappings when using SDL2, but I couldn't find anything concrete online about this particular problem. I have the mappings back working now but I had to run the testgamecontroller sample in the native SDL2 library and pull out the mappings that were generated in there and replace the default mappings in GamePadConfigurationDatabase with those. So instead of

00000000000000000000000000000000,X360 Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,

I now have

00000000000000000000000000000000,X360 Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b10,leftshoulder:b4,leftstick:b8,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b9,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,

I also had to add the following code to GamePadConfiguration so that it would parse hat info (I know hats are an inconsistent pain in the nuts but I just wanted to try and get this working):

private static JoystickButton ParseHat(string item)
  JoystickButton button = JoystickButton.Button0;
  if(item.IndexOf('.') == -1)
    throw new InvalidOperationException(string.Format("[Input] Invalid Gamepad mapping configuration value: {0}", item));
  int id = Int32.Parse(item.Substring(item.IndexOf('.') + 1));
  return button + id;

This has solved things for now but I guess I'd like to know if anyone knows why the default mappings don't work? Incidentally, the GUID that the native library was returning for my gamepad (through SDL_JoystickGetDeviceGUID) was different to the GUID that the OpenTK SDL code was returning. Not sure how relevant that is but I found it interesting:)



Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture

Huh, the configuration in current SDL hg matches the one you posted. It may be that it has changed since last September, or it could be it was copy-pasted incorrectly in the first place. Weird.

I'll add the updated database to a hotfix release later today. Edit:

GUIDs are currently be different on Windows and Linux, because we use a different driver implementation than SDL. This will be resolved in a future version. XInput-compatible controllers will still work correctly on Windows, despite the different GUID.