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

refactor(physics): the ends and the sides of a vehicle as scoped enums

end and side were unscoped enums: front, rear, left and right sat in the
global namespace (the test PCH had to leave mover.h out for it), and an end
went into any int, a side into an end, without a word from the compiler. They
become enum class VehicleEnd and VehicleSide (physics/vehicletypes.h); the
names follow the rule for types, and leave "end" and "side" to the many
locals of that name. The numbers stay: front 0, rear 1, right 0, left 1.

- ByEnd<T> / BySide<T>: two values indexed by the enum, and by a number
  where a loop or a format counts them. The arrays of the ends and the sides
  are these now: Couplers, Neighbours, Pantographs, MotorBlowers, Lights,
  iLights, Doors.instances, pVehicles, IsAnyDoor*, m_lighthints, vCoulpler,
  m_couplersounds, m_mirrormotion, iInventory, and the voltages of the
  couplers
- VehicleEnds / VehicleSides to go through them, Opposite() in place of
  1 - end, NumberOf() where a number is needed
- the couplers and the collisions take the ends they work on as VehicleEnd:
  CouplerForce, CouplerVelocityDifference, CollisionDetect, crush_hit,
  CompatibleCoupling and the rest of their family, DirF, DirPatch, and of
  the vehicle couple, uncouple, the adapters, off_track_gap, has_signal_on;
  Attach, Dettach and DettachStatus have overloads by the ends
- neighbour_data::FacingEnd() and TCoupling::ConnectedEnd() give the end of
  the other vehicle as VehicleEnd; the fields stay numbers, as they hold -1
  and 2 for "none" in places

The walks along the consist (FirstFind, Neighbour, the AI's coupling and
uncoupling) still carry the ends as numbers; where one of them meets a typed
end, NumberOf() and EndOf() say so, and keep the number as it was.

Kept as it was, and worth a look: TDynamicObject::SetLights() switches the
headlights A/B off by CabActive with the cases end::front and end::rear, that
is CabActive 0 and 1, while CabActive is 1 or -1 for the cabs; the cases are
NumberOf(VehicleEnd::front / rear) now, the same numbers.

