18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-01 18:47:06 +01:00
Commit Graph

28 Commits

Author SHA1 Message Date
maj00r a4dd61cd2c Merge feat/e4d-load into feat/e4d-compact 2026-11-30 00:33:02 +01:00
maj00r 161a7762c9 Merge feat/model-format-e4d into feat/e4d-load 2026-11-30 00:33:00 +01:00
maj00r fc74ff0860 Merge origin/staging into feat/model-format-e4d 2026-11-30 00:32:49 +01:00
maj00r 20f2156ce2 Merge #535 and #536's review fixes into feat/e4d-compact
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::.
2026-11-29 17:54:01 +01:00
maj00r fa98bdb8b0 Merge #535's review fixes into feat/e4d-load
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.
2026-11-29 17:53:28 +01:00
maj00r 0d095e225c fix(model): E4D review of #535: no guessed pass in the file, the header and the tree checked, unknown sections passed over
- 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.
2026-11-29 17:25:23 +01:00
maj00r 92cc2dcc28 refactor(model): the new model format is EU07M (.eu07m), not E4D
E4D read as the next version of E3D, which the format isn't meant to be tied to; EU07M goes with the world format .eu07.
The format isn't released, so nothing reads the old name.

- The extension .eu07m, the magic EU7M (the four bytes of the header), model/eu07m/ with eu07m_*.{h,cpp},
  namespace eu07m, docs/eu07m-format.md, tests/unit/test_eu07m.cpp.
- The command line -eu07m convert|dump|validate|diff, TModel3d::LoadFromEU07M, and the key modelformat eu07m|legacy
  of eu07.ini (Global.modelformat_eu07m).
- Nothing else changes: the sections, the records and the components are the same, so a converted file needs only its
  magic and its extension changed.

Unit tests 1189/1189.
2026-11-28 22:02:05 +01:00
maj00r 5185d69dc9 feat(render): the Vulkan renderer keeps the vertex streams of E4D models as they are, 28 bytes a vertex
Stage 3 of the E4D model format. A model loaded from .e4d (modelformat e4d) reaches the Vulkan renderer as its compact
streams: positions (12 B), attributes (QTangent snorm16x4 + uv f32x2, 16 B), user data and indices, without the 48-byte
gfx::basic_vertex in between.

- gfx: gfx::compact_attributes, geometry_bank::create_compact() and GfxRenderer->Insert_Compact(). The default of
  Insert_Compact decodes to basic_vertex, so the OpenGL 4.6 and the null renderers get the models as before. The CPU
  readers of a chunk (pantograph, bounds, picking, the editor) get basic_vertex made from the streams the first time they
  read it; a chunk which is changed (replace, append) turns into basic_vertex first.
- Vulkan: a bank whose chunks are all compact keeps positions, user data, attributes and indices in buffers of their own;
  vertex_kind::scene_compact reads them (location 5 the quaternion as R16G16B16A16_SNORM). A program gets a COMPACT_VERTEX
  variant the first time a compact chunk is drawn with it, in the background with gfx.vulkan.asyncresources, as the
  MODEL_DRAWS one; the variant of the multi draws makes a compact one of its own. Only vertex.vert and cabprobe.vert
  decode the normal (compact_frame() in common.glsl); the shaders of shadows, prepass, picking and cube shadows read
  position and uv as before.
- Ray tracing: the BLAS of a compact chunk reads the positions with a stride of 12, and the reflections read the normal
  and uv from the attributes (RT_FLAG_COMPACT in the record). Not tried with ray tracing on.
- The loader hands the streams of the file to Insert_Compact as they are; the stars keep their colours in the normals
  of basic_vertex and go as before.

Measured on Vulkan (self-test, 250 models of the game, runs alternating with legacy): device memory 1.60-1.64 GiB
against 1.89 GiB, GPU time a frame 1.27-1.39 ms against 1.37-1.57 ms, the same frame time and load time, the picture
within 1/255 of the legacy one, no errors of Vulkan in the log. Unit tests 1189/1189; -e4d diff gives the same results
through the new decode. Not built with GCC here.
2026-11-28 21:52:47 +01:00
maj00r d8e6c6e36e feat(model): the game loads .e4d models, behind modelformat e4d in eu07.ini
Stage 2 of the E4D model format. With modelformat e4d a model with an .e4d file beside its .e3d / .t3d is loaded from it;
legacy, the default, leaves the .e4d files alone and the game loads models exactly as before. The key is written to the
log at the start.

- TModel3d::LoadFromE4D (model/e4d/e4d_load.cpp) builds the same tree of submodels LoadFromBinFile builds from E3D,
  and both go on through the same finish_binary() (the end of the E3D loading, moved out of deserialize unchanged).
  .mmd, events, GetFromName and the editor work as before. A file that can't be read or isn't valid is logged and the
  .e3d / .t3d is loaded instead. TModelsManager finds a model which comes as an .e4d alone.
