From 54a1bb4991be18d706217660a61cd58a46aef6e1 Mon Sep 17 00:00:00 2001 From: Andrea Odetti Date: Thu, 7 Nov 2019 21:30:05 +0000 Subject: [PATCH] This is probably a better way to schedule execution. One step ahead rather than one step behind. Signed-off-by: Andrea Odetti --- source/frontends/qapple/qapple.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/source/frontends/qapple/qapple.cpp b/source/frontends/qapple/qapple.cpp index ffaf15f5..bc9abde3 100644 --- a/source/frontends/qapple/qapple.cpp +++ b/source/frontends/qapple/qapple.cpp @@ -228,11 +228,20 @@ void QApple::closeEvent(QCloseEvent *) void QApple::on_timer() { - const qint64 target = myElapsedTimer.elapsed(); + if (!myElapsedTimer.isValid()) + { + myElapsedTimer.start(); + myCpuTimeReference = emulatorTimeInMS(); + } + + // target x ms ahead of where we are now, which is when the timer should be called again + const qint64 target = myElapsedTimer.elapsed() + myMSGap; const qint64 current = emulatorTimeInMS() - myCpuTimeReference; const qint64 elapsed = target - current; if (elapsed <= 0) { + // we got ahead of the timer by a lot + // wait next call return; } @@ -279,8 +288,7 @@ void QApple::stopTimer() void QApple::restartTimeCounters() { - myElapsedTimer.start(); - myCpuTimeReference = emulatorTimeInMS(); + myElapsedTimer.invalidate(); } void QApple::on_actionStart_triggered()