Skip to content

Reimplement 3 UI functions at 100% from #529, plus 1 with register allocation differences - #550

Open
gynt wants to merge 9 commits into
sourcehold:mainfrom
gynt:reimpl/pr529-matched
Open

gynt wants to merge 9 commits into
sourcehold:mainfrom
gynt:reimpl/pr529-matched

Conversation

@gynt

@gynt gynt commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

This PR carries the finished part of draft #529 (reimpl/ui-menuviews-modals-development): the three functions from that draft that are at 100%, plus one function where only register allocation differs. The files come from the draft and compile against main's headers without changes.

Measured on origin/main (40cbb1c), then again after merging main 592a17d into this branch: I ran a full DLL build with exactly these files in cmake/openshc-sources.txt.local. Both resolver sets were switched on: the struct resolvers through enable_reimplemented_data.py and the function resolvers through enable_local_functions.py. The /GL entries below were in place. I then ran reccmp.

Function Address reccmp raw / normalized Status remark
UI::Helpers::SomeFearFactorComputation 0x0043E5A0 100.0 / 100.0 100.0% | Reimplemented
UI::StatusMenus::RenderStatusMenu_Overview 0x00447DC0 100.0 / 100.0 100.0% | Reimplemented
UI::MenuViews::HistoricMissionIntro::MenuView_HistoricMissionIntro_DoEveryFrame 0x004DB8B0 96.2 / 96.0 100.0% | Reimplemented (counted: only float constant names and _ftol2_sse differ)
UI::MenuViews::ScenarioDescription::MenuView_ScenarioDescription_Prepare 0x004DD100 96.3 / 88.2 96.3% | Register allocation differs

In MenuView_HistoricMissionIntro_DoEveryFrame, only labels differ: the 30.0/31.0/32.0 float constants, which reccmp leaves unlabelled on the original's side, and _ftol2_sse.

In MenuView_ScenarioDescription_Prepare, every remaining difference is an allocation difference, with no functional effect:

  • the two stores after rep stosd take their zero from esi instead of the eax that rep stosd leaves at zero;
  • mov ecx, 0x1f40 sits before xor eax, eax instead of after it;
  • one branch offset moves by 2 bytes, because the esi stores have a longer encoding.

This function was added after the user clarified what counts as register allocation only. Its style pass is in its own commit:

  • the string literals are imported, each with its text as a comment;
  • the comma-operator condition is written as nested ifs;
  • the locals are named, and the unused usings and the trailing return; are gone.

The event conditions are cleared with a nested countof loop over SEC_EventsExtra[event].conditionIsTrue, which MSVC compiles to the original's rep stosd. memset is compiled as a call instead and drops the function to 84.9.

Header changes: none.

GL / visibility entries: cmake/compiler-flags-gl.txt gets RenderStatusMenu_Overview.cpp and SomeFearFactorComputation.cpp, as in the draft. The original's RenderStatusMenu_Overview relies on knowing that SomeFearFactorComputation clobbers only ecx, and that only reproduces when both are compiled with /GL. No function-visibility entries are needed.

Overlap with open PRs: #318 also contains SomeFearFactorComputation.cpp, in a different version. Whichever PR is merged second will conflict on that file. The version in this PR is the one measured at 100% on current main.

Left in the draft:

  • RenderPlayerInfoOnHoverDisplayElement (68.2%)
  • MenuView_CampaignUnk_Prepare (98.2%)
  • MenuView_CrusadeMap_DoEveryFrame (75.3%)
  • MenuView_RankingGames_DoEveryFrame (80.4%)
  • MenuView_ScenarioDescription_DoEveryFrame (90.7%)

None of these differs in register allocation alone, so none goes into this PR. RenderPlayerInfo and ScenarioDescription_DoEveryFrame reassociate an addition (ecx = -0x30 - a; b += ecx in the original against b -= a; b -= 0x30 in ours). CampaignUnk differs in lea against add. CrusadeMap and RankingGames differ in block layout and tail merging. Draft #529 stays open for them.

There is one commit per function, each with its status line. There is also one commit for the /GL entries, plus the style commit and a merge of main.

Style pass (7da4461): all three files now follow REIMPLEMENTATION_STYLE_GUIDE.md as it is on main.

  • MenuView_HistoricMissionIntro_DoEveryFrame:
    • named locals (windPlaying, ticks, blendStrength) instead of BVar1/iVar2, declared at first use;
    • an early return replaces the comma operator in the fade condition, and the fade step uses +=;
    • decimal coordinates, f float literals and no redundant (double) casts;
    • countof for the mission sound table;
    • no trailing return; and no unused usings.
    • The 31.0 in the fade reversal stays a double, with a comment: the original subtracts in double precision (fsubr qword).
  • RenderStatusMenu_Overview:
    • decimal coordinates, font size and text index;
    • += for the width sum;
    • comments on the three description parts;
    • no unused usings, and the unused BGR24 include is gone.
  • SomeFearFactorComputation: comments on the closing namespaces.

