Skip to content

Reimpl/TileMapState 100% batch 2 - #396

Draft
gynt wants to merge 486 commits into
reimpl/TileMapState-100from
reimpl/TileMapState-100-2
Draft

gynt wants to merge 486 commits into
reimpl/TileMapState-100from
reimpl/TileMapState-100-2

Conversation

@gynt

@gynt gynt commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Needs #366 to be merged first obviously

gynt and others added 30 commits October 6, 2026 21:14
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…fers

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Their sources are unchanged; the percentages moved because caller and callee
are now built with /GL (see the compiler-flags-gl.txt commit).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts:
#	AGENTS.md
#	IMPLEMENTATION_CHEAT_SHEET.md
#	cmake/compiler-flags-gl.txt
#	src/OpenSHC/Map/Buildings/Building.hpp
#	src/OpenSHC/Map/TerrainDefinedData.hpp
#	src/OpenSHC/Map/TileMapState/clearMoatData.cpp
#	src/OpenSHC/Map/TileMapState/forceFullTileMapRedraw.cpp
#	src/OpenSHC/Map/TileMapState/getUnownedMoatCount.cpp
#	src/OpenSHC/Map/TileMapState/processDamageToBuildingThunk.cpp
#	src/OpenSHC/Map/TileMapState/processEntityDamageToBuildingCollateralThunk.cpp
#	src/OpenSHC/Map/TileMapState/processMapOrientationChange.cpp
#	src/OpenSHC/Map/TileMapState/recountTotalOwnedMoats.cpp
#	src/OpenSHC/Map/TileMapState/resetMoatArray.cpp
#	src/OpenSHC/Map/TileMapState/resetPitchDitchArray.cpp
#	src/OpenSHC/Map/TileMapState/setMapRotation.cpp
#	src/OpenSHC/Map/TileMapState/setMoatOwnerForAllMatching.cpp
#	src/OpenSHC/Map/TileMapState/setMoatVisualStateAtTile.cpp
#	src/OpenSHC/Map/TileMapState/spreadBrazierPlacementAlgorithm.cpp
#	src/OpenSHC/Map/TileMapState/spreadFlagPlacementAlgorithm.cpp
#	src/OpenSHC/Map/TileMapState/toggleFlatView.cpp
#	src/OpenSHC/Map/TileMapState/updateBuildingPlacementRotationPreview.cpp
#	src/OpenSHC/Map/TileMapState/updateMoatCountdownTimers.cpp
#	tools/mcp/openshcmcp.py
#	tools/reimplementation-helper/batch/README.md
#	tools/reimplementation-helper/batch/common.py
#	tools/reimplementation-helper/batch/declare_at_use.py
#	tools/reimplementation-helper/batch/diff_jcc.py
#	tools/reimplementation-helper/batch/quick_diff.py
…main

This branch was 141 commits behind main and did not compile at all against
main's regenerated headers, so it had never been measured. 179 of its 186
TileMapState sources now build, link and score.

Merging main conflicted on 17 TileMapState sources that main has since gained
independently, plus the docs, tools and two headers; all of those took main's
side. The branch still contributes 169 sources main does not have, so it is
not superseded.

TerrainDefinedData.hpp is the one file where taking main's side was wrong, and
it is resolved by hand instead. Main guesses `unkXYOffsets_0x384[8]`,
`field132_0x3c4[8]` and `padding_0x404[64]` over 0x384..0x444; the branch had
researched the same 192 bytes as `keepOutbuildingOffsets_0x384[3][4]` and
`keepOutbuildingOffsets_0x3e4[3][4]`, which is what placeKeep and
demolishBuildingsInKeepsConstructionFootprint index as [variant][group]. The
researched pair is restored over main's three, same span, and
sizeof(TerrainDefinedData) stays 14252. Main's own gains in that header
(ConstructionSpriteRotationTable, MacroLayerScanOffsets) are kept.

