main: Make the main callback return value symbols smaller (thanks, @Lzard!).

Reference #9901.
This commit is contained in:
Ryan C. Gordon 2024-05-27 16:03:45 -04:00
parent ef5d56de51
commit 3364aff757
No known key found for this signature in database
GPG key ID: FA148B892AB48044
8 changed files with 85 additions and 85 deletions

View file

@ -224,7 +224,7 @@ typedef void (SDLCALL *SDL_AppQuit_func)(void *appstate);
* *
* \since This macro is available since SDL 3.0.0. * \since This macro is available since SDL 3.0.0.
*/ */
#define SDL_MAIN_CALLBACK_CONTINUE 0 #define SDL_APP_CONTINUE 0
/** /**
* Value that requests termination with error from the main callbacks. * Value that requests termination with error from the main callbacks.
@ -239,7 +239,7 @@ typedef void (SDLCALL *SDL_AppQuit_func)(void *appstate);
* *
* \since This macro is available since SDL 3.0.0. * \since This macro is available since SDL 3.0.0.
*/ */
#define SDL_MAIN_CALLBACK_EXIT_FAILURE -1 #define SDL_APP_FAILURE -1
/** /**
* Value that requests termination with success from the main callbacks. * Value that requests termination with success from the main callbacks.
@ -254,7 +254,7 @@ typedef void (SDLCALL *SDL_AppQuit_func)(void *appstate);
* *
* \since This macro is available since SDL 3.0.0. * \since This macro is available since SDL 3.0.0.
*/ */
#define SDL_MAIN_CALLBACK_EXIT_SUCCESS 1 #define SDL_APP_SUCCESS 1
/** /**
@ -277,12 +277,12 @@ typedef void (SDLCALL *SDL_AppQuit_func)(void *appstate);
* to use a global variable. If this isn't set, the pointer will be NULL in * to use a global variable. If this isn't set, the pointer will be NULL in
* future entry points. * future entry points.
* *
* If this function returns SDL_MAIN_CALLBACK_CONTINUE, the app will proceed * If this function returns SDL_APP_CONTINUE, the app will proceed
* to normal operation, and will begin receiving repeated calls to * to normal operation, and will begin receiving repeated calls to
* SDL_AppIterate and SDL_AppEvent for the life of the program. If this * SDL_AppIterate and SDL_AppEvent for the life of the program. If this
* function returns SDL_MAIN_CALLBACK_EXIT_FAILURE, SDL will call SDL_AppQuit * function returns SDL_APP_FAILURE, SDL will call SDL_AppQuit
* and terminate the process with an exit code that reports an error to the * and terminate the process with an exit code that reports an error to the
* platform. If it returns SDL_MAIN_CALLBACK_EXIT_SUCCESS, SDL calls * platform. If it returns SDL_APP_SUCCESS, SDL calls
* SDL_AppQuit and terminates with an exit code that reports success to the * SDL_AppQuit and terminates with an exit code that reports success to the
* platform. * platform.
* *
@ -291,9 +291,9 @@ typedef void (SDLCALL *SDL_AppQuit_func)(void *appstate);
* \param argc The standard ANSI C main's argc; number of elements in `argv` * \param argc The standard ANSI C main's argc; number of elements in `argv`
* \param argv The standard ANSI C main's argv; array of command line * \param argv The standard ANSI C main's argv; array of command line
* arguments. * arguments.
* \returns SDL_MAIN_CALLBACK_EXIT_FAILURE to terminate with an error, * \returns SDL_APP_FAILURE to terminate with an error,
* SDL_MAIN_CALLBACK_EXIT_SUCCESS to terminate with success, * SDL_APP_SUCCESS to terminate with success,
* SDL_MAIN_CALLBACK_CONTINUE to continue. * SDL_APP_CONTINUE to continue.
* *
* \threadsafety This function is not thread safe. * \threadsafety This function is not thread safe.
* *
@ -332,18 +332,18 @@ extern SDLMAIN_DECLSPEC int SDLCALL SDL_AppInit(void **appstate, int argc, char
* The `appstate` parameter is an optional pointer provided by the app during * The `appstate` parameter is an optional pointer provided by the app during
* SDL_AppInit(). If the app never provided a pointer, this will be NULL. * SDL_AppInit(). If the app never provided a pointer, this will be NULL.
* *
* If this function returns SDL_MAIN_CALLBACK_CONTINUE, the app will continue * If this function returns SDL_APP_CONTINUE, the app will continue
* normal operation, receiving repeated calls to SDL_AppIterate and * normal operation, receiving repeated calls to SDL_AppIterate and
* SDL_AppEvent for the life of the program. If this function returns * SDL_AppEvent for the life of the program. If this function returns
* SDL_MAIN_CALLBACK_EXIT_FAILURE, SDL will call SDL_AppQuit and terminate the * SDL_APP_FAILURE, SDL will call SDL_AppQuit and terminate the
* process with an exit code that reports an error to the platform. If it * process with an exit code that reports an error to the platform. If it
* returns SDL_MAIN_CALLBACK_EXIT_SUCCESS, SDL calls SDL_AppQuit and * returns SDL_APP_SUCCESS, SDL calls SDL_AppQuit and
* terminates with an exit code that reports success to the platform. * terminates with an exit code that reports success to the platform.
* *
* \param appstate an optional pointer, provided by the app in SDL_AppInit. * \param appstate an optional pointer, provided by the app in SDL_AppInit.
* \returns SDL_MAIN_CALLBACK_EXIT_FAILURE to terminate with an error, * \returns SDL_APP_FAILURE to terminate with an error,
* SDL_MAIN_CALLBACK_EXIT_SUCCESS to terminate with success, * SDL_APP_SUCCESS to terminate with success,
* SDL_MAIN_CALLBACK_CONTINUE to continue. * SDL_APP_CONTINUE to continue.
* *
* \threadsafety This function is not thread safe. * \threadsafety This function is not thread safe.
* *
@ -379,19 +379,19 @@ extern SDLMAIN_DECLSPEC int SDLCALL SDL_AppIterate(void *appstate);
* The `appstate` parameter is an optional pointer provided by the app during * The `appstate` parameter is an optional pointer provided by the app during
* SDL_AppInit(). If the app never provided a pointer, this will be NULL. * SDL_AppInit(). If the app never provided a pointer, this will be NULL.
* *
* If this function returns SDL_MAIN_CALLBACK_CONTINUE, the app will continue * If this function returns SDL_APP_CONTINUE, the app will continue
* normal operation, receiving repeated calls to SDL_AppIterate and * normal operation, receiving repeated calls to SDL_AppIterate and
* SDL_AppEvent for the life of the program. If this function returns * SDL_AppEvent for the life of the program. If this function returns
* SDL_MAIN_CALLBACK_EXIT_FAILURE, SDL will call SDL_AppQuit and terminate the * SDL_APP_FAILURE, SDL will call SDL_AppQuit and terminate the
* process with an exit code that reports an error to the platform. If it * process with an exit code that reports an error to the platform. If it
* returns SDL_MAIN_CALLBACK_EXIT_SUCCESS, SDL calls SDL_AppQuit and * returns SDL_APP_SUCCESS, SDL calls SDL_AppQuit and
* terminates with an exit code that reports success to the platform. * terminates with an exit code that reports success to the platform.
* *
* \param appstate an optional pointer, provided by the app in SDL_AppInit. * \param appstate an optional pointer, provided by the app in SDL_AppInit.
* \param event the new event for the app to examine. * \param event the new event for the app to examine.
* \returns SDL_MAIN_CALLBACK_EXIT_FAILURE to terminate with an error, * \returns SDL_APP_FAILURE to terminate with an error,
* SDL_MAIN_CALLBACK_EXIT_SUCCESS to terminate with success, * SDL_APP_SUCCESS to terminate with success,
* SDL_MAIN_CALLBACK_CONTINUE to continue. * SDL_APP_CONTINUE to continue.
* *
* \threadsafety This function is not thread safe. * \threadsafety This function is not thread safe.
* *

View file

@ -2404,19 +2404,19 @@ int SDLTest_CommonEventMainCallbacks(SDLTest_CommonState *state, const SDL_Event
} }
break; break;
case SDLK_ESCAPE: case SDLK_ESCAPE:
return SDL_MAIN_CALLBACK_EXIT_SUCCESS; return SDL_APP_SUCCESS;
default: default:
break; break;
} }
break; break;
} }
case SDL_EVENT_QUIT: case SDL_EVENT_QUIT:
return SDL_MAIN_CALLBACK_EXIT_SUCCESS; return SDL_APP_SUCCESS;
default: default:
break; break;
} }
return SDL_MAIN_CALLBACK_CONTINUE; return SDL_APP_CONTINUE;
} }
void SDLTest_CommonEvent(SDLTest_CommonState *state, SDL_Event *event, int *done) void SDLTest_CommonEvent(SDLTest_CommonState *state, SDL_Event *event, int *done)

View file

@ -39,7 +39,7 @@ static int fillerup(void)
if (SDL_GetAudioStreamQueued(stream) < minimum) { if (SDL_GetAudioStreamQueued(stream) < minimum) {
SDL_PutAudioStreamData(stream, wave.sound, wave.soundlen); SDL_PutAudioStreamData(stream, wave.sound, wave.soundlen);
} }
return SDL_MAIN_CALLBACK_CONTINUE; return SDL_APP_CONTINUE;
} }
int SDL_AppInit(void **appstate, int argc, char *argv[]) int SDL_AppInit(void **appstate, int argc, char *argv[])
@ -53,7 +53,7 @@ int SDL_AppInit(void **appstate, int argc, char *argv[])
/* Initialize test framework */ /* Initialize test framework */
state = SDLTest_CommonCreateState(argv, 0); state = SDLTest_CommonCreateState(argv, 0);
if (!state) { if (!state) {
return SDL_MAIN_CALLBACK_EXIT_SUCCESS; return SDL_APP_SUCCESS;
} }
/* Enable standard application logging */ /* Enable standard application logging */
@ -82,21 +82,21 @@ int SDL_AppInit(void **appstate, int argc, char *argv[])
/* Load the SDL library */ /* Load the SDL library */
if (SDL_Init(SDL_INIT_AUDIO | SDL_INIT_EVENTS) < 0) { if (SDL_Init(SDL_INIT_AUDIO | SDL_INIT_EVENTS) < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
return SDL_MAIN_CALLBACK_EXIT_FAILURE; return SDL_APP_FAILURE;
} }
filename = GetResourceFilename(filename, "sample.wav"); filename = GetResourceFilename(filename, "sample.wav");
if (!filename) { if (!filename) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s\n", SDL_GetError());
return SDL_MAIN_CALLBACK_EXIT_FAILURE; return SDL_APP_FAILURE;
} }
/* Load the wave file into memory */ /* Load the wave file into memory */
if (SDL_LoadWAV(filename, &wave.spec, &wave.sound, &wave.soundlen) == -1) { if (SDL_LoadWAV(filename, &wave.spec, &wave.sound, &wave.soundlen) == -1) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s\n", filename, SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s\n", filename, SDL_GetError());
SDL_free(filename); SDL_free(filename);
return SDL_MAIN_CALLBACK_EXIT_FAILURE; return SDL_APP_FAILURE;
} }
SDL_free(filename); SDL_free(filename);
@ -112,16 +112,16 @@ int SDL_AppInit(void **appstate, int argc, char *argv[])
stream = SDL_OpenAudioDeviceStream(SDL_AUDIO_DEVICE_DEFAULT_OUTPUT, &wave.spec, NULL, NULL); stream = SDL_OpenAudioDeviceStream(SDL_AUDIO_DEVICE_DEFAULT_OUTPUT, &wave.spec, NULL, NULL);
if (!stream) { if (!stream) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create audio stream: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create audio stream: %s\n", SDL_GetError());
return SDL_MAIN_CALLBACK_EXIT_FAILURE; return SDL_APP_FAILURE;
} }
SDL_ResumeAudioDevice(SDL_GetAudioStreamDevice(stream)); SDL_ResumeAudioDevice(SDL_GetAudioStreamDevice(stream));
return SDL_MAIN_CALLBACK_CONTINUE; return SDL_APP_CONTINUE;
} }
int SDL_AppEvent(void *appstate, const SDL_Event *event) int SDL_AppEvent(void *appstate, const SDL_Event *event)
{ {
return (event->type == SDL_EVENT_QUIT) ? SDL_MAIN_CALLBACK_EXIT_SUCCESS : SDL_MAIN_CALLBACK_CONTINUE; return (event->type == SDL_EVENT_QUIT) ? SDL_APP_SUCCESS : SDL_APP_CONTINUE;
} }
int SDL_AppIterate(void *appstate) int SDL_AppIterate(void *appstate)

