hidapi: Use GameCube adapter controller port for player index
The Nintendo USB GameCube adapter has four controller ports. Return the port number as 0 to 3 from SDL_JoystickGetPlayerIndex() and SDL_JoystickGetDevicePlayerIndex().
parent
e7b514d8ff
commit
82af42761e
|
@ -267,6 +267,22 @@ HIDAPI_DriverGameCube_NumJoysticks(SDL_HIDAPI_DriverData *context)
|
||||||
return joysticks;
|
return joysticks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
HIDAPI_DriverGameCube_PlayerIndexForIndex(SDL_HIDAPI_DriverData *context, int index)
|
||||||
|
{
|
||||||
|
SDL_DriverGameCube_Context *ctx = (SDL_DriverGameCube_Context *)context->context;
|
||||||
|
Uint8 i;
|
||||||
|
for (i = 0; i < 4; i += 1) {
|
||||||
|
if (ctx->joysticks[i] != -1) {
|
||||||
|
if (index == 0) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
index -= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1; /* Should never get here! */
|
||||||
|
}
|
||||||
|
|
||||||
static SDL_JoystickID
|
static SDL_JoystickID
|
||||||
HIDAPI_DriverGameCube_InstanceIDForIndex(SDL_HIDAPI_DriverData *context, int index)
|
HIDAPI_DriverGameCube_InstanceIDForIndex(SDL_HIDAPI_DriverData *context, int index)
|
||||||
{
|
{
|
||||||
|
@ -294,6 +310,7 @@ HIDAPI_DriverGameCube_OpenJoystick(SDL_HIDAPI_DriverData *context, SDL_Joystick
|
||||||
joystick->nbuttons = 12;
|
joystick->nbuttons = 12;
|
||||||
joystick->naxes = 6;
|
joystick->naxes = 6;
|
||||||
joystick->epowerlevel = SDL_JOYSTICK_POWER_WIRED;
|
joystick->epowerlevel = SDL_JOYSTICK_POWER_WIRED;
|
||||||
|
joystick->player_index = i;
|
||||||
return SDL_TRUE;
|
return SDL_TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -334,6 +351,7 @@ SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverGameCube =
|
||||||
HIDAPI_DriverGameCube_QuitDriver,
|
HIDAPI_DriverGameCube_QuitDriver,
|
||||||
HIDAPI_DriverGameCube_UpdateDriver,
|
HIDAPI_DriverGameCube_UpdateDriver,
|
||||||
HIDAPI_DriverGameCube_NumJoysticks,
|
HIDAPI_DriverGameCube_NumJoysticks,
|
||||||
|
HIDAPI_DriverGameCube_PlayerIndexForIndex,
|
||||||
HIDAPI_DriverGameCube_InstanceIDForIndex,
|
HIDAPI_DriverGameCube_InstanceIDForIndex,
|
||||||
HIDAPI_DriverGameCube_OpenJoystick,
|
HIDAPI_DriverGameCube_OpenJoystick,
|
||||||
HIDAPI_DriverGameCube_Rumble
|
HIDAPI_DriverGameCube_Rumble
|
||||||
|
|
|
@ -338,6 +338,12 @@ HIDAPI_DriverPS4_NumJoysticks(SDL_HIDAPI_DriverData *context)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
HIDAPI_DriverPS4_PlayerIndexForIndex(SDL_HIDAPI_DriverData *context, int index)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
static SDL_JoystickID
|
static SDL_JoystickID
|
||||||
HIDAPI_DriverPS4_InstanceIDForIndex(SDL_HIDAPI_DriverData *context, int index)
|
HIDAPI_DriverPS4_InstanceIDForIndex(SDL_HIDAPI_DriverData *context, int index)
|
||||||
{
|
{
|
||||||
|
@ -592,6 +598,7 @@ SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverPS4 =
|
||||||
HIDAPI_DriverPS4_QuitDriver,
|
HIDAPI_DriverPS4_QuitDriver,
|
||||||
HIDAPI_DriverPS4_UpdateDriver,
|
HIDAPI_DriverPS4_UpdateDriver,
|
||||||
HIDAPI_DriverPS4_NumJoysticks,
|
HIDAPI_DriverPS4_NumJoysticks,
|
||||||
|
HIDAPI_DriverPS4_PlayerIndexForIndex,
|
||||||
HIDAPI_DriverPS4_InstanceIDForIndex,
|
HIDAPI_DriverPS4_InstanceIDForIndex,
|
||||||
HIDAPI_DriverPS4_OpenJoystick,
|
HIDAPI_DriverPS4_OpenJoystick,
|
||||||
HIDAPI_DriverPS4_Rumble
|
HIDAPI_DriverPS4_Rumble
|
||||||
|
|
|
@ -914,6 +914,12 @@ HIDAPI_DriverSwitch_NumJoysticks(SDL_HIDAPI_DriverData *context)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
HIDAPI_DriverSwitch_PlayerIndexForIndex(SDL_HIDAPI_DriverData *context, int index)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
static SDL_JoystickID
|
static SDL_JoystickID
|
||||||
HIDAPI_DriverSwitch_InstanceIDForIndex(SDL_HIDAPI_DriverData *context, int index)
|
HIDAPI_DriverSwitch_InstanceIDForIndex(SDL_HIDAPI_DriverData *context, int index)
|
||||||
{
|
{
|
||||||
|
@ -931,6 +937,7 @@ SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverSwitch =
|
||||||
HIDAPI_DriverSwitch_QuitDriver,
|
HIDAPI_DriverSwitch_QuitDriver,
|
||||||
HIDAPI_DriverSwitch_UpdateDriver,
|
HIDAPI_DriverSwitch_UpdateDriver,
|
||||||
HIDAPI_DriverSwitch_NumJoysticks,
|
HIDAPI_DriverSwitch_NumJoysticks,
|
||||||
|
HIDAPI_DriverSwitch_PlayerIndexForIndex,
|
||||||
HIDAPI_DriverSwitch_InstanceIDForIndex,
|
HIDAPI_DriverSwitch_InstanceIDForIndex,
|
||||||
HIDAPI_DriverSwitch_OpenJoystick,
|
HIDAPI_DriverSwitch_OpenJoystick,
|
||||||
HIDAPI_DriverSwitch_Rumble
|
HIDAPI_DriverSwitch_Rumble
|
||||||
|
|
|
@ -330,6 +330,12 @@ HIDAPI_DriverXbox360_NumJoysticks(SDL_HIDAPI_DriverData *context)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
HIDAPI_DriverXbox360_PlayerIndexForIndex(SDL_HIDAPI_DriverData *context, int index)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
static SDL_JoystickID
|
static SDL_JoystickID
|
||||||
HIDAPI_DriverXbox360_InstanceIDForIndex(SDL_HIDAPI_DriverData *context, int index)
|
HIDAPI_DriverXbox360_InstanceIDForIndex(SDL_HIDAPI_DriverData *context, int index)
|
||||||
{
|
{
|
||||||
|
@ -813,6 +819,7 @@ SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverXbox360 =
|
||||||
HIDAPI_DriverXbox360_QuitDriver,
|
HIDAPI_DriverXbox360_QuitDriver,
|
||||||
HIDAPI_DriverXbox360_UpdateDriver,
|
HIDAPI_DriverXbox360_UpdateDriver,
|
||||||
HIDAPI_DriverXbox360_NumJoysticks,
|
HIDAPI_DriverXbox360_NumJoysticks,
|
||||||
|
HIDAPI_DriverXbox360_PlayerIndexForIndex,
|
||||||
HIDAPI_DriverXbox360_InstanceIDForIndex,
|
HIDAPI_DriverXbox360_InstanceIDForIndex,
|
||||||
HIDAPI_DriverXbox360_OpenJoystick,
|
HIDAPI_DriverXbox360_OpenJoystick,
|
||||||
HIDAPI_DriverXbox360_Rumble
|
HIDAPI_DriverXbox360_Rumble
|
||||||
|
|
|
@ -207,6 +207,12 @@ HIDAPI_DriverXboxOne_NumJoysticks(SDL_HIDAPI_DriverData *context)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
HIDAPI_DriverXboxOne_PlayerIndexForIndex(SDL_HIDAPI_DriverData *context, int index)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
static SDL_JoystickID
|
static SDL_JoystickID
|
||||||
HIDAPI_DriverXboxOne_InstanceIDForIndex(SDL_HIDAPI_DriverData *context, int index)
|
HIDAPI_DriverXboxOne_InstanceIDForIndex(SDL_HIDAPI_DriverData *context, int index)
|
||||||
{
|
{
|
||||||
|
@ -350,6 +356,7 @@ SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverXboxOne =
|
||||||
HIDAPI_DriverXboxOne_QuitDriver,
|
HIDAPI_DriverXboxOne_QuitDriver,
|
||||||
HIDAPI_DriverXboxOne_UpdateDriver,
|
HIDAPI_DriverXboxOne_UpdateDriver,
|
||||||
HIDAPI_DriverXboxOne_NumJoysticks,
|
HIDAPI_DriverXboxOne_NumJoysticks,
|
||||||
|
HIDAPI_DriverXboxOne_PlayerIndexForIndex,
|
||||||
HIDAPI_DriverXboxOne_InstanceIDForIndex,
|
HIDAPI_DriverXboxOne_InstanceIDForIndex,
|
||||||
HIDAPI_DriverXboxOne_OpenJoystick,
|
HIDAPI_DriverXboxOne_OpenJoystick,
|
||||||
HIDAPI_DriverXboxOne_Rumble
|
HIDAPI_DriverXboxOne_Rumble
|
||||||
|
|
|
@ -948,7 +948,19 @@ HIDAPI_JoystickGetDeviceName(int device_index)
|
||||||
static int
|
static int
|
||||||
HIDAPI_JoystickGetDevicePlayerIndex(int device_index)
|
HIDAPI_JoystickGetDevicePlayerIndex(int device_index)
|
||||||
{
|
{
|
||||||
return -1;
|
SDL_HIDAPI_Device *device = SDL_HIDAPI_devices;
|
||||||
|
int joysticks;
|
||||||
|
while (device) {
|
||||||
|
if (device->driver) {
|
||||||
|
joysticks = device->driver->NumJoysticks(&device->devdata);
|
||||||
|
if (device_index < joysticks) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
device_index -= joysticks;
|
||||||
|
}
|
||||||
|
device = device->next;
|
||||||
|
}
|
||||||
|
return device->driver->PlayerIndexForIndex(&device->devdata, device_index);
|
||||||
}
|
}
|
||||||
|
|
||||||
static SDL_JoystickGUID
|
static SDL_JoystickGUID
|
||||||
|
|
|
@ -65,6 +65,8 @@ typedef struct _SDL_HIDAPI_DeviceDriver
|
||||||
SDL_bool (*UpdateDriver)(SDL_HIDAPI_DriverData *context,
|
SDL_bool (*UpdateDriver)(SDL_HIDAPI_DriverData *context,
|
||||||
int *num_joysticks);
|
int *num_joysticks);
|
||||||
int (*NumJoysticks)(SDL_HIDAPI_DriverData *context);
|
int (*NumJoysticks)(SDL_HIDAPI_DriverData *context);
|
||||||
|
int (*PlayerIndexForIndex)(SDL_HIDAPI_DriverData *context,
|
||||||
|
int index);
|
||||||
SDL_JoystickID (*InstanceIDForIndex)(SDL_HIDAPI_DriverData *context,
|
SDL_JoystickID (*InstanceIDForIndex)(SDL_HIDAPI_DriverData *context,
|
||||||
int index);
|
int index);
|
||||||
SDL_bool (*OpenJoystick)(SDL_HIDAPI_DriverData *context,
|
SDL_bool (*OpenJoystick)(SDL_HIDAPI_DriverData *context,
|
||||||
|
|
Loading…
Reference in New Issue