refactor(input): extract the gameplay frame
This commit is contained in:
parent
0bc9fda9de
commit
c557038353
24 changed files with 2433 additions and 559 deletions
209
tests/AcDream.App.Tests/Combat/CombatAttackTargetSourceTests.cs
Normal file
209
tests/AcDream.App.Tests/Combat/CombatAttackTargetSourceTests.cs
Normal file
|
|
@ -0,0 +1,209 @@
|
|||
using System.Numerics;
|
||||
using AcDream.App.Combat;
|
||||
using AcDream.App.Input;
|
||||
using AcDream.App.Rendering;
|
||||
using AcDream.App.Streaming;
|
||||
using AcDream.App.World;
|
||||
using AcDream.Core.Combat;
|
||||
using AcDream.Core.Items;
|
||||
using AcDream.Core.Net;
|
||||
using AcDream.Core.Net.Messages;
|
||||
using AcDream.Core.Physics;
|
||||
using AcDream.Core.Selection;
|
||||
using AcDream.Core.World;
|
||||
using DatReaderWriter.DBObjs;
|
||||
|
||||
namespace AcDream.App.Tests.Combat;
|
||||
|
||||
public sealed class CombatAttackTargetSourceTests
|
||||
{
|
||||
private const uint Player = 0x5000_0001u;
|
||||
|
||||
[Fact]
|
||||
public void ExplicitSelectedHostileIsAcceptedWithoutAutoTarget()
|
||||
{
|
||||
var harness = new Harness();
|
||||
const uint target = 0x7000_0001u;
|
||||
harness.Add(target, new Vector3(2f, 0f, 0f), attackable: true);
|
||||
harness.Selection.Select(target, SelectionChangeSource.Keyboard);
|
||||
|
||||
Assert.Equal(
|
||||
target,
|
||||
harness.Targets.GetSelectedOrClosestCombatTarget(autoTarget: false));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AutoTargetUsesNearestEligibleLiveHostile()
|
||||
{
|
||||
var harness = new Harness();
|
||||
const uint valid = 0x7000_0010u;
|
||||
harness.Add(valid, new Vector3(8f, 0f, 0f), attackable: true);
|
||||
harness.Add(0x7000_0011u, new Vector3(2f, 0f, 0f), attackable: false);
|
||||
WorldEntity dead = harness.Add(
|
||||
0x7000_0012u,
|
||||
new Vector3(3f, 0f, 0f),
|
||||
attackable: true);
|
||||
harness.Runtime.SetAnimationRuntime(
|
||||
dead.ServerGuid,
|
||||
new Animation(dead, MotionCommand.Dead));
|
||||
WorldEntity hidden = harness.Add(
|
||||
0x7000_0013u,
|
||||
new Vector3(4f, 0f, 0f),
|
||||
attackable: true);
|
||||
Assert.True(harness.Runtime.TryApplyState(
|
||||
new SetState.Parsed(
|
||||
hidden.ServerGuid,
|
||||
(uint)(PhysicsStateFlags.ReportCollisions | PhysicsStateFlags.Hidden),
|
||||
InstanceSequence: 1,
|
||||
StateSequence: 2),
|
||||
out _));
|
||||
WorldEntity pending = harness.Add(
|
||||
0x7000_0014u,
|
||||
new Vector3(5f, 0f, 0f),
|
||||
attackable: true);
|
||||
Assert.True(harness.Runtime.WithdrawLiveEntityProjection(pending.ServerGuid));
|
||||
|
||||
uint? selected = harness.Targets.GetSelectedOrClosestCombatTarget(
|
||||
autoTarget: true);
|
||||
|
||||
Assert.Equal(valid, selected);
|
||||
Assert.Equal(valid, harness.Selection.SelectedObjectId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MissingAutoTargetClearsAnInvalidSelection()
|
||||
{
|
||||
var harness = new Harness();
|
||||
const uint nonHostile = 0x7000_0020u;
|
||||
harness.Add(nonHostile, Vector3.UnitX, attackable: false);
|
||||
harness.Selection.Select(nonHostile, SelectionChangeSource.Keyboard);
|
||||
|
||||
Assert.Null(harness.Targets.GetSelectedOrClosestCombatTarget(autoTarget: true));
|
||||
|
||||
Assert.Null(harness.Selection.SelectedObjectId);
|
||||
}
|
||||
|
||||
private sealed class Harness
|
||||
{
|
||||
public ClientObjectTable Objects { get; } = new();
|
||||
public SelectionState Selection { get; } = new();
|
||||
public LiveEntityRuntime Runtime { get; }
|
||||
public CombatAttackTargetSource Targets { get; }
|
||||
|
||||
public Harness()
|
||||
{
|
||||
var spatial = new GpuWorldState();
|
||||
spatial.AddLandblock(new LoadedLandblock(
|
||||
0x0101_FFFFu,
|
||||
new LandBlock(),
|
||||
Array.Empty<WorldEntity>()));
|
||||
Runtime = new LiveEntityRuntime(spatial, new Resources());
|
||||
var identity = new LocalPlayerIdentityState { ServerGuid = Player };
|
||||
Targets = new CombatAttackTargetSource(
|
||||
Selection,
|
||||
Runtime,
|
||||
Objects,
|
||||
identity);
|
||||
Add(Player, Vector3.Zero, attackable: false, isPlayer: true);
|
||||
}
|
||||
|
||||
public WorldEntity Add(
|
||||
uint guid,
|
||||
Vector3 position,
|
||||
bool attackable,
|
||||
bool isPlayer = false)
|
||||
{
|
||||
Runtime.RegisterLiveEntity(Spawn(guid));
|
||||
WorldEntity entity = Runtime.MaterializeLiveEntity(
|
||||
guid,
|
||||
0x0101_0001u,
|
||||
id => new WorldEntity
|
||||
{
|
||||
Id = id,
|
||||
ServerGuid = guid,
|
||||
SourceGfxObjOrSetupId = 0x0200_0001u,
|
||||
Position = position,
|
||||
Rotation = Quaternion.Identity,
|
||||
Scale = 1f,
|
||||
MeshRefs = [],
|
||||
})!;
|
||||
uint flags = attackable ? SelectedObjectHealthPolicy.BfAttackable : 0u;
|
||||
if (isPlayer)
|
||||
flags |= SelectedObjectHealthPolicy.BfPlayer;
|
||||
Objects.AddOrUpdate(new ClientObject
|
||||
{
|
||||
ObjectId = guid,
|
||||
Name = $"Object {guid:X8}",
|
||||
Type = ItemType.Creature,
|
||||
PublicWeenieBitfield = flags,
|
||||
});
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
|
||||
private sealed record Animation(WorldEntity Entity, uint CurrentMotion)
|
||||
: ILiveEntityAnimationRuntime;
|
||||
|
||||
private sealed class Resources : ILiveEntityResourceLifecycle
|
||||
{
|
||||
public void Register(WorldEntity entity)
|
||||
{
|
||||
}
|
||||
public void Unregister(WorldEntity entity)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
private static WorldSession.EntitySpawn Spawn(uint guid)
|
||||
{
|
||||
var position = new CreateObject.ServerPosition(
|
||||
0x0101_0001u,
|
||||
10f,
|
||||
10f,
|
||||
5f,
|
||||
1f,
|
||||
0f,
|
||||
0f,
|
||||
0f);
|
||||
var physics = new PhysicsSpawnData(
|
||||
RawState: (uint)PhysicsStateFlags.ReportCollisions,
|
||||
Position: position,
|
||||
Movement: null,
|
||||
AnimationFrame: null,
|
||||
SetupTableId: 0x0200_0001u,
|
||||
MotionTableId: 0x0900_0001u,
|
||||
SoundTableId: null,
|
||||
PhysicsScriptTableId: null,
|
||||
Parent: null,
|
||||
Children: null,
|
||||
Scale: null,
|
||||
Friction: null,
|
||||
Elasticity: null,
|
||||
Translucency: null,
|
||||
Velocity: null,
|
||||
Acceleration: null,
|
||||
AngularVelocity: null,
|
||||
DefaultScriptType: null,
|
||||
DefaultScriptIntensity: null,
|
||||
Timestamps: new PhysicsTimestamps(1, 1, 1, 1, 0, 1, 0, 1, 1));
|
||||
return new WorldSession.EntitySpawn(
|
||||
guid,
|
||||
position,
|
||||
0x0200_0001u,
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
null,
|
||||
null,
|
||||
"fixture",
|
||||
null,
|
||||
null,
|
||||
0x0900_0001u,
|
||||
PhysicsState: (uint)PhysicsStateFlags.ReportCollisions,
|
||||
InstanceSequence: 1,
|
||||
MovementSequence: 1,
|
||||
ServerControlSequence: 1,
|
||||
PositionSequence: 1,
|
||||
Physics: physics);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,151 @@
|
|||
using AcDream.App.Combat;
|
||||
using AcDream.App.Input;
|
||||
using AcDream.App.Net;
|
||||
using AcDream.Core.Combat;
|
||||
using AcDream.Core.Net;
|
||||
|
||||
namespace AcDream.App.Tests.Combat;
|
||||
|
||||
public sealed class LiveCombatAttackOperationsTests
|
||||
{
|
||||
[Fact]
|
||||
public void UnboundSlotFailsClosedAndRejectsASecondOwner()
|
||||
{
|
||||
var slot = new CombatAttackOperationsSlot();
|
||||
var first = new FakeOperations();
|
||||
var second = new FakeOperations();
|
||||
|
||||
Assert.False(slot.CanStartAttack());
|
||||
Assert.False(slot.SendAttack(AttackHeight.Medium, 0.5f));
|
||||
Assert.False(slot.PlayerReadyForAttack);
|
||||
|
||||
slot.Bind(first);
|
||||
slot.Bind(first);
|
||||
Assert.Throws<InvalidOperationException>(() => slot.Bind(second));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CanStartRequiresLiveWorldBeforeTargetResolution()
|
||||
{
|
||||
Harness harness = CreateHarness();
|
||||
harness.Targets.Acquired = 0x1234u;
|
||||
|
||||
Assert.False(harness.Owner.CanStartAttack());
|
||||
|
||||
Assert.Equal(0, harness.Targets.ResolveCount);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UnsupportedCombatModeUsesTypedFeedbackSink()
|
||||
{
|
||||
Harness harness = CreateHarness(inWorld: true);
|
||||
|
||||
Assert.False(harness.Owner.CanStartAttack());
|
||||
|
||||
Assert.Equal(["Enter melee or missile combat first"], harness.Feedback.Messages);
|
||||
Assert.Equal(0, harness.Targets.ResolveCount);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SupportedModeResolvesTargetUsingLiveAutoTargetSetting()
|
||||
{
|
||||
Harness harness = CreateHarness(inWorld: true);
|
||||
harness.Combat.SetCombatMode(CombatMode.Melee);
|
||||
harness.Settings.AutoTarget = true;
|
||||
harness.Targets.Acquired = 0x1234u;
|
||||
harness.Targets.SelectedObjectId = 0x1234u;
|
||||
|
||||
Assert.True(harness.Owner.CanStartAttack());
|
||||
|
||||
Assert.True(harness.Targets.LastAutoTarget);
|
||||
Assert.Equal(1, harness.Targets.ResolveCount);
|
||||
Assert.Empty(harness.Feedback.Messages);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MissingTargetPreservesRetailUserFeedback()
|
||||
{
|
||||
Harness harness = CreateHarness(inWorld: true);
|
||||
harness.Combat.SetCombatMode(CombatMode.Missile);
|
||||
|
||||
Assert.False(harness.Owner.CanStartAttack());
|
||||
|
||||
Assert.Equal(["No monster target"], harness.Feedback.Messages);
|
||||
}
|
||||
|
||||
private static Harness CreateHarness(bool inWorld = false)
|
||||
{
|
||||
var combat = new CombatState();
|
||||
var targets = new FakeTargets();
|
||||
var settings = new FakeSettings();
|
||||
var player = new LocalPlayerControllerSlot();
|
||||
var live = new FakeLiveSource { IsInWorld = inWorld };
|
||||
var feedback = new FakeFeedback();
|
||||
var outbound = new LocalPlayerOutboundController(
|
||||
static (_, _, _, _, _, _) => { });
|
||||
var owner = new LiveCombatAttackOperations(
|
||||
combat,
|
||||
targets,
|
||||
settings,
|
||||
player,
|
||||
outbound,
|
||||
live,
|
||||
live,
|
||||
feedback);
|
||||
return new Harness(owner, combat, targets, settings, feedback);
|
||||
}
|
||||
|
||||
private sealed record Harness(
|
||||
LiveCombatAttackOperations Owner,
|
||||
CombatState Combat,
|
||||
FakeTargets Targets,
|
||||
FakeSettings Settings,
|
||||
FakeFeedback Feedback);
|
||||
|
||||
private sealed class FakeTargets : ICombatAttackTargetSource
|
||||
{
|
||||
public uint? SelectedObjectId { get; set; }
|
||||
public uint? Acquired { get; set; }
|
||||
public int ResolveCount { get; private set; }
|
||||
public bool LastAutoTarget { get; private set; }
|
||||
public uint? GetSelectedOrClosestCombatTarget(bool autoTarget)
|
||||
{
|
||||
ResolveCount++;
|
||||
LastAutoTarget = autoTarget;
|
||||
return Acquired;
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class FakeSettings : ICombatGameplaySettingsSource
|
||||
{
|
||||
public bool AutoTarget { get; set; }
|
||||
public bool AutoRepeatAttack { get; set; }
|
||||
}
|
||||
|
||||
private sealed class FakeLiveSource : ILiveInWorldSource, ILiveWorldSessionSource
|
||||
{
|
||||
public bool IsInWorld { get; set; }
|
||||
public WorldSession? CurrentSession => null;
|
||||
}
|
||||
|
||||
private sealed class FakeFeedback : ICombatFeedbackSink
|
||||
{
|
||||
public List<string> Messages { get; } = [];
|
||||
public void Show(string message) => Messages.Add(message);
|
||||
}
|
||||
|
||||
private sealed class FakeOperations : ICombatAttackOperations
|
||||
{
|
||||
public bool CanStartAttack() => true;
|
||||
public void PrepareAttackRequest()
|
||||
{
|
||||
}
|
||||
public bool SendAttack(AttackHeight height, float power) => true;
|
||||
public void SendCancelAttack()
|
||||
{
|
||||
}
|
||||
public bool IsDualWield => true;
|
||||
public bool PlayerReadyForAttack => true;
|
||||
public bool AutoRepeatAttack => true;
|
||||
}
|
||||
}
|
||||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -230,12 +230,15 @@ public sealed class UpdateFrameOrchestratorTests
|
|||
Assert.DoesNotContain(ownerFields, field => field.FieldType == typeof(GameWindow));
|
||||
if (owner == typeof(AcDream.App.Input.RetailLocalPlayerFrameController))
|
||||
{
|
||||
// Checkpoint B deliberately leaves this single legacy callback
|
||||
// composition for D/F, which own input capture and the mutable
|
||||
// player-mode/controller slot. No other phase owner may add one.
|
||||
// Checkpoint D replaced input capture with its typed owner.
|
||||
// Checkpoint F still owns the remaining player presentation
|
||||
// callback composition. No other phase owner may add one.
|
||||
Assert.Contains(
|
||||
ownerFields,
|
||||
field => typeof(Delegate).IsAssignableFrom(field.FieldType));
|
||||
Assert.DoesNotContain(
|
||||
ownerFields,
|
||||
field => field.FieldType == typeof(Func<AcDream.App.Input.MovementInput>));
|
||||
continue;
|
||||
}
|
||||
Assert.DoesNotContain(
|
||||
|
|
@ -364,7 +367,7 @@ public sealed class UpdateFrameOrchestratorTests
|
|||
AssertAppearsInOrder(
|
||||
source,
|
||||
"_streamingFrame.Tick();",
|
||||
"_inputDispatcher?.Tick();",
|
||||
"_gameplayInputFrame!.Tick(frameTiming);",
|
||||
"_liveFrameCoordinator.Tick(frameDelta);");
|
||||
Assert.DoesNotContain("_streamingController.Tick(observerCx", source,
|
||||
StringComparison.Ordinal);
|
||||
|
|
@ -373,6 +376,152 @@ public sealed class UpdateFrameOrchestratorTests
|
|||
Assert.DoesNotContain("DrainRescued()", source, StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GameWindow_DelegatesTheCompleteGameplayInputFrameBody()
|
||||
{
|
||||
string source = File.ReadAllText(Path.Combine(
|
||||
FindRepoRoot(),
|
||||
"src",
|
||||
"AcDream.App",
|
||||
"Rendering",
|
||||
"GameWindow.cs"));
|
||||
|
||||
Assert.Contains("new AcDream.App.Input.GameplayInputFrameController(", source);
|
||||
Assert.Equal(1, CountOccurrences(source, "_gameplayInputFrame!.Tick(frameTiming);"));
|
||||
Assert.DoesNotContain("_inputDispatcher?.Tick()", source,
|
||||
StringComparison.Ordinal);
|
||||
Assert.DoesNotContain("TryTakeRawSample", source,
|
||||
StringComparison.Ordinal);
|
||||
Assert.DoesNotContain("_combatAttackController?.Tick()", source,
|
||||
StringComparison.Ordinal);
|
||||
Assert.DoesNotContain("CaptureMovementInput", source,
|
||||
StringComparison.Ordinal);
|
||||
Assert.DoesNotContain("EndMouseLookAndRestoreCursor", source,
|
||||
StringComparison.Ordinal);
|
||||
Assert.DoesNotContain("HideCursorForMouseLook", source,
|
||||
StringComparison.Ordinal);
|
||||
Assert.DoesNotContain("RestoreCursorAfterMouseLook", source,
|
||||
StringComparison.Ordinal);
|
||||
Assert.DoesNotContain("CanStartLiveCombatAttack", source,
|
||||
StringComparison.Ordinal);
|
||||
Assert.DoesNotContain("SendLiveCombatAttack", source,
|
||||
StringComparison.Ordinal);
|
||||
Assert.DoesNotContain("PreparePlayerForAttackRequest", source,
|
||||
StringComparison.Ordinal);
|
||||
Assert.DoesNotContain("DumpMovementTruthOutbound", source,
|
||||
StringComparison.Ordinal);
|
||||
Assert.DoesNotContain("DumpMovementTruthServerEcho", source,
|
||||
StringComparison.Ordinal);
|
||||
Assert.DoesNotContain("wantCaptureMouse: ()", source,
|
||||
StringComparison.Ordinal);
|
||||
Assert.Equal(5, CountOccurrences(
|
||||
source,
|
||||
"_gameplayInputFrame?.EndMouseLook();"));
|
||||
Assert.Contains(
|
||||
"new(\"mouse capture\", () => _gameplayInputFrame?.EndMouseLook())",
|
||||
source,
|
||||
StringComparison.Ordinal);
|
||||
AssertAppearsInOrder(
|
||||
source,
|
||||
"_teleportTransit.CanBegin(teleportSequence)",
|
||||
"_gameplayInputFrame?.EndMouseLook();",
|
||||
"_teleportTransit.QueueStart(teleportSequence)");
|
||||
AssertAppearsInOrder(
|
||||
source,
|
||||
"private void OnFocusChanged(bool focused)",
|
||||
"if (!focused)",
|
||||
"_gameplayInputFrame?.EndMouseLook();");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GameplayInputOwnersUseTypedSeamsWithoutGameWindowBackReferences()
|
||||
{
|
||||
Type[] owners =
|
||||
[
|
||||
typeof(AcDream.App.Input.GameplayInputFrameController),
|
||||
typeof(AcDream.App.Input.DispatcherMovementInputSource),
|
||||
typeof(AcDream.App.Input.MouseLookController),
|
||||
];
|
||||
|
||||
foreach (Type owner in owners)
|
||||
{
|
||||
FieldInfo[] fields = owner.GetFields(
|
||||
BindingFlags.Instance | BindingFlags.NonPublic);
|
||||
Assert.DoesNotContain(fields, field => field.FieldType == typeof(GameWindow));
|
||||
Assert.DoesNotContain(
|
||||
fields,
|
||||
field => typeof(Delegate).IsAssignableFrom(field.FieldType));
|
||||
}
|
||||
|
||||
Assert.DoesNotContain(
|
||||
typeof(AcDream.App.Input.MouseLookController).GetFields(
|
||||
BindingFlags.Instance | BindingFlags.NonPublic),
|
||||
field => field.FieldType == typeof(Silk.NET.Input.IMouse));
|
||||
|
||||
FieldInfo combatOperations = Assert.Single(
|
||||
typeof(AcDream.App.Combat.CombatAttackController).GetFields(
|
||||
BindingFlags.Instance | BindingFlags.NonPublic),
|
||||
field => field.Name == "_operations");
|
||||
Assert.Equal(
|
||||
typeof(AcDream.App.Combat.ICombatAttackOperations),
|
||||
combatOperations.FieldType);
|
||||
Assert.DoesNotContain(
|
||||
typeof(AcDream.App.Combat.LiveCombatAttackOperations).GetFields(
|
||||
BindingFlags.Instance | BindingFlags.NonPublic),
|
||||
field => typeof(Delegate).IsAssignableFrom(field.FieldType));
|
||||
FieldInfo combatTargets = Assert.Single(
|
||||
typeof(AcDream.App.Combat.LiveCombatAttackOperations).GetFields(
|
||||
BindingFlags.Instance | BindingFlags.NonPublic),
|
||||
field => field.Name == "_targets");
|
||||
Assert.Equal(
|
||||
typeof(AcDream.App.Combat.ICombatAttackTargetSource),
|
||||
combatTargets.FieldType);
|
||||
Assert.DoesNotContain(
|
||||
typeof(AcDream.App.Combat.CombatAttackTargetSource).GetFields(
|
||||
BindingFlags.Instance | BindingFlags.NonPublic),
|
||||
field => typeof(Delegate).IsAssignableFrom(field.FieldType));
|
||||
Assert.DoesNotContain(
|
||||
typeof(AcDream.App.Combat.CombatAttackTargetSource).GetFields(
|
||||
BindingFlags.Instance | BindingFlags.NonPublic),
|
||||
field => field.FieldType
|
||||
== typeof(AcDream.App.Interaction.SelectionInteractionController));
|
||||
|
||||
FieldInfo outboundDiagnostics = Assert.Single(
|
||||
typeof(AcDream.App.Input.LocalPlayerOutboundController).GetFields(
|
||||
BindingFlags.Instance | BindingFlags.NonPublic),
|
||||
field => field.Name == "_diagnostic");
|
||||
Assert.Equal(
|
||||
typeof(AcDream.App.Input.IMovementTruthDiagnosticSink),
|
||||
outboundDiagnostics.FieldType);
|
||||
Assert.DoesNotContain(
|
||||
typeof(AcDream.App.Input.MovementTruthDiagnosticController).GetFields(
|
||||
BindingFlags.Instance | BindingFlags.NonPublic),
|
||||
field => typeof(Delegate).IsAssignableFrom(field.FieldType));
|
||||
|
||||
string mouseLookSource = File.ReadAllText(Path.Combine(
|
||||
FindRepoRoot(),
|
||||
"src",
|
||||
"AcDream.App",
|
||||
"Input",
|
||||
"MouseLookController.cs"));
|
||||
AssertAppearsInOrder(
|
||||
mouseLookSource,
|
||||
"controller?.StopMouseDrift",
|
||||
"retail.FilterMouseDelta",
|
||||
"_state.ApplyDelta");
|
||||
|
||||
string localPlayerSource = File.ReadAllText(Path.Combine(
|
||||
FindRepoRoot(),
|
||||
"src",
|
||||
"AcDream.App",
|
||||
"Input",
|
||||
"RetailLocalPlayerFrameController.cs"));
|
||||
Assert.DoesNotContain("Func<MovementInput>", localPlayerSource,
|
||||
StringComparison.Ordinal);
|
||||
Assert.Contains("IMovementInputSource", localPlayerSource,
|
||||
StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
private static UpdateFrameOrchestrator Create(
|
||||
List<string> calls,
|
||||
RecordingTeardown? teardown = null,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue