feat(tapes): "live" follows the tapes of the black box, which it writes as the simulator runs

The simulator's black box writes the tapes of the player's vehicles every two seconds now, like the physics
logs, which no longer keep their files open.

- "Live" follows the player's tape with either one on; the tip that it waited for the closing is gone.
- The descriptions of the two settings say how they write now, in the five languages.
- A tape of a run the starter didn't launch goes with the black box recording when it was written: the
  tape of a vehicle the player left ends before the run does, and could be taken for a run of its own.
This commit is contained in:
maj00r
2026-11-14 00:50:03 +01:00
parent 45105e7b9c
commit 1398545ff2
9 changed files with 54 additions and 24 deletions

View File

@@ -80,6 +80,28 @@ public class BlackBoxListingTests
Assert.Equal(early, sessions[1].StartedUtc);
}
[Fact]
public void The_tape_of_a_vehicle_left_early_in_a_run_with_no_launch_goes_with_its_black_box()
{
// The black box writes the tapes as it goes: that of the vehicle the player left after ten minutes ends
// twenty minutes before the run, that of the next one with it.
var started = new DateTime(2026, 3, 1, 12, 0, 0, DateTimeKind.Utc);
string box = Box("td", started);
var installation = new TestInstallation(new InMemoryFileSystem()
.WithFile(Log("first.dat"), "t")
.WithFile(Log("second.dat"), "t")
.WithFile(Log(box), "b")
.WrittenAt(Log("first.dat"), started.AddMinutes(10))
.WrittenAt(Log(box), started.AddMinutes(30))
.WrittenAt(Log("second.dat"), started.AddMinutes(30).AddSeconds(1)));
var session = Assert.Single(installation.Tapes.Sessions());
Assert.Null(session.Launch);
Assert.Equal(new[] { "first", "second" }, session.Tapes.Select(tape => tape.Vehicle).Order());
Assert.EndsWith(box, Assert.Single(session.BlackBoxes).Path);
}
[Fact]
public void The_black_box_of_a_running_session_is_listed_while_it_is_written()
{

View File

@@ -41,7 +41,7 @@ public class StartSimulationTests
}
[Fact]
public void With_the_black_box_alone_the_launch_is_noted_for_the_tapes_it_writes_at_the_end()
public void With_the_black_box_alone_the_launch_is_noted_for_the_tapes_it_writes()
{
var (start, _, installation) = Rig(files => files.WithExecutable(Build), sceneryClock: "07:52");
installation.SettingsStore.Settings.BlackBox = true;

View File

@@ -35,6 +35,7 @@ public sealed class HaslerTapes
{
private const int RememberedLaunches = 30;
private static readonly TimeSpan QuietBetweenRuns = TimeSpan.FromMinutes(2);
private static readonly TimeSpan TapesAfterBlackBox = TimeSpan.FromSeconds(10);
private readonly IFileSystem _files;
private readonly IGamePaths _paths;
@@ -244,8 +245,9 @@ public sealed class HaslerTapes
/// <summary>
/// The runs the tapes came from, the running or latest one first. A tape belongs
/// to the last launch before it was written, unless a run the starter didn't launch
/// began between them; one with no launch goes with those written about the same
/// time, as a run writes them all at its end.
/// began between them; one with no launch goes with the black box recording when it
/// was written, or else with those written about the same time, as a run writes its
/// logs until it ends.
/// </summary>
public IReadOnlyList<TapeSession> Sessions()
{
@@ -278,11 +280,14 @@ public sealed class HaslerTapes
boxesBehind.GetValueOrDefault(launch, new List<BlackBoxRecording>())));
}
// What no launch covers goes together by when it was written: a run writes it all at its end.
// What no launch covers goes together by when it was written: a run writes its logs until it ends. A tape
// written while a black box recorded is of its run, though: the black box writes the tapes of the player's
// vehicles as it goes, and that of a vehicle the player left ends before the run does.
var looseBoxes = boxes.Where(b => LaunchOf(b, launches) is null).ToList();
var loose = tapes.Where(t => tapeLaunch[t] is null)
.Select(t => (Written: t.LastWriteUtc, Tape: (TapeFile?)t, Box: (BlackBoxRecording?)null))
.Concat(boxes.Where(b => LaunchOf(b, launches) is null)
.Select(b => (Written: b.LastWriteUtc, Tape: (TapeFile?)null, Box: (BlackBoxRecording?)b)))
.Select(t => (Written: RecordingAt(t.LastWriteUtc, looseBoxes)?.LastWriteUtc ?? t.LastWriteUtc,
Tape: (TapeFile?)t, Box: (BlackBoxRecording?)null))
.Concat(looseBoxes.Select(b => (Written: b.LastWriteUtc, Tape: (TapeFile?)null, Box: (BlackBoxRecording?)b)))
.OrderBy(file => file.Written);
var run = new List<TapeFile>();
var runBoxes = new List<BlackBoxRecording>();
@@ -315,6 +320,16 @@ public sealed class HaslerTapes
}
}
/// <summary>
/// The black box that was recording at the moment, the tapes being written last, a moment after it is closed.
/// Of more, the one that stopped nearest to it.
/// </summary>
private static BlackBoxRecording? RecordingAt(DateTime momentUtc, IEnumerable<BlackBoxRecording> boxes) =>
boxes.Where(box => NamedBy(box.Path) is { } named && named.StartedUtc <= momentUtc
&& momentUtc <= box.LastWriteUtc + TapesAfterBlackBox)
.OrderBy(box => (box.LastWriteUtc - momentUtc).Duration())
.FirstOrDefault();
private TapeFile ReadTape(string path) =>
new(path, Path.GetFileNameWithoutExtension(path), _files.GetLastWriteTimeUtc(path), _files.GetFileSize(path));

