New PhysicsDiagnostics flag gates the [push-back] probe shipping in subsequent tasks. Env-var ACDREAM_PROBE_PUSH_BACK=1 + DebugVM mirror, matching the existing probe-toggle pattern. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
121 lines
4.3 KiB
C#
121 lines
4.3 KiB
C#
using AcDream.Core.Physics;
|
|
using DatReaderWriter.Enums;
|
|
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;
|
|
}
|
|
}
|
|
}
|