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
200
src/AcDream.Runtime/Gameplay/RuntimeLocalPlayerMovementState.cs
Normal file
200
src/AcDream.Runtime/Gameplay/RuntimeLocalPlayerMovementState.cs
Normal file
|
|
@ -0,0 +1,200 @@
|
|||
using AcDream.Core.Physics;
|
||||
|
||||
namespace AcDream.Runtime.Gameplay;
|
||||
|
||||
public interface IRuntimeLocalPlayerControllerSource
|
||||
{
|
||||
PlayerMovementController? Controller { get; }
|
||||
}
|
||||
|
||||
public interface IRuntimeLocalPlayerMotionSource
|
||||
{
|
||||
MotionInterpreter? Motion { get; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Canonical local movement lifetime and intent owner. Graphical input,
|
||||
/// presentation, diagnostics, and future no-window hosts borrow this exact
|
||||
/// state; they never mirror the controller or the autorun latch.
|
||||
/// </summary>
|
||||
public sealed class RuntimeLocalPlayerMovementState
|
||||
: IRuntimeLocalPlayerControllerSource,
|
||||
IRuntimeLocalPlayerMotionSource,
|
||||
IRuntimeMovementView,
|
||||
IDisposable
|
||||
{
|
||||
private PlayerMovementController? _controller;
|
||||
private PlayerMovementController? _preparingMotionOwner;
|
||||
private bool _autoRunActive;
|
||||
private bool _disposed;
|
||||
private long _revision;
|
||||
|
||||
public PlayerMovementController? Controller
|
||||
{
|
||||
get => _controller;
|
||||
set
|
||||
{
|
||||
ObjectDisposedException.ThrowIf(_disposed, this);
|
||||
if (ReferenceEquals(_controller, value))
|
||||
return;
|
||||
_controller = value;
|
||||
Interlocked.Increment(ref _revision);
|
||||
}
|
||||
}
|
||||
|
||||
public bool AutoRunActive => _autoRunActive;
|
||||
public long Revision => Interlocked.Read(ref _revision);
|
||||
public IRuntimeMovementView View => this;
|
||||
|
||||
MotionInterpreter? IRuntimeLocalPlayerMotionSource.Motion =>
|
||||
_preparingMotionOwner?.Motion ?? _controller?.Motion;
|
||||
|
||||
public RuntimeMovementSnapshot Snapshot
|
||||
{
|
||||
get
|
||||
{
|
||||
PlayerMovementController? controller = _controller;
|
||||
return controller is null
|
||||
? new RuntimeMovementSnapshot(
|
||||
false,
|
||||
0u,
|
||||
default,
|
||||
default,
|
||||
false,
|
||||
0d,
|
||||
Revision,
|
||||
_autoRunActive)
|
||||
: new RuntimeMovementSnapshot(
|
||||
true,
|
||||
controller.LocalEntityId,
|
||||
controller.CellPosition,
|
||||
controller.BodyVelocity,
|
||||
controller.IsAirborne,
|
||||
controller.SimTimeSeconds,
|
||||
Revision,
|
||||
_autoRunActive);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Opens the retail construction seam where a PartArray completion can
|
||||
/// reach the candidate MotionInterpreter before the controller is
|
||||
/// published to ordinary borrowers.
|
||||
/// </summary>
|
||||
public IDisposable BeginMotionPreparation(
|
||||
PlayerMovementController controller,
|
||||
Action? drainPriorAnimationQueue = null)
|
||||
{
|
||||
ObjectDisposedException.ThrowIf(_disposed, this);
|
||||
ArgumentNullException.ThrowIfNull(controller);
|
||||
if (_preparingMotionOwner is not null)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"A local player motion owner is already being prepared.");
|
||||
}
|
||||
|
||||
drainPriorAnimationQueue?.Invoke();
|
||||
_preparingMotionOwner = controller;
|
||||
return new MotionPreparation(this, controller);
|
||||
}
|
||||
|
||||
public bool Execute(RuntimeMovementCommand command)
|
||||
{
|
||||
ObjectDisposedException.ThrowIf(_disposed, this);
|
||||
switch (command)
|
||||
{
|
||||
case RuntimeMovementCommand.ToggleRunLock:
|
||||
_autoRunActive = !_autoRunActive;
|
||||
Interlocked.Increment(ref _revision);
|
||||
return true;
|
||||
case RuntimeMovementCommand.Stop:
|
||||
CancelAutoRun();
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public bool CancelAutoRun()
|
||||
{
|
||||
ObjectDisposedException.ThrowIf(_disposed, this);
|
||||
if (!_autoRunActive)
|
||||
return false;
|
||||
_autoRunActive = false;
|
||||
Interlocked.Increment(ref _revision);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void ResetInputIntent()
|
||||
{
|
||||
ObjectDisposedException.ThrowIf(_disposed, this);
|
||||
if (!_autoRunActive)
|
||||
return;
|
||||
_autoRunActive = false;
|
||||
Interlocked.Increment(ref _revision);
|
||||
}
|
||||
|
||||
public RuntimeLocalMovementOwnershipSnapshot CaptureOwnership() =>
|
||||
new(
|
||||
_disposed,
|
||||
_controller is not null,
|
||||
_preparingMotionOwner is not null,
|
||||
_autoRunActive,
|
||||
Revision);
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (_disposed)
|
||||
return;
|
||||
_autoRunActive = false;
|
||||
_controller = null;
|
||||
_preparingMotionOwner = null;
|
||||
Interlocked.Increment(ref _revision);
|
||||
_disposed = true;
|
||||
}
|
||||
|
||||
private void EndMotionPreparation(PlayerMovementController controller)
|
||||
{
|
||||
// Terminal disposal clears the unpublished construction seam. A
|
||||
// caller may still unwind the already-issued lease afterward; that
|
||||
// unwind is idempotent rather than resurrecting or faulting the
|
||||
// retired runtime owner.
|
||||
if (_disposed && _preparingMotionOwner is null)
|
||||
return;
|
||||
|
||||
if (!ReferenceEquals(_preparingMotionOwner, controller))
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"The local player motion preparation owner changed unexpectedly.");
|
||||
}
|
||||
_preparingMotionOwner = null;
|
||||
}
|
||||
|
||||
private sealed class MotionPreparation(
|
||||
RuntimeLocalPlayerMovementState owner,
|
||||
PlayerMovementController controller) : IDisposable
|
||||
{
|
||||
private RuntimeLocalPlayerMovementState? _owner = owner;
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
RuntimeLocalPlayerMovementState? current =
|
||||
Interlocked.Exchange(ref _owner, null);
|
||||
current?.EndMotionPreparation(controller);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public readonly record struct RuntimeLocalMovementOwnershipSnapshot(
|
||||
bool IsDisposed,
|
||||
bool HasController,
|
||||
bool HasPreparingMotionOwner,
|
||||
bool AutoRunActive,
|
||||
long Revision)
|
||||
{
|
||||
public bool IsConverged =>
|
||||
IsDisposed
|
||||
&& !HasController
|
||||
&& !HasPreparingMotionOwner
|
||||
&& !AutoRunActive;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue