Skip to content

Entities, projectiles and fire: 17 functions, 3 at 100% - #527

Draft
gynt wants to merge 55 commits into
mainfrom
reimpl/entities-projectiles-fire
Draft

gynt wants to merge 55 commits into
mainfrom
reimpl/entities-projectiles-fire

Conversation

@gynt

@gynt gynt commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

16 entity, projectile and fire functions plus the angleToRotationFrameIndex callee, rebuilt from the original's asm and jump tables. The functions were ported from gynt's catch-all branches: this branch is origin/main plus the copied files, compile fixes, matching work and status.

Measured with reccmp, with both the struct and the function resolvers enabled and main's /GL callees on.

3 of 17 functions at 100%. The others hit a wall: the blocker named for each was measured, and the source forms tried against it tied or scored worse.

At 100%

Function Address Ported at
EntityState::angleToRotationFrameIndex 0x00402BD0 new
EntityState::updateProjectileHeightAndCollision 0x004081E0 60.0%
EntityState::updateEntities 0x004087C0 56.4%

Hit a wall

Function Address Match Ported at Why it stops there
EntityState::spawnProjectileEntity 0x00404AE0 98.4% 70.4% entityID and the constant 1 swap edi/ebp; field-store scheduling (targetX before targetY measured worse).
EntityState::calculateEntityDrawOffset 0x004036F0 98.0% 24.2% The default arm scales x and y in the opposite order. Writing x*2 before y<<4 swaps the registers (-35 quick_diff), index locals -17.
EntityState::initializeProjectileVelocities 0x00403A20 92.9% 36.5% Case 4 divides by a magic multiply, and the case 1 call is tail-merged into case 2.
Entities::IgniteFireAtMiniTile 0x004052E0 91.3% 66.7% The original spills the tile and keeps the height in ebx.
Entities::UpdateEntity_CowFlying 0x00402180 90.5% 12.2% MSVC loads the graphic offset before the division and needs ebx for it.
EntityState::spawnProjectileImpactDebris 0x00405DA0 90.5% 78.9% The reflect-y arm is laid out in the first case instead of after the straight case.
EntityState::moveProjectileEntity 0x004084A0 90.1% 50.4% x87 fxch scheduling in the atan arm; unresolved .rdata constants and CRT calls.
EntityState::handleProjectileWallBounce 0x00403FF0 88.2% 74.9% The original re-tests deltaX and reloads deltaY in the axis chain where we keep them in registers, and keeps the last case's copy of the y-arm. One shared if/else after the switch costs 25 quick_diff points.
Entities::UpdateFireEntity 0x00405680 85.3% 30.5% Argument scheduling for the IgniteFireAtMiniTile calls picks different tail-merge points.
EntityState::processSeaGulls 0x00406900 81.2% 47.5% Allocator wall: the original keeps newMicroY/newMicroX in ebx/ebp and re-reads microY; ours CSEs microY into ebp and spills newMicroX (frame 0x24 vs 0x20). Declaration orders, operand swaps and read orders all tie or lose.
EntityState::processEntityHitBuildingOrUnit 0x00407190 80.0% 47.8% Layout wall: the original lays the unit-hit block before the poison-cloud block, ours after it. !(A && B), if (A && B) goto and empty then/else forms compile byte-identical; replacing goto cowSplat with a copy loses 1.7.
Entities::UpdateFlag_1_2_4_Entity 0x00402900 68.2% 47.3% The original keeps 0 in edi and builds 3 with lea edx, [edi+3]; no zero-init or type change reproduces that constant register.
EntityState::math_atan_1 0x00402C50 66.0% 56.9% The original does fild/fimul straight from the parameter home slots; ours spills the scaled ints to a temp. Six expression forms tie. CRT calls and .rdata constants are also unresolved in the DLL.
EntityState::computeLineOfSightDistance 0x00402E20 37.1% 8.2% Layout wall: the original places each walk's loop body out of line, ours keeps it contiguous. Our block order follows source order through every compiler stage (checked with c2 tuple dumps), and labels/gotos leave the emitted layout unchanged. The original exe has no /GL or PGO objects.

Behaviour fixes

These were wrong in the decompiler output and are fixed against the binary:

  • UpdateEntity_CowFlying: the frame cap fires at >= 120 (Ghidra had > 120).
  • updateProjectileHeightAndCollision: a projectile above 10000 is destroyed and the function returns instead of still writing the rotation frame.
  • UpdateFlag_1_2_4_Entity: a frame <= 0 resets the animation and returns without adding to graphicType2.
  • processSeaGulls: the circling angle wraps when it reaches 360; it used to sit at 360 for a tick.
  • handleProjectileWallBounce: the wall-flag tile is microX / 8 divided signed, as in the original.
  • types commits: Entity::speedUnk is a float (as an int the accumulated speed was truncated every tick), Entity.graphicRotationUnk is a short, spawnEntityEffect1 takes int x/y.

