Fix event order handling for diff.drive

This commit is contained in:
Pascal Serrarens 2025-06-18 17:10:53 +02:00
parent 9bfa288465
commit 66c494ad60
4 changed files with 23 additions and 17 deletions

View File

@ -50,10 +50,14 @@ namespace RoboidControl.Unity {
coreDrive.component = differentialDrive; coreDrive.component = differentialDrive;
break; break;
case RoboidControl.Motor coreMotor: case RoboidControl.Motor coreMotor:
if (coreMotor.component == null) {
Motor wheel = Motor.Create(coreMotor); Motor wheel = Motor.Create(coreMotor);
coreMotor.component = wheel; coreMotor.component = wheel;
// We need to know the details (though a binary msg) // We need to know the details (though a binary msg)
// before we can create the wheel reliably // before we can create the wheel reliably
}
else // Update the component from the core
coreMotor.component.Init(coreMotor);
break; break;
case RoboidControl.Thing coreThing: case RoboidControl.Thing coreThing:
if (coreThing.component == null) { if (coreThing.component == null) {
@ -69,6 +73,8 @@ namespace RoboidControl.Unity {
thing = Thing.Create(coreThing); thing = Thing.Create(coreThing);
coreThing.component = thing; coreThing.component = thing;
} }
else // Update the component from the core
coreThing.component.Init(coreThing);
break; break;
} }
} }

View File

@ -42,7 +42,7 @@ namespace RoboidControl.Unity {
/// </summary> /// </summary>
/// <param name="core">The core of the thing</param> /// <param name="core">The core of the thing</param>
/// This affects the parent and pose of the thing /// This affects the parent and pose of the thing
protected void Init(RoboidControl.Thing core) { public void Init(RoboidControl.Thing core) {
this.core = core; this.core = core;
this.core.component = this; this.core.component = this;
// This is wrong, it should get the owner, which is not the siteserver // This is wrong, it should get the owner, which is not the siteserver

View File

@ -111,9 +111,8 @@ namespace RoboidControl {
aThing.owner.networkId == networkId && aThing.owner.networkId == networkId &&
aThing.id == thingId aThing.id == thingId
); );
//Thing thing = things.Find(aThing => Thing.IsThing(aThing, networkId, thingId)); // if (thing == null)
if (thing == null) // Console.WriteLine($"Unknown Thing {this.networkId} [{networkId}/{thingId}]");
Console.WriteLine($"Unknown Thing {this.networkId} [{networkId}/{thingId}]");
return thing; return thing;
} }

View File

@ -465,15 +465,16 @@ namespace RoboidControl {
} }
Thing thing = owner.Get(msg.networkId, msg.thingId); Thing thing = owner.Get(msg.networkId, msg.thingId);
if (sender.networkId != owner.networkId) { if (thing != null) {
// Sender forwarded this thing msg UpdateEvent e = new() {
// So this is a remote thing messageId = ThingMsg.id,
thing ??= ProcessNewThing(owner, msg, true); thing = thing
};
owner.updateQueue.Enqueue(e);
} }
else { else {
// Sender is the owner of the thing bool isRemote = sender.networkId != owner.networkId;
// So this is a simulated thing thing = ProcessNewThing(owner, msg, isRemote);
thing ??= ProcessNewThing(owner, msg, false);
} }
if (msg.parentId != 0) { if (msg.parentId != 0) {