mirror of
https://github.com/overte-org/overte.git
synced 2025-04-19 15:03:53 +02:00
Getting the Actor class starting to work and usable for the playback master!
This commit is contained in:
parent
3273fbcad4
commit
37d3083e07
2 changed files with 45 additions and 14 deletions
|
@ -65,11 +65,22 @@ function printDebug(message) {
|
|||
return JSON.parse(message);
|
||||
};
|
||||
|
||||
// Actor
|
||||
//---------------------------------
|
||||
var Actor = function() {
|
||||
this.agentID = INVALID_ACTOR;
|
||||
this.onHired = function(actor) {};
|
||||
this.onLost = function(actor) {};
|
||||
};
|
||||
|
||||
this.Actor = Actor;
|
||||
|
||||
// master side
|
||||
//---------------------------------
|
||||
var MasterController = function() {
|
||||
this.timeSinceLastAlive = 0;
|
||||
this.knownAgents = new Array;
|
||||
this.hiredActors = new Array;
|
||||
this.hiringAgentsQueue = new Array;
|
||||
this.subscribed = false;
|
||||
};
|
||||
|
@ -126,6 +137,10 @@ function printDebug(message) {
|
|||
if (agentIndex < 0) {
|
||||
printDebug("Lost agent " + message.src + " " + agentIndex + " Forgeting about it");
|
||||
this.knownAgents[agentIndex] = INVALID_ACTOR;
|
||||
var lostActor = this.hiredActors[agentIndex];
|
||||
this.hiredActors[agentIndex] = null;
|
||||
lostActor.agentID = INVALID_ACTOR;
|
||||
lostActor.onLost(lostActor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -147,22 +162,27 @@ function printDebug(message) {
|
|||
};
|
||||
|
||||
|
||||
MasterController.prototype.hireAgent = function(onHired) {
|
||||
MasterController.prototype.hireAgent = function(actor) {
|
||||
if (actor == null) {
|
||||
printDebug("trying to hire an agent with a null actor, abort");
|
||||
return;
|
||||
}
|
||||
var localThis = this;
|
||||
this.hiringAgentsQueue.unshift(function(agentID) {
|
||||
printDebug("hiring callback with agent " + agentID);
|
||||
|
||||
var indexOfNewAgent = localThis.knownAgents.length;
|
||||
localThis.knownAgents[indexOfNewAgent] = agentID;
|
||||
printDebug("hiring callback with agent " + agentID+ " " + JSON.stringify(localThis) );
|
||||
|
||||
var indexOfNewAgent = localThis.knownAgents.push(agentID)
|
||||
actor.agentID = agentID;
|
||||
localThis.hiredActors.push(actor);
|
||||
|
||||
printDebug("New agent available to be hired " + agentID + " " + index);
|
||||
var hireMessage = "HIRE." + index;
|
||||
printDebug("New agent available to be hired " + agentID + " " + indexOfNewAgent);
|
||||
var hireMessage = "HIRE." + indexOfNewAgent;
|
||||
var answerMessage = packAnnounceMessage(agentID, hireMessage, MASTER_ID);
|
||||
Messages.sendMessage(ANNOUNCE_CHANNEL, answerMessage);
|
||||
|
||||
printDebug("message sent calling the actor" + JSON.stringify(actor) );
|
||||
|
||||
if (onHired != null) {
|
||||
onHired(index);
|
||||
}
|
||||
actor.onHired(actor);
|
||||
})
|
||||
};
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ var masterController = new MasterController();
|
|||
var ac_number = 1; // This is the default number of ACs. Their ID need to be unique and between 0 (included) and ac_number (excluded)
|
||||
var names = new Array(); // It is possible to specify the name of the ACs in this array. ACs names ordered by IDs (Default name is "ACx", x = ID + 1))
|
||||
var input_text = null;
|
||||
|
||||
var actors = new Array();
|
||||
|
||||
// Script. DO NOT MODIFY BEYOND THIS LINE.
|
||||
//Script.include("../libraries/toolBars.js");
|
||||
|
@ -54,8 +54,14 @@ var performanceLoadedNeedUpdate = false;
|
|||
|
||||
setupPlayback();
|
||||
|
||||
function onHiring(agentID, index) {
|
||||
print("agent hired from playbackMaster! " + agentID + " " + index)
|
||||
function onActorHired(actor) {
|
||||
print("agent hired from playbackMaster! " + actor.agentID + " " + actor.index)
|
||||
}
|
||||
|
||||
function onActorLost(actor) {
|
||||
print("agent lost from playbackMaster! " + actor.agentID + " " + actor.index)
|
||||
|
||||
actors[actor.index] = null;
|
||||
}
|
||||
|
||||
function setupPlayback() {
|
||||
|
@ -66,7 +72,12 @@ function setupPlayback() {
|
|||
masterController.reset();
|
||||
|
||||
for (var i = 0; i < ac_number; i++) {
|
||||
masterController.hireAgent(onHiring);
|
||||
var newActor = new Actor();
|
||||
newActor.index = i;
|
||||
newActor.onHired = onActorHired;
|
||||
newActor.onLost = onActorLost;
|
||||
masterController.hireAgent(newActor);
|
||||
actors.push(newActor);
|
||||
}
|
||||
|
||||
setupToolBars();
|
||||
|
|
Loading…
Reference in a new issue