From ee2936d13345fe22a357bbd826c0cdc378cc0dbe Mon Sep 17 00:00:00 2001 From: David Rowe Date: Thu, 18 Jan 2018 14:07:07 +1300 Subject: [PATCH 1/8] Add Pointers API function that disables hover events for nominated items --- interface/src/raypick/PointerScriptingInterface.cpp | 4 ++++ interface/src/raypick/PointerScriptingInterface.h | 8 ++++++++ libraries/pointers/src/Pointer.cpp | 11 +++++++++++ libraries/pointers/src/Pointer.h | 3 +++ libraries/pointers/src/PointerManager.cpp | 7 +++++++ libraries/pointers/src/PointerManager.h | 1 + 6 files changed, 34 insertions(+) diff --git a/interface/src/raypick/PointerScriptingInterface.cpp b/interface/src/raypick/PointerScriptingInterface.cpp index ac5a467e76..8e50b1d629 100644 --- a/interface/src/raypick/PointerScriptingInterface.cpp +++ b/interface/src/raypick/PointerScriptingInterface.cpp @@ -24,6 +24,10 @@ void PointerScriptingInterface::setIncludeItems(unsigned int uid, const QScriptV DependencyManager::get()->setIncludeItems(uid, qVectorQUuidFromScriptValue(includeItems)); } +void PointerScriptingInterface::setNonHoverItems(unsigned int uid, const QScriptValue& nonHoverItems) const { + DependencyManager::get()->setNonHoverItems(uid, qVectorQUuidFromScriptValue(nonHoverItems)); +} + unsigned int PointerScriptingInterface::createPointer(const PickQuery::PickType& type, const QVariant& properties) { // Interaction with managers should always happen on the main thread if (QThread::currentThread() != qApp->thread()) { diff --git a/interface/src/raypick/PointerScriptingInterface.h b/interface/src/raypick/PointerScriptingInterface.h index 1cc7b56503..4791fd802e 100644 --- a/interface/src/raypick/PointerScriptingInterface.h +++ b/interface/src/raypick/PointerScriptingInterface.h @@ -191,6 +191,14 @@ public: */ Q_INVOKABLE void setIncludeItems(unsigned int uid, const QScriptValue& includeEntities) const; + /**jsdoc + * Sets a list of Entity IDs, Overlay IDs, and/or Avatar IDs that the pointer should not send hover events to. + * @function Pointers.setNonHoverItems + * @param {number} uid - The ID of the Pointer, as returned by {@link Pointers.createPointer}. + * @param {Uuid[]} nonHoverItems - A list of IDs to that hover events should not be sent to. + */ + Q_INVOKABLE void setNonHoverItems(unsigned int uid, const QScriptValue& nonHoverItems) const; + /**jsdoc * Lock a Pointer onto a specific object (overlay, entity, or avatar). Optionally, provide an offset in object-space, otherwise the Pointer will lock on to the center of the object. * Not used by Stylus Pointers. diff --git a/libraries/pointers/src/Pointer.cpp b/libraries/pointers/src/Pointer.cpp index 5307e17355..ead3c22687 100644 --- a/libraries/pointers/src/Pointer.cpp +++ b/libraries/pointers/src/Pointer.cpp @@ -52,6 +52,12 @@ void Pointer::setIncludeItems(const QVector& includeItems) const { DependencyManager::get()->setIncludeItems(_pickUID, includeItems); } +void Pointer::setNonHoverItems(const QVector& nonHoverItems) { + withWriteLock([&] { + _nonHoverItems = nonHoverItems; + }); +} + bool Pointer::isLeftHand() const { return DependencyManager::get()->isLeftHand(_pickUID); } @@ -96,6 +102,11 @@ void Pointer::generatePointerEvents(unsigned int pointerID, const PickResultPoin // Hover events bool doHover = shouldHover(pickResult); + + auto pickResultMap = pickResult->toVariantMap(); + auto uuid = QUuid(pickResultMap.value("objectID", "").toString()); + doHover = doHover && !_nonHoverItems.contains(uuid); + Pointer::PickedObject hoveredObject = getHoveredObject(pickResult); PointerEvent hoveredEvent = buildPointerEvent(hoveredObject, pickResult); hoveredEvent.setType(PointerEvent::Move); diff --git a/libraries/pointers/src/Pointer.h b/libraries/pointers/src/Pointer.h index 3197c80cad..6cb366e92a 100644 --- a/libraries/pointers/src/Pointer.h +++ b/libraries/pointers/src/Pointer.h @@ -54,6 +54,8 @@ public: virtual void setIgnoreItems(const QVector& ignoreItems) const; virtual void setIncludeItems(const QVector& includeItems) const; + void setNonHoverItems(const QVector& nonHoverItems); + bool isLeftHand() const; bool isRightHand() const; bool isMouse() const; @@ -102,6 +104,7 @@ private: PointerEvent::Button chooseButton(const std::string& button); + QVector _nonHoverItems; }; #endif // hifi_Pick_h diff --git a/libraries/pointers/src/PointerManager.cpp b/libraries/pointers/src/PointerManager.cpp index be890da392..f2953ce8c8 100644 --- a/libraries/pointers/src/PointerManager.cpp +++ b/libraries/pointers/src/PointerManager.cpp @@ -108,6 +108,13 @@ void PointerManager::setIncludeItems(unsigned int uid, const QVector& inc } } +void PointerManager::setNonHoverItems(unsigned int uid, const QVector& nonHoverItems) const { + auto pointer = find(uid); + if (pointer) { + pointer->setNonHoverItems(nonHoverItems); + } +} + void PointerManager::setLength(unsigned int uid, float length) const { auto pointer = find(uid); if (pointer) { diff --git a/libraries/pointers/src/PointerManager.h b/libraries/pointers/src/PointerManager.h index b98558622f..a2a1e9dcd2 100644 --- a/libraries/pointers/src/PointerManager.h +++ b/libraries/pointers/src/PointerManager.h @@ -34,6 +34,7 @@ public: void setPrecisionPicking(unsigned int uid, bool precisionPicking) const; void setIgnoreItems(unsigned int uid, const QVector& ignoreEntities) const; void setIncludeItems(unsigned int uid, const QVector& includeEntities) const; + void setNonHoverItems(unsigned int uid, const QVector& nonHoverItems) const; void setLength(unsigned int uid, float length) const; void setLockEndUUID(unsigned int uid, const QUuid& objectID, bool isOverlay, const glm::mat4& offsetMat = glm::mat4()) const; From 5878e36ea8fc38c2c1e904e9398af9efa467c3da Mon Sep 17 00:00:00 2001 From: David Rowe Date: Thu, 18 Jan 2018 14:24:23 +1300 Subject: [PATCH 2/8] Display both lasers --- .../controllerModules/webSurfaceLaserInput.js | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js b/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js index 3d9d7979d5..19b5330492 100644 --- a/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js +++ b/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js @@ -87,20 +87,11 @@ Script.include("/~/system/libraries/controllers.js"); return MyAvatar.getDominantHand() === "right" ? 1 : 0; }; - this.dominantHandOverride = false; - this.isReady = function(controllerData) { - var otherModuleRunning = this.getOtherModule().running; - otherModuleRunning = otherModuleRunning && this.getDominantHand() !== this.hand; // Auto-swap to dominant hand. var isTriggerPressed = controllerData.triggerValues[this.hand] > TRIGGER_OFF_VALUE && controllerData.triggerValues[this.otherHand] <= TRIGGER_OFF_VALUE; - if ((!otherModuleRunning || isTriggerPressed) - && (this.isPointingAtOverlay(controllerData) || this.isPointingAtWebEntity(controllerData))) { + if (this.isPointingAtOverlay(controllerData) || this.isPointingAtWebEntity(controllerData)) { this.updateAllwaysOn(); - if (isTriggerPressed) { - this.dominantHandOverride = true; // Override dominant hand. - this.getOtherModule().dominantHandOverride = false; - } if (this.parameters.handLaser.allwaysOn || isTriggerPressed) { return makeRunningValues(true, [], []); } @@ -109,11 +100,8 @@ Script.include("/~/system/libraries/controllers.js"); }; this.run = function(controllerData, deltaTime) { - var otherModuleRunning = this.getOtherModule().running; - otherModuleRunning = otherModuleRunning && this.getDominantHand() !== this.hand; // Auto-swap to dominant hand. - otherModuleRunning = otherModuleRunning || this.getOtherModule().dominantHandOverride; // Override dominant hand. var grabModuleNeedsToRun = this.grabModuleWantsNearbyOverlay(controllerData); - if (!otherModuleRunning && !grabModuleNeedsToRun && (controllerData.triggerValues[this.hand] > TRIGGER_OFF_VALUE + if (!grabModuleNeedsToRun && (controllerData.triggerValues[this.hand] > TRIGGER_OFF_VALUE || this.parameters.handLaser.allwaysOn && (this.isPointingAtOverlay(controllerData) || this.isPointingAtWebEntity(controllerData)))) { this.running = true; @@ -121,7 +109,6 @@ Script.include("/~/system/libraries/controllers.js"); } this.deleteContextOverlay(); this.running = false; - this.dominantHandOverride = false; return makeRunningValues(false, [], []); }; } From 403dd3d7d029a73c63e5e1c4f101d40efeff06ce Mon Sep 17 00:00:00 2001 From: David Rowe Date: Thu, 18 Jan 2018 22:31:12 +1300 Subject: [PATCH 3/8] Only first laser highlights --- .../controllers/controllerDispatcher.js | 64 +++++++++++++++++++ .../controllerModules/webSurfaceLaserInput.js | 45 ++++++++++++- 2 files changed, 107 insertions(+), 2 deletions(-) diff --git a/scripts/system/controllers/controllerDispatcher.js b/scripts/system/controllers/controllerDispatcher.js index 16f1d086b7..15b025a7ea 100644 --- a/scripts/system/controllers/controllerDispatcher.js +++ b/scripts/system/controllers/controllerDispatcher.js @@ -44,7 +44,12 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js"); this.highVarianceCount = 0; this.veryhighVarianceCount = 0; this.tabletID = null; + this.TABLET_UI_UUIDS = []; this.blacklist = []; + this.leftPointerNonHoverItem = null; + this.leftPointerNonHoverItemChanged = false; + this.rightPointerNonHoverItem = null; + this.rightPointerNonHoverItemChanged = false; this.pointerManager = new PointerManager(); // a module can occupy one or more "activity" slots while it's running. If all the required slots for a module are @@ -122,6 +127,10 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js"); return getControllerWorldLocation(Controller.Standard.RightHand, true); }; + this.isTabletID = function (uuid) { + return _this.TABLET_UI_UUIDS.indexOf(uuid) !== -1; + }; + this.updateTimings = function () { _this.intervalCount++; var thisInterval = Date.now(); @@ -148,11 +157,35 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js"); this.setIgnorePointerItems = function() { if (HMD.tabletID !== this.tabletID) { this.tabletID = HMD.tabletID; + this.TABLET_UI_UUIDS = [HMD.tabletID, HMD.tabletScreenID, HMD.homeButtonID, HMD.homeButtonHighlightID]; Pointers.setIgnoreItems(_this.leftPointer, _this.blacklist); Pointers.setIgnoreItems(_this.rightPointer, _this.blacklist); } }; + this.setNonHoverItems = function () { + if (_this.leftPointerNonHoverItemChanged) { + if (_this.leftPointerNonHoverItem === null) { + Pointers.setNonHoverItems(_this.leftPointer, []); + } else if (_this.isTabletID(_this.leftPointerNonHoverItem)) { + Pointers.setNonHoverItems(_this.leftPointer, _this.TABLET_UI_UUIDS); + } else { + Pointers.setNonHoverItems(_this.leftPointer, [_this.leftPointerNonHoverItem]); + } + _this.leftPointerNonHoverItemChanged = false; + } + if (_this.rightPointerNonHoverItemChanged) { + if (_this.rightPointerNonHoverItem === null) { + Pointers.setNonHoverItems(_this.rightPointer, []); + } else if (_this.isTabletID(_this.rightPointerNonHoverItem)) { + Pointers.setNonHoverItems(_this.rightPointer, _this.TABLET_UI_UUIDS); + } else { + Pointers.setNonHoverItems(_this.rightPointer, [_this.rightPointerNonHoverItem]); + } + _this.rightPointerNonHoverItemChanged = false; + } + }; + this.update = function () { try { _this.updateInternal(); @@ -324,6 +357,19 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js"); _this.runningPluginNames[orderedPluginName] = true; _this.markSlots(candidatePlugin, orderedPluginName); _this.pointerManager.makePointerVisible(candidatePlugin.parameters.handLaser); + + if (candidatePlugin.parameters.handLaser.nonHoverItem !== undefined) { + if (candidatePlugin.parameters.handLaser.hand === LEFT_HAND + && _this.leftPointerNonHoverItem !== candidatePlugin.parameters.handLaser.nonHoverItem) { + _this.leftPointerNonHoverItem = candidatePlugin.parameters.handLaser.nonHoverItem; + _this.leftPointerNonHoverItemChanged = true; + } else if (candidatePlugin.parameters.handLaser.hand === RIGHT_HAND + && _this.rightPointerNonHoverItem !== candidatePlugin.parameters.handLaser.nonHoverItem) { + _this.rightPointerNonHoverItem = candidatePlugin.parameters.handLaser.nonHoverItem; + _this.rightPointerNonHoverItemChanged = true; + } + } + if (DEBUG) { print("controllerDispatcher running " + orderedPluginName); } @@ -354,6 +400,21 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js"); Script.beginProfileRange("dispatch.run." + runningPluginName); } var runningness = plugin.run(controllerData, deltaTime); + + if (runningness.active) { + if (plugin.parameters.handLaser.nonHoverItem !== undefined) { + if (plugin.parameters.handLaser.hand === LEFT_HAND + && _this.leftPointerNonHoverItem !== plugin.parameters.handLaser.nonHoverItem) { + _this.leftPointerNonHoverItem = plugin.parameters.handLaser.nonHoverItem; + _this.leftPointerNonHoverItemChanged = true; + } else if (plugin.parameters.handLaser.hand === RIGHT_HAND + && _this.rightPointerNonHoverItem !== plugin.parameters.handLaser.nonHoverItem) { + _this.rightPointerNonHoverItem = plugin.parameters.handLaser.nonHoverItem; + _this.rightPointerNonHoverItemChanged = true; + } + } + } + if (!runningness.active) { // plugin is finished running, for now. remove it from the list // of running plugins and mark its activity-slots as "not in use" @@ -372,6 +433,9 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js"); } } _this.pointerManager.updatePointersRenderState(controllerData.triggerClicks, controllerData.triggerValues); + + _this.setNonHoverItems(); + if (PROFILE) { Script.endProfileRange("dispatch.run"); } diff --git a/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js b/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js index 19b5330492..5b9afa3a2a 100644 --- a/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js +++ b/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js @@ -87,28 +87,69 @@ Script.include("/~/system/libraries/controllers.js"); return MyAvatar.getDominantHand() === "right" ? 1 : 0; }; + this.hoverItem = null; + + this.isTabletID = function (uuid) { + return [HMD.tabletID, HMD.tabletScreenID, HMD.homeButtonID, HMD.homeButtonHightlightID].indexOf(uuid) !== -1; + }; + this.isReady = function(controllerData) { var isTriggerPressed = controllerData.triggerValues[this.hand] > TRIGGER_OFF_VALUE && controllerData.triggerValues[this.otherHand] <= TRIGGER_OFF_VALUE; if (this.isPointingAtOverlay(controllerData) || this.isPointingAtWebEntity(controllerData)) { this.updateAllwaysOn(); if (this.parameters.handLaser.allwaysOn || isTriggerPressed) { + var pointingAt = controllerData.rayPicks[this.hand].objectID; + if (this.isTabletID(pointingAt)) { + pointingAt = HMD.tabletID; + } + + if (pointingAt !== this.getOtherModule().hoverItem) { + this.hoverItem = pointingAt; + this.getOtherModule().parameters.handLaser.nonHoverItem = pointingAt; + } else { + this.hoverItem = null; + this.getOtherModule().parameters.handLaser.nonHoverItem = null; + } + return makeRunningValues(true, [], []); } } + + this.hoverItem = null; + this.getOtherModule().parameters.handLaser.nonHoverItem = null; + return makeRunningValues(false, [], []); }; this.run = function(controllerData, deltaTime) { var grabModuleNeedsToRun = this.grabModuleWantsNearbyOverlay(controllerData); - if (!grabModuleNeedsToRun && (controllerData.triggerValues[this.hand] > TRIGGER_OFF_VALUE - || this.parameters.handLaser.allwaysOn + var isTriggerPressed = controllerData.triggerValues[this.hand] > TRIGGER_OFF_VALUE; + if (!grabModuleNeedsToRun && (isTriggerPressed || this.parameters.handLaser.allwaysOn && (this.isPointingAtOverlay(controllerData) || this.isPointingAtWebEntity(controllerData)))) { this.running = true; + + var pointingAt = controllerData.rayPicks[this.hand].objectID; + if (this.isTabletID(pointingAt)) { + pointingAt = HMD.tabletID; + } + + if (pointingAt !== this.getOtherModule().hoverItem || isTriggerPressed) { + this.hoverItem = pointingAt; + this.getOtherModule().parameters.handLaser.nonHoverItem = pointingAt; + } else { + this.hoverItem = null; + this.getOtherModule().parameters.handLaser.nonHoverItem = null; + } + return makeRunningValues(true, [], []); } this.deleteContextOverlay(); this.running = false; + + this.hoverItem = null; + this.getOtherModule().parameters.handLaser.nonHoverItem = null; + return makeRunningValues(false, [], []); }; } From e0e6fc711bba14648fd54711cb5e408cf5a67816 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Fri, 19 Jan 2018 16:05:09 +1300 Subject: [PATCH 4/8] Replace Pointers API function setNonHoverItems() with setDoesHover() --- .../src/raypick/PointerScriptingInterface.cpp | 10 +-- .../src/raypick/PointerScriptingInterface.h | 16 ++-- libraries/pointers/src/Pointer.cpp | 21 +++-- libraries/pointers/src/Pointer.h | 7 +- libraries/pointers/src/PointerManager.cpp | 14 ++-- libraries/pointers/src/PointerManager.h | 2 +- .../controllers/controllerDispatcher.js | 76 +++++++++---------- .../controllerModules/webSurfaceLaserInput.js | 14 ++-- 8 files changed, 77 insertions(+), 83 deletions(-) diff --git a/interface/src/raypick/PointerScriptingInterface.cpp b/interface/src/raypick/PointerScriptingInterface.cpp index 8e50b1d629..a334834979 100644 --- a/interface/src/raypick/PointerScriptingInterface.cpp +++ b/interface/src/raypick/PointerScriptingInterface.cpp @@ -24,10 +24,6 @@ void PointerScriptingInterface::setIncludeItems(unsigned int uid, const QScriptV DependencyManager::get()->setIncludeItems(uid, qVectorQUuidFromScriptValue(includeItems)); } -void PointerScriptingInterface::setNonHoverItems(unsigned int uid, const QScriptValue& nonHoverItems) const { - DependencyManager::get()->setNonHoverItems(uid, qVectorQUuidFromScriptValue(nonHoverItems)); -} - unsigned int PointerScriptingInterface::createPointer(const PickQuery::PickType& type, const QVariant& properties) { // Interaction with managers should always happen on the main thread if (QThread::currentThread() != qApp->thread()) { @@ -179,4 +175,8 @@ QVariantMap PointerScriptingInterface::getPrevPickResult(unsigned int uid) const result = pickResult->toVariantMap(); } return result; -} \ No newline at end of file +} + +void PointerScriptingInterface::setDoesHover(unsigned int uid, bool hover) const { + DependencyManager::get()->setDoesHover(uid, hover); +} diff --git a/interface/src/raypick/PointerScriptingInterface.h b/interface/src/raypick/PointerScriptingInterface.h index 4791fd802e..451c132769 100644 --- a/interface/src/raypick/PointerScriptingInterface.h +++ b/interface/src/raypick/PointerScriptingInterface.h @@ -191,14 +191,6 @@ public: */ Q_INVOKABLE void setIncludeItems(unsigned int uid, const QScriptValue& includeEntities) const; - /**jsdoc - * Sets a list of Entity IDs, Overlay IDs, and/or Avatar IDs that the pointer should not send hover events to. - * @function Pointers.setNonHoverItems - * @param {number} uid - The ID of the Pointer, as returned by {@link Pointers.createPointer}. - * @param {Uuid[]} nonHoverItems - A list of IDs to that hover events should not be sent to. - */ - Q_INVOKABLE void setNonHoverItems(unsigned int uid, const QScriptValue& nonHoverItems) const; - /**jsdoc * Lock a Pointer onto a specific object (overlay, entity, or avatar). Optionally, provide an offset in object-space, otherwise the Pointer will lock on to the center of the object. * Not used by Stylus Pointers. @@ -210,6 +202,14 @@ public: */ Q_INVOKABLE void setLockEndUUID(unsigned int uid, const QUuid& objectID, bool isOverlay, const glm::mat4& offsetMat = glm::mat4()) const { DependencyManager::get()->setLockEndUUID(uid, objectID, isOverlay, offsetMat); } + /**jsdoc + * Sets whether or not a pointer should generate hover events. + * @function Pointers.setDoesHover + * @param {boolean} uid - The ID of the Pointer, as returned by {@link Pointers.createPointer}. + * @param {boolean} hover - If true then the pointer generates hover events, otherwise it does not. + */ + Q_INVOKABLE void setDoesHover(unsigned int uid, bool hove) const; + /**jsdoc * Check if a Pointer is associated with the left hand. * @function Pointers.isLeftHand diff --git a/libraries/pointers/src/Pointer.cpp b/libraries/pointers/src/Pointer.cpp index ead3c22687..0e542c47da 100644 --- a/libraries/pointers/src/Pointer.cpp +++ b/libraries/pointers/src/Pointer.cpp @@ -52,12 +52,6 @@ void Pointer::setIncludeItems(const QVector& includeItems) const { DependencyManager::get()->setIncludeItems(_pickUID, includeItems); } -void Pointer::setNonHoverItems(const QVector& nonHoverItems) { - withWriteLock([&] { - _nonHoverItems = nonHoverItems; - }); -} - bool Pointer::isLeftHand() const { return DependencyManager::get()->isLeftHand(_pickUID); } @@ -70,6 +64,12 @@ bool Pointer::isMouse() const { return DependencyManager::get()->isMouse(_pickUID); } +void Pointer::setDoesHover(bool doesHover) { + withWriteLock([&] { + _hover = doesHover; + }); +} + void Pointer::update(unsigned int pointerID) { // This only needs to be a read lock because update won't change any of the properties that can be modified from scripts withReadLock([&] { @@ -101,11 +101,7 @@ void Pointer::generatePointerEvents(unsigned int pointerID, const PickResultPoin } // Hover events - bool doHover = shouldHover(pickResult); - - auto pickResultMap = pickResult->toVariantMap(); - auto uuid = QUuid(pickResultMap.value("objectID", "").toString()); - doHover = doHover && !_nonHoverItems.contains(uuid); + bool doHover = _hover && shouldHover(pickResult); Pointer::PickedObject hoveredObject = getHoveredObject(pickResult); PointerEvent hoveredEvent = buildPointerEvent(hoveredObject, pickResult); @@ -240,7 +236,7 @@ void Pointer::generatePointerEvents(unsigned int pointerID, const PickResultPoin } // if we disable the pointer or disable hovering, send hoverEnd events after triggerEnd - if (_hover && ((!_enabled && _prevEnabled) || (!doHover && _prevDoHover))) { + if ((_hover || _prevHover) && ((!_enabled && _prevEnabled) || (!doHover && _prevDoHover))) { if (_prevHoveredObject.type == ENTITY) { emit pointerManager->hoverEndEntity(_prevHoveredObject.objectID, hoveredEvent); } else if (_prevHoveredObject.type == OVERLAY) { @@ -253,6 +249,7 @@ void Pointer::generatePointerEvents(unsigned int pointerID, const PickResultPoin _prevHoveredObject = hoveredObject; _prevButtons = buttons; _prevEnabled = _enabled; + _prevHover = _hover; _prevDoHover = doHover; } diff --git a/libraries/pointers/src/Pointer.h b/libraries/pointers/src/Pointer.h index 6cb366e92a..ef0048cf1e 100644 --- a/libraries/pointers/src/Pointer.h +++ b/libraries/pointers/src/Pointer.h @@ -54,8 +54,6 @@ public: virtual void setIgnoreItems(const QVector& ignoreItems) const; virtual void setIncludeItems(const QVector& includeItems) const; - void setNonHoverItems(const QVector& nonHoverItems); - bool isLeftHand() const; bool isRightHand() const; bool isMouse() const; @@ -64,6 +62,8 @@ public: virtual void setLength(float length) {} virtual void setLockEndUUID(const QUuid& objectID, bool isOverlay, const glm::mat4& offsetMat = glm::mat4()) {} + void setDoesHover(bool hover); + void update(unsigned int pointerID); virtual void updateVisuals(const PickResultPointer& pickResult) = 0; void generatePointerEvents(unsigned int pointerID, const PickResultPointer& pickResult); @@ -99,12 +99,11 @@ private: PickedObject _prevHoveredObject; Buttons _prevButtons; bool _prevEnabled { false }; + bool _prevHover { false }; bool _prevDoHover { false }; std::unordered_map _triggeredObjects; PointerEvent::Button chooseButton(const std::string& button); - - QVector _nonHoverItems; }; #endif // hifi_Pick_h diff --git a/libraries/pointers/src/PointerManager.cpp b/libraries/pointers/src/PointerManager.cpp index f2953ce8c8..13b38457b6 100644 --- a/libraries/pointers/src/PointerManager.cpp +++ b/libraries/pointers/src/PointerManager.cpp @@ -108,13 +108,6 @@ void PointerManager::setIncludeItems(unsigned int uid, const QVector& inc } } -void PointerManager::setNonHoverItems(unsigned int uid, const QVector& nonHoverItems) const { - auto pointer = find(uid); - if (pointer) { - pointer->setNonHoverItems(nonHoverItems); - } -} - void PointerManager::setLength(unsigned int uid, float length) const { auto pointer = find(uid); if (pointer) { @@ -129,6 +122,13 @@ void PointerManager::setLockEndUUID(unsigned int uid, const QUuid& objectID, boo } } +void PointerManager::setDoesHover(unsigned int uid, bool hover) const { + auto pointer = find(uid); + if (pointer) { + pointer->setDoesHover(hover); + } +} + bool PointerManager::isLeftHand(unsigned int uid) { auto pointer = find(uid); if (pointer) { diff --git a/libraries/pointers/src/PointerManager.h b/libraries/pointers/src/PointerManager.h index a2a1e9dcd2..2c9a37e129 100644 --- a/libraries/pointers/src/PointerManager.h +++ b/libraries/pointers/src/PointerManager.h @@ -34,10 +34,10 @@ public: void setPrecisionPicking(unsigned int uid, bool precisionPicking) const; void setIgnoreItems(unsigned int uid, const QVector& ignoreEntities) const; void setIncludeItems(unsigned int uid, const QVector& includeEntities) const; - void setNonHoverItems(unsigned int uid, const QVector& nonHoverItems) const; void setLength(unsigned int uid, float length) const; void setLockEndUUID(unsigned int uid, const QUuid& objectID, bool isOverlay, const glm::mat4& offsetMat = glm::mat4()) const; + void setDoesHover(unsigned int uid, bool hover) const; void update(); diff --git a/scripts/system/controllers/controllerDispatcher.js b/scripts/system/controllers/controllerDispatcher.js index 15b025a7ea..fe18ed25f8 100644 --- a/scripts/system/controllers/controllerDispatcher.js +++ b/scripts/system/controllers/controllerDispatcher.js @@ -46,10 +46,10 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js"); this.tabletID = null; this.TABLET_UI_UUIDS = []; this.blacklist = []; - this.leftPointerNonHoverItem = null; - this.leftPointerNonHoverItemChanged = false; - this.rightPointerNonHoverItem = null; - this.rightPointerNonHoverItemChanged = false; + this.leftPointerDoesHover = true; + this.leftPointerDoesHoverChanged = false; + this.rightPointerDoesHover = true; + this.rightPointerDoesHoverChanged = false; this.pointerManager = new PointerManager(); // a module can occupy one or more "activity" slots while it's running. If all the required slots for a module are @@ -163,26 +163,14 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js"); } }; - this.setNonHoverItems = function () { - if (_this.leftPointerNonHoverItemChanged) { - if (_this.leftPointerNonHoverItem === null) { - Pointers.setNonHoverItems(_this.leftPointer, []); - } else if (_this.isTabletID(_this.leftPointerNonHoverItem)) { - Pointers.setNonHoverItems(_this.leftPointer, _this.TABLET_UI_UUIDS); - } else { - Pointers.setNonHoverItems(_this.leftPointer, [_this.leftPointerNonHoverItem]); - } - _this.leftPointerNonHoverItemChanged = false; + this.updateHovering = function () { + if (_this.leftPointerDoesHoverChanged) { + Pointers.setDoesHover(_this.leftPointer, _this.leftPointerDoesHover); + _this.leftPointerDoesHoverChanged = false; } - if (_this.rightPointerNonHoverItemChanged) { - if (_this.rightPointerNonHoverItem === null) { - Pointers.setNonHoverItems(_this.rightPointer, []); - } else if (_this.isTabletID(_this.rightPointerNonHoverItem)) { - Pointers.setNonHoverItems(_this.rightPointer, _this.TABLET_UI_UUIDS); - } else { - Pointers.setNonHoverItems(_this.rightPointer, [_this.rightPointerNonHoverItem]); - } - _this.rightPointerNonHoverItemChanged = false; + if (_this.rightPointerDoesHoverChanged) { + Pointers.setDoesHover(_this.rightPointer, _this.rightPointerDoesHover); + _this.rightPointerDoesHoverChanged = false; } }; @@ -358,15 +346,15 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js"); _this.markSlots(candidatePlugin, orderedPluginName); _this.pointerManager.makePointerVisible(candidatePlugin.parameters.handLaser); - if (candidatePlugin.parameters.handLaser.nonHoverItem !== undefined) { + if (candidatePlugin.parameters.handLaser.doesHover !== undefined) { if (candidatePlugin.parameters.handLaser.hand === LEFT_HAND - && _this.leftPointerNonHoverItem !== candidatePlugin.parameters.handLaser.nonHoverItem) { - _this.leftPointerNonHoverItem = candidatePlugin.parameters.handLaser.nonHoverItem; - _this.leftPointerNonHoverItemChanged = true; + && _this.leftPointerDoesHover !== candidatePlugin.parameters.handLaser.doesHover) { + _this.leftPointerDoesHover = candidatePlugin.parameters.handLaser.doesHover; + _this.leftPointerDoesHoverChanged = true; } else if (candidatePlugin.parameters.handLaser.hand === RIGHT_HAND - && _this.rightPointerNonHoverItem !== candidatePlugin.parameters.handLaser.nonHoverItem) { - _this.rightPointerNonHoverItem = candidatePlugin.parameters.handLaser.nonHoverItem; - _this.rightPointerNonHoverItemChanged = true; + && _this.rightPointerDoesHover !== candidatePlugin.parameters.handLaser.doesHover) { + _this.rightPointerDoesHover = candidatePlugin.parameters.handLaser.doesHover; + _this.rightPointerDoesHoverChanged = true; } } @@ -402,15 +390,15 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js"); var runningness = plugin.run(controllerData, deltaTime); if (runningness.active) { - if (plugin.parameters.handLaser.nonHoverItem !== undefined) { + if (plugin.parameters.handLaser.doesHover !== undefined) { if (plugin.parameters.handLaser.hand === LEFT_HAND - && _this.leftPointerNonHoverItem !== plugin.parameters.handLaser.nonHoverItem) { - _this.leftPointerNonHoverItem = plugin.parameters.handLaser.nonHoverItem; - _this.leftPointerNonHoverItemChanged = true; + && _this.leftPointerDoesHover !== plugin.parameters.handLaser.doesHover) { + _this.leftPointerDoesHover = plugin.parameters.handLaser.doesHover; + _this.leftPointerDoesHoverChanged = true; } else if (plugin.parameters.handLaser.hand === RIGHT_HAND - && _this.rightPointerNonHoverItem !== plugin.parameters.handLaser.nonHoverItem) { - _this.rightPointerNonHoverItem = plugin.parameters.handLaser.nonHoverItem; - _this.rightPointerNonHoverItemChanged = true; + && _this.rightPointerDoesHover !== plugin.parameters.handLaser.doesHover) { + _this.rightPointerDoesHover = plugin.parameters.handLaser.doesHover; + _this.rightPointerDoesHoverChanged = true; } } } @@ -421,6 +409,17 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js"); delete _this.runningPluginNames[runningPluginName]; _this.markSlots(plugin, false); _this.pointerManager.makePointerInvisible(plugin.parameters.handLaser); + + if (plugin.parameters.handLaser.doesHover !== undefined) { + if (plugin.parameters.handLaser.hand === LEFT_HAND && !_this.leftPointerDoesHover) { + _this.leftPointerDoesHover = true; + _this.leftPointerDoesHoverChanged = true; + } else if (plugin.parameters.handLaser.hand === RIGHT_HAND && !_this.rightPointerDoesHover) { + _this.rightPointerDoesHover = true; + _this.rightPointerDoesHoverChanged = true; + } + } + if (DEBUG) { print("controllerDispatcher stopping " + runningPluginName); } @@ -433,8 +432,7 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js"); } } _this.pointerManager.updatePointersRenderState(controllerData.triggerClicks, controllerData.triggerValues); - - _this.setNonHoverItems(); + _this.updateHovering(); if (PROFILE) { Script.endProfileRange("dispatch.run"); diff --git a/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js b/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js index 5b9afa3a2a..282dd36d17 100644 --- a/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js +++ b/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js @@ -90,7 +90,7 @@ Script.include("/~/system/libraries/controllers.js"); this.hoverItem = null; this.isTabletID = function (uuid) { - return [HMD.tabletID, HMD.tabletScreenID, HMD.homeButtonID, HMD.homeButtonHightlightID].indexOf(uuid) !== -1; + return [HMD.tabletID, HMD.tabletScreenID, HMD.homeButtonID, HMD.homeButtonHighlightID].indexOf(uuid) !== -1; }; this.isReady = function(controllerData) { @@ -105,19 +105,19 @@ Script.include("/~/system/libraries/controllers.js"); } if (pointingAt !== this.getOtherModule().hoverItem) { + this.parameters.handLaser.doesHover = true; this.hoverItem = pointingAt; - this.getOtherModule().parameters.handLaser.nonHoverItem = pointingAt; } else { + this.parameters.handLaser.doesHover = false; this.hoverItem = null; - this.getOtherModule().parameters.handLaser.nonHoverItem = null; } return makeRunningValues(true, [], []); } } + this.parameters.handLaser.doesHover = false; this.hoverItem = null; - this.getOtherModule().parameters.handLaser.nonHoverItem = null; return makeRunningValues(false, [], []); }; @@ -135,11 +135,11 @@ Script.include("/~/system/libraries/controllers.js"); } if (pointingAt !== this.getOtherModule().hoverItem || isTriggerPressed) { + this.parameters.handLaser.doesHover = true; this.hoverItem = pointingAt; - this.getOtherModule().parameters.handLaser.nonHoverItem = pointingAt; } else { + this.parameters.handLaser.doesHover = false; this.hoverItem = null; - this.getOtherModule().parameters.handLaser.nonHoverItem = null; } return makeRunningValues(true, [], []); @@ -147,8 +147,8 @@ Script.include("/~/system/libraries/controllers.js"); this.deleteContextOverlay(); this.running = false; + this.parameters.handLaser.doesHover = false; this.hoverItem = null; - this.getOtherModule().parameters.handLaser.nonHoverItem = null; return makeRunningValues(false, [], []); }; From 45bc6b8dabf371d25b6841901be446dae7d6c57f Mon Sep 17 00:00:00 2001 From: David Rowe Date: Fri, 19 Jan 2018 16:41:23 +1300 Subject: [PATCH 5/8] Dominant hand gets the highlight if both start pointing simultaneously --- .../controllerModules/webSurfaceLaserInput.js | 40 ++++++++++++++----- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js b/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js index 282dd36d17..cc8378af84 100644 --- a/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js +++ b/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js @@ -87,6 +87,23 @@ Script.include("/~/system/libraries/controllers.js"); return MyAvatar.getDominantHand() === "right" ? 1 : 0; }; + this.letOtherHandRunFirst = function (controllerData, pointingAt) { + // If both hands are ready to run, let the other hand run first if it is the dominant hand so that it gets the + // highlight. + var isOtherTriggerPressed = controllerData.triggerValues[this.otherHand] > TRIGGER_OFF_VALUE; + var isLetOtherHandRunFirst = !this.getOtherModule().running + && this.getDominantHand() === this.otherHand + && (this.parameters.handLaser.allwaysOn || isOtherTriggerPressed); + if (isLetOtherHandRunFirst) { + var otherHandPointingAt = controllerData.rayPicks[this.otherHand].objectID; + if (this.isTabletID(otherHandPointingAt)) { + otherHandPointingAt = HMD.tabletID; + } + isLetOtherHandRunFirst = pointingAt === otherHandPointingAt; + } + return isLetOtherHandRunFirst; + }; + this.hoverItem = null; this.isTabletID = function (uuid) { @@ -94,25 +111,28 @@ Script.include("/~/system/libraries/controllers.js"); }; this.isReady = function(controllerData) { - var isTriggerPressed = controllerData.triggerValues[this.hand] > TRIGGER_OFF_VALUE - && controllerData.triggerValues[this.otherHand] <= TRIGGER_OFF_VALUE; if (this.isPointingAtOverlay(controllerData) || this.isPointingAtWebEntity(controllerData)) { this.updateAllwaysOn(); + + var isTriggerPressed = controllerData.triggerValues[this.hand] > TRIGGER_OFF_VALUE; if (this.parameters.handLaser.allwaysOn || isTriggerPressed) { var pointingAt = controllerData.rayPicks[this.hand].objectID; if (this.isTabletID(pointingAt)) { pointingAt = HMD.tabletID; } - if (pointingAt !== this.getOtherModule().hoverItem) { - this.parameters.handLaser.doesHover = true; - this.hoverItem = pointingAt; - } else { - this.parameters.handLaser.doesHover = false; - this.hoverItem = null; - } + if (!this.letOtherHandRunFirst(controllerData, pointingAt)) { - return makeRunningValues(true, [], []); + if (pointingAt !== this.getOtherModule().hoverItem) { + this.parameters.handLaser.doesHover = true; + this.hoverItem = pointingAt; + } else { + this.parameters.handLaser.doesHover = false; + this.hoverItem = null; + } + + return makeRunningValues(true, [], []); + } } } From 94e6a68d4197e84b80a0de1b9396d6a7b7bf749e Mon Sep 17 00:00:00 2001 From: David Rowe Date: Sat, 20 Jan 2018 09:50:24 +1300 Subject: [PATCH 6/8] Code review --- libraries/pointers/src/Pointer.cpp | 4 +- libraries/pointers/src/Pointer.h | 2 +- .../controllers/controllerDispatcher.js | 55 ++++++------------- 3 files changed, 19 insertions(+), 42 deletions(-) diff --git a/libraries/pointers/src/Pointer.cpp b/libraries/pointers/src/Pointer.cpp index 0e542c47da..8691ab8823 100644 --- a/libraries/pointers/src/Pointer.cpp +++ b/libraries/pointers/src/Pointer.cpp @@ -111,7 +111,7 @@ void Pointer::generatePointerEvents(unsigned int pointerID, const PickResultPoin hoveredEvent.setMoveOnHoverLeave(moveOnHoverLeave); // if shouldHover && !_prevDoHover, only send hoverBegin - if (_enabled && _hover && doHover && !_prevDoHover) { + if (_enabled && doHover && !_prevDoHover) { if (hoveredObject.type == ENTITY) { emit pointerManager->hoverBeginEntity(hoveredObject.objectID, hoveredEvent); } else if (hoveredObject.type == OVERLAY) { @@ -119,7 +119,7 @@ void Pointer::generatePointerEvents(unsigned int pointerID, const PickResultPoin } else if (hoveredObject.type == HUD) { emit pointerManager->hoverBeginHUD(hoveredEvent); } - } else if (_enabled && _hover && doHover) { + } else if (_enabled && doHover) { if (hoveredObject.type == OVERLAY) { if (_prevHoveredObject.type == OVERLAY) { if (hoveredObject.objectID == _prevHoveredObject.objectID) { diff --git a/libraries/pointers/src/Pointer.h b/libraries/pointers/src/Pointer.h index ef0048cf1e..62683cb6e7 100644 --- a/libraries/pointers/src/Pointer.h +++ b/libraries/pointers/src/Pointer.h @@ -62,7 +62,7 @@ public: virtual void setLength(float length) {} virtual void setLockEndUUID(const QUuid& objectID, bool isOverlay, const glm::mat4& offsetMat = glm::mat4()) {} - void setDoesHover(bool hover); + virtual void setDoesHover(bool hover); void update(unsigned int pointerID); virtual void updateVisuals(const PickResultPointer& pickResult) = 0; diff --git a/scripts/system/controllers/controllerDispatcher.js b/scripts/system/controllers/controllerDispatcher.js index fe18ed25f8..4946a6525e 100644 --- a/scripts/system/controllers/controllerDispatcher.js +++ b/scripts/system/controllers/controllerDispatcher.js @@ -163,6 +163,20 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js"); } }; + this.updateDoesHover = function(handLaser) { + if (handLaser.doesHover !== undefined) { + if (handLaser.hand === LEFT_HAND + && _this.leftPointerDoesHover !== handLaser.doesHover) { + _this.leftPointerDoesHover = handLaser.doesHover; + _this.leftPointerDoesHoverChanged = true; + } else if (handLaser.hand === RIGHT_HAND + && _this.rightPointerDoesHover !== handLaser.doesHover) { + _this.rightPointerDoesHover = handLaser.doesHover; + _this.rightPointerDoesHoverChanged = true; + } + } + } + this.updateHovering = function () { if (_this.leftPointerDoesHoverChanged) { Pointers.setDoesHover(_this.leftPointer, _this.leftPointerDoesHover); @@ -345,19 +359,7 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js"); _this.runningPluginNames[orderedPluginName] = true; _this.markSlots(candidatePlugin, orderedPluginName); _this.pointerManager.makePointerVisible(candidatePlugin.parameters.handLaser); - - if (candidatePlugin.parameters.handLaser.doesHover !== undefined) { - if (candidatePlugin.parameters.handLaser.hand === LEFT_HAND - && _this.leftPointerDoesHover !== candidatePlugin.parameters.handLaser.doesHover) { - _this.leftPointerDoesHover = candidatePlugin.parameters.handLaser.doesHover; - _this.leftPointerDoesHoverChanged = true; - } else if (candidatePlugin.parameters.handLaser.hand === RIGHT_HAND - && _this.rightPointerDoesHover !== candidatePlugin.parameters.handLaser.doesHover) { - _this.rightPointerDoesHover = candidatePlugin.parameters.handLaser.doesHover; - _this.rightPointerDoesHoverChanged = true; - } - } - + _this.updateDoesHover(candidatePlugin.parameters.handLaser); if (DEBUG) { print("controllerDispatcher running " + orderedPluginName); } @@ -387,39 +389,14 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js"); if (PROFILE) { Script.beginProfileRange("dispatch.run." + runningPluginName); } + _this.updateDoesHover(plugin.parameters.handLaser); var runningness = plugin.run(controllerData, deltaTime); - - if (runningness.active) { - if (plugin.parameters.handLaser.doesHover !== undefined) { - if (plugin.parameters.handLaser.hand === LEFT_HAND - && _this.leftPointerDoesHover !== plugin.parameters.handLaser.doesHover) { - _this.leftPointerDoesHover = plugin.parameters.handLaser.doesHover; - _this.leftPointerDoesHoverChanged = true; - } else if (plugin.parameters.handLaser.hand === RIGHT_HAND - && _this.rightPointerDoesHover !== plugin.parameters.handLaser.doesHover) { - _this.rightPointerDoesHover = plugin.parameters.handLaser.doesHover; - _this.rightPointerDoesHoverChanged = true; - } - } - } - if (!runningness.active) { // plugin is finished running, for now. remove it from the list // of running plugins and mark its activity-slots as "not in use" delete _this.runningPluginNames[runningPluginName]; _this.markSlots(plugin, false); _this.pointerManager.makePointerInvisible(plugin.parameters.handLaser); - - if (plugin.parameters.handLaser.doesHover !== undefined) { - if (plugin.parameters.handLaser.hand === LEFT_HAND && !_this.leftPointerDoesHover) { - _this.leftPointerDoesHover = true; - _this.leftPointerDoesHoverChanged = true; - } else if (plugin.parameters.handLaser.hand === RIGHT_HAND && !_this.rightPointerDoesHover) { - _this.rightPointerDoesHover = true; - _this.rightPointerDoesHoverChanged = true; - } - } - if (DEBUG) { print("controllerDispatcher stopping " + runningPluginName); } From 24dcc8788cd671e99ff8ecdd05f2c4eb087d6ae8 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Sat, 20 Jan 2018 10:07:23 +1300 Subject: [PATCH 7/8] Code review --- libraries/pointers/src/Pointer.cpp | 3 +-- libraries/pointers/src/Pointer.h | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/libraries/pointers/src/Pointer.cpp b/libraries/pointers/src/Pointer.cpp index 8691ab8823..287d5a3c97 100644 --- a/libraries/pointers/src/Pointer.cpp +++ b/libraries/pointers/src/Pointer.cpp @@ -236,7 +236,7 @@ void Pointer::generatePointerEvents(unsigned int pointerID, const PickResultPoin } // if we disable the pointer or disable hovering, send hoverEnd events after triggerEnd - if ((_hover || _prevHover) && ((!_enabled && _prevEnabled) || (!doHover && _prevDoHover))) { + if ((!_enabled && _prevEnabled) || (!doHover && _prevDoHover)) { if (_prevHoveredObject.type == ENTITY) { emit pointerManager->hoverEndEntity(_prevHoveredObject.objectID, hoveredEvent); } else if (_prevHoveredObject.type == OVERLAY) { @@ -249,7 +249,6 @@ void Pointer::generatePointerEvents(unsigned int pointerID, const PickResultPoin _prevHoveredObject = hoveredObject; _prevButtons = buttons; _prevEnabled = _enabled; - _prevHover = _hover; _prevDoHover = doHover; } diff --git a/libraries/pointers/src/Pointer.h b/libraries/pointers/src/Pointer.h index 62683cb6e7..9fd434fb15 100644 --- a/libraries/pointers/src/Pointer.h +++ b/libraries/pointers/src/Pointer.h @@ -99,7 +99,6 @@ private: PickedObject _prevHoveredObject; Buttons _prevButtons; bool _prevEnabled { false }; - bool _prevHover { false }; bool _prevDoHover { false }; std::unordered_map _triggeredObjects; From 7898aa2c4b0f6ef879b02ac285dc5afe3d0cecf8 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Sat, 20 Jan 2018 10:32:42 +1300 Subject: [PATCH 8/8] Code review --- .../controllers/controllerDispatcher.js | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/scripts/system/controllers/controllerDispatcher.js b/scripts/system/controllers/controllerDispatcher.js index 4946a6525e..a8658933e7 100644 --- a/scripts/system/controllers/controllerDispatcher.js +++ b/scripts/system/controllers/controllerDispatcher.js @@ -163,15 +163,13 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js"); } }; - this.updateDoesHover = function(handLaser) { + this.updateDoesHover = function(handLaser, doesHover) { if (handLaser.doesHover !== undefined) { - if (handLaser.hand === LEFT_HAND - && _this.leftPointerDoesHover !== handLaser.doesHover) { - _this.leftPointerDoesHover = handLaser.doesHover; + if (handLaser.hand === LEFT_HAND && _this.leftPointerDoesHover !== doesHover) { + _this.leftPointerDoesHover = doesHover; _this.leftPointerDoesHoverChanged = true; - } else if (handLaser.hand === RIGHT_HAND - && _this.rightPointerDoesHover !== handLaser.doesHover) { - _this.rightPointerDoesHover = handLaser.doesHover; + } else if (handLaser.hand === RIGHT_HAND && _this.rightPointerDoesHover !== doesHover) { + _this.rightPointerDoesHover = doesHover; _this.rightPointerDoesHoverChanged = true; } } @@ -359,7 +357,8 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js"); _this.runningPluginNames[orderedPluginName] = true; _this.markSlots(candidatePlugin, orderedPluginName); _this.pointerManager.makePointerVisible(candidatePlugin.parameters.handLaser); - _this.updateDoesHover(candidatePlugin.parameters.handLaser); + _this.updateDoesHover(candidatePlugin.parameters.handLaser, + candidatePlugin.parameters.handLaser.doesHover); if (DEBUG) { print("controllerDispatcher running " + orderedPluginName); } @@ -389,14 +388,16 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js"); if (PROFILE) { Script.beginProfileRange("dispatch.run." + runningPluginName); } - _this.updateDoesHover(plugin.parameters.handLaser); var runningness = plugin.run(controllerData, deltaTime); - if (!runningness.active) { + if (runningness.active) { + _this.updateDoesHover(plugin.parameters.handLaser, plugin.parameters.handLaser.doesHover); + } else { // plugin is finished running, for now. remove it from the list // of running plugins and mark its activity-slots as "not in use" delete _this.runningPluginNames[runningPluginName]; _this.markSlots(plugin, false); _this.pointerManager.makePointerInvisible(plugin.parameters.handLaser); + _this.updateDoesHover(plugin.parameters.handLaser, true); if (DEBUG) { print("controllerDispatcher stopping " + runningPluginName); }