Only send pose messages for remote things from a site server

This commit is contained in:
Pascal Serrarens 2025-06-11 17:39:15 +02:00
parent d63d3cedd2
commit 9bfa288465
4 changed files with 56 additions and 21 deletions

View File

@ -113,7 +113,7 @@ namespace RoboidControl {
);
//Thing thing = things.Find(aThing => Thing.IsThing(aThing, networkId, thingId));
if (thing == null)
Console.WriteLine($"Could not find thing {this.networkId} [{networkId}/{thingId}]");
Console.WriteLine($"Unknown Thing {this.networkId} [{networkId}/{thingId}]");
return thing;
}
@ -123,7 +123,7 @@ namespace RoboidControl {
/// <param name="thing">The thing to add</param>
/// <param name="checkId">If true, the thing.id is regenerated if it is zero
public void Add(Thing thing, bool checkId = true) {
Console.WriteLine("Add Thing to participant");
// Console.WriteLine("Add Thing to participant");
if (checkId && thing.id == 0) {
thing.id = (byte)(this.things.Count + 1);
this.things.Add(thing);

View File

@ -236,25 +236,25 @@ namespace RoboidControl {
// if (this.isIsolated)
// continue;
if (currentTimeMS > this.nextSendUpdate) {
for (int thingIx = 0; thingIx < owner.things.Count; thingIx++) {
Thing thing = owner.things[thingIx];
if (thing == null)
continue;
// if (currentTimeMS > this.nextSendUpdate) {
// for (int thingIx = 0; thingIx < owner.things.Count; thingIx++) {
// Thing thing = owner.things[thingIx];
// if (thing == null)
// continue;
foreach (Participant participant in Participant.participants) {
if (participant == this || participant == owner)
continue;
// foreach (Participant participant in Participant.participants) {
// if (participant == this || participant == owner)
// continue;
Console.WriteLine($"[{thing.owner.networkId}/{thing.id}] Pose ---> {participant.networkId}");
PoseMsg poseMsg = new(thing.owner.networkId, thing, true);
participant.Send(poseMsg);
}
}
}
// Console.WriteLine($"[{thing.owner.networkId}/{thing.id}] Pose ---> {participant.networkId}");
// PoseMsg poseMsg = new(thing.owner.networkId, thing, true);
// participant.Send(poseMsg);
// }
// }
// }
}
if (currentTimeMS > this.nextSendUpdate)
this.nextSendUpdate = currentTimeMS + this.sendUpdateIntervalMS;
// if (currentTimeMS > this.nextSendUpdate)
// this.nextSendUpdate = currentTimeMS + this.sendUpdateIntervalMS;
}
#endregion Update
@ -490,7 +490,7 @@ namespace RoboidControl {
}
protected virtual Thing ProcessNewThing(Participant owner, ThingMsg msg, bool isRemote) {
Console.WriteLine("--- New Thing");
// Console.WriteLine("--- New Thing");
Thing newThing = msg.thingType switch {
Thing.Type.TouchSensor => new TouchSensor(owner.root),
Thing.Type.DifferentialDrive => new DifferentialDrive(owner.root),
@ -528,7 +528,7 @@ namespace RoboidControl {
}
protected virtual void Process(Participant sender, PoseMsg msg) {
#if DEBUG2
#if DEBUG
Console.WriteLine($"{this.name}: Process PoseMsg [{msg.networkId}/{msg.thingId}] {msg.poseType}");
#endif
Participant owner = Participant.GetParticipant(msg.networkId);

View File

@ -95,6 +95,38 @@ namespace RoboidControl {
}
}
protected override void UpdateOtherThings(ulong currentTimeMS) {
for (int ownerIx = 0; ownerIx < Participant.participants.Count; ownerIx++) {
Participant owner = Participant.participants[ownerIx];
if (owner == null || owner == this)
continue;
owner.Update();
if (currentTimeMS < this.nextSendUpdate)
continue;
// for (int thingIx = 0; thingIx < owner.things.Count; thingIx++) {
// Thing thing = owner.things[thingIx];
foreach (Thing thing in owner.things) {
if (thing == null)
continue;
foreach (Participant participant in Participant.participants) {
if (participant == this || participant == owner)
continue;
PoseMsg poseMsg = new(thing.owner.networkId, thing);
if (poseMsg.poseType != 0)
Console.WriteLine($"[{thing.owner.networkId}/{thing.id}] Pose ---> {participant.networkId}");
participant.Send(poseMsg);
}
}
}
if (currentTimeMS > this.nextSendUpdate)
this.nextSendUpdate = currentTimeMS + this.sendUpdateIntervalMS;
}
#endregion Update
#region Receive

View File

@ -341,7 +341,10 @@ namespace RoboidControl {
public bool orientationUpdated = false;
public void ReplaceOrientation(SwingTwist newOrientation) {
this._orientation = newOrientation;
if (newOrientation != this._orientation) {
this._orientation = newOrientation;
orientationUpdated = true;
}
}
private Spherical _linearVelocity = Spherical.zero;