Type and header changes are in their own types: commits. Resolver flags are not committed.


🤖 Generated with Claude Code

https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ

gynt and others added 30 commits November 28, 2026 13:56
…rojectiles-fire

Their best match lives only on gynt's catch-all branches, which are ~2080 cpp
files ahead of their merge base and 412 commits behind main. The cpp files are
copied unchanged, without the headers of those branches:
- gynt/reimpl/UI-DisplayElements-pr-development@fbc092e15 (16)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ
Renamed fields, globals and resolvers by address, enum-typed arguments,
array fields indexed directly, clang-format.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ
SHC_3BB0A8C1_0x00402180 12.2% UpdateEntity_CowFlying
SHC_3BB0A8C1_0x00402900 47.3% UpdateFlag_1_2_4_Entity
SHC_3BB0A8C1_0x00402C50 56.9% math_atan_1
SHC_3BB0A8C1_0x00402E20 8.2% computeLineOfSightDistance
SHC_3BB0A8C1_0x004036F0 24.2% calculateEntityDrawOffset
SHC_3BB0A8C1_0x00403A20 36.5% initializeProjectileVelocities
SHC_3BB0A8C1_0x00403FF0 74.9% handleProjectileWallBounce
SHC_3BB0A8C1_0x00404AE0 70.4% spawnProjectileEntity
SHC_3BB0A8C1_0x004052E0 66.7% IgniteFireAtMiniTile
SHC_3BB0A8C1_0x00405680 30.5% UpdateFireEntity
SHC_3BB0A8C1_0x00405DA0 78.9% spawnProjectileImpactDebris
SHC_3BB0A8C1_0x00406900 47.5% processSeaGulls
SHC_3BB0A8C1_0x00407190 47.8% processEntityHitBuildingOrUnit
SHC_3BB0A8C1_0x004081E0 60.0% updateProjectileHeightAndCollision
SHC_3BB0A8C1_0x004084A0 50.4% moveProjectileEntity
SHC_3BB0A8C1_0x004087C0 56.4% updateEntities

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ
All three fix behaviour the decompiler output got wrong:

- UpdateEntity_CowFlying 12.2 -> 90.5: the frame cap fires at >= 120 (Ghidra
  had > 120), the frame division is a division again, the airborne arm comes
  first and the counter is decremented through a pointer. Left: MSVC loads
  the graphic offset before the division and needs ebx for it.
- updateProjectileHeightAndCollision 60.0 -> 79.5: a projectile above 10000
  is destroyed and the function returns (Ghidra fell through and still wrote
  the rotation frame); the ground test reads the stored height. Left: the
  original keeps the height in edx across the rotation-frame call (LTCG).
- UpdateFlag_1_2_4_Entity 47.3 -> 53.9: a frame <= 0 resets the animation and
  returns without adding to graphicType2; the locals are int (the original
  sign-extends), the AI tracker tests put the != 0 arms first. Left: the
  original re-reads someTracker for the switch and keeps 0 in edi.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ
- IgniteFireAtMiniTile 66.7 -> 71.7: the existing-fire update comes before
  the spawn path and returns 0 (the original lays it out first), the tower
  and gatehouse cases return directly, the fire-strength test reads
  `two > fireParameter_0xb6`, and the decompiler locals are named consts.
  Left: the parameter is loaded before the jitter table entry is added.
- math_atan_1 56.9 -> 57.1: the 96.275344 constant multiplies the shared
  d * d. Left: the original reuses the dead parameter slots for the fild
  temporaries.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ
Maps an angle to one of nine rotation frames (0 at <= -50 through 8 at
<= 90, with 4 for the middle band and above 90). The original splits on
angle > 5 first and shares the return-4 block, which the nested
if/else form reproduces.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ
The original stores the height it read before angleToRotationFrameIndex
again after the call without reloading it (edx survives the call), which
takes LTCG with the callee compiled with /GL too.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ
24.2 -> 98.0. The sub-tile x and y are each one variable that the
orientation arms mirror and scale in place, as in the original, which
keeps x in ecx and y in eax throughout. Orientations 2 and 6 mirror one
axis and jump into the generic rotated arm's scaling, and orientation 4
mirrors both and falls into orientation 0's; the two labels are kept
because the original shares those blocks (a fall-through switch instead
compiles to a jump table).

Left: the default arm's two scalings are emitted in the opposite order.

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

- Fix: the RNG is advanced for entity IDs from 25 up; Ghidra's
  `25 < entityID` skipped entity 25 (the original tests `cmp 0x19; jl`).
