History

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

samcake committed 9 years ago

Commit ebc47452 parents df340a5 7b23699116 files · +1400 −4569Browse files

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

Unified · Split

interface/src/Application.cpp+51−76
@@ -150,11 +150,11 @@ · 149 unmodified lines
150150 #include "InterfaceLogging.h"
151151 #include "LODManager.h"
152152 #include "ModelPackager.h"
153+#include "scripting/Audio.h"
153154 #include "networking/CloseEventSender.h"
154155 #include "scripting/TestScriptingInterface.h"
155156 #include "scripting/AccountScriptingInterface.h"
156157 #include "scripting/AssetMappingsScriptingInterface.h"
157−#include "scripting/AudioDeviceScriptingInterface.h"
158158 #include "scripting/ClipboardScriptingInterface.h"
159159 #include "scripting/DesktopScriptingInterface.h"
160160 #include "scripting/GlobalServicesScriptingInterface.h"
@@ -251,6 +251,8 @@ static const QString MARKETPLACE_CDN_HOSTNAME = "mpassets.highfidelity.com"; · 90 unmodified lines
251251 static const int INTERVAL_TO_CHECK_HMD_WORN_STATUS = 500; // milliseconds
252252 static const QString DESKTOP_DISPLAY_PLUGIN_NAME = "Desktop";
253253
254+static const QString SYSTEM_TABLET = "com.highfidelity.interface.tablet.system";
255+
254256 const QHash<QString, Application::AcceptURLMethod> Application::_acceptedExtensions {
255257 { SVO_EXTENSION, &Application::importSVOFromURL },
256258 { SVO_JSON_EXTENSION, &Application::importSVOFromURL },
@@ -711,9 +713,9 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo · 454 unmodified lines
711713 recorder->recordFrame(AUDIO_FRAME_TYPE, audio);
712714 }
713715 });
716+ audioIO->startThread();
714717
715− auto audioScriptingInterface = DependencyManager::set<AudioScriptingInterface>();
716− connect(audioIO.data(), &AudioClient::muteToggled, this, &Application::audioMuteToggled);
718+ auto audioScriptingInterface = DependencyManager::set<AudioScriptingInterface, scripting::Audio>();
717719 connect(audioIO.data(), &AudioClient::mutedByMixer, audioScriptingInterface.data(), &AudioScriptingInterface::mutedByMixer);
718720 connect(audioIO.data(), &AudioClient::receivedFirstPacket, audioScriptingInterface.data(), &AudioScriptingInterface::receivedFirstPacket);
719721 connect(audioIO.data(), &AudioClient::disconnected, audioScriptingInterface.data(), &AudioScriptingInterface::disconnected);
@@ -729,8 +731,8 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo · 9 unmodified lines
729731 audioScriptingInterface->environmentMuted();
730732 }
731733 });
732−
733− audioIO->startThread();
734+ connect(this, &Application::activeDisplayPluginChanged,
735+ reinterpret_cast<scripting::Audio*>(audioScriptingInterface.data()), &scripting::Audio::onContextChanged);
734736
735737 ResourceManager::init();
736738 // Make sure we don't time out during slow operations at startup
@@ -953,7 +955,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo · 216 unmodified lines
953955 // Make sure we don't time out during slow operations at startup
954956 updateHeartbeat();
955957
956− connect(this, SIGNAL(aboutToQuit()), this, SLOT(aboutToQuit()));
958+ connect(this, SIGNAL(aboutToQuit()), this, SLOT(onAboutToQuit()));
957959
958960 // hook up bandwidth estimator
959961 QSharedPointer<BandwidthRecorder> bandwidthRecorder = DependencyManager::get<BandwidthRecorder>();
@@ -1447,7 +1449,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo · 487 unmodified lines
14471449 });
14481450 sendStatsTimer->start();
14491451
1450−
14511452 // Periodically check for count of nearby avatars
14521453 static int lastCountOfNearbyAvatars = -1;
14531454 QTimer* checkNearbyAvatarsTimer = new QTimer(this);
@@ -1605,12 +1606,12 @@ QString Application::getUserAgent() { · 151 unmodified lines
16051606 return userAgent;
16061607 }
16071608
1608−void Application::toggleTabletUI() const {
1609+void Application::toggleTabletUI(bool shouldOpen) const {
16091610 auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>();
16101611 auto hmd = DependencyManager::get<HMDScriptingInterface>();
1611− TabletProxy* tablet = dynamic_cast<TabletProxy*>(tabletScriptingInterface->getTablet("com.highfidelity.interface.tablet.system"));
1612+ TabletProxy* tablet = dynamic_cast<TabletProxy*>(tabletScriptingInterface->getTablet(SYSTEM_TABLET));
16121613 bool messageOpen = tablet->isMessageDialogOpen();
1613− if (!messageOpen || (messageOpen && !hmd->getShouldShowTablet())) {
1614+ if ((!messageOpen || (messageOpen && !hmd->getShouldShowTablet())) && !(shouldOpen && hmd->getShouldShowTablet())) {
16141615 auto HMD = DependencyManager::get<HMDScriptingInterface>();
16151616 HMD->toggleShouldShowTablet();
16161617 }
@@ -1642,7 +1643,7 @@ void Application::updateHeartbeat() const { · 25 unmodified lines
16421643 static_cast<DeadlockWatchdogThread*>(_deadlockWatchdogThread)->updateHeartbeat();
16431644 }
16441645
1645−void Application::aboutToQuit() {
1646+void Application::onAboutToQuit() {
16461647 emit beforeAboutToQuit();
16471648
16481649 foreach(auto inputPlugin, PluginManager::getInstance()->getInputPlugins()) {
@@ -1721,6 +1722,10 @@ void Application::cleanupBeforeQuit() { · 72 unmodified lines
17211722
17221723 // Cleanup all overlays after the scripts, as scripts might add more
17231724 _overlays.cleanupAllOverlays();
1725+ // The cleanup process enqueues the transactions but does not process them. Calling this here will force the actual
1726+ // removal of the items.
1727+ // See https://highfidelity.fogbugz.com/f/cases/5328
1728+ _main3DScene->processTransactionQueue();
17241729
17251730 // first stop all timers directly or by invokeMethod
17261731 // depending on what thread they run in
@@ -1983,7 +1988,6 @@ void Application::initializeUi() { · 256 unmodified lines
19831988 surfaceContext->setContextProperty("Stats", Stats::getInstance());
19841989 surfaceContext->setContextProperty("Settings", SettingsScriptingInterface::getInstance());
19851990 surfaceContext->setContextProperty("ScriptDiscoveryService", DependencyManager::get<ScriptEngines>().data());
1986− surfaceContext->setContextProperty("AudioDevice", AudioDeviceScriptingInterface::getInstance());
19871991 surfaceContext->setContextProperty("AvatarBookmarks", DependencyManager::get<AvatarBookmarks>().data());
19881992 surfaceContext->setContextProperty("LocationBookmarks", DependencyManager::get<LocationBookmarks>().data());
19891993
@@ -2312,12 +2316,6 @@ void Application::runTests() { · 322 unmodified lines
23122316 runUnitTests();
23132317 }
23142318
2315−void Application::audioMuteToggled() const {
2316− QAction* muteAction = Menu::getInstance()->getActionForOption(MenuOption::MuteAudio);
2317− Q_CHECK_PTR(muteAction);
2318− muteAction->setChecked(DependencyManager::get<AudioClient>()->isMuted());
2319−}
2320−
23212319 void Application::faceTrackerMuteToggled() {
23222320
23232321 QAction* muteAction = Menu::getInstance()->getActionForOption(MenuOption::MuteFaceTracking);
@@ -2387,7 +2385,7 @@ void Application::showHelp() { · 63 unmodified lines
23872385 queryString.addQueryItem("handControllerName", handControllerName);
23882386 queryString.addQueryItem("defaultTab", defaultTab);
23892387 auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>();
2390− TabletProxy* tablet = dynamic_cast<TabletProxy*>(tabletScriptingInterface->getTablet("com.highfidelity.interface.tablet.system"));
2388+ TabletProxy* tablet = dynamic_cast<TabletProxy*>(tabletScriptingInterface->getTablet(SYSTEM_TABLET));
23912389 tablet->gotoWebScreen(INFO_HELP_PATH + "?" + queryString.toString());
23922390 //InfoView::show(INFO_HELP_PATH, false, queryString.toString());
23932391 }
@@ -2843,7 +2841,7 @@ void Application::keyPressEvent(QKeyEvent* event) { · 449 unmodified lines
28432841 if (isShifted && isMeta) {
28442842 auto offscreenUi = DependencyManager::get<OffscreenUi>();
28452843 offscreenUi->togglePinned();
2846− //offscreenUi->getRootContext()->engine()->clearComponentCache();
2844+ //offscreenUi->getSurfaceContext()->engine()->clearComponentCache();
28472845 //OffscreenUi::information("Debugging", "Component cache cleared");
28482846 // placeholder for dialogs being converted to QML.
28492847 }
@@ -2884,6 +2882,12 @@ void Application::keyPressEvent(QKeyEvent* event) { · 34 unmodified lines
28842882 Menu::getInstance()->triggerOption(MenuOption::DefaultSkybox);
28852883 break;
28862884
2885+ case Qt::Key_M:
2886+ if (isMeta) {
2887+ DependencyManager::get<AudioClient>()->toggleMute();
2888+ }
2889+ break;
2890+
28872891 case Qt::Key_N:
28882892 if (!isOption && !isShifted && isMeta) {
28892893 DependencyManager::get<NodeList>()->toggleIgnoreRadius();
@@ -4468,10 +4472,11 @@ void Application::update(float deltaTime) { · 1578 unmodified lines
44684472 } else {
44694473 const quint64 MUTE_MICROPHONE_AFTER_USECS = 5000000; //5 secs
44704474 Menu* menu = Menu::getInstance();
4471− if (menu->isOptionChecked(MenuOption::AutoMuteAudio) && !menu->isOptionChecked(MenuOption::MuteAudio)) {
4475+ auto audioClient = DependencyManager::get<AudioClient>();
4476+ if (menu->isOptionChecked(MenuOption::AutoMuteAudio) && !audioClient->isMuted()) {
44724477 if (_lastFaceTrackerUpdate > 0
44734478 && ((usecTimestampNow() - _lastFaceTrackerUpdate) > MUTE_MICROPHONE_AFTER_USECS)) {
4474− menu->triggerOption(MenuOption::MuteAudio);
4479+ audioClient->toggleMute();
44754480 _lastFaceTrackerUpdate = 0;
44764481 }
44774482 } else {
@@ -5289,6 +5294,11 @@ void Application::nodeActivated(SharedNodePointer node) { · 811 unmodified lines
52895294
52905295 if (node->getType() == NodeType::AvatarMixer) {
52915296 // new avatar mixer, send off our identity packet on next update loop
5297+ // Reset skeletonModelUrl if the last server modified our choice.
5298+ static const QUrl empty{};
5299+ if (getMyAvatar()->getFullAvatarURLFromPreferences() != getMyAvatar()->cannonicalSkeletonModelURL(empty)) {
5300+ getMyAvatar()->resetFullAvatarURL();
5301+ }
52925302 getMyAvatar()->markIdentityDataChanged();
52935303 getMyAvatar()->resetLastSent();
52945304 }
@@ -5509,7 +5519,6 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri · 214 unmodified lines
55095519 scriptEngine->registerGlobalObject("Stats", Stats::getInstance());
55105520 scriptEngine->registerGlobalObject("Settings", SettingsScriptingInterface::getInstance());
55115521 scriptEngine->registerGlobalObject("Snapshot", DependencyManager::get<Snapshot>().data());
5512− scriptEngine->registerGlobalObject("AudioDevice", AudioDeviceScriptingInterface::getInstance());
55135522 scriptEngine->registerGlobalObject("AudioStats", DependencyManager::get<AudioClient>()->getStats().data());
55145523 scriptEngine->registerGlobalObject("AudioScope", DependencyManager::get<AudioScope>().data());
55155524 scriptEngine->registerGlobalObject("AvatarBookmarks", DependencyManager::get<AvatarBookmarks>().data());
@@ -5788,38 +5797,24 @@ bool Application::displayAvatarAttachmentConfirmationDialog(const QString& name) · 272 unmodified lines
57885797 }
57895798 }
57905799
5791−void Application::toggleRunningScriptsWidget() const {
5792− auto scriptEngines = DependencyManager::get<ScriptEngines>();
5793− bool scriptsRunning = !scriptEngines->getRunningScripts().isEmpty();
5794− auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>();
5795− auto tablet = dynamic_cast<TabletProxy*>(tabletScriptingInterface->getTablet("com.highfidelity.interface.tablet.system"));
5800+void Application::showDialog(const QUrl& widgetUrl, const QUrl& tabletUrl, const QString& name) const {
5801+ auto tablet = DependencyManager::get<TabletScriptingInterface>()->getTablet(SYSTEM_TABLET);
5802+ auto hmd = DependencyManager::get<HMDScriptingInterface>();
5803+ bool onTablet = false;
57965804
5797− if (tablet->getToolbarMode() || false == scriptsRunning) {
5798− static const QUrl url("hifi/dialogs/RunningScripts.qml");
5799− DependencyManager::get<OffscreenUi>()->show(url, "RunningScripts");
5800− } else {
5801− auto hmd = DependencyManager::get<HMDScriptingInterface>();
5802− if (!hmd->getShouldShowTablet() && !isHMDMode()) {
5803− static const QUrl url("hifi/dialogs/RunningScripts.qml");
5804− DependencyManager::get<OffscreenUi>()->show(url, "RunningScripts");
5805− } else {
5806− static const QUrl url("../../hifi/dialogs/TabletRunningScripts.qml");
5807− tablet->pushOntoStack(url);
5805+ if (!tablet->getToolbarMode()) {
5806+ onTablet = tablet->pushOntoStack(tabletUrl);
5807+ if (onTablet) {
5808+ toggleTabletUI(true);
58085809 }
58095810 }
5810− //DependencyManager::get<OffscreenUi>()->show(url, "RunningScripts");
5811− //if (_runningScriptsWidget->isVisible()) {
5812− // if (_runningScriptsWidget->hasFocus()) {
5813− // _runningScriptsWidget->hide();
5814− // } else {
5815− // _runningScriptsWidget->raise();
5816− // setActiveWindow(_runningScriptsWidget);
5817− // _runningScriptsWidget->setFocus();
5818− // }
5819− //} else {
5820− // _runningScriptsWidget->show();
5821− // _runningScriptsWidget->setFocus();
5822− //}
5811+
5812+ if (!onTablet) {
5813+ DependencyManager::get<OffscreenUi>()->show(widgetUrl, name);
5814+ }
5815+ if (tablet->getToolbarMode()) {
5816+ DependencyManager::get<OffscreenUi>()->show(widgetUrl, name);
5817+ }
58235818 }
58245819
58255820 void Application::showScriptLogs() {
@@ -5841,7 +5836,7 @@ void Application::showAssetServerWidget(QString filePath) { · 15 unmodified lines
58415836 }
58425837 };
58435838 auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>();
5844− auto tablet = dynamic_cast<TabletProxy*>(tabletScriptingInterface->getTablet("com.highfidelity.interface.tablet.system"));
5839+ auto tablet = dynamic_cast<TabletProxy*>(tabletScriptingInterface->getTablet(SYSTEM_TABLET));
58455840 auto hmd = DependencyManager::get<HMDScriptingInterface>();
58465841 if (tablet->getToolbarMode()) {
58475842 DependencyManager::get<OffscreenUi>()->show(url, "AssetServer", startUpload);
@@ -5876,21 +5871,6 @@ void Application::addAssetToWorldFromURL(QString url) { · 28 unmodified lines
58765871 request->send();
58775872 }
58785873
5879−void Application::showDialog(const QString& desktopURL, const QString& tabletURL, const QString& name) const {
5880− auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>();
5881− auto tablet = dynamic_cast<TabletProxy*>(tabletScriptingInterface->getTablet("com.highfidelity.interface.tablet.system"));
5882− auto hmd = DependencyManager::get<HMDScriptingInterface>();
5883− if (tablet->getToolbarMode()) {
5884− DependencyManager::get<OffscreenUi>()->show(desktopURL, name);
5885− } else {
5886− tablet->pushOntoStack(tabletURL);
5887− if (!hmd->getShouldShowTablet() && !isHMDMode()) {
5888− hmd->openTablet();
5889− }
5890−
5891− }
5892−}
5893−
58945874 void Application::addAssetToWorldFromURLRequestFinished() {
58955875 auto request = qobject_cast<ResourceRequest*>(sender());
58965876 auto url = request->getUrl().toString();
@@ -6374,7 +6354,7 @@ void Application::loadScriptURLDialog() const { · 477 unmodified lines
63746354
63756355 void Application::loadLODToolsDialog() {
63766356 auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>();
6377− auto tablet = dynamic_cast<TabletProxy*>(tabletScriptingInterface->getTablet("com.highfidelity.interface.tablet.system"));
6357+ auto tablet = dynamic_cast<TabletProxy*>(tabletScriptingInterface->getTablet(SYSTEM_TABLET));
63786358 if (tablet->getToolbarMode() || (!tablet->getTabletRoot() && !isHMDMode())) {
63796359 auto dialogsManager = DependencyManager::get<DialogsManager>();
63806360 dialogsManager->lodTools();
@@ -6386,7 +6366,7 @@ void Application::loadLODToolsDialog() { · 5 unmodified lines
63866366
63876367 void Application::loadEntityStatisticsDialog() {
63886368 auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>();
6389− auto tablet = dynamic_cast<TabletProxy*>(tabletScriptingInterface->getTablet("com.highfidelity.interface.tablet.system"));
6369+ auto tablet = dynamic_cast<TabletProxy*>(tabletScriptingInterface->getTablet(SYSTEM_TABLET));
63906370 if (tablet->getToolbarMode() || (!tablet->getTabletRoot() && !isHMDMode())) {
63916371 auto dialogsManager = DependencyManager::get<DialogsManager>();
63926372 dialogsManager->octreeStatsDetails();
@@ -6397,7 +6377,7 @@ void Application::loadEntityStatisticsDialog() { · 4 unmodified lines
63976377
63986378 void Application::loadDomainConnectionDialog() {
63996379 auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>();
6400− auto tablet = dynamic_cast<TabletProxy*>(tabletScriptingInterface->getTablet("com.highfidelity.interface.tablet.system"));
6380+ auto tablet = dynamic_cast<TabletProxy*>(tabletScriptingInterface->getTablet(SYSTEM_TABLET));
64016381 if (tablet->getToolbarMode() || (!tablet->getTabletRoot() && !isHMDMode())) {
64026382 auto dialogsManager = DependencyManager::get<DialogsManager>();
64036383 dialogsManager->showDomainConnectionDialog();
@@ -7054,11 +7034,6 @@ void Application::updateSystemTabletMode() { · 650 unmodified lines
70547034 }
70557035 }
70567036
7057−void Application::toggleMuteAudio() {
7058− auto menu = Menu::getInstance();
7059− menu->setIsOptionChecked(MenuOption::MuteAudio, !menu->isOptionChecked(MenuOption::MuteAudio));
7060−}
7061−
70627037 OverlayID Application::getTabletScreenID() const {
70637038 auto HMD = DependencyManager::get<HMDScriptingInterface>();
70647039 return HMD->getCurrentTabletScreenID();