Re-measured with a full build and reccmp: unchanged. Two functions are at 100.0 / 100.0, and HistoricMissionIntro is at 96.2 / 96.0 with only labels differing. No change had to be reverted.

Pre-review pass (61bee57): code comments that only explained match-driven forms are now in the PR thread. One-use locals that are not needed for the match are folded into their ifs, and the event clear is a countof loop. The four measurements are unchanged.

🤖 Generated with Claude Code

https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp

gynt and others added 4 commits December 4, 2026 15:14
…n with /GL

RenderStatusMenu_Overview only matches when SomeFearFactorComputation is
compiled with it under /GL: the original's caller knows the callee
clobbers only ecx. Entries taken from draft sourcehold#529.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp
Taken from draft sourcehold#529. Measured on main 40cbb1c with the three files of
this PR in .local, both resolver sets enabled and the /GL entries: reccmp 100.0 / normalized 100.0.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp
Taken from draft sourcehold#529. Measured on main 40cbb1c with the three files of
this PR in .local, both resolver sets enabled and the /GL entries: reccmp 100.0 / normalized 100.0.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp
…ro_DoEveryFrame

Taken from draft sourcehold#529. Measured on main 40cbb1c with the three files of
this PR in .local, both resolver sets enabled and the /GL entries: reccmp 96.2 / normalized 96.0, the only differences being float constant names and _ftol2_sse, so counted as 100% per main's convention.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp
@github-actions

github-actions Bot commented Dec 4, 2026

Copy link
Copy Markdown

Style guide reading (advisory, posted once)

12 possible deviation(s) from REIMPLEMENTATION_STYLE_GUIDE.md across 2 of the 3 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
1 Drop the decompiler trailing return; 1
16 Give variables a name that says what they hold 1
18 Use the name, not the number 8
23 Prefer if-else over ternary 1
24 Declare variables upon first use 1
Where

Rule 1 — Drop the decompiler trailing return;

  • src/OpenSHC/UI/MenuViews/HistoricMissionIntro/MenuView_HistoricMissionIntro_DoEveryFrame.cpp:118 — trailing return; in a void function

Rule 16 — Give variables a name that says what they hold

  • src/OpenSHC/UI/MenuViews/HistoricMissionIntro/MenuView_HistoricMissionIntro_DoEveryFrame.cpp:48 — decompiler name iVar2

Rule 18 — Use the name, not the number

  • src/OpenSHC/UI/MenuViews/HistoricMissionIntro/MenuView_HistoricMissionIntro_DoEveryFrame.cpp:95 — hex constant 0x15E; use a name, or decimal
  • src/OpenSHC/UI/MenuViews/HistoricMissionIntro/MenuView_HistoricMissionIntro_DoEveryFrame.cpp:98 — hex constant 0x15E; use a name, or decimal
  • src/OpenSHC/UI/StatusMenus/RenderStatusMenu_Overview.cpp:37 — hex constant 0x1C7; use a name, or decimal
  • src/OpenSHC/UI/StatusMenus/RenderStatusMenu_Overview.cpp:38 — hex constant 0x1CF; use a name, or decimal
  • src/OpenSHC/UI/StatusMenus/RenderStatusMenu_Overview.cpp:69 — hex constant 0x242; use a name, or decimal
  • src/OpenSHC/UI/StatusMenus/RenderStatusMenu_Overview.cpp:76 — hex constant 0x242; use a name, or decimal
  • src/OpenSHC/UI/StatusMenus/RenderStatusMenu_Overview.cpp:84 — hex constant 0x242; use a name, or decimal
  • src/OpenSHC/UI/StatusMenus/RenderStatusMenu_Overview.cpp:89 — hex constant 0x242; use a name, or decimal

Rule 23 — Prefer if-else over ternary

  • src/OpenSHC/UI/StatusMenus/RenderStatusMenu_Overview.cpp:51 — ternary; the guide prefers extending the if-else chain

Rule 24 — Declare variables upon first use

  • src/OpenSHC/UI/MenuViews/HistoricMissionIntro/MenuView_HistoricMissionIntro_DoEveryFrame.cpp:47 — declare BVar1 where it is first assigned

gynt and others added 3 commits December 4, 2026 15:33
…GUIDE

MenuView_HistoricMissionIntro_DoEveryFrame:
- named locals (windPlaying, ticks, blendStrength) instead of BVar1/iVar2,
  declared at first use
- early return instead of the comma operator in the fade condition,
  += for the fade step
- decimal coordinates, 0.0f/30.0f/31.0f float literals, no redundant
  (double) casts, countof for the mission sound table
- the 31.0 in the fade reversal stays a double with a comment: the
  original subtracts in double precision (fsubr qword)