- The three slot searches are plain for loops with the bounds the
  original tests, and the free-slot fallback (recycle fire/dust entities
  from slot 25) sits under the switch so the cases that allow it and the
  default share the one "everyTenTicks = 2999; return 0" exit, as in the
  original. The `entityType == -1` arm is the else, laid out last.
- The original compares currentGameMode before clearing colorUnk and
  then ignores the result; an if/else storing the same value in both
  arms reproduces the dead compare (+13 quick_diff points on its own).
- The dust-cloud / type-8 rng_1 block is written without gotos, and the
  tile-walkability checks read DAT_BinaryTileMap400x400 by name, y first.
- Field store order hill-climbed against the original.

Left: the 1 constant and entityID swap edi/ebp throughout.

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

Ghidra had flattened the per-orientation wall checks into goto chains
across shared blocks. Read back from the 13 jump tables, every mirrored
orientation does the same thing: mirror the sub-tile x and/or y, and on
a diagonal tie let the wall flags (one mask per quadrant) push x or y to
100, or fall back to the straight bounce; then reflect across x when
x > y, else across y. The cases now say that directly, in place on x
and y as the original keeps them, with the x = 100 arm first (which is
what lets MSVC share the arms between cases as the original does) and
the straight-bounce case last, reached from the both-walls arms.

Left: the reflect-y arm is emitted inside the first case rather than
after the straight case, so the two do not share the x_2 store.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ
Every access in the original is an x87 float op on it: moveProjectileEntity
loads it with `fld dword` and accumulates it with `fadd`/`fstp`,
updateEntities compares it with `fcomp dword`, and the two initialisers
clear it with `fldz`/`fstp`. As an int, moveProjectileEntity's
`speedUnk = (int)(accum + speed)` truncated the accumulated speed every
tick, which the game never does. The casts that bridged the wrong type
are dropped.

moveProjectileEntity 50.4 -> 58.8, updateEntities 56.4 -> 57.1,
initializeProjectileVelocities 36.5 -> 37.2.

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

- The wall-reflection switch is the same one spawnProjectileImpactDebris
  has (same 13 tables, same shared arms), written the same way.
- Fix: the tile passed to the wall-flag lookup is microX / 8 divided
  signed, as the original does (cdq/sar); it was divided unsigned.
- microX/microY are read once as ints instead of being kept twice, as a
  short and as an int.
- someMicroX/Y are `cond ? 1 : -1`, the original's setle/lea pair.
- The axis classification is an else-if chain whose first test is
  `deltaX == 0 && deltaY == 0`, as the original's re-test shows.
- The bounce tail gives each value its own local, and reads the
  velocity field back after storing it, so the stored value is reused
  for both trig products as in the original rather than one converted
  double kept across the cos call.

Left: the axis chain, where the original re-tests deltaX and reloads
deltaY that we keep in registers, and the reflect-y arm's placement.

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

The path setup is the same block handleProjectileWallBounce has, and
gets the same treatment:
- The three delta comparisons are written in the original's operand
  order (`y > targetY`, `x > targetX`, `height >= targetZ`), and so is
  the case-2 height test.
- someMicroX/Y are `cond ? 1 : -1` (setle/lea).
- The axis classification is the else-if chain led by
  `deltaX == 0 && deltaY == 0`.
- The axis-case 3/4 error steps compute the doubled straight step once
  in a local and read the other delta from its field, without the
  label the decompiler shared the pathError store through.

Left: allocation in the path setup (deltaX is spilled), and the curve
dispatch's register assignment.

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

The decompiled body was rewritten from the original instruction stream:
- One `clearance` counter (the original keeps it in a register in three
  branches and in a stack slot in the y-major one, which is what made
  Ghidra show two variables), clamped to 28 only for the straight cases.
- `clear` and `blocked` are dword BOOLs, `building` an int read from the
  start tile, `lastHeight` one variable shared by the prescans and the
  walks.
- The four walks (vertical, y-major, x-major, horizontal) are plain
  counted loops with the original's operand orders: `y > targetY`,
  `height > targetHeight + 54`, `dY > dX`, `abs(cur - start)`, and the
  LogicLayer value read once for both flag tests.
- The prescans are `for (i = 1; i < n; i++)` over the rows/columns next
  to the target.

Left: block layout. The original places the part of the first three
walks after their first if/else at the end of the function, behind the
horizontal walk; no source form tried (loop forms, branch orders,
arm orders) reproduces that.

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

- The distance and height are scaled as ints before the conversion
  (`lea [eax*4]`, the signed `/ 2`), so the height term multiplies an
  int (`fimul`) instead of a converted double.
- One `tangent` variable for both roots, as the original keeps both in
  the same stack slot.
