History

Merge branch 'master' of github.com:highfidelity/hifi into parents

Seth Alves committed 11 years ago

Commit ffb03172 parents fbaa864 71e40929 files · +65 −123Browse files

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

Unified · Split

interface/src/Application.cpp+27−22
@@ -161,8 +161,7 @@ static QTimer locationUpdateTimer; · 160 unmodified lines
161161 static QTimer balanceUpdateTimer;
162162 static QTimer identityPacketTimer;
163163 static QTimer billboardPacketTimer;
164−static QTimer checkFPStimer;
165−static QTimer idleTimer;
164+static QTimer pingTimer;
166165
167166 static const QString SNAPSHOT_EXTENSION = ".jpg";
168167 static const QString SVO_EXTENSION = ".svo";
@@ -186,9 +185,7 @@ static const quint64 TOO_LONG_SINCE_LAST_SEND_DOWNSTREAM_AUDIO_STATS = 1 * USECS · 17 unmodified lines
186185 static const QString INFO_HELP_PATH = "html/interface-welcome.html";
187186 static const QString INFO_EDIT_ENTITIES_PATH = "html/edit-commands.html";
188187
189−static const unsigned int TARGET_SIM_FRAMERATE = 60;
190188 static const unsigned int THROTTLED_SIM_FRAMERATE = 15;
191−static const int TARGET_SIM_FRAME_PERIOD_MS = MSECS_PER_SECOND / TARGET_SIM_FRAMERATE;
192189 static const int THROTTLED_SIM_FRAME_PERIOD_MS = MSECS_PER_SECOND / THROTTLED_SIM_FRAMERATE;
193190
194191 #ifndef __APPLE__
@@ -847,8 +844,7 @@ void Application::cleanupBeforeQuit() { · 652 unmodified lines
847844 balanceUpdateTimer.stop();
848845 identityPacketTimer.stop();
849846 billboardPacketTimer.stop();
850− checkFPStimer.stop();
851− idleTimer.stop();
847+ pingTimer.stop();
852848 QMetaObject::invokeMethod(&_settingsTimer, "stop", Qt::BlockingQueuedConnection);
853849
854850 // save state
@@ -983,12 +979,9 @@ void Application::initializeGL() { · 128 unmodified lines
983979 _entityEditSender.initialize(_enableProcessOctreeThread);
984980
985981 // call our timer function every second
986− connect(&checkFPStimer, &QTimer::timeout, this, &Application::checkFPS);
987− checkFPStimer.start(1000);
982+ connect(&pingTimer, &QTimer::timeout, this, &Application::ping);
983+ pingTimer.start(1000);
988984
989− // call our idle function whenever we can
990− connect(&idleTimer, &QTimer::timeout, this, &Application::idle);
991− idleTimer.start(TARGET_SIM_FRAME_PERIOD_MS);
992985 _idleLoopStdev.reset();
993986
994987 // update before the first render
@@ -1052,6 +1045,26 @@ void Application::initializeUi() { · 57 unmodified lines
10521045 }
10531046
10541047 void Application::paintGL() {
1048+ _frameCount++;
1049+
1050+ // update fps moving average
1051+ uint64_t now = usecTimestampNow();
1052+ static uint64_t lastPaintBegin{ now };
1053+ uint64_t diff = now - lastPaintBegin;
1054+ if (diff != 0) {
1055+ _framesPerSecond.updateAverage((float)USECS_PER_SECOND / (float)diff);
1056+ }
1057+
1058+ lastPaintBegin = now;
1059+
1060+ // update fps once a second
1061+ if (now - _lastFramesPerSecondUpdate > USECS_PER_SECOND) {
1062+ _fps = _framesPerSecond.getAverage();
1063+ _lastFramesPerSecondUpdate = now;
1064+ }
1065+
1066+ idle(now);
1067+
10551068 PROFILE_RANGE(__FUNCTION__);
10561069 PerformanceTimer perfTimer("paintGL");
10571070
@@ -1318,7 +1331,6 @@ void Application::paintGL() { · 260 unmodified lines
13181331 {
13191332 PerformanceTimer perfTimer("makeCurrent");
13201333 _offscreenContext->makeCurrent();
1321− _frameCount++;
13221334 Stats::getInstance()->setRenderDetails(renderArgs._details);
13231335
13241336 // Reset the gpu::Context Stages
@@ -2091,20 +2103,14 @@ bool Application::acceptSnapshot(const QString& urlString) { · 766 unmodified lines
20912103 return true;
20922104 }
20932105
2094−// Every second, check the frame rates and other stuff
2095−void Application::checkFPS() {
2106+// Every second, send a ping, if menu item is checked.
2107+void Application::ping() {
20962108 if (Menu::getInstance()->isOptionChecked(MenuOption::TestPing)) {
20972109 DependencyManager::get<NodeList>()->sendPingPackets();
20982110 }
2099−
2100− float diffTime = (float)_timerStart.nsecsElapsed() / 1000000000.0f;
2101−
2102− _fps = (float)_frameCount / diffTime;
2103− _frameCount = 0;
2104− _timerStart.start();
21052111 }
21062112
2107−void Application::idle() {
2113+void Application::idle(uint64_t now) {
21082114 if (_aboutToQuit) {
21092115 return; // bail early, nothing to do here.
21102116 }
@@ -2127,7 +2133,6 @@ void Application::idle() { · 16 unmodified lines
21272133
21282134 {
21292135 PROFILE_RANGE(__FUNCTION__);
2130− uint64_t now = usecTimestampNow();
21312136 static uint64_t lastIdleStart{ now };
21322137 uint64_t idleStartToStartDuration = now - lastIdleStart;
21332138 if (idleStartToStartDuration != 0) {