refactor(input): extract the gameplay frame
This commit is contained in:
parent
0bc9fda9de
commit
c557038353
24 changed files with 2433 additions and 559 deletions
|
|
@ -0,0 +1,152 @@
|
|||
using AcDream.App.Input;
|
||||
using AcDream.UI.Abstractions.Input;
|
||||
using Silk.NET.Input;
|
||||
|
||||
namespace AcDream.App.Tests.Input;
|
||||
|
||||
public sealed class DispatcherMovementInputSourceTests
|
||||
{
|
||||
[Fact]
|
||||
public void UnboundSourceCapturesNeutralInput()
|
||||
{
|
||||
var source = new DispatcherMovementInputSource();
|
||||
|
||||
Assert.Equal(default, source.Capture());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CapturesDispatcherHeldStateAndRetailWalkModifier()
|
||||
{
|
||||
var (dispatcher, _, _) = CreateDispatcher();
|
||||
var source = new DispatcherMovementInputSource();
|
||||
source.Bind(dispatcher);
|
||||
|
||||
Assert.True(dispatcher.TrySetAutomationActionHeld(
|
||||
InputAction.MovementForward,
|
||||
held: true));
|
||||
Assert.True(dispatcher.TrySetAutomationActionHeld(
|
||||
InputAction.MovementWalkMode,
|
||||
held: true));
|
||||
|
||||
MovementInput captured = source.Capture();
|
||||
|
||||
Assert.True(captured.Forward);
|
||||
Assert.False(captured.Run);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RetainedKeyboardCaptureSilencesHeldKeysButDoesNotCancelAutorun()
|
||||
{
|
||||
var (dispatcher, _, mouse) = CreateDispatcher();
|
||||
var source = new DispatcherMovementInputSource();
|
||||
source.Bind(dispatcher);
|
||||
dispatcher.TrySetAutomationActionHeld(InputAction.MovementForward, held: true);
|
||||
Assert.True(source.HandlePressedAction(InputAction.MovementRunLock));
|
||||
|
||||
mouse.WantCaptureKeyboard = true;
|
||||
MovementInput captured = source.Capture();
|
||||
|
||||
Assert.True(captured.Forward);
|
||||
Assert.True(source.AutoRunActive);
|
||||
|
||||
source.HandlePressedAction(InputAction.MovementRunLock);
|
||||
captured = source.Capture();
|
||||
Assert.False(captured.Forward);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DevToolsKeyboardCapturePausesAutorunWithoutClearingItsLatch()
|
||||
{
|
||||
var capture = new FakeCapture();
|
||||
var (dispatcher, _, _) = CreateDispatcher();
|
||||
var source = new DispatcherMovementInputSource(capture);
|
||||
source.Bind(dispatcher);
|
||||
source.HandlePressedAction(InputAction.MovementRunLock);
|
||||
|
||||
capture.DevToolsWantCaptureKeyboard = true;
|
||||
Assert.Equal(default, source.Capture());
|
||||
Assert.True(source.AutoRunActive);
|
||||
|
||||
capture.DevToolsWantCaptureKeyboard = false;
|
||||
Assert.True(source.Capture().Forward);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(InputAction.MovementBackup)]
|
||||
[InlineData(InputAction.MovementStop)]
|
||||
[InlineData(InputAction.MovementStrafeLeft)]
|
||||
[InlineData(InputAction.MovementStrafeRight)]
|
||||
public void RetailCancelActionsClearAutorun(InputAction action)
|
||||
{
|
||||
var source = new DispatcherMovementInputSource();
|
||||
source.HandlePressedAction(InputAction.MovementRunLock);
|
||||
|
||||
Assert.False(source.HandlePressedAction(action));
|
||||
|
||||
Assert.False(source.AutoRunActive);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ForwardDoesNotCancelAutorunAndResetDoes()
|
||||
{
|
||||
var source = new DispatcherMovementInputSource();
|
||||
source.HandlePressedAction(InputAction.MovementRunLock);
|
||||
|
||||
Assert.False(source.HandlePressedAction(InputAction.MovementForward));
|
||||
Assert.True(source.AutoRunActive);
|
||||
|
||||
source.ResetSession();
|
||||
Assert.False(source.AutoRunActive);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void BindingIsIdempotentOnlyForTheSameDispatcher()
|
||||
{
|
||||
var source = new DispatcherMovementInputSource();
|
||||
var (first, _, _) = CreateDispatcher();
|
||||
var (second, _, _) = CreateDispatcher();
|
||||
|
||||
source.Bind(first);
|
||||
source.Bind(first);
|
||||
|
||||
Assert.Throws<InvalidOperationException>(() => source.Bind(second));
|
||||
}
|
||||
|
||||
private static (InputDispatcher Dispatcher, FakeKeyboard Keyboard, FakeMouse Mouse)
|
||||
CreateDispatcher()
|
||||
{
|
||||
var keyboard = new FakeKeyboard();
|
||||
var mouse = new FakeMouse();
|
||||
return (new InputDispatcher(keyboard, mouse, new KeyBindings()), keyboard, mouse);
|
||||
}
|
||||
|
||||
private sealed class FakeKeyboard : IKeyboardSource
|
||||
{
|
||||
#pragma warning disable CS0067
|
||||
public event Action<Key, ModifierMask>? KeyDown;
|
||||
public event Action<Key, ModifierMask>? KeyUp;
|
||||
#pragma warning restore CS0067
|
||||
public bool IsHeld(Key key) => false;
|
||||
public ModifierMask CurrentModifiers => ModifierMask.None;
|
||||
}
|
||||
|
||||
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 WantCaptureKeyboard { get; set; }
|
||||
public bool WantCaptureMouse { get; set; }
|
||||
public bool IsHeld(MouseButton button) => false;
|
||||
}
|
||||
|
||||
private sealed class FakeCapture : IInputCaptureSource
|
||||
{
|
||||
public bool WantCaptureMouse { get; set; }
|
||||
public bool WantCaptureKeyboard { get; set; }
|
||||
public bool DevToolsWantCaptureKeyboard { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,194 @@
|
|||
using AcDream.App.Input;
|
||||
using AcDream.App.Update;
|
||||
using AcDream.UI.Abstractions.Input;
|
||||
using Silk.NET.Input;
|
||||
|
||||
namespace AcDream.App.Tests.Input;
|
||||
|
||||
public sealed class GameplayInputFrameControllerTests
|
||||
{
|
||||
[Fact]
|
||||
public void TickPreservesDispatcherMouseLookCombatOrder()
|
||||
{
|
||||
var calls = new List<string>();
|
||||
var keyboard = new HeldKeyboard(Key.W);
|
||||
var mouseSource = new NullMouse();
|
||||
var bindings = new KeyBindings();
|
||||
bindings.Add(new Binding(
|
||||
new KeyChord(Key.W, ModifierMask.None),
|
||||
InputAction.MovementForward,
|
||||
ActivationType.Hold));
|
||||
var dispatcher = new InputDispatcher(keyboard, mouseSource, bindings);
|
||||
keyboard.Press(Key.W);
|
||||
dispatcher.Fired += (_, activation) =>
|
||||
{
|
||||
if (activation == ActivationType.Hold)
|
||||
calls.Add("dispatcher");
|
||||
};
|
||||
var mouseLook = new FakeMouseLook(calls);
|
||||
var combat = new FakeCombat(calls);
|
||||
var controller = new GameplayInputFrameController(
|
||||
dispatcher,
|
||||
new DispatcherMovementInputSource(),
|
||||
mouseLook,
|
||||
combat);
|
||||
|
||||
controller.Tick(new UpdateFrameTiming(1d / 60d, 1f / 60f, 1d / 60d));
|
||||
|
||||
Assert.Equal(["dispatcher", "mouse-look", "combat"], calls);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MissingInputDevicesStillTicksCombat()
|
||||
{
|
||||
var calls = new List<string>();
|
||||
var controller = new GameplayInputFrameController(
|
||||
dispatcher: null,
|
||||
new DispatcherMovementInputSource(),
|
||||
mouseLook: null,
|
||||
new FakeCombat(calls));
|
||||
|
||||
controller.Tick(new UpdateFrameTiming(0d, 0f, 0d));
|
||||
|
||||
Assert.Equal(["combat"], calls);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CombatActionFirstAbortsAutomaticAttackThenRoutesAction()
|
||||
{
|
||||
var calls = new List<string>();
|
||||
var controller = new GameplayInputFrameController(
|
||||
dispatcher: null,
|
||||
new DispatcherMovementInputSource(),
|
||||
mouseLook: null,
|
||||
new FakeCombat(calls, consumes: true));
|
||||
|
||||
bool consumed = controller.HandleCombatAction(
|
||||
InputAction.MovementForward,
|
||||
ActivationType.Press);
|
||||
|
||||
Assert.True(consumed);
|
||||
Assert.Equal(["combat-movement", "combat-action"], calls);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResetSessionReleasesMouseLookAndAutorun()
|
||||
{
|
||||
var calls = new List<string>();
|
||||
var movement = new DispatcherMovementInputSource();
|
||||
movement.HandlePressedAction(InputAction.MovementRunLock);
|
||||
var mouseLook = new FakeMouseLook(calls);
|
||||
var controller = new GameplayInputFrameController(
|
||||
dispatcher: null,
|
||||
movement,
|
||||
mouseLook,
|
||||
new FakeCombat(calls));
|
||||
|
||||
controller.ResetSession();
|
||||
|
||||
Assert.False(movement.AutoRunActive);
|
||||
Assert.Equal(["mouse-reset"], calls);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PointerAndRawDeltaRemainOwnedByMouseLookController()
|
||||
{
|
||||
var calls = new List<string>();
|
||||
var mouseLook = new FakeMouseLook(calls, active: true, consumes: true);
|
||||
var controller = new GameplayInputFrameController(
|
||||
dispatcher: null,
|
||||
new DispatcherMovementInputSource(),
|
||||
mouseLook,
|
||||
new FakeCombat(calls));
|
||||
|
||||
Assert.True(controller.MouseLookActive);
|
||||
Assert.True(controller.HandlePointerAction(
|
||||
InputAction.CameraInstantMouseLook,
|
||||
ActivationType.Press));
|
||||
controller.QueueRawMouseDelta(3f, -2f);
|
||||
controller.EndMouseLook();
|
||||
|
||||
Assert.Equal(["mouse-action", "mouse-delta", "mouse-lifecycle-end"], calls);
|
||||
}
|
||||
|
||||
private sealed class FakeCombat : ICombatInputFrameController
|
||||
{
|
||||
private readonly List<string> _calls;
|
||||
private readonly bool _consumes;
|
||||
|
||||
public FakeCombat(List<string> calls, bool consumes = false)
|
||||
{
|
||||
_calls = calls;
|
||||
_consumes = consumes;
|
||||
}
|
||||
|
||||
public void Tick() => _calls.Add("combat");
|
||||
public void HandleMovementInput(InputAction action, ActivationType activation) =>
|
||||
_calls.Add("combat-movement");
|
||||
public bool HandleInputAction(InputAction action, ActivationType activation)
|
||||
{
|
||||
_calls.Add("combat-action");
|
||||
return _consumes;
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class FakeMouseLook : IMouseLookInputFrameController
|
||||
{
|
||||
private readonly List<string> _calls;
|
||||
private readonly bool _consumes;
|
||||
|
||||
public FakeMouseLook(
|
||||
List<string> calls,
|
||||
bool active = false,
|
||||
bool consumes = false)
|
||||
{
|
||||
_calls = calls;
|
||||
_consumes = consumes;
|
||||
Active = active;
|
||||
}
|
||||
|
||||
public bool Active { get; }
|
||||
public void Tick() => _calls.Add("mouse-look");
|
||||
public bool HandlePointerAction(InputAction action, ActivationType activation)
|
||||
{
|
||||
_calls.Add("mouse-action");
|
||||
return _consumes;
|
||||
}
|
||||
public void QueueRawDelta(float dx, float dy) => _calls.Add("mouse-delta");
|
||||
public void EndAndRestoreCursor() => _calls.Add("mouse-end");
|
||||
public void EndForLifecycle() => _calls.Add("mouse-lifecycle-end");
|
||||
public void ResetSession() => _calls.Add("mouse-reset");
|
||||
}
|
||||
|
||||
private sealed class HeldKeyboard : IKeyboardSource
|
||||
{
|
||||
private readonly HashSet<Key> _held = [];
|
||||
|
||||
public HeldKeyboard(params Key[] held)
|
||||
{
|
||||
foreach (Key key in held)
|
||||
_held.Add(key);
|
||||
}
|
||||
|
||||
public event Action<Key, ModifierMask>? KeyDown;
|
||||
#pragma warning disable CS0067
|
||||
public event Action<Key, ModifierMask>? KeyUp;
|
||||
#pragma warning restore CS0067
|
||||
public bool IsHeld(Key key) => _held.Contains(key);
|
||||
public ModifierMask CurrentModifiers => ModifierMask.None;
|
||||
public void Press(Key key) => KeyDown?.Invoke(key, ModifierMask.None);
|
||||
}
|
||||
|
||||
private sealed class NullMouse : 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 IsHeld(MouseButton button) => false;
|
||||
public bool WantCaptureMouse => false;
|
||||
public bool WantCaptureKeyboard => false;
|
||||
}
|
||||
}
|
||||
309
tests/AcDream.App.Tests/Input/MouseLookControllerTests.cs
Normal file
309
tests/AcDream.App.Tests/Input/MouseLookControllerTests.cs
Normal file
|
|
@ -0,0 +1,309 @@
|
|||
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;
|
||||
|
||||
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 LocalPlayerControllerSlot { 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.SetPosition(new Vector3(96f, 96f, 50f), 0x0001u);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
@ -18,7 +18,7 @@ public sealed class RetailLocalPlayerFrameControllerTests
|
|||
var local = new RetailLocalPlayerFrameController(
|
||||
canPresentPlayer: () => true,
|
||||
getController: () => controller,
|
||||
captureInput: () => new MovementInput(Forward: true),
|
||||
movementInput: Input(() => new MovementInput(Forward: true)),
|
||||
resolveLocalEntityId: () => 7u,
|
||||
handleTargeting: () => calls.Add("target"),
|
||||
isHidden: () => false,
|
||||
|
|
@ -82,7 +82,7 @@ public sealed class RetailLocalPlayerFrameControllerTests
|
|||
var local = new RetailLocalPlayerFrameController(
|
||||
canPresentPlayer: () => controller is not null,
|
||||
getController: () => controller,
|
||||
captureInput: () => new MovementInput(Forward: true),
|
||||
movementInput: Input(() => new MovementInput(Forward: true)),
|
||||
resolveLocalEntityId: () => 9u,
|
||||
handleTargeting: () => { },
|
||||
isHidden: () => false,
|
||||
|
|
@ -112,7 +112,7 @@ public sealed class RetailLocalPlayerFrameControllerTests
|
|||
var local = new RetailLocalPlayerFrameController(
|
||||
canPresentPlayer: () => true,
|
||||
getController: () => controller,
|
||||
captureInput: () => new MovementInput(),
|
||||
movementInput: Input(() => new MovementInput()),
|
||||
resolveLocalEntityId: () => 7u,
|
||||
handleTargeting: () => { },
|
||||
isHidden: () => false,
|
||||
|
|
@ -143,7 +143,7 @@ public sealed class RetailLocalPlayerFrameControllerTests
|
|||
var local = new RetailLocalPlayerFrameController(
|
||||
canPresentPlayer: () => true,
|
||||
getController: () => controller,
|
||||
captureInput: () => new MovementInput(Forward: true),
|
||||
movementInput: Input(() => new MovementInput(Forward: true)),
|
||||
resolveLocalEntityId: () => 7u,
|
||||
handleTargeting: () => positionSeenByTargetManager = controller.Position,
|
||||
isHidden: () => false,
|
||||
|
|
@ -169,11 +169,11 @@ public sealed class RetailLocalPlayerFrameControllerTests
|
|||
var local = new RetailLocalPlayerFrameController(
|
||||
canPresentPlayer: () => true,
|
||||
getController: () => controller,
|
||||
captureInput: () =>
|
||||
movementInput: Input(() =>
|
||||
{
|
||||
inputCaptures++;
|
||||
return new MovementInput(Forward: true);
|
||||
},
|
||||
}),
|
||||
resolveLocalEntityId: () => 7u,
|
||||
handleTargeting: () => throw new InvalidOperationException(
|
||||
"Frozen object advanced its manager tail."),
|
||||
|
|
@ -204,7 +204,7 @@ public sealed class RetailLocalPlayerFrameControllerTests
|
|||
var local = new RetailLocalPlayerFrameController(
|
||||
canPresentPlayer: () => true,
|
||||
getController: () => controller,
|
||||
captureInput: () => new MovementInput(),
|
||||
movementInput: Input(() => new MovementInput()),
|
||||
resolveLocalEntityId: () => 7u,
|
||||
handleTargeting: () => { },
|
||||
isHidden: () => true,
|
||||
|
|
@ -231,11 +231,11 @@ public sealed class RetailLocalPlayerFrameControllerTests
|
|||
var local = new RetailLocalPlayerFrameController(
|
||||
canPresentPlayer: () => true,
|
||||
getController: () => controller,
|
||||
captureInput: () =>
|
||||
movementInput: Input(() =>
|
||||
{
|
||||
inputCaptures++;
|
||||
return new MovementInput(Forward: true);
|
||||
},
|
||||
}),
|
||||
resolveLocalEntityId: () => 7u,
|
||||
handleTargeting: () => targeting++,
|
||||
isHidden: () => false,
|
||||
|
|
@ -293,4 +293,13 @@ public sealed class RetailLocalPlayerFrameControllerTests
|
|||
Assert.True(clock.IsActive);
|
||||
return controller;
|
||||
}
|
||||
|
||||
private static IMovementInputSource Input(Func<MovementInput> capture) =>
|
||||
new TestMovementInputSource(capture);
|
||||
|
||||
private sealed class TestMovementInputSource(Func<MovementInput> capture)
|
||||
: IMovementInputSource
|
||||
{
|
||||
public MovementInput Capture() => capture();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue