Emesary MP Bridge; optimisation
Encode the indexes and use add constants to remove hardcoded values
This commit is contained in:
parent
53dcb70e61
commit
beb26236aa
2 changed files with 17 additions and 15 deletions
|
@ -293,22 +293,18 @@ var TransferString =
|
||||||
l = 16;
|
l = 16;
|
||||||
var rv = BinaryAsciiTransfer.encodeInt(l);
|
var rv = BinaryAsciiTransfer.encodeInt(l);
|
||||||
|
|
||||||
print ("Encode string ",v," l=",l);
|
|
||||||
for(var ii = 0; ii < l; ii = ii + 1)
|
for(var ii = 0; ii < l; ii = ii + 1)
|
||||||
{
|
{
|
||||||
printf("%d,%d (%s)\n",ii+1,1,rv);
|
|
||||||
ev = TransferString.getalphanumericchar(substr(v,ii,1));
|
ev = TransferString.getalphanumericchar(substr(v,ii,1));
|
||||||
if (ev != nil)
|
if (ev != nil)
|
||||||
rv = rv ~ ev;
|
rv = rv ~ ev;
|
||||||
}
|
}
|
||||||
print("String encode l=",l," val=",rv);
|
|
||||||
return rv;
|
return rv;
|
||||||
},
|
},
|
||||||
decode : func(v)
|
decode : func(v)
|
||||||
{
|
{
|
||||||
var l = BinaryAsciiTransfer.decodeInt(v);
|
var l = BinaryAsciiTransfer.decodeInt(v);
|
||||||
var rv = substr(v,1,l-1);
|
var rv = substr(v,1,l-1);
|
||||||
print("String decode l=",l," val=",rv);
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -58,6 +58,10 @@
|
||||||
|
|
||||||
var OutgoingMPBridge =
|
var OutgoingMPBridge =
|
||||||
{
|
{
|
||||||
|
SeperatorChar : "!",
|
||||||
|
StartMessageIndex : 11,
|
||||||
|
DefaultMessageLifetime : 10,
|
||||||
|
MPStringMaxLen: 50,
|
||||||
new: func(_ident, _notifications_to_bridge=nil, _mpidx=18, _root="", _transmitter=nil)
|
new: func(_ident, _notifications_to_bridge=nil, _mpidx=18, _root="", _transmitter=nil)
|
||||||
{
|
{
|
||||||
if (_transmitter == nil)
|
if (_transmitter == nil)
|
||||||
|
@ -66,7 +70,7 @@ var OutgoingMPBridge =
|
||||||
print("OutgoingMPBridge created for "~_ident);
|
print("OutgoingMPBridge created for "~_ident);
|
||||||
var new_class = emesary.Recipient.new("OutgoingMPBridge "~_ident);
|
var new_class = emesary.Recipient.new("OutgoingMPBridge "~_ident);
|
||||||
|
|
||||||
new_class.MessageIndex = 100;
|
new_class.MessageIndex = OutgoingMPBridge.StartMessageIndex;
|
||||||
# foreach (var notification; _notifications_to_bridge)
|
# foreach (var notification; _notifications_to_bridge)
|
||||||
# new_class.NotificationsToBridge = notification.new(;
|
# new_class.NotificationsToBridge = notification.new(;
|
||||||
if(_notifications_to_bridge == nil)
|
if(_notifications_to_bridge == nil)
|
||||||
|
@ -177,7 +181,11 @@ var OutgoingMPBridge =
|
||||||
#print("Encode ",eidx,"=",encval);
|
#print("Encode ",eidx,"=",encval);
|
||||||
eidx += 1;
|
eidx += 1;
|
||||||
}
|
}
|
||||||
sect = sprintf("!%d!%d!%s",notification.BridgeMessageId, notification.BridgeMessageNotificationTypeId, encval);
|
# !idx!typ!encv
|
||||||
|
sect = sprintf("%s%s%s%s%s%s",
|
||||||
|
OutgoingMPBridge.SeperatorChar, emesary.BinaryAsciiTransfer.encodeInt(notification.BridgeMessageId),
|
||||||
|
OutgoingMPBridge.SeperatorChar, emesary.BinaryAsciiTransfer.encodeInt(notification.BridgeMessageNotificationTypeId),
|
||||||
|
OutgoingMPBridge.SeperatorChar, encval);
|
||||||
outgoing = outgoing~sect;
|
outgoing = outgoing~sect;
|
||||||
me.OutgoingList[out_idx] = me.OutgoingList[idx];
|
me.OutgoingList[out_idx] = me.OutgoingList[idx];
|
||||||
# print("xmit ",idx," out=",out_idx);
|
# print("xmit ",idx," out=",out_idx);
|
||||||
|
@ -214,7 +222,7 @@ var IncomingMPBridge =
|
||||||
|
|
||||||
var new_class = emesary.Transmitter.new("IncominggMPBridge "~_ident);
|
var new_class = emesary.Transmitter.new("IncominggMPBridge "~_ident);
|
||||||
|
|
||||||
new_class.IncomingMessageIndex = 100;
|
new_class.IncomingMessageIndex = OutgoingMPBridge.StartMessageIndex;
|
||||||
if(_notifications_to_bridge == nil)
|
if(_notifications_to_bridge == nil)
|
||||||
new_class.NotificationsToBridge = [];
|
new_class.NotificationsToBridge = [];
|
||||||
else
|
else
|
||||||
|
@ -222,7 +230,7 @@ var IncomingMPBridge =
|
||||||
|
|
||||||
new_class.MPout = "";
|
new_class.MPout = "";
|
||||||
new_class.MPidx = _mpidx;
|
new_class.MPidx = _mpidx;
|
||||||
new_class.MessageLifeTime = 10; # seconds
|
new_class.MessageLifeTime = OutgoingMPBridge.DefaultMessageLifetime; # seconds
|
||||||
new_class.OutgoingList = [];
|
new_class.OutgoingList = [];
|
||||||
new_class.Transmitter = _transmitter;
|
new_class.Transmitter = _transmitter;
|
||||||
new_class.MpVariable = "";
|
new_class.MpVariable = "";
|
||||||
|
@ -262,13 +270,13 @@ var IncomingMPBridge =
|
||||||
for (var idx = 0; idx < size(encoded_notifications); idx += 1)
|
for (var idx = 0; idx < size(encoded_notifications); idx += 1)
|
||||||
{
|
{
|
||||||
# get the message parts
|
# get the message parts
|
||||||
var encoded_notification = split("!", encoded_val);
|
var encoded_notification = split(OutgoingMPBridge.SeperatorChar, encoded_val);
|
||||||
if (size(encoded_notification) < 4)
|
if (size(encoded_notification) < 4)
|
||||||
print("Error: emesary.IncomingBridge.ProcessIncoming bad msg ",encoded_val);
|
print("Error: emesary.IncomingBridge.ProcessIncoming bad msg ",encoded_val);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var msg_idx = encoded_notification[1];
|
var msg_idx = emesary.BinaryAsciiTransfer.decodeInt(encoded_notification[1]);
|
||||||
var msg_type_id = encoded_notification[2];
|
var msg_type_id = emesary.BinaryAsciiTransfer.decodeInt(encoded_notification[2]);
|
||||||
if (msg_type_id >= size(me.NotificationsToBridge))
|
if (msg_type_id >= size(me.NotificationsToBridge))
|
||||||
{
|
{
|
||||||
print("Error: emesary.IncomingBridge.ProcessIncoming invalid type_id ",msg_type_id);
|
print("Error: emesary.IncomingBridge.ProcessIncoming invalid type_id ",msg_type_id);
|
||||||
|
@ -331,13 +339,11 @@ var IncomingMPBridge =
|
||||||
# Model added will be eg: /ai[0]/models[0]/multiplayer[0]
|
# Model added will be eg: /ai[0]/models[0]/multiplayer[0]
|
||||||
var path = v.getValue();
|
var path = v.getValue();
|
||||||
|
|
||||||
print("Model added ",path);
|
|
||||||
# Ensure we only handle multiplayer elements
|
# Ensure we only handle multiplayer elements
|
||||||
if (find("/multiplayer",path) > 0)
|
if (find("/multiplayer",path) > 0)
|
||||||
{
|
{
|
||||||
print("Callsign path ",path~"/callsign");
|
|
||||||
var callsign = getprop(path~"/callsign");
|
var callsign = getprop(path~"/callsign");
|
||||||
print("Creating Emesary MPBridge for ",callsign);
|
print("Creating Emesary MPBridge for ",path);
|
||||||
if (callsign == "" or callsign == nil)
|
if (callsign == "" or callsign == nil)
|
||||||
callsign = path;
|
callsign = path;
|
||||||
|
|
||||||
|
@ -352,11 +358,11 @@ print("Callsign path ",path~"/callsign");
|
||||||
# when a client disconnects remove the associated bridge.
|
# when a client disconnects remove the associated bridge.
|
||||||
#
|
#
|
||||||
setlistener("/ai/models/model-removed", func(v){
|
setlistener("/ai/models/model-removed", func(v){
|
||||||
print("Model removed ",v.getValue());
|
|
||||||
var path = v.getValue();
|
var path = v.getValue();
|
||||||
var bridge = incomingBridgeList[path];
|
var bridge = incomingBridgeList[path];
|
||||||
if (bridge != nil)
|
if (bridge != nil)
|
||||||
{
|
{
|
||||||
|
# print("Bridge removed for ",v.getValue());
|
||||||
bridge.Remove();
|
bridge.Remove();
|
||||||
incomingBridgeList[path]=nil;
|
incomingBridgeList[path]=nil;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue