Codechange: track _realtime_tick more accurate

_realtime_tick was reset every time the diff was calculated. This
means if it would trigger, say, every N.9 milliseconds, it would
after two iterations already drift a millisecond. This adds up
pretty quick.
This commit is contained in:
Patric Stout
2021-02-17 14:49:45 +01:00
committed by Patric Stout
parent 25f6851ca1
commit 5bfa014505
7 changed files with 55 additions and 18 deletions

View File

@@ -448,7 +448,7 @@ void VideoDriver_Allegro::Stop()
void VideoDriver_Allegro::MainLoop()
{
auto cur_ticks = std::chrono::steady_clock::now();
auto last_cur_ticks = cur_ticks;
auto last_realtime_tick = cur_ticks;
auto next_tick = cur_ticks;
CheckPaletteAnim();
@@ -473,9 +473,15 @@ void VideoDriver_Allegro::MainLoop()
}
cur_ticks = std::chrono::steady_clock::now();
/* If more than a millisecond has passed, increase the _realtime_tick. */
if (cur_ticks - last_realtime_tick > std::chrono::milliseconds(1)) {
auto delta = std::chrono::duration_cast<std::chrono::milliseconds>(cur_ticks - last_realtime_tick);
_realtime_tick += delta.count();
last_realtime_tick += delta;
}
if (cur_ticks >= next_tick || (_fast_forward && !_pause_mode)) {
_realtime_tick += std::chrono::duration_cast<std::chrono::milliseconds>(cur_ticks - last_cur_ticks).count();
last_cur_ticks = cur_ticks;
next_tick = cur_ticks + std::chrono::milliseconds(MILLISECONDS_PER_TICK);
bool old_ctrl_pressed = _ctrl_pressed;