Binary msg receiving fix
This commit is contained in:
parent
1225ee1097
commit
fd8215cc7e
@ -24,7 +24,7 @@ namespace RoboidControl.Unity {
|
||||
|
||||
public void HandleNewThing(RoboidControl.Thing thing) {
|
||||
//Debug.Log($"Handle New thing event for {thing}");
|
||||
site.Add(thing, false);
|
||||
//site.Add(thing, false);
|
||||
thingQueue.Enqueue(thing);
|
||||
}
|
||||
|
||||
|
@ -108,13 +108,13 @@ namespace RoboidControl {
|
||||
public void Add(Thing thing, bool checkId = true, bool invokeEvent = true) {
|
||||
if (checkId && thing.id == 0) {
|
||||
thing.id = (byte)(this.things.Count + 1);
|
||||
things.Add(thing);
|
||||
this.things.Add(thing);
|
||||
}
|
||||
// Console.WriteLine($"added thing [{thing.networkId}/{thing.id}]");
|
||||
Thing foundThing = Get(thing.networkId, thing.id);
|
||||
|
||||
if (foundThing == null) {
|
||||
things.Add(thing);
|
||||
this.things.Add(thing);
|
||||
|
||||
// if (invokeEvent)
|
||||
// Thing.InvokeNewThing(thing);
|
||||
|
@ -33,6 +33,7 @@ namespace RoboidControl {
|
||||
public ParticipantUDP(int port = 0) : base("127.0.0.1", port) {
|
||||
if (this.port == 0)
|
||||
this.isIsolated = true;
|
||||
Participant.AddParticipant(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -45,6 +46,7 @@ namespace RoboidControl {
|
||||
this.isIsolated = true;
|
||||
else
|
||||
this.remoteSite = new Participant(ipAddress, port);
|
||||
Participant.AddParticipant(this);
|
||||
|
||||
this.endPoint = new IPEndPoint(IPAddress.Any, localPort);
|
||||
this.udpClient = new UdpClient(localPort);
|
||||
@ -159,7 +161,9 @@ namespace RoboidControl {
|
||||
if (this.isIsolated)
|
||||
continue;
|
||||
|
||||
foreach (Thing thing in participant.things) {
|
||||
//foreach (Thing thing in participant.things) {
|
||||
for (int thingIx = 0; thingIx < participant.things.Count; thingIx++) {
|
||||
Thing thing = participant.things[thingIx];
|
||||
if (thing == null)
|
||||
continue;
|
||||
|
||||
@ -301,10 +305,6 @@ namespace RoboidControl {
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Process
|
||||
|
||||
protected virtual void Process(Participant sender, ParticipantMsg msg) {
|
||||
#if DEBUG
|
||||
Console.WriteLine($"{this.name} Process participantMsg {msg.networkId}");
|
||||
@ -377,9 +377,9 @@ namespace RoboidControl {
|
||||
}
|
||||
|
||||
protected virtual void Process(Participant sender, BinaryMsg msg) {
|
||||
// #if DEBUG
|
||||
// Console.WriteLine($"Participant: Process BinaryMsg [{msg.networkId}/{msg.thingId}] {msg.dataLength}");
|
||||
// #endif
|
||||
#if DEBUG
|
||||
Console.WriteLine($"Participant: Process BinaryMsg [{msg.networkId}/{msg.thingId}] {msg.dataLength}");
|
||||
#endif
|
||||
Thing thing = sender.Get(msg.networkId, msg.thingId);
|
||||
thing?.ProcessBinary(msg.data);
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ namespace RoboidControl {
|
||||
/// <param name="port"></param>
|
||||
public SiteServer(int port = 7681) : base(port) {
|
||||
this.name = "Site Server";
|
||||
Participant.AddParticipant(this);
|
||||
|
||||
Console.Write($"Prepare receive on port {port}");
|
||||
this.endPoint = new IPEndPoint(IPAddress.Any, port);
|
||||
@ -33,7 +34,11 @@ namespace RoboidControl {
|
||||
#region Update
|
||||
|
||||
protected override void UpdateMyThings(ulong currentTimeMS) {
|
||||
foreach (Thing thing in this.things) {
|
||||
// We don't use foreach to prevent the 'Collection was modified' error
|
||||
int n = this.things.Count;
|
||||
for (int ix = 0; ix < n; ix++) {
|
||||
Thing thing = this.things[ix];
|
||||
|
||||
if (thing == null)
|
||||
continue;
|
||||
|
||||
@ -75,7 +80,7 @@ namespace RoboidControl {
|
||||
thing = new Thing(sender, msg.networkId, msg.thingId, msg.thingType);
|
||||
|
||||
if (msg.parentId != 0) {
|
||||
thing.parent = Get(msg.networkId, msg.parentId);
|
||||
thing.parent = sender.Get(msg.networkId, msg.parentId);
|
||||
if (thing.parent == null)
|
||||
Console.WriteLine($"Could not find parent [{msg.networkId}/{msg.parentId}]");
|
||||
}
|
||||
|
@ -90,6 +90,7 @@ namespace RoboidControl {
|
||||
this.id = thingId;
|
||||
this.type = thingType;
|
||||
this.networkId = networkId;
|
||||
Console.Write($"New thing added to {owner}");
|
||||
this.owner.Add(this);
|
||||
InvokeNewThing(this);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user