- The angle is `a < b ? a : b`, then the max on the `< -90` path.
- `x == inf` with the global on the right, which gives the original's
  `fld; fucomp`.

Left: the original writes the scaled ints back into the parameter
slots, where ours uses a stack temp; the CRT calls and the rdata
constants do not resolve in reccmp.

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

- Bug fix: the circling angle wraps when it reaches 360
  (`cmp ax, 0x168; jl`); the decompiled `360 < angle` let it sit at 360
  for a tick.
- The path step and the destination search swap places: the original
  tests `close to the destination || no path left` and lays the
  destination search out first, the path step after it.
- `abs()` for the closeness tests, the int->double radius converted once
  per circle, declarations at first use, no decompiler copies of
  fields.
- The pathAxisCase-4 straight step really adds entity.someMicroX
  (`[edi + 0x74]` with edi the entity), not the seagull's step; kept.

Left: microY stays in a register between the closeness test and the
dive target in ours, the original re-reads it, which costs one stack
slot (frame 0x24 vs 0x20) and shifts the call arguments' registers.

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

Indexing every access by DAT_CurrentEntityID::instance instead of a
local copy makes MSVC re-read someTracker for the switch and add to
graphicType2 in memory after the intermediate stores, as the original
does, and share the default arm's epilogue.

Left: the original keeps 0 in edi for the comparisons and the reset
store; ours uses immediates.

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

- The random jitter is added to miniTileX/miniTileY themselves, which is
  what puts both coordinates in callee-saved registers before the
  offset table index is dead, as the original does.
- The map bounds and the binary-tile-map test are two early returns;
  combined in one condition, MSVC moved the return block to the end.
- `two >= 3`, so the 3 is shared with the RandomLayer mask in a
  register.
- The binary tile map is read through its named field.

Left: the original spills the tile after the tree check and keeps the
height in ebx for both spawns; ours keeps the tile in ebx.

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

Ghidra lost track of the x87 stack in this function and decompiled the
angle from uninitialised `extraout_ST*` values. Followed through the
original's stack, the projectile's elapsed time (speedUnk), vCos and vSin
are loaded once as doubles before the early return, and:

  distance = vCos * t, rise = vSin * t - t * t * 4.906
  dx = (long)(distance / 4), targetHeight = (long)(2 * rise)
  angle = t != 0
      ? atan((rise - rise(t - accumulator)) / (distance - vCos * (t - accumulator)) * 3) in degrees
      : startingAngle

The `t != 0` test is on the elapsed time; the decompile showed vSin.
The atan arm is the fall-through, as in the original.

Left: ours converts (long)angle once and reuses it in the loop, the
original calls _ftol again in every step.

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

graphicRotationUnk is decremented and tested `jg` against zero in
updateEntities, and the decompile already cast every read to (short);
as a word, `x - 1` compiled to an `add 0xffff` immediate where the
original reuses its -1 register. moveProjectileEntity 72.2 -> 87.9 on
this change alone, no other user moved.

Every caller of spawnEntityEffect1 sign-extends x and y with movsx and
pushes a dword, which is what an int parameter looks like; the callee
only reads the low word.

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

The decompile jumped between the state switch, the type switch and the
loop tail with gotos. Rebuilt from the three jump tables instead: the
state cases in the original's layout order with `continue` for the arms
that skip the rest of the loop body, the type cases grouped as the byte
index table groups them, and the poison cloud's eight directions in
table order so the two arms that end in `microY + 1` share one tail.

`newMaxEntityCount = id + 1` comes before the total-count increment,
as the original computes it from the id it already has in a register.
`& 7U` keeps the direction mask at int width (`and ecx, 7`); with `& 7`
MSVC narrowed it to a byte `and cl, 7` plus a movsx.

moveProjectileEntity moves to 87.9 on the graphicRotationUnk type fix.

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

The curve-type 9 and 10 arms and the collision update share a single
`return TRUE`, and the `height < targetZ` test is the if of an if/else
with the `> targetZ` arm. With an early return per arm MSVC shared the
constant 1 between the return value and `height + 1` (`add [..], ax`);
the original adds the immediate.

Left: the atan arm's x87 scheduling (same operand stack, different
fxch order) and the rdata constants / CRT helpers reccmp does not
resolve.

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

Rewritten block by block from the original instead of restyling the
decompile: named layers instead of raw addresses and `tile * 2` byte
offsets, `/ 8` for the position, the bounds tests with the literals the
asm compares against, the building-type jump table as a switch, and the
hit types as one else-if chain in the original's test order. The
original's `if (x) A; else B` layout decides most of the arm order
(flags, brazier, water/ground, cow hit).

Two gotos stay because the original shares the block: a unit hit by a
flying cow jumps into the cow splat, and a pitch ditch found next to an
arrow jumps into the ditch ignition.

