SDL API renaming: SDL_joystick.h
Fixes https://github.com/libsdl-org/SDL/issues/6881
This commit is contained in:
@@ -368,11 +368,11 @@ WatchJoystick(SDL_Joystick *joystick)
|
||||
SDL_RenderSetLogicalSize(screen, SCREEN_WIDTH, SCREEN_HEIGHT);
|
||||
|
||||
/* Print info about the joystick we are watching */
|
||||
name = SDL_JoystickName(joystick);
|
||||
SDL_Log("Watching joystick %" SDL_PRIs32 ": (%s)\n", SDL_JoystickInstanceID(joystick),
|
||||
name = SDL_GetJoystickName(joystick);
|
||||
SDL_Log("Watching joystick %" SDL_PRIs32 ": (%s)\n", SDL_GetJoystickInstanceID(joystick),
|
||||
name ? name : "Unknown Joystick");
|
||||
SDL_Log("Joystick has %d axes, %d hats, and %d buttons\n",
|
||||
SDL_JoystickNumAxes(joystick), SDL_JoystickNumHats(joystick), SDL_JoystickNumButtons(joystick));
|
||||
SDL_GetNumJoystickAxes(joystick), SDL_GetNumJoystickHats(joystick), SDL_GetNumJoystickButtons(joystick));
|
||||
|
||||
SDL_Log("\n\n\
|
||||
====================================================================================\n\
|
||||
@@ -383,9 +383,9 @@ WatchJoystick(SDL_Joystick *joystick)
|
||||
To exit, press ESC\n\
|
||||
====================================================================================\n");
|
||||
|
||||
nJoystickID = SDL_JoystickInstanceID(joystick);
|
||||
nJoystickID = SDL_GetJoystickInstanceID(joystick);
|
||||
|
||||
s_nNumAxes = SDL_JoystickNumAxes(joystick);
|
||||
s_nNumAxes = SDL_GetNumJoystickAxes(joystick);
|
||||
s_arrAxisState = (AxisState *)SDL_calloc(s_nNumAxes, sizeof(*s_arrAxisState));
|
||||
|
||||
/* Skip any spurious events at start */
|
||||
@@ -448,7 +448,7 @@ WatchJoystick(SDL_Joystick *joystick)
|
||||
int nCurrentDistance, nFarthestDistance;
|
||||
if (!pAxisState->m_bMoving) {
|
||||
Sint16 nInitialValue;
|
||||
pAxisState->m_bMoving = SDL_JoystickGetAxisInitialState(joystick, event.jaxis.axis, &nInitialValue);
|
||||
pAxisState->m_bMoving = SDL_GetJoystickAxisInitialState(joystick, event.jaxis.axis, &nInitialValue);
|
||||
pAxisState->m_nLastValue = nValue;
|
||||
pAxisState->m_nStartingValue = nInitialValue;
|
||||
pAxisState->m_nFarthestValue = nInitialValue;
|
||||
@@ -570,14 +570,14 @@ WatchJoystick(SDL_Joystick *joystick)
|
||||
}
|
||||
|
||||
/* Initialize mapping with GUID and name */
|
||||
guid = SDL_JoystickGetGUID(joystick);
|
||||
guid = SDL_GetJoystickGUID(joystick);
|
||||
SDL_GetJoystickGUIDInfo(guid, NULL, NULL, NULL, &crc);
|
||||
if (crc) {
|
||||
/* Clear the CRC from the GUID for the mapping */
|
||||
guid.data[2] = 0;
|
||||
guid.data[3] = 0;
|
||||
}
|
||||
SDL_JoystickGetGUIDString(guid, mapping, SDL_arraysize(mapping));
|
||||
SDL_GetJoystickGUIDString(guid, mapping, SDL_arraysize(mapping));
|
||||
SDL_strlcat(mapping, ",", SDL_arraysize(mapping));
|
||||
SDL_strlcat(mapping, trimmed_name, SDL_arraysize(mapping));
|
||||
SDL_strlcat(mapping, ",", SDL_arraysize(mapping));
|
||||
@@ -737,7 +737,7 @@ int main(int argc, char *argv[])
|
||||
return 2;
|
||||
}
|
||||
|
||||
while (!done && SDL_NumJoysticks() == 0) {
|
||||
while (!done && SDL_GetNumJoysticks() == 0) {
|
||||
SDL_Event event;
|
||||
|
||||
while (SDL_PollEvent(&event) > 0) {
|
||||
@@ -758,25 +758,25 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
/* Print information about the joysticks */
|
||||
SDL_Log("There are %d joysticks attached\n", SDL_NumJoysticks());
|
||||
for (i = 0; i < SDL_NumJoysticks(); ++i) {
|
||||
name = SDL_JoystickNameForIndex(i);
|
||||
SDL_Log("There are %d joysticks attached\n", SDL_GetNumJoysticks());
|
||||
for (i = 0; i < SDL_GetNumJoysticks(); ++i) {
|
||||
name = SDL_GetJoystickNameForIndex(i);
|
||||
SDL_Log("Joystick %d: %s\n", i, name ? name : "Unknown Joystick");
|
||||
joystick = SDL_JoystickOpen(i);
|
||||
joystick = SDL_OpenJoystick(i);
|
||||
if (joystick == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_JoystickOpen(%d) failed: %s\n", i,
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_OpenJoystick(%d) failed: %s\n", i,
|
||||
SDL_GetError());
|
||||
} else {
|
||||
char guid[64];
|
||||
SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick),
|
||||
SDL_GetJoystickGUIDString(SDL_GetJoystickGUID(joystick),
|
||||
guid, sizeof(guid));
|
||||
SDL_Log(" axes: %d\n", SDL_JoystickNumAxes(joystick));
|
||||
SDL_Log(" hats: %d\n", SDL_JoystickNumHats(joystick));
|
||||
SDL_Log(" buttons: %d\n", SDL_JoystickNumButtons(joystick));
|
||||
SDL_Log("instance id: %" SDL_PRIu32 "\n", SDL_JoystickInstanceID(joystick));
|
||||
SDL_Log(" axes: %d\n", SDL_GetNumJoystickAxes(joystick));
|
||||
SDL_Log(" hats: %d\n", SDL_GetNumJoystickHats(joystick));
|
||||
SDL_Log(" buttons: %d\n", SDL_GetNumJoystickButtons(joystick));
|
||||
SDL_Log("instance id: %" SDL_PRIu32 "\n", SDL_GetJoystickInstanceID(joystick));
|
||||
SDL_Log(" guid: %s\n", guid);
|
||||
SDL_Log(" VID/PID: 0x%.4x/0x%.4x\n", SDL_JoystickGetVendor(joystick), SDL_JoystickGetProduct(joystick));
|
||||
SDL_JoystickClose(joystick);
|
||||
SDL_Log(" VID/PID: 0x%.4x/0x%.4x\n", SDL_GetJoystickVendor(joystick), SDL_GetJoystickProduct(joystick));
|
||||
SDL_CloseJoystick(joystick);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -787,12 +787,12 @@ int main(int argc, char *argv[])
|
||||
break;
|
||||
}
|
||||
}
|
||||
joystick = SDL_JoystickOpen(joystick_index);
|
||||
joystick = SDL_OpenJoystick(joystick_index);
|
||||
if (joystick == NULL) {
|
||||
SDL_Log("Couldn't open joystick %d: %s\n", joystick_index, SDL_GetError());
|
||||
} else {
|
||||
WatchJoystick(joystick);
|
||||
SDL_JoystickClose(joystick);
|
||||
SDL_CloseJoystick(joystick);
|
||||
}
|
||||
|
||||
SDL_DestroyWindow(window);
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
/**
|
||||
* @brief Check virtual joystick creation
|
||||
*
|
||||
* @sa SDL_JoystickAttachVirtualEx
|
||||
* @sa SDL_AttachVirtualJoystickEx
|
||||
*/
|
||||
static int
|
||||
TestVirtualJoystick(void *arg)
|
||||
@@ -32,36 +32,36 @@ TestVirtualJoystick(void *arg)
|
||||
desc.vendor_id = USB_VENDOR_NVIDIA;
|
||||
desc.product_id = USB_PRODUCT_NVIDIA_SHIELD_CONTROLLER_V104;
|
||||
desc.name = "Virtual NVIDIA SHIELD Controller";
|
||||
device_index = SDL_JoystickAttachVirtualEx(&desc);
|
||||
SDLTest_AssertCheck(device_index >= 0, "SDL_JoystickAttachVirtualEx()");
|
||||
SDLTest_AssertCheck(SDL_JoystickIsVirtual(device_index), "SDL_JoystickIsVirtual()");
|
||||
device_index = SDL_AttachVirtualJoystickEx(&desc);
|
||||
SDLTest_AssertCheck(device_index >= 0, "SDL_AttachVirtualJoystickEx()");
|
||||
SDLTest_AssertCheck(SDL_IsJoystickVirtual(device_index), "SDL_IsJoystickVirtual()");
|
||||
if (device_index >= 0) {
|
||||
joystick = SDL_JoystickOpen(device_index);
|
||||
SDLTest_AssertCheck(joystick != NULL, "SDL_JoystickOpen()");
|
||||
joystick = SDL_OpenJoystick(device_index);
|
||||
SDLTest_AssertCheck(joystick != NULL, "SDL_OpenJoystick()");
|
||||
if (joystick) {
|
||||
SDLTest_AssertCheck(SDL_strcmp(SDL_JoystickName(joystick), desc.name) == 0, "SDL_JoystickName()");
|
||||
SDLTest_AssertCheck(SDL_JoystickGetVendor(joystick) == desc.vendor_id, "SDL_JoystickGetVendor()");
|
||||
SDLTest_AssertCheck(SDL_JoystickGetProduct(joystick) == desc.product_id, "SDL_JoystickGetProduct()");
|
||||
SDLTest_AssertCheck(SDL_JoystickGetProductVersion(joystick) == 0, "SDL_JoystickGetProductVersion()");
|
||||
SDLTest_AssertCheck(SDL_JoystickGetFirmwareVersion(joystick) == 0, "SDL_JoystickGetFirmwareVersion()");
|
||||
SDLTest_AssertCheck(SDL_JoystickGetSerial(joystick) == NULL, "SDL_JoystickGetSerial()");
|
||||
SDLTest_AssertCheck(SDL_JoystickGetType(joystick) == desc.type, "SDL_JoystickGetType()");
|
||||
SDLTest_AssertCheck(SDL_JoystickNumAxes(joystick) == desc.naxes, "SDL_JoystickNumAxes()");
|
||||
SDLTest_AssertCheck(SDL_JoystickNumHats(joystick) == desc.nhats, "SDL_JoystickNumHats()");
|
||||
SDLTest_AssertCheck(SDL_JoystickNumButtons(joystick) == desc.nbuttons, "SDL_JoystickNumButtons()");
|
||||
SDLTest_AssertCheck(SDL_strcmp(SDL_GetJoystickName(joystick), desc.name) == 0, "SDL_GetJoystickName()");
|
||||
SDLTest_AssertCheck(SDL_GetJoystickVendor(joystick) == desc.vendor_id, "SDL_GetJoystickVendor()");
|
||||
SDLTest_AssertCheck(SDL_GetJoystickProduct(joystick) == desc.product_id, "SDL_GetJoystickProduct()");
|
||||
SDLTest_AssertCheck(SDL_GetJoystickProductVersion(joystick) == 0, "SDL_GetJoystickProductVersion()");
|
||||
SDLTest_AssertCheck(SDL_GetJoystickFirmwareVersion(joystick) == 0, "SDL_GetJoystickFirmwareVersion()");
|
||||
SDLTest_AssertCheck(SDL_GetJoystickSerial(joystick) == NULL, "SDL_GetJoystickSerial()");
|
||||
SDLTest_AssertCheck(SDL_GetJoystickType(joystick) == desc.type, "SDL_GetJoystickType()");
|
||||
SDLTest_AssertCheck(SDL_GetNumJoystickAxes(joystick) == desc.naxes, "SDL_GetNumJoystickAxes()");
|
||||
SDLTest_AssertCheck(SDL_GetNumJoystickHats(joystick) == desc.nhats, "SDL_GetNumJoystickHats()");
|
||||
SDLTest_AssertCheck(SDL_GetNumJoystickButtons(joystick) == desc.nbuttons, "SDL_GetNumJoystickButtons()");
|
||||
|
||||
SDLTest_AssertCheck(SDL_JoystickSetVirtualButton(joystick, SDL_CONTROLLER_BUTTON_A, SDL_PRESSED) == 0, "SDL_JoystickSetVirtualButton(SDL_CONTROLLER_BUTTON_A, SDL_PRESSED)");
|
||||
SDL_JoystickUpdate();
|
||||
SDLTest_AssertCheck(SDL_JoystickGetButton(joystick, SDL_CONTROLLER_BUTTON_A) == SDL_PRESSED, "SDL_JoystickGetButton(SDL_CONTROLLER_BUTTON_A) == SDL_PRESSED");
|
||||
SDLTest_AssertCheck(SDL_JoystickSetVirtualButton(joystick, SDL_CONTROLLER_BUTTON_A, SDL_RELEASED) == 0, "SDL_JoystickSetVirtualButton(SDL_CONTROLLER_BUTTON_A, SDL_RELEASED)");
|
||||
SDL_JoystickUpdate();
|
||||
SDLTest_AssertCheck(SDL_JoystickGetButton(joystick, SDL_CONTROLLER_BUTTON_A) == SDL_RELEASED, "SDL_JoystickGetButton(SDL_CONTROLLER_BUTTON_A) == SDL_RELEASED");
|
||||
SDLTest_AssertCheck(SDL_SetJoystickVirtualButton(joystick, SDL_CONTROLLER_BUTTON_A, SDL_PRESSED) == 0, "SDL_SetJoystickVirtualButton(SDL_CONTROLLER_BUTTON_A, SDL_PRESSED)");
|
||||
SDL_UpdateJoysticks();
|
||||
SDLTest_AssertCheck(SDL_GetJoystickButton(joystick, SDL_CONTROLLER_BUTTON_A) == SDL_PRESSED, "SDL_GetJoystickButton(SDL_CONTROLLER_BUTTON_A) == SDL_PRESSED");
|
||||
SDLTest_AssertCheck(SDL_SetJoystickVirtualButton(joystick, SDL_CONTROLLER_BUTTON_A, SDL_RELEASED) == 0, "SDL_SetJoystickVirtualButton(SDL_CONTROLLER_BUTTON_A, SDL_RELEASED)");
|
||||
SDL_UpdateJoysticks();
|
||||
SDLTest_AssertCheck(SDL_GetJoystickButton(joystick, SDL_CONTROLLER_BUTTON_A) == SDL_RELEASED, "SDL_GetJoystickButton(SDL_CONTROLLER_BUTTON_A) == SDL_RELEASED");
|
||||
|
||||
SDL_JoystickClose(joystick);
|
||||
SDL_CloseJoystick(joystick);
|
||||
}
|
||||
SDLTest_AssertCheck(SDL_JoystickDetachVirtual(device_index) == 0, "SDL_JoystickDetachVirtual()");
|
||||
SDLTest_AssertCheck(SDL_DetachVirtualJoystick(device_index) == 0, "SDL_DetachVirtualJoystick()");
|
||||
}
|
||||
SDLTest_AssertCheck(!SDL_JoystickIsVirtual(device_index), "!SDL_JoystickIsVirtual()");
|
||||
SDLTest_AssertCheck(!SDL_IsJoystickVirtual(device_index), "!SDL_IsJoystickVirtual()");
|
||||
|
||||
SDL_QuitSubSystem(SDL_INIT_GAMECONTROLLER);
|
||||
|
||||
|
||||
@@ -158,7 +158,7 @@ static int FindController(SDL_JoystickID controller_id)
|
||||
int i;
|
||||
|
||||
for (i = 0; i < num_controllers; ++i) {
|
||||
if (controller_id == SDL_JoystickInstanceID(SDL_GameControllerGetJoystick(gamecontrollers[i]))) {
|
||||
if (controller_id == SDL_GetJoystickInstanceID(SDL_GameControllerGetJoystick(gamecontrollers[i]))) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
@@ -167,7 +167,7 @@ static int FindController(SDL_JoystickID controller_id)
|
||||
|
||||
static void AddController(int device_index, SDL_bool verbose)
|
||||
{
|
||||
SDL_JoystickID controller_id = SDL_JoystickGetDeviceInstanceID(device_index);
|
||||
SDL_JoystickID controller_id = SDL_GetJoystickDeviceInstanceID(device_index);
|
||||
SDL_GameController *controller;
|
||||
SDL_GameController **controllers;
|
||||
Uint16 firmware_version;
|
||||
@@ -181,7 +181,7 @@ static void AddController(int device_index, SDL_bool verbose)
|
||||
};
|
||||
unsigned int i;
|
||||
|
||||
controller_id = SDL_JoystickGetDeviceInstanceID(device_index);
|
||||
controller_id = SDL_GetJoystickDeviceInstanceID(device_index);
|
||||
if (controller_id < 0) {
|
||||
SDL_Log("Couldn't get controller ID: %s\n", SDL_GetError());
|
||||
return;
|
||||
@@ -400,11 +400,11 @@ static void OpenVirtualController()
|
||||
desc.RumbleTriggers = VirtualControllerRumbleTriggers;
|
||||
desc.SetLED = VirtualControllerSetLED;
|
||||
|
||||
virtual_index = SDL_JoystickAttachVirtualEx(&desc);
|
||||
virtual_index = SDL_AttachVirtualJoystickEx(&desc);
|
||||
if (virtual_index < 0) {
|
||||
SDL_Log("Couldn't open virtual device: %s\n", SDL_GetError());
|
||||
} else {
|
||||
virtual_joystick = SDL_JoystickOpen(virtual_index);
|
||||
virtual_joystick = SDL_OpenJoystick(virtual_index);
|
||||
if (virtual_joystick == NULL) {
|
||||
SDL_Log("Couldn't open virtual device: %s\n", SDL_GetError());
|
||||
}
|
||||
@@ -415,14 +415,14 @@ static void CloseVirtualController()
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = SDL_NumJoysticks(); i--;) {
|
||||
if (SDL_JoystickIsVirtual(i)) {
|
||||
SDL_JoystickDetachVirtual(i);
|
||||
for (i = SDL_GetNumJoysticks(); i--;) {
|
||||
if (SDL_IsJoystickVirtual(i)) {
|
||||
SDL_DetachVirtualJoystick(i);
|
||||
}
|
||||
}
|
||||
|
||||
if (virtual_joystick) {
|
||||
SDL_JoystickClose(virtual_joystick);
|
||||
SDL_CloseJoystick(virtual_joystick);
|
||||
virtual_joystick = NULL;
|
||||
}
|
||||
}
|
||||
@@ -481,7 +481,7 @@ static void VirtualControllerMouseMotion(int x, int y)
|
||||
const int MOVING_DISTANCE = 2;
|
||||
if (SDL_abs(x - virtual_axis_start_x) >= MOVING_DISTANCE ||
|
||||
SDL_abs(y - virtual_axis_start_y) >= MOVING_DISTANCE) {
|
||||
SDL_JoystickSetVirtualButton(virtual_joystick, virtual_button_active, SDL_RELEASED);
|
||||
SDL_SetJoystickVirtualButton(virtual_joystick, virtual_button_active, SDL_RELEASED);
|
||||
virtual_button_active = SDL_CONTROLLER_BUTTON_INVALID;
|
||||
}
|
||||
}
|
||||
@@ -493,7 +493,7 @@ static void VirtualControllerMouseMotion(int x, int y)
|
||||
int range = (SDL_JOYSTICK_AXIS_MAX - SDL_JOYSTICK_AXIS_MIN);
|
||||
float distance = SDL_clamp(((float)y - virtual_axis_start_y) / AXIS_SIZE, 0.0f, 1.0f);
|
||||
Sint16 value = (Sint16)(SDL_JOYSTICK_AXIS_MIN + (distance * range));
|
||||
SDL_JoystickSetVirtualAxis(virtual_joystick, virtual_axis_active, value);
|
||||
SDL_SetJoystickVirtualAxis(virtual_joystick, virtual_axis_active, value);
|
||||
} else {
|
||||
float distanceX = SDL_clamp(((float)x - virtual_axis_start_x) / AXIS_SIZE, -1.0f, 1.0f);
|
||||
float distanceY = SDL_clamp(((float)y - virtual_axis_start_y) / AXIS_SIZE, -1.0f, 1.0f);
|
||||
@@ -509,8 +509,8 @@ static void VirtualControllerMouseMotion(int x, int y)
|
||||
} else {
|
||||
valueY = (Sint16)(distanceY * -SDL_JOYSTICK_AXIS_MIN);
|
||||
}
|
||||
SDL_JoystickSetVirtualAxis(virtual_joystick, virtual_axis_active, valueX);
|
||||
SDL_JoystickSetVirtualAxis(virtual_joystick, virtual_axis_active + 1, valueY);
|
||||
SDL_SetJoystickVirtualAxis(virtual_joystick, virtual_axis_active, valueX);
|
||||
SDL_SetJoystickVirtualAxis(virtual_joystick, virtual_axis_active + 1, valueY);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -523,7 +523,7 @@ static void VirtualControllerMouseDown(int x, int y)
|
||||
button = FindButtonAtPosition(x, y);
|
||||
if (button != SDL_CONTROLLER_BUTTON_INVALID) {
|
||||
virtual_button_active = button;
|
||||
SDL_JoystickSetVirtualButton(virtual_joystick, virtual_button_active, SDL_PRESSED);
|
||||
SDL_SetJoystickVirtualButton(virtual_joystick, virtual_button_active, SDL_PRESSED);
|
||||
}
|
||||
|
||||
axis = FindAxisAtPosition(x, y);
|
||||
@@ -537,17 +537,17 @@ static void VirtualControllerMouseDown(int x, int y)
|
||||
static void VirtualControllerMouseUp(int x, int y)
|
||||
{
|
||||
if (virtual_button_active != SDL_CONTROLLER_BUTTON_INVALID) {
|
||||
SDL_JoystickSetVirtualButton(virtual_joystick, virtual_button_active, SDL_RELEASED);
|
||||
SDL_SetJoystickVirtualButton(virtual_joystick, virtual_button_active, SDL_RELEASED);
|
||||
virtual_button_active = SDL_CONTROLLER_BUTTON_INVALID;
|
||||
}
|
||||
|
||||
if (virtual_axis_active != SDL_CONTROLLER_AXIS_INVALID) {
|
||||
if (virtual_axis_active == SDL_CONTROLLER_AXIS_TRIGGERLEFT ||
|
||||
virtual_axis_active == SDL_CONTROLLER_AXIS_TRIGGERRIGHT) {
|
||||
SDL_JoystickSetVirtualAxis(virtual_joystick, virtual_axis_active, SDL_JOYSTICK_AXIS_MIN);
|
||||
SDL_SetJoystickVirtualAxis(virtual_joystick, virtual_axis_active, SDL_JOYSTICK_AXIS_MIN);
|
||||
} else {
|
||||
SDL_JoystickSetVirtualAxis(virtual_joystick, virtual_axis_active, 0);
|
||||
SDL_JoystickSetVirtualAxis(virtual_joystick, virtual_axis_active + 1, 0);
|
||||
SDL_SetJoystickVirtualAxis(virtual_joystick, virtual_axis_active, 0);
|
||||
SDL_SetJoystickVirtualAxis(virtual_joystick, virtual_axis_active + 1, 0);
|
||||
}
|
||||
virtual_axis_active = SDL_CONTROLLER_AXIS_INVALID;
|
||||
}
|
||||
@@ -566,7 +566,7 @@ void loop(void *arg)
|
||||
while (SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT) == 1) {
|
||||
switch (event.type) {
|
||||
case SDL_CONTROLLERDEVICEADDED:
|
||||
SDL_Log("Game controller device %d added.\n", (int)SDL_JoystickGetDeviceInstanceID(event.cdevice.which));
|
||||
SDL_Log("Game controller device %d added.\n", (int)SDL_GetJoystickDeviceInstanceID(event.cdevice.which));
|
||||
AddController(event.cdevice.which, SDL_TRUE);
|
||||
break;
|
||||
|
||||
@@ -823,12 +823,12 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
/* Print information about the controller */
|
||||
for (i = 0; i < SDL_NumJoysticks(); ++i) {
|
||||
for (i = 0; i < SDL_GetNumJoysticks(); ++i) {
|
||||
const char *name;
|
||||
const char *path;
|
||||
const char *description;
|
||||
|
||||
SDL_JoystickGetGUIDString(SDL_JoystickGetDeviceGUID(i),
|
||||
SDL_GetJoystickGUIDString(SDL_GetJoystickDeviceGUID(i),
|
||||
guid, sizeof(guid));
|
||||
|
||||
if (SDL_IsGameController(i)) {
|
||||
@@ -874,15 +874,15 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
AddController(i, SDL_FALSE);
|
||||
} else {
|
||||
name = SDL_JoystickNameForIndex(i);
|
||||
path = SDL_JoystickPathForIndex(i);
|
||||
name = SDL_GetJoystickNameForIndex(i);
|
||||
path = SDL_GetJoystickPathForIndex(i);
|
||||
description = "Joystick";
|
||||
}
|
||||
SDL_Log("%s %d: %s%s%s (guid %s, VID 0x%.4x, PID 0x%.4x, player index = %d)\n",
|
||||
description, i, name ? name : "Unknown", path ? ", " : "", path ? path : "", guid,
|
||||
SDL_JoystickGetDeviceVendor(i), SDL_JoystickGetDeviceProduct(i), SDL_JoystickGetDevicePlayerIndex(i));
|
||||
SDL_GetJoystickDeviceVendor(i), SDL_GetJoystickDeviceProduct(i), SDL_GetJoystickDevicePlayerIndex(i));
|
||||
}
|
||||
SDL_Log("There are %d game controller(s) attached (%d joystick(s))\n", controller_count, SDL_NumJoysticks());
|
||||
SDL_Log("There are %d game controller(s) attached (%d joystick(s))\n", controller_count, SDL_GetNumJoysticks());
|
||||
|
||||
/* Create a window to display controller state */
|
||||
window = SDL_CreateWindow("Game Controller Test", SDL_WINDOWPOS_CENTERED,
|
||||
|
||||
@@ -52,7 +52,7 @@ int main(int argc, char *argv[])
|
||||
//SDL_CreateWindow("Dummy", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 128, 128, 0);
|
||||
*/
|
||||
|
||||
SDL_Log("There are %d joysticks at startup\n", SDL_NumJoysticks());
|
||||
SDL_Log("There are %d joysticks at startup\n", SDL_GetNumJoysticks());
|
||||
if (enable_haptic) {
|
||||
SDL_Log("There are %d haptic devices at startup\n", SDL_NumHaptics());
|
||||
}
|
||||
@@ -68,9 +68,9 @@ int main(int argc, char *argv[])
|
||||
if (joystick != NULL) {
|
||||
SDL_Log("Only one joystick supported by this test\n");
|
||||
} else {
|
||||
joystick = SDL_JoystickOpen(event.jdevice.which);
|
||||
instance = SDL_JoystickInstanceID(joystick);
|
||||
SDL_Log("Joy Added : %" SDL_PRIs32 " : %s\n", event.jdevice.which, SDL_JoystickName(joystick));
|
||||
joystick = SDL_OpenJoystick(event.jdevice.which);
|
||||
instance = SDL_GetJoystickInstanceID(joystick);
|
||||
SDL_Log("Joy Added : %" SDL_PRIs32 " : %s\n", event.jdevice.which, SDL_GetJoystickName(joystick));
|
||||
if (enable_haptic) {
|
||||
if (SDL_JoystickIsHaptic(joystick)) {
|
||||
haptic = SDL_HapticOpenFromJoystick(joystick);
|
||||
@@ -98,7 +98,7 @@ int main(int argc, char *argv[])
|
||||
SDL_HapticClose(haptic);
|
||||
haptic = NULL;
|
||||
}
|
||||
SDL_JoystickClose(joystick);
|
||||
SDL_CloseJoystick(joystick);
|
||||
joystick = NULL;
|
||||
} else {
|
||||
SDL_Log("Unknown joystick diconnected\n");
|
||||
|
||||
@@ -40,9 +40,9 @@ PrintJoystick(SDL_Joystick *joy)
|
||||
const char *type;
|
||||
char guid[64];
|
||||
|
||||
SDL_assert(SDL_JoystickFromInstanceID(SDL_JoystickInstanceID(joy)) == joy);
|
||||
SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joy), guid, sizeof(guid));
|
||||
switch (SDL_JoystickGetType(joy)) {
|
||||
SDL_assert(SDL_GetJoystickFromInstanceID(SDL_GetJoystickInstanceID(joy)) == joy);
|
||||
SDL_GetJoystickGUIDString(SDL_GetJoystickGUID(joy), guid, sizeof(guid));
|
||||
switch (SDL_GetJoystickType(joy)) {
|
||||
case SDL_JOYSTICK_TYPE_GAMECONTROLLER:
|
||||
type = "Game Controller";
|
||||
break;
|
||||
@@ -75,17 +75,17 @@ PrintJoystick(SDL_Joystick *joy)
|
||||
break;
|
||||
}
|
||||
SDL_Log("Joystick\n");
|
||||
SDL_Log(" name: %s\n", SDL_JoystickName(joy));
|
||||
SDL_Log(" name: %s\n", SDL_GetJoystickName(joy));
|
||||
SDL_Log(" type: %s\n", type);
|
||||
SDL_Log(" LED: %s\n", SDL_JoystickHasLED(joy) ? "yes" : "no");
|
||||
SDL_Log(" rumble: %s\n", SDL_JoystickHasRumble(joy) ? "yes" : "no");
|
||||
SDL_Log("trigger rumble: %s\n", SDL_JoystickHasRumbleTriggers(joy) ? "yes" : "no");
|
||||
SDL_Log(" axes: %d\n", SDL_JoystickNumAxes(joy));
|
||||
SDL_Log(" hats: %d\n", SDL_JoystickNumHats(joy));
|
||||
SDL_Log(" buttons: %d\n", SDL_JoystickNumButtons(joy));
|
||||
SDL_Log(" instance id: %" SDL_PRIs32 "\n", SDL_JoystickInstanceID(joy));
|
||||
SDL_Log(" axes: %d\n", SDL_GetNumJoystickAxes(joy));
|
||||
SDL_Log(" hats: %d\n", SDL_GetNumJoystickHats(joy));
|
||||
SDL_Log(" buttons: %d\n", SDL_GetNumJoystickButtons(joy));
|
||||
SDL_Log(" instance id: %" SDL_PRIs32 "\n", SDL_GetJoystickInstanceID(joy));
|
||||
SDL_Log(" guid: %s\n", guid);
|
||||
SDL_Log(" VID/PID: 0x%.4x/0x%.4x\n", SDL_JoystickGetVendor(joy), SDL_JoystickGetProduct(joy));
|
||||
SDL_Log(" VID/PID: 0x%.4x/0x%.4x\n", SDL_GetJoystickVendor(joy), SDL_GetJoystickProduct(joy));
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -114,7 +114,7 @@ void loop(void *arg)
|
||||
case SDL_JOYDEVICEADDED:
|
||||
SDL_Log("Joystick device %d added.\n", (int)event.jdevice.which);
|
||||
if (joystick == NULL) {
|
||||
joystick = SDL_JoystickOpen(event.jdevice.which);
|
||||
joystick = SDL_OpenJoystick(event.jdevice.which);
|
||||
if (joystick) {
|
||||
PrintJoystick(joystick);
|
||||
} else {
|
||||
@@ -125,9 +125,9 @@ void loop(void *arg)
|
||||
|
||||
case SDL_JOYDEVICEREMOVED:
|
||||
SDL_Log("Joystick device %d removed.\n", (int)event.jdevice.which);
|
||||
if (event.jdevice.which == SDL_JoystickInstanceID(joystick)) {
|
||||
SDL_JoystickClose(joystick);
|
||||
joystick = SDL_JoystickOpen(0);
|
||||
if (event.jdevice.which == SDL_GetJoystickInstanceID(joystick)) {
|
||||
SDL_CloseJoystick(joystick);
|
||||
joystick = SDL_OpenJoystick(0);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -161,7 +161,7 @@ void loop(void *arg)
|
||||
event.jbutton.which, event.jbutton.button);
|
||||
/* First button triggers a 0.5 second full strength rumble */
|
||||
if (event.jbutton.button == 0) {
|
||||
SDL_JoystickRumble(joystick, 0xFFFF, 0xFFFF, 500);
|
||||
SDL_RumbleJoystick(joystick, 0xFFFF, 0xFFFF, 500);
|
||||
}
|
||||
break;
|
||||
case SDL_JOYBUTTONUP:
|
||||
@@ -198,21 +198,21 @@ void loop(void *arg)
|
||||
|
||||
/* Update visual joystick state */
|
||||
SDL_SetRenderDrawColor(screen, 0x00, 0xFF, 0x00, SDL_ALPHA_OPAQUE);
|
||||
y = SCREEN_HEIGHT - ((((SDL_JoystickNumButtons(joystick) + (BUTTONS_PER_LINE - 1)) / BUTTONS_PER_LINE) + 1) * 34);
|
||||
for (i = 0; i < SDL_JoystickNumButtons(joystick); ++i) {
|
||||
y = SCREEN_HEIGHT - ((((SDL_GetNumJoystickButtons(joystick) + (BUTTONS_PER_LINE - 1)) / BUTTONS_PER_LINE) + 1) * 34);
|
||||
for (i = 0; i < SDL_GetNumJoystickButtons(joystick); ++i) {
|
||||
if ((i % BUTTONS_PER_LINE) == 0) {
|
||||
y += 34;
|
||||
}
|
||||
if (SDL_JoystickGetButton(joystick, i) == SDL_PRESSED) {
|
||||
if (SDL_GetJoystickButton(joystick, i) == SDL_PRESSED) {
|
||||
x = 2 + (i % BUTTONS_PER_LINE) * 34;
|
||||
DrawRect(screen, x, y, 32, 32);
|
||||
}
|
||||
}
|
||||
|
||||
SDL_SetRenderDrawColor(screen, 0xFF, 0x00, 0x00, SDL_ALPHA_OPAQUE);
|
||||
for (i = 0; i < SDL_JoystickNumAxes(joystick); ++i) {
|
||||
for (i = 0; i < SDL_GetNumJoystickAxes(joystick); ++i) {
|
||||
/* Draw the X/Y axis */
|
||||
x = (((int)SDL_JoystickGetAxis(joystick, i)) + 32768);
|
||||
x = (((int)SDL_GetJoystickAxis(joystick, i)) + 32768);
|
||||
x *= SCREEN_WIDTH;
|
||||
x /= 65535;
|
||||
if (x < 0) {
|
||||
@@ -221,8 +221,8 @@ void loop(void *arg)
|
||||
x = SCREEN_WIDTH - 16;
|
||||
}
|
||||
++i;
|
||||
if (i < SDL_JoystickNumAxes(joystick)) {
|
||||
y = (((int)SDL_JoystickGetAxis(joystick, i)) + 32768);
|
||||
if (i < SDL_GetNumJoystickAxes(joystick)) {
|
||||
y = (((int)SDL_GetJoystickAxis(joystick, i)) + 32768);
|
||||
} else {
|
||||
y = 32768;
|
||||
}
|
||||
@@ -238,9 +238,9 @@ void loop(void *arg)
|
||||
}
|
||||
|
||||
SDL_SetRenderDrawColor(screen, 0x00, 0x00, 0xFF, SDL_ALPHA_OPAQUE);
|
||||
for (i = 0; i < SDL_JoystickNumHats(joystick); ++i) {
|
||||
for (i = 0; i < SDL_GetNumJoystickHats(joystick); ++i) {
|
||||
/* Derive the new position */
|
||||
const Uint8 hat_pos = SDL_JoystickGetHat(joystick, i);
|
||||
const Uint8 hat_pos = SDL_GetJoystickHat(joystick, i);
|
||||
x = SCREEN_WIDTH / 2;
|
||||
y = SCREEN_HEIGHT / 2;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user