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:
Motor wheel = Motor.Create(coreMotor); if (coreMotor.component == null) {
coreMotor.component = wheel; Motor wheel = Motor.Create(coreMotor);
// We need to know the details (though a binary msg) coreMotor.component = wheel;
// before we can create the wheel reliably // We need to know the details (though a binary msg)
// 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
@ -51,8 +51,8 @@ namespace RoboidControl.Unity {
this.owner = core.owner.component; this.owner = core.owner.component;
if (core.parent != null && core.parent.component != null) { if (core.parent != null && core.parent.component != null) {
this.transform.SetParent(core.parent.component.transform, false); this.transform.SetParent(core.parent.component.transform, false);
this.transform.localPosition = Vector3.zero; this.transform.localPosition = Vector3.zero;
} }
else if (core.owner.component != null) { else if (core.owner.component != null) {
this.transform.SetParent(core.owner.component.transform, false); this.transform.SetParent(core.owner.component.transform, false);

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) {