Showing the changes to interface/src/Application.cpp (1 of 9 files). Show all
Unified · Split
| @@ -161,8 +161,7 @@ static QTimer locationUpdateTimer; · 160 unmodified lines | |||
| 161 | static QTimer balanceUpdateTimer; | 161 | static QTimer balanceUpdateTimer; |
| 162 | static QTimer identityPacketTimer; | 162 | static QTimer identityPacketTimer; |
| 163 | static QTimer billboardPacketTimer; | 163 | static QTimer billboardPacketTimer; |
| 164 | static QTimer checkFPStimer; | 164 | static QTimer pingTimer; |
| 165 | static QTimer idleTimer; | ||
| 166 | 165 | ||
| 167 | static const QString SNAPSHOT_EXTENSION = ".jpg"; | 166 | static const QString SNAPSHOT_EXTENSION = ".jpg"; |
| 168 | static const QString SVO_EXTENSION = ".svo"; | 167 | 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 | |||
| 186 | static const QString INFO_HELP_PATH = "html/interface-welcome.html"; | 185 | static const QString INFO_HELP_PATH = "html/interface-welcome.html"; |
| 187 | static const QString INFO_EDIT_ENTITIES_PATH = "html/edit-commands.html"; | 186 | static const QString INFO_EDIT_ENTITIES_PATH = "html/edit-commands.html"; |
| 188 | 187 | ||
| 189 | static const unsigned int TARGET_SIM_FRAMERATE = 60; | ||
| 190 | static const unsigned int THROTTLED_SIM_FRAMERATE = 15; | 188 | static const unsigned int THROTTLED_SIM_FRAMERATE = 15; |
| 191 | static const int TARGET_SIM_FRAME_PERIOD_MS = MSECS_PER_SECOND / TARGET_SIM_FRAMERATE; | ||
| 192 | static const int THROTTLED_SIM_FRAME_PERIOD_MS = MSECS_PER_SECOND / THROTTLED_SIM_FRAMERATE; | 189 | static const int THROTTLED_SIM_FRAME_PERIOD_MS = MSECS_PER_SECOND / THROTTLED_SIM_FRAMERATE; |
| 193 | 190 | ||
| 194 | #ifndef __APPLE__ | 191 | #ifndef __APPLE__ |
| @@ -847,8 +844,7 @@ void Application::cleanupBeforeQuit() { · 652 unmodified lines | |||
| 847 | balanceUpdateTimer.stop(); | 844 | balanceUpdateTimer.stop(); |
| 848 | identityPacketTimer.stop(); | 845 | identityPacketTimer.stop(); |
| 849 | billboardPacketTimer.stop(); | 846 | billboardPacketTimer.stop(); |
| 850 | checkFPStimer.stop(); | 847 | pingTimer.stop(); |
| 851 | idleTimer.stop(); | ||
| 852 | QMetaObject::invokeMethod(&_settingsTimer, "stop", Qt::BlockingQueuedConnection); | 848 | QMetaObject::invokeMethod(&_settingsTimer, "stop", Qt::BlockingQueuedConnection); |
| 853 | 849 | ||
| 854 | // save state | 850 | // save state |
| @@ -983,12 +979,9 @@ void Application::initializeGL() { · 128 unmodified lines | |||
| 983 | _entityEditSender.initialize(_enableProcessOctreeThread); | 979 | _entityEditSender.initialize(_enableProcessOctreeThread); |
| 984 | 980 | ||
| 985 | // call our timer function every second | 981 | // call our timer function every second |
| 986 | connect(&checkFPStimer, &QTimer::timeout, this, &Application::checkFPS); | 982 | connect(&pingTimer, &QTimer::timeout, this, &Application::ping); |
| 987 | checkFPStimer.start(1000); | 983 | pingTimer.start(1000); |
| 988 | 984 | ||
| 989 | // call our idle function whenever we can | ||
| 990 | connect(&idleTimer, &QTimer::timeout, this, &Application::idle); | ||
| 991 | idleTimer.start(TARGET_SIM_FRAME_PERIOD_MS); | ||
| 992 | _idleLoopStdev.reset(); | 985 | _idleLoopStdev.reset(); |
| 993 | 986 | ||
| 994 | // update before the first render | 987 | // update before the first render |
| @@ -1052,6 +1045,26 @@ void Application::initializeUi() { · 57 unmodified lines | |||
| 1052 | } | 1045 | } |
| 1053 | 1046 | ||
| 1054 | void Application::paintGL() { | 1047 | 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 | |||
| 1055 | PROFILE_RANGE(__FUNCTION__); | 1068 | PROFILE_RANGE(__FUNCTION__); |
| 1056 | PerformanceTimer perfTimer("paintGL"); | 1069 | PerformanceTimer perfTimer("paintGL"); |
| 1057 | 1070 | ||
| @@ -1318,7 +1331,6 @@ void Application::paintGL() { · 260 unmodified lines | |||
| 1318 | { | 1331 | { |
| 1319 | PerformanceTimer perfTimer("makeCurrent"); | 1332 | PerformanceTimer perfTimer("makeCurrent"); |
| 1320 | _offscreenContext->makeCurrent(); | 1333 | _offscreenContext->makeCurrent(); |
| 1321 | _frameCount++; | ||
| 1322 | Stats::getInstance()->setRenderDetails(renderArgs._details); | 1334 | Stats::getInstance()->setRenderDetails(renderArgs._details); |
| 1323 | 1335 | ||
| 1324 | // Reset the gpu::Context Stages | 1336 | // Reset the gpu::Context Stages |
| @@ -2091,20 +2103,14 @@ bool Application::acceptSnapshot(const QString& urlString) { · 766 unmodified lines | |||
| 2091 | return true; | 2103 | return true; |
| 2092 | } | 2104 | } |
| 2093 | 2105 | ||
| 2094 | // Every second, check the frame rates and other stuff | 2106 | // Every second, send a ping, if menu item is checked. |
| 2095 | void Application::checkFPS() { | 2107 | void Application::ping() { |
| 2096 | if (Menu::getInstance()->isOptionChecked(MenuOption::TestPing)) { | 2108 | if (Menu::getInstance()->isOptionChecked(MenuOption::TestPing)) { |
| 2097 | DependencyManager::get<NodeList>()->sendPingPackets(); | 2109 | DependencyManager::get<NodeList>()->sendPingPackets(); |
| 2098 | } | 2110 | } |
| 2099 | |||
| 2100 | float diffTime = (float)_timerStart.nsecsElapsed() / 1000000000.0f; | ||
| 2101 | |||
| 2102 | _fps = (float)_frameCount / diffTime; | ||
| 2103 | _frameCount = 0; | ||
| 2104 | _timerStart.start(); | ||
| 2105 | } | 2111 | } |
| 2106 | 2112 | ||
| 2107 | void Application::idle() { | 2113 | void Application::idle(uint64_t now) { |
| 2108 | if (_aboutToQuit) { | 2114 | if (_aboutToQuit) { |
| 2109 | return; // bail early, nothing to do here. | 2115 | return; // bail early, nothing to do here. |
| 2110 | } | 2116 | } |
| @@ -2127,7 +2133,6 @@ void Application::idle() { · 16 unmodified lines | |||
| 2127 | 2133 | ||
| 2128 | { | 2134 | { |
| 2129 | PROFILE_RANGE(__FUNCTION__); | 2135 | PROFILE_RANGE(__FUNCTION__); |
| 2130 | uint64_t now = usecTimestampNow(); | ||
| 2131 | static uint64_t lastIdleStart{ now }; | 2136 | static uint64_t lastIdleStart{ now }; |
| 2132 | uint64_t idleStartToStartDuration = now - lastIdleStart; | 2137 | uint64_t idleStartToStartDuration = now - lastIdleStart; |
| 2133 | if (idleStartToStartDuration != 0) { | 2138 | if (idleStartToStartDuration != 0) { |