View File

@@ -233,14 +233,12 @@ public sealed class HaslerTapeWindow : Window
_recordingOff.IsVisible = !recording;
_logOff.IsVisible = recording && !settings.DebugLog;
// the black box alone writes the tapes when the simulator closes: only the physics log grows while it runs
bool canFollow = _running && settings.PhysicsLog && _tapes.DrivenVehicle is not null;
// the physics logs and the black box's tapes both grow while the simulator runs, every two seconds
bool canFollow = _running && recording && _tapes.DrivenVehicle is not null;
_live.IsEnabled = canFollow;
if (!canFollow)
_live.IsChecked = false;
ToolTip.SetTip(_live, App.Loc[canFollow ? "HaslerLiveTip"
: _running && !settings.PhysicsLog ? "HaslerLiveAtClose"
: "HaslerLiveIdle"]);
ToolTip.SetTip(_live, App.Loc[canFollow ? "HaslerLiveTip" : "HaslerLiveIdle"]);
}
private DockPanel Strip(string textKey, string buttonKey, Action<SimulatorSettings> enable)

View File

@@ -498,7 +498,7 @@
<String key="BreakingPantographPossibility">Možnost zlomení pantografu</String>
<String key="PowerOverheadLineOnly">Napájení jen pod trolejí</String>
<String key="SaveBlackBox">Nahrávat černou skříňku a pásky rychloměru</String>
<String key="SaveBlackBoxDesc">Nahrává jízdu do jednoho souboru ve složce physicslog/ a po zavření simulátoru zapíše pásky (.dat) vozidel, ve kterých jste byli.</String>
<String key="SaveBlackBoxDesc">Nahrává jízdu do jednoho souboru ve složce physicslog/ a průběžně, každé 2 s, zapisuje pásky (.dat) vozidel, ve kterých jste.</String>
<String key="SaveSpeedometerTapes">Ukládat fyzikální log všech vozidel</String>
<String key="SaveSimLogs">Ukládat log simulace</String>
<String key="KeepPrevLogs">Zachovat předchozí logy</String>
@@ -846,7 +846,6 @@
<String key="HaslerTrain">vlak {0}</String>
<String key="HaslerRoleDrivenEarlier">Řízené dříve</String>
<String key="HaslerLiveIdle">Funguje, když běží relace spuštěná ze starteru.</String>
<String key="HaslerLiveAtClose">Černá skříňka zapíše pásky po zavření simulátoru. Živě funguje s fyzikálním logem.</String>
<String key="HaslerLogOff">Log simulátoru je vypnutý: starter nevidí přesedání.</String>
<String key="HaslerLogEnable">Zapnout log</String>
<String key="HaslerRoleStartedIn">Vozidlo ze startu</String>

