acdream/tests/AcDream.Core.Tests/Physics/InitialPlacementOverlapTests.cs
Erik 6921a02744 refactor(physics): delete legacy PhysicsEngine.Resolve/ResolvePlacement/HasCellSurface (C5a, AP-1/AD-1)
Member-wise deletion of the three legacy resolver members named in
docs/research/2026-08-05-c5a-contract.md: PhysicsEngine.Resolve,
PhysicsEngine.HasCellSurface, and PhysicsEngine.ResolvePlacement. An
exhaustive receiver census over src/ found zero production callers of any
of the three — every production placement writer already reaches the
canonical PhysicsEngine.SetPosition transaction exclusively through
RuntimeSetPositionState (three call sites total). The deletion is purely
member-wise: IsSpawnCellReady and AdjustPosition, which shared the same
source region as the deleted members, are preserved byte-identical — every
remaining production caller of either (including PhysicsCameraCollisionProbe,
AdjustPosition's sole surviving production caller) is unaffected.

Companion changes:
- PlayerMovementController's 3-argument SetPosition test overload is renamed
  to SeedPlacementForTest (internal) and CommitPreparedPosition is deleted;
  83 call sites across 19 test files were mechanically renamed to match.
- Seven pinned test dispositions from the contract are executed:
  3.1 (PhysicsEngineTests.cs: 11 legacy-resolver tests deleted, 6
  ResolveWithTransition tests kept), 3.2/3.3/3.4 (re-point to canonical
  SetPosition, with TransitionScratchDifferentialTests.cs additionally
  gaining positive IsCommitted assertions after each bitwise comparison so
  the differential proves a placement actually committed, not just that two
  possibly-uncommitted results match), 3.5 (Runtime rename), and 3.6
  (PlayerMovementPlacementTransactionTests.cs rewritten — its xmldoc now
  states plainly that the render-root publish moved to
  RuntimeSetPositionState.cs, but the sticky-release relocation claim was
  false and is retracted; this disposition's coverage loss is the sticky
  release path, not silently absorbed elsewhere).
- Stale `PhysicsEngine.Resolve`/`Resolve` doc citations in CellTransit.cs,
  PlayerMovementController.cs, and HeadlessSessionWorldProjection.cs are
  corrected to name the surviving canonical entry points by symbol
  (SetPosition, AdjustSetPosition/AdjustPosition, ResolveWithTransition)
  rather than fragile line numbers.

Retires AP-1 and AD-1 in docs/architecture/retail-divergence-register.md:
both rows described production zero-delta placement routing remaining on
the legacy resolver pending the Slice 4B2/4B route cutover; that resolver
no longer exists, so the condition each row tracked is now structurally
false rather than merely narrowed. AP-145 (routed through the prior commit)
and this commit's AP-1/AD-1 together bring the section counts to 101 AP / 47
AD active rows.

Builds on the AP-145 fix (previous commit) — this commit's staged tree was
independently rebuilt and its four suites independently rerun on top of
that commit before this commit was created, in addition to the combined
rebuild/rerun below.

Full-solution build: 0 errors (21 pre-existing warnings, all unrelated).
Suite results (combined tree): Core 4270/4271 passed (1 skip; the single
DatSoundCacheTests concurrent-decode-dedup failure is a known load-sensitive
race, confirmed passing standalone and unrelated to this change), Runtime
1176/1176, Headless 86/86, App 4132/4135 (3 skips).

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-05 14:11:31 +02:00

121 lines
5 KiB
C#

using System.Collections.Immutable;
using System.Numerics;
using AcDream.Core.Physics;
namespace AcDream.Core.Tests.Physics;
/// <summary>
/// Enter-world overlap conformance for retail
/// <c>CTransition::find_placement_pos</c> (0x0050BA50).
///
/// <para>
/// C5a (2026-08-05) re-point: the legacy <c>PhysicsEngine.ResolvePlacement</c>
/// this test originally drove is deleted (zero production callers). Canonical
/// <c>PhysicsEngine.SetPosition</c> reaches the SAME ring-search machinery —
/// <c>SetPositionInternal</c> sets <c>InsertType.Placement</c> before calling
/// <c>Transition.FindValidPosition</c>, which (for any non-<c>Transition</c>
/// insert type) dispatches to <c>FindPlacementPosition</c>
/// (<c>TransitionTypes.cs</c>), and THAT method calls this exact
/// <c>FindPlacementPos</c> ring search after its initial-placement insert —
/// so this is not a new code path, only a new entry point onto the one the
/// legacy method used directly. Sphere shape is reconstructed as the
/// two-sphere capsule the legacy scalar <c>(radius, height)</c> overload
/// built internally (origin (0,0,radius) + (0,0,height-radius), both
/// radius-sized), since canonical <c>SetPosition</c> takes a pre-built
/// sphere list rather than a radius/height pair.
/// </para>
/// </summary>
public sealed class InitialPlacementOverlapTests
{
private const uint Landblock = 0xA9B40000u;
private const uint Cell = Landblock | 0x0001u;
private const uint PlayerId = 0x50000001u;
private const uint MonsterId = 0x50000002u;
private const float Radius = 0.48f;
private const float SphereHeight = 1.835f;
[Fact]
public void PlayerReloggingInsideMonster_SearchesOutToNearestClearRing()
{
var engine = new PhysicsEngine { DataCache = new PhysicsDataCache() };
engine.AddLandblock(
Landblock,
new TerrainSurface(new byte[81], new float[256]),
Array.Empty<CellSurface>(),
Array.Empty<PortalPlane>(),
0f,
0f);
var savedFeet = new Vector3(10f, 10f, 0f);
var playerCenter = savedFeet + new Vector3(0f, 0f, Radius);
var monsterCenter = playerCenter + new Vector3(0.10f, 0f, 0f);
// Retail registers every placed CPhysicsObj, including the local
// player. The mover's OBJECTINFO::object self pointer excludes only
// its own shadow while the monster remains an obstruction.
RegisterSphere(engine, PlayerId, playerCenter,
EntityCollisionFlags.IsPlayer | EntityCollisionFlags.IsCreature);
RegisterSphere(engine, MonsterId, monsterCenter,
EntityCollisionFlags.IsCreature);
// The mover's own two-sphere capsule, matching the legacy scalar
// InitPath(sphereRadius: 0.48, sphereHeight: 1.835) reconstruction:
// a foot sphere at (0,0,radius) and a head sphere at
// (0,0,height-radius), both radius-sized.
ImmutableArray<FlatCollisionSphere> spheres = ImmutableArray.Create(
new FlatCollisionSphere(new Vector3(0f, 0f, Radius), Radius),
new FlatCollisionSphere(new Vector3(0f, 0f, SphereHeight - Radius), Radius));
PhysicsSetPositionResult result = engine.SetPosition(
new PhysicsSetPositionRequest(
Position: savedFeet,
Orientation: Quaternion.Identity,
CellId: Cell,
CellLocalPosition: savedFeet,
Spheres: spheres,
Scale: 1f,
StepUpHeight: 0.4f,
StepDownHeight: 0.4f,
MoverFlags: ObjectInfoState.IsPlayer | ObjectInfoState.EdgeSlide,
MovingEntityId: PlayerId,
Flags: PhysicsSetPositionFlags.Placement
| PhysicsSetPositionFlags.Slide));
Assert.True(result.IsCommitted);
Assert.True(result.InContact);
Assert.True(result.OnWalkable);
Assert.Equal(Cell, result.ContactPlaneCellId);
Assert.NotEqual(savedFeet, result.Position);
float centerDistance = Vector3.Distance(
result.Position + new Vector3(0f, 0f, Radius),
monsterCenter);
Assert.True(centerDistance >= Radius * 2f - PhysicsGlobals.EPSILON,
$"placement must clear the monster; centers remain {centerDistance:F3} m apart");
Assert.True(Vector3.Distance(savedFeet, result.Position) <= 4f,
"retail placement search is bounded to four metres");
}
private static void RegisterSphere(
PhysicsEngine engine,
uint id,
Vector3 center,
EntityCollisionFlags flags)
{
engine.ShadowObjects.Register(
id,
gfxObjId: 0u,
worldPos: center,
rotation: Quaternion.Identity,
radius: Radius,
worldOffsetX: 0f,
worldOffsetY: 0f,
landblockId: Landblock,
collisionType: ShadowCollisionType.Sphere,
cylHeight: 0f,
scale: 1f,
state: 0u,
flags: flags,
seedCellId: Cell,
isStatic: false);
}
}