From b7950af6b62794f94e3fb7ded4373e0c5849c5ef Mon Sep 17 00:00:00 2001 From: maj00r Date: Sun, 15 Nov 2026 23:48:23 +0100 Subject: [PATCH] feat(physicslog): the logs of the trains only, physicslog.trains "physicslog.trains yes" in eu07.ini writes the .dat log of each driver who drives rail vehicles, not of the passengers nor of the road vehicles that make "physicslog yes" hundreds of files on a big scenery: the tape of every train. A driver made primary later begins its log then, and isn't counted while it doesn't log. The black box goes with it when the ini says nothing of its own, and doesn't write a second log of a driver writing its own. The doc tells the doors' sides are the vehicle's, the driver's swapped in the rear cab. --- blackbox_doc.md | 10 +++++++--- simulation/blackboxrecorder.cpp | 5 ++++- utilities/Globals.cpp | 8 ++++++++ vehicle/Driver.cpp | 35 +++++++++++++++++++++++---------- vehicle/Driver.h | 10 ++++++++++ 5 files changed, 54 insertions(+), 14 deletions(-) diff --git a/blackbox_doc.md b/blackbox_doc.md index 704d1e954..3573b4271 100644 --- a/blackbox_doc.md +++ b/blackbox_doc.md @@ -8,7 +8,9 @@ the timetable and how the train kept to it at each station, and where it was tol starter, a viewer) can replay the session on the map, or set the user's driving against the AI's. `blackbox yes` in `eu07.ini` writes it, with the physics logs on or off; `blackbox no` never does. With no -`blackbox` entry it is written along with the physics logs, `physicslog yes`. It is never written in an +`blackbox` entry it is written along with the physics logs, `physicslog yes` or `physicslog.trains yes`. +The latter writes the `.dat` logs of the trains only: of each driver who drives rail vehicles, not of the +passengers nor of the vehicles of the roads, so a big scenery gives far fewer of them. It is never written in an editor session. The file goes to `physicslog/_.blackbox` (the local time the recording started at), next to the `.dat` logs of the vehicles when those are on; they stay as they are. @@ -20,7 +22,8 @@ moves to another cab of the unit or another vehicle of the same train. Taking a goes on in that driver's log, begun then if it is the first time. Back with a driver, the log goes on after the gap in its time. A vehicle with no driver of its own, or whose own driver is passive, takes the log of the driver of its train. So the speed recorder's tape can be read from them as before, also while the -simulator runs, without a log of every vehicle. Like those of `physicslog yes`, they are written every +simulator runs, without a log of every vehicle. A driver who writes a log of its own, with +`physicslog.trains yes`, isn't written twice. Like those of `physicslog yes`, they are written every two seconds, each file opened only for the moment it is written to; a crash loses the last two seconds of real time of them (at a higher time speed, more of the simulated time). A file another program holds for a while doesn't lose its lines: they are written once it can be, the last 64 MB of all such logs at most. @@ -300,7 +303,8 @@ whose motors the cab drives (the motor car of a unit). | 0x0800'0000 | the cruise control holds a speed | The doors, their permits and steps, the departure signal and the releaser are of the vehicle the user is -in; the pumps, the fans, the engine's heat and the cruise control of the one whose motors the cab drives. +in. Left and right are those of the vehicle, seen from its front: from the rear cab (the cab -1) the driver's +left doors are the vehicle's right, as the simulator works them from there. The pumps, the fans, the engine's heat and the cruise control of the one whose motors the cab drives. The lights: 0x001 left headlight, 0x002 left red marker, 0x004 upper headlight, 0x010 right headlight, 0x020 right red marker, 0x040 rear-end signals, 0x080 left and 0x100 right auxiliary diff --git a/simulation/blackboxrecorder.cpp b/simulation/blackboxrecorder.cpp index 28e453926..6d0f76502 100644 --- a/simulation/blackboxrecorder.cpp +++ b/simulation/blackboxrecorder.cpp @@ -236,7 +236,7 @@ void blackbox_recorder::update(double const Deltatime) { return; m_started = true; // "blackbox yes" or "no" of eu07.ini decides by itself, with no entry it goes with the physics logs - if (false == Global.BlackBox.value_or(WriteLogFlag) || Global.editor_session) + if (false == Global.BlackBox.value_or(WriteLogFlag || WriteTrainLogFlag) || Global.editor_session) return; open(); } @@ -503,6 +503,9 @@ void blackbox_recorder::keep_tape_line() { auto const *driver{vehicle->Mechanik != nullptr && vehicle->Mechanik->primary() ? vehicle->Mechanik : vehicle->ctOwner}; if (driver == nullptr) return; + // a driver writing its own, of a train with "physicslog.trains yes", isn't written twice + if (driver->writes_physicslog()) + return; auto const &name{driver->physicslog_name()}; if (m_tapes.insert(name).second) { PhysicsLogs.begin(name, TController::physicslog_header()); diff --git a/utilities/Globals.cpp b/utilities/Globals.cpp index 9c0c10279..db9e0ba79 100644 --- a/utilities/Globals.cpp +++ b/utilities/Globals.cpp @@ -538,6 +538,13 @@ bool global_settings::ConfigParseSimulation(cParser& Parser, const std::string& return true; } + // the physics logs of the trains only, of the drivers of rail vehicles; "physicslog yes" writes them all anyway + if (token == "physicslog.trains") + { + ParseOne(Parser, WriteTrainLogFlag); + return true; + } + if (token == "blackbox") { bool blackbox{false}; @@ -1737,6 +1744,7 @@ global_settings::export_as_text( std::ostream &Output ) const { export_as_text( Output, "sound.volume.ambient", EnvironmentAmbientVolume ); export_as_text( Output, "sound.asyncload", AudioAsyncLoad ); export_as_text( Output, "physicslog", WriteLogFlag ); + export_as_text( Output, "physicslog.trains", WriteTrainLogFlag ); if( BlackBox ) { export_as_text( Output, "blackbox", *BlackBox ); } diff --git a/vehicle/Driver.cpp b/vehicle/Driver.cpp index cde6ed99f..03c3f9d8f 100644 --- a/vehicle/Driver.cpp +++ b/vehicle/Driver.cpp @@ -169,6 +169,7 @@ const double FSOverchargeCRP = 0.05; const double FSMaxTime = 10.0; const double DepartBlockedFSDelay = 10.0; bool WriteLogFlag = false; +bool WriteTrainLogFlag = false; double const deltalog = 0.05; // przyrost czasu std::string StopReasonTable[] = { @@ -2336,14 +2337,8 @@ TController::TController(bool AI, TDynamicObject *NewControll, bool InitPsyche, SetDriverPsyche(); // na końcu, bo wymaga ustawienia zmiennych TableClear(); - if( WriteLogFlag ) { - // physicslog/.dat, written every two seconds along with the logs of the other drivers -#if LOGPRESS == 0 - PhysicsLogs.begin( VehicleName, physicslog_header() ); -#endif -#if LOGPRESS == 1 - PhysicsLogs.begin( VehicleName, "t\tVel\tAcc\tPP\tVVP\tBP\tBVP\tCVP\n" ); -#endif + if( writes_physicslog() ) { + begin_physicslog(); } // HACK: give the simulation a small window to potentially replace the AI with a human driver @@ -5398,6 +5393,18 @@ std::string TController::physicslog_line() const { return line.str(); } +void TController::begin_physicslog() +{ + // physicslog/.dat, written every two seconds along with the logs of the other drivers +#if LOGPRESS == 0 + PhysicsLogs.begin( VehicleName, physicslog_header() ); +#endif +#if LOGPRESS == 1 + PhysicsLogs.begin( VehicleName, "t\tVel\tAcc\tPP\tVVP\tBP\tBVP\tCVP\n" ); +#endif + PhysicsLogBegun = true; +} + void TController::PhysicsLog() { // zapis logu - na razie tylko wypisanie parametrów #if LOGPRESS == 0 @@ -6463,10 +6470,18 @@ TController::update_timers( double dt ) { void TController::update_logs( double const dt ) { // log vehicle data + if( false == writes_physicslog() ) { + // not counted while it isn't logged: a driver which begins to, made primary, writes a line every 0.05 s + // from then on, not one each update to make up for the time before + LastUpdatedTime = 0.0; + return; + } LastUpdatedTime += dt; - if( WriteLogFlag - && LastUpdatedTime > deltalog ) { + if( LastUpdatedTime > deltalog ) { // zapis do pliku DAT + if( false == PhysicsLogBegun ) { + begin_physicslog(); + } PhysicsLog(); LastUpdatedTime -= deltalog; } diff --git a/vehicle/Driver.h b/vehicle/Driver.h index 306287311..bfeeb1b16 100644 --- a/vehicle/Driver.h +++ b/vehicle/Driver.h @@ -198,6 +198,9 @@ static const bool Humandriver = false; static const int maxorders = 64; // ilość rozkazów w tabelce static const int maxdriverfails = 4; // ile błędów może zrobić AI zanim zmieni nastawienie extern bool WriteLogFlag; // logowanie parametrów fizycznych +// the physics logs of the trains only (physicslog.trains yes): of each driver of rail vehicles who drives them, not +// of the passengers nor of the vehicles of the roads +extern bool WriteTrainLogFlag; static const int BrakeAccTableSize = 20; static const int gbh_NP = -2; //odciecie w hamulcu ogolnym @@ -723,7 +726,10 @@ private: // methods // the line of the log, to PhysicsLogs (utilities/physicslog.h) void PhysicsLog(); + // its log begun anew, its file emptied and given the header + void begin_physicslog(); // members + bool PhysicsLogBegun = false; // its log was begun, by this driver double LastUpdatedTime = 0.0; // czas od ostatniego logu double ElapsedTime = 0.0; // czas od poczatku logu @@ -736,6 +742,10 @@ public: // user is in, to write its log at the end when the logs of all the vehicles are off std::string const &physicslog_name() const { return VehicleName; } + // whether it writes its physics log itself: all with "physicslog yes", with "physicslog.trains yes" one who drives + // rail vehicles. a driver made primary later begins its log then + bool writes_physicslog() const { + return WriteLogFlag || ( WriteTrainLogFlag && is_train() && primary() ); } static std::string_view physicslog_header(); std::string physicslog_line() const; TDynamicObject *Vehicle( end const Side ) const {