From f3b863692b20afb370f045ab64a92fde72f0e7b2 Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Thu, 5 Jun 2025 11:37:29 +0200 Subject: [PATCH] Compliency fixes --- Unity/Participant.cs | 4 ++-- Unity/SiteServer.cs | 2 +- Unity/Thing.cs | 10 ++++++---- src/Messages/LowLevelMessages.cs | 2 +- src/Participant.cs | 1 + src/Participants/ParticipantUDP.cs | 2 +- src/Participants/SiteServer.cs | 3 ++- 7 files changed, 14 insertions(+), 10 deletions(-) diff --git a/Unity/Participant.cs b/Unity/Participant.cs index 52539f8..feee822 100644 --- a/Unity/Participant.cs +++ b/Unity/Participant.cs @@ -44,10 +44,10 @@ namespace RoboidControl.Unity { // before we can create the wheel reliably break; case RoboidControl.Thing coreThing: - Debug.Log("Handle Thing"); + // Debug.Log("Handle Thing"); if (coreThing.component == null) { Thing[] things = FindObjectsByType(FindObjectsSortMode.None); - Debug.Log(things.Length); + // Debug.Log(things.Length); Thing thing = things.FirstOrDefault(t => t.core != null && t.core.id == coreThing.id); if (thing == null) thing = Thing.Create(coreThing); diff --git a/Unity/SiteServer.cs b/Unity/SiteServer.cs index 24205c7..0034e2e 100644 --- a/Unity/SiteServer.cs +++ b/Unity/SiteServer.cs @@ -30,7 +30,7 @@ namespace RoboidControl.Unity { while (site.updateQueue.TryDequeue(out RoboidControl.Participant.UpdateEvent e)) HandleUpdateEvent(e); - site.Update((ulong)(Time.time * 1000)); + site.Update(); // while (thingQueue.TryDequeue(out RoboidControl.Thing thing)) // thing.CreateComponent(); } diff --git a/Unity/Thing.cs b/Unity/Thing.cs index b461f13..cf32570 100644 --- a/Unity/Thing.cs +++ b/Unity/Thing.cs @@ -212,9 +212,8 @@ namespace RoboidControl.Unity { } } } - else { - ScanForThings(parentTransform); - } + else + ScanForThings(parentTransform); } else { this.transform.localScale = Vector3.one * 1; @@ -230,7 +229,7 @@ namespace RoboidControl.Unity { for (int thingIx = 0; thingIx < thingArray.Length; thingIx++) { RoboidControl.Thing thing = thingArray[thingIx]; GameObject foundObj = FindThingByName(thing, rootTransform); - if (foundObj != null && foundObj != thing.component.gameObject) { + if (foundObj != null && (thing.component != null && foundObj != thing.component.gameObject)) { Thing foundThing = foundObj.GetComponent(); if (foundThing == null) { Debug.Log($"move thing [{thing.owner.networkId}/{thing.id}] to {foundObj.name}"); @@ -242,6 +241,9 @@ namespace RoboidControl.Unity { Destroy(thing.component.gameObject); thing.component = foundThing; } + else { + Debug.LogWarning($"Could not find [{thing.owner.networkId}/{thing.id}]"); + } } } } diff --git a/src/Messages/LowLevelMessages.cs b/src/Messages/LowLevelMessages.cs index e602ed2..15b630a 100644 --- a/src/Messages/LowLevelMessages.cs +++ b/src/Messages/LowLevelMessages.cs @@ -58,7 +58,7 @@ namespace RoboidControl { float horizontal = ReceiveAngle8(data, ref ix); float vertical = ReceiveAngle8(data, ref ix); float twist = ReceiveAngle8(data, ref ix); - System.Console.Write($"receive st: {horizontal} {vertical} {twist}"); + // System.Console.Write($"receive st: {horizontal} {vertical} {twist}"); SwingTwist r = SwingTwist.Degrees(horizontal, vertical, twist); return r; diff --git a/src/Participant.cs b/src/Participant.cs index 43b42d9..2bebcb3 100644 --- a/src/Participant.cs +++ b/src/Participant.cs @@ -163,6 +163,7 @@ namespace RoboidControl { /// The thing relevant fo the event /// public Thing thing; + public Participant participant; } /// /// Queue containing events happened to this participant diff --git a/src/Participants/ParticipantUDP.cs b/src/Participants/ParticipantUDP.cs index d6e27c2..9144292 100644 --- a/src/Participants/ParticipantUDP.cs +++ b/src/Participants/ParticipantUDP.cs @@ -401,7 +401,7 @@ namespace RoboidControl { protected virtual void Process(Participant sender, PoseMsg msg) { #if DEBUG - Console.WriteLine($"{this.name}: Process PoseMsg [{msg.networkId}/{msg.thingId}] {msg.poseType}"); +// Console.WriteLine($"{this.name}: Process PoseMsg [{msg.networkId}/{msg.thingId}] {msg.poseType}"); #endif Participant owner = Participant.GetParticipant(msg.networkId); if (owner == null) diff --git a/src/Participants/SiteServer.cs b/src/Participants/SiteServer.cs index 3cbea8c..2fc6e2a 100644 --- a/src/Participants/SiteServer.cs +++ b/src/Participants/SiteServer.cs @@ -104,7 +104,8 @@ namespace RoboidControl { // this.Send(sender, new NetworkIdMsg(sender.networkId)); sender.Send(new NetworkIdMsg(sender.networkId)); UpdateEvent e = new() { - messageId = ParticipantMsg.Id + messageId = ParticipantMsg.Id, + participant = sender }; this.updateQueue.Enqueue(e); }