This is probably a better way to schedule execution.

One step ahead rather than one step behind.

Signed-off-by: Andrea Odetti <mariofutire@gmail.com>
This commit is contained in:
Andrea Odetti 2019-11-07 21:30:05 +00:00
parent 730e35150a
commit 54a1bb4991

View file

@ -228,11 +228,20 @@ void QApple::closeEvent(QCloseEvent *)
void QApple::on_timer() 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 current = emulatorTimeInMS() - myCpuTimeReference;
const qint64 elapsed = target - current; const qint64 elapsed = target - current;
if (elapsed <= 0) if (elapsed <= 0)
{ {
// we got ahead of the timer by a lot
// wait next call
return; return;
} }
@ -279,8 +288,7 @@ void QApple::stopTimer()
void QApple::restartTimeCounters() void QApple::restartTimeCounters()
{ {
myElapsedTimer.start(); myElapsedTimer.invalidate();
myCpuTimeReference = emulatorTimeInMS();
} }
void QApple::on_actionStart_triggered() void QApple::on_actionStart_triggered()