Showing the changes to interface/src/Application.cpp (1 of 35 files). Show all
Unified · Split
| @@ -150,7 +150,6 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : · 149 unmodified lines | ||
| 150 | 150 | _viewFrustum(), |
| 151 | 151 | _lastQueriedViewFrustum(), |
| 152 | 152 | _lastQueriedTime(usecTimestampNow()), |
| 153 | − _audioScope(256, 200, true), | |
| 154 | 153 | _mirrorViewRect(QRect(MIRROR_VIEW_LEFT_PADDING, MIRROR_VIEW_TOP_PADDING, MIRROR_VIEW_WIDTH, MIRROR_VIEW_HEIGHT)), |
| 155 | 154 | _mouseX(0), |
| 156 | 155 | _mouseY(0), |
| @@ -161,7 +160,7 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : · 4 unmodified lines | ||
| 161 | 160 | _touchAvgY(0.0f), |
| 162 | 161 | _isTouchPressed(false), |
| 163 | 162 | _mousePressed(false), |
| 164 | − _audio(&_audioScope, STARTUP_JITTER_SAMPLES), | |
| 163 | + _audio(STARTUP_JITTER_SAMPLES), | |
| 165 | 164 | _enableProcessVoxelsThread(true), |
| 166 | 165 | _voxelProcessor(), |
| 167 | 166 | _voxelHideShowThread(&_voxels), |
| @@ -342,11 +341,15 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : · 174 unmodified lines | ||
| 342 | 341 | // clear the scripts, and set out script to our default scripts |
| 343 | 342 | clearScriptsBeforeRunning(); |
| 344 | 343 | loadScript("http://public.highfidelity.io/scripts/defaultScripts.js"); |
| 345 | − | |
| 344 | + | |
| 345 | + QMutexLocker locker(&_settingsMutex); | |
| 346 | 346 | _settings->setValue("firstRun",QVariant(false)); |
| 347 | 347 | } else { |
| 348 | 348 | // do this as late as possible so that all required subsystems are inialized |
| 349 | 349 | loadScripts(); |
| 350 | + | |
| 351 | + QMutexLocker locker(&_settingsMutex); | |
| 352 | + _previousScriptLocation = _settings->value("LastScriptLocation", QVariant("")).toString(); | |
| 350 | 353 | } |
| 351 | 354 | } |
| 352 | 355 | |
| @@ -356,16 +359,12 @@ Application::~Application() { · 3 unmodified lines | ||
| 356 | 359 | |
| 357 | 360 | // make sure we don't call the idle timer any more |
| 358 | 361 | delete idleTimer; |
| 359 | − | |
| 360 | − Menu::getInstance()->saveSettings(); | |
| 361 | − _rearMirrorTools->saveSettings(_settings); | |
| 362 | − | |
| 362 | + | |
| 363 | 363 | _sharedVoxelSystem.changeTree(new VoxelTree); |
| 364 | − if (_voxelImporter) { | |
| 365 | − _voxelImporter->saveSettings(_settings); | |
| 366 | − delete _voxelImporter; | |
| 367 | − } | |
| 368 | − _settings->sync(); | |
| 364 | + | |
| 365 | + saveSettings(); | |
| 366 | + | |
| 367 | + delete _voxelImporter; | |
| 369 | 368 | |
| 370 | 369 | // let the avatar mixer know we're out |
| 371 | 370 | MyAvatar::sendKillAvatar(); |
| @@ -399,35 +398,45 @@ Application::~Application() { · 27 unmodified lines | ||
| 399 | 398 | AccountManager::getInstance().destroy(); |
| 400 | 399 | } |
| 401 | 400 | |
| 401 | +void Application::saveSettings() { | |
| 402 | + Menu::getInstance()->saveSettings(); | |
| 403 | + _rearMirrorTools->saveSettings(_settings); | |
| 404 | + | |
| 405 | + if (_voxelImporter) { | |
| 406 | + _voxelImporter->saveSettings(_settings); | |
| 407 | + } | |
| 408 | + _settings->sync(); | |
| 409 | +} | |
| 410 | + | |
| 411 | + | |
| 402 | 412 | void Application::restoreSizeAndPosition() { |
| 403 | − QSettings* settings = new QSettings(this); | |
| 404 | 413 | QRect available = desktop()->availableGeometry(); |
| 405 | 414 | |
| 406 | − settings->beginGroup("Window"); | |
| 415 | + QMutexLocker locker(&_settingsMutex); | |
| 416 | + _settings->beginGroup("Window"); | |
| 407 | 417 | |
| 408 | − int x = (int)loadSetting(settings, "x", 0); | |
| 409 | − int y = (int)loadSetting(settings, "y", 0); | |
| 418 | + int x = (int)loadSetting(_settings, "x", 0); | |
| 419 | + int y = (int)loadSetting(_settings, "y", 0); | |
| 410 | 420 | _window->move(x, y); |
| 411 | 421 | |
| 412 | − int width = (int)loadSetting(settings, "width", available.width()); | |
| 413 | − int height = (int)loadSetting(settings, "height", available.height()); | |
| 422 | + int width = (int)loadSetting(_settings, "width", available.width()); | |
| 423 | + int height = (int)loadSetting(_settings, "height", available.height()); | |
| 414 | 424 | _window->resize(width, height); |
| 415 | 425 | |
| 416 | − settings->endGroup(); | |
| 426 | + _settings->endGroup(); | |
| 417 | 427 | } |
| 418 | 428 | |
| 419 | 429 | void Application::storeSizeAndPosition() { |
| 420 | − QSettings* settings = new QSettings(this); | |
| 421 | − | |
| 422 | − settings->beginGroup("Window"); | |
| 430 | + QMutexLocker locker(&_settingsMutex); | |
| 431 | + _settings->beginGroup("Window"); | |
| 423 | 432 | |
| 424 | − settings->setValue("width", _window->rect().width()); | |
| 425 | − settings->setValue("height", _window->rect().height()); | |
| 433 | + _settings->setValue("width", _window->rect().width()); | |
| 434 | + _settings->setValue("height", _window->rect().height()); | |
| 426 | 435 | |
| 427 | − settings->setValue("x", _window->pos().x()); | |
| 428 | − settings->setValue("y", _window->pos().y()); | |
| 436 | + _settings->setValue("x", _window->pos().x()); | |
| 437 | + _settings->setValue("y", _window->pos().y()); | |
| 429 | 438 | |
| 430 | − settings->endGroup(); | |
| 439 | + _settings->endGroup(); | |
| 431 | 440 | } |
| 432 | 441 | |
| 433 | 442 | void Application::initializeGL() { |
| @@ -757,9 +766,6 @@ void Application::keyPressEvent(QKeyEvent* event) { · 323 unmodified lines | ||
| 757 | 766 | case Qt::Key_Period: |
| 758 | 767 | Menu::getInstance()->handleViewFrustumOffsetKeyModifier(event->key()); |
| 759 | 768 | break; |
| 760 | − case Qt::Key_Apostrophe: | |
| 761 | − _audioScope.inputPaused = !_audioScope.inputPaused; | |
| 762 | − break; | |
| 763 | 769 | case Qt::Key_L: |
| 764 | 770 | if (isShifted) { |
| 765 | 771 | Menu::getInstance()->triggerOption(MenuOption::LodTools); |
| @@ -1358,6 +1364,12 @@ glm::vec3 Application::getMouseVoxelWorldCoordinates(const VoxelDetail& mouseVox · 592 unmodified lines | ||
| 1358 | 1364 | (mouseVoxel.z + mouseVoxel.s / 2.f) * TREE_SCALE); |
| 1359 | 1365 | } |
| 1360 | 1366 | |
| 1367 | +FaceTracker* Application::getActiveFaceTracker() { | |
| 1368 | + return _faceshift.isActive() ? static_cast<FaceTracker*>(&_faceshift) : | |
| 1369 | + (_faceplus.isActive() ? static_cast<FaceTracker*>(&_faceplus) : | |
| 1370 | + (_visage.isActive() ? static_cast<FaceTracker*>(&_visage) : NULL)); | |
| 1371 | +} | |
| 1372 | + | |
| 1361 | 1373 | struct SendVoxelsOperationArgs { |
| 1362 | 1374 | const unsigned char* newBaseOctCode; |
| 1363 | 1375 | }; |
| @@ -1577,8 +1589,9 @@ void Application::init() { · 213 unmodified lines | ||
| 1577 | 1589 | } |
| 1578 | 1590 | qDebug("Loaded settings"); |
| 1579 | 1591 | |
| 1580 | − // initialize Visage and Faceshift after loading the menu settings | |
| 1592 | + // initialize our face trackers after loading the menu settings | |
| 1581 | 1593 | _faceshift.init(); |
| 1594 | + _faceplus.init(); | |
| 1582 | 1595 | _visage.init(); |
| 1583 | 1596 | |
| 1584 | 1597 | // fire off an immediate domain-server check in now that settings are loaded |
| @@ -1742,19 +1755,11 @@ void Application::updateMyAvatarLookAtPosition() { · 157 unmodified lines | ||
| 1742 | 1755 | glm::distance(_mouseRayOrigin, _myAvatar->getHead()->calculateAverageEyePosition())); |
| 1743 | 1756 | lookAtSpot = _mouseRayOrigin + _mouseRayDirection * qMax(minEyeDistance, distance); |
| 1744 | 1757 | } |
| 1745 | − bool trackerActive = false; | |
| 1746 | − float eyePitch, eyeYaw; | |
| 1747 | − if (_faceshift.isActive()) { | |
| 1748 | − eyePitch = _faceshift.getEstimatedEyePitch(); | |
| 1749 | − eyeYaw = _faceshift.getEstimatedEyeYaw(); | |
| 1750 | − trackerActive = true; | |
| 1751 | − | |
| 1752 | − } else if (_visage.isActive()) { | |
| 1753 | − eyePitch = _visage.getEstimatedEyePitch(); | |
| 1754 | − eyeYaw = _visage.getEstimatedEyeYaw(); | |
| 1755 | − trackerActive = true; | |
| 1756 | − } | |
| 1757 | − if (trackerActive) { | |
| 1758 | + FaceTracker* tracker = getActiveFaceTracker(); | |
| 1759 | + if (tracker) { | |
| 1760 | + float eyePitch = tracker->getEstimatedEyePitch(); | |
| 1761 | + float eyeYaw = tracker->getEstimatedEyeYaw(); | |
| 1762 | + | |
| 1758 | 1763 | // deflect using Faceshift gaze data |
| 1759 | 1764 | glm::vec3 origin = _myAvatar->getHead()->calculateAverageEyePosition(); |
| 1760 | 1765 | float pitchSign = (_myCamera.getMode() == CAMERA_MODE_MIRROR) ? -1.0f : 1.0f; |
| @@ -1840,15 +1845,15 @@ void Application::updateCamera(float deltaTime) { · 79 unmodified lines | ||
| 1840 | 1845 | bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings); |
| 1841 | 1846 | PerformanceWarning warn(showWarnings, "Application::updateCamera()"); |
| 1842 | 1847 | |
| 1843 | − if (!OculusManager::isConnected() && !TV3DManager::isConnected()) { | |
| 1844 | − if (Menu::getInstance()->isOptionChecked(MenuOption::OffAxisProjection)) { | |
| 1845 | − float xSign = _myCamera.getMode() == CAMERA_MODE_MIRROR ? 1.0f : -1.0f; | |
| 1846 | − if (_faceshift.isActive()) { | |
| 1847 | − const float EYE_OFFSET_SCALE = 0.025f; | |
| 1848 | − glm::vec3 position = _faceshift.getHeadTranslation() * EYE_OFFSET_SCALE; | |
| 1849 | − _myCamera.setEyeOffsetPosition(glm::vec3(position.x * xSign, position.y, -position.z)); | |
| 1850 | − updateProjectionMatrix(); | |
| 1851 | − } | |
| 1848 | + if (!OculusManager::isConnected() && !TV3DManager::isConnected() && | |
| 1849 | + Menu::getInstance()->isOptionChecked(MenuOption::OffAxisProjection)) { | |
| 1850 | + FaceTracker* tracker = getActiveFaceTracker(); | |
| 1851 | + if (tracker) { | |
| 1852 | + const float EYE_OFFSET_SCALE = 0.025f; | |
| 1853 | + glm::vec3 position = tracker->getHeadTranslation() * EYE_OFFSET_SCALE; | |
| 1854 | + float xSign = (_myCamera.getMode() == CAMERA_MODE_MIRROR) ? 1.0f : -1.0f; | |
| 1855 | + _myCamera.setEyeOffsetPosition(glm::vec3(position.x * xSign, position.y, -position.z)); | |
| 1856 | + updateProjectionMatrix(); | |
| 1852 | 1857 | } |
| 1853 | 1858 | } |
| 1854 | 1859 | } |
| @@ -2522,15 +2527,6 @@ void Application::displayOverlay() { · 667 unmodified lines | ||
| 2522 | 2527 | } |
| 2523 | 2528 | } |
| 2524 | 2529 | |
| 2525 | − // Audio Scope | |
| 2526 | − const int AUDIO_SCOPE_Y_OFFSET = 135; | |
| 2527 | − if (Menu::getInstance()->isOptionChecked(MenuOption::Stats)) { | |
| 2528 | − if (Menu::getInstance()->isOptionChecked(MenuOption::Oscilloscope)) { | |
| 2529 | − int oscilloscopeTop = _glWidget->height() - AUDIO_SCOPE_Y_OFFSET; | |
| 2530 | − _audioScope.render(MIRROR_VIEW_LEFT_PADDING, oscilloscopeTop); | |
| 2531 | − } | |
| 2532 | − } | |
| 2533 | − | |
| 2534 | 2530 | // Audio VU Meter and Mute Icon |
| 2535 | 2531 | const int MUTE_ICON_SIZE = 24; |
| 2536 | 2532 | const int AUDIO_METER_INSET = 2; |
| @@ -3194,35 +3190,36 @@ void Application::packetSent(quint64 length) { · 657 unmodified lines | ||
| 3194 | 3190 | |
| 3195 | 3191 | void Application::loadScripts() { |
| 3196 | 3192 | // loads all saved scripts |
| 3197 | − QSettings* settings = new QSettings(this); | |
| 3198 | − int size = settings->beginReadArray("Settings"); | |
| 3199 | − | |
| 3193 | + int size = lockSettings()->beginReadArray("Settings"); | |
| 3194 | + unlockSettings(); | |
| 3200 | 3195 | for (int i = 0; i < size; ++i){ |
| 3201 | − settings->setArrayIndex(i); | |
| 3202 | − QString string = settings->value("script").toString(); | |
| 3203 | − loadScript(string); | |
| 3196 | + lockSettings()->setArrayIndex(i); | |
| 3197 | + QString string = _settings->value("script").toString(); | |
| 3198 | + unlockSettings(); | |
| 3199 | + if (!string.isEmpty()) { | |
| 3200 | + loadScript(string); | |
| 3201 | + } | |
| 3204 | 3202 | } |
| 3205 | − | |
| 3206 | − settings->endArray(); | |
| 3203 | + | |
| 3204 | + QMutexLocker locker(&_settingsMutex); | |
| 3205 | + _settings->endArray(); | |
| 3207 | 3206 | } |
| 3208 | 3207 | |
| 3209 | 3208 | void Application::clearScriptsBeforeRunning() { |
| 3210 | 3209 | // clears all scripts from the settings |
| 3211 | − QSettings* settings = new QSettings(this); | |
| 3212 | − settings->beginWriteArray("Settings"); | |
| 3213 | − settings->endArray(); | |
| 3210 | + QMutexLocker locker(&_settingsMutex); | |
| 3211 | + _settings->remove("Settings"); | |
| 3214 | 3212 | } |
| 3215 | 3213 | |
| 3216 | 3214 | void Application::saveScripts() { |
| 3217 | 3215 | // saves all current running scripts |
| 3218 | − QSettings* settings = new QSettings(this); | |
| 3219 | − settings->beginWriteArray("Settings"); | |
| 3216 | + QMutexLocker locker(&_settingsMutex); | |
| 3217 | + _settings->beginWriteArray("Settings"); | |
| 3220 | 3218 | for (int i = 0; i < getRunningScripts().size(); ++i){ |
| 3221 | − settings->setArrayIndex(i); | |
| 3222 | − settings->setValue("script", getRunningScripts().at(i)); | |
| 3219 | + _settings->setArrayIndex(i); | |
| 3220 | + _settings->setValue("script", getRunningScripts().at(i)); | |
| 3223 | 3221 | } |
| 3224 | − | |
| 3225 | − settings->endArray(); | |
| 3222 | + _settings->endArray(); | |
| 3226 | 3223 | } |
| 3227 | 3224 | |
| 3228 | 3225 | void Application::stopAllScripts() { |
| @@ -3363,7 +3360,10 @@ void Application::loadDialog() { · 134 unmodified lines | ||
| 3363 | 3360 | |
| 3364 | 3361 | if (_previousScriptLocation.isEmpty()) { |
| 3365 | 3362 | QString desktopLocation = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); |
| 3363 | +// Temporary fix to Qt bug: http://stackoverflow.com/questions/16194475 | |
| 3364 | +#ifdef __APPLE__ | |
| 3366 | 3365 | suggestedName = desktopLocation.append("/script.js"); |
| 3366 | +#endif | |
| 3367 | 3367 | } else { |
| 3368 | 3368 | suggestedName = _previousScriptLocation; |
| 3369 | 3369 | } |
| @@ -3372,9 +3372,11 @@ void Application::loadDialog() { · 2 unmodified lines | ||
| 3372 | 3372 | tr("JavaScript Files (*.js)")); |
| 3373 | 3373 | if (!fileNameString.isEmpty()) { |
| 3374 | 3374 | _previousScriptLocation = fileNameString; |
| 3375 | + QMutexLocker locker(&_settingsMutex); | |
| 3376 | + _settings->setValue("LastScriptLocation", _previousScriptLocation); | |
| 3377 | + | |
| 3378 | + loadScript(fileNameString); | |
| 3375 | 3379 | } |
| 3376 | − | |
| 3377 | − loadScript(fileNameString); | |
| 3378 | 3380 | } |
| 3379 | 3381 | |
| 3380 | 3382 | void Application::loadScriptURLDialog() { |