mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-09-29 14:38:29 +00:00
Use C99 bool internally in SDL
This commit is contained in:
@@ -54,7 +54,7 @@ static
|
||||
SDL_Mutex *SDL_sensor_lock = NULL; // This needs to support recursive locks
|
||||
static SDL_AtomicInt SDL_sensor_lock_pending;
|
||||
static int SDL_sensors_locked;
|
||||
static SDL_bool SDL_sensors_initialized;
|
||||
static bool SDL_sensors_initialized;
|
||||
static SDL_Sensor *SDL_sensors SDL_GUARDED_BY(SDL_sensor_lock) = NULL;
|
||||
|
||||
#define CHECK_SENSOR_MAGIC(sensor, retval) \
|
||||
@@ -64,7 +64,7 @@ static SDL_Sensor *SDL_sensors SDL_GUARDED_BY(SDL_sensor_lock) = NULL;
|
||||
return retval; \
|
||||
}
|
||||
|
||||
SDL_bool SDL_SensorsInitialized(void)
|
||||
bool SDL_SensorsInitialized(void)
|
||||
{
|
||||
return SDL_sensors_initialized;
|
||||
}
|
||||
@@ -80,14 +80,14 @@ void SDL_LockSensors(void)
|
||||
|
||||
void SDL_UnlockSensors(void)
|
||||
{
|
||||
SDL_bool last_unlock = SDL_FALSE;
|
||||
bool last_unlock = false;
|
||||
|
||||
--SDL_sensors_locked;
|
||||
|
||||
if (!SDL_sensors_initialized) {
|
||||
// NOTE: There's a small window here where another thread could lock the mutex after we've checked for pending locks
|
||||
if (!SDL_sensors_locked && SDL_AtomicGet(&SDL_sensor_lock_pending) == 0) {
|
||||
last_unlock = SDL_TRUE;
|
||||
last_unlock = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ void SDL_UnlockSensors(void)
|
||||
}
|
||||
}
|
||||
|
||||
SDL_bool SDL_SensorsLocked(void)
|
||||
bool SDL_SensorsLocked(void)
|
||||
{
|
||||
return (SDL_sensors_locked > 0);
|
||||
}
|
||||
@@ -135,7 +135,7 @@ int SDL_InitSensors(void)
|
||||
|
||||
SDL_LockSensors();
|
||||
|
||||
SDL_sensors_initialized = SDL_TRUE;
|
||||
SDL_sensors_initialized = true;
|
||||
|
||||
status = -1;
|
||||
for (i = 0; i < SDL_arraysize(SDL_sensor_drivers); ++i) {
|
||||
@@ -153,16 +153,16 @@ int SDL_InitSensors(void)
|
||||
return status;
|
||||
}
|
||||
|
||||
SDL_bool SDL_SensorsOpened(void)
|
||||
bool SDL_SensorsOpened(void)
|
||||
{
|
||||
SDL_bool opened;
|
||||
bool opened;
|
||||
|
||||
SDL_LockSensors();
|
||||
{
|
||||
if (SDL_sensors != NULL) {
|
||||
opened = SDL_TRUE;
|
||||
opened = true;
|
||||
} else {
|
||||
opened = SDL_FALSE;
|
||||
opened = false;
|
||||
}
|
||||
}
|
||||
SDL_UnlockSensors();
|
||||
@@ -214,7 +214,7 @@ SDL_SensorID *SDL_GetSensors(int *count)
|
||||
* Get the driver and device index for a sensor instance ID
|
||||
* This should be called while the sensor lock is held, to prevent another thread from updating the list
|
||||
*/
|
||||
static SDL_bool SDL_GetDriverAndSensorIndex(SDL_SensorID instance_id, SDL_SensorDriver **driver, int *driver_index)
|
||||
static bool SDL_GetDriverAndSensorIndex(SDL_SensorID instance_id, SDL_SensorDriver **driver, int *driver_index)
|
||||
{
|
||||
int i, num_sensors, device_index;
|
||||
|
||||
@@ -226,13 +226,13 @@ static SDL_bool SDL_GetDriverAndSensorIndex(SDL_SensorID instance_id, SDL_Sensor
|
||||
if (sensor_id == instance_id) {
|
||||
*driver = SDL_sensor_drivers[i];
|
||||
*driver_index = device_index;
|
||||
return SDL_TRUE;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
SDL_SetError("Sensor %" SDL_PRIu32 " not found", instance_id);
|
||||
return SDL_FALSE;
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -325,14 +325,14 @@ SDL_Sensor *SDL_OpenSensor(SDL_SensorID instance_id)
|
||||
SDL_UnlockSensors();
|
||||
return NULL;
|
||||
}
|
||||
SDL_SetObjectValid(sensor, SDL_OBJECT_TYPE_SENSOR, SDL_TRUE);
|
||||
SDL_SetObjectValid(sensor, SDL_OBJECT_TYPE_SENSOR, true);
|
||||
sensor->driver = driver;
|
||||
sensor->instance_id = instance_id;
|
||||
sensor->type = driver->GetDeviceType(device_index);
|
||||
sensor->non_portable_type = driver->GetDeviceNonPortableType(device_index);
|
||||
|
||||
if (driver->Open(sensor, device_index) < 0) {
|
||||
SDL_SetObjectValid(sensor, SDL_OBJECT_TYPE_SENSOR, SDL_FALSE);
|
||||
SDL_SetObjectValid(sensor, SDL_OBJECT_TYPE_SENSOR, false);
|
||||
SDL_free(sensor);
|
||||
SDL_UnlockSensors();
|
||||
return NULL;
|
||||
@@ -507,7 +507,7 @@ void SDL_CloseSensor(SDL_Sensor *sensor)
|
||||
|
||||
sensor->driver->Close(sensor);
|
||||
sensor->hwdata = NULL;
|
||||
SDL_SetObjectValid(sensor, SDL_OBJECT_TYPE_SENSOR, SDL_FALSE);
|
||||
SDL_SetObjectValid(sensor, SDL_OBJECT_TYPE_SENSOR, false);
|
||||
|
||||
sensorlist = SDL_sensors;
|
||||
sensorlistprev = NULL;
|
||||
@@ -551,7 +551,7 @@ void SDL_QuitSensors(void)
|
||||
|
||||
SDL_QuitSubSystem(SDL_INIT_EVENTS);
|
||||
|
||||
SDL_sensors_initialized = SDL_FALSE;
|
||||
SDL_sensors_initialized = false;
|
||||
|
||||
SDL_UnlockSensors();
|
||||
}
|
||||
|
@@ -36,10 +36,10 @@ extern int SDL_InitSensors(void);
|
||||
extern void SDL_QuitSensors(void);
|
||||
|
||||
// Return whether the sensor system is currently initialized
|
||||
extern SDL_bool SDL_SensorsInitialized(void);
|
||||
extern bool SDL_SensorsInitialized(void);
|
||||
|
||||
// Return whether the sensors are currently locked
|
||||
extern SDL_bool SDL_SensorsLocked(void);
|
||||
extern bool SDL_SensorsLocked(void);
|
||||
|
||||
// Make sure we currently have the sensors locked
|
||||
extern void SDL_AssertSensorsLocked(void) SDL_ASSERT_CAPABILITY(SDL_sensor_lock);
|
||||
@@ -48,7 +48,7 @@ extern void SDL_LockSensors(void) SDL_ACQUIRE(SDL_sensor_lock);
|
||||
extern void SDL_UnlockSensors(void) SDL_RELEASE(SDL_sensor_lock);
|
||||
|
||||
// Function to return whether there are any sensors opened by the application
|
||||
extern SDL_bool SDL_SensorsOpened(void);
|
||||
extern bool SDL_SensorsOpened(void);
|
||||
|
||||
// Update an individual sensor, used by gamepad sensor fusion
|
||||
extern void SDL_UpdateSensor(SDL_Sensor *sensor);
|
||||
|
@@ -93,7 +93,7 @@ static int SDLCALL SDL_ANDROID_SensorThread(void *data)
|
||||
|
||||
static void SDL_ANDROID_StopSensorThread(SDL_AndroidSensorThreadContext *ctx)
|
||||
{
|
||||
SDL_AtomicSet(&ctx->running, SDL_FALSE);
|
||||
SDL_AtomicSet(&ctx->running, false);
|
||||
|
||||
if (ctx->thread) {
|
||||
int result;
|
||||
@@ -119,7 +119,7 @@ static int SDL_ANDROID_StartSensorThread(SDL_AndroidSensorThreadContext *ctx)
|
||||
return -1;
|
||||
}
|
||||
|
||||
SDL_AtomicSet(&ctx->running, SDL_TRUE);
|
||||
SDL_AtomicSet(&ctx->running, true);
|
||||
ctx->thread = SDL_CreateThread(SDL_ANDROID_SensorThread, "Sensors", ctx);
|
||||
if (!ctx->thread) {
|
||||
SDL_ANDROID_StopSensorThread(ctx);
|
||||
|
@@ -42,7 +42,7 @@ static int InitN3DSServices(void);
|
||||
static void UpdateN3DSAccelerometer(SDL_Sensor *sensor);
|
||||
static void UpdateN3DSGyroscope(SDL_Sensor *sensor);
|
||||
|
||||
static SDL_bool IsDeviceIndexValid(int device_index)
|
||||
static bool IsDeviceIndexValid(int device_index)
|
||||
{
|
||||
return device_index >= 0 && device_index < N3DS_SENSOR_COUNT;
|
||||
}
|
||||
|
@@ -52,7 +52,7 @@ typedef struct
|
||||
|
||||
} SDL_Windows_Sensor;
|
||||
|
||||
static SDL_bool SDL_windowscoinit;
|
||||
static bool SDL_windowscoinit;
|
||||
static ISensorManager *SDL_sensor_manager;
|
||||
static int SDL_num_sensors;
|
||||
static SDL_Windows_Sensor *SDL_sensors;
|
||||
@@ -358,7 +358,7 @@ static int SDL_WINDOWS_SensorInit(void)
|
||||
ISensorCollection *sensor_collection = NULL;
|
||||
|
||||
if (WIN_CoInitialize() == S_OK) {
|
||||
SDL_windowscoinit = SDL_TRUE;
|
||||
SDL_windowscoinit = true;
|
||||
}
|
||||
|
||||
hr = CoCreateInstance(&SDL_CLSID_SensorManager, NULL, CLSCTX_INPROC_SERVER, &SDL_IID_SensorManager, (LPVOID *)&SDL_sensor_manager);
|
||||
|
Reference in New Issue
Block a user