History

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

SamGondelman committed 9 years ago

Commit 489e08a2 parents 8b1c24e 608958764 files · +1173 −759Browse files

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

Unified · Split

interface/src/Application.cpp+157−97
@@ -231,6 +231,7 @@ static const QString FBX_EXTENSION = ".fbx"; · 230 unmodified lines
231231 static const QString OBJ_EXTENSION = ".obj";
232232 static const QString AVA_JSON_EXTENSION = ".ava.json";
233233 static const QString WEB_VIEW_TAG = "noDownload=true";
234+static const QString ZIP_EXTENSION = ".zip";
234235
235236 static const float MIRROR_FULLSCREEN_DISTANCE = 0.389f;
236237
@@ -262,7 +263,8 @@ const QHash<QString, Application::AcceptURLMethod> Application::_acceptedExtensi · 25 unmodified lines
262263 { AVA_JSON_EXTENSION, &Application::askToWearAvatarAttachmentUrl },
263264 { JSON_EXTENSION, &Application::importJSONFromURL },
264265 { JS_EXTENSION, &Application::askToLoadScript },
265− { FST_EXTENSION, &Application::askToSetAvatarUrl }
266+ { FST_EXTENSION, &Application::askToSetAvatarUrl },
267+ { ZIP_EXTENSION, &Application::importFromZIP }
266268 };
267269
268270 class DeadlockWatchdogThread : public QThread {
@@ -2262,7 +2264,7 @@ void Application::paintGL() { · 1993 unmodified lines
22622264 QMutexLocker viewLocker(&_viewMutex);
22632265 _viewFrustum.calculate();
22642266 }
2265− renderArgs = RenderArgs(_gpuContext, getEntities(), lodManager->getOctreeSizeScale(),
2267+ renderArgs = RenderArgs(_gpuContext, lodManager->getOctreeSizeScale(),
22662268 lodManager->getBoundaryLevelAdjust(), RenderArgs::DEFAULT_RENDER_MODE,
22672269 RenderArgs::MONO, RenderArgs::RENDER_DEBUG_NONE);
22682270 {
@@ -2792,6 +2794,20 @@ bool Application::importSVOFromURL(const QString& urlString) { · 523 unmodified lines
27922794 return true;
27932795 }
27942796
2797+void Application::onPresent(quint32 frameCount) {
2798+ if (shouldPaint()) {
2799+ postEvent(this, new QEvent(static_cast<QEvent::Type>(Idle)), Qt::HighEventPriority);
2800+ postEvent(this, new QEvent(static_cast<QEvent::Type>(Paint)), Qt::HighEventPriority);
2801+ }
2802+}
2803+
2804+bool Application::importFromZIP(const QString& filePath) {
2805+ qDebug() << "A zip file has been dropped in: " << filePath;
2806+ QUrl empty;
2807+ qApp->getFileDownloadInterface()->runUnzip(filePath, empty, true, true);
2808+ return true;
2809+}
2810+
27952811 bool _renderRequested { false };
27962812
27972813 bool Application::event(QEvent* event) {
@@ -2808,23 +2824,9 @@ bool Application::event(QEvent* event) { · 10 unmodified lines
28082824 // Explicit idle keeps the idle running at a lower interval, but without any rendering
28092825 // see (windowMinimizedChanged)
28102826 case Event::Idle:
2811− {
2812− float nsecsElapsed = (float)_lastTimeUpdated.nsecsElapsed();
2813− _lastTimeUpdated.start();
2814− idle(nsecsElapsed);
2815− }
2816− return true;
2817−
2818− case Event::Present:
2819− if (!_renderRequested) {
2820− float nsecsElapsed = (float)_lastTimeUpdated.nsecsElapsed();
2821− if (shouldPaint(nsecsElapsed)) {
2822− _renderRequested = true;
2823− _lastTimeUpdated.start();
2824− idle(nsecsElapsed);
2825− postEvent(this, new QEvent(static_cast<QEvent::Type>(Paint)), Qt::HighEventPriority);
2826− }
2827− }
2827+ idle();
2828+ // Clear the event queue of pending idle calls
2829+ removePostedEvents(this, Idle);
28282830 return true;
28292831
28302832 case Event::Paint:
@@ -2832,9 +2834,8 @@ bool Application::event(QEvent* event) { · 1 unmodified line
28322834 // or AvatarInputs will mysteriously move to the bottom-right
28332835 AvatarInputs::getInstance()->update();
28342836 paintGL();
2835− // wait for the next present event before starting idle / paint again
2836− removePostedEvents(this, Present);
2837− _renderRequested = false;
2837+ // Clear the event queue of pending paint calls
2838+ removePostedEvents(this, Paint);
28382839 return true;
28392840
28402841 default:
@@ -3653,7 +3654,7 @@ bool Application::acceptSnapshot(const QString& urlString) { · 812 unmodified lines
36533654
36543655 static uint32_t _renderedFrameIndex { INVALID_FRAME };
36553656
3656−bool Application::shouldPaint(float nsecsElapsed) {
3657+bool Application::shouldPaint() {
36573658 if (_aboutToQuit) {
36583659 return false;
36593660 }
@@ -3673,11 +3674,9 @@ bool Application::shouldPaint(float nsecsElapsed) { · 13 unmodified lines
36733674 (float)paintDelaySamples / paintDelayUsecs << "us";
36743675 }
36753676 #endif
3676−
3677− float msecondsSinceLastUpdate = nsecsElapsed / NSECS_PER_USEC / USECS_PER_MSEC;
3678−
3677+
36793678 // Throttle if requested
3680− if (displayPlugin->isThrottled() && (msecondsSinceLastUpdate < THROTTLED_SIM_FRAME_PERIOD_MS)) {
3679+ if (displayPlugin->isThrottled() && (_lastTimeUpdated.elapsed() < THROTTLED_SIM_FRAME_PERIOD_MS)) {
36813680 return false;
36823681 }
36833682
@@ -3894,7 +3893,7 @@ void setupCpuMonitorThread() { · 210 unmodified lines
38943893 #endif
38953894
38963895
3897−void Application::idle(float nsecsElapsed) {
3896+void Application::idle() {
38983897 PerformanceTimer perfTimer("idle");
38993898
39003899 // Update the deadlock watchdog
@@ -3951,7 +3950,8 @@ void Application::idle(float nsecsElapsed) { · 50 unmodified lines
39513950 steamClient->runCallbacks();
39523951 }
39533952
3954− float secondsSinceLastUpdate = nsecsElapsed / NSECS_PER_MSEC / MSECS_PER_SECOND;
3953+ float secondsSinceLastUpdate = (float)_lastTimeUpdated.nsecsElapsed() / NSECS_PER_MSEC / MSECS_PER_SECOND;
3954+ _lastTimeUpdated.start();
39553955
39563956 // If the offscreen Ui has something active that is NOT the root, then assume it has keyboard focus.
39573957 if (_keyboardDeviceHasFocus && offscreenUi && offscreenUi->getWindow()->activeFocusItem() != offscreenUi->getRootItem()) {
@@ -4185,6 +4185,7 @@ void Application::loadSettings() { · 227 unmodified lines
41854185 //DependencyManager::get<LODManager>()->setAutomaticLODAdjust(false);
41864186
41874187 Menu::getInstance()->loadSettings();
4188+
41884189 // If there is a preferred plugin, we probably messed it up with the menu settings, so fix it.
41894190 auto pluginManager = PluginManager::getInstance();
41904191 auto plugins = pluginManager->getPreferredDisplayPlugins();
@@ -4198,24 +4199,44 @@ void Application::loadSettings() { · 7 unmodified lines
41984199 break;
41994200 }
42004201 }
4201− } else {
4202+ }
4203+
4204+ Setting::Handle<bool> firstRun { Settings::firstRun, true };
4205+ bool isFirstPerson = false;
4206+ if (firstRun.get()) {
42024207 // If this is our first run, and no preferred devices were set, default to
42034208 // an HMD device if available.
4204− Setting::Handle<bool> firstRun { Settings::firstRun, true };
4205− if (firstRun.get()) {
4206− auto displayPlugins = pluginManager->getDisplayPlugins();
4207− for (auto& plugin : displayPlugins) {
4208− if (plugin->isHmd()) {
4209− if (auto action = menu->getActionForOption(plugin->getName())) {
4210− action->setChecked(true);
4211− action->trigger();
4212− break;
4213− }
4209+ auto displayPlugins = pluginManager->getDisplayPlugins();
4210+ for (auto& plugin : displayPlugins) {
4211+ if (plugin->isHmd()) {
4212+ if (auto action = menu->getActionForOption(plugin->getName())) {
4213+ action->setChecked(true);
4214+ action->trigger();
4215+ break;
42144216 }
42154217 }
42164218 }
4219+
4220+ isFirstPerson = (qApp->isHMDMode());
4221+ } else {
4222+ // if this is not the first run, the camera will be initialized differently depending on user settings
4223+
4224+ if (qApp->isHMDMode()) {
4225+ // if the HMD is active, use first-person camera, unless the appropriate setting is checked
4226+ isFirstPerson = menu->isOptionChecked(MenuOption::FirstPersonHMD);
4227+ } else {
4228+ // if HMD is not active, only use first person if the menu option is checked
4229+ isFirstPerson = menu->isOptionChecked(MenuOption::FirstPerson);
4230+ }
42174231 }
42184232
4233+ // finish initializing the camera, based on everything we checked above. Third person camera will be used if no settings
4234+ // dictated that we should be in first person
4235+ Menu::getInstance()->setIsOptionChecked(MenuOption::FirstPerson, isFirstPerson);
4236+ Menu::getInstance()->setIsOptionChecked(MenuOption::ThirdPerson, !isFirstPerson);
4237+ _myCamera.setMode((isFirstPerson) ? CAMERA_MODE_FIRST_PERSON : CAMERA_MODE_THIRD_PERSON);
4238+ cameraMenuChanged();
4239+
42194240 auto inputs = pluginManager->getInputPlugins();
42204241 for (auto plugin : inputs) {
42214242 if (!plugin->isActive()) {
@@ -4264,7 +4285,6 @@ void Application::init() { · 42 unmodified lines
42644285 DependencyManager::get<DeferredLightingEffect>()->init();
42654286
42664287 DependencyManager::get<AvatarManager>()->init();
4267− _myCamera.setMode(CAMERA_MODE_FIRST_PERSON);
42684288
42694289 _timerStart.start();
42704290 _lastTimeUpdated.start();
@@ -4416,10 +4436,9 @@ void Application::updateMyAvatarLookAtPosition() { · 145 unmodified lines
44164436 }
44174437 } else {
44184438 // I am not looking at anyone else, so just look forward
4419− auto headPose = myAvatar->getHeadControllerPoseInSensorFrame();
4439+ auto headPose = myAvatar->getControllerPoseInWorldFrame(controller::Action::HEAD);
44204440 if (headPose.isValid()) {
4421− glm::mat4 worldHeadMat = myAvatar->getSensorToWorldMatrix() * headPose.getMatrix();
4422− lookAtSpot = transformPoint(worldHeadMat, glm::vec3(0.0f, 0.0f, TREE_SCALE));
4441+ lookAtSpot = transformPoint(headPose.getMatrix(), glm::vec3(0.0f, 0.0f, TREE_SCALE));
44234442 } else {
44244443 lookAtSpot = myAvatar->getHead()->getEyePosition() +
44254444 (myAvatar->getHead()->getFinalOrientationInWorldFrame() * glm::vec3(0.0f, 0.0f, -TREE_SCALE));
@@ -4833,52 +4852,76 @@ void Application::update(float deltaTime) { · 407 unmodified lines
48334852 myAvatar->setDriveKey(MyAvatar::ZOOM, userInputMapper->getActionState(controller::Action::TRANSLATE_CAMERA_Z));
48344853 }
48354854
4836− controller::Pose leftHandPose = userInputMapper->getPoseState(controller::Action::LEFT_HAND);
4837− controller::Pose rightHandPose = userInputMapper->getPoseState(controller::Action::RIGHT_HAND);
4838− auto myAvatarMatrix = createMatFromQuatAndPos(myAvatar->getOrientation(), myAvatar->getPosition());
4839− auto worldToSensorMatrix = glm::inverse(myAvatar->getSensorToWorldMatrix());
4840− auto avatarToSensorMatrix = worldToSensorMatrix * myAvatarMatrix;
4841− myAvatar->setHandControllerPosesInSensorFrame(leftHandPose.transform(avatarToSensorMatrix), rightHandPose.transform(avatarToSensorMatrix));
4855+ static const std::vector<controller::Action> avatarControllerActions = {
4856+ controller::Action::LEFT_HAND,
4857+ controller::Action::RIGHT_HAND,
4858+ controller::Action::LEFT_FOOT,
4859+ controller::Action::RIGHT_FOOT,
4860+ controller::Action::HIPS,
4861+ controller::Action::SPINE2,
4862+ controller::Action::HEAD,
4863+ controller::Action::LEFT_HAND_THUMB1,
4864+ controller::Action::LEFT_HAND_THUMB2,
4865+ controller::Action::LEFT_HAND_THUMB3,
4866+ controller::Action::LEFT_HAND_THUMB4,
4867+ controller::Action::LEFT_HAND_INDEX1,
4868+ controller::Action::LEFT_HAND_INDEX2,
4869+ controller::Action::LEFT_HAND_INDEX3,
4870+ controller::Action::LEFT_HAND_INDEX4,
4871+ controller::Action::LEFT_HAND_MIDDLE1,
4872+ controller::Action::LEFT_HAND_MIDDLE2,
4873+ controller::Action::LEFT_HAND_MIDDLE3,
4874+ controller::Action::LEFT_HAND_MIDDLE4,
4875+ controller::Action::LEFT_HAND_RING1,
4876+ controller::Action::LEFT_HAND_RING2,
4877+ controller::Action::LEFT_HAND_RING3,
4878+ controller::Action::LEFT_HAND_RING4,
4879+ controller::Action::LEFT_HAND_PINKY1,
4880+ controller::Action::LEFT_HAND_PINKY2,
4881+ controller::Action::LEFT_HAND_PINKY3,
4882+ controller::Action::LEFT_HAND_PINKY4,
4883+ controller::Action::RIGHT_HAND_THUMB1,
4884+ controller::Action::RIGHT_HAND_THUMB2,
4885+ controller::Action::RIGHT_HAND_THUMB3,
4886+ controller::Action::RIGHT_HAND_THUMB4,
4887+ controller::Action::RIGHT_HAND_INDEX1,
4888+ controller::Action::RIGHT_HAND_INDEX2,
4889+ controller::Action::RIGHT_HAND_INDEX3,
4890+ controller::Action::RIGHT_HAND_INDEX4,
4891+ controller::Action::RIGHT_HAND_MIDDLE1,
4892+ controller::Action::RIGHT_HAND_MIDDLE2,
4893+ controller::Action::RIGHT_HAND_MIDDLE3,
4894+ controller::Action::RIGHT_HAND_MIDDLE4,
4895+ controller::Action::RIGHT_HAND_RING1,
4896+ controller::Action::RIGHT_HAND_RING2,
4897+ controller::Action::RIGHT_HAND_RING3,
4898+ controller::Action::RIGHT_HAND_RING4,
4899+ controller::Action::RIGHT_HAND_PINKY1,
4900+ controller::Action::RIGHT_HAND_PINKY2,
4901+ controller::Action::RIGHT_HAND_PINKY3,
4902+ controller::Action::RIGHT_HAND_PINKY4,
4903+ controller::Action::LEFT_ARM,
4904+ controller::Action::RIGHT_ARM,
4905+ controller::Action::LEFT_SHOULDER,
4906+ controller::Action::RIGHT_SHOULDER,
4907+ controller::Action::LEFT_FORE_ARM,
4908+ controller::Action::RIGHT_FORE_ARM,
4909+ controller::Action::LEFT_LEG,
4910+ controller::Action::RIGHT_LEG,
4911+ controller::Action::LEFT_UP_LEG,
4912+ controller::Action::RIGHT_UP_LEG,
4913+ controller::Action::LEFT_TOE_BASE,
4914+ controller::Action::RIGHT_TOE_BASE
4915+ };
48424916
4843− // If have previously done finger poses or there are new valid finger poses, update finger pose values. This so that if
4844− // fingers are not being controlled, finger joints are not updated in MySkeletonModel.
4845− // Assumption: Finger poses are either all present and valid or not present at all; thus can test just one joint.
4846− MyAvatar::FingerPosesMap leftHandFingerPoses;
4847− if (myAvatar->getLeftHandFingerControllerPosesInSensorFrame().size() > 0
4848− || userInputMapper->getPoseState(controller::Action::LEFT_HAND_THUMB1).isValid()) {
4849− for (int i = (int)controller::Action::LEFT_HAND_THUMB1; i <= (int)controller::Action::LEFT_HAND_PINKY4; i++) {
4850− leftHandFingerPoses[i] = {
4851− userInputMapper->getPoseState((controller::Action)i).transform(avatarToSensorMatrix),
4852− userInputMapper->getActionName((controller::Action)i)
4853− };
4854− }
4855− }
4856− MyAvatar::FingerPosesMap rightHandFingerPoses;
4857− if (myAvatar->getRightHandFingerControllerPosesInSensorFrame().size() > 0
4858− || userInputMapper->getPoseState(controller::Action::RIGHT_HAND_THUMB1).isValid()) {
4859− for (int i = (int)controller::Action::RIGHT_HAND_THUMB1; i <= (int)controller::Action::RIGHT_HAND_PINKY4; i++) {
4860− rightHandFingerPoses[i] = {
4861− userInputMapper->getPoseState((controller::Action)i).transform(avatarToSensorMatrix),
4862− userInputMapper->getActionName((controller::Action)i)
4863− };
4864− }
4917+ // copy controller poses from userInputMapper to myAvatar.
4918+ glm::mat4 myAvatarMatrix = createMatFromQuatAndPos(myAvatar->getOrientation(), myAvatar->getPosition());
4919+ glm::mat4 worldToSensorMatrix = glm::inverse(myAvatar->getSensorToWorldMatrix());
4920+ glm::mat4 avatarToSensorMatrix = worldToSensorMatrix * myAvatarMatrix;
4921+ for (auto& action : avatarControllerActions) {
4922+ controller::Pose pose = userInputMapper->getPoseState(action);
4923+ myAvatar->setControllerPoseInSensorFrame(action, pose.transform(avatarToSensorMatrix));
48654924 }
4866− myAvatar->setFingerControllerPosesInSensorFrame(leftHandFingerPoses, rightHandFingerPoses);
4867−
4868− controller::Pose leftFootPose = userInputMapper->getPoseState(controller::Action::LEFT_FOOT);
4869− controller::Pose rightFootPose = userInputMapper->getPoseState(controller::Action::RIGHT_FOOT);
4870− myAvatar->setFootControllerPosesInSensorFrame(leftFootPose.transform(avatarToSensorMatrix), rightFootPose.transform(avatarToSensorMatrix));
4871−
4872− controller::Pose hipsPose = userInputMapper->getPoseState(controller::Action::HIPS);
4873− controller::Pose spine2Pose = userInputMapper->getPoseState(controller::Action::SPINE2);
4874− myAvatar->setSpineControllerPosesInSensorFrame(hipsPose.transform(avatarToSensorMatrix), spine2Pose.transform(avatarToSensorMatrix));
4875−
4876− controller::Pose headPose = userInputMapper->getPoseState(controller::Action::HEAD);
4877− myAvatar->setHeadControllerPoseInSensorFrame(headPose.transform(avatarToSensorMatrix));
4878−
4879− controller::Pose leftArmPose = userInputMapper->getPoseState(controller::Action::LEFT_ARM);
4880− controller::Pose rightArmPose = userInputMapper->getPoseState(controller::Action::RIGHT_ARM);
4881− myAvatar->setArmControllerPosesInSensorFrame(leftArmPose.transform(avatarToSensorMatrix), rightArmPose.transform(avatarToSensorMatrix));
48824925
48834926 updateThreads(deltaTime); // If running non-threaded, then give the threads some time to process...
48844927 updateDialogs(deltaTime); // update various stats dialogs if present
@@ -6242,7 +6285,7 @@ void Application::addAssetToWorldFromURLRequestFinished() { · 1357 unmodified lines
62426285 if (tempFile.open(QIODevice::WriteOnly)) {
62436286 tempFile.write(request->getData());
62446287 addAssetToWorldInfoClear(filename); // Remove message from list; next one added will have a different key.
6245− qApp->getFileDownloadInterface()->runUnzip(downloadPath, url, true);
6288+ qApp->getFileDownloadInterface()->runUnzip(downloadPath, url, true, false);
62466289 } else {
62476290 QString errorInfo = "Couldn't open temporary file for download";
62486291 qWarning(interfaceapp) << errorInfo;
@@ -6272,12 +6315,18 @@ void Application::addAssetToWorldUnzipFailure(QString filePath) { · 23 unmodified lines
62726315 addAssetToWorldError(filename, "Couldn't unzip file " + filename + ".");
62736316 }
62746317
6275−void Application::addAssetToWorld(QString filePath) {
6318+void Application::addAssetToWorld(QString filePath, QString zipFile, bool isZip) {
62766319 // Automatically upload and add asset to world as an alternative manual process initiated by showAssetServerWidget().
6277−
6278− QString path = QUrl(filePath).toLocalFile();
6320+ QString mapping;
6321+ QString path = filePath;
62796322 QString filename = filenameFromPath(path);
6280− QString mapping = "/" + filename;
6323+ if (isZip) {
6324+ QString assetFolder = zipFile.section("/", -1);
6325+ assetFolder.remove(".zip");
6326+ mapping = "/" + assetFolder + "/" + filename;
6327+ } else {
6328+ mapping = "/" + filename;
6329+ }
62816330
62826331 // Test repeated because possibly different code paths.
62836332 if (!DependencyManager::get<NodeList>()->getThisNodeCanWriteAssets()) {
@@ -6358,7 +6407,13 @@ void Application::addAssetToWorldSetMapping(QString filePath, QString mapping, Q · 74 unmodified lines
63586407 qWarning(interfaceapp) << "Error downloading model: " + errorInfo;
63596408 addAssetToWorldError(filenameFromPath(filePath), errorInfo);
63606409 } else {
6361− addAssetToWorldAddEntity(filePath, mapping);
6410+ // to prevent files that aren't models from being loaded into world automatically
6411+ if (filePath.endsWith(".obj") || filePath.endsWith(".fbx")) {
6412+ addAssetToWorldAddEntity(filePath, mapping);
6413+ } else {
6414+ qCDebug(interfaceapp) << "Zipped contents are not supported entity files";
6415+ addAssetToWorldInfoDone(filenameFromPath(filePath));
6416+ }
63626417 }
63636418 request->deleteLater();
63646419 });
@@ -6648,15 +6703,18 @@ void Application::onAssetToWorldMessageBoxClosed() { · 283 unmodified lines
66486703 }
66496704
66506705
6651−void Application::handleUnzip(QString zipFile, QString unzipFile, bool autoAdd) {
6706+void Application::handleUnzip(QString zipFile, QStringList unzipFile, bool autoAdd, bool isZip) {
66526707 if (autoAdd) {
66536708 if (!unzipFile.isEmpty()) {
6654− addAssetToWorld(unzipFile);
6709+ for (int i = 0; i < unzipFile.length(); i++) {
6710+ qCDebug(interfaceapp) << "Preparing file for asset server: " << unzipFile.at(i);
6711+ addAssetToWorld(unzipFile.at(i), zipFile, isZip);
6712+ }
66556713 } else {
66566714 addAssetToWorldUnzipFailure(zipFile);
66576715 }
66586716 } else {
6659− showAssetServerWidget(unzipFile);
6717+ showAssetServerWidget(unzipFile.first());
66606718 }
66616719 }
66626720
@@ -7119,6 +7177,7 @@ void Application::updateDisplayMode() { · 456 unmodified lines
71197177
71207178 auto oldDisplayPlugin = _displayPlugin;
71217179 if (_displayPlugin) {
7180+ disconnect(_displayPluginPresentConnection);
71227181 _displayPlugin->deactivate();
71237182 }
71247183
@@ -7159,6 +7218,7 @@ void Application::updateDisplayMode() { · 34 unmodified lines
71597218 _offscreenContext->makeCurrent();
71607219 getApplicationCompositor().setDisplayPlugin(newDisplayPlugin);
71617220 _displayPlugin = newDisplayPlugin;
7221+ _displayPluginPresentConnection = connect(_displayPlugin.get(), &DisplayPlugin::presented, this, &Application::onPresent);
71627222 offscreenUi->getDesktop()->setProperty("repositionLocked", wasRepositionLocked);
71637223 }
71647224