Left: the unit-hit loops are laid out after the fire-arrow arm where the
original only moves their exit handlers there, and the register
assignment in the rock arm.

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

- xPosition is computed before yPosition, and the entity type is read
  after the tile, so the early-exit paths stay out of edi and its push
  moves past them as in the original.
- The out-of-map test is two early returns (range, then the binary map),
  which keeps the logicalState = 3 block inline.
- A unit hit by a flying cow tests for the cow first.
- The rock arm tests `flags & 0x40100001` and `flags & 0x100` twice
  rather than naming them: the original keeps those as spilled temps
  and gives the damage values the registers.

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

- One frame value for every tracker state: the negative-tracker arm sets
  it to 1 and the shared `frame <= 0` test decides between the animation
  reset and the graphicType2 store, which is the single store the
  original jumps back to.
- Each tracker arm tests `fireParameter >= 3` first, so the shared
  small-fire lookup is the copy MSVC places after the last arm.
- The spread to the four neighbours is an if/else-if chain on the
  direction with an abs() height test, replacing the decompiler's gotos.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ
78.1 -> 79.2. The original loads pathStepX first in the axisCase 4
diagonal arm, which is the order the source assigned the two fields in.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ
The original tests the LogicLayer blocking bit with `test al, al; js`, which
is what `flags & 0x80` compiles to; `(char)flags < 0` gives `jl` (29.6 -> 35.3).
The remaining gap is block layout: the original places the second half of
three of the four loop bodies after the dY == 0 loop, where ours keeps each
loop contiguous whatever the order of the branches in the source.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ
The curve type dispatch is an if-chain over 0..10 with two shared tails; the
gotos are gone and the locals the decompiler invented with them (62.1 -> 92.9):
- pathDeltaX is stored in both arms like pathDeltaY, so the axis tests read
  the field instead of a spilled local
- the bit tests on rng_1 are plain masks in 32-bit registers; the (byte)
  casts turned them into byte arithmetic
- the line-of-sight distance is held as the int the callee returns
- case 2 reads the entity type before storing the fallback angle

What is left: case 4's first `% 20` becomes a magic multiply where the
original keeps 20 in edi for both divisions, and case 1's computeVelocity call
is tail-merged into case 2's.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ
Declaring newY before newMicroX matches the original's register
assignment for the wander target. 79.2% -> 81.2%.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ
@github-actions github-actions Bot added the declaration/type change This requires changes to the generated/exported types or definitions. label Nov 30, 2026
@github-actions

Copy link
Copy Markdown

Style guide reading (advisory, posted once)

114 possible deviation(s) from REIMPLEMENTATION_STYLE_GUIDE.md across 17 of the 17 reimplemented .cpp file(s) in this PR.

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.

rule what it asks hits
8 Let the compiler unroll 1
9 Prefer for over while/do 1
14 The shape of a file 17
15 Write - 1, not + -1 4
16 Give variables a name that says what they hold 11
18 Use the name, not the number 29
20 Keep nesting low; no goto 36
22 Prefer descriptive code 2
23 Prefer if-else over ternary 8
24 Declare variables upon first use 5
Where

Rule 8 — Let the compiler unroll

  • src/OpenSHC/Map/Entities/EntityState/processEntityHitBuildingOrUnit.cpp:166 — loop steps by 2; try the plain loop and let MSVC unroll

Rule 9 — Prefer for over while/do

  • src/OpenSHC/Map/Entities/EntityState/moveProjectileEntity.cpp:61 — while-loop; the guide asks for a for

Rule 14 — The shape of a file

  • src/OpenSHC/Map/Entities/EntityState/angleToRotationFrameIndex.cpp:1 — first include is not EntityState; the folder is the class
  • src/OpenSHC/Map/Entities/EntityState/calculateEntityDrawOffset.cpp:1 — first include is not EntityState; the folder is the class
  • src/OpenSHC/Map/Entities/EntityState/computeLineOfSightDistance.cpp:1 — first include is not EntityState; the folder is the class
  • src/OpenSHC/Map/Entities/EntityState/handleProjectileWallBounce.cpp:1 — first include is not EntityState; the folder is the class
  • src/OpenSHC/Map/Entities/EntityState/initializeProjectileVelocities.cpp:1 — first include is not EntityState; the folder is the class
  • src/OpenSHC/Map/Entities/EntityState/math_atan_1.cpp:1 — first include is not EntityState; the folder is the class
  • src/OpenSHC/Map/Entities/EntityState/moveProjectileEntity.cpp:1 — first include is not EntityState; the folder is the class
  • src/OpenSHC/Map/Entities/EntityState/processEntityHitBuildingOrUnit.cpp:1 — first include is not EntityState; the folder is the class
  • src/OpenSHC/Map/Entities/EntityState/processSeaGulls.cpp:1 — first include is not EntityState; the folder is the class
  • src/OpenSHC/Map/Entities/EntityState/spawnProjectileEntity.cpp:1 — first include is not EntityState; the folder is the class
  • ... and 7 more

Rule 15 — Write - 1, not + -1

  • src/OpenSHC/Map/Entities/EntityState/spawnProjectileEntity.cpp:132 — writes + -N; the readable form is - N
  • src/OpenSHC/Map/Entities/EntityState/spawnProjectileEntity.cpp:133 — writes + -N; the readable form is - N
  • src/OpenSHC/Map/Entities/EntityState/spawnProjectileEntity.cpp:135 — writes + -N; the readable form is - N
  • src/OpenSHC/Map/Entities/EntityState/spawnProjectileEntity.cpp:136 — writes + -N; the readable form is - N

Rule 16 — Give variables a name that says what they hold

  • src/OpenSHC/Map/Entities/EntityState/handleProjectileWallBounce.cpp:24 — decompiler name sVar4
  • src/OpenSHC/Map/Entities/EntityState/handleProjectileWallBounce.cpp:25 — decompiler name iVar5
  • src/OpenSHC/Map/Entities/EntityState/handleProjectileWallBounce.cpp:26 — decompiler name sVar7
  • src/OpenSHC/Map/Entities/EntityState/handleProjectileWallBounce.cpp:27 — decompiler name sVar8
  • src/OpenSHC/Map/Entities/EntityState/handleProjectileWallBounce.cpp:28 — decompiler name iVar9
  • src/OpenSHC/Map/Entities/EntityState/handleProjectileWallBounce.cpp:361 — decompiler name LAB_0040440f
  • src/OpenSHC/Map/Entities/EntityState/spawnProjectileEntity.cpp:27 — decompiler name bVar1
  • src/OpenSHC/Map/Entities/EntityState/spawnProjectileEntity.cpp:28 — decompiler name dVar2
  • src/OpenSHC/Map/Entities/EntityState/spawnProjectileEntity.cpp:29 — decompiler name uVar5
  • src/OpenSHC/Map/Entities/EntityState/spawnProjectileEntity.cpp:30 — decompiler name uVar6
  • ... and 1 more

Rule 18 — Use the name, not the number

  • src/OpenSHC/Map/Entities/EntityState/computeLineOfSightDistance.cpp:34 — hex constant 0x10000000; use a name, or decimal
  • src/OpenSHC/Map/Entities/EntityState/computeLineOfSightDistance.cpp:66 — hex constant 0x400300; use a name, or decimal
  • src/OpenSHC/Map/Entities/EntityState/computeLineOfSightDistance.cpp:76 — hex constant 0x400200; use a name, or decimal
  • src/OpenSHC/Map/Entities/EntityState/computeLineOfSightDistance.cpp:132 — hex constant 0x400300; use a name, or decimal
  • src/OpenSHC/Map/Entities/EntityState/computeLineOfSightDistance.cpp:142 — hex constant 0x400200; use a name, or decimal
  • src/OpenSHC/Map/Entities/EntityState/computeLineOfSightDistance.cpp:195 — hex constant 0x400300; use a name, or decimal
  • src/OpenSHC/Map/Entities/EntityState/computeLineOfSightDistance.cpp:205 — hex constant 0x400200; use a name, or decimal
  • src/OpenSHC/Map/Entities/EntityState/computeLineOfSightDistance.cpp:238 — hex constant 0x400300; use a name, or decimal
  • src/OpenSHC/Map/Entities/EntityState/computeLineOfSightDistance.cpp:248 — hex constant 0x400200; use a name, or decimal
  • src/OpenSHC/Map/Entities/EntityState/initializeProjectileVelocities.cpp:124 — hex constant 0x8000; use a name, or decimal
  • ... and 19 more

Rule 20 — Keep nesting low; no goto

  • src/OpenSHC/Map/Entities/EntityState/calculateEntityDrawOffset.cpp:22 — goto; check how many predecessors the target has first
  • src/OpenSHC/Map/Entities/EntityState/calculateEntityDrawOffset.cpp:26 — goto; check how many predecessors the target has first
  • src/OpenSHC/Map/Entities/EntityState/calculateEntityDrawOffset.cpp:32 — goto; check how many predecessors the target has first
  • src/OpenSHC/Map/Entities/EntityState/handleProjectileWallBounce.cpp:50 — goto; check how many predecessors the target has first
  • src/OpenSHC/Map/Entities/EntityState/handleProjectileWallBounce.cpp:73 — goto; check how many predecessors the target has first
  • src/OpenSHC/Map/Entities/EntityState/handleProjectileWallBounce.cpp:96 — goto; check how many predecessors the target has first
  • src/OpenSHC/Map/Entities/EntityState/handleProjectileWallBounce.cpp:118 — goto; check how many predecessors the target has first
  • src/OpenSHC/Map/Entities/EntityState/handleProjectileWallBounce.cpp:140 — goto; check how many predecessors the target has first
  • src/OpenSHC/Map/Entities/EntityState/handleProjectileWallBounce.cpp:162 — goto; check how many predecessors the target has first
  • src/OpenSHC/Map/Entities/EntityState/handleProjectileWallBounce.cpp:185 — goto; check how many predecessors the target has first
  • ... and 26 more

