apply_isolated() set every isolated section to the count of the snapshot, also where a
vehicle the load left at its scenery place (misplaced, forced load, road traffic not put
back) stands, or where the snapshot had it. The axles of those vehicles are now counted in
the sections they stand in and out of the ones the snapshot has them in, and the memory
cells of those sections say whether they are taken by that count.
An AI consist doesn't end on a vehicle the load left: the ends are then found along what is
coupled now, as CheckVehicles() finds them.
The player entry no longer writes the cab, which nothing read: the cab is the one the
vehicle has occupied (caboccupied of its entry).
Since #552 the state of physics::Vehicle and of its parts is private, and since #531 the vehicle, the AI
and the cab live in other files under other names. The snapshot code is ported to that:
- the state of a vehicle's physics is saved and loaded by physics::Vehicle::SnapshotSave() and
SnapshotLoad() (physics/components/snapshot.cpp), with the tables of the variables in a nested
snapshot_members; capture_mover() and apply_mover() only hand it the entry. The parts with private
state (low voltage, line breaker, line contactors, protective relays, converter, air of the
pantographs, compressor, air supply) give a plain Snapshot of it and take it back
(TakeSnapshot(), RestoreSnapshot()); the rest goes through their queries and setters
- the keys, their order and the numbers in them are unchanged, so the snapshots written before load:
the fields that moved into the parts are mapped there (Mains to lineBreaker, PipePress to brakePipe,
BrakeCtrlPos to brakes, dizel_* to diesel, hydro_* to torqueConverter and retarder, eimv to
inductionMotor.state in the order of the old table, EngDmgFlag to equipmentFaults, ...)
- TDynamicObject: the machinery of a vehicle (sections, rail joints, the passenger exchange) is saved
by members of its own, as these are private now; MED_oldFED is the last ED demand of the consist's
brake blending (ConsistBrakeBlending::LastElectrodynamicDemand())
- TController: the driving flags are saved as the bits of iDrivigFlags they were, the running brake
test as the number of its stage, the uphill start and the braking shortfall from their structs;
StaticBrakeTest, which is gone, is written as 0 and not read
- the couplings take Coupling, CouplingSet and VehicleEnd; orders are DriverOrders
- the unit tests of the snapshot of a vehicle use the queries and the parts
Cars of the road spawn points which a snapshot has on the road are no longer put back: the spawn point owns
them and the snapshot would leave them frozen on the track. They're counted in the log. The pooled cars keep
their AI drivers, which the snapshot used to delete.
A snapshot whose scenery fingerprint differs is refused unless --load-snapshot-force is given: tracks named
"#N" shift when a track is added. Each vehicle is checked against the x/y/z of its entry after placing. One
more than 1 m off, or one which can't be placed, goes back where the scenery put it, isn't coupled to the
placed vehicles, and keeps its scenery state and driver.
Couplings set from a snapshot keep to CompatibleCoupling, so no MU control between an electric and a diesel
loco (#520).
The snapshotsave key writes to snapshotsdir of eu07.ini (snapshots by default, ini only like screenshotsdir),
adds _2, _3... to a name that is taken, and shows where the file went.
No declaration shadows an enumerator, the variables used only by a
condition are declared in it, write_file takes its writer as a template,
the temporary file is a std::filesystem::path, the isolated sections are
looked up by a transparent hash, apply_couplings is split into helpers,
and the copies of the simulation's random engine are marked NOSONAR.
The test data has no http:// in it. No snapshot key or format changes.
A damaged or edited snapshot could put an index past a table, a count
which takes forever or a number out of the range of its type into the
simulation, and a file cut short was put back half way.
- Reading a value: a whole number has to be whole and fit its type (an
enum its underlying one), a float can't be past its largest value; what
doesn't fit is refused. Every refusal names the entry, the key and the
value, and goes to the log (errors.txt), up to 100 lines and a count.
- Ranges: coupler ends 0 or 1 and the flags of a coupling; couplings which
would close a ring of vehicles; the count of the points of a driver's
table and of its point limits (not past the keys of the entry), the
indices into the table (tablelast, semnext, semnextstop); the order
stack and its position, the timetable station, the driver's enums and
directions; the path, events and distance of an axle, facing and first
axle; the date and time; switch states, made track ends, crossing
segments, event siblings and times, launcher timers, the weather; the
load (amount, and a name which isn't a path); the whole numbers inside
number lists (flags of a table point, the stop of a coupler pair, the
track flags under a vehicle, the fuse count of a power source, the cab
of the vigilance device).
- The positions of the controllers are brought within the ranges of the
vehicle: master and secondary controller (set and actual), reverser,
cabs, light, compressor and wiper switches, brake handle, hand brake,
dimmer.
- A document with problems isn't loaded unless --load-snapshot-force says
so; a test run ends with the error code then. The header counts the
entries, so a file cut between two entries is found too. A file of a
newer version is a warning, not a problem.
- A snapshot is written to <file>.tmp and renamed over the file only when
the stream didn't fail.
- Unit tests of the reader on damaged input.
The scenery counts the axles of every vehicle in the isolated sections of
the tracks it puts it on. A vehicle the snapshot has as removed was only
taken off the list of its track, so its two axles stayed counted there and
the section never went free again: the next train on it went 4-6-4 axles
instead of 0-2-0, and its busy and free events never fired.
- A removed vehicle counts both axles out of the sections of their tracks,
is taken off the list of its track only if it's on it, and has no owner.
- The drivers a snapshot doesn't have are deleted as before, and no
vehicle keeps its owner pointing at one of them.
- The snapshot keeps the count of every isolated section and sets it after
the vehicles are placed: the vehicles a consist leaves behind as it goes
through a portal stay counted where they were, in the game too. A count
the placing gives other than the snapshot has is told in the log.
- A vehicle with two entries is placed once.
- TIsolated::axles() reads and sets the count.
- The harness compares the counts of the sections; a new case,
snapshot_td_portal_isolated, has a train leave through a portal from the
track of a section before the snapshot.
Writes a snapshot of the simulation to snapshots/<scenery>_<date>_<time>.snapshot
in the game folder. The command is the last one of the list, so the numbers of
the others stay.
A driver is kept with its orders and the one it is on, the name of its
timetable and its place in it, the consist it has, what it holds to (speeds of
signals and limits, the reason it stands, its timers and flags), its table of
what is ahead on the track with the point limits it has latched, its tables of
what the brake of the consist gives, and whether the AI drives. A driver who
had moved to another vehicle of its train is moved there.
A run loaded in ghost view (the test mode) is ready before its first frame, as
the run it goes on from was.
The snapshot also names the vehicle the player was in, which --load-snapshot
starts in unless -v says otherwise.
Every vehicle is kept with the place of both its axles (track, distance,
direction, path of a switch, events still to set off), the way it faces, its
couplings with their flags, destination and, through its physics, speed and
load. Loaded, the vehicles are put straight where they were
(TTrackFollower::Place(), which trails no switch and fires no event), then
parted and joined until they are coupled as saved, whatever trainsets the
scenery made of them.
A vehicle of the snapshot the scenery does not have is skipped and reported,
one the snapshot does not know stays as the scenery made it, one which had left
the simulation is taken out again.
--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.