From 691f61983aac911e0d8cac158132eb171c4bc2d6 Mon Sep 17 00:00:00 2001 From: kunalgosar Date: Fri, 10 Feb 2017 17:27:14 -0800 Subject: [PATCH 1/6] added isAway property to MyAvatar --- interface/src/avatar/MyAvatar.cpp | 14 ++++++++++++++ interface/src/avatar/MyAvatar.h | 6 ++++++ 2 files changed, 20 insertions(+) diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 1915046f72..d620fb4705 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -88,6 +88,7 @@ MyAvatar::MyAvatar(RigPointer rig) : _isPushing(false), _isBeingPushed(false), _isBraking(false), + _isAway(false), _boomLength(ZOOM_DEFAULT), _yawSpeed(YAW_SPEED_DEFAULT), _pitchSpeed(PITCH_SPEED_DEFAULT), @@ -2359,6 +2360,19 @@ bool MyAvatar::hasDriveInput() const { return fabsf(_driveKeys[TRANSLATE_X]) > 0.0f || fabsf(_driveKeys[TRANSLATE_Y]) > 0.0f || fabsf(_driveKeys[TRANSLATE_Z]) > 0.0f; } +void MyAvatar::setAway(bool value) { + _isAway = value; + if (_isAway) { + emit wentAway(); + } else { + emit wentActive(); + } +} + +bool MyAvatar::getIsAway() { + return _isAway; +} + // The resulting matrix is used to render the hand controllers, even if the camera is decoupled from the avatar. // Specificly, if we are rendering using a third person camera. We would like to render the hand controllers in front of the camera, // not in front of the avatar. diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index 18774c8719..6bd9650d02 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -82,6 +82,7 @@ class MyAvatar : public Avatar { Q_PROPERTY(controller::Pose rightHandTipPose READ getRightHandTipPose) Q_PROPERTY(float energy READ getEnergy WRITE setEnergy) + Q_PROPERTY(float isAway READ getIsAway WRITE setAway) Q_PROPERTY(bool hmdLeanRecenterEnabled READ getHMDLeanRecenterEnabled WRITE setHMDLeanRecenterEnabled) Q_PROPERTY(bool characterControllerEnabled READ getCharacterControllerEnabled WRITE setCharacterControllerEnabled) @@ -328,6 +329,8 @@ signals: void energyChanged(float newEnergy); void positionGoneTo(); void onLoadComplete(); + void wentAway(); + void wentActive(); private: @@ -385,6 +388,7 @@ private: bool _isPushing; bool _isBeingPushed; bool _isBraking; + bool _isAway; float _boomLength; float _yawSpeed; // degrees/sec @@ -519,6 +523,8 @@ private: float getEnergy(); void setEnergy(float value); bool didTeleport(); + void setAway(bool value); + bool getIsAway(); }; QScriptValue audioListenModeToScriptValue(QScriptEngine* engine, const AudioListenerMode& audioListenerMode); From a8f223518cd7edfe239e71522e896856c2111c1a Mon Sep 17 00:00:00 2001 From: kunalgosar Date: Fri, 10 Feb 2017 17:27:52 -0800 Subject: [PATCH 2/6] modified away script to use MyAvatar.isAway property --- scripts/system/away.js | 49 +++++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/scripts/system/away.js b/scripts/system/away.js index 96813031f1..541fe6f679 100644 --- a/scripts/system/away.js +++ b/scripts/system/away.js @@ -165,9 +165,36 @@ function goAway(fromStartup) { if (!isEnabled || isAway) { return; } - + + // 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); + } + UserActivityLogger.toggledAway(true); + MyAvatar.isAway = true; +} +function goActive() { + if (!isAway) { + return; + } + + UserActivityLogger.toggledAway(false); + MyAvatar.isAway = false; +} + +MyAvatar.wentAway.connect(setAwayProperties) +MyAvatar.wentActive.connect(setActiveProperties) + +function setAwayProperties() { isAway = true; wasMuted = AudioDevice.getMuted(); if (!wasMuted) { @@ -189,27 +216,9 @@ function goAway(fromStartup) { wasHmdMounted = HMD.mounted; // always remember the correct state avatarPosition = MyAvatar.position; - - // 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() { - if (!isAway) { - return; - } - - UserActivityLogger.toggledAway(false); - +function setActiveProperties() { isAway = false; if (!wasMuted) { AudioDevice.toggleMute(); From 9c537726e52af98877a7f948edc6cb8e9bed0add Mon Sep 17 00:00:00 2001 From: kunalgosar Date: Fri, 10 Feb 2017 18:13:09 -0800 Subject: [PATCH 3/6] Fix stuck in pause error with browsers --- interface/resources/qml/windows/Window.qml | 4 ++++ interface/src/avatar/MyAvatar.cpp | 4 ---- interface/src/avatar/MyAvatar.h | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/interface/resources/qml/windows/Window.qml b/interface/resources/qml/windows/Window.qml index 35e0fb961c..d22d8ecbe8 100644 --- a/interface/resources/qml/windows/Window.qml +++ b/interface/resources/qml/windows/Window.qml @@ -296,6 +296,10 @@ Fadable { // fall through default: + if (MyAvatar.isAway) { + // If stuck in a window and a key is pressed this should exit paused mode + MyAvatar.isAway = false; + } // Consume unmodified keyboard entries while the window is focused, to prevent them // from propagating to the application if (event.modifiers === Qt.NoModifier) { diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index d620fb4705..ded5d056bb 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -2369,10 +2369,6 @@ void MyAvatar::setAway(bool value) { } } -bool MyAvatar::getIsAway() { - return _isAway; -} - // The resulting matrix is used to render the hand controllers, even if the camera is decoupled from the avatar. // Specificly, if we are rendering using a third person camera. We would like to render the hand controllers in front of the camera, // not in front of the avatar. diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index 6bd9650d02..238bd9a1cb 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -523,8 +523,8 @@ private: float getEnergy(); void setEnergy(float value); bool didTeleport(); + bool getIsAway() const { return _isAway; } void setAway(bool value); - bool getIsAway(); }; QScriptValue audioListenModeToScriptValue(QScriptEngine* engine, const AudioListenerMode& audioListenerMode); From 18e776bd291dbc82fa48a0dfe851a489803eb237 Mon Sep 17 00:00:00 2001 From: Kunal Gosar Date: Sat, 11 Feb 2017 13:58:23 -0800 Subject: [PATCH 4/6] emit signal only on change --- interface/src/avatar/MyAvatar.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index ded5d056bb..5fa68b859e 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -2361,16 +2361,15 @@ bool MyAvatar::hasDriveInput() const { } void MyAvatar::setAway(bool value) { - _isAway = value; - if (_isAway) { - emit wentAway(); - } else { - emit wentActive(); + if (_isAway == value) { + return; } + _isAway = value; + _isAway ? emit wentAway() : emit wentActive(); } // The resulting matrix is used to render the hand controllers, even if the camera is decoupled from the avatar. -// Specificly, if we are rendering using a third person camera. We would like to render the hand controllers in front of the camera, +// Specifically, if we are rendering using a third person camera. We would like to render the hand controllers in front of the camera, // not in front of the avatar. glm::mat4 MyAvatar::computeCameraRelativeHandControllerMatrix(const glm::mat4& controllerSensorMatrix) const { From 975d844eeed2814c4fa8a53dfe788f39f79c2b52 Mon Sep 17 00:00:00 2001 From: Kunal Gosar Date: Sat, 11 Feb 2017 15:01:02 -0800 Subject: [PATCH 5/6] syntax fix --- interface/src/avatar/MyAvatar.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 5fa68b859e..8b05a55078 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -2365,7 +2365,10 @@ void MyAvatar::setAway(bool value) { return; } _isAway = value; - _isAway ? emit wentAway() : emit wentActive(); + if (_isAway): + emit wentAway(); + else: + emit wentActive(); } // The resulting matrix is used to render the hand controllers, even if the camera is decoupled from the avatar. From c3f2f5779ab45352575330a1acbdd6f8005e70d5 Mon Sep 17 00:00:00 2001 From: Kunal Gosar Date: Sat, 11 Feb 2017 15:46:49 -0800 Subject: [PATCH 6/6] fix if else syntax --- interface/src/avatar/MyAvatar.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 8b05a55078..ded5d056bb 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -2361,18 +2361,16 @@ bool MyAvatar::hasDriveInput() const { } void MyAvatar::setAway(bool value) { - if (_isAway == value) { - return; - } _isAway = value; - if (_isAway): + if (_isAway) { emit wentAway(); - else: + } else { emit wentActive(); + } } // The resulting matrix is used to render the hand controllers, even if the camera is decoupled from the avatar. -// Specifically, if we are rendering using a third person camera. We would like to render the hand controllers in front of the camera, +// Specificly, if we are rendering using a third person camera. We would like to render the hand controllers in front of the camera, // not in front of the avatar. glm::mat4 MyAvatar::computeCameraRelativeHandControllerMatrix(const glm::mat4& controllerSensorMatrix) const {