mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-01 07:07:05 +01:00
d6dba363e3
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.
86 lines
3.5 KiB
C++
86 lines
3.5 KiB
C++
/*
|
|
This Source Code Form is subject to the
|
|
terms of the Mozilla Public License, v.
|
|
2.0. If a copy of the MPL was not
|
|
distributed with this file, You can
|
|
obtain one at
|
|
http://mozilla.org/MPL/2.0/.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "simulation/simulationtestrules.h"
|
|
|
|
class TDynamicObject;
|
|
namespace derailment {
|
|
struct notice;
|
|
}
|
|
|
|
#include <atomic>
|
|
#include <mutex>
|
|
#include <string_view>
|
|
#include <thread>
|
|
|
|
// integration test mode (eu07 --test -s <scenery>, eu07/maszyna#541): the scenery runs unattended in a tight
|
|
// fixed-step loop and the simulator quits with an exit code saying how the test went
|
|
namespace simulation {
|
|
|
|
class test_manager {
|
|
|
|
public:
|
|
// name of the memory cell a scenery reports its result to
|
|
static constexpr std::string_view result_cell { "__test.result" };
|
|
// fixed simulation time step of one frame in test mode [s]: 3 physics steps of 10 ms
|
|
static constexpr double frame_step { 0.03 };
|
|
|
|
// creates the result cell; called with the other scripting interface cells, before the scenery is read
|
|
void init_result_cell() const;
|
|
// the simulation is ready: start the clocks
|
|
void start();
|
|
// checks the end conditions after a simulation frame of Deltatime seconds
|
|
void update(double Deltatime);
|
|
// reported by a driver whose train went past a signal showing stop
|
|
void signal_passed_at_danger(std::string_view Vehicle, std::string_view Signal);
|
|
// the vehicle derailed: a vehicle of the tested trains ends the test with test.fail_on_derailment
|
|
void vehicle_derailed(TDynamicObject const &Vehicle, derailment::notice const &Notice);
|
|
// ends the test with given result and closes the application; the first call wins
|
|
void finish(test_result Result, std::string_view Reason);
|
|
// ends the test with given result, without closing the application: for the ways out that close it anyway
|
|
// (a bad command line, a failed start, an exception). returns false if the test had already ended
|
|
bool conclude(test_result Result, std::string_view Reason);
|
|
// (re)sets the real time limit of the run [s] since the start of the simulator, 0 = none. the first limit
|
|
// starts the watchdog, which ends a run still going at the limit with the timeout code, whatever it's doing
|
|
void watch_wall_clock(double Limit);
|
|
|
|
bool finished() const { return m_finished; }
|
|
// exit code of the process: the result, or error while the test hasn't finished
|
|
int exit_code() const;
|
|
|
|
private:
|
|
// the watchdog's check, at Elapsed seconds of real time since the start of the simulator
|
|
void check_wall_clock(double Elapsed);
|
|
// every vehicle of the tested trains stands: the consists of test.vehicle, or every vehicle without it
|
|
bool tested_trains_at_rest() const;
|
|
// the vehicle is one of the tested trains: in a consist of test.vehicle as it is now, any vehicle without it
|
|
bool tested(TDynamicObject const &Vehicle) const;
|
|
|
|
// the watchdog may end the test from its own thread
|
|
mutable std::mutex m_lock;
|
|
bool m_started { false };
|
|
std::atomic<bool> m_finished { false };
|
|
test_result m_result { test_result::error };
|
|
test_progress m_progress;
|
|
std::atomic<double> m_walllimit { 0.0 }; // [s] since the start of the simulator, 0 = none
|
|
std::jthread m_watchdog;
|
|
};
|
|
|
|
// the test of the run
|
|
test_manager &test();
|
|
|
|
// the settings of the test mode, over whatever the settings files and the scenery say: applied once the command
|
|
// line is read, and again after each config block of the scenery, which could turn the sound, the network or the
|
|
// program run at the end back on
|
|
void apply_test_mode_settings();
|
|
|
|
} // namespace simulation
|