From b4da4ed95a00ccca16fe1fef38ac2d61328514be Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Sun, 4 Dec 2022 09:21:14 -0800
Subject: [PATCH] Removed SDL_SensorGetDataWithTimestamp() and
SDL_GameControllerGetSensorDataWithTimestamp()
If you care about timestamps you'll also want to catch all of the sensor events instead of just polling the current state. For example, Nintendo Switch controllers generate 3 sensor events with distinct values for each polling interval.
---
WhatsNew.txt | 10 ++++++----
docs/README-migration.md | 10 ++++++++++
include/SDL3/SDL_gamecontroller.h | 19 -------------------
include/SDL3/SDL_sensor.h | 17 -----------------
src/dynapi/SDL_dynapi.sym | 2 --
src/dynapi/SDL_dynapi_overrides.h | 2 --
src/dynapi/SDL_dynapi_procs.h | 2 --
src/joystick/SDL_gamecontroller.c | 11 -----------
src/joystick/SDL_joystick.c | 1 -
src/joystick/SDL_sysjoystick.h | 1 -
src/sensor/SDL_sensor.c | 12 ------------
src/sensor/SDL_syssensor.h | 1 -
12 files changed, 16 insertions(+), 72 deletions(-)
diff --git a/WhatsNew.txt b/WhatsNew.txt
index bbcef46f86cc..d2908b076a22 100644
--- a/WhatsNew.txt
+++ b/WhatsNew.txt
@@ -13,16 +13,18 @@ General:
* The preprocessor symbol __IPHONEOS__ has been renamed __IOS__
* Removed the following functions from the API, see docs/README-migration.md for details:
* SDL_CalculateGammaRamp()
+ * SDL_CreateRGBSurface()
+ * SDL_CreateRGBSurfaceFrom()
+ * SDL_CreateRGBSurfaceWithFormat()
+ * SDL_CreateRGBSurfaceWithFormatFrom()
+ * SDL_GameControllerGetSensorDataWithTimestamp()
* SDL_GetRevisionNumber()
* SDL_GetWindowBrightness()
* SDL_GetWindowGammaRamp()
* SDL_RWFromFP()
+ * SDL_SensorGetDataWithTimestamp()
* SDL_SetWindowBrightness()
* SDL_SetWindowGammaRamp()
- * SDL_CreateRGBSurface()
- * SDL_CreateRGBSurfaceWithFormat()
- * SDL_CreateRGBSurfaceFrom()
- * SDL_CreateRGBSurfaceWithFormatFrom()
* Removed the following hints from the API, see docs/README-migration.md for details:
* SDL_HINT_IDLE_TIMER_DISABLED
* SDL_HINT_VIDEO_X11_FORCE_EGL
diff --git a/docs/README-migration.md b/docs/README-migration.md
index 0ee436feea98..993fb7c44a94 100644
--- a/docs/README-migration.md
+++ b/docs/README-migration.md
@@ -40,6 +40,11 @@ The `timestamp_us` member of the sensor events has been renamed `sensor_timestam
You should set the `event.common.timestamp` field before passing an event to `SDL_PushEvent()`. If the timestamp is 0 it will be filled in with `SDL_GetTicksNS()`.
+## SDL_gamecontroller.h
+
+Removed SDL_GameControllerGetSensorDataWithTimestamp(), if you want timestamps for the sensor data, you should use the sensor_timestamp member of SDL_CONTROLLERSENSORUPDATE events.
+
+
## SDL_platform.h
The preprocessor symbol __MACOSX__ has been renamed __MACOS__, and __IPHONEOS__ has been renamed __IOS__
@@ -163,6 +168,11 @@ SDL_RWFromFP(void *fp, SDL_bool autoclose)
+## SDL_sensor.h
+
+Removed SDL_SensorGetDataWithTimestamp(), if you want timestamps for the sensor data, you should use the sensor_timestamp member of SDL_SENSORUPDATE events.
+
+
SDL_stdinc.h
The standard C headers like stdio.h and stdlib.h are no longer included, you should include them directly in your project if you use non-SDL C runtime functions.
diff --git a/include/SDL3/SDL_gamecontroller.h b/include/SDL3/SDL_gamecontroller.h
index d992470252d7…9bd6e6f61091 100644
— a/include/SDL3/SDL_gamecontroller.h
+++ b/include/SDL3/SDL_gamecontroller.h
@@ -895,25 +895,6 @@ extern DECLSPEC float SDLCALL SDL_GameControllerGetSensorDataRate(SDL_GameContro
*/
extern DECLSPEC int SDLCALL SDL_GameControllerGetSensorData(SDL_GameController *gamecontroller, SDL_SensorType type, float *data, int num_values);
-/**
-
- Get the current state of a game controller sensor with the timestamp of the
-
- last update.
-
-
- The number of values and interpretation of the data is sensor dependent.
-
- See SDL_sensor.h for the details for each type of sensor.
-
-
- \param gamecontroller The controller to query
-
- \param type The type of sensor to query
-
- \param timestamp A pointer filled with the timestamp in nanoseconds of the
-
-
current sensor reading, which may not be synchronized with the system clock
-
-
- \param data A pointer filled with the current sensor state
-
- \param num_values The number of values to write to data
-
- \return 0 or -1 if an error occurred.
-
-
- \since This function is available since SDL 3.0.0.
- */
-extern DECLSPEC int SDLCALL SDL_GameControllerGetSensorDataWithTimestamp(SDL_GameController *gamecontroller, SDL_SensorType type, Uint64 *timestamp, float *data, int num_values);
/**
- Start a rumble effect on a game controller.
diff --git a/include/SDL3/SDL_sensor.h b/include/SDL3/SDL_sensor.h
index d99c25fa85d5…c566c75989ef 100644
— a/include/SDL3/SDL_sensor.h
+++ b/include/SDL3/SDL_sensor.h
@@ -269,23 +269,6 @@ extern DECLSPEC SDL_SensorID SDLCALL SDL_SensorGetInstanceID(SDL_Sensor *sensor)
*/
extern DECLSPEC int SDLCALL SDL_SensorGetData(SDL_Sensor *sensor, float *data, int num_values);
-/**
-
- Get the current state of an opened sensor with the timestamp of the last
-
- update.
-
-
- The number of values and interpretation of the data is sensor dependent.
-
-
- \param sensor The SDL_Sensor object to query
-
- \param timestamp A pointer filled with the timestamp in nanoseconds of the
-
-
current sensor reading, which may not be synchronized with the system clock
-
-
- \param data A pointer filled with the current sensor state
-
- \param num_values The number of values to write to data
-
- \returns 0 or -1 if an error occurred.
-
-
- \since This function is available since SDL 3.0.0.
- */
-extern DECLSPEC int SDLCALL SDL_SensorGetDataWithTimestamp(SDL_Sensor *sensor, Uint64 *timestamp, float *data, int num_values);
/**
- Close a sensor previously opened with SDL_SensorOpen().
diff --git a/src/dynapi/SDL_dynapi.sym b/src/dynapi/SDL_dynapi.sym
index d6a110e761d3…d8514dd18a80 100644
— a/src/dynapi/SDL_dynapi.sym
+++ b/src/dynapi/SDL_dynapi.sym
@@ -676,7 +676,6 @@ SDL3_0.0.0 {
SDL_SensorGetNonPortableType;
SDL_SensorGetInstanceID;
SDL_SensorGetData;
- SDL_SensorGetDataWithTimestamp;
SDL_SensorClose;
SDL_SensorUpdate;
SDL_SetHintWithPriority;
@@ -816,7 +815,6 @@ SDL3_0.0.0 {
SDL_GameControllerIsSensorEnabled;
SDL_GameControllerGetSensorDataRate;
SDL_GameControllerGetSensorData; - SDL_GameControllerGetSensorDataWithTimestamp;
SDL_GameControllerRumble;
SDL_GameControllerRumbleTriggers;
SDL_GameControllerHasLED;
diff --git a/src/dynapi/SDL_dynapi_overrides.h b/src/dynapi/SDL_dynapi_overrides.h
index a71417620cef…0984586e638a 100644
— a/src/dynapi/SDL_dynapi_overrides.h
+++ b/src/dynapi/SDL_dynapi_overrides.h
@@ -878,8 +878,6 @@
#define SDL_SetPrimarySelectionText SDL_SetPrimarySelectionText_REAL
#define SDL_GetPrimarySelectionText SDL_GetPrimarySelectionText_REAL
#define SDL_HasPrimarySelectionText SDL_HasPrimarySelectionText_REAL
-#define SDL_GameControllerGetSensorDataWithTimestamp SDL_GameControllerGetSensorDataWithTimestamp_REAL
-#define SDL_SensorGetDataWithTimestamp SDL_SensorGetDataWithTimestamp_REAL
#define SDL_ResetHints SDL_ResetHints_REAL
#define SDL_strcasestr SDL_strcasestr_REAL
#define SDL_EGL_GetProcAddress SDL_EGL_GetProcAddress_REAL
diff --git a/src/dynapi/SDL_dynapi_procs.h b/src/dynapi/SDL_dynapi_procs.h
index 352488ff794e…0ae9be3080ab 100644
— a/src/dynapi/SDL_dynapi_procs.h
+++ b/src/dynapi/SDL_dynapi_procs.h
@@ -952,8 +952,6 @@ SDL_DYNAPI_PROC(void,SDL_GetJoystickGUIDInfo,(SDL_JoystickGUID a, Uint16 *b, Uin
SDL_DYNAPI_PROC(int,SDL_SetPrimarySelectionText,(const char a),(a),return)
SDL_DYNAPI_PROC(char,SDL_GetPrimarySelectionText,(void),(),return)
SDL_DYNAPI_PROC(SDL_bool,SDL_HasPrimarySelectionText,(void),(),return)
-SDL_DYNAPI_PROC(int,SDL_GameControllerGetSensorDataWithTimestamp,(SDL_GameController *a, SDL_SensorType b, Uint64 *c, float *d, int e),(a,b,c,d,e),return)
-SDL_DYNAPI_PROC(int,SDL_SensorGetDataWithTimestamp,(SDL_Sensor *a, Uint64 *b, float c, int d),(a,b,c,d),return)
SDL_DYNAPI_PROC(void,SDL_ResetHints,(void),(),)
SDL_DYNAPI_PROC(char,SDL_strcasestr,(const char *a, const char b),(a,b),return)
SDL_DYNAPI_PROC(void,SDL_EGL_GetProcAddress,(const char *a),(a),return)
diff --git a/src/joystick/SDL_gamecontroller.c b/src/joystick/SDL_gamecontroller.c
index 95519d41be5c…d17ec72c0ff7 100644
— a/src/joystick/SDL_gamecontroller.c
+++ b/src/joystick/SDL_gamecontroller.c
@@ -2431,14 +2431,6 @@ float SDL_GameControllerGetSensorDataRate(SDL_GameController *gamecontroller, SD
- Get the current state of a game controller sensor.
*/
int SDL_GameControllerGetSensorData(SDL_GameController *gamecontroller, SDL_SensorType type, float *data, int num_values)
-{
- return SDL_GameControllerGetSensorDataWithTimestamp(gamecontroller, type, NULL, data, num_values);
-}
-/*
-
- Get the current state of a game controller sensor.
-
*/
-int SDL_GameControllerGetSensorDataWithTimestamp(SDL_GameController *gamecontroller, SDL_SensorType type, Uint64 *timestamp, float *data, int num_values)
{
SDL_Joystick *joystick = SDL_GameControllerGetJoystick(gamecontroller);
int i;
@@ -2453,9 +2445,6 @@ int SDL_GameControllerGetSensorDataWithTimestamp(SDL_GameController *gamecontrol
if (sensor->type == type) {
num_values = SDL_min(num_values, SDL_arraysize(sensor->data));
SDL_memcpy(data, sensor->data, num_values * sizeof(*data)); -
if (timestamp) {
-
*timestamp = sensor->sensor_timestamp;
-
} return 0; }
}
diff --git a/src/joystick/SDL_joystick.c b/src/joystick/SDL_joystick.c
index 44effda6a20c…fe452f8dd881 100644
— a/src/joystick/SDL_joystick.c
+++ b/src/joystick/SDL_joystick.c
@@ -2981,7 +2981,6 @@ int SDL_PrivateJoystickSensor(Uint64 timestamp, SDL_Joystick *joystick, SDL_Sens/* Update internal sensor state */ SDL_memcpy(sensor->data, data, num_values * sizeof(*data));
-
sensor->sensor_timestamp = sensor_timestamp; /* Post the event, if desired */
#if !SDL_EVENTS_DISABLED
diff --git a/src/joystick/SDL_sysjoystick.h b/src/joystick/SDL_sysjoystick.h
index fc840b4403b9…f6ada4aa48c4 100644
— a/src/joystick/SDL_sysjoystick.h
+++ b/src/joystick/SDL_sysjoystick.h
@@ -63,7 +63,6 @@ typedef struct _SDL_JoystickSensorInfo
SDL_bool enabled;
float rate;
float data[3]; /* If this needs to expand, update SDL_ControllerSensorEvent */
- Uint64 sensor_timestamp;
} SDL_JoystickSensorInfo;
struct _SDL_Joystick
diff --git a/src/sensor/SDL_sensor.c b/src/sensor/SDL_sensor.c
index 47ab1690959e…32b93f7c0ad6 100644
— a/src/sensor/SDL_sensor.c
+++ b/src/sensor/SDL_sensor.c
@@ -368,14 +368,6 @@ SDL_SensorGetInstanceID(SDL_Sensor *sensor)
- Get the current state of this sensor
*/
int SDL_SensorGetData(SDL_Sensor *sensor, float *data, int num_values)
-{
- return SDL_SensorGetDataWithTimestamp(sensor, NULL, data, num_values);
-}
-/*
-
- Get the current state of this sensor
-
*/
-int SDL_SensorGetDataWithTimestamp(SDL_Sensor *sensor, Uint64 *timestamp, float *data, int num_values)
{
if (!SDL_PrivateSensorValid(sensor)) {
return -1;
@@ -383,9 +375,6 @@ int SDL_SensorGetDataWithTimestamp(SDL_Sensor *sensor, Uint64 *timestamp, floatnum_values = SDL_min(num_values, SDL_arraysize(sensor->data));
SDL_memcpy(data, sensor->data, num_values * sizeof(*data)); -
if (timestamp) {
-
*timestamp = sensor->sensor_timestamp;
-
}
return 0;
}
@@ -484,7 +473,6 @@ int SDL_PrivateSensorUpdate(Uint64 timestamp, SDL_Sensor sensor, Uint64 sensor_
/ Update internal sensor state */
num_values = SDL_min(num_values, SDL_arraysize(sensor->data));
SDL_memcpy(sensor->data, data, num_values * sizeof(*data));
-
sensor->sensor_timestamp = sensor_timestamp;
/* Post the event, if desired /
posted = 0;
diff --git a/src/sensor/SDL_syssensor.h b/src/sensor/SDL_syssensor.h
index d1fc694aa66c…c33307771820 100644
— a/src/sensor/SDL_syssensor.h
+++ b/src/sensor/SDL_syssensor.h
@@ -35,7 +35,6 @@ struct _SDL_Sensor
SDL_SensorType type; / Type of the sensor /
int non_portable_type; / Platform dependent type of the sensor */ -
Uint64 sensor_timestamp; /* The timestamp of the last sensor update /
float data[16]; / The current state of the sensor */struct _SDL_SensorDriver *driver;