Improved reloading support
This commit is contained in:
parent
cdd1a7a53f
commit
0f0fcfdfbf
@ -47,6 +47,7 @@ namespace Passer.Control {
|
|||||||
ProcessNetworkId(networkId);
|
ProcessNetworkId(networkId);
|
||||||
break;
|
break;
|
||||||
case InvestigateMsg investigate:
|
case InvestigateMsg investigate:
|
||||||
|
UnityEngine.Debug.Log($"investigate [{investigate.networkId}/{investigate.thingId}]");
|
||||||
ProcessInvestigate(investigate);
|
ProcessInvestigate(investigate);
|
||||||
break;
|
break;
|
||||||
case ThingMsg thing:
|
case ThingMsg thing:
|
||||||
@ -96,11 +97,12 @@ namespace Passer.Control {
|
|||||||
|
|
||||||
protected virtual void ProcessDestroy(DestroyMsg destroy) { }
|
protected virtual void ProcessDestroy(DestroyMsg destroy) { }
|
||||||
|
|
||||||
private void ForwardMessage(IMessage thing) {
|
private void ForwardMessage(IMessage msg) {
|
||||||
foreach (Client client in Client.clients) {
|
foreach (Client client in Client.clients) {
|
||||||
if (client == this)
|
if (client == this)
|
||||||
continue;
|
continue;
|
||||||
IMessage.SendMsg(client, thing);
|
UnityEngine.Debug.Log($"---> {client.ipAddress}");
|
||||||
|
IMessage.SendMsg(client, msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
26
Messages.cs
26
Messages.cs
@ -19,6 +19,7 @@ namespace Passer.Control {
|
|||||||
if (client == null || client.ipAddress == null)
|
if (client == null || client.ipAddress == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
//UnityEngine.Debug.Log($"Send msg {buffer[0]} to {client.ipAddress}");
|
||||||
client.udpClient.Send(buffer, buffer.Length, client.ipAddress, client.port);
|
client.udpClient.Send(buffer, buffer.Length, client.ipAddress, client.port);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -168,8 +169,8 @@ namespace Passer.Control {
|
|||||||
this.thingId = buffer[ix++];
|
this.thingId = buffer[ix++];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool Send(Client client, byte thingId) {
|
public static bool Send(Client client, byte networkId, byte thingId) {
|
||||||
InvestigateMsg msg = new(client.networkId, thingId);
|
InvestigateMsg msg = new(networkId, thingId);
|
||||||
return SendMsg(client, msg);
|
return SendMsg(client, msg);
|
||||||
}
|
}
|
||||||
public static async Task<bool> Receive(Stream dataStream, Client client, byte packetSize) {
|
public static async Task<bool> Receive(Stream dataStream, Client client, byte packetSize) {
|
||||||
@ -232,6 +233,10 @@ namespace Passer.Control {
|
|||||||
byte[] buffer = await Receive(dataStream, packetSize);
|
byte[] buffer = await Receive(dataStream, packetSize);
|
||||||
ThingMsg msg = new(buffer);
|
ThingMsg msg = new(buffer);
|
||||||
|
|
||||||
|
// Do no process poses with nwid == 0 (== local)
|
||||||
|
if (msg.networkId == 0)
|
||||||
|
return true;
|
||||||
|
|
||||||
client.messageQueue.Enqueue(msg);
|
client.messageQueue.Enqueue(msg);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -406,13 +411,16 @@ namespace Passer.Control {
|
|||||||
return SendMsg(client, msg);
|
return SendMsg(client, msg);
|
||||||
}
|
}
|
||||||
public static async Task<bool> Receive(Stream dataStream, Client client, byte packetSize) {
|
public static async Task<bool> Receive(Stream dataStream, Client client, byte packetSize) {
|
||||||
UnityEngine.Debug.Log("Receive pose");
|
|
||||||
if (packetSize != length)
|
if (packetSize != length)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
byte[] buffer = await Receive(dataStream, packetSize);
|
byte[] buffer = await Receive(dataStream, packetSize);
|
||||||
PoseMsg msg = new(buffer);
|
PoseMsg msg = new(buffer);
|
||||||
|
|
||||||
|
// Do no process poses with nwid == 0 (== local)
|
||||||
|
if (msg.networkId == 0)
|
||||||
|
return true;
|
||||||
|
|
||||||
client.messageQueue.Enqueue(msg);
|
client.messageQueue.Enqueue(msg);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -436,25 +444,25 @@ namespace Passer.Control {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override byte[] Serialize() {
|
public override byte[] Serialize() {
|
||||||
byte[] buffer = new byte[4 + this.bytes.Length];
|
byte[] buffer = new byte[3 + this.bytes.Length];
|
||||||
byte ix = 0;
|
byte ix = 0;
|
||||||
buffer[ix++] = CustomMsg.Id;
|
buffer[ix++] = CustomMsg.Id;
|
||||||
buffer[ix++] = this.networkId;
|
buffer[ix++] = this.networkId;
|
||||||
buffer[ix++] = this.thingId;
|
buffer[ix++] = this.thingId;
|
||||||
buffer[ix++] = (byte)bytes.Length;
|
//buffer[ix++] = (byte)bytes.Length;
|
||||||
foreach (byte b in bytes)
|
foreach (byte b in bytes)
|
||||||
buffer[ix++] = b;
|
buffer[ix++] = b;
|
||||||
|
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
public override void Deserialize(byte[] buffer) {
|
public override void Deserialize(byte[] buffer) {
|
||||||
uint ix = 0;
|
byte ix = 0;
|
||||||
this.networkId = buffer[ix++];
|
this.networkId = buffer[ix++];
|
||||||
this.thingId = buffer[ix++];
|
this.thingId = buffer[ix++];
|
||||||
byte length = buffer[ix++];
|
byte length = (byte)(buffer.Length - ix);//buffer[ix++];
|
||||||
this.bytes = new byte[length];
|
this.bytes = new byte[length];
|
||||||
for (uint bytesIx = 0; ix < length; ix++, bytesIx++)
|
for (uint bytesIx = 0; bytesIx < length; bytesIx++)
|
||||||
this.bytes[bytesIx] = buffer[ix];
|
this.bytes[bytesIx] = buffer[ix++];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Send(Client client, byte thingId, byte[] bytes) {
|
public static void Send(Client client, byte thingId, byte[] bytes) {
|
||||||
|
@ -21,6 +21,7 @@ namespace Passer.Control {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//UnityEngine.Debug.Log($"R {msgId} from {client.ipAddress}");
|
||||||
bool result = false;
|
bool result = false;
|
||||||
switch (msgId) {
|
switch (msgId) {
|
||||||
case ClientMsg.Id: // 0xA0 / 160
|
case ClientMsg.Id: // 0xA0 / 160
|
||||||
|
Loading…
x
Reference in New Issue
Block a user