fix(physics): close the AP-156 fix review — real containment oracle, type-level invariant, AP-158

Both review lenses PASSED; this is the cleanup, not a rescue. Evidence:
docs/research/2026-08-06-ap156-review-closure.md (the review itself is
committed alongside it as the received artifact).

R1 — the load-bearing containment test could not fail. Its truth and flood
values were two hand-copies of the same expression over the same part set,
so the shortfall was algebraically identically zero for any DAT input. The
oracle is now PHYSICS-POLYGON VERTICES — a different DAT field from the
bounding sphere the builder emits, so the two sides can genuinely disagree.
Sabotage-verified three ways after full cleans: dropping the bounds centre
in production reddens it (428 Setups, worst 35.869 m on 0x0200129A, matching
an independent out-of-repo sweep exactly); dropping only the scale on the
centre reddens it (326); and corrupting the TEST's own bounds oracle reddens
it (467) where under the shipped oracle that same corruption was invisible
by algebra. Renamed accordingly. A6's stale "cap control" comment corrected:
that loop is the test's own uncapped re-implementation and cannot observe a
cap regression — the cap is covered in Core.

R2 — the population was understated. 172 is AP-152's DISPATCH population;
AP-156's is 530 BSP-bearing Setups, of which 525 have a flood sphere move
and 428 fail vertex containment before the fix (412 at a 1 cm tolerance —
the review's figure; the gap is 16 Setups between 1.4 mm and 10 mm, real
geometry). 0 fail after, at any tolerance down to zero. Corrected in the
AP-156 row, the section-3 header, the C5c handoff and two test docstrings.
Dated review artifacts are left as written — "170 of 172" was correct for
what they measured, and rewriting evidence to match a later measurement
loses provenance.

A1 — BoundsCenter = default reopened at the type what the commit closed at
the seam. Dropping the default alone would NOT have closed the review's own
scenario (a copied Cylinder call site would write Vector3.Zero explicitly
and stay green), so ShadowShape's constructor is now private and BSP shapes
are built only through ShadowShape.Bsp(..., FlatCollisionSphere localBounds),
which takes radius and centre as ONE value and scales them together. There
is no expression a caller can write that carries one and drops the other.
22 construction sites converted; the same sabotage now reddens 5 Core tests
where the review's sabotage A reached 4, because both BSP producers share
one scaling path.

A2 — #333 is real and bigger than filed, and its retail question is
answered. I disassembled CObjCell::find_obj_collisions @0x0052b750 from the
PDB-paired binary myself (check_exe_pdb.py MATCH) rather than inheriting the
claim: its only early-out is sphere_path.insert_type == INITIAL_PLACEMENT_
INSERT, then it calls FindObjCollisions on every unparented non-self shadow
object UNCONDITIONALLY. Retail has NO distance pre-filter, so acdream's
"+ movement + 2f" reach filter is an invention with no register row — filed
as AP-158, carrying the disassembly, the F_EPSILON = 0.0002 m contrast, and
the measured blast radius (118 of 477 unique installed physics-BSP GfxObjs
exceed its ~2.5 m budget, 46 exceed 5 m). Active AP rows 109 -> 110.

Recorded prominently in three places a reader will hit: TALL PROPS MAY SHOW
NO VISIBLE CHANGE UNTIL #333 LANDS, and a null result at the connected gate
is EXPECTED, not evidence against AP-156.

