Skip to content

Reimplement 28 Map::Buildings Update* functions that are 100% - #281

Merged
gynt merged 5 commits into
sourcehold:mainfrom
6and8:buildings-update-100
Oct 28, 2026
Merged

gynt merged 5 commits into
sourcehold:mainfrom
6and8:buildings-update-100

Conversation

@6and8

@6and8 6and8 commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

28 Map::Buildings per-building-type Update* functions that measure 100% with reccmp --resolve-wrapped-calls (struct and function resolvers enabled locally, not committed), with their status entries. These are the free functions updateBuildings dispatches to (one per building type, declared in Buildings.func.hpp).

UpdateAppleFarm, UpdateArmorersWorkshop, UpdateBadBuildingChoppingBlock, UpdateBakery, UpdateBarracks, UpdateBlacksmithsWorkshop, UpdateBuildingShared2, UpdateCampGround, UpdateCathedral, UpdateFletchersWorkshop, UpdateGoodBuildingShrine, UpdateGoodBuildingStatue, UpdateHovel, UpdateHuntersPost, UpdateInn, UpdateIronMine, UpdateKeepDoor, UpdateKeepDoorLeft, UpdateKeepDoorRight, UpdateMercenaryPost, UpdatePitchRig, UpdatePoleturnersWorkshop, UpdateStables, UpdateTunnel, UpdateTunnelersGuild, UpdateWellOrWaterpot, UpdateWoodGate1, UpdateWoodcuttersHut.

Built and measured on its own on top of current main (main's BuildingsState sources plus these 28): all 152 functions measure 100%.

Eight of them are built with /GL (cmake/compiler-flags-gl.txt): the five workshops (armorer, fletcher, poleturner, blacksmith, bakery), UpdateInn, UpdateIronMine and UpdateStables. They also need their BuildingsState callees from main built with /GL: updateVisuallyActiveState, validateBuildingTetheredUnits, buildingHasSpaceForResource and getBuildingResourceAmountByUid (still 100% that way). Without LTCG knowledge of those callees the compiler keeps the building ID in a register across the calls, where the original reloads it, and the eight drop to 27-63%.

The second commit renames the Building fields in main's own users (field202_0x2c8 -> field201_0x2c8, ...), which no longer compile after the Ghidra sync; it is the same change as in #280 and #273. The third commit accidentally included my local reccmp resolver flags (Globals/*.hpp, *.func.hpp); the fourth reverts them, so the PR diff has none (37 files).

No header changes are needed. The other 43 Update* functions are reimplemented too but not yet at 100%; I'll keep improving them locally and send them separately, like #273.

Faithful quirks, commented in the source: UpdateInn clears the sprite it just animated, and UpdateHuntersPost stores the value it just compared against.

Cheat sheet candidates

  • Identical tails in two arms: MSVC cross-jumping keeps the first copy. When the original keeps a later copy (the earlier arm jumps forward into it), write the earlier arm as a goto into a label in the later arm (UpdateFletchersWorkshop).
  • Original loads a value above a store that ours makes first: move the read statement before the store in the source (UpdateTunnel).
  • movsx of a short field followed by a 32-bit compare: read the field into an int local first (UpdateHuntersPost).
  • Same body for two values compiled as two compares, each with its own copy of the pushes: separate else if arms instead of || (UpdateIronMine).

Built with the bundled MSVC1400-SP1, natively on Windows.

🤖 Generated with Claude Code

loamifi-jake and others added 4 commits October 28, 2026 13:30
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
field202_0x2c8 -> field201_0x2c8, field201_0x2c6 -> field200_0x2c6, field162_0x280 -> field161_0x280:
these files no longer compiled after the Ghidra sync. Same change as in sourcehold#280 and sourcehold#273.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…with /GL

Without LTCG knowledge of updateVisuallyActiveState, validateBuildingTetheredUnits,
buildingHasSpaceForResource and getBuildingResourceAmountByUid the eight /GL Update*
functions keep the building ID across those calls and do not match.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The /GL list change stays; the Globals/*.hpp and *.func.hpp edits were local reccmp flags.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
gynt
gynt previously approved these changes Oct 28, 2026
@gynt
gynt merged commit 599d13e into sourcehold:main Oct 28, 2026
1 check 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.

3 participants