main: Add an optional appstate param to main callback entry points.

This allows apps to maintain state data without using global variables.

Fixes #9377.
This commit is contained in:
Ryan C. Gordon
2024-03-27 17:22:08 -04:00
parent a9dbdb1947
commit 38e3c6a4aa
7 changed files with 57 additions and 32 deletions

View File

@@ -1036,7 +1036,7 @@ static void WindowResized(const int newwinw, const int newwinh)
state->window_h = newwinh;
}
int SDL_AppInit(int argc, char *argv[])
int SDL_AppInit(void **appstate, int argc, char *argv[])
{
int i;
@@ -1094,7 +1094,7 @@ int SDL_AppInit(int argc, char *argv[])
static SDL_bool saw_event = SDL_FALSE;
int SDL_AppEvent(const SDL_Event *event)
int SDL_AppEvent(void *appstate, const SDL_Event *event)
{
Thing *thing = NULL;
@@ -1214,7 +1214,7 @@ int SDL_AppEvent(const SDL_Event *event)
return SDLTest_CommonEventMainCallbacks(state, event);
}
int SDL_AppIterate(void)
int SDL_AppIterate(void *appstate)
{
if (app_ready_ticks == 0) {
app_ready_ticks = SDL_GetTicks();
@@ -1232,7 +1232,7 @@ int SDL_AppIterate(void)
return 0; /* keep going. */
}
void SDL_AppQuit(void)
void SDL_AppQuit(void *appstate)
{
while (things) {
DestroyThing(things); /* make sure all the audio devices are closed, etc. */