Repository navigation
Reimplement six UnitsState functions at 100%, from gynt's text on main - #539
Merged
Merged
Conversation
UnitsState::ifAnyUnitOnSameTileIsLadderInRightDirection from 62.9% (gynt's text, on main since sourcehold#238) to 100%. The wall bit is tested apart from the other eleven bits of the mask, in all four directions. MSVC makes one test of 0x4a5015b1 out of the two, as the original has it, and the first one loads the layer into a register (0x0052F5C5). With all bits in one mask it keeps the mask in ebx over the function and nothing after the prolog lines up. The other eleven bits are the mask findFreeTileNearby and findRecentOrSignpostSpawnLocation test on main. A loop over the four even directions reads 0.3297 (quick_diff). The body is gynt's (aa4f048, 57.6%). Measured with real builds of this branch's tree on main 4591b6f (bundled MSVC1400-SP1, function and data resolvers on locally, reccmp raw / normalised): 100.0 / 100.0 in a small build with OPENSHC_FUNCTION_VISIBILITY_UNITS off, in one with it on, and in a full build with it off (of this branch merged with the prepareProjectileTarget one). The comment's new wording came after those builds. A small build with it off of the final text (this branch merged with the prepareProjectileTarget one, 550 files, 560 functions) reads every function as the earlier small build with it off did. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
UnitsState::updateUnitFadeAndVisibilityNearStructures from 85.1% / 75.2% (gynt's text, on main since sourcehold#238) to 100%. Three edits, each measured with quick_diff (0.8032 before): - `vanish = 0` is stored in the two arms it belongs to instead of in one arm behind an `||`. MSVC makes one store of them again (0x00533F23), but with two it keeps the 0 in edx from 0x00533EAC to the last test, as the original does: 0.9600. - The four locals that start at 0 are declared in the order fade type, on a structure, tower, gate: 0.9760. - destinationBuildingID is read in front of destinationFlags, which puts the destination tile in esi (0x00533E5D): 1.0000. The body is gynt's (e3df755 56.3%, c6efbfc 77.0%, f2e1b62 85.1%). Measured with real builds of this branch's tree on main 4591b6f (bundled MSVC1400-SP1, function and data resolvers on locally, reccmp raw / normalised): 100.0 / 100.0 in a small build with OPENSHC_FUNCTION_VISIBILITY_UNITS off, in one with it on, and in a full build with it off (of this branch merged with the prepareProjectileTarget one). Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
UnitsState::isTowerTileOvercrowdedByCurrentPlayer from 66.2% / 56.9% to 100% by taking it off the /GL list. The text is gynt's but for its two comments, the name of the loop's index and the result written as TRUE / FALSE (bcbf6a4 73.7%; 0118583, where he recorded 100%). The original reads the building's widthOrHeight again for each call in the loop (0x00536817) and loads currentPlayerSlotID in front of the unit loop (0x00536850): it did not see into getBuildingSizeIndexMappingData, which is on main's /GL list. No .cpp on main calls the function, so nothing else sees its body. The do loop stays: a for reads 0.8882 against 0.9733 (quick_diff; what is left of the 0.9733 is notation), and so does the selection loop's `<= countof(...) - 1`: `<` compares with 27 and jl where the original has 26 and jle (0.9600). Measured with real builds of this branch's tree on main 4591b6f (bundled MSVC1400-SP1, function and data resolvers on locally, reccmp raw / normalised): 100.0 / 100.0 in a small build with OPENSHC_FUNCTION_VISIBILITY_UNITS off, in one with it on, and in a full build with it off (of this branch merged with the prepareProjectileTarget one). The name of the loop's index and the result written as TRUE / FALSE came after those builds. A small build with it off of the final text (this branch merged with the prepareProjectileTarget one, 550 files, 560 functions) reads every function as the earlier small build with it off did. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
UnitsState::giveMoveCommand from 94.5% / 93.1% (gynt's text, on main since sourcehold#238) to 100%. Only the stack slots of _mostFrequentUnitType and _canReachDestination were swapped. MSVC hands the dead parameters' slots out by reference count, counted before it merges equal code. `_canReachDestination = FALSE` now stands in an arm of its own for the blocked tile and for the failed path instead of once behind an `||`; the two stores become one again (0x00536F60), but the variable counts one reference more and takes the first slot. The two calls that return BOOLEnum are tested by truthiness (the same listing). The body is gynt's (742a29f 74.4%, c0b593b 94.5%). Measured with real builds of this branch's tree on main 4591b6f (bundled MSVC1400-SP1, function and data resolvers on locally, reccmp raw / normalised): 100.0 / 100.0 in a small build with OPENSHC_FUNCTION_VISIBILITY_UNITS off, in one with it on, and in a full build with it off (of this branch merged with the prepareProjectileTarget one). The second truth test and the plain 0 for maximumCount came after those builds. A small build with it off of the final text (this branch merged with the prepareProjectileTarget one, 550 files, 560 functions) reads every function as the earlier small build with it off did. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
UnitsState::isWorkerAtProductionIdleState from 48.1% / 46.2% (gynt's text, on main since sourcehold#238) to 100%. Each unit type has its own arm, in the order of the type's value, instead of one arm per state. MSVC folds the equal arms (the jump table's order is the one the types give), but counts their references first, and the state then takes eax as in the original (0x0053A07C) and the pointer and the type ecx (quick_diff 0.5057 -> 1.0000). selectWorkerSpeechOrMoraleStateID 0x0053DDD0, which calls it, goes back from 83.9% / 71.1% to 100.0% / 100.0% with its text unchanged: our function no longer uses edx. gynt described that in 1fab2cf and had it at 100% before (390b34b). Its status line (74.4%) follows. The body here is gynt's (69a106e 64.0%, 1fab2cf 48.1%). Measured with real builds of this branch's tree on main 4591b6f (bundled MSVC1400-SP1, function and data resolvers on locally, reccmp raw / normalised): 100.0 / 100.0 in a small build with OPENSHC_FUNCTION_VISIBILITY_UNITS off, in one with it on, and in a full build with it off (of this branch merged with the prepareProjectileTarget one). The name US_UNKNOWN_10 for the state 10 came after those builds. A small build with it off of the final text (this branch merged with the prepareProjectileTarget one, 550 files, 560 functions) reads every function as the earlier small build with it off did. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
UnitsState::spawnUnit from 94.5% / 89.6% (gynt's text, on main since sourcehold#238) to 100%. Store order only. The unit's time is stored from mapTimeInTicks directly behind the uid (no local), and the height behind the two micro positions: the scheduler then gives the original's order from 0x0053E491 on (quick_diff 0.9484 -> 0.9871). movementRelated is set in front of field_0xe8 (0x0053E58B), which swaps the last two stores: the same listing as the original. The catapult and trebuchet arms stay apart: the original has both, and one test with || reads 0.8467. The rest is gynt's (f012109 53.1%, 77ba3d7 92.9%, 351b48a 94.5%). Measured with real builds of this branch's tree on main 4591b6f (bundled MSVC1400-SP1, function and data resolvers on locally, reccmp raw / normalised): 100.0 / 100.0 in a small build with OPENSHC_FUNCTION_VISIBILITY_UNITS off, in one with it on, and in a full build with it off (of this branch merged with the prepareProjectileTarget one). The names of the constants, the last slot written from countof and the comment came after those builds. A small build with it off of the final text (this branch merged with the prepareProjectileTarget one, 550 files, 560 functions) reads every function as the earlier small build with it off did. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Style guide reading (advisory, posted once) 1 possible deviation(s) from REIMPLEMENTATION_STYLE_GUIDE.md across 1 of the 6 reimplemented The match comes first. Where the ugly form is what matched, it stays -- that is the guide's own overriding rule, and rule 21 asks for a one-line comment saying what was measured so the next reader does not retry it. This report is posted once, when the PR opens, and is not repeated on later pushes.
WhereRule 9 — Prefer
|
This was referenced Dec 2, 2026
Merged
gynt
approved these changes
Dec 2, 2026
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.
Six
UnitsStatefunctions that #238 put on main below 100%. The bodies are gynt's; each commit says what changed. A seventh,selectWorkerSpeechOrMoraleStateID, goes back to 100% with one of them. All read 100.0% / 100.0% (reccmp raw / normalised) withOPENSHC_FUNCTION_VISIBILITY_UNITSoff and on.ifAnyUnitOnSameTileIsLadderInRightDirectionupdateUnitFadeAndVisibilityNearStructuresvanish = 0in its two arms, two declaration ordersisTowerTileOvercrowdedByCurrentPlayer/GLlist, gynt's textgiveMoveCommand_canReachDestination = FALSEin its two armsisWorkerAtProductionIdleStateselectWorkerSpeechOrMoraleStateIDspawnUnit"Before" is main's reading, the same with the option off and on. The old numbers in the status file were partly older still.
What matched them
isWorkerAtProductionIdleState: the arms per unit type raise the count of the state, which then takes eax (0x0053A07C). The jump table's entries stand in the order the types give.giveMoveCommand: two stores ofFALSE, one in the binary (0x00536F60). Only the stack slots of two locals were swapped before.updateUnitFadeAndVisibilityNearStructures: two stores of 0, one in the binary (0x00533F23). With two, MSVC keeps the 0 in edx from 0x00533EAC on.ifAnyUnitOnSameTileIsLadderInRightDirection: two tests ofLogicLayer, one in the binary. With all twelve bits in one mask MSVC keeps the mask in ebx. The eleven bits left are the maskfindFreeTileNearbyandfindRecentOrSignpostSpawnLocationtest on main.isTowerTileOvercrowdedByCurrentPlayer: the original reads the building'swidthOrHeightagain for each call in the loop (0x00536817), so it did not see intogetBuildingSizeIndexMappingData, which is on main's/GLlist. Off the list it matches as gynt wrote it (he recorded 100% in 0118583). No.cppon main calls it.spawnUnit:timedirectly behind the uid, the height behind the two micro positions,movementRelatedin front offield_0xe8.selectWorkerSpeechOrMoraleStateID: gynt had it at 100% (390b34b) untilisWorkerAtProductionIdleStateused edx (he says so in 1fab2cf). It no longer does.Kept as they are
isTowerTileOvercrowdedByCurrentPlayer's two block comments are line comments now, and itsdoloop stays: afortests first and loses the match (0.8882 against 0.9733 inquick_diff). The style-lint bot's one finding is that loop.DAT_UnitsState::instancein members of UnitsState (giveMoveCommand,isTowerTileOvercrowdedByCurrentPlayer,updateUnitFadeAndVisibilityNearStructures): main's text; the original addresses the units through the global there._canReachDestination,_isOnDefensiveStructure, theIsGateOrTowerArrayentries and the calls that returnBOOLEnum(selectionHasMobileAssaultUnits,calculatePathKeepAndWallsGatesNotAllowed,shouldSoundXNotBePlaying). The compares are on numbers:calculateCanPlayerUnitsNavigateToAreaFromAreareturnsint,_blockedAtDestinationis a set of bits and the others are counts or indices.updateUnitFadeAndVisibilityNearStructuresstart at 0 in that order for the match (0.9600 -> 0.9760 inquick_diff), and the tile's flags stay in a local read at the top: reading the field at its one test gives 0.9157.spawnUnit: the catapult and trebuchet arms stay apart, because the original has both; one test with||gives 0.8467.(UnitLogicState)1stays a number, because main's enum has no name for 1.field_0xe8keeps the header's placeholder name: this function only clears it, which says nothing about what it holds.isTowerTileOvercrowdedByCurrentPlayer: the selection loop keeps<= countof(...) - 1. With<MSVC compares with 27 andjlwhere the original has 26 andjle(0.9600 against 0.9733).ifAnyUnitOnSameTileIsLadderInRightDirection: the four directions stay written out: a loop over them gives 0.3297.compiler-flags-gl.txtis on purpose, see above.Measured
Setup: the bundled MSVC1400-SP1 against the Steam
Stronghold Crusader.exe(3bb0a8c1…5387ac5a), both resolver sets enabled locally (not committed), sourcehold's reccmp with--resolve-wrapped-calls --ignore-security-cookie. All builds of this branch were made on main 4591b6f. It is cut from main 0cea04d, which adds six status lines (#538) and a tools script: nothing that is compiled./GLfile of main, every.cppthat readsUnit::disappearFadeAlphaCountdown, the units of 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 UpdatePeasant and UpdateMiller from gynt's units branch, under /GL (100%) #533 and Reimplement UpdateShield, UpdateHunter, UpdateAppleFarmer, UpdateJester and UpdateSlave from gynt's units branch (100%, three with OPENSHC_FUNCTION_VISIBILITY_UNITS on) #537 and the changed functions with their callers and callee closures, every file of a function-visibility group that touches them): BUILD_OK and 0 failures in both. The six andselectWorkerSpeechOrMoraleStateIDread 100.0% / 100.0% in both; every other function reads as in the same build of main but two.UpdateCatapultBuildingreads 100.0% / 100.0% with the option off and 99.6% / 95.5% with it on, where main reads 99.6% / 95.7% off and 100.0% / 100.0% on: its code is unchanged, a tie that goes either way with the layout.triggerDesyncIfTileUnitLinkageInvalidreads 100.0% / 100.0% in both, main 97.2% / 100.0%: the raw number only, from a name.prepareProjectileTarget(every.cppbut the three that don't compile: 3,041 files, 3,059 functions; BUILD_OK, 0 failures), against the full build of main's tree made for Reimplement UpdateShield, UpdateHunter, UpdateAppleFarmer, UpdateJester and UpdateSlave from gynt's units branch (100%, three with OPENSHC_FUNCTION_VISIBILITY_UNITS on) #537: the only functions that read differently are the six,selectWorkerSpeechOrMoraleStateIDandprepareProjectileTarget(up to 100.0%), andConstructor_MenuandhandleMenuItems(98.4% and 97.9% there, 100.0% here: the known 0x11000000 flip with the image layout, their code unchanged). Nothing reads lower.giveMoveCommand,spawnUnit,isWorkerAtProductionIdleState,isTowerTileOvercrowdedByCurrentPlayer,ifAnyUnitOnSameTileIsLadderInRightDirection). The final heads of this branch and theprepareProjectileTargetone, merged, were built again (small, option off, 550 files, 560 functions: this branch's list andcalculatePathKeepAndWallsGatesNotAllowed.cpp; BUILD_OK, 0 failures): every function reads as in the small builds with the option off above.selectWorkerSpeechOrMoraleStateID, whose.cppdoesn't change, and 9 notes, all covered under "Kept as they are".Other PRs
#536 is ours and open. It shares no file with this one but the status file and
compiler-flags-gl.txt, in other lines.prepareProjectileTarget, which needs a header change (one line in each of two headers), is in #540, ours and open; the full and final small builds above were made of both branches together. It shares only the status file with this one, in other lines.🤖 Generated with Claude Code