ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

framelimiter.cpp

Go to the documentation of this file.
00001 /* ResidualVM - A 3D game interpreter
00002  *
00003  * ResidualVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the AUTHORS
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #include "engines/stark/gfx/framelimiter.h"
00024 
00025 #include "common/util.h"
00026 
00027 namespace Stark {
00028 namespace Gfx {
00029 
00030 FrameLimiter::FrameLimiter(OSystem *system, const uint framerate) :
00031         _system(system),
00032         _speedLimitMs(0),
00033         _startFrameTime(0),
00034         _lastFrameDurationMs(_speedLimitMs) {
00035     // The frame limiter is disabled when vsync is enabled.
00036     _enabled = !_system->getFeatureState(OSystem::kFeatureVSync) && framerate != 0;
00037 
00038     if (_enabled) {
00039         _speedLimitMs = 1000 / CLIP<uint>(framerate, 0, 100);
00040     }
00041 }
00042 
00043 void FrameLimiter::startFrame() {
00044     uint currentTime = _system->getMillis();
00045 
00046     if (_startFrameTime != 0) {
00047         _lastFrameDurationMs = currentTime - _startFrameTime;
00048     }
00049 
00050     _startFrameTime = currentTime;
00051 }
00052 
00053 void FrameLimiter::delayBeforeSwap() {
00054     uint endFrameTime = _system->getMillis();
00055     uint frameDuration = endFrameTime - _startFrameTime;
00056 
00057     if (_enabled && frameDuration < _speedLimitMs) {
00058         _system->delayMillis(_speedLimitMs - frameDuration);
00059     }
00060 }
00061 
00062 void FrameLimiter::pause(bool pause) {
00063     if (!pause) {
00064         // Make sure the frame duration value is consistent when resuming
00065         _startFrameTime = 0;
00066     }
00067 }
00068 
00069 uint FrameLimiter::getLastFrameDuration() const {
00070     return _lastFrameDurationMs;
00071 }
00072 
00073 } // End of namespace Gfx
00074 } // End of namespace Stark


Generated on Sat May 18 2019 05:01:03 for ResidualVM by doxygen 1.7.1
curved edge   curved edge