18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-03 17:04:52 +01:00

437 Commits

Author SHA1 Message Date
maj00r 35cafe9de5 fix(audio): the rails stop singing when the editor opens, nor sing in the test mode; Sonar of #584
- driver_mode::push_editor() stops the singing before the editor is pushed, by F11 and by the edit session. push_mode()
  doesn't call exit() of the mode it covers, so the loops went on playing in the editor. Back in the driver mode the
  next update scans the rails again.
- The sound of the singing isn't made in the test mode, which has no sound (enter() skips begin()); update() is under
  the test-mode guard of staging since the merge.
- sound.railsinging.nearboost: a train within 40 m is louder by it, one at 40-100 m by a part of it growing as it comes,
  as closeness() has it; the comment said within 100 m.
- Sonar, the values unchanged: the measured levels written as floats (each the same float as before, checked for all
  232), the centres of the sixths of an octave counted in a while loop, CTAD, try_emplace, the flag of the sound made with
  the default ordering, an if without a variable, using enum in a test. The std::mt19937 of the noise is NOSONAR: the
  noise of a sound, the same for a seed on every compiler.
2026-12-02 18:33:09 +01:00
maj00r fbf4e0b03e Merge remote-tracking branch 'origin/staging' into feat/rail-singing
# Conflicts:
#	application/drivermode.cpp
2026-12-02 18:13:21 +01:00
jerrrrycho ed8708c5e2 feat(simulation): snapshots, save the state of a running scenery and load it back (stage A) (#420)
* feat(simulation): text format of simulation snapshots

A snapshot of a running simulation is a text file in the syntax of the scenery
files: entries of the form <type> <name> <key> <value> ... end<type>, the first
one a header which names the scenery. This is the text alone: entries, writer,
reader, the names of the things of a scenery, the plan of coupling changes and
the command line switches (--load-snapshot, --snapshot-at), in the core library
with unit tests. Nothing reads or writes a snapshot yet.

* 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.

* feat(simulation): state of a vehicle's physics for snapshots (L3, core)

What TMoverParameters holds of a running vehicle, to and from an entry of a
snapshot: speed, load, controls, switches and relays, pantographs, doors,
engine and its cooling, the air of the pipes, of every reservoir of the brake
valve (with the flow it has yet to take in) and of the chambers of the driver's
valves, the vigilance device, the power circuits. In the core library, tested
on the real vehicle definitions: a
vehicle restored on a fresh one saves the same, and runs on next to the one it
was saved from.

The brake valves, the driver's valves and the vigilance device get accessors
for their private state (reservoirs(), latches(), pressures(), state()), a
reservoir one for the flow it has yet to take in; nothing else in the physics
changes. This comes before the vehicles of the scenery (L2), whose
speed and load are kept by it.

* feat(simulation): snapshot of vehicles and consists (L2)

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.

* feat(simulation): pantographs and passenger exchange in snapshots (L3)

What a vehicle keeps of its machinery beside its physics: the arms of the
pantographs as they stand under the wire, the time without voltage, the
passengers getting on and off, the lighting of the compartments, the headlight
toggles, the last force asked of the electrodynamic brake.

* feat(simulation): snapshot of the drivers and of the player's vehicle (L4)

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.

* feat(simulation): snapshotsave command, on [Ctrl]+[Shift]+[F9]

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.

* test: scenario cases which load a simulation snapshot and compare the run

A case with a "snapshot" section runs its scenery to a time, taking snapshots
on the way and at the end, then again from the first snapshot, and compares the
two ends: positions, speeds, pressures, couplings, cells, switches, drivers.
The snapshot saved right after loading has to be the one loaded.
tests/scenarios/snapshots.py reads the format and tells two snapshots apart.
The switches and the format are described in tests/scenarios/README.md.

* fix(simulation): a vehicle gone in the snapshot leaves its isolated sections

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.

* fix(simulation): every value of a snapshot file is checked before it's used

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.

* feat(simulation): the pullee mode and the holding brake timer in snapshots

Of what #419 and #424 added to TMoverParameters, two are state: PulleeMode
(prepared for being hauled dead; the scenery sets it, PulleeModeSwitch()
can change it) and StopBrakeReleaseTimer (how long power has been asked
for, which lets the holding brake of a unit go after its delay). Both are
kept now, as "pulleemode" and "stopbrakereleasetimer". The others
(PressureSwitchBrakeCylinder, EmergencyBrakeMainOffPressure,
StopBrakeReleaseDelay) come from the vehicle definition and aren't.

* fix(simulation): the snapshot code without Sonar issues

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.

* fix(brakes): TSt113 lists the control pressure once

TSt113::pressures() added CP on top of TH14K1::pressures(), which
already has it since #366 removed the CP of TSt113 that hid it. A
snapshot held the St113's control chamber twice. The second entry is
removed.

Tests: every driver's handle lists each pressure once, and the St113
pressures of an EN57 saved through a snapshot come back on a fresh one.

* fix(simulation): snapshots skip road traffic, refuse changed sceneries, keep misplaced vehicles apart

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.

* refactor(simulation): the snapshot reads and writes the private state of the vehicles through their own members

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

* fix(simulation): carry the driver's coupling set in the snapshot as the bits of the set

iCoupler is a CouplingSet since 2098614f, which record::set()/get() can't take. It goes
through the converted values as a whole number, as the driving flags do: Bits() on save,
CouplingSet::FromBits() on load. The key and its values are the same as before.

* fix(simulation): a loaded snapshot counts the vehicles it left where they stand

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).

