From d8f3875929b6fd4829cc6c69ea52de6f03892e0b Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Sat, 7 Nov 2026 18:22:42 +0100 Subject: [PATCH 1/2] fix(gfx): diesel smoke only once the engine fires, not while the starter turns (eu07/maszyna#523) The smoke of a diesel came out at full strength the moment its ignition set Mains and started the spin up, together with the ignition sound, whose first part is the starter cranking the engine. The ignition now starts a countdown of the new optional .fiz parameter SmokeDelay (Engine section of DieselEngine and DieselElectric vehicles, seconds, default 2.0, 0 restores the old behaviour); the smoke source of the vehicle spawns nothing until it runs out. Engines already running, or switched on another way, smoke as before. No SVN data change is needed; vehicle authors may tune SmokeDelay to the cranking part of their ignition: sample. --- McZapkie/MOVER.h | 4 +++ McZapkie/Mover.cpp | 7 ++++ tests/unit/test_smoke.cpp | 68 +++++++++++++++++++++++++++++++++++++++ vehicle/smoke.cpp | 2 +- vehicle/smoke.h | 1 + 5 files changed, 81 insertions(+), 1 deletion(-) diff --git a/McZapkie/MOVER.h b/McZapkie/MOVER.h index 199c65a0..f39de8e2 100644 --- a/McZapkie/MOVER.h +++ b/McZapkie/MOVER.h @@ -2171,6 +2171,10 @@ class TMoverParameters bool dizel_startup{false}; // engine startup procedure request indicator bool dizel_ignition{false}; // engine ignition request indicator bool dizel_spinup{false}; // engine spin up to idle speed flag + // the starter turns the engine a while before it fires: smoke comes out only after SmokeDelay (the Engine section of the .fiz, + // seconds from the start of the spin up) has passed. 0 lets it out as soon as the starter turns, as before eu07/maszyna#523 + double dizel_SmokeDelay{2.0}; + double dizel_FiringCountdown{0.0}; // seconds left until the engine being started fires, 0 once it runs on its own double dizel_engagedeltaomega = 0.0; /*roznica predkosci katowych tarcz sprzegla*/ double dizel_n_old = 0.0; /*poredkosc na potrzeby obliczen sprzegiel*/ double dizel_Torque = 0.0; /*aktualny moment obrotowy silnika spalinowego*/ diff --git a/McZapkie/Mover.cpp b/McZapkie/Mover.cpp index 330e8eb8..8632e404 100644 --- a/McZapkie/Mover.cpp +++ b/McZapkie/Mover.cpp @@ -7843,6 +7843,9 @@ bool TMoverParameters::dizel_Update(double dt) WaterHeaterCheck(dt); OilPumpCheck(dt); FuelPumpCheck(dt); + // the engine being started fires once the starter has turned it a while; one stopped meanwhile starts over + dizel_FiringCountdown = (Mains ? std::max(0.0, dizel_FiringCountdown - dt) : 0.0); + if (true == dizel_startup && true == dizel_StartupCheck()) { dizel_ignition = true; @@ -7857,6 +7860,7 @@ bool TMoverParameters::dizel_Update(double dt) LastSwitchingTime = 0; Mains = true; dizel_spinup = true; + dizel_FiringCountdown = dizel_SmokeDelay; enrot = std::max(enrot, 0.35 * ( // TODO: dac zaleznie od temperatury i baterii EngineType == TEngineType::DieselEngine ? dizel_nmin : DElist[0].RPM / 60.0)); @@ -11365,6 +11369,9 @@ void TMoverParameters::LoadFIZ_Engine(std::string const &Input) // oil pump extract_value(OilPump.pressure_minimum, "OilMinPressure", Input, ""); extract_value(OilPump.pressure_maximum, "OilMaxPressure", Input, ""); + // the time the starter turns the engine before it fires and smokes (eu07/maszyna#523) + extract_value(dizel_SmokeDelay, "SmokeDelay", Input, ""); + dizel_SmokeDelay = std::max(0.0, dizel_SmokeDelay); // engine cooling factore extract_value(dizel_heat.kw, "HeatKW", Input, ""); extract_value(dizel_heat.kv, "HeatKV", Input, ""); diff --git a/tests/unit/test_smoke.cpp b/tests/unit/test_smoke.cpp index 05fb8ae8..a1ea788f 100644 --- a/tests/unit/test_smoke.cpp +++ b/tests/unit/test_smoke.cpp @@ -2,6 +2,7 @@ #include "doctest.h" #include "vehicle.h" +#include "drive.h" #include "vehicle/smoke.h" @@ -83,3 +84,70 @@ TEST_CASE("smoke: the pending particles never outgrow the room of the source") { CHECK(smoke::vehicle_spawn_count(vehicle.mover(), true, rate, 10.0) == rate.limit); } + +TEST_CASE("smoke: an engine the starter turns lets out no smoke until it fires (#523)") { + auto vehicle{diesel()}; + vehicle->dizel_spinup = true; + auto pending{source}; + pending.pending = 5.f; + + vehicle->dizel_FiringCountdown = 0.5; + CHECK(smoke::vehicle_spawn_count(vehicle.mover(), true, pending, update) == 0.f); + + vehicle->dizel_FiringCountdown = 0.0; + CHECK(smoke::vehicle_spawn_count(vehicle.mover(), true, pending, update) >= 1.f); +} + +namespace { + +// the locomotive's engine started the way the AI starts it, a second at a time, until it runs (Mains) +bool start_engine(test::driven const &Driven, test::track const &Track) { + for (int second = 0; second < 120 && false == Driven.controlling.Mains; ++second) { + test::start_up(Driven, Track, 1.0); + } + return Driven.controlling.Mains; +} + +} // namespace + +TEST_CASE("smoke: a real diesel smokes only once its engine has fired, SmokeDelay after the starter began (#523)") { + // a diesel with a mechanical transmission and a diesel-electric one + for (auto const *path : {"sm42_v1/6d1", "st44_v2/m62-1151"}) { + CAPTURE(path); + test::track const track{}; + { + // the default delay + test::vehicle locomotive{test::definition::fiz(path)}; + REQUIRE(locomotive->dizel_SmokeDelay == doctest::Approx(2.0)); + auto const driven{test::driving(locomotive)}; + REQUIRE(start_engine(driven, track)); + // the engine started less than a second ago: the starter still turns it + CHECK(locomotive->dizel_FiringCountdown > 0.5); + CHECK(smoke::vehicle_spawn_count(locomotive.mover(), true, source, update) == 0.f); + // it has fired since + test::drive(driven, track, 3.0); + CHECK(locomotive->Mains); + CHECK(locomotive->dizel_FiringCountdown == 0.0); + CHECK(smoke::vehicle_spawn_count(locomotive.mover(), true, source, update) >= 1.f); + } + { + // SmokeDelay=0: smoke as soon as the starter turns, as before + test::vehicle locomotive{test::definition{test::definition::fiz(path)}.set("Engine", "SmokeDelay", 0)}; + REQUIRE(locomotive->dizel_SmokeDelay == 0.0); + auto const driven{test::driving(locomotive)}; + REQUIRE(start_engine(driven, track)); + CHECK(locomotive->dizel_FiringCountdown == 0.0); + CHECK(smoke::vehicle_spawn_count(locomotive.mover(), true, source, update) >= 1.f); + } + { + // a longer delay from the .fiz + test::vehicle locomotive{test::definition{test::definition::fiz(path)}.set("Engine", "SmokeDelay", 5)}; + auto const driven{test::driving(locomotive)}; + REQUIRE(start_engine(driven, track)); + test::drive(driven, track, 3.0); + CHECK(smoke::vehicle_spawn_count(locomotive.mover(), true, source, update) == 0.f); + test::drive(driven, track, 3.0); + CHECK(smoke::vehicle_spawn_count(locomotive.mover(), true, source, update) >= 1.f); + } + } +} diff --git a/vehicle/smoke.cpp b/vehicle/smoke.cpp index b6e92322..f5f64bef 100644 --- a/vehicle/smoke.cpp +++ b/vehicle/smoke.cpp @@ -34,7 +34,7 @@ double engine_load(TMoverParameters const &Mover) { } // namespace float vehicle_spawn_count(TMoverParameters const &Mover, bool const Ontracks, spawn_rate const &Rate, double const Timedelta) { - if (false == Ontracks) { + if (false == Ontracks || Mover.dizel_FiringCountdown > 0.0) { return 0.f; } // the steady rate of the source, the way a source of the scenery spawns... diff --git a/vehicle/smoke.h b/vehicle/smoke.h index e9dac262..dbcc131a 100644 --- a/vehicle/smoke.h +++ b/vehicle/smoke.h @@ -25,6 +25,7 @@ struct spawn_rate { // number of particles the smoke source of a vehicle has to spawn after Timedelta seconds: the steady rate of the // source, plus a share which grows with the work of its engine. a vehicle taken off the tracks (Ontracks false: gone through a portal, or waiting in the pool of the road // traffic) puffs no more, the particles it already let out fade away as usual +// an engine the starter turns but which hasn't fired yet (TMoverParameters::dizel_FiringCountdown) lets out no smoke either float vehicle_spawn_count(TMoverParameters const &Mover, bool Ontracks, spawn_rate const &Rate, double Timedelta); } // namespace smoke From a6c7d539832b6d3181b77ff59ad9355754f9c40c Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Sun, 8 Nov 2026 12:33:53 +0100 Subject: [PATCH 2/2] fix: SmokeDelay defaults to 0, the delay comes only from the vehicle's .fiz (eu07/maszyna#523) Without SmokeDelay in its Engine section a diesel smokes as soon as the starter turns, as before; the delay is set per locomotive in its own .fiz. The value stays a member of the vehicle's mover, read from its .fiz with an explicit default of 0. Tests: the real SM42 and ST44 with SmokeDelay=2 and 5 in the .fiz, and without it (smoke at once), next to a locomotive with a delay loaded just before, which keeps its own value. --- McZapkie/MOVER.h | 6 +++--- McZapkie/Mover.cpp | 2 +- tests/unit/test_smoke.cpp | 30 +++++++++++++++++++----------- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/McZapkie/MOVER.h b/McZapkie/MOVER.h index f39de8e2..ec8e5e9b 100644 --- a/McZapkie/MOVER.h +++ b/McZapkie/MOVER.h @@ -2171,9 +2171,9 @@ class TMoverParameters bool dizel_startup{false}; // engine startup procedure request indicator bool dizel_ignition{false}; // engine ignition request indicator bool dizel_spinup{false}; // engine spin up to idle speed flag - // the starter turns the engine a while before it fires: smoke comes out only after SmokeDelay (the Engine section of the .fiz, - // seconds from the start of the spin up) has passed. 0 lets it out as soon as the starter turns, as before eu07/maszyna#523 - double dizel_SmokeDelay{2.0}; + // the starter turns the engine a while before it fires: smoke comes out only after SmokeDelay (the Engine section of the vehicle's + // .fiz, seconds from the start of the spin up) has passed. 0, the default, lets it out as soon as the starter turns, as before eu07/maszyna#523 + double dizel_SmokeDelay{0.0}; double dizel_FiringCountdown{0.0}; // seconds left until the engine being started fires, 0 once it runs on its own double dizel_engagedeltaomega = 0.0; /*roznica predkosci katowych tarcz sprzegla*/ double dizel_n_old = 0.0; /*poredkosc na potrzeby obliczen sprzegiel*/ diff --git a/McZapkie/Mover.cpp b/McZapkie/Mover.cpp index 8632e404..cb9eba02 100644 --- a/McZapkie/Mover.cpp +++ b/McZapkie/Mover.cpp @@ -11370,7 +11370,7 @@ void TMoverParameters::LoadFIZ_Engine(std::string const &Input) extract_value(OilPump.pressure_minimum, "OilMinPressure", Input, ""); extract_value(OilPump.pressure_maximum, "OilMaxPressure", Input, ""); // the time the starter turns the engine before it fires and smokes (eu07/maszyna#523) - extract_value(dizel_SmokeDelay, "SmokeDelay", Input, ""); + extract_value(dizel_SmokeDelay, "SmokeDelay", Input, "0"); dizel_SmokeDelay = std::max(0.0, dizel_SmokeDelay); // engine cooling factore extract_value(dizel_heat.kw, "HeatKW", Input, ""); diff --git a/tests/unit/test_smoke.cpp b/tests/unit/test_smoke.cpp index a1ea788f..281b5dbf 100644 --- a/tests/unit/test_smoke.cpp +++ b/tests/unit/test_smoke.cpp @@ -116,8 +116,8 @@ TEST_CASE("smoke: a real diesel smokes only once its engine has fired, SmokeDela CAPTURE(path); test::track const track{}; { - // the default delay - test::vehicle locomotive{test::definition::fiz(path)}; + // SmokeDelay set in the .fiz of the locomotive + test::vehicle locomotive{test::definition{test::definition::fiz(path)}.set("Engine", "SmokeDelay", 2)}; REQUIRE(locomotive->dizel_SmokeDelay == doctest::Approx(2.0)); auto const driven{test::driving(locomotive)}; REQUIRE(start_engine(driven, track)); @@ -130,15 +130,6 @@ TEST_CASE("smoke: a real diesel smokes only once its engine has fired, SmokeDela CHECK(locomotive->dizel_FiringCountdown == 0.0); CHECK(smoke::vehicle_spawn_count(locomotive.mover(), true, source, update) >= 1.f); } - { - // SmokeDelay=0: smoke as soon as the starter turns, as before - test::vehicle locomotive{test::definition{test::definition::fiz(path)}.set("Engine", "SmokeDelay", 0)}; - REQUIRE(locomotive->dizel_SmokeDelay == 0.0); - auto const driven{test::driving(locomotive)}; - REQUIRE(start_engine(driven, track)); - CHECK(locomotive->dizel_FiringCountdown == 0.0); - CHECK(smoke::vehicle_spawn_count(locomotive.mover(), true, source, update) >= 1.f); - } { // a longer delay from the .fiz test::vehicle locomotive{test::definition{test::definition::fiz(path)}.set("Engine", "SmokeDelay", 5)}; @@ -151,3 +142,20 @@ TEST_CASE("smoke: a real diesel smokes only once its engine has fired, SmokeDela } } } + +TEST_CASE("smoke: without SmokeDelay in its .fiz a diesel smokes as soon as the starter turns, as before (#523)") { + for (auto const *path : {"sm42_v1/6d1", "st44_v2/m62-1151"}) { + CAPTURE(path); + test::track const track{}; + // a locomotive which has the delay, loaded first, doesn't hand it on to the next one: the value is the vehicle's own + test::vehicle delayed{test::definition{test::definition::fiz(path)}.set("Engine", "SmokeDelay", 3)}; + REQUIRE(delayed->dizel_SmokeDelay == doctest::Approx(3.0)); + test::vehicle locomotive{test::definition::fiz(path)}; + REQUIRE(locomotive->dizel_SmokeDelay == 0.0); + CHECK(delayed->dizel_SmokeDelay == doctest::Approx(3.0)); + auto const driven{test::driving(locomotive)}; + REQUIRE(start_engine(driven, track)); + CHECK(locomotive->dizel_FiringCountdown == 0.0); + CHECK(smoke::vehicle_spawn_count(locomotive.mover(), true, source, update) >= 1.f); + } +}