mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-01 22:07:55 +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:
@@ -37,9 +37,9 @@ cameraviews::vehicle_pose pose_of(TDynamicObject const *Vehicle) {
|
||||
|
||||
// the end of the Vehicle the Other vehicle is beyond, -1 when it's beyond neither
|
||||
int end_towards(TDynamicObject const *Vehicle, TDynamicObject const *Other) {
|
||||
for (auto const side : {end::front, end::rear}) {
|
||||
for (auto const side : VehicleEnds) {
|
||||
if (Vehicle->MoverParameters->Neighbours[side].vehicle == Other) {
|
||||
return side;
|
||||
return NumberOf(side);
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
@@ -54,10 +54,10 @@ int outer_end(TDynamicObject const *Vehicle, TDynamicObject const *Inner, int co
|
||||
return inner < 0 ? Alone : 1 - inner;
|
||||
}
|
||||
|
||||
cameraviews::coupler coupler_of(TDynamicObject const *Vehicle, int const End) {
|
||||
cameraviews::coupler coupler_of(TDynamicObject const *Vehicle, VehicleEnd const End) {
|
||||
cameraviews::coupler coupler;
|
||||
coupler.position = Vehicle->CouplerPosition(static_cast<end>(End));
|
||||
coupler.outward = Vehicle->VectorFront() * (End == end::front ? 1.0 : -1.0);
|
||||
coupler.position = Vehicle->CouplerPosition(End);
|
||||
coupler.outward = Vehicle->VectorFront() * (End == VehicleEnd::front ? 1.0 : -1.0);
|
||||
coupler.width = Vehicle->MoverParameters->Dim.W;
|
||||
return coupler;
|
||||
}
|
||||
@@ -71,8 +71,8 @@ int driven_way(TDynamicObject const *Driven) {
|
||||
|
||||
// the coupler of the Vehicle furthest along the Way (or furthest back, with a negative Way)
|
||||
glm::dvec3 end_along(TDynamicObject const *Vehicle, glm::dvec3 const &Way) {
|
||||
auto const front{Vehicle->CouplerPosition(end::front)};
|
||||
auto const rear{Vehicle->CouplerPosition(end::rear)};
|
||||
auto const front{Vehicle->CouplerPosition(VehicleEnd::front)};
|
||||
auto const rear{Vehicle->CouplerPosition(VehicleEnd::rear)};
|
||||
return glm::dot(front - rear, Way) >= 0.0 ? front : rear;
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ std::vector<TDynamicObject *> consist_views::train_of(TDynamicObject *Driven) {
|
||||
return train;
|
||||
}
|
||||
auto const *controller{Driven->Mechanik != nullptr ? Driven->Mechanik : Driven->ctOwner};
|
||||
auto *first{controller != nullptr ? controller->Vehicle(end::front) : nullptr};
|
||||
auto *first{controller != nullptr ? controller->Vehicle(VehicleEnd::front) : nullptr};
|
||||
if (first == nullptr) {
|
||||
first = Driven;
|
||||
}
|
||||
@@ -142,7 +142,7 @@ TDynamicObject *consist_views::pick(std::vector<TDynamicObject *> const &Train,
|
||||
return m_vehicle;
|
||||
}
|
||||
|
||||
double consist_views::gap_beyond(TDynamicObject const *Vehicle, int const End) {
|
||||
double consist_views::gap_beyond(TDynamicObject const *Vehicle, VehicleEnd const End) {
|
||||
auto const &neighbour{Vehicle->MoverParameters->Neighbours[End]};
|
||||
if (neighbour.vehicle == nullptr || false == Vehicle->MoverParameters->Couplers[End].CouplingFlag.Empty()) {
|
||||
return -1.0;
|
||||
@@ -163,23 +163,23 @@ consist_views::coupling_place consist_views::coupling_at(std::vector<TDynamicObj
|
||||
auto const aheadend{end_towards(ahead, behind)};
|
||||
auto const behindend{end_towards(behind, ahead)};
|
||||
place.vehicle = ahead;
|
||||
place.coupler = coupler_of(ahead, aheadend < 0 ? end::rear : aheadend);
|
||||
place.coupler = coupler_of(ahead, aheadend < 0 ? VehicleEnd::rear : EndOf(aheadend));
|
||||
place.other = true;
|
||||
place.otherposition = behind->CouplerPosition(static_cast<end>(behindend < 0 ? end::front : behindend));
|
||||
place.otherposition = behind->CouplerPosition(behindend < 0 ? VehicleEnd::front : EndOf(behindend));
|
||||
return place;
|
||||
}
|
||||
// an end of the train, perhaps with another vehicle coming closer to it
|
||||
auto const front{Index <= 0};
|
||||
auto *vehicle{front ? Train.front() : Train.back()};
|
||||
auto const *inner{count > 1 ? Train[front ? 1 : count - 2] : nullptr};
|
||||
auto const outer{outer_end(vehicle, inner, front ? end::front : end::rear)};
|
||||
auto const outer{outer_end(vehicle, inner, NumberOf(front ? VehicleEnd::front : VehicleEnd::rear))};
|
||||
place.vehicle = vehicle;
|
||||
place.coupler = coupler_of(vehicle, outer);
|
||||
place.coupler = coupler_of(vehicle, EndOf(outer));
|
||||
auto const &neighbour{vehicle->MoverParameters->Neighbours[outer]};
|
||||
place.gap = gap_beyond(vehicle, outer);
|
||||
if (place.gap >= 0.0 && (neighbour.vehicle_end == end::front || neighbour.vehicle_end == end::rear)) {
|
||||
place.gap = gap_beyond(vehicle, EndOf(outer));
|
||||
if (place.gap >= 0.0 && (neighbour.FacingEnd() == VehicleEnd::front || neighbour.FacingEnd() == VehicleEnd::rear)) {
|
||||
place.other = true;
|
||||
place.otherposition = neighbour.vehicle->CouplerPosition(static_cast<end>(neighbour.vehicle_end));
|
||||
place.otherposition = neighbour.vehicle->CouplerPosition(neighbour.FacingEnd());
|
||||
}
|
||||
return place;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user