From 921cd94c0794caace610ff3d0dcbbbf0723b19fb Mon Sep 17 00:00:00 2001 From: Sam Cake Date: Tue, 1 Dec 2015 00:15:12 -0800 Subject: [PATCH] Finally a more stable api and playback use case --- examples/acScripts/AgentPoolControler.js | 20 ++++---------- examples/acScripts/playbackAgents.js | 35 ++++++------------------ examples/acScripts/playbackMaster.js | 15 ++++++---- 3 files changed, 23 insertions(+), 47 deletions(-) diff --git a/examples/acScripts/AgentPoolControler.js b/examples/acScripts/AgentPoolControler.js index c7ecd70ad1..74ee12922a 100644 --- a/examples/acScripts/AgentPoolControler.js +++ b/examples/acScripts/AgentPoolControler.js @@ -192,27 +192,22 @@ function printDebug(message) { this.timeSinceLastAlive = 0; Messages.sendMessage(SERVICE_CHANNEL, packServiceMessage(BROADCAST_AGENTS, MASTER_ALIVE, MASTER_ID)); - printDebug("checking the agents status"); { // Check for alive connected agents var lostAgents = new Array(); for (var i = 0; i < this.hiredActors.length; i++) { var actor = this.hiredActors[i]; - printDebug("checking :" + JSON.stringify(actor)); var lastAlive = actor.incrementAliveCycle() if (lastAlive > NUM_CYCLES_BEFORE_RESET) { - printDebug("Agent Lost, firing Agent"); - lostAgents.push(actor); + printDebug("Agent Lost, firing Agent #" + i + JSON.stringify(actor)); + lostAgents.push(i); } } - // now fire gathered lost agents - if (lostAgents.length > 0) { + // now fire gathered lost agents from end to begin + while (lostAgents.length > 0) { printDebug("Firing " + lostAgents.length + " agents" + JSON.stringify(lostAgents)); - - for (var i = 0; i < lostAgents.length; i++) { - this.fireAgent(lostAgents[l]); - } + this.fireAgent(this.hiredActors[lostAgents.pop()]); } } } @@ -251,7 +246,7 @@ function printDebug(message) { MasterController.prototype._removeAgent = function(actorIndex) { // check to see if we know about this agent if (actorIndex >= 0) { - printDebug("before _removeAgent #" + actorIndex + " " + JSON.stringify(this)) + printDebug("MasterController.prototype._removeAgent #" + actorIndex + " " + JSON.stringify(this)) this.knownAgents.splice(actorIndex, 1); var lostActor = this.hiredActors[actorIndex]; @@ -259,9 +254,6 @@ function printDebug(message) { var lostAgentID = lostActor.agentID; lostActor.agentID = INVALID_AGENT; - - printDebug("Clearing agent " + actorIndex + " Forgeting about it"); - printDebug("after _removeAgent #" + actorIndex + " " + JSON.stringify(this)) if (lostAgentID != INVALID_AGENT) { printDebug("fired actor is still connected, send fire command"); diff --git a/examples/acScripts/playbackAgents.js b/examples/acScripts/playbackAgents.js index 67fe8c733e..64c25ec0a8 100644 --- a/examples/acScripts/playbackAgents.js +++ b/examples/acScripts/playbackAgents.js @@ -9,9 +9,6 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -// Agent is an avatar -Agent.isAvatar = true; - Script.include("./AgentPoolControler.js"); var agentController = new AgentController(); @@ -34,8 +31,6 @@ var WAIT_FOR_AUDIO_MIXER = 1; var PLAY = 1; var PLAY_LOOP = 2; var STOP = 3; -var SHOW = 4; -var HIDE = 5; var LOAD = 6; Recording.setPlayFromCurrentLocation(playFromCurrentLocation); @@ -71,28 +66,13 @@ function agentCommand(command) { Recording.stopPlaying(); } break; - case SHOW: - print("Show"); - break; - case HIDE: - print("Hide"); - if (Recording.isPlaying()) { - Recording.stopPlaying(); - } - break; case LOAD: { print("Load" + command.argument_key); print("Agent #" + command.dest_key + " loading clip URL: " + command.argument_key); Recording.loadRecording(command.argument_key); print("After Load" + command.argument_key); - - /*if(command.argument_key == null) { - print("Agent #" + id + " loading clip URL is NULL, nothing happened"); - } else *{ - print("Agent #" + id + " loading clip URL: " + command.argument_key); - Recording.loadRecording(command.argument_key); - }*/ + Recording.setPlayerTime(0); } break; default: @@ -105,17 +85,18 @@ function agentCommand(command) { function agentHired() { print("Agent Hired from playbackAgents.js"); - if (Recording.isPlaying()) { - Recording.stopPlaying(); - } + Agent.isAvatar = true; + Recording.stopPlaying(); Recording.setPlayerLoop(false); + Recording.setPlayerTime(0); } function agentFired() { print("Agent Fired from playbackAgents.js"); - if (Recording.isPlaying()) { - Recording.stopPlaying(); - } + Recording.stopPlaying(); + Recording.setPlayerTime(0); + Recording.setPlayerLoop(false); + Agent.isAvatar = false; } diff --git a/examples/acScripts/playbackMaster.js b/examples/acScripts/playbackMaster.js index 7486256f07..d66a09d633 100644 --- a/examples/acScripts/playbackMaster.js +++ b/examples/acScripts/playbackMaster.js @@ -26,8 +26,6 @@ Tool.IMAGE_WIDTH /= 2; var PLAY = 1; var PLAY_LOOP = 2; var STOP = 3; -var SHOW = 4; -var HIDE = 5; var LOAD = 6; var windowDimensions = Controller.getViewportDimensions(); @@ -42,10 +40,6 @@ var TEXT_MARGIN = 3; // Add new features to Actor class: Actor.prototype.destroy = function() { print("Actor.prototype.destroy"); - - this.toolbar.cleanup(); - Overlays.deleteOverlay(this.nameOverlay); - print("Need to fire myself" + this.agentID); masterController.fireAgent(this); } @@ -123,6 +117,11 @@ Actor.prototype._buildUI = function() { }); } +Actor.prototype._destroyUI = function() { + this.toolbar.cleanup(); + Overlays.deleteOverlay(this.nameOverlay); +} + Actor.prototype.moveUI = function(pos) { var textSize = TEXT_HEIGHT + 2 * TEXT_MARGIN; this.toolbar.move(pos.x, pos.y); @@ -329,6 +328,9 @@ Director.prototype.hireActor = function(clipURL) { if (index >= 0) { localThis.actors.splice(index, 1); } + + actor._destroyUI(); + actor.destroy(); moveUI(); } @@ -338,6 +340,7 @@ Director.prototype.hireActor = function(clipURL) { masterController.sendCommand(actor.agentID, LOAD, actor.clipURL); }); + masterController.hireAgent(newActor); newActor._buildUI();