From 7298cd69404e04d2c46abb45954b16ff3d68eba4 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Fri, 23 Jun 2017 10:54:31 -0700 Subject: [PATCH 01/24] Add support for vs2015 and vs2017 FBX libs --- cmake/modules/FindFBX.cmake | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cmake/modules/FindFBX.cmake b/cmake/modules/FindFBX.cmake index 2e84d1ea19..b362d93cd3 100644 --- a/cmake/modules/FindFBX.cmake +++ b/cmake/modules/FindFBX.cmake @@ -56,6 +56,14 @@ elseif (${CMAKE_CXX_COMPILER_ID} MATCHES "GNU") endif() function(_fbx_find_library _name _lib _suffix) + if (MSVC15) + set(VS_PREFIX vs2017) + endif() + + if (MSVC14) + set(VS_PREFIX vs2015) + endif() + if (MSVC12) set(VS_PREFIX vs2013) endif() From b12018ccf3f7cb2dd5e76cbf05ccb7a1e6d91fbc Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Fri, 23 Jun 2017 10:54:48 -0700 Subject: [PATCH 02/24] Fix Oven not properly handling native separators --- tools/oven/src/Oven.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/oven/src/Oven.cpp b/tools/oven/src/Oven.cpp index dc763cc82d..d0b8c3cd65 100644 --- a/tools/oven/src/Oven.cpp +++ b/tools/oven/src/Oven.cpp @@ -61,7 +61,9 @@ Oven::Oven(int argc, char* argv[]) : if (parser.isSet(CLI_INPUT_PARAMETER) || parser.isSet(CLI_OUTPUT_PARAMETER)) { if (parser.isSet(CLI_INPUT_PARAMETER) && parser.isSet(CLI_OUTPUT_PARAMETER)) { BakerCLI* cli = new BakerCLI(this); - cli->bakeFile(parser.value(CLI_INPUT_PARAMETER), parser.value(CLI_OUTPUT_PARAMETER)); + QUrl inputUrl(QDir::fromNativeSeparators(parser.value(CLI_INPUT_PARAMETER))); + QUrl outputUrl(QDir::fromNativeSeparators(parser.value(CLI_OUTPUT_PARAMETER))); + cli->bakeFile(inputUrl, outputUrl.toString()); } else { parser.showHelp(); QApplication::quit(); From 5f92c1adc09abb7c332a300c40fc1b352c1c6257 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Mon, 26 Jun 2017 09:40:07 -0700 Subject: [PATCH 03/24] Update FindFBX to use newer MSVC_VERSION --- cmake/modules/FindFBX.cmake | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/cmake/modules/FindFBX.cmake b/cmake/modules/FindFBX.cmake index b362d93cd3..9a1d08a010 100644 --- a/cmake/modules/FindFBX.cmake +++ b/cmake/modules/FindFBX.cmake @@ -56,27 +56,17 @@ elseif (${CMAKE_CXX_COMPILER_ID} MATCHES "GNU") endif() function(_fbx_find_library _name _lib _suffix) - if (MSVC15) + if (MSVC_VERSION EQUAL 1910) set(VS_PREFIX vs2017) - endif() - - if (MSVC14) + elseif (MSVC_VERSION EQUAL 1900) set(VS_PREFIX vs2015) - endif() - - if (MSVC12) + elseif (MSVC_VERSION EQUAL 1800) set(VS_PREFIX vs2013) - endif() - - if (MSVC11) + elseif (MSVC_VERSION EQUAL 1700) set(VS_PREFIX vs2012) - endif() - - if (MSVC10) + elseif (MSVC_VERSION EQUAL 1600) set(VS_PREFIX vs2010) - endif() - - if (MSVC90) + elseif (MSVC_VERSION EQUAL 1500) set(VS_PREFIX vs2008) endif() From a2df2f84720ae626cbd76911c6bd9f45094b8920 Mon Sep 17 00:00:00 2001 From: Dante Ruiz Date: Wed, 28 Jun 2017 19:52:19 +0100 Subject: [PATCH 04/24] added user activity status --- .../qml/hifi/tablet/CalibratingScreen.qml | 14 ++++++- .../qml/hifi/tablet/OpenVrConfiguration.qml | 39 +++++++++++++++++-- plugins/openvr/src/ViveControllerManager.cpp | 28 +++++++++++++ plugins/openvr/src/ViveControllerManager.h | 1 + 4 files changed, 77 insertions(+), 5 deletions(-) diff --git a/interface/resources/qml/hifi/tablet/CalibratingScreen.qml b/interface/resources/qml/hifi/tablet/CalibratingScreen.qml index 338a76989f..8053673e9c 100644 --- a/interface/resources/qml/hifi/tablet/CalibratingScreen.qml +++ b/interface/resources/qml/hifi/tablet/CalibratingScreen.qml @@ -25,11 +25,12 @@ Rectangle { signal canceled() signal restart() - property int count: 3 + property int count: 5 property string calibratingText: "CALIBRATING..." property string calibratingCountText: "CALIBRATION STARTING IN" property string calibrationSuccess: "CALIBRATION COMPLETED" property string calibrationFailed: "CALIBRATION FAILED" + property string instructionText: "Please stand in a T-Pose during calibration" HifiConstants { id: hifi } visible: true @@ -158,6 +159,15 @@ Rectangle { onClicked: { restart(); + statusText.color = hifi.colors.blueHighlight; + statusText.text = info.calibratingCountText; + directions.text = instructionText; + countDown.visible = true; + busyIndicator.running = true; + busyRotation.from = 0 + busyRotation.to = 360 + busyIndicator.source = blueIndicator; + closeWindow.stop(); numberAnimation.stop(); info.count = (timer.interval / 1000); numberAnimation.start(); @@ -178,6 +188,7 @@ Rectangle { } } + function start(interval, countNumber) { countDown.visible = true; statusText.color = hifi.colors.blueHighlight; @@ -201,6 +212,7 @@ Rectangle { busyIndicator.running = false; statusText.text = info.calibrationSuccess statusText.color = hifi.colors.greenHighlight + directions.text = "SUCCESS" closeWindow.start(); } diff --git a/interface/resources/qml/hifi/tablet/OpenVrConfiguration.qml b/interface/resources/qml/hifi/tablet/OpenVrConfiguration.qml index 52a935ab19..3b3f23b1d8 100644 --- a/interface/resources/qml/hifi/tablet/OpenVrConfiguration.qml +++ b/interface/resources/qml/hifi/tablet/OpenVrConfiguration.qml @@ -458,7 +458,7 @@ Rectangle { width: glyphButton.width + calibrationText.width + padding height: hifi.dimensions.controlLineHeight anchors.top: bottomSeperator.bottom - anchors.topMargin: 10 + anchors.topMargin: 15 anchors.left: parent.left anchors.leftMargin: leftMargin @@ -590,16 +590,24 @@ Rectangle { lastConfiguration = composeConfigurationSettings(); } + Component.onDestruction: { + var settings = InputConfiguration.configurationSettings(pluginName); + var data = { + "num_pucks": settings["puckCount"] + } + UserActivityLogger.logAction("mocap_ui_close_dialog", data); + } + HifiControls.SpinBox { id: timeToCalibrate width: 70 anchors.top: calibrationButton.bottom - anchors.topMargin: 40 + anchors.topMargin: 20 anchors.left: parent.left anchors.leftMargin: leftMargin - minimumValue: 3 - value: 3 + minimumValue: 5 + value: 5 colorScheme: hifi.colorSchemes.dark onEditingFinished: { @@ -645,10 +653,27 @@ Rectangle { var calibrationScreen = stack.currentItem; if (status["calibrated"]) { calibrationScreen.success(); + var data = { + "num_pucks": status["puckCount"], + "puck_configuration": status["configuration"], + "head_puck": status["head_puck"], + "hand_puck": status["hand_puck"] + } + + UserActivityLogger.logAction("mocap_ui_success", data); } else if (!status["calibrated"]) { var uncalibrated = status["success"]; if (!uncalibrated) { calibrationScreen.failure(); + + var data = { + "num_pucks": status["puckCount"], + "puck_configuration": status["configuration"], + "head_puck": status["head_puck"], + "hand_puck": status["hand_puck"] + } + + UserActivityLogger.logAction("mocap_ui_fail", data); } } @@ -717,6 +742,12 @@ Rectangle { initializeButtonState(); updateCalibrationText(); + + var data = { + "num_pucks": settings["puckCount"] + }; + + UserActivityLogger.logAction("mocap_ui_open_dialog", data); } function displayTrackerConfiguration(type) { diff --git a/plugins/openvr/src/ViveControllerManager.cpp b/plugins/openvr/src/ViveControllerManager.cpp index 648373ccc2..ba5fc7e288 100644 --- a/plugins/openvr/src/ViveControllerManager.cpp +++ b/plugins/openvr/src/ViveControllerManager.cpp @@ -374,6 +374,7 @@ QJsonObject ViveControllerManager::InputDevice::configurationSettings() { configurationSettings["trackerConfiguration"] = configToString(_preferedConfig); configurationSettings["HMDHead"] = (_headConfig == HeadConfig::HMD) ? true : false; configurationSettings["handController"] = (_handConfig == HandConfig::HandController) ? true : false; + configurationSettings["puckCount"] = (int)_validTrackedObjects.size(); return configurationSettings; } @@ -384,14 +385,22 @@ void ViveControllerManager::InputDevice::emitCalibrationStatus(const bool succes if (_calibrated && success) { status["calibrated"] = _calibrated; status["configuration"] = configToString(_preferedConfig); + status["head_puck"] = (_headConfig == HeadConfig::Puck) ? true : false; + status["hand_pucks"] = (_handConfig == HandConfig::Pucks) ? true : false; + status["puckCount"] = (int)_validTrackedObjects.size(); } else if (!_calibrated && !success) { status["calibrated"] = _calibrated; status["success"] = success; + status["success"] = (int)_validTrackedObjects.size(); + status["head_puck"] = (_headConfig == HeadConfig::Puck) ? true : false; + status["hand_pucks"] = (_handConfig == HandConfig::Pucks) ? true : false; } else if (!_calibrated && success) { status["calibrated"] = _calibrated; status["success"] = success; status["configuration"] = configToString(_preferedConfig); status["puckCount"] = (int)_validTrackedObjects.size(); + status["head_puck"] = (_headConfig == HeadConfig::Puck) ? true : false; + status["hand_pucks"] = (_handConfig == HandConfig::Pucks) ? true : false; } emit inputConfiguration->calibrationStatus(status); //inputConfiguration->calibrated(status); @@ -437,12 +446,31 @@ void ViveControllerManager::InputDevice::handleTrackedObject(uint32_t deviceInde } } +void ViveControllerManager::InputDevice::sendUserActivityData(QString activity) { + QJsonObject jsonData = { + {"num_pucks", (int)_validTrackedObjects.size()}, + {"configuration", configToString(_preferedConfig)}, + {"head_puck", (_headConfig == HeadConfig::Puck) ? true : false}, + {"hand_pucks", (_handConfig == HandConfig::Pucks) ? true : false} + }; + + UserActivityLogger::getInstance().logAction(activity, jsonData); +} + void ViveControllerManager::InputDevice::calibrateOrUncalibrate(const controller::InputCalibrationData& inputCalibration) { if (!_calibrated) { calibrate(inputCalibration); + + if (_calibrated) { + sendUserActivityData("mocap_button_success"); + } else { + sendUserActivityData("mocap_button_fail"); + } + } else { uncalibrate(); emitCalibrationStatus(true); + sendUserActivityData("mocap_button_uncalibrate"); } } diff --git a/plugins/openvr/src/ViveControllerManager.h b/plugins/openvr/src/ViveControllerManager.h index 0b0406bb60..19b485ad55 100644 --- a/plugins/openvr/src/ViveControllerManager.h +++ b/plugins/openvr/src/ViveControllerManager.h @@ -73,6 +73,7 @@ private: void calibrateOrUncalibrate(const controller::InputCalibrationData& inputCalibration); void calibrate(const controller::InputCalibrationData& inputCalibration); void uncalibrate(); + void sendUserActivityData(QString activity); void configureCalibrationSettings(const QJsonObject configurationSettings); QJsonObject configurationSettings(); controller::Pose addOffsetToPuckPose(int joint) const; From a7e4dc1473b7ef7efba024de1f1911611158ad56 Mon Sep 17 00:00:00 2001 From: Dante Ruiz Date: Wed, 28 Jun 2017 23:51:00 +0100 Subject: [PATCH 05/24] clean up code --- .../qml/hifi/tablet/OpenVrConfiguration.qml | 41 ++++++++++-------- plugins/openvr/src/ViveControllerManager.cpp | 42 +++++-------------- plugins/openvr/src/ViveControllerManager.h | 4 +- 3 files changed, 36 insertions(+), 51 deletions(-) diff --git a/interface/resources/qml/hifi/tablet/OpenVrConfiguration.qml b/interface/resources/qml/hifi/tablet/OpenVrConfiguration.qml index 3b3f23b1d8..96413534c3 100644 --- a/interface/resources/qml/hifi/tablet/OpenVrConfiguration.qml +++ b/interface/resources/qml/hifi/tablet/OpenVrConfiguration.qml @@ -649,34 +649,39 @@ Rectangle { to: 0 } + function logAction(action, status) { + console.log("calibrated from ui"); + var data = { + "num_pucks": status["puckCount"], + "puck_configuration": status["configuration"], + "head_puck": status["head_puck"], + "hand_puck": status["hand_pucks"] + } + UserActivityLogger.logAction(action, data); + } + function calibrationStatusInfo(status) { var calibrationScreen = stack.currentItem; + + if (!status["UI"]) { + calibratingScreen = screen.createObject(); + stack.push(calibratingScreen); + } + if (status["calibrated"]) { calibrationScreen.success(); - var data = { - "num_pucks": status["puckCount"], - "puck_configuration": status["configuration"], - "head_puck": status["head_puck"], - "hand_puck": status["hand_puck"] + + if (status["UI"]) { + logAction("mocap_ui_success", status); } - UserActivityLogger.logAction("mocap_ui_success", data); } else if (!status["calibrated"]) { - var uncalibrated = status["success"]; - if (!uncalibrated) { - calibrationScreen.failure(); - - var data = { - "num_pucks": status["puckCount"], - "puck_configuration": status["configuration"], - "head_puck": status["head_puck"], - "hand_puck": status["hand_puck"] - } + calibrationScreen.failure(); - UserActivityLogger.logAction("mocap_ui_fail", data); + if (status["UI"]) { + logAction("mocap_ui_failed", status); } } - updateCalibrationButton(); } diff --git a/plugins/openvr/src/ViveControllerManager.cpp b/plugins/openvr/src/ViveControllerManager.cpp index ba5fc7e288..ca211a9cfe 100644 --- a/plugins/openvr/src/ViveControllerManager.cpp +++ b/plugins/openvr/src/ViveControllerManager.cpp @@ -249,6 +249,7 @@ ViveControllerManager::InputDevice::InputDevice(vr::IVRSystem*& system) : contro _configStringMap[Config::FeetAndHips] = QString("FeetAndHips"); _configStringMap[Config::FeetHipsAndChest] = QString("FeetHipsAndChest"); _configStringMap[Config::FeetHipsAndShoulders] = QString("FeetHipsAndShoulders"); + _configStringMap[Config::FeetHipsChestAndShoulders] = QString("FeetHipsChestAndShoulders"); } void ViveControllerManager::InputDevice::update(float deltaTime, const controller::InputCalibrationData& inputCalibrationData) { @@ -325,6 +326,7 @@ void ViveControllerManager::InputDevice::calibrateFromUI(const controller::Input if (_calibrate) { uncalibrate(); calibrate(inputCalibrationData); + emitCalibrationStatus(); _calibrate = false; } } @@ -378,32 +380,17 @@ QJsonObject ViveControllerManager::InputDevice::configurationSettings() { return configurationSettings; } -void ViveControllerManager::InputDevice::emitCalibrationStatus(const bool success) { +void ViveControllerManager::InputDevice::emitCalibrationStatus() { auto inputConfiguration = DependencyManager::get(); QJsonObject status = QJsonObject(); - - if (_calibrated && success) { - status["calibrated"] = _calibrated; - status["configuration"] = configToString(_preferedConfig); - status["head_puck"] = (_headConfig == HeadConfig::Puck) ? true : false; - status["hand_pucks"] = (_handConfig == HandConfig::Pucks) ? true : false; - status["puckCount"] = (int)_validTrackedObjects.size(); - } else if (!_calibrated && !success) { - status["calibrated"] = _calibrated; - status["success"] = success; - status["success"] = (int)_validTrackedObjects.size(); - status["head_puck"] = (_headConfig == HeadConfig::Puck) ? true : false; - status["hand_pucks"] = (_handConfig == HandConfig::Pucks) ? true : false; - } else if (!_calibrated && success) { - status["calibrated"] = _calibrated; - status["success"] = success; - status["configuration"] = configToString(_preferedConfig); - status["puckCount"] = (int)_validTrackedObjects.size(); - status["head_puck"] = (_headConfig == HeadConfig::Puck) ? true : false; - status["hand_pucks"] = (_handConfig == HandConfig::Pucks) ? true : false; - } + status["calibrated"] = _calibrated; + status["configuration"] = configToString(_preferedConfig); + status["head_puck"] = (_headConfig == HeadConfig::Puck) ? true : false; + status["hand_pucks"] = (_handConfig == HandConfig::Pucks) ? true : false; + status["puckCount"] = (int)_validTrackedObjects.size(); + status["UI"] = _calibrate; - emit inputConfiguration->calibrationStatus(status); //inputConfiguration->calibrated(status); + emit inputConfiguration->calibrationStatus(status); } void ViveControllerManager::InputDevice::handleTrackedObject(uint32_t deviceIndex, const controller::InputCalibrationData& inputCalibrationData) { @@ -460,16 +447,14 @@ void ViveControllerManager::InputDevice::sendUserActivityData(QString activity) void ViveControllerManager::InputDevice::calibrateOrUncalibrate(const controller::InputCalibrationData& inputCalibration) { if (!_calibrated) { calibrate(inputCalibration); - if (_calibrated) { sendUserActivityData("mocap_button_success"); } else { sendUserActivityData("mocap_button_fail"); } - + emitCalibrationStatus(); } else { uncalibrate(); - emitCalibrationStatus(true); sendUserActivityData("mocap_button_uncalibrate"); } } @@ -482,7 +467,6 @@ void ViveControllerManager::InputDevice::calibrate(const controller::InputCalibr if (puckCount == 0) { uncalibrate(); - emitCalibrationStatus(false); return; } @@ -501,10 +485,8 @@ void ViveControllerManager::InputDevice::calibrate(const controller::InputCalibr if (!headConfigured || !handsConfigured || !bodyConfigured) { uncalibrate(); - emitCalibrationStatus(false); } else { _calibrated = true; - emitCalibrationStatus(true); qDebug() << "PuckCalibration: " << configToString(_config) << " Configuration Successful"; } } @@ -594,8 +576,6 @@ bool ViveControllerManager::InputDevice::configureBody(glm::mat4& defaultToRefer return true; } qDebug() << "Puck Calibration: " << configToString(_config) << " Config Failed: Could not meet the minimal # of pucks"; - uncalibrate(); - emitCalibrationStatus(false); return false; } diff --git a/plugins/openvr/src/ViveControllerManager.h b/plugins/openvr/src/ViveControllerManager.h index 19b485ad55..8397f8d804 100644 --- a/plugins/openvr/src/ViveControllerManager.h +++ b/plugins/openvr/src/ViveControllerManager.h @@ -107,7 +107,7 @@ private: void calibrateHead(glm::mat4& defaultToReferenceMat, const controller::InputCalibrationData& inputCalibration); void calibrateFromHandController(const controller::InputCalibrationData& inputCalibrationData); void calibrateFromUI(const controller::InputCalibrationData& inputCalibrationData); - void emitCalibrationStatus(const bool success); + void emitCalibrationStatus(); void calibrateNextFrame(); @@ -140,7 +140,7 @@ private: FeetAndHips, FeetHipsAndChest, FeetHipsAndShoulders, - FeetHipsChestAndShoulders, + FeetHipsChestAndShoulders }; enum class HeadConfig { From 9d002d6f6b38dfadd8feaa88ad179a37a3652076 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 28 Jun 2017 11:00:05 -0700 Subject: [PATCH 06/24] move the location of Q_DECLARE_METATYPE(std::function) so that the server-script AC can see it --- libraries/shared/src/RegisteredMetaTypes.cpp | 2 ++ libraries/shared/src/RegisteredMetaTypes.h | 2 ++ libraries/ui/src/ui/OffscreenQmlSurface.cpp | 6 ------ 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/libraries/shared/src/RegisteredMetaTypes.cpp b/libraries/shared/src/RegisteredMetaTypes.cpp index 70067b93f3..f793b78b39 100644 --- a/libraries/shared/src/RegisteredMetaTypes.cpp +++ b/libraries/shared/src/RegisteredMetaTypes.cpp @@ -34,6 +34,8 @@ int pickRayMetaTypeId = qRegisterMetaType(); int collisionMetaTypeId = qRegisterMetaType(); int qMapURLStringMetaTypeId = qRegisterMetaType>(); int socketErrorMetaTypeId = qRegisterMetaType(); +int voidLambdaType = qRegisterMetaType>(); +int variantLambdaType = qRegisterMetaType>(); void registerMetaTypes(QScriptEngine* engine) { qScriptRegisterMetaType(engine, mat4toScriptValue, mat4FromScriptValue); diff --git a/libraries/shared/src/RegisteredMetaTypes.h b/libraries/shared/src/RegisteredMetaTypes.h index 8a15f62eed..255a8115a1 100644 --- a/libraries/shared/src/RegisteredMetaTypes.h +++ b/libraries/shared/src/RegisteredMetaTypes.h @@ -33,6 +33,8 @@ Q_DECLARE_METATYPE(xColor) Q_DECLARE_METATYPE(QVector) Q_DECLARE_METATYPE(QVector) Q_DECLARE_METATYPE(AACube) +Q_DECLARE_METATYPE(std::function); +Q_DECLARE_METATYPE(std::function); void registerMetaTypes(QScriptEngine* engine); diff --git a/libraries/ui/src/ui/OffscreenQmlSurface.cpp b/libraries/ui/src/ui/OffscreenQmlSurface.cpp index f0006cb399..648bdad1bf 100644 --- a/libraries/ui/src/ui/OffscreenQmlSurface.cpp +++ b/libraries/ui/src/ui/OffscreenQmlSurface.cpp @@ -886,12 +886,6 @@ QQmlContext* OffscreenQmlSurface::getSurfaceContext() { return _qmlContext; } -Q_DECLARE_METATYPE(std::function); -auto VoidLambdaType = qRegisterMetaType>(); -Q_DECLARE_METATYPE(std::function); -auto VariantLambdaType = qRegisterMetaType>(); - - void OffscreenQmlSurface::executeOnUiThread(std::function function, bool blocking ) { if (QThread::currentThread() != thread()) { QMetaObject::invokeMethod(this, "executeOnUiThread", blocking ? Qt::BlockingQueuedConnection : Qt::QueuedConnection, From 3fa7d026a77606c9e8c3dc0c97558a41edbfbe3e Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 28 Jun 2017 14:18:14 -0700 Subject: [PATCH 07/24] make ResourceManager be owned by DependencyManager --- assignment-client/src/Agent.cpp | 7 ++--- .../src/entities/EntityServer.cpp | 2 +- .../src/scripts/EntityScriptServer.cpp | 7 ++--- interface/src/Application.cpp | 6 ++-- interface/src/assets/ATPAssetMigrator.cpp | 3 +- .../src/scripting/TestScriptingInterface.cpp | 2 +- .../src/EntityTreeRenderer.cpp | 2 +- libraries/entities/src/EntityEditFilters.cpp | 2 +- libraries/fbx/src/OBJReader.cpp | 4 +-- .../src/model-networking/TextureCache.cpp | 4 +-- libraries/networking/src/AtpReply.cpp | 2 +- libraries/networking/src/ResourceCache.cpp | 2 +- libraries/networking/src/ResourceManager.cpp | 22 ++++++------- libraries/networking/src/ResourceManager.h | 31 ++++++++++++------- .../src/ResourceScriptingInterface.cpp | 2 +- libraries/octree/src/Octree.cpp | 3 +- .../procedural/src/procedural/Procedural.cpp | 2 +- .../src/FileScriptingInterface.cpp | 2 +- libraries/script-engine/src/ScriptCache.cpp | 8 ++--- libraries/script-engine/src/ScriptEngine.cpp | 2 +- tests/render-perf/src/main.cpp | 7 ++--- tests/render-texture-load/src/main.cpp | 4 +-- 22 files changed, 65 insertions(+), 61 deletions(-) diff --git a/assignment-client/src/Agent.cpp b/assignment-client/src/Agent.cpp index 260a6d6825..f336f1dad5 100644 --- a/assignment-client/src/Agent.cpp +++ b/assignment-client/src/Agent.cpp @@ -62,8 +62,6 @@ Agent::Agent(ReceivedMessage& message) : _entityEditSender.setPacketsPerSecond(DEFAULT_ENTITY_PPS_PER_SCRIPT); DependencyManager::get()->setPacketSender(&_entityEditSender); - ResourceManager::init(); - DependencyManager::registerInheritance(); DependencyManager::set(); @@ -81,6 +79,7 @@ Agent::Agent(ReceivedMessage& message) : DependencyManager::set(); DependencyManager::set(); + DependencyManager::set(); auto& packetReceiver = DependencyManager::get()->getPacketReceiver(); @@ -199,7 +198,7 @@ void Agent::requestScript() { return; } - auto request = ResourceManager::createResourceRequest(this, scriptURL); + auto request = DependencyManager::get()->createResourceRequest(this, scriptURL); if (!request) { qWarning() << "Could not create ResourceRequest for Agent script at" << scriptURL.toString(); @@ -779,7 +778,7 @@ void Agent::aboutToFinish() { // our entity tree is going to go away so tell that to the EntityScriptingInterface DependencyManager::get()->setEntityTree(nullptr); - ResourceManager::cleanup(); + DependencyManager::get()->cleanup(); // cleanup the AudioInjectorManager (and any still running injectors) DependencyManager::destroy(); diff --git a/assignment-client/src/entities/EntityServer.cpp b/assignment-client/src/entities/EntityServer.cpp index dc0a2add3a..afcbcf4f1e 100644 --- a/assignment-client/src/entities/EntityServer.cpp +++ b/assignment-client/src/entities/EntityServer.cpp @@ -31,9 +31,9 @@ EntityServer::EntityServer(ReceivedMessage& message) : OctreeServer(message), _entitySimulation(NULL) { - ResourceManager::init(); DependencyManager::set(); DependencyManager::set(); + DependencyManager::set(); auto& packetReceiver = DependencyManager::get()->getPacketReceiver(); packetReceiver.registerListenerForTypes({ PacketType::EntityAdd, PacketType::EntityEdit, PacketType::EntityErase, PacketType::EntityPhysics }, diff --git a/assignment-client/src/scripts/EntityScriptServer.cpp b/assignment-client/src/scripts/EntityScriptServer.cpp index 1b226ab642..489478ff9a 100644 --- a/assignment-client/src/scripts/EntityScriptServer.cpp +++ b/assignment-client/src/scripts/EntityScriptServer.cpp @@ -54,7 +54,7 @@ EntityScriptServer::EntityScriptServer(ReceivedMessage& message) : ThreadedAssig DependencyManager::get()->setPacketSender(&_entityEditSender); - ResourceManager::init(); + DependencyManager::set(); DependencyManager::registerInheritance(); @@ -67,7 +67,6 @@ EntityScriptServer::EntityScriptServer(ReceivedMessage& message) : ThreadedAssig DependencyManager::set(); DependencyManager::set(ScriptEngine::ENTITY_SERVER_SCRIPT); - auto& packetReceiver = DependencyManager::get()->getPacketReceiver(); packetReceiver.registerListenerForTypes({ PacketType::OctreeStats, PacketType::EntityData, PacketType::EntityErase }, this, "handleOctreePacket"); @@ -493,7 +492,7 @@ void EntityScriptServer::checkAndCallPreload(const EntityItemID& entityID, bool if (entity && (reload || notRunning || details.scriptText != entity->getServerScripts())) { QString scriptUrl = entity->getServerScripts(); if (!scriptUrl.isEmpty()) { - scriptUrl = ResourceManager::normalizeURL(scriptUrl); + scriptUrl = DependencyManager::get()->normalizeURL(scriptUrl); qCDebug(entity_script_server) << "Loading entity server script" << scriptUrl << "for" << entityID; _entitiesScriptEngine->loadEntityScript(entityID, scriptUrl, reload); } @@ -551,7 +550,7 @@ void EntityScriptServer::aboutToFinish() { // our entity tree is going to go away so tell that to the EntityScriptingInterface DependencyManager::get()->setEntityTree(nullptr); - ResourceManager::cleanup(); + DependencyManager::get()->cleanup(); // cleanup the AudioInjectorManager (and any still running injectors) DependencyManager::destroy(); diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index c138230893..cfb8db42d7 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -574,6 +574,7 @@ bool setupEssentials(int& argc, char** argv, bool runningMarkerExisted) { DependencyManager::set(); DependencyManager::set(); DependencyManager::set(); + DependencyManager::set(); return previousSessionCrashed; } @@ -764,7 +765,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo connect(this, &Application::activeDisplayPluginChanged, reinterpret_cast(audioScriptingInterface.data()), &scripting::Audio::onContextChanged); - ResourceManager::init(); // Make sure we don't time out during slow operations at startup updateHeartbeat(); @@ -1868,7 +1868,7 @@ Application::~Application() { DependencyManager::destroy(); DependencyManager::destroy(); - ResourceManager::cleanup(); + DependencyManager::get()->cleanup(); // remove the NodeList from the DependencyManager DependencyManager::destroy(); @@ -5925,7 +5925,7 @@ void Application::addAssetToWorldFromURL(QString url) { addAssetToWorldInfo(filename, "Downloading model file " + filename + "."); - auto request = ResourceManager::createResourceRequest(nullptr, QUrl(url)); + auto request = DependencyManager::get()->createResourceRequest(nullptr, QUrl(url)); connect(request, &ResourceRequest::finished, this, &Application::addAssetToWorldFromURLRequestFinished); request->send(); } diff --git a/interface/src/assets/ATPAssetMigrator.cpp b/interface/src/assets/ATPAssetMigrator.cpp index e0e9d5a73a..667c2587b0 100644 --- a/interface/src/assets/ATPAssetMigrator.cpp +++ b/interface/src/assets/ATPAssetMigrator.cpp @@ -106,7 +106,8 @@ void ATPAssetMigrator::loadEntityServerFile() { jsonValue = entityObject; } else if (wantsToMigrateResource(migrationURL)) { - auto request = ResourceManager::createResourceRequest(this, migrationURL); + auto request = + DependencyManager::get()->createResourceRequest(this, migrationURL); if (request) { qCDebug(asset_migrator) << "Requesting" << migrationURL << "for ATP asset migration"; diff --git a/interface/src/scripting/TestScriptingInterface.cpp b/interface/src/scripting/TestScriptingInterface.cpp index b8892fae7e..84c742d0ab 100644 --- a/interface/src/scripting/TestScriptingInterface.cpp +++ b/interface/src/scripting/TestScriptingInterface.cpp @@ -62,7 +62,7 @@ bool TestScriptingInterface::loadTestScene(QString scene) { static const QString TEST_SCRIPTS_ROOT = TEST_ROOT + "scripts/"; static const QString TEST_SCENES_ROOT = TEST_ROOT + "scenes/"; return DependencyManager::get()->returnFromUiThread([scene]()->QVariant { - ResourceManager::setUrlPrefixOverride("atp:/", TEST_BINARY_ROOT + scene + ".atp/"); + DependencyManager::get()->setUrlPrefixOverride("atp:/", TEST_BINARY_ROOT + scene + ".atp/"); auto tree = qApp->getEntities()->getTree(); auto treeIsClient = tree->getIsClient(); // Force the tree to accept the load regardless of permissions diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.cpp b/libraries/entities-renderer/src/EntityTreeRenderer.cpp index ffaac3bf3e..42746d2046 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.cpp +++ b/libraries/entities-renderer/src/EntityTreeRenderer.cpp @@ -880,7 +880,7 @@ void EntityTreeRenderer::checkAndCallPreload(const EntityItemID& entityID, bool entity->scriptHasUnloaded(); } if (shouldLoad) { - scriptUrl = ResourceManager::normalizeURL(scriptUrl); + scriptUrl = DependencyManager::get()->normalizeURL(scriptUrl); _entitiesScriptEngine->loadEntityScript(entityID, scriptUrl, reload); entity->scriptHasPreloaded(); } diff --git a/libraries/entities/src/EntityEditFilters.cpp b/libraries/entities/src/EntityEditFilters.cpp index d62495d95e..5359ebd31b 100644 --- a/libraries/entities/src/EntityEditFilters.cpp +++ b/libraries/entities/src/EntityEditFilters.cpp @@ -132,7 +132,7 @@ void EntityEditFilters::addFilter(EntityItemID entityID, QString filterURL) { _filterDataMap.insert(entityID, filterData); _lock.unlock(); - auto scriptRequest = ResourceManager::createResourceRequest(this, scriptURL); + auto scriptRequest = DependencyManager::get()->createResourceRequest(this, scriptURL); if (!scriptRequest) { qWarning() << "Could not create ResourceRequest for Entity Edit filter script at" << scriptURL.toString(); scriptRequestFinished(entityID); diff --git a/libraries/fbx/src/OBJReader.cpp b/libraries/fbx/src/OBJReader.cpp index 1445d14d84..417901b9ab 100644 --- a/libraries/fbx/src/OBJReader.cpp +++ b/libraries/fbx/src/OBJReader.cpp @@ -202,7 +202,7 @@ bool OBJReader::isValidTexture(const QByteArray &filename) { } QUrl candidateUrl = _url.resolved(QUrl(filename)); - return ResourceManager::resourceExists(candidateUrl); + return DependencyManager::get()->resourceExists(candidateUrl); } void OBJReader::parseMaterialLibrary(QIODevice* device) { @@ -267,7 +267,7 @@ void OBJReader::parseMaterialLibrary(QIODevice* device) { } std::tuple requestData(QUrl& url) { - auto request = ResourceManager::createResourceRequest(nullptr, url); + auto request = DependencyManager::get()->createResourceRequest(nullptr, url); if (!request) { return std::make_tuple(false, QByteArray()); diff --git a/libraries/model-networking/src/model-networking/TextureCache.cpp b/libraries/model-networking/src/model-networking/TextureCache.cpp index ed1715219a..5c8f59f20f 100644 --- a/libraries/model-networking/src/model-networking/TextureCache.cpp +++ b/libraries/model-networking/src/model-networking/TextureCache.cpp @@ -384,7 +384,7 @@ void NetworkTexture::makeRequest() { // Add a fragment to the base url so we can identify the section of the ktx being requested when debugging // The actual requested url is _activeUrl and will not contain the fragment _url.setFragment("head"); - _ktxHeaderRequest = ResourceManager::createResourceRequest(this, _activeUrl); + _ktxHeaderRequest = DependencyManager::get()->createResourceRequest(this, _activeUrl); if (!_ktxHeaderRequest) { qCDebug(networking).noquote() << "Failed to get request for" << _url.toDisplayString(); @@ -454,7 +454,7 @@ void NetworkTexture::startMipRangeRequest(uint16_t low, uint16_t high) { bool isHighMipRequest = low == NULL_MIP_LEVEL && high == NULL_MIP_LEVEL; - _ktxMipRequest = ResourceManager::createResourceRequest(this, _activeUrl); + _ktxMipRequest = DependencyManager::get()->createResourceRequest(this, _activeUrl); if (!_ktxMipRequest) { qCWarning(networking).noquote() << "Failed to get request for" << _url.toDisplayString(); diff --git a/libraries/networking/src/AtpReply.cpp b/libraries/networking/src/AtpReply.cpp index 4440995ee0..6417478005 100644 --- a/libraries/networking/src/AtpReply.cpp +++ b/libraries/networking/src/AtpReply.cpp @@ -13,7 +13,7 @@ #include "AtpReply.h" AtpReply::AtpReply(const QUrl& url, QObject* parent) : - _resourceRequest(ResourceManager::createResourceRequest(parent, url)) { + _resourceRequest(DependencyManager::get()->createResourceRequest(parent, url)) { setOperation(QNetworkAccessManager::GetOperation); connect(_resourceRequest, &AssetResourceRequest::progress, this, &AtpReply::downloadProgress); diff --git a/libraries/networking/src/ResourceCache.cpp b/libraries/networking/src/ResourceCache.cpp index 88ea68780b..f07514cd85 100644 --- a/libraries/networking/src/ResourceCache.cpp +++ b/libraries/networking/src/ResourceCache.cpp @@ -672,7 +672,7 @@ void Resource::makeRequest() { PROFILE_ASYNC_BEGIN(resource, "Resource:" + getType(), QString::number(_requestID), { { "url", _url.toString() }, { "activeURL", _activeUrl.toString() } }); - _request = ResourceManager::createResourceRequest(this, _activeUrl); + _request = DependencyManager::get()->createResourceRequest(this, _activeUrl); if (!_request) { qCDebug(networking).noquote() << "Failed to get request for" << _url.toDisplayString(); diff --git a/libraries/networking/src/ResourceManager.cpp b/libraries/networking/src/ResourceManager.cpp index e2c1cf2431..3ee66f89c1 100644 --- a/libraries/networking/src/ResourceManager.cpp +++ b/libraries/networking/src/ResourceManager.cpp @@ -24,10 +24,16 @@ #include "NetworkAccessManager.h" #include "NetworkLogging.h" -QThread ResourceManager::_thread; -ResourceManager::PrefixMap ResourceManager::_prefixMap; -QMutex ResourceManager::_prefixMapLock; +ResourceManager::ResourceManager() { + _thread.setObjectName("Resource Manager Thread"); + + auto assetClient = DependencyManager::set(); + assetClient->moveToThread(&_thread); + QObject::connect(&_thread, &QThread::started, assetClient.data(), &AssetClient::init); + + _thread.start(); +} void ResourceManager::setUrlPrefixOverride(const QString& prefix, const QString& replacement) { QMutexLocker locker(&_prefixMapLock); @@ -75,16 +81,6 @@ QUrl ResourceManager::normalizeURL(const QUrl& originalUrl) { return url; } -void ResourceManager::init() { - _thread.setObjectName("Resource Manager Thread"); - - auto assetClient = DependencyManager::set(); - assetClient->moveToThread(&_thread); - QObject::connect(&_thread, &QThread::started, assetClient.data(), &AssetClient::init); - - _thread.start(); -} - void ResourceManager::cleanup() { // cleanup the AssetClient thread DependencyManager::destroy(); diff --git a/libraries/networking/src/ResourceManager.h b/libraries/networking/src/ResourceManager.h index 41da892701..f7495e71e9 100644 --- a/libraries/networking/src/ResourceManager.h +++ b/libraries/networking/src/ResourceManager.h @@ -14,7 +14,11 @@ #include +#include #include +#include + +#include #include "ResourceRequest.h" @@ -24,29 +28,34 @@ const QString URL_SCHEME_HTTPS = "https"; const QString URL_SCHEME_FTP = "ftp"; const QString URL_SCHEME_ATP = "atp"; -class ResourceManager { +class ResourceManager: public QObject, public Dependency { + Q_OBJECT + SINGLETON_DEPENDENCY + public: + ResourceManager(); - static void setUrlPrefixOverride(const QString& prefix, const QString& replacement); - static QString normalizeURL(const QString& urlString); - static QUrl normalizeURL(const QUrl& url); + void setUrlPrefixOverride(const QString& prefix, const QString& replacement); + QString normalizeURL(const QString& urlString); + QUrl normalizeURL(const QUrl& url); - static ResourceRequest* createResourceRequest(QObject* parent, const QUrl& url); + ResourceRequest* createResourceRequest(QObject* parent, const QUrl& url); - static void init(); - static void cleanup(); + void init(); + void cleanup(); // Blocking call to check if a resource exists. This function uses a QEventLoop internally // to return to the calling thread so that events can still be processed. - static bool resourceExists(const QUrl& url); + bool resourceExists(const QUrl& url); private: - static QThread _thread; + QThread _thread; using PrefixMap = std::map; - static PrefixMap _prefixMap; - static QMutex _prefixMapLock; + PrefixMap _prefixMap; + QMutex _prefixMapLock; + }; #endif diff --git a/libraries/networking/src/ResourceScriptingInterface.cpp b/libraries/networking/src/ResourceScriptingInterface.cpp index 38be49049c..3227d44de1 100644 --- a/libraries/networking/src/ResourceScriptingInterface.cpp +++ b/libraries/networking/src/ResourceScriptingInterface.cpp @@ -11,5 +11,5 @@ #include "ResourceManager.h" void ResourceScriptingInterface::overrideUrlPrefix(const QString& prefix, const QString& replacement) { - ResourceManager::setUrlPrefixOverride(prefix, replacement); + DependencyManager::get()->setUrlPrefixOverride(prefix, replacement); } diff --git a/libraries/octree/src/Octree.cpp b/libraries/octree/src/Octree.cpp index 180f25f106..2e93f3515f 100644 --- a/libraries/octree/src/Octree.cpp +++ b/libraries/octree/src/Octree.cpp @@ -1668,7 +1668,8 @@ bool Octree::readJSONFromGzippedFile(QString qFileName) { } bool Octree::readFromURL(const QString& urlString) { - auto request = std::unique_ptr(ResourceManager::createResourceRequest(this, urlString)); + auto request = + std::unique_ptr(DependencyManager::get()->createResourceRequest(this, urlString)); if (!request) { return false; diff --git a/libraries/procedural/src/procedural/Procedural.cpp b/libraries/procedural/src/procedural/Procedural.cpp index e4ce3c691a..c38e562672 100644 --- a/libraries/procedural/src/procedural/Procedural.cpp +++ b/libraries/procedural/src/procedural/Procedural.cpp @@ -103,7 +103,7 @@ bool Procedural::parseVersion(const QJsonValue& version) { } bool Procedural::parseShader(const QUrl& shaderPath) { - auto shaderUrl = ResourceManager::normalizeURL(shaderPath); + auto shaderUrl = DependencyManager::get()->normalizeURL(shaderPath); if (!shaderUrl.isValid()) { if (!shaderUrl.isEmpty()) { diff --git a/libraries/script-engine/src/FileScriptingInterface.cpp b/libraries/script-engine/src/FileScriptingInterface.cpp index 2f5cc2bc88..30d0a3a201 100644 --- a/libraries/script-engine/src/FileScriptingInterface.cpp +++ b/libraries/script-engine/src/FileScriptingInterface.cpp @@ -85,7 +85,7 @@ QString FileScriptingInterface::convertUrlToPath(QUrl url) { // this function is not in use void FileScriptingInterface::downloadZip(QString path, const QString link) { QUrl url = QUrl(link); - auto request = ResourceManager::createResourceRequest(nullptr, url); + auto request = DependencyManager::get()->createResourceRequest(nullptr, url); connect(request, &ResourceRequest::finished, this, [this, path]{ unzipFile(path, ""); // so intellisense isn't mad }); diff --git a/libraries/script-engine/src/ScriptCache.cpp b/libraries/script-engine/src/ScriptCache.cpp index 601ca6bc95..dba2db0458 100644 --- a/libraries/script-engine/src/ScriptCache.cpp +++ b/libraries/script-engine/src/ScriptCache.cpp @@ -57,7 +57,7 @@ void ScriptCache::clearATPScriptsFromCache() { } void ScriptCache::deleteScript(const QUrl& unnormalizedURL) { - QUrl url = ResourceManager::normalizeURL(unnormalizedURL); + QUrl url = DependencyManager::get()->normalizeURL(unnormalizedURL); Lock lock(_containerLock); if (_scriptCache.contains(url)) { qCDebug(scriptengine) << "Delete script from cache:" << url.toString(); @@ -70,7 +70,7 @@ void ScriptCache::getScriptContents(const QString& scriptOrURL, contentAvailable qCDebug(scriptengine) << "ScriptCache::getScriptContents() on thread [" << QThread::currentThread() << "] expected thread [" << thread() << "]"; #endif QUrl unnormalizedURL(scriptOrURL); - QUrl url = ResourceManager::normalizeURL(unnormalizedURL); + QUrl url = DependencyManager::get()->normalizeURL(unnormalizedURL); // attempt to determine if this is a URL to a script, or if this is actually a script itself (which is valid in the // entityScript use case) @@ -109,7 +109,7 @@ void ScriptCache::getScriptContents(const QString& scriptOrURL, contentAvailable #ifdef THREAD_DEBUGGING qCDebug(scriptengine) << "about to call: ResourceManager::createResourceRequest(this, url); on thread [" << QThread::currentThread() << "] expected thread [" << thread() << "]"; #endif - auto request = ResourceManager::createResourceRequest(nullptr, url); + auto request = DependencyManager::get()->createResourceRequest(nullptr, url); Q_ASSERT(request); request->setCacheEnabled(!forceDownload); connect(request, &ResourceRequest::finished, this, [=]{ scriptContentAvailable(maxRetries); }); @@ -166,7 +166,7 @@ void ScriptCache::scriptContentAvailable(int maxRetries) { qCDebug(scriptengine) << QString("Retrying script request [%1 / %2]: %3") .arg(attempt).arg(maxRetries).arg(url.toString()); - auto request = ResourceManager::createResourceRequest(nullptr, url); + auto request = DependencyManager::get()->createResourceRequest(nullptr, url); Q_ASSERT(request); // We've already made a request, so the cache must be disabled or it wasn't there, so enabling diff --git a/libraries/script-engine/src/ScriptEngine.cpp b/libraries/script-engine/src/ScriptEngine.cpp index d9b41bb55d..59694cba6f 100644 --- a/libraries/script-engine/src/ScriptEngine.cpp +++ b/libraries/script-engine/src/ScriptEngine.cpp @@ -1755,7 +1755,7 @@ void ScriptEngine::include(const QStringList& includeFiles, QScriptValue callbac QList urls; for (QString includeFile : includeFiles) { - QString file = ResourceManager::normalizeURL(includeFile); + QString file = DependencyManager::get()->normalizeURL(includeFile); QUrl thisURL; bool isStandardLibrary = false; if (file.startsWith("/~/")) { diff --git a/tests/render-perf/src/main.cpp b/tests/render-perf/src/main.cpp index 52592cd202..c4543e354a 100644 --- a/tests/render-perf/src/main.cpp +++ b/tests/render-perf/src/main.cpp @@ -493,6 +493,7 @@ public: DependencyManager::set(); DependencyManager::set(); DependencyManager::set(); + DependencyManager::set(); } QTestWindow() { @@ -519,8 +520,6 @@ public: _entitySimulation = simpleSimulation; } - ResourceManager::init(); - setFlags(Qt::MSWindowsOwnDC | Qt::Window | Qt::Dialog | Qt::WindowMinMaxButtonsHint | Qt::WindowTitleHint); _size = QSize(800, 600); _renderThread._size = _size; @@ -574,7 +573,7 @@ public: DependencyManager::destroy(); DependencyManager::destroy(); DependencyManager::destroy(); - ResourceManager::cleanup(); + DependencyManager::get()->cleanup(); // remove the NodeList from the DependencyManager DependencyManager::destroy(); } @@ -997,7 +996,7 @@ private: QFileInfo atpPathInfo(atpPath); if (atpPathInfo.exists()) { QString atpUrl = QUrl::fromLocalFile(atpPath).toString(); - ResourceManager::setUrlPrefixOverride("atp:/", atpUrl + "/"); + DependencyManager::get()->setUrlPrefixOverride("atp:/", atpUrl + "/"); } _octree->clear(); _octree->getTree()->readFromURL(fileName); diff --git a/tests/render-texture-load/src/main.cpp b/tests/render-texture-load/src/main.cpp index f426cd8024..5920e04558 100644 --- a/tests/render-texture-load/src/main.cpp +++ b/tests/render-texture-load/src/main.cpp @@ -289,6 +289,7 @@ public: DependencyManager::set(); DependencyManager::set(); DependencyManager::set(); + DependencyManager::set(); } struct TextureLoad { @@ -329,7 +330,6 @@ public: installEventFilter(this); QThreadPool::globalInstance()->setMaxThreadCount(2); QThread::currentThread()->setPriority(QThread::HighestPriority); - ResourceManager::init(); setFlags(Qt::MSWindowsOwnDC | Qt::Window | Qt::Dialog | Qt::WindowMinMaxButtonsHint | Qt::WindowTitleHint); _size = QSize(800, 600); _renderThread._size = _size; @@ -369,7 +369,7 @@ public: DependencyManager::destroy(); DependencyManager::destroy(); DependencyManager::destroy(); - ResourceManager::cleanup(); + DependencyManager::get()->cleanup(); } protected: From f59a94d4011be0423ecfa089f93ea98eb9217fcb Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Thu, 29 Jun 2017 00:52:51 +0200 Subject: [PATCH 08/24] move the ResourceManager init back to where it was, to prevent problems --- assignment-client/src/Agent.cpp | 3 ++- assignment-client/src/entities/EntityServer.cpp | 2 +- tests/render-perf/src/main.cpp | 3 ++- tests/render-texture-load/src/main.cpp | 4 ++-- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/assignment-client/src/Agent.cpp b/assignment-client/src/Agent.cpp index f336f1dad5..8aec5adb1f 100644 --- a/assignment-client/src/Agent.cpp +++ b/assignment-client/src/Agent.cpp @@ -62,6 +62,8 @@ Agent::Agent(ReceivedMessage& message) : _entityEditSender.setPacketsPerSecond(DEFAULT_ENTITY_PPS_PER_SCRIPT); DependencyManager::get()->setPacketSender(&_entityEditSender); + DependencyManager::set(); + DependencyManager::registerInheritance(); DependencyManager::set(); @@ -79,7 +81,6 @@ Agent::Agent(ReceivedMessage& message) : DependencyManager::set(); DependencyManager::set(); - DependencyManager::set(); auto& packetReceiver = DependencyManager::get()->getPacketReceiver(); diff --git a/assignment-client/src/entities/EntityServer.cpp b/assignment-client/src/entities/EntityServer.cpp index afcbcf4f1e..ac686e2e0a 100644 --- a/assignment-client/src/entities/EntityServer.cpp +++ b/assignment-client/src/entities/EntityServer.cpp @@ -31,9 +31,9 @@ EntityServer::EntityServer(ReceivedMessage& message) : OctreeServer(message), _entitySimulation(NULL) { + DependencyManager::set(); DependencyManager::set(); DependencyManager::set(); - DependencyManager::set(); auto& packetReceiver = DependencyManager::get()->getPacketReceiver(); packetReceiver.registerListenerForTypes({ PacketType::EntityAdd, PacketType::EntityEdit, PacketType::EntityErase, PacketType::EntityPhysics }, diff --git a/tests/render-perf/src/main.cpp b/tests/render-perf/src/main.cpp index c4543e354a..0b7e68301a 100644 --- a/tests/render-perf/src/main.cpp +++ b/tests/render-perf/src/main.cpp @@ -493,7 +493,6 @@ public: DependencyManager::set(); DependencyManager::set(); DependencyManager::set(); - DependencyManager::set(); } QTestWindow() { @@ -519,6 +518,8 @@ public: _octree->getTree()->setSimulation(simpleSimulation); _entitySimulation = simpleSimulation; } + + DependencyManager::set(); setFlags(Qt::MSWindowsOwnDC | Qt::Window | Qt::Dialog | Qt::WindowMinMaxButtonsHint | Qt::WindowTitleHint); _size = QSize(800, 600); diff --git a/tests/render-texture-load/src/main.cpp b/tests/render-texture-load/src/main.cpp index 5920e04558..d85fcd6a32 100644 --- a/tests/render-texture-load/src/main.cpp +++ b/tests/render-texture-load/src/main.cpp @@ -289,7 +289,6 @@ public: DependencyManager::set(); DependencyManager::set(); DependencyManager::set(); - DependencyManager::set(); } struct TextureLoad { @@ -329,7 +328,8 @@ public: installEventFilter(this); QThreadPool::globalInstance()->setMaxThreadCount(2); - QThread::currentThread()->setPriority(QThread::HighestPriority); + QThread::currentThread()->setPriority(QThread::HighestPriority); + DependencyManager::set(); setFlags(Qt::MSWindowsOwnDC | Qt::Window | Qt::Dialog | Qt::WindowMinMaxButtonsHint | Qt::WindowTitleHint); _size = QSize(800, 600); _renderThread._size = _size; From 6c487ec0afce27d889bf5ed252a312bd37028e85 Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Thu, 29 Jun 2017 01:01:59 +0200 Subject: [PATCH 09/24] I need to setup my code-editor, spaces. --- tests/render-perf/src/main.cpp | 2 +- tests/render-texture-load/src/main.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/render-perf/src/main.cpp b/tests/render-perf/src/main.cpp index 0b7e68301a..d47821ab1c 100644 --- a/tests/render-perf/src/main.cpp +++ b/tests/render-perf/src/main.cpp @@ -518,7 +518,7 @@ public: _octree->getTree()->setSimulation(simpleSimulation); _entitySimulation = simpleSimulation; } - + DependencyManager::set(); setFlags(Qt::MSWindowsOwnDC | Qt::Window | Qt::Dialog | Qt::WindowMinMaxButtonsHint | Qt::WindowTitleHint); diff --git a/tests/render-texture-load/src/main.cpp b/tests/render-texture-load/src/main.cpp index d85fcd6a32..67b80d9ba8 100644 --- a/tests/render-texture-load/src/main.cpp +++ b/tests/render-texture-load/src/main.cpp @@ -328,7 +328,7 @@ public: installEventFilter(this); QThreadPool::globalInstance()->setMaxThreadCount(2); - QThread::currentThread()->setPriority(QThread::HighestPriority); + QThread::currentThread()->setPriority(QThread::HighestPriority); DependencyManager::set(); setFlags(Qt::MSWindowsOwnDC | Qt::Window | Qt::Dialog | Qt::WindowMinMaxButtonsHint | Qt::WindowTitleHint); _size = QSize(800, 600); From a3db9ae726efe37e4da4e7909a702ca107c37801 Mon Sep 17 00:00:00 2001 From: Cain Kilgore Date: Fri, 30 Jun 2017 15:40:42 +0100 Subject: [PATCH 10/24] Begin Rocket Hands branch --- scripts/developer/rockethands.js | 35 ++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 scripts/developer/rockethands.js diff --git a/scripts/developer/rockethands.js b/scripts/developer/rockethands.js new file mode 100644 index 0000000000..b68d6cc9c6 --- /dev/null +++ b/scripts/developer/rockethands.js @@ -0,0 +1,35 @@ +"use strict"; + +// +// rockethands.js +// system +// +// Created by Cain Kilgore on 30/06/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 +// + +(function() { + function logToConsole(message) { + console.log("[rockethands.js] " + message); + } + + logToConsole("Rockethands.js script is now active."); + + Script.setInterval(function() { + if(Controller.Hardware.Vive) { + var rightHand = Controller.getPoseValue(Controller.Hardware.Vive.RightHand).rotation.y; + + // logToConsole("Y VALUE: " + rightHand); + if(rightHand < -0.1 && rightHand > -0.4) { + logToConsole("Pointing down.. eye position: " + Camera.getOrientation().x + ", " + Camera.getOrientation().y + ", " + Camera.getOrientation().z + " - we have liftoff - I think!"); + MyAvatar.motorReferenceFrame = "world"; + // MyAvatar.motorVelocity = {x: Camera.getOrientation().x, y: Camera.getOrientation().y*3, z: Camera.getOrientation().z}; + MyAvatar.motorVelocity = Camera.getOrientation()*3; + MyAvatar.motorTimescale = 1.0; + } + } + }, 1000); +}()); From a749fa19adb3deced0945199505382bfc5f5a67e Mon Sep 17 00:00:00 2001 From: Dante Ruiz Date: Fri, 30 Jun 2017 19:14:22 +0100 Subject: [PATCH 11/24] made requested changes --- plugins/openvr/src/ViveControllerManager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/openvr/src/ViveControllerManager.cpp b/plugins/openvr/src/ViveControllerManager.cpp index ca211a9cfe..825d709b2a 100644 --- a/plugins/openvr/src/ViveControllerManager.cpp +++ b/plugins/openvr/src/ViveControllerManager.cpp @@ -374,8 +374,8 @@ QJsonObject ViveControllerManager::InputDevice::configurationSettings() { Locker locker(_lock); QJsonObject configurationSettings; configurationSettings["trackerConfiguration"] = configToString(_preferedConfig); - configurationSettings["HMDHead"] = (_headConfig == HeadConfig::HMD) ? true : false; - configurationSettings["handController"] = (_handConfig == HandConfig::HandController) ? true : false; + configurationSettings["HMDHead"] = (_headConfig == HeadConfig::HMD); + configurationSettings["handController"] = (_handConfig == HandConfig::HandController); configurationSettings["puckCount"] = (int)_validTrackedObjects.size(); return configurationSettings; } From e0120ebf3011a3d5cb477c437ba076d8e9d983b2 Mon Sep 17 00:00:00 2001 From: Cain Kilgore Date: Sun, 2 Jul 2017 03:20:07 +0100 Subject: [PATCH 12/24] Rocket Hands --- .../marketplace/rocketHands/rockethands.js | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 unpublishedScripts/marketplace/rocketHands/rockethands.js diff --git a/unpublishedScripts/marketplace/rocketHands/rockethands.js b/unpublishedScripts/marketplace/rocketHands/rockethands.js new file mode 100644 index 0000000000..678e51565d --- /dev/null +++ b/unpublishedScripts/marketplace/rocketHands/rockethands.js @@ -0,0 +1,43 @@ +"use strict"; + +/* + rockethands.js + system + + Created by Cain Kilgore on 30/06/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 +*/ + +(function() { + var isRocketing = false; + + Script.setInterval(function() { + if (Controller.Hardware.Vive) { + var rightHand = Controller.getPoseValue(Controller.Hardware.Vive.RightHand); + var getHip = MyAvatar.getJointPosition("Hips"); + var worldControllerPos = Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, rightHand.translation)); + + if ((worldControllerPos.y > (getHip.y - 0.1)) && (worldControllerPos.y < (getHip.y + 0.1))) { + if (rightHand.rotation.y < 0.25 && rightHand.rotation.y > -0.25) { + isRocketing = true; + Controller.triggerHapticPulse(0.1, 120, 2); + MyAvatar.motorReferenceFrame = "world"; + var moveVector = Vec3.multiply(Quat.getFront(Camera.getOrientation()), 10); + if(!MyAvatar.isFlying()) { + moveVector = Vec3.sum(moveVector, {x: 0, y: 1, z: 0}); + } + MyAvatar.motorVelocity = moveVector; + MyAvatar.motorTimescale = 1.0; + } else { + if (isRocketing) { + MyAvatar.motorVelocity = 0; + isRocketing = false; + } + } + } + } + }, 100); +}()); \ No newline at end of file From a693a61ec891dd3f44fcd2f1d9e06eabb7353f04 Mon Sep 17 00:00:00 2001 From: Cain Kilgore Date: Sun, 2 Jul 2017 03:20:54 +0100 Subject: [PATCH 13/24] Cleanup --- scripts/developer/rockethands.js | 35 -------------------------------- 1 file changed, 35 deletions(-) delete mode 100644 scripts/developer/rockethands.js diff --git a/scripts/developer/rockethands.js b/scripts/developer/rockethands.js deleted file mode 100644 index b68d6cc9c6..0000000000 --- a/scripts/developer/rockethands.js +++ /dev/null @@ -1,35 +0,0 @@ -"use strict"; - -// -// rockethands.js -// system -// -// Created by Cain Kilgore on 30/06/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 -// - -(function() { - function logToConsole(message) { - console.log("[rockethands.js] " + message); - } - - logToConsole("Rockethands.js script is now active."); - - Script.setInterval(function() { - if(Controller.Hardware.Vive) { - var rightHand = Controller.getPoseValue(Controller.Hardware.Vive.RightHand).rotation.y; - - // logToConsole("Y VALUE: " + rightHand); - if(rightHand < -0.1 && rightHand > -0.4) { - logToConsole("Pointing down.. eye position: " + Camera.getOrientation().x + ", " + Camera.getOrientation().y + ", " + Camera.getOrientation().z + " - we have liftoff - I think!"); - MyAvatar.motorReferenceFrame = "world"; - // MyAvatar.motorVelocity = {x: Camera.getOrientation().x, y: Camera.getOrientation().y*3, z: Camera.getOrientation().z}; - MyAvatar.motorVelocity = Camera.getOrientation()*3; - MyAvatar.motorTimescale = 1.0; - } - } - }, 1000); -}()); From 44f0b8bd6043484d9aadb14e2e5c2171e1935f98 Mon Sep 17 00:00:00 2001 From: Cain Kilgore Date: Sun, 2 Jul 2017 11:41:33 +0100 Subject: [PATCH 14/24] Support for Oculus & Vive - cleaned up some code, using Script.connect instead of setInterval --- .../marketplace/rocketHands/rockethands.js | 40 ++++++++++++------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/unpublishedScripts/marketplace/rocketHands/rockethands.js b/unpublishedScripts/marketplace/rocketHands/rockethands.js index 678e51565d..a4a4cf777c 100644 --- a/unpublishedScripts/marketplace/rocketHands/rockethands.js +++ b/unpublishedScripts/marketplace/rocketHands/rockethands.js @@ -13,15 +13,18 @@ (function() { var isRocketing = false; + MyAvatar.motorVelocity = 0; - Script.setInterval(function() { - if (Controller.Hardware.Vive) { - var rightHand = Controller.getPoseValue(Controller.Hardware.Vive.RightHand); - var getHip = MyAvatar.getJointPosition("Hips"); - var worldControllerPos = Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, rightHand.translation)); - - if ((worldControllerPos.y > (getHip.y - 0.1)) && (worldControllerPos.y < (getHip.y + 0.1))) { - if (rightHand.rotation.y < 0.25 && rightHand.rotation.y > -0.25) { + function checkRocketting() { + if (Controller.Hardware.Vive || Controller.Hardware.OculusTouch) { + var leftHand = Controller.getPoseValue(Controller.Standard.LeftHand); + var rightHand = Controller.getPoseValue(Controller.Standard.RightHand); + var leftWorldControllerPos = Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, leftHand.translation)); + var rightWorldControllerPos = Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, rightHand.translation)); + var hipPosition = MyAvatar.getJointPosition("Hips"); + + if ((leftWorldControllerPos.y > (hipPosition.y - 0.1)) && (leftWorldControllerPos.y < (hipPosition.y + 0.1)) && rightWorldControllerPos.y > (hipPosition.y - 0.1) && (rightWorldControllerPos.y < (hipPosition.y + 0.1))) { + if (leftHand.rotation.y < 0.25 && leftHand.rotation.y > -0.25 && rightHand.rotation.y < 0.25 && rightHand.rotation.y > -0.25) { isRocketing = true; Controller.triggerHapticPulse(0.1, 120, 2); MyAvatar.motorReferenceFrame = "world"; @@ -31,13 +34,20 @@ } MyAvatar.motorVelocity = moveVector; MyAvatar.motorTimescale = 1.0; - } else { - if (isRocketing) { - MyAvatar.motorVelocity = 0; - isRocketing = false; - } - } + } else { + if (isRocketing) { + MyAvatar.motorVelocity = 0; + isRocketing = false; + } + } + } else { + if (isRocketing) { + MyAvatar.motorVelocity = 0; + isRocketing = false; + } } } - }, 100); + }; + + Script.update.connect(checkRocketting); }()); \ No newline at end of file From 5fbcd494be53abca97c18cfad02ceae3c3469c13 Mon Sep 17 00:00:00 2001 From: Dante Ruiz Date: Mon, 3 Jul 2017 16:46:58 +0100 Subject: [PATCH 15/24] made final requested changes --- plugins/openvr/src/ViveControllerManager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/openvr/src/ViveControllerManager.cpp b/plugins/openvr/src/ViveControllerManager.cpp index 825d709b2a..2f9aa4405a 100644 --- a/plugins/openvr/src/ViveControllerManager.cpp +++ b/plugins/openvr/src/ViveControllerManager.cpp @@ -385,8 +385,8 @@ void ViveControllerManager::InputDevice::emitCalibrationStatus() { QJsonObject status = QJsonObject(); status["calibrated"] = _calibrated; status["configuration"] = configToString(_preferedConfig); - status["head_puck"] = (_headConfig == HeadConfig::Puck) ? true : false; - status["hand_pucks"] = (_handConfig == HandConfig::Pucks) ? true : false; + status["head_puck"] = (_headConfig == HeadConfig::Puck); + status["hand_pucks"] = (_handConfig == HandConfig::Pucks); status["puckCount"] = (int)_validTrackedObjects.size(); status["UI"] = _calibrate; From 7d382d9da0bbd70dc3e726fff4ef52cc1e0af85d Mon Sep 17 00:00:00 2001 From: Cain Kilgore Date: Mon, 3 Jul 2017 17:47:54 +0100 Subject: [PATCH 16/24] Fixed spelling, added is in HMD Check, removed Haptic Feedback as it wasn't part of the WL --- .../marketplace/rocketHands/rockethands.js | 56 ++++++++++--------- 1 file changed, 31 insertions(+), 25 deletions(-) diff --git a/unpublishedScripts/marketplace/rocketHands/rockethands.js b/unpublishedScripts/marketplace/rocketHands/rockethands.js index a4a4cf777c..0e8746add1 100644 --- a/unpublishedScripts/marketplace/rocketHands/rockethands.js +++ b/unpublishedScripts/marketplace/rocketHands/rockethands.js @@ -12,39 +12,45 @@ */ (function() { - var isRocketing = false; + var isRocketting = false; MyAvatar.motorVelocity = 0; function checkRocketting() { - if (Controller.Hardware.Vive || Controller.Hardware.OculusTouch) { - var leftHand = Controller.getPoseValue(Controller.Standard.LeftHand); - var rightHand = Controller.getPoseValue(Controller.Standard.RightHand); - var leftWorldControllerPos = Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, leftHand.translation)); - var rightWorldControllerPos = Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, rightHand.translation)); - var hipPosition = MyAvatar.getJointPosition("Hips"); - - if ((leftWorldControllerPos.y > (hipPosition.y - 0.1)) && (leftWorldControllerPos.y < (hipPosition.y + 0.1)) && rightWorldControllerPos.y > (hipPosition.y - 0.1) && (rightWorldControllerPos.y < (hipPosition.y + 0.1))) { - if (leftHand.rotation.y < 0.25 && leftHand.rotation.y > -0.25 && rightHand.rotation.y < 0.25 && rightHand.rotation.y > -0.25) { - isRocketing = true; - Controller.triggerHapticPulse(0.1, 120, 2); - MyAvatar.motorReferenceFrame = "world"; - var moveVector = Vec3.multiply(Quat.getFront(Camera.getOrientation()), 10); - if(!MyAvatar.isFlying()) { - moveVector = Vec3.sum(moveVector, {x: 0, y: 1, z: 0}); + if (HMD.active) { + if (Controller.Hardware.Vive || Controller.Hardware.OculusTouch) { + var leftHand = Controller.getPoseValue(Controller.Standard.LeftHand); + var rightHand = Controller.getPoseValue(Controller.Standard.RightHand); + var leftWorldControllerPos = Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, leftHand.translation)); + var rightWorldControllerPos = Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, rightHand.translation)); + var hipPosition = MyAvatar.getJointPosition("Hips"); + + if ((leftWorldControllerPos.y > (hipPosition.y - 0.1)) && (leftWorldControllerPos.y < (hipPosition.y + 0.1)) && rightWorldControllerPos.y > (hipPosition.y - 0.1) && (rightWorldControllerPos.y < (hipPosition.y + 0.1))) { + if (leftHand.rotation.y < 0.25 && leftHand.rotation.y > -0.25 && rightHand.rotation.y < 0.25 && rightHand.rotation.y > -0.25) { + isRocketting = true; + MyAvatar.motorReferenceFrame = "world"; + var moveVector = Vec3.multiply(Quat.getFront(Camera.getOrientation()), 10); + if(!MyAvatar.isFlying()) { + moveVector = Vec3.sum(moveVector, {x: 0, y: 1, z: 0}); + } + MyAvatar.motorVelocity = moveVector; + MyAvatar.motorTimescale = 1.0; + } else { + if (isRocketting) { + MyAvatar.motorVelocity = 0; + isRocketting = false; + } } - MyAvatar.motorVelocity = moveVector; - MyAvatar.motorTimescale = 1.0; } else { - if (isRocketing) { + if (isRocketting) { MyAvatar.motorVelocity = 0; - isRocketing = false; + isRocketting = false; } } - } else { - if (isRocketing) { - MyAvatar.motorVelocity = 0; - isRocketing = false; - } + } + } else { + if(isRocketting) { + MyAvatar.motorVelocity = 0; + isRocketting = false; } } }; From 2c53b5b372312ea7ec800a1d4721ec48a2b1c7d7 Mon Sep 17 00:00:00 2001 From: Cain Kilgore Date: Mon, 3 Jul 2017 19:09:54 +0100 Subject: [PATCH 17/24] QA Cleanup --- .../marketplace/rocketHands/rockethands.js | 38 +++++++++---------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/unpublishedScripts/marketplace/rocketHands/rockethands.js b/unpublishedScripts/marketplace/rocketHands/rockethands.js index 0e8746add1..f8a22be579 100644 --- a/unpublishedScripts/marketplace/rocketHands/rockethands.js +++ b/unpublishedScripts/marketplace/rocketHands/rockethands.js @@ -12,10 +12,9 @@ */ (function() { - var isRocketting = false; - MyAvatar.motorVelocity = 0; + var isRocketing = false; - function checkRocketting() { + function checkRocketing() { if (HMD.active) { if (Controller.Hardware.Vive || Controller.Hardware.OculusTouch) { var leftHand = Controller.getPoseValue(Controller.Standard.LeftHand); @@ -23,37 +22,36 @@ var leftWorldControllerPos = Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, leftHand.translation)); var rightWorldControllerPos = Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, rightHand.translation)); var hipPosition = MyAvatar.getJointPosition("Hips"); + var controllerHipThreshold = 0.1; + var controllerRotationThreshold = 0.25; - if ((leftWorldControllerPos.y > (hipPosition.y - 0.1)) && (leftWorldControllerPos.y < (hipPosition.y + 0.1)) && rightWorldControllerPos.y > (hipPosition.y - 0.1) && (rightWorldControllerPos.y < (hipPosition.y + 0.1))) { - if (leftHand.rotation.y < 0.25 && leftHand.rotation.y > -0.25 && rightHand.rotation.y < 0.25 && rightHand.rotation.y > -0.25) { - isRocketting = true; + if ((leftWorldControllerPos.y > (hipPosition.y - controllerHipThreshold)) && (leftWorldControllerPos.y < (hipPosition.y + controllerHipThreshold)) && rightWorldControllerPos.y > (hipPosition.y - controllerHipThreshold) && (rightWorldControllerPos.y < (hipPosition.y + controllerHipThreshold))) { + if (leftHand.rotation.y < controllerRotationThreshold && leftHand.rotation.y > -controllerRotationThreshold && rightHand.rotation.y < controllerRotationThreshold && rightHand.rotation.y > -controllerRotationThreshold) { + isRocketing = true; MyAvatar.motorReferenceFrame = "world"; var moveVector = Vec3.multiply(Quat.getFront(Camera.getOrientation()), 10); - if(!MyAvatar.isFlying()) { + if (!MyAvatar.isFlying()) { moveVector = Vec3.sum(moveVector, {x: 0, y: 1, z: 0}); } MyAvatar.motorVelocity = moveVector; MyAvatar.motorTimescale = 1.0; } else { - if (isRocketting) { - MyAvatar.motorVelocity = 0; - isRocketting = false; - } + checkCanStopRocketing(); } } else { - if (isRocketting) { - MyAvatar.motorVelocity = 0; - isRocketting = false; - } + checkCanStopRocketing(); } } } else { - if(isRocketting) { - MyAvatar.motorVelocity = 0; - isRocketting = false; - } + checkCanStopRocketing(); } }; - Script.update.connect(checkRocketting); + function checkCanStopRocketing() { + if(isRocketing) { + MyAvatar.motorVelocity = 0; + isRocketing = false; + } + } + Script.update.connect(checkRocketing); }()); \ No newline at end of file From 44624c5fab70acde0af6e94c95f2b2bcf5465e58 Mon Sep 17 00:00:00 2001 From: Cain Kilgore Date: Mon, 3 Jul 2017 19:11:57 +0100 Subject: [PATCH 18/24] space --- unpublishedScripts/marketplace/rocketHands/rockethands.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unpublishedScripts/marketplace/rocketHands/rockethands.js b/unpublishedScripts/marketplace/rocketHands/rockethands.js index f8a22be579..e7d60d47a6 100644 --- a/unpublishedScripts/marketplace/rocketHands/rockethands.js +++ b/unpublishedScripts/marketplace/rocketHands/rockethands.js @@ -48,7 +48,7 @@ }; function checkCanStopRocketing() { - if(isRocketing) { + if (isRocketing) { MyAvatar.motorVelocity = 0; isRocketing = false; } From 5f600b4ea96b01efed573ec319f6a225988b5362 Mon Sep 17 00:00:00 2001 From: Cain Kilgore Date: Mon, 3 Jul 2017 19:31:41 +0100 Subject: [PATCH 19/24] Cleanup again --- .../marketplace/rocketHands/rockethands.js | 38 +++++++++++-------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/unpublishedScripts/marketplace/rocketHands/rockethands.js b/unpublishedScripts/marketplace/rocketHands/rockethands.js index e7d60d47a6..da80a84432 100644 --- a/unpublishedScripts/marketplace/rocketHands/rockethands.js +++ b/unpublishedScripts/marketplace/rocketHands/rockethands.js @@ -22,28 +22,34 @@ var leftWorldControllerPos = Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, leftHand.translation)); var rightWorldControllerPos = Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, rightHand.translation)); var hipPosition = MyAvatar.getJointPosition("Hips"); - var controllerHipThreshold = 0.1; - var controllerRotationThreshold = 0.25; + var controllerHipThreshold = 0.1; // In Meters. Experimentally determined. Used to figure out if user's hands are "close enough" to their hips. + var controllerRotationThreshold = 0.25; // In Radians. Experimentally determined. Used to figure out if user's hands are within a rotation threshold. - if ((leftWorldControllerPos.y > (hipPosition.y - controllerHipThreshold)) && (leftWorldControllerPos.y < (hipPosition.y + controllerHipThreshold)) && rightWorldControllerPos.y > (hipPosition.y - controllerHipThreshold) && (rightWorldControllerPos.y < (hipPosition.y + controllerHipThreshold))) { - if (leftHand.rotation.y < controllerRotationThreshold && leftHand.rotation.y > -controllerRotationThreshold && rightHand.rotation.y < controllerRotationThreshold && rightHand.rotation.y > -controllerRotationThreshold) { - isRocketing = true; - MyAvatar.motorReferenceFrame = "world"; - var moveVector = Vec3.multiply(Quat.getFront(Camera.getOrientation()), 10); - if (!MyAvatar.isFlying()) { - moveVector = Vec3.sum(moveVector, {x: 0, y: 1, z: 0}); + if ((leftWorldControllerPos.y > (hipPosition.y - controllerHipThreshold)) && + (leftWorldControllerPos.y < (hipPosition.y + controllerHipThreshold)) && + (rightWorldControllerPos.y > (hipPosition.y - controllerHipThreshold)) && + (rightWorldControllerPos.y < (hipPosition.y + controllerHipThreshold))) { + if ((leftHand.rotation.y < controllerRotationThreshold) && + (leftHand.rotation.y > -controllerRotationThreshold) && + (rightHand.rotation.y < controllerRotationThreshold) && + (rightHand.rotation.y > -controllerRotationThreshold)) { + isRocketing = true; + MyAvatar.motorReferenceFrame = "world"; + var moveVector = Vec3.multiply(Quat.getFront(Camera.getOrientation()), 10); + if (!MyAvatar.isFlying()) { + moveVector = Vec3.sum(moveVector, {x: 0, y: 1, z: 0}); + } + MyAvatar.motorVelocity = moveVector; + MyAvatar.motorTimescale = 1.0; + } else { + checkCanStopRocketing(); } - MyAvatar.motorVelocity = moveVector; - MyAvatar.motorTimescale = 1.0; } else { checkCanStopRocketing(); } - } else { - checkCanStopRocketing(); } - } - } else { - checkCanStopRocketing(); + } else { + checkCanStopRocketing(); } }; From bfcddcf3b7ecaf1b95361ebd44b4831a18f40194 Mon Sep 17 00:00:00 2001 From: Cain Kilgore Date: Mon, 3 Jul 2017 19:53:29 +0100 Subject: [PATCH 20/24] Cleaned up the code, created a function to check if the hands are in the right position. --- .../marketplace/rocketHands/rockethands.js | 62 ++++++++++--------- 1 file changed, 33 insertions(+), 29 deletions(-) diff --git a/unpublishedScripts/marketplace/rocketHands/rockethands.js b/unpublishedScripts/marketplace/rocketHands/rockethands.js index da80a84432..d5dfe48ea0 100644 --- a/unpublishedScripts/marketplace/rocketHands/rockethands.js +++ b/unpublishedScripts/marketplace/rocketHands/rockethands.js @@ -17,39 +17,23 @@ function checkRocketing() { if (HMD.active) { if (Controller.Hardware.Vive || Controller.Hardware.OculusTouch) { - var leftHand = Controller.getPoseValue(Controller.Standard.LeftHand); - var rightHand = Controller.getPoseValue(Controller.Standard.RightHand); - var leftWorldControllerPos = Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, leftHand.translation)); - var rightWorldControllerPos = Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, rightHand.translation)); - var hipPosition = MyAvatar.getJointPosition("Hips"); - var controllerHipThreshold = 0.1; // In Meters. Experimentally determined. Used to figure out if user's hands are "close enough" to their hips. - var controllerRotationThreshold = 0.25; // In Radians. Experimentally determined. Used to figure out if user's hands are within a rotation threshold. - - if ((leftWorldControllerPos.y > (hipPosition.y - controllerHipThreshold)) && - (leftWorldControllerPos.y < (hipPosition.y + controllerHipThreshold)) && - (rightWorldControllerPos.y > (hipPosition.y - controllerHipThreshold)) && - (rightWorldControllerPos.y < (hipPosition.y + controllerHipThreshold))) { - if ((leftHand.rotation.y < controllerRotationThreshold) && - (leftHand.rotation.y > -controllerRotationThreshold) && - (rightHand.rotation.y < controllerRotationThreshold) && - (rightHand.rotation.y > -controllerRotationThreshold)) { - isRocketing = true; - MyAvatar.motorReferenceFrame = "world"; - var moveVector = Vec3.multiply(Quat.getFront(Camera.getOrientation()), 10); - if (!MyAvatar.isFlying()) { - moveVector = Vec3.sum(moveVector, {x: 0, y: 1, z: 0}); - } - MyAvatar.motorVelocity = moveVector; - MyAvatar.motorTimescale = 1.0; - } else { - checkCanStopRocketing(); - } - } else { - checkCanStopRocketing(); + if (canRocket()) { + isRocketing = true; + MyAvatar.motorReferenceFrame = "world"; + var moveVector = Vec3.multiply(Quat.getFront(Camera.getOrientation()), 10); + if (!MyAvatar.isFlying()) { + moveVector = Vec3.sum(moveVector, {x: 0, y: 1, z: 0}); } + MyAvatar.motorVelocity = moveVector; + MyAvatar.motorTimescale = 1.0; + } else { + checkCanStopRocketing(); } } else { checkCanStopRocketing(); + } + } else { + checkCanStopRocketing(); } }; @@ -59,5 +43,25 @@ isRocketing = false; } } + + function canRocket() { + var leftHand = Controller.getPoseValue(Controller.Standard.LeftHand); + var rightHand = Controller.getPoseValue(Controller.Standard.RightHand); + var leftWorldControllerPos = Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, leftHand.translation)); + var rightWorldControllerPos = Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, rightHand.translation)); + var hipPosition = MyAvatar.getJointPosition("Hips"); + var controllerHipThreshold = 0.1; // In Meters. Experimentally determined. Used to figure out if user's hands are "close enough" to their hips. + var controllerRotationThreshold = 0.25; // In Radians. Experimentally determined. Used to figure out if user's hands are within a rotation threshold. + + return ((leftWorldControllerPos.y > (hipPosition.y - controllerHipThreshold)) && + (leftWorldControllerPos.y < (hipPosition.y + controllerHipThreshold)) && + (rightWorldControllerPos.y > (hipPosition.y - controllerHipThreshold)) && + (rightWorldControllerPos.y < (hipPosition.y + controllerHipThreshold)) && + leftHand.rotation.y < controllerRotationThreshold && + leftHand.rotation.y > -controllerRotationThreshold && + rightHand.rotation.y < controllerRotationThreshold && + rightHand.rotation.y > -controllerRotationThreshold); + } + Script.update.connect(checkRocketing); }()); \ No newline at end of file From 1c5923914b4cf5bd99388e8a7a39fb459bd77a2d Mon Sep 17 00:00:00 2001 From: Cain Kilgore Date: Mon, 3 Jul 2017 19:58:26 +0100 Subject: [PATCH 21/24] Combining three if statements into one! --- .../marketplace/rocketHands/rockethands.js | 24 +++++++------------ 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/unpublishedScripts/marketplace/rocketHands/rockethands.js b/unpublishedScripts/marketplace/rocketHands/rockethands.js index d5dfe48ea0..1025dcb0aa 100644 --- a/unpublishedScripts/marketplace/rocketHands/rockethands.js +++ b/unpublishedScripts/marketplace/rocketHands/rockethands.js @@ -15,23 +15,15 @@ var isRocketing = false; function checkRocketing() { - if (HMD.active) { - if (Controller.Hardware.Vive || Controller.Hardware.OculusTouch) { - if (canRocket()) { - isRocketing = true; - MyAvatar.motorReferenceFrame = "world"; - var moveVector = Vec3.multiply(Quat.getFront(Camera.getOrientation()), 10); - if (!MyAvatar.isFlying()) { - moveVector = Vec3.sum(moveVector, {x: 0, y: 1, z: 0}); - } - MyAvatar.motorVelocity = moveVector; - MyAvatar.motorTimescale = 1.0; - } else { - checkCanStopRocketing(); - } - } else { - checkCanStopRocketing(); + if (HMD.active && (Controller.Hardware.Vive || Controller.Hardware.OculusTouch) && canRocket()) { + isRocketing = true; + MyAvatar.motorReferenceFrame = "world"; + var moveVector = Vec3.multiply(Quat.getFront(Camera.getOrientation()), 10); + if (!MyAvatar.isFlying()) { + moveVector = Vec3.sum(moveVector, {x: 0, y: 1, z: 0}); } + MyAvatar.motorVelocity = moveVector; + MyAvatar.motorTimescale = 1.0; } else { checkCanStopRocketing(); } From eddb7a349c18334c56a27f24d90d609ff258cb00 Mon Sep 17 00:00:00 2001 From: Cain Kilgore Date: Mon, 3 Jul 2017 20:01:01 +0100 Subject: [PATCH 22/24] Boilerplate --- unpublishedScripts/marketplace/rocketHands/rockethands.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unpublishedScripts/marketplace/rocketHands/rockethands.js b/unpublishedScripts/marketplace/rocketHands/rockethands.js index 1025dcb0aa..672dcf2540 100644 --- a/unpublishedScripts/marketplace/rocketHands/rockethands.js +++ b/unpublishedScripts/marketplace/rocketHands/rockethands.js @@ -2,7 +2,7 @@ /* rockethands.js - system + unpublishedScripts/marketplace/rocketHands/rockethands.js Created by Cain Kilgore on 30/06/2017 Copyright 2017 High Fidelity, Inc. From 6c86c297cb64d1301e3df3a2e5c75104a3b2b51b Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Mon, 3 Jul 2017 12:40:52 -0700 Subject: [PATCH 23/24] Don't use a blocking connection for a high-frequency function like editOvleray --- interface/src/ui/overlays/Overlays.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/interface/src/ui/overlays/Overlays.cpp b/interface/src/ui/overlays/Overlays.cpp index 0c73f1fa70..48d75bf6e1 100644 --- a/interface/src/ui/overlays/Overlays.cpp +++ b/interface/src/ui/overlays/Overlays.cpp @@ -231,9 +231,12 @@ OverlayID Overlays::cloneOverlay(OverlayID id) { bool Overlays::editOverlay(OverlayID id, const QVariant& properties) { if (QThread::currentThread() != thread()) { - bool result; - BLOCKING_INVOKE_METHOD(this, "editOverlay", Q_RETURN_ARG(bool, result), Q_ARG(OverlayID, id), Q_ARG(QVariant, properties)); - return result; + // NOTE editOverlay can be called very frequently in scripts and can't afford to + // block waiting on the main thread. Additionally, no script actually + // examines the return value and does something useful with it, so use a non-blocking + // invoke and just always return true + QMetaObject::invokeMethod(this, "editOverlay", Q_ARG(OverlayID, id), Q_ARG(QVariant, properties)); + return true; } Overlay::Pointer thisOverlay = getOverlay(id); @@ -246,9 +249,9 @@ bool Overlays::editOverlay(OverlayID id, const QVariant& properties) { bool Overlays::editOverlays(const QVariant& propertiesById) { if (QThread::currentThread() != thread()) { - bool result; - BLOCKING_INVOKE_METHOD(this, "editOverlays", Q_RETURN_ARG(bool, result), Q_ARG(QVariant, propertiesById)); - return result; + // NOTE see comment on editOverlay for why this is not a blocking call + QMetaObject::invokeMethod(this, "editOverlays", Q_ARG(QVariant, propertiesById)); + return true; } QVariantMap map = propertiesById.toMap(); From 97edbb7f374da3f9a41c39afecaaee627b1fb5db Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Mon, 3 Jul 2017 14:43:44 -0700 Subject: [PATCH 24/24] Restore mutex in overlay interface --- interface/src/ui/overlays/Overlays.cpp | 98 +++++++++++++++++++------- interface/src/ui/overlays/Overlays.h | 1 + 2 files changed, 74 insertions(+), 25 deletions(-) diff --git a/interface/src/ui/overlays/Overlays.cpp b/interface/src/ui/overlays/Overlays.cpp index 0c73f1fa70..1495bc2d77 100644 --- a/interface/src/ui/overlays/Overlays.cpp +++ b/interface/src/ui/overlays/Overlays.cpp @@ -40,19 +40,23 @@ Q_LOGGING_CATEGORY(trace_render_overlays, "trace.render.overlays") void Overlays::cleanupAllOverlays() { + QMap overlaysHUD; + QMap overlaysWorld; { - foreach(Overlay::Pointer overlay, _overlaysHUD) { - _overlaysToDelete.push_back(overlay); - } - foreach(Overlay::Pointer overlay, _overlaysWorld) { - _overlaysToDelete.push_back(overlay); - } - _overlaysHUD.clear(); - _overlaysWorld.clear(); -#if OVERLAY_PANELS - _panels.clear(); -#endif + QMutexLocker locker(&_mutex); + overlaysHUD.swap(_overlaysHUD); + overlaysWorld.swap(_overlaysWorld); } + + foreach(Overlay::Pointer overlay, overlaysHUD) { + _overlaysToDelete.push_back(overlay); + } + foreach(Overlay::Pointer overlay, overlaysWorld) { + _overlaysToDelete.push_back(overlay); + } +#if OVERLAY_PANELS + _panels.clear(); +#endif cleanupOverlaysToDelete(); } @@ -63,14 +67,19 @@ void Overlays::init() { } void Overlays::update(float deltatime) { - + QMap overlaysHUD; + QMap overlaysWorld; { - foreach(Overlay::Pointer thisOverlay, _overlaysHUD) { - thisOverlay->update(deltatime); - } - foreach(Overlay::Pointer thisOverlay, _overlaysWorld) { - thisOverlay->update(deltatime); - } + QMutexLocker locker(&_mutex); + overlaysHUD = _overlaysHUD; + overlaysWorld = _overlaysWorld; + } + + foreach(const auto& thisOverlay, overlaysHUD) { + thisOverlay->update(deltatime); + } + foreach(const auto& thisOverlay, overlaysWorld) { + thisOverlay->update(deltatime); } cleanupOverlaysToDelete(); @@ -110,8 +119,14 @@ void Overlays::renderHUD(RenderArgs* renderArgs) { int height = size.y; mat4 legacyProjection = glm::ortho(0, width, height, 0, -1000, 1000); + QMap overlaysHUD; + { + QMutexLocker locker(&_mutex); + overlaysHUD = _overlaysHUD; + } - foreach(Overlay::Pointer thisOverlay, _overlaysHUD) { + + foreach(Overlay::Pointer thisOverlay, overlaysHUD) { // Reset all batch pipeline settings between overlay geometryCache->useSimpleDrawPipeline(batch); @@ -132,7 +147,10 @@ void Overlays::enable() { _enabled = true; } +// Note, can't be invoked by scripts, but can be called by the InterfaceParentFinder +// class on packet processing threads Overlay::Pointer Overlays::getOverlay(OverlayID id) const { + QMutexLocker locker(&_mutex); if (_overlaysHUD.contains(id)) { return _overlaysHUD[id]; } @@ -193,13 +211,17 @@ OverlayID Overlays::addOverlay(const Overlay::Pointer& overlay) { overlay->setOverlayID(thisID); overlay->setStackOrder(_stackOrder++); if (overlay->is3D()) { - _overlaysWorld[thisID] = overlay; + { + QMutexLocker locker(&_mutex); + _overlaysWorld[thisID] = overlay; + } render::ScenePointer scene = qApp->getMain3DScene(); render::Transaction transaction; overlay->addToScene(overlay, scene, transaction); scene->enqueueTransaction(transaction); } else { + QMutexLocker locker(&_mutex); _overlaysHUD[thisID] = overlay; } @@ -275,6 +297,7 @@ void Overlays::deleteOverlay(OverlayID id) { Overlay::Pointer overlayToDelete; { + QMutexLocker locker(&_mutex); if (_overlaysHUD.contains(id)) { overlayToDelete = _overlaysHUD.take(id); } else if (_overlaysWorld.contains(id)) { @@ -378,7 +401,13 @@ OverlayID Overlays::getOverlayAtPoint(const glm::vec2& point) { if (!_enabled) { return UNKNOWN_OVERLAY_ID; } - QMapIterator i(_overlaysHUD); + + QMap overlaysHUD; + { + QMutexLocker locker(&_mutex); + overlaysHUD = _overlaysHUD; + } + QMapIterator i(overlaysHUD); const float LARGE_NEGATIVE_FLOAT = -9999999; glm::vec3 origin(pointCopy.x, pointCopy.y, LARGE_NEGATIVE_FLOAT); @@ -466,8 +495,14 @@ RayToOverlayIntersectionResult Overlays::findRayIntersectionInternal(const PickR float bestDistance = std::numeric_limits::max(); bool bestIsFront = false; + QMap overlaysWorld; + { + QMutexLocker locker(&_mutex); + overlaysWorld = _overlaysWorld; + } + RayToOverlayIntersectionResult result; - QMapIterator i(_overlaysWorld); + QMapIterator i(overlaysWorld); while (i.hasNext()) { i.next(); OverlayID thisID = i.key(); @@ -598,13 +633,20 @@ QSizeF Overlays::textSize(OverlayID id, const QString& text) { return result; } - Overlay::Pointer thisOverlay = _overlaysHUD[id]; + Overlay::Pointer thisOverlay; + { + QMutexLocker locker(&_mutex); + thisOverlay = _overlaysHUD[id]; + } if (thisOverlay) { if (auto textOverlay = std::dynamic_pointer_cast(thisOverlay)) { return textOverlay->textSize(text); } } else { - thisOverlay = _overlaysWorld[id]; + { + QMutexLocker locker(&_mutex); + thisOverlay = _overlaysWorld[id]; + } if (auto text3dOverlay = std::dynamic_pointer_cast(thisOverlay)) { return text3dOverlay->textSize(text); } @@ -675,6 +717,7 @@ bool Overlays::isAddedOverlay(OverlayID id) { return result; } + QMutexLocker locker(&_mutex); return _overlaysHUD.contains(id) || _overlaysWorld.contains(id); } @@ -949,8 +992,13 @@ QVector Overlays::findOverlays(const glm::vec3& center, float radius) { return result; } + QMap overlaysWorld; + { + QMutexLocker locker(&_mutex); + overlaysWorld = _overlaysWorld; + } - QMapIterator i(_overlaysWorld); + QMapIterator i(overlaysWorld); int checked = 0; while (i.hasNext()) { checked++; diff --git a/interface/src/ui/overlays/Overlays.h b/interface/src/ui/overlays/Overlays.h index d3fa70225e..bfb775b041 100644 --- a/interface/src/ui/overlays/Overlays.h +++ b/interface/src/ui/overlays/Overlays.h @@ -319,6 +319,7 @@ signals: private: void cleanupOverlaysToDelete(); + mutable QMutex _mutex; QMap _overlaysHUD; QMap _overlaysWorld; #if OVERLAY_PANELS