From 6d14b6fb564cf64521ffb15e91a25dd91f9629a6 Mon Sep 17 00:00:00 2001 From: Thanasis Antoniou Date: Sun, 1 Sep 2019 22:22:32 +0300 Subject: BLADERUNNER: Framelimiter fixes for delayMillis case --- engines/bladerunner/framelimiter.cpp | 39 ++++++++++++++++++++---------------- engines/bladerunner/framelimiter.h | 9 +++------ 2 files changed, 25 insertions(+), 23 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; diff --git a/engines/bladerunner/framelimiter.h b/engines/bladerunner/framelimiter.h index 66ee0f3b38..032457028d 100644 --- a/engines/bladerunner/framelimiter.h +++ b/engines/bladerunner/framelimiter.h @@ -43,12 +43,12 @@ class Framelimiter { public: static const FramelimiterFpsRate kDefaultFpsRate = kFramelimiter60fps; - static const bool kDefaultUseDelayMillis = false; + static const bool kDefaultUseDelayMillis = true; private: BladeRunnerEngine *_vm; - bool _forceFirstPass; + bool _forceScreenUpdate; uint32 _speedLimitMs; // A pass is when a tick or while loop that contains a potential screen update is repeated @@ -68,12 +68,9 @@ public: Framelimiter(BladeRunnerEngine *vm, FramelimiterFpsRate framerateMode, bool useDelayMs); ~Framelimiter(); -// void startFrame(); -// void delayBeforeSwap(); - // void pause(bool pause); - void init(bool forceFirstPass = true); + void init(bool forceScreenUpdate = true); uint32 getLastFrameDuration() const; uint32 getTimeOfCurrentPass() const; uint32 getTimeOfLastPass() const; -- cgit v1.2.3