Repository navigation
UI: the minimap's second picture at 100% - #465
Open
kotijekriv wants to merge 4 commits into
Open
kotijekriv wants to merge 4 commits into
kotijekriv wants to merge 4 commits into
Conversation
MinimapViewState::renderMinimapTileStripWithLuminescence, the minimap's second picture: for a strip of the screen tile rows it takes the colour of what stands on each tile (moat, trees, plain tiles with one display flag, or the first entry of MiniMapDefinedData's table that shares a bit with the tile's flags), scales it by the tile's luminescence (RGB555 or RGB565) and writes it into the second minimap buffer, at full or at half size; a tile without a colour takes the terrain picture's pixel. It is the sibling of renderMinimapTileColors (0x004B58D0) and is written the same way, from the original's listing. The function was a 21.4% draft in sourcehold#313 ("Pixel store and registers differ"). sourcehold#313's version started from gynt's draft as it stood on his fork's reimpl/UI-Core-development, 10280b1 (2026-10-25; status line "9.3% | Reimplemented, asm differs"), with the body rewritten from the listing. His newest version is 4a1f8dd (2026-11-02, a style pass over the UI folders; "9.0% | Style pass, asm differs") on reimpl/UI-MenuItems-development, where 1056d3f, 2da2d36 and b60bb72 are earlier steps of it (9.03%); 24080c9 and 1955a67 (9.0%) are the same draft on reimpl/UI-Core (sourcehold#256). No behaviour change against sourcehold#313's code (the strip's end is now divided signed, as in the original; the same for every real argument). What sourcehold#313 changed against every version of the draft stays: - `mapSize <= 200` where the draft has `< 200` (every 200 by 200 map); - the return past the strip's end, which the draft lacks (reached by drawMinimap's 2% strips). gynt has it himself in 8ca7861 on reimpl/Wilps-2026-10-18; - the second buffer written through `this`, as in the original, where every version of the draft goes through the global instance (the same address while `this` is DAT_MinimapViewState); - the screen tile table indexed from its base on today's main (not the draft's mistake: its `- 8` was right for the header of its day). What the match needed: - The pixel stores are handwritten assembly in the original: the same two stores as in renderMinimapTileColors, with the address computation of renderMinimapPreview and drawCurrentPixel (`add eax, eax` and a `mul edx` by the row pitch, here the constant 400). Two `__asm` blocks, one per size. No frame pointer, as in the original. - The colour is a 16-bit local, and the blue channel and the mix are written out in both colour-mode arms. Here the original has one shared end for the two arms: the compiler merges the two identical ends itself. Written once behind the arms, the registers of the whole block are different ones. - The channels initialised blue, green, red; red's and green's masks as statements right after their caps, blue's in the mix, as in renderMinimapTileColors. - The table loop: the entry's bits in a local that is set before the tile's flags are read, the first test on that local and the loop's test on the table. The two tests take their operands in the order the variables are first set; with the first test on the table and the loop's on the local, both come out swapped. A flag tells "no entry" from "found"; the compiler turns it into the two jumps. The loop is a guarded do-while: a plain while loop reads 99.7% (one of the two tests swapped, whether it tests the local or the table), and a for loop with a break at its end compiles to two instructions more. - The five simple initialisations before the buffer and the strip rows, so that every stack slot is the original's; the row base holding the orientation's offset first; the viewport height read from the global a second time; the column loop's bound in its test; the tile read before x and y; y inside the tile loop and a copy of x at the top of the full-size branch; the row base stepped in the row loop's header. The channel masks have names in a small file-local enum, as in renderMinimapTileColors. 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) 2 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
Rule 9 — Prefer
|
TheRedDaemon
requested changes
Nov 22, 2026
…5 colour A new enum in OpenSHC::Rendering beside ColorMode: the masks of the red, green and blue channels in the two colour modes. renderMinimapTileStripWithLuminescence (and renderMinimapTileColors) scale each channel of a minimap colour by the tile's light and cap it at these masks; they had them as a file-local enum. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nstants Review: the channel masks come from the new ColorChannelMask header enum; the map's 400 rows and its 200-tile size from Map::MapConstants (MC_MAP_XY_LIMIT, MC_MAP_SIZE_200); the screen tile table's start, its two row lengths (200 and 201) and its 80400 entries per orientation from Rendering::Enums::ViewportConstants. The orientation offsets are VC_SCREEN_POINT_TABLE_START + k * VC_SCREEN_POINT_TABLE_SIZE, and 401 is a short and a long row. The two inline assembly blocks take the buffer's row length from a file-local enum, since inline assembly cannot name a qualified constant. The same code: the quick compile's listing is unchanged, and a narrow build of this file reads 100.0 raw and normalised with no diff entry. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e buffer's row from map constants Review: the first row for a map of up to 200 tiles is the margin around it, (MC_MAP_XY_LIMIT - MC_MAP_SIZE_200) / 2, and the assembly's row length is a buffer row of MC_MAP_XY_LIMIT / 2 pixels in bytes (both minimap buffers are 400 rows of 200 ushorts). The same code: the quick compile's listing is unchanged, and a narrow build of this file reads 100.0 raw and normalised with no diff entry. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kotijekriv
added a commit
to kotijekriv/OpenSHC
that referenced
this pull request
Nov 22, 2026
The style bot suggests letting MSVC unroll the two `offsetX += 2` loops. They draw every other pixel at half size, as in renderMinimapTileStripWithLuminescence (sourcehold#465), and get the same one-line comment. Written as a plain loop that skips the odd pixels, the function no longer matches: in a quick compile 378 lines differ instead of 10. Comments only; the listing is the same as before. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
TheRedDaemon
approved these changes
Nov 22, 2026
kotijekriv
added a commit
to kotijekriv/OpenSHC
that referenced
this pull request
Nov 23, 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.
One function at 100%, the sibling of
renderMinimapTileColors(#461) and written the same way, from the original's listing. It comes out of our draft #313, where it stood at 21.4%. One header change, in a commit of its own: a new enum,OpenSHC::Rendering::ColorChannelMask(src/OpenSHC/Rendering/ColorChannelMask.hpp, 2246b2f), for the colour channels' masks. Main's declaration check fails on any new header undersrc/OpenSHCand labels the PR, so this PR waits for the header to reach main through the Ghidra sync, as the other declaration-change PRs do. No behaviour change against #313's code.MinimapViewState::renderMinimapTileStripWithLuminescence#313's version started from gynt's draft as it stood on his fork's reimpl/UI-Core-development, 10280b1 (2026-10-25; status line "9.3% | Reimplemented, asm differs"), with the body rewritten from the listing. His newest version is 4a1f8dd (2026-11-02, a style pass over the UI folders; "9.0% | Style pass, asm differs") on reimpl/UI-MenuItems-development, where 1056d3f, 2da2d36 and b60bb72 are earlier steps of it (9.03%); 24080c9 and 1955a67 (9.0%) are the same draft on reimpl/UI-Core (#256). What #313 changed against every version of the draft stays:
renderMinimapTileColors(UI: the minimap's terrain colours at 100% #461). The original takes the small maps' path formapSize <= 200(0x004B53E4:cmp ..., 200; jg). Every version of the draft has< 200. So on a 200 by 200 map, with the 4 by 2 pixel tiles that the caller hands it, the draft drew the table's left half into 400 rows of the buffer, where the original fills 200 rows with the table's centre.jgeto the epilogue). The draft has an emptyifthere. gynt has the return himself in 8ca7861 ("wilps-2026-10-18", 2026-10-27) on his reimpl/Wilps-2026-10-18.drawMinimapreaches it on every step of its step-by-step redraw (2% of the rows per call, see below). Without it, each call drew every row from the strip's start to the end of the table.this. Every version of the draft writes the second buffer through the global instance (the fixed address 0x01A31654,DAT_MinimapViewState0x01A31610 plus 0x44). The original takes it fromthis(0x004B5343 to 0x004B534C), as this file does. The two agree whilethisis that instance. Seven of the ten call sites ofsetMapPropertyDependingOnMapSizepass that instance outright;drawMinimap's three pass its ownthis.- 8, which was right for the header of its day (the array at 0x4E600). Main's header has since moved the array to 0x4E5E0 (2bd620b).Update (review)
OpenSHC::Rendering::ColorChannelMaskinsrc/OpenSHC/Rendering/ColorChannelMask.hpp, next toColorMode: the red, green and blue masks of an RGB555 and an RGB565 colour (CCM_RGB555_RED...CCM_RGB_BLUE). It replaces the file-local enum;renderMinimapTileColors(UI: the minimap's terrain colours at 100% #461) has the same five masks.Map::MapConstants: the map's 400 rows and columns (MC_MAP_XY_LIMIT), the 200-tile test (MC_MAP_SIZE_200), and the small map's first row, its margin(MC_MAP_XY_LIMIT - MC_MAP_SIZE_200) / 2. FromRendering::Enums::ViewportConstants: the screen tile table's start and one table of 80400 entries per orientation (VC_SCREEN_POINT_TABLE_START + k * VC_SCREEN_POINT_TABLE_SIZE), and its short and long rows (200 and 201, and 401 for the pair). The inline assembly takes a buffer row in bytes (MC_MAP_XY_LIMIT / 2 * sizeof(ushort)) from a file-local enum, because inline assembly cannot name a qualified constant.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.tools/, 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 callersetMapPropertyDependingOnMapSize, as before. Two functions on main read lower, and it is how reccmp prints a constant, not their code:Menu::handleMenuItems(0x004F6280) reads 97.9 (91.4 normalised) andMenu::Constructor_Menu(0x004F4100) reads 98.4 (95.2), both 100.0 before. Both compare a menu item's type with the constant 0x11000000, five compares in all. In this build's layout a symbol of our DLL lies at exactly the address 0x11000000, so reccmp prints the constant as that symbol's name on our side. The instructions are the same on both sides; UI: three more functions at 100%: the building menu's DoInitial, the credits' prepare and activateModalDialog2 #435 and UI: the credits scroll's fade and the win/defeat window at 100% #437 describe the same two readings. Every other main function reads exactly what it read before (unrounded 99.5746 against 99.5759 raw and 99.5439 against 99.5492 normalised; with those two at 100.0 it would be 99.5761 and 99.5494, as in UI: the minimap's terrain colours at 100% #461's build).lea ecx, [ecx], twolea ebx, [ebx]and twomov edi, edi), in its order; reccmp's diff for the function is empty. The function makes no calls and has no switch table.What the function does
For a strip of the screen tile rows it writes the minimap's second buffer (
field_0x44): each tile in the colour of what stands on it, scaled by the tile's luminescence, at full size or, zoomed out, at half size. A moat tile and a tree tile take a colour from their own tables (field_0x74,field_0x144); anL_PLAIN2_AND_PITCHtile takesfield_0x20's colour if its display layer hasMD_RUBBLE_EDGEUnk; every other tile takes the colour of the first entry ofMinimapColorByLogicBitthat shares a bit with its flags. A tile that ends up without a colour takes the pixel of the terrain picture (minimapPixelBuffer, whichrenderMinimapTileColorsdraws). Its one caller on main,setMapPropertyDependingOnMapSize, always asks for half size and passes its strip on:drawMinimap(0x004B66C0, not on main) asks for 2% of the rows at a time while it redraws the minimap (0x004B67CF, 0x004B67F2).Read block by block against the listing, #313's code already did all of that. One arithmetic detail differs: the strip's end is divided signed here, as in the original (#313 divided unsigned; the same for every real argument).
What got it to 100%
renderMinimapTileColors(UI: the minimap's terrain colours at 100% #461), instruction for instruction but for the stack slots, with the address computation ofrenderMinimapPreviewandPencilRenderCore::drawCurrentPixelon main (add eax, eaxand amul edxby the row pitch, here the constant 400). They are two__asmblocks, one per size, 12 and 10 instructions. Once both functions are on main, the two files can share the stores as a macro in an*Asm.hpp, as AGENTS.md has it for a stream that repeats; that is left for then (a new header undersrc/OpenSHCtrips the declaration check, and either PR would then wait for the other). Everything around them is C++: the loops, the bounds tests, the half-size divisions and the read of the terrain picture's pixel. The function keeps no frame pointer with them, as in the original.renderMinimapTileColors.tests in the order the variables are first set, so with the first test on the table and the loop's on the local both come out swapped, and with every test on the table, or with the local set after the flags, the first one does (99.5% and 99.7% in narrow builds). A flag tells "no entry" from "found"; the compiler turns it into the two jumps and never stores it. The loop is a guarded do-while: a plainwhilereads 99.7% (one of the two tests swapped, whether it tests the local or the table), and aforloop with a break at its end compiles to two instructions more.rowBaseholding the orientation's offset first; the viewport height read from the global a second time for the other row parity; the column loop's bound in its test; the tile read beforexandy;yinside the tile loop and a copy ofxat the top of the full-size branch, so that the stores of the assembly's operands stand where the original has them;rowBasestepped in the row loop's header.One thing our quick single-file compile got wrong on the way: it orders the operands of those two
tests the other way round than the real build does, so the form that matched there read 99.5% in reccmp. The numbers above are all from real builds.Things in the file that look odd and are the original's
int entry = 0; int entryBits = 0;at the top of the tile loop, andint blue = 0; int green = 0; int red = 0;: see "The table loop" and "The channels".bool hasEntry, a flag that is never stored: see "The table loop".entryBitsand the loop's test reads the table again, although the local holds the same value: see "The table loop".if (color == 0)before every pixel): the original tests it there (0x004B5730, 0x004B580F). Only the first pixel can find 0, unless the terrain picture's pixel is 0 as well.viewportHeight + 1in stack slots of their own; the second read is what gives the+ 1its own slot here. The two values only tell the two kinds of row apart.pixelX, a copy ofxfor the full-size store: the original stores it at the top of that branch (0x004B56FC).row * heightFactoris odd are skipped, and the columns go in steps of 2 fromx's low bit.firstColumn - 2), whichrenderMinimapTileColorsdoes not: the original has the- 2(0x004B54E8).Checker CHECKs (not changed)
MinimapViewState::field_0x44is the minimap's second pixel buffer (this function writes it, 400 bytes a row likeminimapPixelBuffer);MiniMapDefinedData::field_0x74are the moat's colours (L_MOAT),field_0x144the trees' (L_TREE | L_TREE_VARIATION), andfield_0x20the colour pair ofL_PLAIN2_AND_PITCHtiles withMD_RUBBLE_EDGEUnk. gynt's headers on reimpl/Wilps-2026-10-18 (8ca7861) already call themcompositedPixelBuffer,moatColors,treeColorsandplain2PitchColor.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 (not changed here)
uint param_4; the code casts. (renderMinimapTileColorshas the two types the other way round,int param_4, uint param_5.)param_1toparam_5:flags(bit 2: half size),widthFactor,heightFactor,stripStart,stripLength.functioninsrc/precomp/addresses-SHC-3BB0A8C1.hpp(no label); it is the row loop's head inside this function, which runs to 0x004B58C8.🤖 Generated with Claude Code