Browse Source

ios: Move animation callback to its own typedef.

Ryan C. Gordon 10 months ago
parent
commit
5416bd5fdc

+ 1 - 1
docs/README-ios.md

@@ -225,7 +225,7 @@ Game Center
 
 Game Center integration might require that you break up your main loop in order to yield control back to the system. In other words, instead of running an endless main loop, you run each frame in a callback function, using:
 
-    int SDL_iOSSetAnimationCallback(SDL_Window * window, int interval, void (*callback)(void*), void *callbackParam);
+    int SDL_iOSSetAnimationCallback(SDL_Window * window, int interval, SDL_iOSAnimationCallback callback, void *callbackParam);
 
 This will set up the given function to be called back on the animation callback, and then you have to return from main() to let the Cocoa event loop run.
 

+ 17 - 1
include/SDL3/SDL_system.h

@@ -191,6 +191,22 @@ extern SDL_DECLSPEC int SDLCALL SDL_LinuxSetThreadPriorityAndPolicy(Sint64 threa
  */
 #ifdef SDL_PLATFORM_IOS
 
+/**
+ * The prototype for an Apple iOS animation callback.
+ *
+ * This datatype is only useful on Apple iOS.
+ *
+ * After passing a function pointer of this type to SDL_iOSSetAnimationCallback,
+ * the system will call that function pointer at a regular interval.
+ *
+ * \param userdata what was passed as `callbackParam` to SDL_iOSSetAnimationCallback as `callbackParam`.
+ *
+ * \since This datatype is available since SDL 3.0.0.
+ *
+ * \sa SDL_iOSSetAnimationCallback
+ */
+typedef void (SDLCALL *SDL_iOSAnimationCallback)(void *userdata);
+
 /**
  * Use this function to set the animation callback on Apple iOS.
  *
@@ -228,7 +244,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_LinuxSetThreadPriorityAndPolicy(Sint64 threa
  *
  * \sa SDL_iOSSetEventPump
  */
-extern SDL_DECLSPEC int SDLCALL SDL_iOSSetAnimationCallback(SDL_Window * window, int interval, void (SDLCALL *callback)(void*), void *callbackParam);
+extern SDL_DECLSPEC int SDLCALL SDL_iOSSetAnimationCallback(SDL_Window * window, int interval, SDL_iOSAnimationCallback callback, void *callbackParam);
 
 /**
  * Use this function to enable or disable the SDL event pump on Apple iOS.

+ 1 - 1
src/dynapi/SDL_dynapi_procs.h

@@ -950,7 +950,7 @@ SDL_DYNAPI_PROC(int,SDL_hid_read_timeout,(SDL_hid_device *a, unsigned char *b, s
 SDL_DYNAPI_PROC(int,SDL_hid_send_feature_report,(SDL_hid_device *a, const unsigned char *b, size_t c),(a,b,c),return)
 SDL_DYNAPI_PROC(int,SDL_hid_set_nonblocking,(SDL_hid_device *a, int b),(a,b),return)
 SDL_DYNAPI_PROC(int,SDL_hid_write,(SDL_hid_device *a, const unsigned char *b, size_t c),(a,b,c),return)
-SDL_DYNAPI_PROC(int,SDL_iOSSetAnimationCallback,(SDL_Window *a, int b, void (SDLCALL *c)(void*), void *d),(a,b,c,d),return)
+SDL_DYNAPI_PROC(int,SDL_iOSSetAnimationCallback,(SDL_Window *a, int b, SDL_iOSAnimationCallback c, void *d),(a,b,c,d),return)
 SDL_DYNAPI_PROC(void,SDL_iOSSetEventPump,(SDL_bool a),(a),)
 SDL_DYNAPI_PROC(size_t,SDL_iconv,(SDL_iconv_t a, const char **b, size_t *c, char **d, size_t *e),(a,b,c,d,e),return)
 SDL_DYNAPI_PROC(int,SDL_iconv_close,(SDL_iconv_t a),(a),return)

+ 4 - 0
src/dynapi/SDL_dynapi_unsupported.h

@@ -49,4 +49,8 @@ typedef struct XUserHandle XUserHandle;
 typedef void *SDL_AndroidRequestPermissionCallback;
 #endif
 
+#ifndef SDL_PLATFORM_IOS
+typedef void *SDL_iOSAnimationCallback;
+#endif
+
 #endif

+ 3 - 2
src/video/SDL_video_unsupported.c

@@ -93,8 +93,9 @@ void SDL_OnApplicationDidChangeStatusBarOrientation(void)
 
 #ifndef SDL_VIDEO_DRIVER_UIKIT
 
-SDL_DECLSPEC int SDLCALL SDL_iOSSetAnimationCallback(SDL_Window *window, int interval, void (*callback)(void *), void *callbackParam);
-int SDL_iOSSetAnimationCallback(SDL_Window *window, int interval, void (*callback)(void *), void *callbackParam)
+typedef void (SDLCALL *SDL_iOSAnimationCallback)(void *userdata);
+SDL_DECLSPEC int SDLCALL SDL_iOSSetAnimationCallback(SDL_Window *window, int interval, SDL_iOSAnimationCallback callback, void *callbackParam);
+int SDL_iOSSetAnimationCallback(SDL_Window *window, int interval, SDL_iOSAnimationCallback callback, void *callbackParam)
 {
     (void)window;
     (void)interval;

+ 1 - 1
src/video/uikit/SDL_uikitwindow.m

@@ -449,7 +449,7 @@ UIKit_GetSupportedOrientations(SDL_Window *window)
 }
 #endif /* !SDL_PLATFORM_TVOS */
 
-int SDL_iOSSetAnimationCallback(SDL_Window *window, int interval, void (*callback)(void *), void *callbackParam)
+int SDL_iOSSetAnimationCallback(SDL_Window *window, int interval, SDL_iOSAnimationCallback callback, void *callbackParam)
 {
     if (!window || !window->driverdata) {
         return SDL_SetError("Invalid window");