18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-01 22:07:55 +01:00

refactor(physics): what the rest of the simulator only reads of a vehicle is private to it

53 fields of physics::Vehicle that only the vehicle itself writes, and the rest
of the simulator reads, are private, with a query each, named as the field was
(Vmax(), TotalMass(), Ft(), nrot(), NAxles(), PhysicActivation(), ...): the
compiler now keeps the cab, the AI, the scenery, the renderer and the tests from
changing what the definition gives or the physics works out. The fields were
picked by what is never written outside the class, of plain types, with no
other member of the same name to confuse; inside the class they keep their
meaning under camelCase names. The one place outside that cleared a flag of
the AI through a reference does it through ClearAIFlag().

No change in behaviour: the golden traces recorded on dfb43c4f match bit for bit.
This commit is contained in:
2026-11-29 13:17:56 +01:00
parent 74f0aa240d
commit 5879c228dc
88 changed files with 1053 additions and 992 deletions
+16 -16
View File
@@ -39,7 +39,7 @@ bool physics::Vehicle::CheckLocomotiveParameters(bool ReadyFlag, int /*Dir*/)
WriteLog("check locomotive parameters...");
bool OK = true;
AutoRelayFlag = AutoRelayType == 1;
autoRelayFlag = autoRelayType == 1;
if (lowVoltage.config.nominalBatteryVoltage == 0.0)
{
@@ -56,10 +56,10 @@ bool physics::Vehicle::CheckLocomotiveParameters(bool ReadyFlag, int /*Dir*/)
// for these engine types secondary controller positions index MotorParam table
if ((EngineType == TEngineType::ElectricSeriesMotor || EngineType == TEngineType::DieselEngine || EngineType == TEngineType::DieselElectric) &&
ScndCtrlPosNo > MotorParametersArraySize)
scndCtrlPosNo > MotorParametersArraySize)
{
WriteLog("SCPN=" + std::to_string(ScndCtrlPosNo) + " exceeds motor parameter table size, limited to " + std::to_string(MotorParametersArraySize));
ScndCtrlPosNo = MotorParametersArraySize;
WriteLog("SCPN=" + std::to_string(scndCtrlPosNo) + " exceeds motor parameter table size, limited to " + std::to_string(MotorParametersArraySize));
scndCtrlPosNo = MotorParametersArraySize;
}
// WriteLog("aa = " + AxleArangement + " " + std::string( Pos("o", AxleArangement)) );
@@ -67,7 +67,7 @@ bool physics::Vehicle::CheckLocomotiveParameters(bool ReadyFlag, int /*Dir*/)
if (contains(AxleArangement, "o") && EngineType == TEngineType::ElectricSeriesMotor)
{
// test poprawnosci ilosci osi indywidualnie napedzanych
OK = RList[1].Bn * RList[1].Mn == NPoweredAxles;
OK = RList[1].Bn * RList[1].Mn == nPoweredAxles;
// WriteLogSS("aa ok", BoolToYN(OK));
}
@@ -226,7 +226,7 @@ void physics::Vehicle::CreateBrakeValve()
case TBrakeValve::K:
{
WriteLog("XBT W, K");
brakes.distributor = std::make_shared<TWest>(brakes.config.maxCylinderPressure[3], brakes.config.cylinders.radius, brakes.config.cylinders.stroke, brakes.config.valveVolume, brakes.config.cylinders.count, brakes.config.availableDelays, brakes.config.method, NAxles, brakes.config.blocksPerAxle);
brakes.distributor = std::make_shared<TWest>(brakes.config.maxCylinderPressure[3], brakes.config.cylinders.radius, brakes.config.cylinders.stroke, brakes.config.valveVolume, brakes.config.cylinders.count, brakes.config.availableDelays, brakes.config.method, nAxles, brakes.config.blocksPerAxle);
if (brakes.config.maxPressureMass < 2) // jesli przystawka wazaca
brakes.distributor->SetLP(0, brakes.config.maxCylinderPressure[3], 0);
else
@@ -236,7 +236,7 @@ void physics::Vehicle::CreateBrakeValve()
case TBrakeValve::KE:
{
WriteLog("XBT WKE");
brakes.distributor = std::make_shared<TKE>(brakes.config.maxCylinderPressure[3], brakes.config.cylinders.radius, brakes.config.cylinders.stroke, brakes.config.valveVolume, brakes.config.cylinders.count, brakes.config.availableDelays, brakes.config.method, NAxles, brakes.config.blocksPerAxle);
brakes.distributor = std::make_shared<TKE>(brakes.config.maxCylinderPressure[3], brakes.config.cylinders.radius, brakes.config.cylinders.stroke, brakes.config.valveVolume, brakes.config.cylinders.count, brakes.config.availableDelays, brakes.config.method, nAxles, brakes.config.blocksPerAxle);
brakes.distributor->SetRM(brakes.config.rapidRatio);
if (brakes.config.maxPressureMass < 2) // jesli przystawka wazaca
brakes.distributor->SetLP(0, brakes.config.maxCylinderPressure[3], 0);
@@ -250,7 +250,7 @@ void physics::Vehicle::CreateBrakeValve()
case TBrakeValve::ESt4:
{
WriteLog("XBT NESt3, ESt3, ESt3AL2, ESt4");
brakes.distributor = std::make_shared<TNESt3>(brakes.config.maxCylinderPressure[3], brakes.config.cylinders.radius, brakes.config.cylinders.stroke, brakes.config.valveVolume, brakes.config.cylinders.count, brakes.config.availableDelays, brakes.config.method, NAxles, brakes.config.blocksPerAxle);
brakes.distributor = std::make_shared<TNESt3>(brakes.config.maxCylinderPressure[3], brakes.config.cylinders.radius, brakes.config.cylinders.stroke, brakes.config.valveVolume, brakes.config.cylinders.count, brakes.config.availableDelays, brakes.config.method, nAxles, brakes.config.blocksPerAxle);
static_cast<TNESt3 *>(brakes.distributor.get())->SetSize(brakes.config.distributorSize, brakes.config.distributorParameters);
if (brakes.config.maxPressureMass < 2) // jesli przystawka wazaca
brakes.distributor->SetLP(0, brakes.config.maxCylinderPressure[3], 0);
@@ -261,14 +261,14 @@ void physics::Vehicle::CreateBrakeValve()
case TBrakeValve::LSt:
{
WriteLog("XBT LSt");
brakes.distributor = std::make_shared<TLSt>(brakes.config.maxCylinderPressure[3], brakes.config.cylinders.radius, brakes.config.cylinders.stroke, brakes.config.valveVolume, brakes.config.cylinders.count, brakes.config.availableDelays, brakes.config.method, NAxles, brakes.config.blocksPerAxle);
brakes.distributor = std::make_shared<TLSt>(brakes.config.maxCylinderPressure[3], brakes.config.cylinders.radius, brakes.config.cylinders.stroke, brakes.config.valveVolume, brakes.config.cylinders.count, brakes.config.availableDelays, brakes.config.method, nAxles, brakes.config.blocksPerAxle);
brakes.distributor->SetRM(brakes.config.rapidRatio);
break;
}
case TBrakeValve::EStED:
{
WriteLog("XBT EStED");
brakes.distributor = std::make_shared<TEStED>(brakes.config.maxCylinderPressure[3], brakes.config.cylinders.radius, brakes.config.cylinders.stroke, brakes.config.valveVolume, brakes.config.cylinders.count, brakes.config.availableDelays, brakes.config.method, NAxles, brakes.config.blocksPerAxle);
brakes.distributor = std::make_shared<TEStED>(brakes.config.maxCylinderPressure[3], brakes.config.cylinders.radius, brakes.config.cylinders.stroke, brakes.config.valveVolume, brakes.config.cylinders.count, brakes.config.availableDelays, brakes.config.method, nAxles, brakes.config.blocksPerAxle);
brakes.distributor->SetRM(brakes.config.rapidRatio);
if (brakes.config.maxPressureMass < 2)
{
@@ -284,14 +284,14 @@ void physics::Vehicle::CreateBrakeValve()
case TBrakeValve::EP2:
{
WriteLog("XBT EP2");
brakes.distributor = std::make_shared<TEStEP2>(brakes.config.maxCylinderPressure[3], brakes.config.cylinders.radius, brakes.config.cylinders.stroke, brakes.config.valveVolume, brakes.config.cylinders.count, brakes.config.availableDelays, brakes.config.method, NAxles, brakes.config.blocksPerAxle);
brakes.distributor = std::make_shared<TEStEP2>(brakes.config.maxCylinderPressure[3], brakes.config.cylinders.radius, brakes.config.cylinders.stroke, brakes.config.valveVolume, brakes.config.cylinders.count, brakes.config.availableDelays, brakes.config.method, nAxles, brakes.config.blocksPerAxle);
brakes.distributor->SetLP(Mass, brakes.config.maxPressureMass, brakes.config.maxCylinderPressure[1]);
break;
}
case TBrakeValve::EP1:
{
WriteLog("XBT EP1");
brakes.distributor = std::make_shared<TEStEP1>(brakes.config.maxCylinderPressure[3], brakes.config.cylinders.radius, brakes.config.cylinders.stroke, brakes.config.valveVolume, brakes.config.cylinders.count, brakes.config.availableDelays, brakes.config.method, NAxles, brakes.config.blocksPerAxle);
brakes.distributor = std::make_shared<TEStEP1>(brakes.config.maxCylinderPressure[3], brakes.config.cylinders.radius, brakes.config.cylinders.stroke, brakes.config.valveVolume, brakes.config.cylinders.count, brakes.config.availableDelays, brakes.config.method, nAxles, brakes.config.blocksPerAxle);
brakes.distributor->SetLP(Mass, brakes.config.maxPressureMass, brakes.config.maxCylinderPressure[1]);
brakes.distributor->SetRM(brakes.config.rapidRatio);
break;
@@ -299,17 +299,17 @@ void physics::Vehicle::CreateBrakeValve()
case TBrakeValve::CV1:
{
WriteLog("XBT CV1");
brakes.distributor = std::make_shared<TCV1>(brakes.config.maxCylinderPressure[3], brakes.config.cylinders.radius, brakes.config.cylinders.stroke, brakes.config.valveVolume, brakes.config.cylinders.count, brakes.config.availableDelays, brakes.config.method, NAxles, brakes.config.blocksPerAxle);
brakes.distributor = std::make_shared<TCV1>(brakes.config.maxCylinderPressure[3], brakes.config.cylinders.radius, brakes.config.cylinders.stroke, brakes.config.valveVolume, brakes.config.cylinders.count, brakes.config.availableDelays, brakes.config.method, nAxles, brakes.config.blocksPerAxle);
break;
}
case TBrakeValve::CV1_L_TR:
{
WriteLog("XBT CV1_L_T");
brakes.distributor = std::make_shared<TCV1L_TR>(brakes.config.maxCylinderPressure[3], brakes.config.cylinders.radius, brakes.config.cylinders.stroke, brakes.config.valveVolume, brakes.config.cylinders.count, brakes.config.availableDelays, brakes.config.method, NAxles, brakes.config.blocksPerAxle);
brakes.distributor = std::make_shared<TCV1L_TR>(brakes.config.maxCylinderPressure[3], brakes.config.cylinders.radius, brakes.config.cylinders.stroke, brakes.config.valveVolume, brakes.config.cylinders.count, brakes.config.availableDelays, brakes.config.method, nAxles, brakes.config.blocksPerAxle);
break;
}
default:
brakes.distributor = std::make_shared<TBrake>(brakes.config.maxCylinderPressure[3], brakes.config.cylinders.radius, brakes.config.cylinders.stroke, brakes.config.valveVolume, brakes.config.cylinders.count, brakes.config.availableDelays, brakes.config.method, NAxles, brakes.config.blocksPerAxle);
brakes.distributor = std::make_shared<TBrake>(brakes.config.maxCylinderPressure[3], brakes.config.cylinders.radius, brakes.config.cylinders.stroke, brakes.config.valveVolume, brakes.config.cylinders.count, brakes.config.availableDelays, brakes.config.method, nAxles, brakes.config.blocksPerAxle);
}
brakes.distributor->SetASBP(brakes.config.maxCylinderPressure[4]);
@@ -364,7 +364,7 @@ void physics::Vehicle::CreateBrakeHandles()
{
brakes.independentValve = std::make_shared<TFD1>();
brakes.independentValve->Init(brakes.config.maxCylinderPressure[0]);
if (TrainType == train_type::emu)
if (trainType == train_type::emu)
{
dynamic_cast<TFD1 *>(brakes.independentValve.get())->SetSpeed(3.5);