Bladeren bron

Added SDL_GetGamepadInstanceID()

Sam Lantinga 1 jaar geleden
bovenliggende
commit
3cbf16b944

+ 14 - 0
include/SDL3/SDL_gamepad.h

@@ -476,6 +476,20 @@ extern DECLSPEC SDL_Gamepad *SDLCALL SDL_GetGamepadFromInstanceID(SDL_JoystickID
  */
 extern DECLSPEC SDL_Gamepad *SDLCALL SDL_GetGamepadFromPlayerIndex(int player_index);
 
+/**
+ * Get the instance ID of an opened gamepad.
+ *
+ * \param gamepad a gamepad identifier previously returned by
+ *                SDL_OpenGamepad()
+ * \returns the instance ID of the specified gamepad on success or 0 on
+ *          failure; call SDL_GetError() for more information.
+ *
+ * \since This function is available since SDL 3.0.0.
+ *
+ * \sa SDL_OpenGamepad
+ */
+extern DECLSPEC SDL_JoystickID SDLCALL SDL_GetGamepadInstanceID(SDL_Gamepad *gamepad);
+
 /**
  * Get the implementation-dependent name for an opened gamepad.
  *

+ 1 - 0
src/dynapi/SDL_dynapi.sym

@@ -869,6 +869,7 @@ SDL3_0.0.0 {
     SDL_wcsstr;
     SDL_wcstol;
     SDL_ClearClipboardData;
+    SDL_GetGamepadInstanceID;
     # extra symbols go here (don't modify this line)
   local: *;
 };

+ 1 - 0
src/dynapi/SDL_dynapi_overrides.h

@@ -895,3 +895,4 @@
 
 /* New API symbols are added at the end */
 #define SDL_ClearClipboardData SDL_ClearClipboardData_REAL
+#define SDL_GetGamepadInstanceID SDL_GetGamepadInstanceID_REAL

+ 1 - 0
src/dynapi/SDL_dynapi_procs.h

@@ -940,3 +940,4 @@ SDL_DYNAPI_PROC(long,SDL_wcstol,(const wchar_t *a, wchar_t **b, int c),(a,b,c),r
 
 /* New API symbols are added at the end */
 SDL_DYNAPI_PROC(int,SDL_ClearClipboardData,(void),(),return)
+SDL_DYNAPI_PROC(SDL_JoystickID,SDL_GetGamepadInstanceID,(SDL_Gamepad *a),(a),return)

+ 10 - 0
src/joystick/SDL_gamepad.c

@@ -2655,6 +2655,16 @@ int SDL_GetGamepadSensorData(SDL_Gamepad *gamepad, SDL_SensorType type, float *d
     return SDL_Unsupported();
 }
 
+SDL_JoystickID SDL_GetGamepadInstanceID(SDL_Gamepad *gamepad)
+{
+    SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad);
+
+    if (joystick == NULL) {
+        return 0;
+    }
+    return SDL_GetJoystickInstanceID(joystick);
+}
+
 const char *SDL_GetGamepadName(SDL_Gamepad *gamepad)
 {
     const char *retval = NULL;