Changed main callback return values to an enumeration

Fixes https://github.com/libsdl-org/SDL/issues/10515
This commit is contained in:
Sam Lantinga
2024-08-16 09:54:35 -07:00
parent 83adcb9d38
commit 438a214420
24 changed files with 180 additions and 207 deletions

View File

@@ -66,6 +66,25 @@ typedef Uint32 SDL_InitFlags;
#define SDL_INIT_SENSOR 0x00008000u /**< `SDL_INIT_SENSOR` implies `SDL_INIT_EVENTS` */
#define SDL_INIT_CAMERA 0x00010000u /**< `SDL_INIT_CAMERA` implies `SDL_INIT_EVENTS` */
/**
* Return values for optional main callbacks.
*
* See https://wiki.libsdl.org/SDL3/README/main-functions#main-callbacks-in-sdl3 for details.
*
* \since This enum is available since SDL 3.0.0.
*/
typedef enum SDL_AppResult
{
SDL_APP_CONTINUE, /** Value that requests that the app continue from the main callbacks. If SDL_AppInit, SDL_AppEvent, or SDL_AppIterate returns this value, the program will continue to run. */
SDL_APP_SUCCESS, /** Value that requests termination with success from the main callbacks. If SDL_AppInit, SDL_AppEvent, or SDL_AppIterate returns this value, the program will terminate and report success to the operating system. What that success looks like is platform-dependent. On Unix, for example, the process error code will be zero. */
SDL_APP_FAILURE /** Value that requests termination with error from the main callbacks. If SDL_AppInit, SDL_AppEvent, or SDL_AppIterate returns this value, the program will terminate and report failure to the operating system. What that failure looks like is platform-dependent. On Unix, for example, the process error code will be non-zero. */
} SDL_AppResult;
typedef SDL_AppResult (SDLCALL *SDL_AppInit_func)(void **appstate, int argc, char *argv[]);
typedef SDL_AppResult (SDLCALL *SDL_AppIterate_func)(void *appstate);
typedef SDL_AppResult (SDLCALL *SDL_AppEvent_func)(void *appstate, const SDL_Event *event);
typedef void (SDLCALL *SDL_AppQuit_func)(void *appstate);
/**
* Initialize the SDL library.
*

View File

@@ -188,16 +188,12 @@
#define main SDL_main
#endif
#include <SDL3/SDL_init.h>
#include <SDL3/SDL_begin_code.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef int (SDLCALL *SDL_AppInit_func)(void **appstate, int argc, char *argv[]);
typedef int (SDLCALL *SDL_AppIterate_func)(void *appstate);
typedef int (SDLCALL *SDL_AppEvent_func)(void *appstate, const SDL_Event *event);
typedef void (SDLCALL *SDL_AppQuit_func)(void *appstate);
/*
* You can (optionally!) define SDL_MAIN_USE_CALLBACKS before including
* SDL_main.h, and then your application will _not_ have a standard
@@ -224,49 +220,6 @@ typedef void (SDLCALL *SDL_AppQuit_func)(void *appstate);
*/
#ifdef SDL_MAIN_USE_CALLBACKS
/**
* Value that requests that the app continue from the main callbacks.
*
* If SDL_AppInit, SDL_AppEvent, or SDL_AppIterate returns this value, the
* program will continue to run. This is the normal return value case.
*
* This is always 0; using this macro may be clearer, but is not required.
*
* \since This macro is available since SDL 3.0.0.
*/
#define SDL_APP_CONTINUE 0
/**
* Value that requests termination with error from the main callbacks.
*
* If SDL_AppInit, SDL_AppEvent, or SDL_AppIterate returns this value, the
* program will terminate and report failure to the operating system.
*
* What that failure looks like is platform-dependent. On Unix, for example,
* the process error code will be non-zero.
*
* This is always -1; using this macro may be clearer, but is not required.
*
* \since This macro is available since SDL 3.0.0.
*/
#define SDL_APP_FAILURE -1
/**
* Value that requests termination with success from the main callbacks.
*
* If SDL_AppInit, SDL_AppEvent, or SDL_AppIterate returns this value, the
* program will terminate and report success to the operating system.
*
* What that success looks like is platform-dependent. On Unix, for example,
* the process error code will be zero.
*
* This is always 1; using this macro may be clearer, but is not required.
*
* \since This macro is available since SDL 3.0.0.
*/
#define SDL_APP_SUCCESS 1
/**
* App-implemented initial entry point for SDL_MAIN_USE_CALLBACKS apps.
*
@@ -311,7 +264,7 @@ typedef void (SDLCALL *SDL_AppQuit_func)(void *appstate);
* \sa SDL_AppEvent
* \sa SDL_AppQuit
*/
extern SDLMAIN_DECLSPEC int SDLCALL SDL_AppInit(void **appstate, int argc, char *argv[]);
extern SDLMAIN_DECLSPEC SDL_AppResult SDLCALL SDL_AppInit(void **appstate, int argc, char *argv[]);
/**
* App-implemented iteration entry point for SDL_MAIN_USE_CALLBACKS apps.
@@ -359,7 +312,7 @@ extern SDLMAIN_DECLSPEC int SDLCALL SDL_AppInit(void **appstate, int argc, char
* \sa SDL_AppInit
* \sa SDL_AppEvent
*/
extern SDLMAIN_DECLSPEC int SDLCALL SDL_AppIterate(void *appstate);
extern SDLMAIN_DECLSPEC SDL_AppResult SDLCALL SDL_AppIterate(void *appstate);
/**
* App-implemented event entry point for SDL_MAIN_USE_CALLBACKS apps.
@@ -406,7 +359,7 @@ extern SDLMAIN_DECLSPEC int SDLCALL SDL_AppIterate(void *appstate);
* \sa SDL_AppInit
* \sa SDL_AppIterate
*/
extern SDLMAIN_DECLSPEC int SDLCALL SDL_AppEvent(void *appstate, const SDL_Event *event);
extern SDLMAIN_DECLSPEC SDL_AppResult SDLCALL SDL_AppEvent(void *appstate, const SDL_Event *event);
/**
* App-implemented deinit entry point for SDL_MAIN_USE_CALLBACKS apps.

View File

@@ -234,7 +234,7 @@ void SDLTest_CommonEvent(SDLTest_CommonState *state, SDL_Event *event, int *done
* \param event The event to handle.
* \returns Value suitable for returning from SDL_AppEvent().
*/
int SDLTest_CommonEventMainCallbacks(SDLTest_CommonState *state, const SDL_Event *event);
SDL_AppResult SDLTest_CommonEventMainCallbacks(SDLTest_CommonState *state, const SDL_Event *event);
/**
* Close test window.