Removed SDL_HasGamepads(), SDL_HasJoysticks(), and SDL_HasSensors()

Also cleaned up logic for whether we need to poll for events:
- We need to periodically poll for joysticks to handle hotplug.
- We need to frequently poll for joysticks and sensors when they're open so their state can be updated
This commit is contained in:
Sam Lantinga
2022-12-29 23:07:30 -08:00
parent 7f23d71b6a
commit 324c0b76a0
15 changed files with 64 additions and 153 deletions

View File

@@ -1914,23 +1914,6 @@ int SDL_InitGamepads(void)
return 0;
}
SDL_bool SDL_HasGamepads(void)
{
SDL_bool retval = SDL_FALSE;
SDL_JoystickID *joysticks = SDL_GetJoysticks(NULL);
if (joysticks) {
int i;
for (i = 0; joysticks[i]; ++i) {
if (SDL_IsGamepad(joysticks[i])) {
retval = SDL_TRUE;
break;
}
}
SDL_free(joysticks);
}
return retval;
}
SDL_JoystickID *SDL_GetGamepads(int *count)
{
int num_joysticks = 0;

View File

@@ -332,19 +332,21 @@ int SDL_InitJoysticks(void)
return status;
}
SDL_bool SDL_HasJoysticks(void)
SDL_bool SDL_JoysticksOpened(void)
{
int i;
SDL_bool retval = SDL_FALSE;
SDL_bool opened;
SDL_LockJoysticks();
for (i = 0; i < SDL_arraysize(SDL_joystick_drivers); ++i) {
if (SDL_joystick_drivers[i]->GetCount() > 0) {
retval = SDL_TRUE;
break;
{
if (SDL_joysticks != NULL) {
opened = SDL_TRUE;
} else {
opened = SDL_FALSE;
}
}
SDL_UnlockJoysticks();
return retval;
return opened;
}
SDL_JoystickID *SDL_GetJoysticks(int *count)

View File

@@ -49,6 +49,9 @@ extern SDL_bool SDL_JoysticksLocked(void);
/* Make sure we currently have the joysticks locked */
extern void SDL_AssertJoysticksLocked(void) SDL_ASSERT_CAPABILITY(SDL_joystick_lock);
/* Function to return whether there are any joysticks opened by the application */
extern SDL_bool SDL_JoysticksOpened(void);
/* Function to get the next available joystick instance ID */
extern SDL_JoystickID SDL_GetNextJoystickInstanceID(void);