refactor(runtime): own local movement and outbound cadence
Move the canonical local movement controller, body/motion managers, object clock, movement wire data, and MTS/jump/AP sender into AcDream.Runtime. Replace process skill defaults with typed Runtime character options, make graphical and direct commands borrow one autorun owner, retain the construction-time PartArray seam, and include movement in terminal ownership convergence. Preserve the accepted pre-inbound movement/jump and post-inbound autonomous-position order while moving the exact packet/cadence fixtures into Runtime tests. Add graphical/direct parity, two-instance isolation, teardown, allocation, architecture, and divergence-path coverage. Co-authored-by: Codex <noreply@openai.com>
This commit is contained in:
parent
3456dff038
commit
aa3f4a60f8
36 changed files with 878 additions and 276 deletions
|
|
@ -8,18 +8,25 @@ internal interface IMovementInputSource
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Owns held movement sampling and the retail autorun latch. The input
|
||||
/// dispatcher remains the only keyboard/mouse-button state source.
|
||||
/// Samples held graphical input and maps press edges onto the Runtime-owned
|
||||
/// retail autorun latch. The dispatcher remains the only physical
|
||||
/// keyboard/mouse-button state source.
|
||||
/// </summary>
|
||||
internal sealed class DispatcherMovementInputSource : IMovementInputSource
|
||||
{
|
||||
private readonly RuntimeLocalPlayerMovementState _movement;
|
||||
private readonly IInputCaptureSource? _capture;
|
||||
private InputDispatcher? _dispatcher;
|
||||
|
||||
public DispatcherMovementInputSource(IInputCaptureSource? capture = null) =>
|
||||
public DispatcherMovementInputSource(
|
||||
RuntimeLocalPlayerMovementState movement,
|
||||
IInputCaptureSource? capture = null)
|
||||
{
|
||||
_movement = movement ?? throw new ArgumentNullException(nameof(movement));
|
||||
_capture = capture;
|
||||
}
|
||||
|
||||
public bool AutoRunActive { get; private set; }
|
||||
public bool AutoRunActive => _movement.AutoRunActive;
|
||||
public bool IsAvailable => _dispatcher is not null;
|
||||
|
||||
public void Bind(InputDispatcher dispatcher)
|
||||
|
|
@ -70,10 +77,8 @@ internal sealed class DispatcherMovementInputSource : IMovementInputSource
|
|||
public bool HandlePressedAction(InputAction action)
|
||||
{
|
||||
if (action == InputAction.MovementRunLock)
|
||||
{
|
||||
AutoRunActive = !AutoRunActive;
|
||||
return true;
|
||||
}
|
||||
return _movement.Execute(
|
||||
AcDream.Runtime.RuntimeMovementCommand.ToggleRunLock);
|
||||
|
||||
if (AutoRunActive && action is (
|
||||
InputAction.MovementBackup
|
||||
|
|
@ -81,11 +86,11 @@ internal sealed class DispatcherMovementInputSource : IMovementInputSource
|
|||
or InputAction.MovementStrafeLeft
|
||||
or InputAction.MovementStrafeRight))
|
||||
{
|
||||
AutoRunActive = false;
|
||||
_movement.CancelAutoRun();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void ResetSession() => AutoRunActive = false;
|
||||
public void ResetSession() => _movement.ResetInputIntent();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,252 +0,0 @@
|
|||
using System.Numerics;
|
||||
using AcDream.Core.Net;
|
||||
using AcDream.Core.Net.Messages;
|
||||
using AcDream.Core.Physics;
|
||||
|
||||
namespace AcDream.App.Input;
|
||||
|
||||
/// <summary>
|
||||
/// Serializes input-originated output from the object-phase result and the
|
||||
/// periodic position report from post-inbound controller state.
|
||||
/// </summary>
|
||||
public sealed class LocalPlayerOutboundController
|
||||
{
|
||||
private readonly IMovementTruthDiagnosticSink _diagnostic;
|
||||
|
||||
internal LocalPlayerOutboundController(IMovementTruthDiagnosticSink diagnostic)
|
||||
{
|
||||
_diagnostic = diagnostic
|
||||
?? throw new ArgumentNullException(nameof(diagnostic));
|
||||
}
|
||||
|
||||
public LocalPlayerOutboundController(
|
||||
Action<string, uint, MovementResult, Vector3, uint, byte> diagnostic)
|
||||
{
|
||||
_diagnostic = new DelegateMovementTruthDiagnosticSink(diagnostic);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends input-originated movement and jump packets before inbound
|
||||
/// dispatch. Retail emits these from input/object processing rather than
|
||||
/// from <c>CommandInterpreter::UseTime</c>.
|
||||
/// </summary>
|
||||
public void SendPreNetworkActions(
|
||||
WorldSession? session,
|
||||
PlayerMovementController controller,
|
||||
MovementResult movement,
|
||||
bool hidden)
|
||||
{
|
||||
if (session is null || hidden)
|
||||
return;
|
||||
|
||||
if (!controller.TryGetOutboundPosition(out Position outboundPosition))
|
||||
{
|
||||
return;
|
||||
}
|
||||
uint wireCellId = outboundPosition.ObjCellId;
|
||||
Vector3 wirePosition = outboundPosition.Frame.Origin;
|
||||
Quaternion wireRotation = outboundPosition.Frame.Orientation;
|
||||
|
||||
if (movement.ShouldSendMovementEvent)
|
||||
TrySendMovement(session, controller, movement);
|
||||
|
||||
if (movement.JumpExtent.HasValue && movement.JumpVelocity.HasValue)
|
||||
{
|
||||
uint sequence = session.NextGameActionSequence();
|
||||
byte[] body = JumpAction.Build(
|
||||
gameActionSequence: sequence,
|
||||
extent: movement.JumpExtent.Value,
|
||||
velocity: movement.JumpVelocity.Value,
|
||||
cellId: wireCellId,
|
||||
position: wirePosition,
|
||||
rotation: wireRotation,
|
||||
instanceSequence: session.InstanceSequence,
|
||||
serverControlSequence: session.ServerControlSequence,
|
||||
teleportSequence: session.TeleportSequence,
|
||||
forcePositionSequence: session.ForcePositionSequence);
|
||||
session.SendGameAction(body);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ports the position-send slot in <c>CommandInterpreter::UseTime</c>
|
||||
/// (<c>0x006B3BF0</c>), which SmartBox calls after draining inbound
|
||||
/// events. The predicate and serialized frame therefore observe any
|
||||
/// accepted ForcePosition or teleport state from this update.
|
||||
/// </summary>
|
||||
public void SendPostNetworkPosition(
|
||||
WorldSession? session,
|
||||
PlayerMovementController controller,
|
||||
bool hidden)
|
||||
{
|
||||
if (session is null || hidden)
|
||||
return;
|
||||
|
||||
if (!controller.TryGetOutboundPosition(out Position position))
|
||||
{
|
||||
return;
|
||||
}
|
||||
uint wireCellId = position.ObjCellId;
|
||||
Vector3 wirePosition = position.Frame.Origin;
|
||||
Quaternion wireRotation = position.Frame.Orientation;
|
||||
|
||||
if (!controller.ShouldSendPositionEvent(
|
||||
position,
|
||||
controller.ContactPlane,
|
||||
controller.SimTimeSeconds)
|
||||
|| !controller.CanSendPositionEvent)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
MovementResult movement = controller.CapturePresentationResult();
|
||||
byte contactByte = movement.IsOnGround ? (byte)1 : (byte)0;
|
||||
uint sequence = session.NextGameActionSequence();
|
||||
byte[] body = AutonomousPosition.Build(
|
||||
gameActionSequence: sequence,
|
||||
cellId: wireCellId,
|
||||
position: wirePosition,
|
||||
rotation: wireRotation,
|
||||
instanceSequence: session.InstanceSequence,
|
||||
serverControlSequence: session.ServerControlSequence,
|
||||
teleportSequence: session.TeleportSequence,
|
||||
forcePositionSequence: session.ForcePositionSequence,
|
||||
lastContact: contactByte);
|
||||
_diagnostic.OnOutbound(
|
||||
"AP",
|
||||
sequence,
|
||||
movement,
|
||||
wirePosition,
|
||||
wireCellId,
|
||||
contactByte);
|
||||
session.SendGameAction(body);
|
||||
controller.NotePositionSent(
|
||||
position,
|
||||
controller.ContactPlane,
|
||||
controller.SimTimeSeconds);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retail ForcePosition acknowledgement sent immediately after the local
|
||||
/// body is blipped. Unlike the periodic post-network sender, this bypasses
|
||||
/// the elapsed/difference predicate but still requires a valid grounded
|
||||
/// canonical frame.
|
||||
/// </summary>
|
||||
internal void SendImmediatePosition(
|
||||
WorldSession? session,
|
||||
PlayerMovementController? controller)
|
||||
{
|
||||
if (session is null
|
||||
|| controller is null
|
||||
|| !controller.CanSendPositionEvent)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!controller.TryGetOutboundPosition(out Position outboundPosition))
|
||||
return;
|
||||
uint cellId = outboundPosition.ObjCellId;
|
||||
Vector3 position = outboundPosition.Frame.Origin;
|
||||
Quaternion rotation = outboundPosition.Frame.Orientation;
|
||||
|
||||
uint sequence = session.NextGameActionSequence();
|
||||
byte[] body = AutonomousPosition.Build(
|
||||
gameActionSequence: sequence,
|
||||
cellId: cellId,
|
||||
position: position,
|
||||
rotation: rotation,
|
||||
instanceSequence: session.InstanceSequence,
|
||||
serverControlSequence: session.ServerControlSequence,
|
||||
teleportSequence: session.TeleportSequence,
|
||||
forcePositionSequence: session.ForcePositionSequence,
|
||||
lastContact: 1);
|
||||
session.SendGameAction(body);
|
||||
controller.NotePositionSent(
|
||||
outboundPosition,
|
||||
controller.ContactPlane,
|
||||
controller.SimTimeSeconds);
|
||||
}
|
||||
|
||||
public bool TrySendMovement(
|
||||
WorldSession? session,
|
||||
PlayerMovementController? controller,
|
||||
MovementResult movement)
|
||||
{
|
||||
if (session is null || controller is null)
|
||||
return false;
|
||||
|
||||
if (!controller.TryGetOutboundPosition(out Position outboundPosition))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
uint wireCellId = outboundPosition.ObjCellId;
|
||||
Vector3 wirePosition = outboundPosition.Frame.Origin;
|
||||
Quaternion wireRotation = outboundPosition.Frame.Orientation;
|
||||
|
||||
byte contactByte = movement.IsOnGround ? (byte)1 : (byte)0;
|
||||
RawMotionState rawMotionState = BuildRawMotionState(movement);
|
||||
uint sequence = session.NextGameActionSequence();
|
||||
byte[] body = MoveToState.Build(
|
||||
gameActionSequence: sequence,
|
||||
rawMotionState: rawMotionState,
|
||||
cellId: wireCellId,
|
||||
position: wirePosition,
|
||||
rotation: wireRotation,
|
||||
instanceSequence: session.InstanceSequence,
|
||||
serverControlSequence: session.ServerControlSequence,
|
||||
teleportSequence: session.TeleportSequence,
|
||||
forcePositionSequence: session.ForcePositionSequence,
|
||||
contact: contactByte != 0,
|
||||
standingLongjump: false);
|
||||
_diagnostic.OnOutbound(
|
||||
"MTS",
|
||||
sequence,
|
||||
movement,
|
||||
wirePosition,
|
||||
wireCellId,
|
||||
contactByte);
|
||||
session.SendGameAction(body);
|
||||
controller.NoteMovementSent(
|
||||
controller.SimTimeSeconds,
|
||||
movement.IsMouseLookMovementEvent);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static RawMotionState BuildRawMotionState(MovementResult movement)
|
||||
{
|
||||
HoldKey axisHoldKey = movement.IsRunning ? HoldKey.Run : HoldKey.None;
|
||||
return new RawMotionState
|
||||
{
|
||||
CurrentHoldKey = axisHoldKey,
|
||||
// CommandInterpreter::SendMovementEvent @ 0x006B4680 passes
|
||||
// CPhysicsObj::InqRawMotionState directly to MoveToStatePack.
|
||||
// RawMotionState::UnPack @ 0x0051EFC0 treats an absent style as
|
||||
// NonCombat, so this is state—not optional observer decoration.
|
||||
CurrentStyle = movement.CurrentStyle,
|
||||
ForwardCommand = movement.ForwardCommand
|
||||
?? RawMotionState.Default.ForwardCommand,
|
||||
ForwardHoldKey = movement.ForwardCommand.HasValue
|
||||
? axisHoldKey : HoldKey.Invalid,
|
||||
ForwardSpeed = movement.ForwardSpeed
|
||||
?? RawMotionState.Default.ForwardSpeed,
|
||||
SidestepCommand = movement.SidestepCommand
|
||||
?? RawMotionState.Default.SidestepCommand,
|
||||
SidestepHoldKey = movement.SidestepCommand.HasValue
|
||||
? movement.SidestepUsesRunHold
|
||||
? HoldKey.Run
|
||||
: axisHoldKey
|
||||
: HoldKey.Invalid,
|
||||
SidestepSpeed = movement.SidestepSpeed
|
||||
?? RawMotionState.Default.SidestepSpeed,
|
||||
TurnCommand = movement.TurnCommand
|
||||
?? RawMotionState.Default.TurnCommand,
|
||||
TurnHoldKey = movement.TurnCommand.HasValue
|
||||
? movement.TurnUsesRunHold
|
||||
? HoldKey.Run
|
||||
: axisHoldKey
|
||||
: HoldKey.Invalid,
|
||||
TurnSpeed = movement.TurnSpeed
|
||||
?? RawMotionState.Default.TurnSpeed,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -16,89 +16,6 @@ internal sealed class LocalPlayerIdentityState : ILocalPlayerIdentitySource
|
|||
public uint ServerGuid { get; set; }
|
||||
}
|
||||
|
||||
internal interface ILocalPlayerControllerSource
|
||||
{
|
||||
PlayerMovementController? Controller { get; }
|
||||
}
|
||||
|
||||
internal interface ILocalPlayerMotionSource
|
||||
{
|
||||
MotionInterpreter? Motion { get; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The one mutable local movement-controller slot. Player-mode lifecycle owns
|
||||
/// assignment; update and presentation owners receive the read-only seam.
|
||||
/// </summary>
|
||||
internal sealed class LocalPlayerControllerSlot
|
||||
: ILocalPlayerControllerSource,
|
||||
ILocalPlayerMotionSource
|
||||
{
|
||||
private PlayerMovementController? _preparingMotionOwner;
|
||||
|
||||
public PlayerMovementController? Controller { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The motion owner visible to the local PartArray completion relay.
|
||||
/// During player-mode construction this is the fully animation-bound
|
||||
/// candidate controller; all other consumers continue to see only the
|
||||
/// committed <see cref="Controller"/>.
|
||||
/// </summary>
|
||||
MotionInterpreter? ILocalPlayerMotionSource.Motion =>
|
||||
_preparingMotionOwner?.Motion ?? Controller?.Motion;
|
||||
|
||||
/// <summary>
|
||||
/// Opens the narrow construction-time ownership seam required by retail's
|
||||
/// CPhysicsObj/PartArray lifetime. Initial placement synchronously queues
|
||||
/// and completes StopCompletely, so its MotionDone relay must reach the
|
||||
/// candidate interpreter before the complete controller is published.
|
||||
/// </summary>
|
||||
public IDisposable BeginMotionPreparation(
|
||||
PlayerMovementController controller,
|
||||
Action? drainPriorAnimationQueue = null)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(controller);
|
||||
if (_preparingMotionOwner is not null)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"A local player motion owner is already being prepared.");
|
||||
}
|
||||
|
||||
// The live PartArray exists before the local player controller. Drain
|
||||
// any animation completions produced under that prior ownership while
|
||||
// they still resolve to the prior (or null) interpreter. Publishing
|
||||
// the fresh interpreter first would let those old callbacks pop its
|
||||
// new pending_motions queue and leave an unmatched Ready sentinel.
|
||||
drainPriorAnimationQueue?.Invoke();
|
||||
_preparingMotionOwner = controller;
|
||||
return new MotionPreparation(this, controller);
|
||||
}
|
||||
|
||||
private void EndMotionPreparation(PlayerMovementController controller)
|
||||
{
|
||||
if (!ReferenceEquals(_preparingMotionOwner, controller))
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"The local player motion preparation owner changed unexpectedly.");
|
||||
}
|
||||
|
||||
_preparingMotionOwner = null;
|
||||
}
|
||||
|
||||
private sealed class MotionPreparation(
|
||||
LocalPlayerControllerSlot owner,
|
||||
PlayerMovementController controller) : IDisposable
|
||||
{
|
||||
private LocalPlayerControllerSlot? _owner = owner;
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
LocalPlayerControllerSlot? current = Interlocked.Exchange(ref _owner, null);
|
||||
current?.EndMotionPreparation(controller);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal interface ILocalPlayerPhysicsHostSource
|
||||
{
|
||||
EntityPhysicsHost? Host { get; }
|
||||
|
|
|
|||
|
|
@ -3,23 +3,6 @@ using AcDream.Core.Net;
|
|||
|
||||
namespace AcDream.App.Input;
|
||||
|
||||
internal interface IMovementTruthDiagnosticSink
|
||||
{
|
||||
void OnOutbound(
|
||||
string kind,
|
||||
uint sequence,
|
||||
MovementResult result,
|
||||
Vector3 wirePosition,
|
||||
uint wireCellId,
|
||||
byte contactByte);
|
||||
|
||||
void OnServerEcho(
|
||||
WorldSession.EntityPositionUpdate update,
|
||||
Vector3 serverWorldPosition);
|
||||
|
||||
void ResetSession();
|
||||
}
|
||||
|
||||
internal sealed class MovementTruthDiagnosticController
|
||||
: IMovementTruthDiagnosticSink
|
||||
{
|
||||
|
|
@ -129,33 +112,3 @@ internal sealed class MovementTruthDiagnosticController
|
|||
? FormattableString.Invariant($"0x{command.Value:X8}")
|
||||
: "-";
|
||||
}
|
||||
|
||||
internal sealed class DelegateMovementTruthDiagnosticSink
|
||||
: IMovementTruthDiagnosticSink
|
||||
{
|
||||
private readonly Action<string, uint, MovementResult, Vector3, uint, byte>
|
||||
_outbound;
|
||||
|
||||
public DelegateMovementTruthDiagnosticSink(
|
||||
Action<string, uint, MovementResult, Vector3, uint, byte> outbound) =>
|
||||
_outbound = outbound ?? throw new ArgumentNullException(nameof(outbound));
|
||||
|
||||
public void OnOutbound(
|
||||
string kind,
|
||||
uint sequence,
|
||||
MovementResult result,
|
||||
Vector3 wirePosition,
|
||||
uint wireCellId,
|
||||
byte contactByte) =>
|
||||
_outbound(kind, sequence, result, wirePosition, wireCellId, contactByte);
|
||||
|
||||
public void OnServerEcho(
|
||||
WorldSession.EntityPositionUpdate update,
|
||||
Vector3 serverWorldPosition)
|
||||
{
|
||||
}
|
||||
|
||||
public void ResetSession()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -256,7 +256,8 @@ internal sealed class PlayerModeController :
|
|||
{
|
||||
var controller = new PlayerMovementController(
|
||||
_physics,
|
||||
playerRecord.ObjectClock);
|
||||
playerRecord.ObjectClock,
|
||||
PlayerMovementConstructionOptions.From(_skills.Snapshot));
|
||||
controller.ApplyPhysicsState(playerRecord.FinalPhysicsState);
|
||||
|
||||
// Retail MovementManager::MakeMoveToManager @ 0x00524000 creates one
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue