mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-04-05 07:09:32 +00:00
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:
@@ -42,7 +42,7 @@ static int fillerup(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SDL_AppInit(int argc, char *argv[])
|
||||
int SDL_AppInit(void **appstate, int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
char *filename = NULL;
|
||||
@@ -119,17 +119,17 @@ int SDL_AppInit(int argc, char *argv[])
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SDL_AppEvent(const SDL_Event *event)
|
||||
int SDL_AppEvent(void *appstate, const SDL_Event *event)
|
||||
{
|
||||
return (event->type == SDL_EVENT_QUIT) ? 1 : 0;
|
||||
}
|
||||
|
||||
int SDL_AppIterate(void)
|
||||
int SDL_AppIterate(void *appstate)
|
||||
{
|
||||
return fillerup();
|
||||
}
|
||||
|
||||
void SDL_AppQuit(void)
|
||||
void SDL_AppQuit(void *appstate)
|
||||
{
|
||||
SDL_DestroyAudioStream(stream);
|
||||
SDL_free(wave.sound);
|
||||
|
||||
@@ -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. */
|
||||
|
||||
@@ -21,7 +21,7 @@ static SDL_AudioStream *stream_in = NULL;
|
||||
static SDL_AudioStream *stream_out = NULL;
|
||||
static SDLTest_CommonState *state = NULL;
|
||||
|
||||
int SDL_AppInit(int argc, char **argv)
|
||||
int SDL_AppInit(void **appstate, int argc, char **argv)
|
||||
{
|
||||
SDL_AudioDeviceID *devices;
|
||||
SDL_AudioSpec outspec;
|
||||
@@ -145,7 +145,7 @@ int SDL_AppInit(int argc, char **argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SDL_AppEvent(const SDL_Event *event)
|
||||
int SDL_AppEvent(void *appstate, const SDL_Event *event)
|
||||
{
|
||||
if (event->type == SDL_EVENT_QUIT) {
|
||||
return 1; /* terminate as success. */
|
||||
@@ -169,7 +169,7 @@ int SDL_AppEvent(const SDL_Event *event)
|
||||
return 0; /* keep going. */
|
||||
}
|
||||
|
||||
int SDL_AppIterate(void)
|
||||
int SDL_AppIterate(void *appstate)
|
||||
{
|
||||
if (!SDL_AudioDevicePaused(SDL_GetAudioStreamDevice(stream_in))) {
|
||||
SDL_SetRenderDrawColor(renderer, 0, 255, 0, 255);
|
||||
@@ -195,7 +195,7 @@ int SDL_AppIterate(void)
|
||||
return 0; /* keep app going. */
|
||||
}
|
||||
|
||||
void SDL_AppQuit(void)
|
||||
void SDL_AppQuit(void *appstate)
|
||||
{
|
||||
SDL_Log("Shutting down.\n");
|
||||
const SDL_AudioDeviceID devid_in = SDL_GetAudioStreamDevice(stream_in);
|
||||
|
||||
@@ -26,7 +26,7 @@ static SDL_Surface *frame_current = NULL;
|
||||
static SDL_CameraDeviceID front_camera = 0;
|
||||
static SDL_CameraDeviceID back_camera = 0;
|
||||
|
||||
int SDL_AppInit(int argc, char *argv[])
|
||||
int SDL_AppInit(void **appstate, int argc, char *argv[])
|
||||
{
|
||||
int devcount = 0;
|
||||
int i;
|
||||
@@ -159,7 +159,7 @@ static int FlipCamera(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SDL_AppEvent(const SDL_Event *event)
|
||||
int SDL_AppEvent(void *appstate, const SDL_Event *event)
|
||||
{
|
||||
switch (event->type) {
|
||||
case SDL_EVENT_KEY_DOWN: {
|
||||
@@ -209,7 +209,7 @@ int SDL_AppEvent(const SDL_Event *event)
|
||||
return SDLTest_CommonEventMainCallbacks(state, event);
|
||||
}
|
||||
|
||||
int SDL_AppIterate(void)
|
||||
int SDL_AppIterate(void *appstate)
|
||||
{
|
||||
SDL_SetRenderDrawColor(renderer, 0x99, 0x99, 0x99, 255);
|
||||
SDL_RenderClear(renderer);
|
||||
@@ -262,7 +262,7 @@ int SDL_AppIterate(void)
|
||||
return 0; /* keep iterating. */
|
||||
}
|
||||
|
||||
void SDL_AppQuit(void)
|
||||
void SDL_AppQuit(void *appstate)
|
||||
{
|
||||
SDL_ReleaseCameraFrame(camera, frame_current);
|
||||
SDL_CloseCamera(camera);
|
||||
|
||||
@@ -45,7 +45,7 @@ static SDL_bool suspend_when_occluded;
|
||||
/* -1: infinite random moves (default); >=0: enables N deterministic moves */
|
||||
static int iterations = -1;
|
||||
|
||||
void SDL_AppQuit(void)
|
||||
void SDL_AppQuit(void *appstate)
|
||||
{
|
||||
SDL_free(sprites);
|
||||
SDL_free(positions);
|
||||
@@ -386,12 +386,12 @@ static void MoveSprites(SDL_Renderer *renderer, SDL_Texture *sprite)
|
||||
SDL_RenderPresent(renderer);
|
||||
}
|
||||
|
||||
int SDL_AppEvent(const SDL_Event *event)
|
||||
int SDL_AppEvent(void *appstate, const SDL_Event *event)
|
||||
{
|
||||
return SDLTest_CommonEventMainCallbacks(state, event);
|
||||
}
|
||||
|
||||
int SDL_AppIterate(void)
|
||||
int SDL_AppIterate(void *appstate)
|
||||
{
|
||||
Uint64 now;
|
||||
int i;
|
||||
@@ -425,7 +425,7 @@ int SDL_AppIterate(void)
|
||||
return 0; /* keep going */
|
||||
}
|
||||
|
||||
int SDL_AppInit(int argc, char *argv[])
|
||||
int SDL_AppInit(void **appstate, int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
Uint64 seed;
|
||||
|
||||
Reference in New Issue
Block a user