Browse Source

Platform: make it possible to run main loop iterations manually.

pull/203/merge
Vladimír Vondruš 9 years ago
parent
commit
0d94673afb
  1. 6
      src/Magnum/Platform/Sdl2Application.cpp
  2. 22
      src/Magnum/Platform/Sdl2Application.h

6
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<Sdl2Application*>(arg)->mainLoop();
static_cast<Sdl2Application*>(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

22
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<Flag> Flags;
CORRADE_ENUMSET_FRIEND_OPERATORS(Flags)
void mainLoop();
#ifndef CORRADE_TARGET_EMSCRIPTEN
SDL_Window* _window;
SDL_GLContext _glContext;

Loading…
Cancel
Save