From d237996afdd14875f21826a4f52b7ec97006701b Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Sun, 29 Nov 2026 02:06:40 +0100 Subject: [PATCH 1/5] fix(scene): the uuid of a scene node no longer takes the random numbers of the simulation Each scene node drew its uuid (which only the editor goes by) from Global.random_engine, the engine of the run's seed, two numbers a node. A node added to a scenery, or made by the program before it, moved every random number drawn after it: the pressure the brake valves are set to, the brake delays, the sound sets and the rest. The memory cell __simulation.metar (2be85410c, merged with #468) did that to every run, so the same seed gave a different train from 27.11 on, with no change in its physics. The uuids come from an engine of their own now. --- tests/unit/test_utilities.cpp | 16 ++++++++++++++++ utilities/uuid.hpp | 12 ++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/tests/unit/test_utilities.cpp b/tests/unit/test_utilities.cpp index 1b12f1b9a..c799fd84d 100644 --- a/tests/unit/test_utilities.cpp +++ b/tests/unit/test_utilities.cpp @@ -7,6 +7,7 @@ #include "utilities/Globals.h" #include "utilities/utilities.h" +#include "utilities/uuid.hpp" #include #include @@ -297,6 +298,21 @@ TEST_CASE("utilities: a version 4 uuid is drawn from the random numbers of the s CHECK(generate_uuid_v4() == first); } +TEST_CASE("utilities: the uuid of a scene node takes none of the random numbers of the simulation") { + // a node added to the scenery (or a memory cell the program makes before it) left the numbers drawn after it as + // they were: the physics of a run of a seed doesn't depend on how many nodes the scenery has + Global.random_engine.seed(11); + auto const before{Global.random_engine}; + auto const first{UID::random()}; + auto const second{UID::random()}; + CHECK(Global.random_engine == before); + CHECK(first != second); + // the version and the variant of a version 4 uuid + CHECK((first.bytes[6] >> 4) == 4); + CHECK((first.bytes[8] >> 6) == 2); + CHECK(first.to_string().size() == 36); +} + TEST_CASE("utilities: a failure is drawn only over the threshold, the likelier the less the value is over it") { debug_mode const mode{false}; for (auto draw{0}; draw < 50; ++draw) { diff --git a/utilities/uuid.hpp b/utilities/uuid.hpp index f68ad49bb..462169874 100644 --- a/utilities/uuid.hpp +++ b/utilities/uuid.hpp @@ -6,6 +6,7 @@ #include #include #include +#include #include "utilities/utilities.h" #include "utilities/Globals.h" @@ -14,10 +15,17 @@ public: std::array bytes; + // the uuid of each scene node, which only the editor goes by. drawn from an engine of its own: from the one of the + // simulation (Global.random_engine) each node made took two of the numbers the run's seed gives, and a node added to + // the scenery, or made by the program before it (a memory cell of the scripting interface), changed every random + // number drawn after it, the physics of the vehicles among them static UID random() { + static std::mt19937 engine(static_cast(true_random_seed())); // NOSONAR: an identifier, not anything security-relevant + static std::mutex mutex; UID u; - uint64_t a = Global.random_engine(); - uint64_t b = Global.random_engine(); + std::scoped_lock lock(mutex); + uint64_t a = engine(); + uint64_t b = engine(); for (int i = 0; i < 8; ++i) u.bytes[i] = uint8_t(a >> (i * 8) & 0xFF); for (int i = 0; i < 8; ++i) u.bytes[8 + i] = uint8_t(b >> (i * 8) & 0xFF); From b4b342c52311905777d171fc7cec3d41f20356d7 Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Sun, 29 Nov 2026 02:19:43 +0100 Subject: [PATCH 2/5] fix(ai): down a gradient a train at walking pace in the last metres before its stop stops there In the final approach the braking curve asks for next to nothing once the train is down to walking pace a metre or two short of the point it aims at, or past it. Down a gradient the pneumatic brake let off for that lets the gradient take the train again: it crept on at about 1 km/h and braked again, a release and an application at a time. EU07 alone down 20 per mille to the signal gr_sem (eu07_td_downgrade_w4_signal) did it three times and stood 12 s later than it had stopped. Below 5 km/h within 2 m of that point, or past it, on a descent, the AI now stops where it is (the desired speed 0), as it does once it stands there. --- tests/unit/test_braking_curve.cpp | 16 ++++++++++++++++ vehicle/Driver.cpp | 6 ++++++ vehicle/brakingcurve.cpp | 8 ++++++++ vehicle/brakingcurve.h | 7 +++++++ 4 files changed, 37 insertions(+) diff --git a/tests/unit/test_braking_curve.cpp b/tests/unit/test_braking_curve.cpp index 6bcf92fc7..f542ec27c 100644 --- a/tests/unit/test_braking_curve.cpp +++ b/tests/unit/test_braking_curve.cpp @@ -228,3 +228,19 @@ TEST_CASE("braking curve: a train gets the demand it got before the curve moved CHECK(braking_curve::demand(approach, &table) == doctest::Approx(expected).epsilon(1e-7)); } + +TEST_CASE("braking curve: down a gradient a train at walking pace in the last metres before its stop stops there") { + // EU07 alone down 20 per mille to the signal gr_sem (eu07_td_downgrade_w4_signal): 3.5 km/h 1.3 m short of the + // middle of the stopping window, the curve asked for next to no braking; the independent brake let off for it, the + // gradient took the locomotive again, and it crept on and braked again three times, for some 12 s + auto constexpr descent{0.196}; // [m/s2] 20 per mille + CHECK(braking_curve::stops_where_it_is(3.5, 1.3, descent)); + // past the point it aims at, it doesn't creep on half a metre at a time either + CHECK(braking_curve::stops_where_it_is(0.2, -1.2, descent)); + // faster, or further out, it follows the curve down to the point + CHECK_FALSE(braking_curve::stops_where_it_is(5.8, 2.6, descent)); + CHECK_FALSE(braking_curve::stops_where_it_is(3.5, 10.0, descent)); + // on the flat and uphill the gradient doesn't take the train when the brake lets off + CHECK_FALSE(braking_curve::stops_where_it_is(3.5, 1.3, 0.0)); + CHECK_FALSE(braking_curve::stops_where_it_is(3.5, 1.3, -0.196)); +} diff --git a/vehicle/Driver.cpp b/vehicle/Driver.cpp index 554d304cc..ae445f73a 100644 --- a/vehicle/Driver.cpp +++ b/vehicle/Driver.cpp @@ -8518,6 +8518,12 @@ TController::adjust_desired_speed_for_final_approach( double const Vel ) { AccDesired = std::min( 0.0, AccPreferred ); VelDesired = min_speed( VelDesired, uphill_coasting_speed( ActualProximityDist - stopping_margin(), fAccGravity ) ); } + if( ( BrakeSystem == TBrakeSystem::Pneumatic ) + && ( braking_curve::stops_where_it_is( Vel, ActualProximityDist - stopping_margin(), fAccGravity ) ) ) { + // down a gradient at walking pace in the last metres before the point it aims at, or past it: it stops here, + // rather than lets off the brake to creep on, which lets the gradient take it again + VelDesired = 0.0; + } } void diff --git a/vehicle/brakingcurve.cpp b/vehicle/brakingcurve.cpp index 1cd1397aa..f28439ed0 100644 --- a/vehicle/brakingcurve.cpp +++ b/vehicle/brakingcurve.cpp @@ -87,4 +87,12 @@ double demand(approach const &Approach, brake_table const *Pneumatictable) { return shaped_demand(velocity, Approach.target, room + 0.1 / 25.92, Approach.gravity, *table); } +bool stops_where_it_is(double const Velocity, double const Room, double const Gravity) { + + constexpr double walking_pace{5.0}; // [km/h] + constexpr double last_metres{2.0}; // [m] + constexpr double descent{0.025}; // [m/s2] about 2.5 per mille down, as the AI takes a gradient going downhill + return (Gravity > descent) && (Velocity < walking_pace) && (Room < last_metres); +} + } // namespace braking_curve diff --git a/vehicle/brakingcurve.h b/vehicle/brakingcurve.h index 3b49597e5..ab8371827 100644 --- a/vehicle/brakingcurve.h +++ b/vehicle/brakingcurve.h @@ -57,4 +57,11 @@ bool brake_acting(double Trainbrakeposition, double Localbrakeposition); // zero, as in shunting) it is the constant deceleration over the distance left double demand(approach const &Approach, brake_table const *Pneumatictable); +// whether a train in the final approach to a stop, down a gradient, stops where it is rather than creeps on to the +// point it aims at: down to walking pace (Velocity [km/h]) within the last metres short of that point, or past it +// (Room [m], negative past it), on a descent (Gravity [m/s2], positive downhill). there the demand of the curve is +// next to nothing; the pneumatic brake let off for it lets the gradient take the train again, and it crept on and +// braked again, a release and an application at a time, for many seconds +bool stops_where_it_is(double Velocity, double Room, double Gravity); + } // namespace braking_curve From e6d576fd82b90daa5052ca27e716b7c377650108 Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Sun, 29 Nov 2026 02:19:44 +0100 Subject: [PATCH 3/5] fix(derailment): a coupling between a vehicle off the track and one on it pulls taut, holds or breaks With either vehicle of a pair off the track (physics.derailment new) the distance between their ends is measured where they are, but the physical coupler model still took its change from the moves of the vehicles along the track. Once the ends had gone past each other (the locomotive lying beside the track, the coach coupled to it running on along the rails) a run that opened the gap counted as closing it: the draw gear unloaded, the coupling carried 0 N while the gap grew to tens of metres, the stop of the draw gear was never hit and the coupling never broke. The tension, had there been any, pushed the coach on. update_neighbours() now gives the pair the shares the move of each vehicle along its axis has in the gap, in the direction the ends are apart in (TMoverParameters::coupler_gap_change()); the gap, its rate and the hit on the stop go by them, and of the coupler force each vehicle takes along its axis the share the gap goes by. On the track nothing changes. The coupling of a vehicle off the track pulls the one coupled to it off the rails once the climbing limit holds over 2 m. That distance was the run of the vehicle off the track, so one lying at rest never pulled off the vehicle running past it; it is the run of the wheels of the vehicle pulled now. --- McZapkie/MOVER.h | 10 +++++ McZapkie/Mover.cpp | 31 +++++++++++---- tests/unit/test_coupler_physics.cpp | 58 +++++++++++++++++++++++++++++ tests/unit/vehicle.cpp | 3 ++ tests/unit/vehicle.h | 5 +++ vehicle/DynObj.cpp | 35 ++++++++++++++--- vehicle/DynObj.h | 6 +-- 7 files changed, 133 insertions(+), 15 deletions(-) diff --git a/McZapkie/MOVER.h b/McZapkie/MOVER.h index d5847cbc1..9c5f71533 100644 --- a/McZapkie/MOVER.h +++ b/McZapkie/MOVER.h @@ -1364,6 +1364,12 @@ struct neighbour_data TDynamicObject *vehicle{nullptr}; // detected obstacle int vehicle_end{-1}; // facing end of the obstacle float distance{10000.f}; // distance to the obstacle // NOTE: legacy value. TBD, TODO: use standard -1 instead? + // physics.derailment new, either vehicle off the track: the distance is between the ends where they are, and it + // changes with the moves of the vehicles (along their own axes, as V and dMoveLen go) by these shares of them, + // rather than as along a track. see TMoverParameters::coupler_gap_change() + bool off_track{false}; + double own_share{0.0}; + double other_share{0.0}; }; struct speed_control @@ -2885,6 +2891,10 @@ class TMoverParameters bool coupler_physics_at(int const End) const; // the force of the coupling at the end by the physical model (couplerphysics in eu07.ini), see couplerphysics.h double coupler_force_physical(int const End, double const dt); + // how much the distance to the vehicle at the End grows [m, or m/s] when this vehicle moves (Own) and the other one + // moves (Other) along their axes: along a track the difference of the two moves; with either vehicle off the + // track (Neighbours[End].off_track) by the shares of them the ends have in the direction they are apart in + double coupler_gap_change(int const End, double const Own, double const Other) const; // with the physical model: whether the vehicles at the end hit the stop of their springs at the last update and // still close in on it, so that they collide; a hit hard enough breaks the coupling or crushes the buffers bool coupler_stop_hit(int const End, TMoverParameters &Other, int const OtherEnd); diff --git a/McZapkie/Mover.cpp b/McZapkie/Mover.cpp index 7ee85203a..8245810cb 100644 --- a/McZapkie/Mover.cpp +++ b/McZapkie/Mover.cpp @@ -6658,7 +6658,10 @@ void TMoverParameters::ComputeTotalForce(double dt) // the velocities before the step, the forces of all the vehicles come before their movement Couplers[end].closing = -CouplerVelocityDifference(end, *Neighbours[end].vehicle->MoverParameters, Neighbours[end].vehicle_end) * DirF(end); Couplers[end].CForce = CouplerForce(end, dt); - FTrain += Couplers[end].CForce; + // off the track (physics.derailment new) the vehicles are apart in another direction than along the axis of + // this one: of the force between them, along it the share the gap goes by, which for ends gone past each + // other is the other way. the force as a whole stays in CForce, for the motion off the track + FTrain += Couplers[end].CForce * (Neighbours[end].off_track ? coupler_gap_change(end, 1.0, 0.0) * DirF(end) : 1.0); // what the buffers of the pair take in, for the budget of the crush (physics.collisions new and monitor) auto &coupler{Couplers[end]}; coupler.contact.update(coupler.Dist < 0.0, coupler.CheckCollision, coupler.closing, compression_at(coupler, end), std::max(0.0, -coupler.Dist), dt); @@ -7095,6 +7098,19 @@ int coupler_sounds(coupler_sound_input const &Input) } // namespace +double TMoverParameters::coupler_gap_change(int const End, double const Own, double const Other) const +{ + auto const &neighbour{Neighbours[End]}; + if (neighbour.off_track) + { + return neighbour.own_share * Own + neighbour.other_share * Other; + } + // the gap opens up when the front end falls behind the vehicle ahead of it, or the rear end runs ahead of the one + // behind; the other vehicle's move turned around when the vehicles face each other + auto const other{Other * DirPatch(End, neighbour.vehicle_end)}; + return End == end::front ? other - Own : Own - other; +} + double TMoverParameters::coupler_force_physical(int const End, double const dt) { auto &thiscoupler{Couplers[End]}; @@ -7103,11 +7119,12 @@ double TMoverParameters::coupler_force_physical(int const End, double const dt) auto &othercoupler{othervehicle->Couplers[otherend]}; auto &state{thiscoupler.physics_state}; - // the gap as it is now: the distance found at the start of the frame, and the movement of both vehicles since - auto const othervehiclemove{othervehicle->dMoveLen * DirPatch(End, otherend)}; - auto const gap{Neighbours[End].distance + (End == end::front ? othervehiclemove - dMoveLen : dMoveLen - othervehiclemove)}; - // the gap opens up when the front end falls behind the vehicle ahead of it, or the rear end runs ahead of the one behind - auto const gaprate{CouplerVelocityDifference(End, *othervehicle, otherend) * DirF(End)}; + // the gap as it is now: the distance found at the start of the frame, and the movement of both vehicles since. + // off the track the ends of a pair may have gone past each other, where a move along the track that would close + // them on it opens the gap; taken as along the track, the draw gear unloaded while the gap grew far past its travel, + // and the coupling neither held nor broke + auto const gap{Neighbours[End].distance + coupler_gap_change(End, dMoveLen, othervehicle->dMoveLen)}; + auto const gaprate{coupler_gap_change(End, V, othervehicle->V)}; auto const coupled{thiscoupler.CouplingFlag != coupling::faux}; auto const adapter{thiscoupler.has_adapter() || othercoupler.has_adapter()}; @@ -7159,7 +7176,7 @@ bool TMoverParameters::coupler_stop_hit(int const End, TMoverParameters &Other, auto &state{thiscoupler.physics_state}; // the draw gear went solid with the gap opening up, the buffers with it closing - auto const gaprate{CouplerVelocityDifference(End, Other, OtherEnd) * DirF(End)}; + auto const gaprate{coupler_gap_change(End, V, Other.V)}; auto const closing{state.stop > 0 ? gaprate : -gaprate}; if (state.stop == 0 || closing <= 0.0) { diff --git a/tests/unit/test_coupler_physics.cpp b/tests/unit/test_coupler_physics.cpp index 6785a2cb3..9e4799464 100644 --- a/tests/unit/test_coupler_physics.cpp +++ b/tests/unit/test_coupler_physics.cpp @@ -7,6 +7,7 @@ #include #include +#include // the physical model of the couplings (McZapkie/couplerphysics.h, couplerphysics in eu07.ini): progressive buffers and // draw gear with friction hysteresis, pressed in series, the play of the coupling, its yield and its breaking @@ -336,6 +337,63 @@ TEST_CASE("coupler physics: a coupling with play pulls only once the play is tak CHECK(front.speed() < 2.5); } +TEST_CASE("coupler physics: off the track, ends gone past each other pull the coupling taut, it holds or breaks") { + // eu07_td_off_track_buckle: the locomotive lay at rest beside the track, the coach coupled to it ran on past it along + // the rails. the gap between their ends grew with the run of the coach, but the model took the run along the track, + // as closing the gap: the draw gear unloaded, the coupling carried 0 N while the gap grew to 30 m, and it never broke + flag_setting const physics{Global.coupler_physics, true}; + flag_setting const everywhere{Global.coupler_physics_all, true}; + auto running{loose_wagon(0.05, 30.0, "running")}; + auto lying{loose_wagon(0.05, 0.0, "lying")}; + join(running, end::front, lying, end::rear); + test::pair pair{running, end::front, lying, end::rear, 0.0}; + running.hold_brake_pipe(5.0); + lying.hold_brake_pipe(5.0); + // as TDynamicObject::update_neighbours() measures the ends where they are: gone past each other, the run of the + // running wagon forwards opens the gap, the other one running after it closes it. from where the pair stands at + // the first step, the ends at one place + std::optional start; + auto const gap = [&]() { return (running->Loc.X - lying->Loc.X) - start.value_or(running->Loc.X - lying->Loc.X); }; + pair.neighbours_found = [&]() { + if (false == start.has_value()) { + start = running->Loc.X - lying->Loc.X; + } + auto const gap{(running->Loc.X - lying->Loc.X) - *start}; + auto &fromrunning{running->Neighbours[end::front]}; + fromrunning.distance = static_cast(gap); + fromrunning.off_track = true; + fromrunning.own_share = 1.0; + fromrunning.other_share = -1.0; + auto &fromlying{lying->Neighbours[end::rear]}; + fromlying.distance = static_cast(gap); + fromlying.off_track = true; + fromlying.own_share = -1.0; + fromlying.other_share = 1.0; + }; + + SUBCASE("with crash damage, the jerk breaks it") { + flag_setting const crashdamage{Global.crash_damage, true}; + pair.run(1.0); + CHECK_FALSE(pair.coupled()); + CHECK((coupler_damaged(running) || coupler_damaged(lying))); + } + SUBCASE("without it, the coupling holds: the wagon running past is held back, the gap stays within the draw gear") { + flag_setting const crashdamage{Global.crash_damage, false}; + auto pulled{false}; + auto widest{0.0}; + for (int i = 0; i < 300; ++i) { + pair.step(); + pulled = pulled || running->Couplers[end::front].CForce != 0.0; + widest = std::max(widest, gap()); + } + CHECK(pulled); + CHECK(pair.coupled()); + // it ran 25 m on past the other one, the coupling carrying nothing + CHECK(widest < 0.5); + CHECK(running.speed() == doctest::Approx(lying.speed()).epsilon(0.2)); + } +} + TEST_CASE("coupler physics: buffers hit at a walking pace give back less than they took") { flag_setting const physics{Global.coupler_physics, true}; flag_setting const everywhere{Global.coupler_physics_all, true}; diff --git a/tests/unit/vehicle.cpp b/tests/unit/vehicle.cpp index afbac8680..f3ef758bd 100644 --- a/tests/unit/vehicle.cpp +++ b/tests/unit/vehicle.cpp @@ -325,6 +325,9 @@ void pair::find_neighbours() { othermover.Couplers[other.end].adapter_length); mover.Neighbours[1 - self.end] = neighbour_data(); } + if (neighbours_found) { + neighbours_found(); + } } void pair::step(track const &Track, double Dt) { diff --git a/tests/unit/vehicle.h b/tests/unit/vehicle.h index 05c03dbf6..98d1ee5c7 100644 --- a/tests/unit/vehicle.h +++ b/tests/unit/vehicle.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include #include @@ -152,6 +153,10 @@ public: int coupling() const; bool coupled() const { return coupling() != coupling::faux; } + // called after each finding of the neighbours, which it may change: stands in for the ends of vehicles off the track + // meeting where they are (TDynamicObject::update_neighbours() with physics.derailment new), not along the track + std::function neighbours_found; + private: struct placement { vehicle *owner{nullptr}; diff --git a/vehicle/DynObj.cpp b/vehicle/DynObj.cpp index fb28557a0..1cf9b71bd 100644 --- a/vehicle/DynObj.cpp +++ b/vehicle/DynObj.cpp @@ -3094,6 +3094,27 @@ std::string_view side_name( int const Side ) { return Side < 0 ? "right" : "none"; } +// the level unit vector the vehicle moves along with a positive V, its front +glm::dvec3 level_front_of( TDynamicObject const &Vehicle ) { + glm::dvec3 const front { Vehicle.VectorFront().x, 0.0, Vehicle.VectorFront().z }; + auto const length { glm::length( front ) }; + return length > 1e-6 ? front / length : glm::dvec3 { 0.0, 0.0, 1.0 }; +} + +// physics.derailment new, either vehicle of the pair off the track: the distance between their ends where they are, and +// the shares the moves of both vehicles along their own axes have in it (TMoverParameters::coupler_gap_change()): along +// the direction they are apart in, which for ends gone past each other is the other way than along the track +void measure_off_track( neighbour_data &Neighbour, TDynamicObject const &Self, int const End ) { + auto const &other { *Neighbour.vehicle }; + auto const meeting { derail_motion::meet( end_point_of( Self, End ), end_point_of( other, Neighbour.vehicle_end ) ) }; + // pressed into each other the buffers give along the bisector of the bend, apart the coupling between the beams + auto const direction { meeting.gap < 0.0 ? meeting.push : meeting.pull }; + Neighbour.distance = static_cast( meeting.gap ); + Neighbour.off_track = true; + Neighbour.own_share = -glm::dot( direction, level_front_of( Self ) ); + Neighbour.other_share = glm::dot( direction, level_front_of( other ) ); +} + } // namespace double TDynamicObject::off_track_gap( int const End ) const { @@ -3332,7 +3353,7 @@ void TDynamicObject::move_off_track( double const Distance ) { crop_off_track_terrain(); } - pull_neighbours( Distance ); + pull_neighbours( time ); // what it cost: a frame of the vehicle off the track should take well under a millisecond auto const took { seconds_since( started ) }; @@ -3358,7 +3379,7 @@ void TDynamicObject::place_off_track() { m_offtrackplaced = true; } -void TDynamicObject::pull_neighbours( double const Distance ) { +void TDynamicObject::pull_neighbours( double const Time ) { for( int end = end::front; end <= end::rear; ++end ) { auto const &coupler { MoverParameters->Couplers[ end ] }; @@ -3384,7 +3405,10 @@ void TDynamicObject::pull_neighbours( double const Distance ) { auto const magnitude { glm::length( glm::dvec3 { force.x, 0.0, force.z } ) }; auto const mass { other.TotalMass - other.Mred }; auto const ratio { derail_motion::pull_ratio( magnitude, angle, mass, other.NAxles ) }; - if( false == m_pulledoff[ end ].update( ratio >= derailment::climbing_limit, Distance ) ) { + // the flange climbs the rail over the distance the wheels of the vehicle pulled run along it, whatever this one + // does: lying at rest beside the track, it went on pulling the vehicle running past it, which then never got + // the distance the climb takes + if( false == m_pulledoff[ end ].update( ratio >= derailment::climbing_limit, std::abs( other.V ) * Time ) ) { continue; } // the way the force across it goes: towards this one pulled, away from it pushed @@ -8443,10 +8467,11 @@ TDynamicObject::update_neighbours() { // neighbour.vehicle = coupler.Connected; // neighbour.vehicle_end = coupler.ConnectedNr; neighbour.distance = TMoverParameters::CouplerDist( MoverParameters, coupler.Connected ); + neighbour.off_track = false; if( MoverParameters->OffTrack.active() || neighbour.vehicle->MoverParameters->OffTrack.active() ) { // physics.derailment new: off the track the bodies turn against each other, the ends meet where they are // (the distance between the middles less the half lengths would press the buffers of a bent pair) - neighbour.distance = off_track_gap( end ); + measure_off_track( neighbour, *this, end ); } // take into account potential adapters attached to the couplers auto const &othercoupler { neighbour.vehicle->MoverParameters->Couplers[ neighbour.vehicle_end ] }; @@ -8475,7 +8500,7 @@ TDynamicObject::update_neighbours() { neighbour.distance = TMoverParameters::CouplerDist( MoverParameters, neighbour.vehicle->MoverParameters ); if( MoverParameters->OffTrack.active() || neighbour.vehicle->MoverParameters->OffTrack.active() ) { // physics.derailment new: the ends where they are, as for a coupled pair - neighbour.distance = off_track_gap( end ); + measure_off_track( neighbour, *this, end ); } // take into account potential adapters attached to the couplers auto const &othercoupler { neighbour.vehicle->MoverParameters->Couplers[ neighbour.vehicle_end ] }; diff --git a/vehicle/DynObj.h b/vehicle/DynObj.h index ca82a0950..7fd1f113f 100644 --- a/vehicle/DynObj.h +++ b/vehicle/DynObj.h @@ -780,9 +780,9 @@ private: derail_motion::formation track_bed() const; glm::dvec3 track_front() const; int outward_side() const; - // the couplings of this vehicle off the track pull the vehicles coupled to it off the rails sideways, the step - // having travelled the distance - void pull_neighbours( double Distance ); + // the couplings of this vehicle off the track pull the vehicles coupled to it off the rails sideways, over the step + // of the time [s] + void pull_neighbours( double Time ); // the scraping of the vehicle off the track, until it stops, and its state to the log every second void update_off_track( double Deltatime ); From a8f295f53a3efdc00470fbdc9fee8f7b92a286e6 Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Sun, 29 Nov 2026 10:15:39 +0100 Subject: [PATCH 4/5] test: NOSONAR on the copy of the simulation's random engine (S2245) --- tests/unit/test_utilities.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/test_utilities.cpp b/tests/unit/test_utilities.cpp index c799fd84d..d9309fa46 100644 --- a/tests/unit/test_utilities.cpp +++ b/tests/unit/test_utilities.cpp @@ -302,7 +302,7 @@ TEST_CASE("utilities: the uuid of a scene node takes none of the random numbers // a node added to the scenery (or a memory cell the program makes before it) left the numbers drawn after it as // they were: the physics of a run of a seed doesn't depend on how many nodes the scenery has Global.random_engine.seed(11); - auto const before{Global.random_engine}; + auto const before{Global.random_engine}; // NOSONAR: a copy of the simulation's engine to compare with; nothing secret is drawn auto const first{UID::random()}; auto const second{UID::random()}; CHECK(Global.random_engine == before); From 66908502b383581531e65d3b77e8cf9b5144fdc6 Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Sun, 29 Nov 2026 15:07:19 +0100 Subject: [PATCH 5/5] test: the off-track coupler case names the ends as VehicleEnd, as staging does since #531 --- tests/unit/test_coupler_physics.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/unit/test_coupler_physics.cpp b/tests/unit/test_coupler_physics.cpp index 2b66ef3b0..647057a94 100644 --- a/tests/unit/test_coupler_physics.cpp +++ b/tests/unit/test_coupler_physics.cpp @@ -345,8 +345,8 @@ TEST_CASE("coupler physics: off the track, ends gone past each other pull the co flag_setting const everywhere{Global.coupler_physics_all, true}; auto running{loose_wagon(0.05, 30.0, "running")}; auto lying{loose_wagon(0.05, 0.0, "lying")}; - join(running, end::front, lying, end::rear); - test::pair pair{running, end::front, lying, end::rear, 0.0}; + join(running, VehicleEnd::front, lying, VehicleEnd::rear); + test::pair pair{running, VehicleEnd::front, lying, VehicleEnd::rear, 0.0}; running.hold_brake_pipe(5.0); lying.hold_brake_pipe(5.0); // as TDynamicObject::update_neighbours() measures the ends where they are: gone past each other, the run of the @@ -359,12 +359,12 @@ TEST_CASE("coupler physics: off the track, ends gone past each other pull the co start = running->Loc.X - lying->Loc.X; } auto const gap{(running->Loc.X - lying->Loc.X) - *start}; - auto &fromrunning{running->Neighbours[end::front]}; + auto &fromrunning{running->Neighbours[VehicleEnd::front]}; fromrunning.distance = static_cast(gap); fromrunning.off_track = true; fromrunning.own_share = 1.0; fromrunning.other_share = -1.0; - auto &fromlying{lying->Neighbours[end::rear]}; + auto &fromlying{lying->Neighbours[VehicleEnd::rear]}; fromlying.distance = static_cast(gap); fromlying.off_track = true; fromlying.own_share = -1.0; @@ -383,7 +383,7 @@ TEST_CASE("coupler physics: off the track, ends gone past each other pull the co auto widest{0.0}; for (int i = 0; i < 300; ++i) { pair.step(); - pulled = pulled || running->Couplers[end::front].CForce != 0.0; + pulled = pulled || running->Couplers[VehicleEnd::front].CForce != 0.0; widest = std::max(widest, gap()); } CHECK(pulled);