Browse Source

Split AbstractXApplication mainLoopIteration

Linked: #577
pull/580/head
Andreas Leroux 4 years ago
parent
commit
b1bfc7d23c
  1. 26
      src/Magnum/Platform/AbstractXApplication.cpp
  2. 20
      src/Magnum/Platform/AbstractXApplication.h

26
src/Magnum/Platform/AbstractXApplication.cpp

@ -139,11 +139,7 @@ int AbstractXApplication::exec() {
return _exitCode; return _exitCode;
} }
bool AbstractXApplication::mainLoopIteration() { bool AbstractXApplication::mainLoopEventIteration() {
/* If exit was requested directly in the constructor, exit immediately
without calling anything else */
if(_flags & Flag::Exit) return false;
XEvent event; XEvent event;
/* Closed window */ /* Closed window */
@ -184,11 +180,29 @@ bool AbstractXApplication::mainLoopIteration() {
} break; } break;
} }
} }
}
bool AbstractXApplication::mainLoopDrawEventIteration() {
if(_flags & Flag::Redraw) { if(_flags & Flag::Redraw) {
_flags &= ~Flag::Redraw; _flags &= ~Flag::Redraw;
drawEvent(); drawEvent();
} else Utility::System::sleep(5); return true;
}
return false;
}
bool AbstractXApplication::mainLoopIteration() {
/* If exit was requested directly in the constructor, exit immediately
without calling anything else */
if(_flags & Flag::Exit) return false;
/* exit was requested in the event loop */
if (!mainLoopEventIteration())
return false;
/* If not drawing anything, delay to prevent CPU hogging */
if (!mainLoopDraweventIteration())
Utility::System::sleep(5);
return !(_flags & Flag::Exit); return !(_flags & Flag::Exit);
} }

20
src/Magnum/Platform/AbstractXApplication.h

@ -134,14 +134,34 @@ class AbstractXApplication {
* should exit, @cpp true @ce otherwise * should exit, @cpp true @ce otherwise
* @m_since{2020,06} * @m_since{2020,06}
* *
* Calls @ref mainLoopEventIteration() and @ref mainLoopDrawEventIteration()
* managing the delays between them.
* Called internally from @ref exec(). If you want to have better * Called internally from @ref exec(). If you want to have better
* control over how the main loop behaves, you can call this function * control over how the main loop behaves, you can call this function
* (or the sub mainLoopIteration functions)
* yourself from your own `main()` function instead of it being called * yourself from your own `main()` function instead of it being called
* automatically from @ref exec() / @ref MAGNUM_GLXAPPLICATION_MAIN() * automatically from @ref exec() / @ref MAGNUM_GLXAPPLICATION_MAIN()
* / @ref MAGNUM_XEGLAPPLICATION_MAIN(). * / @ref MAGNUM_XEGLAPPLICATION_MAIN().
*/ */
bool mainLoopIteration(); bool mainLoopIteration();
/**
* @brief Process pending application events
* @return @cpp false @ce if @ref exit() was called and the application
* should exit, @cpp true @ce otherwise
*
* Called internally from @ref mainLoopIteration().
*/
bool mainLoopEventIteration();
/**
* @brief Calls @ref drawEvent() if @ref Flag::Redraw is set and unset it.
* @return @cpp true @ce if @ref drawEvent() was called, @cpp false @ce otherwise
*
* Called internally from @ref mainLoopIteration().
*/
bool mainLoopDrawEventIteration();
/** /**
* @brief Exit application * @brief Exit application
* @param exitCode The exit code the application should return * @param exitCode The exit code the application should return

Loading…
Cancel
Save