Repository navigation
Reimplement UpdateBrewer from gynt's units branch (100% with OPENSHC_FUNCTION_VISIBILITY_UNITS on) - #562
Open
kotijekriv wants to merge 2 commits into
Open
Reimplement UpdateBrewer from gynt's units branch (100% with OPENSHC_FUNCTION_VISIBILITY_UNITS on)#562kotijekriv wants to merge 2 commits into
kotijekriv wants to merge 2 commits into
Conversation
…N_VISIBILITY_UNITS on Units::UpdateBrewer, from Gynt's draft on sourcehold's reimpl/map-units-updatefunctions (his draft PR 204; his commits on the file: 3062b29 at 55.52%, 284b976 at 62.38%, 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 text has 60 calls and 68 tests where the draft has 57 and 64, because the sound call and its test stand in each of the four substate arms (+3 each) and the ternary is an if (+1); otherwise the calls have the same arguments, and the 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. - State 1, sweeping: the sound test (animationFrame == 2 and animationCycleNumberHasJustIncremented, then playSFXAtLocation with FX_BROOM) stands at the end of each of the four substate arms, where the draft has it once after them. The four copies fold back into one, but with the test once after the arms the 2 of `animationSpeed = 2` is kept in ecx for the compare (`mov ecx, 2` ... `cmp eax, ecx`); the original stores and compares two immediates (0x0055667B, 0x005566E1). quick_diff with the entry's callees in front reads 0.9846 with the test after the arms and 0.9988 with it in each arm (the rest is spelling). - State 1: the next substate (105 after 104, else 102) is an else if / else where the draft has a ternary; the object code is the same. - Any other state (back to state 1, the walk stopped) is the else of the death-state test (checkIfCitizenUnitIsAliveBasedOnState, which returns TRUE for the death states), where the draft puts it after that test, whose branch returns; with the draft's form the object code differs (the unit with the entry's callees in front). - Arms the other way round than in the draft, by state: 2, taking hops (no hops left at the stockpile first: the next stockpile, the way home or the removal; the take after it); 4, walking to the brewery (a destination set first, the exit to disappearing after it); 8, carrying ale (space in the stockpile first; the other stockpile reachable first; at the end, the next hops stockpile reachable first). Each was measured: with the draft's order the object code differs (in the last one only with the entry's callees in front), and a comment above each test says so. Text pass, the same object code before and after (the unit alone and with its entry's callees in front, compiled without /GL, as for PR 561's units): states by UnitState's names (there is no UnitState_Brewer; the resting state 1 as US_IDLEUnk), DNE_UNKNOWN_2, 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, back to his blocks that return, one per state, the ternary as an else if / else, comments on what states 109, 110, 111, 121 and the other death states do, and whys above the sound tests, the swapped tests and the death-state test. Measured with real builds (bundled MSVC1400-SP1, function and data resolvers on locally, reccmp raw / normalised): small builds on main 87e40b6, before this branch was rebased (490 files, 503 functions: every /GL file, the unit, every .cpp that names getBuildingResourceAmountByUid, findQuarryPileThatIsCloseAndHasMostStone, 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.0 / 85.5. On c5de30d (PR 561's UpdateQuarryWorker and UpdateBaker on main), the same list with those two, option on: UpdateBrewer, UpdateQuarryWorker and UpdateBaker 100.0 / 100.0. The branch is now on e3e4265, which adds PR 548 (one Credits .cpp and its status line). The status line carries the default build's raw number. Our earlier text, with the sound test once after the arms, read 98.5 / 82.8 on and 91.4 / 84.2 off in small builds of the same list. 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>
UpdateBrewer needs the bodies of the callees below in the unit it is compiled with: the nine it calls, and setupUnitSharingCurrentTilePosition and setupUnitSharingTileIDs, which it reaches through commitUnitLocation (commitUnitLocation -> setupUnitSharingCurrentTilePosition -> setupUnitSharingTileIDs). The entry names them at the unit's address, the callees in address order. Every name is already a member of the group that holds hasUnitReachedDestination, so the unit joins that group and no other function sees a body it did not see before or loses one. The generator makes 25 wrapper units holding 175 source files (main e3e4265: 25 units, 174 files; on 87e40b6: 172 on the branch, 171 on main): the unit is the only new member. 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 immediate prints as 0xff on the original's side). - UpdateBrewer: 0.6297 alone, 0.9988 with the 11 listed. Left out, getBuildingResourceAmountByUid 0.9690; setupUnitSharingTileIDs 0.9963; IncrementAndOptionalUpdateAVValueRelated 0.8912; ConsiderHavingABreakNowUnk 0.9772; SetStateToFreetimeWalking 0.9534; ComputeGoodsProduced 0.9661; checkIfCitizenUnitIsAliveBasedOnState 0.9594; hasUnitReachedDestination 0.9289; setupUnitSharingCurrentTilePosition 0.9963; UpdateWorker_ConsiderTakingABreakUnk 0.9932; commitUnitLocation 0.9963. Not named, leaving it out changes nothing: makeUnitStopWalkingByClearingPathProgressState. Real builds: the small builds of the unit commit. With the option on the unit reads 100.0 / 100.0. Against main 87e40b6's build of the same list nothing else reads differently; on c5de30d the unit, UpdateQuarryWorker and UpdateBaker read 100.0 / 100.0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
The last of the twelve units on gynt's units branch
reimpl/map-units-updatefunctions(his draft #204) that callBuildingsState::getBuildingResourceAmountByUid, which main definesinlinesince #536; main has the other eleven (six from #536, two from #561, and UpdateEngineer, UpdateInnkeeper and UpdateMiller from #514, #393 and #533). The branch is on main 33cdd1f. UpdateBrewer reads 100.0% raw and normalised with main's function-visibility option on, and 93.0% / 85.5% in the default build (see the table). It gets an entry incmake/function-visibility.txt. The 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 commit keeps that co-author line.Units::UpdateBrewer"Before" is gynt's own status number on the file (main's status file has 0.0%, Pending). The default build's numbers are raw / normalised. The 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 (and #561's UpdateBaker).The sweeping state
In state 1 (sweeping the brewery) the unit stores
animationSpeed = 2, picks the frame from one of four tables by substate, and plays the broom sound when the frame is 2 and the cycle has just moved on. The original stores the 2 and compares with 2 as two immediates (0x0055667B, 0x005566E1), with the cycle number in ecx for the table reads. With the sound test once after the four arms, as in the draft, the 2 is kept in ecx for the compare (mov ecx, 2...cmp eax, ecx), the cycle number moves to edx, the sound call's two pushes change places, and further on the owner's push for the next stockpile changes register: 98.5% / 82.8% with the option on, 0.9846 inquick_diff. With the test written at the end of each arm, the four copies fold back into one and the 2 stays an immediate: 100.0%, 0.9988 (the rest is spelling). A comment above the arms says so.Tried first and not it: the field types (both
int; ashortorunsignedstore or compare shares the 2 all the same), the other uses of 2 in the function (changing any of them leaves the register), the 2 through a local, and the frame test as a one-caseswitch(the 2 goes, but the frame is read again from memory).The entries
#includes its members (without/GL), and the members leave the/GLlist. The entry names the nine callees UpdateBrewer calls, andsetupUnitSharingCurrentTilePositionandsetupUnitSharingTileIDs, which it reaches throughcommitUnitLocation(commitUnitLocation->setupUnitSharingCurrentTilePosition->setupUnitSharingTileIDs). Every name of the entry is already a member of the group that holds hasUnitReachedDestination (as are Reimplement UpdateQuarryWorker and UpdateBaker from gynt's units branch (100%, one with OPENSHC_FUNCTION_VISIBILITY_UNITS on) #561's UpdateQuarryWorker and UpdateBaker): the unit joins it, and no other function sees a body it did not see before or loses one.cmake/function-visibility-units.pymakes 25 wrapper units holding 175 source files on this branch (main e3e4265: 25 units, 174 files; on 87e40b6: 172 on the branch, 171 on main): the unit is the only new member.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 immediate prints as 0xff 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 small builds below are of main 87e40b6 and of this branch on it, and the last one of this branch on c5de30d; the branch was then rebased onto e3e4265 and 33cdd1f. Between 87e40b6 and c5de30d main took #561 (UpdateQuarryWorker, UpdateBaker andUnit::field_0x410aschar), gynt's #551 (three GameStateStructures functions) and hisreccmp/float-literals.csv, which pairs the original's float constants and CRT helpers; UpdateBrewer has no float constant and calls no CRT helper. e3e4265 adds #548: one Credits.cppand its status line, nothing incmake/, so the counts above hold; 3b9e506 and 33cdd1f are gynt's header syncs for #559 (PlayerData::foodTypeToBeEatenNexttyped as the newFoodTypeEnumInt, which no.cppnames), and 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,115 files on the branch and 3,114 on main, BUILD_OK, 3,133 and 3,132 functions compared. Main doesn't haveUpdateBrewer, and here it reads 93.0% / 85.5%.handleMenuItemsandConstructor_Menuread 97.9% / 91.4% and 98.4% / 95.2% in main's build and 100.0% / 100.0% in the branch's: they go between these readings from one build to another with their files unchanged (in Reimplement UpdateQuarryWorker and UpdateBaker from gynt's units branch (100%, one with OPENSHC_FUNCTION_VISIBILITY_UNITS on) #561's full builds they read 100.0% in both). The other 3,130 read the same./GLfile, every.cppthat namesgetBuildingResourceAmountByUid,findQuarryPileThatIsCloseAndHasMostStone.cpp, 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, with this unit added; its callees and its group add no other file): 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.UpdateBrewer93.0% / 85.5%, the getter 100.0% / 100.0%.UpdateBrewerand the getter 100.0% / 100.0%. Against the same build of main (502 functions) onlyUpdateBrewerreads differently: main's build doesn't have it, and the other 502 read the same.UpdateBrewerreads differently in either mode.UpdateBrewer,UpdateQuarryWorkerandUpdateBaker100.0% / 100.0%. Against this branch's option-on build on 87e40b6 onlyplaySFXAtLocationreads differently, besides the two units new on main: 98.1% / 100.0% there, 100.0% / 100.0% here. It calls__CIsqrtand__ftol2_sse, which main's newfloat-literals.csvpairs, and its file did not change./GLas for Reimplement UpdateQuarryWorker and UpdateBaker from gynt's units branch (100%, one with OPENSHC_FUNCTION_VISIBILITY_UNITS on) #561's units: the same. The builds above are of texts with the same object code: the option-on ones and the full builds of this text before its last edits (the substate'selse if, comments), the small option-off one before the earlier ones too (one else-if chain, a ternary). The commit lists its edits.style_lint.py) and the status lines: nothing to fix automatically, no errors and 15 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 draft
The 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. UpdateBrewer has 60 calls and 68 tests where his text has 57 and 64: the sound call and its test stand in each of the four substate arms (+3 each, above), and his ternary is an
if(+1). Otherwise the calls and tests are the same. 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 text keeps the slot in a local read at the top.else if/elsewhere his text has a ternary (the same object code).elseof the death-state test (checkIfCitizenUnitIsAliveBasedOnState, which returns TRUE for the death states; its branch plays the death frames); his text has it after that test, whose branch returns, and then the object code differs (the unit with the entry's callees in front). A comment there says so.Kept as they are
(char)onUnit::engineerManningSiegeStateRef_checkType(state 109): 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, Reimplement UpdateTanner, UpdateArmorer, UpdatePoleTurner, UpdateFletcher, UpdateBlacksmith and UpdateWoodcutter from gynt's units branch, 100% with OPENSHC_FUNCTION_VISIBILITY_UNITS on #536 and Reimplement UpdateQuarryWorker and UpdateBaker from gynt's units branch (100%, one with OPENSHC_FUNCTION_VISIBILITY_UNITS on) #561).(short)stores intotargetID_OR_targetBuildingID,resourceToDepositandworkers[0], as main's unit functions write them.BOOLEnumfieldanimationCycleNumberHasJustIncrementedtested by truthiness, the rest compared with 0:buildingIsAccessible,canBuildingStoreTheAmount,getBuildingResourceAmountByUidandupdateBuildingSignpostCounterreturnint;isDisappearingUnkandgoToRallyPointare two-byteshortfields;DAT_UnitHasBecomeIdleis anundefined4, compared with 0 as on main.UnitState_Brewer, so every state keeps main's generic name (US_STATE_2Unk,US_STATE_3Unk,US_RELOAD_WEAPONUnk,US_AIM_WEAPONUnk,US_FIRE_WEAPONUnk,US_LOOK_AROUNDUnk,US_STAND_UPUnk,US_UNKNOWN_108,US_JESTER_ROAM_TO,US_UNKNOWN_121), which don't fit him. A comment in each state says what it does, but in 108: it setsstateBasedSpeedandfield_0x30_animRelatedto 0 andanimationSheetFrameOffsetto 1, and what it is for is not known.field_0x58(Unit::field_0x58is ashort, the hint comes fromSoundEffectsHelperData1), the two casts above ((short)on the slot forworkers[0],(char)on the fade step), and fields tested both by truthiness and against 0 (animationCycleNumberHasJustIncrementedis aBOOLEnum,isDisappearingUnkandgoToRallyPointareshorts).Names on main this file shows (follow-ups, not changed here)
UnitStateUnionhas no member for the brewer and there is noUnitState_Brewer. In this function 1 is sweeping the brewery, 2 taking hops from the stockpile, 3 bringing them to the brewery, 4 walking to the brewery, 5 starting a batch of ale, 6 brewing, 7 leaving the brewery with ale, 8 carrying it to the stockpile, 109 the fade in or out at the brewery door (after which he goes tocachedState), 110 fading out before the removal, 111 and the other death states dying, 121 resting; what 108 does is not known.field_0x58b4,field_0x590c,field_0x5954andfield_0x59c4(brewer, sweeping, substates 102, 103, 104 and the rest). They areAnimationFrameDatamembers, reached throughUnitPropertiesDefinedData::Frames_Shared_UnitClimbingUp, a name that doesn't fit them.UnitsState::checkIfCitizenUnitIsAliveBasedOnStatereturns TRUE for the death states (US_DEATH_01toUS_STONE_DEATH_03), the opposite of what its name says.Unit::engineerManningSiegeStateRef_checkTypeholds a signed fade step (here 2 and -2, read with(char)): acharin the header would drop the casts here and 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, Reimplement UpdateTanner, UpdateArmorer, UpdatePoleTurner, UpdateFletcher, UpdateBlacksmith and UpdateWoodcutter from gynt's units branch, 100% with OPENSHC_FUNCTION_VISIBILITY_UNITS on #536 and Reimplement UpdateQuarryWorker and UpdateBaker from gynt's units branch (100%, one with OPENSHC_FUNCTION_VISIBILITY_UNITS on) #561's units.Other PRs
cmake/compiler-flags-gl.txt,cmake/function-visibility.txtor the status file merges with this branch exactly as it merges with main 33cdd1f (git merge-treeagainst both): cleanly, or, for Reimpl/viewport render state #241, Reimpl/GameStateStructures development #243, 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 conflicts they already have with main. The exceptions are Reimpl/map units updatefunctions #204 (above), which also conflicts inUpdateBrewer.cpp, 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.inlinein its own file; what that means for the DLL and the EXE is in its text.🤖 Generated with Claude Code