From 5416bd5fdc42ee78daa80136bc93095eb7af2bbb Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Wed, 12 Jun 2024 15:07:39 -0400 Subject: [PATCH] ios: Move animation callback to its own typedef. --- docs/README-ios.md | 2 +- include/SDL3/SDL_system.h | 18 +++++++++++++++++- src/dynapi/SDL_dynapi_procs.h | 2 +- src/dynapi/SDL_dynapi_unsupported.h | 4 ++++ src/video/SDL_video_unsupported.c | 5 +++-- src/video/uikit/SDL_uikitwindow.m | 2 +- 6 files changed, 27 insertions(+), 6 deletions(-) diff --git a/docs/README-ios.md b/docs/README-ios.md index 838d5f5b6..d2838acf4 100644 --- a/docs/README-ios.md +++ b/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. diff --git a/include/SDL3/SDL_system.h b/include/SDL3/SDL_system.h index f5bbb559f..17db87032 100644 --- a/include/SDL3/SDL_system.h +++ b/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. diff --git a/src/dynapi/SDL_dynapi_procs.h b/src/dynapi/SDL_dynapi_procs.h index 40296ea97..e695212a9 100644 --- a/src/dynapi/SDL_dynapi_procs.h +++ b/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) diff --git a/src/dynapi/SDL_dynapi_unsupported.h b/src/dynapi/SDL_dynapi_unsupported.h index af6cd5f3c..272cd5e08 100644 --- a/src/dynapi/SDL_dynapi_unsupported.h +++ b/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 diff --git a/src/video/SDL_video_unsupported.c b/src/video/SDL_video_unsupported.c index 43bdc5985..23a951f62 100644 --- a/src/video/SDL_video_unsupported.c +++ b/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; diff --git a/src/video/uikit/SDL_uikitwindow.m b/src/video/uikit/SDL_uikitwindow.m index 452b90ca8..b443695d6 100644 --- a/src/video/uikit/SDL_uikitwindow.m +++ b/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");