* feat(simulation): the snapshot keeps a derailment and the brakes of a sleeping vehicle

A derailed vehicle came back on the rails. Its entry now keeps what derailed it (outcome,
cause, speed, the cause and side of the motion off the track, the acceleration, the
collision derailment) and the distance its criteria were last checked over; the
derailment the scenery and the test mode were told of (new_derailment()), so it isn't told
again; and with physics.derailment new the motion of the body off the track
(derail_motion::body::state()) with the timers of the vehicle off the track. The terrain
under it is gathered anew around it when it loads.

sleep_brakes, what a sleeping vehicle's brake force came from, is kept too.

All keys are new: an entry without them leaves the vehicle as the scenery made it, so files
written before still load. New scenario case snapshot_td_off_track.

* fix(simulation): the snapshot keeps the sanded start of an AI driver

#494 (in staging since the last runs of the snapshot cases) made a driver whose start
slipped keep sanding under power until the train is under way, and take the power down a
step at a time. Neither the flag nor the time of the last step down was kept, so on
linia61 the loaded run sanded one frame later than the run which went on and parted from
it 0.06 s after loading (suwnica2, 9 mm and 0.08 km/h at 600 s). Both are kept now
(sandedstart, sandedstarttime); an entry without them leaves the driver as it is.

* fix(simulation): the snapshot keeps a train running forked on a switch thrown under it

Staging's switch fork running (#496) gave the axles and the vehicles state of their own: the way of a
switch an axle ran onto (TTrackFollower::iPath, which it leaves the switch by after a throw), the ways it
remembers of the switches behind it (path_memory, read when the axle behind it comes onto one of them),
and per vehicle the switch its bogies or its coupled ends run forked on with whether that was told
(m_forkbogies, m_forkends). None of it was in a snapshot: a loaded train on a switch thrown under it
would have left it by the way it is set now and never derailed running forked.

- Place() sets the way of the switch from the path the axle is put on, as SetCurrentTrack() does, and
  clears the facing entry the vehicle hasn't looked at (there is none between frames).
- A vehicle entry has the remembered ways of each axle, oldest first (axle0switch0, axle0way0...),
  recorded again into an empty memory on load (path_memory::entries()), and the forked watches
  (forkbogies, fork0, fork1 with their "told"). A name which isn't a switch is refused.
- New case snapshot_td_switch_thrown: the snapshot is taken while the second coach of
  eu07_td_switch_thrown_facing_behind_derails runs forked and hasn't derailed yet; the loaded run derails
  it the same way and the two files at 150 s are identical.
