History

Merge branch 'master' into audioStatsDialog

bwent committed 11 years ago

Commit 70e3e7c2 parents 2c24251 029af53455 files · +15918 −12936Browse files

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

Unified · Split

interface/src/Application.cpp+276−261
@@ -66,6 +66,9 @@ · 65 unmodified lines
66#include <EntityScriptingInterface.h>66#include <EntityScriptingInterface.h>
67#include <ErrorDialog.h>67#include <ErrorDialog.h>
68#include <GlowEffect.h>68#include <GlowEffect.h>
69#include <gpu/Batch.h>
70#include <gpu/Context.h>
71#include <gpu/GLBackend.h>
69#include <HFActionEvent.h>72#include <HFActionEvent.h>
70#include <HFBackEvent.h>73#include <HFBackEvent.h>
71#include <InfoView.h>74#include <InfoView.h>
@@ -83,12 +86,15 @@ · 11 unmodified lines
83#include <PerfStat.h>86#include <PerfStat.h>
84#include <PhysicsEngine.h>87#include <PhysicsEngine.h>
85#include <ProgramObject.h>88#include <ProgramObject.h>
89#include <RenderDeferredTask.h>
86#include <ResourceCache.h>90#include <ResourceCache.h>
87#include <SceneScriptingInterface.h>91#include <SceneScriptingInterface.h>
88#include <ScriptCache.h>92#include <ScriptCache.h>
89#include <SettingHandle.h>93#include <SettingHandle.h>
94#include <SimpleAverage.h>
90#include <SoundCache.h>95#include <SoundCache.h>
91#include <TextRenderer.h>96#include <TextRenderer.h>
97#include <Tooltip.h>
92#include <UserActivityLogger.h>98#include <UserActivityLogger.h>
93#include <UUID.h>99#include <UUID.h>
94#include <VrMenu.h>100#include <VrMenu.h>
@@ -106,10 +112,8 @@ · 11 unmodified lines
106 112
107#include "avatar/AvatarManager.h"113#include "avatar/AvatarManager.h"
108 114
109#include "audio/AudioToolBox.h"
110#include "audio/AudioScope.h"115#include "audio/AudioScope.h"
111 116
112#include "devices/CameraToolBox.h"
113#include "devices/DdeFaceTracker.h"117#include "devices/DdeFaceTracker.h"
114#include "devices/Faceshift.h"118#include "devices/Faceshift.h"
115#include "devices/Leapmotion.h"119#include "devices/Leapmotion.h"
@@ -119,12 +123,6 @@ · 3 unmodified lines
119#include "devices/OculusManager.h"123#include "devices/OculusManager.h"
120#include "devices/TV3DManager.h"124#include "devices/TV3DManager.h"
121 125
122#include "gpu/Batch.h"
123#include "gpu/Context.h"
124#include "gpu/GLBackend.h"
125
126#include "RenderDeferredTask.h"
127
128#include "scripting/AccountScriptingInterface.h"126#include "scripting/AccountScriptingInterface.h"
129#include "scripting/AudioDeviceScriptingInterface.h"127#include "scripting/AudioDeviceScriptingInterface.h"
130#include "scripting/ClipboardScriptingInterface.h"128#include "scripting/ClipboardScriptingInterface.h"
@@ -140,6 +138,7 @@ · 9 unmodified lines
140#include "SpeechRecognizer.h"138#include "SpeechRecognizer.h"
141#endif139#endif
142 140
141#include "ui/AvatarInputs.h"
143#include "ui/DataWebDialog.h"142#include "ui/DataWebDialog.h"
144#include "ui/DialogsManager.h"143#include "ui/DialogsManager.h"
145#include "ui/LoginDialog.h"144#include "ui/LoginDialog.h"
@@ -179,6 +178,7 @@ using namespace std; · 33 unmodified lines
179// Starfield information178// Starfield information
180static unsigned STARFIELD_NUM_STARS = 50000;179static unsigned STARFIELD_NUM_STARS = 50000;
181static unsigned STARFIELD_SEED = 1;180static unsigned STARFIELD_SEED = 1;
181static uint8_t THROTTLED_IDLE_TIMER_DELAY = 10;
182 182
183const qint64 MAXIMUM_CACHE_SIZE = 10 * BYTES_PER_GIGABYTES; // 10GB183const qint64 MAXIMUM_CACHE_SIZE = 10 * BYTES_PER_GIGABYTES; // 10GB
184 184
@@ -279,8 +279,6 @@ bool setupEssentials(int& argc, char** argv) { · 94 unmodified lines
279 auto animationCache = DependencyManager::set<AnimationCache>();279 auto animationCache = DependencyManager::set<AnimationCache>();
280 auto ddeFaceTracker = DependencyManager::set<DdeFaceTracker>();280 auto ddeFaceTracker = DependencyManager::set<DdeFaceTracker>();
281 auto modelBlender = DependencyManager::set<ModelBlender>();281 auto modelBlender = DependencyManager::set<ModelBlender>();
282 auto audioToolBox = DependencyManager::set<AudioToolBox>();
283 auto cameraToolBox = DependencyManager::set<CameraToolBox>();
284 auto avatarManager = DependencyManager::set<AvatarManager>();282 auto avatarManager = DependencyManager::set<AvatarManager>();
285 auto lodManager = DependencyManager::set<LODManager>();283 auto lodManager = DependencyManager::set<LODManager>();
286 auto jsConsole = DependencyManager::set<StandAloneJSConsole>();284 auto jsConsole = DependencyManager::set<StandAloneJSConsole>();
@@ -333,13 +331,10 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 46 unmodified lines
333 _cursorVisible(true),331 _cursorVisible(true),
334 _lastMouseMove(usecTimestampNow()),332 _lastMouseMove(usecTimestampNow()),
335 _lastMouseMoveWasSimulated(false),333 _lastMouseMoveWasSimulated(false),
336 _touchAvgX(0.0f),
337 _touchAvgY(0.0f),
338 _isTouchPressed(false),334 _isTouchPressed(false),
339 _mousePressed(false),335 _mousePressed(false),
340 _enableProcessOctreeThread(true),336 _enableProcessOctreeThread(true),
341 _octreeProcessor(),337 _octreeProcessor(),
342 _nodeBoundsDisplay(this),
343 _runningScriptsWidget(NULL),338 _runningScriptsWidget(NULL),
344 _runningScriptsWidgetWasVisible(false),339 _runningScriptsWidgetWasVisible(false),
345 _trayIcon(new QSystemTrayIcon(_window)),340 _trayIcon(new QSystemTrayIcon(_window)),
@@ -396,6 +391,11 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 50 unmodified lines
396 static_cast<NodeList*>(dependency)->deleteLater();391 static_cast<NodeList*>(dependency)->deleteLater();
397 });392 });
398 393
394 // setup a timer for domain-server check ins
395 QTimer* domainCheckInTimer = new QTimer(nodeList.data());
396 connect(domainCheckInTimer, &QTimer::timeout, nodeList.data(), &NodeList::sendDomainServerCheckIn);
397 domainCheckInTimer->start(DOMAIN_SERVER_CHECK_IN_MSECS);
398
399 // put the NodeList and datagram processing on the node thread399 // put the NodeList and datagram processing on the node thread
400 nodeList->moveToThread(nodeThread);400 nodeList->moveToThread(nodeThread);
401 401
@@ -608,6 +608,11 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 206 unmodified lines
608 _settingsTimer.setSingleShot(false);608 _settingsTimer.setSingleShot(false);
609 _settingsTimer.setInterval(SAVE_SETTINGS_INTERVAL);609 _settingsTimer.setInterval(SAVE_SETTINGS_INTERVAL);
610 _settingsThread.start();610 _settingsThread.start();
611
612 if (Menu::getInstance()->isOptionChecked(MenuOption::IndependentMode)) {
613 Menu::getInstance()->setIsOptionChecked(MenuOption::ThirdPerson, true);
614 cameraMenuChanged();
615 }
611 616
612 _trayIcon->show();617 _trayIcon->show();
613 618
@@ -694,6 +699,14 @@ void Application::cleanupBeforeQuit() { · 80 unmodified lines
694#endif699#endif
695}700}
696 701
702void Application::emptyLocalCache() {
703 QNetworkDiskCache* cache = qobject_cast<QNetworkDiskCache*>(NetworkAccessManager::getInstance().cache());
704 if (cache) {
705 qDebug() << "DiskCacheEditor::clear(): Clearing disk cache.";
706 cache->clear();
707 }
708}
709
697Application::~Application() {710Application::~Application() {
698 EntityTree* tree = _entities.getTree();711 EntityTree* tree = _entities.getTree();
699 tree->lockForWrite();712 tree->lockForWrite();
@@ -829,6 +842,7 @@ void Application::initializeUi() { · 129 unmodified lines
829 LoginDialog::registerType();842 LoginDialog::registerType();
830 MessageDialog::registerType();843 MessageDialog::registerType();
831 VrMenu::registerType();844 VrMenu::registerType();
845 Tooltip::registerType();
832 UpdateDialog::registerType();846 UpdateDialog::registerType();
833 847
834 auto offscreenUi = DependencyManager::get<OffscreenUi>();848 auto offscreenUi = DependencyManager::get<OffscreenUi>();
@@ -842,7 +856,7 @@ void Application::initializeUi() { · 7 unmodified lines
842 VrMenu::executeQueuedLambdas();856 VrMenu::executeQueuedLambdas();
843 offscreenUi->setMouseTranslator([this](const QPointF& p){857 offscreenUi->setMouseTranslator([this](const QPointF& p){
844 if (OculusManager::isConnected()) {858 if (OculusManager::isConnected()) {
845 glm::vec2 pos = _applicationOverlay.screenToOverlay(toGlm(p));859 glm::vec2 pos = _compositor.screenToOverlay(toGlm(p));
846 return QPointF(pos.x, pos.y);860 return QPointF(pos.x, pos.y);
847 }861 }
848 return QPointF(p);862 return QPointF(p);
@@ -875,6 +889,7 @@ void Application::paintGL() { · 26 unmodified lines
875 OculusManager::beginFrameTiming();889 OculusManager::beginFrameTiming();
876 }890 }
877 891
892
878 PerformanceWarning::setSuppressShortTimings(Menu::getInstance()->isOptionChecked(MenuOption::SuppressShortTimings));893 PerformanceWarning::setSuppressShortTimings(Menu::getInstance()->isOptionChecked(MenuOption::SuppressShortTimings));
879 bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings);894 bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings);
880 PerformanceWarning warn(showWarnings, "Application::paintGL()");895 PerformanceWarning warn(showWarnings, "Application::paintGL()");
@@ -887,8 +902,11 @@ void Application::paintGL() { · 6 unmodified lines
887 902
888 glEnable(GL_LINE_SMOOTH);903 glEnable(GL_LINE_SMOOTH);
889 904
890 Menu::getInstance()->setIsOptionChecked("First Person", _myAvatar->getBoomLength() <= MyAvatar::ZOOM_MIN);905 if (_myCamera.getMode() == CAMERA_MODE_FIRST_PERSON || _myCamera.getMode() == CAMERA_MODE_THIRD_PERSON) {
891 Application::getInstance()->cameraMenuChanged();906 Menu::getInstance()->setIsOptionChecked(MenuOption::FirstPerson, _myAvatar->getBoomLength() <= MyAvatar::ZOOM_MIN);
907 Menu::getInstance()->setIsOptionChecked(MenuOption::ThirdPerson, !(_myAvatar->getBoomLength() <= MyAvatar::ZOOM_MIN));
908 Application::getInstance()->cameraMenuChanged();
909 }
892 910
893 if (_myCamera.getMode() == CAMERA_MODE_FIRST_PERSON) {911 if (_myCamera.getMode() == CAMERA_MODE_FIRST_PERSON) {
894 // Always use the default eye position, not the actual head eye position.912 // Always use the default eye position, not the actual head eye position.
@@ -954,6 +972,8 @@ void Application::paintGL() { · 59 unmodified lines
954 } else if (TV3DManager::isConnected()) {972 } else if (TV3DManager::isConnected()) {
955 TV3DManager::display(&renderArgs, _myCamera);973 TV3DManager::display(&renderArgs, _myCamera);
956 } else {974 } else {
975 PROFILE_RANGE(__FUNCTION__ "/mainRender");
976
957 DependencyManager::get<GlowEffect>()->prepare(&renderArgs);977 DependencyManager::get<GlowEffect>()->prepare(&renderArgs);
958 978
959 // Viewport is assigned to the size of the framebuffer979 // Viewport is assigned to the size of the framebuffer
@@ -967,27 +987,28 @@ void Application::paintGL() { · 7 unmodified lines
967 glPopMatrix();987 glPopMatrix();
968 988
969 renderArgs._renderMode = RenderArgs::MIRROR_RENDER_MODE;989 renderArgs._renderMode = RenderArgs::MIRROR_RENDER_MODE;
970 if (Menu::getInstance()->isOptionChecked(MenuOption::FullscreenMirror)) {990 if (Menu::getInstance()->isOptionChecked(MenuOption::Mirror)) {
971 _rearMirrorTools->render(&renderArgs, true, _glWidget->mapFromGlobal(QCursor::pos()));991 renderRearViewMirror(&renderArgs, _mirrorViewRect);
972 } else if (Menu::getInstance()->isOptionChecked(MenuOption::Mirror)) {
973 renderRearViewMirror(&renderArgs, _mirrorViewRect);
974 }992 }
975 993
976 renderArgs._renderMode = RenderArgs::NORMAL_RENDER_MODE;994 renderArgs._renderMode = RenderArgs::NORMAL_RENDER_MODE;
977 995
978 auto finalFbo = DependencyManager::get<GlowEffect>()->render(&renderArgs);996 auto finalFbo = DependencyManager::get<GlowEffect>()->render(&renderArgs);
979 997
998
980 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);999 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
981 glBindFramebuffer(GL_READ_FRAMEBUFFER, gpu::GLBackend::getFramebufferID(finalFbo));1000 glBindFramebuffer(GL_READ_FRAMEBUFFER, gpu::GLBackend::getFramebufferID(finalFbo));
982 glBlitFramebuffer(0, 0, _renderResolution.x, _renderResolution.y,1001 glBlitFramebuffer(0, 0, _renderResolution.x, _renderResolution.y,
983 0, 0, _glWidget->getDeviceSize().width(), _glWidget->getDeviceSize().height(),1002 0, 0, _glWidget->getDeviceSize().width(), _glWidget->getDeviceSize().height(),
984 GL_COLOR_BUFFER_BIT, GL_NEAREST);1003 GL_COLOR_BUFFER_BIT, GL_LINEAR);
985 glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);1004 glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
986 1005
987 _applicationOverlay.displayOverlayTexture();1006 _compositor.displayOverlayTexture(&renderArgs);
988 }1007 }
989 1008
1009
990 if (!OculusManager::isConnected() || OculusManager::allowSwap()) {1010 if (!OculusManager::isConnected() || OculusManager::allowSwap()) {
1011 PROFILE_RANGE(__FUNCTION__ "/bufferSwap");
991 _glWidget->swapBuffers();1012 _glWidget->swapBuffers();
992 }1013 }
993 1014
@@ -1000,6 +1021,7 @@ void Application::paintGL() { · 6 unmodified lines
1000 1021
1001void Application::runTests() {1022void Application::runTests() {
1002 runTimingTests();1023 runTimingTests();
1024 runUnitTests();
1003}1025}
1004 1026
1005void Application::audioMuteToggled() {1027void Application::audioMuteToggled() {
@@ -1025,7 +1047,7 @@ void Application::showEditEntitiesHelp() { · 19 unmodified lines
1025 InfoView::show(INFO_EDIT_ENTITIES_PATH);1047 InfoView::show(INFO_EDIT_ENTITIES_PATH);
1026}1048}
1027 1049
1028void Application::resetCamerasOnResizeGL(Camera& camera, const glm::uvec2& size) {1050void Application::resetCameras(Camera& camera, const glm::uvec2& size) {
1029 if (OculusManager::isConnected()) {1051 if (OculusManager::isConnected()) {
1030 OculusManager::configureCamera(camera);1052 OculusManager::configureCamera(camera);
1031 } else if (TV3DManager::isConnected()) {1053 } else if (TV3DManager::isConnected()) {
@@ -1036,6 +1058,7 @@ void Application::resetCamerasOnResizeGL(Camera& camera, const glm::uvec2& size) · 4 unmodified lines
1036}1058}
1037 1059
1038void Application::resizeGL() {1060void Application::resizeGL() {
1061 PROFILE_RANGE(__FUNCTION__);
1039 // Set the desired FBO texture size. If it hasn't changed, this does nothing.1062 // Set the desired FBO texture size. If it hasn't changed, this does nothing.
1040 // Otherwise, it must rebuild the FBOs1063 // Otherwise, it must rebuild the FBOs
1041 QSize renderSize;1064 QSize renderSize;
@@ -1044,27 +1067,25 @@ void Application::resizeGL() { · 2 unmodified lines
1044 } else {1067 } else {
1045 renderSize = _glWidget->getDeviceSize() * getRenderResolutionScale();1068 renderSize = _glWidget->getDeviceSize() * getRenderResolutionScale();
1046 }1069 }
1047 if (_renderResolution == toGlm(renderSize)) {
1048 return;
1049 }
1050 1070
1051 _renderResolution = toGlm(renderSize);1071 if (_renderResolution != toGlm(renderSize)) {
1052 DependencyManager::get<TextureCache>()->setFrameBufferSize(renderSize);1072 _renderResolution = toGlm(renderSize);
1053 resetCamerasOnResizeGL(_myCamera, _renderResolution);1073 DependencyManager::get<TextureCache>()->setFrameBufferSize(renderSize);
1054 1074
1055 glViewport(0, 0, _renderResolution.x, _renderResolution.y); // shouldn't this account for the menu???1075 glViewport(0, 0, _renderResolution.x, _renderResolution.y); // shouldn't this account for the menu???
1076
1077 updateProjectionMatrix();
1078 glLoadIdentity();
1079 }
1056 1080
1057 updateProjectionMatrix();1081 resetCameras(_myCamera, _renderResolution);
1058 glLoadIdentity();
1059 1082
1060 auto offscreenUi = DependencyManager::get<OffscreenUi>();1083 auto offscreenUi = DependencyManager::get<OffscreenUi>();
1061 offscreenUi->resize(_glWidget->size());1084
1085 auto canvasSize = _glWidget->size();
1086 offscreenUi->resize(canvasSize);
1062 _glWidget->makeCurrent();1087 _glWidget->makeCurrent();
1063 1088
1064 // update Stats width
1065 // let's set horizontal offset to give stats some margin to mirror
1066 int horizontalOffset = MIRROR_VIEW_WIDTH + MIRROR_VIEW_LEFT_PADDING * 2;
1067 Stats::getInstance()->resetWidth(_renderResolution.x, horizontalOffset);
1068}1089}
1069 1090
1070void Application::updateProjectionMatrix() {1091void Application::updateProjectionMatrix() {
@@ -1170,7 +1191,6 @@ bool Application::event(QEvent* event) { · 99 unmodified lines
1170}1191}
1171 1192
1172bool Application::eventFilter(QObject* object, QEvent* event) {1193bool Application::eventFilter(QObject* object, QEvent* event) {
1173
1174 if (event->type() == QEvent::ShortcutOverride) {1194 if (event->type() == QEvent::ShortcutOverride) {
1175 if (DependencyManager::get<OffscreenUi>()->shouldSwallowShortcut(event)) {1195 if (DependencyManager::get<OffscreenUi>()->shouldSwallowShortcut(event)) {
1176 event->accept();1196 event->accept();
@@ -1383,11 +1403,17 @@ void Application::keyPressEvent(QKeyEvent* event) { · 206 unmodified lines
1383 if (isShifted) {1403 if (isShifted) {
1384 Menu::getInstance()->triggerOption(MenuOption::Mirror);1404 Menu::getInstance()->triggerOption(MenuOption::Mirror);
1385 } else {1405 } else {
1386 Menu::getInstance()->triggerOption(MenuOption::FullscreenMirror);1406 Menu::getInstance()->setIsOptionChecked(MenuOption::FullscreenMirror, !Menu::getInstance()->isOptionChecked(MenuOption::FullscreenMirror));
1407 if (!Menu::getInstance()->isOptionChecked(MenuOption::FullscreenMirror)) {
1408 Menu::getInstance()->setIsOptionChecked(MenuOption::ThirdPerson, true);
1409 }
1410 cameraMenuChanged();
1387 }1411 }
1388 break;1412 break;
1389 case Qt::Key_P:1413 case Qt::Key_P:
1390 Menu::getInstance()->triggerOption(MenuOption::FirstPerson);1414 Menu::getInstance()->setIsOptionChecked(MenuOption::FirstPerson, !Menu::getInstance()->isOptionChecked(MenuOption::FirstPerson));
1415 Menu::getInstance()->setIsOptionChecked(MenuOption::ThirdPerson, !Menu::getInstance()->isOptionChecked(MenuOption::FirstPerson));
1416 cameraMenuChanged();
1391 break;1417 break;
1392 case Qt::Key_Slash:1418 case Qt::Key_Slash:
1393 Menu::getInstance()->triggerOption(MenuOption::Stats);1419 Menu::getInstance()->triggerOption(MenuOption::Stats);
@@ -1508,6 +1534,7 @@ void Application::focusOutEvent(QFocusEvent* event) { · 114 unmodified lines
1508}1534}
1509 1535
1510void Application::mouseMoveEvent(QMouseEvent* event, unsigned int deviceID) {1536void Application::mouseMoveEvent(QMouseEvent* event, unsigned int deviceID) {
1537 PROFILE_RANGE(__FUNCTION__);
1511 // Used by application overlay to determine how to draw cursor(s)1538 // Used by application overlay to determine how to draw cursor(s)
1512 _lastMouseMoveWasSimulated = deviceID > 0;1539 _lastMouseMoveWasSimulated = deviceID > 0;
1513 if (!_lastMouseMoveWasSimulated) {1540 if (!_lastMouseMoveWasSimulated) {
@@ -1562,27 +1589,9 @@ void Application::mousePressEvent(QMouseEvent* event, unsigned int deviceID) { · 48 unmodified lines
1562 _keyboardMouseDevice.mousePressEvent(event);1589 _keyboardMouseDevice.mousePressEvent(event);
1563 1590
1564 if (event->button() == Qt::LeftButton) {1591 if (event->button() == Qt::LeftButton) {
1565 _mouseDragStartedX = getTrueMouseX();1592 _mouseDragStarted = getTrueMouse();
1566 _mouseDragStartedY = getTrueMouseY();
1567 _mousePressed = true;1593 _mousePressed = true;
1568 1594
1569 if (mouseOnScreen()) {
1570 if (DependencyManager::get<AudioToolBox>()->mousePressEvent(getMouseX(), getMouseY())) {
1571 // stop propagation
1572 return;
1573 }
1574
1575 if (DependencyManager::get<CameraToolBox>()->mousePressEvent(getMouseX(), getMouseY())) {
1576 // stop propagation
1577 return;
1578 }
1579
1580 if (_rearMirrorTools->mousePressEvent(getMouseX(), getMouseY())) {
1581 // stop propagation
1582 return;
1583 }
1584 }
1585
1586 // nobody handled this - make it an action event on the _window object1595 // nobody handled this - make it an action event on the _window object
1587 HFActionEvent actionEvent(HFActionEvent::startType(),1596 HFActionEvent actionEvent(HFActionEvent::startType(),
1588 computePickRay(event->x(), event->y()));1597 computePickRay(event->x(), event->y()));
@@ -1601,17 +1610,6 @@ void Application::mouseDoublePressEvent(QMouseEvent* event, unsigned int deviceI · 12 unmodified lines
1601 }1610 }
1602 1611
1603 _controllerScriptingInterface.emitMouseDoublePressEvent(event);1612 _controllerScriptingInterface.emitMouseDoublePressEvent(event);
1604
1605 if (activeWindow() == _window) {
1606 if (event->button() == Qt::LeftButton) {
1607 if (mouseOnScreen()) {
1608 if (DependencyManager::get<CameraToolBox>()->mouseDoublePressEvent(getMouseX(), getMouseY())) {
1609 // stop propagation
1610 return;
1611 }
1612 }
1613 }
1614 }
1615}1613}
1616 1614
1617void Application::mouseReleaseEvent(QMouseEvent* event, unsigned int deviceID) {1615void Application::mouseReleaseEvent(QMouseEvent* event, unsigned int deviceID) {
@@ -1633,13 +1631,6 @@ void Application::mouseReleaseEvent(QMouseEvent* event, unsigned int deviceID) { · 15 unmodified lines
1633 if (event->button() == Qt::LeftButton) {1631 if (event->button() == Qt::LeftButton) {
1634 _mousePressed = false;1632 _mousePressed = false;
1635 1633
1636 if (Menu::getInstance()->isOptionChecked(MenuOption::Stats) && mouseOnScreen()) {
1637 // let's set horizontal offset to give stats some margin to mirror
1638 int horizontalOffset = MIRROR_VIEW_WIDTH;
1639 Stats::getInstance()->checkClick(getMouseX(), getMouseY(),
1640 getMouseDragStartedX(), getMouseDragStartedY(), horizontalOffset);
1641 }
1642
1643 // fire an action end event1634 // fire an action end event
1644 HFActionEvent actionEvent(HFActionEvent::endType(),1635 HFActionEvent actionEvent(HFActionEvent::endType(),
1645 computePickRay(event->x(), event->y()));1636 computePickRay(event->x(), event->y()));
@@ -1667,22 +1658,18 @@ void Application::touchUpdateEvent(QTouchEvent* event) { · 21 unmodified lines
1667 bool validTouch = false;1658 bool validTouch = false;
1668 if (activeWindow() == _window) {1659 if (activeWindow() == _window) {
1669 const QList<QTouchEvent::TouchPoint>& tPoints = event->touchPoints();1660 const QList<QTouchEvent::TouchPoint>& tPoints = event->touchPoints();
1670 _touchAvgX = 0.0f;1661 _touchAvg = vec2();
1671 _touchAvgY = 0.0f;
1672 int numTouches = tPoints.count();1662 int numTouches = tPoints.count();
1673 if (numTouches > 1) {1663 if (numTouches > 1) {
1674 for (int i = 0; i < numTouches; ++i) {1664 for (int i = 0; i < numTouches; ++i) {
1675 _touchAvgX += (float)tPoints[i].pos().x();1665 _touchAvg += toGlm(tPoints[i].pos());
1676 _touchAvgY += (float)tPoints[i].pos().y();
1677 }1666 }
1678 _touchAvgX /= (float)(numTouches);1667 _touchAvg /= (float)(numTouches);
1679 _touchAvgY /= (float)(numTouches);
1680 validTouch = true;1668 validTouch = true;
1681 }1669 }
1682 }1670 }
1683 if (!_isTouchPressed) {1671 if (!_isTouchPressed) {
1684 _touchDragStartedAvgX = _touchAvgX;1672 _touchDragStartedAvg = _touchAvg;
1685 _touchDragStartedAvgY = _touchAvgY;
1686 }1673 }
1687 _isTouchPressed = validTouch;1674 _isTouchPressed = validTouch;
1688}1675}
@@ -1718,8 +1705,7 @@ void Application::touchEndEvent(QTouchEvent* event) { · 29 unmodified lines
1718 _keyboardMouseDevice.touchEndEvent(event);1705 _keyboardMouseDevice.touchEndEvent(event);
1719 1706
1720 // put any application specific touch behavior below here..1707 // put any application specific touch behavior below here..
1721 _touchDragStartedAvgX = _touchAvgX;1708 _touchDragStartedAvg = _touchAvg;
1722 _touchDragStartedAvgY = _touchAvgY;
1723 _isTouchPressed = false;1709 _isTouchPressed = false;
1724 1710
1725}1711}
@@ -1804,14 +1790,28 @@ void Application::checkFPS() { · 78 unmodified lines
1804 _frameCount = 0;1790 _frameCount = 0;
1805 _datagramProcessor->resetCounters();1791 _datagramProcessor->resetCounters();
1806 _timerStart.start();1792 _timerStart.start();
1807
1808 // ask the node list to check in with the domain server
1809 DependencyManager::get<NodeList>()->sendDomainServerCheckIn();
1810}1793}
1811 1794
1812void Application::idle() {1795void Application::idle() {
1813 PerformanceTimer perfTimer("idle");1796 PROFILE_RANGE(__FUNCTION__);
1797 static SimpleAverage<float> interIdleDurations;
1798 static uint64_t lastIdleEnd{ 0 };
1799
1800 if (lastIdleEnd != 0) {
1801 uint64_t now = usecTimestampNow();
1802 interIdleDurations.update(now - lastIdleEnd);
1803 static uint64_t lastReportTime = now;
1804 if ((now - lastReportTime) >= (USECS_PER_SECOND)) {
1805 static QString LOGLINE("Average inter-idle time: %1 us for %2 samples");
1806 if (Menu::getInstance()->isOptionChecked(MenuOption::LogExtraTimings)) {
1807 qCDebug(interfaceapp_timing) << LOGLINE.arg((int)interIdleDurations.getAverage()).arg(interIdleDurations.getCount());
1808 }
1809 interIdleDurations.reset();
1810 lastReportTime = now;
1811 }
1812 }
1814 1813
1814 PerformanceTimer perfTimer("idle");
1815 if (_aboutToQuit) {1815 if (_aboutToQuit) {
1816 return; // bail early, nothing to do here.1816 return; // bail early, nothing to do here.
1817 }1817 }
@@ -1835,6 +1835,7 @@ void Application::idle() { · 17 unmodified lines
1835 PerformanceTimer perfTimer("update");1835 PerformanceTimer perfTimer("update");
1836 PerformanceWarning warn(showWarnings, "Application::idle()... update()");1836 PerformanceWarning warn(showWarnings, "Application::idle()... update()");
1837 const float BIGGEST_DELTA_TIME_SECS = 0.25f;1837 const float BIGGEST_DELTA_TIME_SECS = 0.25f;
1838 PROFILE_RANGE(__FUNCTION__ "/idleUpdate");
1838 update(glm::clamp((float)timeSinceLastUpdate / 1000.0f, 0.0f, BIGGEST_DELTA_TIME_SECS));1839 update(glm::clamp((float)timeSinceLastUpdate / 1000.0f, 0.0f, BIGGEST_DELTA_TIME_SECS));
1839 }1840 }
1840 {1841 {
@@ -1854,13 +1855,15 @@ void Application::idle() { · 13 unmodified lines
1854 _idleLoopStdev.reset();1855 _idleLoopStdev.reset();
1855 }1856 }
1856 1857
1857 // After finishing all of the above work, restart the idle timer, allowing 2ms to process events.
1858 idleTimer->start(2);
1859 }1858 }
1859 // After finishing all of the above work, ensure the idle timer is set to the proper interval,
1860 // depending on whether we're throttling or not
1861 idleTimer->start(_glWidget->isThrottleRendering() ? THROTTLED_IDLE_TIMER_DELAY : 1);
1860 }1862 }
1861 1863
1862 // check for any requested background downloads.1864 // check for any requested background downloads.
1863 emit checkBackgroundDownloads();1865 emit checkBackgroundDownloads();
1866 lastIdleEnd = usecTimestampNow();
1864}1867}
1865 1868
1866void Application::setFullscreen(bool fullscreen) {1869void Application::setFullscreen(bool fullscreen) {
@@ -1868,9 +1871,9 @@ void Application::setFullscreen(bool fullscreen) { · 1 unmodified line
1868 Menu::getInstance()->getActionForOption(MenuOption::Fullscreen)->setChecked(fullscreen);1871 Menu::getInstance()->getActionForOption(MenuOption::Fullscreen)->setChecked(fullscreen);
1869 }1872 }
1870 1873
1871// The following code block is useful on platforms that can have a visible1874 // The following code block is useful on platforms that can have a visible
1872// app menu in a fullscreen window. However the OSX mechanism hides the1875 // app menu in a fullscreen window. However the OSX mechanism hides the
1873// application menu for fullscreen apps, so the check is not required.1876 // application menu for fullscreen apps, so the check is not required.
1874#ifndef Q_OS_MAC1877#ifndef Q_OS_MAC
1875 if (Menu::getInstance()->isOptionChecked(MenuOption::EnableVRMode)) {1878 if (Menu::getInstance()->isOptionChecked(MenuOption::EnableVRMode)) {
1876 if (fullscreen) {1879 if (fullscreen) {
@@ -1944,11 +1947,6 @@ void Application::setEnableVRMode(bool enableVRMode) { · 67 unmodified lines
1944 } else {1947 } else {
1945 OculusManager::abandonCalibration();1948 OculusManager::abandonCalibration();
1946 OculusManager::disconnect();1949 OculusManager::disconnect();
1947
1948 _mirrorCamera.setHmdPosition(glm::vec3());
1949 _mirrorCamera.setHmdRotation(glm::quat());
1950 _myCamera.setHmdPosition(glm::vec3());
1951 _myCamera.setHmdRotation(glm::quat());
1952 }1950 }
1953 1951
1954 resizeGL();1952 resizeGL();
@@ -1960,44 +1958,34 @@ void Application::setLowVelocityFilter(bool lowVelocityFilter) { · 5 unmodified lines
1960 1958
1961bool Application::mouseOnScreen() const {1959bool Application::mouseOnScreen() const {
1962 if (OculusManager::isConnected()) {1960 if (OculusManager::isConnected()) {
1963 return getMouseX() >= 0 && getMouseX() <= _glWidget->getDeviceWidth() &&1961 ivec2 mouse = getMouse();
1964 getMouseY() >= 0 && getMouseY() <= _glWidget->getDeviceHeight();1962 if (!glm::all(glm::greaterThanEqual(mouse, ivec2()))) {
1963 return false;
1964 }
1965 ivec2 size = toGlm(_glWidget->getDeviceSize());
1966 if (!glm::all(glm::lessThanEqual(mouse, size))) {
1967 return false;
1968 }
1965 }1969 }
1966 return true;1970 return true;
1967}1971}
1968 1972
1969int Application::getMouseX() const {1973ivec2 Application::getMouse() const {
1970 if (OculusManager::isConnected()) {
1971 glm::vec2 pos = _applicationOverlay.screenToOverlay(glm::vec2(getTrueMouseX(), getTrueMouseY()));
1972 return pos.x;
1973 }
1974 return getTrueMouseX();
1975}
1976
1977int Application::getMouseY() const {
1978 if (OculusManager::isConnected()) {1974 if (OculusManager::isConnected()) {
1979 glm::vec2 pos = _applicationOverlay.screenToOverlay(glm::vec2(getTrueMouseX(), getTrueMouseY()));1975 return _compositor.screenToOverlay(getTrueMouse());
1980 return pos.y;
1981 }1976 }
1982 return getTrueMouseY();1977 return getTrueMouse();
1983}1978}
1984 1979
1985int Application::getMouseDragStartedX() const {1980ivec2 Application::getMouseDragStarted() const {
1986 if (OculusManager::isConnected()) {1981 if (OculusManager::isConnected()) {
1987 glm::vec2 pos = _applicationOverlay.screenToOverlay(glm::vec2(getTrueMouseDragStartedX(),1982 return _compositor.screenToOverlay(getTrueMouseDragStarted());
1988 getTrueMouseDragStartedY()));
1989 return pos.x;
1990 }1983 }
1991 return getTrueMouseDragStartedX();1984 return getTrueMouseDragStarted();
1992}1985}
1993 1986
1994int Application::getMouseDragStartedY() const {1987ivec2 Application::getTrueMouseDragStarted() const {
1995 if (OculusManager::isConnected()) {1988 return _mouseDragStarted;
1996 glm::vec2 pos = _applicationOverlay.screenToOverlay(glm::vec2(getTrueMouseDragStartedX(),
1997 getTrueMouseDragStartedY()));
1998 return pos.y;
1999 }
2000 return getTrueMouseDragStartedY();
2001}1989}
2002 1990
2003FaceTracker* Application::getActiveFaceTracker() {1991FaceTracker* Application::getActiveFaceTracker() {
@@ -2242,19 +2230,13 @@ void Application::init() { · 238 unmodified lines
2242 _entityClipboardRenderer.setViewFrustum(getViewFrustum());2230 _entityClipboardRenderer.setViewFrustum(getViewFrustum());
2243 _entityClipboardRenderer.setTree(&_entityClipboard);2231 _entityClipboardRenderer.setTree(&_entityClipboard);
2244 2232
2245 _rearMirrorTools = new RearMirrorTools(_mirrorViewRect);
2246
2247 connect(_rearMirrorTools, SIGNAL(closeView()), SLOT(closeMirrorView()));
2248 connect(_rearMirrorTools, SIGNAL(restoreView()), SLOT(restoreMirrorView()));
2249 connect(_rearMirrorTools, SIGNAL(shrinkView()), SLOT(shrinkMirrorView()));
2250 connect(_rearMirrorTools, SIGNAL(resetView()), SLOT(resetSensors()));
2251
2252 // initialize the GlowEffect with our widget2233 // initialize the GlowEffect with our widget
2253 bool glow = Menu::getInstance()->isOptionChecked(MenuOption::EnableGlowEffect);2234 bool glow = Menu::getInstance()->isOptionChecked(MenuOption::EnableGlowEffect);
2254 DependencyManager::get<GlowEffect>()->init(glow);2235 DependencyManager::get<GlowEffect>()->init(glow);
2255 2236
2256 // Make sure any new sounds are loaded as soon as know about them.2237 // Make sure any new sounds are loaded as soon as know about them.
2257 connect(tree, &EntityTree::newCollisionSoundURL, DependencyManager::get<SoundCache>().data(), &SoundCache::getSound);2238 connect(tree, &EntityTree::newCollisionSoundURL, DependencyManager::get<SoundCache>().data(), &SoundCache::getSound);
2239 connect(_myAvatar, &MyAvatar::newCollisionSoundURL, DependencyManager::get<SoundCache>().data(), &SoundCache::getSound);
2258}2240}
2259 2241
2260void Application::closeMirrorView() {2242void Application::closeMirrorView() {
@@ -2330,38 +2312,42 @@ void Application::updateMyAvatarLookAtPosition() { · 69 unmodified lines
2330 bool isLookingAtSomeone = false;2312 bool isLookingAtSomeone = false;
2331 glm::vec3 lookAtSpot;2313 glm::vec3 lookAtSpot;
2332 if (_myCamera.getMode() == CAMERA_MODE_MIRROR) {2314 if (_myCamera.getMode() == CAMERA_MODE_MIRROR) {
2333 // When I am in mirror mode, just look right at the camera (myself)2315 // When I am in mirror mode, just look right at the camera (myself); don't switch gaze points because when physically
2316 // looking in a mirror one's eyes appear steady.
2334 if (!OculusManager::isConnected()) {2317 if (!OculusManager::isConnected()) {
2335 lookAtSpot = _myCamera.getPosition();2318 lookAtSpot = _myCamera.getPosition();
2336 } else {2319 } else {
2337 if (_myAvatar->isLookingAtLeftEye()) {2320 lookAtSpot = _myCamera.getPosition() + OculusManager::getMidEyePosition();
2338 lookAtSpot = OculusManager::getLeftEyePosition();
2339 } else {
2340 lookAtSpot = OculusManager::getRightEyePosition();
2341 }
2342 }2321 }
2343
2344 } else {2322 } else {
2345 AvatarSharedPointer lookingAt = _myAvatar->getLookAtTargetAvatar().lock();2323 AvatarSharedPointer lookingAt = _myAvatar->getLookAtTargetAvatar().lock();
2346 if (lookingAt && _myAvatar != lookingAt.get()) {2324 if (lookingAt && _myAvatar != lookingAt.get()) {
2347 isLookingAtSomeone = true;
2348 // If I am looking at someone else, look directly at one of their eyes2325 // If I am looking at someone else, look directly at one of their eyes
2349 if (tracker && !tracker->isMuted()) {2326 isLookingAtSomeone = true;
2350 // If a face tracker is active, look at the eye for the side my gaze is biased toward2327 Head* lookingAtHead = static_cast<Avatar*>(lookingAt.get())->getHead();
2351 if (tracker->getEstimatedEyeYaw() > _myAvatar->getHead()->getFinalYaw()) {2328
2352 // Look at their right eye2329 const float MAXIMUM_FACE_ANGLE = 65.0f * RADIANS_PER_DEGREE;
2353 lookAtSpot = static_cast<Avatar*>(lookingAt.get())->getHead()->getRightEyePosition();2330 glm::vec3 lookingAtFaceOrientation = lookingAtHead->getFinalOrientationInWorldFrame() * IDENTITY_FRONT;
2354 } else {2331 glm::vec3 fromLookingAtToMe = glm::normalize(_myAvatar->getHead()->getEyePosition()
2355 // Look at their left eye2332 - lookingAtHead->getEyePosition());
2356 lookAtSpot = static_cast<Avatar*>(lookingAt.get())->getHead()->getLeftEyePosition();2333 float faceAngle = glm::angle(lookingAtFaceOrientation, fromLookingAtToMe);
2334
2335 if (faceAngle < MAXIMUM_FACE_ANGLE) {
2336 // Randomly look back and forth between look targets
2337 switch (_myAvatar->getEyeContactTarget()) {
2338 case LEFT_EYE:
2339 lookAtSpot = lookingAtHead->getLeftEyePosition();
2340 break;
2341 case RIGHT_EYE:
2342 lookAtSpot = lookingAtHead->getRightEyePosition();
2343 break;
2344 case MOUTH:
2345 lookAtSpot = lookingAtHead->getMouthPosition();
2346 break;
2357 }2347 }
2358 } else {2348 } else {
2359 // Need to add randomly looking back and forth between left and right eye for case with no tracker2349 // Just look at their head (mid point between eyes)
2360 if (_myAvatar->isLookingAtLeftEye()) {2350 lookAtSpot = lookingAtHead->getEyePosition();
2361 lookAtSpot = static_cast<Avatar*>(lookingAt.get())->getHead()->getLeftEyePosition();
2362 } else {
2363 lookAtSpot = static_cast<Avatar*>(lookingAt.get())->getHead()->getRightEyePosition();
2364 }
2365 }2351 }
2366 } else {2352 } else {
2367 // I am not looking at anyone else, so just look forward2353 // I am not looking at anyone else, so just look forward
@@ -2369,14 +2355,13 @@ void Application::updateMyAvatarLookAtPosition() { · 1 unmodified line
2369 (_myAvatar->getHead()->getFinalOrientationInWorldFrame() * glm::vec3(0.0f, 0.0f, -TREE_SCALE));2355 (_myAvatar->getHead()->getFinalOrientationInWorldFrame() * glm::vec3(0.0f, 0.0f, -TREE_SCALE));
2370 }2356 }
2371 }2357 }
2372 //2358
2373 // Deflect the eyes a bit to match the detected Gaze from 3D camera if active2359 // Deflect the eyes a bit to match the detected gaze from Faceshift if active.
2374 //2360 // DDE doesn't track eyes.
2375 if (tracker && !tracker->isMuted()) {2361 if (tracker && typeid(*tracker) == typeid(Faceshift) && !tracker->isMuted()) {
2376 float eyePitch = tracker->getEstimatedEyePitch();2362 float eyePitch = tracker->getEstimatedEyePitch();
2377 float eyeYaw = tracker->getEstimatedEyeYaw();2363 float eyeYaw = tracker->getEstimatedEyeYaw();
2378 const float GAZE_DEFLECTION_REDUCTION_DURING_EYE_CONTACT = 0.1f;2364 const float GAZE_DEFLECTION_REDUCTION_DURING_EYE_CONTACT = 0.1f;
2379 // deflect using Faceshift gaze data
2380 glm::vec3 origin = _myAvatar->getHead()->getEyePosition();2365 glm::vec3 origin = _myAvatar->getHead()->getEyePosition();
2381 float pitchSign = (_myCamera.getMode() == CAMERA_MODE_MIRROR) ? -1.0f : 1.0f;2366 float pitchSign = (_myCamera.getMode() == CAMERA_MODE_MIRROR) ? -1.0f : 1.0f;
2382 float deflection = DependencyManager::get<Faceshift>()->getEyeDeflection();2367 float deflection = DependencyManager::get<Faceshift>()->getEyeDeflection();
@@ -2413,16 +2398,29 @@ void Application::cameraMenuChanged() { · 30 unmodified lines
2413 _myCamera.setMode(CAMERA_MODE_FIRST_PERSON);2398 _myCamera.setMode(CAMERA_MODE_FIRST_PERSON);
2414 _myAvatar->setBoomLength(MyAvatar::ZOOM_MIN);2399 _myAvatar->setBoomLength(MyAvatar::ZOOM_MIN);
2415 }2400 }
2416 } else {2401 } else if (Menu::getInstance()->isOptionChecked(MenuOption::ThirdPerson)) {
2417 if (_myCamera.getMode() != CAMERA_MODE_THIRD_PERSON) {2402 if (_myCamera.getMode() != CAMERA_MODE_THIRD_PERSON) {
2418 _myCamera.setMode(CAMERA_MODE_THIRD_PERSON);2403 _myCamera.setMode(CAMERA_MODE_THIRD_PERSON);
2419 if (_myAvatar->getBoomLength() == MyAvatar::ZOOM_MIN) {2404 if (_myAvatar->getBoomLength() == MyAvatar::ZOOM_MIN) {
2420 _myAvatar->setBoomLength(MyAvatar::ZOOM_DEFAULT);2405 _myAvatar->setBoomLength(MyAvatar::ZOOM_DEFAULT);
2421 }2406 }
2422 }2407 }
2408 } else if (Menu::getInstance()->isOptionChecked(MenuOption::IndependentMode)) {
2409 if (_myCamera.getMode() != CAMERA_MODE_INDEPENDENT) {
2410 _myCamera.setMode(CAMERA_MODE_INDEPENDENT);
2411 }
2423 }2412 }
2424}2413}
2425 2414
2415void Application::reloadResourceCaches() {
2416 emptyLocalCache();
2417
2418 DependencyManager::get<AnimationCache>()->refreshAll();
2419 DependencyManager::get<GeometryCache>()->refreshAll();
2420 DependencyManager::get<SoundCache>()->refreshAll();
2421 DependencyManager::get<TextureCache>()->refreshAll();
2422}
2423
2426void Application::rotationModeChanged() {2424void Application::rotationModeChanged() {
2427 if (!Menu::getInstance()->isOptionChecked(MenuOption::CenterPlayerInView)) {2425 if (!Menu::getInstance()->isOptionChecked(MenuOption::CenterPlayerInView)) {
2428 _myAvatar->setHeadPitch(0);2426 _myAvatar->setHeadPitch(0);
@@ -2519,18 +2517,22 @@ void Application::update(float deltaTime) { · 90 unmodified lines
2519 2517
2520 // Transfer the user inputs to the driveKeys2518 // Transfer the user inputs to the driveKeys
2521 _myAvatar->clearDriveKeys();2519 _myAvatar->clearDriveKeys();
2522 _myAvatar->setDriveKeys(FWD, _userInputMapper.getActionState(UserInputMapper::LONGITUDINAL_FORWARD));2520 if (_myCamera.getMode() != CAMERA_MODE_INDEPENDENT) {
2523 _myAvatar->setDriveKeys(BACK, _userInputMapper.getActionState(UserInputMapper::LONGITUDINAL_BACKWARD));2521 if (!_controllerScriptingInterface.areActionsCaptured()) {
2524 _myAvatar->setDriveKeys(UP, _userInputMapper.getActionState(UserInputMapper::VERTICAL_UP));2522 _myAvatar->setDriveKeys(FWD, _userInputMapper.getActionState(UserInputMapper::LONGITUDINAL_FORWARD));
2525 _myAvatar->setDriveKeys(DOWN, _userInputMapper.getActionState(UserInputMapper::VERTICAL_DOWN));2523 _myAvatar->setDriveKeys(BACK, _userInputMapper.getActionState(UserInputMapper::LONGITUDINAL_BACKWARD));
2526 _myAvatar->setDriveKeys(LEFT, _userInputMapper.getActionState(UserInputMapper::LATERAL_LEFT));2524 _myAvatar->setDriveKeys(UP, _userInputMapper.getActionState(UserInputMapper::VERTICAL_UP));
2527 _myAvatar->setDriveKeys(RIGHT, _userInputMapper.getActionState(UserInputMapper::LATERAL_RIGHT));2525 _myAvatar->setDriveKeys(DOWN, _userInputMapper.getActionState(UserInputMapper::VERTICAL_DOWN));
2528 _myAvatar->setDriveKeys(ROT_UP, _userInputMapper.getActionState(UserInputMapper::PITCH_UP));2526 _myAvatar->setDriveKeys(LEFT, _userInputMapper.getActionState(UserInputMapper::LATERAL_LEFT));
2529 _myAvatar->setDriveKeys(ROT_DOWN, _userInputMapper.getActionState(UserInputMapper::PITCH_DOWN));2527 _myAvatar->setDriveKeys(RIGHT, _userInputMapper.getActionState(UserInputMapper::LATERAL_RIGHT));
2530 _myAvatar->setDriveKeys(ROT_LEFT, _userInputMapper.getActionState(UserInputMapper::YAW_LEFT));2528 _myAvatar->setDriveKeys(ROT_UP, _userInputMapper.getActionState(UserInputMapper::PITCH_UP));
2531 _myAvatar->setDriveKeys(ROT_RIGHT, _userInputMapper.getActionState(UserInputMapper::YAW_RIGHT));2529 _myAvatar->setDriveKeys(ROT_DOWN, _userInputMapper.getActionState(UserInputMapper::PITCH_DOWN));
2532 _myAvatar->setDriveKeys(BOOM_IN, _userInputMapper.getActionState(UserInputMapper::BOOM_IN));2530 _myAvatar->setDriveKeys(ROT_LEFT, _userInputMapper.getActionState(UserInputMapper::YAW_LEFT));
2533 _myAvatar->setDriveKeys(BOOM_OUT, _userInputMapper.getActionState(UserInputMapper::BOOM_OUT));2531 _myAvatar->setDriveKeys(ROT_RIGHT, _userInputMapper.getActionState(UserInputMapper::YAW_RIGHT));
2532 }
2533 _myAvatar->setDriveKeys(BOOM_IN, _userInputMapper.getActionState(UserInputMapper::BOOM_IN));
2534 _myAvatar->setDriveKeys(BOOM_OUT, _userInputMapper.getActionState(UserInputMapper::BOOM_OUT));
2535 }
2534 2536
2535 updateThreads(deltaTime); // If running non-threaded, then give the threads some time to process...2537 updateThreads(deltaTime); // If running non-threaded, then give the threads some time to process...
2536 2538
@@ -2547,24 +2549,45 @@ void Application::update(float deltaTime) { · 10 unmodified lines
2547 2549
2548 _entitySimulation.lock();2550 _entitySimulation.lock();
2549 _physicsEngine.deleteObjects(_entitySimulation.getObjectsToDelete());2551 _physicsEngine.deleteObjects(_entitySimulation.getObjectsToDelete());
2552 _entitySimulation.unlock();
2553
2554 _entities.getTree()->lockForWrite();
2555 _entitySimulation.lock();
2550 _physicsEngine.addObjects(_entitySimulation.getObjectsToAdd());2556 _physicsEngine.addObjects(_entitySimulation.getObjectsToAdd());
2557 _entitySimulation.unlock();
2558 _entities.getTree()->unlock();
2559
2560 _entities.getTree()->lockForWrite();
2561 _entitySimulation.lock();
2551 _physicsEngine.changeObjects(_entitySimulation.getObjectsToChange());2562 _physicsEngine.changeObjects(_entitySimulation.getObjectsToChange());
2563 _entitySimulation.unlock();
2564 _entities.getTree()->unlock();
2565
2566 _entitySimulation.lock();
2552 _entitySimulation.applyActionChanges();2567 _entitySimulation.applyActionChanges();
2553 _entitySimulation.unlock();2568 _entitySimulation.unlock();
2554 2569
2570
2555 AvatarManager* avatarManager = DependencyManager::get<AvatarManager>().data();2571 AvatarManager* avatarManager = DependencyManager::get<AvatarManager>().data();
2556 _physicsEngine.deleteObjects(avatarManager->getObjectsToDelete());2572 _physicsEngine.deleteObjects(avatarManager->getObjectsToDelete());
2557 _physicsEngine.addObjects(avatarManager->getObjectsToAdd());2573 _physicsEngine.addObjects(avatarManager->getObjectsToAdd());
2558 _physicsEngine.changeObjects(avatarManager->getObjectsToChange());2574 _physicsEngine.changeObjects(avatarManager->getObjectsToChange());
2559 2575
2576 _entities.getTree()->lockForWrite();
2560 _physicsEngine.stepSimulation();2577 _physicsEngine.stepSimulation();
2578 _entities.getTree()->unlock();
2561 2579
2562 if (_physicsEngine.hasOutgoingChanges()) {2580 if (_physicsEngine.hasOutgoingChanges()) {
2581 _entities.getTree()->lockForWrite();
2563 _entitySimulation.lock();2582 _entitySimulation.lock();
2564 _entitySimulation.handleOutgoingChanges(_physicsEngine.getOutgoingChanges(), _physicsEngine.getSessionID());2583 _entitySimulation.handleOutgoingChanges(_physicsEngine.getOutgoingChanges(), _physicsEngine.getSessionID());
2565 _entitySimulation.unlock();2584 _entitySimulation.unlock();
2585 _entities.getTree()->unlock();
2566 2586
2587 _entities.getTree()->lockForWrite();
2567 avatarManager->handleOutgoingChanges(_physicsEngine.getOutgoingChanges());2588 avatarManager->handleOutgoingChanges(_physicsEngine.getOutgoingChanges());
2589 _entities.getTree()->unlock();
2590
2568 auto collisionEvents = _physicsEngine.getCollisionEvents();2591 auto collisionEvents = _physicsEngine.getCollisionEvents();
2569 avatarManager->handleCollisionEvents(collisionEvents);2592 avatarManager->handleCollisionEvents(collisionEvents);
2570 2593
@@ -2953,6 +2976,7 @@ QRect Application::getDesirableApplicationGeometry() { · 382 unmodified lines
2953// or the "myCamera".2976// or the "myCamera".
2954//2977//
2955void Application::loadViewFrustum(Camera& camera, ViewFrustum& viewFrustum) {2978void Application::loadViewFrustum(Camera& camera, ViewFrustum& viewFrustum) {
2979 PROFILE_RANGE(__FUNCTION__);
2956 // We will use these below, from either the camera or head vectors calculated above2980 // We will use these below, from either the camera or head vectors calculated above
2957 viewFrustum.setProjection(camera.getProjection());2981 viewFrustum.setProjection(camera.getProjection());
2958 2982
@@ -3154,7 +3178,7 @@ PickRay Application::computePickRay(float x, float y) const { · 195 unmodified lines
3154 y /= size.y;3178 y /= size.y;
3155 PickRay result;3179 PickRay result;
3156 if (isHMDMode()) {3180 if (isHMDMode()) {
3157 getApplicationOverlay().computeHmdPickRay(glm::vec2(x, y), result.origin, result.direction);3181 getApplicationCompositor().computeHmdPickRay(glm::vec2(x, y), result.origin, result.direction);
3158 } else {3182 } else {
3159 if (QThread::currentThread() == activeRenderingThread) {3183 if (QThread::currentThread() == activeRenderingThread) {
3160 getDisplayViewFrustum()->computePickRay(x, y, result.origin, result.direction);3184 getDisplayViewFrustum()->computePickRay(x, y, result.origin, result.direction);
@@ -3183,13 +3207,11 @@ QImage Application::renderAvatarBillboard(RenderArgs* renderArgs) { · 22 unmodified lines
3183 renderRearViewMirror(renderArgs, QRect(0, _glWidget->getDeviceHeight() - BILLBOARD_SIZE,3207 renderRearViewMirror(renderArgs, QRect(0, _glWidget->getDeviceHeight() - BILLBOARD_SIZE,
3184 BILLBOARD_SIZE, BILLBOARD_SIZE),3208 BILLBOARD_SIZE, BILLBOARD_SIZE),
3185 true);3209 true);
3186
3187 QImage image(BILLBOARD_SIZE, BILLBOARD_SIZE, QImage::Format_ARGB32);3210 QImage image(BILLBOARD_SIZE, BILLBOARD_SIZE, QImage::Format_ARGB32);
3188 glReadPixels(0, 0, BILLBOARD_SIZE, BILLBOARD_SIZE, GL_BGRA, GL_UNSIGNED_BYTE, image.bits());3211 glReadPixels(0, 0, BILLBOARD_SIZE, BILLBOARD_SIZE, GL_BGRA, GL_UNSIGNED_BYTE, image.bits());
3189 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);3212 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
3190 3213
3191 glBindFramebuffer(GL_FRAMEBUFFER, 0);3214 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3192
3193 return image;3215 return image;
3194}3216}
3195 3217
@@ -3311,7 +3333,7 @@ namespace render { · 115 unmodified lines
3311 const float APPROXIMATE_DISTANCE_FROM_HORIZON = 0.1f;3333 const float APPROXIMATE_DISTANCE_FROM_HORIZON = 0.1f;
3312 const float DOUBLE_APPROXIMATE_DISTANCE_FROM_HORIZON = 0.2f;3334 const float DOUBLE_APPROXIMATE_DISTANCE_FROM_HORIZON = 0.2f;
3313 3335
3314 glm::vec3 sunDirection = (args->_viewFrustum->getPosition()/*getAvatarPosition()*/ - closestData.getSunLocation()) 3336 glm::vec3 sunDirection = (args->_viewFrustum->getPosition()/*getAvatarPosition()*/ - closestData.getSunLocation())
3315 / closestData.getAtmosphereOuterRadius();3337 / closestData.getAtmosphereOuterRadius();
3316 float height = glm::distance(args->_viewFrustum->getPosition()/*theCamera.getPosition()*/, closestData.getAtmosphereCenter());3338 float height = glm::distance(args->_viewFrustum->getPosition()/*theCamera.getPosition()*/, closestData.getAtmosphereCenter());
3317 if (height < closestData.getAtmosphereInnerRadius()) {3339 if (height < closestData.getAtmosphereInnerRadius()) {
@@ -3319,8 +3341,8 @@ namespace render { · 1 unmodified line
3319 alpha = 0.0f;3341 alpha = 0.0f;
3320 3342
3321 if (sunDirection.y > -APPROXIMATE_DISTANCE_FROM_HORIZON) {3343 if (sunDirection.y > -APPROXIMATE_DISTANCE_FROM_HORIZON) {
3322 float directionY = glm::clamp(sunDirection.y, 3344 float directionY = glm::clamp(sunDirection.y,
3323 -APPROXIMATE_DISTANCE_FROM_HORIZON, APPROXIMATE_DISTANCE_FROM_HORIZON) 3345 -APPROXIMATE_DISTANCE_FROM_HORIZON, APPROXIMATE_DISTANCE_FROM_HORIZON)
3324 + APPROXIMATE_DISTANCE_FROM_HORIZON;3346 + APPROXIMATE_DISTANCE_FROM_HORIZON;
3325 alpha = (directionY / DOUBLE_APPROXIMATE_DISTANCE_FROM_HORIZON);3347 alpha = (directionY / DOUBLE_APPROXIMATE_DISTANCE_FROM_HORIZON);
3326 }3348 }
@@ -3331,8 +3353,8 @@ namespace render { · 4 unmodified lines
3331 (closestData.getAtmosphereOuterRadius() - closestData.getAtmosphereInnerRadius());3353 (closestData.getAtmosphereOuterRadius() - closestData.getAtmosphereInnerRadius());
3332 3354
3333 if (sunDirection.y > -APPROXIMATE_DISTANCE_FROM_HORIZON) {3355 if (sunDirection.y > -APPROXIMATE_DISTANCE_FROM_HORIZON) {
3334 float directionY = glm::clamp(sunDirection.y, 3356 float directionY = glm::clamp(sunDirection.y,
3335 -APPROXIMATE_DISTANCE_FROM_HORIZON, APPROXIMATE_DISTANCE_FROM_HORIZON) 3357 -APPROXIMATE_DISTANCE_FROM_HORIZON, APPROXIMATE_DISTANCE_FROM_HORIZON)
3336 + APPROXIMATE_DISTANCE_FROM_HORIZON;3358 + APPROXIMATE_DISTANCE_FROM_HORIZON;
3337 alpha = (directionY / DOUBLE_APPROXIMATE_DISTANCE_FROM_HORIZON);3359 alpha = (directionY / DOUBLE_APPROXIMATE_DISTANCE_FROM_HORIZON);
3338 }3360 }
@@ -3374,6 +3396,11 @@ namespace render { · 35 unmodified lines
3374 3396
3375 3397
3376void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool selfAvatarOnly, bool billboard) {3398void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool selfAvatarOnly, bool billboard) {
3399
3400 // FIXME: This preRender call is temporary until we create a separate render::scene for the mirror rendering.
3401 // Then we can move this logic into the Avatar::simulate call.
3402 _myAvatar->preRender(renderArgs);
3403
3377 activeRenderingThread = QThread::currentThread();3404 activeRenderingThread = QThread::currentThread();
3378 PROFILE_RANGE(__FUNCTION__);3405 PROFILE_RANGE(__FUNCTION__);
3379 PerformanceTimer perfTimer("display");3406 PerformanceTimer perfTimer("display");
@@ -3383,15 +3410,6 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se · 3 unmodified lines
3383 // load the view frustum3410 // load the view frustum
3384 loadViewFrustum(theCamera, _displayViewFrustum);3411 loadViewFrustum(theCamera, _displayViewFrustum);
3385 3412
3386 // flip x if in mirror mode (also requires reversing winding order for backface culling)
3387 if (theCamera.getMode() == CAMERA_MODE_MIRROR) {
3388 glScalef(-1.0f, 1.0f, 1.0f);
3389 glFrontFace(GL_CW);
3390
3391 } else {
3392 glFrontFace(GL_CCW);
3393 }
3394
3395 // transform view according to theCamera3413 // transform view according to theCamera
3396 // could be myCamera (if in normal mode)3414 // could be myCamera (if in normal mode)
3397 // or could be viewFrustumOffsetCamera if in offset mode3415 // or could be viewFrustumOffsetCamera if in offset mode
@@ -3409,9 +3427,6 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se · 11 unmodified lines
3409 Transform viewTransform;3427 Transform viewTransform;
3410 viewTransform.setTranslation(theCamera.getPosition());3428 viewTransform.setTranslation(theCamera.getPosition());
3411 viewTransform.setRotation(rotation);3429 viewTransform.setRotation(rotation);
3412 if (theCamera.getMode() == CAMERA_MODE_MIRROR) {
3413 viewTransform.setScale(Transform::Vec3(-1.0f, 1.0f, 1.0f));
3414 }
3415 if (renderArgs->_renderSide != RenderArgs::MONO) {3430 if (renderArgs->_renderSide != RenderArgs::MONO) {
3416 glm::mat4 invView = glm::inverse(_untranslatedViewMatrix);3431 glm::mat4 invView = glm::inverse(_untranslatedViewMatrix);
3417 3432
@@ -3466,9 +3481,8 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se · 48 unmodified lines
3466 // Assuming nothing get's rendered through that3481 // Assuming nothing get's rendered through that
3467 3482
3468 if (!selfAvatarOnly) {3483 if (!selfAvatarOnly) {
3469
3470 // render models...
3471 if (DependencyManager::get<SceneScriptingInterface>()->shouldRenderEntities()) {3484 if (DependencyManager::get<SceneScriptingInterface>()->shouldRenderEntities()) {
3485 // render models...
3472 PerformanceTimer perfTimer("entities");3486 PerformanceTimer perfTimer("entities");
3473 PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings),3487 PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings),
3474 "Application::displaySide() ... entities...");3488 "Application::displaySide() ... entities...");
@@ -3476,11 +3490,11 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se · 1 unmodified line
3476 RenderArgs::DebugFlags renderDebugFlags = RenderArgs::RENDER_DEBUG_NONE;3490 RenderArgs::DebugFlags renderDebugFlags = RenderArgs::RENDER_DEBUG_NONE;
3477 3491
3478 if (Menu::getInstance()->isOptionChecked(MenuOption::PhysicsShowHulls)) {3492 if (Menu::getInstance()->isOptionChecked(MenuOption::PhysicsShowHulls)) {
3479 renderDebugFlags = (RenderArgs::DebugFlags) (renderDebugFlags | (int) RenderArgs::RENDER_DEBUG_HULLS);3493 renderDebugFlags = (RenderArgs::DebugFlags) (renderDebugFlags | (int)RenderArgs::RENDER_DEBUG_HULLS);
3480 }3494 }
3481 if (Menu::getInstance()->isOptionChecked(MenuOption::PhysicsShowOwned)) {3495 if (Menu::getInstance()->isOptionChecked(MenuOption::PhysicsShowOwned)) {
3482 renderDebugFlags =3496 renderDebugFlags =
3483 (RenderArgs::DebugFlags) (renderDebugFlags | (int) RenderArgs::RENDER_DEBUG_SIMULATION_OWNERSHIP);3497 (RenderArgs::DebugFlags) (renderDebugFlags | (int)RenderArgs::RENDER_DEBUG_SIMULATION_OWNERSHIP);
3484 }3498 }
3485 renderArgs->_debugFlags = renderDebugFlags;3499 renderArgs->_debugFlags = renderDebugFlags;
3486 _entities.render(renderArgs);3500 _entities.render(renderArgs);
@@ -3505,8 +3519,8 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se · 18 unmodified lines
3505 pendingChanges.resetItem(WorldBoxRenderData::_item, worldBoxRenderPayload);3519 pendingChanges.resetItem(WorldBoxRenderData::_item, worldBoxRenderPayload);
3506 } else {3520 } else {
3507 3521
3508 pendingChanges.updateItem<WorldBoxRenderData>(WorldBoxRenderData::_item, 3522 pendingChanges.updateItem<WorldBoxRenderData>(WorldBoxRenderData::_item,
3509 [](WorldBoxRenderData& payload) { 3523 [](WorldBoxRenderData& payload) {
3510 payload._val++;3524 payload._val++;
3511 });3525 });
3512 }3526 }
@@ -3525,7 +3539,7 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se · 12 unmodified lines
3525 }3539 }
3526 3540
3527 {3541 {
3528 PerformanceTimer perfTimer("SceneProcessPendingChanges"); 3542 PerformanceTimer perfTimer("SceneProcessPendingChanges");
3529 _main3DScene->enqueuePendingChanges(pendingChanges);3543 _main3DScene->enqueuePendingChanges(pendingChanges);
3530 3544
3531 _main3DScene->processPendingChangesQueue();3545 _main3DScene->processPendingChangesQueue();
@@ -3549,6 +3563,8 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se · 17 unmodified lines
3549 renderContext._maxDrawnTransparentItems = sceneInterface->getEngineMaxDrawnTransparentItems();3563 renderContext._maxDrawnTransparentItems = sceneInterface->getEngineMaxDrawnTransparentItems();
3550 renderContext._maxDrawnOverlay3DItems = sceneInterface->getEngineMaxDrawnOverlay3DItems();3564 renderContext._maxDrawnOverlay3DItems = sceneInterface->getEngineMaxDrawnOverlay3DItems();
3551 3565
3566 renderContext._drawItemStatus = sceneInterface->doEngineDisplayItemStatus();
3567
3552 renderArgs->_shouldRender = LODManager::shouldRender;3568 renderArgs->_shouldRender = LODManager::shouldRender;
3553 3569
3554 renderContext.args = renderArgs;3570 renderContext.args = renderArgs;
@@ -3570,29 +3586,10 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se · 15 unmodified lines
3570 }3586 }
3571 //Render the sixense lasers3587 //Render the sixense lasers
3572 if (Menu::getInstance()->isOptionChecked(MenuOption::SixenseLasers)) {3588 if (Menu::getInstance()->isOptionChecked(MenuOption::SixenseLasers)) {
3573 _myAvatar->renderLaserPointers();3589 _myAvatar->renderLaserPointers(*renderArgs->_batch);
3574 }3590 }
3575 3591
3576 if (!selfAvatarOnly) {3592 if (!selfAvatarOnly) {
3577 _nodeBoundsDisplay.draw();
3578
3579 // render octree fades if they exist
3580 if (_octreeFades.size() > 0) {
3581 PerformanceTimer perfTimer("octreeFades");
3582 PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings),
3583 "Application::displaySide() ... octree fades...");
3584 _octreeFadesLock.lockForWrite();
3585 for(std::vector<OctreeFade>::iterator fade = _octreeFades.begin(); fade != _octreeFades.end();) {
3586 fade->render(renderArgs);
3587 if(fade->isDone()) {
3588 fade = _octreeFades.erase(fade);
3589 } else {
3590 ++fade;
3591 }
3592 }
3593 _octreeFadesLock.unlock();
3594 }
3595
3596 // give external parties a change to hook in3593 // give external parties a change to hook in
3597 {3594 {
3598 PerformanceTimer perfTimer("inWorldInterface");3595 PerformanceTimer perfTimer("inWorldInterface");
@@ -3693,7 +3690,7 @@ void Application::renderRearViewMirror(RenderArgs* renderArgs, const QRect& regi · 94 unmodified lines
3693 _mirrorCamera.setPosition(_myAvatar->getPosition() +3690 _mirrorCamera.setPosition(_myAvatar->getPosition() +
3694 _myAvatar->getOrientation() * glm::vec3(0.0f, 0.0f, -1.0f) * BILLBOARD_DISTANCE * _myAvatar->getScale());3691 _myAvatar->getOrientation() * glm::vec3(0.0f, 0.0f, -1.0f) * BILLBOARD_DISTANCE * _myAvatar->getScale());
3695 3692
3696 } else if (RearMirrorTools::rearViewZoomLevel.get() == BODY) {3693 } else if (!AvatarInputs::getInstance()->mirrorZoomed()) {
3697 _mirrorCamera.setPosition(_myAvatar->getChestPosition() +3694 _mirrorCamera.setPosition(_myAvatar->getChestPosition() +
3698 _myAvatar->getOrientation() * glm::vec3(0.0f, 0.0f, -1.0f) * MIRROR_REARVIEW_BODY_DISTANCE * _myAvatar->getScale());3695 _myAvatar->getOrientation() * glm::vec3(0.0f, 0.0f, -1.0f) * MIRROR_REARVIEW_BODY_DISTANCE * _myAvatar->getScale());
3699 3696
@@ -3743,10 +3740,6 @@ void Application::renderRearViewMirror(RenderArgs* renderArgs, const QRect& regi · 43 unmodified lines
3743 displaySide(renderArgs, _mirrorCamera, true, billboard);3740 displaySide(renderArgs, _mirrorCamera, true, billboard);
3744 glPopMatrix();3741 glPopMatrix();
3745 3742
3746 if (!billboard) {
3747 _rearMirrorTools->render(renderArgs, false, _glWidget->mapFromGlobal(QCursor::pos()));
3748 }
3749
3750 // reset Viewport and projection matrix3743 // reset Viewport and projection matrix
3751 glViewport(viewport[0], viewport[1], viewport[2], viewport[3]);3744 glViewport(viewport[0], viewport[1], viewport[2], viewport[3]);
3752 glDisable(GL_SCISSOR_TEST);3745 glDisable(GL_SCISSOR_TEST);
@@ -3888,17 +3881,6 @@ void Application::nodeKilled(SharedNodePointer node) { · 135 unmodified lines
3888 qCDebug(interfaceapp, "model server going away...... v[%f, %f, %f, %f]",3881 qCDebug(interfaceapp, "model server going away...... v[%f, %f, %f, %f]",
3889 (double)rootDetails.x, (double)rootDetails.y, (double)rootDetails.z, (double)rootDetails.s);3882 (double)rootDetails.x, (double)rootDetails.y, (double)rootDetails.z, (double)rootDetails.s);
3890 3883
3891 // Add the jurisditionDetails object to the list of "fade outs"
3892 if (!Menu::getInstance()->isOptionChecked(MenuOption::DontFadeOnOctreeServerChanges)) {
3893 OctreeFade fade(OctreeFade::FADE_OUT, NODE_KILLED_RED, NODE_KILLED_GREEN, NODE_KILLED_BLUE);
3894 fade.voxelDetails = rootDetails;
3895 const float slightly_smaller = 0.99f;
3896 fade.voxelDetails.s = fade.voxelDetails.s * slightly_smaller;
3897 _octreeFadesLock.lockForWrite();
3898 _octreeFades.push_back(fade);
3899 _octreeFadesLock.unlock();
3900 }
3901
3902 // If the model server is going away, remove it from our jurisdiction map so we don't send voxels to a dead server3884 // If the model server is going away, remove it from our jurisdiction map so we don't send voxels to a dead server
3903 _entityServerJurisdictions.lockForWrite();3885 _entityServerJurisdictions.lockForWrite();
3904 _entityServerJurisdictions.erase(_entityServerJurisdictions.find(nodeUUID));3886 _entityServerJurisdictions.erase(_entityServerJurisdictions.find(nodeUUID));
@@ -3975,16 +3957,6 @@ int Application::parseOctreeStats(const QByteArray& packet, const SharedNodePoin · 70 unmodified lines
3975 qPrintable(serverType),3957 qPrintable(serverType),
3976 (double)rootDetails.x, (double)rootDetails.y, (double)rootDetails.z, (double)rootDetails.s);3958 (double)rootDetails.x, (double)rootDetails.y, (double)rootDetails.z, (double)rootDetails.s);
3977 3959
3978 // Add the jurisditionDetails object to the list of "fade outs"
3979 if (!Menu::getInstance()->isOptionChecked(MenuOption::DontFadeOnOctreeServerChanges)) {
3980 OctreeFade fade(OctreeFade::FADE_OUT, NODE_ADDED_RED, NODE_ADDED_GREEN, NODE_ADDED_BLUE);
3981 fade.voxelDetails = rootDetails;
3982 const float slightly_smaller = 0.99f;
3983 fade.voxelDetails.s = fade.voxelDetails.s * slightly_smaller;
3984 _octreeFadesLock.lockForWrite();
3985 _octreeFades.push_back(fade);
3986 _octreeFadesLock.unlock();
3987 }
3988 } else {3960 } else {
3989 jurisdiction->unlock();3961 jurisdiction->unlock();
3990 }3962 }
@@ -4080,6 +4052,7 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri · 89 unmodified lines
4080 connect(scriptEngine, SIGNAL(finished(const QString&)), this, SLOT(scriptFinished(const QString&)));4052 connect(scriptEngine, SIGNAL(finished(const QString&)), this, SLOT(scriptFinished(const QString&)));
4081 4053
4082 connect(scriptEngine, SIGNAL(loadScript(const QString&, bool)), this, SLOT(loadScript(const QString&, bool)));4054 connect(scriptEngine, SIGNAL(loadScript(const QString&, bool)), this, SLOT(loadScript(const QString&, bool)));
4055 connect(scriptEngine, SIGNAL(reloadScript(const QString&, bool)), this, SLOT(reloadScript(const QString&, bool)));
4083 4056
4084 scriptEngine->registerGlobalObject("Overlays", &_overlays);4057 scriptEngine->registerGlobalObject("Overlays", &_overlays);
4085 qScriptRegisterMetaType(scriptEngine, OverlayPropertyResultToScriptValue, OverlayPropertyResultFromScriptValue);4058 qScriptRegisterMetaType(scriptEngine, OverlayPropertyResultToScriptValue, OverlayPropertyResultFromScriptValue);
@@ -4295,7 +4268,7 @@ bool Application::askToLoadScript(const QString& scriptFilenameOrURL) { · 209 unmodified lines
4295}4268}
4296 4269
4297ScriptEngine* Application::loadScript(const QString& scriptFilename, bool isUserLoaded,4270ScriptEngine* Application::loadScript(const QString& scriptFilename, bool isUserLoaded,
4298 bool loadScriptFromEditor, bool activateMainWindow) {4271 bool loadScriptFromEditor, bool activateMainWindow, bool reload) {
4299 4272
4300 if (isAboutToQuit()) {4273 if (isAboutToQuit()) {
4301 return NULL;4274 return NULL;
@@ -4324,7 +4297,7 @@ ScriptEngine* Application::loadScript(const QString& scriptFilename, bool isUser · 22 unmodified lines
4324 connect(scriptEngine, &ScriptEngine::errorLoadingScript, this, &Application::handleScriptLoadError);4297 connect(scriptEngine, &ScriptEngine::errorLoadingScript, this, &Application::handleScriptLoadError);
4325 4298
4326 // get the script engine object to load the script at the designated script URL4299 // get the script engine object to load the script at the designated script URL
4327 scriptEngine->loadURL(scriptUrl);4300 scriptEngine->loadURL(scriptUrl, reload);
4328 }4301 }
4329 4302
4330 // restore the main window's active state4303 // restore the main window's active state
@@ -4335,6 +4308,10 @@ ScriptEngine* Application::loadScript(const QString& scriptFilename, bool isUser · 4 unmodified lines
4335 return scriptEngine;4308 return scriptEngine;
4336}4309}
4337 4310
4311void Application::reloadScript(const QString& scriptName, bool isUserLoaded) {
4312 loadScript(scriptName, isUserLoaded, false, false, true);
4313}
4314
4338void Application::handleScriptEngineLoaded(const QString& scriptFilename) {4315void Application::handleScriptEngineLoaded(const QString& scriptFilename) {
4339 ScriptEngine* scriptEngine = qobject_cast<ScriptEngine*>(sender());4316 ScriptEngine* scriptEngine = qobject_cast<ScriptEngine*>(sender());
4340 4317
@@ -4362,14 +4339,25 @@ void Application::scriptFinished(const QString& scriptName) { · 21 unmodified lines
4362}4339}
4363 4340
4364void Application::stopAllScripts(bool restart) {4341void Application::stopAllScripts(bool restart) {
4365 // stops all current running scripts4342 if (restart) {
4343 // Delete all running scripts from cache so that they are re-downloaded when they are restarted
4344 auto scriptCache = DependencyManager::get<ScriptCache>();
4345 for (QHash<QString, ScriptEngine*>::const_iterator it = _scriptEnginesHash.constBegin();
4346 it != _scriptEnginesHash.constEnd(); it++) {
4347 if (!it.value()->isFinished()) {
4348 scriptCache->deleteScript(it.key());
4349 }
4350 }
4351 }
4352
4353 // Stop and possibly restart all currently running scripts
4366 for (QHash<QString, ScriptEngine*>::const_iterator it = _scriptEnginesHash.constBegin();4354 for (QHash<QString, ScriptEngine*>::const_iterator it = _scriptEnginesHash.constBegin();
4367 it != _scriptEnginesHash.constEnd(); it++) {4355 it != _scriptEnginesHash.constEnd(); it++) {
4368 if (it.value()->isFinished()) {4356 if (it.value()->isFinished()) {
4369 continue;4357 continue;
4370 }4358 }
4371 if (restart && it.value()->isUserLoaded()) {4359 if (restart && it.value()->isUserLoaded()) {
4372 connect(it.value(), SIGNAL(finished(const QString&)), SLOT(loadScript(const QString&)));4360 connect(it.value(), SIGNAL(finished(const QString&)), SLOT(reloadScript(const QString&)));
4373 }4361 }
4374 it.value()->stop();4362 it.value()->stop();
4375 qCDebug(interfaceapp) << "stopping script..." << it.key();4363 qCDebug(interfaceapp) << "stopping script..." << it.key();
@@ -4377,13 +4365,20 @@ void Application::stopAllScripts(bool restart) { · 1 unmodified line
4377 // HACK: ATM scripts cannot set/get their animation priorities, so we clear priorities4365 // HACK: ATM scripts cannot set/get their animation priorities, so we clear priorities
4378 // whenever a script stops in case it happened to have been setting joint rotations.4366 // whenever a script stops in case it happened to have been setting joint rotations.
4379 // TODO: expose animation priorities and provide a layered animation control system.4367 // TODO: expose animation priorities and provide a layered animation control system.
4368 _myAvatar->clearJointAnimationPriorities();
4380 _myAvatar->clearScriptableSettings();4369 _myAvatar->clearScriptableSettings();
4381}4370}
4382 4371
4383void Application::stopScript(const QString &scriptName) {4372void Application::stopScript(const QString &scriptName, bool restart) {
4384 const QString& scriptURLString = QUrl(scriptName).toString();4373 const QString& scriptURLString = QUrl(scriptName).toString();
4385 if (_scriptEnginesHash.contains(scriptURLString)) {4374 if (_scriptEnginesHash.contains(scriptURLString)) {
4386 _scriptEnginesHash.value(scriptURLString)->stop();4375 ScriptEngine* scriptEngine = _scriptEnginesHash[scriptURLString];
4376 if (restart) {
4377 auto scriptCache = DependencyManager::get<ScriptCache>();
4378 scriptCache->deleteScript(scriptName);
4379 connect(scriptEngine, SIGNAL(finished(const QString&)), SLOT(reloadScript(const QString&)));
4380 }
4381 scriptEngine->stop();
4387 qCDebug(interfaceapp) << "stopping script..." << scriptName;4382 qCDebug(interfaceapp) << "stopping script..." << scriptName;
4388 // HACK: ATM scripts cannot set/get their animation priorities, so we clear priorities4383 // HACK: ATM scripts cannot set/get their animation priorities, so we clear priorities
4389 // whenever a script stops in case it happened to have been setting joint rotations.4384 // whenever a script stops in case it happened to have been setting joint rotations.
@@ -4399,6 +4394,10 @@ void Application::reloadAllScripts() { · 9 unmodified lines
4399 stopAllScripts(true);4394 stopAllScripts(true);
4400}4395}
4401 4396
4397void Application::reloadOneScript(const QString& scriptName) {
4398 stopScript(scriptName, true);
4399}
4400
4402void Application::loadDefaultScripts() {4401void Application::loadDefaultScripts() {
4403 if (!_scriptEnginesHash.contains(DEFAULT_SCRIPTS_JS_URL)) {4402 if (!_scriptEnginesHash.contains(DEFAULT_SCRIPTS_JS_URL)) {
4404 loadScript(DEFAULT_SCRIPTS_JS_URL);4403 loadScript(DEFAULT_SCRIPTS_JS_URL);
@@ -4753,11 +4752,9 @@ void Application::postLambdaEvent(std::function<void()> f) { · 348 unmodified lines
4753}4752}
4754 4753
4755void Application::initPlugins() {4754void Application::initPlugins() {
4756 OculusManager::init();
4757}4755}
4758 4756
4759void Application::shutdownPlugins() {4757void Application::shutdownPlugins() {
4760 OculusManager::deinit();
4761}4758}
4762 4759
4763glm::vec3 Application::getHeadPosition() const {4760glm::vec3 Application::getHeadPosition() const {
@@ -4777,12 +4774,8 @@ QSize Application::getDeviceSize() const { · 13 unmodified lines
4777 return _glWidget->getDeviceSize();4774 return _glWidget->getDeviceSize();
4778}4775}
4779 4776
4780int Application::getTrueMouseX() const {4777ivec2 Application::getTrueMouse() const {
4781 return _glWidget->mapFromGlobal(QCursor::pos()).x();4778 return toGlm(_glWidget->mapFromGlobal(QCursor::pos()));
4782}
4783
4784int Application::getTrueMouseY() const {
4785 return _glWidget->mapFromGlobal(QCursor::pos()).y();
4786}4779}
4787 4780
4788bool Application::isThrottleRendering() const {4781bool Application::isThrottleRendering() const {
@@ -4812,3 +4805,25 @@ qreal Application::getDevicePixelRatio() { · 23 unmodified lines
4812 return _window ? _window->windowHandle()->devicePixelRatio() : 1.0;4805 return _window ? _window->windowHandle()->devicePixelRatio() : 1.0;
4813}4806}
4814 4807
4808mat4 Application::getEyeProjection(int eye) const {
4809 if (isHMDMode()) {
4810 return OculusManager::getEyeProjection(eye);
4811 }
4812
4813 return _viewFrustum.getProjection();
4814}
4815
4816mat4 Application::getEyePose(int eye) const {
4817 if (isHMDMode()) {
4818 return OculusManager::getEyePose(eye);
4819 }
4820
4821 return mat4();
4822}
4823
4824mat4 Application::getHeadPose() const {
4825 if (isHMDMode()) {
4826 return OculusManager::getHeadPose();
4827 }
4828 return mat4();
4829}