18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-21 02:44:58 +01:00

feat(physicslog): the logs written every two seconds by a thread of their own, no file kept open; the black box's tapes as it goes

"physicslog yes" kept the .dat of every vehicle with a driver open for the whole run and flushed it twenty
times a second from the simulation's thread: some 580 open files on Tomaszewo. The lines are kept now and a
thread of their own writes them every two seconds, each file opened only for the moment it is written to.
The files, their lines and their text mode stay as they were.

- The black box, with the physics logs off, writes the tapes of the user's vehicles through the same
  writer as it goes, not at the end. A log begins when the user is first in the vehicle and goes on
  while the user looks around outside, until another vehicle is taken; back in it, the log goes on after
  the gap. The vehicle's own driver keeps the log only if it is the primary one, as a passive one's clock
  stands still; otherwise the driver of its train does.
- What is kept is written when the simulator closes, after the black box, at the end of a test run, and
  when the test watchdog ends a run. A crash loses the last two seconds.
- On Tomaszewo with the black box alone, the one tape grows every two seconds. With "physicslog yes", the
  581 logs grow and the simulator holds as many handles as without them; writing them takes the thread
  about 1.9 s, which the closing waits for once.
This commit is contained in:
maj00r
2026-11-14 00:48:17 +01:00
parent 5ca2f7e38f
commit 03a3b4c09a
12 changed files with 347 additions and 61 deletions

View File

