acdream/tests/AcDream.App.Tests/Input/MouseLookControllerTests.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

310 lines
9.9 KiB
C#

using System.Numerics;
using AcDream.App.Input;
using AcDream.App.Net;
using AcDream.App.Rendering;
using AcDream.Core.Net;
using AcDream.Core.Physics;
using AcDream.Core.Rendering;
using AcDream.UI.Abstractions.Input;
using Silk.NET.Input;
namespace AcDream.App.Tests.Input;
[Collection(AcDream.App.Tests.Rendering.CameraDiagnosticsCollection.Name)]
public sealed class MouseLookControllerTests
{
[Fact]
public void InstantMouseLookRequiresPlayerChaseAndInWorldState()
{
Harness harness = CreateHarness();
Assert.True(harness.Owner.HandlePointerAction(
InputAction.CameraInstantMouseLook,
ActivationType.Press));
Assert.False(harness.Owner.Active);
harness.Mode.IsPlayerMode = true;
harness.EnterChase();
harness.Player.State = PlayerState.PortalSpace;
harness.Owner.HandlePointerAction(
InputAction.CameraInstantMouseLook,
ActivationType.Press);
Assert.False(harness.Owner.Active);
harness.Player.State = PlayerState.InWorld;
harness.Owner.HandlePointerAction(
InputAction.CameraInstantMouseLook,
ActivationType.Press);
Assert.True(harness.Owner.Active);
Assert.Equal(1, harness.Cursor.HideCount);
}
[Fact]
public void ReleaseEndsMouseLookAndRestoresCursorExactlyOnce()
{
Harness harness = CreateActiveHarness();
harness.Owner.HandlePointerAction(
InputAction.CameraInstantMouseLook,
ActivationType.Release);
harness.Owner.HandlePointerAction(
InputAction.CameraInstantMouseLook,
ActivationType.Release);
Assert.False(harness.Owner.Active);
Assert.Equal(1, harness.Cursor.RestoreCount);
Assert.False(harness.Player.EndMouseLook(new MovementInput()));
}
[Fact]
public void UiCaptureTransitionEndsActiveMouseLook()
{
Harness harness = CreateActiveHarness();
harness.Mouse.WantCaptureMouse = true;
harness.Owner.Tick();
Assert.False(harness.Owner.Active);
Assert.Equal(1, harness.Cursor.RestoreCount);
Assert.False(harness.Player.EndMouseLook(new MovementInput()));
}
[Fact]
public void SessionResetRestoresCaptureAndClearsRmbOrbitWithoutWireSend()
{
Harness harness = CreateActiveHarness();
harness.Owner.HandlePointerAction(
InputAction.AcdreamRmbOrbitHold,
ActivationType.Press);
Assert.True(harness.Chase.RmbOrbitHeld);
harness.Owner.ResetSession();
Assert.False(harness.Owner.Active);
Assert.False(harness.Chase.RmbOrbitHeld);
Assert.Equal(1, harness.Cursor.RestoreCount);
Assert.Null(harness.Session.CurrentSession);
}
[Fact]
public void SixRawSamplesCrossRetailExtentGateAndSubmitTurnMotion()
{
Harness harness = CreateActiveHarness();
for (int i = 0; i < 6; i++)
{
harness.Clock.NowSeconds += 0.01f;
harness.Owner.QueueRawDelta(2f, 0f);
harness.Owner.Tick();
}
MovementResult result = harness.Player.Update(
PhysicsBody.MinQuantum + 0.001f,
new MovementInput());
Assert.NotNull(result.TurnCommand);
}
[Fact]
public void StrictIdleBoundaryStopsMouseDriftOnlyAfterPointTwoSeconds()
{
bool previousRetailCamera = CameraDiagnostics.UseRetailChaseCamera;
CameraDiagnostics.UseRetailChaseCamera = false;
try
{
Harness harness = CreateActiveHarness();
for (int i = 0; i < 6; i++)
{
harness.Clock.NowSeconds += 0.01f;
harness.Owner.QueueRawDelta(2f, 0f);
harness.Owner.Tick();
}
MovementResult turning = harness.Player.Update(
PhysicsBody.MinQuantum + 0.001f,
new MovementInput(Run: true));
Assert.NotNull(turning.TurnCommand);
float boundary = harness.Clock.NowSeconds
+ MouseLookState.IdleZeroDelaySeconds;
harness.Clock.NowSeconds = boundary;
harness.Owner.Tick();
MovementResult held = harness.Player.Update(
PhysicsBody.MinQuantum + 0.001f,
new MovementInput(Run: true));
Assert.NotNull(held.TurnCommand);
harness.Clock.NowSeconds = boundary + 0.0001f;
harness.Owner.Tick();
MovementResult stopped = harness.Player.Update(
PhysicsBody.MinQuantum + 0.001f,
new MovementInput(Run: true));
Assert.Null(stopped.TurnCommand);
}
finally
{
CameraDiagnostics.UseRetailChaseCamera = previousRetailCamera;
}
}
[Fact]
public void LifecycleExitAlsoClearsRmbOrbitLatch()
{
Harness harness = CreateActiveHarness();
harness.Owner.HandlePointerAction(
InputAction.AcdreamRmbOrbitHold,
ActivationType.Press);
Assert.True(harness.Chase.RmbOrbitHeld);
harness.Owner.EndForLifecycle();
Assert.False(harness.Owner.Active);
Assert.False(harness.Chase.RmbOrbitHeld);
Assert.False(harness.Player.EndMouseLook(new MovementInput()));
}
[Fact]
public void RmbOrbitLatchOnlyEngagesInPlayerChaseMode()
{
Harness harness = CreateHarness();
harness.Owner.HandlePointerAction(
InputAction.AcdreamRmbOrbitHold,
ActivationType.Press);
Assert.False(harness.Chase.RmbOrbitHeld);
harness.Mode.IsPlayerMode = true;
harness.EnterChase();
harness.Owner.HandlePointerAction(
InputAction.AcdreamRmbOrbitHold,
ActivationType.Press);
Assert.True(harness.Chase.RmbOrbitHeld);
harness.Owner.HandlePointerAction(
InputAction.AcdreamRmbOrbitHold,
ActivationType.Release);
Assert.False(harness.Chase.RmbOrbitHeld);
}
private static Harness CreateActiveHarness()
{
Harness harness = CreateHarness();
harness.Mode.IsPlayerMode = true;
harness.EnterChase();
harness.Owner.HandlePointerAction(
InputAction.CameraInstantMouseLook,
ActivationType.Press);
Assert.True(harness.Owner.Active);
return harness;
}
private static Harness CreateHarness()
{
PlayerMovementController player = CreatePlayer();
var mode = new LocalPlayerModeState();
var slot = new RuntimeLocalPlayerMovementState { Controller = player };
var camera = new CameraController(new OrbitCamera(), new FlyCamera());
var chase = new ChaseCameraInputState();
var mouse = new FakeMouse();
var pointer = new PointerPositionState { X = 320f, Y = 240f };
var movement = new FixedMovementInputSource();
var cursor = new FakeCursor();
var clock = new FakeClock();
var session = new NullSessionSource();
var outbound = new LocalPlayerOutboundController(
static (_, _, _, _, _, _) => { });
var owner = new MouseLookController(
mouse,
pointer,
mode,
slot,
camera,
chase,
movement,
outbound,
session,
cursor,
clock);
return new Harness(owner, mode, player, camera, chase, mouse, cursor, clock, session);
}
private static PlayerMovementController CreatePlayer()
{
var engine = new PhysicsEngine();
var heights = new byte[81];
Array.Fill(heights, (byte)50);
var heightTable = new float[256];
for (int i = 0; i < heightTable.Length; i++)
heightTable[i] = i;
engine.AddLandblock(
0xA9B4FFFFu,
new TerrainSurface(heights, heightTable),
Array.Empty<CellSurface>(),
Array.Empty<PortalPlane>(),
worldOffsetX: 0f,
worldOffsetY: 0f);
var controller = new PlayerMovementController(engine);
controller.SeedPlacementForTest(new Vector3(96f, 96f, 50f), 0x0001u, new Vector3(96f, 96f, 50f));
return controller;
}
private sealed record Harness(
MouseLookController Owner,
LocalPlayerModeState Mode,
PlayerMovementController Player,
CameraController Camera,
ChaseCameraInputState Chase,
FakeMouse Mouse,
FakeCursor Cursor,
FakeClock Clock,
NullSessionSource Session)
{
public void EnterChase() =>
Camera.EnterChaseMode(new ChaseCamera(), new RetailChaseCamera());
}
private sealed class FixedMovementInputSource : IMovementInputSource
{
public MovementInput Capture() => new(Run: true);
}
private sealed class FakeClock : IInputMonotonicClock
{
public float NowSeconds { get; set; }
}
private sealed class FakeCursor : IMouseLookCursor
{
public int HideCount { get; private set; }
public int RestoreCount { get; private set; }
public bool HasSavedMode { get; private set; }
public void Hide()
{
HideCount++;
HasSavedMode = true;
}
public void Restore()
{
RestoreCount++;
HasSavedMode = false;
}
}
private sealed class NullSessionSource : ILiveWorldSessionSource
{
public WorldSession? CurrentSession => null;
}
private sealed class FakeMouse : IMouseSource
{
#pragma warning disable CS0067
public event Action<MouseButton, ModifierMask>? MouseDown;
public event Action<MouseButton, ModifierMask>? MouseUp;
public event Action<float, float>? MouseMove;
public event Action<float>? Scroll;
#pragma warning restore CS0067
public bool WantCaptureMouse { get; set; }
public bool WantCaptureKeyboard { get; set; }
public bool IsHeld(MouseButton button) => false;
}
}