Finally a more stable api and playback use case

This commit is contained in:
Sam Cake 2015-12-01 00:15:12 -08:00
parent 196f7e71c4
commit 921cd94c07
3 changed files with 23 additions and 47 deletions

View file

@ -192,27 +192,22 @@ function printDebug(message) {
this.timeSinceLastAlive = 0; this.timeSinceLastAlive = 0;
Messages.sendMessage(SERVICE_CHANNEL, packServiceMessage(BROADCAST_AGENTS, MASTER_ALIVE, MASTER_ID)); Messages.sendMessage(SERVICE_CHANNEL, packServiceMessage(BROADCAST_AGENTS, MASTER_ALIVE, MASTER_ID));
printDebug("checking the agents status");
{ {
// Check for alive connected agents // Check for alive connected agents
var lostAgents = new Array(); var lostAgents = new Array();
for (var i = 0; i < this.hiredActors.length; i++) { for (var i = 0; i < this.hiredActors.length; i++) {
var actor = this.hiredActors[i]; var actor = this.hiredActors[i];
printDebug("checking :" + JSON.stringify(actor));
var lastAlive = actor.incrementAliveCycle() var lastAlive = actor.incrementAliveCycle()
if (lastAlive > NUM_CYCLES_BEFORE_RESET) { if (lastAlive > NUM_CYCLES_BEFORE_RESET) {
printDebug("Agent Lost, firing Agent"); printDebug("Agent Lost, firing Agent #" + i + JSON.stringify(actor));
lostAgents.push(actor); lostAgents.push(i);
} }
} }
// now fire gathered lost agents // now fire gathered lost agents from end to begin
if (lostAgents.length > 0) { while (lostAgents.length > 0) {
printDebug("Firing " + lostAgents.length + " agents" + JSON.stringify(lostAgents)); printDebug("Firing " + lostAgents.length + " agents" + JSON.stringify(lostAgents));
this.fireAgent(this.hiredActors[lostAgents.pop()]);
for (var i = 0; i < lostAgents.length; i++) {
this.fireAgent(lostAgents[l]);
}
} }
} }
} }
@ -251,7 +246,7 @@ function printDebug(message) {
MasterController.prototype._removeAgent = function(actorIndex) { MasterController.prototype._removeAgent = function(actorIndex) {
// check to see if we know about this agent // check to see if we know about this agent
if (actorIndex >= 0) { if (actorIndex >= 0) {
printDebug("before _removeAgent #" + actorIndex + " " + JSON.stringify(this)) printDebug("MasterController.prototype._removeAgent #" + actorIndex + " " + JSON.stringify(this))
this.knownAgents.splice(actorIndex, 1); this.knownAgents.splice(actorIndex, 1);
var lostActor = this.hiredActors[actorIndex]; var lostActor = this.hiredActors[actorIndex];
@ -260,9 +255,6 @@ function printDebug(message) {
var lostAgentID = lostActor.agentID; var lostAgentID = lostActor.agentID;
lostActor.agentID = INVALID_AGENT; lostActor.agentID = INVALID_AGENT;
printDebug("Clearing agent " + actorIndex + " Forgeting about it");
printDebug("after _removeAgent #" + actorIndex + " " + JSON.stringify(this))
if (lostAgentID != INVALID_AGENT) { if (lostAgentID != INVALID_AGENT) {
printDebug("fired actor is still connected, send fire command"); printDebug("fired actor is still connected, send fire command");
Messages.sendMessage(SERVICE_CHANNEL, packServiceMessage(lostAgentID, MASTER_FIRE_AGENT, MASTER_ID)); Messages.sendMessage(SERVICE_CHANNEL, packServiceMessage(lostAgentID, MASTER_FIRE_AGENT, MASTER_ID));

View file

@ -9,9 +9,6 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // 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"); Script.include("./AgentPoolControler.js");
var agentController = new AgentController(); var agentController = new AgentController();
@ -34,8 +31,6 @@ var WAIT_FOR_AUDIO_MIXER = 1;
var PLAY = 1; var PLAY = 1;
var PLAY_LOOP = 2; var PLAY_LOOP = 2;
var STOP = 3; var STOP = 3;
var SHOW = 4;
var HIDE = 5;
var LOAD = 6; var LOAD = 6;
Recording.setPlayFromCurrentLocation(playFromCurrentLocation); Recording.setPlayFromCurrentLocation(playFromCurrentLocation);
@ -71,28 +66,13 @@ function agentCommand(command) {
Recording.stopPlaying(); Recording.stopPlaying();
} }
break; break;
case SHOW:
print("Show");
break;
case HIDE:
print("Hide");
if (Recording.isPlaying()) {
Recording.stopPlaying();
}
break;
case LOAD: case LOAD:
{ {
print("Load" + command.argument_key); print("Load" + command.argument_key);
print("Agent #" + command.dest_key + " loading clip URL: " + command.argument_key); print("Agent #" + command.dest_key + " loading clip URL: " + command.argument_key);
Recording.loadRecording(command.argument_key); Recording.loadRecording(command.argument_key);
print("After Load" + command.argument_key); print("After Load" + command.argument_key);
Recording.setPlayerTime(0);
/*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);
}*/
} }
break; break;
default: default:
@ -105,17 +85,18 @@ function agentCommand(command) {
function agentHired() { function agentHired() {
print("Agent Hired from playbackAgents.js"); print("Agent Hired from playbackAgents.js");
if (Recording.isPlaying()) { Agent.isAvatar = true;
Recording.stopPlaying(); Recording.stopPlaying();
}
Recording.setPlayerLoop(false); Recording.setPlayerLoop(false);
Recording.setPlayerTime(0);
} }
function agentFired() { function agentFired() {
print("Agent Fired from playbackAgents.js"); print("Agent Fired from playbackAgents.js");
if (Recording.isPlaying()) { Recording.stopPlaying();
Recording.stopPlaying(); Recording.setPlayerTime(0);
} Recording.setPlayerLoop(false);
Agent.isAvatar = false;
} }

View file

@ -26,8 +26,6 @@ Tool.IMAGE_WIDTH /= 2;
var PLAY = 1; var PLAY = 1;
var PLAY_LOOP = 2; var PLAY_LOOP = 2;
var STOP = 3; var STOP = 3;
var SHOW = 4;
var HIDE = 5;
var LOAD = 6; var LOAD = 6;
var windowDimensions = Controller.getViewportDimensions(); var windowDimensions = Controller.getViewportDimensions();
@ -42,10 +40,6 @@ var TEXT_MARGIN = 3;
// Add new features to Actor class: // Add new features to Actor class:
Actor.prototype.destroy = function() { Actor.prototype.destroy = function() {
print("Actor.prototype.destroy"); print("Actor.prototype.destroy");
this.toolbar.cleanup();
Overlays.deleteOverlay(this.nameOverlay);
print("Need to fire myself" + this.agentID); print("Need to fire myself" + this.agentID);
masterController.fireAgent(this); 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) { Actor.prototype.moveUI = function(pos) {
var textSize = TEXT_HEIGHT + 2 * TEXT_MARGIN; var textSize = TEXT_HEIGHT + 2 * TEXT_MARGIN;
this.toolbar.move(pos.x, pos.y); this.toolbar.move(pos.x, pos.y);
@ -329,6 +328,9 @@ Director.prototype.hireActor = function(clipURL) {
if (index >= 0) { if (index >= 0) {
localThis.actors.splice(index, 1); localThis.actors.splice(index, 1);
} }
actor._destroyUI();
actor.destroy(); actor.destroy();
moveUI(); moveUI();
} }
@ -338,6 +340,7 @@ Director.prototype.hireActor = function(clipURL) {
masterController.sendCommand(actor.agentID, LOAD, actor.clipURL); masterController.sendCommand(actor.agentID, LOAD, actor.clipURL);
}); });
masterController.hireAgent(newActor); masterController.hireAgent(newActor);
newActor._buildUI(); newActor._buildUI();