18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-02 00:22:42 +01:00

refactor(physics): what the rest of the simulator only reads of a vehicle is private to it

53 fields of physics::Vehicle that only the vehicle itself writes, and the rest
of the simulator reads, are private, with a query each, named as the field was
(Vmax(), TotalMass(), Ft(), nrot(), NAxles(), PhysicActivation(), ...): the
compiler now keeps the cab, the AI, the scenery, the renderer and the tests from
changing what the definition gives or the physics works out. The fields were
picked by what is never written outside the class, of plain types, with no
other member of the same name to confuse; inside the class they keep their
meaning under camelCase names. The one place outside that cleared a flag of
the AI through a reference does it through ClearAIFlag().

No change in behaviour: the golden traces recorded on dfb43c4f match bit for bit.
This commit is contained in:
2026-11-29 13:17:56 +01:00
parent 74f0aa240d
commit 5879c228dc
88 changed files with 1053 additions and 992 deletions
+14 -14
View File
@@ -95,7 +95,7 @@ TEST_CASE("elf controller: without EIMCtrlMainEmergency the positions stay as th
REQUIRE(unit.ready);
REQUIRE(unit.charged);
auto &physics{unit.cab()};
CHECK_FALSE(physics.EIMCtrlMainEmergency);
CHECK_FALSE(physics.EIMCtrlMainEmergency());
CHECK(physics.EIMCtrlEmergencyPositions() == 0);
CHECK(physics.MainCtrlPosNo == 4);
CHECK(physics.MainCtrlNoPowerPos() == 3);
@@ -113,7 +113,7 @@ TEST_CASE("elf controller: EIMCtrlMainEmergency shifts the positions up by the e
REQUIRE(unit.ready);
REQUIRE(unit.charged);
auto &physics{unit.cab()};
CHECK(physics.EIMCtrlMainEmergency);
CHECK(physics.EIMCtrlMainEmergency());
CHECK(physics.EIMCtrlEmergencyPositions() == 1);
CHECK(physics.MainCtrlPosNo == 5);
CHECK(physics.MainCtrlNoPowerPos() == 4);
@@ -158,13 +158,13 @@ TEST_CASE("elf controller: EIMCtrlMainEmergency with the old MCPN gets its posit
CHECK(car->MainCtrlPosNo == 5);
CHECK(car->MainCtrlNoPowerPos() == 4);
// DirChangeMaxPos=3 of the file, the old neutral, moves up with the positions
CHECK(car->MainCtrlMaxDirChangePos == 4);
CHECK(car->MainCtrlMaxDirChangePos() == 4);
}
TEST_CASE("elf controller: EIMCtrlMainEmergency leaves DirChangeMaxPos of the files updated for it alone") {
vehicle car{definition::fiz("elf_v1/21we-a").set("Cntrl", "EIMCtrlMainEmergency", "Yes").set("Cntrl", "MCPN", 5).set("Cntrl", "DirChangeMaxPos", 4)};
CHECK(car->MainCtrlPosNo == 5);
CHECK(car->MainCtrlMaxDirChangePos == 4);
CHECK(car->MainCtrlMaxDirChangePos() == 4);
}
TEST_CASE("elf controller: the reverser works at the neutral shifted by EIMCtrlMainEmergency") {
@@ -205,7 +205,7 @@ TEST_CASE("elf controller: an Elf with the emergency brake position leading one
REQUIRE(unit.charged);
auto &lead{unit.cab()};
auto &other{unit.car(3)};
REQUIRE_FALSE(other.EIMCtrlMainEmergency);
REQUIRE_FALSE(other.EIMCtrlMainEmergency());
// neutral of the lead is neutral of the other
CHECK(lead.MainCtrlPos() == 4);
CHECK(other.MainCtrlPos() == other.MainCtrlNoPowerPos());
@@ -235,7 +235,7 @@ TEST_CASE("elf controller: an Elf without the emergency brake position leading o
REQUIRE(unit.charged);
auto &lead{unit.cab()};
auto &other{unit.car(3)};
REQUIRE(other.EIMCtrlMainEmergency);
REQUIRE(other.EIMCtrlMainEmergency());
CHECK(lead.MainCtrlPos() == 3);
CHECK(other.MainCtrlPos() == other.MainCtrlNoPowerPos());
SUBCASE("power") {
@@ -295,15 +295,15 @@ void hold(elf &Unit, bool Hold) {
auto mass{0.0};
auto axles{0};
for (std::size_t i = 0; i < Unit.unit.size(); ++i) {
mass += Unit.car(i).TotalMass;
axles += Unit.car(i).NAxles;
mass += Unit.car(i).TotalMass();
axles += Unit.car(i).NAxles();
}
auto const force{Unit.cab().brakes.holding.deceleration * mass};
for (std::size_t i = 0; i < Unit.unit.size(); ++i) {
auto &car{Unit.car(i)};
auto const nmax{((car.brakes.config.pressureToForce * car.brakes.config.maxCylinderPressure[0] - car.brakes.config.cylinders.springForce) * car.brakes.config.cylinders.leverRatio[0] - car.brakes.config.cylinders.slackAdjusterForce) * car.brakes.config.cylinders.count * car.brakes.config.cylinders.riggingEfficiency};
auto const fmax{nmax * car.brakes.distributor->GetFC(nmax / (car.NAxles * car.brakes.config.blocksPerAxle), car.brakes.blending.referenceSpeed) * 1000};
auto position{Hold ? force * car.NAxles / axles / fmax : 0.0};
auto const fmax{nmax * car.brakes.distributor->GetFC(nmax / (car.NAxles() * car.brakes.config.blocksPerAxle), car.brakes.blending.referenceSpeed) * 1000};
auto position{Hold ? force * car.NAxles() / axles / fmax : 0.0};
if (position > 0.009) {
auto const slack{(car.brakes.config.cylinders.slackAdjusterForce / car.brakes.config.cylinders.leverRatio[0] + car.brakes.config.cylinders.springForce) / (car.brakes.config.pressureToForce * car.brakes.config.maxCylinderPressure[0])};
position = slack + (1 - slack) * position;
@@ -521,16 +521,16 @@ TEST_CASE("elf holding brake: the force of the motors at 1% against the holding
auto mass{0.0};
auto powered{0};
for (std::size_t i = 0; i < unit.unit.size(); ++i) {
mass += unit.car(i).TotalMass;
powered += unit.car(i).NPoweredAxles > 0 ? 1 : 0;
mass += unit.car(i).TotalMass();
powered += unit.car(i).NPoweredAxles() > 0 ? 1 : 0;
}
unit.set_controller(4);
unit.unit.step(unit.line);
unit.set_controller(3);
unit.wait(5.0);
auto const holding{cab.brakes.holding.deceleration * mass};
MESSAGE("mass " << mass << " kg, holding " << holding << " N, cars with motors " << powered << ", demand " << cab.eimic_real << ", cab car Ft " << cab.Ft
MESSAGE("mass " << mass << " kg, holding " << holding << " N, cars with motors " << powered << ", demand " << cab.eimic_real << ", cab car Ft " << cab.Ft()
<< " N, Fful " << cab.inductionMotor.state.fullForce << " kN, speed " << cab.Vel << " km/h after 5 s");
CHECK(cab.eimic_real == doctest::Approx(0.01).epsilon(0.02));
CHECK(cab.Ft * powered < 0.1 * holding);
CHECK(cab.Ft() * powered < 0.1 * holding);
}