18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-02 17:46:48 +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
+32 -32
View File
@@ -10,7 +10,7 @@ http://mozilla.org/MPL/2.0/.
// the vehicle as a body: construction, the forces on it, its movement along the track, adhesion and sand
#include "stdafx.h"
#include "physics/mover.h"
#include "physics/vehicle.h"
#include "vehicle/DynObj.h"
#include "physics/oerlikonest.h"
#include "utilities/Globals.h"
@@ -43,7 +43,7 @@ namespace
// friction of its weight, and the forces of the vehicles coupled to it act on it as on any other: the train behind it
// pushes it on, and it holds the train back. alone it stops as the legacy model has it. the legacy model stops it
// whatever pushes it, and the train behind it stopped at once against it, in a hit no train had
bool legacy_derailed_slides(TMoverParameters const &Vehicle)
bool legacy_derailed_slides(physics::Vehicle const &Vehicle)
{
return Global.collisions == global_settings::collision_model::physical && TestFlag(Vehicle.CategoryFlag, 1) && Vehicle.DamageFlag.HasAll(VehicleDamage::derailed) &&
Vehicle.Derailed == derailment::outcome::none;
@@ -67,7 +67,7 @@ int DirF(VehicleEnd CouplerN)
// *************************************************************************************************
// główny konstruktor
// *************************************************************************************************
TMoverParameters::TMoverParameters(double VelInitial, std::string const &TypeNameInit, std::string const &NameInit, int Cab) : TypeName(TypeNameInit), Name(NameInit), CabOccupied(Cab)
physics::Vehicle::Vehicle(double VelInitial, std::string const &TypeNameInit, std::string const &NameInit, int Cab) : TypeName(TypeNameInit), Name(NameInit), CabOccupied(Cab)
{
WriteLog("------------------------------------------------------");
WriteLog("init default physic values for " + NameInit + ", [" + TypeNameInit + "]");
@@ -166,10 +166,10 @@ TMoverParameters::TMoverParameters(double VelInitial, std::string const &TypeNam
RunningTraction.TractionResistivity = 1.0;
};
void TMoverParameters::change_train_velocity(double const Change)
void physics::Vehicle::change_train_velocity(double const Change)
{
// the vehicles coupled to this one in a line, each with the direction of its axis to the axis of this one
std::vector<std::pair<TMoverParameters *, int>> train{{this, 1}};
std::vector<std::pair<physics::Vehicle *, int>> train{{this, 1}};
for (std::size_t i = 0; i < train.size(); ++i)
{
auto const [vehicle, direction] = train[i];
@@ -191,7 +191,7 @@ void TMoverParameters::change_train_velocity(double const Change)
// *************************************************************************************************
// Oblicza przemieszczenie taboru
// *************************************************************************************************
double TMoverParameters::ComputeMovement(double dt, double dt1, const TTrackShape &Shape, TTrackParam const &Track, TTractionParam const &ElectricTraction, TLocation const &NewLoc, TRotation const &NewRot)
double physics::Vehicle::ComputeMovement(double dt, double dt1, const TTrackShape &Shape, TTrackParam const &Track, TTractionParam const &ElectricTraction, TLocation const &NewLoc, TRotation const &NewRot)
{
if (!DamageFlag.HasAll(VehicleDamage::derailed))
@@ -335,9 +335,9 @@ double TMoverParameters::ComputeMovement(double dt, double dt1, const TTrackShap
// Oblicza przemieszczenie taboru - uproszczona wersja
// *************************************************************************************************
double TMoverParameters::FastComputeMovement(double dt, const TTrackShape & /*Shape*/, TTrackParam & /*Track*/, TLocation const &NewLoc, TRotation const &NewRot)
double physics::Vehicle::FastComputeMovement(double dt, const TTrackShape & /*Shape*/, TTrackParam & /*Track*/, TLocation const &NewLoc, TRotation const &NewRot)
{
// T_MoverParameters::FastComputeMovement(dt, Shape, Track, NewLoc, NewRot);
// physics::Vehicle::FastComputeMovement(dt, Shape, Track, NewLoc, NewRot);
Loc = NewLoc;
Rot = NewRot;
@@ -406,7 +406,7 @@ double TMoverParameters::FastComputeMovement(double dt, const TTrackShape & /*Sh
};
// updates shared between 'fast' and regular movement computation methods
void TMoverParameters::compute_movement_(double const Deltatime)
void physics::Vehicle::compute_movement_(double const Deltatime)
{
// sprawdzanie i ewentualnie wykonywanie->kasowanie poleceń
@@ -534,7 +534,7 @@ void TMoverParameters::compute_movement_(double const Deltatime)
// Q: 20160710
// Siła napędzająca drezynę po naciśnięciu wajhy
// *************************************************************************************************
bool TMoverParameters::AddPulseForce(int Multipler)
bool physics::Vehicle::AddPulseForce(int Multipler)
{
bool APF;
if (EngineType == TEngineType::WheelsDriven && EnginePowerSource.SourceType == TPowerSource::InternalSource && EnginePowerSource.PowerType == TPowerType::BioPower)
@@ -561,7 +561,7 @@ bool TMoverParameters::AddPulseForce(int Multipler)
// yB: 20190909
// sypanie piasku reczne
// *************************************************************************************************
bool TMoverParameters::SandboxManual(bool const State, range_t const Notify)
bool physics::Vehicle::SandboxManual(bool const State, range_t const Notify)
{
bool result{false};
@@ -593,7 +593,7 @@ bool TMoverParameters::SandboxManual(bool const State, range_t const Notify)
// yB: 20190909
// sypanie piasku automatyczne
// *************************************************************************************************
bool TMoverParameters::SandboxAuto(bool const State, range_t const Notify)
bool physics::Vehicle::SandboxAuto(bool const State, range_t const Notify)
{
bool result{false};
if (bool NewState = State && SandDoseAutoAllow; SandDoseAuto != NewState)
@@ -624,7 +624,7 @@ bool TMoverParameters::SandboxAuto(bool const State, range_t const Notify)
// Q: 20160713
// sypanie piasku
// *************************************************************************************************
bool TMoverParameters::Sandbox(bool const State, range_t const Notify)
bool physics::Vehicle::Sandbox(bool const State, range_t const Notify)
{
bool result{false};
@@ -671,7 +671,7 @@ bool TMoverParameters::Sandbox(bool const State, range_t const Notify)
// yB: 20190909
// włączenie / wyłączenie automatycznej piasecznicy
// *************************************************************************************************
bool TMoverParameters::SandboxAutoAllow(bool State)
bool physics::Vehicle::SandboxAutoAllow(bool State)
{
// SendCtrlToNext(VehicleCommand::sandboxAutoAllow, int(State), CabActive, Coupling::control);
@@ -688,7 +688,7 @@ bool TMoverParameters::SandboxAutoAllow(bool State)
// Q: 20160713
// Obliczenie stałych potrzebnych do dalszych obliczeń
// *************************************************************************************************
void TMoverParameters::ComputeConstans(void)
void physics::Vehicle::ComputeConstans(void)
{
double BearingF;
double RollF;
@@ -750,7 +750,7 @@ void TMoverParameters::ComputeConstans(void)
// Q: 20160713
// Oblicza masę ładunku
// *************************************************************************************************
void TMoverParameters::ComputeMass()
void physics::Vehicle::ComputeMass()
{
// Ra: na razie tak, ale nie wszędzie masy wirujące się wliczają
TotalMass = Mass + Mred;
@@ -781,7 +781,7 @@ void TMoverParameters::ComputeMass()
// Obliczanie wypadkowej siły z wszystkich działających sił
// *************************************************************************************************
// TBD, TODO: move some of the calculations out of the method, they're relevant to more than just force calculations
void TMoverParameters::ComputeTotalForce(double dt)
void physics::Vehicle::ComputeTotalForce(double dt)
{
Vel = std::abs(V) * 3.6; // prędkość w km/h
@@ -798,10 +798,10 @@ void TMoverParameters::ComputeTotalForce(double dt)
auto const vehicleisactive{CabActive != 0 || Vel > 0.0001 || accelerating() || LastSwitchingTime < 5 || is_multiple_unit()};
auto const movingvehicleahead{Neighbours[VehicleEnd::front].vehicle != nullptr &&
(Neighbours[VehicleEnd::front].vehicle->MoverParameters->Vel > 0.0001 || Neighbours[VehicleEnd::front].vehicle->MoverParameters->accelerating())};
(Neighbours[VehicleEnd::front].vehicle->physics->Vel > 0.0001 || Neighbours[VehicleEnd::front].vehicle->physics->accelerating())};
auto const movingvehiclebehind{Neighbours[VehicleEnd::rear].vehicle != nullptr &&
(Neighbours[VehicleEnd::rear].vehicle->MoverParameters->Vel > 0.0001 || Neighbours[VehicleEnd::rear].vehicle->MoverParameters->accelerating())};
(Neighbours[VehicleEnd::rear].vehicle->physics->Vel > 0.0001 || Neighbours[VehicleEnd::rear].vehicle->physics->accelerating())};
auto const calculatephysics{vehicleisactive || movingvehicleahead || movingvehiclebehind};
@@ -924,7 +924,7 @@ void TMoverParameters::ComputeTotalForce(double dt)
if (Neighbours[end].vehicle != nullptr)
{
// the velocities before the step, the forces of all the vehicles come before their movement
Couplers[end].closing = -CouplerVelocityDifference(end, *Neighbours[end].vehicle->MoverParameters, Neighbours[end].FacingEnd()) * DirF(end);
Couplers[end].closing = -CouplerVelocityDifference(end, *Neighbours[end].vehicle->physics, Neighbours[end].FacingEnd()) * DirF(end);
Couplers[end].CForce = CouplerForce(end, dt);
FTrain += Couplers[end].CForce;
// what the buffers of the pair take in, for the budget of the crush (physics.collisions new and monitor)
@@ -946,7 +946,7 @@ void TMoverParameters::ComputeTotalForce(double dt)
FTotal = FTrain - Sign(V) * FStand;
}
double TMoverParameters::BrakeForceR(double ratio, double velocity) const
double physics::Vehicle::BrakeForceR(double ratio, double velocity) const
{
double press = 0;
ratio = Hamulec->GetBrakeRatio(ratio);
@@ -976,7 +976,7 @@ double TMoverParameters::BrakeForceR(double ratio, double velocity) const
return BrakeForceP(press * ratio, velocity);
}
double TMoverParameters::BrakeForceP(double press, double velocity) const
double physics::Vehicle::BrakeForceP(double press, double velocity) const
{
double BFP = 0;
double K = ((press * P2FTrans - BrakeCylSpring) * BrakeCylMult[0] - BrakeSlckAdj) * BrakeRigEff;
@@ -989,7 +989,7 @@ double TMoverParameters::BrakeForceP(double press, double velocity) const
// Q: 20160713
// oblicza siłę na styku koła i szyny
// *************************************************************************************************
double TMoverParameters::BrakeForce(TTrackParam const & /*Track*/)
double physics::Vehicle::BrakeForce(TTrackParam const & /*Track*/)
{
double K{0};
@@ -1062,7 +1062,7 @@ double TMoverParameters::BrakeForce(TTrackParam const & /*Track*/)
// Q: 20160713
// Obliczanie siły tarcia
// *************************************************************************************************
double TMoverParameters::FrictionForce() const
double physics::Vehicle::FrictionForce() const
{
double FF = 0;
// ABu 240205: chyba juz ekstremalnie zoptymalizowana funkcja liczaca sily tarcia
@@ -1077,7 +1077,7 @@ double TMoverParameters::FrictionForce() const
// Q: 20160713
// Oblicza przyczepność
// *************************************************************************************************
double TMoverParameters::Adhesive(double staticfriction) const
double physics::Vehicle::Adhesive(double staticfriction) const
{
double adhesion = 0.0;
const double adh_factor = 0.25; // współczynnik określający, jak bardzo spada tarcie przy poślizgu
@@ -1132,7 +1132,7 @@ double TMoverParameters::Adhesive(double staticfriction) const
// Q: 20160713
// Obliczenie predkości obrotowej kół???
// *************************************************************************************************
double TMoverParameters::ComputeRotatingWheel(double WForce, double dt, double n) const
double physics::Vehicle::ComputeRotatingWheel(double WForce, double dt, double n) const
{
double newn = 0;
double eps = 0;
@@ -1152,7 +1152,7 @@ double TMoverParameters::ComputeRotatingWheel(double WForce, double dt, double n
// Q: 20160713
// Przesuwa pojazd o podaną wartość w bok względem toru (dla samochodów)
// *************************************************************************************************
bool TMoverParameters::ChangeOffsetH(double DeltaOffset)
bool physics::Vehicle::ChangeOffsetH(double DeltaOffset)
{
bool COH = false;
if (TestFlag(CategoryFlag, 2) && TestFlag(RunningTrack.CategoryFlag, 2))
@@ -1174,7 +1174,7 @@ bool TMoverParameters::ChangeOffsetH(double DeltaOffset)
// Q: 20160713
// Testuje zmienną (narazie tylko 0) i na podstawie uszkodzenia zwraca informację tekstową
// *************************************************************************************************
std::string TMoverParameters::EngineDescription(int what) const
std::string physics::Vehicle::EngineDescription(int what) const
{
std::string outstr{"OK"};
if (what == 0)
@@ -1238,7 +1238,7 @@ std::string TMoverParameters::EngineDescription(int what) const
// *************************************************************************************************
// whether the vehicle accelerates, for the test which turns the physics off in vehicles standing still
// *************************************************************************************************
bool TMoverParameters::accelerating() const
bool physics::Vehicle::accelerating() const
{
if (std::abs(AccS) <= 0.0001)
return false;
@@ -1251,7 +1251,7 @@ bool TMoverParameters::accelerating() const
return false == held;
}
void TMoverParameters::wake_for_brake()
void physics::Vehicle::wake_for_brake()
{
if (Global.physics_sleepheld)
{
@@ -1268,7 +1268,7 @@ void TMoverParameters::wake_for_brake()
// which the cylinder gives no force: a release ends with the vehicle asleep and no force left. a cylinder holding its
// pressure, or settling within that, leaves the vehicle asleep
// *************************************************************************************************
bool TMoverParameters::brakes_changed_asleep() const
bool physics::Vehicle::brakes_changed_asleep() const
{
if (PhysicActivation)
return false;
@@ -1280,7 +1280,7 @@ bool TMoverParameters::brakes_changed_asleep() const
// *************************************************************************************************
// Kasowanie zmiennych pracy fizyki
// *************************************************************************************************
bool TMoverParameters::switch_physics(bool const State, wake_cause const Cause) // DO PRZETLUMACZENIA NA KONCU
bool physics::Vehicle::switch_physics(bool const State, wake_cause const Cause) // DO PRZETLUMACZENIA NA KONCU
{
if (PhysicActivation == State)
{