TOLTECS: Change the updateScreen() logic a bit

Updating the screen when getMillis() % 10 is 0 seems sub-optimal
to me. It could be true several iterations in a row (shouldn't be
harmful, since updateScreen is assumed to be cheap if the screen
hasn't changed) or we could miss it every single time. Let's
measure the time between updates instead, just to be safer.
This commit is contained in:
Torbjörn Andersson 2011-11-20 23:37:25 +01:00
parent bc4397bf3e
commit 9f5f240e90

View file

@ -183,6 +183,7 @@ void ScriptInterpreter::setMainScript(uint slotIndex) {
}
void ScriptInterpreter::runScript() {
uint32 lastScreenUpdate = 0;
while (!_vm->shouldQuit()) {
@ -217,9 +218,13 @@ void ScriptInterpreter::runScript() {
byte opcode = readByte();
execOpcode(opcode);
// Call updateScreen roughly every 10ms else the mouse cursor will be jerky
if (_vm->_system->getMillis() % 10 == 0)
// Update the screen at semi-regular intervals, else the mouse
// cursor will be jerky.
uint32 now = _vm->_system->getMillis();
if (now < lastScreenUpdate || now - lastScreenUpdate > 10) {
_vm->_system->updateScreen();
lastScreenUpdate = _vm->_system->getMillis();
}
}