Files
StarterNG/StarterNG.Tests/PhysicsPresetTests.cs
Hirek 7c2d259fdc feat(settings): the physical models of the simulator, and Arcade and Realistic levels of realism
The Physics tab has a section of driving realism with the models the simulator
reads (utilities/Globals.cpp):
- couplerphysics: the legacy couplings, or the physical ones (play, give,
  breaking) of the player's train or of every train;
- physics.derailment: off, classic (the simulator's own monitor), physical;
- physics.collisions: classic or physical (the simulator's own);
- physics.trackbuckling: off, from the scenery (its own), also from heat;
- deer: animals by the track;
with the crash damage, the breaking pantographs, the power from the wires only
and the state of a consist at its start, moved here from General.

Two levels set them in one go: Arcade forgives - no derailment, the legacy
couplings and collisions, no buckling, no damage, power without the wires, every
consist ready to drive; Realistic takes the physical models - the couplings of
the player's train, the derailment by its criteria (a track's own speed limit
still derails nothing), the crush of the ends, buckling in the heat - and the
consists as the scenario has them. The simulator's own values stand between the
two and show as custom; each setting can still be changed on its own.

The developer tab has physics.derailment.trustlimits,
controlcoupling.enginecheck, ai.brakesetting.cw1 and physics.trackcheck. A list
takes the other words the simulator reads for its own (couplerphysics true,
physics.derailment no), and a word of a list is named per key where it means
something of its own there.
2026-11-29 20:16:24 +01:00

106 lines
3.8 KiB
C#

using StarterNG.Domain.Settings;
using StarterNG.Tests.Fakes;
namespace StarterNG.Tests;
public class PhysicsPresetTests
{
private static SimulatorSettings Defaults()
{
var installation = new TestInstallation();
installation.SettingsStore.Load();
return installation.SettingsStore.Settings.Copy();
}
[Fact]
public void The_simulators_own_physics_are_neither_arcade_nor_realistic()
{
Assert.Null(PhysicsPreset.Matching(Defaults()));
}
[Fact]
public void A_level_of_realism_applied_is_recognised_until_one_setting_moves()
{
foreach (var preset in PhysicsPreset.All)
{
var settings = Defaults();
preset.ApplyTo(settings);
Assert.Same(preset, PhysicsPreset.Matching(settings));
settings.CrashDamage = !settings.CrashDamage;
Assert.Null(PhysicsPreset.Matching(settings));
}
}
[Fact]
public void Arcade_forgives_and_realistic_takes_the_physical_models()
{
var arcade = Defaults();
PhysicsPreset.Arcade.ApplyTo(arcade);
Assert.False(arcade.CrashDamage);
Assert.False(arcade.LiveTraction);
Assert.Equal(ConsistReadyOverride.AlwaysReady, arcade.ReadyOverride);
Assert.Equal("off", arcade.Extra["physics.derailment"]);
var realistic = Defaults();
PhysicsPreset.Realistic.ApplyTo(realistic);
Assert.True(realistic.CrashDamage);
Assert.Equal(ConsistReadyOverride.Scenery, realistic.ReadyOverride);
Assert.Equal("yes", realistic.Extra["couplerphysics"]);
Assert.Equal("new", realistic.Extra["physics.derailment"]);
Assert.Equal("new", realistic.Extra["physics.collisions"]);
Assert.Equal("auto", realistic.Extra["physics.trackbuckling"]);
}
[Fact]
public void Every_value_of_a_level_is_one_its_row_offers()
{
foreach (var preset in PhysicsPreset.All)
foreach (var (name, value) in preset.Keys)
Assert.True(SimulatorKeys.Named(name).ChoiceIndex(value) >= 0, $"{preset.NameKey} {name} {value}");
Assert.All(PhysicsPreset.All.SelectMany(preset => preset.Keys.Keys), key => Assert.Contains(key, PhysicsPreset.AllKeys));
}
[Fact]
public void No_level_of_realism_touches_the_picture_nor_a_level_of_detail_the_realism()
{
var settings = Defaults();
GraphicsPreset.Low.ApplyTo(settings);
PhysicsPreset.Realistic.ApplyTo(settings);
Assert.Same(GraphicsPreset.Low, GraphicsPreset.Matching(settings));
GraphicsPreset.VeryHigh.ApplyTo(settings);
Assert.Same(PhysicsPreset.Realistic, PhysicsPreset.Matching(settings));
}
[Theory]
[InlineData("couplerphysics", "true", "yes")]
[InlineData("couplerphysics", "1", "yes")]
[InlineData("physics.derailment", "no", "off")]
[InlineData("physics.trackbuckling", "no", "off")]
[InlineData("couplerphysics", "no", "no")]
public void A_word_the_simulator_takes_for_another_stands_for_it(string name, string raw, string word)
{
var key = SimulatorKeys.Named(name);
Assert.Equal(key.ChoiceIndex(word), key.ChoiceIndex(raw));
}
[Fact]
public void A_level_of_realism_survives_a_save()
{
var installation = new TestInstallation();
var store = installation.SettingsStore;
store.Load();
PhysicsPreset.Realistic.ApplyTo(store.Settings);
store.Save();
var again = new TestInstallation(installation.Files).SettingsStore;
again.Load();
Assert.Same(PhysicsPreset.Realistic, PhysicsPreset.Matching(again.Settings));
string saved = installation.Files.ReadAllText(store.SavePath);
Assert.Contains("physics.derailment new", saved);
Assert.Contains("couplerphysics yes", saved);
}
}