mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-03 11:15:23 +01:00
feat(simulation): snapshot of time, weather, cells, switches and events (L1)
--snapshot-at <seconds> <file> writes a snapshot when the simulation has run that long, --load-snapshot <file> puts one over the scenery once it has loaded, before the first frame. This layer keeps the clock and the simulation timer, the weather with the wind, the random engine, the memory cells, the switches, the tracks an event can change and the ones made on the run, the traction power sources, the event queue, the timers of the launchers and the lamps of the signals. While a snapshot is put back the event manager is suspended, so nothing in the scenery reacts to it. Existing classes only get accessors for what was private (the fraction of the second, launcher timers, the speed limit of a track, the wind, the state of a power source, the event queue). Without the switches nothing changes.
This commit is contained in:
@@ -34,6 +34,7 @@ http://mozilla.org/MPL/2.0/.
|
||||
#include "utilities/dictionary.h"
|
||||
#include "version_info.h"
|
||||
#include "simulation/simulationtest.h"
|
||||
#include "simulation/simulationsnapshotworld.h"
|
||||
#include <chrono>
|
||||
#include <format>
|
||||
#include <vector>
|
||||
@@ -1219,6 +1220,15 @@ int eu07_application::init_settings(int Argc, char *Argv[])
|
||||
Global.test.wall_timeout_from_command_line = true;
|
||||
}
|
||||
|
||||
// the simulation snapshots to load and to take (--load-snapshot, --snapshot-at)
|
||||
auto const snapshotcommandline{simulation::snapshot::parse_command_line(std::vector<char const *>(Argv, Argv + Argc))};
|
||||
if (false == snapshotcommandline.error.empty())
|
||||
{
|
||||
std::cerr << snapshotcommandline.error << std::endl;
|
||||
simulation::test().conclude(simulation::test_result::error, snapshotcommandline.error);
|
||||
return -1;
|
||||
}
|
||||
|
||||
fs::path iniPath = user_config_path("eu07.ini");
|
||||
|
||||
// a test reads the settings of the game folder only (and those given with -ini), not the player's own
|
||||
@@ -1235,6 +1245,8 @@ int eu07_application::init_settings(int Argc, char *Argv[])
|
||||
// process command line arguments
|
||||
bool sceneryfromcommandline{false};
|
||||
bool editwithoutscenery{false};
|
||||
bool seedfromcommandline{false};
|
||||
bool vehiclefromcommandline{false};
|
||||
for (int i = 1; i < Argc; ++i)
|
||||
{
|
||||
|
||||
@@ -1253,6 +1265,7 @@ int eu07_application::init_settings(int Argc, char *Argv[])
|
||||
if (i + 1 < Argc)
|
||||
{
|
||||
Global.local_start_vehicle = ToLower(Argv[++i]);
|
||||
vehiclefromcommandline = true;
|
||||
}
|
||||
}
|
||||
else if (token == "-edit")
|
||||
@@ -1275,6 +1288,7 @@ int eu07_application::init_settings(int Argc, char *Argv[])
|
||||
if (i + 1 < Argc)
|
||||
{
|
||||
Global.random_seed = seed_of(Argv[++i]);
|
||||
seedfromcommandline = true;
|
||||
WriteLog(std::format("seed given on the command line: {} -> {}", Argv[i], Global.random_seed));
|
||||
}
|
||||
}
|
||||
@@ -1288,6 +1302,11 @@ int eu07_application::init_settings(int Argc, char *Argv[])
|
||||
// taken from the command line above, with its value
|
||||
++i;
|
||||
}
|
||||
else if (token == "--load-snapshot" || token == "--snapshot-at")
|
||||
{
|
||||
// taken from the command line above, with their values
|
||||
i += simulation::snapshot::option_value_count(token);
|
||||
}
|
||||
else if (token == "-ini")
|
||||
{
|
||||
// extra settings file read on top of eu07.ini, so a run can override a few keys
|
||||
@@ -1305,7 +1324,8 @@ int eu07_application::init_settings(int Argc, char *Argv[])
|
||||
<< " [-edit [sceneryfilepath]]"
|
||||
<< " [-seed number|word]"
|
||||
<< " [-ini settingsfile]"
|
||||
<< " [--test [--test-timeout seconds] [--test-wall-timeout seconds]]" << std::endl;
|
||||
<< " [--test [--test-timeout seconds] [--test-wall-timeout seconds]]"
|
||||
<< " [--load-snapshot file] [--snapshot-at seconds file]" << std::endl;
|
||||
simulation::test().conclude(simulation::test_result::error, std::format("unknown command line argument {}", token));
|
||||
return -1;
|
||||
}
|
||||
@@ -1313,6 +1333,17 @@ int eu07_application::init_settings(int Argc, char *Argv[])
|
||||
if (editwithoutscenery && false == sceneryfromcommandline)
|
||||
Global.SceneryFile.clear();
|
||||
|
||||
simulation::snapshot::request(snapshotcommandline);
|
||||
// the scenery of a snapshot loads the way it did when the snapshot was taken only with the seed it had then
|
||||
if (auto const seed{simulation::snapshot::requested_seed()}; seed.has_value() && false == seedfromcommandline)
|
||||
{
|
||||
Global.random_seed = *seed;
|
||||
WriteLog(std::format("seed taken from the snapshot to load: {}", Global.random_seed));
|
||||
}
|
||||
// and the player goes on in the vehicle they were in
|
||||
if (auto const vehicle{simulation::snapshot::requested_player_vehicle()}; false == vehicle.empty() && false == vehiclefromcommandline)
|
||||
Global.local_start_vehicle = vehicle;
|
||||
|
||||
if (Global.test.enabled)
|
||||
{
|
||||
if (false == sceneryfromcommandline || Global.SceneryFile.empty())
|
||||
|
||||
Reference in New Issue
Block a user