18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-01 12:57:06 +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
+12 -12
View File
@@ -37,7 +37,7 @@ void TMoverParameters::UpdatePantVolume(double dt)
// check the pantograph compressor while at it
// TODO: move the check to a separate method
// automatic start if the pressure is too low
PantCompFlag |= PantPress < 4.2 && true == (Pantographs[end::front].is_active | Pantographs[end::rear].is_active) // TODO: any_pantograph_is_active method
PantCompFlag |= PantPress < 4.2 && true == (Pantographs[VehicleEnd::front].is_active | Pantographs[VehicleEnd::rear].is_active) // TODO: any_pantograph_is_active method
&& (PantographCompressorStart == start_t::automatic || PantographCompressorStart == start_t::manualwithautofallback);
auto const lowvoltagepower{Power24vIsAvailable || Power110vIsAvailable};
@@ -463,17 +463,17 @@ double TMoverParameters::LocalPowerVoltage(Coupling const kind)
// the voltage passed through the vehicle to the coupler at its other end, from the coupled vehicle or its own source
void TMoverParameters::PowerCouplersVoltage(Coupling const kind, double const abslocalvoltage, bool const localpowersource)
{
if (Couplers[end::front].power(kind) == nullptr)
if (Couplers[VehicleEnd::front].power(kind) == nullptr)
{
// not a power coupling, there's no voltage to pass
return;
}
for (auto side = 0; side < 2; ++side)
for (auto const side : VehicleEnds)
{
auto const &thiscoupler{Couplers[side]};
// NOTE: in the loop we actually update the state of the coupler on the opposite end of the vehicle
auto &oppositecoupler{Couplers[side == end::front ? end::rear : end::front]};
auto &oppositecoupler{Couplers[Opposite(side)]};
bool oppositecouplingispresent;
bool localpowerexportisenabled;
@@ -539,8 +539,8 @@ void TMoverParameters::PowerCouplersVoltage(Coupling const kind, double const ab
// the current drawn through the couplers, shared by their voltages, or added to the vehicle's own
void TMoverParameters::PowerCouplersCurrent(Coupling const kind, bool const localpowersource)
{
auto const *frontcoupling{Couplers[end::front].power(kind)};
auto const *rearcoupling{Couplers[end::rear].power(kind)};
auto const *frontcoupling{Couplers[VehicleEnd::front].power(kind)};
auto const *rearcoupling{Couplers[VehicleEnd::rear].power(kind)};
auto *totalcurrent{PowerCircuitCurrent(kind)};
if (frontcoupling == nullptr || rearcoupling == nullptr || totalcurrent == nullptr)
{
@@ -560,7 +560,7 @@ void TMoverParameters::PowerCouplersCurrent(Coupling const kind, bool const loca
continue;
}
auto const &connectedothercoupler{thiscoupler.Connected->Couplers[thiscoupler.ConnectedNr == end::front ? end::rear : end::front]};
auto const &connectedothercoupler{thiscoupler.Connected->Couplers[Opposite(thiscoupler.ConnectedEnd())]};
auto const *connectedothercoupling = connectedothercoupler.power(kind);
auto const extracurrent = kind == Coupling::highVoltage ? std::abs(Itot) * IsVehicleEIMBrakingFactor() : 0.0;
@@ -1191,7 +1191,7 @@ bool TMoverParameters::OperatePantographsValve(operation_t const State, range_t
return true;
}
bool TMoverParameters::OperatePantographValve(end const End, operation_t const State, range_t const Notify)
bool TMoverParameters::OperatePantographValve(VehicleEnd const End, operation_t const State, range_t const Notify)
{
if (EnginePowerSource.SourceType == TPowerSource::CurrentCollector && EnginePowerSource.CollectorParameters.CollectorsNo > 0)
@@ -1248,7 +1248,7 @@ bool TMoverParameters::OperatePantographValve(end const End, operation_t const S
SendCtrlToNext(VehicleCommand::pantographValve,
// HACK: pack the state, pantograph index and sender cab into 8-bit value
// with high bit storing front/rear pantograph, and 7th bit storing sender cab
static_cast<double>(0x80 * (End == end::front ? 0 : 1) + 0x40 * (CabActive != -1 ? 1 : 0) + static_cast<int>(State)), CabActive,
static_cast<double>(0x80 * (End == VehicleEnd::front ? 0 : 1) + 0x40 * (CabActive != -1 ? 1 : 0) + static_cast<int>(State)), CabActive,
Notify == range_t::unit ? Coupling::control | Coupling::permanent : Coupling::control);
}
@@ -1277,8 +1277,8 @@ bool TMoverParameters::DropAllPantographs(bool const State, range_t const Notify
double TMoverParameters::GetTrainsetVoltage(CouplingSet const couplings) const
{ // ABu: funkcja zwracajaca napiecie dla calego skladu, przydatna dla EZT
// TBD, TODO: call once per vehicle update, return cached results?
std::array<double, 2> voltages{0.0, 0.0};
for (int end = end::front; end <= end::rear; ++end)
ByEnd<double> voltages{0.0, 0.0};
for (auto const end : VehicleEnds)
{
if (Couplers[end].Connected == nullptr)
{
@@ -1298,7 +1298,7 @@ double TMoverParameters::GetTrainsetVoltage(CouplingSet const couplings) const
voltages[end] = connectedpowercoupling->voltage;
}
}
return std::max(voltages[end::front], voltages[end::rear]);
return std::max(voltages[VehicleEnd::front], voltages[VehicleEnd::rear]);
}
double TMoverParameters::GetTrainsetHighVoltage() const