Rule 22 — Prefer descriptive code

  • src/OpenSHC/Map/Entities/EntityState/processEntityHitBuildingOrUnit.cpp:79 — unsigned range trick; spell the two bounds out
  • src/OpenSHC/Map/Entities/EntityState/processEntityHitBuildingOrUnit.cpp:244 — unsigned range trick; spell the two bounds out

Rule 23 — Prefer if-else over ternary

  • src/OpenSHC/Map/Entities/EntityState/computeLineOfSightDistance.cpp:52 — ternary; the guide prefers extending the if-else chain
  • src/OpenSHC/Map/Entities/EntityState/computeLineOfSightDistance.cpp:53 — ternary; the guide prefers extending the if-else chain
  • src/OpenSHC/Map/Entities/EntityState/handleProjectileWallBounce.cpp:338 — ternary; the guide prefers extending the if-else chain
  • src/OpenSHC/Map/Entities/EntityState/handleProjectileWallBounce.cpp:340 — ternary; the guide prefers extending the if-else chain
  • src/OpenSHC/Map/Entities/EntityState/initializeProjectileVelocities.cpp:39 — ternary; the guide prefers extending the if-else chain
  • src/OpenSHC/Map/Entities/EntityState/initializeProjectileVelocities.cpp:40 — ternary; the guide prefers extending the if-else chain
  • src/OpenSHC/Map/Entities/EntityState/math_atan_1.cpp:37 — ternary; the guide prefers extending the if-else chain
  • src/OpenSHC/Map/Entities/EntityState/math_atan_1.cpp:39 — ternary; the guide prefers extending the if-else chain

Rule 24 — Declare variables upon first use

  • src/OpenSHC/Map/Entities/EntityState/handleProjectileWallBounce.cpp:24 — declare sVar4 where it is first assigned
  • src/OpenSHC/Map/Entities/EntityState/handleProjectileWallBounce.cpp:27 — declare sVar8 where it is first assigned
  • src/OpenSHC/Map/Entities/EntityState/processEntityHitBuildingOrUnit.cpp:236 — declare groundHeight where it is first assigned
  • src/OpenSHC/Map/Entities/EntityState/processEntityHitBuildingOrUnit.cpp:254 — declare hitType where it is first assigned
  • src/OpenSHC/Map/Entities/EntityState/spawnProjectileEntity.cpp:31 — declare sVar7 where it is first assigned

gynt and others added 2 commits December 2, 2026 16:22
Conflicts: EntityState.hpp and EntityState.func.hpp take main's headers
(main already types spawnEntityEffect1 with int x/y and EntityType);
compiler-flags-gl.txt keeps both sides' entries.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
- angleToRotationFrameIndex returns int, as main declares it.
- Entity::unkMinusOne is blendStrength on main (spawnProjectileEntity,
  UpdateFireEntity).
- spawnEntityEffect1/2 take an EntityType; updateEntities passes the
  entity types 5 and 6, which have no named constant yet.

Every function keeps its match (3 at 100%, the other 14 unchanged).

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

# Conflicts:
#	cmake/compiler-flags-gl.txt
Pass the buildingID local to lightUpBuilding, and give IgniteFireAtMiniTile sight of getFireEntityIDAtTile: the original rematerialises buildingID from BuildingLayer after that call, which it can only do when it knows the callee leaves the layer alone.

Measured 100% with OPENSHC_FUNCTION_VISIBILITY_UNITS=ON (function-visibility.txt: IgniteFireAtMiniTile -> getFireEntityIDAtTile); the file is also in compiler-flags-gl.txt, where it measures 94.2%. getFireEntityIDAtTile is deliberately not added to compiler-flags-gl.txt: with it there, /GL gives IgniteFireAtMiniTile 100% too, but lightUpBuilding drops from 100% to 56%.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp
@github-actions github-actions Bot removed the declaration/type change This requires changes to the generated/exported types or definitions. label Dec 3, 2026
gynt and others added 8 commits December 4, 2026 00:31
Straight-wall case moved to the top of the switch and the inner wall-flag arms reordered (the arm holding case 0 second), so the cross-jumped arms and the reflect-y block land where the original has them. Visibility-unit build mode, both resolver sets on: reccmp 100%.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp
…y float constant names and the CRT math helpers (_CIcos, _CIsin) differ)

