History

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

Brad Hefta-Gaub committed 10 years ago

Commit b0c286b2 parents 519a90f 202a45678 files · +2143 −1227Browse files

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

Unified · Split

interface/src/Application.cpp+22−81
@@ -425,11 +425,11 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) : · 424 unmodified lines
425 _maxOctreePPS(maxOctreePacketsPerSecond.get()),425 _maxOctreePPS(maxOctreePacketsPerSecond.get()),
426 _lastFaceTrackerUpdate(0)426 _lastFaceTrackerUpdate(0)
427{427{
428 // FIXME this may be excessivly conservative. On the other hand 428 // FIXME this may be excessivly conservative. On the other hand
429 // maybe I'm used to having an 8-core machine429 // maybe I'm used to having an 8-core machine
430 // Perhaps find the ideal thread count and subtract 2 or 3 430 // Perhaps find the ideal thread count and subtract 2 or 3
431 // (main thread, present thread, random OS load)431 // (main thread, present thread, random OS load)
432 // More threads == faster concurrent loads, but also more concurrent 432 // More threads == faster concurrent loads, but also more concurrent
433 // load on the GPU until we can serialize GPU transfers (off the main thread)433 // load on the GPU until we can serialize GPU transfers (off the main thread)
434 QThreadPool::globalInstance()->setMaxThreadCount(2);434 QThreadPool::globalInstance()->setMaxThreadCount(2);
435 thread()->setPriority(QThread::HighPriority);435 thread()->setPriority(QThread::HighPriority);
@@ -553,14 +553,13 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) : · 117 unmodified lines
553 connect(&domainHandler, SIGNAL(connectedToDomain(const QString&)), SLOT(updateWindowTitle()));553 connect(&domainHandler, SIGNAL(connectedToDomain(const QString&)), SLOT(updateWindowTitle()));
554 connect(&domainHandler, SIGNAL(disconnectedFromDomain()), SLOT(updateWindowTitle()));554 connect(&domainHandler, SIGNAL(disconnectedFromDomain()), SLOT(updateWindowTitle()));
555 connect(&domainHandler, SIGNAL(disconnectedFromDomain()), SLOT(clearDomainOctreeDetails()));555 connect(&domainHandler, SIGNAL(disconnectedFromDomain()), SLOT(clearDomainOctreeDetails()));
556 connect(&domainHandler, &DomainHandler::settingsReceived, this, &Application::domainSettingsReceived);
557 556
558 // update our location every 5 seconds in the metaverse server, assuming that we are authenticated with one557 // update our location every 5 seconds in the metaverse server, assuming that we are authenticated with one
559 const qint64 DATA_SERVER_LOCATION_CHANGE_UPDATE_MSECS = 5 * 1000;558 const qint64 DATA_SERVER_LOCATION_CHANGE_UPDATE_MSECS = 5 * 1000;
560 559
561 auto discoverabilityManager = DependencyManager::get<DiscoverabilityManager>();560 auto discoverabilityManager = DependencyManager::get<DiscoverabilityManager>();
562 connect(&locationUpdateTimer, &QTimer::timeout, discoverabilityManager.data(), &DiscoverabilityManager::updateLocation);561 connect(&locationUpdateTimer, &QTimer::timeout, discoverabilityManager.data(), &DiscoverabilityManager::updateLocation);
563 connect(&locationUpdateTimer, &QTimer::timeout, 562 connect(&locationUpdateTimer, &QTimer::timeout,
564 DependencyManager::get<AddressManager>().data(), &AddressManager::storeCurrentAddress);563 DependencyManager::get<AddressManager>().data(), &AddressManager::storeCurrentAddress);
565 locationUpdateTimer.start(DATA_SERVER_LOCATION_CHANGE_UPDATE_MSECS);564 locationUpdateTimer.start(DATA_SERVER_LOCATION_CHANGE_UPDATE_MSECS);
566 565
@@ -590,6 +589,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) : · 23 unmodified lines
590 connect(&accountManager, &AccountManager::usernameChanged, this, &Application::updateWindowTitle);589 connect(&accountManager, &AccountManager::usernameChanged, this, &Application::updateWindowTitle);
591 590
592 // set the account manager's root URL and trigger a login request if we don't have the access token591 // set the account manager's root URL and trigger a login request if we don't have the access token
592 accountManager.setIsAgent(true);
593 accountManager.setAuthURL(NetworkingConstants::METAVERSE_SERVER_URL);593 accountManager.setAuthURL(NetworkingConstants::METAVERSE_SERVER_URL);
594 UserActivityLogger::getInstance().launch(applicationVersion());594 UserActivityLogger::getInstance().launch(applicationVersion());
595 595
@@ -604,7 +604,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) : · 8 unmodified lines
604 604
605 connect(addressManager.data(), &AddressManager::hostChanged, this, &Application::updateWindowTitle);605 connect(addressManager.data(), &AddressManager::hostChanged, this, &Application::updateWindowTitle);
606 connect(this, &QCoreApplication::aboutToQuit, addressManager.data(), &AddressManager::storeCurrentAddress);606 connect(this, &QCoreApplication::aboutToQuit, addressManager.data(), &AddressManager::storeCurrentAddress);
607 607
608 // Save avatar location immediately after a teleport.608 // Save avatar location immediately after a teleport.
609 connect(getMyAvatar(), &MyAvatar::positionGoneTo,609 connect(getMyAvatar(), &MyAvatar::positionGoneTo,
610 DependencyManager::get<AddressManager>().data(), &AddressManager::storeCurrentAddress);610 DependencyManager::get<AddressManager>().data(), &AddressManager::storeCurrentAddress);
@@ -625,7 +625,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) : · 14 unmodified lines
625 getEntities()->reloadEntityScripts();625 getEntities()->reloadEntityScripts();
626 }, Qt::QueuedConnection);626 }, Qt::QueuedConnection);
627 627
628 connect(scriptEngines, &ScriptEngines::scriptLoadError, 628 connect(scriptEngines, &ScriptEngines::scriptLoadError,
629 scriptEngines, [](const QString& filename, const QString& error){629 scriptEngines, [](const QString& filename, const QString& error){
630 OffscreenUi::warning(nullptr, "Error Loading Script", filename + " failed to load.");630 OffscreenUi::warning(nullptr, "Error Loading Script", filename + " failed to load.");
631 }, Qt::QueuedConnection);631 }, Qt::QueuedConnection);
@@ -905,9 +905,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) : · 273 unmodified lines
905 SpacemouseManager::getInstance().init();905 SpacemouseManager::getInstance().init();
906#endif906#endif
907 907
908 auto& packetReceiver = nodeList->getPacketReceiver();
909 packetReceiver.registerListener(PacketType::DomainConnectionDenied, this, "handleDomainConnectionDeniedPacket");
910
911 // If the user clicks an an entity, we will check that it's an unlocked web entity, and if so, set the focus to it908 // If the user clicks an an entity, we will check that it's an unlocked web entity, and if so, set the focus to it
912 auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>();909 auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>();
913 connect(entityScriptingInterface.data(), &EntityScriptingInterface::clickDownOnEntity,910 connect(entityScriptingInterface.data(), &EntityScriptingInterface::clickDownOnEntity,
@@ -977,7 +974,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) : · 63 unmodified lines
977 disconnect(_idleTimer);974 disconnect(_idleTimer);
978 });975 });
979 // Setting the interval to zero forces this to get called whenever there are no messages976 // Setting the interval to zero forces this to get called whenever there are no messages
980 // in the queue, which can be pretty damn frequent. Hence the idle function has a bunch 977 // in the queue, which can be pretty damn frequent. Hence the idle function has a bunch
981 // of logic to abort early if it's being called too often.978 // of logic to abort early if it's being called too often.
982 _idleTimer->start(0);979 _idleTimer->start(0);
983}980}
@@ -1025,7 +1022,7 @@ void Application::cleanupBeforeQuit() { · 41 unmodified lines
1025 getEntities()->shutdown(); // tell the entities system we're shutting down, so it will stop running scripts1022 getEntities()->shutdown(); // tell the entities system we're shutting down, so it will stop running scripts
1026 DependencyManager::get<ScriptEngines>()->saveScripts();1023 DependencyManager::get<ScriptEngines>()->saveScripts();
1027 DependencyManager::get<ScriptEngines>()->shutdownScripting(); // stop all currently running global scripts1024 DependencyManager::get<ScriptEngines>()->shutdownScripting(); // stop all currently running global scripts
1028 DependencyManager::destroy<ScriptEngines>(); 1025 DependencyManager::destroy<ScriptEngines>();
1029 1026
1030 // first stop all timers directly or by invokeMethod1027 // first stop all timers directly or by invokeMethod
1031 // depending on what thread they run in1028 // depending on what thread they run in
@@ -1213,10 +1210,10 @@ void Application::initializeUi() { · 181 unmodified lines
1213 1210
1214 setupPreferences();1211 setupPreferences();
1215 1212
1216 // For some reason there is already an "Application" object in the QML context, 1213 // For some reason there is already an "Application" object in the QML context,
1217 // though I can't find it. Hence, "ApplicationInterface"1214 // though I can't find it. Hence, "ApplicationInterface"
1218 rootContext->setContextProperty("SnapshotUploader", new SnapshotUploader());1215 rootContext->setContextProperty("SnapshotUploader", new SnapshotUploader());
1219 rootContext->setContextProperty("ApplicationInterface", this); 1216 rootContext->setContextProperty("ApplicationInterface", this);
1220 rootContext->setContextProperty("AnimationCache", DependencyManager::get<AnimationCache>().data());1217 rootContext->setContextProperty("AnimationCache", DependencyManager::get<AnimationCache>().data());
1221 rootContext->setContextProperty("Audio", &AudioScriptingInterface::getInstance());1218 rootContext->setContextProperty("Audio", &AudioScriptingInterface::getInstance());
1222 rootContext->setContextProperty("Controller", DependencyManager::get<controller::ScriptingInterface>().data());1219 rootContext->setContextProperty("Controller", DependencyManager::get<controller::ScriptingInterface>().data());
@@ -2448,7 +2445,6 @@ void Application::idle(uint64_t now) { · 1225 unmodified lines
2448 _overlayConductor.setEnabled(Menu::getInstance()->isOptionChecked(MenuOption::Overlays));2445 _overlayConductor.setEnabled(Menu::getInstance()->isOptionChecked(MenuOption::Overlays));
2449 }2446 }
2450 2447
2451
2452 auto displayPlugin = getActiveDisplayPlugin();2448 auto displayPlugin = getActiveDisplayPlugin();
2453 // depending on whether we're throttling or not.2449 // depending on whether we're throttling or not.
2454 // Once rendering is off on another thread we should be able to have Application::idle run at start(0) in2450 // Once rendering is off on another thread we should be able to have Application::idle run at start(0) in
@@ -2472,7 +2468,7 @@ void Application::idle(uint64_t now) { · 17 unmodified lines
2472 // Nested ifs are for clarity in the logic. Don't collapse them into a giant single if.2468 // Nested ifs are for clarity in the logic. Don't collapse them into a giant single if.
2473 // Don't saturate the main thread with rendering, no paint calls until the last one is complete2469 // Don't saturate the main thread with rendering, no paint calls until the last one is complete
2474 if (!_pendingPaint) {2470 if (!_pendingPaint) {
2475 // Also no paint calls until the display plugin has increased by at least one frame 2471 // Also no paint calls until the display plugin has increased by at least one frame
2476 // (don't render at 90fps if the display plugin only goes at 60)2472 // (don't render at 90fps if the display plugin only goes at 60)
2477 if (_renderedFrameIndex == INVALID_FRAME || presentCount > _renderedFrameIndex) {2473 if (_renderedFrameIndex == INVALID_FRAME || presentCount > _renderedFrameIndex) {
2478 // Record what present frame we're on2474 // Record what present frame we're on
@@ -2482,14 +2478,14 @@ void Application::idle(uint64_t now) { · 3 unmodified lines
2482 // But when we DO request a paint, get to it as soon as possible: high priority2478 // But when we DO request a paint, get to it as soon as possible: high priority
2483 postEvent(this, new QEvent(static_cast<QEvent::Type>(Paint)), Qt::HighEventPriority);2479 postEvent(this, new QEvent(static_cast<QEvent::Type>(Paint)), Qt::HighEventPriority);
2484 }2480 }
2485 } 2481 }
2486 2482
2487 // For the rest of idle, we want to cap at the max sim rate, so we might not call 2483 // For the rest of idle, we want to cap at the max sim rate, so we might not call
2488 // the remaining idle work every paint frame, or vice versa2484 // the remaining idle work every paint frame, or vice versa
2489 // In theory this means we could call idle processing more often than painting,2485 // In theory this means we could call idle processing more often than painting,
2490 // but in practice, when the paintGL calls aren't keeping up, there's no room left2486 // but in practice, when the paintGL calls aren't keeping up, there's no room left
2491 // in the main thread to call idle more often than paint.2487 // in the main thread to call idle more often than paint.
2492 // This check is mostly to keep idle from burning up CPU cycles by running at 2488 // This check is mostly to keep idle from burning up CPU cycles by running at
2493 // hundreds of idles per second when the rendering is that fast2489 // hundreds of idles per second when the rendering is that fast
2494 if ((timeSinceLastUpdateUs / USECS_PER_MSEC) < CAPPED_SIM_FRAME_PERIOD_MS) {2490 if ((timeSinceLastUpdateUs / USECS_PER_MSEC) < CAPPED_SIM_FRAME_PERIOD_MS) {
2495 // No paint this round, but might be time for a new idle, otherwise return2491 // No paint this round, but might be time for a new idle, otherwise return
@@ -3445,7 +3441,7 @@ void Application::queryOctree(NodeType_t serverType, PacketType packetType, Node · 949 unmodified lines
3445 rootDetails.y * TREE_SCALE,3441 rootDetails.y * TREE_SCALE,
3446 rootDetails.z * TREE_SCALE) - glm::vec3(HALF_TREE_SCALE),3442 rootDetails.z * TREE_SCALE) - glm::vec3(HALF_TREE_SCALE),
3447 rootDetails.s * TREE_SCALE);3443 rootDetails.s * TREE_SCALE);
3448 ViewFrustum::location serverFrustumLocation = _viewFrustum.cubeInFrustum(serverBounds);3444 ViewFrustum::location serverFrustumLocation = _viewFrustum.computeCubeViewLocation(serverBounds);
3449 3445
3450 if (serverFrustumLocation != ViewFrustum::OUTSIDE) {3446 if (serverFrustumLocation != ViewFrustum::OUTSIDE) {
3451 inViewServers++;3447 inViewServers++;
@@ -3513,7 +3509,7 @@ void Application::queryOctree(NodeType_t serverType, PacketType packetType, Node · 61 unmodified lines
3513 rootDetails.s * TREE_SCALE);3509 rootDetails.s * TREE_SCALE);
3514 3510
3515 3511
3516 ViewFrustum::location serverFrustumLocation = _viewFrustum.cubeInFrustum(serverBounds);3512 ViewFrustum::location serverFrustumLocation = _viewFrustum.computeCubeViewLocation(serverBounds);
3517 if (serverFrustumLocation != ViewFrustum::OUTSIDE) {3513 if (serverFrustumLocation != ViewFrustum::OUTSIDE) {
3518 inView = true;3514 inView = true;
3519 } else {3515 } else {
@@ -3840,18 +3836,10 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se · 320 unmodified lines
3840 });3836 });
3841 }3837 }
3842 3838
3843 // Setup the current Zone Entity lighting and skybox3839 // Setup the current Zone Entity lighting
3844 {3840 {
3845 // FIXME: Use a zone setting to determine the ambient light mode3841 auto stage = DependencyManager::get<SceneScriptingInterface>()->getSkyStage();
3846 DependencyManager::get<DeferredLightingEffect>()->setAmbientLightMode(-1);3842 DependencyManager::get<DeferredLightingEffect>()->setGlobalLight(stage->getSunLight(), stage->getSkybox()->getCubemap());
3847 auto skyStage = DependencyManager::get<SceneScriptingInterface>()->getSkyStage();
3848 DependencyManager::get<DeferredLightingEffect>()->setGlobalLight(skyStage->getSunLight()->getDirection(), skyStage->getSunLight()->getColor(), skyStage->getSunLight()->getIntensity(), skyStage->getSunLight()->getAmbientIntensity());
3849
3850 auto skybox = model::SkyboxPointer();
3851 if (skyStage->getBackgroundMode() == model::SunSkyStage::SKY_BOX) {
3852 skybox = skyStage->getSkybox();
3853 }
3854 DependencyManager::get<DeferredLightingEffect>()->setGlobalSkybox(skybox);
3855 }3843 }
3856 3844
3857 {3845 {
@@ -3987,30 +3975,10 @@ void Application::clearDomainOctreeDetails() { · 129 unmodified lines
3987void Application::domainChanged(const QString& domainHostname) {3975void Application::domainChanged(const QString& domainHostname) {
3988 updateWindowTitle();3976 updateWindowTitle();
3989 clearDomainOctreeDetails();3977 clearDomainOctreeDetails();
3990 _domainConnectionRefusals.clear();
3991 // disable physics until we have enough information about our new location to not cause craziness.3978 // disable physics until we have enough information about our new location to not cause craziness.
3992 _physicsEnabled = false;3979 _physicsEnabled = false;
3993}3980}
3994 3981
3995void Application::handleDomainConnectionDeniedPacket(QSharedPointer<ReceivedMessage> message) {
3996 // Read deny reason from packet
3997 quint16 reasonSize;
3998 message->readPrimitive(&reasonSize);
3999 QString reason = QString::fromUtf8(message->readWithoutCopy(reasonSize));
4000
4001 // output to the log so the user knows they got a denied connection request
4002 // and check and signal for an access token so that we can make sure they are logged in
4003 qCDebug(interfaceapp) << "The domain-server denied a connection request: " << reason;
4004 qCDebug(interfaceapp) << "You may need to re-log to generate a keypair so you can provide a username signature.";
4005
4006 if (!_domainConnectionRefusals.contains(reason)) {
4007 _domainConnectionRefusals.append(reason);
4008 emit domainConnectionRefused(reason);
4009 }
4010
4011 AccountManager::getInstance().checkAndSignalForAccessToken();
4012}
4013
4014void Application::connectedToDomain(const QString& hostname) {3982void Application::connectedToDomain(const QString& hostname) {
4015 AccountManager& accountManager = AccountManager::getInstance();3983 AccountManager& accountManager = AccountManager::getInstance();
4016 const QUuid& domainID = DependencyManager::get<NodeList>()->getDomainHandler().getUUID();3984 const QUuid& domainID = DependencyManager::get<NodeList>()->getDomainHandler().getUUID();
@@ -4554,33 +4522,6 @@ void Application::openUrl(const QUrl& url) { · 537 unmodified lines
4554 }4522 }
4555}4523}
4556 4524
4557void Application::domainSettingsReceived(const QJsonObject& domainSettingsObject) {
4558 // from the domain-handler, figure out the satoshi cost per voxel and per meter cubed
4559 const QString VOXEL_SETTINGS_KEY = "voxels";
4560 const QString PER_VOXEL_COST_KEY = "per-voxel-credits";
4561 const QString PER_METER_CUBED_COST_KEY = "per-meter-cubed-credits";
4562 const QString VOXEL_WALLET_UUID = "voxel-wallet";
4563
4564 const QJsonObject& voxelObject = domainSettingsObject[VOXEL_SETTINGS_KEY].toObject();
4565
4566 qint64 satoshisPerVoxel = 0;
4567 qint64 satoshisPerMeterCubed = 0;
4568 QUuid voxelWalletUUID;
4569
4570 if (!domainSettingsObject.isEmpty()) {
4571 float perVoxelCredits = (float) voxelObject[PER_VOXEL_COST_KEY].toDouble();
4572 float perMeterCubedCredits = (float) voxelObject[PER_METER_CUBED_COST_KEY].toDouble();
4573
4574 satoshisPerVoxel = (qint64) floorf(perVoxelCredits * SATOSHIS_PER_CREDIT);
4575 satoshisPerMeterCubed = (qint64) floorf(perMeterCubedCredits * SATOSHIS_PER_CREDIT);
4576
4577 voxelWalletUUID = QUuid(voxelObject[VOXEL_WALLET_UUID].toString());
4578 }
4579
4580 qCDebug(interfaceapp) << "Octree edits costs are" << satoshisPerVoxel << "per octree cell and" << satoshisPerMeterCubed << "per meter cubed";
4581 qCDebug(interfaceapp) << "Destination wallet UUID for edit payments is" << voxelWalletUUID;
4582}
4583
4584void Application::loadDialog() {4525void Application::loadDialog() {
4585 auto scriptEngines = DependencyManager::get<ScriptEngines>();4526 auto scriptEngines = DependencyManager::get<ScriptEngines>();
4586 QString fileNameString = OffscreenUi::getOpenFileName(4527 QString fileNameString = OffscreenUi::getOpenFileName(
@@ -4782,7 +4723,7 @@ static void addDisplayPluginToMenu(DisplayPluginPointer displayPlugin, bool acti · 195 unmodified lines
4782 groupingMenu = "Developer";4723 groupingMenu = "Developer";
4783 break;4724 break;
4784 default:4725 default:
4785 groupingMenu = "Standard"; 4726 groupingMenu = "Standard";
4786 break;4727 break;
4787 }4728 }
4788 4729