View File

@@ -517,9 +517,9 @@
<String key="PowerOverheadLineOnly">Powered only under overhead line</String>
<String key="PowerOverheadLineOnlyDesc">When disabled, a raised pantograph can power the vehicle even without touching the wire.</String>
<String key="SaveBlackBox">Record the black box and the speedometer tapes</String>
<String key="SaveBlackBoxDesc">Records the session to one file in the physicslog/ folder and, when the simulator closes, writes the tapes (.dat) of the vehicles you were in.</String>
<String key="SaveBlackBoxDesc">Records the session to one file in the physicslog/ folder and writes the tapes (.dat) of the vehicles you are in as it goes, every 2 s.</String>
<String key="SaveSpeedometerTapes">Save the physics log of every vehicle</String>
<String key="SaveSpeedometerTapesDesc">Writes the log of every vehicle of the scenery to the physicslog/ folder as it runs, 20 times a second. For diagnostics: on a large scenery that is hundreds of open files.</String>
<String key="SaveSpeedometerTapesDesc">Writes the log of every vehicle of the scenery to the physicslog/ folder: a line every 0.05 s, added every 2 s. For diagnostics: on a large scenery that is hundreds of files.</String>
<String key="SaveSimLogs">Save simulation log</String>
<String key="KeepPrevLogs">Keep previous logs</String>
<String key="KeepPrevLogsDesc">Creates a separate log file for each scenery instead of overwriting errors.txt.</String>
@@ -1075,7 +1075,6 @@
<String key="HaslerTrain">train {0}</String>
<String key="HaslerRoleDrivenEarlier">Driven earlier</String>
<String key="HaslerLiveIdle">Works while a session started from the starter runs.</String>
<String key="HaslerLiveAtClose">The black box writes the tapes when the simulator closes. Live works with the physics log.</String>
<String key="HaslerLogOff">The simulator's log is off: the starter does not see changes of vehicle.</String>
<String key="HaslerLogEnable">Turn the log on</String>
<String key="HaslerRoleStartedIn">Vehicle at the start</String>

View File

@@ -498,7 +498,7 @@
<String key="BreakingPantographPossibility">Áramszedő törésének lehetősége</String>
<String key="PowerOverheadLineOnly">Táplálás csak felsővezeték alatt</String>
<String key="SaveBlackBox">Fekete doboz és sebességmérő-szalagok rögzítése</String>
<String key="SaveBlackBoxDesc">A menetet egy fájlba rögzíti a physicslog/ mappában, és a szimulátor bezárásakor kiírja azoknak a járműveknek a szalagjait (.dat), amelyekben ültél.</String>
<String key="SaveBlackBoxDesc">A menetet egy fájlba rögzíti a physicslog/ mappában, és menet közben, 2 másodpercenként kiírja azoknak a járműveknek a szalagjait (.dat), amelyekben ülsz.</String>
<String key="SaveSpeedometerTapes">Minden jármű fizikai naplójának mentése</String>
<String key="SaveSimLogs">Szimulációs napló mentése</String>
<String key="KeepPrevLogs">Korábbi naplók megtartása</String>
@@ -846,7 +846,6 @@
<String key="HaslerTrain">vonat {0}</String>
<String key="HaslerRoleDrivenEarlier">Korábban vezetett</String>
<String key="HaslerLiveIdle">Az indítóból indított munkamenet alatt működik.</String>
<String key="HaslerLiveAtClose">A fekete doboz a szimulátor bezárásakor írja ki a szalagokat. Az élő nézet a fizikai naplóval működik.</String>
<String key="HaslerLogOff">A szimulátor naplója ki van kapcsolva: az indító nem látja a járműváltást.</String>
<String key="HaslerLogEnable">Napló bekapcsolása</String>
<String key="HaslerRoleStartedIn">Indulási jármű</String>

View File