The bulk of the work is stale generated field names. Main's Ghidra
regenerations renamed or renumbered fields that the branch still referenced,
e.g. field80_0x554894 -> editorRockType, unknownTime_0x5549bc ->
cursorAnimationTime, field84_0x5548a4 -> screenSouthEastDirection,
field151_0x554998 -> placementOnWall. These were resolved mechanically: the
offset is encoded in the old identifier, so each was rewritten to whatever the
header now declares at that same offset, and only where the offset resolved to
exactly one field. field889_0x2be0 needed the array form - it is 4 bytes into
attackedByPlayerArrayUnk[10][8] at 0x2BDC, so [0][1].

Three other classes of breakage:
- clearBuildingTilesAndTrees walked Building* through the tileRefs int array
  (`_pTileRef = &_pTileRef->tileRefs[1]`), which stopped being an lvalue of
  that type once Building became a real struct. It now walks int*, same
  arithmetic. It also needed explicit Logic1.hpp usings for the L_* flags that
  used to arrive transitively.
- Six place* sources passed a default-constructed TextMessageBLLookupStructUnion
  to setBottomLeftTextDisplayText, whose param_4 is now int; that is 0.
- Seven sources are still raw decompiler output (`._0_2_`, `::constant`,
  in_EAX) and are left out of the build list rather than guessed at:
  placeApplefarm, placeBarracks, placeBuilding, placeDairyfarm, placeDrawbridge,
  placeHopfarm, placeWheatfarm. They need real reimplementation, not a rename.

Files that clang-format flagged were formatted; 20 of them were already
non-conformant at HEAD, so part of that churn predates this change.

First measurement, reimplemented data and all 179 resolvers enabled: BUILD_OK,
avg 73.07 over 179, with 142 functions below 100. That is the real starting
point for this branch - no match work is attempted here, because none was
possible until it built.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013Fzi11pcBU1Y7Y4oanrZQL
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NVYWDtHk2xzvq9hszJRS9r
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NVYWDtHk2xzvq9hszJRS9r
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NVYWDtHk2xzvq9hszJRS9r
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NVYWDtHk2xzvq9hszJRS9r
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NVYWDtHk2xzvq9hszJRS9r
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NVYWDtHk2xzvq9hszJRS9r
… tile

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NVYWDtHk2xzvq9hszJRS9r
… bogu

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NVYWDtHk2xzvq9hszJRS9r
…re an

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NVYWDtHk2xzvq9hszJRS9r
…store

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NVYWDtHk2xzvq9hszJRS9r
… tile

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NVYWDtHk2xzvq9hszJRS9r
…store

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NVYWDtHk2xzvq9hszJRS9r
@gynt

gynt commented Nov 14, 2026

Copy link
Copy Markdown
Contributor Author

Round 5: 153 -> 159 of 187 at 100%, avg 98.13 -> 98.54

Measured with a full build and reccmp, both resolver sets on. One function came out slightly worse and was reverted: placeDefensiveStructureTile, -0.1 raw (+3 norm). Its replacement form drops the *(uint volatile*)&x reads, so the volatile cast stays for now.

Now at 100%: eraseAreaWithBrush, prepareAreaForBuildingPlacement, renderPreviewMapperWithBrush, renderWallPlacementPreview, setupBuildingSizeIndexMappingForBuildingWithSize, updateLogicalTileMapRelatedSections.

Big moves below 100:

  • checkBuildingCanBePlacedHere 75.8 -> 93.4
  • placeTree 83.3 -> 98.1
  • processEntityDamageToBuildingCollateral 96.1 -> 99.9
  • placeStockpile 97.8 -> 99.3
  • useEraserBrush 87.6 -> 91.5
  • placeOilsmelter 96.9 -> 98.0

Behaviour fix

  • checkBuildingCanBePlacedHere, gatehouse 6-part loop. The tile was computed from x, which the gate section has already shifted by the first tower's offset. The original (asm and Ghidra agree) adds startX, as the xyAreValid call right above it already did. The gatehouse parts were therefore checked one tower offset to the side.

