18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-03 06:35:21 +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
+51 -51
View File
@@ -4,7 +4,7 @@
#include "application/driveruipanels.h"
#include "vehicle/Driver.h"
#include "vehicle/Train.h"
#include "physics/mover.h"
#include "physics/vehicle.h"
ui::vehicleparams_panel::vehicleparams_panel(const std::string &vehicle) : ui_panel(std::string(STR("Vehicle parameters")) + ": " + vehicle, false), m_vehicle_name(vehicle)
{
@@ -47,7 +47,7 @@ void ui::vehicleparams_panel::draw_infobutton(const char *str, ImVec2 pos, const
ImGui::PopStyleColor(4);
}
void ui::vehicleparams_panel::draw_mini(const TMoverParameters &mover)
void ui::vehicleparams_panel::draw_mini(const physics::Vehicle &physics)
{
if (vehicle_mini == null_handle)
return;
@@ -63,34 +63,34 @@ void ui::vehicleparams_panel::draw_mini(const TMoverParameters &mover)
{
ImGui::Image((ImTextureID)(intptr_t)(tex.get_id()), ImVec2(x, y), ImVec2(0, 1), ImVec2(1, 0));
if (mover.Pantographs[VehicleEnd::rear].is_active)
if (physics.Pantographs[VehicleEnd::rear].is_active)
draw_infobutton("╨╨╨", ImVec2(126, 10));
if (mover.Pantographs[VehicleEnd::front].is_active)
if (physics.Pantographs[VehicleEnd::front].is_active)
draw_infobutton("╨╨╨", ImVec2(290, 10));
if (mover.Battery)
if (physics.Battery)
draw_infobutton(STR_C("bat."), ImVec2(120, 55));
if (mover.Mains)
if (physics.Mains)
draw_infobutton(STR_C("main."));
if (mover.ConverterFlag)
if (physics.ConverterFlag)
draw_infobutton(STR_C("conv."));
if (mover.CompressorFlag)
if (physics.CompressorFlag)
draw_infobutton(STR_C("comp."));
if (mover.WarningSignal)
if (physics.WarningSignal)
draw_infobutton(STR_C("horn"), ImVec2(361, 11));
if (mover.iLights[VehicleEnd::front] & light::redmarker_left)
if (physics.iLights[VehicleEnd::front] & light::redmarker_left)
draw_infobutton("o", ImVec2(490, 71), ImVec4(1.0f, 0.0f, 0.0f, 1.0f));
else if (mover.iLights[VehicleEnd::front] & light::headlight_left)
else if (physics.iLights[VehicleEnd::front] & light::headlight_left)
draw_infobutton("O", ImVec2(490, 71), ImVec4(1.0f, 1.0f, 1.0f, 1.0f));
if (mover.iLights[VehicleEnd::front] & light::redmarker_right)
if (physics.iLights[VehicleEnd::front] & light::redmarker_right)
draw_infobutton("o", ImVec2(443, 71), ImVec4(1.0f, 0.0f, 0.0f, 1.0f));
else if (mover.iLights[VehicleEnd::front] & light::headlight_right)
else if (physics.iLights[VehicleEnd::front] & light::headlight_right)
draw_infobutton("O", ImVec2(443, 71), ImVec4(1.0f, 1.0f, 1.0f, 1.0f));
if (mover.iLights[VehicleEnd::front] & light::headlight_upper)
if (physics.iLights[VehicleEnd::front] & light::headlight_upper)
draw_infobutton("O", ImVec2(467, 18), ImVec4(1.0f, 1.0f, 1.0f, 1.0f));
}
ImGui::EndChild();
@@ -138,28 +138,28 @@ void ui::vehicleparams_panel::render_contents()
}
TDynamicObject &vehicle = *vehicle_ptr;
TMoverParameters &mover = *vehicle.MoverParameters;
physics::Vehicle &physics = *vehicle.physics;
std::vector<text_line> lines;
std::array<char, 1024> buffer;
auto const isdieselenginepowered{(mover.EngineType == TEngineType::DieselElectric) || (mover.EngineType == TEngineType::DieselEngine)};
auto const isdieselinshuntmode{mover.ShuntMode && mover.EngineType == TEngineType::DieselElectric};
auto const isdieselenginepowered{(physics.EngineType == TEngineType::DieselElectric) || (physics.EngineType == TEngineType::DieselEngine)};
auto const isdieselinshuntmode{physics.ShuntMode && physics.EngineType == TEngineType::DieselElectric};
std::snprintf(buffer.data(), buffer.size(), STR_C("Devices: %c%c%c%c%c%c%c%c%c%c%c%c%c%c%s%s\nPower transfers: %.0f@%.0f%s%s%s%.0f@%.0f"),
// devices
(mover.Battery ? 'B' : '.'), (mover.Mains ? 'M' : '.'), (mover.FuseFlag ? '!' : '.'), (mover.Pantographs[VehicleEnd::rear].is_active ? (mover.PantRearVolt > 0.0 ? 'O' : 'o') : '.'),
(mover.Pantographs[VehicleEnd::front].is_active ? (mover.PantFrontVolt > 0.0 ? 'P' : 'p') : '.'), (mover.PantPressLockActive ? '!' : (mover.PantPressSwitchActive ? '*' : '.')),
(mover.WaterPump.is_active ? 'W' : (false == mover.WaterPump.breaker ? '-' : (mover.WaterPump.is_enabled ? 'w' : '.'))),
(true == mover.WaterHeater.is_damaged ? '!' : (mover.WaterHeater.is_active ? 'H' : (false == mover.WaterHeater.breaker ? '-' : (mover.WaterHeater.is_enabled ? 'h' : '.')))),
(mover.FuelPump.is_active ? 'F' : (mover.FuelPump.is_enabled ? 'f' : '.')), (mover.OilPump.is_active ? 'O' : (mover.OilPump.is_enabled ? 'o' : '.')),
(false == mover.ConverterAllowLocal ? '-' : (mover.ConverterAllow ? (mover.ConverterFlag ? 'X' : 'x') : '.')), (mover.ConvOvldFlag ? '!' : '.'),
(mover.CompressorFlag ? 'C' : (false == mover.CompressorAllowLocal ? '-' : ((mover.CompressorAllow || mover.CompressorStart == start_t::automatic) ? 'c' : '.'))),
(mover.CompressorGovernorLock ? '!' : '.'), "", std::string(isdieselenginepowered ? STR(" oil pressure: ") + to_string(mover.OilPump.pressure, 2) : "").c_str(),
(physics.Battery ? 'B' : '.'), (physics.Mains ? 'M' : '.'), (physics.FuseFlag ? '!' : '.'), (physics.Pantographs[VehicleEnd::rear].is_active ? (physics.PantRearVolt > 0.0 ? 'O' : 'o') : '.'),
(physics.Pantographs[VehicleEnd::front].is_active ? (physics.PantFrontVolt > 0.0 ? 'P' : 'p') : '.'), (physics.PantPressLockActive ? '!' : (physics.PantPressSwitchActive ? '*' : '.')),
(physics.WaterPump.is_active ? 'W' : (false == physics.WaterPump.breaker ? '-' : (physics.WaterPump.is_enabled ? 'w' : '.'))),
(true == physics.WaterHeater.is_damaged ? '!' : (physics.WaterHeater.is_active ? 'H' : (false == physics.WaterHeater.breaker ? '-' : (physics.WaterHeater.is_enabled ? 'h' : '.')))),
(physics.FuelPump.is_active ? 'F' : (physics.FuelPump.is_enabled ? 'f' : '.')), (physics.OilPump.is_active ? 'O' : (physics.OilPump.is_enabled ? 'o' : '.')),
(false == physics.ConverterAllowLocal ? '-' : (physics.ConverterAllow ? (physics.ConverterFlag ? 'X' : 'x') : '.')), (physics.ConvOvldFlag ? '!' : '.'),
(physics.CompressorFlag ? 'C' : (false == physics.CompressorAllowLocal ? '-' : ((physics.CompressorAllow || physics.CompressorStart == start_t::automatic) ? 'c' : '.'))),
(physics.CompressorGovernorLock ? '!' : '.'), "", std::string(isdieselenginepowered ? STR(" oil pressure: ") + to_string(physics.OilPump.pressure, 2) : "").c_str(),
// power transfers
mover.Couplers[VehicleEnd::front].power_high.voltage, mover.Couplers[VehicleEnd::front].power_high.current, std::string(mover.Couplers[VehicleEnd::front].power_high.is_local ? "" : "-").c_str(),
std::string(vehicle.DirectionGet() ? ":<<:" : ":>>:").c_str(), std::string(mover.Couplers[VehicleEnd::rear].power_high.is_local ? "" : "-").c_str(),
mover.Couplers[VehicleEnd::rear].power_high.voltage, mover.Couplers[VehicleEnd::rear].power_high.current);
physics.Couplers[VehicleEnd::front].power_high.voltage, physics.Couplers[VehicleEnd::front].power_high.current, std::string(physics.Couplers[VehicleEnd::front].power_high.is_local ? "" : "-").c_str(),
std::string(vehicle.DirectionGet() ? ":<<:" : ":>>:").c_str(), std::string(physics.Couplers[VehicleEnd::rear].power_high.is_local ? "" : "-").c_str(),
physics.Couplers[VehicleEnd::rear].power_high.voltage, physics.Couplers[VehicleEnd::rear].power_high.current);
ImGui::TextUnformatted(buffer.data());
@@ -167,20 +167,20 @@ void ui::vehicleparams_panel::render_contents()
STR_C("Controllers:\n master: %d(%d), secondary: %s\nEngine output: %.1f, current: %.0f\nRevolutions:\n engine: %.0f, motors: %.0f\n engine fans: %.0f, motor fans: %.0f+%.0f, "
"cooling fans: %.0f+%.0f"),
// controllers
mover.MainCtrlPos, mover.MainCtrlActualPos,
std::string(isdieselinshuntmode ? to_string(mover.AnPos, 2) + STR(" (shunt mode)") : std::to_string(mover.ScndCtrlPos) + "(" + std::to_string(mover.ScndCtrlActualPos) + ")").c_str(),
physics.MainCtrlPos, physics.MainCtrlActualPos,
std::string(isdieselinshuntmode ? to_string(physics.AnPos, 2) + STR(" (shunt mode)") : std::to_string(physics.ScndCtrlPos) + "(" + std::to_string(physics.ScndCtrlActualPos) + ")").c_str(),
// engine
mover.EnginePower, std::abs(mover.TrainType == train_type::emu ? mover.ShowCurrent(0) : mover.Im),
physics.EnginePower, std::abs(physics.TrainType == train_type::emu ? physics.ShowCurrent(0) : physics.Im),
// revolutions
std::abs(mover.enrot) * 60, std::abs(mover.nrot) * mover.Transmision.Ratio * 60, mover.RventRot * 60, std::abs(mover.MotorBlowers[VehicleEnd::front].revolutions),
std::abs(mover.MotorBlowers[VehicleEnd::rear].revolutions), mover.diesel.heat.rpmw, mover.diesel.heat.rpmw2);
std::abs(physics.enrot) * 60, std::abs(physics.nrot) * physics.Transmision.Ratio * 60, physics.RventRot * 60, std::abs(physics.MotorBlowers[VehicleEnd::front].revolutions),
std::abs(physics.MotorBlowers[VehicleEnd::rear].revolutions), physics.diesel.heat.rpmw, physics.diesel.heat.rpmw2);
ImGui::TextUnformatted(buffer.data());
if (isdieselenginepowered)
{
std::snprintf(buffer.data(), buffer.size(), STR_C("\nTemperatures:\n engine: %.2f, oil: %.2f, water: %.2f%c%.2f"), mover.diesel.heat.Ts, mover.diesel.heat.To, mover.diesel.heat.temperatura1,
(mover.WaterCircuitsLink ? '-' : '|'), mover.diesel.heat.temperatura2);
std::snprintf(buffer.data(), buffer.size(), STR_C("\nTemperatures:\n engine: %.2f, oil: %.2f, water: %.2f%c%.2f"), physics.diesel.heat.Ts, physics.diesel.heat.To, physics.diesel.heat.temperatura1,
(physics.WaterCircuitsLink ? '-' : '|'), physics.diesel.heat.temperatura2);
ImGui::TextUnformatted(buffer.data());
}
@@ -190,7 +190,7 @@ void ui::vehicleparams_panel::render_contents()
for (auto const &delay : delays)
{
if ((mover.BrakeDelayFlag & delay.first) == delay.first)
if ((physics.BrakeDelayFlag & delay.first) == delay.first)
{
brakedelay += delay.second;
}
@@ -201,19 +201,19 @@ void ui::vehicleparams_panel::render_contents()
STR_C("Brakes:\n train: %.2f, independent: %.2f, mode: %d, delay: %s, load flag: %d\nBrake cylinder pressures:\n train: %.2f, independent: %.2f, status: 0x%.2x\nPipe pressures:\n "
"brake: %.2f (hat: %.2f), main: %.2f, control: %.2f\nTank pressures:\n auxiliary: %.2f, main: %.2f, control: %.2f"),
// brakes
mover.fBrakeCtrlPos, mover.LocalBrakePosA, mover.BrakeOpModeFlag, brakedelay.c_str(), mover.LoadFlag,
physics.fBrakeCtrlPos, physics.LocalBrakePosA, physics.BrakeOpModeFlag, brakedelay.c_str(), physics.LoadFlag,
// cylinders
mover.BrakePress, mover.LocBrakePress, mover.Hamulec->GetBrakeStatus(),
physics.BrakePress, physics.LocBrakePress, physics.Hamulec->GetBrakeStatus(),
// pipes
mover.PipePress, mover.BrakeCtrlPos2, mover.ScndPipePress, mover.CntrlPipePress,
physics.PipePress, physics.BrakeCtrlPos2, physics.ScndPipePress, physics.CntrlPipePress,
// tanks
mover.Hamulec->GetBRP(), mover.Compressor, mover.Hamulec->GetCRP());
physics.Hamulec->GetBRP(), physics.Compressor, physics.Hamulec->GetCRP());
ImGui::TextUnformatted(buffer.data());
if (mover.EnginePowerSource.SourceType == TPowerSource::CurrentCollector)
if (physics.EnginePowerSource.SourceType == TPowerSource::CurrentCollector)
{
std::snprintf(buffer.data(), buffer.size(), STR_C(" pantograph: %.2f%cMT"), mover.PantPress, (mover.bPantKurek3 ? '-' : '|'));
std::snprintf(buffer.data(), buffer.size(), STR_C(" pantograph: %.2f%cMT"), physics.PantPress, (physics.bPantKurek3 ? '-' : '|'));
ImGui::TextUnformatted(buffer.data());
}
@@ -221,16 +221,16 @@ void ui::vehicleparams_panel::render_contents()
STR_C("Forces:\n tractive: %.1f, brake: %.1f, friction: %.2f%s\nAcceleration:\n tangential: %.2f, normal: %.2f (path radius: %s)\nVelocity: %.2f, distance traveled: %.2f\nPosition: "
"[%.2f, %.2f, %.2f]"),
// forces
mover.Ft * 0.001f *
(mover.CabActive ? mover.CabActive :
physics.Ft * 0.001f *
(physics.CabActive ? physics.CabActive :
vehicle.ctOwner ? vehicle.ctOwner->Controlling()->CabActive :
1) +
0.001f,
mover.Fb * 0.001f, mover.Adhesive(mover.RunningTrack.friction), (mover.SlippingWheels ? " (!)" : ""),
physics.Fb * 0.001f, physics.Adhesive(physics.RunningTrack.friction), (physics.SlippingWheels ? " (!)" : ""),
// acceleration
mover.AccSVBased, mover.AccN + 0.001f, std::string(std::abs(mover.RunningShape.R) > 10000.0 ? "~0" : to_string(mover.RunningShape.R, 0)).c_str(),
physics.AccSVBased, physics.AccN + 0.001f, std::string(std::abs(physics.RunningShape.R) > 10000.0 ? "~0" : to_string(physics.RunningShape.R, 0)).c_str(),
// velocity
vehicle.GetVelocity(), mover.DistCounter,
vehicle.GetVelocity(), physics.DistCounter,
// position
vehicle.GetPosition().x, vehicle.GetPosition().y, vehicle.GetPosition().z);
@@ -249,8 +249,8 @@ void ui::vehicleparams_panel::render_contents()
while (vehicle_iter)
{
TrainsetPowerMeter.first += vehicle_iter->MoverParameters->EnergyMeter.first;
TrainsetPowerMeter.second += vehicle_iter->MoverParameters->EnergyMeter.second;
TrainsetPowerMeter.first += vehicle_iter->physics->EnergyMeter.first;
TrainsetPowerMeter.second += vehicle_iter->physics->EnergyMeter.second;
vehicle_iter = vehicle_iter->Prev();
}
@@ -262,7 +262,7 @@ void ui::vehicleparams_panel::render_contents()
ImGui::TextUnformatted(buffer.data());
}
draw_mini(mover);
draw_mini(physics);
if (ImGui::Button(STR_C("Radiostop")))
m_relay.post(user_command::radiostopsend, 0.0, 0.0, GLFW_PRESS, 0, vehicle_ptr->GetPosition());
@@ -293,7 +293,7 @@ void ui::vehicleparams_panel::render_contents()
if (ImGui::IsItemDeactivated())
m_relay.post(user_command::consistreleaser, 0.0, 0.0, GLFW_RELEASE, 0, glm::vec3(0.0f), &vehicle_ptr->name());
if (vehicle_ptr->MoverParameters->V < 0.01)
if (vehicle_ptr->physics->V < 0.01)
{
if (ImGui::Button(STR_C("Move +500m")))
m_relay.post(user_command::dynamicmove, 500.0, 0.0, GLFW_PRESS, 0, glm::vec3(0.0f), &vehicle_ptr->name());