mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-02 16:36:53 +01:00
refactor(physics): the controllers and the switches of the cab are private to the vehicle
The positions of the master and the secondary controller, of the analog
controller and of the lights selector, the occupied cab, the horns, the radio
and its fuse, the radio-stop, the wipers' switch, the dimmer, the mirrors'
button, the end-of-train signalling and the forced resistor fans: fourteen
fields the cab, the AI, the scenery and the tests wrote straight into
physics::Vehicle are private now. The rest of the simulator reads them through
queries named as the fields were (MainCtrlPos(), Radio(), ...) and changes them
through operations (SetMainCtrlPos(), SetRadio(), ...), so every place that
moves a controller past its own stepping (IncMainCtrl()) is named and can be
found; the compiler keeps anything else out. Inside the vehicle they keep
their meaning under camelCase names. The queries return const references, as
the gauges of the cab bind to them.
The .fiz keys are untouched.
No change in behaviour: the golden traces recorded on dfb43c4f match bit for bit.
This commit is contained in:
@@ -56,7 +56,7 @@ struct elf {
|
||||
for (int i = 0; i < 3 && cab().DirActive <= 0; ++i) {
|
||||
cab().DirectionForward();
|
||||
}
|
||||
while (cab().MainCtrlPos < cab().MainCtrlNoPowerPos() && cab().IncMainCtrl(1)) {
|
||||
while (cab().MainCtrlPos() < cab().MainCtrlNoPowerPos() && cab().IncMainCtrl(1)) {
|
||||
// up to neutral
|
||||
}
|
||||
test::release_brakes(cab());
|
||||
@@ -76,9 +76,9 @@ struct elf {
|
||||
physics::Vehicle &car(std::size_t Index) { return unit[Index].physics(); }
|
||||
// the driver moves the controller notch by notch, which the cab sends on to the coupled vehicles
|
||||
void set_controller(int Position) {
|
||||
while (cab().MainCtrlPos < Position && cab().IncMainCtrl(1)) {
|
||||
while (cab().MainCtrlPos() < Position && cab().IncMainCtrl(1)) {
|
||||
}
|
||||
while (cab().MainCtrlPos > Position && cab().DecMainCtrl(1)) {
|
||||
while (cab().MainCtrlPos() > Position && cab().DecMainCtrl(1)) {
|
||||
}
|
||||
}
|
||||
void wait(double Seconds) { test::drive(test::driving(unit), line, Seconds); }
|
||||
@@ -99,9 +99,9 @@ TEST_CASE("elf controller: without EIMCtrlMainEmergency the positions stay as th
|
||||
CHECK(physics.EIMCtrlEmergencyPositions() == 0);
|
||||
CHECK(physics.MainCtrlPosNo == 4);
|
||||
CHECK(physics.MainCtrlNoPowerPos() == 3);
|
||||
CHECK(physics.MainCtrlPos == 3);
|
||||
CHECK(physics.MainCtrlPos() == 3);
|
||||
// the lowest position brakes fully, without emptying the pipe
|
||||
physics.MainCtrlPos = 0;
|
||||
physics.SetMainCtrlPos(0);
|
||||
CHECK_FALSE(physics.IsMainCtrlEmergencyPos());
|
||||
unit.wait(10.0);
|
||||
CHECK(physics.eimic == doctest::Approx(-1.0));
|
||||
@@ -117,27 +117,27 @@ TEST_CASE("elf controller: EIMCtrlMainEmergency shifts the positions up by the e
|
||||
CHECK(physics.EIMCtrlEmergencyPositions() == 1);
|
||||
CHECK(physics.MainCtrlPosNo == 5);
|
||||
CHECK(physics.MainCtrlNoPowerPos() == 4);
|
||||
CHECK(physics.MainCtrlPos == 4);
|
||||
CHECK(physics.MainCtrlPos() == 4);
|
||||
CHECK_FALSE(physics.IsMainCtrlEmergencyPos());
|
||||
SUBCASE("the neutral position neither drives nor brakes") {
|
||||
unit.wait(5.0);
|
||||
CHECK(physics.eimic == doctest::Approx(0.0));
|
||||
}
|
||||
SUBCASE("the full braking position, formerly 0, brakes fully without emptying the pipe") {
|
||||
physics.MainCtrlPos = 1;
|
||||
physics.SetMainCtrlPos(1);
|
||||
unit.wait(10.0);
|
||||
CHECK(physics.eimic == doctest::Approx(-1.0));
|
||||
CHECK(physics.brakePipe.Pressure() > 4.5);
|
||||
}
|
||||
SUBCASE("the braking position, formerly 1, ramps the braking up") {
|
||||
physics.MainCtrlPos = 2;
|
||||
physics.SetMainCtrlPos(2);
|
||||
unit.wait(1.0);
|
||||
CHECK(physics.eimic < 0.0);
|
||||
CHECK(physics.eimic > -1.0);
|
||||
CHECK(physics.brakePipe.Pressure() > 4.5);
|
||||
}
|
||||
SUBCASE("the emergency brake position brakes fully at once and empties the pipe") {
|
||||
physics.MainCtrlPos = 0;
|
||||
physics.SetMainCtrlPos(0);
|
||||
CHECK(physics.IsMainCtrlEmergencyPos());
|
||||
// a single step of the physics
|
||||
unit.unit.step(unit.line);
|
||||
@@ -146,7 +146,7 @@ TEST_CASE("elf controller: EIMCtrlMainEmergency shifts the positions up by the e
|
||||
CHECK(physics.brakePipe.Pressure() < 0.5);
|
||||
CHECK(physics.brakes.cylinderPressure > 1.0);
|
||||
// out of it the pipe charges again
|
||||
physics.MainCtrlPos = physics.MainCtrlNoPowerPos();
|
||||
physics.SetMainCtrlPos(physics.MainCtrlNoPowerPos());
|
||||
CHECK_FALSE(physics.IsMainCtrlEmergencyPos());
|
||||
unit.recharge();
|
||||
CHECK(physics.brakePipe.Pressure() > 4.5);
|
||||
@@ -172,7 +172,7 @@ TEST_CASE("elf controller: the reverser works at the neutral shifted by EIMCtrlM
|
||||
elf unit{{data::emergency_old_layout}};
|
||||
REQUIRE(unit.ready);
|
||||
auto &physics{unit.cab()};
|
||||
REQUIRE(physics.MainCtrlPos == physics.MainCtrlNoPowerPos());
|
||||
REQUIRE(physics.MainCtrlPos() == physics.MainCtrlNoPowerPos());
|
||||
REQUIRE(physics.DirActive == 1);
|
||||
CHECK(physics.DirectionBackward());
|
||||
CHECK(physics.DirActive == 0);
|
||||
@@ -180,7 +180,7 @@ TEST_CASE("elf controller: the reverser works at the neutral shifted by EIMCtrlM
|
||||
CHECK(physics.DirActive == 1);
|
||||
// not in the power position
|
||||
unit.set_controller(physics.MainCtrlNoPowerPos() + 1);
|
||||
REQUIRE(physics.MainCtrlPos == 5);
|
||||
REQUIRE(physics.MainCtrlPos() == 5);
|
||||
CHECK_FALSE(physics.DirectionBackward());
|
||||
CHECK(physics.DirActive == 1);
|
||||
}
|
||||
@@ -191,7 +191,7 @@ TEST_CASE("elf controller: the emergency brake position vents the pipe only from
|
||||
REQUIRE(unit.charged);
|
||||
// the rear car, with its own cab, has its controller in the emergency brake position, the driven one not
|
||||
auto &rear{unit.car(2)};
|
||||
rear.MainCtrlPos = 0;
|
||||
rear.SetMainCtrlPos(0);
|
||||
CHECK(rear.IsMainCtrlEmergencyPos());
|
||||
CHECK_FALSE(rear.IsCabMaster());
|
||||
unit.wait(10.0);
|
||||
@@ -207,22 +207,22 @@ TEST_CASE("elf controller: an Elf with the emergency brake position leading one
|
||||
auto &other{unit.car(3)};
|
||||
REQUIRE_FALSE(other.EIMCtrlMainEmergency);
|
||||
// neutral of the lead is neutral of the other
|
||||
CHECK(lead.MainCtrlPos == 4);
|
||||
CHECK(other.MainCtrlPos == other.MainCtrlNoPowerPos());
|
||||
CHECK(lead.MainCtrlPos() == 4);
|
||||
CHECK(other.MainCtrlPos() == other.MainCtrlNoPowerPos());
|
||||
SUBCASE("power") {
|
||||
unit.set_controller(5);
|
||||
CHECK(other.MainCtrlPos == 4);
|
||||
CHECK(other.MainCtrlPos() == 4);
|
||||
}
|
||||
SUBCASE("full braking") {
|
||||
unit.set_controller(1);
|
||||
CHECK(other.MainCtrlPos == 0);
|
||||
CHECK(other.MainCtrlPos() == 0);
|
||||
unit.wait(10.0);
|
||||
CHECK(lead.brakePipe.Pressure() > 4.5);
|
||||
}
|
||||
SUBCASE("the emergency brake: the other one at its full braking, the pipe vented by the lead") {
|
||||
unit.set_controller(0);
|
||||
REQUIRE(lead.IsMainCtrlEmergencyPos());
|
||||
CHECK(other.MainCtrlPos == 0);
|
||||
CHECK(other.MainCtrlPos() == 0);
|
||||
unit.wait(10.0);
|
||||
CHECK(lead.brakePipe.Pressure() < 0.5);
|
||||
CHECK(other.brakePipe.Pressure() < 0.5);
|
||||
@@ -236,15 +236,15 @@ TEST_CASE("elf controller: an Elf without the emergency brake position leading o
|
||||
auto &lead{unit.cab()};
|
||||
auto &other{unit.car(3)};
|
||||
REQUIRE(other.EIMCtrlMainEmergency);
|
||||
CHECK(lead.MainCtrlPos == 3);
|
||||
CHECK(other.MainCtrlPos == other.MainCtrlNoPowerPos());
|
||||
CHECK(lead.MainCtrlPos() == 3);
|
||||
CHECK(other.MainCtrlPos() == other.MainCtrlNoPowerPos());
|
||||
SUBCASE("power") {
|
||||
unit.set_controller(4);
|
||||
CHECK(other.MainCtrlPos == 5);
|
||||
CHECK(other.MainCtrlPos() == 5);
|
||||
}
|
||||
SUBCASE("the full braking of the lead is the full braking of the other, not its emergency brake") {
|
||||
unit.set_controller(0);
|
||||
CHECK(other.MainCtrlPos == 1);
|
||||
CHECK(other.MainCtrlPos() == 1);
|
||||
CHECK_FALSE(other.IsMainCtrlEmergencyPos());
|
||||
unit.wait(10.0);
|
||||
CHECK(lead.brakePipe.Pressure() > 4.5);
|
||||
@@ -257,7 +257,7 @@ TEST_CASE("elf controller: EIMCtrlMainEmergency leaves the other controllers alo
|
||||
vehicle impuls{definition::fiz("impuls_v1/31we-a_pr").set("Cntrl", "EIMCtrlMainEmergency", "Yes"), 60.0, "impuls", 1};
|
||||
CHECK(impuls->EIMCtrlEmergencyPositions() == 0);
|
||||
CHECK(impuls->MainCtrlPosNo == 10);
|
||||
impuls->MainCtrlPos = 0;
|
||||
impuls->SetMainCtrlPos(0);
|
||||
CHECK_FALSE(impuls->IsMainCtrlEmergencyPos());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user