Skip to content

UI: openBuildingStatusMenuForBuildingID at 100%, out of the draft #313 - #484

Merged
gynt merged 2 commits into
sourcehold:mainfrom
kotijekriv:reimpl/UI-A-obsm-100
Nov 24, 2026
Merged

gynt merged 2 commits into
sourcehold:mainfrom
kotijekriv:reimpl/UI-A-obsm-100

Conversation

@kotijekriv

Copy link
Copy Markdown
Contributor

One function at 100%, from our draft #313, where it stood at 86.1%. One .cpp and its status line. No header change, and no line for cmake/compiler-flags-gl.txt.

Function Address Before reccmp raw Normalised
AlphaAndButtonSurface::openBuildingStatusMenuForBuildingID 0x00463310 86.1% in #313 100.0% 100.0%

#313's version is restructured from gynt's. It started from his 8f3342a (53.1%, after bbc6d12 at 53.08%), and his newest reimplement commit on the file is 63cc49f (2026-10-25, on his fork's reimpl/UI-Rendering-development). The function's logic is his:

  • the two switches over the building type;
  • the menu tabs;
  • the statue's jump straight to the menu;
  • the countdown call.

The commit credits him as co-author.

The last instruction: the barracks' 1

  • Its one difference in Reimplement 17 rendering, UI and GameSynchronyState functions (not yet 100%) #313 was the countdown call's second argument (extendResourceCountdownForPlayerBuildingsOfType, push at 0x004633BD). The original pushes esi, which holds 1 from 0x00463344 on. The draft pushed the immediate 1.
  • The 1 that reaches the menu is the barracks' tab. BT_BARRACKS is the one arm of the second switch that does not set the menu tab; every other arm sets it or returns. With menuTab = 1 as the initial value, the compiler pushes the immediate. The draft tried the argument as menuTab, TRUE, 1u or (dword)1, an int menu tab, and two definitions of it, and all of them gave the same push.
  • Here the menu tab is declared without a value, and the barracks' arm sets it to 1. The 1 then stays in esi, and the call pushes esi, as in the original: quick_diff gives the original's 280 instructions. This is a source handle for the class tools/compiler-internals/msvc-backend.md describes in "A defect class: which constant gets the callee-saved register": the constant gets the register once the variable that also holds it has no initial value.
  • It is still set on every path to the menu. MSVC's C4701 (potentially uninitialized local) stays quiet with the warning on, and does fire on a test function that leaves a path unset. A one-line comment at the declaration says why it has no initial value.
  • The goto stays, with a comment. The statue's jump past the call to the menu is the original's (0x0046335F). Writing it as an if around the call and the second switch instead gives 0.9663: the gatehouse compare's block moves. Writing the menu's tail out in the statue's arm gives 0.8983.

Written as main writes it

  • The menu tabs use main's UI::Enums::BuildingsAndStatusMenuTabType names, as main's SelectBuySellGoods and MainButtons handlers do for buildingandstatusmenuMenuTabToSwitchTo. The siege tent's tab, 28, has no name there and stays a number, with a comment.
  • Two pairs of names read crossed against the building types. The function follows the original's jump tables (all 107 building types checked), so one of main's two enums seems to have these names the wrong way round. Which one, do you know?
    • BT_BATTERINGRAM gets 60, BASMTT_SIEGETENT_SIEGETOWER, and BT_SIEGETOWER gets 61, BASMTT_SIEGETENT_BATTERINGRAM;
    • BT_CAMPGROUND gets 43, BASMTT_CAMPFIRE, and BT_CAMPFIRE (with the parade grounds) gets 52, BASMTT_TRAININGGROUNDS.
  • menuTab is an int, as main's other menu-tab locals are.
  • No casts that convert nothing: the two findParticularBuilding calls and the tutorial call pass the building's fields as main's other calls do. The tutorial call keeps its (BuildingType), which a short needs.
  • The current player is read through the global in the keep's and the granary's arms, in all three indices; the draft's local for it went, so the goto no longer jumps past an initialised local.
  • All of this gives the same listing as the numbers, the casts and the local did.

