Editor: Fix scheduler timer so it doesn't busy wait (#1834)

36/1000 is always 0 and doesn't make a lot of sense anyway. Use 1000/36
(aka 1000ms/36fps) instead so the UI thread has some time to rest.

Also use a Qt::PreciseTimer so Qt doesn't try to coalesce the scheduler
timer with other timers to save energy.
directional-lights
Nicolas Hake 2016-10-28 21:31:00 +02:00
parent f2231e848e
commit bce0b45413
1 changed files with 4 additions and 2 deletions

View File

@ -29,8 +29,9 @@ void C4AbstractApp::Run()
if (Application.isEditor)
{
// Qt has its own event loop. Use a timer to call our own event handling whenever Qt is done
// with its events (zero timeout). The alternative (calling Qt's event handling from
// with its events. The alternative (calling Qt's event handling from
// C4Console::Execute) is too slow, at least on Linux.
// FIXME: All of this should be happening in a background thread instead of on the UI thread
QTimer timer;
QObject::connect(&timer, &QTimer::timeout, [this, &timer]() {
ScheduleProcs(0);
@ -41,8 +42,9 @@ void C4AbstractApp::Run()
}
auto now = C4TimeMilliseconds::Now();
auto next_tick = GetNextTick(now);
timer.setInterval(Clamp(next_tick - now, 0, 36/1000));
timer.setInterval(Clamp(next_tick - now, 0, 1000/36));
});
timer.setTimerType(Qt::PreciseTimer);
timer.start();
QApplication::exec();
return;