History

Merge branch 'spectator-camera' of https://github.com/highfidelity/hifi into dk/spectatorCameraPreview

David Kelly committed 9 years ago

Commit b73102d2 parents 06b59fe 5d8d2fd406 files · +10790 −3706Browse files

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

Unified · Split

interface/src/Application.cpp+112−42
@@ -37,8 +37,6 @@ · 36 unmodified lines
3737 #include <QtQml/QQmlEngine>
3838 #include <QtQuick/QQuickWindow>
3939
40−#include <QtWebEngineWidgets/QWebEngineProfile>
41−
4240 #include <QtWidgets/QDesktopWidget>
4341 #include <QtWidgets/QMessageBox>
4442
@@ -88,6 +86,7 @@ · 43 unmodified lines
8886 #include <UserActivityLoggerScriptingInterface.h>
8987 #include <LogHandler.h>
9088 #include "LocationBookmarks.h"
89+#include <LocationScriptingInterface.h>
9190 #include <MainWindow.h>
9291 #include <MappingRequest.h>
9392 #include <MessagesClient.h>
@@ -98,8 +97,8 @@ · 4 unmodified lines
9897 #include <OctalCode.h>
9998 #include <OctreeSceneStats.h>
10099 #include <OffscreenUi.h>
101−#include <gl/OffscreenQmlSurfaceCache.h>
102100 #include <gl/OffscreenGLCanvas.h>
101+#include <ui/OffscreenQmlSurfaceCache.h>
103102 #include <PathUtils.h>
104103 #include <PerfStat.h>
105104 #include <PhysicsEngine.h>
@@ -108,6 +107,7 @@ · 2 unmodified lines
108107 #include <plugins/PluginManager.h>
109108 #include <plugins/PluginUtils.h>
110109 #include <plugins/SteamClientPlugin.h>
110+#include <plugins/InputConfiguration.h>
111111 #include <RecordingScriptingInterface.h>
112112 #include <RenderableWebEntityItem.h>
113113 #include <RenderShadowTask.h>
@@ -123,7 +123,8 @@ · 9 unmodified lines
123123 #include <ScriptEngines.h>
124124 #include <ScriptCache.h>
125125 #include <SoundCache.h>
126−#include <TabletScriptingInterface.h>
126+#include <ui/TabletScriptingInterface.h>
127+#include <ui/ToolbarScriptingInterface.h>
127128 #include <Tooltip.h>
128129 #include <udt/PacketHeaders.h>
129130 #include <UserActivityLogger.h>
@@ -160,12 +161,10 @@ · 30 unmodified lines
160161 #include "scripting/DesktopScriptingInterface.h"
161162 #include "scripting/GlobalServicesScriptingInterface.h"
162163 #include "scripting/HMDScriptingInterface.h"
163−#include "scripting/LocationScriptingInterface.h"
164164 #include "scripting/MenuScriptingInterface.h"
165165 #include "scripting/SettingsScriptingInterface.h"
166166 #include "scripting/WindowScriptingInterface.h"
167167 #include "scripting/ControllerScriptingInterface.h"
168−#include "scripting/ToolbarScriptingInterface.h"
169168 #include "scripting/RatesScriptingInterface.h"
170169 #if defined(Q_OS_MAC) || defined(Q_OS_WIN)
171170 #include "SpeechRecognizer.h"
@@ -441,8 +440,41 @@ static const QString STATE_ADVANCED_MOVEMENT_CONTROLS = "AdvancedMovement"; · 269 unmodified lines
441440 static const QString STATE_GROUNDED = "Grounded";
442441 static const QString STATE_NAV_FOCUSED = "NavigationFocused";
443442
443+// Statically provided display and input plugins
444+extern DisplayPluginList getDisplayPlugins();
445+extern InputPluginList getInputPlugins();
446+extern void saveInputPluginSettings(const InputPluginList& plugins);
447+
444448 bool setupEssentials(int& argc, char** argv, bool runningMarkerExisted) {
445449 const char** constArgv = const_cast<const char**>(argv);
450+
451+ // HRS: I could not figure out how to move these any earlier in startup, so when using this option, be sure to also supply
452+ // --allowMultipleInstances
453+ auto reportAndQuit = [&](const char* commandSwitch, std::function<void(FILE* fp)> report) {
454+ const char* reportfile = getCmdOption(argc, constArgv, commandSwitch);
455+ // Reports to the specified file, because stdout is set up to be captured for logging.
456+ if (reportfile) {
457+ FILE* fp = fopen(reportfile, "w");
458+ if (fp) {
459+ report(fp);
460+ fclose(fp);
461+ if (!runningMarkerExisted) { // don't leave ours around
462+ RunningMarker runingMarker(RUNNING_MARKER_FILENAME);
463+ runingMarker.deleteRunningMarkerFile(); // happens in deleter, but making the side-effect explicit.
464+ }
465+ _exit(0);
466+ }
467+ }
468+ };
469+ reportAndQuit("--protocolVersion", [&](FILE* fp) {
470+ DependencyManager::set<AddressManager>();
471+ auto version = DependencyManager::get<AddressManager>()->protocolVersion();
472+ fputs(version.toLatin1().data(), fp);
473+ });
474+ reportAndQuit("--version", [&](FILE* fp) {
475+ fputs(BuildInfo::VERSION.toLatin1().data(), fp);
476+ });
477+
446478 const char* portStr = getCmdOption(argc, constArgv, "--listenPort");
447479 const int listenPort = portStr ? atoi(portStr) : INVALID_PORT;
448480
@@ -452,7 +484,12 @@ bool setupEssentials(int& argc, char** argv, bool runningMarkerExisted) { · 3 unmodified lines
452484
453485 Setting::init();
454486
455− if (auto steamClient = PluginManager::getInstance()->getSteamClientPlugin()) {
487+ // Tell the plugin manager about our statically linked plugins
488+ auto pluginManager = PluginManager::getInstance();
489+ pluginManager->setInputPluginProvider([] { return getInputPlugins(); });
490+ pluginManager->setDisplayPluginProvider([] { return getDisplayPlugins(); });
491+ pluginManager->setInputPluginSettingsPersister([](const InputPluginList& plugins) { saveInputPluginSettings(plugins); });
492+ if (auto steamClient = pluginManager->getSteamClientPlugin()) {
456493 steamClient->init();
457494 }
458495
@@ -512,6 +549,7 @@ bool setupEssentials(int& argc, char** argv, bool runningMarkerExisted) { · 53 unmodified lines
512549 DependencyManager::set<HMDScriptingInterface>();
513550 DependencyManager::set<ResourceScriptingInterface>();
514551 DependencyManager::set<TabletScriptingInterface>();
552+ DependencyManager::set<InputConfiguration>();
515553 DependencyManager::set<ToolbarScriptingInterface>();
516554 DependencyManager::set<UserActivityLoggerScriptingInterface>();
517555 DependencyManager::set<AssetMappingsScriptingInterface>();
@@ -582,7 +620,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo · 64 unmodified lines
582620 _undoStackScriptingInterface(&_undoStack),
583621 _entitySimulation(new PhysicalEntitySimulation()),
584622 _physicsEngine(new PhysicsEngine(Vectors::ZERO)),
585− _entityClipboardRenderer(false, this, this),
586623 _entityClipboard(new EntityTree()),
587624 _lastQueriedTime(usecTimestampNow()),
588625 _previousScriptLocation("LastScriptLocation", DESKTOP_LOCATION),
@@ -685,9 +722,13 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo · 96 unmodified lines
685722 updateHeartbeat();
686723
687724 // setup a timer for domain-server check ins
688− QTimer* domainCheckInTimer = new QTimer(nodeList.data());
725+ QTimer* domainCheckInTimer = new QTimer(this);
689726 connect(domainCheckInTimer, &QTimer::timeout, nodeList.data(), &NodeList::sendDomainServerCheckIn);
690727 domainCheckInTimer->start(DOMAIN_SERVER_CHECK_IN_MSECS);
728+ connect(this, &QCoreApplication::aboutToQuit, [domainCheckInTimer] {
729+ domainCheckInTimer->stop();
730+ domainCheckInTimer->deleteLater();
731+ });
691732
692733
693734 auto audioIO = DependencyManager::get<AudioClient>();
@@ -861,6 +902,25 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo · 167 unmodified lines
861902 }
862903 ResourceCache::setRequestLimit(concurrentDownloads);
863904
905+ // perhaps override the avatar url. Since we will test later for validity
906+ // we don't need to do so here.
907+ QString avatarURL = getCmdOption(argc, constArgv, "--avatarURL");
908+ _avatarOverrideUrl = QUrl::fromUserInput(avatarURL);
909+
910+ // If someone specifies both --avatarURL and --replaceAvatarURL,
911+ // the replaceAvatarURL wins. So only set the _overrideUrl if this
912+ // does have a non-empty string.
913+ QString replaceURL = getCmdOption(argc, constArgv, "--replaceAvatarURL");
914+ if (!replaceURL.isEmpty()) {
915+ _avatarOverrideUrl = QUrl::fromUserInput(replaceURL);
916+ _saveAvatarOverrideUrl = true;
917+ }
918+
919+ QString defaultScriptsLocation = getCmdOption(argc, constArgv, "--scripts");
920+ if (!defaultScriptsLocation.isEmpty()) {
921+ PathUtils::defaultScriptsLocation(defaultScriptsLocation);
922+ }
923+
864924 _glWidget = new GLCanvas();
865925 getApplicationCompositor().setRenderingWidget(_glWidget);
866926 _window->setCentralWidget(_glWidget);
@@ -957,7 +1017,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo · 90 unmodified lines
9571017 // Make sure we don't time out during slow operations at startup
9581018 updateHeartbeat();
9591019
960− connect(this, SIGNAL(aboutToQuit()), this, SLOT(aboutToQuit()));
1020+ connect(this, SIGNAL(aboutToQuit()), this, SLOT(onAboutToQuit()));
9611021
9621022 // hook up bandwidth estimator
9631023 QSharedPointer<BandwidthRecorder> bandwidthRecorder = DependencyManager::get<BandwidthRecorder>();
@@ -1125,7 +1185,15 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo · 161 unmodified lines
11251185 // force the model the look at the correct directory (weird order of operations issue)
11261186 scriptEngines->setScriptsLocation(scriptEngines->getScriptsLocation());
11271187 // do this as late as possible so that all required subsystems are initialized
1128− scriptEngines->loadScripts();
1188+ // If we've overridden the default scripts location, just load default scripts
1189+ // otherwise, load 'em all
1190+ if (!defaultScriptsLocation.isEmpty()) {
1191+ scriptEngines->loadDefaultScripts();
1192+ scriptEngines->defaultScriptsLocationOverridden(true);
1193+ } else {
1194+ scriptEngines->loadScripts();
1195+ }
1196+
11291197 // Make sure we don't time out during slow operations at startup
11301198 updateHeartbeat();
11311199
@@ -1451,7 +1519,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo · 319 unmodified lines
14511519 });
14521520 sendStatsTimer->start();
14531521
1454−
14551522 // Periodically check for count of nearby avatars
14561523 static int lastCountOfNearbyAvatars = -1;
14571524 QTimer* checkNearbyAvatarsTimer = new QTimer(this);
@@ -1646,7 +1713,7 @@ void Application::updateHeartbeat() const { · 188 unmodified lines
16461713 static_cast<DeadlockWatchdogThread*>(_deadlockWatchdogThread)->updateHeartbeat();
16471714 }
16481715
1649−void Application::aboutToQuit() {
1716+void Application::onAboutToQuit() {
16501717 emit beforeAboutToQuit();
16511718
16521719 foreach(auto inputPlugin, PluginManager::getInstance()->getInputPlugins()) {
@@ -1751,6 +1818,8 @@ void Application::cleanupBeforeQuit() { · 98 unmodified lines
17511818 #endif
17521819
17531820 // stop QML
1821+ DependencyManager::destroy<TabletScriptingInterface>();
1822+ DependencyManager::destroy<ToolbarScriptingInterface>();
17541823 DependencyManager::destroy<OffscreenUi>();
17551824
17561825 DependencyManager::destroy<OffscreenQmlSurfaceCache>();
@@ -2001,6 +2070,7 @@ void Application::initializeUi() { · 244 unmodified lines
20012070 surfaceContext->setContextProperty("TextureCache", DependencyManager::get<TextureCache>().data());
20022071 surfaceContext->setContextProperty("ModelCache", DependencyManager::get<ModelCache>().data());
20032072 surfaceContext->setContextProperty("SoundCache", DependencyManager::get<SoundCache>().data());
2073+ surfaceContext->setContextProperty("InputConfiguration", DependencyManager::get<InputConfiguration>().data());
20042074
20052075 surfaceContext->setContextProperty("Account", AccountScriptingInterface::getInstance());
20062076 surfaceContext->setContextProperty("Tablet", DependencyManager::get<TabletScriptingInterface>().data());
@@ -2483,8 +2553,11 @@ void Application::handleSandboxStatus(QNetworkReply* reply) { · 476 unmodified lines
24832553 Setting::Handle<bool> tutorialComplete{ "tutorialComplete", false };
24842554 Setting::Handle<bool> firstRun{ Settings::firstRun, true };
24852555
2556+ const QString HIFI_SKIP_TUTORIAL_COMMAND_LINE_KEY = "--skipTutorial";
2557+ // Skips tutorial/help behavior, and does NOT clear firstRun setting.
2558+ bool skipTutorial = arguments().contains(HIFI_SKIP_TUTORIAL_COMMAND_LINE_KEY);
24862559 bool isTutorialComplete = tutorialComplete.get();
2487− bool shouldGoToTutorial = isUsingHMDAndHandControllers && hasTutorialContent && !isTutorialComplete;
2560+ bool shouldGoToTutorial = isUsingHMDAndHandControllers && hasTutorialContent && !isTutorialComplete && !skipTutorial;
24882561
24892562 qCDebug(interfaceapp) << "HMD:" << hasHMD << ", Hand Controllers: " << hasHandControllers << ", Using HMD: " << isUsingHMDAndHandControllers;
24902563 qCDebug(interfaceapp) << "Tutorial version:" << contentVersion << ", sufficient:" << hasTutorialContent <<
@@ -2527,14 +2600,9 @@ void Application::handleSandboxStatus(QNetworkReply* reply) { · 36 unmodified lines
25272600 }
25282601 } else {
25292602
2530− bool isFirstRun = firstRun.get();
2531−
2532− if (isFirstRun) {
2533− showHelp();
2534− }
2535−
25362603 // If this is a first run we short-circuit the address passed in
2537− if (isFirstRun) {
2604+ if (firstRun.get() && !skipTutorial) {
2605+ showHelp();
25382606 if (isUsingHMDAndHandControllers) {
25392607 if (sandboxIsRunning) {
25402608 qCDebug(interfaceapp) << "Home sandbox appears to be running, going to Home.";
@@ -2572,7 +2640,9 @@ void Application::handleSandboxStatus(QNetworkReply* reply) { · 31 unmodified lines
25722640 _connectionMonitor.init();
25732641
25742642 // After all of the constructor is completed, then set firstRun to false.
2575− firstRun.set(false);
2643+ if (!skipTutorial) {
2644+ firstRun.set(false);
2645+ }
25762646 }
25772647
25782648 bool Application::importJSONFromURL(const QString& urlString) {
@@ -3992,11 +4062,6 @@ void Application::init() { · 1413 unmodified lines
39924062 DependencyManager::get<NodeList>()->sendDomainServerCheckIn();
39934063
39944064 getEntities()->init();
3995− {
3996− QMutexLocker viewLocker(&_viewMutex);
3997− getEntities()->setViewFrustum(_viewFrustum);
3998− }
3999−
40004065 getEntities()->setEntityLoadingPriorityFunction([this](const EntityItem& item) {
40014066 auto dims = item.getDimensions();
40024067 auto maxSize = glm::compMax(dims);
@@ -4026,13 +4091,6 @@ void Application::init() { · 23 unmodified lines
40264091 // of events related clicking, hovering over, and entering entities
40274092 getEntities()->connectSignalsToSlots(entityScriptingInterface.data());
40284093
4029− _entityClipboardRenderer.init();
4030− {
4031− QMutexLocker viewLocker(&_viewMutex);
4032− _entityClipboardRenderer.setViewFrustum(_viewFrustum);
4033− }
4034− _entityClipboardRenderer.setTree(_entityClipboard);
4035−
40364094 // Make sure any new sounds are loaded as soon as know about them.
40374095 connect(tree.get(), &EntityTree::newCollisionSoundURL, this, [this](QUrl newURL, EntityItemID id) {
40384096 EntityTreePointer tree = getEntities()->getTree();
@@ -5025,9 +5083,6 @@ QRect Application::getDesirableApplicationGeometry() const { · 986 unmodified lines
50255083 return applicationGeometry;
50265084 }
50275085
5028−// FIXME, preprocessor guard this check to occur only in DEBUG builds
5029−static QThread * activeRenderingThread = nullptr;
5030−
50315086 PickRay Application::computePickRay(float x, float y) const {
50325087 vec2 pickPoint { x, y };
50335088 PickRay result;
@@ -5098,7 +5153,6 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se · 64 unmodified lines
50985153 auto myAvatar = getMyAvatar();
50995154 myAvatar->preDisplaySide(renderArgs);
51005155
5101− activeRenderingThread = QThread::currentThread();
51025156 PROFILE_RANGE(render, __FUNCTION__);
51035157 PerformanceTimer perfTimer("display");
51045158 PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), "Application::displaySide()");
@@ -5171,8 +5225,6 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se · 66 unmodified lines
51715225 // Before the deferred pass, let's try to use the render engine
51725226 _renderEngine->run();
51735227 }
5174−
5175− activeRenderingThread = nullptr;
51765228 }
51775229
51785230 void Application::resetSensors(bool andReload) {
@@ -5303,6 +5355,10 @@ void Application::nodeActivated(SharedNodePointer node) { · 124 unmodified lines
53035355 if (node->getType() == NodeType::AvatarMixer) {
53045356 // new avatar mixer, send off our identity packet on next update loop
53055357 // Reset skeletonModelUrl if the last server modified our choice.
5358+ // Override the avatar url (but not model name) here too.
5359+ if (_avatarOverrideUrl.isValid()) {
5360+ getMyAvatar()->useFullAvatarURL(_avatarOverrideUrl);
5361+ }
53065362 static const QUrl empty{};
53075363 if (getMyAvatar()->getFullAvatarURLFromPreferences() != getMyAvatar()->cannonicalSkeletonModelURL(empty)) {
53085364 getMyAvatar()->resetFullAvatarURL();
@@ -5508,8 +5564,16 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri · 199 unmodified lines
55085564
55095565 scriptEngine->registerGlobalObject("OffscreenFlags", DependencyManager::get<OffscreenUi>()->getFlags());
55105566 scriptEngine->registerGlobalObject("Desktop", DependencyManager::get<DesktopScriptingInterface>().data());
5567+
5568+ qScriptRegisterMetaType(scriptEngine, wrapperToScriptValue<ToolbarProxy>, wrapperFromScriptValue<ToolbarProxy>);
5569+ qScriptRegisterMetaType(scriptEngine, wrapperToScriptValue<ToolbarButtonProxy>, wrapperFromScriptValue<ToolbarButtonProxy>);
55115570 scriptEngine->registerGlobalObject("Toolbars", DependencyManager::get<ToolbarScriptingInterface>().data());
55125571
5572+ qScriptRegisterMetaType(scriptEngine, wrapperToScriptValue<TabletProxy>, wrapperFromScriptValue<TabletProxy>);
5573+ qScriptRegisterMetaType(scriptEngine, wrapperToScriptValue<TabletButtonProxy>, wrapperFromScriptValue<TabletButtonProxy>);
5574+ scriptEngine->registerGlobalObject("Tablet", DependencyManager::get<TabletScriptingInterface>().data());
5575+
5576+
55135577 DependencyManager::get<TabletScriptingInterface>().data()->setToolbarScriptingInterface(DependencyManager::get<ToolbarScriptingInterface>().data());
55145578
55155579 scriptEngine->registerGlobalObject("Window", DependencyManager::get<WindowScriptingInterface>().data());
@@ -5583,7 +5647,6 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri · 67 unmodified lines
55835647 scriptEngine->registerGlobalObject("EntityScriptServerLog", entityScriptServerLog.data());
55845648 scriptEngine->registerGlobalObject("AvatarInputs", AvatarInputs::getInstance());
55855649
5586−
55875650 qScriptRegisterMetaType(scriptEngine, OverlayIDtoScriptValue, OverlayIDfromScriptValue);
55885651
55895652 // connect this script engines printedMessage signal to the global ScriptEngines these various messages
@@ -5591,6 +5654,8 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri · 1 unmodified line
55915654 connect(scriptEngine, &ScriptEngine::errorMessage, DependencyManager::get<ScriptEngines>().data(), &ScriptEngines::onErrorMessage);
55925655 connect(scriptEngine, &ScriptEngine::warningMessage, DependencyManager::get<ScriptEngines>().data(), &ScriptEngines::onWarningMessage);
55935656 connect(scriptEngine, &ScriptEngine::infoMessage, DependencyManager::get<ScriptEngines>().data(), &ScriptEngines::onInfoMessage);
5657+ connect(scriptEngine, &ScriptEngine::clearDebugWindow, DependencyManager::get<ScriptEngines>().data(), &ScriptEngines::onClearDebugWindow);
5658+
55945659 }
55955660
55965661 bool Application::canAcceptURL(const QString& urlString) const {
@@ -5827,7 +5892,7 @@ void Application::showDialog(const QUrl& widgetUrl, const QUrl& tabletUrl, const · 230 unmodified lines
58275892
58285893 void Application::showScriptLogs() {
58295894 auto scriptEngines = DependencyManager::get<ScriptEngines>();
5830− QUrl defaultScriptsLoc = defaultScriptsLocation();
5895+ QUrl defaultScriptsLoc = PathUtils::defaultScriptsLocation();
58315896 defaultScriptsLoc.setPath(defaultScriptsLoc.path() + "developer/debugging/debugWindow.js");
58325897 scriptEngines->loadScript(defaultScriptsLoc.toString());
58335898 }
@@ -7056,3 +7121,8 @@ QUuid Application::getTabletFrameID() const { · 1222 unmodified lines
70567121 auto HMD = DependencyManager::get<HMDScriptingInterface>();
70577122 return HMD->getCurrentTabletFrameID();
70587123 }
7124+
7125+void Application::setAvatarOverrideUrl(const QUrl& url, bool save) {
7126+ _avatarOverrideUrl = url;
7127+ _saveAvatarOverrideUrl = save;
7128+}