mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-01 02:27:06 +01:00
feat(derailment): a derailment is told to the scenery, the black box and the test mode
Every way a vehicle leaves the rails records what derailed it and its speed in the mover (DerailedBy, DerailVelocity), by any physics.derailment model and the collisions. After all vehicles moved, TDynamicObject::new_derailment() notices each derailment once, and state_manager::report_derailment() tells: - the log: "derailment: <vehicle> derailed (<cause>) on track <track> at <speed> km/h"; - a scenery that asked for it: its memory cell __simulation.derailment gets "<vehicle> <cause> <track>", the speed and the code of the cause, then its events __simulation.derailment and <vehicle>:derailed run with the vehicle as activator. Nothing is made at the start, so a scenery without them runs as before (no draw of the random numbers for a new node); - the black box: a derailment record with the new phase 2, for any model, and every derailment record gets the finer cause and the track at its end; - the test mode: test.fail_on_derailment yes (default no) ends the run of a tested train that derailed with the new result derailment, exit code 15; otherwise the verdict line ends with " [derailed: ...]". run.py knows exit code 15 and shows the derailment of the train under test in the summary. New cases eu07_td_buckle_derails_ends_test and eu07_td_off_track_end_scenery_told; the other 83 end as before and their physics logs are byte-identical to staging.
This commit is contained in:
@@ -58,6 +58,7 @@ std::string_view to_string(test_result const Result)
|
||||
case timeout: return "timeout";
|
||||
case standstill: return "standstill";
|
||||
case error: return "error";
|
||||
case derailment: return "derailment";
|
||||
}
|
||||
return "unknown";
|
||||
}
|
||||
@@ -159,4 +160,23 @@ std::optional<test_verdict> evaluate_frame(test_progress &Progress, test_frame c
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::optional<test_verdict> evaluate_derailment(test_progress &Progress, bool const Tested, std::string_view const Description, test_limits const &Limits)
|
||||
{
|
||||
if (false == Tested)
|
||||
return std::nullopt;
|
||||
if (Limits.fail_on_derailment)
|
||||
return test_verdict{test_result::derailment, std::string(Description)};
|
||||
if (Progress.derailments++ == 0)
|
||||
Progress.firstderailment = Description;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::string verdict_reason(test_verdict const &Verdict, test_progress const &Progress)
|
||||
{
|
||||
if (Verdict.result == test_result::derailment || Progress.derailments <= 0)
|
||||
return Verdict.reason;
|
||||
return std::format("{} [derailed: {}{}]", Verdict.reason, Progress.firstderailment,
|
||||
Progress.derailments > 1 ? std::format(", and {} more", Progress.derailments - 1) : std::string());
|
||||
}
|
||||
|
||||
} // namespace simulation
|
||||
|
||||
Reference in New Issue
Block a user