Repository navigation
One more Map::Units function at 100%: UpdateCatapult - #469
Open
kotijekriv wants to merge 1 commit into
Open
kotijekriv wants to merge 1 commit into
kotijekriv wants to merge 1 commit into
Conversation
Units::UpdateCatapult, from gynt's draft efbb0df (44.97%). reccmp reads 100.0, raw and normalized, in a narrower build of main 812d149 with this commit: the files of main's /GL list, the callees the visibility manifest names, activateTraderState, isAIPlayer.cpp and the unit (142 files, 152 functions, both resolver sets on). Against main alone with main's list, the other 150 functions read as before. cmake/compiler-flags-gl.txt gets three lines: the unit, UnitsState/deselectUnit.cpp (0x00535190) and GameSynchronyState/isAIPlayer.cpp (0x004010B0), both at 100% on main. The unit has to see both bodies: behind deselectUnit (0x00568884) the original pushes the slot from edx and calls clearOrDeselectUnitFromSelection without loading ecx again, and behind isAIPlayer (0x00569025, 0x005690EB) it pushes the slot from ebx without reading it again. cmake/function-visibility.txt gets the isAIPlayer edge for the unit. What the code takes from the original's listing: - createTribe gets the owner of units[searched], with searched the counter the search for engineers left behind (0x005688CB); the draft passed the catapult's new owner. - addUnitToTribe gets the new tribe first and the catapult second, as in the original (0x005688EB/EC), although it takes (unitID, tribeID): most likely a second bug of the original, marked fixme like the first. - The moving state stores speed -1 only for a delay above 70 (jle at 0x005693A9); the draft had it from 70 on. - The loop that checks whether the AI's two engineers are back leaves by three separate tests. The original keeps a zero in edx across that loop (0x00568554, made again at 0x00568564 and 0x00568631); as one || chain our compiler made the zero only behind the loop. - The block that sends the two engineers to work is one loop: the original computes the unit's offset anew at its start (0x0056863E), the start of a loop the compiler unrolled. - The distance test to the target has its differences written out; as dx and dy locals they take the registers the original gives the targets. 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>
This was referenced Nov 22, 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.
One more function at 100%, with no header changes.
Units::UpdateCatapultis a Map::Units function from gynt's units branchreimpl/map-units-updatefunctions(his draft #204), and the commit credits him as co-author. It shares most of its code withUpdateMangonel(#445) andUpdateTrebuchet(#453).Units::UpdateCatapult/GLOur work started from his efbb0df (44.97%); the two commits #204 has on the file since then are a style pass and a build fix.
Measured.
Stronghold Crusader.exe(3bb0a8c1…5387ac5a), both resolver sets enabled locally (not committed), and sourcehold's reccmp with--resolve-wrapped-calls --ignore-security-cookie.else { if }now writtenelse if, and one bound now writtencountof(crewCount); quick_diff gives the same listing line for line), with both resolver sets on and the branch's own/GLlist (main's plus the three lines this commit adds), and with 0x004314E0 (theMapEditorLandscaping_GeneralButtonshandler) left out and its resolver off, as in main's baseline: 0 failed of 2,424 compile steps, 99.58 over 2,440 functions, against 99.58 over 2,439 for main alone (built at f489b72; 3458fea only adds files undertools/, and cmake: optional wrapper units built from function-visibility.txt #399 and cmake: function-visibility.txt, which callers must see which callees' bodies #398 add the optional function-visibility units, off by default).UpdateCatapultreads 100.0 raw and normalised there too, with no diff entry.deselectUnitandisAIPlayer, now on the/GLlist, read 100.0 raw and normalised as they do on main. No main function reads differently: every one reads exactly what it read before (unrounded 99.5761 against 99.5759 raw, 99.5494 against 99.5492 normalised; 2,323 against 2,322 functions at 100.0 raw)./GLlist that exist on main, seven more files at 100% on main (six callees that the visibility manifest names, andactivateTraderState),isAIPlayer.cppand the unit: 152 functions, average 99.59.UpdateCatapultreads 100.0% raw and normalised, with no diff entry, anddeselectUnitandisAIPlayerread 100.0% under/GL. Main alone, the same list withoutisAIPlayer.cppand the unit: 99.58 over 150, each reading the same in both builds (main's sources and/GLlist; its tree differed only in afunction-visibility.txtline the default build does not read). That run was of this commit.What got it to 100%
The draft's statements are nearly all still there; what changed is their arrangement and what the compiler can see. On our dev branch (not public), reccmp raw under
/GL: 76.6, 86.6 (every access through the slot global,isAIPlayer's body visible), 86.8 (the height sums), 87.5, 94.2, 96.5 (the distance test) and 100.0 (the check loop's three tests).DAT_CurrentUnitSlotID::instance; the draft's local copy of the slot is gone.createTribegets the owner ofunits[searched], withsearchedthe counter the search for engineers left behind (imul ebx, ebx, 0x490at 0x005688CB), as in the original; the draft passed the catapult's new owner. After the searchsearchedismaxUnitCount, so the tribe gets the owner of the slot past the last unit: most likely a bug in the original, kept for the match and markedfixme:in the code, as in One more Map::Units function at 100%: UpdateTrebuchet #453.addUnitToTribegets its arguments the other way round from its parameters and from every caller on main: the new tribe, then the catapult (push edxwith the slot, thenpush eaxwith the tribe, 0x005688EB / 0x005688EC), where its body takes the unit first and the tribe second. So the original adds the unit whose id is the new tribe's to the tribe whose id is the catapult's slot, and a slot of 1250 or more indexes pasttribes[1250]: most likely a bug as well, kept for the match and markedfixme:in the code. The draft has the same order, and so has One more Map::Units function at 100%: UpdateTrebuchet #453.jleat 0x005693A9). The draft had it from 70 on.edxacross that loop: made in front of it (0x00568554), again on its back edge (0x00568564) and again behind it (0x00568631), where the first test's exit jumps one instruction further (to 0x00568633) becauseedxstill holds it. Written as one||chain with onebreak, our compiler made the zero only inside that block.esiholds it, the start of a loop the compiler unrolled, as in One more Map::Units function at 100%: UpdateMangonel #445 and One more Map::Units function at 100%: UpdateTrebuchet #453.dxanddylocals they took the scratch registers the original gives the two targets (ecx,edx).field_0x3bcis written in each arm of the test on whether the owner is an AI, where the draft had one store behind the test.buildingHeightfirst (0x00568597, 0x00568792); written in that order, as the draft had it, our compiler loads the terrain heights first.PathFindingState::field_0x9cbetween the path searches are<= 2(2 inesi;cmp [field], esiat 0x00568A96 and three more, each withjg); the 16-tick test is((fixedRng ^ ticks ^ 8) & 15) != 0(xor eax, -8; test al, 15at 0x005686D3); the frame offset of the moving state is stored in each of its three arms; the building's half size is a signed division.Behaviour against the draft. Two places differ, both listed above: the owner passed to
createTribe, and the delay of exactly 70 in the moving state (the draft stored speed -1 and clearedfield_0x30_animRelated; the original stores speed 0 and leaves it at 21). A third differs only in theory: the half size is a signed division, as in the original (cdq; sub; sarat 0x00568CC0), where the draft's is unsigned; the two differ only for a width of 2^31 or more. Everything else was read side by side, state by state, and behaves the same, theaddUnitToTribeorder included. The draft'scounter(andownLossesArrayin efbb0df) are today'savailableCowsandhitsDealtToPlayerArray(the same offsets, 0x2278 and 0xA8).Lines added to
cmake/compiler-flags-gl.txtUpdateCatapult.cpp,UnitsState/deselectUnit.cpp(0x00535190) andGameSynchronyState/isAIPlayer.cpp(0x004010B0), both at 100% on main.deselectUnitat 0x00568884 the original pushes the slot fromedx(0x00568892), which it loaded in front of that call, and callsclearOrDeselectUnitFromSelectionwithout loadingecxagain (0x00568894). BehindisAIPlayer(0x00569025, 0x005690EB) it pushes the slot fromebxfor the next call without reading it again; behindTryAcquireAmmunitionOrPlanToBuyStone, which it cannot see, it reads it again (0x00569039, 0x005690FB). quick_diff: 0.9456 withoutdeselectUnit's body, 0.9775 withoutisAIPlayer's, 0.9970 with both.hasUnitReachedDestination, the third callee the unit has to see, is on main's list already.processUnitLossStatisticmakes no difference to it (0.9970 without it) and is not added.isAIPlayer's one other caller on main,BuildingsState::updateLordLadyJesterAndGhostUnits, is off the list, so it never sees the body, and nothing on main callsdeselectUnit. In our narrower run each of the 150 other functions reads the same.cmake/function-visibility.txtgets one line: theisAIPlayeredge forUpdateCatapult, next to the two edges it has.Kept as they are
Six shapes have a one-line why in the code:
engineersInPlaceis declared at the function's start, although only the unmanned state uses it: the original clears it at 0x00568372, in front of the state tests, as in One more Map::Units function at 100%: UpdateMangonel #445 and One more Map::Units function at 100%: UpdateTrebuchet #453. In its block: quick_diff 0.9950 against 0.9970.||chain: 0.9820 against 0.9980.shootProjectilecall (0x0056912C) for that arm's paths.searchedis declared in front of the search for engineers, becausecreateTribereadsunits[searched]after it.And without a comment:
dxanddyare declared without a value and set in both arms of an if / else, a pair in each of the two engineer loops. A conditional expression gives the same code, but the style lint flags it. The larger of the two ismax(dx, dy)(windef.h's macro, as main uses it).DAT_TileMapState::instance.SEC_PathfindingCostTileMap1105[player][tile](0x01EE2998), as main reads it infindBestAttackTileByPathCost; the draft read the address.(char)on the four frame-table reads (read withmovsx), onfield_0x3c5copied intotargetingType(movsx dx, alat 0x00568441), and ondisappearFadeAlphaCountdown > 32(a signed compare);(int)onBuilding::widthOrHeight(a signed halving). The headers have these asbyteanduint.The other CHECKs: 4 for the
dx/dydeclarations above, 2 forsearchedand the endless loop's header, 1 for the endless loop, 1 for the manifest line (a file outsidesrc/OpenSHC), 36 placeholder names (next section), and 3 false hits onUnit::field_0x58, ashort, which the checker takes for another struct's BOOLEnum field of that name.What some placeholders hold
Unit::field_0x3bc: the negative countdown to the next search for a target, as in One more Map::Units function at 100%: UpdateMangonel #445 and One more Map::Units function at 100%: UpdateTrebuchet #453 (-40 or -80 here).Unit::field_0x3c5: an instruction type waiting to be taken over: copied intotargetingTypewhen it holdsUIT_ATTACK_LANDorUIT_THROW_COW, and set toUIT_NO_INSTRUCTION_OR_MOVEUnkafter a cow is thrown.Unit::field_0x3b0: set while a diseased cow is to be thrown (also when the AI decides on one throughAICState::yieldCowThrow), and cleared after the shot.Unit::field_0xd2: counted against 5 next tofriendlyFireCounterUnk; an AI catapult above either limit moves somewhere else (state 9).PathFindingState::field_0x9c: read after eachpathFindingRelatedcall; while it is 2 or less the next search runs, with 5, 10, 20, 60 and 120 as the first argument.Frames_Shared_UnitClimbingUp.field_0x1784,.field_0x17ac(loading) and.field_0x17d4,.field_0x17fc(firing): the catapult's frame tables intoanimationFrameandimageIDUnk, indexed byanimationCycleNumber.US_FIRE_WEAPONUnk(6) unmanned,US_STAND_UPUnk(8) aiming,US_STATE_2Unk(2) loading,US_RELOAD_WEAPONUnk(4) firing,US_STATE_9Unk(9) an AI catapult moving towards the enemy.Proposed, not changed here
Building::widthOrHeightasint, as in One more Map::Units function at 100%: UpdateMangonel #445 and One more Map::Units function at 100%: UpdateTrebuchet #453.charfor byte fields read as signed, 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:Unit::disappearFadeAlphaCountdown,Unit::field_0x3c5and the AnimationFrameData frame tables. Six of the seven casts could go.Other PRs
UpdateCatapult.cppand one more status hunk, at 0x00568320 (100.0% here against his 45.0%). Once this lands, his branch can take main's version.cmake/compiler-flags-gl.txt, so whichever goes in second gets a small conflict there: keep the lines of both (Reimpl/TileMapState 100% batch 2 #396 conflicts there too, but it already conflicts with main). Map::Units::UpdateLion at 100% #425, Reimplement 47 UnitsState functions at 100% and restyle 28 more #378, Reimplement 20 BuildingsState functions at 100% #377, Reimplement 88 Map::TileMapState functions at 100% #366 and Reimplement the remaining Map::Buildings Update* functions #297 merge cleanly. Reimplement 47 UnitsState functions at 100% and restyle 28 more #378, One more Map::Units function at 100%: UpdateMangonel #445, One more Map::Units function at 100%: UpdateBallista #451, One more Map::Units function at 100%: UpdateFireBallista #452 and One more Map::Units function at 100%: UpdateTrebuchet #453 add thedeselectUnit.cppline too, and Five more functions at 100%: InGameMenu MainButtons, Roundtable handler, BuySell, UpdateGhost and UpdateHopsFarmer #416 (forMenuItemActionHandler_Roundtable_Main) and One more Map::Units function at 100%: UpdateTrebuchet #453 addisAIPlayer.cpp; listed twice, each does no harm.cmake/function-visibility.txthas the trebuchet'sisAIPlayeredge already; this PR adds the catapult's.🤖 Generated with Claude Code