mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-02 09:36:48 +01:00
fbb9dc1e89
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.
42 lines
1.8 KiB
C++
42 lines
1.8 KiB
C++
/*
|
|
This Source Code Form is subject to the
|
|
terms of the Mozilla Public License, v.
|
|
2.0. If a copy of the MPL was not
|
|
distributed with this file, You can
|
|
obtain one at
|
|
http://mozilla.org/MPL/2.0/.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <array>
|
|
|
|
#include "physics/mover.h"
|
|
|
|
// the lights the light preset selector (programmer) of the occupied cab gives one vehicle of the consist
|
|
namespace lights_programmer {
|
|
|
|
// the lights for the vehicle's two ends, in the terms of TDynamicObject::RaLightsSet(): head is the end
|
|
// towards the head of the consist (TDynamicObject::Prev()), rear the end towards its tail (Next())
|
|
struct consist_lights {
|
|
int head;
|
|
int rear;
|
|
};
|
|
|
|
// Cablights: the selector's lights for the occupied cab's front and back (Lights[VehicleEnd::front / VehicleEnd::rear]).
|
|
// Cabfacinghead: the occupied cab faces the head of the consist.
|
|
// Direction: the vehicle's iDirection, 1 when its VehicleEnd::front is towards the head of the consist.
|
|
// Coupled: whether another vehicle is coupled at the vehicle's VehicleEnd::front / VehicleEnd::rear; an end with a coupled
|
|
// vehicle stays dark
|
|
inline consist_lights vehicle_lights(ByEnd<int> const &Cablights, bool const Cabfacinghead, int const Direction, ByEnd<bool> const &Coupled) {
|
|
auto const headlights{Cablights[Cabfacinghead ? VehicleEnd::front : VehicleEnd::rear]};
|
|
auto const rearlights{Cablights[Cabfacinghead ? VehicleEnd::rear : VehicleEnd::front]};
|
|
// the head lights go to the vehicle's end towards the head of the consist whichever way the cab faces,
|
|
// so the coupling which keeps them dark is the one at that same end (eu07/maszyna#395)
|
|
auto const headend{Direction > 0 ? VehicleEnd::front : VehicleEnd::rear};
|
|
auto const rearend{Direction > 0 ? VehicleEnd::rear : VehicleEnd::front};
|
|
return {Coupled[headend] ? 0 : headlights, Coupled[rearend] ? 0 : rearlights};
|
|
}
|
|
|
|
} // namespace lights_programmer
|