From 9495bf6a478d01a3ba9a112b06734afff1f87856 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Mon, 10 Apr 2017 19:56:46 +1200 Subject: [PATCH] Fix auto-playback logic --- scripts/system/playRecordingAC.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/scripts/system/playRecordingAC.js b/scripts/system/playRecordingAC.js index efe099f85d..a9fc793017 100644 --- a/scripts/system/playRecordingAC.js +++ b/scripts/system/playRecordingAC.js @@ -19,13 +19,15 @@ PLAYER_COMMAND_STOP = "stop", heartbeatTimer = null, HEARTBEAT_INTERVAL = 3000, // TODO: Final value. + TIMESTAMP_UPDATE_INTERVAL = 2500, // TODO: Final value. + AUTOPLAY_SEARCH_INTERVAL = 5000, // TODO: Final value. scriptUUID, Entity, Player; function log(message) { - print(APP_NAME + ": " + message); + print(APP_NAME + " " + scriptUUID + ": " + message); } Entity = (function () { @@ -33,7 +35,6 @@ var entityID = null, userData, updateTimestampTimer = null, - TIMESTAMP_UPDATE_INTERVAL = 2000, // TODO: Final value. ENTITY_NAME = "Recording", ENTITY_DESCRIPTION = "Avatar recording to play back", ENTITIY_POSITION = { x: -16382, y: -16382, z: -16382 }, // Near but not right on domain corner. @@ -52,6 +53,8 @@ // Create a new persistence entity (even if already have one but that should never occur). var properties; + log("Create recording " + filename); + if (updateTimestampTimer !== null) { Script.clearInterval(updateTimestampTimer); // Just in case. } @@ -104,10 +107,11 @@ } isClaiming = false; - // Return claim as "found" if still valid. + // Complete claim as "found" if still valid. properties = Entities.getEntityProperties(entityID, ["userData"]); userData = JSON.parse(properties.userData); if (userData.scriptUUID === scriptUUID) { + log("Complete claim " + entityID); userData.timestamp = Date.now(); Entities.editEntity(entityID, { userData: JSON.stringify(userData) }); EntityViewer.queryOctree(); // Update octree ready for next find() call. @@ -116,6 +120,7 @@ } // Otherwise resume searching. + log("Release claim " + entityID); EntityViewer.queryOctree(); // Update octree ready for next find() call. return null; } @@ -130,13 +135,14 @@ properties = Entities.getEntityProperties(entityIDs[index], ["name", "userData"]); if (properties.name === ENTITY_NAME) { userData = JSON.parse(properties.userData); - isFound = (Date.now() - userData.timestamp) > ((CLAIM_CHECKS + 1) * TIMESTAMP_UPDATE_INTERVAL); + isFound = (Date.now() - userData.timestamp) > ((CLAIM_CHECKS + 1) * AUTOPLAY_SEARCH_INTERVAL); } } } // Claim entity if found. if (isFound) { + log("Claim entity " + entityIDs[index]); isClaiming = true; claimCheckCount = 0; entityID = entityIDs[index]; @@ -186,8 +192,7 @@ // Recording playback functions. var isPlayingRecording = false, recordingFilename = "", - autoPlayTimer = null, - AUTOPLAY_SEARCH_INTERVAL = 5000; // TODO: Final value. + autoPlayTimer = null; function playRecording(recording, position, orientation) { Agent.isAvatar = true;