Browse Source

Platform: added Sdl2Application::tickEvent().

If implemented by the user, it is called periodically after processing
input events and before draw event and does not depend on whether there
are any input events or the application needs to redraw.
pull/107/head
Vladimír Vondruš 11 years ago
parent
commit
155a484e67
  1. 15
      src/Magnum/Platform/Sdl2Application.cpp
  2. 14
      src/Magnum/Platform/Sdl2Application.h

15
src/Magnum/Platform/Sdl2Application.cpp

@ -322,6 +322,10 @@ void Sdl2Application::mainLoop() {
}
}
/* Tick event */
if(!(_flags & Flag::NoTickEvent)) tickEvent();
/* Draw event */
if(_flags & Flag::Redraw) {
_flags &= ~Flag::Redraw;
drawEvent();
@ -346,8 +350,9 @@ void Sdl2Application::mainLoop() {
SDL_Delay(_minimalLoopPeriod - loopTime);
}
/* Then wait indefinitely for next input event */
SDL_WaitEvent(nullptr);
/* Then, if the tick event doesn't need to be called periodically, wait
indefinitely for next input event */
if(_flags & Flag::NoTickEvent) SDL_WaitEvent(nullptr);
#endif
}
@ -362,6 +367,12 @@ void Sdl2Application::setMouseLocked(bool enabled) {
#endif
}
void Sdl2Application::tickEvent() {
/* If this got called, the tick event is not implemented by user and thus
we don't need to call it ever again */
_flags |= Flag::NoTickEvent;
}
void Sdl2Application::viewportEvent(const Vector2i&) {}
void Sdl2Application::keyPressEvent(KeyEvent&) {}
void Sdl2Application::keyReleaseEvent(KeyEvent&) {}

14
src/Magnum/Platform/Sdl2Application.h

@ -325,6 +325,17 @@ class Sdl2Application {
#else
private:
#endif
/**
* @brief Tick event
*
* If implemented, this function is called periodically after
* processing all input events and before draw event even though there
* might be no input events and redraw is not requested. Useful e.g.
* for asynchronous task polling. Use @ref setMinimalLoopPeriod()/
* @ref setSwapInterval() to control main loop frequency.
*/
virtual void tickEvent();
/**
* @brief Viewport event
*
@ -421,8 +432,9 @@ class Sdl2Application {
enum class Flag: UnsignedByte {
Redraw = 1 << 0,
VSyncEnabled = 1 << 1,
NoTickEvent = 1 << 2,
#ifndef CORRADE_TARGET_EMSCRIPTEN
Exit = 1 << 2
Exit = 1 << 3
#endif
};

Loading…
Cancel
Save