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:
@@ -69,7 +69,7 @@ void tear_brake_hoses(TMoverParameters &Vehicle)
|
||||
// Q: 20160716
|
||||
// Wykrywanie kolizji
|
||||
// *************************************************************************************************
|
||||
void TMoverParameters::CollisionDetect(int const End, double const dt)
|
||||
void TMoverParameters::CollisionDetect(VehicleEnd const End, double const dt)
|
||||
{
|
||||
if (Neighbours[End].vehicle == nullptr)
|
||||
{
|
||||
@@ -78,7 +78,7 @@ void TMoverParameters::CollisionDetect(int const End, double const dt)
|
||||
|
||||
auto const &thiscoupler{Couplers[End]};
|
||||
auto *othervehicle{Neighbours[End].vehicle->MoverParameters};
|
||||
auto const otherend{Neighbours[End].vehicle_end};
|
||||
auto const otherend{Neighbours[End].FacingEnd()};
|
||||
auto const &othercoupler{othervehicle->Couplers[otherend]};
|
||||
|
||||
auto const physical{coupler_physics_at(End)};
|
||||
@@ -114,12 +114,12 @@ void TMoverParameters::CollisionDetect(int const End, double const dt)
|
||||
|
||||
switch (End)
|
||||
{
|
||||
case 0:
|
||||
case VehicleEnd::front:
|
||||
{
|
||||
CCF = ComputeCollision(velocity, othervehiclevelocity, TotalMass, othervehicle->TotalMass, loss, VirtualCoupling) / dt;
|
||||
break; // yB: ej ej ej, a po
|
||||
}
|
||||
case 1:
|
||||
case VehicleEnd::rear:
|
||||
{
|
||||
CCF = ComputeCollision(othervehiclevelocity, velocity, othervehicle->TotalMass, TotalMass, loss, VirtualCoupling) / dt;
|
||||
break;
|
||||
@@ -188,7 +188,7 @@ void TMoverParameters::CollisionDetect(int const End, double const dt)
|
||||
}
|
||||
}
|
||||
|
||||
void TMoverParameters::damage_coupler(int const End)
|
||||
void TMoverParameters::damage_coupler(VehicleEnd const End)
|
||||
{
|
||||
|
||||
auto &thiscoupler{Couplers[End]};
|
||||
@@ -241,12 +241,12 @@ collision::vehicle_kind TMoverParameters::collision_kind() const
|
||||
return collision::kind_of(powered, unit || passengers || (false == powered && HeatingPower > 0.0), false);
|
||||
}
|
||||
|
||||
collision::crush_curve TMoverParameters::crush_curve_at(int const End) const
|
||||
collision::crush_curve TMoverParameters::crush_curve_at(VehicleEnd const End) const
|
||||
{
|
||||
return collision::crush_of(Couplers[End].collision, collision_kind());
|
||||
}
|
||||
|
||||
double TMoverParameters::buffer_height_at(int const End) const
|
||||
double TMoverParameters::buffer_height_at(VehicleEnd const End) const
|
||||
{
|
||||
auto const loadshare{MaxLoad > 0.f ? LoadAmount / MaxLoad : 0.0};
|
||||
return collision::buffer_height(Couplers[End].collision, collision_kind(), loadshare);
|
||||
@@ -282,9 +282,9 @@ namespace
|
||||
{
|
||||
|
||||
|
||||
char const *end_name(int const End)
|
||||
char const *end_name(VehicleEnd const End)
|
||||
{
|
||||
return End == end::front ? "front" : "rear";
|
||||
return End == VehicleEnd::front ? "front" : "rear";
|
||||
}
|
||||
|
||||
char const *kind_name(collision::vehicle_kind const Kind)
|
||||
@@ -306,9 +306,9 @@ char const *kind_name(collision::vehicle_kind const Kind)
|
||||
} // namespace
|
||||
|
||||
// the force pressing the end in, of the coupling or of the buffers touching [N]: forwards at the front pulls
|
||||
double compression_at(TCoupling const &Coupler, int const End)
|
||||
double compression_at(TCoupling const &Coupler, VehicleEnd const End)
|
||||
{
|
||||
return std::max(0.0, (End == end::front ? -1.0 : 1.0) * Coupler.CForce);
|
||||
return std::max(0.0, (End == VehicleEnd::front ? -1.0 : 1.0) * Coupler.CForce);
|
||||
}
|
||||
namespace
|
||||
{
|
||||
@@ -330,11 +330,11 @@ void record_hit(TCoupling &Coupler, double const Force, double const Duration)
|
||||
|
||||
} // namespace
|
||||
|
||||
bool TMoverParameters::crush_hit(int const End, double const dt)
|
||||
bool TMoverParameters::crush_hit(VehicleEnd const End, double const dt)
|
||||
{
|
||||
auto &thiscoupler{Couplers[End]};
|
||||
auto *othervehicle{Neighbours[End].vehicle->MoverParameters};
|
||||
auto const otherend{Neighbours[End].vehicle_end};
|
||||
auto const otherend{Neighbours[End].FacingEnd()};
|
||||
auto &othercoupler{othervehicle->Couplers[otherend]};
|
||||
|
||||
auto const physical{coupler_physics_at(End)};
|
||||
@@ -465,7 +465,7 @@ bool TMoverParameters::crush_hit(int const End, double const dt)
|
||||
// the hit at the force the weaker end gives at pushes the vehicles apart: the velocities alone change, along this
|
||||
// vehicle's axis as in CollisionDetect()
|
||||
auto const otherdirection{DirPatch(End, otherend)};
|
||||
auto const apart{End == end::front ? -1.0 : 1.0};
|
||||
auto const apart{End == VehicleEnd::front ? -1.0 : 1.0};
|
||||
if (false == wall)
|
||||
{
|
||||
V += apart * hit.impulse / mass;
|
||||
@@ -491,10 +491,10 @@ bool TMoverParameters::crush_hit(int const End, double const dt)
|
||||
secondcurve.force(othercoupler.crush) / 1000.0, hit.force / 1000.0, springs / 1000.0, input.start_velocity * 3.6, kinetic / 1000.0,
|
||||
thiscoupler.contact.absorbed() / 1000.0, capacity / 1000.0, thiscoupler.contact.crush_work() / 1000.0);
|
||||
};
|
||||
auto const crushed = [&](TMoverParameters const &Vehicle, int const VehicleEnd, double const Before, double const After) {
|
||||
auto const crushed = [&](TMoverParameters const &Vehicle, VehicleEnd const crushedEnd, double const Before, double const After) {
|
||||
if (Before < collision::crush_mark && After >= collision::crush_mark)
|
||||
{
|
||||
ErrorLog(std::format("Bad driving: {} and {} collided at {:.0f} km/h, the {} end of {} crushed ({})", Name, othervehicle->Name, closing * 3.6, end_name(VehicleEnd), Vehicle.Name, pair()));
|
||||
ErrorLog(std::format("Bad driving: {} and {} collided at {:.0f} km/h, the {} end of {} crushed ({})", Name, othervehicle->Name, closing * 3.6, end_name(crushedEnd), Vehicle.Name, pair()));
|
||||
}
|
||||
};
|
||||
auto const before{thiscoupler.crush};
|
||||
@@ -566,8 +566,8 @@ void TMoverParameters::check_pushed_off(double const dt, double const Distance)
|
||||
auto duration{0.0};
|
||||
auto worst{0.0};
|
||||
auto worstforce{0.0};
|
||||
auto worstend{static_cast<int>(end::front)};
|
||||
for (int end = end::front; end <= end::rear; ++end)
|
||||
auto worstend{VehicleEnd::front};
|
||||
for (auto const end : VehicleEnds)
|
||||
{
|
||||
auto const *other{Neighbours[end].vehicle};
|
||||
if (other == nullptr)
|
||||
@@ -612,9 +612,9 @@ void TMoverParameters::check_pushed_off(double const dt, double const Distance)
|
||||
lifted ? std::format("its wheels lifted off the rail for {:.3f} s", pushed_off_monitor.time())
|
||||
: std::format("the flange climbing over {:.2f} m", pushed_off_monitor.distance()),
|
||||
Vel, std::abs(RunningShape.R), std::min(worst, 99.0),
|
||||
vehicle.mass / 1000.0, kind_name(collision_kind()), vehicle.axles, compression_at(Couplers[end::front], end::front) / 1000.0,
|
||||
compression_at(Couplers[end::rear], end::rear) / 1000.0, Couplers[end::front].hit_force / 1000.0, Couplers[end::rear].hit_force / 1000.0,
|
||||
Couplers[end::front].crush, Couplers[end::rear].crush));
|
||||
vehicle.mass / 1000.0, kind_name(collision_kind()), vehicle.axles, compression_at(Couplers[VehicleEnd::front], VehicleEnd::front) / 1000.0,
|
||||
compression_at(Couplers[VehicleEnd::rear], VehicleEnd::rear) / 1000.0, Couplers[VehicleEnd::front].hit_force / 1000.0, Couplers[VehicleEnd::rear].hit_force / 1000.0,
|
||||
Couplers[VehicleEnd::front].crush, Couplers[VehicleEnd::rear].crush));
|
||||
}
|
||||
}
|
||||
namespace
|
||||
@@ -641,7 +641,7 @@ void repair(TMoverParameters &Vehicle, TCoupling &Coupler)
|
||||
Coupler.stretch_duration = 0.f;
|
||||
Coupler.physics_state.couple();
|
||||
restore_end(Coupler);
|
||||
if (Vehicle.Couplers[end::front].broken || Vehicle.Couplers[end::rear].broken)
|
||||
if (Vehicle.Couplers[VehicleEnd::front].broken || Vehicle.Couplers[VehicleEnd::rear].broken)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -652,7 +652,7 @@ void repair(TMoverParameters &Vehicle, TCoupling &Coupler)
|
||||
|
||||
} // namespace
|
||||
|
||||
bool TMoverParameters::repair_coupler(int const End)
|
||||
bool TMoverParameters::repair_coupler(VehicleEnd const End)
|
||||
{
|
||||
auto &thiscoupler{Couplers[End]};
|
||||
if (false == thiscoupler.broken)
|
||||
@@ -665,7 +665,7 @@ bool TMoverParameters::repair_coupler(int const End)
|
||||
{
|
||||
repair(*other, other->Couplers[thiscoupler.ConnectedNr]);
|
||||
}
|
||||
WriteLog(std::format("Coupler of {} repaired, at its {} end", Name, End == end::front ? "front" : "rear"));
|
||||
WriteLog(std::format("Coupler of {} repaired, at its {} end", Name, End == VehicleEnd::front ? "front" : "rear"));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -694,7 +694,7 @@ void TMoverParameters::check_derailment(TTrackShape const &Shape, TTrackParam co
|
||||
vehicle.length = Dim.L;
|
||||
vehicle.axle_base = ADist > 0.0 ? ADist : BDist;
|
||||
vehicle.centre_of_gravity = centre_of_gravity();
|
||||
for (int end = end::front; end <= end::rear; ++end)
|
||||
for (auto const end : VehicleEnds)
|
||||
{
|
||||
auto const *other{Neighbours[end].vehicle};
|
||||
if (other == nullptr)
|
||||
@@ -702,8 +702,8 @@ void TMoverParameters::check_derailment(TTrackShape const &Shape, TTrackParam co
|
||||
continue;
|
||||
}
|
||||
// the force of the coupling, or of the buffers touching, along this vehicle: forwards at the front pulls
|
||||
vehicle.ends[end].compression = (end == end::front ? -1.0 : 1.0) * Couplers[end].CForce;
|
||||
vehicle.ends[end].other_length = other->MoverParameters->Dim.L;
|
||||
vehicle.ends[NumberOf(end)].compression = (end == VehicleEnd::front ? -1.0 : 1.0) * Couplers[end].CForce;
|
||||
vehicle.ends[NumberOf(end)].other_length = other->MoverParameters->Dim.L;
|
||||
}
|
||||
derailment::track_state track;
|
||||
track.radius = Shape.R;
|
||||
|
||||
Reference in New Issue
Block a user