View file

@ -1042,7 +1042,7 @@ int SDL_AppInit(void **appstate, int argc, char *argv[])
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO | SDL_INIT_AUDIO); state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO | SDL_INIT_AUDIO);
if (!state) { if (!state) {
return SDL_MAIN_CALLBACK_EXIT_FAILURE; return SDL_APP_FAILURE;
} }
state->window_flags |= SDL_WINDOW_RESIZABLE; state->window_flags |= SDL_WINDOW_RESIZABLE;
@ -1060,13 +1060,13 @@ int SDL_AppInit(void **appstate, int argc, char *argv[])
NULL NULL
}; };
SDLTest_CommonLogUsage(state, argv[0], options); SDLTest_CommonLogUsage(state, argv[0], options);
return SDL_MAIN_CALLBACK_EXIT_FAILURE; return SDL_APP_FAILURE;
} }
i += consumed; i += consumed;
} }
if (!SDLTest_CommonInit(state)) { if (!SDLTest_CommonInit(state)) {
return SDL_MAIN_CALLBACK_EXIT_FAILURE; return SDL_APP_FAILURE;
} }
if (state->audio_id) { if (state->audio_id) {
@ -1088,7 +1088,7 @@ int SDL_AppInit(void **appstate, int argc, char *argv[])
CreateDefaultPhysicalDevice(SDL_FALSE); CreateDefaultPhysicalDevice(SDL_FALSE);
CreateDefaultPhysicalDevice(SDL_TRUE); CreateDefaultPhysicalDevice(SDL_TRUE);
return SDL_MAIN_CALLBACK_CONTINUE; return SDL_APP_CONTINUE;
} }
@ -1229,7 +1229,7 @@ int SDL_AppIterate(void *appstate)
SDL_Delay(10); SDL_Delay(10);
} }
return SDL_MAIN_CALLBACK_CONTINUE; return SDL_APP_CONTINUE;
} }
void SDL_AppQuit(void *appstate) void SDL_AppQuit(void *appstate)

