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:
@@ -69,16 +69,16 @@ bool released(scenario &Scenario, double Pressure = 0.1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool open(TMoverParameters const &Vehicle, int Side) {
|
||||
bool open(TMoverParameters const &Vehicle, VehicleSide Side) {
|
||||
return Vehicle.Doors.instances[Side].is_open;
|
||||
}
|
||||
|
||||
// the leaf shut, whatever the step does (closed, is_closed, wants the step folded too)
|
||||
bool shut(TMoverParameters const &Vehicle, int Side) {
|
||||
bool shut(TMoverParameters const &Vehicle, VehicleSide Side) {
|
||||
return Vehicle.Doors.instances[Side].position <= 0.f;
|
||||
}
|
||||
|
||||
bool closed(TMoverParameters const &Vehicle, int Side) {
|
||||
bool closed(TMoverParameters const &Vehicle, VehicleSide Side) {
|
||||
return Vehicle.Doors.instances[Side].is_closed;
|
||||
}
|
||||
|
||||
@@ -100,30 +100,30 @@ TEST_CASE("controls: the doors of an electric unit, opened, locked, permitted an
|
||||
auto &cab{scenario.cab()};
|
||||
auto const &last{scenario.vehicle(scenario.train().size() - 1)};
|
||||
scenario.act("permit left");
|
||||
cab.PermitDoors(side::left, true);
|
||||
cab.PermitDoors(VehicleSide::left, true);
|
||||
scenario.wait(2.0);
|
||||
scenario.act("open left");
|
||||
cab.OperateDoors(side::left, true);
|
||||
cab.OperateDoors(VehicleSide::left, true);
|
||||
scenario.wait(10.0);
|
||||
CHECK(open(cab, side::left));
|
||||
CHECK(open(last, side::left));
|
||||
CHECK(closed(cab, side::right));
|
||||
CHECK(open(cab, VehicleSide::left));
|
||||
CHECK(open(last, VehicleSide::left));
|
||||
CHECK(closed(cab, VehicleSide::right));
|
||||
scenario.act("close left");
|
||||
cab.OperateDoors(side::left, false);
|
||||
cab.OperateDoors(VehicleSide::left, false);
|
||||
scenario.wait(10.0);
|
||||
CHECK(shut(cab, side::left));
|
||||
CHECK(shut(last, side::left));
|
||||
CHECK(shut(cab, VehicleSide::left));
|
||||
CHECK(shut(last, VehicleSide::left));
|
||||
scenario.act("open right without permit");
|
||||
cab.OperateDoors(side::right, true);
|
||||
cab.OperateDoors(VehicleSide::right, true);
|
||||
scenario.wait(5.0);
|
||||
// the EN57 needs no permit
|
||||
CHECK(shut(cab, side::right) == cab.Doors.permit_needed);
|
||||
CHECK(shut(cab, VehicleSide::right) == cab.Doors.permit_needed);
|
||||
scenario.act("permit right, open");
|
||||
cab.PermitDoors(side::right, true);
|
||||
cab.OperateDoors(side::right, true);
|
||||
cab.PermitDoors(VehicleSide::right, true);
|
||||
cab.OperateDoors(VehicleSide::right, true);
|
||||
scenario.wait(10.0);
|
||||
CHECK(open(cab, side::right));
|
||||
CHECK(open(last, side::right));
|
||||
CHECK(open(cab, VehicleSide::right));
|
||||
CHECK(open(last, VehicleSide::right));
|
||||
scenario.act("lock");
|
||||
cab.LockDoors(true);
|
||||
scenario.wait(5.0);
|
||||
@@ -136,29 +136,29 @@ TEST_CASE("controls: the doors of an electric unit, opened, locked, permitted an
|
||||
cab.PermitDoorStep(true);
|
||||
cab.ChangeDoorControlMode(false);
|
||||
scenario.act("close all, unlock");
|
||||
cab.OperateDoors(side::right, false);
|
||||
cab.OperateDoors(side::left, false);
|
||||
cab.OperateDoors(VehicleSide::right, false);
|
||||
cab.OperateDoors(VehicleSide::left, false);
|
||||
cab.LockDoors(false);
|
||||
scenario.wait(10.0);
|
||||
CHECK(shut(cab, side::left));
|
||||
CHECK(shut(cab, side::right));
|
||||
CHECK(shut(cab, VehicleSide::left));
|
||||
CHECK(shut(cab, VehicleSide::right));
|
||||
scenario.act("open both and drive off");
|
||||
cab.PermitDoors(side::left, true);
|
||||
cab.PermitDoors(side::right, true);
|
||||
cab.OperateDoors(side::left, true);
|
||||
cab.OperateDoors(side::right, true);
|
||||
cab.PermitDoors(VehicleSide::left, true);
|
||||
cab.PermitDoors(VehicleSide::right, true);
|
||||
cab.OperateDoors(VehicleSide::left, true);
|
||||
cab.OperateDoors(VehicleSide::right, true);
|
||||
scenario.wait(5.0);
|
||||
CHECK_FALSE(shut(cab, side::left));
|
||||
CHECK_FALSE(shut(cab, side::right));
|
||||
CHECK_FALSE(shut(cab, VehicleSide::left));
|
||||
CHECK_FALSE(shut(cab, VehicleSide::right));
|
||||
scenario.get_going();
|
||||
notch_up(scenario, 4, 2.0);
|
||||
scenario.wait(20.0);
|
||||
// the doors of a train ready to run close as the driver starts off. no CHECK of the speed: the Elf and
|
||||
// the Impuls keep their steps out under the permit, which keeps them from moving (COVERAGE.md)
|
||||
CHECK(shut(cab, side::left) == ready);
|
||||
CHECK(shut(cab, side::right) == ready);
|
||||
CHECK(shut(last, side::left) == ready);
|
||||
CHECK(shut(last, side::right) == ready);
|
||||
CHECK(shut(cab, VehicleSide::left) == ready);
|
||||
CHECK(shut(cab, VehicleSide::right) == ready);
|
||||
CHECK(shut(last, VehicleSide::left) == ready);
|
||||
CHECK(shut(last, VehicleSide::right) == ready);
|
||||
notch_down(scenario);
|
||||
brake_to_stop(scenario);
|
||||
scenario.check();
|
||||
@@ -177,28 +177,28 @@ TEST_CASE("controls: the doors of wagons, worked from the locomotive") {
|
||||
for (auto const range : {range_t::consist, range_t::unit, range_t::local}) {
|
||||
CAPTURE(static_cast<int>(range));
|
||||
scenario.act(std::format("open right {}", static_cast<int>(range)));
|
||||
cab.PermitDoors(side::right, true, range);
|
||||
cab.OperateDoors(side::right, true, range);
|
||||
cab.PermitDoors(VehicleSide::right, true, range);
|
||||
cab.OperateDoors(VehicleSide::right, true, range);
|
||||
scenario.wait(10.0);
|
||||
CHECK(open(coach, side::right) == (range != range_t::local));
|
||||
CHECK(shut(coach, side::left));
|
||||
CHECK(shut(freight, side::right));
|
||||
CHECK(open(coach, VehicleSide::right) == (range != range_t::local));
|
||||
CHECK(shut(coach, VehicleSide::left));
|
||||
CHECK(shut(freight, VehicleSide::right));
|
||||
scenario.act("close right");
|
||||
cab.OperateDoors(side::right, false, range);
|
||||
cab.OperateDoors(VehicleSide::right, false, range);
|
||||
scenario.wait(10.0);
|
||||
CHECK(shut(coach, side::right));
|
||||
CHECK(shut(coach, VehicleSide::right));
|
||||
}
|
||||
scenario.act("wagon opens its own");
|
||||
coach.OperateDoors(side::left, true, range_t::local);
|
||||
coach.OperateDoors(VehicleSide::left, true, range_t::local);
|
||||
// a second at a time, the same run as one wait. the coach's doors close by themselves 5 s after they
|
||||
// opened (DoorStayOpen)
|
||||
scenario.wait(1.0);
|
||||
CHECK_FALSE(shut(coach, side::left));
|
||||
CHECK_FALSE(shut(coach, VehicleSide::left));
|
||||
scenario.wait(9.0);
|
||||
CHECK(shut(coach, side::left));
|
||||
coach.OperateDoors(side::left, false, range_t::local);
|
||||
CHECK(shut(coach, VehicleSide::left));
|
||||
coach.OperateDoors(VehicleSide::left, false, range_t::local);
|
||||
scenario.wait(10.0);
|
||||
CHECK(shut(coach, side::left));
|
||||
CHECK(shut(coach, VehicleSide::left));
|
||||
scenario.check();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user