mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 09:37:29 +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);
|
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
|
// master side
|
||||||
//---------------------------------
|
//---------------------------------
|
||||||
var MasterController = function() {
|
var MasterController = function() {
|
||||||
this.timeSinceLastAlive = 0;
|
this.timeSinceLastAlive = 0;
|
||||||
this.knownAgents = new Array;
|
this.knownAgents = new Array;
|
||||||
|
this.hiredActors = new Array;
|
||||||
this.hiringAgentsQueue = new Array;
|
this.hiringAgentsQueue = new Array;
|
||||||
this.subscribed = false;
|
this.subscribed = false;
|
||||||
};
|
};
|
||||||
|
@ -126,6 +137,10 @@ function printDebug(message) {
|
||||||
if (agentIndex < 0) {
|
if (agentIndex < 0) {
|
||||||
printDebug("Lost agent " + message.src + " " + agentIndex + " Forgeting about it");
|
printDebug("Lost agent " + message.src + " " + agentIndex + " Forgeting about it");
|
||||||
this.knownAgents[agentIndex] = INVALID_ACTOR;
|
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;
|
var localThis = this;
|
||||||
this.hiringAgentsQueue.unshift(function(agentID) {
|
this.hiringAgentsQueue.unshift(function(agentID) {
|
||||||
printDebug("hiring callback with agent " + agentID);
|
printDebug("hiring callback with agent " + agentID+ " " + JSON.stringify(localThis) );
|
||||||
|
|
||||||
var indexOfNewAgent = localThis.knownAgents.length;
|
var indexOfNewAgent = localThis.knownAgents.push(agentID)
|
||||||
localThis.knownAgents[indexOfNewAgent] = agentID;
|
actor.agentID = agentID;
|
||||||
|
localThis.hiredActors.push(actor);
|
||||||
|
|
||||||
printDebug("New agent available to be hired " + agentID + " " + index);
|
printDebug("New agent available to be hired " + agentID + " " + indexOfNewAgent);
|
||||||
var hireMessage = "HIRE." + index;
|
var hireMessage = "HIRE." + indexOfNewAgent;
|
||||||
var answerMessage = packAnnounceMessage(agentID, hireMessage, MASTER_ID);
|
var answerMessage = packAnnounceMessage(agentID, hireMessage, MASTER_ID);
|
||||||
Messages.sendMessage(ANNOUNCE_CHANNEL, answerMessage);
|
Messages.sendMessage(ANNOUNCE_CHANNEL, answerMessage);
|
||||||
|
|
||||||
|
printDebug("message sent calling the actor" + JSON.stringify(actor) );
|
||||||
|
|
||||||
if (onHired != null) {
|
actor.onHired(actor);
|
||||||
onHired(index);
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -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 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 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 input_text = null;
|
||||||
|
var actors = new Array();
|
||||||
|
|
||||||
// Script. DO NOT MODIFY BEYOND THIS LINE.
|
// Script. DO NOT MODIFY BEYOND THIS LINE.
|
||||||
//Script.include("../libraries/toolBars.js");
|
//Script.include("../libraries/toolBars.js");
|
||||||
|
@ -54,8 +54,14 @@ var performanceLoadedNeedUpdate = false;
|
||||||
|
|
||||||
setupPlayback();
|
setupPlayback();
|
||||||
|
|
||||||
function onHiring(agentID, index) {
|
function onActorHired(actor) {
|
||||||
print("agent hired from playbackMaster! " + agentID + " " + index)
|
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() {
|
function setupPlayback() {
|
||||||
|
@ -66,7 +72,12 @@ function setupPlayback() {
|
||||||
masterController.reset();
|
masterController.reset();
|
||||||
|
|
||||||
for (var i = 0; i < ac_number; i++) {
|
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();
|
setupToolBars();
|
||||||
|
|
Loading…
Reference in a new issue