History

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

Stephen Birarda committed 10 years ago

Commit 404fb2f2 parents 184bae2 3a7ec33136 files · +3417 −1538Browse files

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

Unified · Split

interface/src/Application.cpp+127−26
@@ -20,6 +20,8 @@ · 19 unmodified lines
2020 #include <glm/gtc/type_ptr.hpp>
2121
2222 #include <QtCore/QDebug>
23+#include <QtCore/QJsonDocument>
24+#include <QtCore/QJsonObject>
2325 #include <QtCore/QObject>
2426 #include <QtCore/QUrl>
2527 #include <QtCore/QTimer>
@@ -89,6 +91,7 @@ · 63 unmodified lines
8991 #include <ObjectMotionState.h>
9092 #include <OctalCode.h>
9193 #include <OctreeSceneStats.h>
94+#include <OffscreenUi.h>
9295 #include <gl/OffscreenGLCanvas.h>
9396 #include <PathUtils.h>
9497 #include <PerfStat.h>
@@ -187,6 +190,7 @@ static const QString JS_EXTENSION = ".js"; · 92 unmodified lines
187190 static const QString FST_EXTENSION = ".fst";
188191 static const QString FBX_EXTENSION = ".fbx";
189192 static const QString OBJ_EXTENSION = ".obj";
193+static const QString AVA_JSON_EXTENSION = ".ava.json";
190194
191195 static const int MIRROR_VIEW_TOP_PADDING = 5;
192196 static const int MIRROR_VIEW_LEFT_PADDING = 10;
@@ -222,7 +226,8 @@ const QHash<QString, Application::AcceptURLMethod> Application::_acceptedExtensi · 29 unmodified lines
222226 { SVO_EXTENSION, &Application::importSVOFromURL },
223227 { SVO_JSON_EXTENSION, &Application::importSVOFromURL },
224228 { JS_EXTENSION, &Application::askToLoadScript },
225− { FST_EXTENSION, &Application::askToSetAvatarUrl }
229+ { FST_EXTENSION, &Application::askToSetAvatarUrl },
230+ { AVA_JSON_EXTENSION, &Application::askToWearAvatarAttachmentUrl }
226231 };
227232
228233 #ifdef Q_OS_WIN
@@ -347,7 +352,7 @@ bool setupEssentials(int& argc, char** argv) { · 118 unmodified lines
347352 DependencyManager::set<WindowScriptingInterface>();
348353 DependencyManager::set<HMDScriptingInterface>();
349354 DependencyManager::set<ResourceScriptingInterface>();
350−
355+
351356
352357 #if defined(Q_OS_MAC) || defined(Q_OS_WIN)
353358 DependencyManager::set<SpeechRecognizer>();
@@ -378,7 +383,7 @@ PluginContainer* _pluginContainer; · 24 unmodified lines
378383
379384
380385 // FIXME hack access to the internal share context for the Chromium helper
381−// Normally we'd want to use QWebEngine::initialize(), but we can't because
386+// Normally we'd want to use QWebEngine::initialize(), but we can't because
382387 // our primary context is a QGLWidget, which can't easily be initialized to share
383388 // from a QOpenGLContext.
384389 //
@@ -694,7 +699,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) : · 309 unmodified lines
694699 auto userInputMapper = DependencyManager::get<UserInputMapper>();
695700 connect(userInputMapper.data(), &UserInputMapper::actionEvent, [this](int action, float state) {
696701 using namespace controller;
697− static auto offscreenUi = DependencyManager::get<OffscreenUi>();
702+ auto offscreenUi = DependencyManager::get<OffscreenUi>();
698703 if (offscreenUi->navigationFocused()) {
699704 auto actionEnum = static_cast<Action>(action);
700705 int key = Qt::Key_unknown;
@@ -735,6 +740,8 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) : · 34 unmodified lines
735740 case Action::UI_NAV_SELECT:
736741 key = Qt::Key_Return;
737742 break;
743+ default:
744+ break;
738745 }
739746
740747 if (navAxis) {
@@ -832,7 +839,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) : · 91 unmodified lines
832839 return (float)qApp->getMyAvatar()->getCharacterController()->onGround();
833840 }));
834841 _applicationStateDevice->addInputVariant(QString("NavigationFocused"), controller::StateController::ReadLambda([]() -> float {
835− static auto offscreenUi = DependencyManager::get<OffscreenUi>();
842+ auto offscreenUi = DependencyManager::get<OffscreenUi>();
836843 return offscreenUi->navigationFocused() ? 1.0 : 0.0;
837844 }));
838845
@@ -1035,7 +1042,7 @@ void Application::cleanupBeforeQuit() { · 196 unmodified lines
10351042
10361043 // destroy the AudioClient so it and its thread have a chance to go down safely
10371044 DependencyManager::destroy<AudioClient>();
1038−
1045+
10391046 // destroy the AudioInjectorManager so it and its thread have a chance to go down safely
10401047 // this will also stop any ongoing network injectors
10411048 DependencyManager::destroy<AudioInjectorManager>();
@@ -1047,6 +1054,8 @@ void Application::cleanupBeforeQuit() { · 5 unmodified lines
10471054 #ifdef HAVE_IVIEWHMD
10481055 DependencyManager::destroy<EyeTracker>();
10491056 #endif
1057+
1058+ DependencyManager::destroy<OffscreenUi>();
10501059 }
10511060
10521061 void Application::emptyLocalCache() {
@@ -1080,8 +1089,8 @@ Application::~Application() { · 27 unmodified lines
10801089 // remove avatars from physics engine
10811090 DependencyManager::get<AvatarManager>()->clearOtherAvatars();
10821091 VectorOfMotionStates motionStates;
1083− DependencyManager::get<AvatarManager>()->getObjectsToDelete(motionStates);
1084− _physicsEngine->deleteObjects(motionStates);
1092+ DependencyManager::get<AvatarManager>()->getObjectsToRemoveFromPhysics(motionStates);
1093+ _physicsEngine->removeObjects(motionStates);
10851094
10861095 DependencyManager::destroy<OffscreenUi>();
10871096 DependencyManager::destroy<AvatarManager>();
@@ -1176,7 +1185,6 @@ void Application::initializeUi() { · 88 unmodified lines
11761185 offscreenUi->setProxyWindow(_window->windowHandle());
11771186 offscreenUi->setBaseUrl(QUrl::fromLocalFile(PathUtils::resourcesPath() + "/qml/"));
11781187 offscreenUi->load("Root.qml");
1179− offscreenUi->load("RootMenu.qml");
11801188 // FIXME either expose so that dialogs can set this themselves or
11811189 // do better detection in the offscreen UI of what has focus
11821190 offscreenUi->setNavigationFocused(false);
@@ -1265,7 +1273,7 @@ void Application::initializeUi() { · 82 unmodified lines
12651273 }
12661274
12671275 void Application::paintGL() {
1268− // paintGL uses a queued connection, so we can get messages from the queue even after we've quit
1276+ // paintGL uses a queued connection, so we can get messages from the queue even after we've quit
12691277 // and the plugins have shutdown
12701278 if (_aboutToQuit) {
12711279 return;
@@ -1335,7 +1343,7 @@ void Application::paintGL() { · 63 unmodified lines
13351343 renderArgs._context->syncCache();
13361344 }
13371345
1338− if (Menu::getInstance()->isOptionChecked(MenuOption::Mirror)) {
1346+ if (Menu::getInstance()->isOptionChecked(MenuOption::MiniMirror)) {
13391347 PerformanceTimer perfTimer("Mirror");
13401348 auto primaryFbo = DependencyManager::get<FramebufferCache>()->getPrimaryFramebuffer();
13411349
@@ -1624,7 +1632,7 @@ void Application::aboutApp() { · 282 unmodified lines
16241632 InfoView::show(INFO_HELP_PATH);
16251633 }
16261634
1627−void Application::showEditEntitiesHelp() {
1635+void Application::showHelp() {
16281636 InfoView::show(INFO_EDIT_ENTITIES_PATH);
16291637 }
16301638
@@ -1982,7 +1990,7 @@ void Application::keyPressEvent(QKeyEvent* event) { · 351 unmodified lines
19821990
19831991 case Qt::Key_H:
19841992 if (isShifted) {
1985− Menu::getInstance()->triggerOption(MenuOption::Mirror);
1993+ Menu::getInstance()->triggerOption(MenuOption::MiniMirror);
19861994 } else {
19871995 Menu::getInstance()->setIsOptionChecked(MenuOption::FullscreenMirror, !Menu::getInstance()->isOptionChecked(MenuOption::FullscreenMirror));
19881996 if (!Menu::getInstance()->isOptionChecked(MenuOption::FullscreenMirror)) {
@@ -3082,11 +3090,11 @@ void Application::update(float deltaTime) { · 1093 unmodified lines
30823090 PerformanceTimer perfTimer("physics");
30833091
30843092 static VectorOfMotionStates motionStates;
3085− _entitySimulation.getObjectsToDelete(motionStates);
3086− _physicsEngine->deleteObjects(motionStates);
3093+ _entitySimulation.getObjectsToRemoveFromPhysics(motionStates);
3094+ _physicsEngine->removeObjects(motionStates);
30873095
30883096 getEntities()->getTree()->withWriteLock([&] {
3089− _entitySimulation.getObjectsToAdd(motionStates);
3097+ _entitySimulation.getObjectsToAddToPhysics(motionStates);
30903098 _physicsEngine->addObjects(motionStates);
30913099
30923100 });
@@ -3099,9 +3107,9 @@ void Application::update(float deltaTime) { · 6 unmodified lines
30993107 _entitySimulation.applyActionChanges();
31003108
31013109 AvatarManager* avatarManager = DependencyManager::get<AvatarManager>().data();
3102− avatarManager->getObjectsToDelete(motionStates);
3103− _physicsEngine->deleteObjects(motionStates);
3104− avatarManager->getObjectsToAdd(motionStates);
3110+ avatarManager->getObjectsToRemoveFromPhysics(motionStates);
3111+ _physicsEngine->removeObjects(motionStates);
3112+ avatarManager->getObjectsToAddToPhysics(motionStates);
31053113 _physicsEngine->addObjects(motionStates);
31063114 avatarManager->getObjectsToChange(motionStates);
31073115 _physicsEngine->changeObjects(motionStates);
@@ -3738,7 +3746,7 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se · 630 unmodified lines
37383746 auto backgroundRenderData = make_shared<BackgroundRenderData>(&_environment);
37393747 auto backgroundRenderPayload = make_shared<BackgroundRenderData::Payload>(backgroundRenderData);
37403748 BackgroundRenderData::_item = _main3DScene->allocateID();
3741− pendingChanges.resetItem(WorldBoxRenderData::_item, backgroundRenderPayload);
3749+ pendingChanges.resetItem(BackgroundRenderData::_item, backgroundRenderPayload);
37423750 } else {
37433751
37443752 }
@@ -4080,7 +4088,7 @@ bool Application::nearbyEntitiesAreReadyForPhysics() { · 335 unmodified lines
40804088 });
40814089
40824090 foreach (EntityItemPointer entity, entities) {
4083− if (!entity->isReadyToComputeShape()) {
4091+ if (entity->shouldBePhysical() && !entity->isReadyToComputeShape()) {
40844092 static QString repeatedMessage =
40854093 LogHandler::getInstance().addRepeatedMessageRegex("Physics disabled until entity loads: .*");
40864094 qCDebug(interfaceapp) << "Physics disabled until entity loads: " << entity->getID() << entity->getName();
@@ -4380,7 +4388,7 @@ bool Application::askToSetAvatarUrl(const QString& url) { · 293 unmodified lines
43804388 bool Application::askToLoadScript(const QString& scriptFilenameOrURL) {
43814389 QMessageBox::StandardButton reply;
43824390 QString message = "Would you like to run this script:\n" + scriptFilenameOrURL;
4383− reply = QMessageBox::question(getWindow(), "Run Script", message, QMessageBox::Yes|QMessageBox::No);
4391+ reply = OffscreenUi::question(getWindow(), "Run Script", message, QMessageBox::Yes | QMessageBox::No);
43844392
43854393 if (reply == QMessageBox::Yes) {
43864394 qCDebug(interfaceapp) << "Chose to run the script: " << scriptFilenameOrURL;
@@ -4393,7 +4401,7 @@ bool Application::askToLoadScript(const QString& scriptFilenameOrURL) { · 6 unmodified lines
43934401
43944402 bool Application::askToUploadAsset(const QString& filename) {
43954403 if (!DependencyManager::get<NodeList>()->getThisNodeCanRez()) {
4396− QMessageBox::warning(_window, "Failed Upload",
4404+ OffscreenUi::warning(_window, "Failed Upload",
43974405 QString("You don't have upload rights on that domain.\n\n"));
43984406 return false;
43994407 }
@@ -4437,7 +4445,7 @@ bool Application::askToUploadAsset(const QString& filename) { · 37 unmodified lines
44374445 }
44384446
44394447 // display a message box with the error
4440− QMessageBox::warning(_window, "Failed Upload", QString("Failed to upload %1.\n\n").arg(filename));
4448+ OffscreenUi::warning(_window, "Failed Upload", QString("Failed to upload %1.\n\n").arg(filename));
44414449 return false;
44424450 }
44434451
@@ -4464,6 +4472,99 @@ void Application::modelUploadFinished(AssetUpload* upload, const QString& hash) · 20 unmodified lines
44644472 }
44654473 }
44664474
4475+bool Application::askToWearAvatarAttachmentUrl(const QString& url) {
4476+
4477+ QNetworkAccessManager& networkAccessManager = NetworkAccessManager::getInstance();
4478+ QNetworkRequest networkRequest = QNetworkRequest(url);
4479+ networkRequest.setHeader(QNetworkRequest::UserAgentHeader, HIGH_FIDELITY_USER_AGENT);
4480+ QNetworkReply* reply = networkAccessManager.get(networkRequest);
4481+ int requestNumber = ++_avatarAttachmentRequest;
4482+ connect(reply, &QNetworkReply::finished, [this, reply, url, requestNumber]() {
4483+
4484+ if (requestNumber != _avatarAttachmentRequest) {
4485+ // this request has been superseded by another more recent request
4486+ reply->deleteLater();
4487+ return;
4488+ }
4489+
4490+ QNetworkReply::NetworkError networkError = reply->error();
4491+ if (networkError == QNetworkReply::NoError) {
4492+ // download success
4493+ QByteArray contents = reply->readAll();
4494+
4495+ QJsonParseError jsonError;
4496+ auto doc = QJsonDocument::fromJson(contents, &jsonError);
4497+ if (jsonError.error == QJsonParseError::NoError) {
4498+
4499+ auto jsonObject = doc.object();
4500+
4501+ // retrieve optional name field from JSON
4502+ QString name = tr("Unnamed Attachment");
4503+ auto nameValue = jsonObject.value("name");
4504+ if (nameValue.isString()) {
4505+ name = nameValue.toString();
4506+ }
4507+
4508+ // display confirmation dialog
4509+ if (displayAvatarAttachmentConfirmationDialog(name)) {
4510+
4511+ // add attachment to avatar
4512+ auto myAvatar = getMyAvatar();
4513+ assert(myAvatar);
4514+ auto attachmentDataVec = myAvatar->getAttachmentData();
4515+ AttachmentData attachmentData;
4516+ attachmentData.fromJson(jsonObject);
4517+ attachmentDataVec.push_back(attachmentData);
4518+ myAvatar->setAttachmentData(attachmentDataVec);
4519+
4520+ } else {
4521+ qCDebug(interfaceapp) << "User declined to wear the avatar attachment: " << url;
4522+ }
4523+
4524+ } else {
4525+ // json parse error
4526+ auto avatarAttachmentParseErrorString = tr("Error parsing attachment JSON from url: \"%1\"");
4527+ displayAvatarAttachmentWarning(avatarAttachmentParseErrorString.arg(url));
4528+ }
4529+ } else {
4530+ // download failure
4531+ auto avatarAttachmentDownloadErrorString = tr("Error downloading attachment JSON from url: \"%1\"");
4532+ displayAvatarAttachmentWarning(avatarAttachmentDownloadErrorString.arg(url));
4533+ }
4534+ reply->deleteLater();
4535+ });
4536+ return true;
4537+}
4538+
4539+void Application::displayAvatarAttachmentWarning(const QString& message) const {
4540+ auto avatarAttachmentWarningTitle = tr("Avatar Attachment Failure");
4541+ QMessageBox msgBox;
4542+ msgBox.setIcon(QMessageBox::Warning);
4543+ msgBox.setWindowTitle(avatarAttachmentWarningTitle);
4544+ msgBox.setText(message);
4545+ msgBox.exec();
4546+ msgBox.addButton(QMessageBox::Ok);
4547+ msgBox.exec();
4548+}
4549+
4550+bool Application::displayAvatarAttachmentConfirmationDialog(const QString& name) const {
4551+ auto avatarAttachmentConfirmationTitle = tr("Avatar Attachment Confirmation");
4552+ auto avatarAttachmentConfirmationMessage = tr("Would you like to wear '%1' on your avatar?");
4553+ QMessageBox msgBox;
4554+ msgBox.setIcon(QMessageBox::Question);
4555+ msgBox.setWindowTitle(avatarAttachmentConfirmationTitle);
4556+ QPushButton* button = msgBox.addButton(tr("Yes"), QMessageBox::ActionRole);
4557+ QString message = avatarAttachmentConfirmationMessage.arg(name);
4558+ msgBox.setText(message);
4559+ msgBox.addButton(QMessageBox::Cancel);
4560+ msgBox.exec();
4561+ if (msgBox.clickedButton() == button) {
4562+ return true;
4563+ } else {
4564+ return false;
4565+ }
4566+}
4567+
44674568 ScriptEngine* Application::loadScript(const QString& scriptFilename, bool isUserLoaded,
44684569 bool loadScriptFromEditor, bool activateMainWindow, bool reload) {
44694570
@@ -4535,7 +4636,7 @@ void Application::handleScriptEngineLoaded(const QString& scriptFilename) { · 65 unmodified lines
45354636 // FIXME - change to new version of ScriptCache loading notification
45364637 void Application::handleScriptLoadError(const QString& scriptFilename) {
45374638 qCDebug(interfaceapp) << "Application::loadScript(), script failed to load...";
4538− QMessageBox::warning(getWindow(), "Error Loading Script", scriptFilename + " failed to load.");
4639+ OffscreenUi::warning(getWindow(), "Error Loading Script", scriptFilename + " failed to load.");
45394640 }
45404641
45414642 QStringList Application::getRunningScripts() {
@@ -4991,7 +5092,7 @@ void Application::updateDisplayMode() { · 449 unmodified lines
49915092 foreach(auto displayPlugin, displayPlugins) {
49925093 addDisplayPluginToMenu(displayPlugin, first);
49935094 // This must be a queued connection to avoid a deadlock
4994− QObject::connect(displayPlugin.get(), &DisplayPlugin::requestRender,
5095+ QObject::connect(displayPlugin.get(), &DisplayPlugin::requestRender,
49955096 this, &Application::paintGL, Qt::QueuedConnection);
49965097
49975098 QObject::connect(displayPlugin.get(), &DisplayPlugin::recommendedFramebufferSizeChanged, [this](const QSize & size) {