@@ -517,9 +517,9 @@
<String key="PowerOverheadLineOnly">Zasilanie tylko pod siecią trakcyjna</String>
<String key="PowerOverheadLineOnlyDesc">Gdy wyłączone, podniesiony pantograf zasila pojazd nawet bez kontaktu z drutem.</String>
<String key="SaveBlackBox">Zapisuj czarną skrzynkę i taśmy prędkościomierza</String>
<String key="SaveBlackBoxDesc">Nagrywa przejazd do jednego pliku w folderze physicslog/, a po zamknięciu symulatora zapisuje taśmy (.dat) pojazdów, w których byłeś.</String>
<String key="SaveBlackBoxDesc">Nagrywa przejazd do jednego pliku w folderze physicslog/ i na bieżąco, co 2 s, zapisuje taśmy (.dat) pojazdów, w których jesteś.</String>
<String key="SaveSpeedometerTapes">Zapisuj log parametrów fizycznych wszystkich pojazdów</String>
<String key="SaveSpeedometerTapesDesc">Zapisuje na bieżąco log każdego pojazdu scenerii do folderu physicslog/, 20 razy na sekundę. Do diagnostyki: na dużej scenerii to setki otwartych plików.</String>
<String key="SaveSpeedometerTapesDesc">Zapisuje log każdego pojazdu scenerii do folderu physicslog/: wiersz co 0,05 s, dopisywany co 2 s. Do diagnostyki: na dużej scenerii to setki plików.</String>
<String key="SaveSimLogs">Zapisuj log z symulacji</String>
<String key="KeepPrevLogs">Zachowuj poprzednie logi</String>
<String key="KeepPrevLogsDesc">Tworzy osobny plik logu dla każdej scenerii zamiast nadpisywać errors.txt.</String>
@@ -897,7 +897,6 @@
<String key="HaslerTrain">pociąg {0}</String>
<String key="HaslerRoleDrivenEarlier">Prowadzony wcześniej</String>
<String key="HaslerLiveIdle">Działa, gdy trwa sesja uruchomiona ze Startera.</String>
<String key="HaslerLiveAtClose">Czarna skrzynka zapisuje taśmy po zamknięciu symulatora. Na żywo działa z logiem parametrów fizycznych.</String>
<String key="HaslerLogOff">Log symulatora jest wyłączony: Starter nie widzi przesiadek.</String>
<String key="HaslerLogEnable">Włącz log</String>
<String key="HaslerRoleStartedIn">Pojazd ze startu</String>

View File

@@ -498,7 +498,7 @@
<String key="BreakingPantographPossibility">Возможность излома пантографа</String>
<String key="PowerOverheadLineOnly">Питание только под контактной сетью</String>
<String key="SaveBlackBox">Записывать чёрный ящик и ленты скоростемера</String>
<String key="SaveBlackBoxDesc">Записывает поездку в один файл в папке physicslog/, а при закрытии симулятора сохраняет ленты (.dat) тех единиц, в которых вы были.</String>
<String key="SaveBlackBoxDesc">Записывает поездку в один файл в папке physicslog/ и по ходу, каждые 2 с, сохраняет ленты (.dat) тех единиц, в которых вы находитесь.</String>
<String key="SaveSpeedometerTapes">Сохранять физический лог всех единиц</String>
<String key="SaveSimLogs">Сохранять журнал симуляции</String>
<String key="KeepPrevLogs">Сохранять предыдущие журналы</String>
@@ -846,7 +846,6 @@
<String key="HaslerTrain">поезд {0}</String>
<String key="HaslerRoleDrivenEarlier">Управлялся ранее</String>
<String key="HaslerLiveIdle">Работает, пока идёт сеанс, запущенный из стартера.</String>
<String key="HaslerLiveAtClose">Чёрный ящик сохраняет ленты при закрытии симулятора. Режим «вживую» работает с физическим логом.</String>
<String key="HaslerLogOff">Журнал симулятора выключен: стартер не видит пересадок.</String>
<String key="HaslerLogEnable">Включить журнал</String>
<String key="HaslerRoleStartedIn">Транспорт на старте</String>