ScummVM API documentation
framelimiter.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef GFX_FRAMELIMITER_H
23 #define GFX_FRAMELIMITER_H
24 
25 #include "common/system.h"
26 
27 namespace Graphics {
28 
40 class FrameLimiter {
41 public:
42  FrameLimiter(OSystem *system, const uint framerate, const bool deferToVsync = true);
46  void initialize();
47  void initialize(const uint framerate);
48 
53  uint startFrame();
54 
61  bool delayBeforeSwap();
62  void pause(bool pause);
67  uint getLastFrameDuration() const {
68  return _frameDuration;
69  }
75  uint getLastDrawDuration() const {
76  return _drawDuration;
77  }
82  uint getLastLoopDuration() const {
83  return _loopDuration;
84  }
90  bool isEnabled() const {
91  return _enabled;
92  }
93 
94 private:
95  OSystem *_system;
96 
97  bool _enabled;
98  bool _deferToVsync;
99  uint _frameStart = 0; // Time at which screen update completed and startFrame() was called; start of next cycle of game logic
100  uint _frameLimit = 0; // Target frame duration to achieve specified FPS
101  uint _frameDuration = 0; // Duration of previous frame between successive startFrame() calls; total game logic, delay (if any) and screen update time
102  uint _drawStart = 0; // Time at which delayBeforeSwap() returns
103  uint _drawDuration = 0; // Measured screen update time
104  uint _loopDuration = 0; // Duration of last game logic cycle, from when startFrame() was called to when delayBeforeSwap() was called
105  int _delay = 0; // Time to delay before returning from delayBeforeSwap()
106  uint _now = 0; // Current time
107 };
108 
109 } // End of namespace Graphics
110 
111 #endif // GFX_FRAMELIMITER_H
Definition: framelimiter.h:40
uint getLastFrameDuration() const
Definition: framelimiter.h:67
uint getLastDrawDuration() const
Definition: framelimiter.h:75
Definition: formatinfo.h:28
bool isEnabled() const
Definition: framelimiter.h:90
uint getLastLoopDuration() const
Definition: framelimiter.h:82
Definition: system.h:163