From 1626df2bc49945680f596395f06f81256edd2130 Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Sun, 8 Nov 2026 11:22:37 +0100 Subject: [PATCH] fix(simulation): a scenery's config block can't turn back on what a test keeps off The config block of a scenery is read like the settings files, after the test mode settings were applied, so a scenery with soundenabled, multiplayer, execonexit, feedbackmode or the like in it got them back in a test run. The test mode settings now are applied again after each config block of the scenery; apply_test_mode_settings() moved to simulationtest.cpp for that. --- application/application.cpp | 52 +----------------------- simulation/simulationstateserializer.cpp | 5 +++ simulation/simulationtest.cpp | 46 +++++++++++++++++++++ simulation/simulationtest.h | 5 +++ tests/scenarios/README.md | 2 + 5 files changed, 59 insertions(+), 51 deletions(-) diff --git a/application/application.cpp b/application/application.cpp index 638eacdc..d0ef6a01 100644 --- a/application/application.cpp +++ b/application/application.cpp @@ -31,9 +31,6 @@ http://mozilla.org/MPL/2.0/. #include "utilities/dictionary.h" #include "version_info.h" #include "simulation/simulationtest.h" -#ifdef _WIN32 -#include "Console.h" -#endif #include #include #include @@ -1149,53 +1146,6 @@ 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(0.0f); - Global.extra_viewports.clear(); - Global.headtrack_conf.joy.clear(); - // a test runs on its own: no network, and no input from outside (eu07/maszyna#541) - Global.network_servers.clear(); - Global.network_client.reset(); - Global.InputGamepad = false; - Global.InputMouse = false; - Global.uart_conf.enable = false; - Global.motiontelemetry_conf.enable = false; -#ifdef WITH_ZMQ - Global.zmq_address.clear(); -#endif - // nor anything to the outside: no keyboard leds, LPT or PoKeys desk (feedbackmode), no messages to a - // multiplayer server (multiplayer, which also holds some events back for it), no program run at the end - Global.iFeedbackMode = 0; -#ifdef _WIN32 - Console::ModeSet(Global.iFeedbackMode, Global.iFeedbackPort); -#endif - Global.iMultiplayer = 0; - Global.exec_on_exit.clear(); - // 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; @@ -1315,7 +1265,7 @@ int eu07_application::init_settings(int Argc, char *Argv[]) simulation::test().conclude(simulation::test_result::error, "--test needs a scenery given with -s"); return -1; } - apply_test_mode_settings(); + simulation::apply_test_mode_settings(); } return 0; diff --git a/simulation/simulationstateserializer.cpp b/simulation/simulationstateserializer.cpp index 664f3b95..24470007 100644 --- a/simulation/simulationstateserializer.cpp +++ b/simulation/simulationstateserializer.cpp @@ -15,6 +15,7 @@ http://mozilla.org/MPL/2.0/. #include "simulation/simulationtime.h" #include "simulation/simulationsounds.h" #include "simulation/simulationenvironment.h" +#include "simulation/simulationtest.h" #include "scene/scenenodegroups.h" #include "scene/scenelayers.h" #include "scene/sceneterrain.h" @@ -363,6 +364,10 @@ state_serializer::deserialize_config( cParser &Input, scene::scratch_data &Scrat // config parameters (re)definition Global.ConfigParse( Input ); + if( Global.test.enabled ) { + // a scenery doesn't get to turn on what a test keeps off + simulation::apply_test_mode_settings(); + } } void diff --git a/simulation/simulationtest.cpp b/simulation/simulationtest.cpp index 76aa1be3..67e05ad3 100644 --- a/simulation/simulationtest.cpp +++ b/simulation/simulationtest.cpp @@ -15,11 +15,16 @@ http://mozilla.org/MPL/2.0/. #include "simulation/simulation.h" #include "utilities/Globals.h" #include "utilities/Logs.h" +#include "utilities/utilities.h" #include "vehicle/DynObj.h" #include "world/Event.h" #include "world/MemCell.h" +#ifdef _WIN32 +#include "Console.h" +#endif #include +#include #include #include #include @@ -33,6 +38,47 @@ test_manager &test() return instance; } +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(0.0f); + Global.extra_viewports.clear(); + Global.headtrack_conf.joy.clear(); + // a test runs on its own: no network, and no input from outside (eu07/maszyna#541) + Global.network_servers.clear(); + Global.network_client.reset(); + Global.InputGamepad = false; + Global.InputMouse = false; + Global.uart_conf.enable = false; + Global.motiontelemetry_conf.enable = false; +#ifdef WITH_ZMQ + Global.zmq_address.clear(); +#endif + // nor anything to the outside: no keyboard leds, LPT or PoKeys desk (feedbackmode), no messages to a + // multiplayer server (multiplayer, which also holds some events back for it), no program run at the end + Global.iFeedbackMode = 0; +#ifdef _WIN32 + Console::ModeSet(Global.iFeedbackMode, Global.iFeedbackPort); +#endif + Global.iMultiplayer = 0; + Global.exec_on_exit.clear(); + // 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"); +} + void test_manager::init_result_cell() const { auto cell { std::make_unique(scene::node_data{0, -1, std::string(result_cell), "memcell"}) }; diff --git a/simulation/simulationtest.h b/simulation/simulationtest.h index 66384b6e..e67b2ada 100644 --- a/simulation/simulationtest.h +++ b/simulation/simulationtest.h @@ -53,4 +53,9 @@ private: // the test of the run test_manager &test(); +// the settings of the test mode, over whatever the settings files and the scenery say: applied once the command +// line is read, and again after each config block of the scenery, which could turn the sound, the network or the +// program run at the end back on +void apply_test_mode_settings(); + } // namespace simulation diff --git a/tests/scenarios/README.md b/tests/scenarios/README.md index ca45dc34..006a0fc6 100644 --- a/tests/scenarios/README.md +++ b/tests/scenarios/README.md @@ -32,6 +32,8 @@ With `--test` the simulator: - gives nothing to the outside either: no keyboard leds, LPT or PoKeys (`feedbackmode`), no messages to a multiplayer server (`multiplayer`), no program run at the end (`execonexit`), no console window of its own (`showsystemconsole`), and the game's `imgui.ini` stays as it is, +- keeps all of the above whatever the `config` block of the scenery says: the settings of the + test mode are applied again after it, - runs the simulation as fast as it can in fixed steps of 0.03 s of simulation time per frame (three 10 ms physics steps), whatever the real time, the time speed or the machine, - seeds its random numbers with a fixed seed unless `-seed` or `randomseed` gives one, so two