Repository navigation
One more Map::Units function at 100%: UpdateMangonel - #445
Open
kotijekriv wants to merge 2 commits into
Open
kotijekriv wants to merge 2 commits into
kotijekriv wants to merge 2 commits into
Conversation
Units::UpdateMangonel, from gynt's draft bc487ad (42.92%). reccmp reads 100.0, raw and normalized, in a build of main 3458fea with this commit: the files of main's /GL list, the files sourcehold#398's visibility manifest names, and the unit (141 files, 151 functions, both resolver sets on). Against main alone with the same list, the other 150 functions read as before. cmake/compiler-flags-gl.txt gets two lines, the unit and UnitsState/deselectUnit.cpp (0x00535190, 100% on main). The unit has to see that body: behind its call at 0x0056AA21 the original still uses edx from before the call (0x0056AA26) and calls clearOrDeselectUnitFromSelection (0x0056AA31) without loading ecx again. No other file on the /GL list calls deselectUnit. Three things in the text are read off the original's listing: - The block that sends the two engineers to work is one loop over manningEngineerRef. The original computes the unit's offset anew at the block's start (0x0056A7D7) instead of using esi, and its second copy has the stores in source order while the first has the constants' loads in between: a loop the compiler unrolled. - In the two loops over a destroyed or disbanded mangonel's crew the engineer's id is a local. With the nested index written twice the compiler makes the two walking pointers in the other order. - The two distance blocks write the positions out and set dx and dy in both arms of an if / else. With one arm's value as the initialiser the match is lost. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
- The (short) casts on the two stores into short fields are gone. - const on the locals that are assigned once. - The search for engineers names its counter unitID and leaves a pass early with continue. - UT_NONE for the unit type passed to clearOrDeselectUnitFromSelection, no return at the function's end, and the comment on dx and dy is reworded. - engineersInPlace stays at the function's start and gets a comment. Declared in the block that uses it, the unit reads 0.9100 in the quick measure; the original clears it at 0x0056A442, in front of the state tests. The function's /FA listing is the same as at 96ab2e4, label numbers aside. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This was referenced Nov 21, 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::UpdateMangonelis a Map::Units function from gynt's units branchreimpl/map-units-updatefunctions(his draft #204), and both commits credit him as co-author.Units::UpdateMangonel/GLMeasured.
Stronghold Crusader.exe(3bb0a8c1…5387ac5a), both resolver sets enabled locally (not committed), and sourcehold's reccmp with--resolve-wrapped-calls --ignore-security-cookie.tools/).UpdateMangonelanddeselectUnitread 100.0% raw and normalised, with no diff entry, and every other main function reads exactly what it read before, except two that read lower, and it is how reccmp prints a constant, not their code:Menu::handleMenuItems(0x004F6280) reads 97.9 (91.4 normalised) andMenu::Constructor_Menu(0x004F4100) reads 98.4 (95.2), both 100.0 before. Both compare a menu item's type with the constant 0x11000000, five compares in all. In this build's layout a symbol of our DLL lies at exactly the address 0x11000000, so reccmp prints the constant as that symbol's name on our side. The instructions are the same on both sides, as UI: three more functions at 100%: the building menu's DoInitial, the credits' prepare and activateModalDialog2 #435's and UI: the credits scroll's fade and the win/defeat window at 100% #437's texts describe for their builds, and these two readings are why the average is a little lower (unrounded 99.5746 against 99.5759). That build was of the first commit. 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) and the unit: 151 functions, average 99.59,UpdateMangonelat 100.0% raw and normalised. Without the unit and the two new/GLlines: 99.58 over 150, each reading the same in both builds.openshc-pr-fixfinds nothing to change, andopenshc-pr-checkgives 0 ERROR and 35 CHECK (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: 72.1, 80.0, 85.9, 86.2, 89.1, 89.8 and, with the last four points, 100.0.DAT_CurrentUnitSlotID::instance. The draft used a copy of the slot in about two places out of three; with no copy the compiler arrives at the original's loads.findClosestEnemyBuildingWithinRadius(jeat 0x0056A55C) and behindacquireShootTargetin the manned and the waiting state (0x0056A5ED, 0x0056AAF0). The draft had early exits; now the call that works is theifbody and the exit comes last.found >= 2(0x0056A981), and the height sums are written with the terrain heights first: our compiler then loads the building heights first, as the original does (0x0056A734, 0x0056A8F8).esiholds it: the start of a loop the compiler unrolled. Its second copy has the stores in the source's order.shortlocal, the search loop kept the subtraction in each arm. What quick_diff still shows at 0.9950 is not in the code (two jumps over loop padding, three renderings of 0x80000007).Lines added to
cmake/compiler-flags-gl.txtUpdateMangonel.cppandUnitsState/deselectUnit.cpp(0x00535190, at 100% on main).deselectUnit. Behind its call at 0x0056AA21 the original still usesedx(0x0056AA26) and callsclearOrDeselectUnitFromSelection(0x0056AA31) without loadingecxagain, so its compiler knew the callee leaves both alone. quick_diff: 0.9223 without the body, 0.9950 with it.hasUnitReachedDestination, the other callee the unit has to see, is on main's list already (cmake: function-visibility.txt, which callers must see which callees' bodies #398's manifest has both edges).processUnitLossStatisticmakes no difference (0.9950 without it) and is not added. No other file on main's list callsdeselectUnit.Kept as they are
The first two 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 0x0056A442, in front of the state tests. In its block: quick_diff 0.9100.dxanddyare declared without a value and set in both arms of an if / else. Initialised with one arm's value: 0.6028. A conditional expression gives the same code, but the style lint flags it. They are notabscalls: the original usescdq/xor/subfor the height difference and a compare and a branch for these. The larger of the two goes into a local of its own (written intody: 0.9112; asdx < 30 && dy < 30: 0.7970).== 0and!= 0stay ondyingandkilledFlagUnk, which areshortfields, as in Three more Map::Units functions at 100%: UpdateOx, ConsiderHavingABreakNowUnk and UpdateMinerIronFetcher #421.(char)on the four frame-table reads (two intoanimationFrame, two intoimageIDUnk; read withmovsx) and ondisappearFadeAlphaCountdown > 32(a signedjleat 0x0056AF6B), and(int)onBuilding::widthOrHeight(a signed halving at 0x0056ABDF). The headers have the first five asbyte, the last asuint.The other CHECKs: 21 placeholder names (next section), the 4
dx/dydeclarations, and 4 false hits (the checker takesUnit::field_0x58, ashort, for another struct's BOOLEnum field of that name).What some placeholders hold
Unit::field_0x3bc: a negative countdown to the next search for a target: set to -40, -80 or -200 when the mangonel finds nothing to shoot at or has to pause, and counted up by one per update in the manned and the waiting state.Unit::field_0x3c5: an instruction type waiting to be taken over: this function storesUIT_ATTACK_BUILDINGthere next to the same value intargetingType, and the catapult and the trebuchet (Reimpl/map units updatefunctions #204 drafts, not on main) copy it intotargetingTypewhen it holdsUIT_ATTACK_LAND(5) orUIT_THROW_COW(22).Frames_Shared_UnitClimbingUp.field_0x1a24,.field_0x1a60,.field_0x1a9cand.field_0x1ad8: the mangonel's frame tables for loading and firing, indexed byanimationCycleNumber.US_DETERMINE_NEXT_STATEUnk(0) is manned and looking for a target,US_FIRE_WEAPONUnk(6) unmanned,US_LOOK_AROUNDUnk(7) waiting for a target,US_STAND_UPUnk(8) turning towards it,US_STATE_2Unk(2) loading,US_RELOAD_WEAPONUnk(4) firing andUS_STATE_9Unk(9) disbanded; 9 is whatUnitsState::setTowerSiegeEngineToIdle(0x00537E00) stores, written there asUS_STAND_UPUnk | US_IDLEUnk.UpdateMangonel.Proposed, not changed here
Building::widthOrHeightasint: it is halved signed here, and main has three more(int)casts on it.DTET_NONE = 0inDefensiveTowerEngineType(it hasDTET_MANGONEL = 1andDTET_BALLISTA = 2): this function stores 0 when the mangonel on a tower is gone.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. Five of the six casts could go.Other PRs
UpdateMangonel.cppand one more status hunk, at 0x0056A3F0 (100.0% here against his 42.9%). 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. 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 adds thedeselectUnit.cppline too; listed twice, it does no harm.UpdateMangonelstill 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 (the second commit's code; Reimplement 47 UnitsState functions at 100% and restyle 28 more #378's files and/GLlist plus the unit, 299 functions): the other 298 read the same as without the unit.🤖 Generated with Claude Code