LOW items. R3: the comment claiming the cited evidence justified the whole
cap line is corrected, but int.MaxValue on the sorting-sphere branch stays —
capping at 1 would take Spheres[0], and retail's one sphere is
CSetup::sorting_sphere, a different DAT field; capping keeps the wrong field
AND flips the substitution under-inclusive (#98/#168 direction). AP-157
already owns it. R4: acdream scales the flood sphere where retail's
find_transit_cells never reads gfxobj_scale — added as a second residual on
AP-156. R5: retail's slack constant carried into AP-158 and #333. A3: the
per-call delegate allocation is back to a cached field, still derived from
the single bounds resolver. A5: noted; b52967de's message cannot be amended.

Gates: all 44 bin/obj deleted before every verdict-deciding build, each test
run gated on a verified "Build succeeded" in the same invocation. Release
build 0 errors / 21 pre-existing warnings. Complete suite 11,208 passed /
4 skipped / 0 failed — reconciles exactly with the e2b2d04c baseline; one
test renamed, none added, removed or skipped. Nothing conflated with the
known load-sensitive flakes #302 / #308 / #321.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Erik 2026-08-06 16:44:48 +02:00
parent e2b2d04cb5
commit e6457cc849
21 changed files with 1454 additions and 298 deletions

View file

@ -31,8 +31,50 @@ What does NOT go here:
downstream of the AP-156 membership fix, so that fix alone may not be enough to
make the worst objects block.
**Filed:** 2026-08-06 at the AP-156 fix (commit `b52967de`), which surfaced it.
**Updated 2026-08-06** at the AP-156 fix review: the retail question below is
now ANSWERED, and the filter has its own divergence row, **AP-158**.
**Do NOT bundle with AP-156.** Different code path (collision query, not cell
membership), and it needs its own retail question answered first.
membership).
### ANSWERED — retail has no distance pre-filter at all
Disassembled from the PDB-paired binary (`C:\Users\erikn\Downloads\acclient.exe`,
`check_exe_pdb.py` → MATCH, CodeView GUID `9e847e2f-777c-4bd9-886c-22256bb87f32`)
for this update, not inherited from Binary Ninja:
```
CObjCell::find_obj_collisions @0x0052b750
0x0052b759 cmp dword [ebx+0x174], 2 ; sphere_path.insert_type
0x0052b765 je 0x52b7a0 ; INITIAL_PLACEMENT_INSERT -> return OK_TS
0x0052b773 mov ecx,[edi+0xc8] ; shadow_object_list.data
0x0052b77f mov edx,[ecx+0x40] ; physobj->parent
0x0052b784 jne 0x52b795 ; parented -> skip
0x0052b786 cmp ecx,[ebx] ; physobj == mover?
0x0052b788 je 0x52b795 ; self -> skip
0x0052b78b call 0x50f050 ; CPhysicsObj::FindObjCollisions — UNCONDITIONAL
0x0052b79e jb 0x52b773 ; loop, bound = [edi+0xc4]
```
Agrees with `acclient_2013_pseudo_c.txt:308916-308940`. **There is no distance
test in the function.** So the `+ 2f` slack and the `movement.Length()` term are
acdream's own invention, which is why AP-158 exists. For scale: retail's own
cross-cell slack constant is `F_EPSILON` = `1.9999999e-4` — 0.2 mm, read at
`0x0052cb5f fld dword [0x7c8c70]` — not 2 m.
### Measured blast radius
Over the installed `client_portal.dat`, by an independent scratch sweep outside
the repo: **118 of the 477** unique physics-BSP GfxObjs have a root-sphere
offset above the filter's roughly 2.5 m walking budget, and **46** above 5 m. At
a test scale of 1.75 those offsets become 4.4 m and 8.75 m against an unchanged
budget.
### Consequence for the AP-156 connected gate — read this before running it
**Tall props may show NO VISIBLE CHANGE at all until this issue is fixed, and a
null result there is EXPECTED rather than evidence against AP-156.** AP-156 puts
the geometry into the correct cell; this filter then discards it one layer down,
for exactly the largest-offset objects AP-156's commit body points the user at.
### The mechanism
@ -78,11 +120,12 @@ finds a tall prop that still does not block after AP-156, look here first.
### What to establish before fixing
1. Does retail have this pre-filter at all? `CPhysicsObj::FindObjCollisions`
@0x0050f050 walks the cell's object list and dispatches per object; the
`+ 2f` slack and the `movement.Length()` term look like acdream's own
broadphase rather than a port. If it is acdream's, it also needs a
divergence-register row, which it does not currently have.
1. ~~Does retail have this pre-filter at all?~~ **ANSWERED above: no.** The
register row is filed as **AP-158**. What remains open is a judgement call,
not a research question: keep the filter as a deliberate optimisation with a
correct measurement point, or delete it and walk the list as retail does.
Deleting it is the retail-faithful option and should be costed first —
`ShadowEntrySnapshot.Capture` already bounds the per-cell list.
2. If it is kept, it must measure from where the geometry is: `ShadowEntry`
needs the `BoundsCenter` that `ShadowShape` now carries, and `deltaToCurr`
must be taken against `obj.Position + rotate(obj.BoundsCenter, obj.Rotation)`.

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,719 @@
# AP-156 fix review — `b52967de` + `e2b2d04c`
Adversarial dual-lens review of the AP-152 flood-sphere fix, prompted by the
FAIL in `docs/research/2026-08-06-ap152-review-retail.md`.
Worktree `.claude/worktrees/resume-session-e0bd03e1-d5bf45`, HEAD `e2b2d04c`.
All 44 `bin`/`obj` deleted before every verdict-deciding build. Six sabotages
applied and restored; `git status --porcelain` empty at the end.
## VERDICTS
| Lens | Verdict |
|---|---|
| **Retail conformance** | **PASS** |
| **Architecture** | **PASS** |
Three things the brief asked me to settle explicitly:
- **The containment claim — BELIEVED, and true more strongly than asserted.**
The shipped assertion is algebraically tautological (R1), so I re-derived
containment independently against physics-polygon **vertices** rather than
against the root sphere: **0 of 530** BSP-bearing Setups fail after the fix,
**412** failed before it.
- **The cap change — the implementer is RIGHT and both prior reviews were
WRONG.** Byte-verified: the `cmp eax,0xa` clamp is inside the cylsphere
overload only; the BSP walk is uncapped; `@0x0052b990` pushes a literal `1`.
- **The shrink argument — CORRECT, and both prior reviews used the wrong
criterion.** `calc_cross_cells`' BSP branch is reached through an
unconditional jump past both primitive branches, so retail's flood for these
objects contains no primitive contribution at all. "Smaller than before" is
not a defect criterion; containment is. My own sweep reproduces the
implementer's 143.
---
## Part 1 — Independent retail verification
Method: my own Capstone disassembly of the PDB-paired binary
(`C:\Users\erikn\Downloads\acclient.exe`, `check_exe_pdb.py`**MATCH**,
CodeView GUID `9e847e2f-777c-4bd9-886c-22256bb87f32`, linker
2013-09-06T00:17:56Z, image base `0x400000`), every address cross-resolved
through `named-retail/symbols.json` and every struct offset cross-checked
against `named-retail/acclient.h`. Not inherited from the commit, not from the
prior reviews.
### 1.1 Every cited address resolves to the construct claimed — all 12
`symbols.json` lookup by address:
| Address | Symbol |
|---|---|
| `0x0050f050` | `CPhysicsObj::FindObjCollisions` |
| `0x00510fc0` | `CPhysicsObj::find_bbox_cell_list` |
| `0x00515230` | `CPhysicsObj::calc_cross_cells` |
| `0x00518070` / `0x00518090` | `CPartArray::GetSphere` / `GetCylsphere` |
| `0x00518110` | `CPartArray::CacheHasPhysicsBSP` |
| `0x00518160` | `CPartArray::calc_cross_cells_static` |
| `0x00518b00` | `CPartArray::GetSortingSphere` |
| `0x0052b990` / `0x0052b9f0` | `CObjCell::find_cell_list` (two overloads) |
| `0x0052cae0` | `CEnvCell::find_transit_cells` |
| `0x005397e0` | `BSPTREE::GetSphere` |
| `0x004527f0` | `Position::localtolocal` |
No mis-cited neighbour anywhere in this commit, the register rows, or the
tests. (I looked specifically, given the mis-cite found earlier this session.)
### 1.2 `BSPTREE::GetSphere` @`0x005397e0` — claim 4b CONFIRMED byte-exact
```
0x005397e0 8b01 mov eax, dword ptr [ecx] ; BSPTREE::root_node
0x005397e2 83c004 add eax, 4 ; past BSPNODE::vfptr
0x005397e5 c3 ret
```
`acclient.h`: `struct BSPNODE { BSPNODEVtbl *vfptr; CSphere sphere; Plane
splitting_plane; ... }` and `struct CSphere { AC1Legacy::Vector3 center; float
radius; }` → radius at `+0xc` of the returned pointer. Retail's per-part flood
sphere **is** the BSP root bounding sphere, origin included.
`acclient_2013_pseudo_c.txt:319128` (`0x00534b5b`):
`this->physics_sphere = BSPTREE::GetSphere(this->physics_bsp);` — verbatim.
### 1.3 `physics_sphere` = `[gfxobj+0x74]`, `physics_bsp` = `[+0x78]` — claim 4c CONFIRMED
`acclient.h` `CGfxObj` field order: `... use_built_mesh; CSphere
*physics_sphere; BSPTREE *physics_bsp; Vector3 sort_center; unsigned
num_polygons; CPolygon *polygons; CSphere *drawing_sphere; ...` — which places
`physics_sphere` at `+0x74`, `physics_bsp` at `+0x78`, `drawing_sphere` at
`+0x90`. Confirmed against code:
```
CPartArray::CacheHasPhysicsBSP @0x00518110
0x00518120 8b32 mov esi,[edx] ; parts[i]
0x00518122 8b7620 mov esi,[esi+0x20] ; CPhysicsPart::gfxobj
0x00518125 8b36 mov esi,[esi]
0x00518127 8b7e78 mov edi,[esi+0x78] ; physics_bsp <-- exact addr
```
and `find_transit_cells` reads `[ecx+0x74]` with a `[ecx+0x90]` fallback — the
drawing sphere — which only makes sense with this layout.
### 1.4 `CEnvCell::find_transit_cells` @`0x0052cae0` — claim 4a CONFIRMED, centre-then-radius
```
0x0052cb31 8b5020 mov edx,[eax+0x20] ; CPhysicsPart::gfxobj
0x0052cb34 8b0a mov ecx,[edx]
0x0052cb36 8b7174 mov esi,[ecx+0x74] ; physics_sphere
0x0052cb39 85f6 test esi,esi
0x0052cb3d 8bb190.. mov esi,[ecx+0x90] ; else drawing_sphere
0x0052cb4b 56 push esi ; -> &sphere->center
0x0052cb4c 83c030 add eax,0x30 ; CPhysicsPart::pos
0x0052cb4f 50 push eax
0x0052cb50 8d442434 lea eax,[esp+0x34] ; out
0x0052cb54 8d5d54 lea ebx,[ebp+0x54] ; cell->pos
0x0052cb5a e8915cf2ff call 0x4527f0 ; Position::localtolocal
0x0052cb5f d905708c7c00 fld dword [0x7c8c70] ; F_EPSILON = 1.9999999e-4
0x0052cb65 d8460c fadd dword [esi+0xc] ; ONLY NOW the radius
```
`acclient.h` `CPhysicsPart`: `CYpt(0) viewer_heading(4) degrades(0x10)
deg_level(0x14) deg_mode(0x18) draw_state(0x1c) gfxobj(0x20)
gfxobj_scale(0x24) pos(0x30)` — both `+0x20` and `+0x30` are exactly what the
commit says they are.
The call is `cellPos.localtolocal(&out, &part->pos, &sphere->center)`: the
sphere's **centre** is transformed through the part's own `Position` into the
cell frame, and the radius is only added afterwards to build the plane test.
**Carrying the radius alone is a different sphere — the commit's thesis is
right.**
### 1.5 The 10-sphere cap — settled against the implementer's claim
**Claim: the cap lives only in the cylsphere overload. VERIFIED.**
```
CObjCell::find_cell_list @0x0052b9f0 (the N-sphere overload)
0x0052ba1d 8b442414 mov eax,[esp+0x14] ; count
0x0052ba21 83f80a cmp eax,0xa
0x0052ba26 760b jbe 0x52ba33
0x0052ba28 bd0a0000 mov ebp,0xa ; clamp
... copy loop into the STATIC array 0x844838..0x8448d8 (10 x 0x10 stride)
```
The clamp is a fixed static-buffer capacity, not a policy: the destination
array is exactly ten 16-byte entries and the guard byte at `0x8448d8` sits
immediately past it.
```
CObjCell::find_cell_list @0x0052b990 (the sorting-sphere overload)
0x0052b9d6 6a01 push 1 ; literal count of ONE
```
```
CPhysicsObj::calc_cross_cells @0x00515230
0x00515285 test dword [esi+0xa8],0x10000
0x0051528f jne 0x515305 ------------------> 0x0051530c call 0x510fc0 (BSP)
0x005152d1 call 0x52b9f0 (cylsphere, capped)
0x005152fb call 0x52b990 (sorting sphere, one)
```
```
CPhysicsObj::find_bbox_cell_list @0x00510fc0
loop over cells [esi+8], no clamp
0x00511012 call 0x518160
CPartArray::calc_cross_cells_static @0x00518160
0x0051816e mov esi,[eax+0x5c] ; parts
0x00518171 mov eax,[eax+0x58] ; num_parts
0x00518176 call dword [edx+0x7c] ; args (num_parts, parts, cellarray)
CEnvCell::find_transit_cells @0x0052cae0
inner part loop 0x52cb22 .. 0x52cc76, bound = [esp+0x6c] = num_parts
outer portal loop, bound = [ebp+0x108]
NO CLAMP ANYWHERE
```
**The implementer is correct on all three counts. Both prior reviews passed a
cap that retail does not have on that branch.** 7 installed Setups exceed 10
physics-BSP parts (max 49, Setup `0x02001A91` — reproduced independently), and
their tail parts were previously dropped from the flood outright. The change is
a correctness improvement in the same direction as the rest of the commit.
### 1.6 `CPartArray::GetSortingSphere` @`0x00518b00` (AP-157's anchor)
```
0x00518b67 8b4654 mov eax,[esi+0x54]
0x00518b6f 83c070 add eax,0x70
```
Exactly `[partArray+0x54] + 0x70`. `acclient.h` `CSetup` places
`CSphere sorting_sphere` immediately after `step_up_height`. AP-157's citation
holds.
### 1.7 Two retail facts the commit did not use, both relevant
**`CObjCell::find_obj_collisions` @`0x0052b750` has no distance pre-filter.**
Pseudo-C `308916-308940`: it walks `shadow_object_list` and calls
`CPhysicsObj::FindObjCollisions` on every non-parented, non-self entry
unconditionally. So the `maxReach` early-out at
`src/AcDream.Core/Physics/TransitionTypes.cs:3763` — `sphereRadius +
obj.Radius + movement.Length() + 2f` — is entirely acdream's own invention with
no retail counterpart. **#333's characterisation is correct.** See A2.
**Retail's own slack constant is 0.0002 m, not 2 m.** `0x0052cb5f fld dword
[0x7c8c70]` reads `1.9999999494757503e-4` (`F_EPSILON`). Anchor for whoever
fixes #333.
**Retail's cross-cell walk ignores part scale; its collision does not.**
`find_transit_cells` uses only `CPhysicsPart::pos` (`+0x30`) and never
`gfxobj_scale` (`+0x24`), while `CPhysicsPart::find_obj_collisions`
@`0x0050d8d0` explicitly passes `gfxobj_scale.z` into
`SPHEREPATH::cache_localspace_sphere`. See R4.
---
## Part 2 — Independent DAT re-derivation
Scratch console program **outside the repo**, referencing only
`Chorizite.DatReaderWriter 2.1.7` — deliberately **not** `AcDream.Core`, so
nothing under test is in the loop. Every number recomputed by hand from the
installed `client_portal.dat`.
| Quantity | Committed constant | My measurement |
|---|---|---|
| Setups | 5935 | **5935** |
| with CylSphere | 678 | **678** |
| Sphere-only, no CylSphere | 3605 | **3605** |
| without any primitive | 1652 | **1652** |
| with a physics-BSP part | 530 | **530** |
| physics-BSP parts | 973 | **973** |
| off-centre parts (`\|o\| > r/2`) | 376 | **376** |
| affected (primitive + BSP) | 172 (73 cyl / 99 sph) | **172 (73 / 99)** |
| deepest BSP part array | 49, `0x02001A91` | **49, `0x02001A91`** |
| Setups with > 10 BSP parts | 7 | **7** |
| worst part-origin offset | 20.762 m on gfx `0x010036DD` (r 27.708) | **20.762 m, gfx `0x010036DD`, r 27.708** |
| affected Setups failing containment pre-fix | 170 | **170**, worst 17.345 m at scale 1.75 = **9.911 m at scale 1**, Setup `0x02000255` |
| affected Setups failing post-fix | 0 | **0** |
| 143-shrink claim | 143 of 172 | **143** |
| max Spheres on any Setup (AP-157) | 5 | **5** (`0x020016F7`) |
| non-zero `SortingSphere` (AP-157) | 4154 | **4154** |
Every external constant reproduces exactly, including the 9.911 m figure once
the 1.75 test scale is divided out.
### The stronger, genuinely independent containment result
Instead of comparing the flood sphere to the root sphere (which is circular —
see R1), I transformed **every physics-polygon vertex** of every physics-BSP
part into the same world frame and asked whether some emitted flood sphere
covers it:
```
VERTEX containment failures: after the fix = 0 before the fix = 412
```
Zero across all 530 BSP-bearing Setups. **I believe the containment claim.**
---
## Part 3 — Sabotage reproduction
Six of the nine claimed sabotages reproduced, including C, H and I as
requested. Each applied, clean-built, run, reverted.
| # | Sabotage | Claimed | Observed |
|---|---|---|---|
| A | `BuildFloodSpheres`: `world = partWorldPos` | 3 Core | **4 Core** (`FromSetup_CylSphereAndBspSetup_FloodsTheBspFootprint`, `_CapsCylSpheresAtTenButNeverTheBspParts`, `_RotatesTheBoundsCentre…`, `_CentresOnTheBoundsCentre…`) |
| C | `FromSetup` `boundsCenter = Vector3.Zero` (the shipped defect) | 1 Core + 2 App + 1 Content | **1 Core + 2 App + 1 Content** ✓ |
| D | drop `* entScale` on `boundsCenter` | 2 App + 1 Content | **2 App + 1 Content** ✓ |
| E | landblock flat branch `localCenter = Zero` | 1 Core | **1 Core** ✓ |
| H | `int cap = RetailSphereCap` (all branches) | 1 Core | **1 Core** ✓ |
| I | cap removed from the cylsphere branch | 1 Core | **1 Core** ✓ |
The claimed counts are honest; A is understated by one, i.e. coverage is
slightly better than advertised (A5).
**Trap encountered and avoided:** the naive form of sabotage I
(`int cap = int.MaxValue`) makes `RetailSphereCap` unused, which is
`error CS0219` under `TreatWarningsAsErrors`. The build fails, the stale
sabotage-H DLL survives, and the run reports H's failure as I's. I caught it by
grepping the build output for `Build succeeded` before every test run. Anyone
re-running these must do the same.
The fixtures are genuinely off-centre now. `ShadowObjectRegistryMultiPartTests.Bsp()`
defaults `BoundsCenter` to `(0, 6, 0)` and requires an explicit `(0.001, 0, 0)`
to get a near-concentric sphere;
`LiveEntityCollisionBuilderTests.Bsp()` defaults `centerZ = 1.25`;
`ShadowRegistrationOverflowTests.BspGfx()` defaults `centerZ = 0.75`. The
concentric `Radius = 14f` at `LocalPosition = Zero` configuration the prior
review named is gone from every flood fixture.
---
## Part 4 — `FromLandblockBspParts` (neither prior review looked)
`src/AcDream.Core/Physics/ShadowShapeBuilder.cs:268-334`.
- **The same discard existed.** Pre-fix the method computed only
`localRadius = flat.Nodes[flat.RootIndex].BoundingSphere.Radius` (or
`phys.BoundingSphere?.Radius`) and emitted the shape at `pPos`. Identical
defect, on stair runs, fences and rock clusters.
- **Both storage branches are fixed.** Flat (`:310-315`) and graph fallback
(`:316-320`) each take `Origin` alongside `Radius`.
`ShadowRegistrationOverflowTests.FromLandblockBspParts_CarriesTheScaledRootSphereCentre`
asserts both explicitly; sabotage E reddens the flat branch (verified) and
the same test carries the graph assertion.
- **`partScale` is applied correctly.** `Matrix4x4.Decompose` yields
`M = S·R·T`, so a point `v` in the part's own frame maps to root space as
`pPos + rotate(v · pScale, pRot)`. The code emits
`LocalPosition = pPos` (unscaled — correct, the translation is already
absolute in root space), `Radius = localRadius * partScale`,
`BoundsCenter = localCenter * partScale`, `Scale = partScale`. That composes
exactly as `BuildFloodSpheres` and as `TransitionTypes`' BSP transform
(`local * obj.Scale`, rotate, `+ obj.Position`) consume it.
Also verified: the two other `new ShadowShape(...)` sites in `src/`
(`LandblockPhysicsPublisher.cs:1003,1030` and
`LandblockPhysicsContentBuilder.cs:658,683`) emit **Cylinder** shapes only, for
which `BoundsCenter == Zero` is correct by definition. There is no third BSP
producer.
---
## Part 5 — Is `BoundsCenter` the right seam?
**Yes. The implementer's rebuttal of the `LocalPosition`-offset suggestion is
correct, and I verified the reason rather than taking it.**
`ShadowEntry.Position` is load-bearing in three distinct ways:
1. **BSP world origin.** `TransitionTypes.cs:3862-3898` transforms the mover's
spheres by `Vector3.Transform(sphere.Origin - obj.Position, invRot) *
invScale` and passes `worldOrigin: obj.Position` into
`CollisionTraversal.FindCollisions`. The physics BSP is authored about the
**part origin**, so shifting `Position` to the bounding-sphere centre would
translate every collision polygon by the offset — up to 20.762 m.
2. **Broadphase reach.** `TransitionTypes.cs:3757`.
3. **Cylinder XY distance.** `TransitionTypes.cs:3760`.
Moving `LocalPosition` would break (1) outright. A separate field is the only
correct seam.
**Consistency audit — every site that composes a shape's world placement:**
| Site | Uses | Correct? |
|---|---|---|
| `ShadowObjectRegistry.cs:474-490` `RegisterMultiPart``ShadowEntry` | `LocalPosition` only | ✓ (BSP frame) |
| `:578-593` `ReplaceMultiPartPayload``ShadowEntry` | `LocalPosition` only | ✓ |
| `:1484-1500` suspended-owner restore → `ShadowEntry` | `LocalPosition` only | ✓ |
| `:691-693` `BuildFloodSpheres` | `LocalPosition` **+ rotate(BoundsCenter, partWorldRot)** | ✓ |
| `:773`, `:1648`, `:2231` reflood / transfer | delegate to `RegisterMultiPart` | ✓ |
`BuildFloodSpheres` is the single flood site (`UpdatePosition` routes through
`RegisterMultiPart`), and no site reads the old semantics. The one place the
new field is *missing* and should eventually be present is `ShadowEntry` itself
— that is #333 (A2).
`ReplaceMultiPartPayload` deliberately does not re-flood; that matches retail
(`CPartArray::SetPart` changes the part read by later tests and does not
recalculate cross-cells). Not a finding.
---
## Part 6 — Is the shrink argument right?
**Yes. Settle it in favour of the implementer.**
Prior review F2 counted 43 Setups whose post-`4abd1b5e` flood was not a
superset of the pre-`4abd1b5e` one and called it a new under-inclusive defect.
My sweep puts the post-`b52967de` number at **143 of 172** — larger, exactly as
the implementer says.
That is not a defect, because retail's flood for a BSP-bearing object contains
**no primitive contribution at all**:
```
0x00515285 test dword [esi+0xa8],0x10000
0x0051528f jne 0x515305 ; -> find_bbox_cell_list, and it never returns
; into 0x005152d1 / 0x005152fb
```
The cylsphere branch (`0x005152d1`) and the sorting-sphere branch
(`0x005152fb`) are both below that jump and unreachable from it — I read the
control flow, not a summary of it. `find_bbox_cell_list` seeds the object's own
cell (`0x00510fd5``0x00510fe2 call 0x6b4ff0`) and then walks the part array;
nothing else contributes.
So for `0x0200086E` — F2's worst case, whose Sphere reached `z ≈ 11.68` while
its BSP parts reach `z ≈ 9.0`**retail also reaches only `z ≈ 9.0`.** The
pre-commit flood was larger because it included a primitive `calc_cross_cells`
never reads. Shrinking toward the BSP set is convergence, not regression.
The criterion that *does* discriminate is containment, and it now holds at
vertex level for all 530 (Part 2).
**What this means for the connected session** (the practical point):
"props that stopped blocking" is **not** by itself a bug report. The question
to ask of any such observation is whether the object's own BSP geometry still
reaches the cell it stopped blocking from. If it does, that is a bug; if it
does not, that is retail. Conversely, "a tall prop that still does not block"
is the expected symptom of #333, not of this fix (A2).
---
## Findings — retail lens
### R1 (MEDIUM) — the shipped containment assertion is algebraically tautological
`tests/AcDream.Content.Tests/InstalledSetupBspPrimitiveDispatchTests.cs:266-341`.
`truth` is built at `:282-284` as
`(partOrigin + rotate(b.Origin, partRot)) * EntScale` from the **same**
`Bounds()` resolver, over the **same** part set (the gate at `:299` is
`id => Bounds(id) is not null`), with the **same** placement-frame priority
(`:259-264` mirrors `ResolvePlacementFrame`). `flood` is built at `:314-317` as
`shape.LocalPosition + rotate(shape.BoundsCenter, shape.LocalRotation)`, and
`FromSetup` sets `LocalPosition = partFrame.Origin * entScale`,
`BoundsCenter = b.Origin * entScale`, `LocalRotation = partFrame.Orientation`.
The two expressions are identical by algebra, so `Shortfall(flood) ≡ 0` for
**any** DAT content and any future DAT.
Concrete failure scenario: if a later change made `FromSetup` read the wrong
GfxObj's bounding sphere in *both* the resolver and the emission — say a
`SetupId`/`GfxObjId` mix-up inside `Bounds()` — this assertion stays green
while every flood sphere in the game moves.
It is still a useful change-detector (sabotages C and D redden it, verified),
and `ExpectedWouldFailIfOriginDiscarded = 170` is a real, non-circular
measurement of the defect. But the commit body's framing — *"an installed-DAT
containment sweep asserting every emitted BSP flood sphere contains that part's
real bounding sphere"* — overstates what the code proves.
Cheap fix: compare against physics-polygon vertices (`gfx.PhysicsPolygons`
`gfx.VertexArray.Vertices`) instead of against the root sphere. I ran exactly
that and it passes 0/530, so adopting it costs nothing and makes the assertion
mean what it says.
### R2 (MEDIUM) — the defect population is understated 2.4×
The commit, AP-156 and both prior reviews all scope the defect to "170 of the
172" AP-152 Setups. After `4abd1b5e` **every** BSP-bearing Setup floods from
its BSP shapes only, so the discarded origin mis-placed the flood for all of
them, not just the ones that also carry a primitive. Measured:
```
vertex-containment failures with the origin discarded = 412 of 530
```
The 172 subset is AP-152's population, not AP-156's. The biggest single mover I
found — `gfx 0x010036DD`, 20.762 m offset on a 27.708 m sphere, in Setup
`0x0200129A` — is cited in the commit for its offset but its Setup is not
necessarily in the 172.
Consequence for the live gate: the user should be told the change touches
**412 installed Setups**, and that the objects most likely to look different
are not confined to the 73 CylSphere + 99 Sphere lists the commit body names.
### R3 (LOW) — the uncapped third branch is *further* from retail than the 10-cap was
`src/AcDream.Core/Physics/ShadowObjectRegistry.cs:674`:
```csharp
int cap = only == ShadowCollisionType.Cylinder ? RetailSphereCap : int.MaxValue;
```
`only == null` is the sorting-sphere branch. The commit's own justification for
lifting the cap there is *"the sorting-sphere overload @0x0052b990 takes one
sphere"* — which argues for a cap of **1**, not `int.MaxValue`. The cited
evidence does not support the code written.
Inert over installed data (I measured max 5 Spheres on any Setup, `0x020016F7`;
max 7 CylSpheres), and AP-157 registers the substitution honestly. But the
comment block at `:664-673` reads as though it justifies the whole line when it
only justifies the BSP half.
### R4 (LOW) — acdream scales the flood sphere; retail does not — unregistered
`ShadowShapeBuilder.cs:217` (`boundsCenter * entScale`) and `:330`
(`localCenter * partScale`) are new in this commit. Retail's
`find_transit_cells` uses only `CPhysicsPart::pos` (`+0x30`) and never touches
`gfxobj_scale` (`+0x24`), while `CPhysicsPart::find_obj_collisions`
@`0x0050d8d0` explicitly threads `gfxobj_scale.z` into
`SPHEREPATH::cache_localspace_sphere`. Retail's cross-cell walk is therefore
under-inclusive for scaled parts and acdream's is not.
Radius scaling predates this commit; centre scaling does not. Direction is
over-inclusive for `scale > 1` (safe) and under-inclusive for `scale < 1`
(the #98/#168 direction). Deserves a sentence in AP-156's residual paragraph;
the row currently lists only the sphere-vs-portal traversal.
### R5 (INFO) — retail's slack constant, for whoever fixes #333
`0x0052cb5f fld dword [0x7c8c70]` = `1.9999999494757503e-4` — the same
`F_EPSILON` AP-30 already byte-confirmed for `Frame::is_equal`. Retail's
cross-cell sphere test is `radius + 0.0002`, not `radius + 2`.
---
## Findings — architecture lens
### A1 (MEDIUM) — `BoundsCenter = default` reopens, at the type, the exact hole the commit closed at the seam
`src/AcDream.Core/Physics/ShadowShape.cs:61`:
```csharp
Vector3 BoundsCenter = default);
```
The commit's central structural claim is that *"the gate and the geometry
cannot disagree, and the radius cannot be taken while the origin is dropped.
That split is what produced this bug; it no longer exists."* That is true at
the `LiveEntityCollisionBuilder`/`FromSetup` seam — genuinely well done, and
the single-resolver collapse is the right call.
It is **not** true of `ShadowShape` itself. This still compiles today:
```csharp
new ShadowShape(gfxId, pos, rot, scale, ShadowCollisionType.BSP, radius, 0f)
```
and silently reproduces AP-156 with a zero centre. Every current BSP producer
passes it, so nothing is broken now — but a future BSP producer (a new static
publisher, a plugin-facing builder, a bake path) gets the old bug for free,
green.
Concrete failure scenario: someone adds a BSP branch to
`LandblockPhysicsContentBuilder` (which today emits Cylinders at `:658,683`
with no `BoundsCenter`), copies the existing 7-argument call shape, and
reintroduces a 20 m flood mis-placement with no test failing.
Fix: drop the default and pass `Vector3.Zero` explicitly at the two
primitive sites in `ShadowShapeBuilder` and the four in the publishers. Six
call sites, and the type then enforces the invariant the commit body claims.
### A2 (MEDIUM) — #333 is a real defect, correctly identified, but deferring it can mask this fix's entire visible benefit
`e2b2d04c` is honest and well-reasoned: the broadphase at
`TransitionTypes.cs:3757-3765` measures `currPos - obj.Position` (the **part
origin**) against `sphereRadius + obj.Radius + movement + 2f`, where
`obj.Radius` is the root sphere's radius measured about a centre that may be
metres away. Same discarded origin, one layer down.
I confirmed the two things the issue could not:
- **Retail has no such filter at all.** `CObjCell::find_obj_collisions`
@`0x0052b750` (pseudo-C 308916-308940) dispatches every non-parented,
non-self shadow object to `CPhysicsObj::FindObjCollisions` unconditionally.
The `+ 2f` and the movement term are acdream's own. The issue's "looks like
acdream's own broadphase rather than a port" is **correct**, and this is an
unregistered divergence that predates the commit — it should carry an AP row,
not only an issue number.
- **Its blast radius is large.** A genuine surface contact is rejected when
`|offset| > sphereRadius_mover + movement + 2` — roughly 2.5 m for a walking
player. **118 of the 477 unique installed physics-BSP GfxObjs** have a root
sphere offset above 2.5 m, and **46** above 5 m. At the test scale 1.75 those
become 4.4 m and 8.75 m against an unchanged ~2.5 m budget.
The issue's own one-line summary is slightly imprecise — it says contact is
admitted "only when the sphere's centre is within about `movement + 2` metres
of the part origin", where the correct statement is about the **mover's**
distance from the part origin versus `R + r_m + move + 2`. The conclusion is
unchanged.
Deferral judgement: the split is defensible on attributability grounds (it is
literally the AP-155 lesson), and I would not have bundled a *retail-question*
fix. But the practical consequence must be stated plainly to the user rather
than left in an issue body: **for the tall props with the largest offsets —
exactly the objects the commit body tells the user to go look at — the fix may
produce no visible change at all**, because the geometry now lands in the right
cell and is then discarded by the filter. If the connected gate is run before
#333, a null result on tall props is expected, not evidence against AP-156.
The minimal correct fix is mechanical (carry `BoundsCenter` on `ShadowEntry`
and measure from `obj.Position + rotate(BoundsCenter, obj.Rotation)`); only the
`+ 2f` question is genuinely open, and it is open independently of that.
### A3 (LOW) — a cached field became a per-call delegate allocation
`src/AcDream.App/Physics/LiveEntityCollisionBuilder.cs:136`:
```csharp
id => _physicsBspBounds(id) is not null,
```
replaces the cached `_hasPhysicsBsp` field. The lambda captures `this`, so
Roslyn allocates a fresh `Func<uint,bool>` on every `Build` call. `Build` is
per-entity-spawn / per-appearance-rebuild, not per-frame, so this is small —
but the project has spent a whole slice (I1) driving physics-path resolves to
0 B, and a `private readonly Func<uint,bool> _hasBounds` initialised once in
both constructors costs nothing and keeps the single-resolver invariant intact.
Also: the new resolver indexes `flat.Nodes[flat.RootIndex]` where the old gate
only compared `RootIndex >= 0`. A `FlatPhysicsBsp` with `RootIndex >= 0` and an
empty `Nodes` array would now throw where it previously returned `true`. I
found no way to construct one from `FlatCollisionAssetBuilder`, so this is a
note, not a defect.
### A4 (LOW) — uncapping the BSP branch raises a per-tick cost for moving remotes
`RuntimeRemotePhysicsUpdater.cs:482` re-floods a remote through
`RegisterMultiPart` on every tick it actually moves, and `RegisterMultiPart`
writes every shape row into every flooded cell. Lifting the cap changes the
flood input from ≤10 spheres to up to 49, and the row count is
`parts × cells` — both factors grow together.
Bounded in practice: only 7 installed Setups exceed 10 BSP parts, landblock
part arrays are static and register once, and this is what retail does
(`add_shadows_to_cells` @`0x00514ae0``CPartArray::AddPartsShadow` walks the
whole part array into every cross-cell). Worth a glance in the connected
session if a dense indoor scene with a many-part animate prop regresses; not
worth pre-emptive work.
### A5 (LOW) — sabotage A reddens 4 Core tests, not 3
Reproduced: `FromSetup_CylSphereAndBspSetup_FloodsTheBspFootprint`,
`BuildFloodSpheres_CapsCylSpheresAtTenButNeverTheBspParts`,
`BuildFloodSpheres_BspShape_RotatesTheBoundsCentreByThePartRotation`,
`BuildFloodSpheres_BspShape_CentresOnTheBoundsCentreNotThePartOrigin`.
Coverage is one better than the commit body claims; the ledger is simply stale
by one line.
### A6 (LOW) — the Content test's "cap control" does not test the cap
`InstalledSetupBspPrimitiveDispatchTests.cs:302-308` comments that *"EVERY BSP
shape contributes … capping here would silently exclude their tail from the
containment claim below"*, and `:365` asserts
`mostBspShapesOnOneSetup == 49`. But that loop (`:311-319`) is the test's own
re-implementation of the composition with **no cap**, so it cannot observe a
cap regression in `BuildFloodSpheres`. I confirmed empirically: under sabotage
H the Content suite stayed 127/127 green.
The cap is genuinely covered — by
`BuildFloodSpheres_CapsCylSpheresAtTenButNeverTheBspParts` (sabotages H and I
both redden it, verified). The comment just claims coverage that lives
elsewhere.
---
## Gates reproduced
All after deleting all 44 `bin`/`obj`.
| Gate | Claimed | Observed |
|---|---|---|
| Release build | 0 errors, 21 pre-existing warnings | **0 errors, 21 warnings** ✓ |
| Complete suite | 11,208 / 4 skipped / 0 failed | **11,208 / 4 / 0** ✓ |
| Core | 4268 | **4268** (1 skip) ✓ |
| Content | 127 | **127** (0 skips) ✓ |
| App | unchanged, one rename | **4173** (3 skips) ✓ |
| Delta vs `4abd1b5e` | +5 | consistent: +4 Core (3 in `ShadowObjectRegistryMultiPartTests`, 1 in `ShadowRegistrationOverflowTests`) +1 Content, App rename only. Baseline **not** independently re-run — I did not check out `4abd1b5e` in a worktree another agent may share. |
| Active AP register rows | 109 | **109**, literal count of non-struck `AP-` rows in section 3 ✓ (AD 48, IA 18, UN 4) |
Suite run twice — once on the pristine tree before any sabotage, once on a
fully clean rebuild after every restore. Identical both times. No flake from
#302 / #308 / #321 was hit; nothing was conflated with them.
## Rules compliance
- **No workaround, suppression flag, grace period, retry loop or symptom
guard** anywhere in the diff. The fix is at the source: the resolver that
answers "does this dispatch as BSP?" is now the same one that answers "where
and how big is its sphere?".
- **No new skips.** 4 skipped, all pre-existing.
- **No test weakened.** `BspOnlyPart_UsesRealScaledPhysicsBoundingRadius`
`…BoundingSphere` is a rename that **adds** an assertion; the
`LiveAppearanceAnimationTests` and `Builder()` edits drop a now-merged
parameter with no behavioural change. Every flood fixture moved from
concentric to off-centre, which is strictly stronger.
- **Register discipline honoured.** AP-155 narrowed with its false direction
corrected, AP-156 and AP-157 filed, AP-152 retired, count reconciles at a
literal 109 — all in the same commit as the code. This is the register rule
working as designed: AP-155(b)'s recorded direction was the *stated reason*
the residual was safe to defer, and it was backwards.
## What I checked and found clean, so the PASS is auditable
- All 12 cited retail addresses resolve to the named symbol; no mis-cite.
- `BSPTREE::GetSphere`, `find_transit_cells`, `find_bbox_cell_list`,
`calc_cross_cells_static`, `calc_cross_cells`, both `find_cell_list`
overloads, `CacheHasPhysicsBSP`, `GetSortingSphere` — all disassembled from
the PDB-paired binary, not inherited.
- `CGfxObj`, `CPhysicsPart`, `BSPNODE`, `CSphere`, `CSetup` field offsets
cross-checked against `acclient.h` and against the code that reads them.
- Every `new ShadowShape(...)` site in `src/` (8) classified; only two emit BSP
and both carry the centre.
- Every site that composes a shape's world placement (5) classified; none reads
the old semantics.
- Every `BuildShadowCellSet` caller (2) classified; the single-shape
`Register` overload has no production BSP caller.
- `FlatPhysicsBsp.Nodes[RootIndex].BoundingSphere` traced to
`gfxObj.PhysicsBSP.Root.BoundingSphere` in both `PhysicsDataCache`
population paths (`:216`, `:281-287`) and in
`FlatCollisionAssetBuilder` (`:84`, `:393`) — acdream's seam is retail's
`physics_sphere`.
- `ReplaceMultiPartPayload`'s no-reflood behaviour checked against
`CPartArray::SetPart` semantics — retail-faithful.
- Quaternion composition order (`entityWorldRot * s.LocalRotation`, then
`Vector3.Transform(BoundsCenter, partWorldRot)`) checked against the inverse
transform in `TransitionTypes.cs:3859-3876` — consistent.
- Six sabotages reproduced; tree confirmed clean by `git status --porcelain`
before and after.
---
## Recommended, in priority order
1. Tell the user the live-gate criterion is **containment, not size**, and that
"a prop stopped blocking" is only a bug if its own BSP geometry still
reaches the cell (Part 6). State the population as **412 Setups** (R2).
2. Warn that tall props with large offsets may show **no change** until #333
lands, and that a null result there is expected (A2).
3. Fix #333 — it is mechanical apart from the `+ 2f` question — and give the
`maxReach` filter its own AP row, since retail has no such filter at all
(A2).
4. Make `ShadowShape.BoundsCenter` required (A1).
5. Swap the Content containment oracle to physics-polygon vertices (R1) — it
passes today, costs nothing, and makes the load-bearing assertion mean
what it says.
6. Add the scale sentence to AP-156's residual paragraph (R4).

View file

@ -0,0 +1,218 @@
# AP-156 fix review — closure record
Closes the six findings in
[`2026-08-06-ap156-fix-review.md`](2026-08-06-ap156-fix-review.md) (both lenses
PASS; this is cleanup before merge, not a rescue). Worktree
`.claude/worktrees/resume-session-e0bd03e1-d5bf45`, base `e2b2d04c`.
All 44 `bin`/`obj` deleted before every verdict-deciding build, and every test
run gated on a grep for `Build succeeded` in the same invocation — the trap the
review documented (a sabotage that trips `CS0219` under
`TreatWarningsAsErrors` fails the build and lets the *previous* sabotage's DLL
report the wrong failure) was not hit.
---
## R1 — the containment oracle now discriminates
**Done.** `InstalledSetupBspPrimitiveDispatchTests` no longer compares the
emitted flood sphere against a hand-rebuilt copy of the same sphere. It
transforms every **physics-polygon vertex**
(`GfxObj.PhysicsPolygons``GfxObj.VertexArray.Vertices`) of every physics-BSP
part into the entity frame and asserts some emitted flood sphere covers it.
Vertices are a different DAT field from the bounding sphere, so the two sides of
the comparison are no longer the same expression. Renamed to
`InstalledSetups_BspFloodSpheres_ContainTheirOwnPhysicsPolygons`.
New population + defect controls: 973 physics-BSP parts, 530 BSP-bearing
Setups, 376 off-centre parts, **91,689** physics vertices, 428 pre-fix
failures, deepest part array 49. Every one measured first by a scratch
DatReaderWriter console program **outside the repo** that references no acdream
assembly, then reproduced exactly through the production builder.
**Sabotage-verified, three ways, each after a full clean and a verified
`Build succeeded`:**
| # | Sabotage | Result |
|---|---|---|
| S1 | `ShadowShape.Bsp` drops the bounds centre (the AP-156 defect itself) | **RED — 428 Setups, worst 35.869 m on 0x0200129A** (matches the independent sweep exactly) |
| S2 | `ShadowShape.Bsp` applies the scale to the radius but not the centre | **RED — 326 Setups, worst 15.288 m** |
| S3 | the TEST's own `Bounds()` oracle corrupted (`bs.Origin` negated) | **RED — 467 Setups, worst 72.134 m** |
| S1b | same sabotage, run against Core rather than Content | **RED — 5 tests**: the 4 the review's sabotage A found, plus `ShadowRegistrationOverflowTests.FromLandblockBspParts_CarriesTheScaledRootSphereCentre`, which sabotage A could not reach because it only touched `BuildFloodSpheres`. The factory refactor makes both BSP producers share one scaling path, so one sabotage now covers both. |
| — | restored | **GREEN — 127/127 Content, 4,268/1 skip Core** |
S3 is the one that matters for R1. Under the shipped oracle that same
corruption was invisible by algebra: `truth` was
`(partOrigin + rotate(O, R))·s` and `flood` was
`LocalPosition + rotate(BoundsCenter, R)` = `partOrigin·s + rotate(O·s, R)`, so
negating `O` moved both sides identically and the shortfall stayed ≡ 0. The
vertex oracle catches it. That is the tenth green-test-covering-nothing this
campaign, and this is the direction of sabotage that proves it is closed —
breaking the production code was never the hard half.
## R2 — population corrected, and refined
**Done, with a refinement the review will want.** The review says 412, not
"170 of 172". Both figures are right about different things, and neither is the
number to quote to the user:
| Question | Answer |
|---|---|
| Setups carrying both a primitive and a physics-BSP part (AP-152's DISPATCH population) | **172** of 5,935 |
| BSP-bearing Setups (AP-156's population) | **530** |
| …whose flood sphere actually MOVES because of the fix | **525** |
| …failing vertex-level containment before the fix, 1 mm tolerance | **428** |
| …failing at a 1 cm tolerance | **412** ← the review's figure |
| …failing after the fix, at any tolerance down to zero | **0** |
The 412/428 gap is 16 Setups whose pre-fix shortfall lands between 1.4 mm and
10 mm — real geometry, three orders of magnitude above float noise at these
radii, not a measurement artifact. The test keeps its existing 1 mm tolerance
and therefore pins **428**; the register records both and names the tolerance,
because a bare "412" is unreproducible without it.
**The number to tell the user is 525** — Setups whose behaviour changes — not
172, and not 412. Corrected in the AP-156 row, the section-3 header, the C5c
handoff, and the two stale test docstrings. The dated review documents
(`2026-08-06-ap152-review-retail.md`, and the fix review itself) are left
as written: "170 of 172" was correct for what those reviews measured
(root-sphere containment over the 172), and rewriting a dated evidence
artifact to match a later measurement is how provenance gets lost.
The commit's own record cannot be corrected in place — `b52967de` is HEAD~1 and
amending it would rewrite published history. This document plus the register row
is that correction.
## A1 — the hole is closed at the type
**Done, and deliberately stronger than the review's recommendation.** The review
suggested dropping the `= default` and passing `Vector3.Zero` explicitly at six
call sites. That does **not** close the review's own failure scenario: someone
adding a BSP branch to `LandblockPhysicsContentBuilder` by copying the adjacent
Cylinder call would then write `Vector3.Zero` explicitly and get the same
20 m mis-placement, still green.
Instead `ShadowShape`'s constructor is now **private**, and the three factories
are the only way to build one:
```csharp
ShadowShape.Bsp(gfxObjId, localPosition, localRotation, scale, FlatCollisionSphere localBounds)
ShadowShape.Cylinder(gfxObjId, localPosition, localRotation, scale, radius, cylHeight)
ShadowShape.Sphere(gfxObjId, localPosition, localRotation, scale, radius)
```
`Bsp` takes the radius and the centre as **one `FlatCollisionSphere` value** and
scales them together inside the factory. There is no longer an expression a
caller can write that carries one and drops the other — which is the commit
body's own claim ("the radius cannot be taken while the origin is dropped"),
now true of the type and not only of the `FromSetup` seam. 22 construction
sites converted; S1 and S2 above are exactly the two ways the factory could
still be got wrong, and both are red.
Residual, recorded rather than fixed: `default(ShadowShape)` remains
constructible because C# structs always have a parameterless constructor. It
yields `CollisionType = BSP, Radius = 0` — inert, and no production path
produces one.
## A2 — #333 updated, AP-158 filed, and the retail claim independently verified
**Done.** I disassembled `CObjCell::find_obj_collisions` @`0x0052b750` myself
from the PDB-paired binary (`check_exe_pdb.py`**MATCH**, CodeView GUID
`9e847e2f-777c-4bd9-886c-22256bb87f32`, linker 2013-09-06T00:17:56Z) rather
than inheriting the claim, because Binary Ninja drops flag tests and that has
bitten this campaign repeatedly:
```
0x0052b759 cmp dword [ebx+0x174], 2 ; sphere_path.insert_type
0x0052b765 je 0x52b7a0 ; INITIAL_PLACEMENT_INSERT -> return OK_TS
0x0052b773 mov ecx,[edi+0xc8] ; shadow_object_list.data
0x0052b77f mov edx,[ecx+0x40] ; physobj->parent -> skip if set
0x0052b786 cmp ecx,[ebx] ; self -> skip
0x0052b78b call 0x50f050 ; FindObjCollisions — UNCONDITIONAL
0x0052b79e jb 0x52b773 ; loop, bound [edi+0xc4]
```
The single early-out is a transition-state test, not a distance test — the whole
function is 0x54 bytes and there is no float comparison in it. Confirms the
review: **retail has no distance pre-filter at all**, so acdream's
`sphereRadius + obj.Radius + movement.Length() + 2f` is an invention.
`[ebx+0x174]` resolves to `sphere_path.insert_type` against `acclient.h`'s
`CTransition` layout and the pseudo-C at 308916-308940 agrees.
Blast radius reproduced independently: **118 of the 477** unique installed
physics-BSP GfxObjs exceed the ~2.5 m budget, **46** exceed 5 m.
Filed as **AP-158** — the filter had no register row at all — carrying the
disassembly, the `F_EPSILON` = 1.9999999e-4 m contrast (R5), the measured blast
radius, and the "this can mask AP-156's entire visible benefit" consequence.
#333 updated: its research question is struck through and answered, and what
remains is a judgement call (keep the filter with a correct measurement point,
or delete it and walk the list as retail does — the retail-faithful option,
which should be costed first).
## The consequence that had to be recorded prominently
**Tall props may show no visible change at all until #333 lands, and a null
result at the connected gate is EXPECTED, not evidence against AP-156.**
Recorded in three places a reader will actually hit: the AP-156 register row's
`WHAT REMAINS OPEN`, the AP-158 row's risk column, and item 7 of the C5c
handoff's §3.1 gate list — alongside the other half of the same warning, that
"a prop stopped blocking" is only a bug if the object's own BSP geometry still
reaches the cell it stopped blocking from.
## LOW items
**R3 — `int.MaxValue` on the sorting-sphere branch.** *Comment corrected; code
deliberately unchanged, and I think the review's implied fix is wrong.* The
review is right that the cited evidence (`0x0052b9d6 push 1`) argues for a cap
of 1, not `int.MaxValue`, and the comment block claimed to justify the whole
line when it justified only the BSP half — that is fixed, and the comment now
says plainly which half is a port and which is not. But capping at 1 would take
`Spheres[0]`, and retail's one sphere is `CSetup::sorting_sphere`, a **different
DAT field**. Capping would not move toward retail; it would keep the wrong field
and additionally make the substitution under-inclusive, which is the #98/#168
direction. `int.MaxValue` keeps it over-inclusive until AP-157 ports the real
field, which is the honest state. Inert over installed data either way — max 5
Spheres on any Setup (0x020016F7).
**R4 — acdream scales the flood sphere, retail does not.** Recorded as a second
residual on the AP-156 row. `find_transit_cells` @0x0052cae0 reads only
`CPhysicsPart::pos` (`+0x30`) and never `gfxobj_scale` (`+0x24`), while
`CPhysicsPart::find_obj_collisions` @0x0050d8d0 does thread `gfxobj_scale.z`
into `SPHEREPATH::cache_localspace_sphere`. Direction: over-inclusive for
scale > 1, under-inclusive for scale < 1. Radius scaling predates the commit;
centre scaling did not, which is why it needed the row.
**R5 — retail's slack is 0.0002 m, not 2 m.** Carried into AP-158's anchor
column and into #333, where whoever fixes the filter will hit it.
**A3 — per-call delegate allocation.** Fixed: `LiveEntityCollisionBuilder` now
holds `private readonly Func<uint,bool> _hasPhysicsBsp`, initialised once in the
single real constructor and still derived from `_physicsBspBounds`, so the
single-resolver invariant is intact and `Build` allocates no closure.
**A6 — the Content test's "cap control" does not test the cap.** Comment
corrected: the loop is the test's own uncapped re-implementation and cannot
observe a cap regression; the cap is covered by
`BuildFloodSpheres_CapsCylSpheresAtTenButNeverTheBspParts`, which reddens under
both cap sabotages. What `mostBspShapesOnOneSetup == 49` genuinely proves —
that the containment claim reaches Setups past the retired clamp rather than
stopping short of them — is now what the comment claims.
**A5 — sabotage A reddens 4 Core tests, not 3.** Noted; `b52967de`'s message
cannot be amended. Coverage is one better than advertised, which is the benign
direction.
---
## Gates
| Gate | Baseline `e2b2d04c` | Observed |
|---|---|---|
| Release build, all 44 `bin`/`obj` deleted | 0 errors, 21 warnings | **0 errors, 21 warnings** |
| Complete suite, `-m:1`, `ACDREAM_PAK_PATH` set | 11,208 / 4 skipped / 0 failed | **11,208 / 4 / 0** — reconciles exactly; one test RENAMED, none added or removed |
| Content | 127 / 0 skips | **127 / 0 skips** |
| Active AP register rows | 109 | **110** (AP-158 filed) |
No new skips. Nothing was conflated with the known load-sensitive flakes
#302 / #308 / #321.

View file

@ -138,6 +138,29 @@ complete.
5. **AD-65 / AD-66** need a local-player visual gate before any fix (see §5).
6. **C5c proper**: two-client observation, canonical nine-stop soak,
lifecycle/reconnect route on the final binary, and the user's visual matrix.
7. **AP-156 — the BSP flood-sphere placement fix (`b52967de`).**
**The criterion is CONTAINMENT, not size, and a null result on tall props is
EXPECTED.** Two things must be said to the user before this one is run, or
its outcome will be misread in both directions:
- *"A prop stopped blocking"* is **not** by itself a bug report. AP-156
shrinks the flood for 143 of the 172 AP-152 Setups on purpose, because
retail's BSP branch (`calc_cross_cells` @0x00515230, `0x0051528f jne`)
contributes **no primitive at all** — the old flood was larger only
because it included a sphere retail never reads. The question to ask of
any such observation is whether the object's own BSP geometry still
reaches the cell it stopped blocking from. If it does, that is a bug; if
it does not, that is retail.
- *"A tall prop STILL does not block"* is the expected symptom of
**AP-158 / #333**, not of this fix. AP-156 puts the geometry in the right
cell; acdream's own `maxReach` broadphase filter — which retail does not
have at all — then discards it one layer down, for 118 of the 477 unique
installed physics-BSP GfxObjs. **A null result on tall props is not
evidence against AP-156.** Run this gate after #333, or run it on
short/wide off-centre props where the offset is inside the ~2.5 m budget.
Population, for the user: the change touches **525 of the 530** BSP-bearing
Setups (not the 172 the commit body names — that is AP-152's dispatch
population). See the AP-156 register row.
### 3.2 Then, and only then

View file

@ -48,6 +48,12 @@ internal sealed record LiveEntityCollisionRegistration(
internal sealed class LiveEntityCollisionBuilder
{
private readonly Func<uint, FlatCollisionSphere?> _physicsBspBounds;
/// <summary>
/// The dispatch gate, derived from <see cref="_physicsBspBounds"/> so the
/// two can never disagree (AP-156), and cached once so <see cref="Build"/>
/// allocates no closure per call — Slice I1's 0 B/resolve budget.
/// </summary>
private readonly Func<uint, bool> _hasPhysicsBsp;
private readonly LiveEntityDefaultPoseResolver _defaultPose;
public LiveEntityCollisionBuilder(
@ -80,6 +86,7 @@ internal sealed class LiveEntityCollisionBuilder
{
_physicsBspBounds = physicsBspBounds
?? throw new ArgumentNullException(nameof(physicsBspBounds));
_hasPhysicsBsp = id => _physicsBspBounds(id) is not null;
_defaultPose = defaultPose
?? throw new ArgumentNullException(nameof(defaultPose));
}
@ -134,7 +141,7 @@ internal sealed class LiveEntityCollisionBuilder
IReadOnlyList<ShadowShape> shapes = ShadowShapeBuilder.FromSetup(
setup,
scale,
id => _physicsBspBounds(id) is not null,
_hasPhysicsBsp,
partPoseOverride: defaultPose,
effectivePartGfxObjIds: effectivePartGfxObjIds,
physicsBspBounds: _physicsBspBounds);

View file

@ -1000,14 +1000,13 @@ public sealed class LandblockPhysicsPublisher
continue;
Vector3 localOffset = cylinder.Origin * scale;
setupShapes.Add(new ShadowShape(
GfxObjId: entity.SourceGfxObjOrSetupId,
LocalPosition: localOffset,
LocalRotation: Quaternion.Identity,
Scale: scale,
CollisionType: ShadowCollisionType.Cylinder,
Radius: radius,
CylHeight: height));
setupShapes.Add(ShadowShape.Cylinder(
gfxObjId: entity.SourceGfxObjOrSetupId,
localPosition: localOffset,
localRotation: Quaternion.Identity,
scale: scale,
radius: radius,
cylHeight: height));
}
if (setup.Cylinders.Length == 0)
@ -1027,14 +1026,13 @@ public sealed class LandblockPhysicsPublisher
+ Vector3.Transform(
-Vector3.UnitZ * radius,
Quaternion.Inverse(entity.Rotation));
setupShapes.Add(new ShadowShape(
GfxObjId: entity.SourceGfxObjOrSetupId,
LocalPosition: localBaseOffset,
LocalRotation: Quaternion.Identity,
Scale: scale,
CollisionType: ShadowCollisionType.Cylinder,
Radius: radius,
CylHeight: radius * 2f));
setupShapes.Add(ShadowShape.Cylinder(
gfxObjId: entity.SourceGfxObjOrSetupId,
localPosition: localBaseOffset,
localRotation: Quaternion.Identity,
scale: scale,
radius: radius,
cylHeight: radius * 2f));
}
}

View file

@ -655,12 +655,11 @@ public static class LandblockPhysicsContentBuilder
: cylinder.Radius * 4f) * scale;
if (radius <= 0f)
continue;
setupShapes.Add(new ShadowShape(
setupShapes.Add(ShadowShape.Cylinder(
entity.SourceGfxObjOrSetupId,
cylinder.Origin * scale,
Quaternion.Identity,
scale,
ShadowCollisionType.Cylinder,
radius,
height));
}
@ -680,12 +679,11 @@ public static class LandblockPhysicsContentBuilder
+ Vector3.Transform(
-Vector3.UnitZ * radius,
Quaternion.Inverse(entity.Rotation));
setupShapes.Add(new ShadowShape(
setupShapes.Add(ShadowShape.Cylinder(
entity.SourceGfxObjOrSetupId,
localBaseOffset,
Quaternion.Identity,
scale,
ShadowCollisionType.Cylinder,
radius,
radius * 2f));
}

View file

@ -663,14 +663,28 @@ public sealed class ShadowObjectRegistry
// The 10-sphere clamp belongs to the CYLSPHERE branch alone.
// CObjCell::find_cell_list @0x0052b9f0 clamps the cylsphere count at
// 0x0052ba21 cmp eax,0xa / 0x0052ba28 mov ebp,0xa. The BSP branch —
// find_bbox_cell_list @0x00510fc0 -> CPartArray::calc_cross_cells_static
// @0x00518160 -> CEnvCell::find_transit_cells @0x0052cae0 — walks EVERY
// part with no cap, and the sorting-sphere overload @0x0052b990 takes a
// single sphere. Applying the clamp to the BSP branch dropped parts
// 11..N out of the flood entirely: 7 installed Setups carry more than
// 10 physics-BSP parts (max 49, Setup 0x02001A91), and landblock-baked
// part arrays — stair runs, fences, rock clusters — routinely do.
// 0x0052ba21 cmp eax,0xa / 0x0052ba28 mov ebp,0xa, and that clamp is a
// fixed static-buffer capacity (the destination array at
// 0x844838..0x8448d8 is exactly ten 16-byte entries), not a policy.
//
// BSP branch: NO CAP, and this is a retail port. find_bbox_cell_list
// @0x00510fc0 -> CPartArray::calc_cross_cells_static @0x00518160 ->
// CEnvCell::find_transit_cells @0x0052cae0 walks every part, bounded
// only by num_parts. Clamping it dropped parts 11..N out of the flood
// entirely: 7 installed Setups carry more than 10 physics-BSP parts
// (max 49, Setup 0x02001A91), and landblock-baked part arrays — stair
// runs, fences, rock clusters — routinely do.
//
// only == null (the sorting-sphere branch): int.MaxValue is NOT a
// retail port and the addresses above do not justify it. Retail's
// overload @0x0052b990 pushes a literal 1 (0x0052b9d6 push 1) and
// floods from ONE authored CSetup::sorting_sphere. acdream floods from
// every Sphere shape instead — a different DAT field with a different
// cardinality, which is AP-157, filed and open. Capping at 1 HERE would
// not move toward retail: it would take Spheres[0], which is not the
// sorting sphere. int.MaxValue keeps the substitution in its safe
// (over-inclusive) direction until AP-157 ports the real field. Inert
// over installed data — max 5 Spheres on any Setup (0x020016F7).
int cap = only == ShadowCollisionType.Cylinder ? RetailSphereCap : int.MaxValue;
foreach (var s in shapes)

View file

@ -15,47 +15,158 @@ namespace AcDream.Core.Physics;
/// at <c>acclient_2013_pseudo_c.txt:275045-275055</c>. Each part stores its
/// own transform and dispatches per-part collision to its GfxObj.
/// </para>
///
/// <para>
/// CONSTRUCTION IS BY FACTORY ONLY (<see cref="Bsp"/>, <see cref="Cylinder"/>,
/// <see cref="Sphere"/>) and the constructor is private. That is the AP-156
/// invariant expressed at the type rather than only at the producer: a BSP
/// shape's radius and its bounding-sphere CENTRE arrive as one
/// <see cref="FlatCollisionSphere"/> value and are scaled together inside
/// <see cref="Bsp"/>, so no call site — present or future — can take the
/// radius while dropping the origin. That split is exactly what produced
/// AP-156, and with the old public 7-argument constructor a new BSP producer
/// could have reintroduced it silently and green.
/// </para>
/// </summary>
/// <param name="BoundsCenter">
/// Center of the shape's bounding sphere IN THE SHAPE'S OWN LOCAL FRAME —
/// the frame <see cref="LocalRotation"/> rotates out of and
/// <see cref="Radius"/> is measured in — already multiplied by the entity
/// scale, like <see cref="LocalPosition"/> and <see cref="Radius"/>.
/// <c>Zero</c> for Cylinder/Sphere shapes, whose
/// <see cref="LocalPosition"/> already IS their center.
///
/// <para>
/// BSP shapes need it because a GfxObj's physics BSP is authored in the
/// GfxObj's own coordinates and its root bounding sphere is frequently NOT
/// centered on that origin (376 of the 973 physics-BSP parts in the
/// installed <c>client_portal.dat</c> sit further from it than half their
/// own radius; worst 20.762 m on a 27.708 m sphere, gfx 0x010036DD).
/// <see cref="ShadowObjectRegistry.RegisterMultiPart"/>'s flood needs the
/// sphere's real position, not the part origin's.
/// </para>
///
/// <para>
/// Retail anchor: <c>CGfxObj::physics_sphere</c> (<c>[gfxobj+0x74]</c>) is
/// assigned <c>BSPTREE::GetSphere(physics_bsp)</c> @0x005397e0
/// (<c>mov eax,[ecx]; add eax,4</c> — the root <c>BSPNODE</c>'s
/// <c>CSphere sphere</c>, past its 4-byte vftable), so retail's per-part
/// flood sphere IS the BSP root bounding sphere, origin included.
/// <c>CEnvCell::find_transit_cells</c> @0x0052cae0 — the part-array overload
/// reached from <c>CPhysicsObj::find_bbox_cell_list</c> @0x00510fc0 via
/// <c>CPartArray::calc_cross_cells_static</c> @0x00518160's
/// <c>[vtbl+0x7c]</c> dispatch — loads that sphere at
/// <c>0x0052cb36 mov esi,[ecx+0x74]</c>, transforms its CENTER through the
/// part's own <c>Position</c> at <c>[part+0x30]</c>
/// (<c>0x0052cb4c add eax,0x30</c> / <c>0x0052cb5a call Position::localtolocal</c>),
/// and only then reads the radius at <c>0x0052cb65 fadd [esi+0xc]</c>.
/// </para>
/// </param>
public readonly record struct ShadowShape(
uint GfxObjId,
Vector3 LocalPosition,
Quaternion LocalRotation,
float Scale,
ShadowCollisionType CollisionType,
float Radius,
float CylHeight,
Vector3 BoundsCenter = default);
public readonly record struct ShadowShape
{
private ShadowShape(
uint gfxObjId,
Vector3 localPosition,
Quaternion localRotation,
float scale,
ShadowCollisionType collisionType,
float radius,
float cylHeight,
Vector3 boundsCenter)
{
GfxObjId = gfxObjId;
LocalPosition = localPosition;
LocalRotation = localRotation;
Scale = scale;
CollisionType = collisionType;
Radius = radius;
CylHeight = cylHeight;
BoundsCenter = boundsCenter;
}
/// <summary>Source GfxObj id, for the BSP walk and for diagnostics.</summary>
public uint GfxObjId { get; }
/// <summary>Part placement in the entity's own frame, entity-scaled.</summary>
public Vector3 LocalPosition { get; }
/// <summary>Part orientation in the entity's own frame.</summary>
public Quaternion LocalRotation { get; }
/// <summary>The entity (or part) scale already applied to the geometry.</summary>
public float Scale { get; }
public ShadowCollisionType CollisionType { get; }
/// <summary>Collision radius, entity-scaled.</summary>
public float Radius { get; }
/// <summary>Cylinder height, entity-scaled; 0 for BSP and Sphere.</summary>
public float CylHeight { get; }
/// <summary>
/// Center of the shape's bounding sphere IN THE SHAPE'S OWN LOCAL FRAME —
/// the frame <see cref="LocalRotation"/> rotates out of and
/// <see cref="Radius"/> is measured in — already multiplied by the entity
/// scale, like <see cref="LocalPosition"/> and <see cref="Radius"/>.
/// <c>Zero</c> for Cylinder/Sphere shapes, whose
/// <see cref="LocalPosition"/> already IS their center.
///
/// <para>
/// BSP shapes need it because a GfxObj's physics BSP is authored in the
/// GfxObj's own coordinates and its root bounding sphere is frequently NOT
/// centered on that origin (376 of the 973 physics-BSP parts in the
/// installed <c>client_portal.dat</c> sit further from it than half their
/// own radius; worst 20.762 m on a 27.708 m sphere, gfx 0x010036DD).
/// <see cref="ShadowObjectRegistry.RegisterMultiPart"/>'s flood needs the
/// sphere's real position, not the part origin's.
/// </para>
///
/// <para>
/// Retail anchor: <c>CGfxObj::physics_sphere</c> (<c>[gfxobj+0x74]</c>) is
/// assigned <c>BSPTREE::GetSphere(physics_bsp)</c> @0x005397e0
/// (<c>mov eax,[ecx]; add eax,4</c> — the root <c>BSPNODE</c>'s
/// <c>CSphere sphere</c>, past its 4-byte vftable), so retail's per-part
/// flood sphere IS the BSP root bounding sphere, origin included.
/// <c>CEnvCell::find_transit_cells</c> @0x0052cae0 — the part-array overload
/// reached from <c>CPhysicsObj::find_bbox_cell_list</c> @0x00510fc0 via
/// <c>CPartArray::calc_cross_cells_static</c> @0x00518160's
/// <c>[vtbl+0x7c]</c> dispatch — loads that sphere at
/// <c>0x0052cb36 mov esi,[ecx+0x74]</c>, transforms its CENTER through the
/// part's own <c>Position</c> at <c>[part+0x30]</c>
/// (<c>0x0052cb4c add eax,0x30</c> / <c>0x0052cb5a call Position::localtolocal</c>),
/// and only then reads the radius at <c>0x0052cb65 fadd [esi+0xc]</c>.
/// </para>
/// </summary>
public Vector3 BoundsCenter { get; }
/// <summary>
/// One physics-BSP part. <paramref name="localBounds"/> is the part
/// GfxObj's physics-BSP ROOT bounding sphere in the GfxObj's OWN frame,
/// unscaled — retail's <c>CGfxObj::physics_sphere</c>. Radius and centre
/// are scaled together here, which is the whole point of taking them as
/// one value.
/// </summary>
public static ShadowShape Bsp(
uint gfxObjId,
Vector3 localPosition,
Quaternion localRotation,
float scale,
FlatCollisionSphere localBounds)
=> new(
gfxObjId,
localPosition,
localRotation,
scale,
ShadowCollisionType.BSP,
localBounds.Radius * scale,
0f,
localBounds.Origin * scale);
/// <summary>
/// One Setup CylSphere. <paramref name="localPosition"/> already IS the
/// shape's centre, so it carries no separate bounds centre.
/// </summary>
public static ShadowShape Cylinder(
uint gfxObjId,
Vector3 localPosition,
Quaternion localRotation,
float scale,
float radius,
float cylHeight)
=> new(
gfxObjId,
localPosition,
localRotation,
scale,
ShadowCollisionType.Cylinder,
radius,
cylHeight,
Vector3.Zero);
/// <summary>
/// One Setup Sphere. <paramref name="localPosition"/> already IS the
/// shape's centre, so it carries no separate bounds centre.
/// </summary>
public static ShadowShape Sphere(
uint gfxObjId,
Vector3 localPosition,
Quaternion localRotation,
float scale,
float radius)
=> new(
gfxObjId,
localPosition,
localRotation,
scale,
ShadowCollisionType.Sphere,
radius,
0f,
Vector3.Zero);
}

View file

@ -145,14 +145,13 @@ public static class ShadowShapeBuilder
{
if (cyl.Radius <= 0f) continue;
float baseHeight = cyl.Height > 0f ? cyl.Height : cyl.Radius * 4f;
result.Add(new ShadowShape(
GfxObjId: 0u,
LocalPosition: new Vector3(cyl.Origin.X, cyl.Origin.Y, cyl.Origin.Z) * entScale,
LocalRotation: Quaternion.Identity,
Scale: entScale,
CollisionType: ShadowCollisionType.Cylinder,
Radius: cyl.Radius * entScale,
CylHeight: baseHeight * entScale));
result.Add(ShadowShape.Cylinder(
gfxObjId: 0u,
localPosition: new Vector3(cyl.Origin.X, cyl.Origin.Y, cyl.Origin.Z) * entScale,
localRotation: Quaternion.Identity,
scale: entScale,
radius: cyl.Radius * entScale,
cylHeight: baseHeight * entScale));
}
// 2. Spheres — only when no CylSpheres. Retail's CylSphere loop
@ -166,14 +165,12 @@ public static class ShadowShapeBuilder
foreach (var sph in setup.Spheres)
{
if (sph.Radius <= 0f) continue;
result.Add(new ShadowShape(
GfxObjId: 0u,
LocalPosition: new Vector3(sph.Origin.X, sph.Origin.Y, sph.Origin.Z) * entScale,
LocalRotation: Quaternion.Identity,
Scale: entScale,
CollisionType: ShadowCollisionType.Sphere,
Radius: sph.Radius * entScale,
CylHeight: 0f));
result.Add(ShadowShape.Sphere(
gfxObjId: 0u,
localPosition: new Vector3(sph.Origin.X, sph.Origin.Y, sph.Origin.Z) * entScale,
localRotation: Quaternion.Identity,
scale: entScale,
radius: sph.Radius * entScale));
}
}
}
@ -211,20 +208,19 @@ public static class ShadowShapeBuilder
// the part origin: 376 of the 973 installed physics-BSP parts sit
// further from it than half their own radius. A single resolver
// supplies both so one cannot be taken without the other.
// Absent bounds keep the loose-but-safe 2 m placeholder.
FlatCollisionSphere? bounds = physicsBspBounds?.Invoke(gfxId);
float bspRadius = (bounds?.Radius ?? 2f) * entScale;
Vector3 boundsCenter = (bounds?.Origin ?? Vector3.Zero) * entScale;
// Absent bounds keep the loose-but-safe 2 m placeholder, centred
// on the part origin because nothing better is known.
// ShadowShape.Bsp scales radius and centre together.
FlatCollisionSphere bounds =
physicsBspBounds?.Invoke(gfxId)
?? new FlatCollisionSphere(Vector3.Zero, 2f);
result.Add(new ShadowShape(
GfxObjId: gfxId,
LocalPosition: new Vector3(partFrame.Origin.X, partFrame.Origin.Y, partFrame.Origin.Z) * entScale,
LocalRotation: partFrame.Orientation,
Scale: entScale,
CollisionType: ShadowCollisionType.BSP,
Radius: bspRadius,
CylHeight: 0f,
BoundsCenter: boundsCenter));
result.Add(ShadowShape.Bsp(
gfxObjId: gfxId,
localPosition: new Vector3(partFrame.Origin.X, partFrame.Origin.Y, partFrame.Origin.Z) * entScale,
localRotation: partFrame.Orientation,
scale: entScale,
localBounds: bounds));
}
return result;
@ -305,29 +301,19 @@ public static class ShadowShapeBuilder
// same CPartArray walk (CPartArray::calc_cross_cells_static
// @0x00518160), so dropping the center here mis-places the flood
// exactly as it did for live Setups.
float localRadius;
Vector3 localCenter;
if (hasFlat)
{
FlatCollisionSphere root = flat!.Nodes[flat.RootIndex].BoundingSphere;
localRadius = root.Radius;
localCenter = root.Origin;
}
else
{
localRadius = phys.BoundingSphere?.Radius ?? 1f;
localCenter = phys.BoundingSphere?.Origin ?? Vector3.Zero;
}
FlatCollisionSphere localBounds =
hasFlat
? flat!.Nodes[flat.RootIndex].BoundingSphere
: new FlatCollisionSphere(
phys.BoundingSphere?.Origin ?? Vector3.Zero,
phys.BoundingSphere?.Radius ?? 1f);
shapes.Add(new ShadowShape(
GfxObjId: meshRef.GfxObjId,
LocalPosition: pPos,
LocalRotation: pRot,
Scale: partScale,
CollisionType: ShadowCollisionType.BSP,
Radius: localRadius * partScale,
CylHeight: 0f,
BoundsCenter: localCenter * partScale));
shapes.Add(ShadowShape.Bsp(
gfxObjId: meshRef.GfxObjId,
localPosition: pPos,
localRotation: pRot,
scale: partScale,
localBounds: localBounds));
}
return shapes;

View file

@ -105,8 +105,10 @@ public sealed class LiveEntityCollisionBuilderTests
/// <c>CEnvCell::find_transit_cells</c> @0x0052cae0 transforms its centre
/// through the part's Position (<c>0x0052cb4c add eax,0x30</c>) before
/// reading the radius at <c>0x0052cb65</c>. Carrying only the radius is
/// AP-156: 170 of the 172 affected installed Setups then flood from a
/// sphere that does not contain their own collision geometry.
/// AP-156: 428 of the 530 installed BSP-bearing Setups then flood from
/// spheres that do not contain their own physics polygons. (The row as
/// filed said "170 of 172"; 172 is AP-152's DISPATCH population, not
/// AP-156's containment population — corrected at the fix review.)
/// </summary>
[Fact]
public void BspOnlyPart_UsesRealScaledPhysicsBoundingSphere()

View file

@ -81,14 +81,13 @@ public sealed class RemotePhysicsUpdaterTests
entity.Position,
entity.Rotation,
[
new ShadowShape(
ShadowShape.Cylinder(
0x01000001u,
new Vector3(1f, 0f, 0f),
Quaternion.Identity,
Scale: 1f,
CollisionType: ShadowCollisionType.Cylinder,
Radius: 0.25f,
CylHeight: 1f),
scale: 1f,
radius: 0.25f,
cylHeight: 1f),
],
state: (uint)PhysicsStateFlags.ReportCollisions,
flags: EntityCollisionFlags.None,

View file

@ -357,14 +357,13 @@ public sealed class RetailStaticAnimatingObjectSchedulerTests
entity.Rotation,
new[]
{
new ShadowShape(
ShadowShape.Cylinder(
GfxId,
Vector3.UnitX,
Quaternion.Identity,
Scale: 1f,
CollisionType: ShadowCollisionType.Cylinder,
Radius: 0.5f,
CylHeight: 1f),
scale: 1f,
radius: 0.5f,
cylHeight: 1f),
},
state: 0u,
flags: EntityCollisionFlags.None,

View file

@ -364,14 +364,13 @@ public sealed class LiveEntityRuntimeTests
entity.Rotation,
new[]
{
new ShadowShape(
ShadowShape.Cylinder(
0x01000001u,
Vector3.UnitX,
Quaternion.Identity,
Scale: 1f,
CollisionType: ShadowCollisionType.Cylinder,
Radius: 0.5f,
CylHeight: 1f),
scale: 1f,
radius: 0.5f,
cylHeight: 1f),
},
state: (uint)PhysicsStateFlags.ReportCollisions,
flags: EntityCollisionFlags.None,
@ -475,14 +474,13 @@ public sealed class LiveEntityRuntimeTests
oldEntity.Rotation,
new[]
{
new ShadowShape(
ShadowShape.Cylinder(
0x01000001u,
Vector3.UnitX,
Quaternion.Identity,
Scale: 1f,
CollisionType: ShadowCollisionType.Cylinder,
Radius: 0.5f,
CylHeight: 1f),
scale: 1f,
radius: 0.5f,
cylHeight: 1f),
},
state: (uint)PhysicsStateFlags.ReportCollisions,
flags: EntityCollisionFlags.None,

View file

@ -161,27 +161,53 @@ public sealed class InstalledSetupBspPrimitiveDispatchTests
}
// EXTERNAL constants for the containment sweep, measured 2026-08-06 by a
// scratch DatReaderWriter sweep that reproduced the geometry by hand
// rather than calling ShadowShapeBuilder, and independently reproduced by
// the AP-152 retail reviewer's own sweep. NOT derived from the code under
// test.
// scratch DatReaderWriter console program OUTSIDE the repo that resolves
// every quantity from client_portal.dat by hand and references no acdream
// assembly. NOT derived from the code under test.
//
// OffCentreParts is the population control: without it, a build in which
// every BSP root sphere happened to sit at its part origin would satisfy
// the containment claim vacuously.
// WouldFailIfOriginDiscarded is the DEFECT control: it re-runs the
// pre-fix composition (radius carried, root-sphere origin dropped) and
// pins how many of the affected Setups it breaks. If that number ever
// goes to zero the fixture population has stopped exercising the field
// and the containment assertion below has stopped meaning anything.
// BspBearingSetups / PhysicsBspParts / OffCentreParts / PhysicsVertices are
// population controls: without them a broken enumeration, a wrong dat path,
// a silently-empty polygon decode, or a build in which every BSP root
// sphere happened to sit at its part origin would all satisfy the
// containment claim vacuously.
//
// WouldFailIfOriginDiscarded is the DEFECT control: it re-runs the pre-fix
// composition (radius carried, root-sphere origin dropped) against the same
// oracle and pins how many Setups it breaks. If that number ever goes to
// zero the fixture population has stopped exercising the field and the
// containment assertion has stopped meaning anything.
//
// NOTE ON THE POPULATION (AP-156 review finding R2). The defect population
// is NOT the 172 AP-152 Setups. 172 is the DISPATCH population — Setups
// carrying both a primitive and a physics-BSP part. After AP-152 every
// BSP-bearing Setup floods from its BSP shapes alone, so a discarded root
// origin mis-places the flood for all 530 of them. 525 have at least one
// flood sphere move; 428 fail vertex-level containment at the 1 mm
// tolerance below (412 at a 1 cm tolerance — the figure the review quotes).
private const int ExpectedPhysicsBspParts = 973;
private const int ExpectedBspBearingSetups = 530;
private const int ExpectedOffCentreParts = 376; // |origin| > radius/2
private const int ExpectedWouldFailIfOriginDiscarded = 170; // of 172
private const int ExpectedPhysicsVertices = 91689;
private const int ExpectedWouldFailIfOriginDiscarded = 428; // of 530
private const int ExpectedDeepestBspPartArray = 49; // Setup 0x02001A91
/// <summary>
/// AP-156. Every flood sphere acdream emits for a physics-BSP part must
/// CONTAIN that part's real collision geometry.
/// CONTAIN that part's real collision geometry — and the oracle for "real
/// collision geometry" is the part's PHYSICS-POLYGON VERTICES, not its
/// bounding sphere.
///
/// <para>
/// That distinction is the point. The first version of this test compared
/// the emitted flood sphere against a hand-rebuilt copy of the same
/// bounding sphere from the same resolver, which made the shortfall
/// algebraically identically zero for any DAT input — a green test that
/// could not fail (review finding R1). Vertices come from a DIFFERENT DAT
/// field (<c>GfxObj.PhysicsPolygons</c> -&gt; <c>GfxObj.VertexArray</c>)
/// than the bounding sphere the builder emits, so the assertion now has
/// something real to disagree with: any error in which sphere is read,
/// where it is placed, or how it is scaled shows up as an uncovered vertex.
/// </para>
///
/// <para>
/// A GfxObj's physics BSP is authored in the GfxObj's own coordinates and
@ -189,12 +215,9 @@ public sealed class InstalledSetupBspPrimitiveDispatchTests
/// of the 973 installed physics-BSP parts sit further from it than half
/// their own radius, worst 20.762 m on a 27.708 m sphere (gfx 0x010036DD,
/// Setup 0x0200129A). acdream used to take the sphere's radius and drop
/// its origin, flooding from the part origin instead: over the 172
/// AP-152 Setups that failed to contain the object's own BSP sphere for
/// 170 of them, worst shortfall 9.911 m (Setup 0x02000255, whose single
/// part's root sphere sits 9.911 m above the part origin). Indoor floods
/// are 3-D (<c>CellTransit.BuildShadowCellSet</c> routes every candidate
/// with <c>id &amp; 0xFFFF &gt;= 0x0100</c> through
/// its origin, flooding from the part origin instead. Indoor floods are
/// 3-D (<c>CellTransit.BuildShadowCellSet</c> routes every candidate with
/// <c>id &amp; 0xFFFF &gt;= 0x0100</c> through
/// <c>FindTransitCellsSphere</c>), so a tall prop or door slab simply was
/// not registered in the EnvCells it occupies — never a broadphase
/// candidate there, the #98 / #168 class.
@ -212,7 +235,7 @@ public sealed class InstalledSetupBspPrimitiveDispatchTests
/// </para>
/// </summary>
[Fact]
public void InstalledSetups_BspFloodSpheres_ContainTheirOwnBoundingSpheres()
public void InstalledSetups_BspFloodSpheres_ContainTheirOwnPhysicsPolygons()
{
string? datDir = ContentConformanceDats.ResolveDatDir();
if (datDir is null)
@ -220,12 +243,17 @@ public sealed class InstalledSetupBspPrimitiveDispatchTests
using var dats = new DatCollection(datDir, DatAccessType.Read);
// Two INDEPENDENT reads of the same GfxObj: the bounding sphere the
// builder is handed, and the physics-polygon vertices that are the
// truth it must cover. Only the sphere is fed to ShadowShapeBuilder.
var boundsCache = new Dictionary<uint, FlatCollisionSphere?>();
var vertexCache = new Dictionary<uint, Vector3[]>();
FlatCollisionSphere? Bounds(uint gfxObjId)
{
if (boundsCache.TryGetValue(gfxObjId, out FlatCollisionSphere? cached))
return cached;
FlatCollisionSphere? result = null;
Vector3[] vertices = [];
if (dats.Portal.TryGet<GfxObj>(gfxObjId, out GfxObj? gfx)
&& gfx is not null
&& gfx.Flags.HasFlag(GfxObjFlags.HasPhysics)
@ -234,15 +262,31 @@ public sealed class InstalledSetupBspPrimitiveDispatchTests
&& gfx.PhysicsBSP.Root.BoundingSphere is { } bs)
{
result = new FlatCollisionSphere(bs.Origin, bs.Radius);
var collected = new List<Vector3>();
foreach (var polygon in gfx.PhysicsPolygons.Values)
{
foreach (var vertexId in polygon.VertexIds)
{
if (gfx.VertexArray.Vertices.TryGetValue(
(ushort)vertexId, out var vertex))
{
collected.Add(vertex.Origin);
}
}
}
vertices = collected.ToArray();
}
boundsCache[gfxObjId] = result;
vertexCache[gfxObjId] = vertices;
return result;
}
const float EntScale = 1.75f; // not 1: a dropped scale must show up
const float Tolerance = 1e-3f;
int bspParts = 0;
int bspBearingSetups = 0;
int offCentreParts = 0;
int affected = 0;
int physicsVertices = 0;
int wouldFailIfOriginDiscarded = 0;
float worstShortfall = 0f;
uint worstShortfallSetup = 0u;
@ -255,7 +299,7 @@ public sealed class InstalledSetupBspPrimitiveDispatchTests
continue;
// Independent oracle: resolve the placement frame from the raw
// Setup and place each part's TRUE root sphere by hand.
// Setup and place each part's TRUE physics polygons by hand.
AnimationFrame? placement = null;
if (setup.PlacementFrames.TryGetValue(Placement.Resting, out var resting))
placement = resting;
@ -263,10 +307,11 @@ public sealed class InstalledSetupBspPrimitiveDispatchTests
placement = def;
else foreach (var kvp in setup.PlacementFrames) { placement = kvp.Value; break; }
var truth = new List<(Vector3 Centre, float Radius)>();
var truth = new List<Vector3>();
for (int i = 0; i < setup.Parts.Count; i++)
{
FlatCollisionSphere? b = Bounds((uint)setup.Parts[i]);
uint partGfxObjId = (uint)setup.Parts[i];
FlatCollisionSphere? b = Bounds(partGfxObjId);
if (b is null) continue;
bspParts++;
if (b.Value.Origin.Length() > b.Value.Radius / 2f)
@ -279,18 +324,15 @@ public sealed class InstalledSetupBspPrimitiveDispatchTests
partOrigin = placement.Frames[i].Origin;
partRot = placement.Frames[i].Orientation;
}
truth.Add((
(partOrigin + Vector3.Transform(b.Value.Origin, partRot)) * EntScale,
b.Value.Radius * EntScale));
foreach (Vector3 vertex in vertexCache[partGfxObjId])
{
truth.Add(
(partOrigin + Vector3.Transform(vertex, partRot)) * EntScale);
}
}
if (truth.Count == 0) continue;
bool hasCylinder = false;
foreach (var cyl in setup.CylSpheres) if (cyl.Radius > 0f) { hasCylinder = true; break; }
bool hasSphere = false;
foreach (var sph in setup.Spheres) if (sph.Radius > 0f) { hasSphere = true; break; }
if (hasCylinder || (setup.CylSpheres.Count == 0 && hasSphere))
affected++;
bspBearingSetups++;
physicsVertices += truth.Count;
// Production emission, through the production bounds seam.
IReadOnlyList<ShadowShape> shapes = ShadowShapeBuilder.FromSetup(
@ -301,11 +343,17 @@ public sealed class InstalledSetupBspPrimitiveDispatchTests
// ShadowObjectRegistry.BuildFloodSpheres' composition, at an
// entity placed at the world origin with identity rotation.
// EVERY BSP shape contributes: retail's BSP branch has no
// sphere cap (the 10-clamp at 0x0052ba21 is inside the cylsphere
// overload only), and 7 installed Setups carry more than 10
// physics-BSP parts — capping here would silently exclude their
// tail from the containment claim below.
// Deliberately UNCAPPED, matching production: retail's BSP branch
// has no sphere cap (the 10-clamp at 0x0052ba21 is inside the
// cylsphere overload only). This loop is the test's own
// re-implementation, so it cannot observe a cap regression in
// BuildFloodSpheres — that is covered by
// ShadowObjectRegistryMultiPartTests
// .BuildFloodSpheres_CapsCylSpheresAtTenButNeverTheBspParts, which
// reddens under both cap sabotages. What the mostBspShapesOnOneSetup
// assertion below DOES prove is that the containment claim reaches
// Setups past the retired 10-sphere clamp rather than stopping short
// of them.
var flood = new List<(Vector3 Centre, float Radius)>();
var floodIfOriginDiscarded = new List<(Vector3 Centre, float Radius)>();
foreach (ShadowShape shape in shapes)
@ -323,12 +371,12 @@ public sealed class InstalledSetupBspPrimitiveDispatchTests
float Shortfall(List<(Vector3 Centre, float Radius)> spheres)
{
float worst = 0f;
foreach ((Vector3 tc, float tr) in truth)
foreach (Vector3 point in truth)
{
float best = float.MaxValue;
foreach ((Vector3 fc, float fr) in spheres)
{
float need = (tc - fc).Length() + tr - fr;
float need = (point - fc).Length() - fr;
if (need < best) best = need;
}
if (best > worst) worst = best;
@ -336,7 +384,6 @@ public sealed class InstalledSetupBspPrimitiveDispatchTests
return worst;
}
const float Tolerance = 1e-3f;
float shortfall = Shortfall(flood);
if (shortfall > Tolerance)
{
@ -347,28 +394,23 @@ public sealed class InstalledSetupBspPrimitiveDispatchTests
worstShortfallSetup = id;
}
}
if ((hasCylinder || (setup.CylSpheres.Count == 0 && hasSphere))
&& Shortfall(floodIfOriginDiscarded) > Tolerance)
{
if (Shortfall(floodIfOriginDiscarded) > Tolerance)
wouldFailIfOriginDiscarded++;
}
}
// Population + defect controls first.
Assert.Equal(ExpectedPhysicsBspParts, bspParts);
Assert.Equal(ExpectedBspBearingSetups, bspBearingSetups);
Assert.Equal(ExpectedOffCentreParts, offCentreParts);
Assert.Equal(ExpectedAffected, affected);
Assert.Equal(ExpectedPhysicsVertices, physicsVertices);
Assert.Equal(ExpectedWouldFailIfOriginDiscarded, wouldFailIfOriginDiscarded);
// Cap control: the deepest installed part array is 49 BSP shapes, so
// the containment claim genuinely covers Setups past the retired
// 10-sphere clamp rather than stopping short of them.
Assert.Equal(ExpectedDeepestBspPartArray, mostBspShapesOnOneSetup);
// The fact.
Assert.True(
uncontained.Count == 0,
$"{uncontained.Count} Setups flood from a sphere that does not contain "
+ $"their own physics-BSP bounding sphere; worst shortfall "
$"{uncontained.Count} Setups flood from spheres that do not contain "
+ $"their own physics-polygon geometry; worst shortfall "
+ $"{worstShortfall.ToString("F3", CultureInfo.InvariantCulture)} m on "
+ $"Setup 0x{worstShortfallSetup:X8}.");
}

View file

@ -921,7 +921,12 @@ public class DoorBugTrajectoryReplayTests
{
var phys = cache.GetGfxObj(s.GfxObjId);
float bspR = phys?.BoundingSphere?.Radius ?? 2f;
shapes.Add(s with { Radius = bspR });
shapes.Add(ShadowShape.Bsp(
s.GfxObjId,
s.LocalPosition,
s.LocalRotation,
s.Scale,
new FlatCollisionSphere(Vector3.Zero, bspR / s.Scale)));
}
else
{
@ -1103,23 +1108,20 @@ public class DoorBugTrajectoryReplayTests
// to the BSP slab; the cylinder is a small foot collider).
// entityWorldPos = BSP world pos so LocalPos=0 puts the BSP at
// the captured center. cellScope=0u mirrors production.
var bspShape = new ShadowShape(
GfxObjId: DoorGfxObjId,
LocalPosition: Vector3.Zero,
LocalRotation: Quaternion.Identity,
Scale: 1f,
CollisionType: ShadowCollisionType.BSP,
Radius: BspRadius,
CylHeight: 0f);
var bspShape = ShadowShape.Bsp(
gfxObjId: DoorGfxObjId,
localPosition: Vector3.Zero,
localRotation: Quaternion.Identity,
scale: 1f,
localBounds: new FlatCollisionSphere(Vector3.Zero, BspRadius));
var cylShape = new ShadowShape(
GfxObjId: 0u,
LocalPosition: CylWorldPos - BspWorldPos, // express cyl relative to entity origin
LocalRotation: Quaternion.Identity,
Scale: 1f,
CollisionType: ShadowCollisionType.Cylinder,
Radius: CylRadius,
CylHeight: CylHeight);
var cylShape = ShadowShape.Cylinder(
gfxObjId: 0u,
localPosition: CylWorldPos - BspWorldPos, // express cyl relative to entity origin
localRotation: Quaternion.Identity,
scale: 1f,
radius: CylRadius,
cylHeight: CylHeight);
engine.ShadowObjects.RegisterMultiPart(
entityId: DoorEntityId,

View file

@ -14,38 +14,31 @@ public class ShadowObjectRegistryMultiPartTests
private static IReadOnlyList<ShadowShape> DoorShapes() => new[]
{
new ShadowShape(
GfxObjId: 0u,
LocalPosition: new Vector3(0f, 0f, 0.018f),
LocalRotation: Quaternion.Identity,
Scale: 1.0f,
CollisionType: ShadowCollisionType.Cylinder,
Radius: 0.100f,
CylHeight: 0.200f),
new ShadowShape(
GfxObjId: 0x010044B5u,
LocalPosition: Vector3.Zero,
LocalRotation: Quaternion.Identity,
Scale: 1.0f,
CollisionType: ShadowCollisionType.BSP,
Radius: 2.0f,
CylHeight: 0f),
new ShadowShape(
GfxObjId: 0x010044B6u,
LocalPosition: Vector3.Zero,
LocalRotation: Quaternion.Identity,
Scale: 1.0f,
CollisionType: ShadowCollisionType.BSP,
Radius: 2.0f,
CylHeight: 0f),
new ShadowShape(
GfxObjId: 0x010044B6u,
LocalPosition: Vector3.Zero,
LocalRotation: Quaternion.Identity,
Scale: 1.0f,
CollisionType: ShadowCollisionType.BSP,
Radius: 2.0f,
CylHeight: 0f)
ShadowShape.Cylinder(
gfxObjId: 0u,
localPosition: new Vector3(0f, 0f, 0.018f),
localRotation: Quaternion.Identity,
scale: 1.0f,
radius: 0.100f,
cylHeight: 0.200f),
ShadowShape.Bsp(
gfxObjId: 0x010044B5u,
localPosition: Vector3.Zero,
localRotation: Quaternion.Identity,
scale: 1.0f,
localBounds: new FlatCollisionSphere(Vector3.Zero, 2.0f)),
ShadowShape.Bsp(
gfxObjId: 0x010044B6u,
localPosition: Vector3.Zero,
localRotation: Quaternion.Identity,
scale: 1.0f,
localBounds: new FlatCollisionSphere(Vector3.Zero, 2.0f)),
ShadowShape.Bsp(
gfxObjId: 0x010044B6u,
localPosition: Vector3.Zero,
localRotation: Quaternion.Identity,
scale: 1.0f,
localBounds: new FlatCollisionSphere(Vector3.Zero, 2.0f))
};
[Fact]
@ -134,10 +127,8 @@ public class ShadowObjectRegistryMultiPartTests
// Two shapes 30m apart in X — must span two outdoor 24m cells.
var shapes = new[]
{
new ShadowShape(0u, new Vector3( 0f, 0f, 0f), Quaternion.Identity, 1f,
ShadowCollisionType.Cylinder, 1f, 2f),
new ShadowShape(0u, new Vector3(30f, 0f, 0f), Quaternion.Identity, 1f,
ShadowCollisionType.Cylinder, 1f, 2f),
ShadowShape.Cylinder(0u, new Vector3( 0f, 0f, 0f), Quaternion.Identity, 1f, 1f, 2f),
ShadowShape.Cylinder(0u, new Vector3(30f, 0f, 0f), Quaternion.Identity, 1f, 1f, 2f),
};
reg.RegisterMultiPart(0x1u, new Vector3(12f, 12f, 50f), Quaternion.Identity,
shapes, 0u, EntityCollisionFlags.None, OffX, OffY, LbId);
@ -170,10 +161,8 @@ public class ShadowObjectRegistryMultiPartTests
var shapes = new[]
{
new ShadowShape(0u, new Vector3(0f, 0f, 0f), Quaternion.Identity, 1f,
ShadowCollisionType.Cylinder, 0.5f, 1f),
new ShadowShape(0u, new Vector3(1f, 0f, 0f), Quaternion.Identity, 1f,
ShadowCollisionType.Cylinder, 0.5f, 1f),
ShadowShape.Cylinder(0u, new Vector3(0f, 0f, 0f), Quaternion.Identity, 1f, 0.5f, 1f),
ShadowShape.Cylinder(0u, new Vector3(1f, 0f, 0f), Quaternion.Identity, 1f, 0.5f, 1f),
};
reg.RegisterMultiPart(movingEntityId, new Vector3(10f, 10f, 50f),
Quaternion.Identity, shapes, 0u,
@ -243,10 +232,14 @@ public class ShadowObjectRegistryMultiPartTests
return cells;
}
private static ShadowShape Cyl(float radius) => new(
GfxObjId: 0u, LocalPosition: Vector3.Zero, LocalRotation: Quaternion.Identity,
Scale: 1f, CollisionType: ShadowCollisionType.Cylinder,
Radius: radius, CylHeight: radius * 2f);
private static ShadowShape Cyl(float radius, Vector3 localPosition = default)
=> ShadowShape.Cylinder(
gfxObjId: 0u,
localPosition: localPosition,
localRotation: Quaternion.Identity,
scale: 1f,
radius: radius,
cylHeight: radius * 2f);
/// <summary>
/// A physics-BSP part shape. <paramref name="boundsCenter"/> defaults
@ -261,13 +254,15 @@ public class ShadowObjectRegistryMultiPartTests
float radius,
Vector3 boundsCenter = default,
Vector3 localPosition = default,
Quaternion localRotation = default) => new(
GfxObjId: 0x010044B5u,
LocalPosition: localPosition,
LocalRotation: localRotation == default ? Quaternion.Identity : localRotation,
Scale: 1f, CollisionType: ShadowCollisionType.BSP,
Radius: radius, CylHeight: 0f,
BoundsCenter: boundsCenter == default ? new Vector3(0f, 6f, 0f) : boundsCenter);
Quaternion localRotation = default)
=> ShadowShape.Bsp(
gfxObjId: 0x010044B5u,
localPosition: localPosition,
localRotation: localRotation == default ? Quaternion.Identity : localRotation,
scale: 1f,
localBounds: new FlatCollisionSphere(
boundsCenter == default ? new Vector3(0f, 6f, 0f) : boundsCenter,
radius));
private static List<uint> FloodCellsFor(params ShadowShape[] shapes)
{
@ -317,9 +312,12 @@ public class ShadowObjectRegistryMultiPartTests
///
/// <para>
/// acdream used to flood from the part ORIGIN with the sphere's radius.
/// Over the installed DAT that failed to contain the object's own BSP
/// sphere for 170 of the 172 AP-152 Setups, shortfall up to 9.911 m
/// (0x02000255) — under-inclusive membership, the #98 / #168 class.
/// Over the installed DAT that failed to contain the parts' own physics
/// polygons for 428 of the 530 BSP-bearing Setups, shortfall up to
/// 35.869 m at entity scale 1.75 (0x0200129A) — under-inclusive
/// membership, the #98 / #168 class. (172 is AP-152's DISPATCH
/// population; the AP-156 row's original "170 of 172" understated this
/// 2.5x and was corrected at the fix review.)
/// </para>
/// </summary>
[Fact]
@ -377,8 +375,8 @@ public class ShadowObjectRegistryMultiPartTests
var cyls = new ShadowShape[11];
for (int i = 0; i < 10; i++)
cyls[i] = Cyl(1f) with { LocalPosition = near };
cyls[10] = Cyl(1f) with { LocalPosition = far };
cyls[i] = Cyl(1f, near);
cyls[10] = Cyl(1f, far);
List<uint> cylCells = FloodCellsFor(cyls);
Assert.Contains(ownCell, bspCells);

View file

@ -967,14 +967,13 @@ public class ShadowObjectRegistryTests
};
}
private static ShadowShape BspShape(uint gfxObjId, float radius) => new(
gfxObjId,
Vector3.Zero,
Quaternion.Identity,
Scale: 1f,
CollisionType: ShadowCollisionType.BSP,
Radius: radius,
CylHeight: 0f);
private static ShadowShape BspShape(uint gfxObjId, float radius)
=> ShadowShape.Bsp(
gfxObjId,
Vector3.Zero,
Quaternion.Identity,
scale: 1f,
localBounds: new FlatCollisionSphere(Vector3.Zero, radius));
private static CellPhysics BuildShadowCellSetTests_MakeLeafCell(Matrix4x4 worldTransform)
{

View file

@ -48,9 +48,9 @@ public class ShadowRegistrationOverflowTests
// ── The bug: old per-part Register loses one registration ─────────────
private static ShadowShape Cyl(Vector3 local) => new(
GfxObjId: 0u, LocalPosition: local, LocalRotation: Quaternion.Identity,
Scale: 1f, CollisionType: ShadowCollisionType.Cylinder, Radius: 1f, CylHeight: 2f);
private static ShadowShape Cyl(Vector3 local) => ShadowShape.Cylinder(
gfxObjId: 0u, localPosition: local, localRotation: Quaternion.Identity,
scale: 1f, radius: 1f, cylHeight: 2f);
[Fact]
public void OldPerPartRegister_CollidingIds_SecondSilentlyOverwritesFirst()

View file

@ -461,12 +461,11 @@ public sealed class ShadowSetPositionCommitTests
return registry;
}
private static ShadowShape Shape(uint gfxObjId, Vector3 local) => new(
gfxObjId,
local,
Quaternion.Identity,
1f,
ShadowCollisionType.BSP,
0.25f,
0f);
private static ShadowShape Shape(uint gfxObjId, Vector3 local)
=> ShadowShape.Bsp(
gfxObjId,
local,
Quaternion.Identity,
scale: 1f,
localBounds: new FlatCollisionSphere(Vector3.Zero, 0.25f));
}