mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-04-05 07:09:32 +00:00
Changed main callback return values to an enumeration
Fixes https://github.com/libsdl-org/SDL/issues/10515
This commit is contained in:
@@ -46,8 +46,8 @@ static SDL_bool ShouldDispatchImmediately(SDL_Event *event)
|
||||
|
||||
static void SDL_DispatchMainCallbackEvent(SDL_Event *event)
|
||||
{
|
||||
if (SDL_AtomicGet(&apprc) == 0) { // if already quitting, don't send the event to the app.
|
||||
SDL_AtomicCompareAndSwap(&apprc, 0, SDL_main_event_callback(SDL_main_appstate, event));
|
||||
if (SDL_AtomicGet(&apprc) == SDL_APP_CONTINUE) { // if already quitting, don't send the event to the app.
|
||||
SDL_AtomicCompareAndSwap(&apprc, SDL_APP_CONTINUE, SDL_main_event_callback(SDL_main_appstate, event));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,23 +89,23 @@ SDL_bool SDL_HasMainCallbacks(void)
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
int SDL_InitMainCallbacks(int argc, char* argv[], SDL_AppInit_func appinit, SDL_AppIterate_func appiter, SDL_AppEvent_func appevent, SDL_AppQuit_func appquit)
|
||||
SDL_AppResult SDL_InitMainCallbacks(int argc, char* argv[], SDL_AppInit_func appinit, SDL_AppIterate_func appiter, SDL_AppEvent_func appevent, SDL_AppQuit_func appquit)
|
||||
{
|
||||
SDL_main_iteration_callback = appiter;
|
||||
SDL_main_event_callback = appevent;
|
||||
SDL_main_quit_callback = appquit;
|
||||
SDL_AtomicSet(&apprc, 0);
|
||||
SDL_AtomicSet(&apprc, SDL_APP_CONTINUE);
|
||||
|
||||
const int rc = appinit(&SDL_main_appstate, argc, argv);
|
||||
if (SDL_AtomicCompareAndSwap(&apprc, 0, rc) && (rc == 0)) { // bounce if SDL_AppInit already said abort, otherwise...
|
||||
const SDL_AppResult rc = appinit(&SDL_main_appstate, argc, argv);
|
||||
if (SDL_AtomicCompareAndSwap(&apprc, SDL_APP_CONTINUE, rc) && (rc == SDL_APP_CONTINUE)) { // bounce if SDL_AppInit already said abort, otherwise...
|
||||
// make sure we definitely have events initialized, even if the app didn't do it.
|
||||
if (SDL_InitSubSystem(SDL_INIT_EVENTS) == -1) {
|
||||
SDL_AtomicSet(&apprc, -1);
|
||||
SDL_AtomicSet(&apprc, SDL_APP_FAILURE);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (SDL_AddEventWatch(SDL_MainCallbackEventWatcher, NULL) < 0) {
|
||||
SDL_AtomicSet(&apprc, -1);
|
||||
SDL_AtomicSet(&apprc, SDL_APP_FAILURE);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@@ -113,17 +113,17 @@ int SDL_InitMainCallbacks(int argc, char* argv[], SDL_AppInit_func appinit, SDL_
|
||||
return SDL_AtomicGet(&apprc);
|
||||
}
|
||||
|
||||
int SDL_IterateMainCallbacks(SDL_bool pump_events)
|
||||
SDL_AppResult SDL_IterateMainCallbacks(SDL_bool pump_events)
|
||||
{
|
||||
if (pump_events) {
|
||||
SDL_PumpEvents();
|
||||
}
|
||||
SDL_DispatchMainCallbackEvents();
|
||||
|
||||
int rc = SDL_AtomicGet(&apprc);
|
||||
if (rc == 0) {
|
||||
SDL_AppResult rc = SDL_AtomicGet(&apprc);
|
||||
if (rc == SDL_APP_CONTINUE) {
|
||||
rc = SDL_main_iteration_callback(SDL_main_appstate);
|
||||
if (!SDL_AtomicCompareAndSwap(&apprc, 0, rc)) {
|
||||
if (!SDL_AtomicCompareAndSwap(&apprc, SDL_APP_CONTINUE, rc)) {
|
||||
rc = SDL_AtomicGet(&apprc); // something else already set a quit result, keep that.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,8 +23,8 @@
|
||||
#define SDL_main_callbacks_h_
|
||||
|
||||
SDL_bool SDL_HasMainCallbacks(void);
|
||||
int SDL_InitMainCallbacks(int argc, char *argv[], SDL_AppInit_func appinit, SDL_AppIterate_func _appiter, SDL_AppEvent_func _appevent, SDL_AppQuit_func _appquit);
|
||||
int SDL_IterateMainCallbacks(SDL_bool pump_events);
|
||||
SDL_AppResult SDL_InitMainCallbacks(int argc, char *argv[], SDL_AppInit_func appinit, SDL_AppIterate_func _appiter, SDL_AppEvent_func _appevent, SDL_AppQuit_func _appquit);
|
||||
SDL_AppResult SDL_IterateMainCallbacks(SDL_bool pump_events);
|
||||
void SDL_QuitMainCallbacks(void);
|
||||
|
||||
#endif // SDL_main_callbacks_h_
|
||||
|
||||
@@ -26,22 +26,22 @@
|
||||
|
||||
static void EmscriptenInternalMainloop(void)
|
||||
{
|
||||
const int rc = SDL_IterateMainCallbacks(SDL_TRUE);
|
||||
if (rc != 0) {
|
||||
const SDL_AppResult rc = SDL_IterateMainCallbacks(SDL_TRUE);
|
||||
if (rc != SDL_APP_CONTINUE) {
|
||||
SDL_QuitMainCallbacks();
|
||||
emscripten_cancel_main_loop(); // kill" the mainloop, so it stops calling back into it.
|
||||
exit((rc < 0) ? 1 : 0); // hopefully this takes down everything else, too.
|
||||
exit((rc == SDL_APP_FAILURE) ? 1 : 0); // hopefully this takes down everything else, too.
|
||||
}
|
||||
}
|
||||
|
||||
int SDL_EnterAppMainCallbacks(int argc, char* argv[], SDL_AppInit_func appinit, SDL_AppIterate_func appiter, SDL_AppEvent_func appevent, SDL_AppQuit_func appquit)
|
||||
{
|
||||
const int rc = SDL_InitMainCallbacks(argc, argv, appinit, appiter, appevent, appquit);
|
||||
if (rc == 0) {
|
||||
const SDL_AppResult rc = SDL_InitMainCallbacks(argc, argv, appinit, appiter, appevent, appquit);
|
||||
if (rc == SDL_APP_CONTINUE) {
|
||||
emscripten_set_main_loop(EmscriptenInternalMainloop, 0, 0); // run at refresh rate, don't throw an exception since we do an orderly return.
|
||||
} else {
|
||||
SDL_QuitMainCallbacks();
|
||||
}
|
||||
return (rc < 0) ? 1 : 0;
|
||||
return (rc == SDL_APP_FAILURE) ? 1 : 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -39,13 +39,13 @@ static void SDLCALL MainCallbackRateHintChanged(void *userdata, const char *name
|
||||
|
||||
int SDL_EnterAppMainCallbacks(int argc, char* argv[], SDL_AppInit_func appinit, SDL_AppIterate_func appiter, SDL_AppEvent_func appevent, SDL_AppQuit_func appquit)
|
||||
{
|
||||
int rc = SDL_InitMainCallbacks(argc, argv, appinit, appiter, appevent, appquit);
|
||||
SDL_AppResult rc = SDL_InitMainCallbacks(argc, argv, appinit, appiter, appevent, appquit);
|
||||
if (rc == 0) {
|
||||
SDL_AddHintCallback(SDL_HINT_MAIN_CALLBACK_RATE, MainCallbackRateHintChanged, NULL);
|
||||
|
||||
Uint64 next_iteration = callback_rate_increment ? (SDL_GetTicksNS() + callback_rate_increment) : 0;
|
||||
|
||||
while ((rc = SDL_IterateMainCallbacks(SDL_TRUE)) == 0) {
|
||||
while ((rc = SDL_IterateMainCallbacks(SDL_TRUE)) == SDL_APP_CONTINUE) {
|
||||
// !!! FIXME: this can be made more complicated if we decide to
|
||||
// !!! FIXME: optionally hand off callback responsibility to the
|
||||
// !!! FIXME: video subsystem (for example, if Wayland has a
|
||||
@@ -77,7 +77,7 @@ int SDL_EnterAppMainCallbacks(int argc, char* argv[], SDL_AppInit_func appinit,
|
||||
}
|
||||
SDL_QuitMainCallbacks();
|
||||
|
||||
return (rc < 0) ? 1 : 0;
|
||||
return (rc == SDL_APP_FAILURE) ? 1 : 0;
|
||||
}
|
||||
|
||||
#endif // !SDL_PLATFORM_IOS
|
||||
|
||||
@@ -50,14 +50,14 @@ static SDLIosMainCallbacksDisplayLink *globalDisplayLink;
|
||||
|
||||
- (void)appIteration:(CADisplayLink *)sender
|
||||
{
|
||||
const int rc = SDL_IterateMainCallbacks(SDL_TRUE);
|
||||
if (rc != 0) {
|
||||
const SDL_AppResult rc = SDL_IterateMainCallbacks(SDL_TRUE);
|
||||
if (rc != SDL_APP_CONTINUE) {
|
||||
[self.displayLink invalidate];
|
||||
self.displayLink = nil;
|
||||
globalDisplayLink = nil;
|
||||
SDL_QuitMainCallbacks();
|
||||
SDL_UpdateLifecycleObserver();
|
||||
exit((rc < 0) ? 1 : 0);
|
||||
exit((rc == SDL_APP_FAILURE) ? 1 : 0);
|
||||
}
|
||||
}
|
||||
@end
|
||||
@@ -66,8 +66,8 @@ static SDLIosMainCallbacksDisplayLink *globalDisplayLink;
|
||||
// When we return from here, we're living in the RunLoop, and a CADisplayLink is firing regularly for us.
|
||||
int SDL_EnterAppMainCallbacks(int argc, char* argv[], SDL_AppInit_func appinit, SDL_AppIterate_func appiter, SDL_AppEvent_func appevent, SDL_AppQuit_func appquit)
|
||||
{
|
||||
const int rc = SDL_InitMainCallbacks(argc, argv, appinit, appiter, appevent, appquit);
|
||||
if (rc == 0) {
|
||||
const SDL_AppResult rc = SDL_InitMainCallbacks(argc, argv, appinit, appiter, appevent, appquit);
|
||||
if (rc == SDL_APP_CONTINUE) {
|
||||
globalDisplayLink = [[SDLIosMainCallbacksDisplayLink alloc] init:appiter quitfunc:appquit];
|
||||
if (globalDisplayLink != nil) {
|
||||
return 0; // this will fall all the way out of SDL_main, where UIApplicationMain will keep running the RunLoop.
|
||||
@@ -76,7 +76,7 @@ int SDL_EnterAppMainCallbacks(int argc, char* argv[], SDL_AppInit_func appinit,
|
||||
|
||||
// appinit requested quit, just bounce out now.
|
||||
SDL_QuitMainCallbacks();
|
||||
exit((rc < 0) ? 1 : 0);
|
||||
exit((rc == SDL_APP_FAILURE) ? 1 : 0);
|
||||
|
||||
return 1; // just in case.
|
||||
}
|
||||
|
||||
@@ -2090,7 +2090,7 @@ static void FullscreenTo(SDLTest_CommonState *state, int index, int windowId)
|
||||
SDL_free(displays);
|
||||
}
|
||||
|
||||
int SDLTest_CommonEventMainCallbacks(SDLTest_CommonState *state, const SDL_Event *event)
|
||||
SDL_AppResult SDLTest_CommonEventMainCallbacks(SDLTest_CommonState *state, const SDL_Event *event)
|
||||
{
|
||||
int i;
|
||||
|
||||
@@ -2487,7 +2487,7 @@ int SDLTest_CommonEventMainCallbacks(SDLTest_CommonState *state, const SDL_Event
|
||||
|
||||
void SDLTest_CommonEvent(SDLTest_CommonState *state, SDL_Event *event, int *done)
|
||||
{
|
||||
if (SDLTest_CommonEventMainCallbacks(state, event)) {
|
||||
if (SDLTest_CommonEventMainCallbacks(state, event) != SDL_APP_CONTINUE) {
|
||||
*done = 1;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user