acdream/tests/AcDream.Core.Tests/Physics/PhysicsDataCachePhantomSourceTests.cs
Erik 6ca872feba docs(test): #101 — sync stale GameWindow.cs line ref in test class doc
Task 2's 11-line insertion shifted the synthesis gate from line
6116 to 6127. The implementation XML doc was updated in the same
commit; the parallel test-class-level reference was missed.
Code-review minor finding; one-character fix.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-25 19:56:35 +02:00

74 lines
3.2 KiB
C#

using System.Collections.Generic;
using AcDream.Core.Physics;
using DatReaderWriter.Enums;
using DatReaderWriter.Types;
using Xunit;
namespace AcDream.Core.Tests.Physics;
/// <summary>
/// Issue #101 (2026-05-25) — phantom-stair fix. Retail's
/// <c>CPartArray::InitParts</c> emits collision shapes only from
/// Setup-level <c>CylSpheres</c>/<c>Spheres</c> or per-Part
/// <c>PhysicsBSP</c>. There is NO synthesis from visual mesh AABB.
/// Acdream's <c>mesh-aabb-fallback</c> path at
/// <c>GameWindow.cs:6127</c> previously fired for ANY entity that
/// reached it with <c>entityBsp==0 &amp;&amp; entityCyl==0</c>,
/// including GfxObj-only stabs whose GfxObj has
/// <c>HasPhysics=False</c>. This produced the 10 phantom 0.80 m
/// cylinders that block the Holtburg upper-floor staircase (see
/// <c>docs/research/2026-05-25-a6-stairs-cyl-retail-investigation.md</c>).
///
/// <para>
/// <see cref="PhysicsDataCache.IsPhantomGfxObjSource"/> captures the
/// retail rule as a predicate: "the entity's source is a GfxObj
/// (high byte 0x01) AND the cache has no <see cref="GfxObjPhysics"/>
/// entry for it." When this returns true, the caller suppresses the
/// fallback synthesis.
/// </para>
/// </summary>
public class PhysicsDataCachePhantomSourceTests
{
[Fact]
public void IsPhantomGfxObjSource_SetupHighByte_ReturnsFalse()
{
// Setup source (high byte 0x02) is never the GfxObj-phantom case.
// The existing isPhantomSetup check at GameWindow.cs:6090 handles
// the Setup-side phantom. This predicate is scoped to GfxObj only.
var cache = new PhysicsDataCache();
Assert.False(cache.IsPhantomGfxObjSource(0x020019FFu)); // door setup
Assert.False(cache.IsPhantomGfxObjSource(0x02000266u)); // some setup
}
[Fact]
public void IsPhantomGfxObjSource_GfxObjUncached_ReturnsTrue()
{
// GfxObj source (high byte 0x01) with NO cached GfxObjPhysics
// = the phantom case. The stair-step GfxObj 0x0100081A from
// issue #101's broken-stairs capture has HasPhysics=False and
// does not enter the cache. Acdream should treat it as phantom.
var cache = new PhysicsDataCache();
Assert.True(cache.IsPhantomGfxObjSource(0x0100081Au));
}
[Fact]
public void IsPhantomGfxObjSource_GfxObjCached_ReturnsFalse()
{
// GfxObj source (high byte 0x01) WITH a cached GfxObjPhysics
// (i.e. the GfxObj's HasPhysics flag was set and its PhysicsBSP
// root is non-null) is NOT phantom. The staircase BSP entity
// 0x40B50089 from issue #101's capture, backed by GfxObj
// 0x01000C16 with hasPhys=True, is this case.
var cache = new PhysicsDataCache();
var leaf = new PhysicsBSPNode { Type = BSPNodeType.Leaf };
var fakePhysics = new GfxObjPhysics
{
BSP = new PhysicsBSPTree { Root = leaf },
PhysicsPolygons = new Dictionary<ushort, Polygon>(),
Vertices = new VertexArray(),
Resolved = new Dictionary<ushort, ResolvedPolygon>(),
};
cache.RegisterGfxObjForTest(0x01000C16u, fakePhysics);
Assert.False(cache.IsPhantomGfxObjSource(0x01000C16u));
}
}