From ef8f36026c9b825d85ffa9f952af0d32983c339c Mon Sep 17 00:00:00 2001 From: David Rowe Date: Sat, 15 Apr 2017 13:20:42 +1200 Subject: [PATCH] Improve speed of starting playing animations at server start-up --- scripts/system/playRecordingAC.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/scripts/system/playRecordingAC.js b/scripts/system/playRecordingAC.js index 0a47de8eff..b88637f8c4 100644 --- a/scripts/system/playRecordingAC.js +++ b/scripts/system/playRecordingAC.js @@ -279,15 +279,19 @@ } function autoPlay() { - var recording; + var recording, + AUTOPLAY_SEARCH_DELTA = 1000; // TODO: Final value. - recording = Entity.find(); - if (recording) { - log("Play persisted recording " + recordingFilename); - playRecording(recording.recording, recording.position, recording.orientation); - } else { - autoPlayTimer = Script.setTimeout(autoPlay, AUTOPLAY_SEARCH_INTERVAL); // Try again soon. - } + // Random delay to help reduce collisions between AC scripts. + Script.setTimeout(function () { + recording = Entity.find(); + if (recording) { + log("Play persisted recording " + recordingFilename); + playRecording(recording.recording, recording.position, recording.orientation); + } else { + autoPlayTimer = Script.setTimeout(autoPlay, AUTOPLAY_SEARCH_INTERVAL); // Try again soon. + } + }, Math.random() * AUTOPLAY_SEARCH_DELTA); } playRecording = function (recording, position, orientation) {