From 91e0d90e8daa12a0861663271c1683a593a38e09 Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Sun, 8 Nov 2026 17:38:59 +0100 Subject: [PATCH] fix: review of the separate engine start switches (eu07/maszyna#80) - initialise the cooling power read from the .fiz to its default, no division by an indeterminate value - integer step counters in the engine start tests - main_sw opening the consist turns the two-state mainb_sw / mainc_sw off too, left on they'd start the engines again - the doc comment of MainCircuitOpensWithStarterOnly() back on it; the .fiz read is the controlled vehicle's --- McZapkie/MOVER.h | 6 +++--- McZapkie/Mover.cpp | 2 +- tests/unit/test_engine_start.cpp | 17 +++++++++++------ vehicle/Train.cpp | 12 ++++++++++++ vehicle/enginestart.h | 7 ++++--- 5 files changed, 31 insertions(+), 13 deletions(-) diff --git a/McZapkie/MOVER.h b/McZapkie/MOVER.h index 3d0f7b777..1d9ca414b 100644 --- a/McZapkie/MOVER.h +++ b/McZapkie/MOVER.h @@ -2475,15 +2475,15 @@ class TMoverParameters } return false == StLinFlag && MainCircuitLampsEnabled(); } - // whether the cab command opening the main circuit opens it where the only cab switch of the circuit is the button - // closing it: on a diesel that's the starter button, and the command is the one way to stop an engine whose fuel pump - // starts on its own (eu07/maszyna#427). the other vehicles with such a button keep ignoring the command // the vehicles the line breaker / engine start switch of this vehicle works, and its engine stopping on its own // stops: the whole consist, or with JointEngineStart=No this vehicle alone (eu07/maszyna#80) range_t MainSwitchRange() const { return JointEngineStart ? range_t::consist : range_t::local; } + // whether the cab command opening the main circuit opens it where the only cab switch of the circuit is the button + // closing it: on a diesel that's the starter button, and the command is the one way to stop an engine whose fuel pump + // starts on its own (eu07/maszyna#427). the other vehicles with such a button keep ignoring the command bool MainCircuitOpensWithStarterOnly() const { return EngineType == TEngineType::DieselEngine || EngineType == TEngineType::DieselElectric; diff --git a/McZapkie/Mover.cpp b/McZapkie/Mover.cpp index e48ae4e11..f6697d934 100644 --- a/McZapkie/Mover.cpp +++ b/McZapkie/Mover.cpp @@ -11394,7 +11394,7 @@ void TMoverParameters::LoadFIZ_Engine(std::string const &Input) // water heater extract_value(WaterHeater.config.temp_min, "HeaterMinTemperature", Input, ""); extract_value(WaterHeater.config.temp_max, "HeaterMaxTemperature", Input, ""); - float pf; + float pf{ 1235.f }; extract_value(pf, "NominalCoolingPower", Input, "1235"); dizel_heat.powerfactor = 1235 / pf; } diff --git a/tests/unit/test_engine_start.cpp b/tests/unit/test_engine_start.cpp index 6524075c3..e763a4404 100644 --- a/tests/unit/test_engine_start.cpp +++ b/tests/unit/test_engine_start.cpp @@ -42,10 +42,17 @@ bool running(TMoverParameters const &Vehicle) { return Vehicle.Mains && Vehicle.enrot > 0.5 * Vehicle.dizel_nmin; } +// the time step of the train in the loops below +auto const dt{0.01}; + +// the count of the steps of dt making up Seconds +int steps(double const Seconds) { + return static_cast(std::lround(Seconds / dt)); +} + // the switch of Engine held closed for Seconds, then let go, in steps of the train void hold(consist &Train, engine_start::remote_switch &Switch, TMoverParameters *Engine, double const Seconds, bool const Closesonrelease = false) { - auto const dt{0.01}; - for (auto time = 0.0; time < Seconds; time += dt) { + for (auto step = 0; step < steps(Seconds); ++step) { Switch.update(Engine, true, false, dt, Closesonrelease); Train.step({}, dt); } @@ -185,8 +192,7 @@ TEST_CASE("engine start: the switch of another vehicle is held for the vehicle's hold(train, switchb, &second, 1.0); CHECK_FALSE(engine_start::remote_switch::is_running(second)); // the switch opening the circuit held along, the closing one does nothing - auto const dt{0.01}; - for (auto time = 0.0; time < 3.0; time += dt) { + for (auto step = 0; step < steps(3.0); ++step) { switchb.update(&second, true, true, dt, false); train.step({}, dt); } @@ -204,9 +210,8 @@ TEST_CASE("engine start: a switch closing on release, as an electric locomotive' auto &second{train.add(sn61(false).set("Cntrl", "IniCDelay", "1.0")).mover()}; prepare(train); engine_start::remote_switch switchb; - auto const dt{0.01}; // held past the delay, the circuit stays open while the switch is held - for (auto time = 0.0; time < 2.0; time += dt) { + for (auto step = 0; step < steps(2.0); ++step) { switchb.update(&second, true, false, dt, true); train.step({}, dt); } diff --git a/vehicle/Train.cpp b/vehicle/Train.cpp index ab60371c4..8fa708c29 100644 --- a/vehicle/Train.cpp +++ b/vehicle/Train.cpp @@ -3727,6 +3727,18 @@ void TTrain::OnCommand_linebreakeropen(TTrain *Train, command_data const &Comman if (true == Train->mvControlled->MainSwitch(false, Train->mvControlled->MainSwitchRange())) { Train->m_linebreakerstate = 0; + if (Train->mvControlled->MainSwitchRange() != range_t::local) + { + // the engines of the vehicles in multiple stopped along: their two-state switches go off too, left on + // they'd start them again after the delay + for (auto &controls : Train->m_remotelinebreakers) + { + if (controls.main_switch.SubModel != nullptr && controls.main_switch.type() == TGaugeType::toggle) + { + controls.main_switch.UpdateValue(0.0); + } + } + } } } else if (Command.action == GLFW_RELEASE) diff --git a/vehicle/enginestart.h b/vehicle/enginestart.h index beedab106..77b6a2d93 100644 --- a/vehicle/enginestart.h +++ b/vehicle/enginestart.h @@ -13,9 +13,10 @@ class TMoverParameters; // starting the engines (closing the line breakers) of the vehicles in multiple from the cab (eu07/maszyna#80). in // vehicles like the ST43, the SP32 or the SN61 every engine of the train has its own switches in the cab: main_* work -// the cab's own vehicle, mainb_* the second one and mainc_* the third one under its control. Engine:JointEngineStart=No -// in the .fiz of the cab's vehicle keeps main_* to that vehicle alone (TMoverParameters::MainSwitchRange()); by -// default it works all of them, as before. +// the vehicle the cab controls (TTrain::mvControlled: the cab's own vehicle, on an EMU its motor car), mainb_* the +// second one and mainc_* the third one under its control. Engine:JointEngineStart=No in the .fiz of the controlled +// vehicle (on an EMU the motor car's, not the one of the car with the cab) keeps main_* to that vehicle alone +// (TMoverParameters::MainSwitchRange()); by default it works all of them, as before. namespace engine_start { // the Number-th vehicle with an engine under the cab's control: 1 is Controlled, the cab's own; then the others