Same switch-arm order as spawnProjectileImpactDebris; the axis chain and the Bresenham steps read pathDeltaX/pathDeltaY from the entity instead of a short local, which gives the original's re-tests and reloads. reccmp 99.7%, the rest is the unresolved rdata constants and the CRT cos/sin names. Visibility-unit build mode, both resolver sets on.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp
…y float constant names and the CRT math helpers (_CIcos, _CIsin) differ)

Case 4 reads rng_1 from the entity for the modulo, so both % 20 stay idiv against edi as in the original instead of a magic multiply, and vCos/vSin read velocityUnk from the entity so the int-to-double temp shares the y parameter slot. reccmp 98.5%, the rest is the unresolved rdata constants and the CRT cos/sin names. Visibility-unit build mode, both resolver sets on.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp
The entity index local is int, not uint; with it the graphicType2RelatedOffset load is scheduled after the division and needs no ebx. Visibility-unit build mode, both resolver sets on: reccmp 100%.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp
The unrotated arm doubles x first, as a shift (x << 1), then shifts y; the original computes x*2 before y<<4 there. tuple_dump showed the IL already held y<<4 first, so the order is the source's, not the scheduler's. Measured with both resolver sets, full build + reccmp.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp
…fter the field re-read; rock-arm register naming

The unit-hit test reads the entity's type from the field for its first compare. With the local there, MSVC threads the rng_2 != 2 edge past the type tests (it knows type == 1), so FgCodeMotion pulled the cloud code up and pushed both unit loops after the fire-arrow arm. Reading the field keeps the original's inline layout. The field and the local hold the same value here: nothing writes entityType on this path. Measured with both resolver sets, full build + reccmp.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp
…riginal keeps newMicroX; microY CSE kept in a register

One radians variable reused for both angles, as the original's shared [esp+0x1c] slot shows: frame 0x24 -> 0x20.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp
…t enregistered and clearance in esi instead of ebp

Set-up chain first, then a mode dispatch to the four loops. Jump threading removes the dispatch after DFO has placed the loops after all preludes, which gives the original's heads-first, bodies-after-returns layout. Clearance arms flipped so clearance-- falls through.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp
gynt added a commit to gynt/OpenSHC that referenced this pull request Dec 4, 2026
From draft sourcehold#527. Measured 68.2% raw / 68.2% normalized on main 592a17d.

The original keeps 0 in edi: it compares against edi instead of 0, stores di for 0, builds 3 as
lea edx, [edi + 3], and pushes/pops edi. Ours uses immediates and test reg, reg, and pops esi before
the jump table. Block order, stores and computation are the same, so nothing differs in behaviour.

Status: SHC_3BB0A8C1_0x00402900 | 68.2% | Register allocation differs

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp
gynt and others added 8 commits December 5, 2026 04:27
…ctiles-fire

# Conflicts:
#	cmake/compiler-flags-gl.txt
moveProjectileEntity gains from main's _ftol2_sse, 180.0 and pi rows (90.1 -> 93.1). Operand-order and declaration-order variants of the atan argument all stay at quick_diff 0.9544; the remaining gaps are the x87 order, a loop-top pad that depends on the function's address, and four constants (0x59e898 4.906, 0x59e890 0.25, 0x59e880 3.0, 0x57ee10 __CIatan) that need float-literals.csv rows; with them it reads 94.8.

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

The original reloads microY for newMicroY instead of keeping the value from the abs() test; a read through a
reference is not merged with the direct one (cheat sheet). newMicroX is computed first, as the original loads
someMicroX before dividing newMicroY. 90.0 -> 90.8; newY still takes ebp where the original keeps newMicroX.

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

The original reads entityType at the seagull test and keeps it in ecx only up to a switch on the flag, brazier
and heads-on-spikes types (add eax, -0xa; cmp eax, 5 is a switch range check); later tests re-read the field.
Without the long-lived local, this and tile get ebx and ebp as in the original and edi is no longer saved in the
prologue. 80.8 -> 84.2.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp
math_atan_1 gains from main's _CIsqrt, _ftol2_sse, 9.812, 180.0 and pi rows (66.0 -> 72.6); with rows for
0x59e860 96.275344, 0x59e858 1.0, 0x59e840 0.4999, 0x57ecf1 _isnan and 0x57ee10 __CIatan it reads 79.2.
Expression, declaration and local-vs-parameter variants all leave the spill slots unchanged.

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

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

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant