From 58884b1244e2ff88aeeec4d5f281c56ec9ba3139 Mon Sep 17 00:00:00 2001 From: Sylvain Dupont Date: Sat, 5 Feb 2011 12:11:57 +0000 Subject: TOON: Add some sleep if the game refreshes too fast Prevents the game from using 100% CPU? svn-id: r55786 --- engines/toon/toon.cpp | 10 ++++++++++ engines/toon/toon.h | 1 + 2 files changed, 11 insertions(+) (limited to 'engines') diff --git a/engines/toon/toon.cpp b/engines/toon/toon.cpp index eb4120123d..a9b0d7aa5e 100644 --- a/engines/toon/toon.cpp +++ b/engines/toon/toon.cpp @@ -160,6 +160,7 @@ void ToonEngine::init() { _lastMouseButton = 0; _mouseButton = 0; + _lastRenderTime = _system->getMillis(); } void ToonEngine::waitForScriptStep() { @@ -417,6 +418,15 @@ void ToonEngine::render() { } else { copyToVirtualScreen(true); } + + // add a little sleep here if needed. + int32 newMillis = (int32)_system->getMillis(); + if(newMillis - _lastRenderTime < _tickLength) { + int32 sleepMs = _tickLength - ( _system->getMillis() - _lastRenderTime ); + assert(sleepMs >= 0); + _system->delayMillis(sleepMs); + } + _lastRenderTime = _system->getMillis(); } void ToonEngine::doMagnifierEffect() { diff --git a/engines/toon/toon.h b/engines/toon/toon.h index c16336722d..0627674cd6 100644 --- a/engines/toon/toon.h +++ b/engines/toon/toon.h @@ -407,6 +407,7 @@ protected: int32 _oldTimer; int32 _oldTimer2; + int32 _lastRenderTime; Movie *_moviePlayer; -- cgit v1.2.3