History

Merge branch 'master' of https://github.com/highfidelity/hifi into decouple-avatar-updates

Howard Stearns committed 11 years ago

Commit b3a919a2 parents 2429134 dd5d58a31 files · +627 −358Browse files

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

Unified · Split

interface/src/Application.cpp+71−163
@@ -104,6 +104,7 @@ · 103 unmodified lines
104104 #include <RenderableWebEntityItem.h>
105105
106106 #include "AudioClient.h"
107+#include "CrashHandler.h"
107108 #include "DiscoverabilityManager.h"
108109 #include "GLCanvas.h"
109110 #include "LODManager.h"
@@ -189,6 +190,11 @@ static QTimer* billboardPacketTimer = NULL; · 79 unmodified lines
189190 static QTimer* checkFPStimer = NULL;
190191 static QTimer* idleTimer = NULL;
191192
193+static const unsigned int TARGET_SIM_FRAMERATE = 60;
194+static const unsigned int THROTTLED_SIM_FRAMERATE = 15;
195+static const int TARGET_SIM_FRAME_PERIOD_MS = MSECS_PER_SECOND / TARGET_SIM_FRAMERATE;
196+static const int THROTTLED_SIM_FRAME_PERIOD_MS = MSECS_PER_SECOND / THROTTLED_SIM_FRAMERATE;
197+
192198 const QString CHECK_VERSION_URL = "https://highfidelity.com/latestVersion.xml";
193199 const QString SKIP_FILENAME = QStandardPaths::writableLocation(QStandardPaths::DataLocation) + "/hifi.skipversion";
194200
@@ -257,6 +263,12 @@ bool setupEssentials(int& argc, char** argv) { · 62 unmodified lines
257263 // Set build version
258264 QCoreApplication::setApplicationVersion(BUILD_VERSION);
259265
266+ Setting::preInit();
267+
268+ CrashHandler::checkForAndHandleCrash();
269+ CrashHandler::writeRunningMarkerFiler();
270+ qAddPostRoutine(CrashHandler::deleteRunningMarkerFile);
271+
260272 DependencyManager::registerInheritance<LimitedNodeList, NodeList>();
261273 DependencyManager::registerInheritance<AvatarHashMap, AvatarManager>();
262274 DependencyManager::registerInheritance<EntityActionFactoryInterface, InterfaceActionFactory>();
@@ -347,7 +359,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 84 unmodified lines
347359 _trayIcon(new QSystemTrayIcon(_window)),
348360 _lastNackTime(usecTimestampNow()),
349361 _lastSendDownstreamAudioStats(usecTimestampNow()),
350− _isVSyncOn(true),
351362 _isThrottleFPSEnabled(true),
352363 _aboutToQuit(false),
353364 _notifiedPacketVersionMismatchThisDomain(false),
@@ -745,8 +756,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 391 unmodified lines
745756 });
746757
747758 connect(this, &Application::applicationStateChanged, this, &Application::activeChanged);
748−
749− setVSyncEnabled(); // make sure VSync is set properly at startup
750759 }
751760
752761 void Application::aboutToQuit() {
@@ -921,7 +930,7 @@ void Application::initializeGL() { · 168 unmodified lines
921930 // call our idle function whenever we can
922931 idleTimer = new QTimer(this);
923932 connect(idleTimer, SIGNAL(timeout()), SLOT(idle()));
924− idleTimer->start(0);
933+ idleTimer->start(TARGET_SIM_FRAME_PERIOD_MS);
925934 _idleLoopStdev.reset();
926935
927936 if (_justStarted) {
@@ -2034,38 +2043,38 @@ void Application::checkFPS() { · 1106 unmodified lines
20342043 }
20352044
20362045 void Application::idle() {
2037− PROFILE_RANGE(__FUNCTION__);
2038− static SimpleAverage<float> interIdleDurations;
2046+ if (_aboutToQuit) {
2047+ return; // bail early, nothing to do here.
2048+ }
20392049
2040− static uint64_t lastIdleStart{ 0 };
2041− static uint64_t lastIdleEnd{ 0 };
2042− uint64_t now = usecTimestampNow();
2043− uint64_t idleStartToStartDuration = now - lastIdleStart;
2050+ // depending on whether we're throttling or not.
2051+ // Once rendering is off on another thread we should be able to have Application::idle run at start(0) in
2052+ // perpetuity and not expect events to get backed up.
2053+ bool isThrottled = getActiveDisplayPlugin()->isThrottled();
2054+ // Only run simulation code if more than the targetFramePeriod have passed since last time we ran
2055+ // This attempts to lock the simulation at 60 updates per second, regardless of framerate
2056+ float timeSinceLastUpdateUs = (float)_lastTimeUpdated.nsecsElapsed() / NSECS_PER_USEC;
2057+ float secondsSinceLastUpdate = timeSinceLastUpdateUs / USECS_PER_SECOND;
20442058
2045− if (lastIdleStart > 0 && idleStartToStartDuration > 0) {
2046− _simsPerSecond.updateAverage((float)USECS_PER_SECOND / (float)idleStartToStartDuration);
2059+ if (isThrottled && (timeSinceLastUpdateUs / USECS_PER_MSEC) < THROTTLED_SIM_FRAME_PERIOD_MS) {
2060+ return; // bail early, we're throttled and not enough time has elapsed
20472061 }
20482062
2049− lastIdleStart = now;
2063+ _lastTimeUpdated.start();
20502064
2051− if (lastIdleEnd != 0) {
2052− interIdleDurations.update(now - lastIdleEnd);
2053− static uint64_t lastReportTime = now;
2054− if ((now - lastReportTime) >= (USECS_PER_SECOND)) {
2055− static QString LOGLINE("Average inter-idle time: %1 us for %2 samples");
2056− if (Menu::getInstance()->isOptionChecked(MenuOption::LogExtraTimings)) {
2057− qCDebug(interfaceapp_timing) << LOGLINE.arg((int)interIdleDurations.getAverage()).arg(interIdleDurations.getCount());
2058− }
2059− interIdleDurations.reset();
2060− lastReportTime = now;
2065+
2066+ {
2067+ PROFILE_RANGE(__FUNCTION__);
2068+ uint64_t now = usecTimestampNow();
2069+ static uint64_t lastIdleStart{ now };
2070+ uint64_t idleStartToStartDuration = now - lastIdleStart;
2071+ if (idleStartToStartDuration != 0) {
2072+ _simsPerSecond.updateAverage((float)USECS_PER_SECOND / (float)idleStartToStartDuration);
20612073 }
2074+ lastIdleStart = now;
20622075 }
20632076
20642077 PerformanceTimer perfTimer("idle");
2065− if (_aboutToQuit) {
2066− return; // bail early, nothing to do here.
2067− }
2068−
20692078 // Drop focus from _keyboardFocusedItem if no keyboard messages for 30 seconds
20702079 if (!_keyboardFocusedItem.isInvalidID()) {
20712080 const quint64 LOSE_FOCUS_AFTER_ELAPSED_TIME = 30 * USECS_PER_SECOND; // if idle for 30 seconds, drop focus
@@ -2081,69 +2090,42 @@ void Application::idle() { · 9 unmodified lines
20812090 bool showWarnings = getLogger()->extraDebugging();
20822091 PerformanceWarning warn(showWarnings, "idle()");
20832092
2084− // Only run simulation code if more than the targetFramePeriod have passed since last time we ran
2085− double targetFramePeriod = 0.0;
2086− unsigned int targetFramerate = getRenderTargetFramerate();
2087− if (targetFramerate > 0) {
2088− targetFramePeriod = 1000.0 / targetFramerate;
2089− }
2090− double timeSinceLastUpdate = (double)_lastTimeUpdated.nsecsElapsed() / 1000000.0;
2091− if (timeSinceLastUpdate > targetFramePeriod) {
2092− _lastTimeUpdated.start();
2093− {
2094− PerformanceTimer perfTimer("update");
2095− PerformanceWarning warn(showWarnings, "Application::idle()... update()");
2096− const float BIGGEST_DELTA_TIME_SECS = 0.25f;
2097− PROFILE_RANGE(__FUNCTION__ "/idleUpdate");
2098− update(glm::clamp((float)timeSinceLastUpdate / 1000.0f, 0.0f, BIGGEST_DELTA_TIME_SECS));
2099− }
2100− {
2101− PerformanceTimer perfTimer("updateGL");
2102− PerformanceWarning warn(showWarnings, "Application::idle()... updateGL()");
2103− getActiveDisplayPlugin()->idle();
2104− auto inputPlugins = PluginManager::getInstance()->getInputPlugins();
2105− foreach(auto inputPlugin, inputPlugins) {
2106− QString name = inputPlugin->getName();
2107− QAction* action = Menu::getInstance()->getActionForOption(name);
2108− if (action && action->isChecked()) {
2109− inputPlugin->idle();
2110− }
2111− }
2112− }
2113− {
2114− PerformanceTimer perfTimer("rest");
2115− PerformanceWarning warn(showWarnings, "Application::idle()... rest of it");
2116− _idleLoopStdev.addValue(timeSinceLastUpdate);
2117−
2118− // Record standard deviation and reset counter if needed
2119− const int STDEV_SAMPLES = 500;
2120− if (_idleLoopStdev.getSamples() > STDEV_SAMPLES) {
2121− _idleLoopMeasuredJitter = _idleLoopStdev.getStDev();
2122− _idleLoopStdev.reset();
2093+ {
2094+ PerformanceTimer perfTimer("update");
2095+ PerformanceWarning warn(showWarnings, "Application::idle()... update()");
2096+ static const float BIGGEST_DELTA_TIME_SECS = 0.25f;
2097+ update(glm::clamp(secondsSinceLastUpdate, 0.0f, BIGGEST_DELTA_TIME_SECS));
2098+ }
2099+ {
2100+ PerformanceTimer perfTimer("pluginIdle");
2101+ PerformanceWarning warn(showWarnings, "Application::idle()... pluginIdle()");
2102+ getActiveDisplayPlugin()->idle();
2103+ auto inputPlugins = PluginManager::getInstance()->getInputPlugins();
2104+ foreach(auto inputPlugin, inputPlugins) {
2105+ QString name = inputPlugin->getName();
2106+ QAction* action = Menu::getInstance()->getActionForOption(name);
2107+ if (action && action->isChecked()) {
2108+ inputPlugin->idle();
21232109 }
21242110 }
2125−
2126− float secondsSinceLastUpdate = (float)timeSinceLastUpdate / 1000.0f;
2127− _overlayConductor.update(secondsSinceLastUpdate);
2128−
2129− // depending on whether we're throttling or not.
2130− // Once rendering is off on another thread we should be able to have Application::idle run at start(0) in
2131− // perpetuity and not expect events to get backed up.
2132−
2133− bool isThrottled = getActiveDisplayPlugin()->isThrottled();
2134− static const int THROTTLED_IDLE_TIMER_DELAY = MSECS_PER_SECOND / 15;
2135− static const int IDLE_TIMER_DELAY_MS = 2;
2136− int desiredInterval = isThrottled ? THROTTLED_IDLE_TIMER_DELAY : IDLE_TIMER_DELAY_MS;
2137− //qDebug() << "isThrottled:" << isThrottled << "desiredInterval:" << desiredInterval;
2138−
2139− if (idleTimer->interval() != desiredInterval) {
2140− idleTimer->start(desiredInterval);
2111+ }
2112+ {
2113+ PerformanceTimer perfTimer("rest");
2114+ PerformanceWarning warn(showWarnings, "Application::idle()... rest of it");
2115+ _idleLoopStdev.addValue(secondsSinceLastUpdate);
2116+
2117+ // Record standard deviation and reset counter if needed
2118+ const int STDEV_SAMPLES = 500;
2119+ if (_idleLoopStdev.getSamples() > STDEV_SAMPLES) {
2120+ _idleLoopMeasuredJitter = _idleLoopStdev.getStDev();
2121+ _idleLoopStdev.reset();
21412122 }
21422123 }
2124+
2125+ _overlayConductor.update(secondsSinceLastUpdate);
21432126
21442127 // check for any requested background downloads.
21452128 emit checkBackgroundDownloads();
2146− lastIdleEnd = usecTimestampNow();
21472129 }
21482130
21492131 float Application::getAverageSimsPerSecond() {
@@ -4485,90 +4467,10 @@ void Application::takeSnapshot() { · 2335 unmodified lines
44854467
44864468 }
44874469
4488−void Application::setVSyncEnabled() {
4489− _glWidget->makeCurrent();
4490−#if defined(Q_OS_WIN)
4491− bool vsyncOn = Menu::getInstance()->isOptionChecked(MenuOption::RenderTargetFramerateVSyncOn);
4492− if (wglewGetExtension("WGL_EXT_swap_control")) {
4493− wglSwapIntervalEXT(vsyncOn);
4494− int swapInterval = wglGetSwapIntervalEXT();
4495− qCDebug(interfaceapp, "V-Sync is %s\n", (swapInterval > 0 ? "ON" : "OFF"));
4496− } else {
4497− qCDebug(interfaceapp, "V-Sync is FORCED ON on this system\n");
4498− }
4499−#elif defined(Q_OS_LINUX)
4500− // TODO: write the poper code for linux
4501− /*
4502− if (glQueryExtension.... ("GLX_EXT_swap_control")) {
4503− glxSwapIntervalEXT(vsyncOn);
4504− int swapInterval = xglGetSwapIntervalEXT();
4505− _isVSyncOn = swapInterval;
4506− qCDebug(interfaceapp, "V-Sync is %s\n", (swapInterval > 0 ? "ON" : "OFF"));
4507− } else {
4508− qCDebug(interfaceapp, "V-Sync is FORCED ON on this system\n");
4509− }
4510− */
4511−#else
4512− qCDebug(interfaceapp, "V-Sync is FORCED ON on this system\n");
4513−#endif
4514− _offscreenContext->makeCurrent();
4515−}
4516−
45174470 void Application::setThrottleFPSEnabled() {
45184471 _isThrottleFPSEnabled = Menu::getInstance()->isOptionChecked(MenuOption::ThrottleFPSIfNotFocus);
45194472 }
45204473
4521−bool Application::isVSyncOn() const {
4522−#if defined(Q_OS_WIN)
4523− if (wglewGetExtension("WGL_EXT_swap_control")) {
4524− int swapInterval = wglGetSwapIntervalEXT();
4525− return (swapInterval > 0);
4526− }
4527−#elif defined(Q_OS_LINUX)
4528− // TODO: write the poper code for linux
4529− /*
4530− if (glQueryExtension.... ("GLX_EXT_swap_control")) {
4531− int swapInterval = xglGetSwapIntervalEXT();
4532− return (swapInterval > 0);
4533− } else {
4534− return true;
4535− }
4536− */
4537−#endif
4538− return true;
4539−}
4540−
4541−bool Application::isVSyncEditable() const {
4542−#if defined(Q_OS_WIN)
4543− if (wglewGetExtension("WGL_EXT_swap_control")) {
4544− return true;
4545− }
4546−#elif defined(Q_OS_LINUX)
4547− // TODO: write the poper code for linux
4548− /*
4549− if (glQueryExtension.... ("GLX_EXT_swap_control")) {
4550− return true;
4551− }
4552− */
4553−#endif
4554− return false;
4555−}
4556−
4557−unsigned int Application::getRenderTargetFramerate() const {
4558− if (Menu::getInstance()->isOptionChecked(MenuOption::RenderTargetFramerateUnlimited)) {
4559− return 0;
4560− } else if (Menu::getInstance()->isOptionChecked(MenuOption::RenderTargetFramerate60)) {
4561− return 60;
4562− } else if (Menu::getInstance()->isOptionChecked(MenuOption::RenderTargetFramerate50)) {
4563− return 50;
4564− } else if (Menu::getInstance()->isOptionChecked(MenuOption::RenderTargetFramerate40)) {
4565− return 40;
4566− } else if (Menu::getInstance()->isOptionChecked(MenuOption::RenderTargetFramerate30)) {
4567− return 30;
4568− }
4569− return 0;
4570−}
4571−
45724474 float Application::getRenderResolutionScale() const {
45734475 if (Menu::getInstance()->isOptionChecked(MenuOption::RenderResolutionOne)) {
45744476 return 1.0f;
@@ -5150,3 +5052,9 @@ void Application::emulateMouse(Hand* hand, float click, float shift, int index) · 575 unmodified lines
51505052 _oldHandLeftClick[index] = false;
51515053 }
51525054 }
5055+
5056+void Application::crashApplication() {
5057+ QObject* object = nullptr;
5058+ bool value = object->isWindowType();
5059+ qCDebug(interfaceapp) << "Intentionally crashed Interface";
5060+}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t