From 83d3af60091263d78df05121d67c8945fca76a5a Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sat, 24 Aug 2019 20:03:44 +0200 Subject: HDB: Make the frame delay variable in order to have a more stable frame rate --- engines/hdb/hdb.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'engines') diff --git a/engines/hdb/hdb.cpp b/engines/hdb/hdb.cpp index 1a8c81160d..62e2ec8d67 100644 --- a/engines/hdb/hdb.cpp +++ b/engines/hdb/hdb.cpp @@ -803,14 +803,12 @@ void HDBGame::drawProgressBar() { } void HDBGame::checkProgress() { - int x, i; - if (!_progressActive) return; - x = _screenWidth / 2 - _progressGfx->_width / 2; + int x = _screenWidth / 2 - _progressGfx->_width / 2; _progressGfx->drawMasked(x, g_hdb->_progressY); - for (i = x; i < _progressXOffset; i += _progressMarkGfx->_width) + for (int i = x; i < _progressXOffset; i += _progressMarkGfx->_width) _progressMarkGfx->drawMasked(i, g_hdb->_progressY); _progressMarkGfx->drawMasked(_progressXOffset, g_hdb->_progressY); } @@ -943,6 +941,7 @@ Common::Error HDBGame::run() { lua->executeFile("test.lua"); #endif + uint32 lastTime = g_system->getMillis(); while (!shouldQuit()) { Common::Event event; while (g_system->getEventManager()->pollEvent(event)) { @@ -1053,7 +1052,15 @@ Common::Error HDBGame::run() { while (g_hdb->_frames[0] < g_system->getMillis() - 1000) g_hdb->_frames.remove_at(0); } - g_system->delayMillis(1000 / kGameFPS); + uint32 curTime = g_system->getMillis(); + uint32 frameTime = curTime - lastTime; + + uint32 frameCap = 1000 / kGameFPS; + if (frameTime < frameCap) { + g_system->delayMillis(frameCap - frameTime); + } + + lastTime = g_system->getMillis(); } return Common::kNoError; -- cgit v1.2.3