From c4a80996d5f7e2a6ce21fd31ce108734179cb881 Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Fri, 23 Sep 2016 16:17:28 -0700 Subject: [PATCH 1/4] fix away HMD unmouted logic --- scripts/system/away.js | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/scripts/system/away.js b/scripts/system/away.js index 716fe1340e..b3380a6737 100644 --- a/scripts/system/away.js +++ b/scripts/system/away.js @@ -148,15 +148,7 @@ var eventMappingName = "io.highfidelity.away"; // goActive on hand controller bu var eventMapping = Controller.newMapping(eventMappingName); var avatarPosition = MyAvatar.position; -// backward compatible version of getting HMD.mounted, so it works in old clients -function safeGetHMDMounted() { - if (HMD.mounted === undefined) { - return true; - } - return HMD.mounted; -} - -var wasHmdMounted = safeGetHMDMounted(); +var wasHmdMounted = HMD.mounted; function goAway() { if (isAway) { @@ -188,7 +180,7 @@ function goAway() { // For HMD, the hmd preview will show the system mouse because of allowMouseCapture, // but we want to turn off our Reticle so that we don't get two in preview and a stuck one in headset. Reticle.visible = !HMD.active; - wasHmdMounted = safeGetHMDMounted(); // always remember the correct state + wasHmdMounted = HMD.mounted; // always remember the correct state avatarPosition = MyAvatar.position; Script.update.connect(ifAvatarMovedGoActive); @@ -229,7 +221,7 @@ function goActive() { if (HMD.active) { Reticle.position = HMD.getHUDLookAtPosition2D(); } - wasHmdMounted = safeGetHMDMounted(); // always remember the correct state + wasHmdMounted = HMD.mounted; // always remember the correct state Script.update.disconnect(ifAvatarMovedGoActive); } @@ -249,6 +241,8 @@ var wasHmdActive = HMD.active; var wasMouseCaptured = Reticle.mouseCaptured; function maybeGoAway() { + + // If our active state change (went to or from HMD mode), and we are now in the HMD, go into away if (HMD.active !== wasHmdActive) { wasHmdActive = !wasHmdActive; if (wasHmdActive) { @@ -267,11 +261,21 @@ function maybeGoAway() { } // If you've removed your HMD from your head, and we can detect it, we will also go away... - var hmdMounted = safeGetHMDMounted(); - if (HMD.active && !hmdMounted && wasHmdMounted) { - wasHmdMounted = hmdMounted; - goAway(); + if (HMD.mounted != wasHmdMounted) { + print("HMD mounted changed..."); + + // We're putting the HMD on... switch to those devices + if (HMD.mounted) { + print("NOW mounted..."); + } else { + print("HMD NOW un-mounted..."); + + if (HMD.active) { + goAway(); + } + } } + wasHmdMounted = HMD.mounted; } Script.update.connect(maybeMoveOverlay); From 73e3e993fbbc9a0c2db8c385ea442c9b5c45c29e Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Mon, 26 Sep 2016 17:29:11 -0700 Subject: [PATCH 2/4] fix Vive's HMD.mounted --- plugins/openvr/src/OpenVrDisplayPlugin.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plugins/openvr/src/OpenVrDisplayPlugin.cpp b/plugins/openvr/src/OpenVrDisplayPlugin.cpp index 4c4fcbbd37..57b5cc8783 100644 --- a/plugins/openvr/src/OpenVrDisplayPlugin.cpp +++ b/plugins/openvr/src/OpenVrDisplayPlugin.cpp @@ -516,7 +516,11 @@ void OpenVrDisplayPlugin::postPreview() { _nextSimPoseData = nextSim; }); _nextRenderPoseData = nextRender; + + // FIXME - this looks wrong! _hmdActivityLevel = vr::k_EDeviceActivityLevel_UserInteraction; // _system->GetTrackedDeviceActivityLevel(vr::k_unTrackedDeviceIndex_Hmd); +#else + _hmdActivityLevel = _system->GetTrackedDeviceActivityLevel(vr::k_unTrackedDeviceIndex_Hmd); #endif } From f7228993a5f6db2cbc185d6a601fe2386924baae Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Mon, 26 Sep 2016 17:29:37 -0700 Subject: [PATCH 3/4] go into away if the application starts in HMD mode but it's not mounted --- scripts/system/away.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scripts/system/away.js b/scripts/system/away.js index b3380a6737..331205c538 100644 --- a/scripts/system/away.js +++ b/scripts/system/away.js @@ -308,4 +308,10 @@ Script.scriptEnding.connect(function () { Controller.keyPressEvent.disconnect(maybeGoActive); }); +if (HMD.active && !HMD.mounted) { + print("Starting script, while HMD is active and not mounted..."); + goAway(); +} + + }()); // END LOCAL_SCOPE From 20c522a9bcfac069c96b83886bd7d0eb7f4eaf89 Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Sat, 8 Oct 2016 13:45:18 -0700 Subject: [PATCH 4/4] fix more bugs in away --- scripts/system/away.js | 72 ++++++++++++++++++++++++++++-------------- 1 file changed, 48 insertions(+), 24 deletions(-) diff --git a/scripts/system/away.js b/scripts/system/away.js index 95af49d070..f4a1a22bf6 100644 --- a/scripts/system/away.js +++ b/scripts/system/away.js @@ -16,6 +16,7 @@ (function() { // BEGIN LOCAL_SCOPE +var BASIC_TIMER_INTERVAL = 50; // 50ms = 20hz var OVERLAY_WIDTH = 1920; var OVERLAY_HEIGHT = 1080; var OVERLAY_DATA = { @@ -49,6 +50,21 @@ var AWAY_INTRO = { endFrame: 83.0 }; +// MAIN CONTROL +var isEnabled = true; +var wasMuted; // unknonwn? +var isAway = false; // we start in the un-away state +var wasOverlaysVisible = Menu.isOptionChecked("Overlays"); +var eventMappingName = "io.highfidelity.away"; // goActive on hand controller button events, too. +var eventMapping = Controller.newMapping(eventMappingName); +var avatarPosition = MyAvatar.position; +var wasHmdMounted = HMD.mounted; + + +// some intervals we may create/delete +var avatarMovedInterval; + + // prefetch the kneel animation and hold a ref so it's always resident in memory when we need it. var _animation = AnimationCache.prefetch(AWAY_INTRO.url); @@ -125,33 +141,28 @@ function maybeMoveOverlay() { var halfWayBetweenOldAndLookAt = Vec3.multiply(lookAtChange, EASE_BY_RATIO); var newOverlayPosition = Vec3.sum(lastOverlayPosition, halfWayBetweenOldAndLookAt); lastOverlayPosition = newOverlayPosition; - var actualOverlayPositon = moveCloserToCamera(lastOverlayPosition); Overlays.editOverlay(overlayHMD, { visible: true, position: actualOverlayPositon }); // make sure desktop version is hidden Overlays.editOverlay(overlay, { visible: false }); + + // also remember avatar position + avatarPosition = MyAvatar.position; + } } } function ifAvatarMovedGoActive() { - if (Vec3.distance(MyAvatar.position, avatarPosition) > AVATAR_MOVE_FOR_ACTIVE_DISTANCE) { + var newAvatarPosition = MyAvatar.position; + if (Vec3.distance(newAvatarPosition, avatarPosition) > AVATAR_MOVE_FOR_ACTIVE_DISTANCE) { goActive(); } + avatarPosition = newAvatarPosition; } -// MAIN CONTROL -var isEnabled = true; -var wasMuted, isAway; -var wasOverlaysVisible = Menu.isOptionChecked("Overlays"); -var eventMappingName = "io.highfidelity.away"; // goActive on hand controller button events, too. -var eventMapping = Controller.newMapping(eventMappingName); -var avatarPosition = MyAvatar.position; - -var wasHmdMounted = HMD.mounted; - -function goAway() { +function goAway(fromStartup) { if (!isEnabled || isAway) { return; } @@ -159,7 +170,6 @@ function goAway() { UserActivityLogger.toggledAway(true); isAway = true; - print('going "away"'); wasMuted = AudioDevice.getMuted(); if (!wasMuted) { AudioDevice.toggleMute(); @@ -184,7 +194,18 @@ function goAway() { wasHmdMounted = HMD.mounted; // always remember the correct state avatarPosition = MyAvatar.position; - Script.update.connect(ifAvatarMovedGoActive); + + // If we're entering away mode from some other state than startup, then we create our move timer immediately. + // However if we're just stating up, we need to delay this process so that we don't think the initial teleport + // is actually a move. + if (fromStartup === undefined || fromStartup === false) { + avatarMovedInterval = Script.setInterval(ifAvatarMovedGoActive, BASIC_TIMER_INTERVAL); + } else { + var WAIT_FOR_MOVE_ON_STARTUP = 3000; // 3 seconds + Script.setTimeout(function() { + avatarMovedInterval = Script.setInterval(ifAvatarMovedGoActive, BASIC_TIMER_INTERVAL); + }, WAIT_FOR_MOVE_ON_STARTUP); + } } function goActive() { @@ -195,7 +216,6 @@ function goActive() { UserActivityLogger.toggledAway(false); isAway = false; - print('going "active"'); if (!wasMuted) { AudioDevice.toggleMute(); } @@ -224,7 +244,7 @@ function goActive() { } wasHmdMounted = HMD.mounted; // always remember the correct state - Script.update.disconnect(ifAvatarMovedGoActive); + Script.clearInterval(avatarMovedInterval); } function maybeGoActive(event) { @@ -242,12 +262,12 @@ var wasHmdActive = HMD.active; var wasMouseCaptured = Reticle.mouseCaptured; function maybeGoAway() { - // If our active state change (went to or from HMD mode), and we are now in the HMD, go into away if (HMD.active !== wasHmdActive) { wasHmdActive = !wasHmdActive; if (wasHmdActive) { goAway(); + return; } } @@ -258,11 +278,13 @@ function maybeGoAway() { wasMouseCaptured = !wasMouseCaptured; if (!wasMouseCaptured) { goAway(); + return; } } // If you've removed your HMD from your head, and we can detect it, we will also go away... if (HMD.mounted != wasHmdMounted) { + wasHmdMounted = HMD.mounted; print("HMD mounted changed..."); // We're putting the HMD on... switch to those devices @@ -273,14 +295,13 @@ function maybeGoAway() { if (HMD.active) { goAway(); + return; } } } - wasHmdMounted = HMD.mounted; } function setEnabled(value) { - print("setting away enabled: ", value); if (!value) { goActive(); } @@ -297,9 +318,12 @@ var handleMessage = function(channel, message, sender) { Messages.subscribe(CHANNEL_AWAY_ENABLE); Messages.messageReceived.connect(handleMessage); -Script.update.connect(maybeMoveOverlay); +var maybeIntervalTimer = Script.setInterval(function(){ + maybeMoveOverlay(); + maybeGoAway(); +}, BASIC_TIMER_INTERVAL); + -Script.update.connect(maybeGoAway); Controller.mousePressEvent.connect(goActive); Controller.keyPressEvent.connect(maybeGoActive); // Note peek() so as to not interfere with other mappings. @@ -320,7 +344,7 @@ eventMapping.from(Controller.Standard.Start).peek().to(goActive); Controller.enableMapping(eventMappingName); Script.scriptEnding.connect(function () { - Script.update.disconnect(maybeGoAway); + Script.clearInterval(maybeIntervalTimer); goActive(); Controller.disableMapping(eventMappingName); Controller.mousePressEvent.disconnect(goActive); @@ -329,7 +353,7 @@ Script.scriptEnding.connect(function () { if (HMD.active && !HMD.mounted) { print("Starting script, while HMD is active and not mounted..."); - goAway(); + goAway(true); }