fix(physics): AP-152 — dispatch collision shapes BSP-first, at emission and at the cell flood
The register row predicted "catching or stopping on a doorway sill". That
symptom could not have been occurring. `Transition.BspOnlyDispatch`
(TransitionTypes.cs:1348, landed 2026-05-25 as A6.P7) already skipped both
primitive branches (:3911, :3954) whenever the target's wire PhysicsState
carries HAS_PHYSICS_BSP_PS, and ACE sets that bit from CSetup.HasPhysicsBSP
for every affected Setup. The extra primitive was never tested for collision.
The live defect was CELL MEMBERSHIP. The same shape list feeds
`ShadowObjectRegistry.BuildFloodSpheres`, which had no such guard and
preferred Cylinders over everything whenever any Cylinder existed — retail's
SECOND priority applied ahead of its first. For the 73 CylSphere+BSP Setups
acdream therefore flooded shadow cells from the cylinder and never from the
slab: an object absent from cells it physically occupies, which is the
#98 / #168 symptom class, not the door-collision class the row named.
Retail, re-disassembled from the PDB-paired binary (v11.4186, CodeView GUID
9e847e2f-777c-4bd9-886c-22256bb87f32, check_exe_pdb.py MATCH) rather than
taken from Binary Ninja, which drops flag tests:
CPhysicsObj::FindObjCollisions @0x0050f050
0x0050f165 test dword [esi+0xa8], 0x10000
0x0050f16f je 0x50f1a2 ; clear -> primitive dispatch
0x0050f18d call 0x518180 ; CPartArray::FindObjCollisions
0x0050f19d jmp 0x50f2b0 ; UNCONDITIONAL, past BOTH primitive loops
; (CylSphere 0x50f1a2, Sphere 0x50f21d)
0x0050f1d6 jae 0x50f317 ; CylSphere loop exhausted -> RETURN
0x0050f22f je 0x50f31b ; zero Spheres -> RETURN seeded OK_TS
CPhysicsObj::calc_cross_cells @0x00515230
0x00515285 test dword [esi+0xa8], 0x10000
0x0051528f jne 0x515305 -> CPhysicsObj::find_bbox_cell_list @0x00510fc0
0x005152d1 call 0x52b9f0 ; cylsphere branch, below the jump
0x005152fb call 0x52b990 ; sorting-sphere branch, below the jump
Priority at both consumers: BSP -> CylSphere -> Sphere -> nothing. BSP wins.
Every address above was resolved back to its symbol by exact lookup in
named-retail/symbols.json.
Changes:
* `ShadowShapeBuilder.FromSetup` gains a step-0 dispatch gate. Steps 1 and 2
are skipped entirely when any part's EFFECTIVE GfxObj carries a physics
BSP. The gate and step 3 now share one `EffectivePartGfxObjId` helper, so
they cannot read different identities — a gate on `setup.Parts` would,
after an ObjDesc swap, suppress the primitives while step 3 emitted
nothing and `Build` returned null, deleting the entity's collision.
Emission order is unchanged. This also removes acdream's undeclared
reliance on the server sending the flag: the gate is derived from the
parts, exactly as CPartArray::CacheHasPhysicsBSP @0x00518110 derives it.
* `ShadowObjectRegistry.BuildFloodSpheres` now applies calc_cross_cells'
own order: BSP, else Cylinder, else everything. Given the gate above this
is a no-op for every shape list acdream produces (FromSetup is now
exclusive; both landblock-static publishers already emit homogeneous
lists), so the measured membership delta remains attributable to the
gate alone. It is kept for the same reason BspOnlyDispatch is kept: retail
genuinely dispatches here, and it guards a future additive producer.
`Transition.BspOnlyDispatch` is deliberately untouched.
Register: AP-152 RETIRED with its four false statements corrected — the risk
statement (the symptom was already inert); "small and centred at the part
origin" (max primitive is 6.714 m, and 0x0200086E's sphere origin is
(0.759, 0.165, 5.842)); the cottage door's "~14 cm base Sphere" (it is
0.100 m; 0.141 is Setup.Radius, which AP-22 proved is never collision
geometry); and naming one pinning test where two existed. AP-153/154/155
filed: retail's dispatch flag is cached once at InitPartArrayObject+0x7e
where acdream's gate is live; the query-time guard takes a client-derived
flag off the wire; and the static publishers emit Setup Spheres as
height-capped Cylinders while BuildFloodSpheres approximates retail's
bounding box with bounding spheres.
Tests. Both pinning tests corrected, neither deleted:
`FromSetup_DoorSetup_ProducesFourShapes` -> `..._EmitsBspPartsOnly`;
`FromSetup_DoorSetup_SphereAtExpectedLocalOffset` re-hosted on
`_ => false`, the DAT-real configuration for the 3,605 Sphere-only Setups.
`FromSetup_ScaleFactor_MultipliesAllRadiiAndOffsets` was the campaign's
eighth green test covering nothing — its assertions sat inside
`if (CollisionType == Cylinder)` on a fixture with zero CylSpheres, so only
`Scale == 2.0f` ever ran. Proved empirically: with the sphere radius scale
deleted, the old body passes and the corrected body fails. Three new facts:
the effective-identity gate, the App-layer CylSphere+BSP registration (no
App fixture combined the two before), and the flood-set dispatch. One new
installed-DAT sweep pins 172 affected Setups (73 CylSphere+BSP, 99
Sphere+BSP) behind external bucket controls, re-measured independently and
agreeing exactly with the filing commit's separate sweep.
All eight sabotages run and reported; every discriminating fact reddens in
the intended direction and only there. Clean Release build after deleting
every bin/obj: 0 errors. Complete suite 11,203 passed / 4 skipped / 0
failed, +5 on the 11,198 baseline at ec29a732 — exactly the five added
facts, no new skips.
Blast radius, corrected: the FromSetup half is graphical-only (its sole
production caller is LiveEntityCollisionBuilder in AcDream.App, which
AcDream.Headless cannot reference — Headless -> Runtime -> Core/Content).
The BuildFloodSpheres half lives in AcDream.Core and DOES execute in
Headless via LandblockPhysicsContentBuilder, but is behaviour-neutral there
because both of that builder's registrations pass homogeneous lists.
Headless suite green at 89/89.
NOT yet gated live: this changes shadow-cell membership for 22 Setups used
by 151 Door weenies and 38 stationary props. Needs a connected session.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
ec29a732f5
commit
4abd1b5eb7
9 changed files with 1635 additions and 85 deletions
|
|
@ -597,11 +597,35 @@ public sealed class ShadowObjectRegistry
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retail flood-sphere rule (CylSphere overload, Ghidra 0x0052b9f0):
|
||||
/// when the object has cylinder shapes, each contributes one sphere at
|
||||
/// its world BASE point (low_pt) with the cylinder radius, capped at 10;
|
||||
/// otherwise the BSP parts' bounding spheres are the footprint (the
|
||||
/// sorting-sphere fallback, calc_cross_cells 0x00515230 tail).
|
||||
/// Retail cross-cell dispatch, <c>CPhysicsObj::calc_cross_cells</c>
|
||||
/// @0x00515230, in retail's own priority order:
|
||||
///
|
||||
/// <list type="number">
|
||||
/// <item>BSP-bearing (<c>0x00515285 test dword [esi+0xa8],0x10000</c> /
|
||||
/// <c>0x0051528f jne 0x515305</c>) → <c>CPhysicsObj::find_bbox_cell_list</c>
|
||||
/// @0x00510fc0. The cylsphere and sorting-sphere branches are BOTH below
|
||||
/// that jump and unreachable from it. acdream approximates the bbox with
|
||||
/// the BSP parts' bounding spheres.</item>
|
||||
/// <item>else cylspheres (<c>0x00515298 GetNumCylsphere</c> non-zero) →
|
||||
/// <c>CObjCell::find_cell_list</c> @0x0052b9f0 over the cylsphere array;
|
||||
/// each contributes one sphere at its world BASE point with the cylinder
|
||||
/// radius, capped at 10.</item>
|
||||
/// <item>else the sorting sphere (<c>0x005152dc</c> →
|
||||
/// <c>CPartArray::GetSortingSphere</c> @0x00518b00 →
|
||||
/// <c>CObjCell::find_cell_list</c> @0x0052b990).</item>
|
||||
/// </list>
|
||||
///
|
||||
/// <para>
|
||||
/// The BSP-first rule is redundant for every shape list acdream produces
|
||||
/// today — <see cref="ShadowShapeBuilder.FromSetup"/> dispatches at
|
||||
/// emission (AP-152) and both landblock-static publishers emit
|
||||
/// homogeneous lists — exactly as
|
||||
/// <c>Transition.BspOnlyDispatch</c> is redundant at the query site. It is
|
||||
/// kept because retail genuinely dispatches here, and because a producer
|
||||
/// that handed this method a mixed list would otherwise flood a
|
||||
/// BSP-bearing object from its primitive and silently place it in the
|
||||
/// wrong shadow cells (the #98 / #168 symptom class).
|
||||
/// </para>
|
||||
/// </summary>
|
||||
private static List<DatReaderWriter.Types.Sphere> BuildFloodSpheres(
|
||||
Vector3 entityWorldPos,
|
||||
|
|
@ -611,15 +635,25 @@ public sealed class ShadowObjectRegistry
|
|||
const int RetailSphereCap = 10;
|
||||
|
||||
var spheres = new List<DatReaderWriter.Types.Sphere>();
|
||||
bool anyBsp = false;
|
||||
bool anyCyl = false;
|
||||
foreach (var s in shapes)
|
||||
{
|
||||
if (s.CollisionType == ShadowCollisionType.Cylinder) { anyCyl = true; break; }
|
||||
if (s.CollisionType == ShadowCollisionType.BSP) anyBsp = true;
|
||||
else if (s.CollisionType == ShadowCollisionType.Cylinder) anyCyl = true;
|
||||
}
|
||||
|
||||
// Retail's branch, chosen once: BSP-bbox, else cylspheres, else the
|
||||
// sorting sphere (which acdream approximates with the remaining
|
||||
// shapes' bounding spheres).
|
||||
ShadowCollisionType? only =
|
||||
anyBsp ? ShadowCollisionType.BSP
|
||||
: anyCyl ? ShadowCollisionType.Cylinder
|
||||
: null;
|
||||
|
||||
foreach (var s in shapes)
|
||||
{
|
||||
if (anyCyl && s.CollisionType != ShadowCollisionType.Cylinder)
|
||||
if (only is { } required && s.CollisionType != required)
|
||||
continue;
|
||||
if (spheres.Count >= RetailSphereCap)
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -14,21 +14,25 @@ namespace AcDream.Core.Physics;
|
|||
/// <see cref="ShadowObjectRegistry.RegisterMultiPart"/>.
|
||||
///
|
||||
/// <para>
|
||||
/// Walks (1) every CylSphere → Cylinder shape, (2) every Sphere ONLY when no
|
||||
/// CylSpheres are present (matches retail and the existing landblock-static
|
||||
/// convention at GameWindow.cs:6034), and (3) every Part whose GfxObj has a
|
||||
/// non-null PhysicsBSP → per-part BSP shape, with local transforms from
|
||||
/// PlacementFrames[Resting | Default | first available].
|
||||
/// This is a DISPATCH, not a union. In priority order: (3) when ANY Part's
|
||||
/// effective GfxObj has a non-null PhysicsBSP, emit one BSP shape per such
|
||||
/// Part — and nothing else; otherwise (1) every CylSphere → Cylinder shape;
|
||||
/// otherwise (2) every Sphere → Sphere shape; otherwise nothing at all. Local
|
||||
/// transforms come from PlacementFrames[Resting | Default | first available].
|
||||
/// </para>
|
||||
///
|
||||
/// <para>
|
||||
/// Retail anchor: <c>CPhysicsObj::FindObjCollisions</c> (0x0050f050)
|
||||
/// dispatches EXCLUSIVELY on <c>HAS_PHYSICS_BSP_PS</c> (0x10000): it calls
|
||||
/// dispatches EXCLUSIVELY on <c>HAS_PHYSICS_BSP_PS</c> (0x10000)
|
||||
/// (<c>0x0050f165 test dword [esi+0xa8],0x10000</c> /
|
||||
/// <c>0x0050f16f je 0x50f1a2</c>): it calls
|
||||
/// <c>CPartArray::FindObjCollisions</c> (the per-part BSP walk) and returns
|
||||
/// (<c>0x0050f19d jmp</c> past the primitive branches), OR walks the Setup's
|
||||
/// CylSpheres, OR walks the Setup's Spheres, OR — with none of the three —
|
||||
/// returns the seeded <c>OK_TS</c> without synthesizing any shape
|
||||
/// (<c>0x0050f22f je 0x50f31b</c>). It is never a union.
|
||||
/// (<c>0x0050f19d jmp 0x50f2b0</c>, an UNCONDITIONAL jump past both primitive
|
||||
/// branches — the CylSphere loop starts at 0x50f1a2 and the Sphere loop at
|
||||
/// 0x50f21d), OR walks the Setup's CylSpheres and returns
|
||||
/// (<c>0x0050f1d6 jae 0x50f317</c>), OR walks the Setup's Spheres, OR — with
|
||||
/// none of the three — returns the seeded <c>OK_TS</c> without synthesizing
|
||||
/// any shape (<c>0x0050f22f je 0x50f31b</c>). BSP wins.
|
||||
/// <c>CPhysicsPart::find_obj_collisions</c> (0x0050d8d0) tests ONLY the
|
||||
/// GfxObj physics BSP; CylSpheres and Spheres are <c>Setup</c>-level arrays
|
||||
/// reached through <c>CPartArray::GetCylsphere</c> (0x00518090) and
|
||||
|
|
@ -36,12 +40,28 @@ namespace AcDream.Core.Physics;
|
|||
/// </para>
|
||||
///
|
||||
/// <para>
|
||||
/// KNOWN DIVERGENCE (AP-152): steps 1/2 and step 3 below are emitted
|
||||
/// ADDITIVELY here, where retail is exclusive — 172 of 5,935 installed
|
||||
/// Setups carry a primitive and a physics-BSP part. Do not cite the anchor
|
||||
/// above as justification for the additive design; it is the evidence
|
||||
/// against it. acdream's two static publication paths already implement the
|
||||
/// exclusive rule.
|
||||
/// Cell membership dispatches on the SAME flag and in the same priority:
|
||||
/// <c>CPhysicsObj::calc_cross_cells</c> (0x00515230) tests
|
||||
/// <c>0x10000</c> at <c>0x00515285</c> and routes a BSP-bearing object to
|
||||
/// <c>CPhysicsObj::find_bbox_cell_list</c> (0x00510fc0) at
|
||||
/// <c>0x0051528f jne 0x515305</c>, never reaching its cylsphere
|
||||
/// (<c>0x005152d1</c>) or sorting-sphere (<c>0x005152fb</c>) branches. That
|
||||
/// is why the exclusivity is enforced HERE, at emission, rather than only at
|
||||
/// the query-time guard <c>Transition.BspOnlyDispatch</c>: the shape list is
|
||||
/// also the input to <c>ShadowObjectRegistry.BuildFloodSpheres</c>.
|
||||
/// </para>
|
||||
///
|
||||
/// <para>
|
||||
/// AP-152 (filed and retired 2026-08-06): these three steps used to be
|
||||
/// emitted ADDITIVELY — 172 of 5,935 installed Setups carry both a primitive
|
||||
/// and a physics-BSP part. The collision half of that divergence was already
|
||||
/// inert, because <c>Transition.BspOnlyDispatch</c> skips both primitive
|
||||
/// branches whenever the wire <c>PhysicsState</c> carries 0x10000 and ACE
|
||||
/// derives that bit from the same DAT flag; the live half was CELL
|
||||
/// MEMBERSHIP, which had no such guard. Gating here also removes acdream's
|
||||
/// undeclared dependency on the server sending the bit: the gate is derived
|
||||
/// from the parts, exactly as retail's <c>CPartArray::CacheHasPhysicsBSP</c>
|
||||
/// (0x00518110) derives it.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public static class ShadowShapeBuilder
|
||||
|
|
@ -81,38 +101,66 @@ public static class ShadowShapeBuilder
|
|||
|
||||
var result = new List<ShadowShape>();
|
||||
|
||||
// 1. CylSpheres — each becomes a Cylinder shape.
|
||||
foreach (var cyl in setup.CylSpheres)
|
||||
// 0. Retail dispatch gate. CPhysicsObj::FindObjCollisions tests
|
||||
// HAS_PHYSICS_BSP_PS FIRST (0x0050f165) and leaves the BSP branch
|
||||
// through an unconditional jmp past both primitive loops
|
||||
// (0x0050f19d); CPhysicsObj::calc_cross_cells tests the same flag
|
||||
// at 0x00515285 and routes to find_bbox_cell_list. Retail derives
|
||||
// the flag from the part array itself
|
||||
// (CPartArray::CacheHasPhysicsBSP 0x00518110 ORs 0x10000 on the
|
||||
// first part whose gfxobj->physics_bsp is non-null), so the gate
|
||||
// below reads the SAME effective part identities step 3 reads —
|
||||
// never setup.Parts directly. A gate keyed on a different identity
|
||||
// could suppress the primitives while step 3 emitted nothing,
|
||||
// silently deleting the entity's collision.
|
||||
bool anyPhysicsBspPart = false;
|
||||
for (int i = 0; i < setup.Parts.Count; i++)
|
||||
{
|
||||
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));
|
||||
if (hasPhysicsBsp(EffectivePartGfxObjId(setup, effectivePartGfxObjIds, i)))
|
||||
{
|
||||
anyPhysicsBspPart = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Spheres — only when no CylSpheres (matches landblock-static convention
|
||||
// at GameWindow.cs:6034). Each becomes a true Sphere (no height clamping).
|
||||
// Retail anchor: CSphere::intersects_sphere @ 0x00537A80 uses 3-D distance
|
||||
// for the overlap check, unlike CCylSphere which clips to [low_pt, high_pt].
|
||||
if (setup.CylSpheres.Count == 0)
|
||||
// Steps 1 and 2 run ONLY for an object with no physics-BSP part.
|
||||
if (!anyPhysicsBspPart)
|
||||
{
|
||||
foreach (var sph in setup.Spheres)
|
||||
// 1. CylSpheres — each becomes a Cylinder shape.
|
||||
foreach (var cyl in setup.CylSpheres)
|
||||
{
|
||||
if (sph.Radius <= 0f) continue;
|
||||
if (cyl.Radius <= 0f) continue;
|
||||
float baseHeight = cyl.Height > 0f ? cyl.Height : cyl.Radius * 4f;
|
||||
result.Add(new ShadowShape(
|
||||
GfxObjId: 0u,
|
||||
LocalPosition: new Vector3(sph.Origin.X, sph.Origin.Y, sph.Origin.Z) * entScale,
|
||||
LocalPosition: new Vector3(cyl.Origin.X, cyl.Origin.Y, cyl.Origin.Z) * entScale,
|
||||
LocalRotation: Quaternion.Identity,
|
||||
Scale: entScale,
|
||||
CollisionType: ShadowCollisionType.Sphere,
|
||||
Radius: sph.Radius * entScale,
|
||||
CylHeight: 0f));
|
||||
CollisionType: ShadowCollisionType.Cylinder,
|
||||
Radius: cyl.Radius * entScale,
|
||||
CylHeight: baseHeight * entScale));
|
||||
}
|
||||
|
||||
// 2. Spheres — only when no CylSpheres. Retail's CylSphere loop
|
||||
// returns rather than falling into the Sphere loop
|
||||
// (0x0050f1d6 jae 0x50f317). Each becomes a true Sphere (no
|
||||
// height clamping): CSphere::intersects_sphere @ 0x00537A80
|
||||
// uses 3-D distance for the overlap check, unlike CCylSphere
|
||||
// which clips to [low_pt, high_pt].
|
||||
if (setup.CylSpheres.Count == 0)
|
||||
{
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -126,10 +174,7 @@ public static class ShadowShapeBuilder
|
|||
// degrade array before CPartArray::FindObjCollisions reads it.
|
||||
// Keep the stable Setup part index/pose, but source collision
|
||||
// identity from that effective part when one was supplied.
|
||||
uint gfxId = effectivePartGfxObjIds is not null
|
||||
&& i < effectivePartGfxObjIds.Count
|
||||
? effectivePartGfxObjIds[i]
|
||||
: (uint)setup.Parts[i];
|
||||
uint gfxId = EffectivePartGfxObjId(setup, effectivePartGfxObjIds, i);
|
||||
if (!hasPhysicsBsp(gfxId)) continue;
|
||||
|
||||
Frame partFrame;
|
||||
|
|
@ -241,6 +286,20 @@ public static class ShadowShapeBuilder
|
|||
return shapes;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The collision identity of part <paramref name="index"/>: the installed
|
||||
/// <c>AnimPartChanged</c> replacement when one was supplied, else the
|
||||
/// Setup's own part. Shared by the step-0 dispatch gate and the step-3
|
||||
/// emission so the two can never read different identities.
|
||||
/// </summary>
|
||||
private static uint EffectivePartGfxObjId(
|
||||
Setup setup,
|
||||
IReadOnlyList<uint>? effectivePartGfxObjIds,
|
||||
int index)
|
||||
=> effectivePartGfxObjIds is not null && index < effectivePartGfxObjIds.Count
|
||||
? effectivePartGfxObjIds[index]
|
||||
: (uint)setup.Parts[index];
|
||||
|
||||
/// <summary>Resolve the placement frame in priority Resting → Default →
|
||||
/// first available. Mirrors <c>SetupMesh.Flatten</c>'s convention.</summary>
|
||||
private static AnimationFrame? ResolvePlacementFrame(Setup setup)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue