mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-08-28 17:41:38 +00:00
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:
@@ -409,8 +409,6 @@ SDL3_0.0.0 {
|
||||
SDL_HasClipboardText;
|
||||
SDL_HasEvent;
|
||||
SDL_HasEvents;
|
||||
SDL_HasGamepads;
|
||||
SDL_HasJoysticks;
|
||||
SDL_HasLASX;
|
||||
SDL_HasLSX;
|
||||
SDL_HasMMX;
|
||||
@@ -425,7 +423,6 @@ SDL3_0.0.0 {
|
||||
SDL_HasSSE42;
|
||||
SDL_HasSSE;
|
||||
SDL_HasScreenKeyboardSupport;
|
||||
SDL_HasSensors;
|
||||
SDL_HideCursor;
|
||||
SDL_HideWindow;
|
||||
SDL_Init;
|
||||
|
||||
@@ -435,8 +435,6 @@
|
||||
#define SDL_HasClipboardText SDL_HasClipboardText_REAL
|
||||
#define SDL_HasEvent SDL_HasEvent_REAL
|
||||
#define SDL_HasEvents SDL_HasEvents_REAL
|
||||
#define SDL_HasGamepads SDL_HasGamepads_REAL
|
||||
#define SDL_HasJoysticks SDL_HasJoysticks_REAL
|
||||
#define SDL_HasLASX SDL_HasLASX_REAL
|
||||
#define SDL_HasLSX SDL_HasLSX_REAL
|
||||
#define SDL_HasMMX SDL_HasMMX_REAL
|
||||
@@ -451,7 +449,6 @@
|
||||
#define SDL_HasSSE41 SDL_HasSSE41_REAL
|
||||
#define SDL_HasSSE42 SDL_HasSSE42_REAL
|
||||
#define SDL_HasScreenKeyboardSupport SDL_HasScreenKeyboardSupport_REAL
|
||||
#define SDL_HasSensors SDL_HasSensors_REAL
|
||||
#define SDL_HideCursor SDL_HideCursor_REAL
|
||||
#define SDL_HideWindow SDL_HideWindow_REAL
|
||||
#define SDL_Init SDL_Init_REAL
|
||||
|
||||
@@ -507,8 +507,6 @@ SDL_DYNAPI_PROC(SDL_bool,SDL_HasAltiVec,(void),(),return)
|
||||
SDL_DYNAPI_PROC(SDL_bool,SDL_HasClipboardText,(void),(),return)
|
||||
SDL_DYNAPI_PROC(SDL_bool,SDL_HasEvent,(Uint32 a),(a),return)
|
||||
SDL_DYNAPI_PROC(SDL_bool,SDL_HasEvents,(Uint32 a, Uint32 b),(a,b),return)
|
||||
SDL_DYNAPI_PROC(SDL_bool,SDL_HasGamepads,(void),(),return)
|
||||
SDL_DYNAPI_PROC(SDL_bool,SDL_HasJoysticks,(void),(),return)
|
||||
SDL_DYNAPI_PROC(SDL_bool,SDL_HasLASX,(void),(),return)
|
||||
SDL_DYNAPI_PROC(SDL_bool,SDL_HasLSX,(void),(),return)
|
||||
SDL_DYNAPI_PROC(SDL_bool,SDL_HasMMX,(void),(),return)
|
||||
@@ -523,7 +521,6 @@ SDL_DYNAPI_PROC(SDL_bool,SDL_HasSSE3,(void),(),return)
|
||||
SDL_DYNAPI_PROC(SDL_bool,SDL_HasSSE41,(void),(),return)
|
||||
SDL_DYNAPI_PROC(SDL_bool,SDL_HasSSE42,(void),(),return)
|
||||
SDL_DYNAPI_PROC(SDL_bool,SDL_HasScreenKeyboardSupport,(void),(),return)
|
||||
SDL_DYNAPI_PROC(SDL_bool,SDL_HasSensors,(void),(),return)
|
||||
SDL_DYNAPI_PROC(int,SDL_HideCursor,(void),(),return)
|
||||
SDL_DYNAPI_PROC(void,SDL_HideWindow,(SDL_Window *a),(a),)
|
||||
SDL_DYNAPI_PROC(int,SDL_Init,(Uint32 a),(a),return)
|
||||
|
||||
@@ -28,6 +28,9 @@
|
||||
#if !SDL_JOYSTICK_DISABLED
|
||||
#include "../joystick/SDL_joystick_c.h"
|
||||
#endif
|
||||
#if !SDL_SENSOR_DISABLED
|
||||
#include "../sensor/SDL_sensor_c.h"
|
||||
#endif
|
||||
#include "../video/SDL_sysvideo.h"
|
||||
#include <SDL3/SDL_syswm.h>
|
||||
|
||||
@@ -99,19 +102,9 @@ static struct
|
||||
|
||||
static SDL_bool SDL_update_joysticks = SDL_TRUE;
|
||||
|
||||
static void SDL_CalculateShouldUpdateJoysticks(SDL_bool hint_value)
|
||||
{
|
||||
if (hint_value &&
|
||||
(!SDL_disabled_events[SDL_JOYAXISMOTION >> 8] || SDL_JoystickEventsEnabled())) {
|
||||
SDL_update_joysticks = SDL_TRUE;
|
||||
} else {
|
||||
SDL_update_joysticks = SDL_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
static void SDLCALL SDL_AutoUpdateJoysticksChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
|
||||
{
|
||||
SDL_CalculateShouldUpdateJoysticks(SDL_GetStringBoolean(hint, SDL_TRUE));
|
||||
SDL_update_joysticks = SDL_GetStringBoolean(hint, SDL_TRUE);
|
||||
}
|
||||
|
||||
#endif /* !SDL_JOYSTICK_DISABLED */
|
||||
@@ -120,19 +113,9 @@ static void SDLCALL SDL_AutoUpdateJoysticksChanged(void *userdata, const char *n
|
||||
|
||||
static SDL_bool SDL_update_sensors = SDL_TRUE;
|
||||
|
||||
static void SDL_CalculateShouldUpdateSensors(SDL_bool hint_value)
|
||||
{
|
||||
if (hint_value &&
|
||||
!SDL_disabled_events[SDL_SENSORUPDATE >> 8]) {
|
||||
SDL_update_sensors = SDL_TRUE;
|
||||
} else {
|
||||
SDL_update_sensors = SDL_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
static void SDLCALL SDL_AutoUpdateSensorsChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
|
||||
{
|
||||
SDL_CalculateShouldUpdateSensors(SDL_GetStringBoolean(hint, SDL_TRUE));
|
||||
SDL_update_sensors = SDL_GetStringBoolean(hint, SDL_TRUE);
|
||||
}
|
||||
|
||||
#endif /* !SDL_SENSOR_DISABLED */
|
||||
@@ -908,13 +891,7 @@ static SDL_bool SDL_events_need_periodic_poll()
|
||||
SDL_bool need_periodic_poll = SDL_FALSE;
|
||||
|
||||
#if !SDL_JOYSTICK_DISABLED
|
||||
need_periodic_poll =
|
||||
SDL_WasInit(SDL_INIT_JOYSTICK) && SDL_update_joysticks;
|
||||
#endif
|
||||
|
||||
#if !SDL_SENSOR_DISABLED
|
||||
need_periodic_poll = need_periodic_poll ||
|
||||
(SDL_WasInit(SDL_INIT_SENSOR) && SDL_update_sensors);
|
||||
need_periodic_poll = SDL_WasInit(SDL_INIT_JOYSTICK) && SDL_update_joysticks;
|
||||
#endif
|
||||
|
||||
return need_periodic_poll;
|
||||
@@ -997,12 +974,12 @@ static SDL_bool SDL_events_need_polling()
|
||||
SDL_bool need_polling = SDL_FALSE;
|
||||
|
||||
#if !SDL_JOYSTICK_DISABLED
|
||||
need_polling = SDL_WasInit(SDL_INIT_JOYSTICK) && SDL_update_joysticks && SDL_HasJoysticks();
|
||||
need_polling = SDL_WasInit(SDL_INIT_JOYSTICK) && SDL_update_joysticks && SDL_JoysticksOpened();
|
||||
#endif
|
||||
|
||||
#if !SDL_SENSOR_DISABLED
|
||||
need_polling = need_polling ||
|
||||
(SDL_WasInit(SDL_INIT_SENSOR) && SDL_update_sensors && SDL_HasSensors());
|
||||
(SDL_WasInit(SDL_INIT_SENSOR) && SDL_update_sensors && SDL_SensorsOpened());
|
||||
#endif
|
||||
|
||||
return need_polling;
|
||||
@@ -1293,13 +1270,6 @@ void SDL_SetEventEnabled(Uint32 type, SDL_bool enabled)
|
||||
}
|
||||
}
|
||||
|
||||
#if !SDL_JOYSTICK_DISABLED
|
||||
SDL_CalculateShouldUpdateJoysticks(SDL_GetHintBoolean(SDL_HINT_AUTO_UPDATE_JOYSTICKS, SDL_TRUE));
|
||||
#endif
|
||||
#if !SDL_SENSOR_DISABLED
|
||||
SDL_CalculateShouldUpdateSensors(SDL_GetHintBoolean(SDL_HINT_AUTO_UPDATE_SENSORS, SDL_TRUE));
|
||||
#endif
|
||||
|
||||
/* turn off drag'n'drop support if we've disabled the events.
|
||||
This might change some UI details at the OS level. */
|
||||
if (type == SDL_DROPFILE || type == SDL_DROPTEXT) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -51,7 +51,6 @@ static SDL_SensorDriver *SDL_sensor_drivers[] = {
|
||||
static SDL_mutex *SDL_sensor_lock = NULL; /* This needs to support recursive locks */
|
||||
static SDL_Sensor *SDL_sensors SDL_GUARDED_BY(SDL_sensor_lock) = NULL;
|
||||
static SDL_atomic_t SDL_last_sensor_instance_id SDL_GUARDED_BY(SDL_sensor_lock);
|
||||
static SDL_bool SDL_updating_sensor SDL_GUARDED_BY(SDL_sensor_lock) = SDL_FALSE;
|
||||
|
||||
void SDL_LockSensors(void) SDL_ACQUIRE(SDL_sensor_lock)
|
||||
{
|
||||
@@ -87,19 +86,21 @@ int SDL_InitSensors(void)
|
||||
return status;
|
||||
}
|
||||
|
||||
SDL_bool SDL_HasSensors(void)
|
||||
SDL_bool SDL_SensorsOpened(void)
|
||||
{
|
||||
int i;
|
||||
SDL_bool retval = SDL_FALSE;
|
||||
SDL_bool opened;
|
||||
|
||||
SDL_LockSensors();
|
||||
for (i = 0; i < SDL_arraysize(SDL_sensor_drivers); ++i) {
|
||||
if (SDL_sensor_drivers[i]->GetCount() > 0) {
|
||||
retval = SDL_TRUE;
|
||||
break;
|
||||
{
|
||||
if (SDL_sensors != NULL) {
|
||||
opened = SDL_TRUE;
|
||||
} else {
|
||||
opened = SDL_FALSE;
|
||||
}
|
||||
}
|
||||
SDL_UnlockSensors();
|
||||
return retval;
|
||||
|
||||
return opened;
|
||||
}
|
||||
|
||||
SDL_SensorID *SDL_GetSensors(int *count)
|
||||
@@ -413,11 +414,6 @@ void SDL_CloseSensor(SDL_Sensor *sensor)
|
||||
return;
|
||||
}
|
||||
|
||||
if (SDL_updating_sensor) {
|
||||
SDL_UnlockSensors();
|
||||
return;
|
||||
}
|
||||
|
||||
sensor->driver->Close(sensor);
|
||||
sensor->hwdata = NULL;
|
||||
|
||||
@@ -451,9 +447,6 @@ void SDL_QuitSensors(void)
|
||||
|
||||
SDL_LockSensors();
|
||||
|
||||
/* Make sure we're not getting called in the middle of updating sensors */
|
||||
SDL_assert(!SDL_updating_sensor);
|
||||
|
||||
/* Stop the event polling */
|
||||
while (SDL_sensors) {
|
||||
SDL_sensors->ref_count = 1;
|
||||
@@ -510,7 +503,7 @@ int SDL_SendSensorUpdate(Uint64 timestamp, SDL_Sensor *sensor, Uint64 sensor_tim
|
||||
void SDL_UpdateSensors(void)
|
||||
{
|
||||
int i;
|
||||
SDL_Sensor *sensor, *next;
|
||||
SDL_Sensor *sensor;
|
||||
|
||||
if (!SDL_WasInit(SDL_INIT_SENSOR)) {
|
||||
return;
|
||||
@@ -518,28 +511,10 @@ void SDL_UpdateSensors(void)
|
||||
|
||||
SDL_LockSensors();
|
||||
|
||||
if (SDL_updating_sensor) {
|
||||
/* The sensors are already being updated */
|
||||
SDL_UnlockSensors();
|
||||
return;
|
||||
}
|
||||
|
||||
SDL_updating_sensor = SDL_TRUE;
|
||||
|
||||
for (sensor = SDL_sensors; sensor; sensor = sensor->next) {
|
||||
sensor->driver->Update(sensor);
|
||||
}
|
||||
|
||||
SDL_updating_sensor = SDL_FALSE;
|
||||
|
||||
/* If any sensors were closed while updating, free them here */
|
||||
for (sensor = SDL_sensors; sensor; sensor = next) {
|
||||
next = sensor->next;
|
||||
if (sensor->ref_count <= 0) {
|
||||
SDL_CloseSensor(sensor);
|
||||
}
|
||||
}
|
||||
|
||||
/* this needs to happen AFTER walking the sensor list above, so that any
|
||||
dangling hardware data from removed devices can be free'd
|
||||
*/
|
||||
|
||||
@@ -37,6 +37,9 @@ extern void SDL_QuitSensors(void);
|
||||
extern void SDL_LockSensors(void);
|
||||
extern void SDL_UnlockSensors(void);
|
||||
|
||||
/* Function to return whether there are any sensors opened by the application */
|
||||
extern SDL_bool SDL_SensorsOpened(void);
|
||||
|
||||
/* Internal event queueing functions */
|
||||
extern int SDL_SendSensorUpdate(Uint64 timestamp, SDL_Sensor *sensor, Uint64 sensor_timestamp, float *data, int num_values);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user