18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-03 00:45:29 +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
+24 -24
View File
@@ -26,7 +26,7 @@ http://mozilla.org/MPL/2.0/.
#include "utilities/physicslog.h"
#include "utilities/utilities.h"
#include "world/stationnames.h"
#include "physics/mover.h"
#include "physics/vehicle.h"
#include <algorithm>
#include <cctype>
@@ -70,7 +70,7 @@ blackbox::driver driver_of(TDynamicObject const &Vehicle) {
}
// the switches of the user's train: those of its own vehicle, and those of the one with the motors it drives
std::uint32_t devices_of(TMoverParameters const &Occupied, TMoverParameters const &Controlling) {
std::uint32_t devices_of(physics::Vehicle const &Occupied, physics::Vehicle const &Controlling) {
namespace device = blackbox::cab_devices;
auto const on{[](bool const State, std::uint32_t const Bit) { return State ? Bit : 0u; }};
return on(Occupied.Battery || Controlling.Battery, device::battery) | on(Controlling.Mains, device::main_breaker) |
@@ -90,8 +90,8 @@ std::uint32_t devices_of(TMoverParameters const &Occupied, TMoverParameters cons
on(Controlling.diesel.heat.engine_is_hot, device::engine_hot) | on(Controlling.SpeedCtrl && Controlling.SpeedCtrlUnit.IsActive, device::speed_control);
}
std::uint8_t engine_of(TMoverParameters const &Mover) {
switch (Mover.EngineType) {
std::uint8_t engine_of(physics::Vehicle const &Physics) {
switch (Physics.EngineType) {
case TEngineType::ElectricSeriesMotor:
return blackbox::engines::electric;
case TEngineType::ElectricInductionMotor:
@@ -109,10 +109,10 @@ std::uint8_t engine_of(TMoverParameters const &Mover) {
// the lights at an end of the train: of its head or of its tail, at the end of that vehicle turned away from the rest
std::uint16_t outward_lights(TDynamicObject const *Vehicle, bool const Head) {
if (Vehicle == nullptr || Vehicle->MoverParameters == nullptr)
if (Vehicle == nullptr || Vehicle->physics == nullptr)
return 0;
auto const along{Vehicle->iDirection > 0};
return static_cast<std::uint16_t>(Vehicle->MoverParameters->iLights[Head == along ? VehicleEnd::front : VehicleEnd::rear]);
return static_cast<std::uint16_t>(Vehicle->physics->iLights[Head == along ? VehicleEnd::front : VehicleEnd::rear]);
}
// the lamps the vehicle has at that end: the driver checks a pattern against those of it there are
@@ -206,9 +206,9 @@ bool coupled(TDynamicObject const *From, TDynamicObject const *To) {
auto side{start};
// going on away from the first vehicle: through the coupler opposite the one each was reached by
for (int step = 0; step < 1000 && vehicle != nullptr; ++step) {
auto const *mover{vehicle->MoverParameters};
auto const &neighbour{mover->Neighbours[side]};
if (mover->Couplers[side].CouplingFlag.Empty() || neighbour.vehicle == nullptr)
auto const *physics{vehicle->physics};
auto const &neighbour{physics->Neighbours[side]};
if (physics->Couplers[side].CouplingFlag.Empty() || neighbour.vehicle == nullptr)
break;
if (neighbour.vehicle == To)
return true;
@@ -225,7 +225,7 @@ blackbox::vehicle_state state_of(TDynamicObject const &Vehicle, std::uint32_t co
state.position = glm::vec3{Vehicle.GetPosition()};
auto const front{Vehicle.VectorFront()};
state.heading = static_cast<float>(std::atan2(front.x, front.z));
state.speed_kmh = static_cast<float>(Vehicle.MoverParameters->V * 3.6);
state.speed_kmh = static_cast<float>(Vehicle.physics->V * 3.6);
state.driving = driver_of(Vehicle);
return state;
}
@@ -415,7 +415,7 @@ void blackbox_recorder::write_cab() {
if (train == nullptr || train->Dynamic() == nullptr)
return;
auto const *vehicle{train->Dynamic()};
auto const *occupied{vehicle->MoverParameters};
auto const *occupied{vehicle->physics};
// the one which drives the consist, as the driving aid tells it
auto const *owner{vehicle->ctOwner != nullptr ? vehicle->ctOwner : vehicle->Mechanik};
auto const *controlling{owner != nullptr ? owner->Controlling() : occupied};
@@ -431,7 +431,7 @@ void blackbox_recorder::write_cab() {
// the vehicle itself, if none in the unit is powered
auto const *powered{train->Dynamic()->FindPowered()};
auto const facing{powered->DirectionGet() * vehicle->DirectionGet()};
sample.wheel_speed_kmh = static_cast<float>(facing * M_PI * powered->MoverParameters->WheelDiameter * powered->MoverParameters->nrot * 3.6);
sample.wheel_speed_kmh = static_cast<float>(facing * M_PI * powered->physics->WheelDiameter * powered->physics->nrot * 3.6);
sample.acceleration = static_cast<float>(controlling->AccS);
sample.lateral_acceleration = static_cast<float>(occupied->AccN);
if (owner != nullptr && owner->is_train()) {
@@ -494,8 +494,8 @@ void blackbox_recorder::write_cab() {
// the brakes of the whole train: the highest of its cylinders, from the head to the tail
auto brakes{occupied->BrakePress};
for (auto const *each{owner != nullptr ? owner->Vehicle(VehicleEnd::front) : nullptr}; each != nullptr; each = each->Next())
if (each->MoverParameters != nullptr)
brakes = std::max(brakes, each->MoverParameters->BrakePress);
if (each->physics != nullptr)
brakes = std::max(brakes, each->physics->BrakePress);
sample.consist_brake_cylinder = static_cast<float>(brakes);
m_writer->cab(sample);
}
@@ -528,7 +528,7 @@ void blackbox_recorder::look_around(bool const Keyframe) {
auto *train{simulation::Train};
auto const uservehicle{train != nullptr && train->Dynamic() != nullptr ? vehicle_id(train->Dynamic()) : blackbox::no_vehicle};
auto const userincab{uservehicle != blackbox::no_vehicle && false == FreeFlyModeFlag};
auto const usercab{uservehicle != blackbox::no_vehicle ? static_cast<std::int8_t>(train->Dynamic()->MoverParameters->CabOccupied) : std::int8_t{0}};
auto const usercab{uservehicle != blackbox::no_vehicle ? static_cast<std::int8_t>(train->Dynamic()->physics->CabOccupied) : std::int8_t{0}};
if (false == m_userknown || uservehicle != m_uservehicle || userincab != m_userincab || usercab != m_usercab) {
m_writer->user_vehicle(m_time, uservehicle, userincab, usercab);
m_uservehicle = uservehicle;
@@ -582,7 +582,7 @@ void blackbox_recorder::look_at_derailments() {
for (auto *vehicle : simulation::Vehicles.sequence()) {
if (false == vehicle->bEnabled)
continue;
auto const &motion{vehicle->MoverParameters->OffTrack};
auto const &motion{vehicle->physics->OffTrack};
auto const id{vehicle_id(vehicle)};
auto &entry{m_vehicles[vehicle]};
if (false == motion.active()) {
@@ -598,7 +598,7 @@ void blackbox_recorder::look_at_derailments() {
state.cause = cause_of(motion.reason());
state.position = vehicle->GetPosition();
state.heading = static_cast<float>(std::atan2(vehicle->VectorFront().x, vehicle->VectorFront().z));
state.speed_kmh = static_cast<float>(vehicle->MoverParameters->V * 3.6);
state.speed_kmh = static_cast<float>(vehicle->physics->V * 3.6);
state.offset = static_cast<float>(vehicle->off_track_offset());
state.roll = static_cast<float>(motion.roll());
state.travelled = static_cast<float>(motion.travelled());
@@ -617,12 +617,12 @@ void blackbox_recorder::look_at_couplers() {
if (false == vehicle->bEnabled)
continue;
auto &entry{m_vehicles[vehicle]};
auto const *mover{vehicle->MoverParameters};
auto const *physics{vehicle->physics};
for (int side = 0; side < 2; ++side) {
auto const flags{mover->Couplers[side].CouplingFlag};
auto const flags{physics->Couplers[side].CouplingFlag};
// a neighbour not coupled is only seen on the same track
auto const *other{false == flags.Empty() ? mover->Neighbours[side].vehicle : nullptr};
coupler_entry const now{other, other != nullptr ? mover->Neighbours[side].vehicle_end : 0, other != nullptr ? flags.Bits() : 0};
auto const *other{false == flags.Empty() ? physics->Neighbours[side].vehicle : nullptr};
coupler_entry const now{other, other != nullptr ? physics->Neighbours[side].vehicle_end : 0, other != nullptr ? flags.Bits() : 0};
auto &last{entry.couplers[side]};
auto const changed{now.other != last.other || now.other_side != last.other_side || now.flags != last.flags};
auto const before{last};
@@ -764,11 +764,11 @@ std::uint32_t blackbox_recorder::vehicle_id(TDynamicObject const *Vehicle) {
auto &entry{m_vehicles[Vehicle]};
entry.id = m_nextvehicle++;
auto const *mover{Vehicle->MoverParameters};
auto const *physics{Vehicle->physics};
auto const *driver{Vehicle->Mechanik};
auto const train{driver != nullptr && driver->TrainName() != "none" ? driver->TrainName() : std::string{}};
m_writer->vehicle({entry.id, text_of(Vehicle->name()), text_of(mover->TypeName), text_of(train), static_cast<float>(mover->Dim.L), static_cast<float>(mover->Dim.W),
static_cast<std::uint8_t>(mover->CategoryFlag)});
m_writer->vehicle({entry.id, text_of(Vehicle->name()), text_of(physics->TypeName), text_of(train), static_cast<float>(physics->Dim.L), static_cast<float>(physics->Dim.W),
static_cast<std::uint8_t>(physics->CategoryFlag)});
return entry.id;
}