Repository navigation
One more Map::Units function at 100%: UpdateBatteringRam - #471
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::UpdateBatteringRam, from gynt's draft 0ab0162 (52.83%). reccmp reads 100.0, raw and normalized, in a narrower build of main 25d2e9e with this commit: the files of main's /GL list, the callees the visibility manifest names and the unit (both resolver sets on). Against main alone with main's list, the other functions read as before. cmake/compiler-flags-gl.txt gets two lines: the unit and UnitsState/deselectUnit.cpp (0x00535190, at 100% on main). The unit has to see deselectUnit's body: in the loop that sends the four engineers to work the original reads the engineer's owner through edx behind deselectUnit (0x00545F7A) and calls clearOrDeselectUnitFromSelection without loading ecx again (0x00545F85). hasUnitReachedDestination, which it also has to see, is on main's list. cmake/function-visibility.txt gets an entry for the unit with these two callees, at its address. What the code takes from the original's listing: - engineersInPlace is declared first: the original copies the owner into displayColorPlayerID through ax (0x005459FB) and clears the counter behind it (0x00545A15); declared behind the owner copies, the counter made our compiler use dx for the copy. - The loop that checks whether the AI's four engineers are back leaves by three separate tests, and the scan for engineers skips by six separate tests. The original keeps a zero in edx across both loops (made again behind the first at 0x00545BCE and on the second's back edge at 0x00545D30); written as one chain, either loop loses the match (quick_diff 0.9105 and 0.9448 against 0.9884). - The search for the capturing owner is a loop from 1 to 9 with a found flag: the original tests first, counts to 9 and returns behind the loop (0x00545E50 to 0x00545E5D). - createTribe gets the owner of units[searched], with searched the counter the scan left behind (imul ebp at 0x00545EBA); sourcehold#204's draft passes the ram's new owner. After the scan searched is maxUnitCount: most likely a bug in the original, kept for the match and marked fixme. - addUnitToTribe gets the new tribe first and the ram second, as in the original (0x00545EDA / 0x00545EDB), although it takes (unitID, tribeID): most likely a second bug of the original, marked fixme like the first. - Every access reads the unit through DAT_CurrentUnitSlotID::instance, except the state store behind stopUnitIfNextToTarget (0x00534240, not reimplemented), which goes through the copy made at the start: the original stores through esi there (0x005464D3). 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::UpdateBatteringRamis 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 withUpdateCatapult(#469),UpdateMangonel(#445) andUpdateTrebuchet(#453).Units::UpdateBatteringRam/GLOur work started from his 0ab0162 (52.83%); the two commits #204 has on the file since then are a style pass and a build fix. His later copy with other names, on his fork's
reimpl/Wilps-2026-10-18(8ca7861), already passesunits[i].ownertocreateTribe, as the original does.Measured.
Stronghold Crusader.exe(3bb0a8c1…5387ac5a), both resolver sets enabled locally (not committed), and sourcehold's reccmp with--resolve-wrapped-calls --ignore-security-cookie./GLlist (main's plus the two 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; since then main has only added files undertools/(3458fea, feat(import): update requirements and documentation of tools/import #456) and the optional function-visibility units (cmake: optional wrapper units built from function-visibility.txt #399, cmake: function-visibility.txt, which callers must see which callees' bodies #398), off by default).UpdateBatteringRamreads 100.0 raw and normalised there too, with no diff entry.deselectUnitandhasUnitReachedDestination, on the/GLlist with it, 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). Every function also reads exactly what it read in the same build of this commit's previous cut./GLlist that exist on main, seven more files at 100% on main (six callees that the visibility manifest names, among themdeselectUnit, andactivateTraderState) and the unit: 151 functions, average 99.59.UpdateBatteringRamreads 100.0% raw and normalised, with no diff entry, anddeselectUnitandhasUnitReachedDestinationread 100.0% under/GL. Main alone with the same list without the unit: 99.58 over 150, each reading the same in both builds. 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: 85.4 (the changes of the Mangonel family: one counter for the function,createTribe's owner, the search as a loop with a flag, the slot through the global), 90.6 (newOwnerof its own andmemset), 99.7 (the scan's six tests as statements) and 100.0 (engineersInPlacefirst).DAT_CurrentUnitSlotID::instance, except one store (below).createTribegets the owner ofunits[searched], withsearchedthe counter the scan for engineers left behind (imul ebp, ebp, 0x490at 0x00545EBA), as in the original; Reimpl/map units updatefunctions #204's draft passes the ram's new owner (the Wilps copy already hasunits[i].owner). After the scansearchedismaxUnitCount, 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 ram (push ecxwith the slot, thenpush eaxwith the tribe, 0x00545EDA / 0x00545EDB), 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 ram'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, as in the Catapult and One more Map::Units function at 100%: UpdateTrebuchet #453. The draft has the same order.edxacross both loops: made again right behind the first (0x00545BCE, in front of a test that does not use it) and on the second's back edge (0x00545D30, behind the jump at 0x00545D2B), and it comparesdyingwithdx(0x00545D40). As one chain, the constant 1 also moved fromecx(0x005459D6) toedi.engineersInPlaceis the function's first statement (99.7 to 100.0). The original copies the owner intodisplayColorPlayerIDthroughax(0x005459FB) and clears the counter behind it (0x00545A15); declared behind the two owner copies, the counter made our compiler usedxfor the copy. Anywhere in front of the first copy gives the same code.mov eax, ediat 0x00545EEC), and is a loop from 1 to 9 with a found flag: the original tests first, counts to 9 and returns behind the loop (0x00545E50 to 0x00545E5D).memset: the original uses a freshxor eax, eaxfor the nine stores (0x00545CF2) althoughedxholds its zero; the draft had a loop.FALSEcomparisons and the== 0onsetDestinationNearTargetedBuildingandmoveUnitToBehaviorTargetare truth tests, all+= 1are++, the loop bounds arecountof(...), and0for the unit type and the hit sound areUT_NONEandHSM_NONE, with the same code.Behaviour against the draft. One place differs from #204's draft: the owner passed to
createTribe(above). IfmaxUnitCountcan reach 2500, the length ofunits, the original reads one element past the array there (insideUnitsState, but not a unit). The draft reads the slot through its local copy where the original keeps the slot from the start inebxandesi(behindhasUnitReachedDestination,deselectUnitandstopUnitIfNextToTargettoo), and throughDAT_CurrentUnitSlotID::instancewhere the original reads it again. This code reads the global everywhere but one store. Our compiler sees that the first two callees leave the slot alone and keeps it in the same registers, so both give the original's code; as sources they would differ only if one of those callees changed the current slot. Everything else was read side by side, state by state, and behaves the same;ownLossesArrayin 0ab0162, renamed in #204 since, is today'shitsDealtToPlayerArray(the same offset, 0xA8).Lines added to
cmake/compiler-flags-gl.txtUpdateBatteringRam.cppandUnitsState/deselectUnit.cpp(0x00535190, at 100% on main).deselectUnit's body. In the loop that sends the four engineers to work the original reads the engineer's owner throughedxbehinddeselectUnit(0x00545F7A) and callsclearOrDeselectUnitFromSelectionwithout loadingecxagain (0x00545F85). quick_diff: 0.7870 withoutdeselectUnit's body, 0.9884 with it (the rest is quick_diff's own renderings: the jump over loop padding at 0x00545AFB, 0xFFFF, the stack arrays' offsets andcall edifortimeGetTime).hasUnitReachedDestination, which the unit also has to see (0.5635 without it), is on main's list already.processUnitLossStatisticmakes no difference (0.9884 without it) and is not added.deselectUnit, and in our narrower run each of the 150 other functions reads the same.cmake/function-visibility.txtgets an entry forUpdateBatteringRamwithhasUnitReachedDestinationanddeselectUnit, as the Catapult's, Trebuchet's and Mangonel's entries have, at its address (betweenUpdateLadyandUpdateJuggler).Kept as they are
Five shapes have a one-line why in the code:
engineersInPlaceis declared at the function's start (above). In the AI check's block: quick_diff 0.8274 against 0.9884; behind the owner copies it is the 99.7 code.||chain: 0.9105 against 0.9884.||chain withcontinue, or as one&&chain around the rest: 0.9448 each.searchedis declared in front of the scan, becausecreateTribereadsunits[searched]after it (thefixme:above).stopUnitIfNextToTargetgoes through the copy of the slot made at the start. The original stores throughesi, the unit's offset from the start, without reading the slot again (0x005464D3), so either its compiler saw that the callee leaves the slot alone, or its source read the slot through a copy there.stopUnitIfNextToTarget(0x00534240) is not reimplemented, so its body cannot be made visible; the copy gives the same code. Declared in the move state, in front of the call, the copy loses the match (quick_diff 0.9860 against 0.9884).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, and the larger ismax(dx, dy), as in the Catapult. A conditional expression gives the same code, but the style lint flags it.(char)on the two frame-table reads (read withmovsx) and ondisappearFadeAlphaCountdown > 32(a signed compare). The headers have these asbyte.The other CHECKs: 4 for the
dx/dydeclarations above, 2 for the two loops without their counter in the header (searched, andnewOwner, which the capture reads after its search), 1 for the manifest line (a file outsidesrc/OpenSHC), 4 placeholder names (next section), and 1 false hit onUnit::field_0x58, ashort, which the checker takes for another struct's BOOLEnum field of that name.What some placeholders hold
Unit::field_0x3bc(WilpsretargetDelayOrSiegeTile): cleared when the ram reaches its destination (in One more Map::Units function at 100%: UpdateMangonel #445 and One more Map::Units function at 100%: UpdateTrebuchet #453 the negative countdown to the next search for a target).Unit::field_0x58(WilpsfaceViewer): cleared in the unmanned state, as in the other siege units.Frames_Shared_UnitClimbingUp.field_0x83a8(WilpsanimationFrames.animBatteringRamSwing): the ram's swing frame table intoanimationFrame, indexed byanimationCycleNumber; at frame 0 the swing starts again, and frame 10 setsDAT_UnitHasBecomeIdle(WilpsDAT_UnitAnimationFinished), behind which the hit is dealt; the gate warning's time isDWORD_00ee1044(WilpsTIME_LastRamGateWarningMoment).US_FIRE_WEAPONUnk(6) unmanned,US_MELEE_ATTACK_WALLswinging at a gate or wall,US_UNKNOWN_108(108) standing still (speed 0, frame offset 1).US_JESTER_ROAM_TO, WilpsUS_FADE_TRANSITION) fades them into the ram:disappearFadeAlphaCountdown(WilpsfadeLevel) from 0 in steps ofengineerManningSiegeStateRef_checkType(WilpsfadeAlphaStep, 2 here), then the state incachedState(WilpsstateAfterFade, 5 here).Proposed, not changed here
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::disappearFadeAlphaCountdownand the AnimationFrameData frame tables. All three casts could go.Other PRs
UpdateBatteringRam.cppand one more status hunk, at 0x005459B0 (100.0% here against his 52.8%). 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/BuildingsState #234, Reimpl/units state #238, Reimpl/viewport render state #241, reimplement OpenSHC::Text::TextManager and OpenSHC::Text::UserTextHandler #265, Reimplement 3 UI::MenuItems functions from gynt's drafts (not yet 100%) #328 and Reimpl/TileMapState 100% batch 2 #396 conflict there too, but they already conflict with main). 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, One more Map::Units function at 100%: UpdateTrebuchet #453 and One more Map::Units function at 100%: UpdateCatapult #469 add thedeselectUnit.cppline too; listed twice, it does no harm. Every other open PR merges with this one exactly as with main,cmake/function-visibility.txtincluded.🤖 Generated with Claude Code