T6 (BR-7) C3: per-cell shadow architecture - flood registration, building channel, per-cell query; b3ce505 stopgap DELETED (closes #99)
The A6.P4 port, fused into one installment per the BR-2 half-port lesson
(registration and query are co-dependent: flood-registering shells under
the old radial query would re-open #98 through the vestibule).
REGISTRATION (ShadowObjectRegistry rewritten):
- Register/RegisterMultiPart/UpdatePosition compute the cell set via
CellTransit.BuildShadowCellSet (the C2 find_cell_list flood) seeded by
the entity's m_position cell id; the private 24m XY-grid rectangle and
its single-landblock clamp are deleted. Flood spheres follow retail's
CylSphere rule (base point + cyl radius, cap 10; BSP bounding-sphere
fallback - Ghidra 0x0052b9f0). Statics flood with the do_not_load
prune; dynamics (server spawns, isStatic:false) without.
- Keep-when-empty (SetPositionInternal num_cells gate, pc:283540): a
failed flood leaves the previous registration in place.
- RefloodLandblock: streaming-race hook re-runs the flood when a
landblock's cells hydrate (retail init_objects -> recalc_cross_cells,
Ghidra 0x0052b420/0x00515a30); wired at GameWindow's hydration tail.
- GameWindow sites pass the server position's full cell id as the seed
(spawn + UpdatePosition); the five static sites pass ParentCellId.
BUILDING CHANNEL (CSortCell.building shape):
- Building SHELLS are not shadow objects in retail (only caller of
find_building_collisions is CSortCell::find_collisions 0x005340aa;
one building per origin landcell, init_buildings 0x0052fd80 verified
verbatim + ACE cross-ref). IsBuildingShell entities skip the registry;
Transition.FindBuildingCollisions runs the shell part-0 BSP off
cache.GetBuilding(cellId) with bldg_check set around it
(find_building_collisions 0x006b5300), CollidedWithEnvironment on
non-Contact non-OK. BuildingPhysics.ModelId = pre-resolved part-0
GfxObj (0x02 Setups resolved at the CacheBuilding site).
- Placement/ethereal weakening: BSPQuery Path 1 passes center_solid=0
when BldgCheck && HitsInteriorCell (BSPTREE::find_collisions 0x0053a82e
+ placement_insert 0x005399d8) so doorway crossings don't hard-fail
against shell solids. SpherePath gains both retail fields;
HitsInteriorCell is rebuilt at every cell-array build
(build_cell_array reset 0x00509ef2 + find_cell_list/check_building_
transit set sites).
QUERY (retail per-cell order, transitional_insert 0x0050b6f0):
- TransitionalInsert per attempt: env -> building (LandCell only) ->
objects on the PRIMARY cell, then on OK the check_other_cells pass
(env -> building -> objects per OTHER overlapped cell) + the
carried-cell advance - the advance now happens AFTER all per-cell
object passes (the WF1 ordering divergence), with Adjusted/Slid
feeding the retry exactly like retail's OK_TS case.
- FindObjCollisionsInCell = CObjCell::find_obj_collisions (0x0052b750):
iterate ONLY the asked cell's list. DELETED: the radial 9-landblock
sweep, the +5m query pad, the b3ce505 indoor-primary gate, and the
isViewer exemption (the camera is bounded by interior cell-BSP env
collision - retail's own channel; CameraCornerSealReplayTests pins it
against real dat, and the new building-channel camera test pins the
outdoor stop).
TESTS: Core 1416/0/2 (was 1398 + 4 pre-existing #99-era fails + 1 skip),
App 225, UI 420, Net 294 - all green.
- 3 of the 4 #99-era reds flipped green as designed: the door apparatus
(Apparatus_Grounded_50cmOffCenter_FrontApproach_Blocks) and tick-13558
(indoor walkthrough) now assert the door BLOCKS; tick-22760 pins the
outdoor blocking invariant.
- The 4th (BSPStepUp D4) + 22760's lateral-slide delta are NOT cell-set
problems (probes prove the door is found + BSP-only dispatched;
BR-7 left both byte-identical) - filed as issue #116 (slide-response
family), D4 skipped with the issue reference.
- FindEnvCollisionsMultiCellTests migrated to the public entry (the A4
multi-cell halt now lives at the retail call site).
- New registry pins: per-cell query surface, outdoor-footprint-never-
indoor (#98 architectural), door-outdoor-cell membership, reflood.
- CameraCollisionIndoorTests rewritten against the building channel
(the isViewer-exemption pins died with the exemption).
Closes #99 (doors block both ways via registration-time cell membership
+ the straddle-spanning player cell array). #97 likely closed (the +5m
radial pad that produced phantom-collision candidates is gone) - verify
at T5. #98 stays closed ARCHITECTURALLY (outdoor footprints structurally
cannot reach interior cells; the cellar harness stays green).
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
parent
abf36e2743
commit
dbfbf8506c
15 changed files with 1109 additions and 856 deletions
|
|
@ -10,363 +10,144 @@ using Xunit;
|
|||
namespace AcDream.App.Tests.Rendering;
|
||||
|
||||
/// <summary>
|
||||
/// Phase U — RED diagnostic test for the camera-collision indoor non-engagement bug.
|
||||
/// Camera (viewer) sweep vs the BUILDING collision channel.
|
||||
///
|
||||
/// <para>
|
||||
/// Root cause (b): when the camera sphere is in an indoor cell, <see cref="ShadowObjectRegistry.GetNearbyObjects"/>
|
||||
/// returns early at line 480 (<c>if ((primaryCellId & 0xFFFF) >= 0x0100) return;</c>),
|
||||
/// skipping the outdoor radial sweep. The cottage exterior-shell GfxObj is registered
|
||||
/// with <c>cellScope=0</c> (landblock-wide, outdoor) — it lives in the outdoor per-cell
|
||||
/// shadow lists. With the indoor-primary gate active, the camera sweep (which uses
|
||||
/// <see cref="ObjectInfoState.IsViewer"/> not <see cref="ObjectInfoState.IsPlayer"/>) never
|
||||
/// finds the exterior shell while its sphere center is inside the indoor CellBSP volume.
|
||||
/// Once the sphere center exits the CellBSP boundary (<see cref="PhysicsEngine.ResolveCellId"/>
|
||||
/// falls through to outdoor), the outdoor sweep runs — but by then the sphere may have
|
||||
/// already crossed the exterior wall polygon's front face (going in the same direction).
|
||||
/// History: this file was born as the Phase U RED diagnostic for the
|
||||
/// camera-collision indoor non-engagement bug — the b3ce505 #98 indoor gate
|
||||
/// in the old radial <c>GetNearbyObjects</c> blocked the viewer sweep from
|
||||
/// reaching the exterior-shell GfxObj, and the fix was an
|
||||
/// <c>isViewer</c> exemption. BR-7 / A6.P4 (2026-06-11) deleted that whole
|
||||
/// stack: building shells are no longer shadow objects at all — they
|
||||
/// dispatch through the retail per-LandCell building channel
|
||||
/// (<c>CSortCell::find_collisions</c> → <c>find_building_collisions</c>,
|
||||
/// Ghidra 0x005340a0/0x006b5300), and the indoor camera is bounded by the
|
||||
/// interior cell's own physics BSP (the env channel — retail's actual
|
||||
/// viewer enclosure; pinned against real dat by
|
||||
/// <c>CameraCornerSealReplayTests</c>).
|
||||
/// </para>
|
||||
///
|
||||
/// <para>
|
||||
/// Evidence from post-fix live capture (<c>u4c-fix.log</c>): <c>eyeInRoot=n</c> ~90%
|
||||
/// of frames; eye-player distance mean 3.43 m (full/zoomed chase, NOT pulled in).
|
||||
/// The <c>[flap-sweep]</c> diagnostic in <see cref="PhysicsCameraCollisionProbe.SweepEye"/>
|
||||
/// was designed to confirm this: <c>bsp=ok pulledIn≈0</c> means the cell is loaded with
|
||||
/// a valid BSP but the sweep returns full eye distance, confirming the exterior shell is
|
||||
/// not reached from the indoor context.
|
||||
/// What remains here is the end-to-end pin of the NEW channel: a viewer
|
||||
/// sweep whose primary cell is an outdoor landcell with a cached building
|
||||
/// must be stopped by the building's shell BSP.
|
||||
/// </para>
|
||||
///
|
||||
/// <para>
|
||||
/// The issue #98 fix (2026-05-24) deliberately gates the outdoor sweep when the primary
|
||||
/// cell is indoor — this is CORRECT for the player (prevents the cottage floor from
|
||||
/// capping the player's head sphere). But it is WRONG for the camera probe
|
||||
/// (<see cref="ObjectInfoState.IsViewer"/>), which needs to find the exterior building
|
||||
/// shell to implement retail's <c>SmartBox::update_viewer</c> spring-arm pull-in.
|
||||
/// </para>
|
||||
///
|
||||
/// <para>
|
||||
/// Fixture gap: the actual residual cells (0xA9B40174/0175, main-floor cottage) are not
|
||||
/// in the fixture set (the issue-98 fixtures cover 0xA9B4014X, a different cellar
|
||||
/// cottage). This test uses a fully synthetic setup to prove the mechanism identically —
|
||||
/// the issue #98 gate fires on any indoor primary cell id.
|
||||
/// </para>
|
||||
///
|
||||
/// <para>Diagnosis doc: <c>docs/research/2026-05-31-camera-collision-indoor-diagnosis.md</c>.</para>
|
||||
/// </summary>
|
||||
public class CameraCollisionIndoorTests
|
||||
{
|
||||
// ── Geometry constants ─────────────────────────────────────────────────
|
||||
// Room interior: player at world (0, 1, 94). Pivot = (0, 1, 95.5).
|
||||
// Camera sweeps backward (+Y) and slightly upward.
|
||||
// The EXTERIOR WALL GfxObj is at Y = 4.0 (just outside the room's back boundary
|
||||
// at Y = 3.5). The interior CellBSP covers Y ∈ [-2, 3.5].
|
||||
//
|
||||
// Desired eye: Y = 5.0 — past the exterior wall.
|
||||
//
|
||||
// Expected: sweep stops at the exterior wall (pulledIn ≥ MinExpectedPullIn = 0.5 m).
|
||||
// Actual: sweep reaches Y = 5.0 (pulledIn ≈ 0) because GetNearbyObjects skips the
|
||||
// outdoor sweep when primaryCellId is indoor, so the GfxObj exterior wall is not
|
||||
// tested while the sphere is inside the CellBSP volume. After the sphere crosses the
|
||||
// CellBSP boundary (Y > 3.5 + ~0.3 = 3.8), ResolveCellId returns an outdoor cell
|
||||
// and the outdoor sweep IS run — but the exterior wall is at Y = 4.0 and the sphere
|
||||
// center is approaching from Y = 3.8 toward +Y, so the exterior wall polygon (with
|
||||
// inward normal = -Y) is hit from its BACK FACE. If the wall polygon is one-sided
|
||||
// (CullMode.Clockwise from the outer face), the back-face hit is suppressed and the
|
||||
// sphere passes through. The net result is no stop.
|
||||
// Player outdoors at (0, 1, 94). Pivot = (0, 1, 95.5). Camera sweeps
|
||||
// backward (+Y) and slightly upward toward the building wall at Y=4.0.
|
||||
|
||||
private const uint IndoorCellId = 0xA9B40175u; // low 16 bits 0x0175 ≥ 0x0100 → indoor
|
||||
private const uint LandblockId = 0xA9B40000u;
|
||||
private const uint OutdoorCellId = 0xA9B40001u; // landcell (0,0)
|
||||
private const uint LandblockId = 0xA9B40000u;
|
||||
|
||||
// Player head-pivot in world space.
|
||||
private static readonly Vector3 PivotWorld = new(0f, 1f, 95.5f);
|
||||
private static readonly Vector3 PivotWorld = new(0f, 1f, 95.5f);
|
||||
|
||||
// Desired eye: backward and slightly above pivot.
|
||||
// Goes from Y=1 to Y=5, passing through the exterior wall at Y=4.0.
|
||||
private static readonly Vector3 DesiredEye = new(0f, 5f, 96.25f);
|
||||
// Desired eye: backward past the building wall at Y=4.0.
|
||||
private static readonly Vector3 DesiredEye = new(0f, 5f, 96.25f);
|
||||
|
||||
// Exterior wall GfxObj position: at Y=4.0, normal facing INTO the room (-Y).
|
||||
// When seen from outside, the front face has +Y normal (outward). When seen
|
||||
// from inside (camera going toward +Y), the facing side is the back face.
|
||||
// The wall is registered with cellScope=0 (landblock-wide, outdoor shadow list).
|
||||
private const float ExteriorWallY = 4.0f;
|
||||
private const float BuildingWallY = 4.0f;
|
||||
|
||||
// The sphere should be stopped at approximately Y = ExteriorWallY - ViewerSphereRadius.
|
||||
// Pulled-in distance ≥ MinExpectedPullIn.
|
||||
// The sphere should be stopped near Y = BuildingWallY - viewerRadius;
|
||||
// anything ≥ this margin proves the channel engaged.
|
||||
private const float MinExpectedPullIn = 0.5f;
|
||||
|
||||
// CellBSP inner boundary: sphere is considered "inside" the cell when Y ≤ 3.5.
|
||||
// Once the sphere center crosses Y = 3.5 + (radius + 0.01) ≈ 3.81, ResolveCellId
|
||||
// will classify it as outdoor.
|
||||
private const float CellBspBoundaryY = 3.5f;
|
||||
|
||||
// ── Test ───────────────────────────────────────────────────────────────
|
||||
|
||||
/// <summary>
|
||||
/// Documents the fix for the camera-collision indoor non-engagement bug (cause b).
|
||||
///
|
||||
/// <para>
|
||||
/// Setup: indoor cell <c>0xA9B40175</c> with a CellBSP boundary at Y=3.5 and no
|
||||
/// solid physics wall at that boundary (the room opens toward +Y, representing the
|
||||
/// cottage front wall / portal). A landblock-baked exterior-shell GfxObj is registered
|
||||
/// at Y=4.0 with <c>cellScope=0</c> (outdoor shadow list, NOT in the indoor cell's
|
||||
/// portal-reachable set).
|
||||
/// </para>
|
||||
///
|
||||
/// <para>
|
||||
/// The fix: <see cref="ShadowObjectRegistry.GetNearbyObjects"/> now accepts an
|
||||
/// <c>isViewer</c> parameter (default <c>false</c>). When <c>isViewer=true</c>, the
|
||||
/// issue-#98 indoor gate is bypassed so the camera probe can reach the exterior-shell
|
||||
/// GfxObj. <see cref="Transition.FindObjCollisions"/> passes <c>oi.IsViewer</c> (i.e.
|
||||
/// <c>ObjectInfo.IsViewer</c> at TransitionTypes.cs:75) at the <c>GetNearbyObjects</c>
|
||||
/// call site. The #98 gate remains active for all non-viewer (player, NPC) sweeps.
|
||||
/// </para>
|
||||
///
|
||||
/// <para>
|
||||
/// Retail faithfulness: <c>SmartBox::update_viewer</c> at
|
||||
/// <c>acclient_2013_pseudo_c.txt:92761</c> bounds the viewer via the player-cell
|
||||
/// enclosure; retail's interior EnvCells are self-enclosing. In acdream's data model
|
||||
/// the enclosure is the exterior-shell GfxObj (issue #98). Retail's
|
||||
/// <c>find_obj_collisions</c> at <c>:308918</c> has no indoor gate — so exempting
|
||||
/// <c>IsViewer</c> is the faithful analog.
|
||||
/// </para>
|
||||
///
|
||||
/// <para>This test PASSES with the fix, FAILS without it.</para>
|
||||
/// BR-7 / A6.P4: the viewer sweep is stopped by the building channel —
|
||||
/// <c>Transition.FindBuildingCollisions</c> runs the shell part-0 BSP
|
||||
/// for the outdoor primary cell holding the building reference, exactly
|
||||
/// like retail <c>CLandCell::find_collisions</c> →
|
||||
/// <c>CSortCell::find_collisions</c> (Ghidra 0x00532d60/0x005340a0).
|
||||
/// The shell is NOT in the ShadowObjectRegistry (production skips
|
||||
/// <c>IsBuildingShell</c> entities); the stop can only come from the
|
||||
/// channel.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void SweepEye_IndoorCellExteriorGfxObjWall_StoppedByExteriorShell_AfterViewerGateExemption()
|
||||
public void SweepEye_OutdoorCell_StoppedByBuildingChannelShell()
|
||||
{
|
||||
var (engine, _) = BuildEngineWithSyntheticRoom();
|
||||
var (engine, _) = BuildEngineWithBuilding();
|
||||
var probe = new PhysicsCameraCollisionProbe(engine);
|
||||
|
||||
var stoppedEye = probe.SweepEye(
|
||||
pivot: PivotWorld,
|
||||
desiredEye: DesiredEye,
|
||||
cellId: IndoorCellId,
|
||||
cellId: OutdoorCellId,
|
||||
selfEntityId: 0u,
|
||||
playerPos: PivotWorld - new Vector3(0f, 0f, 1.5f)).Eye;
|
||||
|
||||
// The eye should be stopped before the exterior wall at Y=4.0.
|
||||
// Expected stopped eye Y ≈ 4.0 - ViewerSphereRadius = 3.7.
|
||||
// Pulled-in = |DesiredEye.Y - stoppedEye.Y| should be ≥ 0.5 m.
|
||||
float pulledIn = MathF.Abs(DesiredEye.Y - stoppedEye.Y);
|
||||
|
||||
Assert.True(
|
||||
pulledIn >= MinExpectedPullIn,
|
||||
$"Camera sweep should be stopped by the exterior-shell GfxObj wall at " +
|
||||
$"Y={ExteriorWallY:F1} (registered outdoor/landblock-wide, cellScope=0). " +
|
||||
$"Camera sweep should be stopped by the building-channel shell BSP at " +
|
||||
$"Y={BuildingWallY:F1} (cache.GetBuilding({OutdoorCellId:X8}) with ModelId set). " +
|
||||
$"Actual pulled-in: {pulledIn:F4} m (stopped eye Y={stoppedEye.Y:F4}). " +
|
||||
$"REGRESSION: ShadowObjectRegistry.GetNearbyObjects indoor gate is incorrectly " +
|
||||
$"blocking the IsViewer (camera) sweep from reaching the exterior-shell GfxObj. " +
|
||||
$"Fix: pass isViewer=true at the FindObjCollisions call site so the indoor gate " +
|
||||
$"is bypassed for camera sweeps (ShadowObjectRegistry.cs, TransitionTypes.cs:~2307).");
|
||||
}
|
||||
|
||||
// ── Issue #98 regression guard ────────────────────────────────────────
|
||||
|
||||
/// <summary>
|
||||
/// Regression guard: the issue-#98 indoor gate must remain active for non-viewer sweeps.
|
||||
///
|
||||
/// <para>
|
||||
/// A GfxObj registered with <c>cellScope=0</c> (outdoor shadow list) must NOT be returned
|
||||
/// by <see cref="ShadowObjectRegistry.GetNearbyObjects"/> when the primary cell is indoor
|
||||
/// and <c>isViewer=false</c> (i.e. the default player / NPC path). This is the protection
|
||||
/// that prevents the cottage-floor polygon from capping the player's head sphere while the
|
||||
/// player is in the cellar directly below.
|
||||
/// </para>
|
||||
///
|
||||
/// <para>
|
||||
/// Issue #98 fix (2026-05-24): gate fires at <c>ShadowObjectRegistry.cs:~480</c> when
|
||||
/// <c>(primaryCellId & 0xFFFF) >= 0x0100</c> AND <c>isViewer=false</c>. This test
|
||||
/// ensures the guard cannot regress.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void GetNearbyObjects_IndoorPrimaryCell_NonViewer_DoesNotReturnOutdoorGfxObj()
|
||||
{
|
||||
var registry = new ShadowObjectRegistry();
|
||||
|
||||
// Register a GfxObj at cellScope=0 (landblock-wide / outdoor shadow list).
|
||||
const uint EntityId = 0x00010001u;
|
||||
const uint GfxId = 0x01000001u;
|
||||
const uint LbId = 0xA9B40000u;
|
||||
var pos = new Vector3(0f, 4f, 96f);
|
||||
registry.Register(
|
||||
entityId: EntityId,
|
||||
gfxObjId: GfxId,
|
||||
worldPos: pos,
|
||||
rotation: System.Numerics.Quaternion.Identity,
|
||||
radius: 10f,
|
||||
worldOffsetX: 0f,
|
||||
worldOffsetY: 0f,
|
||||
landblockId: LbId,
|
||||
collisionType: ShadowCollisionType.BSP,
|
||||
scale: 1.0f,
|
||||
cellScope: 0u); // outdoor, landblock-wide
|
||||
|
||||
var results = new List<ShadowEntry>();
|
||||
|
||||
// Non-viewer query with indoor primary cell — gate must fire, GfxObj NOT returned.
|
||||
registry.GetNearbyObjects(
|
||||
worldPos: pos,
|
||||
queryRadius: 20f,
|
||||
worldOffsetX: 0f,
|
||||
worldOffsetY: 0f,
|
||||
landblockId: LbId,
|
||||
results: results,
|
||||
portalReachableCells: null,
|
||||
primaryCellId: 0xA9B40175u, // indoor cell (low 16 bits 0x0175 >= 0x0100)
|
||||
isViewer: false);
|
||||
|
||||
Assert.Empty(results); // Issue #98 gate must block the outdoor GfxObj for non-viewer sweeps.
|
||||
$"REGRESSION: Transition.FindBuildingCollisions (retail " +
|
||||
$"CBuildingObj::find_building_collisions, Ghidra 0x006b5300) is not engaging " +
|
||||
$"for the viewer's outdoor primary cell.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Regression guard: the viewer exemption allows the camera to reach outdoor GfxObjs
|
||||
/// registered at <c>cellScope=0</c> even when the primary cell is indoor.
|
||||
///
|
||||
/// <para>
|
||||
/// This is the dual of <see cref="GetNearbyObjects_IndoorPrimaryCell_NonViewer_DoesNotReturnOutdoorGfxObj"/>:
|
||||
/// the same GfxObj / same indoor primary cell, but <c>isViewer=true</c>.
|
||||
/// The outdoor sweep must run and return the GfxObj.
|
||||
/// </para>
|
||||
///
|
||||
/// <para>
|
||||
/// Retail faithfulness: <c>SmartBox::update_viewer</c> (acclient_2013_pseudo_c.txt:92761)
|
||||
/// calls <c>find_obj_collisions</c> (:308918) which has no indoor-cell gate — the viewer
|
||||
/// reaches any geometry in the player's cell enclosure. The #98 gate is an acdream-specific
|
||||
/// workaround that must not apply to the viewer.
|
||||
/// </para>
|
||||
/// Channel inertness guard: a building cached WITHOUT a model id
|
||||
/// (legacy entries, portal-transit-only callers) must not collide —
|
||||
/// the sweep reaches the desired eye.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void GetNearbyObjects_IndoorPrimaryCell_IsViewer_DoesReturnOutdoorGfxObj()
|
||||
public void SweepEye_BuildingWithoutModelId_ChannelInert()
|
||||
{
|
||||
var registry = new ShadowObjectRegistry();
|
||||
var (engine, cache) = BuildEngineWithBuilding();
|
||||
|
||||
// Same outdoor-scope GfxObj as the non-viewer test above.
|
||||
const uint EntityId = 0x00010002u;
|
||||
const uint GfxId = 0x01000002u;
|
||||
const uint LbId = 0xA9B40000u;
|
||||
var pos = new Vector3(0f, 4f, 96f);
|
||||
registry.Register(
|
||||
entityId: EntityId,
|
||||
gfxObjId: GfxId,
|
||||
worldPos: pos,
|
||||
rotation: System.Numerics.Quaternion.Identity,
|
||||
radius: 10f,
|
||||
worldOffsetX: 0f,
|
||||
worldOffsetY: 0f,
|
||||
landblockId: LbId,
|
||||
collisionType: ShadowCollisionType.BSP,
|
||||
scale: 1.0f,
|
||||
cellScope: 0u); // outdoor, landblock-wide
|
||||
// Replace the building entry with a model-less one.
|
||||
cache.RegisterBuildingForTest(OutdoorCellId, new BuildingPhysics
|
||||
{
|
||||
WorldTransform = Matrix4x4.CreateTranslation(0f, BuildingWallY, 96f),
|
||||
InverseWorldTransform = InvertOrIdentity(Matrix4x4.CreateTranslation(0f, BuildingWallY, 96f)),
|
||||
Portals = Array.Empty<BldPortalInfo>(),
|
||||
ModelId = 0u,
|
||||
});
|
||||
|
||||
var results = new List<ShadowEntry>();
|
||||
var probe = new PhysicsCameraCollisionProbe(engine);
|
||||
var stoppedEye = probe.SweepEye(
|
||||
pivot: PivotWorld,
|
||||
desiredEye: DesiredEye,
|
||||
cellId: OutdoorCellId,
|
||||
selfEntityId: 0u,
|
||||
playerPos: PivotWorld - new Vector3(0f, 0f, 1.5f)).Eye;
|
||||
|
||||
// Viewer query with indoor primary cell — gate must be bypassed, GfxObj IS returned.
|
||||
registry.GetNearbyObjects(
|
||||
worldPos: pos,
|
||||
queryRadius: 20f,
|
||||
worldOffsetX: 0f,
|
||||
worldOffsetY: 0f,
|
||||
landblockId: LbId,
|
||||
results: results,
|
||||
portalReachableCells: null,
|
||||
primaryCellId: 0xA9B40175u, // indoor cell (low 16 bits 0x0175 >= 0x0100)
|
||||
isViewer: true);
|
||||
|
||||
Assert.NotEmpty(results); // Viewer must bypass the indoor gate and find the exterior GfxObj.
|
||||
Assert.Equal(EntityId, results[0].EntityId);
|
||||
Assert.True(MathF.Abs(DesiredEye.Y - stoppedEye.Y) < 0.05f,
|
||||
$"Model-less building entries must keep the channel inert; eye stopped at " +
|
||||
$"Y={stoppedEye.Y:F4} instead of reaching {DesiredEye.Y:F4}.");
|
||||
}
|
||||
|
||||
// ── Engine + fixture builder ──────────────────────────────────────────
|
||||
|
||||
private static Matrix4x4 InvertOrIdentity(Matrix4x4 m)
|
||||
=> Matrix4x4.Invert(m, out var inv) ? inv : Matrix4x4.Identity;
|
||||
|
||||
/// <summary>
|
||||
/// Builds a minimal <see cref="PhysicsEngine"/> with:
|
||||
/// Minimal engine with ONE outdoor landcell building:
|
||||
/// <list type="bullet">
|
||||
/// <item>One synthetic indoor cell (<see cref="IndoorCellId"/>), identity world transform.
|
||||
/// CellBSP boundary at Y=<see cref="CellBspBoundaryY"/>.
|
||||
/// PhysicsBSP is an empty leaf (no interior wall polygons at the target side —
|
||||
/// represents an open portal/doorway toward +Y).</item>
|
||||
/// <item>One exterior-shell GfxObj registered with <c>cellScope=0</c>
|
||||
/// (landblock-wide, outdoor shadow list). The GfxObj has a wall polygon
|
||||
/// at Y=<see cref="ExteriorWallY"/>, representing the cottage exterior shell
|
||||
/// that retail's camera spring-arm should stop on.</item>
|
||||
/// <item>A stub landblock with terrain far below (Z=-1000) to prevent outdoor
|
||||
/// terrain collision from interfering.</item>
|
||||
/// <item>Shell GfxObj: a single two-sided wall polygon at local Y=0,
|
||||
/// anchored by the building transform at world Y=<see cref="BuildingWallY"/>.</item>
|
||||
/// <item><see cref="PhysicsDataCache.RegisterBuildingForTest"/> at
|
||||
/// <see cref="OutdoorCellId"/> with <c>ModelId</c> set — the
|
||||
/// per-LandCell building reference (retail CSortCell.building,
|
||||
/// set once at the origin cell by CLandBlock::init_buildings,
|
||||
/// Ghidra 0x0052fd80).</item>
|
||||
/// <item>Stub terrain far below so terrain collision never interferes.</item>
|
||||
/// </list>
|
||||
///
|
||||
/// <para>
|
||||
/// This fixture directly reproduces the production gap: the issue-#98 fix
|
||||
/// (<see cref="ShadowObjectRegistry.GetNearbyObjects"/> early-return at line 480)
|
||||
/// correctly prevents indoor spheres (the PLAYER) from being capped by the landblock-baked
|
||||
/// cottage floor. But it also prevents the camera sphere (<see cref="ObjectInfoState.IsViewer"/>)
|
||||
/// from seeing the exterior shell GfxObj — the same fix that closes issue #98 is what
|
||||
/// breaks camera-collision indoors.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
private static (PhysicsEngine engine, PhysicsDataCache cache)
|
||||
BuildEngineWithSyntheticRoom()
|
||||
BuildEngineWithBuilding()
|
||||
{
|
||||
var cache = new PhysicsDataCache();
|
||||
var engine = new PhysicsEngine { DataCache = cache };
|
||||
|
||||
// ── 1. Indoor cell with open-toward-+Y boundary ────────────────────
|
||||
// PhysicsBSP: empty leaf — no walls on the +Y side. This represents
|
||||
// a room that has a portal (doorway / open passage) toward +Y.
|
||||
// The exterior shell is NOT part of any indoor cell's BSP.
|
||||
var emptyLeaf = new PhysicsBSPNode
|
||||
{
|
||||
Type = BSPNodeType.Leaf,
|
||||
BoundingSphere = new Sphere { Origin = Vector3.Zero, Radius = 20f },
|
||||
};
|
||||
var emptyBsp = new PhysicsBSPTree { Root = emptyLeaf };
|
||||
|
||||
// CellBSP: splitting plane at Y = CellBspBoundaryY with normal = -Y
|
||||
// (interior is at Y ≤ CellBspBoundaryY).
|
||||
// SphereIntersectsCellBsp returns false when:
|
||||
// dist = dot(-Y, center) + CellBspBoundaryY = CellBspBoundaryY - center.Y
|
||||
// < -(radius + 0.01f)
|
||||
// i.e. center.Y > CellBspBoundaryY + radius + 0.01
|
||||
// For radius=0.3: center.Y > 3.5 + 0.31 = 3.81.
|
||||
var cellBspLeaf = new CellBSPNode { Type = BSPNodeType.Leaf };
|
||||
var cellBspRoot = new CellBSPNode
|
||||
{
|
||||
SplittingPlane = new Plane(new Vector3(0f, -1f, 0f), CellBspBoundaryY),
|
||||
PosNode = cellBspLeaf,
|
||||
};
|
||||
|
||||
var indoorCell = new CellPhysics
|
||||
{
|
||||
BSP = emptyBsp,
|
||||
WorldTransform = Matrix4x4.Identity,
|
||||
InverseWorldTransform = Matrix4x4.Identity,
|
||||
Resolved = new Dictionary<ushort, ResolvedPolygon>(), // no interior walls toward +Y
|
||||
CellBSP = new CellBSPTree { Root = cellBspRoot },
|
||||
Portals = Array.Empty<PortalInfo>(),
|
||||
PortalPolygons = new Dictionary<ushort, ResolvedPolygon>(),
|
||||
VisibleCellIds = new System.Collections.Generic.HashSet<uint>(),
|
||||
};
|
||||
cache.RegisterCellStructForTest(IndoorCellId, indoorCell);
|
||||
|
||||
// ── 2. Exterior shell GfxObj registered OUTDOORS (cellScope=0) ─────
|
||||
// This is the landblock-baked cottage exterior shell. The wall polygon
|
||||
// at Y=ExteriorWallY has its front face pointing INTO the room (-Y normal)
|
||||
// — so from the outside the polygon's front face faces +Y (outward).
|
||||
// When the camera sphere approaches from inside (+Y direction), it hits
|
||||
// the BACK face of this polygon.
|
||||
//
|
||||
// We register it with cellScope=0 (landblock-wide), which puts it in the
|
||||
// outdoor per-cell shadow lists — NOT in the indoor cell's portal-reachable
|
||||
// set. This mirrors how production registers landblock-baked statics:
|
||||
// GameWindow.cs:5899 uses entity.ParentCellId ?? 0u → 0 for top-level statics.
|
||||
const uint ExteriorShellEntityId = 0x00990001u;
|
||||
const uint ExteriorShellGfxId = 0x01AABB01u;
|
||||
|
||||
// Wall polygon in OBJECT-LOCAL space (GfxObj registered at world Y=ExteriorWallY).
|
||||
// In local space the wall is at Y=0 (directly at the GfxObj's origin).
|
||||
// Normal stays (-Y, facing INTO the room) — same direction as in world space.
|
||||
// X ∈ [-3, 3], Z ∈ [-3, 3] (local, centered on the GfxObj's world origin).
|
||||
var wallNormal = new Vector3(0f, -1f, 0f);
|
||||
const float wallLocalD = 0f; // wall at local Y=0 (GfxObj origin)
|
||||
// ── 1. Shell GfxObj: one two-sided wall polygon at local Y=0 ──────
|
||||
const uint ShellGfxId = 0x01AABB01u;
|
||||
const ushort WallPolyId = 1;
|
||||
|
||||
var wallPoly = new ResolvedPolygon
|
||||
{
|
||||
Vertices = new[]
|
||||
|
|
@ -376,21 +157,15 @@ public class CameraCollisionIndoorTests
|
|||
new Vector3( 3f, 0f, 3f),
|
||||
new Vector3(-3f, 0f, 3f),
|
||||
},
|
||||
Plane = new Plane(wallNormal, wallLocalD),
|
||||
Plane = new System.Numerics.Plane(new Vector3(0f, -1f, 0f), 0f),
|
||||
NumPoints = 4,
|
||||
SidesType = CullMode.None, // two-sided: should stop from both directions
|
||||
SidesType = CullMode.None, // two-sided: stops from both directions
|
||||
};
|
||||
|
||||
// GfxObj PhysicsBSP: single leaf containing the exterior wall.
|
||||
// BoundingSphere in OBJECT-LOCAL space: centered at origin (0,0,0), radius 10.
|
||||
var gfxLeaf = new PhysicsBSPNode
|
||||
{
|
||||
Type = BSPNodeType.Leaf,
|
||||
BoundingSphere = new Sphere
|
||||
{
|
||||
Origin = Vector3.Zero, // local-space center
|
||||
Radius = 10f,
|
||||
},
|
||||
BoundingSphere = new Sphere { Origin = Vector3.Zero, Radius = 10f },
|
||||
};
|
||||
gfxLeaf.Polygons.Add(WallPolyId);
|
||||
|
||||
|
|
@ -402,31 +177,25 @@ public class CameraCollisionIndoorTests
|
|||
Resolved = new Dictionary<ushort, ResolvedPolygon> { [WallPolyId] = wallPoly },
|
||||
BoundingSphere = new Sphere { Origin = Vector3.Zero, Radius = 10f },
|
||||
};
|
||||
cache.RegisterGfxObjForTest(ExteriorShellGfxId, gfxPhysics);
|
||||
cache.RegisterGfxObjForTest(ShellGfxId, gfxPhysics);
|
||||
|
||||
// Register in the OUTDOOR shadow list (cellScope=0 → landblock-wide).
|
||||
// This mirrors production's GameWindow.cs:5893 for landblock-baked statics.
|
||||
engine.ShadowObjects.Register(
|
||||
entityId: ExteriorShellEntityId,
|
||||
gfxObjId: ExteriorShellGfxId,
|
||||
worldPos: new Vector3(0f, ExteriorWallY, 96f),
|
||||
rotation: Quaternion.Identity,
|
||||
radius: 10f,
|
||||
worldOffsetX: 0f,
|
||||
worldOffsetY: 0f,
|
||||
landblockId: LandblockId,
|
||||
collisionType: ShadowCollisionType.BSP,
|
||||
scale: 1.0f,
|
||||
cellScope: 0u); // ← landblock-wide outdoor, NOT indoor cell scope
|
||||
// ── 2. The per-LandCell building reference ─────────────────────────
|
||||
var bldTransform = Matrix4x4.CreateTranslation(0f, BuildingWallY, 96f);
|
||||
cache.RegisterBuildingForTest(OutdoorCellId, new BuildingPhysics
|
||||
{
|
||||
WorldTransform = bldTransform,
|
||||
InverseWorldTransform = InvertOrIdentity(bldTransform),
|
||||
Portals = Array.Empty<BldPortalInfo>(),
|
||||
ModelId = ShellGfxId,
|
||||
});
|
||||
|
||||
// ── 3. Stub landblock: terrain far below ───────────────────────────
|
||||
var heights = new byte[81];
|
||||
var heightTable = new float[256];
|
||||
for (int i = 0; i < 256; i++) heightTable[i] = -1000f;
|
||||
var stubTerrain = new TerrainSurface(heights, heightTable);
|
||||
engine.AddLandblock(
|
||||
landblockId: LandblockId,
|
||||
terrain: stubTerrain,
|
||||
terrain: new TerrainSurface(heights, heightTable),
|
||||
cells: Array.Empty<CellSurface>(),
|
||||
portals: Array.Empty<PortalPlane>(),
|
||||
worldOffsetX: 0f,
|
||||
|
|
|
|||
|
|
@ -546,7 +546,14 @@ public class BSPStepUpTests
|
|||
/// every frame replays the same hard stop and the character hangs in falling
|
||||
/// animation until another correction breaks the loop.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
[Fact(Skip = "Issue #116 — slide-response divergence family (P1-era " +
|
||||
"slide_sphere work made the first airborne wall frame slide in-frame " +
|
||||
"to Z=1.92 instead of the L.2c-pinned hard stop at Z=2.0; the cached " +
|
||||
"sliding-normal mechanism retail seeds via get_object_info " +
|
||||
"(pc:279992, transient bit 4 → init_sliding_normal) only governs the " +
|
||||
"NEXT frame, so which first-frame response is retail-faithful needs " +
|
||||
"its own oracle read. NOT a cell-set problem — BR-7/A6.P4 left this " +
|
||||
"byte-identical. See docs/ISSUES.md #116.")]
|
||||
public void D4_AirborneMover_TallWall_PersistsSlidingNormalAcrossFrames()
|
||||
{
|
||||
var (root, resolved) = BSPStepUpFixtures.TallWall();
|
||||
|
|
|
|||
|
|
@ -1177,11 +1177,13 @@ public class CellarUpTrajectoryReplayTests : IDisposable
|
|||
landblockId: 0xA9B40000u,
|
||||
collisionType: ShadowCollisionType.BSP,
|
||||
scale: 1.0f,
|
||||
// Landblock-baked statics in production (GameWindow.cs:5899) use
|
||||
// `entity.ParentCellId ?? 0u` — the cottage building has no
|
||||
// ParentCellId (it's a top-level landblock static), so the
|
||||
// scope is landblock-wide (cellScope=0).
|
||||
cellScope: 0u);
|
||||
// BR-7: outdoor seed derived from the world position. (In
|
||||
// production the cottage SHELL no longer registers as a shadow
|
||||
// object at all — it dispatches via the per-LandCell building
|
||||
// channel; this fixture keeps the shadow registration to pin the
|
||||
// #98 regression shape: an outdoor-registered footprint must
|
||||
// stay invisible to fully-interior cellar queries.)
|
||||
seedCellId: 0u);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -87,9 +87,24 @@ public class DoorBugTrajectoryReplayTests
|
|||
var datDir = ResolveDatDir();
|
||||
if (datDir is null) return;
|
||||
|
||||
// BR-7 / A6.P4 (2026-06-11) — FLIPPED from match-the-capture to
|
||||
// assert-the-fix. The capture IS the #99 bug (live walked through:
|
||||
// cnValid=false, position == target past the slab). The per-cell
|
||||
// shadow architecture makes the door reachable from the indoor
|
||||
// side (the straddling sphere's cell array spans both threshold
|
||||
// cells; retail "covered twice", wf1-interior-collision.md), so
|
||||
// the replay must now BLOCK: a collision fires and the sphere
|
||||
// cannot cross the slab's BSP Y-range [16.848, 17.109].
|
||||
var (engine, _) = BuildEngineWithDoorFixture(datDir);
|
||||
var captured = LoadCapturedRecord(r => r.Tick == 13558);
|
||||
AssertCallMatchesCapture(engine, captured);
|
||||
var (result, _) = ReplayCapturedCall(engine, captured);
|
||||
|
||||
Assert.True(result.CollisionNormalValid,
|
||||
$"Door must block the indoor-side off-center approach (#99 closed); " +
|
||||
$"pos=({result.Position.X:F4},{result.Position.Y:F4},{result.Position.Z:F4})");
|
||||
Assert.True(result.Position.Y <= 17.0f,
|
||||
$"Sphere must not cross the slab; pos.Y={result.Position.Y:F4} " +
|
||||
$"(capture's walkthrough reached 17.2041)");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -107,9 +122,28 @@ public class DoorBugTrajectoryReplayTests
|
|||
var datDir = ResolveDatDir();
|
||||
if (datDir is null) return;
|
||||
|
||||
// BR-7 / A6.P4 (2026-06-11) — narrowed from full-capture match to
|
||||
// the blocking invariant. The capture (the WORKING outdoor side)
|
||||
// blocked Y at 18.0183 and slid the tiny lateral component
|
||||
// (X -0.0357, cn=(0,+1,0)). The harness blocks Y identically but
|
||||
// LOSES the near-perpendicular lateral slide (degenerate-offset
|
||||
// guard in the slide response converts it to a hard stop,
|
||||
// cn=(0,0,1) from the post-stop ground refresh). That residual is
|
||||
// filed as issue #116 (slide-response, NOT a cell-set problem —
|
||||
// the [bsp-test]/[cyl-skip-bsp] probes show the door found +
|
||||
// BSP-only dispatched correctly; see
|
||||
// Diagnostic_Tick22760_DumpEngineInternals). The invariant this
|
||||
// pin protects: the door BLOCKS from the outdoor side.
|
||||
var (engine, _) = BuildEngineWithDoorFixture(datDir);
|
||||
var captured = LoadCapturedRecord(r => r.Tick == 22760);
|
||||
AssertCallMatchesCapture(engine, captured);
|
||||
var (result, _) = ReplayCapturedCall(engine, captured);
|
||||
|
||||
Assert.True(result.CollisionNormalValid,
|
||||
$"Door must block the outdoor-side approach; " +
|
||||
$"pos=({result.Position.X:F4},{result.Position.Y:F4},{result.Position.Z:F4})");
|
||||
Assert.True(result.Position.Y >= 17.95f,
|
||||
$"Sphere must not penetrate southward past the slab; " +
|
||||
$"pos.Y={result.Position.Y:F4} (live blocked at 18.0183)");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -119,6 +153,63 @@ public class DoorBugTrajectoryReplayTests
|
|||
/// to see the engine's internal decisions on the failing tick.
|
||||
/// Always passes (diagnostic-only).
|
||||
/// </summary>
|
||||
/// <summary>
|
||||
/// BR-7 diagnostic twin for tick 22760 (outdoor-side block). Live slid
|
||||
/// along the door face (cn=(0,1,0), X free); the harness has historically
|
||||
/// hard-stopped with cn=(0,0,1). Always passes; read the console dump.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void Diagnostic_Tick22760_DumpEngineInternals()
|
||||
{
|
||||
var datDir = ResolveDatDir();
|
||||
if (datDir is null) return;
|
||||
|
||||
PhysicsDiagnostics.ProbeResolveEnabled = true;
|
||||
PhysicsDiagnostics.ProbeBuildingEnabled = true;
|
||||
PhysicsDiagnostics.ProbeIndoorBspEnabled = true;
|
||||
PhysicsDiagnostics.ProbePushBackEnabled = true;
|
||||
PhysicsDiagnostics.ProbeStepWalkEnabled = true;
|
||||
try
|
||||
{
|
||||
var (engine, _) = BuildEngineWithDoorFixture(datDir);
|
||||
var captured = LoadCapturedRecord(r => r.Tick == 22760);
|
||||
var body = SeedBodyFromSnapshot(captured.BodyBefore!);
|
||||
|
||||
Console.WriteLine("=== Replay tick 22760 (outdoor-side block) ===");
|
||||
var result = engine.ResolveWithTransition(
|
||||
currentPos: captured.Input.CurrentPos,
|
||||
targetPos: captured.Input.TargetPos,
|
||||
cellId: captured.Input.CellId,
|
||||
sphereRadius: captured.Input.SphereRadius,
|
||||
sphereHeight: captured.Input.SphereHeight,
|
||||
stepUpHeight: captured.Input.StepUpHeight,
|
||||
stepDownHeight: captured.Input.StepDownHeight,
|
||||
isOnGround: captured.Input.IsOnGround,
|
||||
body: body,
|
||||
moverFlags: (ObjectInfoState)captured.Input.MoverFlags,
|
||||
movingEntityId: captured.Input.MovingEntityId);
|
||||
|
||||
Console.WriteLine(string.Format(System.Globalization.CultureInfo.InvariantCulture,
|
||||
"=== Harness: pos=({0:F4},{1:F4},{2:F4}) cn=({3:F4},{4:F4},{5:F4}) cnValid={6} onGround={7} cell=0x{8:X8}",
|
||||
result.Position.X, result.Position.Y, result.Position.Z,
|
||||
result.CollisionNormal.X, result.CollisionNormal.Y, result.CollisionNormal.Z,
|
||||
result.CollisionNormalValid, result.IsOnGround, result.CellId));
|
||||
Console.WriteLine(string.Format(System.Globalization.CultureInfo.InvariantCulture,
|
||||
"=== Live: pos=({0:F4},{1:F4},{2:F4}) cn=({3:F4},{4:F4},{5:F4}) cnValid={6} onGround={7} cell=0x{8:X8}",
|
||||
captured.Result.Position.X, captured.Result.Position.Y, captured.Result.Position.Z,
|
||||
captured.Result.CollisionNormal.X, captured.Result.CollisionNormal.Y, captured.Result.CollisionNormal.Z,
|
||||
captured.Result.CollisionNormalValid, captured.Result.IsOnGround, captured.Result.CellId));
|
||||
}
|
||||
finally
|
||||
{
|
||||
PhysicsDiagnostics.ProbeResolveEnabled = false;
|
||||
PhysicsDiagnostics.ProbeBuildingEnabled = false;
|
||||
PhysicsDiagnostics.ProbeIndoorBspEnabled = false;
|
||||
PhysicsDiagnostics.ProbePushBackEnabled = false;
|
||||
PhysicsDiagnostics.ProbeStepWalkEnabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Diagnostic_Tick13558_DumpEngineInternals()
|
||||
{
|
||||
|
|
@ -412,7 +503,7 @@ public class DoorBugTrajectoryReplayTests
|
|||
landblockId: DoorLandblockId,
|
||||
collisionType: ShadowCollisionType.BSP,
|
||||
scale: 1.0f,
|
||||
cellScope: 0u);
|
||||
seedCellId: 0u);
|
||||
|
||||
// Replay captured tick 3254 inputs exactly.
|
||||
var currentPos = new Vector3(133.65524f, 17.58999f, 94f);
|
||||
|
|
@ -480,7 +571,7 @@ public class DoorBugTrajectoryReplayTests
|
|||
landblockId: DoorLandblockId,
|
||||
collisionType: ShadowCollisionType.BSP,
|
||||
scale: 1.0f,
|
||||
cellScope: 0u);
|
||||
seedCellId: 0u);
|
||||
|
||||
// 2. Load cell 0xA9B40150 BSP into cache (the alcove walls).
|
||||
const uint AlcoveCellId = 0xA9B40150u;
|
||||
|
|
@ -1102,6 +1193,34 @@ public class DoorBugTrajectoryReplayTests
|
|||
CellarUpTrajectoryReplayTests.CaptureJsonOptions)!;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Replays one captured ResolveWithTransition call against
|
||||
/// <paramref name="engine"/>, seeded with bodyBefore, and returns the
|
||||
/// harness result for invariant-style assertions (BR-7 flips).
|
||||
/// </summary>
|
||||
private static (ResolveResult result, PhysicsBody body) ReplayCapturedCall(
|
||||
PhysicsEngine engine,
|
||||
ResolveCaptureRecord captured)
|
||||
{
|
||||
Assert.NotNull(captured.BodyBefore);
|
||||
var body = SeedBodyFromSnapshot(captured.BodyBefore!);
|
||||
|
||||
var result = engine.ResolveWithTransition(
|
||||
currentPos: captured.Input.CurrentPos,
|
||||
targetPos: captured.Input.TargetPos,
|
||||
cellId: captured.Input.CellId,
|
||||
sphereRadius: captured.Input.SphereRadius,
|
||||
sphereHeight: captured.Input.SphereHeight,
|
||||
stepUpHeight: captured.Input.StepUpHeight,
|
||||
stepDownHeight: captured.Input.StepDownHeight,
|
||||
isOnGround: captured.Input.IsOnGround,
|
||||
body: body,
|
||||
moverFlags: (ObjectInfoState)captured.Input.MoverFlags,
|
||||
movingEntityId: captured.Input.MovingEntityId);
|
||||
|
||||
return (result, body);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Replays one captured ResolveWithTransition call against
|
||||
/// <paramref name="engine"/>, seeded with bodyBefore, and reports
|
||||
|
|
|
|||
|
|
@ -209,8 +209,13 @@ public class DoorCollisionApparatusTests
|
|||
/// sphere walks through — exactly what the user reports in the
|
||||
/// live Holtburg session 2026-05-24.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// BR-7 / A6.P4 (2026-06-11) — FLIPPED from documents-the-bug to
|
||||
/// asserts-the-fix: with the per-cell shadow architecture the door is
|
||||
/// found from every overlapped cell and this approach now blocks.
|
||||
/// </remarks>
|
||||
[Fact]
|
||||
public void Apparatus_Grounded_50cmOffCenter_FrontApproach_DocumentsBug()
|
||||
public void Apparatus_Grounded_50cmOffCenter_FrontApproach_Blocks()
|
||||
{
|
||||
if (!TryBuildScenario(out var ctx)) return;
|
||||
|
||||
|
|
@ -282,19 +287,19 @@ public class DoorCollisionApparatusTests
|
|||
_out.WriteLine($"Final pos = ({pos.X:F3}, {pos.Y:F3}, {pos.Z:F3}) after {ticks + 1} ticks; blocked={blocked}");
|
||||
_out.WriteLine($"Grounded={isOnGround}");
|
||||
|
||||
// EXPECTED FAILURE (documents-the-bug): the grounded sphere walks
|
||||
// straight through, reaching the far side at Y > 12.30. When the
|
||||
// fix lands, flip this to Assert.True(blocked) — same shape as
|
||||
// the Path-6 apparatus tests above.
|
||||
// FLIPPED (BR-7 / A6.P4, 2026-06-11): this test documented the #99
|
||||
// walk-through; the per-cell shadow architecture closes it. The
|
||||
// grounded Path-5 approach must now BLOCK before the slab
|
||||
// (Y < 12.0) — the same shape as the Path-6 apparatus tests above.
|
||||
PhysicsDiagnostics.ProbeResolveEnabled = false;
|
||||
PhysicsDiagnostics.ProbeBuildingEnabled = false;
|
||||
Env.SetEnvironmentVariable("ACDREAM_DUMP_STEPUP", null);
|
||||
|
||||
Assert.True(pos.Y > 12.30f,
|
||||
$"This test documents the production bug. If this is failing " +
|
||||
$"because the sphere now blocks, the door fix worked — flip " +
|
||||
$"the assertion to Assert.True(blocked) and Assert.True(pos.Y < 12.0f). " +
|
||||
Assert.True(blocked,
|
||||
$"Door must block the grounded off-center approach (#99 closed). " +
|
||||
$"Current pos=({pos.X:F3},{pos.Y:F3},{pos.Z:F3}) blocked={blocked}");
|
||||
Assert.True(pos.Y < 12.0f,
|
||||
$"Sphere must stop before the slab; pos.Y={pos.Y:F3}");
|
||||
}
|
||||
|
||||
// ───────────────────────────────────────────────────────────────
|
||||
|
|
|
|||
|
|
@ -128,21 +128,22 @@ public class FindEnvCollisionsMultiCellTests
|
|||
stepUpHeight: 0.04f,
|
||||
cellId: VestibuleCellId);
|
||||
|
||||
// SetCheckPos sets the candidate position FindEnvCollisions evaluates.
|
||||
t.SpherePath.SetCheckPos(to, VestibuleCellId);
|
||||
|
||||
// ── Act ───────────────────────────────────────────────────────────
|
||||
// Call FindEnvCollisions directly (now internal). Bypasses
|
||||
// FindTransitionalPosition's sub-step iteration so we can assert on
|
||||
// the single result.
|
||||
var result = t.FindEnvCollisions(engine);
|
||||
// BR-7 / A6.P4 (2026-06-11): the other-cells pass moved from
|
||||
// FindEnvCollisions into TransitionalInsert Phase 2.5 (retail
|
||||
// transitional_insert's OK_TS case, Ghidra 0x0050b756: the primary
|
||||
// insert runs env → building → objects, THEN check_other_cells).
|
||||
// Drive the public entry so the full per-attempt order runs.
|
||||
t.FindTransitionalPosition(engine);
|
||||
|
||||
// ── Assert ────────────────────────────────────────────────────────
|
||||
// Pre-A4: empty vestibule BSP returns OK, interior is never queried,
|
||||
// result == OK (sphere walks through the wall).
|
||||
// Post-A4: CheckOtherCells iterates the interior cell, BSPQuery on
|
||||
// TallWall returns Slid (the wall-slide path matching B2), and
|
||||
// FindEnvCollisions returns Slid via ApplyOtherCellResult.
|
||||
Assert.NotEqual(TransitionState.OK, result);
|
||||
// and the sphere walks through the wall to x=0.7.
|
||||
// Post-A4 (now via Phase 2.5's CheckOtherCells): the interior cell's
|
||||
// TallWall halts/slides the sphere — its center cannot pass
|
||||
// wall-X (0.8 world) minus the sphere radius (0.2) = 0.6.
|
||||
Assert.True(t.SpherePath.CurPos.X <= 0.6f + PhysicsGlobals.EPSILON * 20f,
|
||||
$"Adjacent cell's wall must block the sphere at world x≈0.6; " +
|
||||
$"CurPos.X={t.SpherePath.CurPos.X:F4} (walked through = A4 regression).");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -114,49 +114,48 @@ public class ShadowObjectRegistryTests
|
|||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// GetNearbyObjects
|
||||
// Per-cell query surface (BR-7 / A6.P4 2026-06-11): GetObjectsInCell IS
|
||||
// the query — retail CObjCell::find_obj_collisions iterates only the
|
||||
// asked cell's shadow_object_list (Ghidra 0x0052b750). The former
|
||||
// radial GetNearbyObjects sweep is deleted; cell membership is the
|
||||
// broad phase.
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
[Fact]
|
||||
public void GetNearbyObjects_QueryCoversEntity_ReturnsIt()
|
||||
public void PerCellQuery_EntityCell_ReturnsIt()
|
||||
{
|
||||
var reg = new ShadowObjectRegistry();
|
||||
reg.Register(10u, 0x01000005u, new Vector3(30f, 30f, 50f), Quaternion.Identity, 1f, OffX, OffY, LbId);
|
||||
|
||||
var results = new List<ShadowEntry>();
|
||||
reg.GetNearbyObjects(new Vector3(30f, 30f, 50f), 5f, OffX, OffY, LbId, results);
|
||||
|
||||
// local (30,30) → landcell (1,1) → 1*8+1+1 = 10.
|
||||
var results = reg.GetObjectsInCell(LbId | 10u);
|
||||
Assert.Single(results);
|
||||
Assert.Equal(10u, results[0].EntityId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetNearbyObjects_QueryFarFromEntity_ReturnsEmpty()
|
||||
public void PerCellQuery_FarCell_ReturnsEmpty()
|
||||
{
|
||||
var reg = new ShadowObjectRegistry();
|
||||
// Entity at local (12, 12) — cell (0,0).
|
||||
reg.Register(11u, 0x01000006u, new Vector3(12f, 12f, 50f), Quaternion.Identity, 1f, OffX, OffY, LbId);
|
||||
|
||||
var results = new List<ShadowEntry>();
|
||||
// Query at local (180, 180) — cell (7,7) — far away.
|
||||
reg.GetNearbyObjects(new Vector3(180f, 180f, 50f), 5f, OffX, OffY, LbId, results);
|
||||
|
||||
Assert.Empty(results);
|
||||
// Cell (7,7) — far away. No spatial radius can reach across cells.
|
||||
Assert.Empty(reg.GetObjectsInCell(LbId | 64u));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetNearbyObjects_EntityInMultipleCells_ReturnedOnce()
|
||||
public void PerCellQuery_EntityInMultipleCells_OncePerCellList()
|
||||
{
|
||||
// Entity spans cells 0,0 and 1,0 (local X≈24, radius=2).
|
||||
// Entity spans cells (0,0) and (1,0) (local X≈24, radius=2) via the
|
||||
// flood's boundary-neighbor adds. Each overlapped cell's list holds
|
||||
// the entry exactly once — retail tests an object once per iterated
|
||||
// cell (no cross-cell dedup exists in find_obj_collisions).
|
||||
var reg = new ShadowObjectRegistry();
|
||||
reg.Register(20u, 0x01000007u, new Vector3(24f, 12f, 50f), Quaternion.Identity, 2f, OffX, OffY, LbId);
|
||||
|
||||
var results = new List<ShadowEntry>();
|
||||
// Large query covers both cells; entity must appear exactly once.
|
||||
reg.GetNearbyObjects(new Vector3(24f, 12f, 50f), 10f, OffX, OffY, LbId, results);
|
||||
|
||||
Assert.Single(results);
|
||||
Assert.Equal(20u, results[0].EntityId);
|
||||
Assert.Single(reg.GetObjectsInCell(LbId | 1u), e => e.EntityId == 20u);
|
||||
Assert.Single(reg.GetObjectsInCell(LbId | 9u), e => e.EntityId == 20u);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
|
|
@ -303,71 +302,151 @@ public class ShadowObjectRegistryTests
|
|||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// A6.P4 slice 1 — portalReachableCells set includes outdoor cells
|
||||
// when sphere straddles an exit portal (issue #99)
|
||||
// BR-7 / A6.P4 (2026-06-11) — registration-side architecture pins.
|
||||
// The former query-side compensations (the b3ce505 indoor gate, the
|
||||
// portalReachableCells expansion, the isViewer exemption) are deleted;
|
||||
// these pin the registration shapes that replaced them.
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
[Fact]
|
||||
public void GetNearbyObjects_PortalReachableSetIncludesOutdoorCell_IndoorPrimary_DoorReturned()
|
||||
public void Register_OutdoorSeed_DoorVisibleInItsOutdoorCell_NotInUnrelatedIndoorCell()
|
||||
{
|
||||
// A6.P4 slice 1 / issue #99 (2026-05-24): when the player's sphere is
|
||||
// in an indoor cell but its CellTransit.FindCellSet result includes
|
||||
// an outdoor cell (via AddAllOutsideCells triggered by the sphere
|
||||
// straddling an OtherCellId=0xFFFF exit portal), GetNearbyObjects
|
||||
// must return shadows registered in that outdoor cell. Doors are
|
||||
// server-spawned entities registered at GameWindow.cs:3139 with
|
||||
// default cellScope=0u → outdoor 24-m grid registration. Before this
|
||||
// fix, the loop filtered out outdoor cell ids ("skip outdoor ids")
|
||||
// AND #98's primaryCellId gate skipped the radial sweep — net result
|
||||
// was that doors at building thresholds were invisible to spheres
|
||||
// on the indoor side: walk-through.
|
||||
// Issue #99 architecture: a door registered at its outdoor cell is
|
||||
// found by iterating THAT cell's list — which the Transition reaches
|
||||
// from the indoor side when its sphere straddles the exit portal
|
||||
// (the cell array spans both cells at the threshold; retail
|
||||
// "covered twice" note, wf1-interior-collision.md). Without a
|
||||
// building bridge in the flood cache, the door floods outdoor-only.
|
||||
var reg = new ShadowObjectRegistry();
|
||||
|
||||
const uint doorEntityId = 0x000F4244u;
|
||||
reg.Register(doorEntityId, 0x020019FFu, new Vector3(12f, 12f, 50f),
|
||||
Quaternion.Identity, 1f, OffX, OffY, LbId,
|
||||
ShadowCollisionType.Cylinder, cylHeight: 2.5f);
|
||||
ShadowCollisionType.Cylinder, cylHeight: 2.5f,
|
||||
isStatic: false);
|
||||
|
||||
var results = new List<ShadowEntry>();
|
||||
uint doorOutdoorCellId = LbId | 1u; // outdoor cell where door sits
|
||||
uint vestibuleCellId = LbId | 0x0145u; // indoor cell on the other side
|
||||
|
||||
// Sphere is in the vestibule; FindCellSet added the doorway's outdoor
|
||||
// cell via AddAllOutsideCells. Both ids land in portalReachableCells.
|
||||
reg.GetNearbyObjects(
|
||||
new Vector3(12f, 12f, 50f), 5f, OffX, OffY, LbId, results,
|
||||
portalReachableCells: new[] { vestibuleCellId, doorOutdoorCellId },
|
||||
primaryCellId: vestibuleCellId);
|
||||
|
||||
Assert.Contains(results, e => e.EntityId == doorEntityId);
|
||||
Assert.Contains(reg.GetObjectsInCell(doorOutdoorCellId), e => e.EntityId == doorEntityId);
|
||||
Assert.DoesNotContain(reg.GetObjectsInCell(vestibuleCellId), e => e.EntityId == doorEntityId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetNearbyObjects_IndoorPrimary_IndoorOnlyPortalSet_OutdoorRadialStillSkipped()
|
||||
public void Register_OutdoorFootprint_NeverLandsInInteriorCells()
|
||||
{
|
||||
// Regression check for issue #98: when the FindCellSet result holds
|
||||
// only indoor cells (sphere not near an exit portal — e.g. deep in
|
||||
// a cellar), the radial outdoor sweep must stay skipped so the
|
||||
// landblock-baked cottage GfxObj (registered at outdoor cellScope=0)
|
||||
// is NOT returned to a sphere in the cellar EnvCell. Otherwise the
|
||||
// head sphere bumps the cottage's downward-facing floor poly from
|
||||
// below and caps the cellar ascent at world Z≈92.7.
|
||||
// The #98 shape, now closed at REGISTRATION: an outdoor-positioned
|
||||
// footprint (the old cottage GfxObj entry) floods into outdoor
|
||||
// landcells only — without a building-bridge admission its spheres
|
||||
// can never reach an interior cell's list, so a fully-interior
|
||||
// cellar query structurally cannot see it. (In production the
|
||||
// cottage SHELL additionally left the registry entirely — the
|
||||
// per-LandCell building channel owns it.)
|
||||
var reg = new ShadowObjectRegistry();
|
||||
|
||||
const uint cottageEntityId = 0xA9B47900u;
|
||||
reg.Register(cottageEntityId, 0x01000A2Bu, new Vector3(12f, 12f, 90f),
|
||||
Quaternion.Identity, 5.5f, OffX, OffY, LbId);
|
||||
|
||||
var results = new List<ShadowEntry>();
|
||||
uint cellarCellId = LbId | 0x0146u;
|
||||
Assert.Empty(reg.GetObjectsInCell(cellarCellId));
|
||||
|
||||
// Sphere is in the cellar; FindCellSet returned indoor-only set
|
||||
// (no exit portal nearby).
|
||||
reg.GetNearbyObjects(
|
||||
new Vector3(12f, 12f, 50f), 5.5f, OffX, OffY, LbId, results,
|
||||
portalReachableCells: new[] { cellarCellId },
|
||||
primaryCellId: cellarCellId);
|
||||
// And every cell it DID land in is outdoor.
|
||||
foreach (var entry in reg.AllEntriesForDebug())
|
||||
Assert.Equal(cottageEntityId, entry.EntityId);
|
||||
}
|
||||
|
||||
Assert.DoesNotContain(results, e => e.EntityId == cottageEntityId);
|
||||
[Fact]
|
||||
public void RefloodLandblock_RerunsFloodAfterCellsHydrate()
|
||||
{
|
||||
// The streaming race (spec §7 Q3 / retail init_objects →
|
||||
// recalc_cross_cells): an entity registered while its indoor seed
|
||||
// cell was unhydrated stays pinned to {seed}; once the cell (with a
|
||||
// portal neighbor) hydrates, RefloodLandblock re-runs the flood and
|
||||
// the neighbor appears in the set.
|
||||
var reg = new ShadowObjectRegistry();
|
||||
var cache = new PhysicsDataCache();
|
||||
reg.DataCache = cache;
|
||||
|
||||
const uint seedCell = 0xA9B40100u;
|
||||
const uint neighborCell = 0xA9B40101u;
|
||||
|
||||
reg.Register(77u, 0x01000009u, new Vector3(2.0f, 0f, 2.5f),
|
||||
Quaternion.Identity, 0.5f, OffX, OffY, LbId,
|
||||
seedCellId: seedCell, isStatic: false);
|
||||
|
||||
// Unhydrated seed → registered under the claimed cell only.
|
||||
Assert.Contains(reg.GetObjectsInCell(seedCell), e => e.EntityId == 77u);
|
||||
Assert.Empty(reg.GetObjectsInCell(neighborCell));
|
||||
|
||||
// Hydrate the seed (portal to the neighbor at x=2.5) + the neighbor
|
||||
// (leaf BSP admits the straddling sphere), then re-flood.
|
||||
cache.RegisterCellStructForTest(seedCell,
|
||||
BuildShadowCellSetTests_MakeCellWithPortalAtRightWall(Matrix4x4.Identity, 0x0101));
|
||||
cache.RegisterCellStructForTest(neighborCell,
|
||||
BuildShadowCellSetTests_MakeLeafCell(Matrix4x4.CreateTranslation(5f, 0f, 0f)));
|
||||
|
||||
reg.RefloodLandblock(LbId);
|
||||
|
||||
Assert.Contains(reg.GetObjectsInCell(seedCell), e => e.EntityId == 77u);
|
||||
Assert.Contains(reg.GetObjectsInCell(neighborCell), e => e.EntityId == 77u);
|
||||
}
|
||||
|
||||
// Local copies of the BuildShadowCellSetTests fixture helpers (kept
|
||||
// private per test class by repo convention).
|
||||
private static CellPhysics BuildShadowCellSetTests_MakeCellWithPortalAtRightWall(
|
||||
Matrix4x4 worldTransform, ushort otherCellId)
|
||||
{
|
||||
var portalPoly = new ResolvedPolygon
|
||||
{
|
||||
Vertices = new[]
|
||||
{
|
||||
new Vector3(2.5f, -2.5f, 0f),
|
||||
new Vector3(2.5f, 2.5f, 0f),
|
||||
new Vector3(2.5f, 2.5f, 5f),
|
||||
new Vector3(2.5f, -2.5f, 5f),
|
||||
},
|
||||
Plane = new System.Numerics.Plane(new Vector3(1, 0, 0), -2.5f),
|
||||
NumPoints = 4,
|
||||
SidesType = DatReaderWriter.Enums.CullMode.None,
|
||||
};
|
||||
|
||||
Matrix4x4.Invert(worldTransform, out var inv);
|
||||
return new CellPhysics
|
||||
{
|
||||
WorldTransform = worldTransform,
|
||||
InverseWorldTransform = inv,
|
||||
Resolved = new Dictionary<ushort, ResolvedPolygon>(),
|
||||
PortalPolygons = new Dictionary<ushort, ResolvedPolygon> { [10] = portalPoly },
|
||||
Portals = new[]
|
||||
{
|
||||
new PortalInfo(otherCellId: otherCellId, polygonId: 10, flags: 0),
|
||||
},
|
||||
CellBSP = new DatReaderWriter.Types.CellBSPTree
|
||||
{
|
||||
Root = new DatReaderWriter.Types.CellBSPNode
|
||||
{
|
||||
Type = DatReaderWriter.Enums.BSPNodeType.Leaf,
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
private static CellPhysics BuildShadowCellSetTests_MakeLeafCell(Matrix4x4 worldTransform)
|
||||
{
|
||||
Matrix4x4.Invert(worldTransform, out var inv);
|
||||
return new CellPhysics
|
||||
{
|
||||
WorldTransform = worldTransform,
|
||||
InverseWorldTransform = inv,
|
||||
Resolved = new Dictionary<ushort, ResolvedPolygon>(),
|
||||
CellBSP = new DatReaderWriter.Types.CellBSPTree
|
||||
{
|
||||
Root = new DatReaderWriter.Types.CellBSPNode
|
||||
{
|
||||
Type = DatReaderWriter.Enums.BSPNodeType.Leaf,
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue