diff --git a/tests/unit/test_gauge_scale.cpp b/tests/unit/test_gauge_scale.cpp index 57486cee2..04fa645bb 100644 --- a/tests/unit/test_gauge_scale.cpp +++ b/tests/unit/test_gauge_scale.cpp @@ -79,7 +79,7 @@ TEST_CASE("gauge scale: two points of the same value make a step") { CHECK(gauge_scale::interpolate(table.points, 1.5f) == doctest::Approx(0.55)); } -TEST_CASE("main ctrl act: the marker of a diesel locomotive follows its controller (MaSzyna-EU07/maszyna#74)") { +TEST_CASE("main ctrl act: the marker of a diesel locomotive with a scaletable: follows its controller (MaSzyna-EU07/maszyna#74)") { // nothing sets the actual position of a diesel engine's controller, the marker stayed at 0 for (auto const *path : {"st44_v2/m62-1151", "sm42_v1/6d1", "su45_v2/301d"}) { CAPTURE(path); @@ -89,22 +89,42 @@ TEST_CASE("main ctrl act: the marker of a diesel locomotive follows its controll REQUIRE(locomotive.EIMCtrlType == 0); locomotive.MainCtrlPos = 5; CHECK(locomotive.MainCtrlActualPos == 0); - CHECK(main_ctrl_act::position(locomotive) == doctest::Approx(5.0)); + CHECK(main_ctrl_act::position(locomotive, true) == doctest::Approx(5.0)); // one with a controller of the EIM kind keeps its actual position itself locomotive.EIMCtrlType = 2; - CHECK(main_ctrl_act::position(locomotive) == doctest::Approx(0.0)); + CHECK(main_ctrl_act::position(locomotive, true) == doctest::Approx(0.0)); + } +} + +TEST_CASE("main ctrl act: the marker of a diesel locomotive without a scaletable: stays still, as before") { + // the shipped ST43 cabs define mainctrlact: with a linear scale nobody has seen working; it is not opted in + for (auto const *path : {"st44_v2/m62-1151", "sm42_v1/6d1", "su45_v2/301d"}) { + CAPTURE(path); + consist train; + auto &locomotive{train.add(definition::fiz(path), 1).mover()}; + REQUIRE(locomotive.EIMCtrlType == 0); + locomotive.MainCtrlPos = 5; + locomotive.ScndCtrlPos = 1; + for (auto const coupled : {false, true}) { + CAPTURE(coupled); + locomotive.CoupledCtrl = coupled; + CHECK(main_ctrl_act::position(locomotive, false) == doctest::Approx(0.0)); + } } } TEST_CASE("main ctrl act: the marker of an electric locomotive shows its actual position, as before") { - consist train; - auto &locomotive{train.add(definition::fiz("et22_v3/201e-w"), 1).mover()}; - locomotive.MainCtrlPos = 10; - locomotive.MainCtrlActualPos = 3; - locomotive.ScndCtrlPos = 2; - locomotive.ScndCtrlActualPos = 1; - locomotive.CoupledCtrl = false; - CHECK(main_ctrl_act::position(locomotive) == doctest::Approx(3.0)); - locomotive.CoupledCtrl = true; - CHECK(main_ctrl_act::position(locomotive) == doctest::Approx(4.0)); + for (auto const scaletable : {false, true}) { + CAPTURE(scaletable); + consist train; + auto &locomotive{train.add(definition::fiz("et22_v3/201e-w"), 1).mover()}; + locomotive.MainCtrlPos = 10; + locomotive.MainCtrlActualPos = 3; + locomotive.ScndCtrlPos = 2; + locomotive.ScndCtrlActualPos = 1; + locomotive.CoupledCtrl = false; + CHECK(main_ctrl_act::position(locomotive, scaletable) == doctest::Approx(3.0)); + locomotive.CoupledCtrl = true; + CHECK(main_ctrl_act::position(locomotive, scaletable) == doctest::Approx(4.0)); + } } diff --git a/vehicle/Gauge.cpp b/vehicle/Gauge.cpp index 18750c93a..e952da6fa 100644 --- a/vehicle/Gauge.cpp +++ b/vehicle/Gauge.cpp @@ -112,6 +112,8 @@ void TGauge::Load( cParser &Parser, TDynamicObject const *Owner, double const mu Parser.getTokens(); if( Parser.peek() != "{" ) { // old fixed size config + // it has no scaletable:, drop the one of an earlier definition of the same control + m_scaletable.clear(); Parser >> submodelname; gaugetypename = Parser.getToken( true ); Parser.getTokens( 3, false ); diff --git a/vehicle/Gauge.h b/vehicle/Gauge.h index 59faff3f1..b79f8de8d 100644 --- a/vehicle/Gauge.h +++ b/vehicle/Gauge.h @@ -67,6 +67,9 @@ public: return ( static_cast( type() ) & static_cast( TGaugeType::toggle ) ) != 0; } bool is_delayed() const { return ( static_cast( type() ) & static_cast( TGaugeType::delayed ) ) != 0; } + // true if the gauge was given a non-uniform scale (scaletable:) + bool has_scaletable() const { + return false == m_scaletable.empty(); } // members TSubModel *SubModel { nullptr }; // McZapkie-310302: zeby mozna bylo sprawdzac czy zainicjowany poprawnie TSubModel *SubModelOn { nullptr }; // optional submodel visible when the state input is set diff --git a/vehicle/Train.cpp b/vehicle/Train.cpp index 050717419..2b0e04fe6 100644 --- a/vehicle/Train.cpp +++ b/vehicle/Train.cpp @@ -9337,7 +9337,7 @@ bool TTrain::Update(double const Deltatime) } if (ggMainCtrlAct.SubModel != nullptr) { - ggMainCtrlAct.UpdateValue(main_ctrl_act::position(*mvControlled)); + ggMainCtrlAct.UpdateValue(main_ctrl_act::position(*mvControlled, ggMainCtrlAct.has_scaletable())); ggMainCtrlAct.Update(); } if (ggScndCtrl.SubModel != nullptr) diff --git a/vehicle/mainctrlact.h b/vehicle/mainctrlact.h index 0f187b1b4..df61aa061 100644 --- a/vehicle/mainctrlact.h +++ b/vehicle/mainctrlact.h @@ -21,8 +21,11 @@ inline bool follows_controller(TMoverParameters const &Vehicle) { return (Vehicle.EngineType == TEngineType::DieselEngine || Vehicle.EngineType == TEngineType::DieselElectric) && Vehicle.EIMCtrlType == 0; } -inline float position(TMoverParameters const &Vehicle) { - auto const controller{follows_controller(Vehicle)}; +// Scaletable: the cab's gauge has a scaletable:. only such a marker follows the controller; the cabs that define +// mainctrlact: without one (the ST43 so far) keep their marker still, as before, instead of moving it on a scale +// nobody has checked +inline float position(TMoverParameters const &Vehicle, bool const Scaletable) { + auto const controller{Scaletable && follows_controller(Vehicle)}; auto const main{controller ? Vehicle.MainCtrlPos : Vehicle.MainCtrlActualPos}; auto const scnd{controller ? Vehicle.ScndCtrlPos : Vehicle.ScndCtrlActualPos}; return static_cast(Vehicle.CoupledCtrl ? main + scnd : main);