using AcDream.Core.Physics; using DatReaderWriter.Enums; using System.Numerics; using Xunit; namespace AcDream.Core.Tests.Physics; /// /// L.2d slice 1 (2026-05-13) — unit coverage for the new /// flag and /// diagnostic /// side-channel. /// /// /// The full multi-line [resolve-bldg] format itself is verified /// by the slice's acceptance criterion #2 (live Holtburg-doorway /// capture) — covering it here would require a heavy /// PhysicsEngine + ShadowObjectRegistry + Transition /// 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. /// /// 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; } } }