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

View File

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

View File

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