Repository navigation
Two more Map::Units functions at 100%: UpdateHunterDog and UpdateFireWatch - #433
Open
kotijekriv wants to merge 2 commits into
Open
kotijekriv wants to merge 2 commits into
kotijekriv wants to merge 2 commits into
Conversation
Units::UpdateHunterDog, from Gynt's draft on sourcehold's reimpl/map-units-updatefunctions (his commits on the file: 09935e7 at 19.74%, 7f24f78 at 23.07%, 76269a6 at 24.90% "int index, orig branch order", and the style commit 974c32f), through the forms on our development branches, where its history is. What the match needed, in the order found (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 (44.1 -> 87.0). - Behind setDestinationForUnit towards the hunter the long path (totalSizeOfPathPlan > 8) is the first arm; the prey's ID is an int (one movsx, as in the original, where a short gave a movzx and a movsx); in the state that runs to the shot prey the computeLadderClimbPath that works is the if body and the one that fails is the exit behind it (-> 94.6). - 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. With blocks that return the compiler keeps the earlier of two identical tails, with arms that fall out it keeps the later one, which the original has (-> 95.9). - Inside state 6 (US_FIRE_WEAPONUnk) the three outcomes behind the idle test are an if / else-if / else chain as well. States 3 and 6 both end in the exit that stores state 6; the original has it once, at 0x0056C2D7 behind state 6's code, and state 3 jumps forward to it (0x0056C09F, 0x0056C0A9). With blocks that return in state 6 the compiler kept state 3's copy (-> 100.0). The text follows main's unit functions: BOOLEnum results by truthiness; the UnitState names main has (US_STATE_2Unk, US_STATE_3Unk, US_STATE_9Unk, US_UNKNOWN_120; 10 has no name and stays a cast); const on the five locals that are assigned once; the draft's ternary on closestEnemyMicroDistance as two more arms of its if / else-if chain (style guide 23; the compiler still emits the setg); the steps by one as ++ and -- (rule 29); and a one-line why at each of the two chains. The instruction stream of the function is the same line for line with and without these (a /FA compile with its /GL callees in the unit). compiler-flags-gl.txt gets UpdateHunterDog.cpp. The callees it needs visible are on the list already: checkIfCitizenUnitIsAliveBasedOnState, hasTunnelerNotFinishedDigging, hasUnitReachedDestination, makeUnitStopWalkingByClearingPathProgressState and resumeMovementIfNoAttackTarget. Measured with reccmp, both resolver sets on: - a /GL build of this file with its callee closure: UpdateHunterDog 100.0% raw and normalised, no diff entry; - a build of every file of main's /GL list that exists on main (3458fea), with and without this file and its /GL line (made on the text before the style changes above, same instruction stream): UpdateHunterDog 100.0%, and each of the other 144 functions 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>
Units::UpdateFireWatch, from Gynt's draft on sourcehold's reimpl/map-units-updatefunctions (his commits on the file: 515a714 at 39.28%, 9743265 at 43.29%, and the style commit 974c32f), through the forms on our development branches, where its history is. What the match needed, in the order found (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 (65.5 -> 84.8). - Three branches the way round the original has them. In the state that walks to the patrol point the failing setDestinationForUnit is the else arm, and the found building is handled first with the two exits for no building behind it, the one with a target first. In the state that walks to the fire, where the search for another burning building runs again, the found building is the first arm and the idle state the else (-> 92.1). - 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. With blocks that return the compiler keeps the earlier of two identical tails, with arms that fall out it keeps the later one, which the original has (-> 94.1). - The three death states (US_DEATH_01, US_DEATH_03 and the alive-check arm) in the idiom the other animation states have: the last-frame arm sets gfxNumber and DAT_UnitHasBecomeIdle, the else arm sets gfxNumber from the frame, and one `if (DAT_UnitHasBecomeIdle::instance != 0)` behind both stores ULS_REMOVE. The draft's last-frame arm stored logicalState itself and returned. For one state the instructions are the same either way, because the compiler knows the flag is set on that path. But with the store written out in the arm it merged the identical exits of US_DEATH_01 and US_DEATH_03 (the second jumped back into the first), where the original has one in each state (0x005439F7 and 0x00543A47): six instructions short (-> 100.0). The text follows main's unit functions: BOOLEnum results by truthiness, the UnitState names main has (US_STATE_2Unk, US_STATE_3Unk, US_UNKNOWN_108), const on the ten locals that are assigned once, the steps by one as ++ and --, and a one-line why at the chain. compiler-flags-gl.txt gets UpdateFireWatch.cpp. The callees it needs visible are on the list already: checkIfCitizenUnitIsAliveBasedOnState, commitUnitLocation, hasUnitReachedDestination and makeUnitStopWalkingByClearingPathProgressState. Measured with reccmp, both resolver sets on: - a /GL build of this file with its callee closure: UpdateFireWatch 100.0% raw and normalised, no diff entry; - a build of every file of main's /GL list that exists on main (3458fea) plus this branch's two files: UpdateFireWatch and UpdateHunterDog 100.0% with no diff entry, and each of the other 144 functions reads the same as in the same build of main. Not run in game. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This was referenced Nov 20, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two more functions at 100%, with no header changes. Both are Map::Units functions from gynt's units branch
reimpl/map-units-updatefunctions(his draft #204), and both commits credit him as co-author.Units::UpdateHunterDog/GLUnits::UpdateFireWatch/GLgynt's numbers are as he recorded them in his commit messages; we did not measure his commits again. His last change to both files is the style commit 974c32f.
The steps in between, on our dev branch (not public), reccmp raw / normalised with the file on the
/GLlist:UpdateHunterDogUpdateFireWatch/GLlistMeasured.
Stronghold Crusader.exe(3bb0a8c1…5387ac5a), both resolver sets enabled locally (not committed), and sourcehold's reccmp with--resolve-wrapped-calls --ignore-security-cookie.UpdateHunterDogandUpdateFireWatchread 100.0% raw and normalised, and no function on main reads lower or higher than in the main baseline build (99.58 over 2439)./GLlist that exist on main,parseHlp.cpp(the first entry of our local build list, not on the/GLlist) and the two new files.UpdateHunterDogandUpdateFireWatchread 100.0% raw and normalised, with no diff entries. The average is 99.57 over 146 functions. The same list without the two files and their/GLlines, which is main (3458fea), gives 99.56 over 144, and each of those 144 functions reads the same in both builds.updateBuildingPlacementRotationPreview46.2%,playUnitSelectSpeech94.1%,InitBlendFilterArraysUnk97.9%,lightUpBuilding99.3%,UpdateFireBallistaBuilding99.6% andparseHlp99.7%. That run does not build every file, and we did not look further into them. The full build above is the one to go by.openshc-pr-fixfinds nothing to change, andopenshc-pr-checkgives 0 ERROR and 63 CHECK (all explained below). Main's style lint finds nothing.What got them to 100%
Apart from the dropped
unitIDcopy and UpdateFireWatch's death-state stores, the drafts' statements are all still there; what changed is how they are arranged. The numbers are reccmp raw on our dev branch, on the/GLlist (the table above has the normalised ones).Common to both:
/GLlist (below), and every access reads the unit throughDAT_CurrentUnitSlotID::instance. The drafts took a copy of the slot at the top (int unitID). The original keeps the global itself in a register and loads it again only behind a call that may change it; a local copy is never loaded again. With no copy at all the compiler arrives at the original's loads (UpdateHunterDog 44.1% to 87.0%, UpdateFireWatch 65.5% to 84.8%).UpdateHunterDog:
setDestinationForUnittowards the hunter, the long path (totalSizeOfPathPlan > 8) is the first arm. The prey's ID is anint, which gives the original's onemovsxwhere ashortgave amovzxand amovsx. In the state that runs to the shot prey, thecomputeLadderClimbPaththat works is theifbody and the one that fails is the exit behind it (87.0% to 94.6%).US_FIRE_WEAPONUnk, the dog waits while the hunter shoots). Behind the idle test its three outcomes are an if / else-if / else chain too. States 3 and 6 both end in the exit that stores state 6. The original has it once, at 0x0056C2D7 behind state 6's code, and state 3 jumps forward to it (the twojeat 0x0056C09F and 0x0056C0A9). With blocks that return in state 6 the compiler kept state 3's copy and made state 6 jump back: the same six instructions, in the other place (95.9% to 100.0%). State 3 keeps the blocks that return it had in the draft; written as a chain too it reads the same.UpdateFireWatch:
setDestinationForUnitis the else arm, and the found building is handled first with the two exits for no building behind it, the one with a target first. In the state that walks to the fire, the found building is the first arm and the idle state the else (84.8% to 92.1%).gfxNumberandDAT_UnitHasBecomeIdle, the else arm setsgfxNumberfrom the frame, and oneif (DAT_UnitHasBecomeIdle::instance != 0)behind both storesULS_REMOVE. The draft's last-frame arm storedlogicalStateitself and returned. For one state the instructions are the same either way, because the compiler knows the flag is set on that path and threads the test away. But with the store written out in the arm, it merged the identical exits ofUS_DEATH_01andUS_DEATH_03(the second jumped back into the first), where the original has one in each state, at 0x005439F7 and 0x00543A47: six instructions short, 485 against 491. Written once behind the flag, each state gets its own exit, and the else parts are still shared the way the original shares them (0x00543A1C jumps forward to 0x00543A6C) (94.1% to 100.0%).quick_diff, with the
/GLcallees in the unit, reads 1.0000 for both: 711 instructions against 711, and 491 against 491.Lines added to
cmake/compiler-flags-gl.txtUpdateHunterDog.cpp. Its five callees that have to be visible are on main's list already:checkIfCitizenUnitIsAliveBasedOnState,hasTunnelerNotFinishedDigging,hasUnitReachedDestination,makeUnitStopWalkingByClearingPathProgressStateandresumeMovementIfNoAttackTarget. quick_diff reads 1.0000 with them visible and 0.3336 with none of them (668 instructions against 711).UpdateFireWatch.cpp. Its four are on main's list already too:checkIfCitizenUnitIsAliveBasedOnState,commitUnitLocation,hasUnitReachedDestinationandmakeUnitStopWalkingByClearingPathProgressState. quick_diff reads 1.0000 with them visible and 0.3834 with none of them (474 instructions against 491).cmake/compiler-flags-gl.txt, so whichever goes in second gets a small conflict there: keep the lines of both. Those three are the only PRs this one gives a new conflict in that file. Map::Units::UpdateLion at 100% #425 merges cleanly (its line goes one above the end). reimpl/BuildingsState #234, Reimpl/units state #238, Reimpl/viewport render state #241, reimplement OpenSHC::Text::TextManager and OpenSHC::Text::UserTextHandler #265 and Reimpl/TileMapState 100% batch 2 #396 conflict with main in that file already, and this PR adds nothing to that. Reimplement the remaining Map::Buildings Update* functions #297, Reimplement 16 rendering, UI and GameSynchronyState functions (not yet 100%) #313, Reimplement 88 Map::TileMapState functions at 100% #366, Reimplement 20 BuildingsState functions at 100% #377 and Reimplement 47 UnitsState functions at 100% and restyle 28 more #378 merge cleanly, and Reimpl/tile map state #242's conflicts with main are in headers only.Kept as they are (the 63 CHECKs)
(char)casts (31 CHECKs: 18 in UpdateHunterDog, 13 in UpdateFireWatch): the frame-table reads intoanimationFrame(16 and 8), the compares ofdisappearFadeAlphaCountdown(2 and 4) and the fire watch's one compare ofengineerManningSiegeStateRef_checkType. The headers have these asbyte, and the original reads them signed (see the proposal below).Unit::field_0x3f4,Unit::field_0x40a, and the reads of theFrames_Shared_UnitClimbingUp.field_0x…tables (16 reads of 13 tables for the dog, 8 reads of 7 tables for the fire watch). What they hold is in the next section.(UnitState)10in five places in UpdateHunterDog (5 CHECKs): the enum on main has names for 9 and 11 and none for 10 (see the proposal below).(short)DAT_CurrentUnitSlotID::instancein UpdateFireWatch (1 CHECK): the slot, anintglobal, is stored into the workplace'sworkers[], an array ofshort.Not flagged, but match-driven or worth knowing:
uidandDNE_DESTINATION_NEEDED). The original has the three copies (theuidloads at 0x005434B4, 0x0054361E and 0x00543700).!= 0onshortfields and onDAT_UnitHasBecomeIdle(anundefined4), asUpdateDeerandUpdateDrunkardon main have them.BOOLEnumresults and fields, and theboolfieldsleeping, are tested by truthiness.buildings[i].logicalState != 0stays a number:BuildingLogicalStatehas no name for 0.closestEnemyMicroDistanceis two more arms of the if / else-if chain above it (style guide 23). The compiler still emits the original'ssetg.// sniffing around,// throwing water, ...) are gynt's, from his drafts.What some placeholders hold
US_RELOAD_WEAPONUnk(4) is the dog trotting after the hunter,US_AIM_WEAPONUnk(5) running after him,US_FIRE_WEAPONUnk(6) waiting while he shoots,US_LOOK_AROUNDUnk(7) running to the shot prey andUS_STAND_UPUnk(8) circling it.US_SIT_DOWNUnk(11) is tested on the hunter, not on the dog. For the fire watchUS_RELOAD_WEAPONUnk(4) is throwing water, andUS_JESTER_ROAM_TO(109) is a fade in or out over 17 updates that ends incachedState.Unit::field_0x3f4: above 1 the dog goes toUS_DISAPPEAR.UpdateDrunkardon main has the same test.Unit::field_0x40a: the fire watch sets it to 1 on every update. Nothing more is known from this function.Unit::workplaceBuildingID_1andworkplaceBuildingUID: for the dog the hunter's hut it belongs to. The dog is removed when the hut is gone, asleep or without a worker, and otherwise counted in the hut'snumberOfAnimals. The fire watch writes its own slot into its workplace'sworkers[workerIndex]on every update.Unit::resourceToDeposit: for the dog a counter of its visits to shot prey. On every second one it whimpers first (FX_DOG_WHIMPER, state 10) before it goes back.Unit::targetX_2andtargetY_2: the destination of the dog's way back (state 9,FX_DOG_PANTon arrival), and the fire watch's patrol point.Unit::targetedUnitID__OR__engineerMannedSiegeEngineRefand the…_OR_buildingUID_…field next to it: for the fire watch the burning building it walks to and that building'suid.Unit::engineerManningSiegeStateRef_checkType: for the fire watch the signed step of the fade in state 109 (added todisappearFadeAlphaCountdowneach tick; above 0 the unit's location is committed at the end).Frames_Shared_UnitClimbingUp, the dog:field_0x75e4,0x76d4,0x774c,0x77bcand0x7834are its five frame tables for sitting at the hut, picked bysubstate;field_0x78ec,0x792cand0x7984standing next to the hunter;field_0x79c8states 2 and 6;field_0x79e4whimpering;field_0x7a2cthe melee attack;field_0x7a54andfield_0x7aacthe two deaths.Frames_Shared_UnitClimbingUp, the fire watch:field_0x82f8,0x8320,0x834cand0x837care its four look-out tables, picked bysubstate;field_0x82d0throwing water;field_0x8234bothUS_DEATH_01andUS_DEATH_03;field_0x8284the third death.hasTunnelerNotFinishedDiggingandcomputeLadderClimbPathare called for the dog here (and for the drunkard and the burning man on main), so both names are narrower than what the functions do.findClosestReachableAlliedBuildingis what the fire watch calls for the building to put out; it then tests that building'sfireDuration.Proposed, not changed here
charfor byte fields read as signed:Unit::disappearFadeAlphaCountdown,Unit::engineerManningSiegeStateRef_checkTypeand the AnimationFrameData frame tables, as on Five more functions at 100%: InGameMenu MainButtons, Roundtable handler, BuySell, UpdateGhost and UpdateHopsFarmer #416 and Three more Map::Units functions at 100%: UpdateOx, ConsiderHavingABreakNowUnk and UpdateMinerIronFetcher #421. Ascharthe(char)casts above could go.UnitState10 (US_STATE_10Unk, next toUS_STATE_9Unk), through the Ghidra sync. UpdateHunterDog's five casts would then go. We did not add it here: Map::Units::UpdateLion at 100% #425 found that new enumerators inUnitState.hppmove one function on main.Other PRs
UpdateHunterDog.cppand onUpdateFireWatch.cpp, and two more hunks in the status file, where it conflicts with main already: 0x0056B970 (100.0% here against his 24.9%) and 0x00543340 (100.0% against his 43.3%). Once this lands, his branch can take main's version of both files and lines.UpdateOx,ConsiderHavingABreakNowUnk) and Map::Units::UpdateLion at 100% #425 (UpdateLion) are independent of this one. Three more Map::Units functions at 100%: UpdateOx, ConsiderHavingABreakNowUnk and UpdateMinerIronFetcher #421 has the/GLlist conflict named above; Map::Units::UpdateLion at 100% #425 merges cleanly./GLlist (computeLadderClimbPath,changeDestinationByAmount,changeDestinationByLeftoverandresumeMovementAfterInterruption) and merges cleanly. On a local test tree, our dev branch with Reimplement 47 UnitsState functions at 100% and restyle 28 more #378's 47 new files and its/GLlines on top, both functions still read 100.0% raw and normalised; that is not a build of main with Reimplement 47 UnitsState functions at 100% and restyle 28 more #378.🤖 Generated with Claude Code