- dropped the trailing return and the unused usings

RenderStatusMenu_Overview:
- decimal coordinates, font size and text index, += for the width sum,
  comments for the three description parts
- dropped the unused usings and the unused BGR24 include

SomeFearFactorComputation: namespace closing comments.

Re-measured on main 40cbb1c with a full build and reccmp: unchanged,
SomeFearFactorComputation and RenderStatusMenu_Overview at 100.0 / 100.0,
HistoricMissionIntro at 96.2 / 96.0 with only float constant names and
_ftol2_sse differing.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp
…on_Prepare, register allocation differs

Taken from draft sourcehold#529, with the style pass applied (imported string
literals with their text as comments, the comma-operator condition written
out as nested ifs, named locals for the event-condition clear, no
unused usings or trailing return). memset was measured for the clear and
costs the match (it is called, not inlined), so the pointer walk stays
with a comment.

Measured on main 592a17d with a full build and reccmp: 96.3 / 88.2.
The only remaining differences are allocation ones:
- the two stores after the rep stosd use the zero in esi instead of the
  eax that rep stosd leaves at zero;
- the mov ecx, 0x1f40 count load sits before instead of after xor eax, eax;
- one branch offset moves by 2 bytes because the esi stores encode longer.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp
@gynt gynt changed the title Reimplement 3 UI functions at 100% from #529 Reimplement 3 UI functions at 100% from #529, plus 1 with register allocation differences Dec 4, 2026
- SomeFearFactorComputation, HistoricMissionIntro: the comments that only
  explained match-driven forms move to the PR thread.
- HistoricMissionIntro: the wind-sound check and the tick count feed the
  ifs directly instead of going through one-use locals.
- ScenarioDescription_Prepare: the event-condition clear is a countof loop
  over SEC_EventsExtra[event].conditionIsTrue instead of a pointer walk;
  MSVC still turns it into the original's rep stosd.
- RenderStatusMenu_Overview: the two description comments are one.

Re-measured on main 592a17d with a full build and reccmp, unchanged:
100.0 / 100.0 / 96.2 (counted) / 96.3 (register allocation differs).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp
@gynt

gynt commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor Author

These forms stay as they are because they are needed for the match. Each was measured with a full build and reccmp on main 592a17d.

SomeFearFactorComputation

  • The last check, if (fearFactor >= 0) return 17;, is always true at that point, and the function returns 17 after it anyway. Without that check (a plain return 17;, an if/else-if chain, or a result variable), MSVC folds the 17/18 pair into setge, while the original loads 18 before the jge and branches. The plain form drops from 100% to 85.7% in quick_diff, the same if-conversion that held the draft at 85.1%. The one other matching form, if (fearFactor <= 2) return 17;, is just as redundant, so I kept the current one.
  • The return type undefined4 comes from Helpers.hpp. The function returns a TEXT_PLAYER_DESC index, so it should probably be int. I left the header unchanged because the match does not need a change there.

RenderStatusMenu_Overview

  • The locals nameX/nameY/name, descY/description, andY, popY/popularity and widthPopularity fix the order in which the original loads the positions relative to the calls. Passing those values straight into the calls drops the function from 100% to 68.9%.

MenuView_HistoricMissionIntro_DoEveryFrame

  • 31.0 - FLOAT_00ec0834::instance keeps the double literal on purpose. The original subtracts in double precision (fsubr qword), and 31.0f would turn that into a float subtraction.
  • The textX/textY/borderW/borderH locals before renderMultilineText5Unk give the original's load order. Writing the sums directly into the call drops the function from 96.2% to 92.5%.

MenuView_ScenarioDescription_Prepare

  • memset(SEC_EventsExtra, 0, sizeof(SEC_EventsExtra)) is compiled as a call instead of being inlined to the original's rep stosd, which drops the function to 84.9%. A nested countof loop over SEC_EventsExtra[event].conditionIsTrue gives the rep stosd, and that is the form used now.
  • loadMapSiegeHeaderForMissionIndex is declared with a char* parameter but is passed the mission number. That is why (char*)DAT_GameCore::instance.missionNumber1to20 needs a cast, and the parameter type is probably wrong. The header is left unchanged.

Casts kept after the cast pass. No cast in this PR could go without changing the code or the build. Kept:

  • MenuView_ScenarioDescription_Prepare.cpp:102, (char*)DAT_GameCore::instance.missionNumber1to20: the header declares loadMapSiegeHeaderForMissionIndex with a char* parameter, but the original takes an int mission number. I proposed int for Ghidra; the cast goes away once that is fixed in Ghidra.
  • MenuView_HistoricMissionIntro_DoEveryFrame.cpp:67,69, (long) on the float fade value stored into the int blend strength: without it C4244 appears.

This branch has not been deployed

No deployments
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.

1 participant