Why some forms look odd (all measured; the plain form loses)

  • eraseAreaWithBrush / useEraserBrush / placeTree: baseTile and tile each written as the full translationMatrix[y].addXgetTile + x, rather than baseTile = tile.
    • The second copy is CSE'd, which lowers the tile value's allocator priority below y's.
    • That restores the original's registers and loop temporaries.
    • placeTree also computes the tile after the two tree-type calls, as the original does.
  • checkBuildingCanBePlacedHere: this->buildingY + y written inline instead of tileY/partY locals, and the main bound guard split into three ifs.
    • The inline sums are the original's CSE temps.
    • prepareAreaForBuildingPlacement's inline translationMatrix[this->buildingY + y] is the same lever, and it gives the register-register lea.
  • renderPreviewMapperWithBrush: one uint brushY in a block around both brush loops, plus a volatile store of the reused x.
    • The shared block-scoped local keeps the frame at the original's size. That is what made the round-3 volatile store lose.
  • renderWallPlacementPreview: int variationStep = 0; declared with the other top-of-function locals.
    • The 16-bit narrowing pass gives operands new symbol ids in first-reference order, and those ids set the commutative sort.
  • placeStockpile: the wall-owner merge split into &= 0xf8; and |= (byte)(playerID - 1); in the pathable loop only.
    • This adds one CSE entry, which moves the loop's induction temps to the original's operand order (round 4's mod-4 rule).
  • setupBuildingSizeIndexMappingForBuildingWithSize: for (diagonal = 0, run = 1; ...) in all four passes.
    • With this, run = 1 follows the zero in IL order, which fixes three scheduler positions and turns a mov edi, 1 into the original's lea edi, [ebx+1].
  • updateLogicalTileMapRelatedSections: the shadow walk indexes directionTranslationMatrix[row + step * orientedRowStep] instead of advancing a pointer.
    • It computes the same values; strength reduction then hoists the orientedRowStep << 5 stride as the original does.
    • It also removes a pointer walk.
  • processEntityDamageToBuildingCollateral: char const& damageLevel / byte& height references.
    • They replace a volatile cast and fix the hoisted DamageLayer load.
  • renderWallDragPreview: (steps > 10 ? 10 : steps) inline fixes an lea operand swap.
  • processDamageToBuilding: the top-level test written as the building test, with the building arm first.
    • The shared return blocks land where the original has them.
  • placeOilsmelter: one buildingID for the smelter and then the campfire, plus smelterID saved after the first loop.
    • This rebuilds the original's frame: the compiler no longer keeps buildingID * 0x32c across loop 1.

Compiler findings (c2.dll)

  • Scheduler priority (SchComputeStaticPriority 0x10c71f00, post-RA weight table 0x10cd981c):
    • prio = flag<<23 + memsrc<<15 + (height + edgecount)<<10, tie-broken by IL order.
    • A memory-reading instruction outranks almost anything, which explains most of the remaining "scheduler order" swaps.
  • getHeightAtTileIncludingOwnersBuildings (FgTailMergeWithoutCheck):
    • With identical calls in both arms, every source shape merges the gatehouse copy.
    • Making the gatehouse arm call a different function gives a byte-identical match.
    • So the original most likely called a separate function with a body identical to getTotalHeightAtTile, which the linker folded into 0x4FFB10. updatePathLinkagesForBuilding's remaining diff (tail-jump targets only) looks like the same kind of folding.
    • Reaching 100 would need a second declared method sharing that address. That is a header and resolver decision, so it is not applied.

Still walls

  • determineBuildingPlacementRotation, isValidCastleSiteLocation, useTerrainHeightBrush, setConstructionGFXLayerBasedOnPlacementChecks and validateWallBuildPath: see rounds 3 and 4.
  • evaluateBuildingPlacementAtCursor: ebx/ebp ordering.
  • placeApplefarm / placeBuilding: stack slot ties that are decided by load order.
  • demolishBuildingsInKeepsConstructionFootprint: the lea only appears when the value is a CSE temp, and that temp then takes x's home.
  • setupMovementDirectionTranslationMatrix: strength-reduction latch order.
  • updateBuildingGraphicsLayer: live-range split of index.
  • placeRock: the extra movzx comes from the 16-bit read itself.

gynt and others added 2 commits November 14, 2026 18:41
…talHeightAtTile

The original getHeightAtTileIncludingOwnersBuildings calls two functions with
byte-identical bodies that its linker folded into 0x004FFB10. Only distinct call
targets keep c2 from tail-merging the gatehouse arm into the keep/tower arm.
A second resolver at the same address is not possible (AddressUsageKeeper aborts
on a second registration), so the twin has no resolver and is only called from
reimplemented code.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmb6xg8rirS2UbTZA3i
@gynt

gynt commented Nov 14, 2026

Copy link
Copy Markdown
Contributor Author

getHeightAtTileIncludingOwnersBuildings: linker-folded twin (a32b7c0, 37a928f)

The keep/tower arm and the gatehouse arm both end in return getTotalHeightAtTile(tile). With identical calls, c2 always tail-merges the gatehouse copy, but the original keeps both copies. With a distinct call target in one arm the function is byte-identical. So the original called two functions with identical bodies, and its linker folded them into 0x004FFB10.

  • TileMapState.hpp declares getTotalHeightAtTile2. Its body is in getTotalHeightAtTile.cpp, identical to getTotalHeightAtTile's. The gatehouse arm calls it.
  • No resolver. Two resolvers cannot share a game address: FunctionResolver::initialize logs FATAL "address ... was resolved more then once" through the shared AddressUsageKeeper<address>. The twin is therefore a plain member that only reimplemented code calls.
  • Result: 89.3 -> 99.3 raw, 100 norm. The only remaining difference is the call target name, and the status file records it as Reimplemented.
  • Ghidra / the header generator need to know. A regenerated TileMapState.hpp will drop the declaration unless the twin is added on the Ghidra side too.

updatePathLinkagesForBuilding's remaining diff (tail-jump targets only) looks like the same kind of folding and could get the same treatment once its twins are identified.

@gynt

gynt commented Nov 14, 2026

Copy link
Copy Markdown
Contributor Author

Why getTotalHeightAtTile2 exists: reccmp with and without it

getHeightAtTileIncludingOwnersBuildings has two switch arms that both end with the same call:

case BT_STONEKEEP: ... case BT_TOWER5: {
    // check all 8 neighbours belong to the building
    return MACRO_CALL_MEMBER(TileMapState_Func::getTotalHeightAtTile, this)(tile);
}
case BT_GATEHOUSELARGE: case BT_GATEHOUSESMALL: {
    // check the 2 neighbours along the gate belong to the building
    return MACRO_CALL_MEMBER(TileMapState_Func::getTotalHeightAtTile, this)(tile);   // <- same call
}

Without it (both arms call getTotalHeightAtTile): 89.3%, norm 84.1%

The end of the gatehouse arm (- original, + ours):

 cmp edx, edi
-jne 0xc
-push eax
-call OpenSHC::Map::TileMapState::getTotalHeightAtTile (FUNCTION)
-pop ebx
-pop edi
-pop esi
-ret 8
+je -0x5d 	(getHeightAtTileIncludingOwnersBuildings.cpp:80)
 pop ebx
 pop edi
 xor eax, eax 	(getHeightAtTileIncludingOwnersBuildings.cpp:83)

The original gives the gatehouse arm its own copy of push eax; call; pop; pop; pop; ret 8.

Our compiler sees that this tail is identical to the end of the keep/tower arm, so it deletes it and jumps back into the other arm's copy (je -0x5d). The function becomes 7 instructions shorter, and every later jump offset and jump-table entry moves with it (ja 0xa5/0x99, jne 0x74/0x68, start + 0x146/0x13a, not shown above). That is where the 10 points go.

With it (the gatehouse arm calls getTotalHeightAtTile2): 99.3%, norm 100%

 cmp edx, edi
 jne 0xc 	(getHeightAtTileIncludingOwnersBuildings.cpp:78)
 push eax 	(getHeightAtTileIncludingOwnersBuildings.cpp:80)
-call OpenSHC::Map::TileMapState::getTotalHeightAtTile (FUNCTION)
+call OpenSHC::Map::TileMapState::getTotalHeightAtTile2 (FUNCTION)
 pop ebx
 pop edi
 pop esi
 ret 8 	(getHeightAtTileIncludingOwnersBuildings.cpp:85)

The tails now differ by their call target, so the compiler keeps both copies and every instruction lines up. The only remaining difference is the name of the call target, which is why the normalized score is 100.

Why the original could keep two copies

MSVC's backend (c2.dll) runs a tail-merge pass. Decompiling it (FgTailMergeWithoutCheck) shows two cases:

  • A tail is merged for free when the preceding branch jumps straight past it to the function exit.
  • Otherwise a tail is merged only if it is longer than 20 bytes.

Our gatehouse tail falls into the free case. No source shape keeps it as long as both arms make the same call: round 5 tried && chains, nested ifs, a shared return and separate returns, and every one was merged.

The original kept both copies, so its two calls must have gone to two different functions. The binary still shows only one target, 0x004FFB10, which means both functions had the same body and the linker folded them into one address. This is MSVC's identical COMDAT folding, /OPT:ICF, which is on by default in release builds. The compiler decides the tail merge per function, before linking, so it saw two distinct calls and kept both tails. The linker merged the two callees afterwards.

How it is implemented, and why there is no resolver

  • Declaration: TileMapState.hpp declares uint getTotalHeightAtTile2(int tile);.

  • Body: the body is in getTotalHeightAtTile.cpp, identical to getTotalHeightAtTile's.

  • Call site: the gatehouse arm calls this->getTotalHeightAtTile2(tile).

  • No resolver: a second resolver at 0x004FFB10 is not possible. All resolvers for an address share one FunctionResolver::AddressUsageKeeper<address>::initialized flag, and FunctionResolver::initialize (src/core/Resolver.cpp) logs FATAL "address ... was resolved more then once" on a second registration. That happens even with the implemented flag set to false, because the initializer runs regardless.

    The twin therefore has no game address and is only ever called from reimplemented code. That is correct behaviour: in the game binary both calls already land in 0x004FFB10.

Caveats:

  • The name is made up (following getSpriteID2), because the original name is unknown.
  • A regenerated TileMapState.hpp will drop the declaration unless the twin is also added on the Ghidra side.
  • Which arm called the twin cannot be recovered from the binary, since both calls hit the same address. Putting it in the gatehouse arm is a choice.

@gynt

gynt commented Nov 14, 2026

Copy link
Copy Markdown
Contributor Author

Round 6: 160 -> 164 of 187 at 100%, avg 98.60 -> 98.88

Measured with a full build and reccmp, both resolver sets on. Nothing got worse. checkBuildingCanBePlacedHere's round-6 change rose on quick_gl but dropped in reccmp (93.4 -> 92.7), so it was reverted.

Now at 100%: placeApplefarm, placeDefensiveStructureTile, renderWallDragPreview, setupMovementDirectionTranslationMatrix, validateWallBuildPath.

Big moves below 100:

  • processDamageToBuilding 80.7 -> 88.8
  • useEraserBrush 91.5 -> 95.0
  • setConstructionGFXLayerBasedOnPlacementChecks 77.5 -> 78.0
  • useTerrainHeightBrush 75.2 -> 75.8

Header change (separate types: commit 6229ec6)

  • placeApplefarm(..., BuildingTypeShort buildingType, ...).
    • The original only reads the parameter as a word (movsx ecx, word ptr [esp+0x2c]) or as a byte (the BuildingWasLayer store).
    • As a 2-byte symbol it sorts ahead of every 4-byte element when stack slots are coloured. That breaks the weight-2 tie with averageHeight the original's way, and is the whole remaining gap: 96.8 -> 100. The .cpp body is unchanged.
    • The caller placeBuilding stays at 97.3.

Why some forms look odd (all measured; the plain form loses)

  • placeDefensiveStructureTile: the *(uint volatile*)&x reads are gone.
    • The parity tests are written inline as (x & 1) == 1 / == 0; global opts does not jump-thread those, so the original's redundant test ecx, ecx; jne re-test stays.
    • Each arm uses byte& height = this->HeightLayer[tile]; height += 98;, which drops the parity temps' allocator key below x's, so the and lands in x's register.
  • renderWallDragPreview: } else if (x == x2 && y == y2) { overshoot -= 1; } else { overshoot -= 1; }.
    • The identical arm gives overshoot one more reference before stack slots are assigned (weight 9 against 7). The arms then merge, and the slot order matches the original (slot_probe).
    • This only works for read-modify-write arms; plain assignments are folded before colouring.
  • validateWallBuildPath:
    • The walk uses an index, with x/y declared just before the loop.
    • Each step updates y first.
    • A bool const endOutsideMap holds the x2/y2 range check. That puts push ebx and the inline fail block where the original has them (78.5 -> 100).
  • setupMovementDirectionTranslationMatrix: int* const offsets = this->directionTranslationMatrix[0] + offsetIndex; with offsetIndex += 8 in the loop header.
    • The separate stride-8 counter keeps the matrix pointer as its own induction-variable family, updated last as in the original.
    • It indexes the 2-D array flat, but nothing walks a pointer (97.8 -> 100).
  • processDamageToBuilding: BOOLEnum volatile destroyed.
    • The original keeps destroyed in memory, and with it the no-wall path shares the default arm's tail. Four changes that each measured worse before then pay:
      • the if/else store of showNoRubbleWhenDestroyingBuilding;
      • the siege-tower block last, with remaining <= 0 tested first and an int rider local;
      • the smelter load order;
      • owner declared after the rebuild-delay check.
    • The agent's version read it once through const_cast<BOOLEnum&> (89.3). Reading a volatile object through a non-volatile glvalue is undefined behaviour, so the plain read is used instead (88.8).
  • useEraserBrush: the brush walks its own int tile instead of reusing x. x's first region candidate was taking eax and caused the late x load.
  • useTerrainHeightBrush: one byte const& height replaces three volatile casts.
  • setConstructionGFXLayerBasedOnPlacementChecks: the wheat, hops and apple loops are do-while loops ending in j < N. That gives the original's jl without unrolling. The same form on placeStockpile measured worse (0.9886 -> 0.9810).