View file

@ -37,7 +37,7 @@ int SDL_AppInit(void **appstate, int argc, char **argv)
/* Initialize test framework */ /* Initialize test framework */
state = SDLTest_CommonCreateState(argv, 0); state = SDLTest_CommonCreateState(argv, 0);
if (!state) { if (!state) {
return SDL_MAIN_CALLBACK_EXIT_SUCCESS; return SDL_APP_SUCCESS;
} }
/* Enable standard application logging */ /* Enable standard application logging */
@ -57,7 +57,7 @@ int SDL_AppInit(void **appstate, int argc, char **argv)
if (consumed <= 0) { if (consumed <= 0) {
static const char *options[] = { "[device_name]", NULL }; static const char *options[] = { "[device_name]", NULL };
SDLTest_CommonLogUsage(state, argv[0], options); SDLTest_CommonLogUsage(state, argv[0], options);
return SDL_MAIN_CALLBACK_EXIT_FAILURE; return SDL_APP_FAILURE;
} }
i += consumed; i += consumed;
@ -66,12 +66,12 @@ int SDL_AppInit(void **appstate, int argc, char **argv)
/* Load the SDL library */ /* Load the SDL library */
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) { if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
return SDL_MAIN_CALLBACK_EXIT_SUCCESS; return SDL_APP_SUCCESS;
} }
if (SDL_CreateWindowAndRenderer("testaudiocapture", 320, 240, 0, &window, &renderer) < 0) { if (SDL_CreateWindowAndRenderer("testaudiocapture", 320, 240, 0, &window, &renderer) < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create SDL window and renderer: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create SDL window and renderer: %s\n", SDL_GetError());
return SDL_MAIN_CALLBACK_EXIT_SUCCESS; return SDL_APP_SUCCESS;
} }
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255); SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
SDL_RenderClear(renderer); SDL_RenderClear(renderer);
@ -104,17 +104,17 @@ int SDL_AppInit(void **appstate, int argc, char **argv)
device = SDL_OpenAudioDevice(SDL_AUDIO_DEVICE_DEFAULT_OUTPUT, NULL); device = SDL_OpenAudioDevice(SDL_AUDIO_DEVICE_DEFAULT_OUTPUT, NULL);
if (!device) { if (!device) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't open an audio device for playback: %s!\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't open an audio device for playback: %s!\n", SDL_GetError());
return SDL_MAIN_CALLBACK_EXIT_FAILURE; return SDL_APP_FAILURE;
} }
SDL_PauseAudioDevice(device); SDL_PauseAudioDevice(device);
SDL_GetAudioDeviceFormat(device, &outspec, NULL); SDL_GetAudioDeviceFormat(device, &outspec, NULL);
stream_out = SDL_CreateAudioStream(&outspec, &outspec); stream_out = SDL_CreateAudioStream(&outspec, &outspec);
if (!stream_out) { if (!stream_out) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create an audio stream for playback: %s!\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create an audio stream for playback: %s!\n", SDL_GetError());
return SDL_MAIN_CALLBACK_EXIT_FAILURE; return SDL_APP_FAILURE;
} else if (SDL_BindAudioStream(device, stream_out) == -1) { } else if (SDL_BindAudioStream(device, stream_out) == -1) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't bind an audio stream for playback: %s!\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't bind an audio stream for playback: %s!\n", SDL_GetError());
return SDL_MAIN_CALLBACK_EXIT_FAILURE; return SDL_APP_FAILURE;
} }
SDL_Log("Opening capture device %s%s%s...\n", SDL_Log("Opening capture device %s%s%s...\n",
@ -125,33 +125,33 @@ int SDL_AppInit(void **appstate, int argc, char **argv)
device = SDL_OpenAudioDevice(want_device, NULL); device = SDL_OpenAudioDevice(want_device, NULL);
if (!device) { if (!device) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't open an audio device for capture: %s!\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't open an audio device for capture: %s!\n", SDL_GetError());
return SDL_MAIN_CALLBACK_EXIT_FAILURE; return SDL_APP_FAILURE;
} }
SDL_PauseAudioDevice(device); SDL_PauseAudioDevice(device);
SDL_GetAudioDeviceFormat(device, &inspec, NULL); SDL_GetAudioDeviceFormat(device, &inspec, NULL);
stream_in = SDL_CreateAudioStream(&inspec, &inspec); stream_in = SDL_CreateAudioStream(&inspec, &inspec);
if (!stream_in) { if (!stream_in) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create an audio stream for capture: %s!\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create an audio stream for capture: %s!\n", SDL_GetError());
return SDL_MAIN_CALLBACK_EXIT_FAILURE; return SDL_APP_FAILURE;
} else if (SDL_BindAudioStream(device, stream_in) == -1) { } else if (SDL_BindAudioStream(device, stream_in) == -1) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't bind an audio stream for capture: %s!\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't bind an audio stream for capture: %s!\n", SDL_GetError());
return SDL_MAIN_CALLBACK_EXIT_FAILURE; return SDL_APP_FAILURE;
} }
SDL_SetAudioStreamFormat(stream_in, NULL, &outspec); /* make sure we output at the playback format. */ SDL_SetAudioStreamFormat(stream_in, NULL, &outspec); /* make sure we output at the playback format. */
SDL_Log("Ready! Hold down mouse or finger to record!\n"); SDL_Log("Ready! Hold down mouse or finger to record!\n");
return SDL_MAIN_CALLBACK_CONTINUE; return SDL_APP_CONTINUE;
} }
int SDL_AppEvent(void *appstate, const SDL_Event *event) int SDL_AppEvent(void *appstate, const SDL_Event *event)
{ {
if (event->type == SDL_EVENT_QUIT) { if (event->type == SDL_EVENT_QUIT) {
return SDL_MAIN_CALLBACK_EXIT_SUCCESS; return SDL_APP_SUCCESS;
} else if (event->type == SDL_EVENT_KEY_DOWN) { } else if (event->type == SDL_EVENT_KEY_DOWN) {
if (event->key.keysym.sym == SDLK_ESCAPE) { if (event->key.keysym.sym == SDLK_ESCAPE) {
return SDL_MAIN_CALLBACK_EXIT_SUCCESS; return SDL_APP_SUCCESS;
} }
} else if (event->type == SDL_EVENT_MOUSE_BUTTON_DOWN) { } else if (event->type == SDL_EVENT_MOUSE_BUTTON_DOWN) {
if (event->button.button == 1) { if (event->button.button == 1) {
@ -166,7 +166,7 @@ int SDL_AppEvent(void *appstate, const SDL_Event *event)
SDL_ResumeAudioDevice(SDL_GetAudioStreamDevice(stream_out)); SDL_ResumeAudioDevice(SDL_GetAudioStreamDevice(stream_out));
} }
} }
return SDL_MAIN_CALLBACK_CONTINUE; return SDL_APP_CONTINUE;
} }
int SDL_AppIterate(void *appstate) int SDL_AppIterate(void *appstate)
@ -185,14 +185,14 @@ int SDL_AppIterate(void *appstate)
const int br = SDL_GetAudioStreamData(stream_in, buf, sizeof(buf)); const int br = SDL_GetAudioStreamData(stream_in, buf, sizeof(buf));
if (br < 0) { if (br < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to read from input audio stream: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to read from input audio stream: %s\n", SDL_GetError());
return SDL_MAIN_CALLBACK_EXIT_FAILURE; return SDL_APP_FAILURE;
} else if (SDL_PutAudioStreamData(stream_out, buf, br) < 0) { } else if (SDL_PutAudioStreamData(stream_out, buf, br) < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to write to output audio stream: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to write to output audio stream: %s\n", SDL_GetError());
return SDL_MAIN_CALLBACK_EXIT_FAILURE; return SDL_APP_FAILURE;
} }
} }
return SDL_MAIN_CALLBACK_CONTINUE; return SDL_APP_CONTINUE;
} }
void SDL_AppQuit(void *appstate) void SDL_AppQuit(void *appstate)

