18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-04 23:45:17 +01:00

fix: SonarQube findings of the buffer stops

- The notice of a finished hit is taken out of the contact with std::exchange before it goes to the scenery, so
  what the scenery does with it can't reach the one held in the contact.
- The loops count whole steps (an int, the number of steps taken with ceil) instead of adding a floating step.
- The local final of bufferstop::contact() is ending (final is a contextual keyword).

Unit tests 1294/1294.
This commit is contained in:
jerrrrycho
2026-12-02 17:04:29 +01:00
parent 9ecbd110da
commit 885c28c1ef
4 changed files with 22 additions and 15 deletions
+8 -8
View File
@@ -357,7 +357,7 @@ contact_result contact(definition const &Stop, state &Stop_state, contact_input
auto penetration{Input.penetration};
auto vehiclecrush{Input.vehicle_end.crush};
auto time{0.0};
auto final{outcome::none};
auto ending{outcome::none};
while (Input.dt - time > 1e-12) {
auto const step{std::min(length, Input.dt - time)};
auto deflection{penetration - (now.absorber + now.slid + now.crush + vehiclecrush)};
@@ -409,7 +409,7 @@ contact_result contact(definition const &Stop, state &Stop_state, contact_input
if (now.slid >= Stop.runout - 1e-9) {
// slid off the end of its run-out: it goes on with the vehicle, holding nothing
now.overrun = true;
final = outcome::overrun;
ending = outcome::overrun;
}
}
}
@@ -453,11 +453,11 @@ contact_result contact(definition const &Stop, state &Stop_state, contact_input
result.climbed = true;
result.work += climbed.work;
velocity = climbed.velocity;
final = climbed.result;
ending = climbed.result;
}
else if (now.crush >= Stop.demolish) {
now.demolished = true;
final = outcome::demolished;
ending = outcome::demolished;
}
break;
}
@@ -483,12 +483,12 @@ contact_result contact(definition const &Stop, state &Stop_state, contact_input
result.climbed = true;
result.work += climbed.work;
velocity = climbed.velocity;
final = climbed.result;
ending = climbed.result;
break;
}
if (now.crush >= Stop.demolish) {
now.demolished = true;
final = outcome::demolished;
ending = outcome::demolished;
break;
}
}
@@ -501,8 +501,8 @@ contact_result contact(definition const &Stop, state &Stop_state, contact_input
result.impulse = Input.mass * (Input.closing - velocity);
result.vehicle_crush = vehiclecrush - Input.vehicle_end.crush;
now.peak_force = std::max(now.peak_force, result.force);
if (final != outcome::none) {
result.result = final;
if (ending != outcome::none) {
result.result = ending;
}
else if (result.touched) {
result.result = now.crush >= collision::crush_mark ? outcome::damaged : outcome::held;