- Format additions found by comparing loads (the format isn't released, so still version 1.0):
  - the LMAT component: the material of a node without geometry (light points, rotators), whose light threshold,
    colours and material the lights use;
  - node_flags::no_transform: an E3D submodel without a matrix, told apart from one with the identity matrix;
  - section_flags::meshopt: the vertex and index streams in the codecs of meshoptimizer (vertex codec version 1,
    index sequence codec), lossless, several times faster to unpack than zstd on this data. zstd packs the other
    sections; zstd over the coded streams is an option for archives (write_options::compress_streams).
- meshoptimizer v1.3 (MIT) as a submodule in ref/meshoptimizer; only its vertex and index codecs are built, into
  eu07_core.
- Loading speed: the big streams unpack on threads of their own, and a model of 100 000 vertices or more fills the
  vertices and indices of its submodels on up to 8 threads (std::jthread); the vertices are written once, without the
  zeroes of resize(). QTangent decoding takes the two matrix columns it needs without a square root.
- eu07 -e4d diff <e3d|t3d> <e4d> [dynamic] compares the two loads submodel by submodel and times them.

Checked:
- 250 random models of the installed game: all convert, and loaded from E4D they give the same tree, names, flags,
  materials and indices as from E3D; positions and UVs bit for bit, transforms within 6.5e-5, normals within 0.03 deg
  (4 vertices with a broken normal in the E3D get a proper one).
- Size 39% of the E3D (263 MB against 682 MB). Load outside the game, with the files in the system's cache: 516 ms
  against 561 ms, 0.75 of the time for the models of 5 MB and more, 1.21 for the smaller ones.
- In the game on Vulkan (self-test, the same 250 models): 3.05 s against 3.15 s to load them, the same frame time and
  device memory, the picture within 1/255 of the legacy one.
- Unit tests 1189/1189, among them the codecs with and without zstd, a codec on a wrong section and a cut stream. Not
  built with GCC here.

No asset change is needed: the game data has no .e4d files, and the release doesn't read them.
2026-11-28 20:55:57 +01:00
pwarszawski 0b94534b83 Drop the occlusion query of a submodel, nothing uses it any more
The glare of a light point has its own queries for each instance in the
renderer now.
2026-11-27 23:41:26 +01:00
Hirek d4120ea5db Merge branch 'master' into feat/renderers-cleanup 2026-11-07 16:44:51 +01:00
pawelw bb009b0499 Text displays: draw opaque characters in the opaque pass (#201)
* Text displays: accept characters above 127, in windows-1250 or utf-8

A text display (sub-model of type "text") looks up the sub-model of each character
in a 256 entry table, and indexed it with a plain char. With char being signed, any
character above 127 gave a negative index: reading the text went outside the table,
and so did filling the table if a character sub-model had such a name. In effect the
displays could only show ASCII, and a text with national characters could crash.

The lookup is now keyed by unicode code point. Both the displayed text and the names
of the character sub-models are decoded as utf-8 if they are valid utf-8, and as
windows-1250 otherwise, so legacy (ansi) sceneries and models work next to utf-8
ones, and the two can be mixed. A short ansi text can be valid utf-8 by accident
(two upper case accented letters in a row will do); when both readings are possible
the one which finds more of its characters in the model is used.

The rest is unchanged: the first character of the text still isn't displayed, the
characters are still drawn in the translucent pass only. A missing text pointer no
longer gets dereferenced.

* Text displays: draw opaque characters in the opaque pass

The characters of a text display were only laid out in the translucent pass, so a
display had to be made of translucent sub-models to show anything. Those don't write
depth: overhead wires and other translucent geometry drawn later showed through the
display, and translucent geometry in front of it could end up painted over.

The opaque pass now lays the characters out the same way, so a display built from
opaque sub-models is drawn with depth like any other opaque geometry (and casts
shadows). Translucent characters keep working as before.

A model with a text display shows the text of its own instance, so such models are
excluded from the GPU-instanced opaque path.

* Text displays: prepare the characters once for each text

The sequence of character sub-models was cached for the last text only, so
displays of several instances drawn in turn decoded their texts again on
every draw. It is now kept for each text the display shows; the texts of the
instances don't change, so a draw costs a single lookup.

Also the comments added in the renderers are now in English.

* Text displays: move the text decoding to utilities

utf8_to_utf32() and win1250_to_utf32(), with the windows-1250 table, now sit
next to win1250_to_utf8(). The existing function maps only the Polish letters
and passes other bytes above 127 through, so it can't serve the displays.

* Text displays: address the SonarCloud findings

std::array instead of the C-style arrays, the utf-8 sequence length worked
out in a function of its own instead of nested conditional operators,
std::byte for the bit operations, std::ranges::count_if and contains().
The character loop of the renderers moved to Render_Alpha_text(), which
takes the nesting back to the limit, and the static pasText is accessed
through the class.

* Text displays: move the opaque character loop to Render_text()

The same as for the translucent pass: the loop sits in a function of its
own and the static pasText is accessed through the class, which keeps the
nesting within the limit.

* Text displays: access the static iAlpha through the class in the opaque pass

* Text displays: transparent lookup of the text layouts, init-statement for the lookup result

Two SonarCloud findings left in the code of #198: the map of the text layouts
gets a transparent hasher with std::equal_to<>, and the result of the lookup
is declared in the if statement.
2026-11-07 12:36:17 +01:00
Hirek 91c6324965 Add the optional LightOnly of FreeSpotLight 2026-10-28 21:50:08 +01:00
Hirek c4e23932bf Add the optional Radius, ShadeSelf, CastShadows and SoftFalloff of FreeSpotLight and make FalloffAngle 360 a point light 2026-10-28 16:18:03 +01:00
Hirek 1447dcf075 Walk the shadow passes and the culled model groups on worker threads in the Vulkan renderer 2026-10-27 20:56:11 +01:00
Hirek 3e2d292709 perf(gpucull): keep the walks of the submodel trees of the instances from frame to frame and make them again only when the model changes (gfx.gpucull.walkcache) 2026-10-24 01:01:43 +02:00
Hirek 5d3f857c39 perf(gl46): leave out instance buckets before the culling, lod bounds once per model, shared walks of the shadow cascades 2026-10-22 20:13:25 +02:00
Hirek 0545f93f24 Keep the hotspotpower of light points apart from their colour 2026-10-19 17:51:13 +02:00
Hirek 61bfc6eb1a Move modern OpenGL renderer to rendering/opengl46 and rename classes 2026-10-15 01:12:05 +02:00
Hirek 3d3eef2e1c Remove legacy OpenGL 2.1 renderer 2026-10-15 00:06:31 +02:00
Hirek 917c8f7285 Merge branch 'master' into feat/modern-editor 2026-10-08 17:44:58 +02:00
Hirek 3a05d0d649 perf(models): replacable skins of scenery models located once for a skin name; light and season variant submodels located once for a model instead of for each instance 2026-10-06 03:35:00 +02:00
pawelw 51521a135a Text displays: accept characters above 127, in windows-1250 or utf-8 (#198)
* Text displays: accept characters above 127, in windows-1250 or utf-8

A text display (sub-model of type "text") looks up the sub-model of each character
in a 256 entry table, and indexed it with a plain char. With char being signed, any
character above 127 gave a negative index: reading the text went outside the table,
and so did filling the table if a character sub-model had such a name. In effect the
displays could only show ASCII, and a text with national characters could crash.

The lookup is now keyed by unicode code point. Both the displayed text and the names
of the character sub-models are decoded as utf-8 if they are valid utf-8, and as
windows-1250 otherwise, so legacy (ansi) sceneries and models work next to utf-8
ones, and the two can be mixed. A short ansi text can be valid utf-8 by accident
(two upper case accented letters in a row will do); when both readings are possible
the one which finds more of its characters in the model is used.

The rest is unchanged: the first character of the text still isn't displayed, the
characters are still drawn in the translucent pass only. A missing text pointer no
longer gets dereferenced.

* Text displays: prepare the characters once for each text

The sequence of character sub-models was cached for the last text only, so
displays of several instances drawn in turn decoded their texts again on
every draw. It is now kept for each text the display shows; the texts of the
instances don't change, so a draw costs a single lookup.

Also the comments added in the renderers are now in English.

* Text displays: move the text decoding to utilities

utf8_to_utf32() and win1250_to_utf32(), with the windows-1250 table, now sit
next to win1250_to_utf8(). The existing function maps only the Polish letters
and passes other bytes above 127 through, so it can't serve the displays.

* Text displays: address the SonarCloud findings

std::array instead of the C-style arrays, the utf-8 sequence length worked
out in a function of its own instead of nested conditional operators,
std::byte for the bit operations, std::ranges::count_if and contains().
The character loop of the renderers moved to Render_Alpha_text(), which
takes the nesting back to the limit, and the static pasText is accessed
through the class.
2026-10-03 12:05:32 +02:00
jerrrrycho 8fbb482350 feat(materials): texture randomization for loads
* feat(materials): texture randomization for loads
2026-09-27 00:09:16 +02:00
jerrrrycho d85096f64d reformat: remove redundant parentheses 2026-06-30 21:19:46 +02:00
docentYT 1553f82c49 use glm instead of Math3D in Model3d 2026-04-26 22:54:12 +02:00
copilot-swe-agent[bot] 7e49aa8740 Rewrite #includes to use explicit subdirectory paths
Co-authored-by: Hirek193 <23196899+Hirek193@users.noreply.github.com>
2026-03-14 19:16:48 +00:00
copilot-swe-agent[bot] 0531086bb9 Reorganize source files into logical subdirectories
Co-authored-by: Hirek193 <23196899+Hirek193@users.noreply.github.com>
2026-03-14 19:01:57 +00:00