Repository navigation
One more Map::Units function at 100%: UpdateTrebuchet - #453
Open
kotijekriv wants to merge 3 commits into
Open
kotijekriv wants to merge 3 commits into
kotijekriv wants to merge 3 commits into
Conversation
Units::UpdateTrebuchet, from gynt's draft 7a7639c (42.59%). reccmp reads 100.0, raw and normalized, in a narrower build of main 3458fea with this commit: the files of main's /GL list, the callees sourcehold#398's visibility manifest names, 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 its calls to them (0x00569A25, 0x0056A05B, 0x0056A124) the original passes the slot from ebx to the next call without reading it again. No other file on the /GL list calls either. What the code takes from the original's listing: - createTribe gets the owner of units[i], with i the counter the search for engineers left behind (0x00569A71). - The block that sends the three engineers to work is one loop: the original computes the unit's offset anew at its start (0x005697BA), 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. - One dx / dy pair serves both engineer loops. With a pair per loop the search for engineers loses its match once the target block has no pair of its own. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- field_0x3c5 is compared with UIT_ATTACK_LAND and UIT_THROW_COW and set to UIT_NO_INSTRUCTION_OR_MOVEUnk. - harassBuildingsWithSiegeAI's result is tested by truthiness. - The comment on createTribe's argument is a fixme: the original passes units[i].owner with i = maxUnitCount. - `--` for the four `-= 1`, and `++` for eight of the eleven `+= 1`. The three counters of state 6 keep `+= 1`, with a comment: with them as `++` too, the search for engineers gets other registers. - const on ownX and ownY. - The search's counter is `searched`, initialised where it is declared (it no longer shares its name with the crew loop's i), and present is engineersInPlace, as in UpdateMangonel. The function's /FA listing is the same as at 6757ed1, apart from the two renamed locals' names. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 21, 2026
…hanged Two comments, no code line changes; quick_diff gives the same listing line for line. - addUnitToTribe takes (unitID, tribeID): its body multiplies the first by the unit size and the second by the tribe size, and every caller on main passes them so. The original passes the new tribe first and the trebuchet's slot second (push ecx with the slot, then push eax with createTribe's result, 0x00569A91 / 0x00569A92). That is most likely a bug in the original, next to the createTribe one; it is kept for the match and now marked fixme. - The capture search's comment said its two exit tests are in the original's order; our source tests the bound first and the compiler turns it into the original's loop, so the comment says that now. Co-authored-by: Gynt <gynt@users.noreply.github.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::UpdateTrebuchetis a Map::Units function from gynt's units branchreimpl/map-units-updatefunctions(his draft #204), and both commits credit him as co-author. It shares most of its code withUpdateMangonel(#445) andUpdateCatapult(a draft in #204).Units::UpdateTrebuchet/GLMeasured.
Stronghold Crusader.exe(3bb0a8c1…5387ac5a), both resolver sets enabled locally (not committed), and sourcehold's reccmp with--resolve-wrapped-calls --ignore-security-cookie./GLlines, and 0x004314E0 (theMapEditorLandscaping_GeneralButtonshandler) left out with 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/).UpdateTrebuchetreads 100.0 raw and normalised there too, with no diff entry, anddeselectUnitandisAIPlayerread 100.0 raw and normalised under/GL. Every main function reads exactly what it read before (unrounded 99.5761 against 99.5759), includingisAIPlayer's one caller on main,BuildingsState::updateLordLadyJesterAndGhostUnits, which is not on the/GLlist (100.0 in both builds). The second commit holds the review fixes; the function's compiler listing is the same line for line./GLlist that exist on main, seven more files at 100% on main (six callees that cmake: function-visibility.txt, which callers must see which callees' bodies #398's manifest names, andactivateTraderState),isAIPlayer.cppand the unit: 152 functions, average 99.59.UpdateTrebuchetreads 100.0% raw and normalised, with no diff entry, anddeselectUnitandisAIPlayerread 100.0% under/GL. Main alone with the same list withoutisAIPlayer.cppand the unit: 99.58 over 150, each reading the same in both builds.openshc-pr-fixfinds nothing to change (on the first commit), andopenshc-pr-checkgives 0 ERROR and 48 CHECK on the branch (explained below).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.8, 80.9 (isAIPlayer's body visible), 82.7, 84.6, 85.2, 97.6 and 100.0.DAT_CurrentUnitSlotID::instancewhere the original reads the slot again, and through theunitIDcopy where it keeps the slot in a register (settled by measuring).createTribegets the owner ofunits[i], withithe counter the search for engineers left behind (imul ebp, ebp, 0x490at 0x00569A71), as in the original; the draft passed the trebuchet's new owner. After the searchiismaxUnitCount, 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. The search for the capturing owner has a variable of its own, copied to the crew owner at the end of the capture (mov eax, ediat 0x00569AA3).addUnitToTribegets its arguments the other way round from its parameters and from every caller on main: the new tribe, then the trebuchet (push ecxwith the slot, thenpush eaxwithcreateTribe's result, 0x00569A91 / 0x00569A92).addUnitToTribetakes(unitID, tribeID): its body multiplies the first by the unit size and the second by the tribe size. So the original adds the unit whose id is the new tribe's to the tribe whose id is the trebuchet's slot, and a slot of 1250 or more indexes pasttribes[1250]: most likely a bug as well, kept for the match and now markedfixme:in the code. The draft has the same order.esiholds it, the start of a loop the compiler unrolled; its second and third copy have the stores in the source's order.buildingHeightfirst (0x00569715, 0x00569923); written in that order, as the draft had it, our compiler loads the terrain heights first.dxanddylocals, each used twice, they were served registers before the two targets and took the scratch registers the original gives the targets (ecx,edx).dx/dypair for the whole function, used by both engineer loops. Without the target block's pair, the loop that searches engineers lost its match (the other engineer's x went toedxinstead ofedi, and the subtraction stayed in each arm), and no form of that block, nor a shift of the translation unit's symbol count, brought it back. One pair for the whole function does, so the original's source most likely declared them once.Lines added to
cmake/compiler-flags-gl.txtUpdateTrebuchet.cpp,UnitsState/deselectUnit.cpp(0x00535190) andGameSynchronyState/isAIPlayer.cpp(0x004010B0), both at 100% on main.deselectUnitat 0x00569B25 the original still usesedx(0x00569B2A) and callsclearOrDeselectUnitFromSelectionwithout loadingecxagain (0x00569B35). BehindisAIPlayer(0x0056A05B, 0x0056A124) it pushes the slot fromebxfor the next call without reading it again; behindTryAcquireAmmunitionOrPlanToBuyStone, which it cannot see, it reads it again (0x0056A06F). quick_diff: 0.7925 withoutdeselectUnit's body, 0.9132 withoutisAIPlayer's, 0.9818 with both (the rest is one jump over loop padding at 0x0056A35B and the renderings of 0x80000007).hasUnitReachedDestination, the third callee the unit has to see, is on main's list already.processUnitLossStatisticmakes no difference to it (0.9818 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.UpdateTrebuchetwithhasUnitReachedDestinationanddeselectUnit; theisAIPlayeredge will be added there.Kept as they are
Seven 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 0x00569465, in front of the state tests, as in One more Map::Units function at 100%: UpdateMangonel #445. In its block: quick_diff 0.9501.dxanddyare declared at the start without a value (above).shootProjectilecall (0x0056A164) for its paths.+= 1. The other eight+= 1are++and the four-= 1are--, all with the same code; with these three as++too the search for engineers gets other registers (0.9709).searchedis declared in front of the search for engineers, becausecreateTribereadsunits[searched]after it.And without a comment:
dxanddyismax(dx, dy)(windef.h's macro, as main uses it), which is the same expression as the draft's ternary. A local of its own for it, or writing it intodyordx, loses the match (0.9709, 0.8086, 0.8023).(char)on the six frame-table reads (read withmovsx), onfield_0x3c5copied intotargetingType(movsx ax, alat 0x00569582), and ondisappearFadeAlphaCountdown > 32(a signed compare);(int)onBuilding::widthOrHeight(a signed halving). The headers have these asbyteanduint.The other CHECKs: 3 for the
+= 1above, 4 for the declarations above, 28 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 (-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.Frames_Shared_UnitClimbingUp.field_0x183c,.field_0x18a0,.field_0x1904(loading) and.field_0x196c,.field_0x19a8,.field_0x19e4(firing): the trebuchet's frame tables intoanimationFrame,imageIDUnkandimageID2, indexed byanimationCycleNumber.US_FIRE_WEAPONUnk(6) unmanned,US_STAND_UPUnk(8) aiming,US_STATE_2Unk(2) loading,US_RELOAD_WEAPONUnk(4) firing.Proposed, not changed here
Building::widthOrHeightasint, as in One more Map::Units function at 100%: UpdateMangonel #445.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. Eight of the nine casts could go.Other PRs
UpdateTrebuchet.cppand one more status hunk, at 0x00569410 (100.0% here against his 42.6%). 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, Reimplement the remaining Map::Buildings Update* functions #297 and cmake: function-visibility.txt, which callers must see which callees' bodies #398 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 and One more Map::Units function at 100%: UpdateFireBallista #452 add thedeselectUnit.cppline too, and Five more functions at 100%: InGameMenu MainButtons, Roundtable handler, BuySell, UpdateGhost and UpdateHopsFarmer #416 addsisAIPlayer.cpp(forMenuItemActionHandler_Roundtable_Main); listed twice, each does no harm.UpdateTrebuchetstill reads 100.0% raw and normalised, although Reimplement 47 UnitsState functions at 100% and restyle 28 more #378 putsclearOrDeselectUnitFromSelection.cpp(called here, and it writes the unit slot) on the/GLlist. Measured in a narrower run on a local merge of main, Reimplement 47 UnitsState functions at 100% and restyle 28 more #378 and this branch (Reimplement 47 UnitsState functions at 100% and restyle 28 more #378's files and/GLlist plusisAIPlayer.cppand the unit, 300 functions): the other 298 read the same as without the unit andisAIPlayer.🤖 Generated with Claude Code