diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index f31e6e524e..8cd2c44088 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -267,7 +267,7 @@ class MyAvatar : public Avatar { * @property {number} analogPlusWalkSpeed - The walk speed of your avatar for the "AnalogPlus" control scheme. *

Warning: Setting this value also sets the value of analogPlusSprintSpeed to twice * the value.

- * @property {number} analogPlusSprintSpeed - The sprint speed of your avatar for the "AnalogPlus" control scheme. + * @property {number} analogPlusSprintSpeed - The sprint (run) speed of your avatar for the "AnalogPlus" control scheme. * @property {MyAvatar.SitStandModelType} userRecenterModel - Controls avatar leaning and recentering behavior. * @property {number} isInSittingState - true if your avatar is sitting (avatar leaning is disabled, * recenntering is enabled), false if it is standing (avatar leaning is enabled, and avatar recenters if it @@ -2198,33 +2198,35 @@ signals: void audioListenerModeChanged(); /**jsdoc - * Notifies when the analogPlusWalkSpeed value is changed. + * Triggered when the walk speed set for the "AnalogPlus" control scheme changes. * @function MyAvatar.analogPlusWalkSpeedChanged - * @param {float} value - the new avatar walk speed + * @param {number} speed - The new walk speed set for the "AnalogPlus" control scheme. * @returns {Signal} */ void analogPlusWalkSpeedChanged(float value); /**jsdoc - * Notifies when the analogPlusSprintSpeed value is changed. + * Triggered when the sprint (run) speed set for the "AnalogPlus" control scheme changes. * @function MyAvatar.analogPlusSprintSpeedChanged - * @param {float} value - the new avatar sprint speed + * @param {number} speed - The new sprint speed set for the "AnalogPlus" control scheme. * @returns {Signal} */ void analogPlusSprintSpeedChanged(float value); /**jsdoc - * Notifies when the sprintSpeed value is changed. + * Triggered when the sprint (run) speed set for the current control scheme (see + * {@link MyAvatar.getControlScheme|getControlScheme}) changes. * @function MyAvatar.sprintSpeedChanged - * @param {float} value - the new avatar sprint speed + * @param {number} speed -The new sprint speed set for the current control scheme. * @returns {Signal} */ void sprintSpeedChanged(float value); /**jsdoc - * Notifies when the walkBackwardSpeed value is changed. + * Triggered when the walk backward speed set for the current control scheme (see + * {@link MyAvatar.getControlScheme|getControlScheme}) changes. * @function MyAvatar.walkBackwardSpeedChanged - * @param {float} value - the new avatar walk backward speed + * @param {number} speed - The new walk backward speed set for the current control scheme. * @returns {Signal} */ void walkBackwardSpeedChanged(float value); diff --git a/scripts/simplifiedUI/ui/simplifiedNametag/resources/modules/nameTagListManager.js b/scripts/simplifiedUI/ui/simplifiedNametag/resources/modules/nameTagListManager.js index f8b6f2e6cd..2ba9904845 100644 --- a/scripts/simplifiedUI/ui/simplifiedNametag/resources/modules/nameTagListManager.js +++ b/scripts/simplifiedUI/ui/simplifiedNametag/resources/modules/nameTagListManager.js @@ -9,16 +9,17 @@ // // Helps manage the list of avatars added to the nametag list // - -var EntityMaker = Script.require('./entityMaker.js?' + Date.now()); -var entityProps = Script.require('./defaultLocalEntityProps.js?' + Date.now()); -var textHelper = new (Script.require('./textHelper.js?' + Date.now())); +var EntityMaker = Script.require('./entityMaker.js'); +var entityProps = Script.require('./defaultLocalEntityProps.js'); +var textHelper = new (Script.require('./textHelper.js')); var X = 0; var Y = 1; var Z = 2; var HALF = 0.5; var CLEAR_ENTITY_EDIT_PROPS = true; var MILISECONDS_IN_SECOND = 1000; +var SECONDS_IN_MINUTE = 60; +var ALWAYS_ON_MAX_LIFETIME_IN_SECONDS = 20 * SECONDS_IN_MINUTE; // Delete after 20 minutes in case a nametag is hanging around in on mode // ************************************* // START UTILTY @@ -58,8 +59,6 @@ var distanceScaler = DISTANCE_SCALER_ON; var userScaler = 1.0; var DEFAULT_LINE_HEIGHT = entityProps.lineHeight; function calculateInitialProperties(uuid) { - var avatar = _this.avatars[uuid]; - var adjustedScaler = null; var distance = null; var dimensions = null; @@ -97,19 +96,6 @@ function calculateInitialProperties(uuid) { } -// Used in alwaysOn mode to show or hide if they reached the max radius -function showHide(uuid, type) { - var avatar = _this.avatars[uuid]; - var nametag = avatar.nametag; - - if (type === "show") { - nametag.show(); - } else { - nametag.hide(); - } -} - - // Go through the selected avatar list and see if any of the avatars need a redraw function checkAllSelectedForRedraw() { for (var avatar in _this.selectedAvatars) { @@ -168,6 +154,18 @@ function getDistance(uuid, checkAvatar, shouldSave) { } +// Quick check for distance from avatar +function quickDistanceCheckForNonSelectedAvatars(uuid) { + var source = MyAvatar.position; + + var target = AvatarManager.getAvatar(uuid).position; + + var avatarDistance = Vec3.distance(target, source); + + return avatarDistance; +} + + // Check to see if we need to toggle our interval check because we went to 0 avatars // or if we got our first avatar in the select list function shouldToggleInterval() { @@ -197,7 +195,9 @@ function toggleInterval() { } -// handle turning the peristenet mode on +// Handle checking to see if we should add or delete nametags in persistent mode +var alwaysOnAvatarDistanceCheck = false; +var DISTANCE_CHECK_INTERVAL_MS = 1000; function handleAlwaysOnMode(shouldTurnOnAlwaysOnMode) { _this.reset(); if (shouldTurnOnAlwaysOnMode) { @@ -205,9 +205,23 @@ function handleAlwaysOnMode(shouldTurnOnAlwaysOnMode) { .getAvatarIdentifiers() .forEach(function (avatar) { if (avatar) { - add(avatar); + var avatarDistance = quickDistanceCheckForNonSelectedAvatars(avatar); + if (avatarDistance < MAX_RADIUS_IGNORE_METERS) { + add(avatar); + } } }); + maybeClearAlwaysOnAvatarDistanceCheck(); + alwaysOnAvatarDistanceCheck = Script.setInterval(maybeAddOrRemoveIntervalCheck, DISTANCE_CHECK_INTERVAL_MS); + } +} + + +// Check to see if we need to clear the distance check in persistent mode +function maybeClearAlwaysOnAvatarDistanceCheck() { + if (alwaysOnAvatarDistanceCheck) { + Script.clearInterval(alwaysOnAvatarDistanceCheck); + alwaysOnAvatarDistanceCheck = false; } } @@ -313,12 +327,6 @@ function makeNameTag(uuid) { var nameTagPosition = jointInObjectFrame.y + scaledDimenionsYHalf + ABOVE_HEAD_OFFSET; var localPosition = [0, nameTagPosition, 0]; - var visible = true; - if (avatarNametagMode === "alwaysOn") { - var currentDistance = getDistance(uuid, CHECK_AVATAR, false); - visible = currentDistance > MAX_RADIUS_IGNORE_METERS ? false : true; - } - nametag .add("leftMargin", lineHeight * LEFT_MARGIN_SCALER) .add("rightMargin", lineHeight * RIGHT_MARGIN_SCALER) @@ -328,7 +336,6 @@ function makeNameTag(uuid) { .add("dimensions", scaledDimensions) .add("parentID", parentID) .add("localPosition", localPosition) - .add("visible", visible) .create(CLEAR_ENTITY_EDIT_PROPS); Script.setTimeout(function () { @@ -341,33 +348,45 @@ function makeNameTag(uuid) { var MAX_RADIUS_IGNORE_METERS = 22; var MAX_ON_MODE_DISTANCE = 35; var CHECK_AVATAR = true; -var MIN_DISTANCE = 0.2; +var MIN_DISTANCE_FOR_REDRAW_METERS = 0.1; function maybeRedraw(uuid) { var avatar = _this.avatars[uuid]; getAvatarData(uuid); getDistance(uuid); - var avatarDistance = getDistance(uuid, CHECK_AVATAR, false); - if (avatarNametagMode === "alwaysOn" && avatarDistance > MAX_RADIUS_IGNORE_METERS) { - showHide(uuid, "hide"); - } - - if (avatarNametagMode === "alwaysOn" && avatarDistance < MAX_RADIUS_IGNORE_METERS) { - showHide(uuid, "show"); - } + var distanceDelta = Math.abs(avatar.currentDistance - avatar.previousDistance); var name = getCorrectName(uuid); if (avatar.previousName !== name) { updateName(uuid, name); - } else { + } else if (distanceDelta > MIN_DISTANCE_FOR_REDRAW_METERS) { redraw(uuid); } +} + +// Check to see if we need to add or remove this avatar during always on mode +function maybeAddOrRemoveIntervalCheck() { + AvatarManager + .getAvatarIdentifiers() + .forEach(function (avatar) { + if (avatar) { + var avatarDistance = quickDistanceCheckForNonSelectedAvatars(avatar); + if (avatar && avatarNametagMode === "alwaysOn" && !(avatar in _this.avatars) && avatarDistance < MAX_RADIUS_IGNORE_METERS) { + add(avatar); + return; + } + if (avatarDistance > MAX_RADIUS_IGNORE_METERS) { + maybeRemove(avatar); + } + } + }); } // Handle redrawing if needed +var MIN_DISTANCE = 0.1; function redraw(uuid) { var avatar = _this.avatars[uuid]; @@ -447,7 +466,7 @@ function add(uuid) { _this.selectedAvatars[uuid] = true; if (avatarNametagMode === "alwaysOn") { - entityProps.lifetime = -1; + entityProps.lifetime = ALWAYS_ON_MAX_LIFETIME_IN_SECONDS; } else { entityProps.lifetime = DEFAULT_LIFETIME; } @@ -521,16 +540,20 @@ function removeNametag(uuid) { // #region API -// Create the manager and hook up username signal +// Create the manager. function create() { + if (avatarNametagMode === "alwaysOn") { + handleAvatarNametagMode("alwaysOn"); + } return _this; } -// Destory the manager and disconnect from username signal +// Destroy the manager function destroy() { _this.reset(); + return _this; } @@ -601,7 +624,9 @@ function maybeRemove(uuid) { // Check to see if we need to add this user to our list function maybeAdd(uuid) { - if (uuid && avatarNametagMode === "alwaysOn" && !(uuid in _this.avatars)) { + var avatarDistance = quickDistanceCheckForNonSelectedAvatars(uuid); + + if (uuid && avatarNametagMode === "alwaysOn" && !(uuid in _this.avatars) && avatarDistance < MAX_RADIUS_IGNORE_METERS) { add(uuid); } } @@ -628,6 +653,7 @@ function reset() { removeAllNametags(); _this.avatars = {}; shouldToggleInterval(); + maybeClearAlwaysOnAvatarDistanceCheck(); return _this; } diff --git a/scripts/simplifiedUI/ui/simplifiedNametag/simplifiedNametag.js b/scripts/simplifiedUI/ui/simplifiedNametag/simplifiedNametag.js index 9b4d9cfad3..7c23c45674 100644 --- a/scripts/simplifiedUI/ui/simplifiedNametag/simplifiedNametag.js +++ b/scripts/simplifiedUI/ui/simplifiedNametag/simplifiedNametag.js @@ -8,8 +8,8 @@ // // Click on someone to get a nametag for them // -var PickRayController = Script.require('./resources/modules/pickRayController.js?' + Date.now()); -var NameTagListManager = Script.require('./resources/modules/nameTagListManager.js?' + Date.now()); +var PickRayController = Script.require('./resources/modules/pickRayController.js'); +var NameTagListManager = Script.require('./resources/modules/nameTagListManager.js'); var pickRayController = new PickRayController(); var nameTagListManager = new NameTagListManager(); @@ -31,6 +31,7 @@ function selectAvatar(uuid, intersection) { // Handles reset of list if you change domains function onDomainChange() { nameTagListManager.reset(); + nameTagListManager.handleAvatarNametagMode(avatarNametagMode); }