From ff3ae852459e599dee20b69cd7ad4f83d578f9d2 Mon Sep 17 00:00:00 2001 From: samcake Date: Tue, 1 Dec 2015 12:36:49 -0800 Subject: [PATCH] Separating the ui to get the url from the actual loading to maybe avoid playbackMaster.js crash? --- examples/acScripts/AgentPoolControler.js | 22 +++++---- examples/acScripts/playbackMaster.js | 59 ++++++++++++++++-------- 2 files changed, 53 insertions(+), 28 deletions(-) diff --git a/examples/acScripts/AgentPoolControler.js b/examples/acScripts/AgentPoolControler.js index 74ee12922a..e5917ea93e 100644 --- a/examples/acScripts/AgentPoolControler.js +++ b/examples/acScripts/AgentPoolControler.js @@ -141,7 +141,7 @@ function printDebug(message) { } else { // Master think the agent is hired but not the other way around, forget about it printDebug("New agent still sending ready ? " + message.src + " " + agentIndex + " Forgeting about it"); - this._removeAgent(agentIndex); + this._removeHiredAgent(agentIndex); } } else if (message.command == AGENT_ALIVE) { // check to see if we know about this agent @@ -199,7 +199,7 @@ function printDebug(message) { var actor = this.hiredActors[i]; var lastAlive = actor.incrementAliveCycle() if (lastAlive > NUM_CYCLES_BEFORE_RESET) { - printDebug("Agent Lost, firing Agent #" + i + JSON.stringify(actor)); + printDebug("Agent Lost, firing Agent #" + i + " ID " + actor.agentID); lostAgents.push(i); } } @@ -228,25 +228,31 @@ function printDebug(message) { MasterController.prototype.fireAgent = function(actor) { // check to see if we know about this agent - printDebug("MasterController.prototype.fireAgent" + JSON.stringify(actor) + " " + JSON.stringify(this.knownAgents)); + printDebug("MasterController.prototype.fireAgent" + actor.agentID); + // Try the waiting list first var waitingIndex = this.hiringAgentsQueue.indexOf(actor); if (waitingIndex >= 0) { - printDebug("MasterController.prototype.fireAgent found actor on waiting queue #" + waitingIndex); - this.hiringAgentsQueue.splice(waitingIndex, 1); + printDebug("fireAgent found actor on waiting queue #" + waitingIndex); + var lostActor = this.hiringAgentsQueue.splice(waitingIndex, 1); + if (lostActor.length) { + lostActor[0].onFired(lostActor[0]); + } + return; } + // then the hired agents var actorIndex = this.knownAgents.indexOf(actor.agentID); if (actorIndex >= 0) { printDebug("fired actor found #" + actorIndex); - this._removeAgent(actorIndex); + this._removeHiredAgent(actorIndex); } } - MasterController.prototype._removeAgent = function(actorIndex) { + MasterController.prototype._removeHiredAgent = function(actorIndex) { // check to see if we know about this agent if (actorIndex >= 0) { - printDebug("MasterController.prototype._removeAgent #" + actorIndex + " " + JSON.stringify(this)) + printDebug("MasterController.prototype._removeHiredAgent #" + this.knownAgents[actorIndex]) this.knownAgents.splice(actorIndex, 1); var lostActor = this.hiredActors[actorIndex]; diff --git a/examples/acScripts/playbackMaster.js b/examples/acScripts/playbackMaster.js index d66a09d633..5115dc9871 100644 --- a/examples/acScripts/playbackMaster.js +++ b/examples/acScripts/playbackMaster.js @@ -61,6 +61,8 @@ Actor.prototype.onMousePressEvent = function(clickedOverlay) { masterController.sendCommand(this.agentID, PLAY_LOOP); } else if (this.stopIcon === this.toolbar.clicked(clickedOverlay, false)) { masterController.sendCommand(this.agentID, STOP); + } else if (this.nameOverlay === clickedOverlay) { + print("Actor: " + JSON.stringify(this)); } else { return false; } @@ -136,6 +138,8 @@ Director = function() { this.actors = new Array(); this.toolbar = null; this._buildUI(); + this.requestPerformanceLoad = false; + this.performanceURL = ""; }; Director.prototype.destroy = function () { @@ -234,27 +238,11 @@ Director.prototype.onMousePressEvent = function(clickedOverlay) { input_text = Window.prompt("Insert the url of the clip: ",""); if (!(input_text === "" || input_text === null)) { print("Performance file ready to be loaded url = " + input_text); - var urlpartition = input_text.split("."); - print(urlpartition[0]); - print(urlpartition[1]); - - if ((urlpartition.length > 1) && (urlpartition[urlpartition.length - 1] === "hfr")) { - print("detected a unique clip url"); - var oneClipPerformance = new Object(); - oneClipPerformance.avatarClips = new Array(); - oneClipPerformance.avatarClips[0] = input_text; - - print(JSON.stringify(oneClipPerformance)); - - // we make a local simple performance file with a single clip and pipe in directly - this.onPerformanceLoaded(oneClipPerformance); - return true; - } else { - // FIXME: I cannot pass directly this.onPerformanceLoaded, is that exepected ? - var localThis = this; - Assets.downloadData(input_text, function(data) { localThis.onPerformanceLoaded(JSON.parse(data)); }); - } + this.requestPerformanceLoad = true; + this.performanceURL = input_text; } + } else if (this.nameOverlay === clickedOverlay) { + print("Director: " + JSON.stringify(this)); } else { // Check individual controls for (var i = 0; i < this.actors.length; i++) { @@ -285,6 +273,32 @@ Director.prototype.moveUI = function(pos) { } } + +Director.prototype.reloadPerformance = function() { + this.requestPerformanceLoad = false; + + var urlpartition = this.performanceURL.split("."); + print(urlpartition[0]); + print(urlpartition[1]); + + if ((urlpartition.length > 1) && (urlpartition[urlpartition.length - 1] === "hfr")) { + print("detected a unique clip url"); + var oneClipPerformance = new Object(); + oneClipPerformance.avatarClips = new Array(); + oneClipPerformance.avatarClips[0] = input_text; + + print(JSON.stringify(oneClipPerformance)); + + // we make a local simple performance file with a single clip and pipe in directly + this.onPerformanceLoaded(oneClipPerformance); + return true; + } else { + // FIXME: I cannot pass directly this.onPerformanceLoaded, is that exepected ? + var localThis = this; + Assets.downloadData(input_text, function(data) { localThis.onPerformanceLoaded(JSON.parse(data)); }); + } +} + Director.prototype.onPerformanceLoaded = function(performanceJSON) { // First fire all the current actors this.clearActors(); @@ -377,6 +391,11 @@ function update(deltaTime) { moveUI(); } + if (director.requestPerformanceLoad) { + print("reloadPerformance " + director.performanceURL); + director.reloadPerformance(); + } + masterController.update(deltaTime); }