Skip to content

Commit

Permalink
COMPOSER: Another attempt to fix timing issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
fuzzie committed Aug 23, 2011
1 parent b777a2f commit fca52e0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
17 changes: 15 additions & 2 deletions engines/composer/composer.cpp
Expand Up @@ -97,9 +97,13 @@ Common::Error ComposerEngine::run() {

loadLibrary(0);

_currentTime = 0;
_lastTime = 0;

uint fps = atoi(getStringFromConfig("Common", "FPS").c_str());
uint frameTime = 1000 / fps;
uint32 lastDrawTime = 0;

while (!shouldQuit()) {
for (uint i = 0; i < _pendingPageChanges.size(); i++) {
if (_pendingPageChanges[i]._remove)
Expand All @@ -112,15 +116,24 @@ Common::Error ComposerEngine::run() {
_pendingPageChanges.clear();

uint32 thisTime = _system->getMillis();
// maintain our own internal timing, since otherwise we get
// confused when starved of CPU (for example when the user
// is dragging the scummvm window around)
if (thisTime > _lastTime + frameTime)
_currentTime += frameTime;
else
_currentTime += thisTime - _lastTime;
_lastTime = thisTime;

for (uint i = 0; i < _queuedScripts.size(); i++) {
QueuedScript &script = _queuedScripts[i];
if (!script._count)
continue;
if (script._baseTime + script._duration > thisTime)
if (script._baseTime + script._duration > _currentTime)
continue;
if (script._count != 0xffffffff)
script._count--;
script._baseTime = thisTime;
script._baseTime = _currentTime;
runScript(script._scriptId, i, 0, 0);
}

Expand Down
2 changes: 2 additions & 0 deletions engines/composer/composer.h
Expand Up @@ -140,6 +140,8 @@ class ComposerEngine : public Engine {
Audio::QueuingAudioStream *_audioStream;
uint16 _currSoundPriority;

uint32 _currentTime, _lastTime;

bool _needsUpdate;
Common::Array<Common::Rect> _dirtyRects;
Graphics::Surface _surface;
Expand Down
4 changes: 2 additions & 2 deletions engines/composer/scripting.cpp
Expand Up @@ -531,7 +531,7 @@ int16 ComposerEngine::scriptFuncCall(uint16 id, int16 param1, int16 param2, int1
return 0;
case kFuncQueueScript:
debug(3, "kFuncQueueScript(%d, %d, %d)", param1, param2, param3);
_queuedScripts[param1]._baseTime = _system->getMillis();
_queuedScripts[param1]._baseTime = _currentTime;
_queuedScripts[param1]._duration = 10 * param2;
_queuedScripts[param1]._count = 0xffffffff;
_queuedScripts[param1]._scriptId = param3;
Expand Down Expand Up @@ -642,7 +642,7 @@ int16 ComposerEngine::scriptFuncCall(uint16 id, int16 param1, int16 param2, int1
return 1;
case kFuncQueueScriptOnce:
debug(3, "kFuncQueueScriptOnce(%d, %d, %d)", param1, param2, param3);
_queuedScripts[param1]._baseTime = _system->getMillis();
_queuedScripts[param1]._baseTime = _currentTime;
_queuedScripts[param1]._duration = 10 * param2;
_queuedScripts[param1]._count = 1;
_queuedScripts[param1]._scriptId = param3;
Expand Down

0 comments on commit fca52e0

Please sign in to comment.