History

Application: don't simulate until we are ready to render.

Anthony J. Thibault committed 10 years ago

Commit 1fdae131 parent 8422d4f2 files · +17 −33Browse files

Showing the changes to interface/src/Application.cpp (1 of 2 files). Show all

Unified · Split

interface/src/Application.cpp+17−32
@@ -210,8 +210,6 @@ static const QString INFO_EDIT_ENTITIES_PATH = "html/edit-commands.html"; · 209 unmodified lines
210210
211211 static const unsigned int THROTTLED_SIM_FRAMERATE = 15;
212212 static const int THROTTLED_SIM_FRAME_PERIOD_MS = MSECS_PER_SECOND / THROTTLED_SIM_FRAMERATE;
213−static const unsigned int CAPPED_SIM_FRAMERATE = 120;
214−static const int CAPPED_SIM_FRAME_PERIOD_MS = MSECS_PER_SECOND / CAPPED_SIM_FRAMERATE;
215213
216214 static const uint32_t INVALID_FRAME = UINT32_MAX;
217215
@@ -317,6 +315,9 @@ bool setupEssentials(int& argc, char** argv) { · 99 unmodified lines
317315
318316 Setting::preInit();
319317
318+ LogHandler::getInstance().setShouldDisplayMilliseconds(true);
319+ LogHandler::getInstance().setShouldOutputThreadID(true);
320+
320321 CrashHandler::checkForAndHandleCrash();
321322 CrashHandler::writeRunningMarkerFiler();
322323 qAddPostRoutine(CrashHandler::deleteRunningMarkerFile);
@@ -967,6 +968,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) : · 644 unmodified lines
967968
968969 connect(this, &Application::applicationStateChanged, this, &Application::activeChanged);
969970 qCDebug(interfaceapp, "Startup time: %4.2f seconds.", (double)startupTimer.elapsed() / 1000.0);
971+
970972 _idleTimer = new QTimer(this);
971973 connect(_idleTimer, &QTimer::timeout, [=] {
972974 idle(usecTimestampNow());
@@ -975,7 +977,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) : · 2 unmodified lines
975977 disconnect(_idleTimer);
976978 });
977979 // Setting the interval to zero forces this to get called whenever there are no messages
978− // in the queue, which can be pretty damn frequent. Hence the idle function has a bunch
980+ // in the queue, which can be pretty damn frequent. Hence the idle function has a bunch
979981 // of logic to abort early if it's being called too often.
980982 _idleTimer->start(0);
981983 }
@@ -1296,6 +1298,7 @@ void Application::initializeUi() { · 314 unmodified lines
12961298 }
12971299
12981300 void Application::paintGL() {
1301+
12991302 // paintGL uses a queued connection, so we can get messages from the queue even after we've quit
13001303 // and the plugins have shutdown
13011304 if (_aboutToQuit) {
@@ -1321,10 +1324,6 @@ void Application::paintGL() { · 19 unmodified lines
13211324 _lastFramesPerSecondUpdate = now;
13221325 }
13231326
1324− if (_isGLInitialized) {
1325− idle(now);
1326− }
1327−
13281327 PROFILE_RANGE(__FUNCTION__);
13291328 PerformanceTimer perfTimer("paintGL");
13301329
@@ -1619,7 +1618,6 @@ void Application::paintGL() { · 288 unmodified lines
16191618 }
16201619
16211620 _lastInstantaneousFps = instantaneousFps;
1622− _pendingPaint = false;
16231621 }
16241622
16251623 void Application::runTests() {
@@ -2432,10 +2430,11 @@ bool Application::acceptSnapshot(const QString& urlString) { · 806 unmodified lines
24322430 static uint32_t _renderedFrameIndex { INVALID_FRAME };
24332431
24342432 void Application::idle(uint64_t now) {
2433+
24352434 if (_aboutToQuit) {
24362435 return; // bail early, nothing to do here.
24372436 }
2438−
2437+
24392438 auto displayPlugin = getActiveDisplayPlugin();
24402439 // depending on whether we're throttling or not.
24412440 // Once rendering is off on another thread we should be able to have Application::idle run at start(0) in
@@ -2456,30 +2455,16 @@ void Application::idle(uint64_t now) { · 14 unmodified lines
24562455 _renderedFrameIndex = INVALID_FRAME;
24572456 }
24582457
2459− // Nested ifs are for clarity in the logic. Don't collapse them into a giant single if.
24602458 // Don't saturate the main thread with rendering, no paint calls until the last one is complete
2461− if (!_pendingPaint) {
2462− // Also no paint calls until the display plugin has increased by at least one frame
2463− // (don't render at 90fps if the display plugin only goes at 60)
2464− if (_renderedFrameIndex == INVALID_FRAME || presentCount > _renderedFrameIndex) {
2465− // Record what present frame we're on
2466− _renderedFrameIndex = presentCount;
2467− // Don't allow paint requests to stack up in the event queue
2468− _pendingPaint = true;
2469− // But when we DO request a paint, get to it as soon as possible: high priority
2470− postEvent(this, new QEvent(static_cast<QEvent::Type>(Paint)), Qt::HighEventPriority);
2471− }
2472− }
2473−
2474− // For the rest of idle, we want to cap at the max sim rate, so we might not call
2475− // the remaining idle work every paint frame, or vice versa
2476− // In theory this means we could call idle processing more often than painting,
2477− // but in practice, when the paintGL calls aren't keeping up, there's no room left
2478− // in the main thread to call idle more often than paint.
2479− // This check is mostly to keep idle from burning up CPU cycles by running at
2480− // hundreds of idles per second when the rendering is that fast
2481− if ((timeSinceLastUpdateUs / USECS_PER_MSEC) < CAPPED_SIM_FRAME_PERIOD_MS) {
2482− // No paint this round, but might be time for a new idle, otherwise return
2459+ // Also no paint calls until the display plugin has increased by at least one frame
2460+ // (don't render at 90fps if the display plugin only goes at 60)
2461+ if (_renderedFrameIndex == INVALID_FRAME || presentCount > _renderedFrameIndex) {
2462+ // Record what present frame we're on
2463+ _renderedFrameIndex = presentCount;
2464+
2465+ // But when we DO request a paint, get to it as soon as possible: high priority
2466+ postEvent(this, new QEvent(static_cast<QEvent::Type>(Paint)), Qt::HighEventPriority);
2467+ } else {
24832468 return;
24842469 }
24852470