diff --git a/src/Magnum/Platform/Sdl2Application.cpp b/src/Magnum/Platform/Sdl2Application.cpp index a20544349..28b5160e8 100644 --- a/src/Magnum/Platform/Sdl2Application.cpp +++ b/src/Magnum/Platform/Sdl2Application.cpp @@ -319,10 +319,10 @@ Sdl2Application::~Sdl2Application() { int Sdl2Application::exec() { #ifndef CORRADE_TARGET_EMSCRIPTEN - while(!(_flags & Flag::Exit)) mainLoop(); + while(!(_flags & Flag::Exit)) mainLoopIteration(); #else emscripten_set_main_loop_arg([](void* arg) { - static_cast(arg)->mainLoop(); + static_cast(arg)->mainLoopIteration(); }, this, 0, true); #endif return 0; @@ -336,7 +336,7 @@ void Sdl2Application::exit() { #endif } -void Sdl2Application::mainLoop() { +void Sdl2Application::mainLoopIteration() { #ifndef CORRADE_TARGET_EMSCRIPTEN const UnsignedInt timeBefore = _minimalLoopPeriod ? SDL_GetTicks() : 0; #endif diff --git a/src/Magnum/Platform/Sdl2Application.h b/src/Magnum/Platform/Sdl2Application.h index 6b14dc623..99c3174bf 100644 --- a/src/Magnum/Platform/Sdl2Application.h +++ b/src/Magnum/Platform/Sdl2Application.h @@ -389,13 +389,29 @@ class Sdl2Application { * @brief Execute main loop * @return Value for returning from `main()` * - * See @ref MAGNUM_SDL2APPLICATION_MAIN() for usage information. + * Calls @ref mainLoopIteration() in a loop until @ref exit() is + * called. See @ref MAGNUM_SDL2APPLICATION_MAIN() for usage + * information. */ int exec(); - /** @brief Exit application main loop */ + /** + * @brief Exit application main loop + * + * Stops main loop started by @ref exec(). + */ void exit(); + /** + * @brief Run one iteration of application main loop + * + * Called internally from @ref exec(). If you want to have better + * control over how the main loop behaves, you can call this function + * yourself from your own `main()` function instead of it being called + * automatically from @ref exec() / @ref MAGNUM_SDL2APPLICATION_MAIN(). + */ + void mainLoopIteration(); + #ifndef CORRADE_TARGET_EMSCRIPTEN /** * @brief Underlying window handle @@ -710,8 +726,6 @@ class Sdl2Application { typedef Containers::EnumSet Flags; CORRADE_ENUMSET_FRIEND_OPERATORS(Flags) - void mainLoop(); - #ifndef CORRADE_TARGET_EMSCRIPTEN SDL_Window* _window; SDL_GLContext _glContext;