Browse Source

Platform: Sdl2Application::mainLoopIteration() now returns a bool.

To indicate when the app desires to exit.
pull/388/head
Vladimír Vondruš 7 years ago
parent
commit
82f53862e1
  1. 2
      doc/changelog.dox
  2. 21
      src/Magnum/Platform/Sdl2Application.cpp
  3. 8
      src/Magnum/Platform/Sdl2Application.h

2
doc/changelog.dox

@ -500,6 +500,8 @@ See also:
@ref Platform::GlfwApplication::exit() now have an optional parameter to
specify the actual application return code (see
[mosra/magnum#332](https://github.com/mosra/magnum/pull/332))
- @ref Platform::Sdl2Application::mainLoopIteration() now returns a
@cpp bool @ce to indicate if the application should exit
- @ref Platform::GlfwApplication and @ref Platform::EmscriptenApplication now
implement @ref Platform::GlfwApplication::MouseMoveEvent::relativePosition()
as well for better compatibility with @ref Platform::Sdl2Application. The

21
src/Magnum/Platform/Sdl2Application.cpp

@ -692,7 +692,7 @@ Sdl2Application::~Sdl2Application() {
int Sdl2Application::exec() {
#ifndef CORRADE_TARGET_EMSCRIPTEN
while(!(_flags & Flag::Exit)) mainLoopIteration();
while(mainLoopIteration()) {}
#else
emscripten_set_main_loop_arg([](void* arg) {
static_cast<Sdl2Application*>(arg)->mainLoopIteration();
@ -701,16 +701,17 @@ int Sdl2Application::exec() {
return _exitCode;
}
void Sdl2Application::exit(int exitCode) {
#ifndef CORRADE_TARGET_EMSCRIPTEN
void Sdl2Application::exit(const int exitCode) {
/* On Emscripten this flag is used only to indicate a desire to exit from
mainLoopIteration() */
_flags |= Flag::Exit;
#else
#ifdef CORRADE_TARGET_EMSCRIPTEN
emscripten_cancel_main_loop();
#endif
_exitCode = exitCode;
}
void Sdl2Application::mainLoopIteration() {
bool Sdl2Application::mainLoopIteration() {
#ifndef CORRADE_TARGET_EMSCRIPTEN
const UnsignedInt timeBefore = _minimalLoopPeriod ? SDL_GetTicks() : 0;
#endif
@ -828,12 +829,13 @@ void Sdl2Application::mainLoopIteration() {
ExitEvent e{event};
exitEvent(e);
if(e.isAccepted()) {
#ifndef CORRADE_TARGET_EMSCRIPTEN
/* On Emscripten this flag is used only to indicate a
desire to exit from mainLoopIteration() */
_flags |= Flag::Exit;
#else
#ifdef CORRADE_TARGET_EMSCRIPTEN
emscripten_cancel_main_loop();
#endif
return;
return !(_flags & Flag::Exit);
}
} break;
@ -860,7 +862,7 @@ void Sdl2Application::mainLoopIteration() {
}
#endif
return;
return !(_flags & Flag::Exit);
}
#ifndef CORRADE_TARGET_EMSCRIPTEN
@ -875,6 +877,7 @@ void Sdl2Application::mainLoopIteration() {
indefinitely for next input event */
if(_flags & Flag::NoTickEvent) SDL_WaitEvent(nullptr);
#endif
return !(_flags & Flag::Exit);
}
void Sdl2Application::setMouseLocked(bool enabled) {

8
src/Magnum/Platform/Sdl2Application.h

@ -504,13 +504,15 @@ class Sdl2Application {
/**
* @brief Run one iteration of application main loop
* @return @cpp false @ce if @ref exit() was called and the application
* should exit, @cpp true @ce otherwise
*
* 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();
bool mainLoopIteration();
#ifndef CORRADE_TARGET_EMSCRIPTEN
/**
@ -1003,9 +1005,7 @@ class Sdl2Application {
VSyncEnabled = 1 << 1,
NoTickEvent = 1 << 2,
NoAnyEvent = 1 << 3,
#ifndef CORRADE_TARGET_EMSCRIPTEN
Exit = 1 << 4
#endif
Exit = 1 << 4,
#ifdef CORRADE_TARGET_EMSCRIPTEN
TextInputActive = 1 << 5,
Resizable = 1 << 6

Loading…
Cancel
Save