diff options
author | Thanasis Antoniou | 2019-09-01 22:22:32 +0300 |
---|---|---|
committer | Thanasis Antoniou | 2019-09-01 22:22:57 +0300 |
commit | 6d14b6fb564cf64521ffb15e91a25dd91f9629a6 (patch) | |
tree | f22bb1787c52562fd74388868862e93e3ce62f66 /engines/bladerunner/framelimiter.cpp | |
parent | 3996783c885d056b812b90e699f635685c2781dd (diff) | |
download | scummvm-rg350-6d14b6fb564cf64521ffb15e91a25dd91f9629a6.tar.gz scummvm-rg350-6d14b6fb564cf64521ffb15e91a25dd91f9629a6.tar.bz2 scummvm-rg350-6d14b6fb564cf64521ffb15e91a25dd91f9629a6.zip |
BLADERUNNER: Framelimiter fixes for delayMillis case
Diffstat (limited to 'engines/bladerunner/framelimiter.cpp')
-rw-r--r-- | engines/bladerunner/framelimiter.cpp | 39 |
1 files changed, 22 insertions, 17 deletions
diff --git a/engines/bladerunner/framelimiter.cpp b/engines/bladerunner/framelimiter.cpp index 08cc9fc99b..91277bafb8 100644 --- a/engines/bladerunner/framelimiter.cpp +++ b/engines/bladerunner/framelimiter.cpp @@ -70,10 +70,10 @@ Framelimiter::Framelimiter(BladeRunnerEngine *vm, FramelimiterFpsRate framerateM Framelimiter::~Framelimiter() { } -void Framelimiter::init(bool forceFirstPass) { +void Framelimiter::init(bool forceScreenUpdate) { reset(); _timeOfLastPass = _vm->_time->currentSystem(); - _forceFirstPass = forceFirstPass; + _forceScreenUpdate = forceScreenUpdate; } uint32 Framelimiter::getLastFrameDuration() const { @@ -92,12 +92,23 @@ bool Framelimiter::shouldExecuteScreenUpdate() { bool shouldUpdateScreen = true; _timeOfCurrentPass = _vm->_time->currentSystem(); if (_enabled) { - shouldUpdateScreen = ((_timeOfCurrentPass - _timeOfLastPass) >= _speedLimitMs) || _forceFirstPass; + if (_useDelayMs) { + // _timeOfCurrentPass is used to calculate the duration that the current frame is on screen so far + uint32 frameDuration = _timeOfCurrentPass - _startFrameTime; + if (frameDuration < _speedLimitMs) { + _vm->_system->delayMillis(_speedLimitMs - frameDuration); + // cheaper than calling _vm->_time->currentSystem() again + _timeOfCurrentPass += (_speedLimitMs - frameDuration); + } + } + + shouldUpdateScreen = ((_timeOfCurrentPass - _timeOfLastPass) >= _speedLimitMs) || _forceScreenUpdate || _useDelayMs; if (shouldUpdateScreen) { - if (_forceFirstPass) { - _forceFirstPass = false; + if (_forceScreenUpdate) { + _forceScreenUpdate = false; } + _lastFrameDurationMs = _timeOfCurrentPass - _startFrameTime; _startFrameTime = _timeOfCurrentPass; } } @@ -106,21 +117,15 @@ bool Framelimiter::shouldExecuteScreenUpdate() { void Framelimiter::postScreenUpdate() { _timeOfLastPass = _timeOfCurrentPass; - if (_enabled) { - - if (_useDelayMs) { - uint32 endFrameTime = _vm->_time->currentSystem(); - uint32 frameDuration = endFrameTime - _startFrameTime; - - if (frameDuration < _speedLimitMs) { - _vm->_system->delayMillis(_speedLimitMs - frameDuration); - } - } - } +// if (_enabled) { +// // for debug purposes, this calculates the time between deciding to draw the frame, and the time after drawing the update to the screen +// uint32 endFrameTime = _vm->_time->currentSystem(); +// uint32 frameDuration = endFrameTime - _startFrameTime; +// } } void Framelimiter::reset() { - _forceFirstPass = false; + _forceScreenUpdate = false; _timeOfLastPass = 0u; _timeOfCurrentPass = 0u; _startFrameTime = 0u; |