Repository navigation
UI: TextureRenderCore's moveOverlappingMenuPartsToMapSurface at 100% - #476
Open
kotijekriv wants to merge 1 commit into
Open
kotijekriv wants to merge 1 commit into
kotijekriv wants to merge 1 commit into
Conversation
TextureRenderCore::moveOverlappingMenuPartsToMapSurface: copies the parts of the open menu tab that reach over the map from the menu surface onto the map surface, all but the magenta pixels. The tab's records hold x, y, width and height; -1 ends them, and the records after a -2 lie outside the 800 pixels of the menu, so at 800x600 the function stops there. The pixel copy is the original's handwritten loop, as inline assembly. From gynt's draft: his 68.0% c2e5474 ("Asm copy loop recovered, fixed missing return at 800x600") on sourcehold's reimpl/TextureRenderCore, the newest cee658d (2026-11-02) on his fork's reimpl/UI-MenuItems-development. Behaviour against the draft: at 800x600 the original returns at the first -2 marker (0x00454F64), so the records behind it are not drawn. c2e5474 and 8ca7861 have that return; 4696942 / 196c54f (the 24.6% file, which is what sourcehold#255 had when it closed), 81e1041, 5c82ddb, dd14331, 63cc49f and cee658d have an empty `if` there and draw them anyway. What the match needed: the zero-based tab (`tab - 1`) as a value of its own (written into the -1 test's index, its -5 is folded into that address); the record index computed a second time in a local of its own, as the original does; the four record pointers in the original's order; the end test at the bottom of a `for (;;)`. Measured in a narrow build of this file on main 0e4a83b with both resolver sets on: 100.0% raw and normalised. Not run in game. 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%, from our draft in #363 (96.5% there), which started from gynt's asm draft. No header changes. One behaviour fix against most versions of his draft (below).
TextureRenderCore::moveOverlappingMenuPartsToMapSurfacegynt's draft goes back to 4696942 (2026-10-01, "reimplement: SHC_3BB0A8C1_0x00454F00 24.60% Style pass, asm differs"); 196c54f is the same file, and it is what #255 had when it closed. His best is c2e5474 (2026-10-04, "reimplement: SHC_3BB0A8C1_0x00454F00 68.0% Asm copy loop recovered, fixed missing return at 800x600, ..."), on sourcehold's reimpl/TextureRenderCore. The newest version is cee658d (2026-11-02, "style: rules 1, 3, 15 and 22 over UI/Rendering, BuildingMenus, Helpers and the rest") on his fork's reimpl/UI-MenuItems-development, and 8ca7861 on reimpl/Wilps-2026-10-18 has his newer export.
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).MapEditorLandscaping_GeneralButtonshandler) left out and its resolver off, as in main's baseline: 0 failed of 2,426 compile steps, 99.58 over 2,442 functions. The new function reads 100.0 raw and normalised there too, with no diff entry. Against main's baseline build (made at f489b72, 2,439 functions) the other changes are main's own since then (One more UI::MenuModals function at 100%: ProgressBarBox #467'sMenuModalRenderFunction_ProgressBarBoxand UI: the single-player game launch at 100% #466'sLaunchSinglePlayerGameUnkat 100.0,Constructor_MenuModal_ProgressBarBoxat 100.0 instead of 93.8) and two functions that read lower only in how reccmp prints a constant:Menu::handleMenuItems(0x004F6280) reads 97.9 (91.4 normalised) andMenu::Constructor_Menu(0x004F4100) 98.4 (95.2), both 100.0 before. Both compare a menu item's type with the constant 0x11000000, five compares in all, and in this build's layout a symbol of our DLL lies at exactly that address, so reccmp prints the constant as the symbol's name on our side; the instructions are the same on both sides (UI: the single-player game launch at 100% #466 describes the same two readings). Every other function reads exactly what it read before (unrounded 99.5775 raw and 99.5475 normalised, 2,324 at 100.0 raw; with those two at 100.0 it would be 99.5790 and 99.5529, 2,326, as the same main with one other function at 100% reads).What the function does
When a menu tab is open, the parts of it that reach over the map are copied from the menu surface onto the map surface, all but the magenta pixels. The tab's records in
BlendingDefinedDatahold x, y, width and height; -1 ends them, and the records after a -2 lie outside the 800 pixels of the menu, so at 800x600 the function stops there. The copy is the original's handwritten pixel loop, as inline assembly.Behaviour against the draft
jeto the epilogue), so the records behind it are not drawn. c2e5474 and 8ca7861 have that return. 4696942 / 196c54f (reimplement OpenSHC::UI::Rendering (106 functions, 19 at 100%) #255's), 81e1041, 5c82ddb, dd14331, 63cc49f and cee658d have an emptyifthere and draw them anyway.The rest does what the draft does.
What got it to 100%
Each of these was measured against the alternative it names:
tab - 1) as a value of its own. The original keeps the -5 of(tab - 1) * 5in itslea(lea ecx, [eax + eax*4 - 5], then the shift). Written into the -1 test's index, the -5 is folded into that address. A redundant conditional (tab != 0 ? tab - 1 : 0) gives the same code as the local.for (;;), as in the original. With the test in thefor's header (for (; *x != -1; y += 4, height += 4, width += 4, x += 4)), a narrow build reads 80.4% (70.6% normalised), with 104 instructions to the original's 100: the first record's x is tested once more in front of the loop.Why the pixel loop is inline assembly
There is no
mov reg, 0here. The loop shows the inline-asm shape instead: each of its inputs is stored to a stack slot and loaded straight back into esi, edi, ecx or edx just before it (0x00454FA1 to 0x00455002), the width is reloaded from its slot on every row, the colour key sits inbx, and the function keeps a frame pointer. gynt's c2e5474 already had these 17 instructions as inline asm.Checker CHECKs (not changed)
field_0x3014is a placeholder: inBlendingDefinedDatait holds the menu tabs' records of the parts that reach over the map (x, y, width, height per record; -1 ends a tab's list, and the records after a -2 lie outside the 800 pixels of the menu). Not renamed here (see below).for (;;)with its end test at the bottom, see above.COL_MAGENTAitself, so the block namesCOL_MAGENTA::instance.shortValue. Main's drawTgxOnFlaggedSurface namesDAT_TextureRenderCoreObject::instance.currentRenderSurfacethe same way. The(void)sizeof(COL_MAGENTA::instance)line lets inline asm name it, as on main in ApplyBlending, BlitMapImageWithVerticalClip, RenderTerrainTilesCenterPiece and five PencilRenderCore files. The surface pointers, the line jumps and the record walk are C++.Proposed, not changed here
field_0x3014isint[55][8]in main's header, nothing else on main uses it, and in the exe only this function reads it. The exe's data at 0x00AB8730 is 11 tabs of 10 records of x, y, width and height (160 bytes a tab), sotabIndex * 5is five rows of eight ints a tab; -1 ends each tab's list (the last tab has none), and every record after a -2 lies outside the 800 pixels of the menu: (800, 417, 22, 55), (-49, 464, 57, 8) and (869, 461, 36, 11). Proposed: a record struct{ int x, y, width, height; }as[11][10], with a name such asmenuTabMapOverlapRects. Not changed here: the match hangs on how the index is written, so a retyped table needs its own measurement (a[11][40]shape did not help at 84.8%, before thetabIndexchange), and it is a header change of its own.ViewportConstantshasVC_MAP_SURFACE_HEIGHT = 2076but no width, and main's.cppfiles write 4056 on 35 lines, with a comment as here (drawTgxOnFlaggedSurface, in the same class). Proposed:VC_MAP_SURFACE_WIDTH = 4056. Not added here: it is a header change, and its use belongs in all 35 places at once.🤖 Generated with Claude Code