mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-02 07:22:42 +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:
@@ -4,7 +4,7 @@
|
||||
#include "drive.h"
|
||||
#include "vehicle.h"
|
||||
#include "physics/collision.h"
|
||||
#include "physics/mover.h"
|
||||
#include "physics/vehicle.h"
|
||||
#include "utilities/Globals.h"
|
||||
|
||||
#include <cmath>
|
||||
@@ -111,11 +111,11 @@ cl::crush_curve const locomotive_curve{cl::default_crush(cl::vehicle_kind::locom
|
||||
|
||||
// ---- trains of real vehicles
|
||||
|
||||
bool derailed(TMoverParameters const &Vehicle) {
|
||||
bool derailed(physics::Vehicle const &Vehicle) {
|
||||
return Vehicle.DamageFlag.HasAll(VehicleDamage::derailed);
|
||||
}
|
||||
|
||||
double crush_of(TMoverParameters const &Vehicle) {
|
||||
double crush_of(physics::Vehicle const &Vehicle) {
|
||||
return std::max(Vehicle.Couplers[VehicleEnd::front].crush, Vehicle.Couplers[VehicleEnd::rear].crush);
|
||||
}
|
||||
|
||||
@@ -170,7 +170,7 @@ crash_outcome freight_crash(double const Speed, double const Radius, double cons
|
||||
|
||||
crash_outcome result;
|
||||
for (std::size_t i = 0; i < train.size(); ++i) {
|
||||
auto const &vehicle{train[i].mover()};
|
||||
auto const &vehicle{train[i].physics()};
|
||||
auto const name{i < standing ? std::format("standing {}", standing - 1 - i) : i == standing ? std::string{"locomotive"} : std::format("running {}", i - standing - 1)};
|
||||
for (auto const end : VehicleEnds) {
|
||||
if (vehicle.Couplers[end].crush >= cl::crush_mark) {
|
||||
@@ -208,17 +208,17 @@ double locomotive_into_wagon(double const Speed, double const Dt) {
|
||||
}
|
||||
|
||||
// the energy the crush of both ends of the pair took, by their curves [J]
|
||||
double crush_energy(TMoverParameters const &First, VehicleEnd const FirstEnd, TMoverParameters const &Second, VehicleEnd const SecondEnd) {
|
||||
double crush_energy(physics::Vehicle const &First, VehicleEnd const FirstEnd, physics::Vehicle const &Second, VehicleEnd const SecondEnd) {
|
||||
return First.crush_curve_at(FirstEnd).energy(0.0, First.Couplers[FirstEnd].crush) + Second.crush_curve_at(SecondEnd).energy(0.0, Second.Couplers[SecondEnd].crush);
|
||||
}
|
||||
|
||||
// what the buffers of EN 15551 of the two ends take in [J]
|
||||
double capacity_of(TMoverParameters const &First, VehicleEnd const FirstEnd, TMoverParameters const &Second, VehicleEnd const SecondEnd) {
|
||||
double capacity_of(physics::Vehicle const &First, VehicleEnd const FirstEnd, physics::Vehicle const &Second, VehicleEnd const SecondEnd) {
|
||||
return cl::buffer_capacity(First.Couplers[FirstEnd].collision, First.collision_kind()) + cl::buffer_capacity(Second.Couplers[SecondEnd].collision, Second.collision_kind());
|
||||
}
|
||||
|
||||
// the kinetic energy of the relative motion of two vehicles closing in at the velocity [J]
|
||||
double relative_energy(TMoverParameters const &First, TMoverParameters const &Second, double const Velocity) {
|
||||
double relative_energy(physics::Vehicle const &First, physics::Vehicle const &Second, double const Velocity) {
|
||||
auto const mass{First.TotalMass * Second.TotalMass / (First.TotalMass + Second.TotalMass)};
|
||||
return 0.5 * mass * Velocity * Velocity;
|
||||
}
|
||||
@@ -239,9 +239,9 @@ contact_outcome contact(definition const &Front, definition const &Back, double
|
||||
train.run(Seconds, {}, Dt);
|
||||
contact_outcome result;
|
||||
result.crush = front->Couplers[VehicleEnd::rear].crush + back->Couplers[VehicleEnd::front].crush;
|
||||
result.energy = crush_energy(front.mover(), VehicleEnd::rear, back.mover(), VehicleEnd::front);
|
||||
result.available = std::max(0.0, relative_energy(front.mover(), back.mover(), Speed * kmh) - capacity_of(front.mover(), VehicleEnd::rear, back.mover(), VehicleEnd::front));
|
||||
result.derailed = derailed(front.mover()) || derailed(back.mover());
|
||||
result.energy = crush_energy(front.physics(), VehicleEnd::rear, back.physics(), VehicleEnd::front);
|
||||
result.available = std::max(0.0, relative_energy(front.physics(), back.physics(), Speed * kmh) - capacity_of(front.physics(), VehicleEnd::rear, back.physics(), VehicleEnd::front));
|
||||
result.derailed = derailed(front.physics()) || derailed(back.physics());
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -251,7 +251,7 @@ definition coach(double const Mass) {
|
||||
}
|
||||
|
||||
// Y / Q of the leading wheel of the vehicle at the end pressed in by its coupling, as check_pushed_off() takes it
|
||||
double pushed_ratio_of(TMoverParameters const &Vehicle, VehicleEnd const End, double const OtherLength, double const Radius) {
|
||||
double pushed_ratio_of(physics::Vehicle const &Vehicle, VehicleEnd const End, double const OtherLength, double const Radius) {
|
||||
cl::pushed_vehicle pushed;
|
||||
pushed.mass = Vehicle.TotalMass - Vehicle.Mred;
|
||||
pushed.axles = Vehicle.NAxles > 0 ? Vehicle.NAxles : 4;
|
||||
@@ -580,9 +580,9 @@ TEST_CASE("collisions: a locomotive at its starting effort against a braked trai
|
||||
}
|
||||
train.run(30.0, line);
|
||||
auto &locomotive{train.add(definition::fiz("st44_v2/m62-1151"), 1, Coupling::none, 0.0, 0.0)};
|
||||
test::driven const driver{locomotive.mover(), locomotive.mover(), locomotive.mover(), [&train](double const Seconds, test::track const &Track) { train.run(Seconds, Track); }};
|
||||
test::driven const driver{locomotive.physics(), locomotive.physics(), locomotive.physics(), [&train](double const Seconds, test::track const &Track) { train.run(Seconds, Track); }};
|
||||
REQUIRE(test::start_up(driver, line));
|
||||
test::release_brakes(locomotive.mover());
|
||||
test::release_brakes(locomotive.physics());
|
||||
for (int i = 0; i < 3 && locomotive->DirActive <= 0; ++i) {
|
||||
locomotive->DirectionForward();
|
||||
}
|
||||
@@ -592,7 +592,7 @@ TEST_CASE("collisions: a locomotive at its starting effort against a braked trai
|
||||
auto worst{0.0};
|
||||
auto const watch = [&]() {
|
||||
pushed = std::max(pushed, -locomotive->Couplers[VehicleEnd::front].CForce);
|
||||
worst = std::max(worst, pushed_ratio_of(empty.mover(), VehicleEnd::rear, locomotive->Dim.L, line.radius));
|
||||
worst = std::max(worst, pushed_ratio_of(empty.physics(), VehicleEnd::rear, locomotive->Dim.L, line.radius));
|
||||
};
|
||||
// the line contactors close at the first position, once their delay and the pressure switch let them
|
||||
locomotive->IncMainCtrl(1);
|
||||
@@ -612,7 +612,7 @@ TEST_CASE("collisions: a locomotive at its starting effort against a braked trai
|
||||
MESSAGE(std::format("ST44 pushing at up to {:.0f} kN, the empty 3WL at Y/Q {:.2f}, rolled {:.3f} m", pushed / 1000.0, worst, rolled));
|
||||
REQUIRE(worst >= derailment::climbing_limit);
|
||||
CHECK(rolled < 0.5);
|
||||
CHECK_FALSE(derailed(empty.mover()));
|
||||
CHECK_FALSE(derailed(empty.physics()));
|
||||
CHECK(empty->CollisionDerail == NONE);
|
||||
}
|
||||
|
||||
@@ -632,7 +632,7 @@ TEST_CASE("collisions: a locomotive running onto an empty wagon at 9 km/h doesn'
|
||||
for (int step = 0; step < 500; ++step) {
|
||||
train.step(curve);
|
||||
pushed = std::max(pushed, empty->Couplers[VehicleEnd::rear].CForce);
|
||||
auto const ratio{pushed_ratio_of(empty.mover(), VehicleEnd::rear, locomotive->Dim.L, curve.radius)};
|
||||
auto const ratio{pushed_ratio_of(empty.physics(), VehicleEnd::rear, locomotive->Dim.L, curve.radius)};
|
||||
worst = std::max(worst, ratio);
|
||||
over += ratio >= derailment::climbing_limit;
|
||||
}
|
||||
@@ -640,8 +640,8 @@ TEST_CASE("collisions: a locomotive running onto an empty wagon at 9 km/h doesn'
|
||||
empty.speed()));
|
||||
REQUIRE(worst >= derailment::climbing_limit);
|
||||
REQUIRE(over >= 5);
|
||||
CHECK_FALSE(derailed(empty.mover()));
|
||||
CHECK_FALSE(derailed(locomotive.mover()));
|
||||
CHECK_FALSE(derailed(empty.physics()));
|
||||
CHECK_FALSE(derailed(locomotive.physics()));
|
||||
}
|
||||
|
||||
TEST_CASE("collisions: a train propelling an empty wagon into a braked one in a curve pushes it off as it rolls on") {
|
||||
@@ -668,7 +668,7 @@ TEST_CASE("collisions: a train propelling an empty wagon into a braked one in a
|
||||
}
|
||||
auto const start{empty->DistCounter};
|
||||
train.run(10.0, curve);
|
||||
MESSAGE(std::format("the empty 3WL: derailed {}, {}, rolled {:.2f} m", derailed(empty.mover()), empty->CollisionDerail == COLLISION_PUSHED_OFF ? "pushed off" : "not pushed off",
|
||||
MESSAGE(std::format("the empty 3WL: derailed {}, {}, rolled {:.2f} m", derailed(empty.physics()), empty->CollisionDerail == COLLISION_PUSHED_OFF ? "pushed off" : "not pushed off",
|
||||
(empty->DistCounter - start) * 1000.0));
|
||||
CHECK(empty->CollisionDerail == COLLISION_PUSHED_OFF);
|
||||
}
|
||||
@@ -685,16 +685,16 @@ TEST_CASE("collisions: a repaired vehicle has its ends rebuilt and is back on th
|
||||
auto &locomotive{train.add(definition::fiz("4e_v1/4e"), 0, Coupling::none, 30.0, 0.5)};
|
||||
train.run(3.0);
|
||||
REQUIRE(wagon->Couplers[VehicleEnd::rear].crush + locomotive->Couplers[VehicleEnd::front].crush > cl::override_crush);
|
||||
REQUIRE((derailed(wagon.mover()) || derailed(locomotive.mover())));
|
||||
REQUIRE((derailed(wagon.physics()) || derailed(locomotive.physics())));
|
||||
for (auto *vehicle : {&wagon, &locomotive}) {
|
||||
auto &mover{vehicle->mover()};
|
||||
mover.repair_damage();
|
||||
CHECK(mover.DamageFlag.Empty());
|
||||
CHECK(mover.Derailed == derailment::outcome::none);
|
||||
CHECK(mover.CollisionDerail == NONE);
|
||||
CHECK(mover.pushed_off_monitor.distance() == 0.0);
|
||||
CHECK(mover.pushed_off_monitor.time() == 0.0);
|
||||
for (auto const &coupler : mover.Couplers) {
|
||||
auto &physics{vehicle->physics()};
|
||||
physics.repair_damage();
|
||||
CHECK(physics.DamageFlag.Empty());
|
||||
CHECK(physics.Derailed == derailment::outcome::none);
|
||||
CHECK(physics.CollisionDerail == NONE);
|
||||
CHECK(physics.pushed_off_monitor.distance() == 0.0);
|
||||
CHECK(physics.pushed_off_monitor.time() == 0.0);
|
||||
for (auto const &coupler : physics.Couplers) {
|
||||
CHECK(coupler.crush == 0.0);
|
||||
CHECK(coupler.contact.absorbed() == 0.0);
|
||||
CHECK(coupler.contact.crush_work() == 0.0);
|
||||
@@ -766,8 +766,8 @@ TEST_CASE("collisions: the legacy rule with physics.collisions old, the crush wi
|
||||
train.add(definition::fiz(front));
|
||||
train.add(definition::fiz(back), 0, Coupling::none, speed, 20.0);
|
||||
train.run(10.0);
|
||||
CHECK(derailed(train[0].mover()) == (physical ? frontout_new : frontout_old));
|
||||
CHECK(derailed(train[1].mover()) == (physical ? backout_new : backout_old));
|
||||
CHECK(derailed(train[0].physics()) == (physical ? frontout_new : frontout_old));
|
||||
CHECK(derailed(train[1].physics()) == (physical ? backout_new : backout_old));
|
||||
auto const crush{train[0]->Couplers[VehicleEnd::rear].crush + train[1]->Couplers[VehicleEnd::front].crush};
|
||||
if (physical) {
|
||||
MESSAGE(name, ": crush ", crush, " m");
|
||||
@@ -853,13 +853,13 @@ TEST_CASE("collisions: automatic couplers hit too fast don't catch, the ends cru
|
||||
auto coupled{false};
|
||||
auto fast{false}; // coupled while closing in faster than the couplers catch
|
||||
for (int i = 0; i < 1000; ++i) {
|
||||
auto const closing{moving->CollisionVelocity(VehicleEnd::front, standing.mover(), VehicleEnd::rear)};
|
||||
auto const closing{moving->CollisionVelocity(VehicleEnd::front, standing.physics(), VehicleEnd::rear)};
|
||||
pair.step();
|
||||
fast = fast || (pair.coupled() && false == coupled && closing > TMoverParameters::SafeCollisionVelocity);
|
||||
fast = fast || (pair.coupled() && false == coupled && closing > physics::Vehicle::SafeCollisionVelocity);
|
||||
coupled = coupled || pair.coupled();
|
||||
}
|
||||
auto const crush{moving->Couplers[VehicleEnd::front].crush + standing->Couplers[VehicleEnd::rear].crush};
|
||||
MESSAGE(speed, " km/h: crush ", crush, " m, derailed ", derailed(moving.mover()), " ", derailed(standing.mover()), ", coupled later ", coupled);
|
||||
MESSAGE(speed, " km/h: crush ", crush, " m, derailed ", derailed(moving.physics()), " ", derailed(standing.physics()), ", coupled later ", coupled);
|
||||
CHECK_FALSE(fast);
|
||||
CHECK(crush > 0.0);
|
||||
// crushed past the draw gear, the coupler is gone; short of it, the wagons may roll together again slowly
|
||||
@@ -869,8 +869,8 @@ TEST_CASE("collisions: automatic couplers hit too fast don't catch, the ends cru
|
||||
CHECK((moving->Couplers[VehicleEnd::front].broken || standing->Couplers[VehicleEnd::rear].broken));
|
||||
}
|
||||
// the two alike: neither climbs onto the other until the crush is deep enough for both to
|
||||
CHECK(derailed(moving.mover()) == derailed(standing.mover()));
|
||||
CHECK(derailed(moving.mover()) == (crush > cl::override_both));
|
||||
CHECK(derailed(moving.physics()) == derailed(standing.physics()));
|
||||
CHECK(derailed(moving.physics()) == (crush > cl::override_both));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -884,8 +884,8 @@ TEST_CASE("collisions: road vehicles keep the legacy rule") {
|
||||
road.add(definition::fiz("road/man/nl293"));
|
||||
road.add(definition::fiz("road/man/nl293"), 0, Coupling::none, 40.0, 5.0);
|
||||
road.run(5.0);
|
||||
CHECK(derailed(road[0].mover()));
|
||||
CHECK(derailed(road[1].mover()));
|
||||
CHECK(derailed(road[0].physics()));
|
||||
CHECK(derailed(road[1].physics()));
|
||||
CHECK(road[0]->Couplers[VehicleEnd::rear].crush == 0.0);
|
||||
CHECK(road[1]->CollisionDerail == NONE);
|
||||
CHECK(road[0]->crush_reports + road[1]->crush_reports == 0);
|
||||
@@ -899,7 +899,7 @@ TEST_CASE("collisions: a vehicle off the rails by the new model stays in the cha
|
||||
auto &wagon{train.add(definition::fiz("430w_v2/430w"))};
|
||||
auto &locomotive{train.add(definition::fiz("4e_v1/4e"), 0, Coupling::none, 10.0, 0.5)};
|
||||
wagon->derail_in_collision(COLLISION_PUSHED_OFF, "for the test");
|
||||
REQUIRE(derailed(wagon.mover()));
|
||||
REQUIRE(derailed(wagon.physics()));
|
||||
auto const before{wagon->TotalMass * wagon->V + locomotive->TotalMass * locomotive->V};
|
||||
// the hit is over within a second, the friction of the derailed wagon slows the pair down over it
|
||||
train.run(1.0);
|
||||
@@ -954,10 +954,10 @@ TEST_CASE("collisions: identical units built to EN 15227 at 36 km/h") {
|
||||
double inner;
|
||||
int derailed;
|
||||
bool higher;
|
||||
} result{train[1]->Couplers[VehicleEnd::rear].crush + train[2]->Couplers[VehicleEnd::front].crush, std::max(crush_of(train[0].mover()), crush_of(train[3].mover())), 0,
|
||||
derailed(train[2].mover())};
|
||||
} result{train[1]->Couplers[VehicleEnd::rear].crush + train[2]->Couplers[VehicleEnd::front].crush, std::max(crush_of(train[0].physics()), crush_of(train[3].physics())), 0,
|
||||
derailed(train[2].physics())};
|
||||
for (std::size_t i = 0; i < train.size(); ++i) {
|
||||
result.derailed += derailed(train[i].mover());
|
||||
result.derailed += derailed(train[i].physics());
|
||||
}
|
||||
return result;
|
||||
};
|
||||
@@ -1204,7 +1204,7 @@ TEST_CASE("collisions: two coaches (36 t and 41.6 t) at 8 km/h don't crush, nor
|
||||
consist train;
|
||||
auto &wall{train.add(light)};
|
||||
wall->Derail(END_OF_TRACK);
|
||||
REQUIRE(derailed(wall.mover()));
|
||||
REQUIRE(derailed(wall.physics()));
|
||||
auto &running{train.add(heavy, 0, Coupling::none, 5.0, gap)};
|
||||
train.run(5.0);
|
||||
CHECK(wall->Couplers[VehicleEnd::rear].crush + running->Couplers[VehicleEnd::front].crush == 0.0);
|
||||
@@ -1232,9 +1232,9 @@ TEST_CASE("collisions: a locomotive pushing a standing braked train at full powe
|
||||
train.run(30.0, line);
|
||||
// the locomotive behind them, touching, driven forwards into them at full power
|
||||
auto &locomotive{train.add(definition::fiz(path), 1, Coupling::none, 0.0, 0.0)};
|
||||
test::driven const driver{locomotive.mover(), locomotive.mover(), locomotive.mover(), [&train](double const Seconds, test::track const &Track) { train.run(Seconds, Track); }};
|
||||
test::driven const driver{locomotive.physics(), locomotive.physics(), locomotive.physics(), [&train](double const Seconds, test::track const &Track) { train.run(Seconds, Track); }};
|
||||
REQUIRE(test::start_up(driver, line));
|
||||
test::release_brakes(locomotive.mover());
|
||||
test::release_brakes(locomotive.physics());
|
||||
for (int i = 0; i < 3 && locomotive->DirActive <= 0; ++i) {
|
||||
locomotive->DirectionForward();
|
||||
}
|
||||
@@ -1265,8 +1265,8 @@ TEST_CASE("collisions: a locomotive pushing a standing braked train at full powe
|
||||
CHECK(seconds >= 55);
|
||||
for (std::size_t i = 0; i < train.size(); ++i) {
|
||||
CAPTURE(i);
|
||||
CHECK(crush_of(train[i].mover()) == 0.0);
|
||||
CHECK_FALSE(derailed(train[i].mover()));
|
||||
CHECK(crush_of(train[i].physics()) == 0.0);
|
||||
CHECK_FALSE(derailed(train[i].physics()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1326,7 +1326,7 @@ struct train_damage {
|
||||
train_damage damage_of(consist &Train) {
|
||||
train_damage result;
|
||||
for (std::size_t i = 0; i < Train.size(); ++i) {
|
||||
auto const &vehicle{Train[i].mover()};
|
||||
auto const &vehicle{Train[i].physics()};
|
||||
result.crush = std::max(result.crush, crush_of(vehicle));
|
||||
for (auto const end : VehicleEnds) {
|
||||
result.energy += vehicle.crush_curve_at(end).energy(0.0, vehicle.Couplers[end].crush);
|
||||
@@ -1382,7 +1382,7 @@ TEST_CASE("collisions: the cut of the speed of the legacy derailment is no hit i
|
||||
locomotive->Derail(reason);
|
||||
}
|
||||
train.step();
|
||||
REQUIRE(derailed(locomotive.mover()));
|
||||
REQUIRE(derailed(locomotive.physics()));
|
||||
// the train loses the speed with it
|
||||
for (std::size_t i = 1; i < train.size(); ++i) {
|
||||
CAPTURE(i);
|
||||
@@ -1432,7 +1432,7 @@ TEST_CASE("collisions: the train behind a vehicle that ran off the end of the tr
|
||||
auto const kinetic{kinetic_of(train)};
|
||||
train[0].damage_track(dtrack_norail);
|
||||
train.run(20.0);
|
||||
REQUIRE(derailed(train[0].mover()));
|
||||
REQUIRE(derailed(train[0].physics()));
|
||||
auto const damage{damage_of(train)};
|
||||
INFO(damage.list);
|
||||
MESSAGE(std::format("{}: crush {:.3f} m, {:.0f} kJ of the {:.0f} kJ of the train", pushed ? "pushed" : "pulled", damage.crush, damage.energy / 1000.0, kinetic / 1000.0));
|
||||
@@ -1442,7 +1442,7 @@ TEST_CASE("collisions: the train behind a vehicle that ran off the end of the tr
|
||||
CHECK(damage.broken == 0);
|
||||
for (std::size_t i = 1; i < train.size(); ++i) {
|
||||
CAPTURE(i);
|
||||
CHECK_FALSE(derailed(train[i].mover()));
|
||||
CHECK_FALSE(derailed(train[i].physics()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user