Remaining / candidates

  • processDamageToBuilding has two gaps left:

    • owner (round-1 allocator key +50) takes ebx from playerID.
    • The gate arm's playSFXAtLocation tail (23 bytes, over c2's 20-byte rule) merges into the smelter arm's.

    A distinct callee in one arm removes that merge (+0.2 quick), so one of the two calls might be another linker-folded twin of 0x449DC0. The evidence is weaker than for getTotalHeightAtTile2, and it would need a declaration in SFXState, so it is not applied.

  • determineBuildingPlacementRotation: the original keeps the constants 4 and 8 in ebx/ebp. Which constant gets a callee-saved register cannot be set from source.

  • isValidCastleSiteLocation: most likely the plain source compiled under /GL together with getTileForBrush, isEnemyTooCloseUnk, getCastleBuildRangeForMapSize and isOpponentBuildingInRange. That can only be tested once those are reimplemented.

  • placeBuilding, placeOilsmelter, updateBuildingGraphicsLayer, evaluateBuildingPlacementAtCursor, demolishBuildingsInKeepsConstructionFootprint, placeTree, placeRock: unchanged; see the rounds 5 and 6 notes.

gynt and others added 11 commits November 15, 2026 15:22
… directly

c2 inlines only __forceinline callees once global optimisation is off
(InlCallTupleIsCandidate, test ecx,0x2080 at 0x10b69d48 when _Globopt_flag
is 0). Functions under #pragma optimize("", off), or turned /Od by C4740,
therefore compiled every MACRO_CALL to `call get` + `call eax` where the
original has one direct call. Optimised functions already inlined get(),
so their code is unchanged.

setBitFlagBasedOnWallTowerGatehouseOrKeep, setTerrain, updateGFXLayers,
updateMacroLayerRelated and updateGfxLayer go to 100%. The status refresh
also records clearSizeFiveBuildingFootprintAndMoats at 100% (its earlier /GL
gain) and placeStockpile at 99.3%.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmaL4CQf53VmKTVHqhH
The /Od inlining gate, the unroll veto, scheduler edges from address-taken
locals, copy-preference order, the airlock reload at a loop latch, the
volatile ?: refusal, FgCodeMotion's fall-through rule and stack weights
counted before cross-jumping, each with its c2.dll addresses and the source
lever where one was found. Also notes that a src/precomp header edit does
not rebuild the PCH.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmaL4CQf53VmKTVHqhH
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmaL4CQf53VmKTVHqhH

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

declaration/type change This requires changes to the generated/exported types or definitions.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant