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

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.
This commit is contained in:
jerrrrycho
2026-11-08 11:22:37 +01:00
parent 7f8892cda6
commit 1626df2bc4
5 changed files with 59 additions and 51 deletions

View File

@@ -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 <chrono>
#include <format>
#include <vector>
@@ -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<float>(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;

View File

@@ -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

View File

@@ -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 <algorithm>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <format>
@@ -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<float>(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<TMemCell>(scene::node_data{0, -1, std::string(result_cell), "memcell"}) };

View File

@@ -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

View File

@@ -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