Measured

  • Setup: the bundled MSVC1400-SP1 against the Steam Stronghold Crusader.exe (3bb0a8c1…5387ac5a), the struct resolvers and the function resolvers enabled locally (not committed), and sourcehold's reccmp with --resolve-wrapped-calls --ignore-security-cookie.
  • Full build: an all-on build of the previous cut of this branch on main 0e4a83b (the same code: this cut names the menu tabs with main's enum, drops casts that convert nothing, declares menuTab as int, reads the current player from the global in both arms and changes comments; its whole listing is the same in a narrow real build), with both resolver sets on and main's own /GL list (this file is not on it), and with 0x004314E0 (the MapEditorLandscaping_GeneralButtons handler) left out and its resolver off, as in main's baseline: 0 failed of 2,426 compile steps, 99.58 over 2,442 functions. openBuildingStatusMenuForBuildingID reads 100.0 raw and normalised there, with no diff entry, and its five callees (findParticularBuilding, closeHelpDialogAndReturnToMenu, switchToMenuView, extendResourceCountdownForPlayerBuildingsOfType and SetTutorialBuildingActionState) read 100.0 as before; no reimplemented function calls it. Against main's own build (made at f489b72, 2,439 functions) the only other changes are main's since then (One more UI::MenuModals function at 100%: ProgressBarBox #467's MenuModalRenderFunction_ProgressBarBox and its constructor, UI: the single-player game launch at 100% #466's LaunchSinglePlayerGameUnk), and every other function reads exactly what it read before (unrounded 99.5790 raw and 99.5529 normalised, 2,326 functions at 100.0 raw; main 0e4a83b alone: 99.5788 and 99.5528 over 2,441, 2,325 at 100.0).
  • Our narrower run: main's /GL list (the 133 files that exist) and this file, with its resolver on. The function reads 100.0% raw and normalised with no diff entry, and every other function reads as in the same build without it.
  • Checks: our local style checker gives 0 ERROR and 6 CHECK: the goto and the declaration without a value (both commented, above), and one placeholder name, field_0x2c6, read twice. Our local fixer finds nothing to change.
  • Not run in game.

🤖 Generated with Claude Code

AlphaAndButtonSurface::openBuildingStatusMenuForBuildingID comes out of our draft sourcehold#313, where it stood at 86.1%.
That version is restructured from gynt's: his 8f3342a (53.1%, after bbc6d12 at 53.08%), and his newest
reimplement commit on the file, 63cc49f (2026-10-25, on his fork's reimpl/UI-Rendering-development). The
function's logic is his: the two switches, the menu tabs, the statue's jump to the menu and the countdown call.
sourcehold#313 reordered the second switch's cases to the original's block layout (cb62724) and cleaned up the
decompiler's names and gotos.

Its one differing instruction was the second argument of the extendResourceCountdownForPlayerBuildingsOfType call
(0x004633BD): the original pushes esi, which holds 1 from 0x00463344 on, and the draft pushed the immediate 1. The
1 that reaches the menu is the barracks' tab: BT_BARRACKS is the one arm of the second switch that does not set the
menu tab. With `menuTab = 1` as the initial value the compiler pushes the immediate. Declared without a value and
set to 1 in the barracks' arm, the 1 stays in esi and the call pushes esi, as in the original. The menu tab is
still set on every path to the menu (MSVC's C4701 stays quiet with the warning on), and a one-line comment says why
it has no initial value. The one goto left, the statue's jump past the call to the menu, gets a one-line comment:
with an if around the call instead, the match is lost. The status line is 100.0%.

The menu tabs are main's UI::Enums::BuildingsAndStatusMenuTabType names; the siege tent's 28, which has none, stays
a number with a comment. menuTab is an int, as main's other menu tab locals are. The casts that convert nothing in
the two findParticularBuilding calls and the tutorial call are gone, as main passes these fields. The keep's and
the granary's arms read the current player through the global in all three indices; the local that held it went, so
the goto no longer jumps past an initialised local. The same listing as with the numbers, the casts and the local.

Measured: with the precompiled header, quick_diff gives the original's 280 instructions. A narrow real build
(main's /GL list and this file, with the struct resolvers and its function resolvers on, sourcehold's reccmp with
--resolve-wrapped-calls --ignore-security-cookie) reads 100.0% raw and normalised with no differing line, and every
other function reads as in the same build without it.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Style guide reading (advisory, posted once)

1 possible deviation(s) from REIMPLEMENTATION_STYLE_GUIDE.md across 1 of the 1 reimplemented .cpp file(s) in this PR.

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.

rule what it asks hits
20 Keep nesting low; no goto 1
Where

Rule 20 — Keep nesting low; no goto

  • src/OpenSHC/UI/Rendering/AlphaAndButtonSurface/openBuildingStatusMenuForBuildingID.cpp:45 — goto; check how many predecessors the target has first

…pass for by break, no goto

The review asked whether the goto is necessary. It is not. The body from the ownership test to the end of the
second switch now sits in a `for (;;)` that runs once: the unowned statue's arm leaves it with `break` where it
jumped to the label, and the other paths to the menu reach the `break` at its end. No switch encloses the statue's
arm, so its break leaves the loop; the breaks in the two switches still leave only their switch. The control flow
is the goto's, and so is the code: on this head merged with main 7c2e4d6 the quick listing is the same as the
head's, 280 instructions against the original's 280, quick_diff 1.0000 (the head reads 100.0 in a real build). `do
{ ... } while (0)` reads the same; the style guide asks for a for loop.

The goto-free forms that do not match: a bool or an int flag set in the statue arm, the first switch in an else and
the countdown call and the second switch under `if (!flag)`, 0.9875 (279 instructions); measured before, if / else
with `if (menuTab != 89)` around the call 0.9663 and the tail written out in the statue arm 0.8983.

The loop's body is one level deeper, so clang-format re-wraps three statements, and the comment on someone else's
building is reworded to stay on one line. Nothing else changes.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@gynt
gynt added this pull request to the merge queue Nov 24, 2026
Merged via the queue into sourcehold:main with commit 2aa1881 Nov 24, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants