diff --git a/blackbox_doc.md b/blackbox_doc.md index 3573b4271..8b4e23e0f 100644 --- a/blackbox_doc.md +++ b/blackbox_doc.md @@ -30,7 +30,8 @@ for a while doesn't lose its lines: they are written once it can be, the last 64 The recording starts once the scenery is loaded and ends when the simulator closes. Going into the editor (F11) ends it too, since the editor may take away the tracks and the vehicles it refers to; no -new one starts when driving goes on after that. +new one starts when driving goes on after that. The `.dat` logs it gives with the physics logs off go on +then, after the gap of the time in the editor, until the simulator closes: they are files of their own. It is written as the session goes and flushed once a second, so the file can be read while the simulator still writes it, and after a crash all but the last second is there. A file without the `end` record diff --git a/simulation/blackboxrecorder.cpp b/simulation/blackboxrecorder.cpp index 6d0f76502..efd92c3fc 100644 --- a/simulation/blackboxrecorder.cpp +++ b/simulation/blackboxrecorder.cpp @@ -238,22 +238,26 @@ void blackbox_recorder::update(double const Deltatime) { // "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 || WriteTrainLogFlag) || Global.editor_session) return; + m_taping = true; open(); } - if (m_writer == nullptr) + if (false == m_taping) return; std::scoped_lock lock{m_mutex}; m_time += Deltatime; - if (m_time >= m_cabdue) { - write_cab(); - m_cabdue = std::max(m_cabdue + cabinterval, m_time); - } - // with the physics logs on, each driver writes its own all the time + // with the physics logs on, each driver writes its own all the time. the tapes are files of their own: they go on + // after the recording ends in the editor, and with a recording which couldn't be made if (false == WriteLogFlag && m_time >= m_tapedue) { keep_tape_line(); m_tapedue = std::max(m_tapedue + tapeinterval, m_time); } + if (m_writer == nullptr) + return; + if (m_time >= m_cabdue) { + write_cab(); + m_cabdue = std::max(m_cabdue + cabinterval, m_time); + } if (m_time >= m_cameradue) { write_camera(); m_cameradue = std::max(m_cameradue + camerainterval, m_time); diff --git a/simulation/blackboxrecorder.h b/simulation/blackboxrecorder.h index 67742b24e..a3aaf5d0f 100644 --- a/simulation/blackboxrecorder.h +++ b/simulation/blackboxrecorder.h @@ -32,13 +32,14 @@ enum class user_command; namespace simulation { // the black box of the session (see blackbox_doc.md): written along with the physics logs, in driver mode, -// from the moment the scenario is loaded until the simulator closes or the editor is entered +// from the moment the scenario is loaded until the simulator closes or the editor is entered. the tapes of the user's +// vehicles, with the physics logs off, go on after the editor until the simulator closes class blackbox_recorder { public: // starts the recording once the scenario is ready, if it is to be made, then records what is due. // Deltatime: simulation time passed since the last call void update(double Deltatime); - // writes the end of the recording and closes the file. a recording closed isn't started again + // writes the end of the recording and closes the file. a recording closed isn't started again; its tapes go on void close(); // what happens between the looks, from wherever it happens; the cabs may run on threads of their own. @@ -112,6 +113,7 @@ private: std::ofstream m_file; std::unique_ptr m_writer; bool m_started{false}; // tried to start, made or not + bool m_taping{false}; // the recording was to be made: its tapes are kept from then on, the file made or not, closed or not double m_time{0.0}; double m_cabdue{0.0}; double m_tapedue{0.0};