Repository navigation
cmake: function-visibility.txt, which callers must see which callees' bodies - #398
Conversation
… bodies
One entry per caller, with the callees whose bodies it must see when it is
compiled, fully qualified as the definitions are written:
OpenSHC::funcA
OpenSHC::funcB
87 entries, 127 edges, sorted by the caller's address. Every edge is a
tu_merge.py measurement: pasting the callee into the caller's unit raises the
caller's quick_diff ratio, and for callers with several callees a leave-one-out
over the full set decided which are needed together. In all 127 the callee is
at a lower address than its caller.
Twelve measured gains are left out because they cannot be same-file edges:
in seven the callee is at a higher address than its caller, and the other
five would put a callee into a unit with callers that measure worse when they
see it.
23 names are not on main yet. 22 are Map::Units Update callers: they were
measured on our local branches reimpl/units-B-development and
reimpl/units-A-development (UpdateCamel is also on the local
reimpl/units-B-round2-100), and gynt's reimpl/map-units-updatefunctions has
drafts of all 22. The 23rd is UnitsState::changeDestinationByAmount from sourcehold#378.
A generator skips names it cannot find. The measurements are in the PR
description.
Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tCounter's body sourcehold#290 rewrote UpdateBadBuildingGibbet and UpdateBadBuildingStretchingRack so that they reach 100% without /GL. On main (ea63a49), tu_merge.py gives both 1.0000 in all three layouts: the caller alone, the callee's body pasted before it, and pasted after it (45 of 45 and 41 of 41 instructions). Seeing updateBuildingSignpostCounter no longer helps either of them, so their two entries go. The callee keeps its other two callers, UpdateBadBuildingGallows and UpdateBadBuildingDungeon. The manifest now has 85 entries and 125 edges. On main's sources the wrapper generator from sourcehold#399 makes 24 units holding 91 source files (93 before), with no internal-name clashes and the same 23 names not on main yet. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Updated after #290: I merged main in (a731ab3), then dropped two entries (6ba3369). UpdateBadBuildingGibbet and UpdateBadBuildingStretchingRack now reach 100% with or without updateBuildingSignpostCounter's body, so those two edges are gone, and the list has 85 entries and 125 edges. Their "must not see addBuildingToTargetableBuildings" rows still hold on the new code: with that body they drop to 0.8539 and 0.7407. #399 builds its wrappers from this list, so it only needed the new head (61ef05f). The description has the updated numbers. |
The entry for UpdateMerchant listed GameStateStructures::activateTraderState. That edge was measured on a 93.8% draft of UpdateMerchant. The function has since landed on main at 100% (sourcehold#409), and it reaches that under /GL without the body: activateTraderState.cpp is not on the /GL list. With the body in its unit the caller keeps the unit slot in esi across the call, where the original reads it again, so the original's caller did not know it. Measured on main 3458fea with sourcehold#399's wrapper build (-DOPENSHC_FUNCTION_VISIBILITY_UNITS=ON), reccmp, raw: UpdateMerchant reads 100.0 under /GL, 90.0 with the wrappers before this change and 100.0 after it. It was the only one of the 150 functions in that build (main's /GL list plus every file the manifest names) whose raw number differed between /GL and the wrappers, and none differs now. The manifest now has 85 entries and 124 edges. On main's sources the generator makes 24 units holding 92 source files (93 before). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
UpdateTrebuchet (0x00569410) calls GameSynchronyState::isAIPlayer twice, at 0x0056A05B and 0x0056A124. Behind each call the original pushes ebx, the unit slot it read from 0xEE0FC8, without reading the slot again (0x0056A068, 0x0056A12D); behind the next call, to 0x00465F20, it reads it again (0x0056A06F, 0x0056A134). So the original's caller knew that isAIPlayer writes no memory, which it can know only from the body. Measured with tu_merge.py on main 3458fea (in a clone with two UI commits on top, nothing under Map or Synchrony) plus worker C's UpdateTrebuchet.cpp (6757ed1, at 100% under /GL), every struct and function resolver on, quick_diff ratio of the caller: caller alone 0.5440 isAIPlayer, hasUnitReachedDestination, deselectUnit 0.9818 hasUnitReachedDestination, deselectUnit 0.9132 isAIPlayer alone 0.5587 (callees first and caller first read the same in each row). Leaving isAIPlayer out lowers the score, so it is needed together with the other two. isAIPlayer (0x004010B0) is at a lower address than its caller, and it goes first in the entry, whose callees are sorted by address. The manifest now has 85 entries and 125 edges. On main's sources the generator from sourcehold#399 makes the same 24 units holding 92 source files, file for file, since UpdateTrebuchet is not on main. With that UpdateTrebuchet.cpp in the build, isAIPlayer.cpp joins its unit (24 units holding 95 source files, 94 without the line); no other file in that unit calls isAIPlayer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Hi @kotijekriv , I merged your other branch. Is this one still relevant? |
The manifest itself is on main since sourcehold#399 (02fab42); this branch keeps one more edge, UpdateTrebuchet -> GameSynchronyState::isAIPlayer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks for merging #399. This one is down to a single line now: I merged main into it, so against main it only adds the edge UpdateTrebuchet → If you'd rather not keep a PR open for one line, I can move it into #453 and close this one. Either way works for us. |
* reimplement: SHC_3BB0A8C1_0x0056A3F0 100.0% Reimplemented Units::UpdateMangonel, from gynt's draft bc487ad (42.92%). reccmp reads 100.0, raw and normalized, in a build of main 3458fea with this commit: the files of main's /GL list, the files sourcehold#398's visibility manifest names, and the unit (141 files, 151 functions, both resolver sets on). Against main alone with the same list, the other 150 functions read as before. cmake/compiler-flags-gl.txt gets two lines, the unit and UnitsState/deselectUnit.cpp (0x00535190, 100% on main). The unit has to see that body: behind its call at 0x0056AA21 the original still uses edx from before the call (0x0056AA26) and calls clearOrDeselectUnitFromSelection (0x0056AA31) without loading ecx again. No other file on the /GL list calls deselectUnit. Three things in the text are read off the original's listing: - The block that sends the two engineers to work is one loop over manningEngineerRef. The original computes the unit's offset anew at the block's start (0x0056A7D7) instead of using esi, and its second copy has the stores in source order while the first has the constants' loads in between: a loop the compiler unrolled. - In the two loops over a destroyed or disbanded mangonel's crew the engineer's id is a local. With the nested index written twice the compiler makes the two walking pointers in the other order. - The two distance blocks write the positions out and set dx and dy in both arms of an if / else. With one arm's value as the initialiser the match is lost. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * UpdateMangonel: review fixes, the code is unchanged - The (short) casts on the two stores into short fields are gone. - const on the locals that are assigned once. - The search for engineers names its counter unitID and leaves a pass early with continue. - UT_NONE for the unit type passed to clearOrDeselectUnitFromSelection, no return at the function's end, and the comment on dx and dy is reworded. - engineersInPlace stays at the function's start and gets a comment. Declared in the block that uses it, the unit reads 0.9100 in the quick measure; the original clears it at 0x0056A442, in front of the state tests. The function's /FA listing is the same as at 96ab2e4, label numbers aside. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> --------- Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
Units::UpdateBallista, from Gynt's draft on sourcehold's reimpl/map-units-updatefunctions (e44a5a0 at 32.08%), through versions on our dev branch from 85.9% to 94.5%. The forms that matter: - the siege engine shapes: the crew search's tick test is ((fixedRng ^ ticks ^ 8) & 15) != 0, the target building's half size a signed division of an int ((int)widthOrHeight / 2: cdq; sub; sar), the projectile's height offset a local that starts at 26 and becomes 0 for a negative shootTargetedUnit, and the failed target search of the resting state written behind its success path; - when both of the AI's engineers are back, the two are set out in a loop of two passes over manningEngineerRef, which the compiler unrolls. The original reads the slot again in front of it and computes the unit's offset anew (`mov ecx, [slot]; imul ecx, ecx, 1168` at 0x0056F045), and keeps 0x6d and 5 in ebp and ebx for the second pass; written as two blocks the function is 16 bytes short. The six stores are in the order of the second pass; - in the search for a new crew the distance to an engineer is taken with the engineer's coordinate first (`cmp di, ax; jle` at 0x0056F1A2), and in the two loops that remove the crew the engineer's slot is read once into a local. Main's style-lint flags every ternary on one line, so the six of the two crew loops are if / else, and the unit is read through the slot global everywhere, with no local copy of the unit ID; the code is the same. compiler-flags-gl.txt gets UpdateBallista.cpp and UnitsState/deselectUnit.cpp, which is at 100% on main and was on no /GL list. The crew loop calls deselectUnit, and the compiler has to see its body: the original keeps edx across the call at 0x0056F291 (used at 0x0056F296) and does not reload ecx before 0x0056F2A1; quick_diff with the /GL callees in the unit reads 0.9836 with it and 0.9063 without it. hasUnitReachedDestination, the other callee it has to see, is on main's list already (0.5999 without it, 0.5601 with no callee at all); #398's manifest has both edges. reccmp in a build of main's whole /GL list (the 133 files that exist) and the two files, with every resolver of those files on: 145 functions, average 99.57. UpdateBallista 100.0% raw and normalised, no differing line; deselectUnit 100.0%. In the same narrow build of main (3458fea) without the two lines (143 functions), UpdateFireBallistaBuilding reads 99.6% (normalised 95.5), and 100.0% with them; main's own full build reads it at 100.0% already, so that is a reading of the narrow build. Each of the other 142 functions reads the same. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
* reimplement: SHC_3BB0A8C1_0x00569410 100.0% Reimplemented Units::UpdateTrebuchet, from gynt's draft 7a7639c (42.59%). reccmp reads 100.0, raw and normalized, in a narrower build of main 3458fea with this commit: the files of main's /GL list, the callees #398's visibility manifest names, isAIPlayer.cpp and the unit (142 files, 152 functions, both resolver sets on). Against main alone with main's list, the other 150 functions read as before. cmake/compiler-flags-gl.txt gets three lines: the unit, UnitsState/deselectUnit.cpp (0x00535190) and GameSynchronyState/isAIPlayer.cpp (0x004010B0), both at 100% on main. The unit has to see both bodies: behind its calls to them (0x00569A25, 0x0056A05B, 0x0056A124) the original passes the slot from ebx to the next call without reading it again. No other file on the /GL list calls either. What the code takes from the original's listing: - createTribe gets the owner of units[i], with i the counter the search for engineers left behind (0x00569A71). - The block that sends the three engineers to work is one loop: the original computes the unit's offset anew at its start (0x005697BA), the start of a loop the compiler unrolled. - The distance test to the target has its differences written out; as dx and dy locals they take the registers the original gives the targets. - One dx / dy pair serves both engineer loops. With a pair per loop the search for engineers loses its match once the target block has no pair of its own. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * UpdateTrebuchet: review fixes, the code is unchanged - field_0x3c5 is compared with UIT_ATTACK_LAND and UIT_THROW_COW and set to UIT_NO_INSTRUCTION_OR_MOVEUnk. - harassBuildingsWithSiegeAI's result is tested by truthiness. - The comment on createTribe's argument is a fixme: the original passes units[i].owner with i = maxUnitCount. - `--` for the four `-= 1`, and `++` for eight of the eleven `+= 1`. The three counters of state 6 keep `+= 1`, with a comment: with them as `++` too, the search for engineers gets other registers. - const on ownX and ownY. - The search's counter is `searched`, initialised where it is declared (it no longer shares its name with the crew loop's i), and present is engineersInPlace, as in UpdateMangonel. The function's /FA listing is the same as at 6757ed1, apart from the two renamed locals' names. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * UpdateTrebuchet: fixme on addUnitToTribe's arguments, the code is unchanged Two comments, no code line changes; quick_diff gives the same listing line for line. - addUnitToTribe takes (unitID, tribeID): its body multiplies the first by the unit size and the second by the tribe size, and every caller on main passes them so. The original passes the new tribe first and the trebuchet's slot second (push ecx with the slot, then push eax with createTribe's result, 0x00569A91 / 0x00569A92). That is most likely a bug in the original, next to the createTribe one; it is kept for the match and now marked fixme. - The capture search's comment said its two exit tests are in the original's order; our source tests the bound first and the compiler turns it into the original's loop, so the comment says that now. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
…#455) MenuViews::CrusadeMissionIntro::MenuView_CrusadeMissionIntro_DoEveryFrame, the crusader trail's mission intro screen: the map preview with the keeps, the lords' gold, the mission's number and name, and the opponents sorted by team. Written from the original's listing. gynt's best is b4fa695 on his fork's archive/UI-MenuViews-merged-full (53.54%, "Style pass"; its status line reads 53.5%); his closed sourcehold#253 has 35.8%, and his later 1958ae8 ("Early returns", 42.04%, on reimpl/UI-MenuViews-development, now 45.0% at 466d2ea) has the three returns already. His 08c492b on reimpl/UI-MenuItems-development (38.6%) writes the id test as `<= 0`, where the original compares with 1 (0x004DE193), so it stays `id < 1` here. One behaviour fix against b4fa695: when the current trail is complete (extreme 20, war chest 30, first edition 50 missions) the original draws "Crusader Trail Completed!" and returns (three copies, 0x004DD7F7 to 0x004DD8E2); b4fa695 draws the text and then the whole screen as well. Everything else it does the way the original does. What the match needed: - The title written out per trail and per font: the number, "." and name six times over, as the original has them (its six arms end in two shared tails, one per font). With one copy and the font in a local, the function came out at 588 instructions to the original's 822. - The position (y, then x) of the completed-trail message, of the lords' texts and of the mission's name in locals right before each call, and the name's index for the width test and for the name itself. Written inline, the compiler merges the three message copies the original keeps, hands the scratch registers out in another order from the lords' texts on, and the six title arms do not share their tails. - The opponents' list in the original's two paths: the team stored in each arm of the game-suspended test, and the no-lord arm counting and continuing on its own. With one count after the test the entries are walked through one pointer where the original walks one per field. - The time tests compare the map time first, as the original does. - avatarX copied from listX after rowY: copied straight after listX, the border height is read only once (the original reads it twice). - The rows' previous team in its own variable, set with the draw buffer before the two positions: with the sort's variable reused, listX, avatarY and the previous team take other stack slots. 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 Opus 5.5 <noreply@anthropic.com>
* reimplement: SHC_3BB0A8C1_0x004B5330 100.0% Reimplemented 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> * headers: ColorChannelMask, the channel bits of an RGB555 and an RGB565 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> * renderMinimapTileStripWithLuminescence: name the numbers by main's constants 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> * renderMinimapTileStripWithLuminescence: the small map's margin and the 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> --------- Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
…itor_TextInputRelatedUnk This PR puts MenuItemActionHandler_TextEditor_TextInputRelatedUnk and Text/TextEditorState/helpToken.cpp on cmake/compiler-flags-gl.txt. The handler calls helpToken_getHelpTokenAdvanceLength, below it, and gets an entry at its address with that callee. The /GL lines stay as they are. Measured as sourcehold#398's edges were: the handler's file compiled with helpToken.cpp in its unit, against the handler alone, quick_diff on this head merged with main 7c2e4d6, every function resolver that has a .cpp and every struct resolver on: 0.8291 alone, 0.9350 with helpToken.cpp. helpToken.cpp's two functions call no /GL-listed function, so they get no entry of their own. With every .cpp of that merge as the build list, cmake/function-visibility-units.py makes 25 units holding 110 source files (24 and 108 before): the handler and helpToken.cpp form a unit of their own. No internal names clash, and the 13 names it skips are the ones main's manifest skips. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This PR puts CommandSwitchTeams, countPlayersInSameTeam and addChatMessageToDisplayList on cmake/compiler-flags-gl.txt. CommandSwitchTeams has to see countPlayersInSameTeam's body and gets an entry at its address with that callee. The /GL lines stay as they are. Measured as sourcehold#398's edges were: the caller's file compiled with the callee files in its unit, against the caller alone, quick_diff on this head merged with main 7c2e4d6, every function resolver that has a .cpp and every struct resolver on. - CommandSwitchTeams: 0.6638 alone, 1.0000 with countPlayersInSameTeam, and 1.0000 with both of its /GL callees. addChatMessageToDisplayList changes nothing (0.6638 with it alone, 1.0000 without it). - addChatMessageToDisplayList reads 1.0000 alone; its one /GL-listed callee, LowLevelMemory::copyData, changes nothing. receiveAllTransmittedCommands on main, which calls it, reads 0.9600 with and without its body. countPlayersInSameTeam calls no /GL-listed function. With every .cpp of that merge as the build list, cmake/function-visibility-units.py makes 25 units holding 110 source files (24 and 108 before): CommandSwitchTeams and countPlayersInSameTeam form a unit of their own. No internal names clash, and the 13 names it skips are the ones main's manifest skips. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…onFetcher This PR puts UpdateOx, UpdateMinerIronFetcher, UpdateWorker_ConsiderTakingABreakUnk, ConsiderHavingABreakNowUnk and UnitsState::isWorkplaceBuildingOnAdjacentTile on cmake/compiler-flags-gl.txt. UpdateOx and UpdateMinerIronFetcher get entries at their addresses, their callees in address order. The /GL lines stay as they are. Measured as sourcehold#398's edges were: the caller's file compiled with the callee files in its unit, against the caller alone, quick_diff on this head merged with main 7c2e4d6, every function resolver that has a .cpp and every struct resolver on. The callees tried are the caller's /GL-listed callees below its address. A callee is listed when it raises the caller's ratio on its own, or when leaving it out of the full set lowers it; the listed set reads what the full set reads. - UpdateOx: 0.9016 alone, 0.9955 with checkIfCitizenUnitIsAliveBasedOnState and hasUnitReachedDestination, the same as with all five of its /GL callees. The two are needed together: on its own checkIfCitizenUnitIsAliveBasedOnState reads 0.7582 and hasUnitReachedDestination 0.9169, and leaving one of the five out reads 0.9169 and 0.7582. buildingIsAccessible, addResourceToStockpile and makeUnitStopWalkingByClearingPathProgressState change nothing. - UpdateMinerIronFetcher: 0.4456 alone, 0.9249 with its four callees, the same as with all ten of its /GL callees; leaving one of the ten out reads 0.8410 (IncrementAndOptionalUpdateAVValueRelated), 0.7674 (checkIfCitizenUnitIsAliveBasedOnState), 0.8974 (hasUnitReachedDestination), 0.7253 (isWorkplaceBuildingOnAdjacentTile). UpdateWorker_ConsiderTakingABreakUnk, buildingIsAccessible, ComputeGoodsProduced, addResourceToStockpile, SetStateToFreetimeWalking and makeUnitStopWalkingByClearingPathProgressState change nothing. - UpdateWorker_ConsiderTakingABreakUnk reads 1.0000 alone; its one /GL-listed callee, ConsiderHavingABreakNowUnk, changes nothing. UpdateHopsFarmer on main, which calls it, reads 0.9514 with its entry's callees with and without it. ConsiderHavingABreakNowUnk and isWorkplaceBuildingOnAdjacentTile call no /GL-listed function. With every .cpp of that merge as the build list, cmake/function-visibility-units.py makes 24 units holding 111 source files (108 before): UpdateOx, UpdateMinerIronFetcher and isWorkplaceBuildingOnAdjacentTile join the existing groups. No internal names clash, and the 13 names it skips are the ones main's manifest skips. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This PR puts UpdateLion on cmake/compiler-flags-gl.txt. It gets an entry at its address with the two callees whose bodies it has to see, in address order. The /GL line stays as it is. Measured as sourcehold#398's edges were: UpdateLion's file compiled with the callee files in its unit, against it alone, quick_diff on this head merged with main 7c2e4d6, every function resolver that has a .cpp and every struct resolver on, trying its /GL-listed callees below its address: 0.8396 alone, 0.9939 with checkIfCitizenUnitIsAliveBasedOnState and hasUnitReachedDestination, the same as with all five of its /GL callees. Leaving one of the five out reads 0.8409 (checkIfCitizenUnitIsAliveBasedOnState) and 0.9591 (hasUnitReachedDestination). tryAttackUnitID (on main's list since sourcehold#438), makeUnitStopWalkingByClearingPathProgressState and resumeMovementIfNoAttackTarget change nothing. With every .cpp of that merge as the build list, cmake/function-visibility-units.py makes 24 units holding 109 source files (108 before): UpdateLion joins the existing Units group. No internal names clash, and the 13 names it skips are the ones main's manifest skips. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…old#416, sourcehold#433 and sourcehold#438 (sourcehold#491) sourcehold#416, sourcehold#433 and sourcehold#438 put six callers on cmake/compiler-flags-gl.txt after sourcehold#398 without an entry here: InGameMenu's MenuItemRenderFunction_InGameMenu_MainButtons and Roundtable's MenuItemActionHandler_Roundtable_Main (sourcehold#416), UpdateGhost (sourcehold#416), UpdateFireWatch and UpdateHunterDog (sourcehold#433), and UpdateCageDog (sourcehold#438). Each gets an entry at its address, its callees in address order. The /GL lines stay as they are. Each edge is measured as sourcehold#398's were: the caller's file compiled with the callee files in its unit, against the caller alone, quick_diff on main 7c2e4d6 with every function resolver that has a .cpp and every struct resolver on. The callees tried are the caller's /GL-listed callees below its address. A callee is listed when it raises the caller's ratio on its own, or when leaving it out of the full set lowers it; the listed set reads what the full set reads. - MainButtons: 0.8217 alone, 1.0000 with ButtonGmData::getPictureNumberInGm. - Roundtable_Main: 0.9391 alone, 0.9984 with GameSynchronyState::isAIPlayer. - UpdateFireWatch: 0.3834 alone, 0.9980 with checkIfCitizenUnitIsAliveBasedOnState and hasUnitReachedDestination, the same as with all four of its /GL callees; leaving one of the four out reads 0.7178 (checkIfCitizenUnitIsAliveBasedOnState) and 0.6606 (hasUnitReachedDestination). makeUnitStopWalkingByClearingPathProgressState and commitUnitLocation change nothing. - UpdateGhost: 0.5214 alone, 0.9712 with hasUnitReachedDestination. makeUnitStopWalkingByClearingPathProgressState changes nothing. - UpdateHunterDog: 0.3336 alone, 1.0000 with its four callees and with all five of its /GL callees; leaving one of the five out reads 0.9944 (makeUnitStopWalkingByClearingPathProgressState), 0.7283 (checkIfCitizenUnitIsAliveBasedOnState), 0.9298 (hasUnitReachedDestination), 0.9114 (hasTunnelerNotFinishedDigging). resumeMovementIfNoAttackTarget changes nothing. - UpdateCageDog: 0.2829 alone, 1.0000 with its four callees and with all seven of its /GL callees; leaving one of the seven out reads 0.8651 (makeUnitStopWalkingByClearingPathProgressState), 0.7162 (checkIfCitizenUnitIsAliveBasedOnState), 0.4142 (hasUnitReachedDestination), 0.9949 (tryAttackUnitID, which sourcehold#438 added to the /GL list for it). buildingIsAccessible, resumeMovementIfNoAttackTarget and commitUnitLocation change nothing. sourcehold#473 and sourcehold#475 put UpdateSiegeTent and UpdateHorseArcher_DoShooting on the /GL list; neither calls a /GL-listed function, so neither gets an entry. UpdateHorseArcher calls UpdateHorseArcher_DoShooting, which sits below it, but reads worse with its body (0.9929 with hasUnitReachedDestination, 0.9906 with both), so its entry stays as it is. With every .cpp of main as the build list, cmake/function-visibility-units.py now makes 24 units holding 116 source files (108 before): the six callers, tryAttackUnitID and makeUnitStopWalkingByClearingPathProgressState join the existing groups. No internal names clash, and the 13 names it skips are the ones it skipped before. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
* headers: UnitState gets US_UNKNOWN_206, US_UNKNOWN_207 and US_UNKNOWN_208 Units::UpdateLion (0x0056B0E0) tests its state against these numbers: cmp dx, 208 at 0x0056B24A, 207 at 0x0056B28A and 206 at 0x0056B68F. The values already in the enum do not change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * reimplement: SHC_3BB0A8C1_0x0056B0E0 100.0% Reimplemented Units::UpdateLion, from Gynt's draft on sourcehold's reimpl/map-units-updatefunctions (974c32f, after e3fc5d9 at 59.36%), through an earlier version on our dev branch at 87.9%. Kept forms, each with quick_diff of the form without it (the /GL callees in the unit; the final form reads 0.9939, all of it quick_diff's view of the two timeGetTime calls): - the first state reads the slot into a local behind setUnitFacingDirectionTowardsTarget and again behind each findClosestAnimalStoreResult (without those three reads 0.9479, through the global throughout 0.9817); - state 205 sets a frame local in each arm, stores it once and tests the local (through the field 0.9837); - the chase state keeps the target in a short with an int copy for the index (one int 0.9888) and stores destinationNeeded through the slot ahead of that read (through unitID 0.9919). compiler-flags-gl.txt gets UpdateLion.cpp. The callees it needs visible are on the list already: checkIfCitizenUnitIsAliveBasedOnState (quick_diff without it 0.8409) and hasUnitReachedDestination (0.9591). With no callee bodies at all, i.e. off the list, 0.8396. reccmp in a build of main's whole /GL list with every resolver of those files on: UpdateLion 100.0%. Every other function in that build reads the same as in the same build of main (3458fea). Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * style: UpdateLion tests tryAttackUnitID's BOOLEnum result by truthiness tryAttackUnitID returns BOOLEnum, and the lion's test was `== 0`; TheRedDaemon's review on #300 asks for a BOOLEnum result to be tested by truthiness, so it is `!tryAttackUnitID(...)` now. No other change. Measured: with the precompiled header, quick_diff gives the same listing for the pushed head's text and this one. A narrow real build (main's /GL list and this round's files of several 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> * cmake: function-visibility.txt entry for UpdateLion This PR puts UpdateLion on cmake/compiler-flags-gl.txt. It gets an entry at its address with the two callees whose bodies it has to see, in address order. The /GL line stays as it is. Measured as #398's edges were: UpdateLion's file compiled with the callee files in its unit, against it alone, quick_diff on this head merged with main 7c2e4d6, every function resolver that has a .cpp and every struct resolver on, trying its /GL-listed callees below its address: 0.8396 alone, 0.9939 with checkIfCitizenUnitIsAliveBasedOnState and hasUnitReachedDestination, the same as with all five of its /GL callees. Leaving one of the five out reads 0.8409 (checkIfCitizenUnitIsAliveBasedOnState) and 0.9591 (hasUnitReachedDestination). tryAttackUnitID (on main's list since #438), makeUnitStopWalkingByClearingPathProgressState and resumeMovementIfNoAttackTarget change nothing. With every .cpp of that merge as the build list, cmake/function-visibility-units.py makes 24 units holding 109 source files (108 before): UpdateLion joins the existing Units group. No internal names clash, and the 13 names it skips are the ones main's manifest skips. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Gynt <gynt@users.noreply.github.com>
* reimplement: SHC_3BB0A8C1_0x004B58D0 100.0% Reimplemented 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: renderMinimapTileColors names its map, buffer and screen tile 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> * headers: MinimapConstants, with a row of the minimap buffer in bytes A new generated-form enum, UI::Enums::MinimapConstants, with one value: MMC_BUFFER_ROW_BYTES = 400, a row of MinimapViewState's pixel buffer (200 pixels of 2 bytes; the buffer is ushort[80000], 400 such rows). renderMinimapTileColors' handwritten pixel stores multiply the row by it (`mov edx, 400; mul edx`, 0x004B5E68 and 0x004B5F01). Asked for on the review, in place of the file-local constant. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * renderMinimapTileColors uses ColorChannelMask's and MinimapConstants' names The file-local colour mask enum goes: main has Rendering::ColorChannelMask now, and the five masks are its CCM_RGB555_RED, CCM_RGB555_GREEN, CCM_RGB565_RED, CCM_RGB565_GREEN and CCM_RGB_BLUE, named with using-declarations as renderMinimapTileStripWithLuminescence does. The file-local BUFFER_ROW_BYTES goes too: the assembly's two row multiplies use MinimapConstants' MMC_BUFFER_ROW_BYTES, through a using-declaration, since inline assembly cannot name a qualified constant but does take the unqualified name. The function compiles to the same code: its listing is the same instruction for instruction once MSVC's numbering of locals and temporaries is normalised, and a narrow real build reads 100.0% raw and normalised. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
…akNowUnk and UpdateMinerIronFetcher (sourcehold#421) * reimplement: SHC_3BB0A8C1_0x00530C40 100.0% Reimplemented Units::ConsiderHavingABreakNowUnk, from Gynt's draft on sourcehold's reimpl/map-units-updatefunctions (84dce4b at 97.56%, "load scheduling"). The draft was one instruction out of order: the original loads the unit's owner before the branch on destinationNeeded (the load at 0x00530C52 sits between the cmp at 0x00530C4A and the je at 0x00530C59), although only the path behind that branch uses it, and in the draft the compiler folded the read into its use behind the branch. What the match needed: the owner is read into an int local above the test, and the player's productivity is read twice through it, in the `< 100` test and in the target formula, with no local for the productivity. A value with two uses keeps its load where it is declared; one with a single use is loaded at that use. Measured with quick_diff: the draft 0.9756; the owner as a short 0.9639; the local declared behind the test 0.8293; a PlayerData pointer 0.7952; this form 1.0000, 41 instructions on both sides and every jump on the same instruction. Also US_UNKNOWN_121 for the state the draft wrote as (UnitState)121, and main's name field_0x2fe. reccmp, with both resolver sets on: 100.0 (normalized 100.0), and the caller UpdateWorker_ConsiderTakingABreakUnk stays at 100.0. That is from one run of 151 functions: the 133 files of main's /GL list that exist on main, this function, its caller and UpdateOx, and two files outside that set, a local draft of takeScreenshot.cpp (which main's list names but main does not have) and ResourceManager/paths.cpp (which it needs to link). The run was made before `const` was added to the owner local; the function's instruction stream is the same line for line with and without it. The function is not on the /GL list and needs no line there. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * reimplement: SHC_3BB0A8C1_0x0053F940 100.0% Reimplemented Units::UpdateOx, from Gynt's draft on sourcehold's reimpl/map-units-updatefunctions (dab4c1d at 67.64%, "int index local"; c703e13 at 62.84% before it). How it got to 100: - compiler-flags-gl.txt gets UpdateOx.cpp. The five callees whose bodies it has to see are on main's list already: addResourceToStockpile, buildingIsAccessible, checkIfCitizenUnitIsAliveBasedOnState, hasUnitReachedDestination and makeUnitStopWalkingByClearingPathProgressState. - Most accesses to the unit go through DAT_CurrentUnitSlotID::instance, the rest through the copy of the slot taken at the top. The original loads the global again behind a call that may change it and keeps using the copy it holds elsewhere. Which statement reads which was settled by measuring, not by copying the original: in three places (0x0053FC32, 0x0053FED8, 0x0053FF2E) the original keeps using the copy it already holds in esi behind the call, where the source reads the global, and the compiler arrives at the same instructions. With that, the wait state's success as the then-arm, the reset state's two stores written on both paths and the delivery tests nested so each failure keeps its own reset, the draft went to 97.8. - The eating-grass state, 97.8 to 100: the code that resets the state is written once, behind a flag. The flag starts TRUE; the arm for a frame above 0 clears it when the unit has not become idle; `if (reset)` holds the reset, and the rest of the state follows it. The compiler removes the flag by threading the jumps, and that leaves the original's layout: the arm for a frame of 0 or below jumps forward (0x0053FB3F) to the reset code at 0x0053FB5D, which sits behind the other arm's idle test. With the reset after the if/else, or written out in both arms, the compiler keeps the copy behind the first arm and the second arm jumps back to it (the 97.8). A goto into the reset code compiles to the same code as the flag. Measured with quick_diff, the five /GL callees in the unit: this form has 443 instructions on both sides and every jump on the same instruction, and the two lines it still shows are `mov word ptr [..], 0xffff` against `-0x1`, the same bytes. The reset state's two stores written once behind the if: 0.8682, 437 instructions. The delivery tests as one `&&` condition: 0.9591, 437 instructions. reccmp, with both resolver sets on: UpdateOx 100.0 (normalized 100.0), ConsiderHavingABreakNowUnk and its caller UpdateWorker_ConsiderTakingABreakUnk 100.0. That is from one run of 151 functions: the 133 files of main's /GL list that exist on main, the three files just named, and two files outside that set, a local draft of takeScreenshot.cpp (which main's list names but main does not have) and ResourceManager/paths.cpp (which it needs to link). Leaving out the five functions of those two files, 142 of 146 read 100.0. The four below are lightUpBuilding 99.3, updateBuildingPlacementRotationPreview 46.2, playUnitSelectSpeech 94.1 and InitBlendFilterArraysUnk 97.9: those are readings of this narrow file set, not of a full build (main's status file has the first, second and fourth at 100.0 and playUnitSelectSpeech at 82.4), and this branch does not touch them. The run was made before `const` was added to six locals and before the two comments on the nesting; the function's instruction stream is the same line for line before and after. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * reimplement: SHC_3BB0A8C1_0x00566010 100.0% Reimplemented Units::UpdateMinerIronFetcher, from Gynt's draft on sourcehold's reimpl/map-units-updatefunctions (his commits on the file: b3d9191 at 44.16%, a2fddde at 49.78%, and the style commit 974c32f), through the forms on our development branches, where its history is. On top of ConsiderHavingABreakNowUnk (ef8c838), which it needs. What the match needed, against the draft (reccmp on the development branch, on the /GL list): - Every access reads the unit through DAT_CurrentUnitSlotID::instance, and the draft's local copy `int unitID` is gone: the original keeps the global itself in a register and loads it again only behind a call that may change it, which a local copy never does (68.1 -> 75.6). - Four branches the way round the original has them: the call that works is the first arm behind setWorkplaceBuildingEntryAsTarget in state 1 and behind canBuildingStoreTheAmount and buildingIsAccessible in the unloading state, and the odd slots come first where the waiting animation picks its frame table. (The search that found them had also put the running frame first in US_DEATH_01, which read 87.0; that one was wrong and is not in this commit: the draft's order there, the last frame first, is the original's, jg at 0x00566677.) - The compiler has to see two more callees. The original keeps the slot in ebx and its offset in esi across isWorkplaceBuildingOnAdjacentTile (0x005660E7 to 0x005660F2) and across UpdateWorker_ConsiderTakingABreakUnk (0x005661A1 to 0x005661C2), and reads the slot again behind setDestinationForUnit (0x005661D1). So its compiler knew that the first two leave DAT_CurrentUnitSlotID alone. Ours knows it only when it sees their bodies, and for the break check also the body of ConsiderHavingABreakNowUnk, the one function it calls. - The working path as the fall-through, twice: behind setDestinationForUnit in state 2 (je at 0x005661CF to the US_DISAPPEAR exit) and behind setWorkplaceBuildingEntryAsTarget in the unloading state (je at 0x005664D1, the store of state 2 behind it at 0x005664D9). Both were early exits with the rest behind them. - The states are one if / else-if / else chain whose arms fall out of it, where the draft had a block per state that returns. The else parts of US_DEATH_01 and of the alive-check arm end in the same instructions; falling out of a chain, the compiler keeps the later copy, as the original does (US_DEATH_01 jumps forward from 0x005666A1 to 0x00566708). With blocks that return it kept the earlier one (-> 100.0). The text follows main's unit functions: BOOLEnum results by truthiness where the call is the whole condition (SetStateToFreetimeWalking's is compared with 0 inside an && condition and stays so), the names main has for the states and for DNE_UNKNOWN_2 and RT_IRON, const on the five locals that are assigned once, the steps by one as ++ and --, the draft's ternary as an if / else (style guide 23; the compiler still emits the sete), and a one-line why at the chain. compiler-flags-gl.txt gets UpdateMinerIronFetcher.cpp and six of the callees it has to see: ComputeGoodsProduced, IncrementAndOptionalUpdateAVValueRelated, SetStateToFreetimeWalking, UpdateWorker_ConsiderTakingABreakUnk, isWorkplaceBuildingOnAdjacentTile and ConsiderHavingABreakNowUnk. hasUnitReachedDestination and checkIfCitizenUnitIsAliveBasedOnState, the other two, are on the list already. quick_diff with those eight in the unit reads 1.0000, 463 instructions against 463; leaving any one of them out lowers it (0.8319 to 0.9903), and with none 0.4461. Measured with reccmp, both resolver sets on: - a /GL build of this file with its callee closure: UpdateMinerIronFetcher 100.0% raw and normalised, no diff entry; the six callees read 100.0% on the list as off it; - a build of every file of main's /GL list that exists on main (3458fea), parseHlp.cpp, UpdateOx.cpp and this commit's seven files: 152 functions, UpdateMinerIronFetcher 100.0% with no diff entry; the same build without this file and with the six callees off the /GL list, as on 7af01b5: 151 functions, and each of them reads the same in both. Not run in game. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * cmake: function-visibility.txt entries for UpdateOx and UpdateMinerIronFetcher This PR puts UpdateOx, UpdateMinerIronFetcher, UpdateWorker_ConsiderTakingABreakUnk, ConsiderHavingABreakNowUnk and UnitsState::isWorkplaceBuildingOnAdjacentTile on cmake/compiler-flags-gl.txt. UpdateOx and UpdateMinerIronFetcher get entries at their addresses, their callees in address order. The /GL lines stay as they are. Measured as sourcehold#398's edges were: the caller's file compiled with the callee files in its unit, against the caller alone, quick_diff on this head merged with main 7c2e4d6, every function resolver that has a .cpp and every struct resolver on. The callees tried are the caller's /GL-listed callees below its address. A callee is listed when it raises the caller's ratio on its own, or when leaving it out of the full set lowers it; the listed set reads what the full set reads. - UpdateOx: 0.9016 alone, 0.9955 with checkIfCitizenUnitIsAliveBasedOnState and hasUnitReachedDestination, the same as with all five of its /GL callees. The two are needed together: on its own checkIfCitizenUnitIsAliveBasedOnState reads 0.7582 and hasUnitReachedDestination 0.9169, and leaving one of the five out reads 0.9169 and 0.7582. buildingIsAccessible, addResourceToStockpile and makeUnitStopWalkingByClearingPathProgressState change nothing. - UpdateMinerIronFetcher: 0.4456 alone, 0.9249 with its four callees, the same as with all ten of its /GL callees; leaving one of the ten out reads 0.8410 (IncrementAndOptionalUpdateAVValueRelated), 0.7674 (checkIfCitizenUnitIsAliveBasedOnState), 0.8974 (hasUnitReachedDestination), 0.7253 (isWorkplaceBuildingOnAdjacentTile). UpdateWorker_ConsiderTakingABreakUnk, buildingIsAccessible, ComputeGoodsProduced, addResourceToStockpile, SetStateToFreetimeWalking and makeUnitStopWalkingByClearingPathProgressState change nothing. - UpdateWorker_ConsiderTakingABreakUnk reads 1.0000 alone; its one /GL-listed callee, ConsiderHavingABreakNowUnk, changes nothing. UpdateHopsFarmer on main, which calls it, reads 0.9514 with its entry's callees with and without it. ConsiderHavingABreakNowUnk and isWorkplaceBuildingOnAdjacentTile call no /GL-listed function. With every .cpp of that merge as the build list, cmake/function-visibility-units.py makes 24 units holding 111 source files (108 before): UpdateOx, UpdateMinerIronFetcher and isWorkplaceBuildingOnAdjacentTile join the existing groups. No internal names clash, and the 13 names it skips are the ones main's manifest skips. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
* reimplement: SHC_3BB0A8C1_0x0042C620 100.0% Reimplemented Actions::LaunchSinglePlayerGameUnk starts a single-player game on a map: it loads the map picked in the map choice (or, called with 1, the map whose name standaloneFilename already holds), sets what can be made and recruited, applies the mission type's rules and opens the first menu view. For a siege that is the map's siege engines as an attack wave scaled by the difficulty, the attacker's troops (the ones picked in the map choice in the advanced mode, otherwise 70% of the map's for a player in slot 2) and no peasants; for an invasion on difficulty 1 to 3 (from the map choice always 1: its start button sets it), on a map for which mapHasCertainEvent says no, it takes every fourth, third or second of the player's own units away until a quarter, a third or half of their troop value is gone. 663 instructions, written from the original's listing. The fields it uses come from gynt's draft, under main's names today. The draft goes back to ce7ebb0 (2026-10-02, "reimplement: SHC_3BB0A8C1_0x0042C620 25.26% Style pass, asm differs"). Its best score, 28.35%, is ca39d7b (2026-10-03, the same subject), where he merged the draft's split name buffer (`char local_7e0[4]` and a `local_7dc[1004]` that nothing used) into one of 1008 bytes; his 409e2a3 ("Split buffer merged", on sourcehold's own reimpl/UI-Core) makes the same change and says why. The newest version is 15e5712 (2026-11-02, "style: rule 12, import 76 string literals across UI/Rendering and Helpers") on his fork's reimpl/UI-MenuItems-development, whose status line reads "28.4% | Style pass, asm differs". reimpl/UI-Core-development has it at 27.1% (10280b1) and reimpl/UI-Core (sourcehold#256) at 26.3% (2f1c52c); both still have the 4-byte name buffer. That draft does not compile on today's main: DAT_SiegeInformationArray is `int[7][3]` now, and two SiegeUnitCounts fields, Building's tower engine field and PlayerData's keep entry have other names. No behaviour change against the draft: read block by block, both do the same. One thing a literal port would get wrong: the draft reads the picked map from DAT_ArrayOfMapIndices[scroll offset + selection - 1], which was right for the header of its day (the array started one entry later); on main the array starts where the original reads it, so the index has no `- 1`. gynt's own newer export (8ca7861 on reimpl/Wilps-2026-10-18) has it without the `- 1` too. What the match needed, each measured against its alternative: - The two name buffers are char[1005] and char[1001] (the frame's size, as gynt found in 409e2a3). - The first six "can be made" stores in the order crossbow, pike, sword, bow, spear, mace; in ascending order two of the stores move. - The picked map's index as selection + scroll offset; the other way round swaps the two loads. - The nine recruitable flags cleared in front of the loop that copies the fourteen recruitable values. Behind it the loop takes the register that holds the function's zero, and the zero is no longer in a register from the first test of the argument on. - The siege numbers are zeroed by their own `if (type != siege)` in front of the siege's peasant loop. As the else arm of that loop's test, the three blocks before it stay in the written order; the original has them behind the keep's part of the function. - The twenty siege troop counts are walked as an array in all three places (copy, 70%, zero). The header has twenty named fields; twenty written zero stores take the function's zero register where the original makes a new one. - In the invasion block the unit counter is declared in front of the value total; the other way round the two are set to zero in the other order. - The last menu call written in each arm; one call with a `? :` argument computes the number without a jump. - The argument is compared with 1 at the end, as in the original; a truth test compares with zero. The mission types (0 just build, 1 economic, 2 siege, 3 invasion) are plain numbers with a comment, as in main's other files: DAT_MapMissionType has no enum, and a file-local one changes two registers of the second map name call (declared alone, without a single use). 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> * LaunchSinglePlayerGameUnk: TRUE and FALSE for the flags it sets Review: the six "can be made" settings (MapPropertiesState's SEC_*Producible_save shorts and GameCore's *Producible_logic ints) and the nine euroRecruitableCopy_* flags are only ever 0 or 1 in the original: every store is a 1 or a 0, a toggle with `xor 1` (the map editor) or a copy between the two sets of fields, and every read tests against 0. They now take TRUE and FALSE. Main has no 16-bit BOOLEnum, so the short fields keep their type; no header changes. One comment says what the nine flags are. 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> * LaunchSinglePlayerGameUnk: index euroRecruitable by unit type Review: euroRecruitable is indexed by the unit type counted from UT_E_ARCHER (main's IsEuroUnitRecruitableUnk reads it as euroRecruitable[unitType - UT_E_ARCHER]), so the seven tests behind the copy loop are written euroRecruitable[UT_E_XBOW - UT_E_ARCHER] and so on. 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> --------- Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
Update (2026-11-21), after #399: #399 brought this manifest onto main (02fab42) as it stood at 20176fe, so everything described below is on main already. main is now merged into this branch (3e959f2), and against main this PR adds only one edge: UpdateTrebuchet →
GameSynchronyState::isAIPlayer(its update note is below; UpdateTrebuchet is in #453).Adds
cmake/function-visibility.txt, the list gynt asked for on Discord: for each caller, the functions whose bodies it has to see when it is compiled.means UpdateCamel has to be compiled in a unit that also holds those two bodies. Whether a callee needs something itself is its own entry. Names are fully qualified the way the definitions are written. Entries are sorted by the caller's address, and each entry's callees by theirs. There are 85 entries with 125 edges, and in every one of them the callee is at a lower address than its caller. Nothing else changes: the file is not read by the build yet.
Update after #290: #290 rewrote UpdateBadBuildingGibbet and UpdateBadBuildingStretchingRack so that they reach 100% without
/GL. On mainea63a49d9both measure 1.0000 with and without updateBuildingSignpostCounter's body, so their two edges are gone (87 entries and 127 edges before). Their "must not see" rows for addBuildingToTargetableBuildings still hold on the new code and are re-measured below: 1.0000 alone, 0.8539 (Gibbet) and 0.7407 (StretchingRack) with it.Update (2026-11-21), for #378: #378 puts
UnitsState/selectionContainsOnlyArabAssassins.cppon the/GLlist.BuildingsState::canUnitReachBuildingPerimeter(on main at 100%) calls that function and must not see its body: the pair is in the "Must not see" table below (0.7731 alone, 0.5738 with it). Nothing had to be added to the list for it. Its entry is already here, withgetBuildingHeightForBuildingID, the one callee it must see. With #399's option on, that puts it into a wrapper of three files built without/GL. Real builds, reccmp, raw:canUnitReachBuildingPerimeter3458fea34,/GLe81059741,/GL/GLlineTwo limits. The list isn't read by the default build, so there only the
/GLlist decides. And an entry without callee lines changes nothing, because the generator groups only files that an entry joins.Update (2026-11-21), for UpdateTrebuchet: one edge more, UpdateTrebuchet →
GameSynchronyState::isAIPlayer. Without it UpdateTrebuchet measures 0.9132 with its other two callees; with it 0.9818. The original calls it at 0x0056A05B and 0x0056A124 and does not re-read the unit slot behind either call.One edge is gone: UpdateMerchant →
activateTraderState. It was measured on a 93.8% draft, the weaker kind of evidence named under "Known gaps". UpdateMerchant has since landed on main at 100% (#409), and that version must not see the body. On main3458fea34it reads 100.0 under/GL(activateTraderState.cppisn't on the/GLlist), 90.0 in a wrapper build with the old line and 100.0 without it. It was the only one of 150 functions (the/GLlist plus every file this list names) whose raw number differed between/GLand the wrappers.How each edge was measured
Every edge comes from
tools/compiler-internals/tu_merge.py, not from reading the code. For a caller and one or more callees, it compiles the caller as committed and with the callees' bodies pasted into its file (bundled MSVC 2005,/FA, no/GL). Each result is diffed against the original withquick_diff.py --name CALLER. Every function and struct resolver was switched on./GLlist lets every listed file see every other.Trees measured:
677469cd2cmake/compiler-flags-gl.txtreimpl/units-B-development(our Map::Units branch, contains main)reimpl/units-A-development(our other Map::Units branch)The list was then checked against main
3458fea34: every name from main resolves there. 22 names are not on main yet. 21 are Map::Units Update functions (UpdateMerchant landed with #409): they were measured on our local branchesreimpl/units-B-developmentandreimpl/units-A-development(UpdateCamel is also on the localreimpl/units-B-round2-100), and gynt'sreimpl/map-units-updatefunctionshas drafts of all of them. The 22nd isUnitsState::changeDestinationByAmountfrom #378. A generator would skip them until they land. If you'd rather keep only what is on main, they are easy to take out.Highlights
/GLboth are on the list, so Dairy can't avoid it, which is why it is at 93.9 today./GLbatch already found./GLworkshop functions (UpdateArmorersWorkshop and friends) need updateVisuallyActiveState. That matches gl-conundrum.md.Measured gains left out of the file
Twelve callees raised their caller's score but cannot be same-file edges, so they are not in the file:
So the building Update functions gain from seeing playSFXAtLocation's body, although by the address layout it cannot have been in their file. I haven't found the reason yet.
Some kept edges span huge distances: UpdateInnkeeper (0x540EC0) → getBuildingResourceAmountByUid (0x409330), and UpdatePikeman/UpdateMaceman →
ViewportRenderState::xyAreValidat 0x401000. They contradict no other measurement, so they stay. Innkeeper's is confirmed by a build (below). A third, UpdateMerchant → activateTraderState, was removed (update of 2026-11-21).Known gaps
cmake/compiler-flags-gl.txton main has six lines for four files that don't exist:takeScreenshot.cpp,determineBuildingPlacementRotation.cpp, andexecuteDefaultCastleAIV.cppandfindAppropriateGridLocationForBuilding.cpp(twice each).The
staticideaDeclaring the Update functions
staticchanges nothing. A static function can't go intoMACRO_FUNCTION_RESOLVERas it stands (MSVC 2005 error C2970: an internal-linkage function as a template argument). So the test swapped the resolver's argument for0and kept the function alive with an external function pointer, the way a dispatch table would.static/GLcalleesstatic/GLlist; the file lists 6)Does a wrapper build reproduce
/GL?Yes, so far. #399 builds on this PR and adds the generator gynt suggested:
cmake/function-visibility-units.pyand an option,-DOPENSHC_FUNCTION_VISIBILITY_UNITS=ON, off by default. It groups each caller with its callees (one group per connected set, since a function is defined once), writes one wrapper.cppper group that#includes the members, and builds the wrappers instead of the members, without/GL.Built with the file as first posted (87 entries, before the updates above) on our Map::Units development branch, which contains main and its
/GLlist: 24 wrappers holding 124 files, no build failures, and it links. Against the/GLbuild of the same code, 2,247 of 2,254 functions are identical, 7 are better and none is worse. All 2,107 functions at 100% stay at 100%./GL/GLThis PR is only the list; the build doesn't read it.
The measurements
Single-callee rows: the caller alone, then with that one callee pasted in before it ("callee first") and after it ("callee after"). Scores are quick_diff ratios; % is each function's status.
Must not see (69 pairs)
ea63a49d9ea63a49d9Hurt alone, needed together with the caller's other callees (10 pairs)
Gained, one callee at a time (143 pairs, including the 12 left out above)
The leave-one-out rounds of the 55 callers and the 259 pairs with no effect don't fit here; I can post them as a comment.
🤖 Generated with Claude Code