18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-01 19:57:06 +01:00

refactor(physics): TMoverParameters becomes physics::Vehicle, the mover is gone

The physics of a vehicle loses the name it had from the Pascal of 2001. Done by
tools/rename/mover_to_physics.py, committed with it:

  physics/mover.h                  physics/vehicle.h
  TMoverParameters                 physics::Vehicle (in namespace physics)
  TDynamicObject::MoverParameters  physics
  mvOccupied, mvControlled         occupied, controlled (TTrain, TController)
  mvSecond, mvThird                secondUnit, thirdUnit
  mvPantographUnit                 pantographUnit
  mover, Mover, movers             physics, Physics, vehicles (locals, params)
  m_mover, othermover, currentMover, from_movers, renderMoverEventSounds
                                   m_physics, otherPhysics, currentPhysics,
                                   from_vehicles, renderPhysicsEventSounds

The code and the comments are renamed, the string literals are not: no text
the game shows, logs or looks up has changed (none had the names). The movers
of the editor, the tracks a slide moves, keep their name.

By hand: two member functions of TDynamicObject (gather_off_track_terrain,
begin_off_track) had a local mover aliasing their own MoverParameters, which
the rename made physics { *physics }; the alias is gone, they use physics->.
No other function has a renamed local meeting a renamed member (checked over
all the functions of the code before the rename).

For the branches made before it: run the script on the branch (python
tools/rename/mover_to_physics.py, from the root of the repository) before
merging it with this one, and the names don't conflict. It can be run again;
the second time it changes nothing.

The class is the same as it was; breaking it into its parts (braking,
electrics, controls, load) and making its data private are the next stages.

