* feat(render): models with lights drawn instanced, behind gfx.instancedlights in eu07.ini
Stage 5 of the EU07M model format. A model with lights (lights, Light_On## / Light_Off##), such as a signal head, was
drawn instance by instance, a draw call for each part of each one. With gfx.instancedlights 1 the instances of such a
model go into the instanced batches like the others, in both renderers, with the culling of the GPU and without it. The
default 0 draws them as before. It applies to EU07M and E3D models alike.
- The light state of an instance is a word in the element [0][3] of its instance matrix, which an affine matrix leaves
unused: bits 0-7 the lit parts shown, bits 8-15 the dark parts, in the mantissa of a float of exponent 128
(0x40000000), a normal number the GPU carries through its matrix products whole. Without that marker the shader
draws everything, as before.
- model_ubs.light_part says which part of which slot a draw is (0 none, 1 + slot lit, 9 + slot dark); a part the
instance doesn't show gets a zero matrix in the vertex shader (instance_hides_part() and effective_modelview() in
shaders/vk14/common.glsl and shaders/ogl46/common.glsl). The batch instance shows every light part
(TAnimModel::RaPrepareInstanced()).
- CPU path: each instance drawn is animated (RaAnimate) and its word put in its matrix (Render_Instanced). GPU culling:
the word is in rotationscale[0].w of the instance record, refreshed once a frame for buckets with lights
(Refresh_Light_Records), which marks the records to send again when a word changes.
- An instance shows the whole lit part or the whole dark one: blinking and switching (ls_On / ls_Off / ls_Blink) change
over at half the fade, where the draw instance by instance fades the lit part in over the dark one. Steady states look
the same as before.
- The freespot lights (TP_FREESPOTLIGHT with flag 0x4000 and no animation) don't keep a model out of the instancing
when gfx.instancedlights is on. Light parts aren't put in the ray tracing of an instance batch.
Measured on Vulkan, 200 heads s4ipcpb_dd: with gfx.gpucull 0 frame 9.2 ms -> 1.5-2.5 ms and 2400 -> 16 draw calls, with
gfx.gpucull 1 9.1 ms -> 3.0 ms and 2410 -> 26 draw calls. Steady light states pixel for pixel the same as drawn
instance by instance on all three paths in Vulkan, and on GL 4.6 where the editor panels don't cover them; blinking
checked in Vulkan on all three paths (with time let run in the editor for the test only). Not run in the driver mode,
blinking not checked on GL 4.6, not built with GCC here. Unit tests 1189/1189.
* fix(render): EU07M review of #538: an instance with light colours of its own drawn alone, the light records locked only when stale
- An instance with lightcolors of its own isn't instanced: the colours go onto the shared submodels as the instance is
prepared, which the instances of a bucket don't each get, so they all showed the colours of one of them.
- The walk takes the exclusive lock for the light records of a bucket only when they are stale in this frame
(Refresh_Light_Records() checks again under it): the later passes of the frame no longer stop the other walkers.
- instance_cull.comp (both renderers) puts the word of the light parts into [0][3] after the product with the view, so a
view with a translation can't stretch the first column of a lit instance.
- The spec: ls_Dark / ls_Home switch without the fade too, and the instances with light colours of their own.
In place of .r3a (2fe1064f9): the model files are .ng3d and eu07.ini selects them with modelformat ng3d. The format keeps its name (EU07M), its magic and the -eu07m command line tool. Neither name has been released.
The model files of the format are named .r3a in place of .eu07m, and eu07.ini selects them with modelformat r3a in place of
modelformat eu07m. The format keeps its name (EU07M), its magic and the -eu07m command line tool. Neither the extension nor
the key has been released, so nothing reads the old ones.
- The bounding radius, offset() and MaxY() read the positions of a chunk alone (Positions(), geometry_bank::positions()):
on Vulkan the compact streams are no longer decoded into basic_vertex and kept for the life of the bank as every model
loads, so the host memory of EU07M models stays below that of E3D. What still needs whole vertices (the editor, the
picking, the export) decodes them on first use as before.
- A COMPACT_VERTEX variant which doesn't compile is told once in the log and the banks of EU07M models go back to
basic_vertex (compact_layout_failed()), those built already when they are drawn next, instead of the models being left
out for the session.
- The shader validator compiles the vk14 shaders which have COMPACT_VERTEX with it, alone and with MODEL_DRAWS, as the
renderer makes the variants.
Resolved for the rename to EU07M: the stale-file check is eu07m_up_to_date() before LoadFromEU07M, the loader catches
what reading throws, and the new tests name eu07m::.
- modelformat e4d: an .e4d older than its .e3d / .t3d isn't loaded, with a line in the log; the model was changed after
it was converted.
- LoadFromE4D catches what reading and building throw (no memory for what a broken file declares) and leaves nothing of
the model, so its .e3d / .t3d loads instead; a worker of fill_geometry() hands its exception to the caller after the
join instead of ending the program.
- ref/meshoptimizer is cloned shallow like the other submodules.
The pass bits the converter no longer bakes (#535) are guessed again by BinInit, which finish_binary() runs, so the
loader needs no change for them.
Resolved: start_tools() parses the convertmodels flags with from_chars and both commands stop on bad flags; a vehicle's
.t3d is refused before it. The reader keeps the streams of this branch and the known sections of #535: an unknown
section the model needs is refused as unknown before its codec is looked at, and an unknown optional one in the codec of
the streams is passed over even by the tools, which can't keep it unpacked (forward compatibility of the codec flag). An
exception in a stream worker (no memory for a declared size) becomes the error of the file instead of std::terminate;
NOSONAR on the S2259 false positive there and on the seeded engines of the tests.
- The pass bits (0x30) BinInit guesses from a material when the E3D has none are marked (TSubModel::m_passguessed) and the
converter leaves them out of legacy_flags and the primitive flags: it loads through the null renderer, whose materials
all guess opaque, so the game makes the guess again with the real material.
- A vehicle's model isn't converted from its .t3d (dynamic 1): the game prepares it only after the vehicle marked its
animated parts, so the .e3d the game makes of it is converted instead.
- read_header refuses a file_size smaller than the header, which made the hash check read outside the span.
- Sections seen twice are found with a set, not O(n^2); all the sections together may claim at most 2 GiB; a section the
reader doesn't know and the model can do without is passed over before it is unpacked when keep_unknown is off.
- validate() checks that the parent of each node is the innermost node whose subtree holds it, so the tree of the ranges
is the tree of the parents.
- Light_OnNN / Light_OffNN found by the game's GetFromName, so of two submodels of a name the same one counts; a
replaceable skin drawn translucent gets material_flags::translucent; the convertmodels flags parsed without stoi.
- S3519: the matrix made with glm::make_mat4 instead of a memcpy into its first column; NOSONAR on the seeded engines of
the tests (S2245).
- The spec: u16 indices up to 65 536 vertices, and the two rules above.
Tests: a file_size below the header, a node in the subtree of another than its parent, an unknown section passed over.
The windscreen weather (#367) and the compiler cache of the CI (#434). The
wipers' code of both renderers takes staging's side, reading the active cab and
the speed through TDynamicObject (ActiveCab(), Speed()) as the renderer does on
this branch; the windscreen water reads the speed the same way, and the deer
(world/deer.cpp) read the vehicle through its queries (V(), WarningSignal(),
CabOccupied()).
The golden traces recorded on dfb43c4f still match bit for bit: staging didn't
touch the physics.
AGENTS.md says that outside physics/ the state of a physics::Vehicle changes
only through its operations, its definition aside as the vehicle loads; that a
field the rest only reads is private with a query named as the field was, one
nothing outside uses private outright, and a new one private from the start;
and that the cab and the events read the AI through its queries, the debug and
timetable panels alone being its friends.
eimic_real, the demand of the integrated controller the vehicle goes by with
the speed control counted, which TDynamicObject and the consist braking set
for the vehicle that leads, is private: EimicReal() and SetEimicReal(). The
field of the same name of drivingaid::input stays as it is.
No change in behaviour: the golden traces recorded on dfb43c4f match bit for bit.
71 public fields of physics::Vehicle that no code outside the class reads or
writes (the definitions of the circuits and the tables only the vehicle's own
step goes through, the forces and the timers of its step, the programmable
controller, ...) move into its private part as they are, with the comments
above them. The fields of the old doors inside EU07_USEOLDDOORCODE stay where
they are.
No change in behaviour: the golden traces recorded on dfb43c4f match bit for bit.
The mass of the empty vehicle, the braking force, the outcome of a derailment,
the departure signal, the traction mode of a dual-mode vehicle and the moment
of the motors are private to physics::Vehicle like the 53 before them, read
through Mass(), Fb(), Derailed(), DepartureSignal(), TractionMode() and Mm().
Inside the class they are emptyMass, brakingForce, derailOutcome,
departureSignalOn, tractionModeSetting and motorMoment, as the plain camelCase
names were taken by locals there.
No change in behaviour: the golden traces recorded on dfb43c4f match bit for bit.
53 fields of physics::Vehicle that only the vehicle itself writes, and the rest
of the simulator reads, are private, with a query each, named as the field was
(Vmax(), TotalMass(), Ft(), nrot(), NAxles(), PhysicActivation(), ...): the
compiler now keeps the cab, the AI, the scenery, the renderer and the tests from
changing what the definition gives or the physics works out. The fields were
picked by what is never written outside the class, of plain types, with no
other member of the same name to confuse; inside the class they keep their
meaning under camelCase names. The one place outside that cleared a flag of
the AI through a reference does it through ClearAIFlag().
No change in behaviour: the golden traces recorded on dfb43c4f match bit for bit.
TTrain and whois_event reached into the private members of TController as its
friends; they read what the AI knows of its consist and its route through
queries now (ConsistDoorsOpen(), ConsistConverterOverloaded(), ConsistLength(),
DesiredVelocity(), NextSignalVelocity(), BrakesReleaseLevel(), ...), and the cab
changes the radio channel through SetRadioChannel() rather than a reference to
the AI's field. The reversers of the consist, the stations of the timetable and
the obstacle ahead are public queries and operations.
The public fields of TController are private: whether the AI drives
(AIControllFlag()), the masks of the running without current the vehicles of
the consist set (MarkOverhead(), the same bits TDynamicObject::OverheadTrack()
set itself), the most deceleration of the blended brakes (MedAmax(),
SetMedAmax()), and the positions the driving aid panels show. Only the four
debug and timetable panels stay friends.
No change in behaviour: the golden traces recorded on dfb43c4f match bit for bit.
The new views of the consist put the camera at any vehicle of the train, one with an active cab of
its own too: taken for another vehicle, it wiped the insects met and the memory of the blades, so
the insects were gone from the glass after a change of the view. Outside the cab (FreeFlyModeFlag)
the glasses now follow the train driven, in both renderers.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BqfRrTiBDaAyQ2gT6ZrnZD
- the cells of the rain: the opengl renderer makes their storage (cleared) with the first bind and keeps it
bound, the glasses read the cells only when they were worked out in the frame (scene_ubs.rain_state.w,
both renderers): never the storage before the first rain, nor the stand-in of the vulkan renderer
- the pass of the motion blur and (opengl) the velocities drawn only in the frames which need them: the
motion blur with something moving, the taa, or a glass of the rain, the insects or the snow in the view
(windscreen_water::wants_glass_requests(): the cab seen from inside has one, or the view is not from the
cab). the glasses keep their drops and haze with the motion blur off, the motion is blurred by 0 then
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BqfRrTiBDaAyQ2gT6ZrnZD
What the AI, the cab and TDynamicObject still set in the physics directly is
named now: the stabiliser of the brake pipe reset as a driver takes over a cab
(ResetPipeStabiliser()), the spring brake released by hand
(ReleaseSpringBrake()), the mode of the brake (SetBrakeOperatingMode()), the
brake cut out by the player (ClaimBrakeCutOut()), the pressure of the consist's
brake pipe (SetEquivalentPipePressure()), the inverters switched from the cab
(SwitchInverter()), the odometer (SetOdometer(), ShowOdometer()).
The state the pantographs' sounds last followed belonged to the sounds, not to
the physics: it moves from basic_pantograph to TDynamicObject.
Outside physics/ nothing writes into a vehicle's state any more but the
definition the scenery and the .mmd adjust as the vehicle loads.
No change in behaviour: the golden traces recorded on dfb43c4f match bit for bit.
The speed along the couplers, the location, the offsets from the track axis,
the accelerations, the distance counter and the distance moved since the last
check, the flat of the wheels and the truck hunting, the distance of the
derailment check, whether the vehicle is inside a consist and in the coupler
model, the analog demand of the integrated controller and the flow of the pipe
stabiliser are private to physics::Vehicle. TDynamicObject places and moves the
vehicle, the scenery puts road vehicles on their way and the contacts push them
through the operations (SetV(), SetLoc(), SetOffsetTrackH(), ...), and the
jolts of the track are ShakeVertically() and ShakeHorizontally(), the same
additions as before.
No change in behaviour: the golden traces recorded on dfb43c4f match bit for bit.
The positions of the driver's brake valve (stepped, continuous, and of the
FV4a with its cap), of the independent brake and of its EP counterpart in
units with induction motors, and of the hand brake are private to
physics::Braking: read through HandlePosition(), IndependentPosition(), ...
and moved through SetHandlePosition(), SetIndependentPosition(), ..., by the
vehicle's own stepping as by the cab, the AI and the consist braking. The
gauges of the cab bind to them read-only.
No change in behaviour: the golden traces recorded on dfb43c4f match bit for bit.
- The lights switched on at each end (iLights) are LitLights(), changed
through SetLitLights(): the cab's switches, the AI's light patterns and the
scenery's toggles of the end signals all go through it.
- The exchange of the load, which TDynamicObject ran by setting the status, the
amount and the mass itself, goes through UnloadStep(), LoadStep(),
FinishLoadExchange() and AcknowledgeLoadExchange(), with the same arithmetic;
the change of the kind of the load is taken once (TakeLoadTypeChange()).
- The events the physics reports for the sounds to follow up are raised and
cleared by name (RaiseEventFlag(), ClearEventFlag(), ClearSoundFlags()).
No change in behaviour: the golden traces recorded on dfb43c4f match bit for bit.
The positions of the master and the secondary controller, of the analog
controller and of the lights selector, the occupied cab, the horns, the radio
and its fuse, the radio-stop, the wipers' switch, the dimmer, the mirrors'
button, the end-of-train signalling and the forced resistor fans: fourteen
fields the cab, the AI, the scenery and the tests wrote straight into
physics::Vehicle are private now. The rest of the simulator reads them through
queries named as the fields were (MainCtrlPos(), Radio(), ...) and changes them
through operations (SetMainCtrlPos(), SetRadio(), ...), so every place that
moves a controller past its own stepping (IncMainCtrl()) is named and can be
found; the compiler keeps anything else out. Inside the vehicle they keep
their meaning under camelCase names. The queries return const references, as
the gauges of the cab bind to them.
The .fiz keys are untouched.
No change in behaviour: the golden traces recorded on dfb43c4f match bit for bit.
The tables of an entry were headed a second time with the time alone, under the heading which already gives the time, the
frames and the longest of them.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The vehicle's physics is TDynamicObject::physics now (physics::Vehicle): the wipers, the insects and the
rain of the glasses, the snow of the windscreen water and the deer take it from there. The includes of
staging kept in opengl46renderer.cpp; the texture check of staging first in
Render_Instances_Indirect_Shadow(), then the materials with a vertex shader of their own.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BqfRrTiBDaAyQ2gT6ZrnZD
A grazing deer takes fright when the train is deer.reactiontime seconds of its speed away (default 3.5 s: it needs 2.0-2.75 s
from the alarm to be off the track), but no nearer than deer.reactiondistance (default 20 m) for a slow or a standing train. So
the slower the train, the closer it gets before the deer runs. The horn (deer.hornrange) sends it off sooner, as before.
deer.fleedistance, of the test builds of this feature only and never in a release, goes; an eu07.ini that still has it is read
with its value passed over.
The way a deer runs away may go down the slope of an embankment (to 6 m below the sleepers) or up the one of a cutting (to 4 m
above them), no steeper than 35 degrees between the samples of the ground, now 17 of them, about 1.5 m apart. Water, walls and
cliffs still keep a deer away. Running, the deer leans up and down the slope by the ground under its hooves (at most 30 degrees,
smoothed, about its side axis, which keeps the turn the shader reads the clip and the moment from), and grazes leaning where it
stopped, drawn on its own, out of the groups of the instances of its model.
No change to the assets: the same models and textures of the deer (models/animals/jelen_*.t3d, textures/animals/jelen_*).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GXgG7F4L42c2F9sDSAJbT2
mat_rain_windscreen has no param water_slot (only the glasses of the snow have a slot of their own), so wants_rain_cells() never found the glass of the rain and the cells weren't worked out: the glass showed only its fine droplets. A material of the cab with raindropsatlas and without snow_slot now (the insects too, which don't come with rain).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BqfRrTiBDaAyQ2gT6ZrnZD