fix(blackbox): the doors' sides as the driver has them, from the rear cab swapped

The recording holds the left and right of the vehicle, and from its rear cab
the driver's left doors are the vehicle's right, as the simulator works them.
The cab panel and the events showed the vehicle's sides, so after a change of
direction to the other cab the doors opened on the wrong side. A change of the
cab tells nothing of the doors in the events.
This commit is contained in:
maj00r
2026-11-15 23:46:26 +01:00
parent 06513537f0
commit b2fd53f7bc
4 changed files with 60 additions and 4 deletions

View File

@@ -226,7 +226,7 @@ public sealed class CabPanel : Control
// The doors under them, in two columns: open, permitted, the departure signal, the steps and the lock.
top = Math.Max(bottom, top + 16 + 9 * LampRow) + 6;
context.DrawText(MapView.Text(Strings["CabGroupDoors"], Palette.DimText, 10, FontWeight.SemiBold), new Point(Pad, top));
var doors = Doors(s);
var doors = Doors(s.AsTheCabSees);
double doorColumn = width / DoorColumns;
for (int i = 0; i < doors.Length; i++)
{

View File

@@ -282,6 +282,8 @@ public sealed class EventList : ListBox
(CabDevices.DoorStep, "DevDoorStep"), (CabDevices.DoorLock, "DevDoorLock"), (CabDevices.SpeedControl, "DevSpeedControl")
];
private const CabDevices DoorSides = CabDevices.DoorsLeft | CabDevices.DoorsRight | CabDevices.DoorPermitLeft | CabDevices.DoorPermitRight;
/// <summary>
/// What the driver did in the cab, from one look to the next in the same vehicle: the switches on and off, the
/// doors opened and closed, the departure signal, the hand brake, the brakes' setting, the radio's channel, the
@@ -291,7 +293,8 @@ public sealed class EventList : ListBox
{
CabSample? last = null;
bool movingOpen = false;
foreach (var s in recording.Cab)
// the doors' sides as the driver has them, from the cab the driver is in (CabSample.AsTheCabSees)
foreach (var s in recording.Cab.Select(sample => sample.AsTheCabSees))
{
if (last is not { } b || b.Vehicle != s.Vehicle)
{
@@ -299,8 +302,10 @@ public sealed class EventList : ListBox
movingOpen = false;
continue;
}
bool Came(CabDevices device) => !b.Has(device) && s.Has(device);
bool Went(CabDevices device) => b.Has(device) && !s.Has(device);
// another cab swaps the sides, and tells nothing of the doors
bool sameCab = b.CabEnd == s.CabEnd;
bool Came(CabDevices device) => !b.Has(device) && s.Has(device) && (sameCab || (device & DoorSides) == 0);
bool Went(CabDevices device) => b.Has(device) && !s.Has(device) && (sameCab || (device & DoorSides) == 0);
foreach (var (device, key) in Switched)
{
if (Came(device))

View File

@@ -375,6 +375,26 @@ public readonly record struct CabSample(double Time, int Vehicle, Position Posit
public bool Has(CabDevices device) => (Devices & device) == device;
public bool Has(SecurityFlags flag) => (Security & flag) == flag;
private const CabDevices LeftDoors = CabDevices.DoorsLeft | CabDevices.DoorPermitLeft;
private const CabDevices RightDoors = CabDevices.DoorsRight | CabDevices.DoorPermitRight;
/// <summary>
/// The doors as the driver has them: the recording holds the left and right of the vehicle, and from its rear
/// cab the driver's left is the vehicle's right, as the simulator works the doors from it. Out of a cab, the
/// vehicle's.
/// </summary>
public CabSample AsTheCabSees =>
CabEnd >= 0
? this
: this with
{
Devices = (Devices & ~(LeftDoors | RightDoors))
| ((Devices & CabDevices.DoorsLeft) != 0 ? CabDevices.DoorsRight : 0)
| ((Devices & CabDevices.DoorsRight) != 0 ? CabDevices.DoorsLeft : 0)
| ((Devices & CabDevices.DoorPermitLeft) != 0 ? CabDevices.DoorPermitRight : 0)
| ((Devices & CabDevices.DoorPermitRight) != 0 ? CabDevices.DoorPermitLeft : 0)
};
public bool AiValid => (Flags & CabFlags.AiValid) != 0;
public bool InCab => (Flags & CabFlags.InCab) != 0;
public float AbsSpeedKmh => Math.Abs(SpeedKmh);

View File

@@ -0,0 +1,31 @@
using Eu07.BlackBox;
namespace StarterNG.Tests.BlackBox;
public class CabDoorsTests
{
private static CabSample Sample(sbyte cab, CabDevices devices) =>
default(CabSample) with { CabEnd = cab, Devices = devices | CabDevices.Radio };
[Fact]
public void From_the_rear_cab_the_vehicles_right_doors_are_the_drivers_left()
{
var seen = Sample(-1, CabDevices.DoorsRight | CabDevices.DoorPermitRight).AsTheCabSees;
Assert.True(seen.Has(CabDevices.DoorsLeft));
Assert.True(seen.Has(CabDevices.DoorPermitLeft));
Assert.False(seen.Has(CabDevices.DoorsRight));
Assert.False(seen.Has(CabDevices.DoorPermitRight));
Assert.True(seen.Has(CabDevices.Radio));
}
[Theory]
[InlineData(1)]
[InlineData(0)]
public void From_the_front_cab_or_out_of_one_the_sides_are_the_vehicles(sbyte cab)
{
var sample = Sample(cab, CabDevices.DoorsLeft | CabDevices.DoorPermitRight);
Assert.Equal(sample, sample.AsTheCabSees);
}
}