diff options
author | Peter Kohaut | 2019-09-04 16:00:35 +0200 |
---|---|---|
committer | Peter Kohaut | 2019-09-04 21:26:37 +0200 |
commit | 89384b9124dfc385626f9b3aebb7ef4ad19a38b1 (patch) | |
tree | 5464f0959116e1c3c8203e8babca8789e7f319aa /engines/bladerunner | |
parent | cb88db65cdff4302dd5952a0ed2a048ba5ef489a (diff) | |
download | scummvm-rg350-89384b9124dfc385626f9b3aebb7ef4ad19a38b1.tar.gz scummvm-rg350-89384b9124dfc385626f9b3aebb7ef4ad19a38b1.tar.bz2 scummvm-rg350-89384b9124dfc385626f9b3aebb7ef4ad19a38b1.zip |
BLADERUNNER: Framelimiter simplification
Diffstat (limited to 'engines/bladerunner')
-rw-r--r-- | engines/bladerunner/bladerunner.cpp | 26 | ||||
-rw-r--r-- | engines/bladerunner/bladerunner.h | 3 | ||||
-rw-r--r-- | engines/bladerunner/framelimiter.cpp | 112 | ||||
-rw-r--r-- | engines/bladerunner/framelimiter.h | 41 | ||||
-rw-r--r-- | engines/bladerunner/outtake.cpp | 15 | ||||
-rw-r--r-- | engines/bladerunner/outtake.h | 2 | ||||
-rw-r--r-- | engines/bladerunner/ui/elevator.cpp | 45 | ||||
-rw-r--r-- | engines/bladerunner/ui/elevator.h | 2 | ||||
-rw-r--r-- | engines/bladerunner/ui/end_credits.cpp | 19 | ||||
-rw-r--r-- | engines/bladerunner/ui/end_credits.h | 2 | ||||
-rw-r--r-- | engines/bladerunner/ui/esper.cpp | 46 | ||||
-rw-r--r-- | engines/bladerunner/ui/esper.h | 2 | ||||
-rw-r--r-- | engines/bladerunner/ui/kia.cpp | 23 | ||||
-rw-r--r-- | engines/bladerunner/ui/kia.h | 4 | ||||
-rw-r--r-- | engines/bladerunner/ui/spinner.cpp | 47 | ||||
-rw-r--r-- | engines/bladerunner/ui/spinner.h | 2 | ||||
-rw-r--r-- | engines/bladerunner/ui/vk.cpp | 46 | ||||
-rw-r--r-- | engines/bladerunner/ui/vk.h | 2 |
18 files changed, 115 insertions, 324 deletions
diff --git a/engines/bladerunner/bladerunner.cpp b/engines/bladerunner/bladerunner.cpp index b73afdd8b8..fa0d79e0ba 100644 --- a/engines/bladerunner/bladerunner.cpp +++ b/engines/bladerunner/bladerunner.cpp @@ -169,6 +169,7 @@ BladeRunnerEngine::BladeRunnerEngine(OSystem *syst, const ADGameDescription *des _obstacles = nullptr; _sceneScript = nullptr; _time = nullptr; + _framelimiter = nullptr; _gameInfo = nullptr; _waypoints = nullptr; _gameVars = nullptr; @@ -217,7 +218,6 @@ BladeRunnerEngine::BladeRunnerEngine(OSystem *syst, const ADGameDescription *des _actors[i] = nullptr; } _debugger = nullptr; - _mainLoopFrameLimiter = nullptr; walkingReset(); @@ -313,7 +313,6 @@ void BladeRunnerEngine::pauseEngineIntern(bool pause) { } Common::Error BladeRunnerEngine::run() { - Common::Array<Common::String> missingFiles; if (!checkFiles(missingFiles)) { Common::String missingFileStr = ""; @@ -340,7 +339,6 @@ Common::Error BladeRunnerEngine::run() { return Common::Error(Common::kUnknownError, _("Failed to initialize resources")); } - // improvement: Use a do-while() loop to handle the normal end-game state // so that the game won't exit abruptly after end credits do { @@ -486,6 +484,8 @@ bool BladeRunnerEngine::startup(bool hasSavegames) { _time = new Time(this); + _framelimiter = new Framelimiter(this); + // Try to load the SUBTITLES.MIX first, before Startup.MIX // allows overriding any identically named resources (such as the original font files and as a bonus also the TRE files for the UI and dialogue menu) _subtitles = new Subtitles(this); @@ -529,8 +529,6 @@ bool BladeRunnerEngine::startup(bool hasSavegames) { _cosTable1024 = new Common::CosineTable(1024); // 10-bits = 1024 points for 2*PI; _sinTable1024 = new Common::SineTable(1024); - _mainLoopFrameLimiter = new Framelimiter(this, Framelimiter::kDefaultFpsRate, Framelimiter::kDefaultUseDelayMillis); - _view = new View(); _sceneObjects = new SceneObjects(this, _view); @@ -898,6 +896,9 @@ void BladeRunnerEngine::shutdown() { _subtitles = nullptr; } + delete _framelimiter; + _framelimiter = nullptr; + delete _time; _time = nullptr; @@ -932,11 +933,6 @@ void BladeRunnerEngine::shutdown() { delete _screenEffects; _screenEffects = nullptr; - - if (_mainLoopFrameLimiter) { - delete _mainLoopFrameLimiter; - _mainLoopFrameLimiter = nullptr; - } } bool BladeRunnerEngine::loadSplash() { @@ -965,7 +961,6 @@ bool BladeRunnerEngine::isMouseButtonDown() const { void BladeRunnerEngine::gameLoop() { _gameIsRunning = true; - _mainLoopFrameLimiter->init(); do { if (_playerDead) { playerDied(); @@ -980,7 +975,6 @@ void BladeRunnerEngine::gameTick() { handleEvents(); if (!_gameIsRunning || !_windowIsActive) { - _mainLoopFrameLimiter->init(); return; } @@ -989,7 +983,6 @@ void BladeRunnerEngine::gameTick() { Common::Error runtimeError = Common::Error(Common::kUnknownError, _("A required game resource was not found")); GUI::MessageDialog dialog(runtimeError.getDesc()); dialog.runModal(); - _mainLoopFrameLimiter->init(); return; } } @@ -1124,12 +1117,8 @@ void BladeRunnerEngine::gameTick() { // Without this condition the game may flash back to the game screen // between and ending outtake and the end credits. if (!_gameOver) { - if (_mainLoopFrameLimiter->shouldExecuteScreenUpdate()) { - blitToScreen(_surfaceFront); - _mainLoopFrameLimiter->postScreenUpdate(); - } + blitToScreen(_surfaceFront); } - } void BladeRunnerEngine::actorsUpdate() { @@ -2253,6 +2242,7 @@ void BladeRunnerEngine::ISez(const Common::String &str) { } void BladeRunnerEngine::blitToScreen(const Graphics::Surface &src) const { + _framelimiter->wait(); _system->copyRectToScreen(src.getPixels(), src.pitch, 0, 0, src.w, src.h); _system->updateScreen(); } diff --git a/engines/bladerunner/bladerunner.h b/engines/bladerunner/bladerunner.h index 5b59a09206..ab1179569f 100644 --- a/engines/bladerunner/bladerunner.h +++ b/engines/bladerunner/bladerunner.h @@ -166,6 +166,7 @@ public: SuspectsDatabase *_suspectsDatabase; Time *_time; View *_view; + Framelimiter *_framelimiter; VK *_vk; Waypoints *_waypoints; int *_gameVars; @@ -197,8 +198,6 @@ public: Common::CosineTable *_cosTable1024; Common::SineTable *_sinTable1024; - Framelimiter *_mainLoopFrameLimiter; - bool _isWalkingInterruptible; bool _interruptWalking; bool _playerActorIdle; diff --git a/engines/bladerunner/framelimiter.cpp b/engines/bladerunner/framelimiter.cpp index 91277bafb8..9dea099eef 100644 --- a/engines/bladerunner/framelimiter.cpp +++ b/engines/bladerunner/framelimiter.cpp @@ -24,112 +24,48 @@ #include "bladerunner/bladerunner.h" #include "bladerunner/time.h" + +#include "common/debug.h" #include "common/system.h" namespace BladeRunner { -Framelimiter::Framelimiter(BladeRunnerEngine *vm, FramelimiterFpsRate framerateMode, bool useDelayMs) { +Framelimiter::Framelimiter(BladeRunnerEngine *vm, uint fps) { _vm = vm; -// // FUTURE: The frame limiter is disabled when vsync is enabled. -// _enabled = !_system->getFeatureState(OSystem::kFeatureVSync); - _enabled = true; - _useDelayMs = useDelayMs; + reset(); - _speedLimitMs = 0u; - uint32 framerate = 1u; // dummy init - switch (framerateMode) { - case kFramelimiter15fps: - framerate = 15u; - break; - case kFramelimiter25fps: - framerate = 25u; - break; - case kFramelimiter30fps: - framerate = 30u; - break; - case kFramelimiter60fps: - framerate = 60u; - break; - case kFramelimiter120fps: - framerate = 120u; - break; - case kFramelimiterDisabled: - // fall through - default: + if (fps > 0) { + _enabled = true; + _speedLimitMs = 1000 / fps; + } else { _enabled = false; - break; } - if (_enabled) { - _speedLimitMs = 1000 / CLIP<uint32>(framerate, 1, 120); - } - - reset(); -} - -Framelimiter::~Framelimiter() { } - -void Framelimiter::init(bool forceScreenUpdate) { - reset(); - _timeOfLastPass = _vm->_time->currentSystem(); - _forceScreenUpdate = forceScreenUpdate; -} - -uint32 Framelimiter::getLastFrameDuration() const { - return _lastFrameDurationMs; + _timeFrameStart = _vm->_time->currentSystem(); } -uint32 Framelimiter::getTimeOfCurrentPass() const { - return _timeOfCurrentPass; -} - -uint32 Framelimiter::getTimeOfLastPass() const { - return _timeOfLastPass; -} +void Framelimiter::wait() { + // TODO: when vsync will be supported, use it -bool Framelimiter::shouldExecuteScreenUpdate() { - bool shouldUpdateScreen = true; - _timeOfCurrentPass = _vm->_time->currentSystem(); - if (_enabled) { - 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 (_forceScreenUpdate) { - _forceScreenUpdate = false; - } - _lastFrameDurationMs = _timeOfCurrentPass - _startFrameTime; - _startFrameTime = _timeOfCurrentPass; - } + if (!_enabled) { + return; } - return shouldUpdateScreen; -} -void Framelimiter::postScreenUpdate() { - _timeOfLastPass = _timeOfCurrentPass; -// 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; -// } + uint32 timeNow = _vm->_time->currentSystem(); + uint32 frameDuration = timeNow - _timeFrameStart; + if (frameDuration < _speedLimitMs) { + uint32 wait = _speedLimitMs - frameDuration; + _vm->_system->delayMillis(wait); + timeNow += wait; + } + // debug("frametime %i ms", timeNow - _timeFrameStart); + // using _vm->_time->currentSystem() here is slower and causes some shutters + _timeFrameStart = timeNow; } void Framelimiter::reset() { - _forceScreenUpdate = false; - _timeOfLastPass = 0u; - _timeOfCurrentPass = 0u; - _startFrameTime = 0u; - _lastFrameDurationMs = _speedLimitMs; + _timeFrameStart = 0u; } } // End of namespace BladeRunner diff --git a/engines/bladerunner/framelimiter.h b/engines/bladerunner/framelimiter.h index 032457028d..a36e20856c 100644 --- a/engines/bladerunner/framelimiter.h +++ b/engines/bladerunner/framelimiter.h @@ -27,56 +27,23 @@ namespace BladeRunner { -enum FramelimiterFpsRate { - kFramelimiterDisabled = 0, - kFramelimiter15fps = 1, - kFramelimiter25fps = 2, - kFramelimiter30fps = 3, - kFramelimiter60fps = 4, - kFramelimiter120fps = 5 -}; - class BladeRunnerEngine; class Framelimiter { friend class Debugger; -public: - static const FramelimiterFpsRate kDefaultFpsRate = kFramelimiter60fps; - static const bool kDefaultUseDelayMillis = true; - private: BladeRunnerEngine *_vm; - bool _forceScreenUpdate; + bool _enabled; uint32 _speedLimitMs; - // A pass is when a tick or while loop that contains a potential screen update is repeated - // it's essentially when the check is made for a screen update - // Not every pass will necessarily result in a screen update (because that's the purpose of the frame limiter) - // So the "_startFrameTime" is not always equal to "_timeOfCurrentPass" - uint32 _timeOfLastPass; - uint32 _timeOfCurrentPass; - - uint32 _startFrameTime; // is updated and valid, only if the current pass will result in a screen update (see method: shouldExecuteScreenUpdate()) - uint32 _lastFrameDurationMs; // can be used for average FPS calculation and display purposes when frame limiter is enabled - - bool _enabled; - bool _useDelayMs; // true: will use calls to delayMillis(), false: will use non-blocking software timer instead + uint32 _timeFrameStart; public: - Framelimiter(BladeRunnerEngine *vm, FramelimiterFpsRate framerateMode, bool useDelayMs); - ~Framelimiter(); - -// void pause(bool pause); - - void init(bool forceScreenUpdate = true); - uint32 getLastFrameDuration() const; - uint32 getTimeOfCurrentPass() const; - uint32 getTimeOfLastPass() const; + Framelimiter(BladeRunnerEngine *vm, uint fps = 60); - bool shouldExecuteScreenUpdate(); - void postScreenUpdate(); + void wait(); private: void reset(); diff --git a/engines/bladerunner/outtake.cpp b/engines/bladerunner/outtake.cpp index 2f49099455..03192d69bf 100644 --- a/engines/bladerunner/outtake.cpp +++ b/engines/bladerunner/outtake.cpp @@ -24,7 +24,6 @@ #include "bladerunner/bladerunner.h" #include "bladerunner/chapters.h" -#include "bladerunner/framelimiter.h" #include "bladerunner/subtitles.h" #include "bladerunner/vqa_player.h" #include "bladerunner/time.h" @@ -38,16 +37,10 @@ namespace BladeRunner { OuttakePlayer::OuttakePlayer(BladeRunnerEngine *vm) { _vm = vm; _surfaceVideo.create(_vm->_surfaceBack.w, _vm->_surfaceBack.h, _vm->_surfaceBack.format); - _framelimiter = new Framelimiter(_vm, Framelimiter::kDefaultFpsRate, Framelimiter::kDefaultUseDelayMillis); } OuttakePlayer::~OuttakePlayer() { _surfaceVideo.free(); - - if (_framelimiter) { - delete _framelimiter; - _framelimiter = nullptr; - } } void OuttakePlayer::play(const Common::String &name, bool noLocalization, int container) { @@ -77,17 +70,10 @@ void OuttakePlayer::play(const Common::String &name, bool noLocalization, int co _vm->_vqaIsPlaying = true; _vm->_vqaStopIsRequested = false; - _framelimiter->init(); - while (!_vm->_vqaStopIsRequested && !_vm->shouldQuit()) { _vm->handleEvents(); if (!_vm->_windowIsActive) { - _framelimiter->init(); - continue; - } - - if (!_framelimiter->shouldExecuteScreenUpdate()) { continue; } @@ -102,7 +88,6 @@ void OuttakePlayer::play(const Common::String &name, bool noLocalization, int co _vm->_subtitles->tickOuttakes(_vm->_surfaceFront); _vm->blitToScreen(_vm->_surfaceFront); } - _framelimiter->postScreenUpdate(); } _vm->_vqaIsPlaying = false; diff --git a/engines/bladerunner/outtake.h b/engines/bladerunner/outtake.h index 0305e80554..d01bc34030 100644 --- a/engines/bladerunner/outtake.h +++ b/engines/bladerunner/outtake.h @@ -30,11 +30,9 @@ namespace BladeRunner { class BladeRunnerEngine; -class Framelimiter; class OuttakePlayer { BladeRunnerEngine *_vm; - Framelimiter *_framelimiter; Graphics::Surface _surfaceVideo; diff --git a/engines/bladerunner/ui/elevator.cpp b/engines/bladerunner/ui/elevator.cpp index d01acc21ed..cff2a16ab7 100644 --- a/engines/bladerunner/ui/elevator.cpp +++ b/engines/bladerunner/ui/elevator.cpp @@ -25,7 +25,6 @@ #include "bladerunner/actor.h" #include "bladerunner/bladerunner.h" #include "bladerunner/audio_player.h" -#include "bladerunner/framelimiter.h" #include "bladerunner/game_info.h" #include "bladerunner/mouse.h" #include "bladerunner/shape.h" @@ -45,17 +44,11 @@ Elevator::Elevator(BladeRunnerEngine *vm) { _vm = vm; reset(); _imagePicker = new UIImagePicker(vm, 8); - _framelimiter = new Framelimiter(_vm, Framelimiter::kDefaultFpsRate, Framelimiter::kDefaultUseDelayMillis); } Elevator::~Elevator() { delete _imagePicker; _imagePicker = nullptr; - - if (_framelimiter) { - delete _framelimiter; - _framelimiter = nullptr; - } } int Elevator::activate(int elevatorId) { @@ -194,7 +187,6 @@ int Elevator::activate(int elevatorId) { void Elevator::open() { resetDescription(); _isOpen = true; - _framelimiter->init(); } bool Elevator::isOpen() const { @@ -213,35 +205,32 @@ int Elevator::handleMouseDown(int x, int y) { void Elevator::tick() { if (!_vm->_windowIsActive) { - _framelimiter->init(); return; } - if (_framelimiter->shouldExecuteScreenUpdate()) { - int frame = _vqaPlayer->update(); - assert(frame >= -1); + int frame = _vqaPlayer->update(); + assert(frame >= -1); + + // vqaPlayer renders to _surfaceBack + blit(_vm->_surfaceBack, _vm->_surfaceFront); - // vqaPlayer renders to _surfaceBack - blit(_vm->_surfaceBack, _vm->_surfaceFront); + Common::Point p = _vm->getMousePos(); - Common::Point p = _vm->getMousePos(); + // TODO(madmoose): BLADE.EXE has hasHoveredImage before handleMouseAction? + _imagePicker->handleMouseAction(p.x, p.y, false, false, false); + if (_imagePicker->hasHoveredImage()) { + _vm->_mouse->setCursor(1); + } else { + _vm->_mouse->setCursor(0); + } - // TODO(madmoose): BLADE.EXE has hasHoveredImage before handleMouseAction? - _imagePicker->handleMouseAction(p.x, p.y, false, false, false); - if (_imagePicker->hasHoveredImage()) { - _vm->_mouse->setCursor(1); - } else { - _vm->_mouse->setCursor(0); - } + _imagePicker->draw(_vm->_surfaceFront); + _vm->_mouse->draw(_vm->_surfaceFront, p.x, p.y); - _imagePicker->draw(_vm->_surfaceFront); - _vm->_mouse->draw(_vm->_surfaceFront, p.x, p.y); + _vm->_subtitles->tick(_vm->_surfaceFront); - _vm->_subtitles->tick(_vm->_surfaceFront); + _vm->blitToScreen(_vm->_surfaceFront); - _vm->blitToScreen(_vm->_surfaceFront); - _framelimiter->postScreenUpdate(); - } tickDescription(); } diff --git a/engines/bladerunner/ui/elevator.h b/engines/bladerunner/ui/elevator.h index c64152c3fc..6ed91ce799 100644 --- a/engines/bladerunner/ui/elevator.h +++ b/engines/bladerunner/ui/elevator.h @@ -28,14 +28,12 @@ namespace BladeRunner { class BladeRunnerEngine; -class Framelimiter; class Shape; class VQAPlayer; class UIImagePicker; class Elevator { BladeRunnerEngine *_vm; - Framelimiter *_framelimiter; bool _isOpen; VQAPlayer *_vqaPlayer; int _buttonClicked; diff --git a/engines/bladerunner/ui/end_credits.cpp b/engines/bladerunner/ui/end_credits.cpp index 291014c5a3..b609e2ea0d 100644 --- a/engines/bladerunner/ui/end_credits.cpp +++ b/engines/bladerunner/ui/end_credits.cpp @@ -29,7 +29,6 @@ #include "bladerunner/game_constants.h" #include "bladerunner/ambient_sounds.h" #include "bladerunner/audio_speech.h" -#include "bladerunner/framelimiter.h" #include "bladerunner/font.h" #include "bladerunner/game_info.h" #include "bladerunner/mouse.h" @@ -42,14 +41,9 @@ namespace BladeRunner { EndCredits::EndCredits(BladeRunnerEngine *vm) { _vm = vm; - _framelimiter = new Framelimiter(_vm, Framelimiter::kDefaultFpsRate, Framelimiter::kDefaultUseDelayMillis); } EndCredits::~EndCredits() { - if (_framelimiter) { - delete _framelimiter; - _framelimiter = nullptr; - } } void EndCredits::show() { @@ -98,7 +92,7 @@ void EndCredits::show() { _vm->_vqaStopIsRequested = false; double position = 0.0; - _framelimiter->init(); + uint32 timeLast = _vm->_time->currentSystem(); while (!_vm->_vqaStopIsRequested && !_vm->shouldQuit()) { if (position >= textPositions[textCount - 1]) { @@ -109,15 +103,13 @@ void EndCredits::show() { _vm->handleEvents(); if (!_vm->_windowIsActive) { - _framelimiter->init(); - continue; - } - - if (!_framelimiter->shouldExecuteScreenUpdate()) { + timeLast = _vm->_time->currentSystem(); continue; } - position += (double)(_framelimiter->getTimeOfCurrentPass() - _framelimiter->getTimeOfLastPass()) * 0.05f; // unsigned difference is intentional + uint32 timeNow = _vm->_time->currentSystem(); + position += (double)(timeNow - timeLast) * 0.05f; // unsigned difference is intentional + timeLast = timeNow; _vm->_surfaceFront.fillRect(Common::Rect(640, 480), 0); @@ -154,7 +146,6 @@ void EndCredits::show() { _vm->_surfaceFront.fillRect(Common::Rect(0, 452, 640, 480), 0); _vm->blitToScreen(_vm->_surfaceFront); - _framelimiter->postScreenUpdate(); } _vm->_vqaIsPlaying = false; diff --git a/engines/bladerunner/ui/end_credits.h b/engines/bladerunner/ui/end_credits.h index 6c45adfd60..39086cd796 100644 --- a/engines/bladerunner/ui/end_credits.h +++ b/engines/bladerunner/ui/end_credits.h @@ -26,11 +26,9 @@ namespace BladeRunner { class BladeRunnerEngine; -class Framelimiter; class EndCredits { BladeRunnerEngine *_vm; - Framelimiter *_framelimiter; public: EndCredits(BladeRunnerEngine *vm); diff --git a/engines/bladerunner/ui/esper.cpp b/engines/bladerunner/ui/esper.cpp index f5257bf694..fe59805153 100644 --- a/engines/bladerunner/ui/esper.cpp +++ b/engines/bladerunner/ui/esper.cpp @@ -28,7 +28,6 @@ #include "bladerunner/bladerunner.h" #include "bladerunner/debugger.h" #include "bladerunner/decompress_lcw.h" -#include "bladerunner/framelimiter.h" #include "bladerunner/font.h" #include "bladerunner/game_info.h" #include "bladerunner/mouse.h" @@ -67,17 +66,11 @@ ESPER::ESPER(BladeRunnerEngine *vm) { reset(); _buttons = new UIImagePicker(vm, kPhotoCount + 4); - _framelimiter = new Framelimiter(_vm, Framelimiter::kDefaultFpsRate, Framelimiter::kDefaultUseDelayMillis); } ESPER::~ESPER() { delete _buttons; reset(); - - if (_framelimiter) { - delete _framelimiter; - _framelimiter = nullptr; - } } void ESPER::open(Graphics::Surface *surface) { @@ -122,8 +115,6 @@ void ESPER::open(Graphics::Surface *surface) { _vqaPlayerMain->setLoop(2, -1, kLoopSetModeJustStart, nullptr, nullptr); _isOpen = true; - _framelimiter->init(); - _flash = false; _script = new ESPERScript(_vm); @@ -216,35 +207,30 @@ void ESPER::handleMouseDown(int x, int y, bool mainButton) { void ESPER::tick() { if (!_vm->_windowIsActive) { - _framelimiter->init(); return; } - if (_framelimiter->shouldExecuteScreenUpdate()) { - tickSound(); + tickSound(); - blit(_vm->_surfaceBack, _vm->_surfaceFront); + blit(_vm->_surfaceBack, _vm->_surfaceFront); - int mouseX, mouseY; - _vm->_mouse->getXY(&mouseX, &mouseY); - if (!_vm->_mouse->isDisabled()) { - _buttons->handleMouseAction(mouseX, mouseY, false, false, false); - } - - if (!_isOpen) { - return; - } + int mouseX, mouseY; + _vm->_mouse->getXY(&mouseX, &mouseY); + if (!_vm->_mouse->isDisabled()) { + _buttons->handleMouseAction(mouseX, mouseY, false, false, false); + } - draw(_vm->_surfaceFront); - _buttons->draw(_vm->_surfaceFront); - drawMouse(_vm->_surfaceFront); + if (!_isOpen) { + return; + } - tickSound(); - _vm->_subtitles->tick(_vm->_surfaceFront); - _vm->blitToScreen(_vm->_surfaceFront); + draw(_vm->_surfaceFront); + _buttons->draw(_vm->_surfaceFront); + drawMouse(_vm->_surfaceFront); - _framelimiter->postScreenUpdate(); - } + tickSound(); + _vm->_subtitles->tick(_vm->_surfaceFront); + _vm->blitToScreen(_vm->_surfaceFront); if (_statePhoto == kEsperPhotoStateVideoShow) { if (_regionSelectedAck) { diff --git a/engines/bladerunner/ui/esper.h b/engines/bladerunner/ui/esper.h index 818d51ca44..0c1c6a86e8 100644 --- a/engines/bladerunner/ui/esper.h +++ b/engines/bladerunner/ui/esper.h @@ -31,7 +31,6 @@ namespace BladeRunner { class BladeRunnerEngine; -class Framelimiter; class Font; class Shape; class VQAPlayer; @@ -88,7 +87,6 @@ class ESPER { }; BladeRunnerEngine *_vm; - Framelimiter *_framelimiter; ESPERScript *_script; bool _isWaiting; diff --git a/engines/bladerunner/ui/kia.cpp b/engines/bladerunner/ui/kia.cpp index 501a1e7cf2..3e9011e0c0 100644 --- a/engines/bladerunner/ui/kia.cpp +++ b/engines/bladerunner/ui/kia.cpp @@ -26,7 +26,6 @@ #include "bladerunner/audio_player.h" #include "bladerunner/bladerunner.h" #include "bladerunner/combat.h" -#include "bladerunner/framelimiter.h" #include "bladerunner/font.h" #include "bladerunner/game_constants.h" #include "bladerunner/game_flags.h" @@ -81,6 +80,7 @@ KIA::KIA(BladeRunnerEngine *vm) { _playerPhotograph = nullptr; _playerSliceModelId = -1; _playerSliceModelAngle = 0.0f; + _timeLast = _vm->_time->currentSystem(); _playerActorDialogueQueuePosition = 0; _playerActorDialogueQueueSize = 0; _playerActorDialogueState = 0; @@ -110,9 +110,6 @@ KIA::KIA(BladeRunnerEngine *vm) { _playerActorDialogueQueue[i].actorId = -1; _playerActorDialogueQueue[i].sentenceId = -1; } - - _framelimiter = new Framelimiter(_vm, Framelimiter::kDefaultFpsRate, Framelimiter::kDefaultUseDelayMillis); - _framelimiter->init(); } KIA::~KIA() { @@ -136,11 +133,6 @@ KIA::~KIA() { delete _shapes; delete _log; delete _script; - - if (_framelimiter) { - delete _framelimiter; - _framelimiter = nullptr; - } } void KIA::reset() { @@ -238,13 +230,9 @@ void KIA::tick() { return; } - if (!_framelimiter->shouldExecuteScreenUpdate()) { - return; - } - - uint32 timeNow = _framelimiter->getTimeOfCurrentPass(); + uint32 timeNow = _vm->_time->currentSystem(); // unsigned difference is intentional - uint32 timeDiff = timeNow - _framelimiter->getTimeOfLastPass(); + uint32 timeDiff = timeNow - _timeLast; if (_playerActorDialogueQueueSize == _playerActorDialogueQueuePosition) { _playerActorDialogueState = 0; @@ -396,7 +384,7 @@ void KIA::tick() { _vm->blitToScreen(_vm->_surfaceFront); - _framelimiter->postScreenUpdate(); + _timeLast = timeNow; } void KIA::resume() { @@ -691,8 +679,7 @@ void KIA::init() { playerReset(); _playerVqaFrame = 0; _playerVqaTimeLast = _vm->_time->currentSystem(); - - _framelimiter->init(); + _timeLast = _vm->_time->currentSystem(); if (_vm->_gameFlags->query(kFlagKIAPrivacyAddon) && !_vm->_gameFlags->query(kFlagKIAPrivacyAddonIntro)) { _vm->_gameFlags->set(kFlagKIAPrivacyAddonIntro); diff --git a/engines/bladerunner/ui/kia.h b/engines/bladerunner/ui/kia.h index fdc4d8ef15..2a87f5df6a 100644 --- a/engines/bladerunner/ui/kia.h +++ b/engines/bladerunner/ui/kia.h @@ -34,7 +34,6 @@ struct KeyState; namespace BladeRunner { class BladeRunnerEngine; -class Framelimiter; class KIALog; class KIAScript; class KIASectionBase; @@ -76,7 +75,6 @@ class KIA { }; BladeRunnerEngine *_vm; - Framelimiter *_framelimiter; int _transitionId; @@ -89,7 +87,7 @@ class KIA { int _playerSliceModelId; float _playerSliceModelAngle; Graphics::Surface _playerImage; -// uint32 _timeLast; + uint32 _timeLast; ActorDialogueQueueEntry _playerActorDialogueQueue[kPlayerActorDialogueQueueCapacity]; int _playerActorDialogueQueuePosition; diff --git a/engines/bladerunner/ui/spinner.cpp b/engines/bladerunner/ui/spinner.cpp index 85d2c373bb..27116a8f20 100644 --- a/engines/bladerunner/ui/spinner.cpp +++ b/engines/bladerunner/ui/spinner.cpp @@ -28,7 +28,6 @@ #include "bladerunner/ambient_sounds.h" #include "bladerunner/game_info.h" #include "bladerunner/subtitles.h" -#include "bladerunner/framelimiter.h" #include "bladerunner/game_constants.h" #include "bladerunner/mouse.h" #include "bladerunner/savefile.h" @@ -49,7 +48,6 @@ Spinner::Spinner(BladeRunnerEngine *vm) { reset(); _imagePicker = new UIImagePicker(vm, kSpinnerDestinations); _vqaPlayer = nullptr; - _framelimiter = new Framelimiter(_vm, Framelimiter::kDefaultFpsRate, Framelimiter::kDefaultUseDelayMillis); } Spinner::~Spinner() { @@ -61,11 +59,6 @@ Spinner::~Spinner() { _vqaPlayer->close(); delete _vqaPlayer; } - - if (_framelimiter) { - delete _framelimiter; - _framelimiter = nullptr; - } } void Spinner::setSelectableDestinationFlag(int destination, bool selectable) { @@ -237,7 +230,6 @@ void Spinner::mouseUpCallback(int destinationImage, void *self) { void Spinner::open() { _isOpen = true; - _framelimiter->init(); } bool Spinner::isOpen() const { @@ -256,35 +248,30 @@ int Spinner::handleMouseDown(int x, int y) { void Spinner::tick() { if (!_vm->_windowIsActive) { - _framelimiter->init(); return; } - if (_framelimiter->shouldExecuteScreenUpdate()) { - int frame = _vqaPlayer->update(); - assert(frame >= -1); + int frame = _vqaPlayer->update(); + assert(frame >= -1); - // vqaPlayer renders to _surfaceBack - blit(_vm->_surfaceBack, _vm->_surfaceFront); - - Common::Point p = _vm->getMousePos(); - _imagePicker->handleMouseAction(p.x, p.y, false, false, false); - if (_imagePicker->hasHoveredImage()) { - _vm->_mouse->setCursor(1); - } else { - _vm->_mouse->setCursor(0); - } - _imagePicker->draw(_vm->_surfaceFront); - _vm->_mouse->draw(_vm->_surfaceFront, p.x, p.y); - _imagePicker->drawTooltip(_vm->_surfaceFront, p.x, p.y); + // vqaPlayer renders to _surfaceBack + blit(_vm->_surfaceBack, _vm->_surfaceFront); - if (_vm->_cutContent) { - _vm->_subtitles->tick(_vm->_surfaceFront); - } - _vm->blitToScreen(_vm->_surfaceFront); - _framelimiter->postScreenUpdate(); + Common::Point p = _vm->getMousePos(); + _imagePicker->handleMouseAction(p.x, p.y, false, false, false); + if (_imagePicker->hasHoveredImage()) { + _vm->_mouse->setCursor(1); + } else { + _vm->_mouse->setCursor(0); + } + _imagePicker->draw(_vm->_surfaceFront); + _vm->_mouse->draw(_vm->_surfaceFront, p.x, p.y); + _imagePicker->drawTooltip(_vm->_surfaceFront, p.x, p.y); + if (_vm->_cutContent) { + _vm->_subtitles->tick(_vm->_surfaceFront); } + _vm->blitToScreen(_vm->_surfaceFront); if (_vm->_cutContent) { tickDescription(); diff --git a/engines/bladerunner/ui/spinner.h b/engines/bladerunner/ui/spinner.h index 78c2943eb2..2fa0dc659c 100644 --- a/engines/bladerunner/ui/spinner.h +++ b/engines/bladerunner/ui/spinner.h @@ -29,7 +29,6 @@ namespace BladeRunner { class BladeRunnerEngine; -class Framelimiter; class SaveFileReadStream; class SaveFileWriteStream; class Shape; @@ -45,7 +44,6 @@ class Spinner { }; BladeRunnerEngine *_vm; - Framelimiter *_framelimiter; bool _isDestinationSelectable[kSpinnerDestinations]; bool _isOpen; VQAPlayer *_vqaPlayer; diff --git a/engines/bladerunner/ui/vk.cpp b/engines/bladerunner/ui/vk.cpp index 7e24b798b6..245bae9512 100644 --- a/engines/bladerunner/ui/vk.cpp +++ b/engines/bladerunner/ui/vk.cpp @@ -27,7 +27,6 @@ #include "bladerunner/audio_player.h" #include "bladerunner/bladerunner.h" #include "bladerunner/combat.h" -#include "bladerunner/framelimiter.h" #include "bladerunner/font.h" #include "bladerunner/game_constants.h" #include "bladerunner/game_flags.h" @@ -54,16 +53,10 @@ VK::VK(BladeRunnerEngine *vm) { _vm = vm; reset(); - _framelimiter = new Framelimiter(_vm, Framelimiter::kDefaultFpsRate, Framelimiter::kDefaultUseDelayMillis); } VK::~VK() { reset(); - - if (_framelimiter) { - delete _framelimiter; - _framelimiter = nullptr; - } } void VK::open(int actorId, int calibrationRatio) { @@ -133,7 +126,6 @@ void VK::open(int actorId, int calibrationRatio) { } _isOpen = true; - _framelimiter->init(); _script = new VKScript(_vm); @@ -198,31 +190,27 @@ void VK::close() { } void VK::tick() { + int mouseX, mouseY; + _vm->_mouse->getXY(&mouseX, &mouseY); + if (!_vm->_mouse->isDisabled()) { + _buttons->handleMouseAction(mouseX, mouseY, false, false, false); + } - if (_framelimiter->shouldExecuteScreenUpdate()) { - int mouseX, mouseY; - _vm->_mouse->getXY(&mouseX, &mouseY); - if (!_vm->_mouse->isDisabled()) { - _buttons->handleMouseAction(mouseX, mouseY, false, false, false); - } - - draw(); + draw(); - if ( _vm->_debugger->_showStatsVk - && !_vm->_actors[_actorId]->isSpeeching() - && !_vm->_actors[kActorMcCoy]->isSpeeching() - && !_vm->_actors[kActorAnsweringMachine]->isSpeeching() - && !_isClosing - ) { - _vm->_subtitles->setGameSubsText(Common::String::format("Calibration: %02d Ratio: %02d Anxiety: %02d%%\nReplicant: %02d%% Human: %02d%%", _calibration, _calibrationRatio, _anxiety, _replicantProbability, _humanProbability), true); - _vm->_subtitles->show(); - } + if ( _vm->_debugger->_showStatsVk + && !_vm->_actors[_actorId]->isSpeeching() + && !_vm->_actors[kActorMcCoy]->isSpeeching() + && !_vm->_actors[kActorAnsweringMachine]->isSpeeching() + && !_isClosing + ) { + _vm->_subtitles->setGameSubsText(Common::String::format("Calibration: %02d Ratio: %02d Anxiety: %02d%%\nReplicant: %02d%% Human: %02d%%", _calibration, _calibrationRatio, _anxiety, _replicantProbability, _humanProbability), true); + _vm->_subtitles->show(); + } - _vm->_subtitles->tick(_vm->_surfaceFront); + _vm->_subtitles->tick(_vm->_surfaceFront); - _vm->blitToScreen(_vm->_surfaceFront); - _framelimiter->postScreenUpdate(); - } + _vm->blitToScreen(_vm->_surfaceFront); // unsigned difference is intentional if (_isClosing && (_vm->_time->current() - _timeCloseStart >= 3000u) && !_script->isInsideScript()) { diff --git a/engines/bladerunner/ui/vk.h b/engines/bladerunner/ui/vk.h index a8802046e3..eeaee1b54d 100644 --- a/engines/bladerunner/ui/vk.h +++ b/engines/bladerunner/ui/vk.h @@ -31,7 +31,6 @@ namespace BladeRunner { class BladeRunnerEngine; -class Framelimiter; class VKScript; class Shape; class UIImagePicker; @@ -48,7 +47,6 @@ class VK { }; BladeRunnerEngine *_vm; - Framelimiter *_framelimiter; VKScript *_script; |