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;
break;
case RoboidControl.Motor coreMotor:
if (coreMotor.component == null) {
Motor wheel = Motor.Create(coreMotor);
coreMotor.component = wheel;
// 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;
case RoboidControl.Thing coreThing:
if (coreThing.component == null) {
@ -69,6 +73,8 @@ namespace RoboidControl.Unity {
thing = Thing.Create(coreThing);
coreThing.component = thing;
}
else // Update the component from the core
coreThing.component.Init(coreThing);
break;
}
}

View File

@ -42,7 +42,7 @@ namespace RoboidControl.Unity {
/// </summary>
/// <param name="core">The core of the thing</param>
/// 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.component = this;
// 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.id == thingId
);
//Thing thing = things.Find(aThing => Thing.IsThing(aThing, networkId, thingId));
if (thing == null)
Console.WriteLine($"Unknown Thing {this.networkId} [{networkId}/{thingId}]");
// if (thing == null)
// Console.WriteLine($"Unknown Thing {this.networkId} [{networkId}/{thingId}]");
return thing;
}

View File

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