We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 3447 - Missing GameController Functions -- InstanceID, NumAxes, NumButtons
Summary: Missing GameController Functions -- InstanceID, NumAxes, NumButtons
Status: RESOLVED INVALID
Alias: None
Product: SDL
Classification: Unclassified
Component: joystick (show other bugs)
Version: 2.0.4
Hardware: x86 Other
: P2 normal
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-10-05 05:46 UTC by Intellectual Kitty
Modified: 2017-08-11 20:46 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Intellectual Kitty 2016-10-05 05:46:11 UTC
The following functions (which have corresponding counterparts in the Joystick interface) are missing from the GameController interface:

    SDL_GameControllerID SDL_GameControllerInstanceID(SDL_GameController* gamecontroller);
    int SDL_GameControllerNumAxes(SDL_GameController* gamecontroller);
    int SDL_GameControllerNumButtons(SDL_GameController* gamecontroller);

The lack of SDL_GameControllerInstanceID is particularly problematic since the SDL_CONTROLLERDEVICEADDED event will provide a device_index in event.cdevice.which (where event is an SDL_Event struct) rather than an instance ID.  Without SDL_GameControllerInstanceID, there is no way to obtain the instance ID.
Comment 1 Alex Szpakowski 2016-10-05 14:28:55 UTC
(In reply to Intellectual Kitty from comment #0)
>     int SDL_GameControllerNumAxes(SDL_GameController* gamecontroller);
>     int SDL_GameControllerNumButtons(SDL_GameController* gamecontroller);

GameControllers have a fixed set of axes and buttons. You can cast SDL_CONTROLLER_AXIS_MAX and SDL_CONTROLLER_BUTTON_MAX to ints to find out how many (at compile time).

(In reply to Intellectual Kitty from comment #0)
> The lack of SDL_GameControllerInstanceID is particularly problematic since
> the SDL_CONTROLLERDEVICEADDED event will provide a device_index in
> event.cdevice.which (where event is an SDL_Event struct) rather than an
> instance ID.  Without SDL_GameControllerInstanceID, there is no way to
> obtain the instance ID.

event.cdevice.which gives back a device index (usable with SDL_IsGameController(int joystick_index) and SDL_GameControllerOpen(int joystick_index) on connect, and the joystick instance ID (usable with SDL_GameControllerFromInstanceID(SDL_JoystickID joyid), or JoystickInstanceID(SDL_GameControllerGetJoystick(controller))) on disconnect.
Comment 2 Intellectual Kitty 2016-10-05 20:31:34 UTC
Thank you, Alex.  That clarifies all of my problems.
Comment 3 Sam Lantinga 2017-08-11 20:45:48 UTC
Thanks Alex!
Comment 4 Sam Lantinga 2017-08-11 20:46:08 UTC
This is actually not a fixed bug, just closed.