diff --git a/BUILD.md b/BUILD.md index 4d321146c3..feed677828 100644 --- a/BUILD.md +++ b/BUILD.md @@ -25,7 +25,7 @@ The above dependencies will be downloaded, built, linked and included automatica These are not placed in your normal build tree when doing an out of source build so that they do not need to be re-downloaded and re-compiled every time the CMake build folder is cleared. Should you want to force a re-download and re-compile of a specific external, you can simply remove that directory from the appropriate subfolder in `build/ext`. Should you want to force a re-download and re-compile of all externals, just remove the `build/ext` folder. -If you would like to use a specific install of a dependency instead of the version that would be grabbed as a CMake ExternalProject, you can pass -DUSE_LOCAL_$NAME=0 (where $NAME is the name of the subfolder in [cmake/externals](cmake/externals)) when you run CMake to tell it not to get that dependency as an external project. +If you would like to use a specific install of a dependency instead of the version that would be grabbed as a CMake ExternalProject, you can pass -DUSE\_LOCAL\_$NAME=0 (where $NAME is the name of the subfolder in [cmake/externals](cmake/externals)) when you run CMake to tell it not to get that dependency as an external project. ### OS Specific Build Guides diff --git a/assignment-client/src/scripts/EntityScriptServer.cpp b/assignment-client/src/scripts/EntityScriptServer.cpp index 2bfcdcdf8c..0ced0a632e 100644 --- a/assignment-client/src/scripts/EntityScriptServer.cpp +++ b/assignment-client/src/scripts/EntityScriptServer.cpp @@ -85,6 +85,7 @@ EntityScriptServer::EntityScriptServer(ReceivedMessage& message) : ThreadedAssig packetReceiver.registerListener(PacketType::ReloadEntityServerScript, this, "handleReloadEntityServerScriptPacket"); packetReceiver.registerListener(PacketType::EntityScriptGetStatus, this, "handleEntityScriptGetStatusPacket"); packetReceiver.registerListener(PacketType::EntityServerScriptLog, this, "handleEntityServerScriptLogPacket"); + packetReceiver.registerListener(PacketType::EntityScriptCallMethod, this, "handleEntityScriptCallMethodPacket"); static const int LOG_INTERVAL = MSECS_PER_SECOND / 10; auto timer = new QTimer(this); @@ -231,6 +232,27 @@ void EntityScriptServer::pushLogs() { } } +void EntityScriptServer::handleEntityScriptCallMethodPacket(QSharedPointer receivedMessage, SharedNodePointer senderNode) { + + if (_entitiesScriptEngine && _entityViewer.getTree() && !_shuttingDown) { + auto entityID = QUuid::fromRfc4122(receivedMessage->read(NUM_BYTES_RFC4122_UUID)); + + auto method = receivedMessage->readString(); + + quint16 paramCount; + receivedMessage->readPrimitive(¶mCount); + + QStringList params; + for (int param = 0; param < paramCount; param++) { + auto paramString = receivedMessage->readString(); + params << paramString; + } + + _entitiesScriptEngine->callEntityScriptMethod(entityID, method, params, senderNode->getUUID()); + } +} + + void EntityScriptServer::run() { // make sure we request our script once the agent connects to the domain auto nodeList = DependencyManager::get(); diff --git a/assignment-client/src/scripts/EntityScriptServer.h b/assignment-client/src/scripts/EntityScriptServer.h index e6bd12460b..f9c5e921f0 100644 --- a/assignment-client/src/scripts/EntityScriptServer.h +++ b/assignment-client/src/scripts/EntityScriptServer.h @@ -54,6 +54,9 @@ private slots: void pushLogs(); + void handleEntityScriptCallMethodPacket(QSharedPointer message, SharedNodePointer senderNode); + + private: void negotiateAudioFormat(); void selectAudioFormat(const QString& selectedCodecName); diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt index 08af8601c5..4c1b8d8d92 100644 --- a/interface/CMakeLists.txt +++ b/interface/CMakeLists.txt @@ -210,6 +210,7 @@ endif() # link required hifi libraries link_hifi_libraries( shared octree ktx gpu gl gpu-gl procedural model render + pointers recording fbx networking model-networking entities avatars trackers audio audio-client animation script-engine physics render-utils entities-renderer avatars-renderer ui auto-updater midi diff --git a/interface/resources/qml/controls-uit/Button.qml b/interface/resources/qml/controls-uit/Button.qml index 5acc31dfd0..c068fdcfaf 100644 --- a/interface/resources/qml/controls-uit/Button.qml +++ b/interface/resources/qml/controls-uit/Button.qml @@ -11,6 +11,7 @@ import QtQuick 2.5 import QtQuick.Controls 1.4 as Original import QtQuick.Controls.Styles 1.4 +import TabletScriptingInterface 1.0 import "../styles-uit" @@ -26,6 +27,16 @@ Original.Button { HifiConstants { id: hifi } + onHoveredChanged: { + if (hovered) { + tabletInterface.playSound(TabletEnums.ButtonHover); + } + } + + onClicked: { + tabletInterface.playSound(TabletEnums.ButtonClick); + } + style: ButtonStyle { background: Rectangle { diff --git a/interface/resources/qml/controls-uit/CheckBox.qml b/interface/resources/qml/controls-uit/CheckBox.qml index b279b7ca8d..22b25671c3 100644 --- a/interface/resources/qml/controls-uit/CheckBox.qml +++ b/interface/resources/qml/controls-uit/CheckBox.qml @@ -14,6 +14,8 @@ import QtQuick.Controls.Styles 1.4 import "../styles-uit" +import TabletScriptingInterface 1.0 + Original.CheckBox { id: checkBox @@ -28,6 +30,15 @@ Original.CheckBox { readonly property int checkRadius: 2 activeFocusOnPress: true + onClicked: { + tabletInterface.playSound(TabletEnums.ButtonClick); + } + +// TODO: doesnt works for QQC1. check with QQC2 +// onHovered: { +// tabletInterface.playSound(TabletEnums.ButtonHover); +// } + style: CheckBoxStyle { indicator: Rectangle { id: box diff --git a/interface/resources/qml/controls-uit/CheckBoxQQC2.qml b/interface/resources/qml/controls-uit/CheckBoxQQC2.qml index 92bad04d01..32d69cf339 100644 --- a/interface/resources/qml/controls-uit/CheckBoxQQC2.qml +++ b/interface/resources/qml/controls-uit/CheckBoxQQC2.qml @@ -13,6 +13,7 @@ import QtQuick.Controls 2.2 import "../styles-uit" import "../controls-uit" as HiFiControls +import TabletScriptingInterface 1.0 CheckBox { id: checkBox @@ -32,6 +33,17 @@ CheckBox { readonly property int checkSize: Math.max(boxSize - 8, 10) readonly property int checkRadius: isRound ? checkSize / 2 : 2 focusPolicy: Qt.ClickFocus + hoverEnabled: true + + onClicked: { + tabletInterface.playSound(TabletEnums.ButtonClick); + } + + onHoveredChanged: { + if (hovered) { + tabletInterface.playSound(TabletEnums.ButtonHover); + } + } indicator: Rectangle { id: box diff --git a/interface/resources/qml/controls-uit/GlyphButton.qml b/interface/resources/qml/controls-uit/GlyphButton.qml index ac353b5a52..bc7bc636fe 100644 --- a/interface/resources/qml/controls-uit/GlyphButton.qml +++ b/interface/resources/qml/controls-uit/GlyphButton.qml @@ -12,6 +12,7 @@ import QtQuick 2.5 import QtQuick.Controls 1.4 as Original import QtQuick.Controls.Styles 1.4 +import TabletScriptingInterface 1.0 import "../styles-uit" @@ -24,6 +25,16 @@ Original.Button { width: 120 height: 28 + onHoveredChanged: { + if (hovered) { + tabletInterface.playSound(TabletEnums.ButtonHover); + } + } + + onClicked: { + tabletInterface.playSound(TabletEnums.ButtonClick); + } + style: ButtonStyle { background: Rectangle { diff --git a/interface/resources/qml/controls-uit/Key.qml b/interface/resources/qml/controls-uit/Key.qml index 0c888d1a0a..eda9c03fa2 100644 --- a/interface/resources/qml/controls-uit/Key.qml +++ b/interface/resources/qml/controls-uit/Key.qml @@ -1,4 +1,5 @@ import QtQuick 2.0 +import TabletScriptingInterface 1.0 Item { id: keyItem @@ -32,8 +33,15 @@ Item { } } + onContainsMouseChanged: { + if (containsMouse) { + tabletInterface.playSound(TabletEnums.ButtonHover); + } + } + onClicked: { mouse.accepted = true; + tabletInterface.playSound(TabletEnums.ButtonClick); webEntity.synthesizeKeyPress(glyph); webEntity.synthesizeKeyPress(glyph, mirrorText); diff --git a/interface/resources/qml/controls-uit/RadioButton.qml b/interface/resources/qml/controls-uit/RadioButton.qml index ab11ec68b1..65d36d2dcb 100644 --- a/interface/resources/qml/controls-uit/RadioButton.qml +++ b/interface/resources/qml/controls-uit/RadioButton.qml @@ -15,6 +15,8 @@ import QtQuick.Controls.Styles 1.4 import "../styles-uit" import "../controls-uit" as HifiControls +import TabletScriptingInterface 1.0 + Original.RadioButton { id: radioButton HifiConstants { id: hifi } @@ -27,6 +29,15 @@ Original.RadioButton { readonly property int checkSize: 10 readonly property int checkRadius: 2 + onClicked: { + tabletInterface.playSound(TabletEnums.ButtonClick); + } + +// TODO: doesnt works for QQC1. check with QQC2 +// onHovered: { +// tabletInterface.playSound(TabletEnums.ButtonHover); +// } + style: RadioButtonStyle { indicator: Rectangle { id: box diff --git a/interface/resources/qml/dialogs/preferences/ButtonPreference.qml b/interface/resources/qml/dialogs/preferences/ButtonPreference.qml index 06332bd1be..3a5c850031 100644 --- a/interface/resources/qml/dialogs/preferences/ButtonPreference.qml +++ b/interface/resources/qml/dialogs/preferences/ButtonPreference.qml @@ -9,6 +9,7 @@ // import QtQuick 2.5 +import TabletScriptingInterface 1.0 import "../../controls-uit" @@ -22,7 +23,16 @@ Preference { Button { id: button - onClicked: preference.trigger() + onHoveredChanged: { + if (hovered) { + tabletInterface.playSound(TabletEnums.ButtonHover); + } + } + + onClicked: { + preference.trigger(); + tabletInterface.playSound(TabletEnums.ButtonClick); + } width: 180 anchors.bottom: parent.bottom } diff --git a/interface/resources/qml/dialogs/preferences/CheckBoxPreference.qml b/interface/resources/qml/dialogs/preferences/CheckBoxPreference.qml index f8f992735c..8904896ab7 100644 --- a/interface/resources/qml/dialogs/preferences/CheckBoxPreference.qml +++ b/interface/resources/qml/dialogs/preferences/CheckBoxPreference.qml @@ -9,6 +9,7 @@ // import QtQuick 2.5 +import TabletScriptingInterface 1.0 import "../../controls-uit" @@ -38,6 +39,16 @@ Preference { CheckBox { id: checkBox + onHoveredChanged: { + if (hovered) { + tabletInterface.playSound(TabletEnums.ButtonHover); + } + } + + onClicked: { + tabletInterface.playSound(TabletEnums.ButtonClick); + } + anchors { top: spacer.bottom left: parent.left diff --git a/interface/resources/qml/hifi/Card.qml b/interface/resources/qml/hifi/Card.qml index 678245910b..fc7b8c6200 100644 --- a/interface/resources/qml/hifi/Card.qml +++ b/interface/resources/qml/hifi/Card.qml @@ -14,6 +14,8 @@ import Hifi 1.0 import QtQuick 2.5 import QtGraphicalEffects 1.0 +import TabletScriptingInterface 1.0 + import "toolbars" import "../styles-uit" @@ -243,9 +245,15 @@ Item { MouseArea { anchors.fill: parent; acceptedButtons: Qt.LeftButton; - onClicked: goFunction("hifi://" + hifiUrl); + onClicked: { + tabletInterface.playSound(TabletEnums.ButtonClick); + goFunction("hifi://" + hifiUrl); + } hoverEnabled: true; - onEntered: hoverThunk(); + onEntered: { + tabletInterface.playSound(TabletEnums.ButtonHover); + hoverThunk(); + } onExited: unhoverThunk(); } StateImage { @@ -261,6 +269,7 @@ Item { } } function go() { + tabletInterface.playSound(TabletEnums.ButtonClick); goFunction(drillDownToPlace ? ("/places/" + placeName) : ("/user_stories/" + storyId)); } MouseArea { diff --git a/interface/resources/qml/hifi/SkyboxChanger.qml b/interface/resources/qml/hifi/SkyboxChanger.qml index a4798ba959..2aa0460e15 100644 --- a/interface/resources/qml/hifi/SkyboxChanger.qml +++ b/interface/resources/qml/hifi/SkyboxChanger.qml @@ -1,6 +1,6 @@ // -// skyboxchanger.qml -// +// SkyboxChanger.qml +// qml/hifi // // Created by Cain Kilgore on 9th August 2017 // Copyright 2017 High Fidelity, Inc. @@ -9,33 +9,97 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -import QtQuick.Layouts 1.3 +import QtQuick 2.5 +import "../styles-uit" +import "../controls-uit" as HifiControls -Rectangle { +Item { id: root; + HifiConstants { id: hifi; } + + property var defaultThumbnails: []; + property var defaultFulls: []; + + SkyboxSelectionModel { + id: skyboxModel; + } + + function getSkyboxes() { + var xmlhttp = new XMLHttpRequest(); + var url = "http://mpassets.highfidelity.com/5fbdbeef-1cf8-4954-811d-3d4acbba4dc9-v1/skyboxes.json"; + xmlhttp.onreadystatechange = function() { + if (xmlhttp.readyState === XMLHttpRequest.DONE && xmlhttp.status === 200) { + sortSkyboxes(xmlhttp.responseText); + } + } + xmlhttp.open("GET", url, true); + xmlhttp.send(); + } + + function sortSkyboxes(response) { + var arr = JSON.parse(response); + for (var i = 0; i < arr.length; i++) { + defaultThumbnails.push(arr[i].thumb); + defaultFulls.push(arr[i].full); + } + setDefaultSkyboxes(); + } + + function setDefaultSkyboxes() { + for (var i = 0; i < skyboxModel.count; i++) { + skyboxModel.setProperty(i, "thumbnailPath", defaultThumbnails[i]); + skyboxModel.setProperty(i, "fullSkyboxPath", defaultFulls[i]); + } + } + + function shuffle(array) { + var tmp, current, top = array.length; + if (top) { + while (--top) { + current = Math.floor(Math.random() * (top + 1)); + tmp = array[current]; + array[current] = array[top]; + array[top] = tmp; + } + } + return array; + } - color: hifi.colors.baseGray; - + function chooseRandom() { + for (var a = [], i=0; i < defaultFulls.length; ++i) { + a[i] = i; + } + + a = shuffle(a); + + for (var i = 0; i < skyboxModel.count; i++) { + skyboxModel.setProperty(i, "thumbnailPath", defaultThumbnails[a[i]]); + skyboxModel.setProperty(i, "fullSkyboxPath", defaultFulls[a[i]]); + } + } + + + Component.onCompleted: { + getSkyboxes(); + } + Item { id: titleBarContainer; - // Size width: parent.width; - height: 50; - // Anchors + height: childrenRect.height; anchors.left: parent.left; anchors.top: parent.top; - - RalewaySemiBold { + anchors.right: parent.right; + anchors.topMargin: 20; + RalewayBold { id: titleBarText; text: "Skybox Changer"; - // Text size size: hifi.fontSizes.overlayTitle; - // Anchors - anchors.fill: parent; - anchors.leftMargin: 16; - // Style + anchors.top: parent.top; + anchors.left: parent.left; + anchors.leftMargin: 40 + height: paintedHeight; color: hifi.colors.lightGrayText; - // Alignment horizontalAlignment: Text.AlignHCenter; verticalAlignment: Text.AlignVCenter; } @@ -43,131 +107,68 @@ Rectangle { id: titleBarDesc; text: "Click an image to choose a new Skybox."; wrapMode: Text.Wrap - // Text size size: 14; - // Anchors - anchors.fill: parent; - anchors.top: titleBarText.bottom - anchors.leftMargin: 16; - anchors.rightMargin: 16; - // Style + anchors.top: titleBarText.bottom; + anchors.left: parent.left; + anchors.leftMargin: 40 + height: paintedHeight; color: hifi.colors.lightGrayText; - // Alignment horizontalAlignment: Text.AlignHCenter; verticalAlignment: Text.AlignVCenter; - } + } + HifiControls.Button { + id: randomButton + text: "Randomize" + color: hifi.buttons.blue + colorScheme: root.colorScheme + width: 100 + anchors.right: parent.right + anchors.top: parent.top + anchors.topMargin: 5 + anchors.rightMargin: 40 + onClicked: { + chooseRandom() + } + } } - // This RowLayout could be a GridLayout instead for further expandability. - // As this SkyboxChanger task only required 6 images, implementing GridLayout wasn't necessary. - // In the future if this is to be expanded to add more Skyboxes, it might be worth changing this. - RowLayout { - id: row1 + GridView { + id: gridView + interactive: false + clip: true anchors.top: titleBarContainer.bottom - anchors.left: parent.left - anchors.leftMargin: 30 - Layout.fillWidth: true - anchors.topMargin: 30 - spacing: 10 - Image { - width: 200; height: 200 - fillMode: Image.Stretch - source: "http://mpassets.highfidelity.com/05904016-8f7d-4dfc-88e1-2bf9ba3fac20-v1/thumbnails/thumb_1.jpg" - clip: true - id: preview1 - MouseArea { + anchors.topMargin: 20 + anchors.horizontalCenter: parent.horizontalCenter + width: 400 + height: parent.height + currentIndex: -1 + + cellWidth: 200 + cellHeight: 200 + model: skyboxModel + delegate: Item { + width: gridView.cellWidth + height: gridView.cellHeight + Item { anchors.fill: parent - onClicked: { - sendToScript({method: 'changeSkybox', url: 'http://mpassets.highfidelity.com/05904016-8f7d-4dfc-88e1-2bf9ba3fac20-v1/skyboxes/1.jpg'}); + Image { + source: thumbnailPath + anchors.horizontalCenter: parent.horizontalCenter + anchors.verticalCenter: parent.verticalCenter + fillMode: Image.Stretch + sourceSize.width: parent.width + sourceSize.height: parent.height + mipmap: true } } - Layout.fillWidth: true - } - Image { - width: 200; height: 200 - fillMode: Image.Stretch - source: "http://mpassets.highfidelity.com/05904016-8f7d-4dfc-88e1-2bf9ba3fac20-v1/thumbnails/thumb_2.jpg" - clip: true - id: preview2 MouseArea { anchors.fill: parent onClicked: { - sendToScript({method: 'changeSkybox', url: 'http://mpassets.highfidelity.com/05904016-8f7d-4dfc-88e1-2bf9ba3fac20-v1/skyboxes/2.png'}); - } - } - } - } - RowLayout { - id: row2 - anchors.top: row1.bottom - anchors.topMargin: 10 - anchors.left: parent.left - Layout.fillWidth: true - anchors.leftMargin: 30 - spacing: 10 - Image { - width: 200; height: 200 - fillMode: Image.Stretch - source: "http://mpassets.highfidelity.com/05904016-8f7d-4dfc-88e1-2bf9ba3fac20-v1/thumbnails/thumb_3.jpg" - clip: true - id: preview3 - MouseArea { - anchors.fill: parent - onClicked: { - sendToScript({method: 'changeSkybox', url: 'http://mpassets.highfidelity.com/05904016-8f7d-4dfc-88e1-2bf9ba3fac20-v1/skyboxes/3.jpg'}); - } - } - } - Image { - width: 200; height: 200 - fillMode: Image.Stretch - source: "http://mpassets.highfidelity.com/05904016-8f7d-4dfc-88e1-2bf9ba3fac20-v1/thumbnails/thumb_4.jpg" - clip: true - id: preview4 - MouseArea { - anchors.fill: parent - onClicked: { - sendToScript({method: 'changeSkybox', url: 'http://mpassets.highfidelity.com/05904016-8f7d-4dfc-88e1-2bf9ba3fac20-v1/skyboxes/4.jpg'}); - } - } - } - } - RowLayout { - id: row3 - anchors.top: row2.bottom - anchors.topMargin: 10 - anchors.left: parent.left - Layout.fillWidth: true - anchors.leftMargin: 30 - spacing: 10 - Image { - width: 200; height: 200 - fillMode: Image.Stretch - source: "http://mpassets.highfidelity.com/05904016-8f7d-4dfc-88e1-2bf9ba3fac20-v1/thumbnails/thumb_5.jpg" - clip: true - id: preview5 - MouseArea { - anchors.fill: parent - onClicked: { - sendToScript({method: 'changeSkybox', url: 'http://mpassets.highfidelity.com/05904016-8f7d-4dfc-88e1-2bf9ba3fac20-v1/skyboxes/5.png'}); - } - } - } - Image { - width: 200; height: 200 - fillMode: Image.Stretch - source: "http://mpassets.highfidelity.com/05904016-8f7d-4dfc-88e1-2bf9ba3fac20-v1/thumbnails/thumb_6.jpg" - clip: true - id: preview6 - MouseArea { - anchors.fill: parent - onClicked: { - sendToScript({method: 'changeSkybox', url: 'http://mpassets.highfidelity.com/05904016-8f7d-4dfc-88e1-2bf9ba3fac20-v1/skyboxes/6.jpg'}); + sendToScript({method: 'changeSkybox', url: fullSkyboxPath}); } } } } signal sendToScript(var message); - -} +} \ No newline at end of file diff --git a/interface/resources/qml/hifi/SkyboxSelectionModel.qml b/interface/resources/qml/hifi/SkyboxSelectionModel.qml new file mode 100644 index 0000000000..45a964fcb3 --- /dev/null +++ b/interface/resources/qml/hifi/SkyboxSelectionModel.qml @@ -0,0 +1,40 @@ +// +// SkyboxSelectionModel.qml +// qml/hifi +// +// Created by Cain Kilgore on 21st October 2017 +// Copyright 2017 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +import QtQuick 2.5 + +ListModel { + id: root; + ListElement{ + thumbnailPath: "http://mpassets.highfidelity.com/05904016-8f7d-4dfc-88e1-2bf9ba3fac20-v1/thumbnails/thumb_1.jpg" + fullSkyboxPath: "http://mpassets.highfidelity.com/05904016-8f7d-4dfc-88e1-2bf9ba3fac20-v1/skyboxes/1.jpg" + } + ListElement{ + thumbnailPath: "http://mpassets.highfidelity.com/05904016-8f7d-4dfc-88e1-2bf9ba3fac20-v1/thumbnails/thumb_1.jpg" + fullSkyboxPath: "http://mpassets.highfidelity.com/05904016-8f7d-4dfc-88e1-2bf9ba3fac20-v1/skyboxes/1.jpg" + } + ListElement{ + thumbnailPath: "http://mpassets.highfidelity.com/05904016-8f7d-4dfc-88e1-2bf9ba3fac20-v1/thumbnails/thumb_1.jpg" + fullSkyboxPath: "http://mpassets.highfidelity.com/05904016-8f7d-4dfc-88e1-2bf9ba3fac20-v1/skyboxes/1.jpg" + } + ListElement{ + thumbnailPath: "http://mpassets.highfidelity.com/05904016-8f7d-4dfc-88e1-2bf9ba3fac20-v1/thumbnails/thumb_1.jpg" + fullSkyboxPath: "http://mpassets.highfidelity.com/05904016-8f7d-4dfc-88e1-2bf9ba3fac20-v1/skyboxes/1.jpg" + } + ListElement{ + thumbnailPath: "http://mpassets.highfidelity.com/05904016-8f7d-4dfc-88e1-2bf9ba3fac20-v1/thumbnails/thumb_1.jpg" + fullSkyboxPath: "http://mpassets.highfidelity.com/05904016-8f7d-4dfc-88e1-2bf9ba3fac20-v1/skyboxes/1.jpg" + } + ListElement{ + thumbnailPath: "http://mpassets.highfidelity.com/05904016-8f7d-4dfc-88e1-2bf9ba3fac20-v1/thumbnails/thumb_1.jpg" + fullSkyboxPath: "http://mpassets.highfidelity.com/05904016-8f7d-4dfc-88e1-2bf9ba3fac20-v1/skyboxes/1.jpg" + } +} diff --git a/interface/resources/qml/hifi/audio/MicBar.qml b/interface/resources/qml/hifi/audio/MicBar.qml index e757d7cadf..b6699d6ceb 100644 --- a/interface/resources/qml/hifi/audio/MicBar.qml +++ b/interface/resources/qml/hifi/audio/MicBar.qml @@ -14,6 +14,8 @@ import QtQuick.Controls 1.4 import QtQuick.Layouts 1.3 import QtGraphicalEffects 1.0 +import TabletScriptingInterface 1.0 + Rectangle { readonly property var level: Audio.inputLevel; @@ -57,8 +59,16 @@ Rectangle { hoverEnabled: true; scrollGestureEnabled: false; - onClicked: { Audio.muted = !Audio.muted; } + onClicked: { + Audio.muted = !Audio.muted; + tabletInterface.playSound(TabletEnums.ButtonClick); + } drag.target: dragTarget; + onContainsMouseChanged: { + if (containsMouse) { + tabletInterface.playSound(TabletEnums.ButtonHover); + } + } } QtObject { diff --git a/interface/resources/qml/hifi/tablet/NewEntityButton.qml b/interface/resources/qml/hifi/tablet/NewEntityButton.qml index e5684fa791..7f838717df 100644 --- a/interface/resources/qml/hifi/tablet/NewEntityButton.qml +++ b/interface/resources/qml/hifi/tablet/NewEntityButton.qml @@ -1,5 +1,6 @@ import QtQuick 2.0 import QtGraphicalEffects 1.0 +import TabletScriptingInterface 1.0 Item { id: newEntityButton @@ -122,9 +123,11 @@ Item { hoverEnabled: true enabled: true onClicked: { + tabletInterface.playSound(TabletEnums.ButtonClick); newEntityButton.clicked(); } onEntered: { + tabletInterface.playSound(TabletEnums.ButtonHover); newEntityButton.state = "hover state"; } onExited: { diff --git a/interface/resources/qml/hifi/tablet/TabletButton.qml b/interface/resources/qml/hifi/tablet/TabletButton.qml index 98a73eb0fd..169c7acec1 100644 --- a/interface/resources/qml/hifi/tablet/TabletButton.qml +++ b/interface/resources/qml/hifi/tablet/TabletButton.qml @@ -1,5 +1,6 @@ import QtQuick 2.0 import QtGraphicalEffects 1.0 +import TabletScriptingInterface 1.0 Item { id: tabletButton @@ -130,11 +131,13 @@ Item { } tabletButton.clicked(); if (tabletRoot) { - tabletRoot.playButtonClickSound(); + tabletInterface.playSound(TabletEnums.ButtonClick); } } onEntered: { tabletButton.isEntered = true; + tabletInterface.playSound(TabletEnums.ButtonHover); + if (tabletButton.isActive) { tabletButton.state = "hover active state"; } else { diff --git a/interface/resources/qml/hifi/tablet/TabletMenuView.qml b/interface/resources/qml/hifi/tablet/TabletMenuView.qml index ecfb653923..4a4a6b7f87 100644 --- a/interface/resources/qml/hifi/tablet/TabletMenuView.qml +++ b/interface/resources/qml/hifi/tablet/TabletMenuView.qml @@ -9,9 +9,13 @@ // import QtQuick 2.5 +import QtQuick.Controls 1.4 +import QtQuick.Controls.Styles 1.4 +import TabletScriptingInterface 1.0 import "../../styles-uit" import "." + FocusScope { id: root implicitHeight: background.height @@ -69,12 +73,17 @@ FocusScope { onImplicitWidthChanged: listView !== null ? listView.recalcSize() : 0 MouseArea { + enabled: name !== "" && item.enabled anchors.fill: parent hoverEnabled: true - onEntered: listView.currentIndex = index + onEntered: { + tabletInterface.playSound(TabletEnums.ButtonHover); + listView.currentIndex = index + } + onClicked: { - root.selected(item) - tabletRoot.playButtonClickSound(); + tabletInterface.playSound(TabletEnums.ButtonClick); + root.selected(item); } } } diff --git a/interface/resources/qml/hifi/tablet/TabletRoot.qml b/interface/resources/qml/hifi/tablet/TabletRoot.qml index 5084377273..ba9d06eee3 100644 --- a/interface/resources/qml/hifi/tablet/TabletRoot.qml +++ b/interface/resources/qml/hifi/tablet/TabletRoot.qml @@ -1,6 +1,7 @@ import QtQuick 2.0 import Hifi 1.0 import QtQuick.Controls 1.4 + import "../../dialogs" import "../../controls" diff --git a/interface/resources/sounds/Button01.wav b/interface/resources/sounds/Button01.wav new file mode 100644 index 0000000000..e1c8111c6f Binary files /dev/null and b/interface/resources/sounds/Button01.wav differ diff --git a/interface/resources/sounds/Button02.wav b/interface/resources/sounds/Button02.wav new file mode 100644 index 0000000000..f4bac99e38 Binary files /dev/null and b/interface/resources/sounds/Button02.wav differ diff --git a/interface/resources/sounds/Button03.wav b/interface/resources/sounds/Button03.wav new file mode 100644 index 0000000000..1eb28b7daf Binary files /dev/null and b/interface/resources/sounds/Button03.wav differ diff --git a/interface/resources/sounds/Button04.wav b/interface/resources/sounds/Button04.wav new file mode 100644 index 0000000000..cd76d0174c Binary files /dev/null and b/interface/resources/sounds/Button04.wav differ diff --git a/interface/resources/sounds/Button05.wav b/interface/resources/sounds/Button05.wav new file mode 100644 index 0000000000..72d2622e9d Binary files /dev/null and b/interface/resources/sounds/Button05.wav differ diff --git a/interface/resources/sounds/Button06.wav b/interface/resources/sounds/Button06.wav new file mode 100644 index 0000000000..30a097ce45 Binary files /dev/null and b/interface/resources/sounds/Button06.wav differ diff --git a/interface/resources/sounds/Button07.wav b/interface/resources/sounds/Button07.wav new file mode 100644 index 0000000000..5d285ffa07 Binary files /dev/null and b/interface/resources/sounds/Button07.wav differ diff --git a/interface/resources/sounds/Collapse.wav b/interface/resources/sounds/Collapse.wav new file mode 100644 index 0000000000..7a169d506c Binary files /dev/null and b/interface/resources/sounds/Collapse.wav differ diff --git a/interface/resources/sounds/Expand.wav b/interface/resources/sounds/Expand.wav new file mode 100644 index 0000000000..7f7710e7f6 Binary files /dev/null and b/interface/resources/sounds/Expand.wav differ diff --git a/interface/resources/sounds/Tab01.wav b/interface/resources/sounds/Tab01.wav new file mode 100644 index 0000000000..38cf7decc4 Binary files /dev/null and b/interface/resources/sounds/Tab01.wav differ diff --git a/interface/resources/sounds/Tab02.wav b/interface/resources/sounds/Tab02.wav new file mode 100644 index 0000000000..04ad9b909f Binary files /dev/null and b/interface/resources/sounds/Tab02.wav differ diff --git a/interface/resources/sounds/Tab03.wav b/interface/resources/sounds/Tab03.wav new file mode 100644 index 0000000000..db7545a365 Binary files /dev/null and b/interface/resources/sounds/Tab03.wav differ diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 4ebcd3943f..f61f7e1f93 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1848,6 +1848,9 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo _rayPickManager.setPrecisionPicking(rayPickID, value); }); + // Preload Tablet sounds + DependencyManager::get()->preloadSounds(); + qCDebug(interfaceapp) << "Metaverse session ID is" << uuidStringWithoutCurlyBraces(accountManager->getSessionID()); } @@ -2325,6 +2328,8 @@ void Application::initializeUi() { surfaceContext->setContextProperty("Account", AccountScriptingInterface::getInstance()); surfaceContext->setContextProperty("Tablet", DependencyManager::get().data()); + // Tablet inteference with Tablet.qml. Need to avoid this in QML space + surfaceContext->setContextProperty("tabletInterface", DependencyManager::get().data()); surfaceContext->setContextProperty("DialogsManager", _dialogsManagerScriptingInterface); surfaceContext->setContextProperty("GlobalServices", GlobalServicesScriptingInterface::getInstance()); surfaceContext->setContextProperty("FaceTracker", DependencyManager::get().data()); @@ -2393,8 +2398,8 @@ void Application::initializeUi() { } void Application::updateCamera(RenderArgs& renderArgs) { - PROFILE_RANGE(render, "/updateCamera"); - PerformanceTimer perfTimer("CameraUpdates"); + PROFILE_RANGE(render, __FUNCTION__); + PerformanceTimer perfTimer("updateCamera"); glm::vec3 boomOffset; auto myAvatar = getMyAvatar(); @@ -2610,7 +2615,7 @@ void Application::resizeGL() { } void Application::handleSandboxStatus(QNetworkReply* reply) { - PROFILE_RANGE(render, "HandleSandboxStatus"); + PROFILE_RANGE(render, __FUNCTION__); bool sandboxIsRunning = SandboxUtils::readStatus(reply->readAll()); qDebug() << "HandleSandboxStatus" << sandboxIsRunning; @@ -4639,7 +4644,6 @@ void Application::updateDialogs(float deltaTime) const { static bool domainLoadingInProgress = false; void Application::update(float deltaTime) { - PROFILE_RANGE_EX(app, __FUNCTION__, 0xffff0000, (uint64_t)_renderFrameCount + 1); if (!_physicsEnabled) { @@ -4834,11 +4838,11 @@ void Application::update(float deltaTime) { QSharedPointer avatarManager = DependencyManager::get(); { - PROFILE_RANGE_EX(simulation_physics, "Physics", 0xffff0000, (uint64_t)getActiveDisplayPlugin()->presentCount()); + PROFILE_RANGE(simulation_physics, "Physics"); PerformanceTimer perfTimer("physics"); if (_physicsEnabled) { { - PROFILE_RANGE_EX(simulation_physics, "UpdateStates", 0xffffff00, (uint64_t)getActiveDisplayPlugin()->presentCount()); + PROFILE_RANGE(simulation_physics, "PreStep"); PerformanceTimer perfTimer("updateStates)"); static VectorOfMotionStates motionStates; @@ -4872,14 +4876,14 @@ void Application::update(float deltaTime) { }); } { - PROFILE_RANGE_EX(simulation_physics, "StepSimulation", 0xffff8000, (uint64_t)getActiveDisplayPlugin()->presentCount()); + PROFILE_RANGE(simulation_physics, "Step"); PerformanceTimer perfTimer("stepSimulation"); getEntities()->getTree()->withWriteLock([&] { _physicsEngine->stepSimulation(); }); } { - PROFILE_RANGE_EX(simulation_physics, "HarvestChanges", 0xffffff00, (uint64_t)getActiveDisplayPlugin()->presentCount()); + PROFILE_RANGE(simulation_physics, "PostStep"); PerformanceTimer perfTimer("harvestChanges"); if (_physicsEngine->hasOutgoingChanges()) { // grab the collision events BEFORE handleOutgoingChanges() because at this point @@ -4887,6 +4891,7 @@ void Application::update(float deltaTime) { auto& collisionEvents = _physicsEngine->getCollisionEvents(); getEntities()->getTree()->withWriteLock([&] { + PROFILE_RANGE(simulation_physics, "Harvest"); PerformanceTimer perfTimer("handleOutgoingChanges"); const VectorOfMotionStates& outgoingChanges = _physicsEngine->getChangedMotionStates(); @@ -4899,18 +4904,25 @@ void Application::update(float deltaTime) { if (!_aboutToQuit) { // handleCollisionEvents() AFTER handleOutgoinChanges() - PerformanceTimer perfTimer("entities"); - avatarManager->handleCollisionEvents(collisionEvents); - // Collision events (and their scripts) must not be handled when we're locked, above. (That would risk - // deadlock.) - _entitySimulation->handleCollisionEvents(collisionEvents); + { + PROFILE_RANGE(simulation_physics, "CollisionEvents"); + PerformanceTimer perfTimer("entities"); + avatarManager->handleCollisionEvents(collisionEvents); + // Collision events (and their scripts) must not be handled when we're locked, above. (That would risk + // deadlock.) + _entitySimulation->handleCollisionEvents(collisionEvents); + } + PROFILE_RANGE(simulation_physics, "UpdateEntities"); // NOTE: the getEntities()->update() call below will wait for lock // and will simulate entity motion (the EntityTree has been given an EntitySimulation). getEntities()->update(true); // update the models... } - myAvatar->harvestResultsFromPhysicsSimulation(deltaTime); + { + PROFILE_RANGE(simulation_physics, "MyAvatar"); + myAvatar->harvestResultsFromPhysicsSimulation(deltaTime); + } if (Menu::getInstance()->isOptionChecked(MenuOption::DisplayDebugTimingDetails) && Menu::getInstance()->isOptionChecked(MenuOption::ExpandPhysicsSimulationTiming)) { @@ -4929,13 +4941,13 @@ void Application::update(float deltaTime) { // AvatarManager update { { + PROFILE_RANGE(simulation, "OtherAvatars"); PerformanceTimer perfTimer("otherAvatars"); - PROFILE_RANGE_EX(simulation, "OtherAvatars", 0xffff00ff, (uint64_t)getActiveDisplayPlugin()->presentCount()); avatarManager->updateOtherAvatars(deltaTime); } { - PROFILE_RANGE_EX(simulation, "MyAvatar", 0xffff00ff, (uint64_t)getActiveDisplayPlugin()->presentCount()); + PROFILE_RANGE(simulation, "MyAvatar"); PerformanceTimer perfTimer("MyAvatar"); qApp->updateMyAvatarLookAtPosition(); avatarManager->updateMyAvatar(deltaTime); @@ -5811,6 +5823,8 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEnginePointe qScriptRegisterMetaType(scriptEngine.data(), wrapperToScriptValue, wrapperFromScriptValue); qScriptRegisterMetaType(scriptEngine.data(), wrapperToScriptValue, wrapperFromScriptValue); + // Tablet inteference with Tablet.qml. Need to avoid this in QML space + scriptEngine->registerGlobalObject("tabletInterface", DependencyManager::get().data()); scriptEngine->registerGlobalObject("Tablet", DependencyManager::get().data()); auto toolbarScriptingInterface = DependencyManager::get().data(); diff --git a/interface/src/raypick/JointRayPick.cpp b/interface/src/raypick/JointRayPick.cpp index b4f0dde687..cf3f380ca0 100644 --- a/interface/src/raypick/JointRayPick.cpp +++ b/interface/src/raypick/JointRayPick.cpp @@ -10,7 +10,6 @@ // #include "JointRayPick.h" -#include "DependencyManager.h" #include "avatar/AvatarManager.h" JointRayPick::JointRayPick(const std::string& jointName, const glm::vec3& posOffset, const glm::vec3& dirOffset, const RayPickFilter& filter, const float maxDistance, const bool enabled) : diff --git a/interface/src/raypick/JointRayPick.h b/interface/src/raypick/JointRayPick.h index 3cd622fbbe..e3e5670e20 100644 --- a/interface/src/raypick/JointRayPick.h +++ b/interface/src/raypick/JointRayPick.h @@ -11,7 +11,7 @@ #ifndef hifi_JointRayPick_h #define hifi_JointRayPick_h -#include "RayPick.h" +#include class JointRayPick : public RayPick { diff --git a/interface/src/raypick/LaserPointer.cpp b/interface/src/raypick/LaserPointer.cpp index 0405320423..75b43a251b 100644 --- a/interface/src/raypick/LaserPointer.cpp +++ b/interface/src/raypick/LaserPointer.cpp @@ -11,8 +11,8 @@ #include "LaserPointer.h" #include "Application.h" -#include "ui/overlays/Overlay.h" #include "avatar/AvatarManager.h" +#include "RayPickScriptingInterface.h" LaserPointer::LaserPointer(const QVariant& rayProps, const RenderStateMap& renderStates, const DefaultRenderStateMap& defaultRenderStates, const bool faceAvatar, const bool centerEndY, const bool lockEnd, const bool distanceScaleEnd, const bool enabled) : @@ -22,9 +22,10 @@ LaserPointer::LaserPointer(const QVariant& rayProps, const RenderStateMap& rende _faceAvatar(faceAvatar), _centerEndY(centerEndY), _lockEnd(lockEnd), - _distanceScaleEnd(distanceScaleEnd) + _distanceScaleEnd(distanceScaleEnd), + _rayPickUID(DependencyManager::get()->createRayPick(rayProps)) { - _rayPickUID = DependencyManager::get()->createRayPick(rayProps); + for (auto& state : _renderStates) { if (!enabled || state.first != _currentRenderState) { @@ -39,7 +40,7 @@ LaserPointer::LaserPointer(const QVariant& rayProps, const RenderStateMap& rende } LaserPointer::~LaserPointer() { - DependencyManager::get()->removeRayPick(_rayPickUID); + qApp->getRayPickManager().removeRayPick(_rayPickUID); for (auto& renderState : _renderStates) { renderState.second.deleteOverlays(); @@ -50,47 +51,51 @@ LaserPointer::~LaserPointer() { } void LaserPointer::enable() { - QWriteLocker lock(getLock()); - DependencyManager::get()->enableRayPick(_rayPickUID); - _renderingEnabled = true; + qApp->getRayPickManager().enableRayPick(_rayPickUID); + withWriteLock([&] { + _renderingEnabled = true; + }); } void LaserPointer::disable() { - QWriteLocker lock(getLock()); - DependencyManager::get()->disableRayPick(_rayPickUID); - _renderingEnabled = false; - if (!_currentRenderState.empty()) { - if (_renderStates.find(_currentRenderState) != _renderStates.end()) { - disableRenderState(_renderStates[_currentRenderState]); + qApp->getRayPickManager().disableRayPick(_rayPickUID); + withWriteLock([&] { + _renderingEnabled = false; + if (!_currentRenderState.empty()) { + if (_renderStates.find(_currentRenderState) != _renderStates.end()) { + disableRenderState(_renderStates[_currentRenderState]); + } + if (_defaultRenderStates.find(_currentRenderState) != _defaultRenderStates.end()) { + disableRenderState(_defaultRenderStates[_currentRenderState].second); + } } - if (_defaultRenderStates.find(_currentRenderState) != _defaultRenderStates.end()) { - disableRenderState(_defaultRenderStates[_currentRenderState].second); - } - } + }); } void LaserPointer::setRenderState(const std::string& state) { - QWriteLocker lock(getLock()); - if (!_currentRenderState.empty() && state != _currentRenderState) { - if (_renderStates.find(_currentRenderState) != _renderStates.end()) { - disableRenderState(_renderStates[_currentRenderState]); + withWriteLock([&] { + if (!_currentRenderState.empty() && state != _currentRenderState) { + if (_renderStates.find(_currentRenderState) != _renderStates.end()) { + disableRenderState(_renderStates[_currentRenderState]); + } + if (_defaultRenderStates.find(_currentRenderState) != _defaultRenderStates.end()) { + disableRenderState(_defaultRenderStates[_currentRenderState].second); + } } - if (_defaultRenderStates.find(_currentRenderState) != _defaultRenderStates.end()) { - disableRenderState(_defaultRenderStates[_currentRenderState].second); - } - } - _currentRenderState = state; + _currentRenderState = state; + }); } void LaserPointer::editRenderState(const std::string& state, const QVariant& startProps, const QVariant& pathProps, const QVariant& endProps) { - QWriteLocker lock(getLock()); - updateRenderStateOverlay(_renderStates[state].getStartID(), startProps); - updateRenderStateOverlay(_renderStates[state].getPathID(), pathProps); - updateRenderStateOverlay(_renderStates[state].getEndID(), endProps); - QVariant endDim = endProps.toMap()["dimensions"]; - if (endDim.isValid()) { - _renderStates[state].setEndDim(vec3FromVariant(endDim)); - } + withWriteLock([&] { + updateRenderStateOverlay(_renderStates[state].getStartID(), startProps); + updateRenderStateOverlay(_renderStates[state].getPathID(), pathProps); + updateRenderStateOverlay(_renderStates[state].getEndID(), endProps); + QVariant endDim = endProps.toMap()["dimensions"]; + if (endDim.isValid()) { + _renderStates[state].setEndDim(vec3FromVariant(endDim)); + } + }); } void LaserPointer::updateRenderStateOverlay(const OverlayID& id, const QVariant& props) { @@ -102,8 +107,7 @@ void LaserPointer::updateRenderStateOverlay(const OverlayID& id, const QVariant& } const RayPickResult LaserPointer::getPrevRayPickResult() { - QReadLocker lock(getLock()); - return DependencyManager::get()->getPrevRayPickResult(_rayPickUID); + return qApp->getRayPickManager().getPrevRayPickResult(_rayPickUID); } void LaserPointer::updateRenderState(const RenderState& renderState, const IntersectionType type, const float distance, const QUuid& objectID, const PickRay& pickRay, const bool defaultState) { @@ -202,65 +206,45 @@ void LaserPointer::disableRenderState(const RenderState& renderState) { void LaserPointer::update() { // This only needs to be a read lock because update won't change any of the properties that can be modified from scripts - QReadLocker lock(getLock()); - RayPickResult prevRayPickResult = DependencyManager::get()->getPrevRayPickResult(_rayPickUID); - if (_renderingEnabled && !_currentRenderState.empty() && _renderStates.find(_currentRenderState) != _renderStates.end() && + withReadLock([&] { + RayPickResult prevRayPickResult = qApp->getRayPickManager().getPrevRayPickResult(_rayPickUID); + if (_renderingEnabled && !_currentRenderState.empty() && _renderStates.find(_currentRenderState) != _renderStates.end() && (prevRayPickResult.type != IntersectionType::NONE || _laserLength > 0.0f || !_objectLockEnd.first.isNull())) { - float distance = _laserLength > 0.0f ? _laserLength : prevRayPickResult.distance; - updateRenderState(_renderStates[_currentRenderState], prevRayPickResult.type, distance, prevRayPickResult.objectID, prevRayPickResult.searchRay, false); - disableRenderState(_defaultRenderStates[_currentRenderState].second); - } else if (_renderingEnabled && !_currentRenderState.empty() && _defaultRenderStates.find(_currentRenderState) != _defaultRenderStates.end()) { - disableRenderState(_renderStates[_currentRenderState]); - updateRenderState(_defaultRenderStates[_currentRenderState].second, IntersectionType::NONE, _defaultRenderStates[_currentRenderState].first, QUuid(), prevRayPickResult.searchRay, true); - } else if (!_currentRenderState.empty()) { - disableRenderState(_renderStates[_currentRenderState]); - disableRenderState(_defaultRenderStates[_currentRenderState].second); - } + float distance = _laserLength > 0.0f ? _laserLength : prevRayPickResult.distance; + updateRenderState(_renderStates[_currentRenderState], prevRayPickResult.type, distance, prevRayPickResult.objectID, prevRayPickResult.searchRay, false); + disableRenderState(_defaultRenderStates[_currentRenderState].second); + } else if (_renderingEnabled && !_currentRenderState.empty() && _defaultRenderStates.find(_currentRenderState) != _defaultRenderStates.end()) { + disableRenderState(_renderStates[_currentRenderState]); + updateRenderState(_defaultRenderStates[_currentRenderState].second, IntersectionType::NONE, _defaultRenderStates[_currentRenderState].first, QUuid(), prevRayPickResult.searchRay, true); + } else if (!_currentRenderState.empty()) { + disableRenderState(_renderStates[_currentRenderState]); + disableRenderState(_defaultRenderStates[_currentRenderState].second); + } + }); } void LaserPointer::setPrecisionPicking(const bool precisionPicking) { - QWriteLocker lock(getLock()); - DependencyManager::get()->setPrecisionPicking(_rayPickUID, precisionPicking); + qApp->getRayPickManager().setPrecisionPicking(_rayPickUID, precisionPicking); } void LaserPointer::setLaserLength(const float laserLength) { - QWriteLocker lock(getLock()); - _laserLength = laserLength; + withWriteLock([&] { + _laserLength = laserLength; + }); } void LaserPointer::setLockEndUUID(QUuid objectID, const bool isOverlay) { - QWriteLocker lock(getLock()); - _objectLockEnd = std::pair(objectID, isOverlay); + withWriteLock([&] { + _objectLockEnd = std::pair(objectID, isOverlay); + }); } -void LaserPointer::setIgnoreEntities(const QScriptValue& ignoreEntities) { - QWriteLocker lock(getLock()); - DependencyManager::get()->setIgnoreEntities(_rayPickUID, ignoreEntities); +void LaserPointer::setIgnoreItems(const QVector& ignoreItems) const { + qApp->getRayPickManager().setIgnoreItems(_rayPickUID, ignoreItems); } -void LaserPointer::setIncludeEntities(const QScriptValue& includeEntities) { - QWriteLocker lock(getLock()); - DependencyManager::get()->setIncludeEntities(_rayPickUID, includeEntities); -} - -void LaserPointer::setIgnoreOverlays(const QScriptValue& ignoreOverlays) { - QWriteLocker lock(getLock()); - DependencyManager::get()->setIgnoreOverlays(_rayPickUID, ignoreOverlays); -} - -void LaserPointer::setIncludeOverlays(const QScriptValue& includeOverlays) { - QWriteLocker lock(getLock()); - DependencyManager::get()->setIncludeOverlays(_rayPickUID, includeOverlays); -} - -void LaserPointer::setIgnoreAvatars(const QScriptValue& ignoreAvatars) { - QWriteLocker lock(getLock()); - DependencyManager::get()->setIgnoreAvatars(_rayPickUID, ignoreAvatars); -} - -void LaserPointer::setIncludeAvatars(const QScriptValue& includeAvatars) { - QWriteLocker lock(getLock()); - DependencyManager::get()->setIncludeAvatars(_rayPickUID, includeAvatars); +void LaserPointer::setIncludeItems(const QVector& includeItems) const { + qApp->getRayPickManager().setIncludeItems(_rayPickUID, includeItems); } RenderState::RenderState(const OverlayID& startID, const OverlayID& pathID, const OverlayID& endID) : @@ -288,4 +272,4 @@ void RenderState::deleteOverlays() { if (!_endID.isNull()) { qApp->getOverlays().deleteOverlay(_endID); } -} \ No newline at end of file +} diff --git a/interface/src/raypick/LaserPointer.h b/interface/src/raypick/LaserPointer.h index a6b85fbfc2..f2350c7199 100644 --- a/interface/src/raypick/LaserPointer.h +++ b/interface/src/raypick/LaserPointer.h @@ -12,10 +12,12 @@ #define hifi_LaserPointer_h #include -#include "glm/glm.hpp" +#include #include -#include "raypick/RayPickScriptingInterface.h" +#include + +#include "ui/overlays/Overlay.h" class RayPickResult; @@ -49,9 +51,10 @@ private: }; -class LaserPointer { +class LaserPointer : public ReadWriteLockable { public: + using Pointer = std::shared_ptr; typedef std::unordered_map RenderStateMap; typedef std::unordered_map> DefaultRenderStateMap; @@ -73,14 +76,8 @@ public: void setLaserLength(const float laserLength); void setLockEndUUID(QUuid objectID, const bool isOverlay); - void setIgnoreEntities(const QScriptValue& ignoreEntities); - void setIncludeEntities(const QScriptValue& includeEntities); - void setIgnoreOverlays(const QScriptValue& ignoreOverlays); - void setIncludeOverlays(const QScriptValue& includeOverlays); - void setIgnoreAvatars(const QScriptValue& ignoreAvatars); - void setIncludeAvatars(const QScriptValue& includeAvatars); - - QReadWriteLock* getLock() { return &_lock; } + void setIgnoreItems(const QVector& ignoreItems) const; + void setIncludeItems(const QVector& includeItems) const; void update(); @@ -96,8 +93,7 @@ private: bool _distanceScaleEnd; std::pair _objectLockEnd { std::pair(QUuid(), false)}; - QUuid _rayPickUID; - QReadWriteLock _lock; + const QUuid _rayPickUID; void updateRenderStateOverlay(const OverlayID& id, const QVariant& props); void updateRenderState(const RenderState& renderState, const IntersectionType type, const float distance, const QUuid& objectID, const PickRay& pickRay, const bool defaultState); diff --git a/interface/src/raypick/LaserPointerManager.cpp b/interface/src/raypick/LaserPointerManager.cpp index 7b6e93889d..9d58cc2587 100644 --- a/interface/src/raypick/LaserPointerManager.cpp +++ b/interface/src/raypick/LaserPointerManager.cpp @@ -12,138 +12,110 @@ QUuid LaserPointerManager::createLaserPointer(const QVariant& rayProps, const LaserPointer::RenderStateMap& renderStates, const LaserPointer::DefaultRenderStateMap& defaultRenderStates, const bool faceAvatar, const bool centerEndY, const bool lockEnd, const bool distanceScaleEnd, const bool enabled) { + QUuid result; std::shared_ptr laserPointer = std::make_shared(rayProps, renderStates, defaultRenderStates, faceAvatar, centerEndY, lockEnd, distanceScaleEnd, enabled); if (!laserPointer->getRayUID().isNull()) { - QWriteLocker containsLock(&_containsLock); - QUuid id = QUuid::createUuid(); - _laserPointers[id] = laserPointer; - return id; + result = QUuid::createUuid(); + withWriteLock([&] { _laserPointers[result] = laserPointer; }); } - return QUuid(); + return result; } -void LaserPointerManager::removeLaserPointer(const QUuid uid) { - QWriteLocker lock(&_containsLock); - _laserPointers.remove(uid); + +LaserPointer::Pointer LaserPointerManager::find(const QUuid& uid) const { + return resultWithReadLock([&] { + auto itr = _laserPointers.find(uid); + if (itr != _laserPointers.end()) { + return *itr; + } + return LaserPointer::Pointer(); + }); } -void LaserPointerManager::enableLaserPointer(const QUuid uid) { - QReadLocker lock(&_containsLock); - auto laserPointer = _laserPointers.find(uid); - if (laserPointer != _laserPointers.end()) { - laserPointer.value()->enable(); + +void LaserPointerManager::removeLaserPointer(const QUuid& uid) { + withWriteLock([&] { + _laserPointers.remove(uid); + }); +} + +void LaserPointerManager::enableLaserPointer(const QUuid& uid) const { + auto laserPointer = find(uid); + if (laserPointer) { + laserPointer->enable(); } } -void LaserPointerManager::disableLaserPointer(const QUuid uid) { - QReadLocker lock(&_containsLock); - auto laserPointer = _laserPointers.find(uid); - if (laserPointer != _laserPointers.end()) { - laserPointer.value()->disable(); +void LaserPointerManager::disableLaserPointer(const QUuid& uid) const { + auto laserPointer = find(uid); + if (laserPointer) { + laserPointer->disable(); } } -void LaserPointerManager::setRenderState(QUuid uid, const std::string& renderState) { - QReadLocker lock(&_containsLock); - auto laserPointer = _laserPointers.find(uid); - if (laserPointer != _laserPointers.end()) { - laserPointer.value()->setRenderState(renderState); +void LaserPointerManager::setRenderState(const QUuid& uid, const std::string& renderState) const { + auto laserPointer = find(uid); + if (laserPointer) { + laserPointer->setRenderState(renderState); } } -void LaserPointerManager::editRenderState(QUuid uid, const std::string& state, const QVariant& startProps, const QVariant& pathProps, const QVariant& endProps) { - QReadLocker lock(&_containsLock); - auto laserPointer = _laserPointers.find(uid); - if (laserPointer != _laserPointers.end()) { - laserPointer.value()->editRenderState(state, startProps, pathProps, endProps); +void LaserPointerManager::editRenderState(const QUuid& uid, const std::string& state, const QVariant& startProps, const QVariant& pathProps, const QVariant& endProps) const { + auto laserPointer = find(uid); + if (laserPointer) { + laserPointer->editRenderState(state, startProps, pathProps, endProps); } } -const RayPickResult LaserPointerManager::getPrevRayPickResult(const QUuid uid) { - QReadLocker lock(&_containsLock); - auto laserPointer = _laserPointers.find(uid); - if (laserPointer != _laserPointers.end()) { - return laserPointer.value()->getPrevRayPickResult(); +const RayPickResult LaserPointerManager::getPrevRayPickResult(const QUuid& uid) const { + auto laserPointer = find(uid); + if (laserPointer) { + return laserPointer->getPrevRayPickResult(); } return RayPickResult(); } void LaserPointerManager::update() { - QReadLocker lock(&_containsLock); - for (QUuid& uid : _laserPointers.keys()) { - auto laserPointer = _laserPointers.find(uid); - laserPointer.value()->update(); + auto cachedLaserPointers = resultWithReadLock>>([&] { + return _laserPointers.values(); + }); + + for (const auto& laserPointer : cachedLaserPointers) { + laserPointer->update(); } } -void LaserPointerManager::setPrecisionPicking(QUuid uid, const bool precisionPicking) { - QReadLocker lock(&_containsLock); - auto laserPointer = _laserPointers.find(uid); - if (laserPointer != _laserPointers.end()) { - laserPointer.value()->setPrecisionPicking(precisionPicking); +void LaserPointerManager::setPrecisionPicking(const QUuid& uid, const bool precisionPicking) const { + auto laserPointer = find(uid); + if (laserPointer) { + laserPointer->setPrecisionPicking(precisionPicking); } } -void LaserPointerManager::setLaserLength(QUuid uid, const float laserLength) { - QReadLocker lock(&_containsLock); - auto laserPointer = _laserPointers.find(uid); - if (laserPointer != _laserPointers.end()) { - laserPointer.value()->setLaserLength(laserLength); +void LaserPointerManager::setLaserLength(const QUuid& uid, const float laserLength) const { + auto laserPointer = find(uid); + if (laserPointer) { + laserPointer->setLaserLength(laserLength); } } -void LaserPointerManager::setIgnoreEntities(QUuid uid, const QScriptValue& ignoreEntities) { - QReadLocker lock(&_containsLock); - auto laserPointer = _laserPointers.find(uid); - if (laserPointer != _laserPointers.end()) { - laserPointer.value()->setIgnoreEntities(ignoreEntities); +void LaserPointerManager::setIgnoreItems(const QUuid& uid, const QVector& ignoreEntities) const { + auto laserPointer = find(uid); + if (laserPointer) { + laserPointer->setIgnoreItems(ignoreEntities); } } -void LaserPointerManager::setIncludeEntities(QUuid uid, const QScriptValue& includeEntities) { - QReadLocker lock(&_containsLock); - auto laserPointer = _laserPointers.find(uid); - if (laserPointer != _laserPointers.end()) { - laserPointer.value()->setIncludeEntities(includeEntities); +void LaserPointerManager::setIncludeItems(const QUuid& uid, const QVector& includeEntities) const { + auto laserPointer = find(uid); + if (laserPointer) { + laserPointer->setIncludeItems(includeEntities); } } -void LaserPointerManager::setIgnoreOverlays(QUuid uid, const QScriptValue& ignoreOverlays) { - QReadLocker lock(&_containsLock); - auto laserPointer = _laserPointers.find(uid); - if (laserPointer != _laserPointers.end()) { - laserPointer.value()->setIgnoreOverlays(ignoreOverlays); - } -} - -void LaserPointerManager::setIncludeOverlays(QUuid uid, const QScriptValue& includeOverlays) { - QReadLocker lock(&_containsLock); - auto laserPointer = _laserPointers.find(uid); - if (laserPointer != _laserPointers.end()) { - laserPointer.value()->setIncludeOverlays(includeOverlays); - } -} - -void LaserPointerManager::setIgnoreAvatars(QUuid uid, const QScriptValue& ignoreAvatars) { - QReadLocker lock(&_containsLock); - auto laserPointer = _laserPointers.find(uid); - if (laserPointer != _laserPointers.end()) { - laserPointer.value()->setIgnoreAvatars(ignoreAvatars); - } -} - -void LaserPointerManager::setIncludeAvatars(QUuid uid, const QScriptValue& includeAvatars) { - QReadLocker lock(&_containsLock); - auto laserPointer = _laserPointers.find(uid); - if (laserPointer != _laserPointers.end()) { - laserPointer.value()->setIncludeAvatars(includeAvatars); - } -} - -void LaserPointerManager::setLockEndUUID(QUuid uid, QUuid objectID, const bool isOverlay) { - QReadLocker lock(&_containsLock); - auto laserPointer = _laserPointers.find(uid); - if (laserPointer != _laserPointers.end()) { - laserPointer.value()->setLockEndUUID(objectID, isOverlay); +void LaserPointerManager::setLockEndUUID(const QUuid& uid, const QUuid& objectID, const bool isOverlay) const { + auto laserPointer = find(uid); + if (laserPointer) { + laserPointer->setLockEndUUID(objectID, isOverlay); } } diff --git a/interface/src/raypick/LaserPointerManager.h b/interface/src/raypick/LaserPointerManager.h index 29d7be2ed3..e302318483 100644 --- a/interface/src/raypick/LaserPointerManager.h +++ b/interface/src/raypick/LaserPointerManager.h @@ -14,39 +14,38 @@ #include #include +#include + #include "LaserPointer.h" class RayPickResult; -class LaserPointerManager { + +class LaserPointerManager : protected ReadWriteLockable { public: QUuid createLaserPointer(const QVariant& rayProps, const LaserPointer::RenderStateMap& renderStates, const LaserPointer::DefaultRenderStateMap& defaultRenderStates, const bool faceAvatar, const bool centerEndY, const bool lockEnd, const bool distanceScaleEnd, const bool enabled); - void removeLaserPointer(const QUuid uid); - void enableLaserPointer(const QUuid uid); - void disableLaserPointer(const QUuid uid); - void setRenderState(QUuid uid, const std::string& renderState); - void editRenderState(QUuid uid, const std::string& state, const QVariant& startProps, const QVariant& pathProps, const QVariant& endProps); - const RayPickResult getPrevRayPickResult(const QUuid uid); - void setPrecisionPicking(QUuid uid, const bool precisionPicking); - void setLaserLength(QUuid uid, const float laserLength); - void setIgnoreEntities(QUuid uid, const QScriptValue& ignoreEntities); - void setIncludeEntities(QUuid uid, const QScriptValue& includeEntities); - void setIgnoreOverlays(QUuid uid, const QScriptValue& ignoreOverlays); - void setIncludeOverlays(QUuid uid, const QScriptValue& includeOverlays); - void setIgnoreAvatars(QUuid uid, const QScriptValue& ignoreAvatars); - void setIncludeAvatars(QUuid uid, const QScriptValue& includeAvatars); + void removeLaserPointer(const QUuid& uid); + void enableLaserPointer(const QUuid& uid) const; + void disableLaserPointer(const QUuid& uid) const; + void setRenderState(const QUuid& uid, const std::string& renderState) const; + void editRenderState(const QUuid& uid, const std::string& state, const QVariant& startProps, const QVariant& pathProps, const QVariant& endProps) const; + const RayPickResult getPrevRayPickResult(const QUuid& uid) const; - void setLockEndUUID(QUuid uid, QUuid objectID, const bool isOverlay); + void setPrecisionPicking(const QUuid& uid, const bool precisionPicking) const; + void setLaserLength(const QUuid& uid, const float laserLength) const; + void setIgnoreItems(const QUuid& uid, const QVector& ignoreEntities) const; + void setIncludeItems(const QUuid& uid, const QVector& includeEntities) const; + + void setLockEndUUID(const QUuid& uid, const QUuid& objectID, const bool isOverlay) const; void update(); private: + LaserPointer::Pointer find(const QUuid& uid) const; QHash> _laserPointers; - QReadWriteLock _containsLock; - }; #endif // hifi_LaserPointerManager_h diff --git a/interface/src/raypick/LaserPointerScriptingInterface.cpp b/interface/src/raypick/LaserPointerScriptingInterface.cpp index 304a6da4f2..e8d28bfab2 100644 --- a/interface/src/raypick/LaserPointerScriptingInterface.cpp +++ b/interface/src/raypick/LaserPointerScriptingInterface.cpp @@ -11,10 +11,19 @@ #include "LaserPointerScriptingInterface.h" -#include -#include "GLMHelpers.h" +#include -QUuid LaserPointerScriptingInterface::createLaserPointer(const QVariant& properties) { +#include +#include + +void LaserPointerScriptingInterface::setIgnoreItems(const QUuid& uid, const QScriptValue& ignoreItems) const { + qApp->getLaserPointerManager().setIgnoreItems(uid, qVectorQUuidFromScriptValue(ignoreItems)); +} +void LaserPointerScriptingInterface::setIncludeItems(const QUuid& uid, const QScriptValue& includeItems) const { + qApp->getLaserPointerManager().setIncludeItems(uid, qVectorQUuidFromScriptValue(includeItems)); +} + +QUuid LaserPointerScriptingInterface::createLaserPointer(const QVariant& properties) const { QVariantMap propertyMap = properties.toMap(); bool faceAvatar = false; @@ -74,7 +83,7 @@ QUuid LaserPointerScriptingInterface::createLaserPointer(const QVariant& propert return qApp->getLaserPointerManager().createLaserPointer(properties, renderStates, defaultRenderStates, faceAvatar, centerEndY, lockEnd, distanceScaleEnd, enabled); } -void LaserPointerScriptingInterface::editRenderState(QUuid uid, const QString& renderState, const QVariant& properties) { +void LaserPointerScriptingInterface::editRenderState(const QUuid& uid, const QString& renderState, const QVariant& properties) const { QVariantMap propMap = properties.toMap(); QVariant startProps; @@ -95,7 +104,7 @@ void LaserPointerScriptingInterface::editRenderState(QUuid uid, const QString& r qApp->getLaserPointerManager().editRenderState(uid, renderState.toStdString(), startProps, pathProps, endProps); } -const RenderState LaserPointerScriptingInterface::buildRenderState(const QVariantMap& propMap) { +RenderState LaserPointerScriptingInterface::buildRenderState(const QVariantMap& propMap) { QUuid startID; if (propMap["start"].isValid()) { QVariantMap startMap = propMap["start"].toMap(); diff --git a/interface/src/raypick/LaserPointerScriptingInterface.h b/interface/src/raypick/LaserPointerScriptingInterface.h index 2f6da87b5f..19262e6e5d 100644 --- a/interface/src/raypick/LaserPointerScriptingInterface.h +++ b/interface/src/raypick/LaserPointerScriptingInterface.h @@ -22,27 +22,23 @@ class LaserPointerScriptingInterface : public QObject, public Dependency { SINGLETON_DEPENDENCY public slots: - Q_INVOKABLE QUuid createLaserPointer(const QVariant& properties); - Q_INVOKABLE void enableLaserPointer(QUuid uid) { qApp->getLaserPointerManager().enableLaserPointer(uid); } - Q_INVOKABLE void disableLaserPointer(QUuid uid) { qApp->getLaserPointerManager().disableLaserPointer(uid); } - Q_INVOKABLE void removeLaserPointer(QUuid uid) { qApp->getLaserPointerManager().removeLaserPointer(uid); } - Q_INVOKABLE void editRenderState(QUuid uid, const QString& renderState, const QVariant& properties); - Q_INVOKABLE void setRenderState(QUuid uid, const QString& renderState) { qApp->getLaserPointerManager().setRenderState(uid, renderState.toStdString()); } - Q_INVOKABLE RayPickResult getPrevRayPickResult(QUuid uid) { return qApp->getLaserPointerManager().getPrevRayPickResult(uid); } + Q_INVOKABLE QUuid createLaserPointer(const QVariant& properties) const; + Q_INVOKABLE void enableLaserPointer(const QUuid& uid) const { qApp->getLaserPointerManager().enableLaserPointer(uid); } + Q_INVOKABLE void disableLaserPointer(const QUuid& uid) const { qApp->getLaserPointerManager().disableLaserPointer(uid); } + Q_INVOKABLE void removeLaserPointer(const QUuid& uid) const { qApp->getLaserPointerManager().removeLaserPointer(uid); } + Q_INVOKABLE void editRenderState(const QUuid& uid, const QString& renderState, const QVariant& properties) const; + Q_INVOKABLE void setRenderState(const QUuid& uid, const QString& renderState) const { qApp->getLaserPointerManager().setRenderState(uid, renderState.toStdString()); } + Q_INVOKABLE RayPickResult getPrevRayPickResult(QUuid uid) const { return qApp->getLaserPointerManager().getPrevRayPickResult(uid); } - Q_INVOKABLE void setPrecisionPicking(QUuid uid, const bool precisionPicking) { qApp->getLaserPointerManager().setPrecisionPicking(uid, precisionPicking); } - Q_INVOKABLE void setLaserLength(QUuid uid, const float laserLength) { qApp->getLaserPointerManager().setLaserLength(uid, laserLength); } - Q_INVOKABLE void setIgnoreEntities(QUuid uid, const QScriptValue& ignoreEntities) { qApp->getLaserPointerManager().setIgnoreEntities(uid, ignoreEntities); } - Q_INVOKABLE void setIncludeEntities(QUuid uid, const QScriptValue& includeEntities) { qApp->getLaserPointerManager().setIncludeEntities(uid, includeEntities); } - Q_INVOKABLE void setIgnoreOverlays(QUuid uid, const QScriptValue& ignoreOverlays) { qApp->getLaserPointerManager().setIgnoreOverlays(uid, ignoreOverlays); } - Q_INVOKABLE void setIncludeOverlays(QUuid uid, const QScriptValue& includeOverlays) { qApp->getLaserPointerManager().setIncludeOverlays(uid, includeOverlays); } - Q_INVOKABLE void setIgnoreAvatars(QUuid uid, const QScriptValue& ignoreAvatars) { qApp->getLaserPointerManager().setIgnoreAvatars(uid, ignoreAvatars); } - Q_INVOKABLE void setIncludeAvatars(QUuid uid, const QScriptValue& includeAvatars) { qApp->getLaserPointerManager().setIncludeAvatars(uid, includeAvatars); } + Q_INVOKABLE void setPrecisionPicking(const QUuid& uid, bool precisionPicking) const { qApp->getLaserPointerManager().setPrecisionPicking(uid, precisionPicking); } + Q_INVOKABLE void setLaserLength(const QUuid& uid, float laserLength) const { qApp->getLaserPointerManager().setLaserLength(uid, laserLength); } + Q_INVOKABLE void setIgnoreItems(const QUuid& uid, const QScriptValue& ignoreEntities) const; + Q_INVOKABLE void setIncludeItems(const QUuid& uid, const QScriptValue& includeEntities) const; - Q_INVOKABLE void setLockEndUUID(QUuid uid, QUuid objectID, const bool isOverlay) { qApp->getLaserPointerManager().setLockEndUUID(uid, objectID, isOverlay); } + Q_INVOKABLE void setLockEndUUID(const QUuid& uid, const QUuid& objectID, bool isOverlay) const { qApp->getLaserPointerManager().setLockEndUUID(uid, objectID, isOverlay); } private: - const RenderState buildRenderState(const QVariantMap& propMap); + static RenderState buildRenderState(const QVariantMap& propMap); }; diff --git a/interface/src/raypick/MouseRayPick.h b/interface/src/raypick/MouseRayPick.h index 848a5de336..47f9404f3a 100644 --- a/interface/src/raypick/MouseRayPick.h +++ b/interface/src/raypick/MouseRayPick.h @@ -11,7 +11,7 @@ #ifndef hifi_MouseRayPick_h #define hifi_MouseRayPick_h -#include "RayPick.h" +#include class MouseRayPick : public RayPick { diff --git a/interface/src/raypick/RayPick.cpp b/interface/src/raypick/RayPick.cpp deleted file mode 100644 index a5b1299210..0000000000 --- a/interface/src/raypick/RayPick.cpp +++ /dev/null @@ -1,62 +0,0 @@ -// -// RayPick.cpp -// interface/src/raypick -// -// Created by Sam Gondelman 7/11/2017 -// Copyright 2017 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// -#include "RayPick.h" - -RayPick::RayPick(const RayPickFilter& filter, const float maxDistance, const bool enabled) : - _filter(filter), - _maxDistance(maxDistance), - _enabled(enabled) -{ -} -void RayPick::enable() { - QWriteLocker lock(getLock()); - _enabled = true; -} - -void RayPick::disable() { - QWriteLocker lock(getLock()); - _enabled = false; -} - -const RayPickResult& RayPick::getPrevRayPickResult() { - QReadLocker lock(getLock()); - return _prevResult; -} - -void RayPick::setIgnoreEntities(const QScriptValue& ignoreEntities) { - QWriteLocker lock(getLock()); - _ignoreEntities = qVectorEntityItemIDFromScriptValue(ignoreEntities); -} - -void RayPick::setIncludeEntities(const QScriptValue& includeEntities) { - QWriteLocker lock(getLock()); - _includeEntities = qVectorEntityItemIDFromScriptValue(includeEntities); -} - -void RayPick::setIgnoreOverlays(const QScriptValue& ignoreOverlays) { - QWriteLocker lock(getLock()); - _ignoreOverlays = qVectorOverlayIDFromScriptValue(ignoreOverlays); -} - -void RayPick::setIncludeOverlays(const QScriptValue& includeOverlays) { - QWriteLocker lock(getLock()); - _includeOverlays = qVectorOverlayIDFromScriptValue(includeOverlays); -} - -void RayPick::setIgnoreAvatars(const QScriptValue& ignoreAvatars) { - QWriteLocker lock(getLock()); - _ignoreAvatars = qVectorEntityItemIDFromScriptValue(ignoreAvatars); -} - -void RayPick::setIncludeAvatars(const QScriptValue& includeAvatars) { - QWriteLocker lock(getLock()); - _includeAvatars = qVectorEntityItemIDFromScriptValue(includeAvatars); -} \ No newline at end of file diff --git a/interface/src/raypick/RayPickManager.cpp b/interface/src/raypick/RayPickManager.cpp index 1728ecd01a..15489ce93d 100644 --- a/interface/src/raypick/RayPickManager.cpp +++ b/interface/src/raypick/RayPickManager.cpp @@ -10,6 +10,8 @@ // #include "RayPickManager.h" +#include + #include "Application.h" #include "EntityScriptingInterface.h" #include "ui/overlays/Overlays.h" @@ -18,45 +20,50 @@ #include "DependencyManager.h" #include "JointRayPick.h" -#include "StaticRayPick.h" #include "MouseRayPick.h" -bool RayPickManager::checkAndCompareCachedResults(QPair& ray, RayPickCache& cache, RayPickResult& res, const RayPickFilter::Flags& mask) { - if (cache.contains(ray) && cache[ray].find(mask) != cache[ray].end()) { - if (cache[ray][mask].distance < res.distance) { - res = cache[ray][mask]; +bool RayPickManager::checkAndCompareCachedResults(QPair& ray, RayPickCache& cache, RayPickResult& res, const RayCacheKey& key) { + if (cache.contains(ray) && cache[ray].find(key) != cache[ray].end()) { + if (cache[ray][key].distance < res.distance) { + res = cache[ray][key]; } return true; } return false; } -void RayPickManager::cacheResult(const bool intersects, const RayPickResult& resTemp, const RayPickFilter::Flags& mask, RayPickResult& res, QPair& ray, RayPickCache& cache) { +void RayPickManager::cacheResult(const bool intersects, const RayPickResult& resTemp, const RayCacheKey& key, RayPickResult& res, QPair& ray, RayPickCache& cache) { if (intersects) { - cache[ray][mask] = resTemp; + cache[ray][key] = resTemp; if (resTemp.distance < res.distance) { res = resTemp; } } else { - cache[ray][mask] = RayPickResult(res.searchRay); + cache[ray][key] = RayPickResult(res.searchRay); } } void RayPickManager::update() { - QReadLocker lock(&_containsLock); RayPickCache results; - for (auto& uid : _rayPicks.keys()) { - std::shared_ptr rayPick = _rayPicks[uid]; - QWriteLocker lock(rayPick->getLock()); + QHash cachedRayPicks; + withReadLock([&] { + cachedRayPicks = _rayPicks; + }); + + for (const auto& uid : cachedRayPicks.keys()) { + std::shared_ptr rayPick = cachedRayPicks[uid]; if (!rayPick->isEnabled() || rayPick->getFilter().doesPickNothing() || rayPick->getMaxDistance() < 0.0f) { continue; } - bool valid; - PickRay ray = rayPick->getPickRay(valid); + PickRay ray; - if (!valid) { - continue; + { + bool valid; + ray = rayPick->getPickRay(valid); + if (!valid) { + continue; + } } QPair rayKey = QPair(ray.origin, ray.direction); @@ -67,16 +74,16 @@ void RayPickManager::update() { bool fromCache = true; bool invisible = rayPick->getFilter().doesPickInvisible(); bool nonCollidable = rayPick->getFilter().doesPickNonCollidable(); - RayPickFilter::Flags entityMask = rayPick->getFilter().getEntityFlags(); - if (!checkAndCompareCachedResults(rayKey, results, res, entityMask)) { - entityRes = DependencyManager::get()->findRayIntersectionVector(ray, !rayPick->getFilter().doesPickCourse(), - rayPick->getIncludeEntites(), rayPick->getIgnoreEntites(), !invisible, !nonCollidable); + RayCacheKey entityKey = { rayPick->getFilter().getEntityFlags(), rayPick->getIncludeItems(), rayPick->getIgnoreItems() }; + if (!checkAndCompareCachedResults(rayKey, results, res, entityKey)) { + entityRes = DependencyManager::get()->findRayIntersectionVector(ray, !rayPick->getFilter().doesPickCoarse(), + rayPick->getIncludeItemsAs(), rayPick->getIgnoreItemsAs(), !invisible, !nonCollidable); fromCache = false; } if (!fromCache) { cacheResult(entityRes.intersects, RayPickResult(IntersectionType::ENTITY, entityRes.entityID, entityRes.distance, entityRes.intersection, ray, entityRes.surfaceNormal), - entityMask, res, rayKey, results); + entityKey, res, rayKey, results); } } @@ -85,33 +92,34 @@ void RayPickManager::update() { bool fromCache = true; bool invisible = rayPick->getFilter().doesPickInvisible(); bool nonCollidable = rayPick->getFilter().doesPickNonCollidable(); - RayPickFilter::Flags overlayMask = rayPick->getFilter().getOverlayFlags(); - if (!checkAndCompareCachedResults(rayKey, results, res, overlayMask)) { - overlayRes = qApp->getOverlays().findRayIntersectionVector(ray, !rayPick->getFilter().doesPickCourse(), - rayPick->getIncludeOverlays(), rayPick->getIgnoreOverlays(), !invisible, !nonCollidable); + RayCacheKey overlayKey = { rayPick->getFilter().getOverlayFlags(), rayPick->getIncludeItems(), rayPick->getIgnoreItems() }; + if (!checkAndCompareCachedResults(rayKey, results, res, overlayKey)) { + overlayRes = qApp->getOverlays().findRayIntersectionVector(ray, !rayPick->getFilter().doesPickCoarse(), + rayPick->getIncludeItemsAs(), rayPick->getIgnoreItemsAs(), !invisible, !nonCollidable); fromCache = false; } if (!fromCache) { cacheResult(overlayRes.intersects, RayPickResult(IntersectionType::OVERLAY, overlayRes.overlayID, overlayRes.distance, overlayRes.intersection, ray, overlayRes.surfaceNormal), - overlayMask, res, rayKey, results); + overlayKey, res, rayKey, results); } } if (rayPick->getFilter().doesPickAvatars()) { - RayPickFilter::Flags avatarMask = rayPick->getFilter().getAvatarFlags(); - if (!checkAndCompareCachedResults(rayKey, results, res, avatarMask)) { - RayToAvatarIntersectionResult avatarRes = DependencyManager::get()->findRayIntersectionVector(ray, rayPick->getIncludeAvatars(), rayPick->getIgnoreAvatars()); - cacheResult(avatarRes.intersects, RayPickResult(IntersectionType::AVATAR, avatarRes.avatarID, avatarRes.distance, avatarRes.intersection, ray), avatarMask, res, rayKey, results); + RayCacheKey avatarKey = { rayPick->getFilter().getAvatarFlags(), rayPick->getIncludeItems(), rayPick->getIgnoreItems() }; + if (!checkAndCompareCachedResults(rayKey, results, res, avatarKey)) { + RayToAvatarIntersectionResult avatarRes = DependencyManager::get()->findRayIntersectionVector(ray, + rayPick->getIncludeItemsAs(), rayPick->getIgnoreItemsAs()); + cacheResult(avatarRes.intersects, RayPickResult(IntersectionType::AVATAR, avatarRes.avatarID, avatarRes.distance, avatarRes.intersection, ray), avatarKey, res, rayKey, results); } } // Can't intersect with HUD in desktop mode if (rayPick->getFilter().doesPickHUD() && DependencyManager::get()->isHMDMode()) { - RayPickFilter::Flags hudMask = rayPick->getFilter().getHUDFlags(); - if (!checkAndCompareCachedResults(rayKey, results, res, hudMask)) { + RayCacheKey hudKey = { rayPick->getFilter().getHUDFlags(), QVector(), QVector() }; + if (!checkAndCompareCachedResults(rayKey, results, res, hudKey)) { glm::vec3 hudRes = DependencyManager::get()->calculateRayUICollisionPoint(ray.origin, ray.direction); - cacheResult(true, RayPickResult(IntersectionType::HUD, 0, glm::distance(ray.origin, hudRes), hudRes, ray), hudMask, res, rayKey, results); + cacheResult(true, RayPickResult(IntersectionType::HUD, 0, glm::distance(ray.origin, hudRes), hudRes, ray), hudKey, res, rayKey, results); } } @@ -123,109 +131,87 @@ void RayPickManager::update() { } } -QUuid RayPickManager::createRayPick(const std::string& jointName, const glm::vec3& posOffset, const glm::vec3& dirOffset, const RayPickFilter& filter, const float maxDistance, const bool enabled) { - QWriteLocker lock(&_containsLock); +QUuid RayPickManager::createRayPick(const std::string& jointName, const glm::vec3& posOffset, const glm::vec3& dirOffset, const RayPickFilter& filter, float maxDistance, bool enabled) { + auto newRayPick = std::make_shared(jointName, posOffset, dirOffset, filter, maxDistance, enabled); QUuid id = QUuid::createUuid(); - _rayPicks[id] = std::make_shared(jointName, posOffset, dirOffset, filter, maxDistance, enabled); + withWriteLock([&] { + _rayPicks[id] = newRayPick; + }); return id; } -QUuid RayPickManager::createRayPick(const RayPickFilter& filter, const float maxDistance, const bool enabled) { - QWriteLocker lock(&_containsLock); +QUuid RayPickManager::createRayPick(const RayPickFilter& filter, float maxDistance, bool enabled) { QUuid id = QUuid::createUuid(); - _rayPicks[id] = std::make_shared(filter, maxDistance, enabled); + auto newRayPick = std::make_shared(filter, maxDistance, enabled); + withWriteLock([&] { + _rayPicks[id] = newRayPick; + }); return id; } -QUuid RayPickManager::createRayPick(const glm::vec3& position, const glm::vec3& direction, const RayPickFilter& filter, const float maxDistance, const bool enabled) { - QWriteLocker lock(&_containsLock); +QUuid RayPickManager::createRayPick(const glm::vec3& position, const glm::vec3& direction, const RayPickFilter& filter, float maxDistance, bool enabled) { QUuid id = QUuid::createUuid(); - _rayPicks[id] = std::make_shared(position, direction, filter, maxDistance, enabled); + auto newRayPick = std::make_shared(position, direction, filter, maxDistance, enabled); + withWriteLock([&] { + _rayPicks[id] = newRayPick; + }); return id; } -void RayPickManager::removeRayPick(const QUuid uid) { - QWriteLocker lock(&_containsLock); - _rayPicks.remove(uid); +void RayPickManager::removeRayPick(const QUuid& uid) { + withWriteLock([&] { + _rayPicks.remove(uid); + }); } -void RayPickManager::enableRayPick(const QUuid uid) { - QReadLocker containsLock(&_containsLock); - auto rayPick = _rayPicks.find(uid); - if (rayPick != _rayPicks.end()) { - rayPick.value()->enable(); +RayPick::Pointer RayPickManager::findRayPick(const QUuid& uid) const { + return resultWithReadLock([&] { + if (_rayPicks.contains(uid)) { + return _rayPicks[uid]; + } + return RayPick::Pointer(); + }); +} + +void RayPickManager::enableRayPick(const QUuid& uid) const { + auto rayPick = findRayPick(uid); + if (rayPick) { + rayPick->enable(); } } -void RayPickManager::disableRayPick(const QUuid uid) { - QReadLocker containsLock(&_containsLock); - auto rayPick = _rayPicks.find(uid); - if (rayPick != _rayPicks.end()) { - rayPick.value()->disable(); +void RayPickManager::disableRayPick(const QUuid& uid) const { + auto rayPick = findRayPick(uid); + if (rayPick) { + rayPick->disable(); } } -const RayPickResult RayPickManager::getPrevRayPickResult(const QUuid uid) { - QReadLocker containsLock(&_containsLock); - auto rayPick = _rayPicks.find(uid); - if (rayPick != _rayPicks.end()) { - return rayPick.value()->getPrevRayPickResult(); +RayPickResult RayPickManager::getPrevRayPickResult(const QUuid& uid) const { + auto rayPick = findRayPick(uid); + if (rayPick) { + return rayPick->getPrevRayPickResult(); } return RayPickResult(); } -void RayPickManager::setPrecisionPicking(QUuid uid, const bool precisionPicking) { - QReadLocker containsLock(&_containsLock); - auto rayPick = _rayPicks.find(uid); - if (rayPick != _rayPicks.end()) { - rayPick.value()->setPrecisionPicking(precisionPicking); +void RayPickManager::setPrecisionPicking(const QUuid& uid, bool precisionPicking) const { + auto rayPick = findRayPick(uid); + if (rayPick) { + rayPick->setPrecisionPicking(precisionPicking); } } -void RayPickManager::setIgnoreEntities(QUuid uid, const QScriptValue& ignoreEntities) { - QReadLocker containsLock(&_containsLock); - auto rayPick = _rayPicks.find(uid); - if (rayPick != _rayPicks.end()) { - rayPick.value()->setIgnoreEntities(ignoreEntities); +void RayPickManager::setIgnoreItems(const QUuid& uid, const QVector& ignore) const { + auto rayPick = findRayPick(uid); + if (rayPick) { + rayPick->setIgnoreItems(ignore); } } -void RayPickManager::setIncludeEntities(QUuid uid, const QScriptValue& includeEntities) { - QReadLocker containsLock(&_containsLock); - auto rayPick = _rayPicks.find(uid); - if (rayPick != _rayPicks.end()) { - rayPick.value()->setIncludeEntities(includeEntities); +void RayPickManager::setIncludeItems(const QUuid& uid, const QVector& include) const { + auto rayPick = findRayPick(uid); + if (rayPick) { + rayPick->setIncludeItems(include); } } - -void RayPickManager::setIgnoreOverlays(QUuid uid, const QScriptValue& ignoreOverlays) { - QReadLocker containsLock(&_containsLock); - auto rayPick = _rayPicks.find(uid); - if (rayPick != _rayPicks.end()) { - rayPick.value()->setIgnoreOverlays(ignoreOverlays); - } -} - -void RayPickManager::setIncludeOverlays(QUuid uid, const QScriptValue& includeOverlays) { - QReadLocker containsLock(&_containsLock); - auto rayPick = _rayPicks.find(uid); - if (rayPick != _rayPicks.end()) { - rayPick.value()->setIncludeOverlays(includeOverlays); - } -} - -void RayPickManager::setIgnoreAvatars(QUuid uid, const QScriptValue& ignoreAvatars) { - QReadLocker containsLock(&_containsLock); - auto rayPick = _rayPicks.find(uid); - if (rayPick != _rayPicks.end()) { - rayPick.value()->setIgnoreAvatars(ignoreAvatars); - } -} - -void RayPickManager::setIncludeAvatars(QUuid uid, const QScriptValue& includeAvatars) { - QReadLocker containsLock(&_containsLock); - auto rayPick = _rayPicks.find(uid); - if (rayPick != _rayPicks.end()) { - rayPick.value()->setIncludeAvatars(includeAvatars); - } -} \ No newline at end of file diff --git a/interface/src/raypick/RayPickManager.h b/interface/src/raypick/RayPickManager.h index 974022eb4d..fd2c6f4a6b 100644 --- a/interface/src/raypick/RayPickManager.h +++ b/interface/src/raypick/RayPickManager.h @@ -11,19 +11,39 @@ #ifndef hifi_RayPickManager_h #define hifi_RayPickManager_h -#include "RayPick.h" #include -#include - -#include "RegisteredMetaTypes.h" - #include #include +#include + +#include +#include + + class RayPickResult; -class RayPickManager { +typedef struct RayCacheKey { + RayPickFilter::Flags mask; + QVector include; + QVector ignore; + + bool operator==(const RayCacheKey& other) const { + return (mask == other.mask && include == other.include && ignore == other.ignore); + } +} RayCacheKey; + +namespace std { + template <> + struct hash { + size_t operator()(const RayCacheKey& k) const { + return ((hash()(k.mask) ^ (qHash(k.include) << 1)) >> 1) ^ (qHash(k.ignore) << 1); + } + }; +} + +class RayPickManager : protected ReadWriteLockable { public: void update(); @@ -31,28 +51,24 @@ public: QUuid createRayPick(const std::string& jointName, const glm::vec3& posOffset, const glm::vec3& dirOffset, const RayPickFilter& filter, const float maxDistance, const bool enabled); QUuid createRayPick(const RayPickFilter& filter, const float maxDistance, const bool enabled); QUuid createRayPick(const glm::vec3& position, const glm::vec3& direction, const RayPickFilter& filter, const float maxDistance, const bool enabled); - void removeRayPick(const QUuid uid); - void enableRayPick(const QUuid uid); - void disableRayPick(const QUuid uid); - const RayPickResult getPrevRayPickResult(const QUuid uid); + void removeRayPick(const QUuid& uid); + void enableRayPick(const QUuid& uid) const; + void disableRayPick(const QUuid& uid) const; + RayPickResult getPrevRayPickResult(const QUuid& uid) const; - void setPrecisionPicking(QUuid uid, const bool precisionPicking); - void setIgnoreEntities(QUuid uid, const QScriptValue& ignoreEntities); - void setIncludeEntities(QUuid uid, const QScriptValue& includeEntities); - void setIgnoreOverlays(QUuid uid, const QScriptValue& ignoreOverlays); - void setIncludeOverlays(QUuid uid, const QScriptValue& includeOverlays); - void setIgnoreAvatars(QUuid uid, const QScriptValue& ignoreAvatars); - void setIncludeAvatars(QUuid uid, const QScriptValue& includeAvatars); + void setPrecisionPicking(const QUuid& uid, bool precisionPicking) const; + void setIgnoreItems(const QUuid& uid, const QVector& ignore) const; + void setIncludeItems(const QUuid& uid, const QVector& include) const; private: - QHash> _rayPicks; - QReadWriteLock _containsLock; + RayPick::Pointer findRayPick(const QUuid& uid) const; + QHash _rayPicks; - typedef QHash, std::unordered_map> RayPickCache; + typedef QHash, std::unordered_map> RayPickCache; // Returns true if this ray exists in the cache, and if it does, update res if the cached result is closer - bool checkAndCompareCachedResults(QPair& ray, RayPickCache& cache, RayPickResult& res, const RayPickFilter::Flags& mask); - void cacheResult(const bool intersects, const RayPickResult& resTemp, const RayPickFilter::Flags& mask, RayPickResult& res, QPair& ray, RayPickCache& cache); + bool checkAndCompareCachedResults(QPair& ray, RayPickCache& cache, RayPickResult& res, const RayCacheKey& key); + void cacheResult(const bool intersects, const RayPickResult& resTemp, const RayCacheKey& key, RayPickResult& res, QPair& ray, RayPickCache& cache); }; #endif // hifi_RayPickManager_h \ No newline at end of file diff --git a/interface/src/raypick/RayPickScriptingInterface.cpp b/interface/src/raypick/RayPickScriptingInterface.cpp index cb2b3e4471..621ae9b738 100644 --- a/interface/src/raypick/RayPickScriptingInterface.cpp +++ b/interface/src/raypick/RayPickScriptingInterface.cpp @@ -66,46 +66,30 @@ QUuid RayPickScriptingInterface::createRayPick(const QVariant& properties) { return QUuid(); } -void RayPickScriptingInterface::enableRayPick(QUuid uid) { +void RayPickScriptingInterface::enableRayPick(const QUuid& uid) { qApp->getRayPickManager().enableRayPick(uid); } -void RayPickScriptingInterface::disableRayPick(QUuid uid) { +void RayPickScriptingInterface::disableRayPick(const QUuid& uid) { qApp->getRayPickManager().disableRayPick(uid); } -void RayPickScriptingInterface::removeRayPick(QUuid uid) { +void RayPickScriptingInterface::removeRayPick(const QUuid& uid) { qApp->getRayPickManager().removeRayPick(uid); } -RayPickResult RayPickScriptingInterface::getPrevRayPickResult(QUuid uid) { +RayPickResult RayPickScriptingInterface::getPrevRayPickResult(const QUuid& uid) { return qApp->getRayPickManager().getPrevRayPickResult(uid); } -void RayPickScriptingInterface::setPrecisionPicking(QUuid uid, const bool precisionPicking) { +void RayPickScriptingInterface::setPrecisionPicking(const QUuid& uid, const bool precisionPicking) { qApp->getRayPickManager().setPrecisionPicking(uid, precisionPicking); } -void RayPickScriptingInterface::setIgnoreEntities(QUuid uid, const QScriptValue& ignoreEntities) { - qApp->getRayPickManager().setIgnoreEntities(uid, ignoreEntities); +void RayPickScriptingInterface::setIgnoreItems(const QUuid& uid, const QScriptValue& ignoreItems) { + qApp->getRayPickManager().setIgnoreItems(uid, qVectorQUuidFromScriptValue(ignoreItems)); } -void RayPickScriptingInterface::setIncludeEntities(QUuid uid, const QScriptValue& includeEntities) { - qApp->getRayPickManager().setIncludeEntities(uid, includeEntities); -} - -void RayPickScriptingInterface::setIgnoreOverlays(QUuid uid, const QScriptValue& ignoreOverlays) { - qApp->getRayPickManager().setIgnoreOverlays(uid, ignoreOverlays); -} - -void RayPickScriptingInterface::setIncludeOverlays(QUuid uid, const QScriptValue& includeOverlays) { - qApp->getRayPickManager().setIncludeOverlays(uid, includeOverlays); -} - -void RayPickScriptingInterface::setIgnoreAvatars(QUuid uid, const QScriptValue& ignoreAvatars) { - qApp->getRayPickManager().setIgnoreAvatars(uid, ignoreAvatars); -} - -void RayPickScriptingInterface::setIncludeAvatars(QUuid uid, const QScriptValue& includeAvatars) { - qApp->getRayPickManager().setIncludeAvatars(uid, includeAvatars); +void RayPickScriptingInterface::setIncludeItems(const QUuid& uid, const QScriptValue& includeItems) { + qApp->getRayPickManager().setIncludeItems(uid, qVectorQUuidFromScriptValue(includeItems)); } diff --git a/interface/src/raypick/RayPickScriptingInterface.h b/interface/src/raypick/RayPickScriptingInterface.h index f7ed2e6fa6..099103e4c5 100644 --- a/interface/src/raypick/RayPickScriptingInterface.h +++ b/interface/src/raypick/RayPickScriptingInterface.h @@ -13,10 +13,9 @@ #include -#include "RegisteredMetaTypes.h" -#include "DependencyManager.h" - -#include "RayPick.h" +#include +#include +#include class RayPickScriptingInterface : public QObject, public Dependency { Q_OBJECT @@ -25,7 +24,7 @@ class RayPickScriptingInterface : public QObject, public Dependency { Q_PROPERTY(unsigned int PICK_OVERLAYS READ PICK_OVERLAYS CONSTANT) Q_PROPERTY(unsigned int PICK_AVATARS READ PICK_AVATARS CONSTANT) Q_PROPERTY(unsigned int PICK_HUD READ PICK_HUD CONSTANT) - Q_PROPERTY(unsigned int PICK_COURSE READ PICK_COURSE CONSTANT) + Q_PROPERTY(unsigned int PICK_COARSE READ PICK_COARSE CONSTANT) Q_PROPERTY(unsigned int PICK_INCLUDE_INVISIBLE READ PICK_INCLUDE_INVISIBLE CONSTANT) Q_PROPERTY(unsigned int PICK_INCLUDE_NONCOLLIDABLE READ PICK_INCLUDE_NONCOLLIDABLE CONSTANT) Q_PROPERTY(unsigned int PICK_ALL_INTERSECTIONS READ PICK_ALL_INTERSECTIONS CONSTANT) @@ -38,25 +37,21 @@ class RayPickScriptingInterface : public QObject, public Dependency { public slots: Q_INVOKABLE QUuid createRayPick(const QVariant& properties); - Q_INVOKABLE void enableRayPick(QUuid uid); - Q_INVOKABLE void disableRayPick(QUuid uid); - Q_INVOKABLE void removeRayPick(QUuid uid); - Q_INVOKABLE RayPickResult getPrevRayPickResult(QUuid uid); + Q_INVOKABLE void enableRayPick(const QUuid& uid); + Q_INVOKABLE void disableRayPick(const QUuid& uid); + Q_INVOKABLE void removeRayPick(const QUuid& uid); + Q_INVOKABLE RayPickResult getPrevRayPickResult(const QUuid& uid); - Q_INVOKABLE void setPrecisionPicking(QUuid uid, const bool precisionPicking); - Q_INVOKABLE void setIgnoreEntities(QUuid uid, const QScriptValue& ignoreEntities); - Q_INVOKABLE void setIncludeEntities(QUuid uid, const QScriptValue& includeEntities); - Q_INVOKABLE void setIgnoreOverlays(QUuid uid, const QScriptValue& ignoreOverlays); - Q_INVOKABLE void setIncludeOverlays(QUuid uid, const QScriptValue& includeOverlays); - Q_INVOKABLE void setIgnoreAvatars(QUuid uid, const QScriptValue& ignoreAvatars); - Q_INVOKABLE void setIncludeAvatars(QUuid uid, const QScriptValue& includeAvatars); + Q_INVOKABLE void setPrecisionPicking(const QUuid& uid, const bool precisionPicking); + Q_INVOKABLE void setIgnoreItems(const QUuid& uid, const QScriptValue& ignoreEntities); + Q_INVOKABLE void setIncludeItems(const QUuid& uid, const QScriptValue& includeEntities); - unsigned int PICK_NOTHING() { return RayPickFilter::getBitMask(RayPickFilter::FlagBit::PICK_NOTHING); } + unsigned int PICK_NOTHING() { return 0; } unsigned int PICK_ENTITIES() { return RayPickFilter::getBitMask(RayPickFilter::FlagBit::PICK_ENTITIES); } unsigned int PICK_OVERLAYS() { return RayPickFilter::getBitMask(RayPickFilter::FlagBit::PICK_OVERLAYS); } unsigned int PICK_AVATARS() { return RayPickFilter::getBitMask(RayPickFilter::FlagBit::PICK_AVATARS); } unsigned int PICK_HUD() { return RayPickFilter::getBitMask(RayPickFilter::FlagBit::PICK_HUD); } - unsigned int PICK_COURSE() { return RayPickFilter::getBitMask(RayPickFilter::FlagBit::PICK_COURSE); } + unsigned int PICK_COARSE() { return RayPickFilter::getBitMask(RayPickFilter::FlagBit::PICK_COARSE); } unsigned int PICK_INCLUDE_INVISIBLE() { return RayPickFilter::getBitMask(RayPickFilter::FlagBit::PICK_INCLUDE_INVISIBLE); } unsigned int PICK_INCLUDE_NONCOLLIDABLE() { return RayPickFilter::getBitMask(RayPickFilter::FlagBit::PICK_INCLUDE_NONCOLLIDABLE); } unsigned int PICK_ALL_INTERSECTIONS() { return RayPickFilter::getBitMask(RayPickFilter::FlagBit::PICK_ALL_INTERSECTIONS); } diff --git a/interface/src/ui/overlays/Image3DOverlay.cpp b/interface/src/ui/overlays/Image3DOverlay.cpp index d0024d9710..313d71fc40 100644 --- a/interface/src/ui/overlays/Image3DOverlay.cpp +++ b/interface/src/ui/overlays/Image3DOverlay.cpp @@ -51,13 +51,11 @@ void Image3DOverlay::update(float deltatime) { _texture = DependencyManager::get()->getTexture(_url); _textureIsLoaded = false; } -#if OVERLAY_PANELS if (usecTimestampNow() > _transformExpiry) { Transform transform = getTransform(); applyTransformTo(transform); setTransform(transform); } -#endif Parent::update(deltatime); } diff --git a/interface/src/ui/overlays/Text3DOverlay.cpp b/interface/src/ui/overlays/Text3DOverlay.cpp index 2e55a9a471..d8188cf6dc 100644 --- a/interface/src/ui/overlays/Text3DOverlay.cpp +++ b/interface/src/ui/overlays/Text3DOverlay.cpp @@ -257,7 +257,3 @@ bool Text3DOverlay::findRayIntersection(const glm::vec3 &origin, const glm::vec3 return Billboard3DOverlay::findRayIntersection(origin, direction, distance, face, surfaceNormal); } -Transform Text3DOverlay::evalRenderTransform() { - return Parent::evalRenderTransform(); -} - diff --git a/interface/src/ui/overlays/Text3DOverlay.h b/interface/src/ui/overlays/Text3DOverlay.h index 6ed31f37b3..daa5fdc804 100644 --- a/interface/src/ui/overlays/Text3DOverlay.h +++ b/interface/src/ui/overlays/Text3DOverlay.h @@ -65,9 +65,6 @@ public: virtual Text3DOverlay* createClone() const override; -protected: - Transform evalRenderTransform() override; - private: TextRenderer3D* _textRenderer = nullptr; diff --git a/interface/src/ui/overlays/Web3DOverlay.cpp b/interface/src/ui/overlays/Web3DOverlay.cpp index 526890b9c1..363c85b395 100644 --- a/interface/src/ui/overlays/Web3DOverlay.cpp +++ b/interface/src/ui/overlays/Web3DOverlay.cpp @@ -63,7 +63,6 @@ static const float OPAQUE_ALPHA_THRESHOLD = 0.99f; const QString Web3DOverlay::TYPE = "web3d"; const QString Web3DOverlay::QML = "Web3DOverlay.qml"; - Web3DOverlay::Web3DOverlay() : _dpi(DPI) { _touchDevice.setCapabilities(QTouchDevice::Position); _touchDevice.setType(QTouchDevice::TouchScreen); @@ -248,6 +247,9 @@ void Web3DOverlay::setupQmlSurface() { _webSurface->getSurfaceContext()->setContextProperty("pathToFonts", "../../"); + // Tablet inteference with Tablet.qml. Need to avoid this in QML space + _webSurface->getSurfaceContext()->setContextProperty("tabletInterface", DependencyManager::get().data()); + tabletScriptingInterface->setQmlTabletRoot("com.highfidelity.interface.tablet.system", _webSurface.data()); // mark the TabletProxy object as cpp ownership. QObject* tablet = tabletScriptingInterface->getTablet("com.highfidelity.interface.tablet.system"); diff --git a/libraries/animation/src/Rig.cpp b/libraries/animation/src/Rig.cpp index 0897c26a12..0f2bce5ca4 100644 --- a/libraries/animation/src/Rig.cpp +++ b/libraries/animation/src/Rig.cpp @@ -32,6 +32,7 @@ #include "AnimUtil.h" #include "IKTarget.h" + static int nextRigId = 1; static std::map rigRegistry; static std::mutex rigRegistryMutex; @@ -999,14 +1000,13 @@ void Rig::updateAnimationStateHandlers() { // called on avatar update thread (wh } void Rig::updateAnimations(float deltaTime, const glm::mat4& rootTransform, const glm::mat4& rigToWorldTransform) { - - PROFILE_RANGE_EX(simulation_animation_detail, __FUNCTION__, 0xffff00ff, 0); - PerformanceTimer perfTimer("updateAnimations"); + DETAILED_PROFILE_RANGE_EX(simulation_animation_detail, __FUNCTION__, 0xffff00ff, 0); + DETAILED_PERFORMANCE_TIMER("updateAnimations"); setModelOffset(rootTransform); if (_animNode && _enabledAnimations) { - PerformanceTimer perfTimer("handleTriggers"); + DETAILED_PERFORMANCE_TIMER("handleTriggers"); updateAnimationStateHandlers(); _animVars.setRigToGeometryTransform(_rigToGeometryTransform); @@ -1658,7 +1658,7 @@ bool Rig::getModelRegistrationPoint(glm::vec3& modelRegistrationPointOut) const } void Rig::applyOverridePoses() { - PerformanceTimer perfTimer("override"); + DETAILED_PERFORMANCE_TIMER("override"); if (_numOverrides == 0 || !_animSkeleton) { return; } @@ -1675,7 +1675,7 @@ void Rig::applyOverridePoses() { } void Rig::buildAbsoluteRigPoses(const AnimPoseVec& relativePoses, AnimPoseVec& absolutePosesOut) { - PerformanceTimer perfTimer("buildAbsolute"); + DETAILED_PERFORMANCE_TIMER("buildAbsolute"); if (!_animSkeleton) { return; } @@ -1730,8 +1730,9 @@ void Rig::copyJointsIntoJointData(QVector& jointDataVec) const { } void Rig::copyJointsFromJointData(const QVector& jointDataVec) { - PerformanceTimer perfTimer("copyJoints"); - PROFILE_RANGE(simulation_animation_detail, "copyJoints"); + DETAILED_PROFILE_RANGE(simulation_animation_detail, "copyJoints"); + DETAILED_PERFORMANCE_TIMER("copyJoints"); + if (!_animSkeleton) { return; } diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.cpp b/libraries/entities-renderer/src/EntityTreeRenderer.cpp index 85916baf60..4238eb4050 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.cpp +++ b/libraries/entities-renderer/src/EntityTreeRenderer.cpp @@ -160,6 +160,8 @@ void EntityTreeRenderer::shutdown() { } void EntityTreeRenderer::addPendingEntities(const render::ScenePointer& scene, render::Transaction& transaction) { + PROFILE_RANGE_EX(simulation_physics, "Add", 0xffff00ff, (uint64_t)_entitiesToAdd.size()); + PerformanceTimer pt("add"); // Clear any expired entities // FIXME should be able to use std::remove_if, but it fails due to some // weird compilation error related to EntityItemID assignment operators @@ -203,6 +205,8 @@ void EntityTreeRenderer::addPendingEntities(const render::ScenePointer& scene, r } void EntityTreeRenderer::updateChangedEntities(const render::ScenePointer& scene, render::Transaction& transaction) { + PROFILE_RANGE_EX(simulation_physics, "Change", 0xffff00ff, (uint64_t)_changedEntities.size()); + PerformanceTimer pt("change"); std::unordered_set changedEntities; _changedEntitiesGuard.withWriteLock([&] { #if 0 @@ -223,6 +227,7 @@ void EntityTreeRenderer::updateChangedEntities(const render::ScenePointer& scene } if (!_renderablesToUpdate.empty()) { + PROFILE_RANGE_EX(simulation_physics, "UpdateRenderables", 0xffff00ff, (uint64_t)_renderablesToUpdate.size()); for (const auto& entry : _renderablesToUpdate) { const auto& renderable = entry.second; renderable->updateInScene(scene, transaction); @@ -232,6 +237,7 @@ void EntityTreeRenderer::updateChangedEntities(const render::ScenePointer& scene } void EntityTreeRenderer::update(bool simulate) { + PROFILE_RANGE(simulation_physics, "ETR::update"); PerformanceTimer perfTimer("ETRupdate"); if (_tree && !_shuttingDown) { EntityTreePointer tree = std::static_pointer_cast(_tree); @@ -239,22 +245,14 @@ void EntityTreeRenderer::update(bool simulate) { // Update the rendereable entities as needed { + PROFILE_RANGE(simulation_physics, "Scene"); PerformanceTimer sceneTimer("scene"); auto scene = _viewState->getMain3DScene(); if (scene) { render::Transaction transaction; - { - PerformanceTimer pt("add"); - addPendingEntities(scene, transaction); - } - { - PerformanceTimer pt("change"); - updateChangedEntities(scene, transaction); - } - { - PerformanceTimer pt("enqueue"); - scene->enqueueTransaction(transaction); - } + addPendingEntities(scene, transaction); + updateChangedEntities(scene, transaction); + scene->enqueueTransaction(transaction); } } @@ -336,7 +334,8 @@ bool EntityTreeRenderer::findBestZoneAndMaybeContainingEntities(QVectorsetSnapModelToRegistrationPoint(true, getRegistrationPoint()); model->setRotation(getRotation()); model->setTranslation(getPosition()); - { - PerformanceTimer perfTimer("model->simulate"); + + if (_needsInitialSimulation) { model->simulate(0.0f); + _needsInitialSimulation = false; } - _needsInitialSimulation = false; } void RenderableModelEntityItem::autoResizeJointArrays() { @@ -138,6 +140,7 @@ void RenderableModelEntityItem::autoResizeJointArrays() { } bool RenderableModelEntityItem::needsUpdateModelBounds() const { + DETAILED_PROFILE_RANGE(simulation_physics, __FUNCTION__); ModelPointer model = getModel(); if (!hasModel() || !model) { return false; @@ -151,7 +154,7 @@ bool RenderableModelEntityItem::needsUpdateModelBounds() const { return true; } - if (isMovingRelativeToParent() || isAnimatingSomething()) { + if (isAnimatingSomething()) { return true; } @@ -178,13 +181,61 @@ bool RenderableModelEntityItem::needsUpdateModelBounds() const { } } - return false; + return model->needsReload(); } void RenderableModelEntityItem::updateModelBounds() { - if (needsUpdateModelBounds()) { - doInitialModelSimulation(); + DETAILED_PROFILE_RANGE(simulation_physics, "updateModelBounds"); + + if (!_dimensionsInitialized || !hasModel()) { + return; + } + + ModelPointer model = getModel(); + if (!model || !model->isLoaded()) { + return; + } + + bool updateRenderItems = false; + if (model->needsReload()) { + model->updateGeometry(); + updateRenderItems = true; + } + + if (model->getScaleToFitDimensions() != getDimensions() || + model->getRegistrationPoint() != getRegistrationPoint()) { + // The machinery for updateModelBounds will give existing models the opportunity to fix their + // translation/rotation/scale/registration. The first two are straightforward, but the latter two + // have guards to make sure they don't happen after they've already been set. Here we reset those guards. + // This doesn't cause the entity values to change -- it just allows the model to match once it comes in. + model->setScaleToFit(false, getDimensions()); + model->setSnapModelToRegistrationPoint(false, getRegistrationPoint()); + + // now recalculate the bounds and registration + model->setScaleToFit(true, getDimensions()); + model->setSnapModelToRegistrationPoint(true, getRegistrationPoint()); + updateRenderItems = true; + } + + bool success; + auto transform = getTransform(success); + if (success && (model->getTranslation() != transform.getTranslation() || + model->getRotation() != transform.getRotation())) { + model->setTransformNoUpdateRenderItems(transform); + updateRenderItems = true; + } + + if (_needsInitialSimulation || _needsJointSimulation || isAnimatingSomething()) { + // NOTE: on isAnimatingSomething() we need to call Model::simulate() which calls Rig::updateRig() + // TODO: there is opportunity to further optimize the isAnimatingSomething() case. + model->simulate(0.0f); + _needsInitialSimulation = false; _needsJointSimulation = false; + updateRenderItems = true; + } + + if (updateRenderItems) { + model->updateRenderItems(); } } @@ -293,7 +344,7 @@ bool RenderableModelEntityItem::isReadyToComputeShape() const { // we have both URLs AND both geometries AND they are both fully loaded. if (_needsInitialSimulation) { // the _model's offset will be wrong until _needsInitialSimulation is false - PerformanceTimer perfTimer("_model->simulate"); + DETAILED_PERFORMANCE_TIMER("_model->simulate"); const_cast(this)->doInitialModelSimulation(); } return true; @@ -839,7 +890,7 @@ void RenderableModelEntityItem::setJointTranslationsSet(const QVector& tra } void RenderableModelEntityItem::locationChanged(bool tellPhysics) { - PerformanceTimer pertTimer("locationChanged"); + DETAILED_PERFORMANCE_TIMER("locationChanged"); EntityItem::locationChanged(tellPhysics); auto model = getModel(); if (model && model->isLoaded()) { @@ -880,7 +931,6 @@ void RenderableModelEntityItem::copyAnimationJointDataToModel() { return; } - // relay any inbound joint changes from scripts/animation/network to the model/rig _jointDataLock.withWriteLock([&] { for (int index = 0; index < _localJointData.size(); ++index) { @@ -897,15 +947,11 @@ void RenderableModelEntityItem::copyAnimationJointDataToModel() { }); } -bool RenderableModelEntityItem::isAnimatingSomething() const { - return !getAnimationURL().isEmpty() && getAnimationIsPlaying() && getAnimationFPS() != 0.0f; -} - using namespace render; using namespace render::entities; ItemKey ModelEntityRenderer::getKey() { - return ItemKey::Builder().withTypeMeta(); + return ItemKey::Builder().withTypeMeta().withTypeShape(); } uint32_t ModelEntityRenderer::metaFetchMetaSubItems(ItemIDs& subItems) { @@ -1124,6 +1170,7 @@ bool ModelEntityRenderer::needsRenderUpdateFromTypedEntity(const TypedEntityPoin } void ModelEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& scene, Transaction& transaction, const TypedEntityPointer& entity) { + DETAILED_PROFILE_RANGE(simulation_physics, __FUNCTION__); if (_hasModel != entity->hasModel()) { _hasModel = entity->hasModel(); } @@ -1202,9 +1249,7 @@ void ModelEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& sce } } - if (entity->needsUpdateModelBounds()) { - entity->updateModelBounds(); - } + entity->updateModelBounds(); if (model->isVisible() != _visible) { // FIXME: this seems like it could be optimized if we tracked our last known visible state in @@ -1212,13 +1257,16 @@ void ModelEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& sce // so most of the time we don't do anything in this function. model->setVisibleInScene(_visible, scene); } + // TODO? early exit here when not visible? - //entity->doInitialModelSimulation(); - if (model->needsFixupInScene()) { - model->removeFromScene(scene, transaction); - render::Item::Status::Getters statusGetters; - makeStatusGetters(entity, statusGetters); - model->addToScene(scene, transaction, statusGetters); + { + DETAILED_PROFILE_RANGE(simulation_physics, "Fixup"); + if (model->needsFixupInScene()) { + model->removeFromScene(scene, transaction); + render::Item::Status::Getters statusGetters; + makeStatusGetters(entity, statusGetters); + model->addToScene(scene, transaction, statusGetters); + } } // When the individual mesh parts of a model finish fading, they will mark their Model as needing updating @@ -1227,16 +1275,20 @@ void ModelEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& sce model->updateRenderItems(); } - // make a copy of the animation properites - auto newAnimationProperties = entity->getAnimationProperties(); - if (newAnimationProperties != _renderAnimationProperties) { - withWriteLock([&] { - _renderAnimationProperties = newAnimationProperties; - _currentFrame = _renderAnimationProperties.getCurrentFrame(); - }); + { + DETAILED_PROFILE_RANGE(simulation_physics, "CheckAnimation"); + // make a copy of the animation properites + auto newAnimationProperties = entity->getAnimationProperties(); + if (newAnimationProperties != _renderAnimationProperties) { + withWriteLock([&] { + _renderAnimationProperties = newAnimationProperties; + _currentFrame = _renderAnimationProperties.getCurrentFrame(); + }); + } } if (_animating) { + DETAILED_PROFILE_RANGE(simulation_physics, "Animate"); if (!jointsMapped()) { mapJoints(entity, model->getJointNames()); } @@ -1247,15 +1299,16 @@ void ModelEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& sce // NOTE: this only renders the "meta" portion of the Model, namely it renders debugging items void ModelEntityRenderer::doRender(RenderArgs* args) { - PROFILE_RANGE(render_detail, "MetaModelRender"); - PerformanceTimer perfTimer("RMEIrender"); + DETAILED_PROFILE_RANGE(render_detail, "MetaModelRender"); + DETAILED_PERFORMANCE_TIMER("RMEIrender"); ModelPointer model; withReadLock([&]{ model = _model; }); - if (_model && _model->didVisualGeometryRequestFail()) { + // If we don't have a model, or the model doesn't have visual geometry, render our bounding box as green wireframe + if (!model || (model && model->didVisualGeometryRequestFail())) { static glm::vec4 greenColor(0.0f, 1.0f, 0.0f, 1.0f); gpu::Batch& batch = *args->_batch; batch.setModelTransform(_modelTransform); // we want to include the scale as well diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.h b/libraries/entities-renderer/src/RenderableModelEntityItem.h index d1424316e9..a50ca63382 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.h +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.h @@ -108,7 +108,6 @@ public: private: bool needsUpdateModelBounds() const; - bool isAnimatingSomething() const; void autoResizeJointArrays(); void copyAnimationJointDataToModel(); diff --git a/libraries/entities/src/EntitiesScriptEngineProvider.h b/libraries/entities/src/EntitiesScriptEngineProvider.h index d87dd105c2..100c17df5f 100644 --- a/libraries/entities/src/EntitiesScriptEngineProvider.h +++ b/libraries/entities/src/EntitiesScriptEngineProvider.h @@ -20,7 +20,8 @@ class EntitiesScriptEngineProvider { public: - virtual void callEntityScriptMethod(const EntityItemID& entityID, const QString& methodName, const QStringList& params = QStringList()) = 0; + virtual void callEntityScriptMethod(const EntityItemID& entityID, const QString& methodName, + const QStringList& params = QStringList(), const QUuid& remoteCallerID = QUuid()) = 0; virtual QFuture getLocalEntityScriptDetails(const EntityItemID& entityID) = 0; }; diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index 32ac9823f6..51ed66bb23 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -228,11 +228,21 @@ const std::array COMPONENT_MODES = { { } }; QString EntityItemProperties::getHazeModeAsString() const { - return COMPONENT_MODES[_hazeMode].second; + // return "inherit" if _hazeMode is not valid + if (_hazeMode < COMPONENT_MODE_ITEM_COUNT) { + return COMPONENT_MODES[_hazeMode].second; + } else { + return COMPONENT_MODES[COMPONENT_MODE_INHERIT].second; + } } QString EntityItemProperties::getHazeModeString(uint32_t mode) { - return COMPONENT_MODES[mode].second; + // return "inherit" if mode is not valid + if (mode < COMPONENT_MODE_ITEM_COUNT) { + return COMPONENT_MODES[mode].second; + } else { + return COMPONENT_MODES[COMPONENT_MODE_INHERIT].second; + } } void EntityItemProperties::setHazeModeFromString(const QString& hazeMode) { diff --git a/libraries/entities/src/EntityScriptingInterface.cpp b/libraries/entities/src/EntityScriptingInterface.cpp index 66a64db15e..2c349a9297 100644 --- a/libraries/entities/src/EntityScriptingInterface.cpp +++ b/libraries/entities/src/EntityScriptingInterface.cpp @@ -566,6 +566,11 @@ void EntityScriptingInterface::callEntityMethod(QUuid id, const QString& method, } } +void EntityScriptingInterface::callEntityServerMethod(QUuid id, const QString& method, const QStringList& params) { + PROFILE_RANGE(script_entities, __FUNCTION__); + DependencyManager::get()->callEntityServerMethod(id, method, params); +} + QUuid EntityScriptingInterface::findClosestEntity(const glm::vec3& center, float radius) const { PROFILE_RANGE(script_entities, __FUNCTION__); diff --git a/libraries/entities/src/EntityScriptingInterface.h b/libraries/entities/src/EntityScriptingInterface.h index 2dc31dbe7d..3f89b6dea7 100644 --- a/libraries/entities/src/EntityScriptingInterface.h +++ b/libraries/entities/src/EntityScriptingInterface.h @@ -188,11 +188,11 @@ public slots: */ Q_INVOKABLE void deleteEntity(QUuid entityID); - /// Allows a script to call a method on an entity's script. The method will execute in the entity script - /// engine. If the entity does not have an entity script or the method does not exist, this call will have - /// no effect. /**jsdoc - * Call a method on an entity. If it is running an entity script (specified by the `script` property) + * Call a method on an entity. Allows a script to call a method on an entity's script. + * The method will execute in the entity script engine. If the entity does not have an + * entity script or the method does not exist, this call will have no effect. + * If it is running an entity script (specified by the `script` property) * and it exposes a property with the specified name `method`, it will be called * using `params` as the list of arguments. * @@ -203,10 +203,29 @@ public slots: */ Q_INVOKABLE void callEntityMethod(QUuid entityID, const QString& method, const QStringList& params = QStringList()); - /// finds the closest model to the center point, within the radius - /// will return a EntityItemID.isKnownID = false if no models are in the radius - /// this function will not find any models in script engine contexts which don't have access to models /**jsdoc + * Call a server method on an entity. Allows a client entity script to call a method on an + * entity's server script. The method will execute in the entity server script engine. If + * the entity does not have an entity server script or the method does not exist, this call will + * have no effect. If the entity is running an entity script (specified by the `serverScripts` property) + * and it exposes a property with the specified name `method`, it will be called using `params` as + * the list of arguments. + * + * @function Entities.callEntityServerMethod + * @param {EntityID} entityID The ID of the entity to call the method on. + * @param {string} method The name of the method to call. + * @param {string[]} params The list of parameters to call the specified method with. + */ + Q_INVOKABLE void callEntityServerMethod(QUuid entityID, const QString& method, const QStringList& params = QStringList()); + + /**jsdoc + * finds the closest model to the center point, within the radius + * will return a EntityItemID.isKnownID = false if no models are in the radius + * this function will not find any models in script engine contexts which don't have access to models + * @function Entities.findClosestEntity + * @param {vec3} center point + * @param {float} radius to search + * @return {EntityID} The EntityID of the entity that is closest and in the radius. */ Q_INVOKABLE QUuid findClosestEntity(const glm::vec3& center, float radius) const; diff --git a/libraries/entities/src/EntitySimulation.cpp b/libraries/entities/src/EntitySimulation.cpp index 2e330fdcc5..f91d728d78 100644 --- a/libraries/entities/src/EntitySimulation.cpp +++ b/libraries/entities/src/EntitySimulation.cpp @@ -9,9 +9,11 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include - #include "EntitySimulation.h" + +#include +#include + #include "EntitiesLogging.h" #include "MovingEntitiesOperator.h" @@ -27,6 +29,7 @@ void EntitySimulation::setEntityTree(EntityTreePointer tree) { } void EntitySimulation::updateEntities() { + PROFILE_RANGE(simulation_physics, "ES::updateEntities"); QMutexLocker lock(&_mutex); quint64 now = usecTimestampNow(); @@ -35,8 +38,12 @@ void EntitySimulation::updateEntities() { callUpdateOnEntitiesThatNeedIt(now); moveSimpleKinematics(now); updateEntitiesInternal(now); - PerformanceTimer perfTimer("sortingEntities"); - sortEntitiesThatMoved(); + + { + PROFILE_RANGE(simulation_physics, "Sort"); + PerformanceTimer perfTimer("sortingEntities"); + sortEntitiesThatMoved(); + } } void EntitySimulation::takeEntitiesToDelete(VectorOfEntities& entitiesToDelete) { @@ -258,6 +265,7 @@ void EntitySimulation::clearEntities() { } void EntitySimulation::moveSimpleKinematics(const quint64& now) { + PROFILE_RANGE_EX(simulation_physics, "Kinematics", 0xffff00ff, (uint64_t)_simpleKinematicEntities.size()); SetOfEntities::iterator itemItr = _simpleKinematicEntities.begin(); while (itemItr != _simpleKinematicEntities.end()) { EntityItemPointer entity = *itemItr; diff --git a/libraries/entities/src/EntityTree.cpp b/libraries/entities/src/EntityTree.cpp index f8db876728..bca921fe0f 100644 --- a/libraries/entities/src/EntityTree.cpp +++ b/libraries/entities/src/EntityTree.cpp @@ -25,8 +25,9 @@ #include -#include #include +#include +#include #include "EntitySimulation.h" #include "VariantMapToScriptValue.h" @@ -1628,6 +1629,7 @@ void EntityTree::entityChanged(EntityItemPointer entity) { void EntityTree::fixupNeedsParentFixups() { + PROFILE_RANGE(simulation_physics, "FixupParents"); MovingEntitiesOperator moveOperator; QWriteLocker locker(&_needsParentFixupLock); @@ -1717,6 +1719,7 @@ void EntityTree::addToNeedsParentFixupList(EntityItemPointer entity) { } void EntityTree::update(bool simulate) { + PROFILE_RANGE(simulation_physics, "ET::update"); fixupNeedsParentFixups(); if (simulate && _simulation) { withWriteLock([&] { diff --git a/libraries/entities/src/ModelEntityItem.cpp b/libraries/entities/src/ModelEntityItem.cpp index 6af4db154a..a5d259ea87 100644 --- a/libraries/entities/src/ModelEntityItem.cpp +++ b/libraries/entities/src/ModelEntityItem.cpp @@ -557,12 +557,6 @@ void ModelEntityItem::setAnimationLoop(bool loop) { }); } -bool ModelEntityItem::getAnimationLoop() const { - return resultWithReadLock([&] { - return _animationProperties.getLoop(); - }); -} - void ModelEntityItem::setAnimationHold(bool hold) { withWriteLock([&] { _animationProperties.setHold(hold); @@ -610,8 +604,10 @@ float ModelEntityItem::getAnimationCurrentFrame() const { }); } -float ModelEntityItem::getAnimationFPS() const { +bool ModelEntityItem::isAnimatingSomething() const { return resultWithReadLock([&] { - return _animationProperties.getFPS(); - }); + return !_animationProperties.getURL().isEmpty() && + _animationProperties.getRunning() && + (_animationProperties.getFPS() != 0.0f); + }); } diff --git a/libraries/entities/src/ModelEntityItem.h b/libraries/entities/src/ModelEntityItem.h index 7efb493735..2c3ef3aa2d 100644 --- a/libraries/entities/src/ModelEntityItem.h +++ b/libraries/entities/src/ModelEntityItem.h @@ -90,7 +90,6 @@ public: bool getAnimationAllowTranslation() const { return _animationProperties.getAllowTranslation(); }; void setAnimationLoop(bool loop); - bool getAnimationLoop() const; void setAnimationHold(bool hold); bool getAnimationHold() const; @@ -101,10 +100,9 @@ public: void setAnimationLastFrame(float lastFrame); float getAnimationLastFrame() const; - bool getAnimationIsPlaying() const; float getAnimationCurrentFrame() const; - float getAnimationFPS() const; + bool isAnimatingSomething() const; static const QString DEFAULT_TEXTURES; const QString getTextures() const; @@ -123,7 +121,6 @@ public: QVector getJointRotationsSet() const; QVector getJointTranslations() const; QVector getJointTranslationsSet() const; - bool isAnimatingSomething() const; private: void setAnimationSettings(const QString& value); // only called for old bitstream format diff --git a/libraries/entities/src/ZoneEntityItem.cpp b/libraries/entities/src/ZoneEntityItem.cpp index 077024c3ab..588c1f9386 100644 --- a/libraries/entities/src/ZoneEntityItem.cpp +++ b/libraries/entities/src/ZoneEntityItem.cpp @@ -321,8 +321,10 @@ void ZoneEntityItem::resetRenderingPropertiesChanged() { } void ZoneEntityItem::setHazeMode(const uint32_t value) { - _hazeMode = value; - _hazePropertiesChanged = true; + if (value < COMPONENT_MODE_ITEM_COUNT) { + _hazeMode = value; + _hazePropertiesChanged = true; + } } uint32_t ZoneEntityItem::getHazeMode() const { diff --git a/libraries/entities/src/ZoneEntityItem.h b/libraries/entities/src/ZoneEntityItem.h index 066bd5518f..ddbb2ed914 100644 --- a/libraries/entities/src/ZoneEntityItem.h +++ b/libraries/entities/src/ZoneEntityItem.h @@ -138,6 +138,8 @@ public: static const bool DEFAULT_GHOSTING_ALLOWED; static const QString DEFAULT_FILTER_URL; + static const uint32_t DEFAULT_HAZE_MODE{ (uint32_t)COMPONENT_MODE_INHERIT }; + protected: KeyLightPropertyGroup _keyLightProperties; @@ -146,7 +148,7 @@ protected: BackgroundMode _backgroundMode = BACKGROUND_MODE_INHERIT; - uint8_t _hazeMode{ (uint8_t)COMPONENT_MODE_INHERIT }; + uint32_t _hazeMode{ DEFAULT_HAZE_MODE }; float _hazeRange{ HazePropertyGroup::DEFAULT_HAZE_RANGE }; xColor _hazeColor{ HazePropertyGroup::DEFAULT_HAZE_COLOR }; diff --git a/libraries/model/src/model/Stage.cpp b/libraries/model/src/model/Stage.cpp index 75a94f0cea..cd2312122c 100644 --- a/libraries/model/src/model/Stage.cpp +++ b/libraries/model/src/model/Stage.cpp @@ -13,6 +13,7 @@ #include #include #include +#include using namespace model; @@ -256,8 +257,9 @@ void SunSkyStage::setSkybox(const SkyboxPointer& skybox) { invalidate(); } -// Haze -void SunSkyStage::setHazeMode(uint32_t mode) { - _hazeMode = mode; - invalidate(); +void SunSkyStage::setHazeMode(uint32_t hazeMode) { + if (hazeMode < COMPONENT_MODE_ITEM_COUNT) { + _hazeMode = hazeMode; + invalidate(); + } } diff --git a/libraries/networking/src/EntityScriptClient.cpp b/libraries/networking/src/EntityScriptClient.cpp index ef59ec99b8..399cb80bfa 100644 --- a/libraries/networking/src/EntityScriptClient.cpp +++ b/libraries/networking/src/EntityScriptClient.cpp @@ -69,6 +69,30 @@ bool EntityScriptClient::reloadServerScript(QUuid entityID) { return false; } +void EntityScriptClient::callEntityServerMethod(QUuid entityID, const QString& method, const QStringList& params) { + // Send packet to entity script server + auto nodeList = DependencyManager::get(); + SharedNodePointer entityScriptServer = nodeList->soloNodeOfType(NodeType::EntityScriptServer); + + if (entityScriptServer) { + auto packetList = NLPacketList::create(PacketType::EntityScriptCallMethod, QByteArray(), true, true); + + packetList->write(entityID.toRfc4122()); + + packetList->writeString(method); + + quint16 paramCount = params.length(); + packetList->writePrimitive(paramCount); + + foreach(const QString& param, params) { + packetList->writeString(param); + } + + nodeList->sendPacketList(std::move(packetList), *entityScriptServer); + } +} + + MessageID EntityScriptClient::getEntityServerScriptStatus(QUuid entityID, GetScriptStatusCallback callback) { auto nodeList = DependencyManager::get(); SharedNodePointer entityScriptServer = nodeList->soloNodeOfType(NodeType::EntityScriptServer); diff --git a/libraries/networking/src/EntityScriptClient.h b/libraries/networking/src/EntityScriptClient.h index 926521d9b8..6f1a0376ea 100644 --- a/libraries/networking/src/EntityScriptClient.h +++ b/libraries/networking/src/EntityScriptClient.h @@ -58,6 +58,8 @@ public: bool reloadServerScript(QUuid entityID); MessageID getEntityServerScriptStatus(QUuid entityID, GetScriptStatusCallback callback); + void callEntityServerMethod(QUuid id, const QString& method, const QStringList& params); + private slots: void handleNodeKilled(SharedNodePointer node); diff --git a/libraries/networking/src/udt/PacketHeaders.h b/libraries/networking/src/udt/PacketHeaders.h index 3f5ebb8fcd..3e4e1d54f3 100644 --- a/libraries/networking/src/udt/PacketHeaders.h +++ b/libraries/networking/src/udt/PacketHeaders.h @@ -123,6 +123,7 @@ public: ReplicatedBulkAvatarData, OctreeFileReplacementFromUrl, ChallengeOwnership, + EntityScriptCallMethod, NUM_PACKET_TYPE }; diff --git a/libraries/pointers/CMakeLists.txt b/libraries/pointers/CMakeLists.txt new file mode 100644 index 0000000000..504484574c --- /dev/null +++ b/libraries/pointers/CMakeLists.txt @@ -0,0 +1,5 @@ +set(TARGET_NAME pointers) +setup_hifi_library() +GroupSources(src) +link_hifi_libraries(shared) + diff --git a/libraries/pointers/src/pointers/PointerManager.cpp b/libraries/pointers/src/pointers/PointerManager.cpp new file mode 100644 index 0000000000..63bd983420 --- /dev/null +++ b/libraries/pointers/src/pointers/PointerManager.cpp @@ -0,0 +1,6 @@ +#include "PointerManager.h" + +PointerManager::PointerManager() { + +} + diff --git a/libraries/pointers/src/pointers/PointerManager.h b/libraries/pointers/src/pointers/PointerManager.h new file mode 100644 index 0000000000..16f854bff5 --- /dev/null +++ b/libraries/pointers/src/pointers/PointerManager.h @@ -0,0 +1,30 @@ +// +// Created by Bradley Austin Davis on 2017/10/16 +// Copyright 2013-2017 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// +#ifndef hifi_pointers_PointerManager_h +#define hifi_pointers_PointerManager_h + +#include +#include + +class PointerManager : public QObject, public Dependency { + Q_OBJECT + SINGLETON_DEPENDENCY +public: + PointerManager(); + +signals: + void triggerBegin(const QUuid& id, const PointerEvent& pointerEvent); + void triggerContinue(const QUuid& id, const PointerEvent& pointerEvent); + void triggerEnd(const QUuid& id, const PointerEvent& pointerEvent); + + void hoverEnter(const QUuid& id, const PointerEvent& pointerEvent); + void hoverOver(const QUuid& id, const PointerEvent& pointerEvent); + void hoverLeave(const QUuid& id, const PointerEvent& pointerEvent); +}; + +#endif // hifi_pointers_PointerManager_h diff --git a/libraries/pointers/src/pointers/rays/RayPick.cpp b/libraries/pointers/src/pointers/rays/RayPick.cpp new file mode 100644 index 0000000000..bc3a05cd7a --- /dev/null +++ b/libraries/pointers/src/pointers/rays/RayPick.cpp @@ -0,0 +1,81 @@ +// +// Created by Sam Gondelman 7/11/2017 +// Copyright 2017 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// +#include "RayPick.h" + +const RayPickFilter RayPickFilter::NOTHING; + +RayPick::RayPick(const RayPickFilter& filter, const float maxDistance, const bool enabled) : + _filter(filter), + _maxDistance(maxDistance), + _enabled(enabled) +{ +} + +void RayPick::enable(bool enabled) { + withWriteLock([&] { + _enabled = enabled; + }); +} + +RayPickFilter RayPick::getFilter() const { + return resultWithReadLock([&] { + return _filter; + }); +} + +float RayPick::getMaxDistance() const { + return _maxDistance; +} + +bool RayPick::isEnabled() const { + return resultWithReadLock([&] { + return _enabled; + }); +} + +void RayPick::setPrecisionPicking(bool precisionPicking) { + withWriteLock([&]{ + _filter.setFlag(RayPickFilter::PICK_COARSE, !precisionPicking); + }); +} + +void RayPick::setRayPickResult(const RayPickResult& rayPickResult) { + withWriteLock([&] { + _prevResult = rayPickResult; + }); +} + +QVector RayPick::getIgnoreItems() const { + return resultWithReadLock>([&] { + return _ignoreItems; + }); +} + +QVector RayPick::getIncludeItems() const { + return resultWithReadLock>([&] { + return _includeItems; + }); +} + +RayPickResult RayPick::getPrevRayPickResult() const { + return resultWithReadLock([&] { + return _prevResult; + }); +} + +void RayPick::setIgnoreItems(const QVector& ignoreItems) { + withWriteLock([&] { + _ignoreItems = ignoreItems; + }); +} + +void RayPick::setIncludeItems(const QVector& includeItems) { + withWriteLock([&] { + _includeItems = includeItems; + }); +} diff --git a/interface/src/raypick/RayPick.h b/libraries/pointers/src/pointers/rays/RayPick.h similarity index 55% rename from interface/src/raypick/RayPick.h rename to libraries/pointers/src/pointers/rays/RayPick.h index 6dacc084b4..5a53891dc6 100644 --- a/interface/src/raypick/RayPick.h +++ b/libraries/pointers/src/pointers/rays/RayPick.h @@ -1,7 +1,4 @@ // -// RayPick.h -// interface/src/raypick -// // Created by Sam Gondelman 7/11/2017 // Copyright 2017 High Fidelity, Inc. // @@ -12,22 +9,22 @@ #define hifi_RayPick_h #include -#include "RegisteredMetaTypes.h" +#include -#include "EntityItemID.h" -#include "ui/overlays/Overlay.h" -#include +#include + +#include +#include class RayPickFilter { public: enum FlagBit { - PICK_NOTHING = 0, - PICK_ENTITIES, + PICK_ENTITIES = 0, PICK_OVERLAYS, PICK_AVATARS, PICK_HUD, - PICK_COURSE, // if not set, does precise intersection, otherwise, doesn't + PICK_COARSE, // if not set, does precise intersection, otherwise, doesn't PICK_INCLUDE_INVISIBLE, // if not set, will not intersect invisible elements, otherwise, intersects both visible and invisible elements PICK_INCLUDE_NONCOLLIDABLE, // if not set, will not intersect noncollidable elements, otherwise, intersects both collidable and noncollidable elements @@ -42,7 +39,7 @@ public: // The key is the Flags Flags _flags; - RayPickFilter() : _flags(getBitMask(PICK_NOTHING)) {} + RayPickFilter() {} RayPickFilter(const Flags& flags) : _flags(flags) {} bool operator== (const RayPickFilter& rhs) const { return _flags == rhs._flags; } @@ -50,13 +47,13 @@ public: void setFlag(FlagBit flag, bool value) { _flags[flag] = value; } - bool doesPickNothing() const { return _flags[PICK_NOTHING]; } + bool doesPickNothing() const { return _flags == NOTHING._flags; } bool doesPickEntities() const { return _flags[PICK_ENTITIES]; } bool doesPickOverlays() const { return _flags[PICK_OVERLAYS]; } bool doesPickAvatars() const { return _flags[PICK_AVATARS]; } bool doesPickHUD() const { return _flags[PICK_HUD]; } - bool doesPickCourse() const { return _flags[PICK_COURSE]; } + bool doesPickCoarse() const { return _flags[PICK_COARSE]; } bool doesPickInvisible() const { return _flags[PICK_INCLUDE_INVISIBLE]; } bool doesPickNonCollidable() const { return _flags[PICK_INCLUDE_NONCOLLIDABLE]; } @@ -71,8 +68,8 @@ public: if (doesPickNonCollidable()) { toReturn |= getBitMask(PICK_INCLUDE_NONCOLLIDABLE); } - if (doesPickCourse()) { - toReturn |= getBitMask(PICK_COURSE); + if (doesPickCoarse()) { + toReturn |= getBitMask(PICK_COARSE); } return Flags(toReturn); } @@ -84,66 +81,76 @@ public: if (doesPickNonCollidable()) { toReturn |= getBitMask(PICK_INCLUDE_NONCOLLIDABLE); } - if (doesPickCourse()) { - toReturn |= getBitMask(PICK_COURSE); + if (doesPickCoarse()) { + toReturn |= getBitMask(PICK_COARSE); } return Flags(toReturn); } Flags getAvatarFlags() const { return Flags(getBitMask(PICK_AVATARS)); } Flags getHUDFlags() const { return Flags(getBitMask(PICK_HUD)); } - static unsigned int getBitMask(FlagBit bit) { return 1 << bit; } + static constexpr unsigned int getBitMask(FlagBit bit) { return 1 << bit; } + static const RayPickFilter NOTHING; }; -class RayPick { +class RayPick : protected ReadWriteLockable { public: + using Pointer = std::shared_ptr; + RayPick(const RayPickFilter& filter, const float maxDistance, const bool enabled); virtual const PickRay getPickRay(bool& valid) const = 0; - void enable(); - void disable(); + void enable(bool enabled = true); + void disable() { enable(false); } - const RayPickFilter& getFilter() { return _filter; } - float getMaxDistance() { return _maxDistance; } - bool isEnabled() { return _enabled; } - const RayPickResult& getPrevRayPickResult(); + RayPickFilter getFilter() const; + float getMaxDistance() const; + bool isEnabled() const; + RayPickResult getPrevRayPickResult() const; - void setPrecisionPicking(bool precisionPicking) { _filter.setFlag(RayPickFilter::PICK_COURSE, !precisionPicking); } + void setPrecisionPicking(bool precisionPicking); - void setRayPickResult(const RayPickResult& rayPickResult) { _prevResult = rayPickResult; } + void setRayPickResult(const RayPickResult& rayPickResult); - const QVector& getIgnoreEntites() { return _ignoreEntities; } - const QVector& getIncludeEntites() { return _includeEntities; } - const QVector& getIgnoreOverlays() { return _ignoreOverlays; } - const QVector& getIncludeOverlays() { return _includeOverlays; } - const QVector& getIgnoreAvatars() { return _ignoreAvatars; } - const QVector& getIncludeAvatars() { return _includeAvatars; } - void setIgnoreEntities(const QScriptValue& ignoreEntities); - void setIncludeEntities(const QScriptValue& includeEntities); - void setIgnoreOverlays(const QScriptValue& ignoreOverlays); - void setIncludeOverlays(const QScriptValue& includeOverlays); - void setIgnoreAvatars(const QScriptValue& ignoreAvatars); - void setIncludeAvatars(const QScriptValue& includeAvatars); + QVector getIgnoreItems() const; + QVector getIncludeItems() const; - QReadWriteLock* getLock() { return &_lock; } + template + QVector getIgnoreItemsAs() const { + QVector result; + withReadLock([&] { + for (const auto& uid : _ignoreItems) { + result.push_back(uid); + } + }); + return result; + } + + template + QVector getIncludeItemsAs() const { + QVector result; + withReadLock([&] { + for (const auto& uid : _includeItems) { + result.push_back(uid); + } + }); + return result; + } + + void setIgnoreItems(const QVector& items); + void setIncludeItems(const QVector& items); private: RayPickFilter _filter; - float _maxDistance; + const float _maxDistance; bool _enabled; RayPickResult _prevResult; - QVector _ignoreEntities; - QVector _includeEntities; - QVector _ignoreOverlays; - QVector _includeOverlays; - QVector _ignoreAvatars; - QVector _includeAvatars; - - QReadWriteLock _lock; + QVector _ignoreItems; + QVector _includeItems; }; #endif // hifi_RayPick_h diff --git a/interface/src/raypick/StaticRayPick.cpp b/libraries/pointers/src/pointers/rays/StaticRayPick.cpp similarity index 92% rename from interface/src/raypick/StaticRayPick.cpp rename to libraries/pointers/src/pointers/rays/StaticRayPick.cpp index 89bcddb3df..e507341021 100644 --- a/interface/src/raypick/StaticRayPick.cpp +++ b/libraries/pointers/src/pointers/rays/StaticRayPick.cpp @@ -1,7 +1,4 @@ // -// StaticRayPick.cpp -// interface/src/raypick -// // Created by Sam Gondelman 7/11/2017 // Copyright 2017 High Fidelity, Inc. // diff --git a/interface/src/raypick/StaticRayPick.h b/libraries/pointers/src/pointers/rays/StaticRayPick.h similarity index 92% rename from interface/src/raypick/StaticRayPick.h rename to libraries/pointers/src/pointers/rays/StaticRayPick.h index fc09ee6a27..de5ec234a5 100644 --- a/interface/src/raypick/StaticRayPick.h +++ b/libraries/pointers/src/pointers/rays/StaticRayPick.h @@ -1,7 +1,4 @@ // -// StaticRayPick.h -// interface/src/raypick -// // Created by Sam Gondelman 7/11/2017 // Copyright 2017 High Fidelity, Inc. // diff --git a/libraries/render-utils/src/Model.cpp b/libraries/render-utils/src/Model.cpp index 4573b5aa78..964a1961d6 100644 --- a/libraries/render-utils/src/Model.cpp +++ b/libraries/render-utils/src/Model.cpp @@ -121,8 +121,6 @@ bool Model::needsFixupInScene() const { return (_needsFixupInScene || !_addedToScene) && !_needsReload && isLoaded(); } -// TODO?: should we combine translation and rotation into single method to avoid double-work? -// (figure out where we call these) void Model::setTranslation(const glm::vec3& translation) { _translation = translation; updateRenderItems(); @@ -133,6 +131,14 @@ void Model::setRotation(const glm::quat& rotation) { updateRenderItems(); } +// temporary HACK: set transform while avoiding implicit calls to updateRenderItems() +// TODO: make setRotation() and friends set flag to be used later to decide to updateRenderItems() +void Model::setTransformNoUpdateRenderItems(const Transform& transform) { + _translation = transform.getTranslation(); + _rotation = transform.getRotation(); + // DO NOT call updateRenderItems() here! +} + Transform Model::getTransform() const { if (_spatiallyNestableOverride) { bool success; @@ -957,7 +963,7 @@ Blender::Blender(ModelPointer model, int blendNumber, const Geometry::WeakPointe } void Blender::run() { - PROFILE_RANGE_EX(simulation_animation, __FUNCTION__, 0xFFFF0000, 0, { { "url", _model->getURL().toString() } }); + DETAILED_PROFILE_RANGE_EX(simulation_animation, __FUNCTION__, 0xFFFF0000, 0, { { "url", _model->getURL().toString() } }); QVector vertices, normals; if (_model) { int offset = 0; @@ -1078,8 +1084,7 @@ void Model::snapToRegistrationPoint() { } void Model::simulate(float deltaTime, bool fullUpdate) { - PROFILE_RANGE(simulation_detail, __FUNCTION__); - PerformanceTimer perfTimer("Model::simulate"); + DETAILED_PROFILE_RANGE(simulation_detail, __FUNCTION__); fullUpdate = updateGeometry() || fullUpdate || (_scaleToFit && !_scaledToFit) || (_snapModelToRegistrationPoint && !_snappedToRegistrationPoint); @@ -1117,7 +1122,7 @@ void Model::computeMeshPartLocalBounds() { // virtual void Model::updateClusterMatrices() { - PerformanceTimer perfTimer("Model::updateClusterMatrices"); + DETAILED_PERFORMANCE_TIMER("Model::updateClusterMatrices"); if (!_needsUpdateClusterMatrices || !isLoaded()) { return; diff --git a/libraries/render-utils/src/Model.h b/libraries/render-utils/src/Model.h index 0207a4871a..8bce976b4e 100644 --- a/libraries/render-utils/src/Model.h +++ b/libraries/render-utils/src/Model.h @@ -206,6 +206,7 @@ public: void setTranslation(const glm::vec3& translation); void setRotation(const glm::quat& rotation); + void setTransformNoUpdateRenderItems(const Transform& transform); // temporary HACK const glm::vec3& getTranslation() const { return _translation; } const glm::quat& getRotation() const { return _rotation; } diff --git a/libraries/script-engine/src/ScriptEngine.cpp b/libraries/script-engine/src/ScriptEngine.cpp index 348a687ae2..98846c5213 100644 --- a/libraries/script-engine/src/ScriptEngine.cpp +++ b/libraries/script-engine/src/ScriptEngine.cpp @@ -2476,7 +2476,7 @@ void ScriptEngine::callWithEnvironment(const EntityItemID& entityID, const QUrl& doWithEnvironment(entityID, sandboxURL, operation); } -void ScriptEngine::callEntityScriptMethod(const EntityItemID& entityID, const QString& methodName, const QStringList& params) { +void ScriptEngine::callEntityScriptMethod(const EntityItemID& entityID, const QString& methodName, const QStringList& params, const QUuid& remoteCallerID) { if (QThread::currentThread() != thread()) { #ifdef THREAD_DEBUGGING qCDebug(scriptengine) << "*** WARNING *** ScriptEngine::callEntityScriptMethod() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] " @@ -2486,7 +2486,8 @@ void ScriptEngine::callEntityScriptMethod(const EntityItemID& entityID, const QS QMetaObject::invokeMethod(this, "callEntityScriptMethod", Q_ARG(const EntityItemID&, entityID), Q_ARG(const QString&, methodName), - Q_ARG(const QStringList&, params)); + Q_ARG(const QStringList&, params), + Q_ARG(const QUuid&, remoteCallerID)); return; } #ifdef THREAD_DEBUGGING @@ -2500,13 +2501,41 @@ void ScriptEngine::callEntityScriptMethod(const EntityItemID& entityID, const QS if (isEntityScriptRunning(entityID)) { EntityScriptDetails details = _entityScripts[entityID]; QScriptValue entityScript = details.scriptObject; // previously loaded - if (entityScript.property(methodName).isFunction()) { + + // If this is a remote call, we need to check to see if the function is remotely callable + // we do this by checking for the existance of the 'remotelyCallable' property on the + // entityScript. And we confirm that the method name is included. If this fails, the + // function will not be called. + bool callAllowed = false; + if (remoteCallerID == QUuid()) { + callAllowed = true; + } else { + if (entityScript.property("remotelyCallable").isArray()) { + auto callables = entityScript.property("remotelyCallable"); + auto callableCount = callables.property("length").toInteger(); + for (int i = 0; i < callableCount; i++) { + auto callable = callables.property(i).toString(); + if (callable == methodName) { + callAllowed = true; + break; + } + } + } + if (!callAllowed) { + qDebug() << "Method [" << methodName << "] not remotely callable."; + } + } + + if (callAllowed && entityScript.property(methodName).isFunction()) { QScriptValueList args; args << entityID.toScriptValue(this); args << qScriptValueFromSequence(this, params); - callWithEnvironment(entityID, details.definingSandboxURL, entityScript.property(methodName), entityScript, args); - } + QScriptValue oldData = this->globalObject().property("Script").property("remoteCallerID"); + this->globalObject().property("Script").setProperty("remoteCallerID", remoteCallerID.toString()); // Make the remoteCallerID available to javascript as a global. + callWithEnvironment(entityID, details.definingSandboxURL, entityScript.property(methodName), entityScript, args); + this->globalObject().property("Script").setProperty("remoteCallerID", oldData); + } } } diff --git a/libraries/script-engine/src/ScriptEngine.h b/libraries/script-engine/src/ScriptEngine.h index 7109e0f582..db159e7265 100644 --- a/libraries/script-engine/src/ScriptEngine.h +++ b/libraries/script-engine/src/ScriptEngine.h @@ -198,7 +198,8 @@ public: Q_INVOKABLE void unloadEntityScript(const EntityItemID& entityID, bool shouldRemoveFromMap = false); // will call unload method Q_INVOKABLE void unloadAllEntityScripts(); Q_INVOKABLE void callEntityScriptMethod(const EntityItemID& entityID, const QString& methodName, - const QStringList& params = QStringList()) override; + const QStringList& params = QStringList(), + const QUuid& remoteCallerID = QUuid()) override; Q_INVOKABLE void callEntityScriptMethod(const EntityItemID& entityID, const QString& methodName, const PointerEvent& event); Q_INVOKABLE void callEntityScriptMethod(const EntityItemID& entityID, const QString& methodName, const EntityItemID& otherID, const Collision& collision); diff --git a/libraries/shared/src/PerfStat.h b/libraries/shared/src/PerfStat.h index 785920779e..b09cb38808 100644 --- a/libraries/shared/src/PerfStat.h +++ b/libraries/shared/src/PerfStat.h @@ -97,5 +97,12 @@ private: static QMap _records; }; +// uncomment WANT_DETAILED_PERFORMANCE_TIMERS definition to enable performance timers in high-frequency contexts +//#define WANT_DETAILED_PERFORMANCE_TIMERS +#ifdef WANT_DETAILED_PERFORMANCE_TIMERS + #define DETAILED_PERFORMANCE_TIMER(name) PerformanceTimer detailedPerformanceTimer(name); +#else // WANT_DETAILED_PERFORMANCE_TIMERS + #define DETAILED_PERFORMANCE_TIMER(name) ; // no-op +#endif // WANT_DETAILED_PERFORMANCE_TIMERS #endif // hifi_PerfStat_h diff --git a/libraries/shared/src/Profile.h b/libraries/shared/src/Profile.h index 5de4e8f41a..fc6a2a52cb 100644 --- a/libraries/shared/src/Profile.h +++ b/libraries/shared/src/Profile.h @@ -108,4 +108,14 @@ inline void metadata(const QString& metadataType, const QVariantMap& args) { #define SAMPLE_PROFILE_COUNTER(chance, category, name, ...) if (randFloat() <= chance) { PROFILE_COUNTER(category, name, ##__VA_ARGS__); } #define SAMPLE_PROFILE_INSTANT(chance, category, name, ...) if (randFloat() <= chance) { PROFILE_INSTANT(category, name, ##__VA_ARGS__); } +// uncomment WANT_DETAILED_PROFILING definition to enable profiling in high-frequency contexts +//#define WANT_DETAILED_PROFILING +#ifdef WANT_DETAILED_PROFILING +#define DETAILED_PROFILE_RANGE(category, name) Duration profileRangeThis(trace_##category(), name); +#define DETAILED_PROFILE_RANGE_EX(category, name, argbColor, payload, ...) Duration profileRangeThis(trace_##category(), name, argbColor, (uint64_t)payload, ##__VA_ARGS__); +#else // WANT_DETAILED_PROFILING +#define DETAILED_PROFILE_RANGE(category, name) ; // no-op +#define DETAILED_PROFILE_RANGE_EX(category, name, argbColor, payload, ...) ; // no-op +#endif // WANT_DETAILED_PROFILING + #endif diff --git a/libraries/ui/src/ui/TabletScriptingInterface.cpp b/libraries/ui/src/ui/TabletScriptingInterface.cpp index 4e625c2494..b9da230715 100644 --- a/libraries/ui/src/ui/TabletScriptingInterface.cpp +++ b/libraries/ui/src/ui/TabletScriptingInterface.cpp @@ -23,16 +23,28 @@ #include "ToolbarScriptingInterface.h" #include "Logging.h" +#include + +#include "SettingHandle.h" + // FIXME move to global app properties const QString SYSTEM_TOOLBAR = "com.highfidelity.interface.toolbar.system"; const QString SYSTEM_TABLET = "com.highfidelity.interface.tablet.system"; const QString TabletScriptingInterface::QML = "hifi/tablet/TabletRoot.qml"; +static Setting::Handle tabletSoundsButtonClick("TabletSounds", QStringList { "/sounds/Button06.wav", + "/sounds/Button04.wav", + "/sounds/Button07.wav", + "/sounds/Tab01.wav", + "/sounds/Tab02.wav" }); + TabletScriptingInterface::TabletScriptingInterface() { + qmlRegisterType("TabletScriptingInterface", 1, 0, "TabletEnums"); } TabletScriptingInterface::~TabletScriptingInterface() { + tabletSoundsButtonClick.set(tabletSoundsButtonClick.get()); } ToolbarProxy* TabletScriptingInterface::getSystemToolbarProxy() { @@ -63,6 +75,29 @@ TabletProxy* TabletScriptingInterface::getTablet(const QString& tabletId) { return tabletProxy; } +void TabletScriptingInterface::preloadSounds() { + //preload audio events + const QStringList &audioSettings = tabletSoundsButtonClick.get(); + for (int i = 0; i < TabletAudioEvents::Last; i++) { + QFileInfo inf = QFileInfo(PathUtils::resourcesPath() + audioSettings.at(i)); + SharedSoundPointer sound = DependencyManager::get()-> + getSound(QUrl::fromLocalFile(inf.absoluteFilePath())); + _audioEvents.insert(static_cast(i), sound); + } +} + +void TabletScriptingInterface::playSound(TabletAudioEvents aEvent) { + SharedSoundPointer sound = _audioEvents[aEvent]; + if (sound) { + AudioInjectorOptions options; + options.stereo = sound->isStereo(); + options.ambisonic = sound->isAmbisonic(); + options.localOnly = true; + + AudioInjectorPointer injector = AudioInjector::playSoundAndDelete(sound->getByteArray(), options); + } +} + void TabletScriptingInterface::setToolbarMode(bool toolbarMode) { Q_ASSERT(QThread::currentThread() == qApp->thread()); _toolbarMode = toolbarMode; @@ -323,9 +358,12 @@ void TabletProxy::emitWebEvent(const QVariant& msg) { } void TabletProxy::onTabletShown() { - if (_tabletShown && _showRunningScripts) { - _showRunningScripts = false; - pushOntoStack("../../hifi/dialogs/TabletRunningScripts.qml"); + if (_tabletShown) { + static_cast(parent())->playSound(TabletScriptingInterface::TabletOpen); + if (_showRunningScripts) { + _showRunningScripts = false; + pushOntoStack("../../hifi/dialogs/TabletRunningScripts.qml"); + } } } diff --git a/libraries/ui/src/ui/TabletScriptingInterface.h b/libraries/ui/src/ui/TabletScriptingInterface.h index 386bce45a8..bd195fdd20 100644 --- a/libraries/ui/src/ui/TabletScriptingInterface.h +++ b/libraries/ui/src/ui/TabletScriptingInterface.h @@ -23,7 +23,7 @@ #include #include #include - +#include "SoundCache.h" #include class ToolbarProxy; @@ -40,8 +40,11 @@ class OffscreenQmlSurface; class TabletScriptingInterface : public QObject, public Dependency { Q_OBJECT public: + enum TabletAudioEvents { ButtonClick, ButtonHover, TabletOpen, TabletHandsIn, TabletHandsOut, Last}; + Q_ENUM(TabletAudioEvents) + TabletScriptingInterface(); - ~TabletScriptingInterface(); + virtual ~TabletScriptingInterface(); static const QString QML; void setToolbarScriptingInterface(ToolbarScriptingInterface* toolbarScriptingInterface) { _toolbarScriptingInterface = toolbarScriptingInterface; } @@ -54,6 +57,9 @@ public: */ Q_INVOKABLE TabletProxy* getTablet(const QString& tabletId); + void preloadSounds(); + Q_INVOKABLE void playSound(TabletAudioEvents aEvent); + void setToolbarMode(bool toolbarMode); void setQmlTabletRoot(QString tabletId, OffscreenQmlSurface* offscreenQmlSurface); @@ -77,6 +83,7 @@ private: void processTabletEvents(QObject* object, const QKeyEvent* event); ToolbarProxy* getSystemToolbarProxy(); + QMap _audioEvents; protected: std::map _tabletProxies; ToolbarScriptingInterface* _toolbarScriptingInterface { nullptr }; diff --git a/scripts/system/controllers/controllerDispatcher.js b/scripts/system/controllers/controllerDispatcher.js index 62792c0749..37cd173cfa 100644 --- a/scripts/system/controllers/controllerDispatcher.js +++ b/scripts/system/controllers/controllerDispatcher.js @@ -141,8 +141,11 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js"); }; this.setIgnoreTablet = function() { - RayPick.setIgnoreOverlays(_this.leftControllerRayPick, [HMD.tabletID]); - RayPick.setIgnoreOverlays(_this.rightControllerRayPick, [HMD.tabletID]); + if (HMD.tabletID !== this.tabletID) { + this.tabletID = HMD.tabletID; + RayPick.setIgnoreItems(_this.leftControllerRayPick, _this.blacklist.concat([HMD.tabletID])); + RayPick.setIgnoreItems(_this.rightControllerRayPick, _this.blacklist.concat([HMD.tabletID])); + } }; this.update = function () { @@ -367,9 +370,8 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js"); }; this.setBlacklist = function() { - RayPick.setIgnoreEntities(_this.leftControllerRayPick, this.blacklist); - RayPick.setIgnoreEntities(_this.rightControllerRayPick, this.blacklist); - + RayPick.setIgnoreItems(_this.leftControllerRayPick, this.blacklist.concat(HMD.tabletID)); + RayPick.setIgnoreItems(_this.rightControllerRayPick, this.blacklist.concat(HMD.tabletID)); }; var MAPPING_NAME = "com.highfidelity.controllerDispatcher"; diff --git a/scripts/system/controllers/controllerModules/inEditMode.js b/scripts/system/controllers/controllerModules/inEditMode.js index f68389080e..f9ec38d22a 100644 --- a/scripts/system/controllers/controllerModules/inEditMode.js +++ b/scripts/system/controllers/controllerModules/inEditMode.js @@ -127,6 +127,13 @@ Script.include("/~/system/libraries/utils.js"); this.updateLaserPointer = function(controllerData) { LaserPointers.enableLaserPointer(this.laserPointer); LaserPointers.setRenderState(this.laserPointer, this.mode); + + if (HMD.tabletID !== this.tabletID || HMD.tabletButtonID !== this.tabletButtonID || HMD.tabletScreenID !== this.tabletScreenID) { + this.tabletID = HMD.tabletID; + this.tabletButtonID = HMD.tabletButtonID; + this.tabletScreenID = HMD.tabletScreenID; + LaserPointers.setIgnoreItems(this.laserPointer, [HMD.tabletID, HMD.tabletButtonID, HMD.tabletScreenID]); + } }; this.pointingAtTablet = function(objectID) { @@ -233,7 +240,7 @@ Script.include("/~/system/libraries/utils.js"); defaultRenderStates: defaultRenderStates }); - LaserPointers.setIgnoreOverlays(this.laserPointer, [HMD.tabletID, HMD.tabletButtonID, HMD.tabletScreenID]); + LaserPointers.setIgnoreItems(this.laserPointer, [HMD.tabletID, HMD.tabletButtonID, HMD.tabletScreenID]); } var leftHandInEditMode = new InEditMode(LEFT_HAND); diff --git a/scripts/system/controllers/controllerModules/overlayLaserInput.js b/scripts/system/controllers/controllerModules/overlayLaserInput.js index 9cd355f060..1c83f38d9b 100644 --- a/scripts/system/controllers/controllerModules/overlayLaserInput.js +++ b/scripts/system/controllers/controllerModules/overlayLaserInput.js @@ -177,6 +177,11 @@ Script.include("/~/system/libraries/controllers.js"); this.updateLaserPointer = function(controllerData) { LaserPointers.enableLaserPointer(this.laserPointer); LaserPointers.setRenderState(this.laserPointer, this.mode); + + if (HMD.tabletID !== this.tabletID) { + this.tabletID = HMD.tabletID; + LaserPointers.setIgnoreItems(this.laserPointer, [HMD.tabletID]); + } }; this.processControllerTriggers = function(controllerData) { @@ -369,7 +374,7 @@ Script.include("/~/system/libraries/controllers.js"); defaultRenderStates: defaultRenderStates }); - LaserPointers.setIgnoreOverlays(this.laserPointer, [HMD.tabletID]); + LaserPointers.setIgnoreItems(this.laserPointer, [HMD.tabletID]); } var leftOverlayLaserInput = new OverlayLaserInput(LEFT_HAND); diff --git a/scripts/system/controllers/controllerModules/teleport.js b/scripts/system/controllers/controllerModules/teleport.js index ce6480f989..0364e4f9b4 100644 --- a/scripts/system/controllers/controllerModules/teleport.js +++ b/scripts/system/controllers/controllerModules/teleport.js @@ -349,10 +349,10 @@ Script.include("/~/system/libraries/controllers.js"); }; this.setIgnoreEntities = function(entitiesToIgnore) { - LaserPointers.setIgnoreEntities(this.teleportRayHandVisible, entitiesToIgnore); - LaserPointers.setIgnoreEntities(this.teleportRayHandInvisible, entitiesToIgnore); - LaserPointers.setIgnoreEntities(this.teleportRayHeadVisible, entitiesToIgnore); - LaserPointers.setIgnoreEntities(this.teleportRayHeadInvisible, entitiesToIgnore); + LaserPointers.setIgnoreItems(this.teleportRayHandVisible, entitiesToIgnore); + LaserPointers.setIgnoreItems(this.teleportRayHandInvisible, entitiesToIgnore); + LaserPointers.setIgnoreItems(this.teleportRayHeadVisible, entitiesToIgnore); + LaserPointers.setIgnoreItems(this.teleportRayHeadInvisible, entitiesToIgnore); }; } diff --git a/scripts/system/controllers/grab.js b/scripts/system/controllers/grab.js index 2f046cbce3..a1846e7ad7 100644 --- a/scripts/system/controllers/grab.js +++ b/scripts/system/controllers/grab.js @@ -263,7 +263,7 @@ function Grabber() { filter: RayPick.PICK_OVERLAYS, enabled: true }); - RayPick.setIncludeOverlays(this.mouseRayOverlays, [HMD.tabletID, HMD.tabletScreenID, HMD.homeButtonID]); + RayPick.setIncludeItems(this.mouseRayOverlays, [HMD.tabletID, HMD.tabletScreenID, HMD.homeButtonID]); var renderStates = [{name: "grabbed", end: beacon}]; this.mouseRayEntities = LaserPointers.createLaserPointer({ joint: "Mouse", diff --git a/scripts/system/dialTone.js b/scripts/system/dialTone.js index 7b693aa2de..7c0a5b250d 100644 --- a/scripts/system/dialTone.js +++ b/scripts/system/dialTone.js @@ -33,10 +33,4 @@ Audio.disconnected.connect(function(){ Audio.playSound(disconnectSound, soundOptions); }); -Audio.mutedChanged.connect(function () { - if (Audio.muted) { - Audio.playSound(micMutedSound, soundOptions); - } -}); - }()); // END LOCAL_SCOPE