* feat(odometer): stamp the states with the day they were last updated, drop those not updated for a year
The odometer store kept every vehicle ever run. Each state now carries the
day it was last updated, written as a comment line "# updated <yyyy-mm-dd>"
before the states of that day, which the builds without the stamps skip.
A state with no stamp counts as updated the day it is read. A save drops
the states not updated for more than 365 days, those the other simulations
saved included. Refs #283.
* test(odometer): cover the stamps of the states and their expiry
* fix(odometer): a wrong clock doesn't drop the states, odometer.expiry sets the period
Review of #435. A stamp later than today was taken as today on every read, so a session with the clock set back
rewrote every state with that day, and the next session with the right clock dropped them all. The stamps are now
kept as written and a recorded state keeps its later day, so a day never goes back.
The expiry was measured from today, so a clock set forward, or the first save after a break of a year, dropped every
state not run in that session. It is now measured from the latest day of the states read at the start of the
session when that is earlier than today. The states this session records are stamped today, so the newest day of
the merged store would always be today in a save that writes.
The period is odometer.expiry <days> in eu07.ini, 365 unless set, 0 for never. A scenery's config block doesn't
change it, it would drop the player's states.
The states dropped are logged by the save that writes the file without them, not at every save while the write
fails. as_written() reads with the day given to save().
Two simulations sharing eu07_odometers.txt could lose a save: A reads the
file, B renames its file in, A renames its own over it. B had already
cleared its modified flag, so its next save returned at once and its
states stayed lost (known limit from the review of #283).
A write now leaves the store unconfirmed. The next save with nothing
recorded reads and merges the file as before, and writes again only when
the file lacks a state of the process, the same or newer by the merge
rule (compared as written, rounded to the file's digits). Otherwise the
store is confirmed and later saves return at once, as before. A process
holding an older state takes the file's one, so two processes settle
instead of rewriting each other.
HasDriverCab() decides by the BrakeHandle, which the DL2 draisine doesn't
have: its cab counter (distcounter: with offset 85) was never saved and
started from the .mmd offset each session. A vehicle is now also recorded
when a cab showed its odometer in the session (reading::shown: TTrain loaded
a cab model of it for a player, or bound a cab's counter to it) or when a
cab's counter seeded its state (origin::counter). The counter-seeded state is
saved as a known one, so the next session starts from it and keeps counting
whenever the counter is bound again.
the renderers of the units (elf_v1, impuls_v1) keep the unit's state, their cars are named after the unit and the
letter of the car (EN76-022a .. EN76-022d), so they drop the last character. the koliber screens of scripts/ keep
theirs in scripts/kilometry by the whole name, which wasn't read
every vehicle which ran got a line in the store, the wagons of the AI's trains in every scenario too. the store
records a vehicle with a driver's brake valve (BrakeHandle in the .fiz), which can show its odometer; the locomotives
and units the AI runs before a player's cab loads them still get in with their replaceable made up states. the
states already in the file stay as they are
the autotests (--test, Global.test.enabled) run the vehicles of the player's game: their odometers count from the
legacy or made up states in a store of their own, and nothing is written to eu07_odometers.txt
- each process writes its own <file>.<pid>.tmp and renames it in place; before writing it re-reads the file and
merges it per vehicle (a known state beats a made up one, else the larger one, never the sum)
- a state counted from a made up one is saved as ~<km> and the .mmd counter offset still replaces it later
- a vehicle removed from the scenery has its odometer recorded right away
Sonar (S5443) flags the shared temporary directory; the tests now use one
in their working directory. Also makes the scratch directory non-copyable
and spells out the optional checks Sonar asked about.
Every vehicle gets an odometer (TMoverParameters::Odometer) counting along
with the per-session DistCounter, starting from its state saved in
eu07_odometers.txt in the user's settings directory, else from the file a
python screen kept it in (kilometry/<name>_przebieg.txt), else from a state
made up from the vehicle name. The store is saved every minute of
simulation time and on closing.
The cab's distcounter: gauge shows the odometer; its .mmd offset seeds a
vehicle with no known state. Python screens get it as
state["odometer_total"]; state["odometer"] stays the session distance the
logbook and mirror scripts count differences of.