mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-01 18:47: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:
@@ -518,37 +518,37 @@ bool TMoverParameters::RunBlowersCommand(VehicleCommand const Command, double CV
|
||||
{
|
||||
if (Command == VehicleCommand::motorBlowersFrontSwitch)
|
||||
{
|
||||
if (MotorBlowers[end::front].start_type != start_t::manual && MotorBlowers[end::front].start_type != start_t::manualwithautofallback)
|
||||
if (MotorBlowers[VehicleEnd::front].start_type != start_t::manual && MotorBlowers[VehicleEnd::front].start_type != start_t::manualwithautofallback)
|
||||
{
|
||||
// automatic device ignores 'manual' state commands
|
||||
MotorBlowers[end::front].is_enabled = CValue1 == 1;
|
||||
MotorBlowers[VehicleEnd::front].is_enabled = CValue1 == 1;
|
||||
}
|
||||
OK = SendCtrlToNext(Command, CValue1, CValue2, Couplertype);
|
||||
}
|
||||
else if (Command == VehicleCommand::motorBlowersFrontSwitchOff)
|
||||
{
|
||||
if (MotorBlowers[end::front].start_type != start_t::manual && MotorBlowers[end::front].start_type != start_t::manualwithautofallback)
|
||||
if (MotorBlowers[VehicleEnd::front].start_type != start_t::manual && MotorBlowers[VehicleEnd::front].start_type != start_t::manualwithautofallback)
|
||||
{
|
||||
// automatic device ignores 'manual' state commands
|
||||
MotorBlowers[end::front].is_disabled = CValue1 == 1;
|
||||
MotorBlowers[VehicleEnd::front].is_disabled = CValue1 == 1;
|
||||
}
|
||||
OK = SendCtrlToNext(Command, CValue1, CValue2, Couplertype);
|
||||
}
|
||||
else if (Command == VehicleCommand::motorBlowersRearSwitch)
|
||||
{
|
||||
if (MotorBlowers[end::rear].start_type != start_t::manual && MotorBlowers[end::rear].start_type != start_t::manualwithautofallback)
|
||||
if (MotorBlowers[VehicleEnd::rear].start_type != start_t::manual && MotorBlowers[VehicleEnd::rear].start_type != start_t::manualwithautofallback)
|
||||
{
|
||||
// automatic device ignores 'manual' state commands
|
||||
MotorBlowers[end::rear].is_enabled = CValue1 == 1;
|
||||
MotorBlowers[VehicleEnd::rear].is_enabled = CValue1 == 1;
|
||||
}
|
||||
OK = SendCtrlToNext(Command, CValue1, CValue2, Couplertype);
|
||||
}
|
||||
else if (Command == VehicleCommand::motorBlowersRearSwitchOff)
|
||||
{
|
||||
if (MotorBlowers[end::rear].start_type != start_t::manual && MotorBlowers[end::rear].start_type != start_t::manualwithautofallback)
|
||||
if (MotorBlowers[VehicleEnd::rear].start_type != start_t::manual && MotorBlowers[VehicleEnd::rear].start_type != start_t::manualwithautofallback)
|
||||
{
|
||||
// automatic device ignores 'manual' state commands
|
||||
MotorBlowers[end::rear].is_disabled = CValue1 == 1;
|
||||
MotorBlowers[VehicleEnd::rear].is_disabled = CValue1 == 1;
|
||||
}
|
||||
OK = SendCtrlToNext(Command, CValue1, CValue2, Couplertype);
|
||||
}
|
||||
@@ -598,12 +598,12 @@ bool TMoverParameters::RunPowerCommand(VehicleCommand const Command, double CVal
|
||||
auto const inputcab{(static_cast<int>(CValue1) & 0x40) != 0 ? 1 : 0};
|
||||
auto const inputoperation{static_cast<int>(CValue1) & ~(0x80 | 0x40)};
|
||||
auto const noswap{TrainType == train_type::emu || TrainType == train_type::et41};
|
||||
auto swap{false == noswap && Couplers[CValue2 == -1 ? end::rear : end::front].CouplingFlag.HasAll(Coupling::control)};
|
||||
auto swap{false == noswap && Couplers[CValue2 == -1 ? VehicleEnd::rear : VehicleEnd::front].CouplingFlag.HasAll(Coupling::control)};
|
||||
if (auto const reversed{inputcab != (CabActive != -1 ? 1 : 0)}; reversed)
|
||||
{
|
||||
swap = !swap;
|
||||
} // TODO: check whether this part has RL equivalent
|
||||
OperatePantographValve(static_cast<end>(swap ? 1 - inputend : inputend), static_cast<operation_t>(inputoperation), range_t::local);
|
||||
OperatePantographValve(static_cast<VehicleEnd>(swap ? 1 - inputend : inputend), static_cast<operation_t>(inputoperation), range_t::local);
|
||||
OK = SendCtrlToNext(Command, CValue1, CValue2, Couplertype);
|
||||
}
|
||||
else if (Command == VehicleCommand::pantographsValve)
|
||||
@@ -680,11 +680,11 @@ void TMoverParameters::DoorPermitCommand(double const CValue1, double const CVal
|
||||
auto const leftside{CValue2 > 0 ? 1 : 2};
|
||||
if (auto const rightside{3 - leftside}; std::abs(static_cast<int>(CValue1)) & rightside)
|
||||
{
|
||||
PermitDoors_(side::right, CValue1 > 0);
|
||||
PermitDoors_(VehicleSide::right, CValue1 > 0);
|
||||
}
|
||||
if (std::abs(static_cast<int>(CValue1)) & leftside)
|
||||
{
|
||||
PermitDoors_(side::left, CValue1 > 0);
|
||||
PermitDoors_(VehicleSide::left, CValue1 > 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -700,13 +700,13 @@ void TMoverParameters::DoorRemoteCommand(bool const Open, double const CValue1,
|
||||
auto const leftside{CValue2 > 0 ? 1 : 2};
|
||||
if (auto const rightside{3 - leftside}; static_cast<int>(CValue1) & rightside)
|
||||
{
|
||||
Doors.instances[side::right].remote_open = Open;
|
||||
Doors.instances[side::right].remote_close = false == Open;
|
||||
Doors.instances[VehicleSide::right].remote_open = Open;
|
||||
Doors.instances[VehicleSide::right].remote_close = false == Open;
|
||||
}
|
||||
if (static_cast<int>(CValue1) & leftside)
|
||||
{
|
||||
Doors.instances[side::left].remote_open = Open;
|
||||
Doors.instances[side::left].remote_close = false == Open;
|
||||
Doors.instances[VehicleSide::left].remote_open = Open;
|
||||
Doors.instances[VehicleSide::left].remote_close = false == Open;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user