No change in behaviour: 1149/1149 tests, golden traces exact against staging
62f7a29b.
This commit is contained in:
2026-11-28 23:56:46 +01:00
parent 9568dba9e4
commit d0387753f8
207 changed files with 5147 additions and 4950 deletions
+28 -28
View File
@@ -10,7 +10,7 @@ http://mozilla.org/MPL/2.0/.
// collisions of the ends, their crush and repair, derailment and putting back on the rails
#include "stdafx.h"
#include "physics/mover.h"
#include "physics/vehicle.h"
#include "vehicle/DynObj.h"
#include "physics/oerlikonest.h"
#include "utilities/Globals.h"
@@ -55,7 +55,7 @@ namespace
{
// a derailed vehicle tears its brake hoses: the brake pipe vents and the rest of the train brakes in emergency
void tear_brake_hoses(TMoverParameters &Vehicle)
void tear_brake_hoses(physics::Vehicle &Vehicle)
{
if (std::any_of(std::begin(Vehicle.Couplers), std::end(Vehicle.Couplers), [](auto const &Coupler) { return Coupler.CouplingFlag.HasAll(Coupling::brakeHose); }))
{
@@ -69,7 +69,7 @@ void tear_brake_hoses(TMoverParameters &Vehicle)
// Q: 20160716
// Wykrywanie kolizji
// *************************************************************************************************
void TMoverParameters::CollisionDetect(VehicleEnd const End, double const dt)
void physics::Vehicle::CollisionDetect(VehicleEnd const End, double const dt)
{
if (Neighbours[End].vehicle == nullptr)
{
@@ -77,7 +77,7 @@ void TMoverParameters::CollisionDetect(VehicleEnd const End, double const dt)
} // shouldn't normally happen but, eh
auto const &thiscoupler{Couplers[End]};
auto *othervehicle{Neighbours[End].vehicle->MoverParameters};
auto *othervehicle{Neighbours[End].vehicle->physics};
auto const otherend{Neighbours[End].FacingEnd()};
auto const &othercoupler{othervehicle->Couplers[otherend]};
@@ -170,7 +170,7 @@ void TMoverParameters::CollisionDetect(VehicleEnd const End, double const dt)
// derailed the legacy way a vehicle is a wall, off the rails by the new criteria it slides on and takes the hit. with
// the crush, the vehicles coupled to the wall push it on (crush_hit())
auto const coupled{thiscoupler.CouplingFlag != Coupling::none};
auto const wall = [crushing, coupled](TMoverParameters const &Vehicle) {
auto const wall = [crushing, coupled](physics::Vehicle const &Vehicle) {
return Vehicle.DamageFlag.HasAll(VehicleDamage::derailed) && (false == crushing || (Vehicle.Derailed == derailment::outcome::none && false == coupled));
};
if (false == wall(*this))
@@ -188,7 +188,7 @@ void TMoverParameters::CollisionDetect(VehicleEnd const End, double const dt)
}
}
void TMoverParameters::damage_coupler(VehicleEnd const End)
void physics::Vehicle::damage_coupler(VehicleEnd const End)
{
auto &thiscoupler{Couplers[End]};
@@ -232,7 +232,7 @@ void TMoverParameters::damage_coupler(VehicleEnd const End)
// *************************************************************************************************
// physics.collisions new: the collisions past the buffers, see collision.h
// *************************************************************************************************
collision::vehicle_kind TMoverParameters::collision_kind() const
collision::vehicle_kind physics::Vehicle::collision_kind() const
{
auto const powered{EngineType != TEngineType::None && EngineType != TEngineType::Dumb};
auto const unit{is_multiple_unit()};
@@ -241,18 +241,18 @@ 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(VehicleEnd const End) const
collision::crush_curve physics::Vehicle::crush_curve_at(VehicleEnd const End) const
{
return collision::crush_of(Couplers[End].collision, collision_kind());
}
double TMoverParameters::buffer_height_at(VehicleEnd const End) const
double physics::Vehicle::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);
}
void TMoverParameters::derail_in_collision(DerailReason const Reason, std::string const &Why)
void physics::Vehicle::derail_in_collision(DerailReason const Reason, std::string const &Why)
{
if (false == DamageFlag.Set(VehicleDamage::derailed))
{
@@ -330,10 +330,10 @@ void record_hit(TCoupling &Coupler, double const Force, double const Duration)
} // namespace
bool TMoverParameters::crush_hit(VehicleEnd const End, double const dt)
bool physics::Vehicle::crush_hit(VehicleEnd const End, double const dt)
{
auto &thiscoupler{Couplers[End]};
auto *othervehicle{Neighbours[End].vehicle->MoverParameters};
auto *othervehicle{Neighbours[End].vehicle->physics};
auto const otherend{Neighbours[End].FacingEnd()};
auto &othercoupler{othervehicle->Couplers[otherend]};
@@ -491,7 +491,7 @@ bool TMoverParameters::crush_hit(VehicleEnd 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, VehicleEnd const crushedEnd, double const Before, double const After) {
auto const crushed = [&](physics::Vehicle 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(crushedEnd), Vehicle.Name, pair()));
@@ -530,7 +530,7 @@ bool TMoverParameters::crush_hit(VehicleEnd const End, double const dt)
// the end crushed deep enough lets one vehicle climb onto the other one
auto const climbing{climbing_of(thiscoupler.crush, othercoupler.crush)};
auto const climbed{collision::override_of(climbing)};
auto const why = [&](TMoverParameters const &Climber, TMoverParameters const &Other) {
auto const why = [&](physics::Vehicle const &Climber, physics::Vehicle const &Other) {
return std::format("{} rode up onto {} at {:.0f} km/h, the ends crushed by {:.2f} m, buffers at {:.0f} / {:.0f} mm, anticlimbers {} ({})", Climber.Name, Other.Name, closing * 3.6,
thiscoupler.crush + othercoupler.crush, climbing.height1 * 1000.0, climbing.height2 * 1000.0, climbing.anticlimbers ? "yes" : "no", pair());
};
@@ -545,7 +545,7 @@ bool TMoverParameters::crush_hit(VehicleEnd const End, double const dt)
return true;
}
void TMoverParameters::check_pushed_off(double const dt, double const Distance)
void physics::Vehicle::check_pushed_off(double const dt, double const Distance)
{
if (Global.collisions != global_settings::collision_model::physical || false == Global.crash_damage || DamageFlag.HasAll(VehicleDamage::derailed) || false == TestFlag(CategoryFlag, 1) ||
DebugModeFlag)
@@ -576,7 +576,7 @@ void TMoverParameters::check_pushed_off(double const dt, double const Distance)
}
auto const &coupler{Couplers[end]};
collision::pushed_end pushed;
pushed.other_length = other->MoverParameters->Dim.L;
pushed.other_length = other->physics->Dim.L;
pushed.crush = coupler.crush;
// the steady push of the springs over the step, or the peak of a hit for as long as it lasted: the flange climbs
// over the distance the wheels rolled meanwhile, a wheel lifted off the rail goes in a short time, rolling or not
@@ -635,7 +635,7 @@ void restore_end(TCoupling &Coupler)
// the coupler as good as new, its end with it (the crush that tore the draw gear off), the vehicle without the coupler
// damage (and the emergency braking of the torn brake hose) once neither of its couplers is broken
void repair(TMoverParameters &Vehicle, TCoupling &Coupler)
void repair(physics::Vehicle &Vehicle, TCoupling &Coupler)
{
Coupler.broken = false;
Coupler.stretch_duration = 0.f;
@@ -652,7 +652,7 @@ void repair(TMoverParameters &Vehicle, TCoupling &Coupler)
} // namespace
bool TMoverParameters::repair_coupler(VehicleEnd const End)
bool physics::Vehicle::repair_coupler(VehicleEnd const End)
{
auto &thiscoupler{Couplers[End]};
if (false == thiscoupler.broken)
@@ -672,7 +672,7 @@ bool TMoverParameters::repair_coupler(VehicleEnd const End)
static_assert(derailment::track_damage::railwear == dtrack_railwear && derailment::track_damage::freerail == dtrack_freerail && derailment::track_damage::thinrail == dtrack_thinrail &&
derailment::track_damage::railbend == dtrack_railbend);
double TMoverParameters::centre_of_gravity() const
double physics::Vehicle::centre_of_gravity() const
{
auto const kind{EngineType == TEngineType::None ? derailment::vehicle_class::unpowered : derailment::vehicle_class::powered};
auto const empty{CentreOfGravity > 0.0 ? CentreOfGravity : derailment::default_centre_of_gravity(Dim.H, kind)};
@@ -681,7 +681,7 @@ double TMoverParameters::centre_of_gravity() const
return derailment::loaded_centre_of_gravity(empty, Mass, loadmass, loadshare, Floor, Dim.H);
}
void TMoverParameters::check_derailment(TTrackShape const &Shape, TTrackParam const &Track, double const Distance)
void physics::Vehicle::check_derailment(TTrackShape const &Shape, TTrackParam const &Track, double const Distance)
{
if (DamageFlag.HasAll(VehicleDamage::derailed) || false == TestFlag(CategoryFlag, 1) || DebugModeFlag)
{
@@ -703,7 +703,7 @@ void TMoverParameters::check_derailment(TTrackShape const &Shape, TTrackParam co
}
// the force of the coupling, or of the buffers touching, along this vehicle: forwards at the front pulls
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;
vehicle.ends[NumberOf(end)].other_length = other->physics->Dim.L;
}
derailment::track_state track;
track.radius = Shape.R;
@@ -734,7 +734,7 @@ void TMoverParameters::check_derailment(TTrackShape const &Shape, TTrackParam co
WriteLog("derailment monitor: " + Name + " " + derailment::report(verdict, vehicle, track, V, Track.Name != nullptr ? *Track.Name : std::string{}));
}
void TMoverParameters::derail(derailment::verdict const &Verdict, derailment::vehicle_state const &Vehicle, derailment::track_state const &Track, std::string const *TrackName)
void physics::Vehicle::derail(derailment::verdict const &Verdict, derailment::vehicle_state const &Vehicle, derailment::track_state const &Track, std::string const *TrackName)
{
if (false == DamageFlag.Set(VehicleDamage::derailed))
{
@@ -757,7 +757,7 @@ void TMoverParameters::derail(derailment::verdict const &Verdict, derailment::ve
}
}
void TMoverParameters::rerail()
void physics::Vehicle::rerail()
{
DamageFlag.Clear(VehicleDamage::derailed);
Derailed = derailment::outcome::none;
@@ -785,7 +785,7 @@ void TMoverParameters::rerail()
switch_physics(true, wake_cause::command);
}
void TMoverParameters::repair_damage()
void physics::Vehicle::repair_damage()
{
DamageFlag = {};
EngDmgFlag = 0;
@@ -799,7 +799,7 @@ void TMoverParameters::repair_damage()
rerail();
}
void TMoverParameters::Derail(DerailReason const Reason)
void physics::Vehicle::Derail(DerailReason const Reason)
{
if (DamageFlag.Set(VehicleDamage::derailed))
{
@@ -844,19 +844,19 @@ void TMoverParameters::Derail(DerailReason const Reason)
else if (Reason == WRONG_TRACK_TYPE)
ErrorLog("Bad dynamic: " + Name + " derailed due to wrong track type"); // błąd w scenerii
else if (Reason == COLLISION)
WriteLog("Bad driving: " + Name + " derailed"); // This reason also generates its own message in `TMoverParameters::CollisionDetect()`
WriteLog("Bad driving: " + Name + " derailed"); // This reason also generates its own message in `physics::Vehicle::CollisionDetect()`
else if (Reason == TRAILED_SWITCH)
ErrorLog("Bad driving: " + Name + " derailed trailing through a switch with a movable nose set the other way");
}
}
bool TMoverParameters::leaves_track() const
bool physics::Vehicle::leaves_track() const
{
return Global.derailment == global_settings::derailment_model::physical && TestFlag(CategoryFlag, 1) && DamageFlag.HasAll(VehicleDamage::derailed) && Derailed != derailment::outcome::none &&
false == OffTrack.active();
}
void TMoverParameters::pull_off(int const Side, double const Acceleration, std::string const &Why)
void physics::Vehicle::pull_off(int const Side, double const Acceleration, std::string const &Why)
{
if (Global.derailment != global_settings::derailment_model::physical || false == DamageFlag.Set(VehicleDamage::derailed))
{