17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-08 18:50:34 +01:00
Files
maszyna/model/AnimModel.cpp
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

37 KiB