18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-02 10:46:45 +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
+14 -14
View File
@@ -16,7 +16,7 @@ http://mozilla.org/MPL/2.0/.
#include "vehicle/Camera.h"
#include "vehicle/Driver.h"
#include "vehicle/DynObj.h"
#include "physics/mover.h"
#include "physics/vehicle.h"
namespace {
@@ -29,16 +29,16 @@ cameraviews::vehicle_pose pose_of(TDynamicObject const *Vehicle) {
cameraviews::vehicle_pose pose;
pose.position = Vehicle->GetPosition();
pose.front = Vehicle->VectorFront();
pose.length = Vehicle->MoverParameters->Dim.L;
pose.width = Vehicle->MoverParameters->Dim.W;
pose.height = Vehicle->MoverParameters->Dim.H;
pose.length = Vehicle->physics->Dim.L;
pose.width = Vehicle->physics->Dim.W;
pose.height = Vehicle->physics->Dim.H;
return pose;
}
// the end of the Vehicle the Other vehicle is beyond, -1 when it's beyond neither
int end_towards(TDynamicObject const *Vehicle, TDynamicObject const *Other) {
for (auto const side : VehicleEnds) {
if (Vehicle->MoverParameters->Neighbours[side].vehicle == Other) {
if (Vehicle->physics->Neighbours[side].vehicle == Other) {
return NumberOf(side);
}
}
@@ -58,14 +58,14 @@ cameraviews::coupler coupler_of(TDynamicObject const *Vehicle, VehicleEnd const
cameraviews::coupler coupler;
coupler.position = Vehicle->CouplerPosition(End);
coupler.outward = Vehicle->VectorFront() * (End == VehicleEnd::front ? 1.0 : -1.0);
coupler.width = Vehicle->MoverParameters->Dim.W;
coupler.width = Vehicle->physics->Dim.W;
return coupler;
}
// the driver's way: the front (1) or the rear (-1) of the Driven vehicle, as the user drives it
int driven_way(TDynamicObject const *Driven) {
auto const cab{Driven->MoverParameters->CabOccupied < 0 ? -1 : 1};
auto const direction{Driven->MoverParameters->DirActive < 0 ? -1 : 1};
auto const cab{Driven->physics->CabOccupied < 0 ? -1 : 1};
auto const direction{Driven->physics->DirActive < 0 ? -1 : 1};
return cab * direction;
}
@@ -143,8 +143,8 @@ TDynamicObject *consist_views::pick(std::vector<TDynamicObject *> const &Train,
}
double consist_views::gap_beyond(TDynamicObject const *Vehicle, VehicleEnd const End) {
auto const &neighbour{Vehicle->MoverParameters->Neighbours[End]};
if (neighbour.vehicle == nullptr || false == Vehicle->MoverParameters->Couplers[End].CouplingFlag.Empty()) {
auto const &neighbour{Vehicle->physics->Neighbours[End]};
if (neighbour.vehicle == nullptr || false == Vehicle->physics->Couplers[End].CouplingFlag.Empty()) {
return -1.0;
}
if (neighbour.distance > cameraviews::coupler_watch_range) {
@@ -175,7 +175,7 @@ consist_views::coupling_place consist_views::coupling_at(std::vector<TDynamicObj
auto const outer{outer_end(vehicle, inner, NumberOf(front ? VehicleEnd::front : VehicleEnd::rear))};
place.vehicle = vehicle;
place.coupler = coupler_of(vehicle, EndOf(outer));
auto const &neighbour{vehicle->MoverParameters->Neighbours[outer]};
auto const &neighbour{vehicle->physics->Neighbours[outer]};
place.gap = gap_beyond(vehicle, EndOf(outer));
if (place.gap >= 0.0 && (neighbour.FacingEnd() == VehicleEnd::front || neighbour.FacingEnd() == VehicleEnd::rear)) {
place.other = true;
@@ -208,7 +208,7 @@ cameraviews::train_motion consist_views::motion_of(std::vector<TDynamicObject *>
motion.head = end_along(Train[head], m_direction);
motion.tail = end_along(Train[tail], -m_direction);
motion.speed = std::abs(m_vehicle->GetVelocity()) / 3.6;
motion.width = m_vehicle->MoverParameters->Dim.W;
motion.width = m_vehicle->physics->Dim.W;
if (Train.size() > 1) {
auto const *behind{Train[head == 0 ? 1 : head - 1]};
motion.curvature = cameraviews::line_curvature(Train[head]->GetPosition(), facing_along(Train[head], m_direction), behind->GetPosition(), facing_along(behind, m_direction));
@@ -232,10 +232,10 @@ cameraviews::placement consist_views::place_shunting(TCamera const &Camera, std:
auto const pose{pose_of(m_vehicle)};
auto length{0.0};
for (auto const *vehicle : Train) {
length += vehicle->MoverParameters->Dim.L;
length += vehicle->physics->Dim.L;
}
m_topdown = cameraviews::topdown_moved(m_topdown, Camera.Velocity, Seconds, pose, 0.5 * length + 50.0);
auto const facing{cameraviews::driving_facing(m_vehicle->VectorFront(), Driven->VectorFront(), Driven->MoverParameters->CabOccupied)};
auto const facing{cameraviews::driving_facing(m_vehicle->VectorFront(), Driven->VectorFront(), Driven->physics->CabOccupied)};
return cameraviews::topdown_placement(m_topdown, pose, facing);
}