View file

@ -34,14 +34,14 @@ int SDL_AppInit(void **appstate, int argc, char *argv[])
/* Initialize test framework */ /* Initialize test framework */
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO | SDL_INIT_CAMERA); state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO | SDL_INIT_CAMERA);
if (!state) { if (!state) {
return SDL_MAIN_CALLBACK_EXIT_FAILURE; return SDL_APP_FAILURE;
} }
/* Enable standard application logging */ /* Enable standard application logging */
SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
if (!SDLTest_CommonDefaultArgs(state, argc, argv)) { if (!SDLTest_CommonDefaultArgs(state, argc, argv)) {
return SDL_MAIN_CALLBACK_EXIT_FAILURE; return SDL_APP_FAILURE;
} }
state->num_windows = 1; state->num_windows = 1;
@ -49,13 +49,13 @@ int SDL_AppInit(void **appstate, int argc, char *argv[])
/* Load the SDL library */ /* Load the SDL library */
if (!SDLTest_CommonInit(state)) { if (!SDLTest_CommonInit(state)) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s", SDL_GetError());
return SDL_MAIN_CALLBACK_EXIT_FAILURE; return SDL_APP_FAILURE;
} }
window = state->windows[0]; window = state->windows[0];
if (!window) { if (!window) {
SDL_Log("Couldn't create window: %s", SDL_GetError()); SDL_Log("Couldn't create window: %s", SDL_GetError());
return SDL_MAIN_CALLBACK_EXIT_FAILURE; return SDL_APP_FAILURE;
} }
SDL_SetLogPriorities(SDL_LOG_PRIORITY_VERBOSE); SDL_SetLogPriorities(SDL_LOG_PRIORITY_VERBOSE);
@ -63,13 +63,13 @@ int SDL_AppInit(void **appstate, int argc, char *argv[])
renderer = state->renderers[0]; renderer = state->renderers[0];
if (!renderer) { if (!renderer) {
/* SDL_Log("Couldn't create renderer: %s", SDL_GetError()); */ /* SDL_Log("Couldn't create renderer: %s", SDL_GetError()); */
return SDL_MAIN_CALLBACK_EXIT_FAILURE; return SDL_APP_FAILURE;
} }
SDL_CameraDeviceID *devices = SDL_GetCameraDevices(&devcount); SDL_CameraDeviceID *devices = SDL_GetCameraDevices(&devcount);
if (!devices) { if (!devices) {
SDL_Log("SDL_GetCameraDevices failed: %s", SDL_GetError()); SDL_Log("SDL_GetCameraDevices failed: %s", SDL_GetError());
return SDL_MAIN_CALLBACK_EXIT_FAILURE; return SDL_APP_FAILURE;
} }
SDL_Log("Saw %d camera devices.", devcount); SDL_Log("Saw %d camera devices.", devcount);
@ -94,7 +94,7 @@ int SDL_AppInit(void **appstate, int argc, char *argv[])
if (!devid) { if (!devid) {
SDL_Log("No cameras available?"); SDL_Log("No cameras available?");
return SDL_MAIN_CALLBACK_EXIT_FAILURE; return SDL_APP_FAILURE;
} }
SDL_CameraSpec *pspec = &spec; SDL_CameraSpec *pspec = &spec;
@ -104,10 +104,10 @@ int SDL_AppInit(void **appstate, int argc, char *argv[])
camera = SDL_OpenCameraDevice(devid, pspec); camera = SDL_OpenCameraDevice(devid, pspec);
if (!camera) { if (!camera) {
SDL_Log("Failed to open camera device: %s", SDL_GetError()); SDL_Log("Failed to open camera device: %s", SDL_GetError());
return SDL_MAIN_CALLBACK_EXIT_FAILURE; return SDL_APP_FAILURE;
} }
return SDL_MAIN_CALLBACK_CONTINUE; return SDL_APP_CONTINUE;
} }
@ -115,7 +115,7 @@ static int FlipCamera(void)
{ {
static Uint64 last_flip = 0; static Uint64 last_flip = 0;
if ((SDL_GetTicks() - last_flip) < 3000) { /* must wait at least 3 seconds between flips. */ if ((SDL_GetTicks() - last_flip) < 3000) { /* must wait at least 3 seconds between flips. */
return SDL_MAIN_CALLBACK_CONTINUE; return SDL_APP_CONTINUE;
} }
if (camera) { if (camera) {
@ -145,14 +145,14 @@ static int FlipCamera(void)
camera = SDL_OpenCameraDevice(nextcam, NULL); camera = SDL_OpenCameraDevice(nextcam, NULL);
if (!camera) { if (!camera) {
SDL_Log("Failed to open camera device: %s", SDL_GetError()); SDL_Log("Failed to open camera device: %s", SDL_GetError());
return SDL_MAIN_CALLBACK_EXIT_FAILURE; return SDL_APP_FAILURE;
} }
last_flip = SDL_GetTicks(); last_flip = SDL_GetTicks();
} }
} }
return SDL_MAIN_CALLBACK_CONTINUE; return SDL_APP_CONTINUE;
} }
int SDL_AppEvent(void *appstate, const SDL_Event *event) int SDL_AppEvent(void *appstate, const SDL_Event *event)
@ -162,10 +162,10 @@ int SDL_AppEvent(void *appstate, const SDL_Event *event)
const SDL_Keycode sym = event->key.keysym.sym; const SDL_Keycode sym = event->key.keysym.sym;
if (sym == SDLK_ESCAPE || sym == SDLK_AC_BACK) { if (sym == SDLK_ESCAPE || sym == SDLK_AC_BACK) {
SDL_Log("Key : Escape!"); SDL_Log("Key : Escape!");
return SDL_MAIN_CALLBACK_EXIT_SUCCESS; return SDL_APP_SUCCESS;
} else if (sym == SDLK_SPACE) { } else if (sym == SDLK_SPACE) {
FlipCamera(); FlipCamera();
return SDL_MAIN_CALLBACK_CONTINUE; return SDL_APP_CONTINUE;
} }
break; break;
} }
@ -182,7 +182,7 @@ int SDL_AppEvent(void *appstate, const SDL_Event *event)
SDL_Log("Camera approved!"); SDL_Log("Camera approved!");
if (SDL_GetCameraFormat(camera, &spec) < 0) { if (SDL_GetCameraFormat(camera, &spec) < 0) {
SDL_Log("Couldn't get camera spec: %s", SDL_GetError()); SDL_Log("Couldn't get camera spec: %s", SDL_GetError());
return SDL_MAIN_CALLBACK_EXIT_FAILURE; return SDL_APP_FAILURE;
} }
/* Resize the window to match */ /* Resize the window to match */
@ -193,14 +193,14 @@ int SDL_AppEvent(void *appstate, const SDL_Event *event)
texture = SDL_CreateTexture(renderer, spec.format, SDL_TEXTUREACCESS_STREAMING, spec.width, spec.height); texture = SDL_CreateTexture(renderer, spec.format, SDL_TEXTUREACCESS_STREAMING, spec.width, spec.height);
if (!texture) { if (!texture) {
SDL_Log("Couldn't create texture: %s", SDL_GetError()); SDL_Log("Couldn't create texture: %s", SDL_GetError());
return SDL_MAIN_CALLBACK_EXIT_FAILURE; return SDL_APP_FAILURE;
} }
break; break;
case SDL_EVENT_CAMERA_DEVICE_DENIED: case SDL_EVENT_CAMERA_DEVICE_DENIED:
SDL_Log("Camera denied!"); SDL_Log("Camera denied!");
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Camera permission denied!", "User denied access to the camera!", window); SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Camera permission denied!", "User denied access to the camera!", window);
return SDL_MAIN_CALLBACK_EXIT_FAILURE; return SDL_APP_FAILURE;
default: default:
break; break;
} }
@ -258,7 +258,7 @@ int SDL_AppIterate(void *appstate)
SDL_RenderPresent(renderer); SDL_RenderPresent(renderer);
return SDL_MAIN_CALLBACK_CONTINUE; return SDL_APP_CONTINUE;
} }
void SDL_AppQuit(void *appstate) void SDL_AppQuit(void *appstate)

