diff --git a/src/Magnum/Platform/EmscriptenApplication.cpp b/src/Magnum/Platform/EmscriptenApplication.cpp index 13fd92761..79721e11a 100644 --- a/src/Magnum/Platform/EmscriptenApplication.cpp +++ b/src/Magnum/Platform/EmscriptenApplication.cpp @@ -549,17 +549,15 @@ EmscriptenApplication::GLConfiguration::GLConfiguration(): _colorBufferSize{8, 8, 8, 0}, _depthBufferSize{24}, _stencilBufferSize{0} {} #endif -void EmscriptenApplication::mainLoopIteration() { - if(!(_flags & Flag::Redraw)) return; +int EmscriptenApplication::exec() { + emscripten_set_main_loop_arg([](void* userData) { + auto& app = *static_cast(userData); + if(!(app._flags & Flag::Redraw)) return; - _flags &= ~Flag::Redraw; - drawEvent(); -} - -void EmscriptenApplication::exec() { - emscripten_set_main_loop_arg([](void* arg) { - static_cast(arg)->mainLoopIteration(); + app._flags &= ~Flag::Redraw; + app.drawEvent(); }, this, 0, true); + return 0; } void EmscriptenApplication::exit(int) { diff --git a/src/Magnum/Platform/EmscriptenApplication.h b/src/Magnum/Platform/EmscriptenApplication.h index 82e00b3a3..1f7246d87 100644 --- a/src/Magnum/Platform/EmscriptenApplication.h +++ b/src/Magnum/Platform/EmscriptenApplication.h @@ -292,33 +292,23 @@ class EmscriptenApplication { EmscriptenApplication& operator=(EmscriptenApplication&&) = delete; /** - * @brief Execute main loop + * @brief Execute the application * - * Calls @ref mainLoopIteration() in a loop until @ref exit() is + * Sets up Emscripten to execute event handlers until @ref exit() is * called. See @ref MAGNUM_EMSCRIPTENAPPLICATION_MAIN() for usage * information. */ - void exec(); + int exec(); /** * @brief Exit application main loop - * @param exitCode Exit code for compatibility with other application - * implementations * - * Stops main loop started by @ref exec(). + * Stops execution started by @ref exec(). The @p exitCode is ignored + * and present only for API compatibility with other app + * implementations. */ void exit(int exitCode = 0); - /** - * @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_EMSCRIPTENAPPLICATION_MAIN(). - */ - void mainLoopIteration(); - protected: /* Nobody will need to have (and delete) EmscriptenApplication*, thus this is faster than public pure virtual destructor */