No change in behaviour: 1144/1144 tests, golden traces exact against staging
62f7a29b. betterRenderer/, not built, has had only end:: and side:: renamed.
This commit is contained in:
2026-11-28 18:32:58 +01:00
parent 4679201cb9
commit fbb9dc1e89
96 changed files with 1395 additions and 1304 deletions
+15 -15
View File
@@ -50,7 +50,7 @@ void get_ready(test::vehicle &Loco, test::driven const &Driven) {
}
REQUIRE_FALSE(Loco->ControlPressureSwitch);
REQUIRE(Loco->Mains);
REQUIRE(Loco->Pantographs[end::rear].is_active);
REQUIRE(Loco->Pantographs[VehicleEnd::rear].is_active);
}
// the master controller taken to the given position a notch a second
@@ -109,7 +109,7 @@ TEST_CASE("pressure switch: with the brake cylinders at 3.8 bar the EP05 takes n
CHECK_FALSE(loco->StLinFlag);
CHECK(loco->Im == 0.0);
CHECK(loco->Mains);
CHECK(loco->Pantographs[end::rear].is_active);
CHECK(loco->Pantographs[VehicleEnd::rear].is_active);
}
TEST_CASE("pressure switch: without its brake cylinder half the EP05 takes current with the brake cylinders at 3.8 bar") {
@@ -149,7 +149,7 @@ TEST_CASE("pressure switch: without its brake cylinder half the brake pipe still
CHECK(loco->Im == 0.0);
// nothing else lets go without the other key
CHECK(loco->Mains);
CHECK(loco->Pantographs[end::rear].is_active);
CHECK(loco->Pantographs[VehicleEnd::rear].is_active);
}
TEST_CASE("pressure switch: an emergency application with the master controller on a power position opens the line breaker and drops the pantographs") {
@@ -167,8 +167,8 @@ TEST_CASE("pressure switch: an emergency application with the master controller
REQUIRE(loco->PipePress < emergency_pressure);
REQUIRE(loco->MainCtrlPos == 5);
CHECK_FALSE(loco->Mains);
CHECK_FALSE(loco->Pantographs[end::front].is_active);
CHECK_FALSE(loco->Pantographs[end::rear].is_active);
CHECK_FALSE(loco->Pantographs[VehicleEnd::front].is_active);
CHECK_FALSE(loco->Pantographs[VehicleEnd::rear].is_active);
CHECK(loco->PantographVoltage == 0.0);
CHECK_FALSE(loco->StLinFlag);
CHECK(loco->Im == 0.0);
@@ -177,7 +177,7 @@ TEST_CASE("pressure switch: an emergency application with the master controller
loco->MainSwitch(true);
test::drive(driven, line, 2.0);
CHECK_FALSE(loco->Mains);
CHECK_FALSE(loco->Pantographs[end::rear].is_active);
CHECK_FALSE(loco->Pantographs[VehicleEnd::rear].is_active);
}
TEST_CASE("pressure switch: an emergency application with the master controller at zero leaves the line breaker and the pantographs alone") {
@@ -192,7 +192,7 @@ TEST_CASE("pressure switch: an emergency application with the master controller
emergency_application(loco, driven);
CHECK(loco->Mains);
CHECK(loco->Pantographs[end::rear].is_active);
CHECK(loco->Pantographs[VehicleEnd::rear].is_active);
CHECK(loco->PantographVoltage == doctest::Approx(test::catenary_3kv));
CHECK(loco->Im == 0.0);
@@ -200,7 +200,7 @@ TEST_CASE("pressure switch: an emergency application with the master controller
loco->IncMainCtrl(1);
test::drive(driven, line, 2.0);
CHECK_FALSE(loco->Mains);
CHECK_FALSE(loco->Pantographs[end::rear].is_active);
CHECK_FALSE(loco->Pantographs[VehicleEnd::rear].is_active);
}
TEST_CASE("pressure switch: a service application with the master controller on a power position doesn't open the line breaker") {
@@ -219,7 +219,7 @@ TEST_CASE("pressure switch: a service application with the master controller on
REQUIRE(lowest < 3.0);
CHECK(lowest > emergency_pressure);
CHECK(loco->Mains);
CHECK(loco->Pantographs[end::rear].is_active);
CHECK(loco->Pantographs[VehicleEnd::rear].is_active);
// the pressure switch has cut the motors off
CHECK_FALSE(loco->StLinFlag);
CHECK(loco->Im == 0.0);
@@ -233,7 +233,7 @@ TEST_CASE("pressure switch: without the key an emergency application leaves the
emergency_application(loco, driven);
REQUIRE(loco->MainCtrlPos == 5);
CHECK(loco->Mains);
CHECK(loco->Pantographs[end::rear].is_active);
CHECK(loco->Pantographs[VehicleEnd::rear].is_active);
CHECK(loco->PantographVoltage == doctest::Approx(test::catenary_3kv));
// the pressure switch cuts the motors off
CHECK(loco->ControlPressureSwitch);
@@ -249,7 +249,7 @@ TEST_CASE("pressure switch: where the pantographs don't hang on the line breaker
emergency_application(loco, driven);
CHECK_FALSE(loco->Mains);
CHECK(loco->Pantographs[end::rear].is_active);
CHECK(loco->Pantographs[VehicleEnd::rear].is_active);
CHECK(loco->PantographVoltage == doctest::Approx(test::catenary_3kv));
CHECK_FALSE(loco->StLinFlag);
CHECK(loco->Im == 0.0);
@@ -264,20 +264,20 @@ TEST_CASE("pressure switch: after the emergency application the driver's start-u
get_under_power(loco, driven, 5);
emergency_application(loco, driven);
REQUIRE_FALSE(loco->Mains);
REQUIRE_FALSE(loco->Pantographs[end::rear].is_active);
REQUIRE(loco->Pantographs[end::rear].valve.is_enabled);
REQUIRE_FALSE(loco->Pantographs[VehicleEnd::rear].is_active);
REQUIRE(loco->Pantographs[VehicleEnd::rear].valve.is_enabled);
// with the brake pipe still empty
REQUIRE(test::start_up(driven, line, 60.0));
CHECK(loco->MainCtrlPos == 0);
CHECK(loco->Mains);
CHECK(loco->Pantographs[end::rear].is_active);
CHECK(loco->Pantographs[VehicleEnd::rear].is_active);
CHECK(loco->PantographVoltage == doctest::Approx(test::catenary_3kv));
REQUIRE(loco->PipePress < emergency_pressure);
// and it stays so
test::drive(driven, line, 30.0);
CHECK(loco->Mains);
CHECK(loco->Pantographs[end::rear].is_active);
CHECK(loco->Pantographs[VehicleEnd::rear].is_active);
// the brakes released (the AI fills an emptied pipe with the releaser held, TController::control_releaser()),
// the pressure switch lets the start be made