18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-19 05:16:01 +01:00

refactor(simulation): tidy the test mode code

The test manager is reached through simulation::test() instead of a global,
the result cell is owned by a unique_ptr until the memory table takes it, the
cell value is compared with a margin, strings are built with std::format and
the --test settings moved to apply_test_mode_settings(). The driver's signal
check is folded into UpdateSpeedPosition(), which updates a speed table entry
and reports a signal at stop the head of the train just passed. The test.*
keys are listed with the other settings at the start of the log.
This commit is contained in:
jerrrrycho
2026-11-07 17:12:11 +01:00
parent 6a538d202b
commit 441caeed64
12 changed files with 131 additions and 75 deletions

View File

@@ -1137,6 +1137,38 @@ void eu07_application::init_files()
}
namespace fs = std::filesystem;
namespace
{
// the settings of the test mode (--test), over whatever the settings files say
void apply_test_mode_settings()
{
// nobody watches nor listens: no player vehicle, nothing drawn, no sound, no window in the way
Global.editor_session = false;
Global.local_start_vehicle = "ghostview";
Global.GfxRenderer = "null";
Global.NvRenderer = false;
Global.bSoundEnabled = false;
Global.python_enabled = false;
Global.bInactivePause = false;
Global.bFullScreen = false;
Global.fullscreen_windowed = false;
Global.VSync = false;
Global.iMultisampling = 0;
Global.gfx_usegles = false;
Global.minframetime = std::chrono::duration<float>(0.0f);
Global.extra_viewports.clear();
Global.headtrack_conf.joy.clear();
// a test runs on its own
Global.network_servers.clear();
Global.network_client.reset();
// and the same way every time, unless given another seed (-seed, or randomseed in the settings)
if (!Global.random_seed)
Global.random_seed = seed_of("test");
}
} // namespace
int eu07_application::init_settings(int Argc, char *Argv[])
{
Global.asVersion = VERSION_INFO;
@@ -1241,28 +1273,7 @@ int eu07_application::init_settings(int Argc, char *Argv[])
ErrorLog("test: --test needs a scenery given with -s");
return -1;
}
// nobody watches nor listens: no player vehicle, nothing drawn, no sound, no window in the way
Global.editor_session = false;
Global.local_start_vehicle = "ghostview";
Global.GfxRenderer = "null";
Global.NvRenderer = false;
Global.bSoundEnabled = false;
Global.python_enabled = false;
Global.bInactivePause = false;
Global.bFullScreen = false;
Global.fullscreen_windowed = false;
Global.VSync = false;
Global.iMultisampling = 0;
Global.gfx_usegles = false;
Global.minframetime = std::chrono::duration<float>(0.0f);
Global.extra_viewports.clear();
Global.headtrack_conf.joy.clear();
// a test runs on its own
Global.network_servers.clear();
Global.network_client.reset();
// and the same way every time, unless given another seed (-seed, or randomseed in the settings)
if (!Global.random_seed)
Global.random_seed = seed_of("test");
apply_test_mode_settings();
}
return 0;

View File

@@ -309,7 +309,7 @@ bool driver_mode::update()
if (Global.test.enabled && simulation::is_ready)
{
simulation::Test.update(deltatime);
simulation::test().update(deltatime);
}
}
@@ -488,7 +488,7 @@ void driver_mode::enter()
{
// the test runs as fast as it can compute, in steps of fixed length, so that runs on different machines agree
Timer::set_fixed_step(simulation::test_manager::frame_step);
simulation::Test.start();
simulation::test().start();
}
set_picking(!Global.captureonstart);

View File

@@ -60,7 +60,7 @@ bool scenarioloader_mode::update() {
ErrorLog(std::format("Bad init: scenario \"{}\" couldn't be opened ({})", Global.SceneryFile, e.what()));
state.reset();
if (Global.test.enabled) {
simulation::Test.finish(simulation::test_result::error, "scenario couldn't be opened");
simulation::test().finish(simulation::test_result::error, "scenario couldn't be opened");
return true;
}
Global.SceneryFile.clear();
@@ -80,7 +80,7 @@ bool scenarioloader_mode::update() {
state.reset();
if( Global.test.enabled ) {
// there's nothing to test; the exit code says the run went wrong
simulation::Test.finish( simulation::test_result::error, "scenario loading failed" );
simulation::test().finish( simulation::test_result::error, "scenario loading failed" );
return true;
}
Global.SceneryFile.clear();