mirror of
https://github.com/SWG-Source/dsrc.git
synced 2026-10-13 04:13:01 -04:00
who isn't sick of converting the freaking scripts? this negates the need
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
package script.base;
|
||||
|
||||
import script.*;
|
||||
import script.base_class.*;
|
||||
import script.combat_engine.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Vector;
|
||||
import script.base_script;
|
||||
|
||||
public class remote_object extends script.base_script
|
||||
{
|
||||
public remote_object()
|
||||
{
|
||||
}
|
||||
public static final String REMOTE_OBJECT_MANAGER = "remote_object_manager";
|
||||
public static final String BASE_NAME = "remote_object";
|
||||
public static final String ATTACH_SCRIPTS = BASE_NAME + ".attachScripts";
|
||||
public static final String CREATE_PARAMS = BASE_NAME + ".createParams";
|
||||
public static final String CREATOR = BASE_NAME + ".creator";
|
||||
public static final String IN_SPACE = BASE_NAME + ".inSpace";
|
||||
public static final String OBJECT_NAME = BASE_NAME + ".objectName";
|
||||
public static final String REMOTE_OBJECT = BASE_NAME + ".remoteObject";
|
||||
public static final String REQUESTER = BASE_NAME + ".requester";
|
||||
public static final String SCENE_NAME = BASE_NAME + ".sceneName";
|
||||
public static final String USE_RANDOM_LOCATION = BASE_NAME + ".useRandomLocation";
|
||||
public static final String X = BASE_NAME + ".x";
|
||||
public static final String Y = BASE_NAME + ".y";
|
||||
public static final String Z = BASE_NAME + ".z";
|
||||
public static final String CREATE_REMOTE_OBJECT = "createRemoteObject";
|
||||
public static final String CREATE_REMOTE_OBJECT_RESPONSE = "createRemoteObjectResponse";
|
||||
public static final String RO = "RemoteObject";
|
||||
public static final boolean LOGS_ENABLED = false;
|
||||
public void log(String text) throws InterruptedException
|
||||
{
|
||||
log(text, LOGS_ENABLED);
|
||||
}
|
||||
public void logError(String text) throws InterruptedException
|
||||
{
|
||||
log("Error:" + text, true);
|
||||
}
|
||||
public void log(String text, boolean force) throws InterruptedException
|
||||
{
|
||||
if (LOGS_ENABLED || force)
|
||||
{
|
||||
LOG(RO, text);
|
||||
}
|
||||
}
|
||||
public boolean logsEnabled() throws InterruptedException
|
||||
{
|
||||
return LOGS_ENABLED;
|
||||
}
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
// =====================================================================
|
||||
// remote_object.script
|
||||
// =====================================================================
|
||||
|
||||
//-- cluster wide data object manager
|
||||
const String REMOTE_OBJECT_MANAGER = "remote_object_manager";
|
||||
|
||||
//-- parameter prefix
|
||||
const String BASE_NAME = "remote_object";
|
||||
|
||||
//-- parameters
|
||||
const String ATTACH_SCRIPTS = BASE_NAME + ".attachScripts";
|
||||
const String CREATE_PARAMS = BASE_NAME + ".createParams";
|
||||
const String CREATOR = BASE_NAME + ".creator";
|
||||
const String IN_SPACE = BASE_NAME + ".inSpace";
|
||||
const String OBJECT_NAME = BASE_NAME + ".objectName";
|
||||
const String REMOTE_OBJECT = BASE_NAME + ".remoteObject";
|
||||
const String REQUESTER = BASE_NAME + ".requester";
|
||||
const String SCENE_NAME = BASE_NAME + ".sceneName";
|
||||
const String USE_RANDOM_LOCATION = BASE_NAME + ".useRandomLocation";
|
||||
const String X = BASE_NAME + ".x";
|
||||
const String Y = BASE_NAME + ".y";
|
||||
const String Z = BASE_NAME + ".z";
|
||||
|
||||
//-- message handlers
|
||||
const String CREATE_REMOTE_OBJECT = "createRemoteObject";
|
||||
const String CREATE_REMOTE_OBJECT_RESPONSE= "createRemoteObjectResponse";
|
||||
|
||||
//-- logging
|
||||
const String RO = "RemoteObject";
|
||||
const boolean LOGS_ENABLED = false;
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
void log(String text)
|
||||
{
|
||||
log(text, LOGS_ENABLED);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
void logError(String text)
|
||||
{
|
||||
log("Error:" + text, true);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
void log(String text, boolean force)
|
||||
{
|
||||
if (LOGS_ENABLED || force)
|
||||
{
|
||||
LOG(RO, text);
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
boolean logsEnabled()
|
||||
{
|
||||
return LOGS_ENABLED;
|
||||
}
|
||||
|
||||
// =====================================================================
|
||||
@@ -0,0 +1,99 @@
|
||||
package script.base;
|
||||
|
||||
import script.*;
|
||||
import script.base_class.*;
|
||||
import script.combat_engine.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Vector;
|
||||
import script.base_script;
|
||||
|
||||
import script.library.create;
|
||||
import script.library.space_create;
|
||||
import script.library.space_quest;
|
||||
import script.library.utils;
|
||||
|
||||
public class remote_object_creator extends script.base.remote_object
|
||||
{
|
||||
public remote_object_creator()
|
||||
{
|
||||
}
|
||||
public void registerForRemoteObjectCreation(obj_id self) throws InterruptedException
|
||||
{
|
||||
log("registerForRemoteObjectCreation: setting cluster wide data.");
|
||||
dictionary objectData = new dictionary();
|
||||
objectData.put(CREATOR, self);
|
||||
objectData.put(IN_SPACE, isSpaceScene());
|
||||
replaceClusterWideData(REMOTE_OBJECT_MANAGER, getCurrentSceneName(), objectData, false, 0);
|
||||
}
|
||||
public int createRemoteObject(obj_id self, dictionary params) throws InterruptedException
|
||||
{
|
||||
log("createRemoteObject: message received.");
|
||||
log("createRemoteObject: " + params.toString());
|
||||
obj_id requester = params.getObjId(REQUESTER);
|
||||
String objectName = params.getString(OBJECT_NAME);
|
||||
boolean useRandomLocation = params.getBoolean(USE_RANDOM_LOCATION);
|
||||
float x, y, z;
|
||||
if (!useRandomLocation)
|
||||
{
|
||||
x = params.getFloat(X);
|
||||
y = params.getFloat(Y);
|
||||
z = params.getFloat(Z);
|
||||
}
|
||||
else
|
||||
{
|
||||
x = y = z = 0;
|
||||
}
|
||||
obj_id created;
|
||||
if (isSpaceScene())
|
||||
{
|
||||
if (!useRandomLocation)
|
||||
{
|
||||
created = space_create.createShip(objectName, transform.identity.setPosition_p(x, y, z));
|
||||
}
|
||||
else
|
||||
{
|
||||
transform randomTransform = space_quest.getRandomPositionInSphere(transform.identity, 512, 2048);
|
||||
vector pos = randomTransform.getPosition_p();
|
||||
params.put(X, pos.x);
|
||||
params.put(Y, pos.y);
|
||||
params.put(Z, pos.z);
|
||||
created = space_create.createShipHyperspace(objectName, randomTransform);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
created = create.object(objectName, new location(x, y, z));
|
||||
}
|
||||
params.put(SCENE_NAME, getCurrentSceneName());
|
||||
if (isValidId(created))
|
||||
{
|
||||
log("createRemoteObject: creation successful. [" + objectName + "][" + created + "]");
|
||||
utils.setScriptVar(created, REQUESTER, requester);
|
||||
utils.setScriptVar(created, CREATE_PARAMS, params);
|
||||
if (params.containsKey(ATTACH_SCRIPTS))
|
||||
{
|
||||
String[] scripts = split(params.getString(ATTACH_SCRIPTS), ':');
|
||||
for (int i = 0; i < scripts.length; ++i)
|
||||
{
|
||||
if (!hasScript(created, scripts[i]))
|
||||
{
|
||||
attachScript(created, scripts[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
logError("createRemoteObject: creation failed.");
|
||||
}
|
||||
params.put(REMOTE_OBJECT, created);
|
||||
messageTo(requester, CREATE_REMOTE_OBJECT_RESPONSE, params, 0.0f, false);
|
||||
return SCRIPT_CONTINUE;
|
||||
}
|
||||
public int OnInitialize(obj_id self) throws InterruptedException
|
||||
{
|
||||
registerForRemoteObjectCreation(self);
|
||||
return SCRIPT_CONTINUE;
|
||||
}
|
||||
}
|
||||
@@ -1,138 +0,0 @@
|
||||
// =====================================================================
|
||||
// remote_object_creator.script
|
||||
// =====================================================================
|
||||
|
||||
include library.create;
|
||||
include library.space_create;
|
||||
include library.space_quest;
|
||||
include library.utils;
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
inherits base.remote_object;
|
||||
|
||||
// =====================================================================
|
||||
|
||||
/**
|
||||
* Register an object for remote object creation.
|
||||
* Self is registered to be available to create objects in its scene.
|
||||
*/
|
||||
void registerForRemoteObjectCreation(obj_id self)
|
||||
{
|
||||
log("registerForRemoteObjectCreation: setting cluster wide data.");
|
||||
|
||||
dictionary objectData = new dictionary();
|
||||
objectData.put(CREATOR, self);
|
||||
objectData.put(IN_SPACE, isSpaceScene());
|
||||
|
||||
//-- may want to put scene loading data here as well ... (and periodically update it)
|
||||
|
||||
replaceClusterWideData(REMOTE_OBJECT_MANAGER, getCurrentSceneName(), objectData, false, 0);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Create a remote object.
|
||||
* Set an script var on the created object to the object id of the requester for future communication.
|
||||
* Send a message back to the requester with the object id of the object created.
|
||||
* This will be an invalid id if creation fails.
|
||||
*/
|
||||
messageHandler createRemoteObject()
|
||||
{
|
||||
log("createRemoteObject: message received.");
|
||||
log("createRemoteObject: " + params.toString());
|
||||
|
||||
//-- read input parameters
|
||||
obj_id requester = params.getObjId(REQUESTER);
|
||||
String objectName = params.getString(OBJECT_NAME);
|
||||
boolean useRandomLocation = params.getBoolean(USE_RANDOM_LOCATION);
|
||||
float x, y, z;
|
||||
|
||||
if (!useRandomLocation)
|
||||
{
|
||||
x = params.getFloat(X);
|
||||
y = params.getFloat(Y);
|
||||
z = params.getFloat(Z);
|
||||
}
|
||||
else
|
||||
{
|
||||
x = y = z = 0;
|
||||
}
|
||||
|
||||
//-- create the object in the current scene
|
||||
obj_id created;
|
||||
|
||||
if (isSpaceScene())
|
||||
{
|
||||
if (!useRandomLocation)
|
||||
{
|
||||
created = space_create.createShip(objectName, transform.identity.setPosition_p(x, y, z));
|
||||
}
|
||||
else
|
||||
{
|
||||
//-- determine a random location
|
||||
transform randomTransform = space_quest.getRandomPositionInSphere(transform.identity, 512, 2048);
|
||||
|
||||
vector pos = randomTransform.getPosition_p();
|
||||
params.put(X, pos.x);
|
||||
params.put(Y, pos.y);
|
||||
params.put(Z, pos.z);
|
||||
|
||||
//created = space_create.createShip(objectName, randomTransform);
|
||||
created = space_create.createShipHyperspace(objectName, randomTransform);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
created = create.object(objectName, new location(x, y, z));
|
||||
}
|
||||
|
||||
params.put(SCENE_NAME, getCurrentSceneName());
|
||||
|
||||
//-- validation
|
||||
if (isValidId(created))
|
||||
{
|
||||
log("createRemoteObject: creation successful. [" + objectName + "][" + created + "]");
|
||||
utils.setScriptVar(created, REQUESTER, requester);
|
||||
utils.setScriptVar(created, CREATE_PARAMS, params);
|
||||
|
||||
if (params.containsKey(ATTACH_SCRIPTS))
|
||||
{
|
||||
String[] scripts = split(params.getString(ATTACH_SCRIPTS), ':');
|
||||
for (int i=0; i<scripts.length; ++i)
|
||||
{
|
||||
if (!hasScript(created, scripts[i]))
|
||||
{
|
||||
attachScript(created, scripts[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
logError("createRemoteObject: creation failed.");
|
||||
}
|
||||
|
||||
//-- if the creation fails, the object id returned will be invalid
|
||||
params.put(REMOTE_OBJECT, created);
|
||||
|
||||
//-- return message to requester
|
||||
messageTo(requester, CREATE_REMOTE_OBJECT_RESPONSE, params, 0.0f, false);
|
||||
|
||||
return SCRIPT_CONTINUE;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Register the object for remote object creation.
|
||||
*/
|
||||
trigger OnInitialize()
|
||||
{
|
||||
registerForRemoteObjectCreation(self);
|
||||
|
||||
return SCRIPT_CONTINUE;
|
||||
}
|
||||
|
||||
// =====================================================================
|
||||
@@ -0,0 +1,176 @@
|
||||
package script.base;
|
||||
|
||||
import script.*;
|
||||
import script.base_class.*;
|
||||
import script.combat_engine.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Vector;
|
||||
import script.base_script;
|
||||
|
||||
import script.library.utils;
|
||||
|
||||
public class remote_object_requester extends script.base.remote_object
|
||||
{
|
||||
public remote_object_requester()
|
||||
{
|
||||
}
|
||||
public int OnClusterWideDataResponse(obj_id self, String managerName, String elementNameExp, int requestId, String[] elementNameList, dictionary[] dictionaryList, int lockKey) throws InterruptedException
|
||||
{
|
||||
if (logsEnabled())
|
||||
{
|
||||
log("OnClusterWideDataResponse() manager name (" + managerName + ") element name (" + elementNameExp + ") request id (" + requestId + ") match count (" + elementNameList.length + ") lock key (" + lockKey + ")");
|
||||
for (int i = 0; i < elementNameList.length; ++i)
|
||||
{
|
||||
log("element " + (i + 1) + " is (" + elementNameList[i] + ")");
|
||||
log("dictionary " + dictionaryList[i].toString());
|
||||
}
|
||||
}
|
||||
if (managerName.equals(REMOTE_OBJECT_MANAGER))
|
||||
{
|
||||
if (dictionaryList.length < 1)
|
||||
{
|
||||
logError("No object available for remote creation. [" + elementNameExp + "]");
|
||||
}
|
||||
else if (!hasValidCreateScriptVars(self, requestId))
|
||||
{
|
||||
logError("Missing script vars for this request! [" + requestId + "]");
|
||||
}
|
||||
else if (utils.hasScriptVar(self, getSceneNameVarName(requestId)) && !elementNameExp.equals(getSceneName(self, requestId)))
|
||||
{
|
||||
logError("Wrong scene! [" + elementNameExp + "][" + getSceneName(self, requestId) + "]");
|
||||
}
|
||||
else
|
||||
{
|
||||
obj_id remoteObjectCreator = getRemoteObjectCreator(self, requestId, elementNameList, dictionaryList);
|
||||
if (isValidId(remoteObjectCreator))
|
||||
{
|
||||
messageTo(remoteObjectCreator, CREATE_REMOTE_OBJECT, getRemoteCreateParams(self, requestId), 0.0f, false);
|
||||
log("Remote object creation request sent!");
|
||||
}
|
||||
else
|
||||
{
|
||||
logError("No valid remote object creator found!");
|
||||
}
|
||||
}
|
||||
removeRemoteCreateScriptVars(self, requestId);
|
||||
}
|
||||
return SCRIPT_CONTINUE;
|
||||
}
|
||||
public int createRemoteObjectResponse(obj_id self, dictionary params) throws InterruptedException
|
||||
{
|
||||
log("createRemoteObjectResponse: " + params.toString());
|
||||
obj_id remoteObject = params.getObjId(REMOTE_OBJECT);
|
||||
if (isValidId(remoteObject))
|
||||
{
|
||||
log("Successfully created " + remoteObject);
|
||||
}
|
||||
else
|
||||
{
|
||||
logError("Creation failed!");
|
||||
}
|
||||
return SCRIPT_CONTINUE;
|
||||
}
|
||||
public void remoteCreate(String sceneName, String objectName, float x, float y, float z) throws InterruptedException
|
||||
{
|
||||
obj_id self = getSelf();
|
||||
int requestId = getClusterWideData(REMOTE_OBJECT_MANAGER, sceneName, false, self);
|
||||
utils.setScriptVar(self, getSceneNameVarName(requestId), sceneName);
|
||||
utils.setScriptVar(self, getObjectNameVarName(requestId), objectName);
|
||||
utils.setScriptVar(self, getUseRandomLocationVarName(requestId), false);
|
||||
utils.setScriptVar(self, getXVarName(requestId), x);
|
||||
utils.setScriptVar(self, getYVarName(requestId), y);
|
||||
utils.setScriptVar(self, getZVarName(requestId), z);
|
||||
}
|
||||
public void remoteCreate(String sceneName, String objectName) throws InterruptedException
|
||||
{
|
||||
obj_id self = getSelf();
|
||||
int requestId = getClusterWideData(REMOTE_OBJECT_MANAGER, sceneName, false, self);
|
||||
utils.setScriptVar(self, getSceneNameVarName(requestId), sceneName);
|
||||
utils.setScriptVar(self, getObjectNameVarName(requestId), objectName);
|
||||
utils.setScriptVar(self, getUseRandomLocationVarName(requestId), true);
|
||||
}
|
||||
public int remoteCreate() throws InterruptedException
|
||||
{
|
||||
obj_id self = getSelf();
|
||||
int requestId = getClusterWideData(REMOTE_OBJECT_MANAGER, "*", false, self);
|
||||
return requestId;
|
||||
}
|
||||
public String getSceneNameVarName(int requestId) throws InterruptedException
|
||||
{
|
||||
return SCENE_NAME + "." + requestId;
|
||||
}
|
||||
public String getSceneName(obj_id self, int requestId) throws InterruptedException
|
||||
{
|
||||
return utils.getStringScriptVar(self, getSceneNameVarName(requestId));
|
||||
}
|
||||
public String getObjectNameVarName(int requestId) throws InterruptedException
|
||||
{
|
||||
return OBJECT_NAME + "." + requestId;
|
||||
}
|
||||
public String getObjectName(obj_id self, int requestId) throws InterruptedException
|
||||
{
|
||||
return utils.getStringScriptVar(self, getObjectNameVarName(requestId));
|
||||
}
|
||||
public String getXVarName(int requestId) throws InterruptedException
|
||||
{
|
||||
return X + "." + requestId;
|
||||
}
|
||||
public float getX(obj_id self, int requestId) throws InterruptedException
|
||||
{
|
||||
return utils.getFloatScriptVar(self, getXVarName(requestId));
|
||||
}
|
||||
public String getYVarName(int requestId) throws InterruptedException
|
||||
{
|
||||
return Y + "." + requestId;
|
||||
}
|
||||
public float getY(obj_id self, int requestId) throws InterruptedException
|
||||
{
|
||||
return utils.getFloatScriptVar(self, getYVarName(requestId));
|
||||
}
|
||||
public String getZVarName(int requestId) throws InterruptedException
|
||||
{
|
||||
return Z + "." + requestId;
|
||||
}
|
||||
public float getZ(obj_id self, int requestId) throws InterruptedException
|
||||
{
|
||||
return utils.getFloatScriptVar(self, getZVarName(requestId));
|
||||
}
|
||||
public String getUseRandomLocationVarName(int requestId) throws InterruptedException
|
||||
{
|
||||
return USE_RANDOM_LOCATION + "." + requestId;
|
||||
}
|
||||
public boolean getUseRandomLocationVarName(obj_id self, int requestId) throws InterruptedException
|
||||
{
|
||||
return utils.getBooleanScriptVar(self, getUseRandomLocationVarName(requestId));
|
||||
}
|
||||
public void removeRemoteCreateScriptVars(obj_id self, int requestId) throws InterruptedException
|
||||
{
|
||||
utils.removeScriptVar(self, getSceneNameVarName(requestId));
|
||||
utils.removeScriptVar(self, getObjectNameVarName(requestId));
|
||||
utils.removeScriptVar(self, getXVarName(requestId));
|
||||
utils.removeScriptVar(self, getYVarName(requestId));
|
||||
utils.removeScriptVar(self, getZVarName(requestId));
|
||||
}
|
||||
public boolean hasValidCreateScriptVars(obj_id self, int requestId) throws InterruptedException
|
||||
{
|
||||
return utils.hasScriptVar(self, getSceneNameVarName(requestId)) && utils.hasScriptVar(self, getObjectNameVarName(requestId));
|
||||
}
|
||||
public dictionary getRemoteCreateParams(obj_id self, int requestId) throws InterruptedException
|
||||
{
|
||||
dictionary createParams = new dictionary();
|
||||
createParams.put(REQUESTER, self);
|
||||
createParams.put(SCENE_NAME, getSceneName(self, requestId));
|
||||
createParams.put(OBJECT_NAME, getObjectName(self, requestId));
|
||||
createParams.put(X, getX(self, requestId));
|
||||
createParams.put(Y, getY(self, requestId));
|
||||
createParams.put(Z, getZ(self, requestId));
|
||||
return createParams;
|
||||
}
|
||||
public obj_id getRemoteObjectCreator(obj_id self, int requestId, String[] elementNameList, dictionary[] dictionaryList) throws InterruptedException
|
||||
{
|
||||
int randomIndex = rand(0, dictionaryList.length);
|
||||
obj_id remoteObjectCreator = dictionaryList[randomIndex].getObjId(CREATOR);
|
||||
return remoteObjectCreator;
|
||||
}
|
||||
}
|
||||
@@ -1,271 +0,0 @@
|
||||
// =====================================================================
|
||||
// remote_object_requester.script
|
||||
// =====================================================================
|
||||
|
||||
include library.utils;
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
inherits base.remote_object;
|
||||
|
||||
// ======================================================================
|
||||
|
||||
trigger OnClusterWideDataResponse(String managerName, String elementNameExp, int requestId,
|
||||
String[] elementNameList, dictionary[] dictionaryList, int lockKey)
|
||||
{
|
||||
if (logsEnabled())
|
||||
{
|
||||
log("OnClusterWideDataResponse() manager name (" + managerName + ") element name ("
|
||||
+ elementNameExp + ") request id (" + requestId + ") match count (" + elementNameList.length
|
||||
+ ") lock key (" + lockKey + ")");
|
||||
|
||||
for (int i = 0; i < elementNameList.length; ++i)
|
||||
{
|
||||
log("element " + (i+1) + " is (" + elementNameList[i] + ")");
|
||||
log("dictionary " + dictionaryList[i].toString());
|
||||
}
|
||||
}
|
||||
|
||||
if (managerName == REMOTE_OBJECT_MANAGER)
|
||||
{
|
||||
if (dictionaryList.length < 1)
|
||||
{
|
||||
logError("No object available for remote creation. [" + elementNameExp + "]");
|
||||
}
|
||||
else if (!hasValidCreateScriptVars(self, requestId))
|
||||
{
|
||||
logError("Missing script vars for this request! [" + requestId + "]");
|
||||
}
|
||||
else if (utils.hasScriptVar(self, getSceneNameVarName(requestId)) && !elementNameExp.equals(getSceneName(self, requestId)))
|
||||
{
|
||||
logError("Wrong scene! [" + elementNameExp + "][" + getSceneName(self, requestId) + "]");
|
||||
}
|
||||
else
|
||||
{
|
||||
obj_id remoteObjectCreator = getRemoteObjectCreator(self, requestId, elementNameList, dictionaryList);
|
||||
|
||||
if (isValidId(remoteObjectCreator))
|
||||
{
|
||||
messageTo(remoteObjectCreator, CREATE_REMOTE_OBJECT, getRemoteCreateParams(self, requestId), 0.0f, false);
|
||||
log("Remote object creation request sent!");
|
||||
}
|
||||
else
|
||||
{
|
||||
logError("No valid remote object creator found!");
|
||||
}
|
||||
}
|
||||
|
||||
removeRemoteCreateScriptVars(self, requestId);
|
||||
}
|
||||
|
||||
return SCRIPT_CONTINUE;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
messageHandler createRemoteObjectResponse()
|
||||
{
|
||||
log("createRemoteObjectResponse: " + params.toString());
|
||||
|
||||
obj_id remoteObject = params.getObjId(REMOTE_OBJECT);
|
||||
|
||||
if (isValidId(remoteObject))
|
||||
{
|
||||
log("Successfully created " + remoteObject);
|
||||
}
|
||||
else
|
||||
{
|
||||
logError("Creation failed!");
|
||||
}
|
||||
|
||||
return SCRIPT_CONTINUE;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
void remoteCreate(String sceneName, String objectName, float x, float y, float z)
|
||||
{
|
||||
obj_id self = getSelf();
|
||||
|
||||
int requestId = getClusterWideData(REMOTE_OBJECT_MANAGER, sceneName, false, self);
|
||||
|
||||
utils.setScriptVar(self, getSceneNameVarName(requestId), sceneName);
|
||||
utils.setScriptVar(self, getObjectNameVarName(requestId), objectName);
|
||||
|
||||
utils.setScriptVar(self, getUseRandomLocationVarName(requestId), false);
|
||||
utils.setScriptVar(self, getXVarName(requestId), x);
|
||||
utils.setScriptVar(self, getYVarName(requestId), y);
|
||||
utils.setScriptVar(self, getZVarName(requestId), z);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
void remoteCreate(String sceneName, String objectName)
|
||||
{
|
||||
obj_id self = getSelf();
|
||||
|
||||
int requestId = getClusterWideData(REMOTE_OBJECT_MANAGER, sceneName, false, self);
|
||||
|
||||
utils.setScriptVar(self, getSceneNameVarName(requestId), sceneName);
|
||||
utils.setScriptVar(self, getObjectNameVarName(requestId), objectName);
|
||||
utils.setScriptVar(self, getUseRandomLocationVarName(requestId), true);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Invoke remote create and the base class will provide all parameters
|
||||
*/
|
||||
int remoteCreate()
|
||||
{
|
||||
obj_id self = getSelf();
|
||||
|
||||
int requestId = getClusterWideData(REMOTE_OBJECT_MANAGER, "*", false, self);
|
||||
|
||||
return requestId;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
String getSceneNameVarName(int requestId)
|
||||
{
|
||||
return SCENE_NAME + "." + requestId;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
String getSceneName(obj_id self, int requestId)
|
||||
{
|
||||
return utils.getStringScriptVar(self, getSceneNameVarName(requestId));
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
String getObjectNameVarName(int requestId)
|
||||
{
|
||||
return OBJECT_NAME + "." + requestId;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
String getObjectName(obj_id self, int requestId)
|
||||
{
|
||||
return utils.getStringScriptVar(self, getObjectNameVarName(requestId));
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
String getXVarName(int requestId)
|
||||
{
|
||||
return X + "." + requestId;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
float getX(obj_id self, int requestId)
|
||||
{
|
||||
return utils.getFloatScriptVar(self, getXVarName(requestId));
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
String getYVarName(int requestId)
|
||||
{
|
||||
return Y + "." + requestId;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
float getY(obj_id self, int requestId)
|
||||
{
|
||||
return utils.getFloatScriptVar(self, getYVarName(requestId));
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
String getZVarName(int requestId)
|
||||
{
|
||||
return Z + "." + requestId;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
float getZ(obj_id self, int requestId)
|
||||
{
|
||||
return utils.getFloatScriptVar(self, getZVarName(requestId));
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
String getUseRandomLocationVarName(int requestId)
|
||||
{
|
||||
return USE_RANDOM_LOCATION + "." + requestId;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
boolean getUseRandomLocationVarName(obj_id self, int requestId)
|
||||
{
|
||||
return utils.getBooleanScriptVar(self, getUseRandomLocationVarName(requestId));
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Base classes should override this method to remove creation parameters
|
||||
*/
|
||||
void removeRemoteCreateScriptVars(obj_id self, int requestId)
|
||||
{
|
||||
utils.removeScriptVar(self, getSceneNameVarName(requestId));
|
||||
utils.removeScriptVar(self, getObjectNameVarName(requestId));
|
||||
|
||||
utils.removeScriptVar(self, getXVarName(requestId));
|
||||
utils.removeScriptVar(self, getYVarName(requestId));
|
||||
utils.removeScriptVar(self, getZVarName(requestId));
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Base classes should override this method if sceneName and objectName are not stored
|
||||
*/
|
||||
boolean hasValidCreateScriptVars(obj_id self, int requestId)
|
||||
{
|
||||
return utils.hasScriptVar(self, getSceneNameVarName(requestId)) &&
|
||||
utils.hasScriptVar(self, getObjectNameVarName(requestId));
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Base classes should override this method to control creation parameters
|
||||
*/
|
||||
dictionary getRemoteCreateParams(obj_id self, int requestId)
|
||||
{
|
||||
dictionary createParams = new dictionary();
|
||||
|
||||
createParams.put(REQUESTER, self);
|
||||
|
||||
createParams.put(SCENE_NAME, getSceneName(self, requestId));
|
||||
createParams.put(OBJECT_NAME, getObjectName(self, requestId));
|
||||
createParams.put(X, getX(self, requestId));
|
||||
createParams.put(Y, getY(self, requestId));
|
||||
createParams.put(Z, getZ(self, requestId));
|
||||
|
||||
return createParams;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Base classes should override this method to control which remote creator to use
|
||||
*/
|
||||
obj_id getRemoteObjectCreator(obj_id self, int requestId, String[] elementNameList, dictionary[] dictionaryList)
|
||||
{
|
||||
int randomIndex = rand(0, dictionaryList.length);
|
||||
obj_id remoteObjectCreator = dictionaryList[randomIndex].getObjId(CREATOR);
|
||||
|
||||
return remoteObjectCreator;
|
||||
}
|
||||
|
||||
// ======================================================================
|
||||
Reference in New Issue
Block a user