Add ProbeSweptEnabled (ACDREAM_PROBE_SWEPT=1) to PhysicsDiagnostics mirroring ProbeCellEnabled. Emits one [cell-swept] line per ResolveWithTransition call — sp.CurCellId and sp.CheckCellId (the transition's swept cells) alongside the incoming cellId so a doorway capture shows whether the swept cell is stable where ResolveCellId strobes. No ResolveCellId call in the probe — avoids the CellGraph.CurrCell side effect. No behavior change. TDD: ProbeSweptEnabled_DefaultsToFalse RED→GREEN in PhysicsDiagnosticsTests. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
179 lines
6.4 KiB
C#
179 lines
6.4 KiB
C#
using AcDream.Core.Physics;
|
|
using DatReaderWriter.Enums;
|
|
using System.Collections.Generic;
|
|
using System.Numerics;
|
|
using Xunit;
|
|
|
|
namespace AcDream.Core.Tests.Physics;
|
|
|
|
/// <summary>
|
|
/// L.2d slice 1 (2026-05-13) — unit coverage for the new
|
|
/// <see cref="PhysicsDiagnostics.ProbeBuildingEnabled"/> flag and
|
|
/// <see cref="PhysicsDiagnostics.LastBspHitPoly"/> diagnostic
|
|
/// side-channel.
|
|
///
|
|
/// <para>
|
|
/// The full multi-line <c>[resolve-bldg]</c> format itself is verified
|
|
/// by the slice's acceptance criterion #2 (live Holtburg-doorway
|
|
/// capture) — covering it here would require a heavy
|
|
/// <c>PhysicsEngine</c> + <c>ShadowObjectRegistry</c> + <c>Transition</c>
|
|
/// fixture for what's a diagnostic-only emission. These tests pin the
|
|
/// static API contract that the emission code depends on; if either of
|
|
/// these tests breaks the emission will start producing stale data or
|
|
/// failing to emit at all.
|
|
/// </para>
|
|
/// </summary>
|
|
public class PhysicsDiagnosticsTests
|
|
{
|
|
// -----------------------------------------------------------------------
|
|
// ProbeBuildingEnabled — flag gates the emission path.
|
|
// -----------------------------------------------------------------------
|
|
|
|
[Fact]
|
|
public void ProbeBuilding_StaticApi_Roundtrip()
|
|
{
|
|
bool initial = PhysicsDiagnostics.ProbeBuildingEnabled;
|
|
try
|
|
{
|
|
PhysicsDiagnostics.ProbeBuildingEnabled = true;
|
|
Assert.True(PhysicsDiagnostics.ProbeBuildingEnabled);
|
|
|
|
PhysicsDiagnostics.ProbeBuildingEnabled = false;
|
|
Assert.False(PhysicsDiagnostics.ProbeBuildingEnabled);
|
|
}
|
|
finally
|
|
{
|
|
// Restore so a process-wide static doesn't leak between tests
|
|
// (env-var init was the only thing that set this before).
|
|
PhysicsDiagnostics.ProbeBuildingEnabled = initial;
|
|
}
|
|
}
|
|
|
|
// -----------------------------------------------------------------------
|
|
// LastBspHitPoly — side-channel set by BSPQuery, read by FindObjCollisions.
|
|
//
|
|
// TransitionTypes.FindObjCollisions clears this to null before each
|
|
// shadow-entry dispatch; BSPQuery writes to it on hit when the probe is
|
|
// on; the emission site reads it. A failure here means the side-channel
|
|
// can't carry data through the call chain.
|
|
// -----------------------------------------------------------------------
|
|
|
|
[Fact]
|
|
public void LastBspHitPoly_StaticApi_Roundtrip()
|
|
{
|
|
ResolvedPolygon? initial = PhysicsDiagnostics.LastBspHitPoly;
|
|
try
|
|
{
|
|
PhysicsDiagnostics.LastBspHitPoly = null;
|
|
Assert.Null(PhysicsDiagnostics.LastBspHitPoly);
|
|
|
|
var synthetic = new ResolvedPolygon
|
|
{
|
|
Vertices = new[]
|
|
{
|
|
new Vector3(-1f, 0f, 0f),
|
|
new Vector3( 1f, 0f, 0f),
|
|
new Vector3( 1f, 0f, 2f),
|
|
new Vector3(-1f, 0f, 2f),
|
|
},
|
|
Plane = new System.Numerics.Plane(0f, 1f, 0f, -94.123f),
|
|
NumPoints = 4,
|
|
SidesType = CullMode.None,
|
|
};
|
|
PhysicsDiagnostics.LastBspHitPoly = synthetic;
|
|
|
|
var read = PhysicsDiagnostics.LastBspHitPoly;
|
|
Assert.NotNull(read);
|
|
Assert.Equal(4, read!.NumPoints);
|
|
Assert.Equal(synthetic.Plane.D, read.Plane.D);
|
|
Assert.Same(synthetic, read);
|
|
|
|
PhysicsDiagnostics.LastBspHitPoly = null;
|
|
Assert.Null(PhysicsDiagnostics.LastBspHitPoly);
|
|
}
|
|
finally
|
|
{
|
|
PhysicsDiagnostics.LastBspHitPoly = initial;
|
|
}
|
|
}
|
|
|
|
// -----------------------------------------------------------------------
|
|
// ProbePushBackEnabled — flag gates the [push-back] emission path.
|
|
// A6.P1 (2026-05-21).
|
|
// -----------------------------------------------------------------------
|
|
|
|
[Fact]
|
|
public void ProbePushBack_StaticApi_Roundtrip()
|
|
{
|
|
bool initial = PhysicsDiagnostics.ProbePushBackEnabled;
|
|
try
|
|
{
|
|
PhysicsDiagnostics.ProbePushBackEnabled = true;
|
|
Assert.True(PhysicsDiagnostics.ProbePushBackEnabled);
|
|
|
|
PhysicsDiagnostics.ProbePushBackEnabled = false;
|
|
Assert.False(PhysicsDiagnostics.ProbePushBackEnabled);
|
|
}
|
|
finally
|
|
{
|
|
PhysicsDiagnostics.ProbePushBackEnabled = initial;
|
|
}
|
|
}
|
|
|
|
// -----------------------------------------------------------------------
|
|
// ProbeStepWalkEnabled - flag gates the [step-walk] emission path.
|
|
// A6.P3 issue #98 (2026-05-23).
|
|
// -----------------------------------------------------------------------
|
|
|
|
[Fact]
|
|
public void ProbeStepWalk_StaticApi_Roundtrip()
|
|
{
|
|
bool initial = PhysicsDiagnostics.ProbeStepWalkEnabled;
|
|
try
|
|
{
|
|
PhysicsDiagnostics.ProbeStepWalkEnabled = true;
|
|
Assert.True(PhysicsDiagnostics.ProbeStepWalkEnabled);
|
|
|
|
PhysicsDiagnostics.ProbeStepWalkEnabled = false;
|
|
Assert.False(PhysicsDiagnostics.ProbeStepWalkEnabled);
|
|
}
|
|
finally
|
|
{
|
|
PhysicsDiagnostics.ProbeStepWalkEnabled = initial;
|
|
}
|
|
}
|
|
|
|
// -----------------------------------------------------------------------
|
|
// ProbeSweptEnabled — Phase W Stage 0 (2026-06-02): [cell-swept] diagnostic.
|
|
// -----------------------------------------------------------------------
|
|
|
|
[Fact]
|
|
public void ProbeSweptEnabled_DefaultsToFalse()
|
|
{
|
|
PhysicsDiagnostics.ProbeSweptEnabled = false;
|
|
Assert.False(PhysicsDiagnostics.ProbeSweptEnabled);
|
|
}
|
|
|
|
// -----------------------------------------------------------------------
|
|
// ProbeDumpGfxObjs — parallel of ProbeDumpCells (A6.P3 #98, evening v2).
|
|
// -----------------------------------------------------------------------
|
|
|
|
[Fact]
|
|
public void ProbeDumpGfxObjs_EnabledTracksIdSetNonEmpty()
|
|
{
|
|
var initial = PhysicsDiagnostics.ProbeDumpGfxObjIds;
|
|
try
|
|
{
|
|
PhysicsDiagnostics.ProbeDumpGfxObjIds = new HashSet<uint>();
|
|
Assert.False(PhysicsDiagnostics.ProbeDumpGfxObjsEnabled);
|
|
|
|
PhysicsDiagnostics.ProbeDumpGfxObjIds = new HashSet<uint> { 0x01000A2Bu };
|
|
Assert.True(PhysicsDiagnostics.ProbeDumpGfxObjsEnabled);
|
|
Assert.Contains(0x01000A2Bu, PhysicsDiagnostics.ProbeDumpGfxObjIds);
|
|
}
|
|
finally
|
|
{
|
|
PhysicsDiagnostics.ProbeDumpGfxObjIds = initial;
|
|
}
|
|
}
|
|
}
|