18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-01 07:07:05 +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
+54 -54
View File
@@ -10,7 +10,7 @@ http://mozilla.org/MPL/2.0/.
// the master and the secondary controllers, the automatic relay and the camshaft, the integrated controller, the speed control
#include "stdafx.h"
#include "physics/mover.h"
#include "physics/vehicle.h"
#include "vehicle/DynObj.h"
#include "physics/oerlikonest.h"
#include "utilities/Globals.h"
@@ -40,7 +40,7 @@ http://mozilla.org/MPL/2.0/.
// zwiększenie nastawinika
// *************************************************************************************************
bool TMoverParameters::IncMainCtrl(int CtrlSpeed)
bool physics::Vehicle::IncMainCtrl(int CtrlSpeed)
{
// basic fail conditions:
if (MainCtrlPosNo <= 0 || CabActive == 0)
@@ -107,14 +107,14 @@ bool TMoverParameters::IncMainCtrl(int CtrlSpeed)
}
// a notch up, as the kind of the engine takes it; returns whether the controller moved
bool TMoverParameters::IncMainCtrlByEngine(int const CtrlSpeed)
bool physics::Vehicle::IncMainCtrlByEngine(int const CtrlSpeed)
{
return Drive().IncreaseMainController(*this, CtrlSpeed);
}
// a notch up of the series motors' controller: CtrlSpeed over 1 runs it to the first position without resistors;
// returns whether it moved as asked
bool TMoverParameters::IncMainCtrlSeriesMotor(int const CtrlSpeed)
bool physics::Vehicle::IncMainCtrlSeriesMotor(int const CtrlSpeed)
{
bool OK = false;
if (DirActive == 0)
@@ -179,7 +179,7 @@ bool TMoverParameters::IncMainCtrlSeriesMotor(int const CtrlSpeed)
// Q: 20160710
// zmniejszenie nastawnika
// *****************************************************************************
bool TMoverParameters::DecMainCtrl(int CtrlSpeed)
bool physics::Vehicle::DecMainCtrl(int CtrlSpeed)
{
bool OK = false;
// basic fail conditions:
@@ -236,13 +236,13 @@ bool TMoverParameters::DecMainCtrl(int CtrlSpeed)
}
// a notch down, as the kind of the engine takes it; returns whether the controller moved
bool TMoverParameters::DecMainCtrlByEngine(int const CtrlSpeed)
bool physics::Vehicle::DecMainCtrlByEngine(int const CtrlSpeed)
{
return Drive().DecreaseMainController(*this, CtrlSpeed);
}
// a notch down of the series motors' controller: CtrlSpeed over 1 runs it down to the first position without resistors
bool TMoverParameters::DecMainCtrlSeriesMotor(int const CtrlSpeed)
bool physics::Vehicle::DecMainCtrlSeriesMotor(int const CtrlSpeed)
{
bool OK = false;
if (CtrlSpeed == 1) /*and (ScndCtrlPos=0)*/
@@ -267,25 +267,25 @@ bool TMoverParameters::DecMainCtrlSeriesMotor(int const CtrlSpeed)
return OK;
}
bool TMoverParameters::IsMainCtrlActualNoPowerPos() const
bool physics::Vehicle::IsMainCtrlActualNoPowerPos() const
{
// TODO: wrap controller pieces into a class for potential specializations, similar to brake subsystems
return MainCtrlActualPos <= MainCtrlNoPowerPos();
}
bool TMoverParameters::IsMainCtrlNoPowerPos() const
bool physics::Vehicle::IsMainCtrlNoPowerPos() const
{
// TODO: wrap controller pieces into a class for potential specializations, similar to brake subsystems
return MainCtrlPos <= MainCtrlNoPowerPos();
}
bool TMoverParameters::IsMainCtrlMaxPowerPos() const
bool physics::Vehicle::IsMainCtrlMaxPowerPos() const
{
// TODO: wrap controller pieces into a class for potential specializations, similar to brake subsystems
return MainCtrlPos == MainCtrlPosNo;
}
int TMoverParameters::MainCtrlNoPowerPos() const
int physics::Vehicle::MainCtrlNoPowerPos() const
{
switch (EIMCtrlType)
@@ -309,35 +309,35 @@ int TMoverParameters::MainCtrlNoPowerPos() const
}
}
int TMoverParameters::MainCtrlActualPowerPos() const
int physics::Vehicle::MainCtrlActualPowerPos() const
{
return MainCtrlActualPos - MainCtrlNoPowerPos();
}
int TMoverParameters::MainCtrlPowerPos() const
int physics::Vehicle::MainCtrlPowerPos() const
{
return MainCtrlPos - MainCtrlNoPowerPos();
}
int TMoverParameters::EIMCtrlEmergencyPositions() const
int physics::Vehicle::EIMCtrlEmergencyPositions() const
{
return (EIMCtrlType == 2 && EIMCtrlMainEmergency) ? 1 : 0;
}
bool TMoverParameters::IsMainCtrlEmergencyPos() const
bool physics::Vehicle::IsMainCtrlEmergencyPos() const
{
return MainCtrlPos < EIMCtrlEmergencyPositions();
}
int TMoverParameters::MainCtrlPosForCoupled() const
int physics::Vehicle::MainCtrlPosForCoupled() const
{
// the emergency brake itself reaches the train through the brake pipe, vented by the vehicle driven from
return std::max(0, MainCtrlPos - EIMCtrlEmergencyPositions());
}
int TMoverParameters::MainCtrlPosFromCoupled(int const Position) const
int physics::Vehicle::MainCtrlPosFromCoupled(int const Position) const
{
return Position + EIMCtrlEmergencyPositions();
}
@@ -346,7 +346,7 @@ int TMoverParameters::MainCtrlPosFromCoupled(int const Position) const
// Q: 20160710
// zwiększenie bocznika
// *************************************************************************************************
bool TMoverParameters::IncScndCtrl(int CtrlSpeed)
bool physics::Vehicle::IncScndCtrl(int CtrlSpeed)
{
bool OK = false;
@@ -419,7 +419,7 @@ bool TMoverParameters::IncScndCtrl(int CtrlSpeed)
// Q: 20160710
// zmniejszenie bocznika
// *************************************************************************************************
bool TMoverParameters::DecScndCtrl(int CtrlSpeed)
bool physics::Vehicle::DecScndCtrl(int CtrlSpeed)
{
bool OK = false;
@@ -480,13 +480,13 @@ bool TMoverParameters::DecScndCtrl(int CtrlSpeed)
return OK;
}
bool TMoverParameters::IsScndCtrlLockedByMainCtrl() const
bool physics::Vehicle::IsScndCtrlLockedByMainCtrl() const
{
// ET21, ET22, EP09: the field shunting engages only on the resistance-free positions of the master controller (eu07/maszyna#402)
return ScndCtrlResistiveLock && (IsMainCtrlNoPowerPos() || RList[MainCtrlPos].R >= 0.01);
}
void TMoverParameters::ScndCtrlResistiveLockCheck()
void physics::Vehicle::ScndCtrlResistiveLockCheck()
{
// the shunt controller, locked in both directions on zero and the resistive positions, would otherwise stay engaged there once the
// master controller is taken back (or set from elsewhere, e.g. by the AI or another vehicle of the consist) with the shunt on
@@ -496,20 +496,20 @@ void TMoverParameters::ScndCtrlResistiveLockCheck()
}
}
int TMoverParameters::GetVirtualScndPos() const
int physics::Vehicle::GetVirtualScndPos() const
{
if (TrainType == train_type::et42 && DynamicBrakeFlag && !ScndCtrlPos)
return -1;
return ScndCtrlPos;
}
bool TMoverParameters::IsScndCtrlNoPowerPos() const
bool physics::Vehicle::IsScndCtrlNoPowerPos() const
{
// TODO: refine the check on account of potential electric series vehicles with speed control
return ScndCtrlPos == 0 || true == SpeedCtrl;
}
bool TMoverParameters::IsScndCtrlMaxPowerPos() const
bool physics::Vehicle::IsScndCtrlMaxPowerPos() const
{
// TODO: refine the check on account of potential electric series vehicles with speed control
return ScndCtrlPos == ScndCtrlPosNo || true == SpeedCtrl;
@@ -519,7 +519,7 @@ bool TMoverParameters::IsScndCtrlMaxPowerPos() const
// Q: 20160713
// Włączenie / wyłączenie automatycznego rozruchu
// *************************************************************************************************
bool TMoverParameters::AutoRelaySwitch(bool State)
bool physics::Vehicle::AutoRelaySwitch(bool State)
{
bool ARS;
if (AutoRelayType == 2 && AutoRelayFlag != State)
@@ -539,7 +539,7 @@ bool TMoverParameters::AutoRelaySwitch(bool State)
// Sprawdzenie warunków pracy automatycznego rozruchu
// *************************************************************************************************
bool TMoverParameters::AutoRelayCheck(void)
bool physics::Vehicle::AutoRelayCheck(void)
{
bool OK = false; // b:int;
@@ -592,7 +592,7 @@ bool TMoverParameters::AutoRelayCheck(void)
}
// a step of the shunt field on a position without resistors, up or down to the second controller
bool TMoverParameters::AutoRelayShuntStep(bool const ARFASI2)
bool physics::Vehicle::AutoRelayShuntStep(bool const ARFASI2)
{
bool OK = false;
// scnd bez samoczynnego rozruchu
@@ -620,7 +620,7 @@ bool TMoverParameters::AutoRelayShuntStep(bool const ARFASI2)
}
// a step of the main controller's relays, up or down to its position, or the shunt field off on the resistors
bool TMoverParameters::AutoRelayMainStep(bool const ARFASI)
bool physics::Vehicle::AutoRelayMainStep(bool const ARFASI)
{
bool OK = false;
// running backwards, the motors don't get joined in more branches than allowed (the series connection
@@ -654,7 +654,7 @@ bool TMoverParameters::AutoRelayMainStep(bool const ARFASI)
// a step of the main relays up to the controller's position, at once to the parallel position without resistors
// on a fast serial circuit (303E); returns whether the relays moved, never into parallel with the overload relay high
bool TMoverParameters::AutoRelayMainUp(bool const ARFASI)
bool physics::Vehicle::AutoRelayMainUp(bool const ARFASI)
{
bool OK = false;
// prevent switch to parallel mode if motor overload relay is set to high threshold mode
@@ -690,7 +690,7 @@ bool TMoverParameters::AutoRelayMainUp(bool const ARFASI)
// a notch up of the main relays after their delay, through the group switch of the ET22, and the sounds of the
// parallel positions; returns whether they moved
bool TMoverParameters::AutoRelayMainNotchUp()
bool physics::Vehicle::AutoRelayMainNotchUp()
{
bool OK = false;
// WriteLog("LRT = " + FloatToStr(LastRelayTime) + ", " +
@@ -739,7 +739,7 @@ bool TMoverParameters::AutoRelayMainNotchUp()
}
// a step of the main relays down to the controller's position; returns whether they moved
bool TMoverParameters::AutoRelayMainDown()
bool physics::Vehicle::AutoRelayMainDown()
{
bool OK = false;
if (RList[MainCtrlPos].R == 0 && MainCtrlPos > 0 && !(MainCtrlPos == MainCtrlPosNo) && FastSerialCircuit == 1)
@@ -771,7 +771,7 @@ bool TMoverParameters::AutoRelayMainDown()
}
// the line contactors closed at the first position, or, open, the camshaft run back to zero
bool TMoverParameters::AutoRelayLineContactorsStep(bool const motorconnectorsoff)
bool physics::Vehicle::AutoRelayLineContactorsStep(bool const motorconnectorsoff)
{
bool OK = false;
// ybARC - zalaczenie stycznikow liniowych
@@ -802,7 +802,7 @@ bool TMoverParameters::AutoRelayLineContactorsStep(bool const motorconnectorsoff
// the camshaft, the line contactors open, run back to its zero position a step at a time, or at once without one;
// returns whether it moved
bool TMoverParameters::CamshaftRunDown()
bool physics::Vehicle::CamshaftRunDown()
{
bool OK = false;
@@ -850,7 +850,7 @@ bool TMoverParameters::CamshaftRunDown()
}
// the one way camshaft of the EN57 run on to its end and round to zero; returns whether it moved
bool TMoverParameters::CamshaftRunDownEMU()
bool physics::Vehicle::CamshaftRunDownEMU()
{
bool OK = false;
// EN57 wal jednokierunkowy calosciowy
@@ -889,7 +889,7 @@ bool TMoverParameters::CamshaftRunDownEMU()
return OK;
}
bool TMoverParameters::MotorConnectorsCheck()
bool physics::Vehicle::MotorConnectorsCheck()
{
// hunter-111211: wylacznik cisnieniowy
@@ -910,7 +910,7 @@ bool TMoverParameters::MotorConnectorsCheck()
return false == connectorsoff && LineContactorsInterlockReleased();
}
bool TMoverParameters::LineContactorsInterlockReleased() const
bool physics::Vehicle::LineContactorsInterlockReleased() const
{
switch (LineContactorsInterlock)
{
@@ -990,7 +990,7 @@ double stepped_uc_value(double const Current, double const Ramped, TUniversalCtr
} // namespace
void TMoverParameters::CheckEIMIC(double dt)
void physics::Vehicle::CheckEIMIC(double dt)
{
double offset = EIMCtrlAdditionalZeros ? 1.0 : 0.0;
double multiplier = (EIMCtrlEmergency ? 1.0 : 0.0) + offset;
@@ -1034,7 +1034,7 @@ void TMoverParameters::CheckEIMIC(double dt)
}
// the controller (EIMCtrlType 0): the position of the main controller, or the analog one, or the brake asked
void TMoverParameters::EIMICFromController(double const brakeDemand, double const offset, double const multiplier)
void physics::Vehicle::EIMICFromController(double const brakeDemand, double const offset, double const multiplier)
{
eimic = brakeDemand > 0.01 ? -brakeDemand : eimic_analog > 0.01 ? eimic_analog : (double)MainCtrlPos / (double)MainCtrlPosNo;
if (EIMCtrlAdditionalZeros || EIMCtrlEmergency)
@@ -1049,7 +1049,7 @@ void TMoverParameters::EIMICFromController(double const brakeDemand, double cons
}
// EIMCtrlType 1: the positions B+ to TMax move the value at a steady pace
void TMoverParameters::EIMICFromSteps(double dt)
void physics::Vehicle::EIMICFromSteps(double dt)
{
switch (MainCtrlPos)
{
@@ -1085,7 +1085,7 @@ void TMoverParameters::EIMICFromSteps(double dt)
// EIMCtrlType 2: the positions 0 to 4 move the value towards -1, 0 or 1, from the controller's delay on; the
// emergency brake position below them, where the controller has one, brakes in full at once
void TMoverParameters::EIMICFromFourPositions(double dt)
void physics::Vehicle::EIMICFromFourPositions(double dt)
{
if (IsMainCtrlEmergencyPos())
{
@@ -1129,7 +1129,7 @@ void TMoverParameters::EIMICFromFourPositions(double dt)
}
// EIMCtrlType 3: the universal controller of UniCtrlList, with the train brake built in or not
void TMoverParameters::EIMICFromUniversalController(double dt, double const brakeDemand)
void physics::Vehicle::EIMICFromUniversalController(double dt, double const brakeDemand)
{
if (UniCtrlIntegratedBrakePNCtrl)
{
@@ -1166,7 +1166,7 @@ void TMoverParameters::EIMICFromUniversalController(double dt, double const brak
// the train brake built into the universal controller: the handle set to the controller's position, or the
// controller, at a brake handle moved alone, to the nearest position of the handle's
void TMoverParameters::UniversalControllerTrainBrake()
void physics::Vehicle::UniversalControllerTrainBrake()
{
if (UniCtrlList[MainCtrlPos].mode != BrakeCtrlPos && MainCtrlActualPos == MainCtrlPos) // there was no move of controller, but brake only
{
@@ -1187,7 +1187,7 @@ void TMoverParameters::UniversalControllerTrainBrake()
}
// the local brake of the TRAXX locomotives, by time: released, held or applied, which cuts the drive off
void TMoverParameters::EIMICTraxxLocalBrake(double dt)
void physics::Vehicle::EIMICTraxxLocalBrake(double dt)
{
if (LocalBrakeRatio() < 0.4) // pozycja 0, odhamowywanie
{
@@ -1210,7 +1210,7 @@ void TMoverParameters::EIMICTraxxLocalBrake(double dt)
}
// the value limited by the power, the spring brake, the pipe lock, the direction and the doors' permits
void TMoverParameters::EIMICLimit()
void physics::Vehicle::EIMICLimit()
{
auto const eimicpowerenabled{(MainCircuitPowered() || Power == 0.0) && (!SpringBrake.IsActive || !SpringBrakeCutsOffDrive) && !LockPipe && DirAbsolute != 0};
auto const eimicdoorenabled{(SpringBrake.IsActive && ReleaseParkingBySpringBrakeWhenDoorIsOpen)};
@@ -1236,7 +1236,7 @@ void TMoverParameters::EIMICLimit()
eimic = safe_clamp(eimic, -1.0, eimicpowerenabled ? eimic_max : 0.0);
}
void TMoverParameters::CheckSpeedCtrl(double dt)
void physics::Vehicle::CheckSpeedCtrl(double dt)
{
if (EIMCtrlType == 0)
{
@@ -1301,7 +1301,7 @@ void TMoverParameters::CheckSpeedCtrl(double dt)
// the PI regulator of the speed control: the power asked of the drive, or its brake intervention, from the error of
// the speed; accfactor, the most power it may ask
void TMoverParameters::SpeedCtrlRegulator(double dt, double const accfactor)
void physics::Vehicle::SpeedCtrlRegulator(double dt, double const accfactor)
{
if (SpeedCtrlUnit.ManualStateOverride && eimic > 0.0009)
eimic = 1.0;
@@ -1339,18 +1339,18 @@ void TMoverParameters::SpeedCtrlRegulator(double dt, double const accfactor)
}
}
bool TMoverParameters::IsSpeedCtrlSeparate() const
bool physics::Vehicle::IsSpeedCtrlSeparate() const
{
// no secondary controller, or one of these engines', which shunts the field of the traction motors (eu07/maszyna#69)
return SpeedCtrl && (ScndCtrlPosNo == 0 || EngineType == TEngineType::ElectricSeriesMotor || EngineType == TEngineType::DieselElectric);
}
bool TMoverParameters::IsSpeedCtrlEngaged() const
bool physics::Vehicle::IsSpeedCtrlEngaged() const
{
return IsSpeedCtrlSeparate() ? SpeedCtrlUnit.IsActive : ScndCtrlPos > 0;
}
bool TMoverParameters::SpeedCtrlSwitch(bool const State)
bool physics::Vehicle::SpeedCtrlSwitch(bool const State)
{
if (false == IsSpeedCtrlSeparate())
{
@@ -1377,7 +1377,7 @@ bool TMoverParameters::SpeedCtrlSwitch(bool const State)
return wasactive;
}
void TMoverParameters::SpeedCtrlButton(int button)
void physics::Vehicle::SpeedCtrlButton(int button)
{
if (SpeedCtrl && IsSpeedCtrlEngaged())
{
@@ -1385,7 +1385,7 @@ void TMoverParameters::SpeedCtrlButton(int button)
}
}
void TMoverParameters::SpeedCtrlInc()
void physics::Vehicle::SpeedCtrlInc()
{
if (SpeedCtrl && IsSpeedCtrlEngaged())
{
@@ -1394,7 +1394,7 @@ void TMoverParameters::SpeedCtrlInc()
}
}
void TMoverParameters::SpeedCtrlDec()
void physics::Vehicle::SpeedCtrlDec()
{
if (SpeedCtrl && IsSpeedCtrlEngaged())
{
@@ -1403,7 +1403,7 @@ void TMoverParameters::SpeedCtrlDec()
}
}
bool TMoverParameters::SpeedCtrlPowerInc()
bool physics::Vehicle::SpeedCtrlPowerInc()
{
if (!(SpeedCtrl && IsSpeedCtrlEngaged()))
return false;
@@ -1415,7 +1415,7 @@ bool TMoverParameters::SpeedCtrlPowerInc()
return true;
}
bool TMoverParameters::SpeedCtrlPowerDec()
bool physics::Vehicle::SpeedCtrlPowerDec()
{
if (!(SpeedCtrl && IsSpeedCtrlEngaged()))
return false;