2026-12-02 15:40:25 +01:00
Hirek 304ce934cc Merge pull request #375 from miloszunio/pr/brush
Editor: the brush of models as one model or many in a circle
2026-12-01 23:40:31 +00:00
Hirek 33feccb61b Merge pull request #406 from MaSzyna-EU07/fix/linux-case-extras
fix(files): the files #362 left are found and written in another case on Linux (GE#542)
2026-12-01 23:40:14 +00:00
Hirek fdc77484b8 Merge pull request #566 from MaSzyna-EU07/perf/msvc-release-lto
build: link-time optimization on by default for MSVC Release builds
2026-12-01 23:39:47 +00:00
Hirek b7772203fc Merge pull request #558 from MaSzyna-EU07/fix/sonar-staging-reliability
fix: the five bugs SonarQube Cloud reports on staging (reliability E)
2026-12-01 23:39:12 +00:00
Hirek 9bbbed18f6 Merge pull request #488 from MaSzyna-EU07/fix/inactive-cab-mirrors-flag
fix(vehicle): fold the mirrors of an inactive cab only when InactiveCabFlag says so
2026-12-01 23:38:42 +00:00
Hirek 082f248264 Merge pull request #484 from miloszunio/feat/flashlight-gl46
feat(driver): a flashlight for the player (Ctrl+Shift+F)
2026-12-01 23:37:41 +00:00
Hirek 1b3b92f6af Merge pull request #496 from MaSzyna-EU07/feat/switch-fork-running
feat(physics): a switch thrown under a train runs forked, and may derail it
2026-12-01 23:37:22 +00:00
Hirek 664a864f13 Merge pull request #563 from MaSzyna-EU07/perf/test-mode-hot-paths
perf: faster simulation step, mostly in the test mode (byte-identical results)
2026-12-01 23:35:27 +00:00
Hirek f71da105f6 Merge pull request #581 from MaSzyna-EU07/fix/derail-coupling-pull-angle
fix(derailment): the coupling off the track pulls hook to hook, not straight across (GH#579)
2026-12-01 23:34:09 +00:00
maj00r ed58a3aab0 Merge pull request #535 from MaSzyna-EU07/feat/model-format-e4d
feat(model): the E4D model format: spec, reader, writer and conversion from E3D/T3D
2026-12-02 00:11:40 +01:00
maj00r 98ce78a659 feat(audio): the rails sing before a train comes, as heard by the track
A listener by the track hears the rail next to them hiss before a train
arrives: the wheels set the rail vibrating and the bending waves run along
the steel far ahead of the train. The rail nearest the listener now gives
this sound for the trains along it, as far as the way along the rails lets
it through.

The sound is made in code when first needed, so no asset is needed. It's
built from a recording of rail singing: noise of its measured spectrum (a
table of levels every 1/24 octave), close tones near 1.2-1.5 kHz that
swell together now and then, a calm ring near 7.84 kHz, short tones
falling from about 1.3 to 0.9 kHz now and then, and, for a train within
100 m, steady tones near 5 and 6 kHz measured under a passing train. The
parts are six looped buffers, played by sources placed on the rail where
it's nearest the listener.

The volume follows the way along the rails, walked through the switches as
they are set: the rail takes 0.02 dB/m, each joint 0.5 dB (from the
existing sound distance of the track, so jointed track carries it a much
shorter way), each switch 3 dB. The sound comes in from 1500 m, faster as
the train nears, in full from 100 m, and 6 dB louder within 100 m. It
grows with the speed and with the mean axle load of the consist, so a
draisine hardly sings. The listener's own consist isn't heard from the
rails.

eu07.ini: sound.railsinging (yes) turns it off, and sound.railsinging.volume
(0.45), .range (1500 m), .full (100 m), .decay (0.02 dB/m) and .nearboost
(6 dB) tune it. With sound.railsinging no the simulator behaves as before.
No format changes, no SVN changes.
2026-12-01 23:24:09 +01:00
miloszunio 585e51d140 docs(editor): the brush says rightly what happens when the step of a stroke is gone; the test's generator marked for Sonar (#375)
A correction of 1a6d2bb, whose message and comment were wrong: a stroke whose step is gone from the history didn't crash the
editor and doesn't go on in a step of its own. brush_dab() ends it before the models of the dab, as it did in a87a94d, so
brush_step(true) always has a step in the loop; the null check there is for the analysis (S2259). brush_step() returns null for a
step that is gone without touching the serial, as before 1a6d2bb, and the comments say so.

The helper of the unit test which takes the generator of the test carries the NOSONAR(cpp:S2245) the other ones have: a
repeatable test, not security. Without it the quality gate failed on the security rating.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DDcMn1p6qPUo2Cgx4KaVYU
2026-12-01 22:34:14 +01:00
miloszunio 1a6d2bbc2f fix(editor): the brush keeps its models when the step of the stroke is gone from the history (Sonar)
A stroke held long enough for its step to be trimmed from the history took the step as null and the next model crashed the
editor (Sonar S2259 in editormodebrush.cpp). The rest of the stroke now goes to a step of its own, which Ctrl+Z takes back.

The other notes of the analysis, with no change of behaviour: the fill loops test their counter only and stop on the limit
inside (S886), brush_on_line() is const, the step is found with std::to_address, the line shape of the brush is
shape::along_line (it shadowed the line settings, S1117), and the test of the picks without finite settings is a helper
(S134), with std::numbers::pi in the density test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DDcMn1p6qPUo2Cgx4KaVYU
2026-12-01 20:29:37 +01:00
jerrrrycho 4f8b77c474 fix(derailment): the coupling off the track pulls hook to hook, not across between the buffer faces (GH#579)
With physics.derailment new, derail_motion::meet() took the pull of the
coupling along the line between the two buffer faces. Ends side by side,
almost touching along the track and 0.4 m apart across it, gave a line at
80-90 deg to the vehicles, and pull_neighbours() pulled the neighbours off
with Y/Q 1.4-4.3 from a coach that had barely left its line.

A screw coupling hangs between the draw hooks, which swing in the
headstocks behind the buffers. The pull now goes from the hook of one end
to that of the other: the end points moved back along each body's axis by
hook_depth (= buffer_length, 0.6 m; UIC buffers stand 620 mm out of the
headstock). 0.4 m across with the buffers touching gives ~18 deg. In line
nothing changes. Ends gone past each other (gap = distance between the
beams) keep the line between the beams, the way that gap closes: the hook
line turns about there and would hold the bodies with the hooks side by
side, pulling straight across.

gap, push, the buffer path and the point the force acts at are unchanged.
The shares of the force along each vehicle (measure_off_track) follow the
new line too.
2026-12-01 18:58:27 +01:00
jerrrrycho 77affa28d5 fix(files): the files found in another case are counted, and listed only with logs.filecase
These files load fine since #362, so a run no longer gets a log line for each of them. It gets one line with their
count when the game closes, none when there are none; "logs.filecase yes" in eu07.ini logs each name, once, as before.

- The count is written at the closing, as it covers the whole run: the vehicles, sounds and textures loaded after the
  scenery count too, which a line at the end of loading would miss.
- An eu07.ini key rather than a log type of its own: logs.filter sets all the types at once, so a type off by default
  would come on for anyone with "logs.filter 0".
- On Windows nothing is found in another case, so nothing is counted or logged.
2026-12-01 18:24:05 +01:00
jerrrrycho 67a7e3876c fix(files): a new layer isn't made over a file there in another case, and the review's smaller points
- node_layers::create() refuses a name a file is there with in any case: on Linux path() wrote over it.
- A name is marked as logged only once the file is known to be there.
- The log line says the file is on disk in another case; the folders FileOnDiskToWrite() looks up aren't logged.
- The editor start reads the layers, and the heightmap terrain its terrain.yaml and pack files, as they're named on the disk.
- The write test compares the names exactly; a test of the log line once per name, with the lines kept by the test log stub.
2026-12-01 18:24:04 +01:00
jerrrrycho d670cc2e53 fix(files): the files #362 left are found and written in another case on Linux (GE#542)
were still opened by the name the scenery gives, in lowercase, and some were written by it, so on Linux a new file went
to a new lowercase folder next to the real one, or a second file was made next to the one there.

Opened through FileOnDisk() now: the .vmd animations of the events, the Lua script of the scenery, the Lua and WASM
screens and the files they read from their folder, the textures read for the colour of the rails, and the .sbt files a
scenery includes with the terrain directive.

FileOnDiskToWrite() gives the file to write: the one there in any case under its name on the disk, otherwise the name
given in the folders as they are on the disk, the folders missing in any case named as given. The editor's layers
(node_layers::path()), the .sbt the game writes and the heightmap terrain folder go through it; the editor removes an
.sbt there in another case. The .e3d made of a .t3d is written next to the text, or over the .e3d there in another case.

FileCased() writes each file found only in another case to the log once (logtype::file), the list for the authors of
the data to name the files as they're asked for.

Nothing changes on Windows: FileCased() gives the name back as it is there, and nothing is logged.
2026-12-01 18:23:24 +01:00
jerrrrycho a1a988d753 test: the trains of the hose exchange kept from one step to the next against ones worked out in every step
One train, a locomotive with five freight wagons on a gradient, stepped twice from the same seed: as the game
steps it, the trains of the hoses kept in the cache, and with them worked out again in every step
(test::consist::keep_hose_trains(false)). Charged, braked, the last two wagons uncoupled, released: with
Global.physics_sleepheld the wagons held by their brakes fall asleep and wake on the way, so the trains change
with the uncoupling and with the vehicles going to sleep and waking. The pipes, the reservoirs of the hoses and
the brake cylinders of the two are bitwise the same after every step. A cache which is never laid out again
after its first step fails it (10203 differences).
2026-12-01 17:28:55 +01:00
jerrrrycho b490d6a49d build: link-time optimization for the unit tests too, reword the USE_LTO comment
eu07_unit_tests links eu07_core, which USE_LTO compiles with /GL; without the property on the test
target MSVC met those objects in a link without /LTCG and restarted the link with it, after a warning.
INTERPROCEDURAL_OPTIMIZATION_RELEASE is now set on the test target too.
2026-12-01 16:58:17 +01:00
jerrrrycho 4a7eab6e13 test: the copy of the thread's engine marked as the simulation's randomness for Sonar (S2245) 2026-12-01 16:57:52 +01:00
Hirek 1ae8fdc62a Merge pull request #560 from MaSzyna-EU07/fix/derailment-ground-556
fix(derailment): no fall through the ground off the track, and more friction on it (#556)
2026-12-01 10:07:17 +00:00
miloszunio a87a94d36d fix(editor): the brush after the review of 30.11: a second uniform stroke doubles nothing, the step of a stroke by its serial
- the uniform fill is told of the models which stand near the dab already (scatter::dab(), Standing) and leaves the points of
  its grid alone where one stands: a second stroke over the same ground adds nothing, as the description says. After a Ctrl+Z
  of the first the ground is filled again
- the step of the history of a stroke is made with its first model and looked up by its serial for each model
  (editor_mode::brush_step()): a step pushed while the button is held (Del) no longer takes the later models of the stroke,
  and a press which puts nothing (on the sky, no model chosen) leaves the steps to redo as they were
- the settings of the brush are bounded before they are used (scatter: sane()): a number typed into a field which isn't
  finite gives no place nor transform which isn't, and the fields clamp what is typed (ImGuiSliderFlags_AlwaysClamp).
  Within the ranges of the panel nothing changes
- tests: the second stroke, the settings which aren't numbers, the ranges of the panel
- redo_last() ends the stroke after the step of the terrain, and tests/unit/CMakeLists.txt lists editorScatter.cpp apart from
  the lines #311, #430 and #431 add, so the four merge without a conflict
2026-11-30 22:16:26 +00:00
miloszunio 1e3c9b9c40 fix(driver): the flashlight after the review of 30.11: the toggle in a helper, a line in the log with the clustered lights off
- TCamera::OnCommand() hands the command to toggle_flashlight(), which keeps the complexity of the handler where it was (S3776)
- turned on with gfx.lights.clustered off the flashlight lights nothing: the log says so
- local_lights::add_flashlight() is private; gather() adds the flashlight right after the lights of the cab, apart from the
  place the arcs of the pantographs of #431 are added in, so the two merge without a conflict
- a test of the toggle: the key going up switches it, a press and the repeats don't
2026-11-30 22:01:30 +00:00
Hirek 4c30fe4c3b Merge pull request #569 from MaSzyna-EU07/fix/snow-layer-driver-crash
Fix/snow layer driver crash
2026-11-30 19:04:16 +00:00
Hirek 01893ded61 Merge pull request #547 from MaSzyna-EU07/feat/derailment-event
A derailment is told to the scenery and ends a test run on request
2026-11-30 18:59:42 +00:00
Hirek 40a39ad390 Merge branch 'staging' of https://github.com/MaSzyna-EU07/maszyna into fix/snow-layer-driver-crash 2026-11-30 19:40:15 +01:00
Hirek 48b7c679a0 Windscreen snow: no crash of the simulator when the driver's compiler faults
A player's simulator (Vulkan, GeForce RTX 4060, NVIDIA 610.88, through Steam) crashed at every start
as the cab loaded: an access violation (read of address 8) inside nvgpucomp64.dll while
vkCreateComputePipelines compiled water_snowlayer.comp. The crash came on $baltyk_skm1.scn and $td.scn
alike, at the same address in the driver.

The snow shaders (shaders/vk14 and shaders/ogl46, the same in both) no longer use what the
compute shader alone had: a vector component written at an index known only while running through an
inout parameter (snRef), constant arrays of structs and of ints indexed at run time (sn_grids,
sn_lump_tiles, the neighbours of snSpan) and a local vec4 indexed by the blade. They are worked out by
small functions and explicit components instead (snRefPut, snRefWord, snGrid, snLumpTile, snNear),
and the blade is read from the storage as water_snow.comp, which the same driver compiled, does.
The results are the same. glslc compiles both variants and spirv-val passes; whether 610.88 compiles
them now can't be checked without that driver.

So that a driver crashing on a program the renderer can go without doesn't take the simulator down,
the programs of the windscreen water are made under gfx::DriverCrashGuard
(rendering/common/drivercrashguard.*):
- with msvc the fault of the driver is caught (SEH) and the session goes on without the program: the
  glasses without the snow, or without the simulation of the water;
- the program is written down in the cache of the renderer (driver_crash_attempt.txt) before the driver
  gets it and crossed out after. a program a session ended on is suspect (driver_crash_suspects.txt);
  when a second session ends on it, or when a fault was caught, it is recorded (driver_crashes.txt) and
  not made again with that driver. a new driver or a changed program is tried again;
- Vulkan makes these pipelines without the VkPipelineCache, whose lock a faulting driver might leave
  taken (the drivers keep their own cache on the disk).

Tested: unit tests (1211/1211, with a caught access violation), Vulkan and OpenGL 4.6 in the cab of
303E on $td.scn (RTX 4070, 621.14), and on Vulkan with a real access violation injected into the
pipeline of water_snowlayer.comp: the session went on without the snow, the next one skipped it.

No change of the game data.
2026-11-30 19:39:29 +01:00
Hirek 7d3ccd6dc4 Textures: read KTX2 files (BC1-BC7, RGBA8, zstd) in both renderers
The game now reads .ktx2 texture files, for the OpenGL 4.6 and the Vulkan
renderer alike (texture_source::load_KTX2(), parser in model/ktx2.*):

- formats: BC1 (RGB and RGBA), BC2, BC3, BC4, BC5 (unsigned and signed),
  BC6H (unsigned and signed float), BC7, and plain R8G8B8A8 / B8G8R8A8;
- the levels stored as they are or packed with zstd (the bundled zstd);
  with gfx.textures.streaming the worker threads read and unpack them;
- the KTXorientation key is honoured: "rd" files are flipped to the bottom
  row first, BC1-BC5 block by block, plain texels row by row. BC6H and BC7
  can't be flipped without decoding: an "rd" file of these is loaded as
  stored, with a warning in the log, as the BC7 dds files are. A file
  without the key is taken the way the dds files are (ddsupperorigin);
- srgb or linear colour is chosen by the material, as for the dds files;
- the alpha of BC7 is checked on a small level, as for the dds files.

Not supported, refused with the reason in the log: Basis Universal
(ETC1S / UASTC, BasisLZ), zlib supercompression, arrays, cube maps and
3d images.

BC1 without alpha, BC4, BC5 and BC6H are new formats for the renderers:
opengl_texture::mapping and the Vulkan texture_format_of() map them (no
srgb variants for BC4/BC5/BC6H; their alpha reads 1).

.ktx2 is looked for right after .dds (textures, materials, the editor's
texture browsers). Existing data holds no .ktx2 files, so nothing changes
for existing sceneries and vehicles, and no asset change in the SVN is
needed.

Unit tests: tests/unit/test_ktx2.cpp (header, levels, zstd, orientation,
refused files, flipping of BC1-BC5 and plain texels).
2026-11-30 15:08:45 +01:00
miloszunio cb3ac22a8d fix(editor): a stroke of the brush leaves the density set on the ground it goes over
The density of the random and the feathered fills was counted for the whole circle of every dab. The
circles of a stroke overlap (a dab every half of the radius), so each place got its share from every
dab that went over it: 5 models a 100 m² set came to some 15 on the ground, and more wherever the
cursor came back. The count was also rounded for each dab, so a circle too small for half a model
(1 m at 4 a 100 m²) never got any.

A stroke now keeps the circles of its dabs beside the places of its models (scatter::stroke). A dab
draws as many places as the density asks for in its circle and keeps each with the chance of what
the ground there is short of: nothing where an earlier dab of the stroke has filled it, so the
overlaps and the way back add no more. The count is the whole part of what is asked for and one more
with the chance of its fraction, so small circles and low densities get their share over the stroke.
The feathered fill is as dense as set in the middle of the stroke and thins out towards its edge;
a single dab of it used to squeeze the whole count of the circle into its middle.

The uniform fill (the grid) is as it was. The tooltip of the density says what it counts.
2026-11-30 12:20:57 +00:00
miloszunio 71bd8d95f4 merge: staging (6a716b67) into pr/brush: the brush kept beside the track names list in CMakeLists.txt, the unit tests and editor_pl.po 2026-11-30 12:10:29 +00:00
jerrrrycho 89de7380ee perf(physics): the trains of the hose exchange are kept from one step to the next
exchange_through_hoses() worked out on every call which vehicles the brake and the main reservoir hoses
join into trains (hose_trains(): the list sorted by address, a search through the couplers), and laid
them out train by train: ~2.7% of the main thread on Tomaszewo, for trains which change only with a
coupling, a vehicle going to sleep or waking up, or one added or taken away.

vehicle_table::update_brake_pipes(), which passes all the vehicles of the scenery in every step, now
keeps them in a physics::hose_trains_cache (physics/components/hosetrains.h) together with what they
were worked out from: of each vehicle of the list, whether it stepped the pipe and the neighbour the
hose of each end joins it to. On every step that is gathered again (one pass over the list) and
compared: the trains are worked out again unless it's all the same, so they're always the ones
hose_trains() gives. The groups stepped in parallel (update_steps_parallel()) and
physics::Vehicle::UpdatePipeCouplers() work them out on each call as before. hose_substeps() goes by
the pressures, which change in every step, and is left as it is.

The unit tests' consist steps its brake pipes the way update_brake_pipes() does now, with the trains
kept, so the golden traces (recorded on staging) check the kept trains, the uncouplings of the tests
included.

600 s in --test, seed 12345, one run each: Tomaszewo (raj40821) sim 134.9 s against 137.4 s the step
before (-1.8%); L107 (linia_107_objazdy) sim 18.1 s against 18.8 s. The physics logs (14 and 9) and the
event logs are byte-identical to staging's, unit tests 1207/1207 with exact golden traces.
2026-11-30 09:01:34 +01:00
jerrrrycho 3b6c60964e fix(derailment): the slope of the bed goes on down to the terrain; the toe only bounds it where there's none
The toe limited the slope of the bed everywhere, so beside an embankment higher than 3 m the bed was a
floor in mid-air 3 m under the ballast, over the field (review of #560). formation::height() is the
slope again, unbounded; reaches() alone bounds the bed where the terrain has no ground under the point.

The zigzag test runs 32 seeds instead of 8 (23 trains fold, 14 pairs of folds, 8 of them opposite
ways), so that one seed folding otherwise doesn't decide it.
2026-11-30 08:15:52 +01:00
jerrrrycho aa9fc1b6f3 perf(physics): the engine of a group of vehicles stepped in parallel is seeded at its first draw
vehicle_table::update_steps_parallel() gives each group of vehicles an engine of Random() of its own,
seeded from the run's engine and the group, so the draws are the same whichever thread takes the
group. It built a std::mt19937 from a std::seed_seq for every group in every step: seed_seq::generate
filling the 624 words of the state was 2.4% of the main thread and most of what the worker threads did
(5263 of their non-waiting samples) on Tomaszewo, where most groups (parked wagons, cars) draw nothing.

The group now gets a lazy_random_engine (utilities/lazyrandom.h) holding the two numbers, which
Random() seeds the same way (std::seed_seq of the two) at the group's first draw. A group that draws
gets the same numbers as before, one that doesn't skips the seeding. Ported from a local branch of
2026-11-28 (perf/parallel-group-random-engine-lazy-seed, on the layout before #531), with its tests:
the lazy engine draws as one seeded up front from the same numbers, is seeded at the first draw only,
and stands ahead of the thread's engine while it's set.

600 s in --test, seed 12345, one run each: Tomaszewo (raj40821) sim 151.5 s against 206.7 s the step
before (-27%); L107 (linia_107_objazdy, binary terrain, gfxrenderer null) sim 20.5 s against 31.1 s.
The physics logs (14 and 9) and the event logs are byte-identical to staging's, unit tests 1207/1207
with exact golden traces.
2026-11-30 08:15:16 +01:00
jerrrrycho f0d3cfbd98 test(derailment): the deceleration on its side and the zigzag of a folded train with the new friction 2026-11-30 02:33:37 +01:00
jerrrrycho 551172f9db test(derailment): the expectations of the friction on the ground follow its new values 2026-11-30 02:08:01 +01:00
jerrrrycho d1e08078f1 fix(derailment): no fall through the ground off the track, and more friction on it (GH#556)
physics.derailment new: a vehicle off the track takes the ground from the
terrain of the scenery and from the bed of the track. Where the terrain had
no ground under a support (a hole in it, past the edge of what was gathered),
the slope of the bed was taken, and it went down for ever: 100 m off the track
some 65 m. The vehicle fell into it, and once under the terrain it never found
the terrain again, as that was over it (a ceiling of 1 m over the vehicle).
The slope now ends at its toe, 3 m under the top of the ballast, and away
from it, where the terrain says nothing, there's no ground: the vehicle keeps
its height.

The friction of a vehicle sliding off the track goes from 0.3 to 0.45 on its
wheels and from 0.5 to 0.7 on its side: a train off the track at 130-150 km/h
slid some 250 m.
2026-11-30 01:03:54 +01:00
maj00r 6a716b6720 Merge pull request #533 from MaSzyna-EU07/fix/wiperlist-bytesum-parse
Read the WiperList wiper mask as a number, not a character
2026-11-30 00:41:27 +01:00
maj00r fc74ff0860 Merge origin/staging into feat/model-format-e4d 2026-11-30 00:32:49 +01:00
jerrrrycho 7eb73ad9d4 fix: the five bugs SonarQube Cloud reports on staging (reliability E)
- application/driveruipanels.cpp (S3584, blocker): the UART section of the
  debug panel leaked a new char*[] of the port names every frame it was open;
  the names go through a vector now.
- rendering/vulkan14/vulkan14swapchain.cpp (S1048): the destructor called
  destroy(), whose release_images() keeps the presentation semaphores in a
  vector and may throw on allocation; the destructor catches it.
- rendering/vulkan14/vulkan14scene.cpp (S2259): walk_shadow_material()
  dereferenced m_context, which own_shadow_program() just before treats as
  possibly empty; it returns without a context.
- tests/unit/test_door_component.cpp, test_consist_braking.cpp (S2193): the
  float loop counters become while loops summing the same time, so the cases
  take exactly the steps they took before.
2026-11-30 00:29:19 +01:00
jerrrrycho a81d149541 feat: a memory cell of its own for the derailment of a vehicle
report_derailment() writes the memory cell at once and only queues the
events, which run later in Events.update(). A collision derails both
vehicles in one frame, so when <A>:derailed ran, __simulation.derailment
already held B. The scenery can now declare the memory cell
<vehicle>:derailed, written the same way and with the same three fields
as __simulation.derailment, for the events of that one vehicle to read.

Documented that __simulation.derailment keeps only the last derailment
of a frame; eu07_td_off_track_end_scenery_told checks the cell of the
locomotive now.
2026-11-30 00:15:50 +01:00
jerrrrycho 61aaaa7c62 Merge staging into feat/derailment-event
# Conflicts:
#	physics/derailment.cpp
#	physics/derailment.h
#	tests/scenarios/README.md
#	tests/unit/test_derailment.cpp
2026-11-30 00:12:29 +01:00
Hirek f964f75ece Merge pull request #544 from MaSzyna-EU07/fix/staging-case-regressions
Fix two scenario cases broken on staging: the uuid of scene nodes, the AI stop on a gradient, an off-track coupling
2026-11-29 17:35:36 +00:00
jerrrrycho b7421e6179 Merge staging into fix/inactive-cab-mirrors-flag
MirrorsFold() moves with the split of Mover.cpp (#531): declared in physics/vehicle.h, defined in physics/components/cab.cpp beside CabDeactivisationAuto(), reading the private mirrorForbidden (#552). TDynamicObject::updateMirrors() in vehicle/dynamic/update.cpp calls it; the unit test sets the switch through SetMirrorForbidden() and reaches the physics through vehicle::physics().
2026-11-29 18:05:43 +01:00
jerrrrycho fff6020158 Merge staging into feat/switch-fork-running
# Conflicts:
#	CMakeLists.txt
#	McZapkie/MOVER.h
#	McZapkie/Mover.cpp
#	vehicle/Driver.cpp
#	vehicle/DynObj.cpp
2026-11-29 18:04:15 +01:00
jerrrrycho ba6ad19c08 Merge staging into fix/wiperlist-bytesum-parse 2026-11-29 18:04:01 +01:00
jerrrrycho a8bd72cc7f Merge staging into fix/staging-case-regressions 2026-11-29 18:04:00 +01:00
jerrrrycho c0e1f1c8fe Merge staging into feat/derailment-trust-limits 2026-11-29 18:04:00 +01:00