Separating the ui to get the url from the actual loading to maybe avoid playbackMaster.js crash?

This commit is contained in:
samcake 2015-12-01 12:36:49 -08:00
parent 921cd94c07
commit ff3ae85245
2 changed files with 53 additions and 28 deletions

View file

@ -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];

View file

@ -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);
}