Repository navigation
UI: the minimap's terrain colours at 100% - #461
Open
kotijekriv wants to merge 2 commits into
Open
kotijekriv wants to merge 2 commits into
kotijekriv wants to merge 2 commits into
Conversation
MinimapViewState::renderMinimapTileColors, the minimap's terrain picture: for a strip of the screen tile rows it takes each tile's colour from its terrain flags and MiniMapDefinedData's tables, scales it by the tile's luminescence (RGB555 or RGB565) and writes it into the minimap pixel buffer, at full or at half size. Written from the original's listing. gynt's draft is 4a1f8dd (2026-11-02, a style pass over the UI folders; status line "20.4% | Style pass, asm differs") on his fork's reimpl/UI-MenuItems-development; his 0b3142f, 1de07cb and 0d4e470 are earlier steps of it at 20.36%. 10280b1 on reimpl/UI-Core-development has 20.2%, and a0e86e1 (20.4%) and ab8f1e3 (20.2%) are the same draft on his reimpl/UI-Core (sourcehold#256). The draft has the tables' names and the whole colour chain as the original has it. Behaviour fixes against 4a1f8dd: - the map-size test is `mapSize < 200` where the original has `<= 200` (0x004B597E: `cmp ..., 200; jg`), so a 200-tile map took the larger maps' path, where the column count is halved: rows 0 to 399 and columns 0 to 99 of the screen tile table, where the original draws the table's centre, rows 100 to 299 and columns 50 to 149 (every 200 by 200 map); - past the strip's end the original returns (0x004B5A6B); the draft has an empty `if` there and draws on (no caller passes a partial strip today). gynt has that return himself in 8ca7861 on reimpl/Wilps-2026-10-18. Two places where the code differs from the draft without a change on today's callers: - the pixels are written through `this->minimapPixelBuffer`, as in the original, not through the fixed address 0x01A58754, the same address while `this` is DAT_MinimapViewState; - the screen tile table is indexed from its base on today's main (the draft's `- 8` was right for the header of its day and reads 8 entries too low now). What the match needed: - The pixel stores are handwritten assembly in the original: `add eax, eax` and a `mul edx` by the row pitch, the same address computation as in renderMinimapPreview and drawCurrentPixel (whose pitch is `horizontalByteSize`, not the constant 400). Here they are two `__asm` blocks, one per size. The function keeps no frame pointer with them, as in the original. - The colour is a 16-bit local. As a uint, the two colour modes' ends are merged into one block and the (ushort) of the mix is split over its operands; the original has both ends written out. - The channels: each mask as a statement right after its cap, and green set before red (the mix takes the two in the order they are first set, so the three are initialised blue, green, red). - The five simple initialisations before the two strip-row divisions: a local set while a parameter is still to be read cannot take its stack slot. With them first, every stack slot is the original's (the row counter, the colour and x's stepping value sit in the dead parameters' slots). - The viewport height read from the global a second time for the other parity; y declared inside the tile loop and a copy of x at the top of the full-size branch, so that the stores of the assembly's operands stand where the original has them; the tile read before x; rowBase stepped in the row loop's header; the column loop started at `firstRow / 2` (started at firstColumn, the compiler folds x's first value, which the original computes as `(firstColumn - firstColumn) * widthFactor + rowX`); rowBase holding the orientation's offset first, with north writing the 8 again. The channel masks have names in a small file-local enum (the style lint asks for names or decimals); the listing is the same with the hex numbers. Measured in a narrow build on main 3458fea of this file alone (main is now 812d149: sourcehold#399 and sourcehold#398 add only the optional function-visibility units, off by default), struct resolvers and its resolver on: 100.0% raw and normalised, no diff entry. Not run in game. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
Style guide reading (advisory, posted once) 1 possible deviation(s) from REIMPLEMENTATION_STYLE_GUIDE.md across 1 of the 1 reimplemented The match comes first. Where the ugly form is what matched, it stays -- that is the guide's own overriding rule, and rule 21 asks for a one-line comment saying what was measured so the next reader does not retry it. This report is posted once, when the PR opens, and is not repeated on later pushes.
WhereRule 8 — Let the compiler unroll
|
This was referenced Nov 22, 2026
…table sizes The three 400s in the C++ (the strip's first and end rows, and the number of columns) are the map's 400 screen tile rows and columns, Map::MC_MAP_XY_LIMIT. The assembly's two `mov edx, 400` are a row of the minimap buffer in bytes (200 pixels of 2 bytes): a file-local BUFFER_ROW_BYTES, defined as MC_MAP_XY_LIMIT / 2 * sizeof(ushort), as renderMinimapTileStripWithLuminescence in sourcehold#465 does, because inline assembly cannot name a qualified constant. The screen tile table's numbers use main's ViewportConstants, as sourcehold#465 writes them: the table's start (8) is VC_SCREEN_POINT_TABLE_START, the other orientations' tables (80408, 160808, 241208) are VC_SCREEN_POINT_TABLE_START plus one, two and three VC_SCREEN_POINT_TABLE_SIZE, a short and a long row together (401) are VC_SCREEN_POINT_SHORT_ROW + VC_SCREEN_POINT_LONG_ROW, and the row lengths (200, 201) are those two. The 200 of the row count and of the map size test is Map::MC_MAP_SIZE_200, and such a map's first row (100) is (MC_MAP_XY_LIMIT - MC_MAP_SIZE_200) / 2. The comment above the orientation test names the table's start instead of the 8. The file includes MapConstants.hpp and ViewportConstants.hpp. No other change. The colour masks stay a file-local enum for now: Rendering::ColorChannelMask, which names them, comes with sourcehold#465, and this file switches to it once sourcehold#465 is on main. Measured: with the precompiled header, quick_diff gives the same listing for the pushed head's text and this one after MSVC's `$T` temp labels are normalised. A narrow real build (main's /GL list and this round's files of two of our PRs, with the struct resolvers and those files' function resolvers on, sourcehold's reccmp with --resolve-wrapped-calls --ignore-security-cookie) reads 100.0% raw and normalised with no differing line for each function this commit touches, and every other function reads as in the same build without them. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Correction (2026-11-22): an earlier version of this text said that no caller reaches the return at the strip's end. That was wrong:
drawMinimap's step-by-step redraw passes 2% strips, as described below. The commit message still has the clause "(no caller passes a partial strip today)"; please drop it if the PR is squashed.One function at 100%, written from the original's listing with gynt's draft beside it. No header changes. Two behaviour fixes against his draft: one shows on every 200-tile map, the other (which he also made on another branch) runs on every step of the minimap's step-by-step redraw. Two more places differ from the draft without a change on today's callers (below).
MinimapViewState::renderMinimapTileColorsgynt's draft is 4a1f8dd (2026-11-02, a style pass over the UI folders; status line "20.4% | Style pass, asm differs") on his fork's reimpl/UI-MenuItems-development; 0b3142f, 1de07cb and 0d4e470 are earlier steps of it at 20.36%. 10280b1 on reimpl/UI-Core-development has it at 20.2%, and a0e86e1 (20.4%) and ab8f1e3 (20.2%) are the same draft on reimpl/UI-Core (#256). The draft has the names of the 14 colour tables and the whole colour chain as the original has it.
Measured
Stronghold Crusader.exe(3bb0a8c1…5387ac5a), and sourcehold's reccmp with--resolve-wrapped-calls --ignore-security-cookie. The struct resolvers and the function resolvers are enabled locally (not committed). In the full build 0x004314E0 (theMapEditorLandscaping_GeneralButtonshandler) is left out and its resolver stays off, as in main's baseline.BOOLEnumand writes five tests withcontinue, which compiles to the same listing), with both resolver sets on: 0 failed of 2,424 compile steps, 99.58 over 2,440 functions, against 99.58 over 2,439 for main alone (built at f489b72; 3458fea only adds files undertools/, and cmake: optional wrapper units built from function-visibility.txt #399 and cmake: function-visibility.txt, which callers must see which callees' bodies #398 add the optional function-visibility units, off by default). The new function reads 100.0 raw and normalised there too, with no diff entry, and so does its callersetTileColorsDependingOnMapSize, as before. Every main function reads exactly what it read before: unrounded 99.5761 against 99.5759 raw and 99.5494 against 99.5492 normalised, with 2,323 against 2,322 functions at 100.0 raw.lea ecx, [ecx], anopand alea ebx, [ebx]), in its order; reccmp's diff for the function is empty. The function makes no calls and has no switch table.The behaviour fixes
The function draws the minimap's terrain: for a strip of the screen tile rows it takes each tile's colour from its terrain flags and
MiniMapDefinedData's tables, scales it by the tile's luminescence and writes it into the minimap pixel buffer, at full size or, zoomed out, at half size. Its one caller on main,setTileColorsDependingOnMapSize, always asks for half size and passes its strip on: the whole table, or 2% of the rows at a time fromdrawMinimap's step-by-step redraw.mapSize <= 200(0x004B597E:cmp ..., 200; jg): it draws the centre of the screen tile table, rows 100 to 299 and columns 50 to 149. The draft testsmapSize < 200, so a 200-tile map took the larger maps' path, where the column count is halved instead (columns / columnDivisor). With the 4 by 2 pixel tiles that the caller (which testsmapSize > 200) hands it, that is rows 0 to 399 and columns 0 to 99: the table's left half, drawn into 400 rows of the pixel buffer, where the original fills 200 with its centre. 200 is one of the game's four map sizes (160, 200, 300 and 400, the switch at 0x004AC0A0), so this is every 200 by 200 map. Every version of the draft has< 200.jgeto the epilogue). 4a1f8dd has an emptyifthere and goes on drawing the rows after the strip. gynt has this return himself in 8ca7861 ("wilps-2026-10-18", 2026-10-27) on his reimpl/Wilps-2026-10-18.drawMinimap(0x004B66C0, not on main) reaches it on every step of its step-by-step redraw. While itsfield_0x38is non-zero, it callssetTileColorsDependingOnMapSize(field_0x34, 2)(0x004B67C2, 0x004B67E5) and stepsfield_0x34by 2 up to 100, so each call covers 8 of the 400 rows. Without the return, each of those calls drew every row from the strip's start to the end of the table. gynt's own drawMinimap on reimpl/Wilps-2026-10-18 makes the same calls (incrementalRedrawPercent, 2).Two more differences change nothing on today's callers:
DAT_MinimapViewState(0x01A31610) plusminimapPixelBuffer's 0x27144. The original takes it fromthis(0x004B58D5:add ecx, 0x27144), as this file does; the two agree whilethisis that instance, which seven of the ten call sites ofsetTileColorsDependingOnMapSizepass outright; drawMinimap's three pass its ownthis.screenPointToTileNumber + ... - 8, which was right for the header of its day (the array at 0x4E600). Main's header has since moved the array's start to 0x4E5E0 (2bd620b), so on today's main the draft reads 8 entries too low; here the index has no- 8.Read block by block against the listing, 4a1f8dd does everything else the way the original does. (Its row-parity counter starts at 0 where the original's starts at
firstRow * heightFactor; the two agree in parity, becausefirstRowis 0 or 100.)What got it to 100%
mov edx, 400; mul edx,add eax, eaxand the colour throughax, the same address computation as inrenderMinimapPreviewandPencilRenderCore::drawCurrentPixelon main (theirs takes the pitch fromhorizontalByteSize, here it is the constant 400). Here they are two__asmblocks, one per size (next section). With the two stores written in C++ instead, the same file compiles to 419 instructions against the original's 457.uint, the compiler merges the two colour modes' identical ends into one block and splits the(ushort)of the mix over its operands, whatever the source form (about 40 were tried, inline helpers included). As aushortthe mix isor; or; movzx reg, ax; mov, withecxin one arm andedxin the other, and both ends stay, as in the original.ors swap).ydeclared inside the tile loop and a copy ofxat the top of the full-size branch, so that their stores stand where the original has them.viewportHeight + 1is added up anew in every row and has no slot); the tile read beforex;rowBasestepped in the row loop's header; the column loop started atfirstRow / 2(below);rowBaseholding the orientation's offset first, with north writing its 8 again.The inline assembly
Two blocks, 12 and 10 instructions: the pixel store itself and nothing else. The loops around them, the bounds tests, the half-size divisions and the colour are C++, and every operand of the blocks is a C++ local named there (
buffer,pixelX,offsetX,y,offsetY,color;halfX,halfY). Nothing of the store can move to C++: it builds the address inediwithadd eax, eaxand amulby 400 loaded intoedx, where the compiler writesleaandimul, and it reads each operand from its stack slot. The function keeps no frame pointer with the two blocks, as the original keeps none (sub esp, 0x58,ebpa general register).The sibling
renderMinimapTileStripWithLuminescence(0x004B5330) has the same two stores (0x004B575D to 0x004B5783 and 0x004B5835 to 0x004B5853). When it is written, the two can share them as a macro in an*Asm.hpp, as AGENTS.md has it for a stream that repeats; with one user they stay blocks here.Things in the file that look odd and are the original's
for (int column = firstRow / 2; ...)next tofirstColumn, which holds the same value: the original computes x's first value as(firstColumn - firstColumn) * widthFactor + rowX, the subtraction left in (0x004B5AA6:mov edx, esi; sub edx, esi). Started atfirstColumn, the compiler folds it torowX.int blue = 0; int green = 0; int red = 0;, never read before they are set: see "The channels" above.rowBase = 8although it holds 8 already: the original has that arm (0x004B59B4), and a path without it for an orientation that is none of the four.viewportHeight + 1in stack slots of their own; the second read is what gives the+ 1its own slot here. The rows alternate by comparingrowParitywithviewportHeight + 1: the two values only tell the two kinds of row apart (every other row starts half a tile in and has one entry less in the table: 200 against 201).& 7like the 16-entry tables, on a table the header gives 8 entries (0x004B5B2E; a header finding below).L2_STONES_OR_DRIVEN_SANDUnkflag and again for ground higher than 16. The original jumps back to the first block for the second (0x004B5C94).blueis masked inside the mix while red and green are masked by statements: the original masks blue last, in the mix's block.pixelX, a copy ofxfor the full-size store: the original stores it at the top of that branch (0x004B5E19).row * heightFactoris odd are skipped, and the columns go in steps of 2 fromx's low bit.Checker CHECKs (not changed)
rowLengthandrowXare set in both arms of the row-parity test (rowLengthis declared in front of the row loop because the loop's header stepsrowBaseby it), andcolorby every arm of the colour chain.Header findings (nothing changed here)
MiniMapDefinedData::FordMinimapColorshas 16 entries, not 8: it is indexed[mode + (random & 7) * 2](0x004B5B2E to 0x004B5B34). The header'sfield_0x64[8]behind it is its second half.(param_4 + param_5) * 400 / 100is a signed division (0x004B58F8 to 0x004B591C), where the header hasuint param_5; the code casts. The siblingrenderMinimapTileStripWithLuminescencehas the two types the other way round (uint param_4, int param_5).param_1toparam_5:flags(bit 2: half size),widthFactor,heightFactor(a tile's width and height in pixels),stripStart,stripLength(in percent of the 400 screen tile rows).MiniMapDefinedData::MinimapColorArrayis the table for tiles withL_ROCKY(0x004B5B7F), as gynt's 2cb2df7, which named the 14 tables, notes.functioninsrc/precomp/addresses-SHC-3BB0A8C1.hpp(no label); it is the row loop's head inside this function, which runs to 0x004B5F6B.ebpin any function containing an__asmblock. This function has two and keeps none, in the original and here; the rule seems to need a narrower wording. main'sdrawCurrentPixel(0x00468F20) is another: an__asmblock and no frame pointer, whererenderMinimapPreview(0x004B5280) has one.🤖 Generated with Claude Code