Repository navigation
Reimplement 5 Map::Units update functions from gynt's units branch, under /GL (100%) - #393
Conversation
…callees UpdateBurningMan, UpdateMiner, UpdateQuarryMason, UpdateDrunkard and UpdateInnkeeper only match with link-time code generation. The original keeps values in registers across the calls it could see into: a constant or the unit's state in edx across checkIfCitizenUnitIsAliveBasedOnState (which leaves edx alone) in the first four, and the unit index in esi/edi across hasUnitReachedDestination, checkIfCitizenUnitIsAliveBasedOnState and getBuildingResourceAmountByUid in UpdateInnkeeper. After the calls it could not see into, it reads DAT_CurrentUnitSlotID again. The six UnitsState functions added here are 100% on main with their function resolvers on, and each stays at 100% under /GL (full build of this branch alone). Who needs them: - checkIfCitizenUnitIsAliveBasedOnState and makeUnitStopWalkingByClearingPathProgressState: all five; - hasTunnelerNotFinishedDigging: UpdateBurningMan (its last 0.8 points) and UpdateDrunkard; - hasUnitReachedDestination and commitUnitLocation: UpdateMiner, UpdateQuarryMason and UpdateInnkeeper; - resumeMovementIfNoAttackTarget: UpdateQuarryMason and UpdateDrunkard. UpdateInnkeeper's four BuildingsState callees are on main's list already and stay at 100% too: buildingIsAccessible, getStorageBuildingForResourceTypeAndAmount, getBuildingResourceAmountByUid and addResourceToStockpile. Three callees that are 100% on main stay off the list. setLastEncounteredTroopUnit (UpdateMiner, UpdateQuarryMason) makes no calls, so under /GL the caller would know it leaves DAT_CurrentUnitSlotID alone and skip the re-read the original does (with it in UpdateQuarryMason's translation unit: quick_diff 1.0000 -> 0.9901; UpdateMiner returns right after the call and stays 1.0000). setWorkplaceBuildingEntryAsTarget and resetUnitMovementState (UpdateInnkeeper) would gain nothing: they call on into functions that are not under /GL (buildingIsAccessible's callees calculateCanPlayerUnitsNavigateToAreaFromArea and determineBuildingEntranceFromKeepArea, which are not reimplemented yet, and commitPendingUnitPosition), so UpdateInnkeeper reads the slot again after them either way, and with both in its translation unit its code is identical (quick_diff 1.0000). setDestinationForUnit, computeLadderClimbPath and changeDestinationByAmount are not reimplemented yet. quick_diff here is the variant that compares absolute global addresses, run with the callees' .cpp files #included at the top of the caller; that emulates /GL for these functions to the instruction. On reimpl/map-units-updatefunctions, gynt's status lines for these five read "LTCG regs across calls" (UpdateInnkeeper: "LTCG_regs"), which is where this started. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Units::UpdateBurningMan (0x0053BC20) puts a unit into state 120 (mov word ptr [ecx + 0x138880C], 0x78 at 0x0053BC9D: the units array at 0x0138854C plus state at 0x2C0) and tests for it (cmp bp, 0x78 at 0x0053BCEA). Units::UpdateMiner (0x005401D0), Units::UpdateQuarryMason (0x00550A50) and Units::UpdateInnkeeper (0x00540EC0) test for state 108 (cmp ax, 0x6c at 0x005402E3, cmp dx, 0x6c at 0x00550B66, cmp ax, 0x6c at 0x00541523). The enum goes from US_MELEE_ATTACK_WALL (107) to US_JESTER_ROAM_TO (109) and from US_STONE_DEATH_03 (116) to US_UNKNOWN_121 (121); the two are named in the US_UNKNOWN_<n> form. Used in place of (UnitState)108 and (UnitState)120; code generation is the same. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
UpdateBurningMan. Builds on gynt's bd4d1d5 ("66.14% LTCG regs across calls") as our fork's copy of his branch has it, with main merged in and main's header renames followed (43a17df, names only), where his draft measures 76.5% in reccmp (normalized 74.5%) in a full build with the Globals and the function resolvers on (2026-11-10). This version is 100.0% (normalized 100.0%) in a full build of this branch alone, with /GL on it and on its callees hasTunnelerNotFinishedDigging, checkIfCitizenUnitIsAliveBasedOnState and makeUnitStopWalkingByClearingPathProgressState (first commit), which all stay at 100%. The stores before the state read, the state-0 block, the unit-is-alive block and the three stores after hasTunnelerNotFinishedDigging index the units through DAT_CurrentUnitSlotID. That keeps them in the original's order and leaves edx for the constant 1 the original keeps across checkIfCitizenUnitIsAliveBasedOnState (everything through unitID: quick_diff 1.0000 -> 0.7154, in one comment above unitID). State 120 is US_UNKNOWN_120 (header commit), and computeLadderClimbPath's BOOLEnum is tested for truth. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
UpdateMiner. Builds on gynt's 5e96437 ("51.78% LTCG regs across calls") as our fork's copy of his branch has it, with main merged in and main's header renames followed (43a17df, names only), where his draft measures 58.9% in reccmp (normalized 58.9%) in a full build with the Globals and the function resolvers on (2026-11-10). This version is 100.0% (normalized 100.0%) in a full build of this branch alone, with /GL on it and on its callees checkIfCitizenUnitIsAliveBasedOnState, hasUnitReachedDestination, commitUnitLocation and makeUnitStopWalkingByClearingPathProgressState (first commit), which all stay at 100%. Ten unit accesses go through DAT_CurrentUnitSlotID, which keeps the original's load and store order and its registers (everything through unitID: quick_diff 1.0000 -> 0.9013), and the death, unit-is-alive and default blocks form one else-if chain, so the shared tail sits in the second arm as in the original (early returns: quick_diff 1.0000 -> 0.9385). The worker slot takes unitID without a (short) cast, and state 108 is US_UNKNOWN_108 (header commit). Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
UpdateQuarryMason. Builds on gynt's ec84561 ("45.27% LTCG regs across calls") as our fork's copy of his branch has it, with main merged in and main's header renames followed (43a17df, names only), where his draft measures 62.2% in reccmp (normalized 62.2%) in a full build with the Globals and the function resolvers on (2026-11-10). This version is 100.0% (normalized 100.0%) in a full build of this branch alone, with /GL on it and on its callees checkIfCitizenUnitIsAliveBasedOnState, hasUnitReachedDestination, commitUnitLocation, makeUnitStopWalkingByClearingPathProgressState and resumeMovementIfNoAttackTarget (first commit), which all stay at 100%. Twelve unit accesses go through DAT_CurrentUnitSlotID, which keeps the original's load and store order and its registers (everything through unitID: quick_diff 1.0000 -> 0.9059). One of them is the workplace read at the end of the disappear block, where the original reads the slot again after setLastEncounteredTroopUnit (the workplace local there: quick_diff 1.0000 -> 0.8536). The blocks from the death state on form one else-if chain (early returns: quick_diff 1.0000 -> 0.9507). The worker slot takes unitID without a (short) cast, and state 108 is US_UNKNOWN_108 (header commit). Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
UpdateDrunkard. Builds on gynt's 171a691 ("48.31% LTCG regs across calls") as our fork's copy of his branch has it, with main merged in and main's header renames followed (43a17df, names only), where his draft measures 53.5% in reccmp (normalized 53.5%) in a full build with the Globals and the function resolvers on (2026-11-10). This version is 100.0% (normalized 100.0%) in a full build of this branch alone, with /GL on it and on its callees checkIfCitizenUnitIsAliveBasedOnState, hasTunnelerNotFinishedDigging, makeUnitStopWalkingByClearingPathProgressState and resumeMovementIfNoAttackTarget (first commit), which all stay at 100%. Fifteen unit accesses go through DAT_CurrentUnitSlotID, which keeps the original's load and store order and its registers (everything through unitID: quick_diff 1.0000 -> 0.6877), and the next state comes from an if that tests resourceToDeposit >= 6, which gives the original's setl (< 6 with the arms swapped: quick_diff 1.0000 -> 0.9848). computeLadderClimbPath's BOOLEnum is tested for truth. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
UpdateInnkeeper. Builds on gynt's 6b8b0c2 ("50.68% LTCG_regs") as our fork's copy of his branch has it, with main merged in and main's header renames followed (43a17df, names only), where his draft measures 63.4% in reccmp (normalized 58.5%) in a full build with the Globals and the function resolvers on (2026-11-10). This version is 100.0% (normalized 100.0%) in a full build of this branch alone, with /GL on it and on its callees checkIfCitizenUnitIsAliveBasedOnState, hasUnitReachedDestination, commitUnitLocation and makeUnitStopWalkingByClearingPathProgressState (first commit) and buildingIsAccessible, getStorageBuildingForResourceTypeAndAmount, getBuildingResourceAmountByUid and addResourceToStockpile (on main's list), which all stay at 100%. His draft had the ale-level tests one step off: < 150 and > 400 where the original has jg and jge, that is <= 150 and >= 400. Every unit access goes through DAT_CurrentUnitSlotID, which the original reads again after each call it cannot see into (a unitID local: quick_diff 1.0000 -> 0.6159), and the substate wraps at >= 4. Three tests that the draft wrote as early returns keep the success path in the then-arm and the failure after the if, which is where the original puts the failure blocks (it jumps forward to them): - state 2, ale fetched: when setWorkplaceBuildingEntryAsTarget fails, the unit is removed after the then-arm (an early return: quick_diff 1.0000 -> 0.9723); - state 3, ale delivered: the < 400 then-arm comes first, and the full inn's commitUnitLocation after it (0.9822); - inside that arm, the accessible-storage path comes first, and the other commitUnitLocation after it (0.9881). The other failures return early, as in the draft: the unreached destination in states 2 and 3, the storage that is not accessible after the serving animation and in state US_AIM_WEAPONUnk, and the full inn there. setWorkplaceBuildingEntryAsTarget's BOOLEnum is tested for truth, the target slot takes storage without a (short) cast, states 2 and 3 are US_STATE_2Unk and US_STATE_3Unk, and state 108 is US_UNKNOWN_108 (header commit). Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
gynt
left a comment
There was a problem hiding this comment.
changes were just pushed upstream btw
Its Ghidra sync brings UnitState's US_UNKNOWN_108 and US_UNKNOWN_120, so the header commit now matches main. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ate functions gynt on sourcehold#393: "These comments can go!" The top comment of UpdateBurningMan, UpdateMiner, UpdateQuarryMason, UpdateDrunkard and UpdateInnkeeper explained why their unit accesses index through DAT_CurrentUnitSlotID. Comments only; the code is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks! Main (02b5f47) is merged in (17a84e8), so The other one-line comments are still there: the three early-return ones in UpdateInnkeeper, the else-if chains in UpdateMiner and UpdateQuarryMason, the workplace re-read in UpdateQuarryMason and the |
Those are fine |
Five more Map::Units update functions from gynt's units branch
reimpl/map-units-updatefunctions(his draft #204), all at 100%. They are the ones his status marks "LTCG regs across calls": each matches only with/GLon it and on the callees it keeps registers across.Units::UpdateBurningManUnits::UpdateMinerUnits::UpdateQuarryMasonUnits::UpdateDrunkardUnits::UpdateInnkeeper"His draft today" is his file on our fork's copy of his branch (his 48b79a2 with main d5d965d merged in, plus a names-only build fix), in a full reccmp build with the Globals and the function resolvers on (2026-11-10). Each commit says which of his commits it builds on and carries him as co-author.
What made them match:
/GL(first commit). The original keeps a constant, or the unit's state, inedxacrosscheckIfCitizenUnitIsAliveBasedOnState, which leavesedxalone (the first four). UpdateInnkeeper keeps the unit index inesi/ediacrosshasUnitReachedDestination,checkIfCitizenUnitIsAliveBasedOnStateandgetBuildingResourceAmountByUid. That only happens with link-time code generation, so the five go oncmake/compiler-flags-gl.txtwith six UnitsState callees:checkIfCitizenUnitIsAliveBasedOnState,makeUnitStopWalkingByClearingPathProgressState,hasTunnelerNotFinishedDigging,hasUnitReachedDestination,commitUnitLocationandresumeMovementIfNoAttackTarget. All six are 100% on main and stay at 100% under/GL. UpdateInnkeeper's four BuildingsState callees are on the list already.setLastEncounteredTroopUnitmakes no calls, so under/GLUpdateQuarryMason would skip the re-read ofDAT_CurrentUnitSlotIDthat the original does after it (quick_diff 1.0000 -> 0.9901).setWorkplaceBuildingEntryAsTargetandresetUnitMovementStategain nothing, since they call into functions that are not under/GL.DAT_CurrentUnitSlotID. After each call it cannot see into, the original reads the current slot again instead of keepingunitID. So 10 to 15 statements per function indexunits[DAT_CurrentUnitSlotID::instance], as the original does; UpdateInnkeeper has nounitIDlocal at all. Everything throughunitIDmeasures 0.62 to 0.91 in quick_diff (0.7154 BurningMan, 0.9013 Miner, 0.9059 QuarryMason, 0.6877 Drunkard, 0.6159 Innkeeper).jg/jge, so they are<= 150and>= 400.Measured on main 639c193. Main is merged in up to 02b5f47, whose newer commits add enum names only, and the changes here since the build are comment lines only.
Stronghold Crusader.exe(3bb0a8c1…5387ac5a), resolvers enabled locally (not committed), and sourcehold's reccmp with--resolve-wrapped-calls --ignore-security-cookie./GLcallees at 100%..cppfiles#included at the top of the caller. That emulates/GLfor these functions to the instruction.openshc-pr-checkgives no errors, andstatus_regression.pyfinds no score below a known one.Header change (a commit of its own)
gynt's Ghidra sync 02b5f47 brought both values to main. Main is merged in (17a84e8), so this commit now matches main.
UnitStategetsUS_UNKNOWN_108andUS_UNKNOWN_120(380b74f4b), in theUS_UNKNOWN_<n>form, in place of(UnitState)108and(UnitState)120; code generation is the same.mov word ptr [ecx + 0x138880C], 0x78at 0x0053BC9D: the units array at 0x0138854C plusstateat 0x2C0) and tests it (cmp bp, 0x78at 0x0053BCEA).cmp ax, 0x6cat 0x005402E3,cmp dx, 0x6cat 0x00550B66,cmp ax, 0x6cat 0x00541523).US_MELEE_ATTACK_WALL(107) toUS_JESTER_ROAM_TO(109), and fromUS_STONE_DEATH_03(116) toUS_UNKNOWN_121.Kept as they are, measured with quick_diff (each has a one-line comment)
< 400arm first, the full inn'scommitUnitLocationafter itsetLastEncounteredTroopUnitworkplacelocal: 1.0000 -> 0.8536resourceToDeposit >= 6for the next state (the original'ssetl)< 6with the arms swapped: 1.0000 -> 0.9848Proposed, not changed here
(char)casts remain, onUnit::disappearFadeAlphaCountdown(+0x32E) and on fields of the AnimationFrameData tables. Both arebytein the headers, but the original compares them as signed (< 0,> 32), so without the cast< 0is always false. Retyping them tocharin Ghidra would let the casts go.Frames_Shared_UnitClimbingUp(UnitPropertiesDefinedData +0x8B78, 33,748 bytes) is the whole AnimationFrameData table. All five read other animations from it (ANIM_Frames_UnitDeath,DAT_InnKeeperAnimationIndices,drunkard), so a name such asAnimationFrameswould fit better.DAT_UnitHasBecomeIdleisundefined4, but it is only ever stored 1 or tested against 0, so it could beBOOLEnum(as Reimplement 11 Map::Units functions from gynt's units branch (100%) #390 said too).animationCycleNumber = 0a second time whensetDestinationForUnitfails (line 106), as the original does.buildingIsAccessiblereturnsint, so the tests on it stay== 0/!= 0.Other PRs
🤖 Generated with Claude Code