What is the difference between controller and joystick?

There are two subsystems – SDL_INIT_GAMECONTROLLER and SDL_INIT_JOYSTICK – in SDL. But I can’t see the difference between them. Although they have distinct even type, the even structure in the union – jaxis/caxis, jbutton/cbutton – are all the same. Also, I found that the joystick subsystem is adequate to work with my XBox 360 gamepad (I don’t know whether it is called a joystick or game controller). So what is the difference between controller and joystick? What differential feature makes SDL have two subsystems to manage a single type of device? Thanks.

SDL_Controller is implemented on top of SDL_Joystick, so every Controller device also has a corresponding Joystick device (but not every Joystick is a Controller).

SDL_Controllers are devices that are similar to the xbox360, playstation dualshock etc pads: They have a DPAD, two analog sticks, 4 buttons on the right (A,B,X,Y or geometric shapes on PS), shoulder buttons (two of which might be axes) and 3 buttons or so in the middle (Start, Back etc).
SDL_Controller provides a consistent interface to these kinds of controllers, kinda like XInput on Windows (but SDL_Controller is not limited to XInput devices), so you’ll know that SDL_CONTROLLER_AXIS_LEFTX is always the X-Axis of the left Analog Stick, or SDL_CONTROLLER_BUTTON_B is always the rightmost buttons of the 4 buttons on the right (the names are xbox360-pad style), for example.
This makes providing consistent input bindings (for this kind of device) to your users easy, like “press B to jump, move around with the left analog stick” - with SDL_Joystick (and the underlying APIs like DirectInput) it’s impossible to know which SDL (or DirectInput) axis or button corresponds to which physical axis/button on the device.

AFAIK this works for all XInput devices, all device that are known to SDL and have a mapping (see https://wiki.libsdl.org/SDL_GameControllerAddMapping and https://hg.libsdl.org/SDL/file/tip/src/joystick/SDL_gamecontrollerdb.h), and (at least on Linux, unsure about Windows?) devices that are configured in Steam (somewhere in Big Picture Mode settings), if the game is started from Steam.

1 Like

Thank you very much!

1 Like