Repository navigation
Reimplement UpdateQuarryWorker and UpdateBaker from gynt's units branch (100%, one with OPENSHC_FUNCTION_VISIBILITY_UNITS on) - #561
Merged
Conversation
Unit.hpp, offset 0x410: `byte` -> `char`, the size and the name stay. The original tests the field signed in UpdateQuarryWorker: mov cl, byte ptr [unit + 0x138895c] at 0x00551205, test cl, cl, jle at 0x0055120D. The other instructions of the game with that address are that function's two stores (0x00551212, 0x0055123E) and the compare with 0 at 0x00422497 in findQuarryPileThatIsCloseAndHasMostStone, the field's only user on main, which tests it with `!= 0` and reads the same: 100.0 / 100.0 in the small builds of this branch on main 06cdd81, with OPENSHC_FUNCTION_VISIBILITY_UNITS on and off. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Units::UpdateQuarryWorker, from Gynt's draft on sourcehold's reimpl/map-units-updatefunctions (his draft PR 204; his commits on the file: 99f9b5b at 53.35%, d839367 at 59.76%, then 974c32f's clang-format), through the forms on our development branches. It reads 100.0 / 100.0 in the default build; with OPENSHC_FUNCTION_VISIBILITY_UNITS on, its entry in cmake/function-visibility.txt and getBuildingResourceAmountByUid defined inline in its own file (on main since PR 536) it reads 100.0 / 100.0 (reccmp raw / normalised). Compared with his draft as folded text (spelling, qualifiers and the local copy of the slot folded): the 36 calls have the same arguments, and the 64 tests and the stores are the same but for the list below (a BOOLEnum call's `!= 0` / `== FALSE` written as a truth test, and tests turned round where the arms are swapped, are not listed). - Every access reads the unit through DAT_CurrentUnitSlotID::instance; the draft keeps the slot in a local read at the top, and reads the global itself behind some calls. quick_diff with the entry's callees in front reads 0.9932 with the local (without the callee below) and 0.9973 without it and with that callee. - State 1: behind tracePathFromLadderExitSetDestination the original does not load the slot again (one load at 0x00550F92, used at 0x00550F98 and 0x00550FA3), so it saw that body: the entry names it. No .cpp on main calls it. - State 7: the reset of the animation cycle tests DAT_UnitHasBecomeIdle itself, and the idle local is read behind it; the draft reads the local first and tests it. The test stands in front of the gfxNumber store in the original (0x0055105F, 0x00551061). - `substate > 6` is `>= 7` and `currentIndexInPathPlan > 7` is `>= 8`, the constants the original compares with (0x005510A9, 0x00551402). - States 101 and 102 have the arm with a stone first, and state 102 the arm with space in the stockpile. Text pass (after the changes above), the same object code before and after, the unit alone and with its entry's callees in front: states by UnitState_QuarryWorker's names (state.quarryWorker) where it has one, resources[4] as RT_STONE, hex constants as decimal, the file-scope using lines gone, the (char) casts on the fade countdown, the frame tables and field_0x410 dropped (char in the headers), ++ / -- for the steps of one, the BOOLEnum calls tested by truthiness, const on the locals, a why above the ternary and above the three locals at the top, state comments that say what the state does. Measured with real builds (bundled MSVC1400-SP1, function and data resolvers on locally, reccmp raw / normalised), small builds of this branch on main 06cdd81 (491 files, 504 functions: every /GL file, both units, every .cpp that names getBuildingResourceAmountByUid, findQuarryPileThatIsCloseAndHasMostStone (field_0x410's user), the callees of these that read 100.0 down their call trees, IO/ResourceManager/paths.cpp for the link, and every file of a function-visibility group that touches one of these), with OPENSHC_FUNCTION_VISIBILITY_UNITS on and off, 0 failures. On and off: 100.0 / 100.0. The text was measured before on an older base (small and full builds, both modes, the same readings); on main 06cdd81 its object code is the same, bytes and relocations, alone and with the entry's callees in front. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…N_VISIBILITY_UNITS on Units::UpdateBaker, from Gynt's draft on sourcehold's reimpl/map-units-updatefunctions (his draft PR 204; his commits on the file: 159da06 at 51.69%, aa0d801 at 57.72%, then 974c32f's clang-format), through the forms on our development branches. With OPENSHC_FUNCTION_VISIBILITY_UNITS on, its entry in cmake/function-visibility.txt and getBuildingResourceAmountByUid defined inline in its own file (on main since PR 536) it reads 100.0 / 100.0 (reccmp raw / normalised). Compared with his draft as folded text (spelling, qualifiers and the local copy of the slot folded): the 55 calls have the same arguments, and the 72 tests and the stores are the same but for the list below (a BOOLEnum call's `!= 0` / `== FALSE` written as a truth test, and tests turned round where the arms are swapped, are not listed). - Every access reads the unit through DAT_CurrentUnitSlotID::instance; the draft keeps the slot in a local read at the top, and reads the global itself behind some calls. - The states are one if / else-if / else chain whose arms fall out; with a return closing each state the match is lost (checked on this text: the object code differs with the entry's callees in front). - Arms the other way round than in the draft, by state: 1 (the paused baker's frame first); 2 (a destination found first, the exit to disappearing behind it); 7, the fetching state (no way to the next stockpile first, the removal behind it; the way home first, the removal behind it; the way to the bakery first, the removal behind it); 6, the delivery (space in the granary first; the next granary reachable first; the next stockpile reachable first; the way home first, the removal behind it, in both arms). State 8, carrying flour to the bakery, has the draft's arms. - The stores that send him home stand in each arm that reaches them, where the draft has them once behind the tests: state 2, substate -1, seated 0 and destinationNeeded in state 6, state 2 and destinationNeeded in state 7. With the draft's form in state 7 or in state 6, or one setWorkplaceBuildingEntryAsTarget test behind both paths in state 6, the object code differs (each tried). Text pass (after the changes above), the same object code before and after, the unit alone and with its entry's callees in front: states by UnitState_Baker's names where it has one (through state.generic, the union has no member for it), hex constants as decimal, the file-scope using lines gone, the (char) casts on the fade countdown and the frame tables dropped (char in the headers), engineerManningSiegeStateRef_checkType set to -2, ++ / -- for the steps of one, the BOOLEnum calls tested by truthiness, const on the locals, a local of its own for the next stockpile, a return that falls out anyway dropped, whys above the local at the top and above the repeated stores (in states 6 and 7). Measured with real builds (bundled MSVC1400-SP1, function and data resolvers on locally, reccmp raw / normalised), small builds of this branch on main 06cdd81 (491 files, 504 functions: every /GL file, both units, every .cpp that names getBuildingResourceAmountByUid, findQuarryPileThatIsCloseAndHasMostStone (field_0x410's user), the callees of these that read 100.0 down their call trees, IO/ResourceManager/paths.cpp for the link, and every file of a function-visibility group that touches one of these), with OPENSHC_FUNCTION_VISIBILITY_UNITS on and off, 0 failures. On: 100.0 / 100.0. Off: 93.2 / 87.2. The status line carries the default build's raw number. The text was measured before on an older base (small and full builds, both modes, the same readings); on main 06cdd81 its object code is the same, bytes and relocations, alone and with the entry's callees in front. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ateBaker Both need the bodies of the callees below in the unit they are compiled with; each entry names them at the unit's address, the callees in address order. Every name but one is already a member of the group that holds hasUnitReachedDestination. The one is tracePathFromLadderExitSetDestination (100.0%, no calls of its own, on the /GL list): no .cpp on main calls it, so it joins the group (and leaves the /GL list with the option on) and no other function sees a body it did not see before or loses one. The generator makes 25 wrapper units holding 174 source files (25 and 171 on main 06cdd81): the two units and that callee are the only new members. Measured with quick_diff, the unit compiled with the callee files in front of it (the getter inline) against the unit alone. The rest to 1 is spelling in quick_diff's two streams (a negative byte or word immediate prints as 0xff / 0xffff on the original's side). - UpdateQuarryWorker: 0.5256 alone, 0.9986 with the 9 listed. Left out, getBuildingResourceAmountByUid 0.9959; IncrementAndOptionalUpdateAVValueRelated 0.9436; ConsiderHavingABreakNowUnk 0.9802; SetStateToFreetimeWalking 0.9714; ComputeGoodsProduced 0.9883; checkIfCitizenUnitIsAliveBasedOnState 0.79; hasUnitReachedDestination 0.9544; tracePathFromLadderExitSetDestination 0.9856; UpdateWorker_ConsiderTakingABreakUnk 0.9802. - UpdateBaker: 0.5688 alone, 0.9953 with the 14 listed. Left out, getBuildingResourceAmountByUid 0.9764; setupUnitSharingTileIDs 0.9929; standUpIfSeated 0.9923; sitDownIfStanding 0.9935; IncrementAndOptionalUpdateAVValueRelated 0.8231; ConsiderHavingABreakNowUnk 0.99; SetStateToFreetimeWalking 0.9682; CheckUnitProductionPaused 0.9369; ComputeGoodsProduced 0.9529; checkIfCitizenUnitIsAliveBasedOnState 0.9226; hasUnitReachedDestination 0.9442; setupUnitSharingCurrentTilePosition 0.9929; UpdateWorker_ConsiderTakingABreakUnk 0.99; commitUnitLocation 0.9929. Not named, leaving it out changes nothing: makeUnitStopWalkingByClearingPathProgressState. Real builds: the small builds of the unit commits. With the option on the two units read 100.0 / 100.0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Style guide reading (advisory, posted once) 1 possible deviation(s) from REIMPLEMENTATION_STYLE_GUIDE.md across 1 of the 2 reimplemented The match comes first. Where the ugly form is what matched, it stays -- that is the guide's own overriding rule, and rule 21 asks for a one-line comment saying what was measured so the next reader does not retry it. This report is posted once, when the PR opens, and is not repeated on later pushes.
WhereRule 23 — Prefer if-else over ternary
|
gynt
added a commit
that referenced
this pull request
Dec 4, 2026
Main now has Unit::field_0x410 as a char (gynt's 55fa231), the same change as this branch's header commit, so the merge is clean and the PR no longer changes Unit.hpp. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
gynt
approved these changes
Dec 4, 2026
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 of the units from gynt's units branch
reimpl/map-units-updatefunctions(his draft #204) that callBuildingsState::getBuildingResourceAmountByUid, which main definesinlinesince #536. The branch is on main 87e40b6, with main 4a2a6cb merged in. UpdateQuarryWorker reads 100.0% raw and normalised in the default build and with main's function-visibility option on, UpdateBaker with the option on and less in the default build (see the table). Each gets an entry incmake/function-visibility.txt; one header field gets its type (Unit::field_0x410, below). Each unit commit cites gynt's commits on the file and credits him as co-author; the text work began on other development branches of ours, written with Claude Fable 5.2, and the unit commits keep that co-author line.Units::UpdateQuarryWorkerUnits::UpdateBaker"Before" is gynt's own status number on the file (main's status file has 0.0%, Pending, for both). The default build's numbers are raw / normalised. UpdateBaker's status line carries the default build's raw number with the remark
100.0 with OPENSHC_FUNCTION_VISIBILITY_UNITS on, as main's UpdatePitchman, UpdateEngineer and UpdateDairyFarmer have.Header change
Unit::field_0x410(Unit.hpp, offset 0x410):bytetochar, in a commit of its own in front of the units. gynt synced it to main in 55fa231, and main is merged in, so the PR's diff no longer shows it; the commit stays in the branch's history. The original tests it signed in UpdateQuarryWorker (mov cl, byte ptr [unit + 0x138895c]at 0x00551205,test cl, cl,jleat 0x0055120D). The other instructions of the game with that address are that function's two stores (0x00551212, 0x0055123E) and the compare with 0 at 0x00422497 infindQuarryPileThatIsCloseAndHasMostStone, the field's only user on main, which tests it with!= 0and reads 100.0% / 100.0% in this branch's small builds, option on and off, and in main's with the option on. The size and the name stay.The entries
#includes its members (without/GL), and the members leave the/GLlist. Every name but one is already a member of the group that holds hasUnitReachedDestination. The one istracePathFromLadderExitSetDestination(100.0%, no calls of its own, on the/GLlist): no .cpp on main calls it, so it joins the group (and leaves the/GLlist with the option on) and no other function sees a body it did not see before or loses one.cmake/function-visibility-units.pymakes 25 wrapper units holding 174 source files on this branch, 171 on main 06cdd81: the two units and that callee are the only new members.tracePathFromLadderExitSetDestinationthe original does not load the slot again (one load at 0x00550F92, used at 0x00550F98 and 0x00550FA3), so it saw that body. UpdateQuarryWorker is 0.9856 without it and 0.9986 with it./GLwith their group, so without the entry it would lose their bodies; the 0.5256 for the unit alone is the measure.quick_diff, the unit with the callees of its entry in front of it. The rest to 1 is spelling in quick_diff's two streams (a negative byte or word immediate prints as 0xff / 0xffff on the original's side).Measured
Setup: the bundled MSVC1400-SP1 against the Steam
Stronghold Crusader.exe(3bb0a8c1…5387ac5a), both resolver sets enabled locally (not committed: the data resolvers withtools/reimplementation-control/enable_reimplemented_data.py, the function resolver of every.cppin the build withtools/reimplementation-helper/batch/enable_local_functions.py), and sourcehold's reccmp with--resolve-wrapped-calls --ignore-security-cookie. The builds are of main 06cdd81 and of this branch on it, before it was rebased onto 87e40b6. gynt's three header syncs in between (1fea2ce, c1b50c4, 87e40b6) add one line to the status file, add theTribeStateandTribeStateShortenums and renameTreeStateEnum's values (TS_toTSE_), which no.cppnames; no.cppchanges.prepareProjectileTarget.cppcompiles, and leaving outresetTileAndClearMoat(it doesn't compile on main until Reimplement 67 Map::TileMapState functions (batch 2) #396),TransformAndRenderPercentage(on our list from before Reimplement 59 TextManager and UserTextHandler functions at 100% #509) andfindBestAttackTileByPathCost(on our list from before 592a17d made it compile): 3,111 files on the branch and 3,109 on main, BUILD_OK, 3,129 and 3,127 functions compared. Only the two units read differently: main doesn't have them, and hereUpdateQuarryWorkerreads 100.0% / 100.0% andUpdateBaker93.2% / 87.2%. The other 3,127 read the same,handleMenuItemsandConstructor_Menuincluded: they go between two readings from one build to another with their files unchanged, and read 100.0% in both of these./GLfile, both units, every.cppthat namesgetBuildingResourceAmountByUid,findQuarryPileThatIsCloseAndHasMostStone.cpp(the user ofUnit::field_0x410), the callees of these that read 100.0% down their call trees, every file of a function-visibility group that touches one of these, andIO/ResourceManager/paths.cpp, which the link needs): BUILD_OK and 0 failures in all three. Main's small build with the option off was not run; the full builds above compare that mode.UpdateQuarryWorker100.0% / 100.0%,UpdateBaker93.2% / 87.2%; the getter,tracePathFromLadderExitSetDestinationandfindQuarryPileThatIsCloseAndHasMostStone100.0% / 100.0%.UpdateQuarryWorkerandUpdateBaker100.0% / 100.0%, and so do the getter,tracePathFromLadderExitSetDestinationandfindQuarryPileThatIsCloseAndHasMostStone. Against the same build of main (502 functions) only the two units read differently: main's build doesn't have them, and the other 502 read the same.style_lint.py) and the status lines: nothing to fix automatically, no errors and 35 notes, all of the kinds below.resetTileAndClearMoat(it doesn't compile on main until Reimplement 67 Map::TileMapState functions (batch 2) #396),TransformAndRenderPercentage(on our list from before Reimplement 59 TextManager and UserTextHandler functions at 100% #509) and main'sprepareProjectileTarget.cpp(main's header declares itvoidsince d134c77 while the.cppstill returnsint; our Reimplement UnitsState::prepareProjectileTarget at 100%, from gynt's text on main (one header line each in two files) #540 changes the.cpp). This PR doesn't touch them.Against gynt's drafts
Each text was compared with gynt's as folded text (spelling, qualifiers and his local copy of the slot folded): every call with its arguments, every test and every store. UpdateQuarryWorker has the same 36 calls and 64 tests, UpdateBaker the same 55 calls and 72 tests. A BOOLEnum call's
!= 0/== FALSEwritten as a truth test and tests turned round where arms are swapped are not listed. What differs:DAT_CurrentUnitSlotID::instance; his texts keep the slot in a local read at the top, and read the global itself behind some calls.DAT_UnitHasBecomeIdleitself for the reset of the animation cycle and reads the idle local behind it (his reads the local first; nothing between the two reads writes the flag);substate > 6is>= 7andcurrentIndexInPathPlan > 7is>= 8, the constants the original compares with; states 101 and 102 have their arms the other way round.setWorkplaceBuildingEntryAsTargettest (the way home first, the removal behind it) and the bakery's destination test (found first, state 8; the removal behind it); 6, the delivery: the space test (space first), the next granary's access test (accessible first; his has the one that clears the load first), the next stockpile's access test (accessible first) and bothsetWorkplaceBuildingEntryAsTargettests (the way home first, the removal behind it). The stores that send him home stand in each arm that reaches them (states 6 and 7), where his text has them once behind the tests.Kept as they are
setgeat 0x0055140A). The style-lint bot will list it.(char)onUnit::engineerManningSiegeStateRef_checkType(UpdateBaker): the field holds the signed fade step and is abytein the header (as in Reimplement UpdateCamel, UpdateLady, UpdateMother and UpdateFireEater from gynt's units branch, under /GL (100%) #515, Reimplement UpdateChild, UpdateWheatFarmer, UpdateCrossbowman, UpdateLadderman, UpdateTunneler and UpdateFireThrower from gynt's units branch, under /GL (100%) #516, Reimplement UpdateArabianArcher and UpdateCrusaderArcher from gynt's units branch, under /GL (100%) #518 and Reimplement UpdateTanner, UpdateArmorer, UpdatePoleTurner, UpdateFletcher, UpdateBlacksmith and UpdateWoodcutter from gynt's units branch, 100% with OPENSHC_FUNCTION_VISIBILITY_UNITS on #536).(short)stores intotargetID_OR_targetBuildingID,resourceToDepositandworkers[0], as main's unit functions write them.buildingIsAccessible,canBuildingStoreTheAmount,getResourceCountThatCanBeDepositedandupdateBuildingSignpostCounterreturnint;isDisappearingUnk,goToRallyPointandkilledFlagUnkare two-byteshortfields;DAT_UnitHasBecomeIdleis anundefined4, compared with 0 as on main.102in UpdateQuarryWorker (a state main's enums have no name for), and the generic names for 7, 101, 108 and 121, whichUnitState_QuarryWorkerdoes not have. 110 and 111 (US_DISAPPEAR,US_DEATH_01) are generic in both units.UnitState_Baker, so they keep main's generic names (US_STATE_3Unk,US_RELOAD_WEAPONUnk,US_UNKNOWN_108,US_JESTER_ROAM_TO,US_UNKNOWN_121), which don't fit him: 3 is baking, 4 putting the flour into the oven and 109 the fade at the bakery door.owneror UpdateBaker'sbakeryread at its uses the code differs. Where the text reads a field again that a local already holds, the object code with the local there differs (each tried):ownerin UpdateQuarryWorker's states 1, 6, 102 and 110,workplacein states 1 and 110,bakeryin UpdateBaker's states 3 (twice), 4, 109 and 110.setDestinationForUnitsucceeds the baker is removed (0x00555D24, 0x00555D55), when it fails he goes to the bakery: the original has it, and the text has a comment there. WhensetWorkplaceBuildingEntryAsTargetfails after he took the flour, the state stays (0x00555DCD).< 0(0x00551328) and then takes one, so a load of 0 goes to -1: the original has it.setWorkplaceBuildingEntryAsTargetbehind both paths in state 6, the object code differs.field_0x58(Unit::field_0x58is ashort, the hint comes fromSoundEffectsHelperData1), casts on fields we list here, and the header change (above).Names on main these files show (follow-ups, not changed here)
UnitState_QuarryWorker: in this function 2 (USQW_AWAITING_STORE_SPACE) is picking up a stone at the pile, 3 (USQW_TAKING_GOODS_TO_STORE) walking to the stockpile, 6 (USQW_WAITING_6) taking a stone off the ox's load; 7 is the resting state (unitTypeSpecificRestingState), and 5 (USQW_RESTING) does not occur; 101 is walking to the pile or back, 102 carrying a stone to the stockpile.UnitStateUnionhas no member forUnitState_BakerShort.UnitState_Bakerhas no names for 3 (baking), 4 (putting the flour into the oven) and 109 (the fade in or out at the bakery door, behind which he goes tocachedState).Unit::field_0x410is set to 8 whenever the quarry worker leaves the pile without a stone (none left, the quarry not accessible, or no path to it) and counts down with each stone he picks up.UnitPropertiesDefinedDataby the state that reads them:field_0x4ad4(quarry worker, resting),field_0x41bc(melee),field_0x4ab0(death);field_0x5150,field_0x5160,field_0x51ec,field_0x52b4,field_0x5324,field_0x53dc(baker, idle substates 100, 101 and 106 to 109),field_0x5174(production paused).Left out
Other PRs
inlinein its own file; what that means for the DLL and the EXE is in its text.cmake/compiler-flags-gl.txt,cmake/function-visibility.txt, the status file orUnit.hppmerges with this branch exactly as it merges with main (git merge-treeagainst both): cleanly, or, for Reimpl/viewport render state #241, Entities, projectiles and fire: 17 functions, 3 at 100% #527, UI rendering and DirectDraw: 3 functions, none at 100% yet #531 and Reimplement 9 Map::Entities functions at 100% from #527 (one with visibility units), plus 1 with register allocation differences #556, with the conflict incompiler-flags-gl.txtthey already have with main. The exceptions are Reimpl/map units updatefunctions #204 (above), which also conflicts in the two units' files, and our draft Reimplement 3 UI::MenuItems functions from gynt's drafts (not yet 100%) #328, which merges cleanly with main but conflicts with this branch at the end ofcompiler-flags-gl.txt, where both add lines; we'll merge main into it once this lands.🤖 Generated with Claude Code