Skip to content
Browse files

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.
  • Loading branch information
isilkor committed Oct 28, 2016
1 parent f2231e8 commit bce0b454133099d74b9301063db71f619e67fda7
Showing with 4 additions and 2 deletions.
  1. +4 −2 src/platform/C4App.cpp
@@ -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]() {
@@ -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));

0 comments on commit bce0b45

Please sign in to comment.
You can’t perform that action at this time.