Merge commit '371e5b724c421a694ed9faef482a71471f01597e'

This commit is contained in:
Pascal Serrarens 2025-06-06 12:47:26 +02:00
commit 57cff2d4b2
4 changed files with 36 additions and 36 deletions

View File

@ -128,7 +128,7 @@ namespace RoboidControl.Unity {
this.gameObject.name = core.name; this.gameObject.name = core.name;
break; break;
case ModelUrlMsg.Id: case ModelUrlMsg.Id:
Debug.Log("{this.id} Handle Model URL"); Debug.Log($"{this.core.id} Handle Model URL");
string extension = core.modelUrl[core.modelUrl.LastIndexOf(".")..]; string extension = core.modelUrl[core.modelUrl.LastIndexOf(".")..];
if (extension == ".jpg" || extension == ".png") if (extension == ".jpg" || extension == ".png")
StartCoroutine(LoadJPG()); StartCoroutine(LoadJPG());

View File

@ -244,6 +244,7 @@ namespace RoboidControl {
/// <returns>The added participant</returns> /// <returns>The added participant</returns>
public static Participant AddParticipant(string ipAddress, int port, Participant localParticipant = null) { public static Participant AddParticipant(string ipAddress, int port, Participant localParticipant = null) {
Console.WriteLine($"New Participant {ipAddress}:{port}"); Console.WriteLine($"New Participant {ipAddress}:{port}");
// This code is only valid for site, because those can distribute networkIds.....
Participant participant = new(ipAddress, port, localParticipant) { Participant participant = new(ipAddress, port, localParticipant) {
networkId = (byte)(Participant.participants.Count + 1) networkId = (byte)(Participant.participants.Count + 1)
}; };

View File

@ -97,7 +97,7 @@ namespace RoboidControl {
/// </summary> /// </summary>
/// Isolated participants do not communicate with other participants /// Isolated participants do not communicate with other participants
public bool isIsolated = false; public bool isIsolated = false;
/// <summary> /// <summary>
/// The remote site when this participant is connected to a site /// The remote site when this participant is connected to a site
/// </summary> /// </summary>
@ -379,6 +379,16 @@ namespace RoboidControl {
this.networkId = msg.networkId; this.networkId = msg.networkId;
foreach (Thing thing in this.things) //Thing.GetAllThings()) foreach (Thing thing in this.things) //Thing.GetAllThings())
sender.SendThingInfo(thing); sender.SendThingInfo(thing);
// HACK to get the networkId for sites corrected to 0.
// This is needed because AddParticipant assigns a networkId for non-sites
sender.networkId = 0;
UpdateEvent e = new() {
messageId = NetworkIdMsg.Id,
participant = sender
};
this.updateQueue.Enqueue(e);
} }
} }
@ -392,6 +402,29 @@ namespace RoboidControl {
#if DEBUG #if DEBUG
Console.WriteLine($"{this.name}: Process ThingMsg [{msg.networkId}/{msg.thingId}] {msg.thingType} {msg.parentId}"); Console.WriteLine($"{this.name}: Process ThingMsg [{msg.networkId}/{msg.thingId}] {msg.thingType} {msg.parentId}");
#endif #endif
Thing thing = sender.Get(msg.thingId);
thing ??= ProcessNewThing(sender, msg);
if (msg.parentId != 0) {
thing.parent = sender.Get(msg.parentId);
if (thing.parent == null)
Console.WriteLine($"Could not find parent [{msg.networkId}/{msg.parentId}]");
}
else {
// Console.Write($"Dropped {thing.id}");
thing.parent = null;
}
}
protected virtual Thing ProcessNewThing(Participant sender, ThingMsg msg) {
Thing newThing = msg.thingType switch {
Thing.Type.TouchSensor => new TouchSensor(sender.root),
Thing.Type.DifferentialDrive => new DifferentialDrive(sender.root),
_ => new Thing(sender.root)
};
newThing.id = msg.thingId;
newThing.type = msg.thingType;
return newThing;
} }
protected virtual void Process(Participant sender, NameMsg msg) { protected virtual void Process(Participant sender, NameMsg msg) {

View File

@ -76,16 +76,11 @@ namespace RoboidControl {
if (this.isIsolated == false) { if (this.isIsolated == false) {
// Send to all other participants // Send to all other participants
//foreach (Participant participant in Participant.participants) {
for (int participantIx = 0; participantIx < Participant.participants.Count; participantIx++) { for (int participantIx = 0; participantIx < Participant.participants.Count; participantIx++) {
Participant participant = Participant.participants[participantIx]; Participant participant = Participant.participants[participantIx];
if (participant == null || participant == this) if (participant == null || participant == this)
continue; continue;
// PoseMsg poseMsg = new(thing.owner.networkId, thing);
// this.Send(participant, poseMsg);
// BinaryMsg binaryMsg = new(thing.owner.networkId, thing);
// this.Send(participant, binaryMsg);
participant.Send(new PoseMsg(thing.owner.networkId, thing)); participant.Send(new PoseMsg(thing.owner.networkId, thing));
participant.Send(new BinaryMsg(thing.owner.networkId, thing)); participant.Send(new BinaryMsg(thing.owner.networkId, thing));
} }
@ -101,7 +96,6 @@ namespace RoboidControl {
base.Process(sender, msg); base.Process(sender, msg);
if (msg.networkId != sender.networkId) { if (msg.networkId != sender.networkId) {
//Console.WriteLine($"{this.name} received New Participant -> {sender.networkId}"); //Console.WriteLine($"{this.name} received New Participant -> {sender.networkId}");
// this.Send(sender, new NetworkIdMsg(sender.networkId));
sender.Send(new NetworkIdMsg(sender.networkId)); sender.Send(new NetworkIdMsg(sender.networkId));
UpdateEvent e = new() { UpdateEvent e = new() {
messageId = ParticipantMsg.Id, messageId = ParticipantMsg.Id,
@ -113,34 +107,6 @@ namespace RoboidControl {
protected override void Process(Participant sender, NetworkIdMsg msg) { } protected override void Process(Participant sender, NetworkIdMsg msg) { }
protected override void Process(Participant sender, ThingMsg msg) {
Console.WriteLine($"{this.name}: Process thing [{msg.networkId}/{msg.thingId}] {msg.thingType} {msg.parentId} ");
Thing thing = sender.Get(msg.thingId);
thing ??= ProcessNewThing(sender, msg);
if (msg.parentId != 0) {
thing.parent = sender.Get(msg.parentId);
if (thing.parent == null)
Console.WriteLine($"Could not find parent [{msg.networkId}/{msg.parentId}]");
}
else {
// Console.Write($"Dropped {thing.id}");
thing.parent = null;
}
}
protected virtual Thing ProcessNewThing(Participant sender, ThingMsg msg) {
Thing newThing = msg.thingType switch {
Thing.Type.TouchSensor => new TouchSensor(sender.root),
Thing.Type.DifferentialDrive => new DifferentialDrive(sender.root),
_ => new Thing(sender.root)
};
newThing.id = msg.thingId;
newThing.type = msg.thingType;
return newThing;
}
#endregion Receive #endregion Receive
} }