@@ -546,6 +546,7 @@ set(CORE_SOURCES
"scripting/scriptscreendrawing.cpp" "scripting/scriptscreendrawing.cpp"
"simulation/simulationtestrules.cpp" "simulation/simulationtestrules.cpp"
"vehicle/blackbox.cpp" "vehicle/blackbox.cpp"
"utilities/physicslog.cpp"
"vehicle/enginestart.cpp" "vehicle/enginestart.cpp"
"vehicle/brakesetting.cpp" "vehicle/brakesetting.cpp"
"vehicle/handover.cpp" "vehicle/handover.cpp"

View File

@@ -22,6 +22,7 @@ Stele, firleju, szociu, hunter, ZiomalCl, OLI_EU and others
#include "simulation/simulationtest.h" #include "simulation/simulationtest.h"
#include "utilities/Globals.h" #include "utilities/Globals.h"
#include "utilities/Logs.h" #include "utilities/Logs.h"
#include "utilities/physicslog.h"
#include <cstdlib> #include <cstdlib>
#include <exception> #include <exception>
#include <string_view> #include <string_view>
@@ -112,6 +113,8 @@ void finish_log()
[[noreturn]] void end_test_run(std::string_view const Reason) [[noreturn]] void end_test_run(std::string_view const Reason)
{ {
simulation::test().conclude(simulation::test_result::error, Reason); simulation::test().conclude(simulation::test_result::error, Reason);
// the last two seconds of the physics logs, which the runner of the tests reads
PhysicsLogs.stop();
finish_log(); finish_log();
fflush(stdout); fflush(stdout);
fflush(stderr); fflush(stderr);
@@ -141,10 +144,10 @@ void finish_log()
end_test_run("the simulator stopped before the test ended"); end_test_run("the simulator stopped before the test ended");
} }
// every vehicle with a driver keeps its physics log open for the whole run, and on a scenery with some five hundred // the physics logs used to keep a file open for every vehicle with a driver, and on a scenery with some five hundred
// of them the logs took all the files the C library of Windows lets a process have open by default (512): the // of them they took all the files the C library of Windows lets a process have open by default (512): the files
// files opened after them, the shaders of the map among them, couldn't be read. so the limit is raised to the most // opened after them, the shaders of the map among them, couldn't be read. they keep none open now (physicslog.h),
// either system allows // but the limit is raised to the most either system allows still, for whatever else opens many files at once
void raise_open_files_limit() void raise_open_files_limit()
{ {
#ifdef _WIN32 #ifdef _WIN32

View File

@@ -34,6 +34,7 @@ http://mozilla.org/MPL/2.0/.
#include "utilities/dictionary.h" #include "utilities/dictionary.h"
#include "version_info.h" #include "version_info.h"
#include "simulation/simulationtest.h" #include "simulation/simulationtest.h"
#include "utilities/physicslog.h"
#include <chrono> #include <chrono>
#include <format> #include <format>
#include <vector> #include <vector>
@@ -745,6 +746,9 @@ void eu07_application::exit()
track_sleepers::stop_background(); track_sleepers::stop_background();
step("the black box"); step("the black box");
simulation::Blackbox.close(); simulation::Blackbox.close();
step("the physics logs");
// what is kept of them, the black box's written last
PhysicsLogs.stop();
step("the modes"); step("the modes");
for (auto &mode : m_modes) for (auto &mode : m_modes)
mode.reset(); mode.reset();

View File

@@ -12,12 +12,15 @@ starter, a viewer) can replay the session on the map, or set the user's driving
editor session. The file goes to `physicslog/<scenery>_<YYYY-MM-DD_HH-MM-SS>.blackbox` (the local time the editor session. The file goes to `physicslog/<scenery>_<YYYY-MM-DD_HH-MM-SS>.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. recording started at), next to the `.dat` logs of the vehicles when those are on; they stay as they are.
With the physics logs off it still gives the `.dat` log of each vehicle the user was in, written when the With the physics logs off it still gives the `.dat` log of each vehicle the user was in, as it goes:
recording ends: `physicslog/<vehicle>.dat`, the same file name, the same columns and the same line every `physicslog/<vehicle>.dat`, the same file name, the same columns and the same line every 0.05 s as
0.05 s as `physicslog yes` would write, but only of the times the user was there. A vehicle with no driver `physicslog yes` would write. A log begins when the user first is in the vehicle, and goes on while the
of its own takes the log of the driver of its train. So the speed recorder's tape can be read from them as user looks around outside it, until the user takes another vehicle, whose log begins then. Back in a
before, without the simulator keeping a log of every vehicle open all the time. A simulator that crashes vehicle, its log goes on after the gap in its time. A vehicle with no driver of its own takes the log of the
leaves the recording, but not these logs. 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
two seconds, each file opened only for the moment it is written to; a crash loses the last two seconds
of them.
The recording starts once the scenery is loaded and ends when the simulator closes. Going into the 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 editor (F11) ends it too, since the editor may take away the tracks and the vehicles it refers to; no

View File

@@ -23,6 +23,7 @@ http://mozilla.org/MPL/2.0/.
#include "world/Track.h" #include "world/Track.h"
#include "utilities/Globals.h" #include "utilities/Globals.h"
#include "utilities/Logs.h" #include "utilities/Logs.h"
#include "utilities/physicslog.h"
#include "utilities/utilities.h" #include "utilities/utilities.h"
#include <algorithm> #include <algorithm>
@@ -280,7 +281,6 @@ void blackbox_recorder::close() {
m_writer->end(m_time); m_writer->end(m_time);
m_writer.reset(); m_writer.reset();
m_file.close(); m_file.close();
write_tapes();
using milliseconds = std::chrono::duration<double, std::milli>; using milliseconds = std::chrono::duration<double, std::milli>;
WriteLog(std::format("Black box: recording closed; {} looks around, {:.3f} ms each on average, the longest {:.3f} ms", m_looks, WriteLog(std::format("Black box: recording closed; {} looks around, {:.3f} ms each on average, the longest {:.3f} ms", m_looks,
m_looks > 0 ? milliseconds{m_looktime}.count() / m_looks : 0.0, milliseconds{m_looklongest}.count())); m_looks > 0 ? milliseconds{m_looktime}.count() / m_looks : 0.0, milliseconds{m_looklongest}.count()));
@@ -492,30 +492,16 @@ void blackbox_recorder::keep_tape_line() {
return; return;
auto const *vehicle{train->Dynamic()}; auto const *vehicle{train->Dynamic()};
// the driver of the vehicle, whose log it would be: it keeps the name of its first vehicle, so a change of the cab // the driver of the vehicle, whose log it would be: it keeps the name of its first vehicle, so a change of the cab
// in a unit goes on in the same log. in a vehicle without one, the driver of its train // in a unit goes on in the same log. a passive one stands still (its clock too), so then the driver of the train
auto const *driver{vehicle->Mechanik != nullptr ? vehicle->Mechanik : vehicle->ctOwner}; auto const *driver{vehicle->Mechanik != nullptr && vehicle->Mechanik->primary() ? vehicle->Mechanik : vehicle->ctOwner};
if (driver == nullptr) if (driver == nullptr)
return; return;
m_tapes[driver->physicslog_name()] += driver->physicslog_line(); auto const &name{driver->physicslog_name()};
} if (m_tapes.insert(name).second) {
PhysicsLogs.begin(name, TController::physicslog_header());
void blackbox_recorder::write_tapes() { WriteLog(std::format("Black box: the physics log \"physicslog/{}.dat\" begun", name));
for (auto const &[name, lines] : m_tapes) {
// opened as the driver opens its log, so the file is the same to the byte
auto const filename{"physicslog/" + name + ".dat"};
std::fstream file{filename, std::ios::in | std::ios::out | std::ios::trunc};
if (false == file.is_open()) {
ErrorLog(std::format("Black box: can't create the physics log \"{}\"", filename));
continue;
}
file << TController::physicslog_header() << lines;
file.close();
if (file.fail())
ErrorLog(std::format("Black box: the physics log \"{}\" wasn't written whole", filename));
else
WriteLog(std::format("Black box: the physics log \"{}\" written from the recording", filename));
} }
m_tapes.clear(); PhysicsLogs.append(name, driver->physicslog_line());
} }
void blackbox_recorder::look_around(bool const Keyframe) { void blackbox_recorder::look_around(bool const Keyframe) {

View File

@@ -15,9 +15,9 @@ http://mozilla.org/MPL/2.0/.
#include <chrono> #include <chrono>
#include <cstdint> #include <cstdint>
#include <fstream> #include <fstream>
#include <map>
#include <memory> #include <memory>
#include <mutex> #include <mutex>
#include <set>
#include <string> #include <string>
#include <unordered_map> #include <unordered_map>
#include <utility> #include <utility>
@@ -87,10 +87,10 @@ private:
void write_map(); void write_map();
static std::vector<std::pair<glm::dvec3, float>> stop_point_headings(); static std::vector<std::pair<glm::dvec3, float>> stop_point_headings();
void write_cab(); void write_cab();
// with the physics logs off, the line of the log of the driver the user is with, kept for the end // with the physics logs off, the line of the log of the driver the user is with, to its log, physicslog/<vehicle>.dat,
// as the physics logs would have it. a log is begun at the first line of the recording, and goes on while the user
// looks around outside, until the user takes another vehicle; back in the vehicle, it goes on after the gap
void keep_tape_line(); void keep_tape_line();
// the kept lines, each driver's to its log, physicslog/<vehicle>.dat, as the physics logs would have it
void write_tapes();
// the clock, the user's vehicle, the vehicles, the switches and the signals // the clock, the user's vehicle, the vehicles, the switches and the signals
void look_around(bool Keyframe); void look_around(bool Keyframe);
void look_at_vehicles(bool Keyframe); void look_at_vehicles(bool Keyframe);
@@ -115,8 +115,8 @@ private:
double m_time{0.0}; double m_time{0.0};
double m_cabdue{0.0}; double m_cabdue{0.0};
double m_tapedue{0.0}; double m_tapedue{0.0};
// the lines of the physics log by the name of its file, of the times the user was with its driver // the names of the logs begun by the recording
std::map<std::string, std::string> m_tapes; std::set<std::string> m_tapes;
double m_lookdue{0.0}; double m_lookdue{0.0};
double m_keyframedue{0.0}; double m_keyframedue{0.0};
std::unordered_map<TDynamicObject const *, vehicle_entry> m_vehicles; std::unordered_map<TDynamicObject const *, vehicle_entry> m_vehicles;

View File

@@ -15,6 +15,7 @@ http://mozilla.org/MPL/2.0/.
#include "simulation/simulation.h" #include "simulation/simulation.h"
#include "utilities/Globals.h" #include "utilities/Globals.h"
#include "utilities/Logs.h" #include "utilities/Logs.h"
#include "utilities/physicslog.h"
#include "utilities/utilities.h" #include "utilities/utilities.h"
#include "vehicle/DynObj.h" #include "vehicle/DynObj.h"
#include "world/Event.h" #include "world/Event.h"
@@ -262,6 +263,7 @@ void test_manager::check_wall_clock(double const Elapsed)
if (false == conclude(test_result::timeout, std::format("still running after {:.0f} s of real time (test.wall_timeout)", limit))) if (false == conclude(test_result::timeout, std::format("still running after {:.0f} s of real time (test.wall_timeout)", limit)))
ErrorLog(std::format("test: the simulator was still running {:.0f} s of real time after the start, ended", limit)); ErrorLog(std::format("test: the simulator was still running {:.0f} s of real time after the start, ended", limit));
// what was logged last gets written, unless the log is held up by a hung thread // what was logged last gets written, unless the log is held up by a hung thread
PhysicsLogs.flush();
StopLogService(); StopLogService();
std::this_thread::sleep_for(std::chrono::milliseconds(250)); std::this_thread::sleep_for(std::chrono::milliseconds(250));
std::_Exit(exit_code()); std::_Exit(exit_code());

View File

@@ -0,0 +1,131 @@
#include "stdafx.h"
#include "doctest.h"
#include "utilities/physicslog.h"
#include <chrono>
#include <filesystem>
#include <format>
#include <fstream>
#include <sstream>
#include <string>
#include <system_error>
#include <thread>
// the physics logs are kept and written by a thread of their own every so often, each file opened only to be written to
namespace {
// a folder of its own for the logs of a test, in the build folder of the tests, removed with the object. the writer
// makes it itself
class log_folder {
public:
explicit log_folder(std::string const &Name) : m_path{std::filesystem::path{EU07_UNIT_TESTS_SCRATCH} / std::format("eu07_physicslog_test_{}", Name)} {
std::filesystem::remove_all(m_path);
}
~log_folder() {
std::error_code error;
std::filesystem::remove_all(m_path, error);
}
log_folder(log_folder const &) = delete;
log_folder &operator=(log_folder const &) = delete;
std::filesystem::path const &path() const { return m_path; }
// the log as it stands, read in text mode as it is written: what was given to it
std::string read(std::string const &Name) const {
std::ifstream file{m_path / (Name + ".dat")};
if (false == file.is_open())
return {};
std::ostringstream text;
text << file.rdbuf();
return text.str();
}
// waits up to five seconds for the log to read Text
bool reads(std::string const &Name, std::string const &Text) const {
auto const until{std::chrono::steady_clock::now() + std::chrono::seconds{5}};
while (read(Name) != Text && std::chrono::steady_clock::now() < until)
std::this_thread::sleep_for(std::chrono::milliseconds{10});
return read(Name) == Text;
}
private:
std::filesystem::path m_path;
};
constexpr auto header{"Time[s] Velocity[m/s]\r\n"};
} // namespace
TEST_CASE("physicslog: a log begun is emptied and given its header, and its lines follow it at each writing") {
log_folder folder{"begin"};
physicslog_writer logs{folder.path(), std::chrono::hours{1}};
logs.begin("EU07-424", header);
logs.append("EU07-424", "0.0500 0.0000\r\n");
CHECK(folder.read("EU07-424").empty());
logs.flush();
CHECK(folder.read("EU07-424") == std::string{header} + "0.0500 0.0000\r\n");
logs.append("EU07-424", "0.1000 1.5000\r\n");
logs.flush();
CHECK(folder.read("EU07-424") == std::string{header} + "0.0500 0.0000\r\n0.1000 1.5000\r\n");
// begun again: the lines not written yet are dropped along with those written
logs.append("EU07-424", "0.1500 3.0000\r\n");
logs.begin("EU07-424", header);
logs.flush();
CHECK(folder.read("EU07-424") == header);
}
TEST_CASE("physicslog: no file is kept open between the writings, and a log not begun is added to as it stands") {
log_folder folder{"closed"};
physicslog_writer logs{folder.path(), std::chrono::hours{1}};
logs.begin("SM42-001", header);
logs.flush();
// Windows doesn't let a file open in a program be removed
std::error_code error;
CHECK(std::filesystem::remove(folder.path() / "SM42-001.dat", error));
CHECK_FALSE(error);
logs.append("SM42-001", "0.0500 0.0000\r\n");
logs.flush();
CHECK(folder.read("SM42-001") == "0.0500 0.0000\r\n");
}
TEST_CASE("physicslog: the thread writes the logs by itself") {
log_folder folder{"thread"};
physicslog_writer logs{folder.path(), std::chrono::milliseconds{20}};
logs.begin("ET22-001", header);
logs.append("ET22-001", "0.0500 0.0000\r\n");
CHECK(folder.reads("ET22-001", std::string{header} + "0.0500 0.0000\r\n"));
logs.append("ET22-001", "0.1000 0.0000\r\n");
CHECK(folder.reads("ET22-001", std::string{header} + "0.0500 0.0000\r\n0.1000 0.0000\r\n"));
}
TEST_CASE("physicslog: stopping writes what is kept at once, and what comes after waits for a writing") {
log_folder folder{"stop"};
physicslog_writer logs{folder.path(), std::chrono::hours{1}};
logs.begin("EN57-1001", header);
logs.append("EN57-1001", "0.0500 0.0000\r\n");
logs.stop();
CHECK(folder.read("EN57-1001") == std::string{header} + "0.0500 0.0000\r\n");
logs.append("EN57-1001", "0.1000 0.0000\r\n");
std::this_thread::sleep_for(std::chrono::milliseconds{50});
CHECK(folder.read("EN57-1001") == std::string{header} + "0.0500 0.0000\r\n");
logs.flush();
CHECK(folder.read("EN57-1001") == std::string{header} + "0.0500 0.0000\r\n0.1000 0.0000\r\n");
}
TEST_CASE("physicslog: what is kept is written when the writer goes") {
log_folder folder{"end"};
{
physicslog_writer logs{folder.path(), std::chrono::hours{1}};
logs.begin("ST44-001", header);
logs.append("ST44-001", "0.0500 0.0000\r\n");
}
CHECK(folder.read("ST44-001") == std::string{header} + "0.0500 0.0000\r\n");
}

98
utilities/physicslog.cpp Normal file
View File

@@ -0,0 +1,98 @@
/*
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/.
*/
#include "stdafx.h"
#include "utilities/physicslog.h"
#include "utilities/Logs.h"
#include <fstream>
#include <system_error>
#include <utility>
physicslog_writer PhysicsLogs;
physicslog_writer::physicslog_writer(std::filesystem::path Folder, std::chrono::milliseconds const Interval) : m_folder{std::move(Folder)}, m_interval{Interval} {}
physicslog_writer::~physicslog_writer() {
stop();
}
void physicslog_writer::begin(std::string const &Name, std::string_view const Header) {
std::scoped_lock lock{m_mutex};
auto &lines{m_pending[Name]};
lines.fresh = true;
lines.text.assign(Header);
start();
}
void physicslog_writer::append(std::string const &Name, std::string_view const Line) {
std::scoped_lock lock{m_mutex};
m_pending[Name].text.append(Line);
start();
}
void physicslog_writer::flush() {
write();
}
void physicslog_writer::stop() {
{
std::scoped_lock lock{m_mutex};
m_stopped = true;
}
// started only before m_stopped was set, so no one else touches it now
if (m_thread.joinable()) {
m_thread.request_stop();
m_thread.join();
}
write();
}
void physicslog_writer::start() {
if (m_stopped || m_thread.joinable())
return;
m_thread = std::jthread([this](std::stop_token const &Stop) { run(Stop); });
}
void physicslog_writer::run(std::stop_token const &Stop) {
while (false == Stop.stop_requested()) {
{
std::unique_lock lock{m_mutex};
// woken early only to stop, which writes the rest itself
if (m_wake.wait_for(lock, Stop, m_interval, [] { return false; }) || Stop.stop_requested())
return;
}
write();
}
}
void physicslog_writer::write() {
std::scoped_lock files{m_filemutex};
std::map<std::string, pending> taken;
{
std::scoped_lock lock{m_mutex};
taken.swap(m_pending);
}
if (taken.empty())
return;
std::error_code error;
std::filesystem::create_directories(m_folder, error);
for (auto const &[name, lines] : taken) {
if (lines.text.empty() && false == lines.fresh)
continue;
auto const path{m_folder / (name + ".dat")};
// in text mode, as the logs were always written: on Windows their lines, which end with "\r\n", end with "\r\r\n"
std::ofstream file{path, lines.fresh ? std::ios::out | std::ios::trunc : std::ios::out | std::ios::app};
if (file.is_open())
file << lines.text;
file.close();
if (file.fail() && m_failed.insert(name).second)
ErrorLog("Bad physics log: can't write " + path.string());
}
}

67
utilities/physicslog.h Normal file
View File

@@ -0,0 +1,67 @@
/*
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 <chrono>
#include <condition_variable>
#include <filesystem>
#include <map>
#include <mutex>
#include <set>
#include <stop_token>
#include <string>
#include <string_view>
#include <thread>
// the physics logs, <folder>/<name>.dat. the lines given are kept, and written every two seconds by a thread of its
// own, each file opened only for the moment it is written to: the logs of hundreds of vehicles hold no files open, and
// the simulation doesn't wait for the disk. a crash loses the last two seconds of them
class physicslog_writer {
public:
explicit physicslog_writer(std::filesystem::path Folder = "physicslog", std::chrono::milliseconds Interval = std::chrono::seconds{2});
physicslog_writer(physicslog_writer const &) = delete;
physicslog_writer &operator=(physicslog_writer const &) = delete;
// stops, writing what is kept
~physicslog_writer();
// starts the log Name anew: its file is emptied and Header written into it, the next time the logs are written.
// the lines of it not written yet are dropped
void begin(std::string const &Name, std::string_view Header);
// Line at the end of the log Name. a log not begun is added to as its file stands
void append(std::string const &Name, std::string_view Line);
// writes what is kept, now
void flush();
// writes what is kept and ends the thread. what is given after is written by a flush, or at the end
void stop();
private:
struct pending {
bool fresh{false}; // its file is to be emptied first
std::string text;
};
// the thread, on the first line given, unless stopped. called with m_mutex held
void start();
void run(std::stop_token const &Stop);
void write();
std::filesystem::path const m_folder;
std::chrono::milliseconds const m_interval;
std::mutex m_mutex; // the lines kept and the thread
std::map<std::string, pending> m_pending;
bool m_stopped{false};
std::condition_variable_any m_wake;
std::jthread m_thread;
std::mutex m_filemutex; // the files are written one batch at a time, so the lines of a log stay in order
std::set<std::string> m_failed; // the logs whose file couldn't be written, told once
};
// the physics logs of the drivers (physicslog yes), and those the black box writes of the user's vehicles
extern physicslog_writer PhysicsLogs;

View File

@@ -18,6 +18,7 @@ http://mozilla.org/MPL/2.0/.
#include "utilities/Globals.h" #include "utilities/Globals.h"
#include "utilities/translation.h" #include "utilities/translation.h"
#include "utilities/Logs.h" #include "utilities/Logs.h"
#include "utilities/physicslog.h"
#include "vehicle/Train.h" #include "vehicle/Train.h"
#include "vehicle/brakesetting.h" #include "vehicle/brakesetting.h"
#include "vehicle/handover.h" #include "vehicle/handover.h"
@@ -2336,20 +2337,13 @@ TController::TController(bool AI, TDynamicObject *NewControll, bool InitPsyche,
TableClear(); TableClear();
if( WriteLogFlag ) { if( WriteLogFlag ) {
#ifdef _WIN32 // physicslog/<vehicle>.dat, written every two seconds along with the logs of the other drivers
CreateDirectory( "physicslog", nullptr);
#elif __unix__
mkdir( "physicslog", 0740 );
#endif
LogFile.open( std::string( "physicslog/" + VehicleName + ".dat" ),
std::ios::in | std::ios::out | std::ios::trunc );
#if LOGPRESS == 0 #if LOGPRESS == 0
LogFile << physicslog_header(); PhysicsLogs.begin( VehicleName, physicslog_header() );
#endif #endif
#if LOGPRESS == 1 #if LOGPRESS == 1
LogFile << string( "t\tVel\tAcc\tPP\tVVP\tBP\tBVP\tCVP" ).c_str() << "\n"; PhysicsLogs.begin( VehicleName, "t\tVel\tAcc\tPP\tVVP\tBP\tBVP\tCVP\n" );
#endif #endif
LogFile.flush();
} }
// HACK: give the simulation a small window to potentially replace the AI with a human driver // HACK: give the simulation a small window to potentially replace the AI with a human driver
@@ -2358,7 +2352,6 @@ TController::TController(bool AI, TDynamicObject *NewControll, bool InitPsyche,
TController::~TController() TController::~TController()
{ // wykopanie mechanika z roboty { // wykopanie mechanika z roboty
// LogFile is closed by its own destructor
}; };
// zamiana kodu rozkazu na opis // zamiana kodu rozkazu na opis
@@ -5407,21 +5400,19 @@ std::string TController::physicslog_line() const {
void TController::PhysicsLog() void TController::PhysicsLog()
{ // zapis logu - na razie tylko wypisanie parametrów { // zapis logu - na razie tylko wypisanie parametrów
if (LogFile.is_open())
{
#if LOGPRESS == 0 #if LOGPRESS == 0
LogFile << physicslog_line(); PhysicsLogs.append( VehicleName, physicslog_line() );
#endif #endif
#if LOGPRESS == 1 #if LOGPRESS == 1
LogFile << ElapsedTime << "\t" << fabs(11.31 * mvOccupied->WheelDiameter * mvOccupied->nrot) std::ostringstream line;
<< "\t"; line << ElapsedTime << "\t" << fabs(11.31 * mvOccupied->WheelDiameter * mvOccupied->nrot)
LogFile << Controlling->AccS << "\t"; << "\t";
LogFile << mvOccupied->PipePress << "\t" << mvOccupied->CntrlPipePress << "\t" line << mvControlling->AccS << "\t";
<< mvOccupied->BrakePress << "\t"; line << mvOccupied->PipePress << "\t" << mvOccupied->CntrlPipePress << "\t"
LogFile << mvOccupied->Volume << "\t" << mvOccupied->Hamulec->GetCRP() << "\n"; << mvOccupied->BrakePress << "\t";
line << mvOccupied->Volume << "\t" << mvOccupied->Hamulec->GetCRP() << "\n";
PhysicsLogs.append( VehicleName, line.str() );
#endif #endif
LogFile.flush();
}
}; };
void void

View File

@@ -721,9 +721,9 @@ private:
// logs // logs
// methods // methods
// the line of the log, to PhysicsLogs (utilities/physicslog.h)
void PhysicsLog(); void PhysicsLog();
// members // members
std::ofstream LogFile; // zapis parametrow fizycznych
double LastUpdatedTime = 0.0; // czas od ostatniego logu double LastUpdatedTime = 0.0; // czas od ostatniego logu
double ElapsedTime = 0.0; // czas od poczatku logu double ElapsedTime = 0.0; // czas od poczatku logu