mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-01 07:07:05 +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:
@@ -72,8 +72,8 @@ struct elf {
|
||||
cab().UniversalBrakeButton(0, 0);
|
||||
wait(30.0);
|
||||
}
|
||||
TMoverParameters &cab() { return unit[0].mover(); }
|
||||
TMoverParameters &car(std::size_t Index) { return unit[Index].mover(); }
|
||||
physics::Vehicle &cab() { return unit[0].physics(); }
|
||||
physics::Vehicle &car(std::size_t Index) { return unit[Index].physics(); }
|
||||
// the driver moves the controller notch by notch, which the cab sends on to the coupled vehicles
|
||||
void set_controller(int Position) {
|
||||
while (cab().MainCtrlPos < Position && cab().IncMainCtrl(1)) {
|
||||
@@ -94,62 +94,62 @@ TEST_CASE("elf controller: without EIMCtrlMainEmergency the positions stay as th
|
||||
elf unit{false};
|
||||
REQUIRE(unit.ready);
|
||||
REQUIRE(unit.charged);
|
||||
auto &mover{unit.cab()};
|
||||
CHECK_FALSE(mover.EIMCtrlMainEmergency);
|
||||
CHECK(mover.EIMCtrlEmergencyPositions() == 0);
|
||||
CHECK(mover.MainCtrlPosNo == 4);
|
||||
CHECK(mover.MainCtrlNoPowerPos() == 3);
|
||||
CHECK(mover.MainCtrlPos == 3);
|
||||
auto &physics{unit.cab()};
|
||||
CHECK_FALSE(physics.EIMCtrlMainEmergency);
|
||||
CHECK(physics.EIMCtrlEmergencyPositions() == 0);
|
||||
CHECK(physics.MainCtrlPosNo == 4);
|
||||
CHECK(physics.MainCtrlNoPowerPos() == 3);
|
||||
CHECK(physics.MainCtrlPos == 3);
|
||||
// the lowest position brakes fully, without emptying the pipe
|
||||
mover.MainCtrlPos = 0;
|
||||
CHECK_FALSE(mover.IsMainCtrlEmergencyPos());
|
||||
physics.MainCtrlPos = 0;
|
||||
CHECK_FALSE(physics.IsMainCtrlEmergencyPos());
|
||||
unit.wait(10.0);
|
||||
CHECK(mover.eimic == doctest::Approx(-1.0));
|
||||
CHECK(mover.PipePress > 4.5);
|
||||
CHECK(physics.eimic == doctest::Approx(-1.0));
|
||||
CHECK(physics.PipePress > 4.5);
|
||||
}
|
||||
|
||||
TEST_CASE("elf controller: EIMCtrlMainEmergency shifts the positions up by the emergency brake one") {
|
||||
elf unit{true};
|
||||
REQUIRE(unit.ready);
|
||||
REQUIRE(unit.charged);
|
||||
auto &mover{unit.cab()};
|
||||
CHECK(mover.EIMCtrlMainEmergency);
|
||||
CHECK(mover.EIMCtrlEmergencyPositions() == 1);
|
||||
CHECK(mover.MainCtrlPosNo == 5);
|
||||
CHECK(mover.MainCtrlNoPowerPos() == 4);
|
||||
CHECK(mover.MainCtrlPos == 4);
|
||||
CHECK_FALSE(mover.IsMainCtrlEmergencyPos());
|
||||
auto &physics{unit.cab()};
|
||||
CHECK(physics.EIMCtrlMainEmergency);
|
||||
CHECK(physics.EIMCtrlEmergencyPositions() == 1);
|
||||
CHECK(physics.MainCtrlPosNo == 5);
|
||||
CHECK(physics.MainCtrlNoPowerPos() == 4);
|
||||
CHECK(physics.MainCtrlPos == 4);
|
||||
CHECK_FALSE(physics.IsMainCtrlEmergencyPos());
|
||||
SUBCASE("the neutral position neither drives nor brakes") {
|
||||
unit.wait(5.0);
|
||||
CHECK(mover.eimic == doctest::Approx(0.0));
|
||||
CHECK(physics.eimic == doctest::Approx(0.0));
|
||||
}
|
||||
SUBCASE("the full braking position, formerly 0, brakes fully without emptying the pipe") {
|
||||
mover.MainCtrlPos = 1;
|
||||
physics.MainCtrlPos = 1;
|
||||
unit.wait(10.0);
|
||||
CHECK(mover.eimic == doctest::Approx(-1.0));
|
||||
CHECK(mover.PipePress > 4.5);
|
||||
CHECK(physics.eimic == doctest::Approx(-1.0));
|
||||
CHECK(physics.PipePress > 4.5);
|
||||
}
|
||||
SUBCASE("the braking position, formerly 1, ramps the braking up") {
|
||||
mover.MainCtrlPos = 2;
|
||||
physics.MainCtrlPos = 2;
|
||||
unit.wait(1.0);
|
||||
CHECK(mover.eimic < 0.0);
|
||||
CHECK(mover.eimic > -1.0);
|
||||
CHECK(mover.PipePress > 4.5);
|
||||
CHECK(physics.eimic < 0.0);
|
||||
CHECK(physics.eimic > -1.0);
|
||||
CHECK(physics.PipePress > 4.5);
|
||||
}
|
||||
SUBCASE("the emergency brake position brakes fully at once and empties the pipe") {
|
||||
mover.MainCtrlPos = 0;
|
||||
CHECK(mover.IsMainCtrlEmergencyPos());
|
||||
physics.MainCtrlPos = 0;
|
||||
CHECK(physics.IsMainCtrlEmergencyPos());
|
||||
// a single step of the physics
|
||||
unit.unit.step(unit.line);
|
||||
CHECK(mover.eimic == doctest::Approx(-1.0));
|
||||
CHECK(physics.eimic == doctest::Approx(-1.0));
|
||||
unit.wait(10.0);
|
||||
CHECK(mover.PipePress < 0.5);
|
||||
CHECK(mover.BrakePress > 1.0);
|
||||
CHECK(physics.PipePress < 0.5);
|
||||
CHECK(physics.BrakePress > 1.0);
|
||||
// out of it the pipe charges again
|
||||
mover.MainCtrlPos = mover.MainCtrlNoPowerPos();
|
||||
CHECK_FALSE(mover.IsMainCtrlEmergencyPos());
|
||||
physics.MainCtrlPos = physics.MainCtrlNoPowerPos();
|
||||
CHECK_FALSE(physics.IsMainCtrlEmergencyPos());
|
||||
unit.recharge();
|
||||
CHECK(mover.PipePress > 4.5);
|
||||
CHECK(physics.PipePress > 4.5);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,18 +171,18 @@ TEST_CASE("elf controller: the reverser works at the neutral shifted by EIMCtrlM
|
||||
// the key added to the old files, DirChangeMaxPos=3 in them
|
||||
elf unit{{data::emergency_old_layout}};
|
||||
REQUIRE(unit.ready);
|
||||
auto &mover{unit.cab()};
|
||||
REQUIRE(mover.MainCtrlPos == mover.MainCtrlNoPowerPos());
|
||||
REQUIRE(mover.DirActive == 1);
|
||||
CHECK(mover.DirectionBackward());
|
||||
CHECK(mover.DirActive == 0);
|
||||
CHECK(mover.DirectionForward());
|
||||
CHECK(mover.DirActive == 1);
|
||||
auto &physics{unit.cab()};
|
||||
REQUIRE(physics.MainCtrlPos == physics.MainCtrlNoPowerPos());
|
||||
REQUIRE(physics.DirActive == 1);
|
||||
CHECK(physics.DirectionBackward());
|
||||
CHECK(physics.DirActive == 0);
|
||||
CHECK(physics.DirectionForward());
|
||||
CHECK(physics.DirActive == 1);
|
||||
// not in the power position
|
||||
unit.set_controller(mover.MainCtrlNoPowerPos() + 1);
|
||||
REQUIRE(mover.MainCtrlPos == 5);
|
||||
CHECK_FALSE(mover.DirectionBackward());
|
||||
CHECK(mover.DirActive == 1);
|
||||
unit.set_controller(physics.MainCtrlNoPowerPos() + 1);
|
||||
REQUIRE(physics.MainCtrlPos == 5);
|
||||
CHECK_FALSE(physics.DirectionBackward());
|
||||
CHECK(physics.DirActive == 1);
|
||||
}
|
||||
|
||||
TEST_CASE("elf controller: the emergency brake position vents the pipe only from the vehicle driven from") {
|
||||
@@ -264,7 +264,7 @@ TEST_CASE("elf controller: EIMCtrlMainEmergency leaves the other controllers alo
|
||||
// the holding brake of the Elf (SBD) lets go only once power has been demanded for SBDReleaseDelay (eu07/maszyna#556):
|
||||
// the release waits the initial delay of the controller (IniCDelay) instead of going at the first percent of the
|
||||
// demand. TDynamicObject::Update() works the holding brake out, its MED isn't in the tests, so they do here what it
|
||||
// does with it: TMoverParameters::UpdateStopBrakeRelease() of the cab with its demand after every step and, where the
|
||||
// does with it: physics::Vehicle::UpdateStopBrakeRelease() of the cab with its demand after every step and, where the
|
||||
// brake matters, the brake's share of every car on its cylinders (LocalBrakePosAEIM)
|
||||
|
||||
namespace {
|
||||
|
||||
Reference in New Issue
Block a user