View file

@ -63,7 +63,7 @@ int SDL_AppIterate(void *appstate)
} }
SDL_RenderPresent(renderer); SDL_RenderPresent(renderer);
} }
return SDL_MAIN_CALLBACK_CONTINUE; return SDL_APP_CONTINUE;
} }
int SDL_AppInit(void **appstate, int argc, char *argv[]) { int SDL_AppInit(void **appstate, int argc, char *argv[]) {
@ -74,7 +74,7 @@ int SDL_AppInit(void **appstate, int argc, char *argv[]) {
/* Initialize test framework */ /* Initialize test framework */
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO); state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
if (!state) { if (!state) {
return SDL_MAIN_CALLBACK_EXIT_FAILURE; return SDL_APP_FAILURE;
} }
/* Enable standard application logging */ /* Enable standard application logging */
@ -107,10 +107,10 @@ int SDL_AppInit(void **appstate, int argc, char *argv[]) {
*appstate = dialog; *appstate = dialog;
dialog->state = state; dialog->state = state;
return SDL_MAIN_CALLBACK_CONTINUE; return SDL_APP_CONTINUE;
onerror: onerror:
SDLTest_CommonQuit(state); SDLTest_CommonQuit(state);
return SDL_MAIN_CALLBACK_EXIT_FAILURE; return SDL_APP_FAILURE;
} }
void SDL_AppQuit(void *appstate) void SDL_AppQuit(void *appstate)

View file

@ -422,7 +422,7 @@ int SDL_AppIterate(void *appstate)
frames = 0; frames = 0;
} }
return SDL_MAIN_CALLBACK_CONTINUE; return SDL_APP_CONTINUE;
} }
int SDL_AppInit(void **appstate, int argc, char *argv[]) int SDL_AppInit(void **appstate, int argc, char *argv[])
@ -437,7 +437,7 @@ int SDL_AppInit(void **appstate, int argc, char *argv[])
/* Initialize test framework */ /* Initialize test framework */
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO); state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
if (!state) { if (!state) {
return SDL_MAIN_CALLBACK_EXIT_FAILURE; return SDL_APP_FAILURE;
} }
for (i = 1; i < argc;) { for (i = 1; i < argc;) {
@ -495,7 +495,7 @@ int SDL_AppInit(void **appstate, int argc, char *argv[])
* Use an 'indices' array */ * Use an 'indices' array */
use_rendergeometry = 2; use_rendergeometry = 2;
} else { } else {
return SDL_MAIN_CALLBACK_EXIT_FAILURE; return SDL_APP_FAILURE;
} }
} }
consumed = 2; consumed = 2;
@ -520,12 +520,12 @@ int SDL_AppInit(void **appstate, int argc, char *argv[])
NULL NULL
}; };
SDLTest_CommonLogUsage(state, argv[0], options); SDLTest_CommonLogUsage(state, argv[0], options);
return SDL_MAIN_CALLBACK_EXIT_FAILURE; return SDL_APP_FAILURE;
} }
i += consumed; i += consumed;
} }
if (!SDLTest_CommonInit(state)) { if (!SDLTest_CommonInit(state)) {
return SDL_MAIN_CALLBACK_EXIT_FAILURE; return SDL_APP_FAILURE;
} }
/* Create the windows, initialize the renderers, and load the textures */ /* Create the windows, initialize the renderers, and load the textures */
@ -533,7 +533,7 @@ int SDL_AppInit(void **appstate, int argc, char *argv[])
(SDL_Texture **)SDL_malloc(state->num_windows * sizeof(*sprites)); (SDL_Texture **)SDL_malloc(state->num_windows * sizeof(*sprites));
if (!sprites) { if (!sprites) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!\n"); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!\n");
return SDL_MAIN_CALLBACK_EXIT_FAILURE; return SDL_APP_FAILURE;
} }
for (i = 0; i < state->num_windows; ++i) { for (i = 0; i < state->num_windows; ++i) {
SDL_Renderer *renderer = state->renderers[i]; SDL_Renderer *renderer = state->renderers[i];
@ -541,7 +541,7 @@ int SDL_AppInit(void **appstate, int argc, char *argv[])
SDL_RenderClear(renderer); SDL_RenderClear(renderer);
} }
if (LoadSprite(icon) < 0) { if (LoadSprite(icon) < 0) {
return SDL_MAIN_CALLBACK_EXIT_FAILURE; return SDL_APP_FAILURE;
} }
/* Allocate memory for the sprite info */ /* Allocate memory for the sprite info */
@ -549,7 +549,7 @@ int SDL_AppInit(void **appstate, int argc, char *argv[])
velocities = (SDL_FRect *)SDL_malloc(num_sprites * sizeof(*velocities)); velocities = (SDL_FRect *)SDL_malloc(num_sprites * sizeof(*velocities));
if (!positions || !velocities) { if (!positions || !velocities) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!\n"); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!\n");
return SDL_MAIN_CALLBACK_EXIT_FAILURE; return SDL_APP_FAILURE;
} }
/* Position sprites and set their velocities using the fuzzer */ /* Position sprites and set their velocities using the fuzzer */
@ -578,6 +578,6 @@ int SDL_AppInit(void **appstate, int argc, char *argv[])
frames = 0; frames = 0;
next_fps_check = SDL_GetTicks() + fps_check_delay; next_fps_check = SDL_GetTicks() + fps_check_delay;
return SDL_MAIN_CALLBACK_CONTINUE; return SDL_APP_CONTINUE;
} }