18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-02 07:22:42 +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
+16 -16
View File
@@ -74,19 +74,19 @@ std::uint32_t devices_of(TMoverParameters const &Occupied, TMoverParameters cons
namespace device = blackbox::cab_devices;
auto const on{[](bool const State, std::uint32_t const Bit) { return State ? Bit : 0u; }};
return on(Occupied.Battery || Controlling.Battery, device::battery) | on(Controlling.Mains, device::main_breaker) |
on(Controlling.Pantographs[end::front].is_active, device::pantograph_front) | on(Controlling.Pantographs[end::rear].is_active, device::pantograph_rear) |
on(Controlling.Pantographs[VehicleEnd::front].is_active, device::pantograph_front) | on(Controlling.Pantographs[VehicleEnd::rear].is_active, device::pantograph_rear) |
on(Controlling.ConverterFlag, device::converter) | on(Controlling.CompressorFlag, device::compressor) | on(Controlling.StLinFlag, device::line_contactors) |
on(Controlling.FuseFlag, device::overload_relay) | on(Controlling.SandDose, device::sanding) | on(Occupied.WarningSignal != 0, device::horn) |
on(false == Occupied.Doors.instances[side::left].is_closed, device::doors_left) |
on(false == Occupied.Doors.instances[side::right].is_closed, device::doors_right) | on(Occupied.Radio, device::radio) |
on(false == Occupied.Doors.instances[VehicleSide::left].is_closed, device::doors_left) |
on(false == Occupied.Doors.instances[VehicleSide::right].is_closed, device::doors_right) | on(Occupied.Radio, device::radio) |
on(Controlling.Heating, device::heating) | on(Occupied.SpringBrake.IsActive, device::spring_brake) | on(Controlling.ShuntMode, device::shunt_mode) |
// the doors as the cab works them: the permits, the departure signal, the steps and the lock
on(Occupied.DepartureSignal, device::departure_signal) | on(Occupied.Doors.instances[side::left].open_permit, device::door_permit_left) |
on(Occupied.Doors.instances[side::right].open_permit, device::door_permit_right) | on(Occupied.Doors.step_enabled, device::door_step) |
on(Occupied.DepartureSignal, device::departure_signal) | on(Occupied.Doors.instances[VehicleSide::left].open_permit, device::door_permit_left) |
on(Occupied.Doors.instances[VehicleSide::right].open_permit, device::door_permit_right) | on(Occupied.Doors.step_enabled, device::door_step) |
on(Occupied.Doors.lock_enabled, device::door_lock) | on(Occupied.Doors.is_locked, device::doors_locked) |
on(Occupied.Hamulec != nullptr && Occupied.Hamulec->Releaser(), device::brake_releaser) | on(Controlling.FuelPump.is_active, device::fuel_pump) |
on(Controlling.OilPump.is_active, device::oil_pump) |
on(Controlling.MotorBlowers[end::front].is_active || Controlling.MotorBlowers[end::rear].is_active, device::motor_blowers) |
on(Controlling.MotorBlowers[VehicleEnd::front].is_active || Controlling.MotorBlowers[VehicleEnd::rear].is_active, device::motor_blowers) |
on(Controlling.diesel.heat.engine_is_hot, device::engine_hot) | on(Controlling.SpeedCtrl && Controlling.SpeedCtrlUnit.IsActive, device::speed_control);
}
@@ -112,7 +112,7 @@ std::uint16_t outward_lights(TDynamicObject const *Vehicle, bool const Head) {
if (Vehicle == nullptr || Vehicle->MoverParameters == nullptr)
return 0;
auto const along{Vehicle->iDirection > 0};
return static_cast<std::uint16_t>(Vehicle->MoverParameters->iLights[Head == along ? end::front : end::rear]);
return static_cast<std::uint16_t>(Vehicle->MoverParameters->iLights[Head == along ? VehicleEnd::front : VehicleEnd::rear]);
}
// the lamps the vehicle has at that end: the driver checks a pattern against those of it there are
@@ -120,7 +120,7 @@ std::uint16_t outward_lamps(TDynamicObject const *Vehicle, bool const Head) {
if (Vehicle == nullptr)
return 0;
auto const along{Vehicle->iDirection > 0};
return static_cast<std::uint16_t>(Vehicle->LightList(Head == along ? end::front : end::rear));
return static_cast<std::uint16_t>(Vehicle->LightList(Head == along ? VehicleEnd::front : VehicleEnd::rear));
}
// the scenario file without the starter's $, the folders and the extension, safe for a file name
@@ -438,8 +438,8 @@ void blackbox_recorder::write_cab() {
auto const order{owner->order_current()};
sample.movement = order.HasAny(DriverOrder::obeyTrain) ? blackbox::movements::train :
order.HasAny(DriverOrder::shunt | DriverOrder::looseShunt | DriverOrder::connect) ? blackbox::movements::shunting : blackbox::movements::other;
sample.light_hint_head = static_cast<std::int16_t>(owner->light_hint(end::front));
sample.light_hint_tail = static_cast<std::int16_t>(owner->light_hint(end::rear));
sample.light_hint_head = static_cast<std::int16_t>(owner->light_hint(VehicleEnd::front));
sample.light_hint_tail = static_cast<std::int16_t>(owner->light_hint(VehicleEnd::rear));
}
sample.odometer_km = static_cast<float>(occupied->DistCounter);
sample.driving = driver_of(*vehicle);
@@ -462,10 +462,10 @@ void blackbox_recorder::write_cab() {
sample.voltage = static_cast<float>(controlling->EngineVoltage);
sample.engine_rpm = static_cast<float>(std::abs(controlling->enrot) * 60.0);
// the lights at the ends of the train: of the vehicles at its ends, at their ends turned away from the rest
sample.lights_head = outward_lights(owner != nullptr ? owner->Vehicle(end::front) : vehicle, true);
sample.lights_tail = outward_lights(owner != nullptr ? owner->Vehicle(end::rear) : vehicle, false);
sample.equipped_head = outward_lamps(owner != nullptr ? owner->Vehicle(end::front) : vehicle, true);
sample.equipped_tail = outward_lamps(owner != nullptr ? owner->Vehicle(end::rear) : vehicle, false);
sample.lights_head = outward_lights(owner != nullptr ? owner->Vehicle(VehicleEnd::front) : vehicle, true);
sample.lights_tail = outward_lights(owner != nullptr ? owner->Vehicle(VehicleEnd::rear) : vehicle, false);
sample.equipped_head = outward_lamps(owner != nullptr ? owner->Vehicle(VehicleEnd::front) : vehicle, true);
sample.equipped_tail = outward_lamps(owner != nullptr ? owner->Vehicle(VehicleEnd::rear) : vehicle, false);
auto const &security{controlling->SecuritySystem};
namespace flag = blackbox::security_flags;
sample.security = static_cast<std::uint8_t>((security.is_vigilance_blinking() ? flag::vigilance : 0) | (security.is_cabsignal_blinking() ? flag::cabsignal : 0) |
@@ -493,7 +493,7 @@ void blackbox_recorder::write_cab() {
sample.converter_fill = static_cast<float>(controlling->torqueConverter.fill);
// the brakes of the whole train: the highest of its cylinders, from the head to the tail
auto brakes{occupied->BrakePress};
for (auto const *each{owner != nullptr ? owner->Vehicle(end::front) : nullptr}; each != nullptr; each = each->Next())
for (auto const *each{owner != nullptr ? owner->Vehicle(VehicleEnd::front) : nullptr}; each != nullptr; each = each->Next())
if (each->MoverParameters != nullptr)
brakes = std::max(brakes, each->MoverParameters->BrakePress);
sample.consist_brake_cylinder = static_cast<float>(brakes);
@@ -646,7 +646,7 @@ void blackbox_recorder::look_at_couplers() {
change.flags = static_cast<std::uint8_t>(now.flags);
change.previous_flags = static_cast<std::uint8_t>(entry.couplers_known ? before.flags : 0);
change.previous_other = entry.couplers_known ? known_id(before.other) : blackbox::no_vehicle;
change.position = vehicle->CouplerPosition(static_cast<end>(side));
change.position = vehicle->CouplerPosition(static_cast<VehicleEnd>(side));
m_writer->coupling(change);
}
entry.couplers_known = true;