#include <framelimiter.h>
Public Member Functions | |
FrameLimiter (OSystem *system, const uint framerate, const bool deferToVsync=true) | |
void | initialize () |
void | initialize (const uint framerate) |
uint | startFrame () |
bool | delayBeforeSwap () |
void | pause (bool pause) |
uint | getLastFrameDuration () const |
uint | getLastDrawDuration () const |
uint | getLastLoopDuration () const |
bool | isEnabled () const |
A framerate limiter
Ensures the framerate does not exceed the specified value by delaying until all of the timeslot allocated to the frame is consumed. Allows to curb CPU usage and have a stable framerate. If deferToVsync is set true (default), framerate will only be limited to the set value when hardware vsync is inactive, otherwise it will track Vsync directly. If deferToVsync is set false, framerate will always be limited to the set value, whether or not hardware vsync is active. In order for hardware vsync status detection to work correctly, initialize() must be called AFTER initGraphics; see below.
void Graphics::FrameLimiter::initialize | ( | ) |
Always call this after instantiating Screen & calling initGraphics(), to ensure Vsync status is detected correctly!
uint Graphics::FrameLimiter::startFrame | ( | ) |
Call immediately before starting game logic cycle, and immediately after previous screen->update(), if any. Returns last frame duration.
bool Graphics::FrameLimiter::delayBeforeSwap | ( | ) |
Call immediately after game logic cycle is completed, and immediately before screen->update(). If Vsync is inactive, will wait and return at the appropriate moment to call screen->update() in order to maintain the specified FPS. If Vsync is active, will return immediately as screen->update() should automatically wait for the right moment. Returns true if next frame is expected to be late.
|
inline |
Return duration of last whole frame, including game logic, frame limiter or Vsync delay (if any), and screen redraw time. Specifically, this is the time between the last two successive startFrame() calls.
|
inline |
Return duration of last screen update If Vsync is inactive, this value will just be the duration of the redraw process itself; If Vsync is active, this value will encompass both the redraw time AND the delay between presenting the frame to redraw and the screen redraw actually starting.
|
inline |
Return duration of last game logic loop Specifically, this is the time from when startFrame() was last called to when delayBeforeSwap() was last called
|
inline |
If true, framelimiter is active and applying _system->delayMillis(delay) to maintain the specified FPS, if valid. If false, framelimiter is inactive, either because supplied FPS was invalid or because Vsync is active. delayBeforeSwap() should still be called even if inactive, in order to ensure timers are updated correctly.