18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-02 18:56:49 +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
@@ -244,13 +244,13 @@ TEST_CASE("commands: every command run on every real vehicle") {
auto channels{state()};
channels.emplace_back("Done", [&done](auto const &) { return flag(done); });
test::trace trace{"commands/" + path, channels, 1, false};
trace.sample(0.0, real.mover());
trace.sample(0.0, real.physics());
for (std::size_t i = 0; i < commands.size(); ++i) {
auto const &command{commands[i]};
trace.mark(std::format("{} {} {}", command.name, command.value1, command.value2));
auto const parsed{ParseVehicleCommand(command.name)};
done = real->RunCommand(parsed.command, command.value1, command.value2, Coupling::control, parsed.argument);
trace.sample(static_cast<double>(i + 1), real.mover());
trace.sample(static_cast<double>(i + 1), real.physics());
}
trace.check();
}
@@ -261,7 +261,7 @@ namespace {
// a switch of the cab, worked on the driven vehicle
struct action {
std::string name;
std::function<bool(TMoverParameters &)> work;
std::function<bool(physics::Vehicle &)> work;
};
// every switch sending its state to the rest of the train, each way and to each range, in the order a crew
@@ -378,19 +378,19 @@ TEST_CASE("commands: every switch of the cab, sent to the next vehicle") {
test::reseed_random();
vehicle driven{definition::fiz(path), 0.0, "driven", 1};
vehicle next{definition::fiz(path), 0.0, "next"};
driven->Attach(VehicleEnd::rear, VehicleEnd::front, &next.mover(), test::consist::full_coupling, true, false);
driven->Attach(VehicleEnd::rear, VehicleEnd::front, &next.physics(), test::consist::full_coupling, true, false);
auto done{false};
auto channels{state()};
for (auto const &channel : state()) {
channels.emplace_back("next." + channel.name, [&next, value = channel.value](auto const &) { return value(next.mover()); });
channels.emplace_back("next." + channel.name, [&next, value = channel.value](auto const &) { return value(next.physics()); });
}
channels.emplace_back("Done", [&done](auto const &) { return flag(done); });
test::trace trace{"switches/" + path, channels, 1, false};
trace.sample(0.0, driven.mover());
trace.sample(0.0, driven.physics());
for (std::size_t i = 0; i < actions.size(); ++i) {
trace.mark(actions[i].name);
done = actions[i].work(driven.mover());
trace.sample(static_cast<double>(i + 1), driven.mover());
done = actions[i].work(driven.physics());
trace.sample(static_cast<double>(i + 1), driven.physics());
}
trace.check();
}
@@ -422,17 +422,17 @@ TEST_CASE("commands: every switch of the cab, worked on a pair standing under th
});
auto const own{channels.size()};
for (std::size_t i = 0; i < own; ++i) {
channels.emplace_back("next." + channels[i].name, [&pair, value = channels[i].value](auto const &) { return value(pair[1].mover()); });
channels.emplace_back("next." + channels[i].name, [&pair, value = channels[i].value](auto const &) { return value(pair[1].physics()); });
}
channels.emplace_back("Done", [&done](auto const &) { return flag(done); });
test::trace trace{"switches_live/" + path, channels, 1, false};
trace.sample(0.0, pair[0].mover());
trace.sample(0.0, pair[0].physics());
test::track const catenary{.voltage = test::catenary_3kv};
for (std::size_t i = 0; i < actions.size(); ++i) {
trace.mark(actions[i].name);
done = actions[i].work(pair[0].mover());
done = actions[i].work(pair[0].physics());
pair.run(2.0, catenary);
trace.sample(static_cast<double>(i + 1), pair[0].mover());
trace.sample(static_cast<double>(i + 1), pair[0].physics());
}
trace.check();
}
@@ -449,8 +449,8 @@ struct train {
vehicle last{definition::fiz("4e_v1/4e"), 0.0, "last"};
explicit train(CouplingSet const couplings) {
head->Attach(VehicleEnd::rear, VehicleEnd::rear, &middle.mover(), couplings, true, false);
middle->Attach(VehicleEnd::front, VehicleEnd::front, &last.mover(), couplings, true, false);
head->Attach(VehicleEnd::rear, VehicleEnd::rear, &middle.physics(), couplings, true, false);
middle->Attach(VehicleEnd::front, VehicleEnd::front, &last.physics(), couplings, true, false);
}
};