A local-player ForcePosition had TWO independent writers for one accepted
packet: LocalForcePositionTransaction snapped the physics body
(PlayerMovementController.BlipPosition, a raw SnapToCell with no collision
resolve), while LiveEntityNetworkUpdateController's generic tail separately
wrote position/cell/rotation to the render WorldEntity from the raw wire and
rebucketed it. Two stores, one packet — the divergence class 670f307c fixed on
the remote path. The outbound AutonomousPosition ack also fired BEFORE any
canonical commit existed: we told ACE "got it, I'm here" before deciding where
"here" was, and the trailing isCurrent() could only suppress the continuation,
never recall the packet.
RuntimeAcceptedPositionDriveController is now the one Runtime-owned seam. Both
hosts call the identical TryExecuteAcceptedLocalPosition; App and headless
project the committed result through the existing placement projection sink
(LiveEntityRuntime.TryApplyRuntimePlacementPlace already performed the same
four writes, from committed state rather than a wire guess).
Retail: SmartBox::HandleReceivedPosition @0x00453FD0's FORCE_POSITION branch is
get_heading -> Frame::set_heading -> SmartBox::BlipPlayer @0x00453940 -> stamp
POSITION_TS -> SendPositionEvent @0x00454091 -> return @0x0045409D. BlipPlayer
is CPhysicsObj::SetPositionSimple @0x005162B0 with flags 0x1012
(Teleport|Slide|SendPositionEvent) — a real collision-resolving SetPosition,
not a snap. The pinned classifier already encoded this exactly.
Named behaviour changes:
* The ack is now an OUTPUT of the committed route, fired strictly after the
canonical commit and exactly once per accepted force packet.
* The ForcePosition route no longer re-arms the constraint leash. The force
branch returns at 0x0045409D, ahead of all three ConstrainTo sites
(0x00454272, 0x0045418A, 0x004541EC); the old re-arm cited retail's "Player,
normal" branch, which BlipPlayer is not on. The teleport, CommitPreparedPosition
and first-entry callers legitimately still constrain and are untouched.
* A force correction that terminates WITHOUT committing still sends its
position event and is not retried — retail's BlipPlayer discards
SetPositionSimple's SetPositionError return and acks unconditionally.
A single _pending funnel owns the in-flight placement, deciding on the token's
PositionAuthorityVersion against the record's: equal -> clear; advanced with the
newest accepted event still a force -> re-issue, re-classified; advanced to an
ordinary Apply -> clear, since newer server truth owns that pose. This closes a
double-apply/double-ack and a silently-dropped correction that two earlier
iterations of this slice each introduced.
AD-62 records the residual: a ForcePosition our async collision publication
cannot carry to a committed placement is not re-applied. Retail has no park —
its world is fully resident and its placement synchronous — so the state is
unreachable there. AP-131 is NOT retired; its legacy Position caller is route 4.
Deleted: LocalForcePositionTransaction, PlayerMovementController.BlipPosition,
HeadlessSessionWorldProjection.BlipLocalPlayer.
Gates: complete Release solution 10,858 passed / 4 skipped / 0 failed (baseline
10,844/4/0). Two independent Opus reviews (retail-conformance and
architecture/adversarial) PASS on the final diff after three FAIL rounds; every
intermediate state was fully green, so the suite caught none of the four real
defects. Connected acceptance is NOT run: nothing a user can do makes ACE emit
a ForcePosition without retail's @pklite, which acdream does not implement — see
docs/research/2026-08-03-c4-route-2-visual-gate.md.
Known gap, recorded not claimed: the plan's acceptance item 2 is unmet. The App
double-write check is a source pin, and "the committed projection moves the
render entity" is uncovered at any layer (#292). Filed alongside: #286-#291,
#293-#296.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1453 lines
61 KiB
C#
1453 lines
61 KiB
C#
using System.Net;
|
|
using System.Numerics;
|
|
using AcDream.Core.Combat;
|
|
using AcDream.Core.Items;
|
|
using AcDream.Core.Net;
|
|
using AcDream.Core.Net.Messages;
|
|
using AcDream.Core.Physics;
|
|
using AcDream.Core.Spells;
|
|
using AcDream.Runtime.Entities;
|
|
using AcDream.Runtime.Gameplay;
|
|
using AcDream.Runtime.Physics;
|
|
using AcDream.Runtime.Session;
|
|
using AcDream.Runtime.World;
|
|
|
|
namespace AcDream.Runtime.Tests.Session;
|
|
|
|
/// <summary>
|
|
/// C4 route 2 (2026-08-03): the Runtime-owned accepted-Position execution
|
|
/// seam for a ForcePosition on an already-live local player. Fixture
|
|
/// construction mirrors <c>RuntimeLiveEntitySessionControllerTests</c>'
|
|
/// session/first-entry harness — a live <see cref="PlayerMovementController"/>
|
|
/// only exists once the local player's initial-Create residence has fully
|
|
/// drained through <see cref="RuntimeFirstEntryDriveController"/>.
|
|
/// </summary>
|
|
public sealed class RuntimeAcceptedPositionDriveControllerTests
|
|
{
|
|
private const uint PlayerGuid = 0x50000001u;
|
|
private const uint SpawnLandblock = 0x01010000u;
|
|
private const float SpawnHeight = 5f;
|
|
|
|
[Fact]
|
|
public void NotApplicable_WhenDispositionIsNotForcePosition()
|
|
{
|
|
using StartedRuntime started = StartRuntime();
|
|
(RuntimeEntityRecord record, PlayerMovementController controller) =
|
|
EnterLocalPlayer(started.Runtime);
|
|
RuntimeAcceptedPositionDriveController drive =
|
|
CreateAcceptedPositionDrive(started.Runtime, out List<byte[]> gameActions);
|
|
|
|
RuntimeAcceptedPositionExecutionStatus status =
|
|
drive.TryExecuteAcceptedLocalPosition(
|
|
record,
|
|
ForceUpdate(new Vector3(30f, 30f, 5f)),
|
|
PositionTimestampDisposition.Apply,
|
|
Timestamps(teleport: 0),
|
|
previousTeleportSequence: 0);
|
|
|
|
Assert.Equal(RuntimeAcceptedPositionExecutionStatus.NotApplicable, status);
|
|
Assert.Empty(gameActions);
|
|
}
|
|
|
|
[Fact]
|
|
public void NotApplicable_WhenRecordIsNotTheLocalPlayer()
|
|
{
|
|
using StartedRuntime started = StartRuntime();
|
|
(RuntimeEntityRecord record, _) = EnterLocalPlayer(started.Runtime);
|
|
RuntimeAcceptedPositionDriveController drive =
|
|
CreateAcceptedPositionDrive(started.Runtime, out _);
|
|
|
|
// Same record, but the drive's own local-player-guid accessor no
|
|
// longer matches it (as if it belonged to some other entity).
|
|
started.Runtime.PlayerIdentity.ServerGuid = 0x70000099u;
|
|
|
|
RuntimeAcceptedPositionExecutionStatus status =
|
|
drive.TryExecuteAcceptedLocalPosition(
|
|
record,
|
|
ForceUpdate(new Vector3(30f, 30f, 5f)),
|
|
PositionTimestampDisposition.ForcePosition,
|
|
Timestamps(teleport: 0),
|
|
previousTeleportSequence: 0);
|
|
|
|
Assert.Equal(RuntimeAcceptedPositionExecutionStatus.NotApplicable, status);
|
|
}
|
|
|
|
[Fact]
|
|
public void NotApplicable_WhileAnInitialCreateResidenceIsStillActive()
|
|
{
|
|
using StartedRuntime started = StartRuntime();
|
|
GameRuntime runtime = started.Runtime;
|
|
runtime.PlayerIdentity.ServerGuid = PlayerGuid;
|
|
CommitLandblockCollision(runtime, SpawnLandblock);
|
|
RuntimeEntityRecord record = runtime.EntityObjects
|
|
.RegisterEntityWithInitialResidence(
|
|
Spawn(PlayerGuid), isLocalPlayer: true)
|
|
.Canonical!;
|
|
// Deliberately do NOT drain the first-entry drive: the residence
|
|
// (and hence no PhysicsBody/controller) is still open — route 1's
|
|
// job, never route 2's.
|
|
RuntimeAcceptedPositionDriveController drive =
|
|
CreateAcceptedPositionDrive(runtime, out List<byte[]> gameActions);
|
|
|
|
RuntimeAcceptedPositionExecutionStatus status =
|
|
drive.TryExecuteAcceptedLocalPosition(
|
|
record,
|
|
ForceUpdate(new Vector3(30f, 30f, 5f)),
|
|
PositionTimestampDisposition.ForcePosition,
|
|
Timestamps(teleport: 0),
|
|
previousTeleportSequence: 0);
|
|
|
|
Assert.Equal(RuntimeAcceptedPositionExecutionStatus.NotApplicable, status);
|
|
Assert.Empty(gameActions);
|
|
}
|
|
|
|
[Fact]
|
|
public void Rejected_WhenTheClassifierDeclinesTheFrame()
|
|
{
|
|
using StartedRuntime started = StartRuntime();
|
|
(RuntimeEntityRecord record, PlayerMovementController controller) =
|
|
EnterLocalPlayer(started.Runtime);
|
|
Vector3 positionBefore = controller.Position;
|
|
RuntimeAcceptedPositionDriveController drive =
|
|
CreateAcceptedPositionDrive(started.Runtime, out List<byte[]> gameActions);
|
|
|
|
// RuntimeAuthoritativePositionRouteClassifier.ValidAcceptedAuthority's
|
|
// ForcePosition case requires PreviousTeleportSequence ==
|
|
// AcceptedTeleportSequence; a mismatch is a genuine data-validity
|
|
// rejection (this call site never re-derives the timestamp gate's
|
|
// own freshness rule — it is asserting the classifier's own
|
|
// independent structural check).
|
|
RuntimeAcceptedPositionExecutionStatus status =
|
|
drive.TryExecuteAcceptedLocalPosition(
|
|
record,
|
|
ForceUpdate(new Vector3(30f, 30f, 5f)),
|
|
PositionTimestampDisposition.ForcePosition,
|
|
Timestamps(teleport: 6),
|
|
previousTeleportSequence: 5);
|
|
|
|
Assert.Equal(RuntimeAcceptedPositionExecutionStatus.Rejected, status);
|
|
Assert.Equal(positionBefore, controller.Position);
|
|
Assert.Empty(gameActions);
|
|
AssertConverged(started.Runtime);
|
|
}
|
|
|
|
[Fact]
|
|
public void Committed_MovesTheBodyPreservesHeadingAndAcksExactlyOnceAfterCommit()
|
|
{
|
|
using StartedRuntime started = StartRuntime();
|
|
GameRuntime runtime = started.Runtime;
|
|
(RuntimeEntityRecord record, PlayerMovementController controller) =
|
|
EnterLocalPlayer(runtime);
|
|
Quaternion headingBeforeCorrection = controller.BodyOrientation;
|
|
|
|
var corrected = new Vector3(30f, 32f, 5f);
|
|
WorldSession.EntityPositionUpdate wire = ForceUpdate(corrected);
|
|
// A deliberately different wire rotation than the controller's own
|
|
// heading, exactly like a real server correction carries whatever
|
|
// heading it last observed — proves the seam never applies a SECOND
|
|
// heading substitution on top of the one the upstream merge already
|
|
// performed (contract §1c: RuntimeEntityObjectLifetime.TryApplyPosition's
|
|
// forcePositionRotation argument, exercised for real below via
|
|
// MergeAccepted).
|
|
wire = wire with
|
|
{
|
|
Position = wire.Position with
|
|
{
|
|
RotationX = 0f,
|
|
RotationY = 0f,
|
|
RotationZ = 1f,
|
|
RotationW = 0f,
|
|
},
|
|
};
|
|
(PositionTimestampDisposition disposition, AcceptedPhysicsTimestamps timestamps) =
|
|
MergeAccepted(runtime, controller, wire);
|
|
Assert.Equal(PositionTimestampDisposition.ForcePosition, disposition);
|
|
|
|
RuntimeAcceptedPositionDriveController drive =
|
|
CreateAcceptedPositionDrive(runtime, out List<byte[]> gameActions);
|
|
|
|
RuntimeAcceptedPositionExecutionStatus status =
|
|
drive.TryExecuteAcceptedLocalPosition(
|
|
record,
|
|
wire,
|
|
disposition,
|
|
timestamps,
|
|
timestamps.PreviousTeleport);
|
|
|
|
Assert.Equal(RuntimeAcceptedPositionExecutionStatus.Committed, status);
|
|
Assert.Equal(corrected, controller.Position);
|
|
Assert.Equal(headingBeforeCorrection, controller.BodyOrientation);
|
|
Assert.Single(gameActions);
|
|
AssertConverged(runtime);
|
|
}
|
|
|
|
[Fact]
|
|
public void Contention_WhenTheEntityAlreadyOwnsAnActiveOperation()
|
|
{
|
|
using StartedRuntime started = StartRuntime();
|
|
GameRuntime runtime = started.Runtime;
|
|
(RuntimeEntityRecord record, PlayerMovementController controller) =
|
|
EnterLocalPlayer(runtime);
|
|
Vector3 positionBefore = controller.Position;
|
|
WorldSession.EntityPositionUpdate wire =
|
|
ForceUpdate(new Vector3(30f, 32f, 5f));
|
|
(PositionTimestampDisposition disposition, AcceptedPhysicsTimestamps timestamps) =
|
|
MergeAccepted(runtime, controller, wire);
|
|
Assert.Equal(PositionTimestampDisposition.ForcePosition, disposition);
|
|
|
|
// Mirrors the displaced-authority scenario the deleted
|
|
// LocalForcePositionTransaction's trailing isCurrent() covered: some
|
|
// OTHER operation is already in flight for this exact entity (e.g. a
|
|
// remote-authoritative resolve mid-transaction) when the
|
|
// ForcePosition arrives.
|
|
RuntimeEntityPlacementToken displaced = runtime.EntityObjects.Physics
|
|
.SetPosition.TryBeginExclusiveAuthoredPlacement(
|
|
record,
|
|
record.PositionAuthorityVersion,
|
|
RuntimeSetPositionOperationKind.LocalAuthoritative);
|
|
Assert.True(displaced.IsValid);
|
|
RuntimeAcceptedPositionDriveController drive =
|
|
CreateAcceptedPositionDrive(runtime, out List<byte[]> gameActions);
|
|
|
|
RuntimeAcceptedPositionExecutionStatus status =
|
|
drive.TryExecuteAcceptedLocalPosition(
|
|
record,
|
|
wire,
|
|
disposition,
|
|
timestamps,
|
|
timestamps.PreviousTeleport);
|
|
|
|
Assert.Equal(RuntimeAcceptedPositionExecutionStatus.Contention, status);
|
|
Assert.Equal(positionBefore, controller.Position);
|
|
Assert.Empty(gameActions);
|
|
|
|
// Cleanup: release the displaced operation so the fixture converges.
|
|
RuntimePlacementCancellationReceipt cancellation = runtime.EntityObjects
|
|
.Physics.SetPosition.ForgetExactPlacement(displaced);
|
|
if (cancellation.IsValid)
|
|
{
|
|
runtime.EntityObjects.Physics.SetPosition
|
|
.PublishCancellation(cancellation);
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void DeferredCell_ParksThenCommitsAndNeverDoubleAcksAfterTheCollisionGenerationWakes()
|
|
{
|
|
using StartedRuntime started = StartRuntime();
|
|
GameRuntime runtime = started.Runtime;
|
|
(RuntimeEntityRecord record, PlayerMovementController controller) =
|
|
EnterLocalPlayer(runtime);
|
|
RuntimeAcceptedPositionDriveController drive =
|
|
CreateAcceptedPositionDrive(runtime, out List<byte[]> gameActions);
|
|
|
|
// A destination landblock whose collision generation was never
|
|
// committed (mirrors RuntimeSetPositionStateTests' CrossLandblockRequest
|
|
// pattern — re-admitting an ALREADY-ready landblock through this
|
|
// simple Begin/CommitCollisionGeneration pair does not block a new
|
|
// placement; only a genuinely fresh landblock does) parks the
|
|
// operation instead of committing it. Runtime's world-frame
|
|
// resolution is arithmetic once ANY frame is observed
|
|
// (RuntimePhysicsState.TryGetWorldFrameOffset:598-617), so this
|
|
// parks on collision readiness specifically, not on an unresolved
|
|
// frame.
|
|
const uint deferredLandblock = 0x02020000u;
|
|
var deferredPosition = new Vector3(10f, 10f, SpawnHeight);
|
|
WorldSession.EntityPositionUpdate parkedUpdate = ForceUpdate(
|
|
deferredPosition,
|
|
landblockId: deferredLandblock | 0x0001u);
|
|
(PositionTimestampDisposition disposition, AcceptedPhysicsTimestamps timestamps) =
|
|
MergeAccepted(runtime, controller, parkedUpdate);
|
|
Assert.Equal(PositionTimestampDisposition.ForcePosition, disposition);
|
|
|
|
RuntimeAcceptedPositionExecutionStatus parked =
|
|
drive.TryExecuteAcceptedLocalPosition(
|
|
record,
|
|
parkedUpdate,
|
|
disposition,
|
|
timestamps,
|
|
timestamps.PreviousTeleport);
|
|
|
|
Assert.Equal(RuntimeAcceptedPositionExecutionStatus.DeferredCell, parked);
|
|
Assert.Empty(gameActions);
|
|
Assert.Equal(1, drive.PendingCount);
|
|
|
|
// Advance() before the destination is ready makes no progress.
|
|
drive.Advance();
|
|
Assert.Empty(gameActions);
|
|
Assert.Equal(1, drive.PendingCount);
|
|
|
|
CommitLandblockCollision(runtime, deferredLandblock);
|
|
// Production always has a LIVE host subscription
|
|
// (RuntimePlacementProjectionSubscription) that applies-and-
|
|
// acknowledges the resubmitted Place synchronously the instant
|
|
// RetryDeferred's CommitCanonical publishes it — that is what
|
|
// promotes this controller's own Watch into an observable
|
|
// acknowledged completion (RuntimeSetPositionState.AcknowledgeProjection's
|
|
// Place branch). This bare-Runtime fixture has no host wired, so it
|
|
// stands in for that subscription exactly like
|
|
// RuntimeLiveEntitySessionControllerTests' own DrainPlacementFifo.
|
|
DrainPlacementFifo(runtime);
|
|
|
|
// A single Advance() pump resolves the deferred commit.
|
|
drive.Advance();
|
|
|
|
Assert.Equal(0, drive.PendingCount);
|
|
// World position, not the cell-local wire position: the deferred
|
|
// landblock (0x0202) sits one landblock diagonally from the spawn
|
|
// landblock (0x0101) in Runtime's world frame, a (192, 192, 0) m
|
|
// offset (RuntimePhysicsState.TryGetWorldFrameOffset).
|
|
Assert.Equal(deferredPosition + new Vector3(192f, 192f, 0f), controller.Position);
|
|
// R8 review fix (2026-08-03): the ack is gated on retail's own
|
|
// independent CanSendPositionEvent requirement (Contact + OnWalkable
|
|
// — PlayerMovementController.cs:1517). Measured directly: this
|
|
// synthetic cross-landblock jump resolves with InContact=false in
|
|
// this bare-Runtime fixture (no subsequent physics tick runs here to
|
|
// sweep the body onto the terrain it was placed exactly tangent to —
|
|
// unlike the WITHIN-landblock move
|
|
// Committed_MovesTheBodyPreservesHeadingAndAcksExactlyOnceAfterCommit
|
|
// exercises, which measures Contact=true and DOES get its ack). This
|
|
// test therefore does NOT verify the single-ack-after-wake sequence
|
|
// end to end — it only proves the non-double-ack invariant below.
|
|
// Asserting exactly one ack here would require driving a real
|
|
// physics tick after the wake to establish ground contact, which is
|
|
// out of this fixture's scope; do not report this sequence as
|
|
// ack-verified (docs/ISSUES.md #285) until a harness does that.
|
|
int acksAfterFirstResolve = gameActions.Count;
|
|
|
|
// Further pumps are no-ops — the ack must never fire twice, however
|
|
// many times Advance() is pumped (still true wants Contact to
|
|
// eventually flip and the ack to fire exactly once, whenever that
|
|
// happens).
|
|
drive.Advance();
|
|
drive.Advance();
|
|
Assert.Equal(acksAfterFirstResolve, gameActions.Count);
|
|
AssertConverged(runtime);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Round 2 unified rule, branch 1 of 3 — <b>EQUAL</b>. The parked
|
|
/// operation dies (here through the exact
|
|
/// <c>RuntimeSetPositionState.Forget</c> funnel every mid-session
|
|
/// cancellation shares: supersession, the lost-cell deadline,
|
|
/// <c>ParkCollisionResidents</c>, a generation change) while NO newer
|
|
/// accepted position has taken the authority, so the record's
|
|
/// <c>PositionAuthorityVersion</c> still equals the dead operation's own.
|
|
/// Nothing is outstanding: <c>_pending</c> clears, and the drive must NOT
|
|
/// re-issue. Re-issuing on an unchanged authority is precisely the shape
|
|
/// that produced N1's second placement + second ack.
|
|
/// </summary>
|
|
[Fact]
|
|
public void Equal_ClearsPendingWithoutReissuingWhenNoNewerAcceptedAuthorityArrived()
|
|
{
|
|
using StartedRuntime started = StartRuntime();
|
|
GameRuntime runtime = started.Runtime;
|
|
(RuntimeEntityRecord record, PlayerMovementController controller) =
|
|
EnterLocalPlayer(runtime);
|
|
RuntimeAcceptedPositionDriveController drive =
|
|
CreateAcceptedPositionDrive(runtime, out List<byte[]> gameActions);
|
|
|
|
const uint deferredLandblock = 0x02020000u;
|
|
var deferredPosition = new Vector3(10f, 10f, SpawnHeight);
|
|
WorldSession.EntityPositionUpdate parkedUpdate = ForceUpdate(
|
|
deferredPosition,
|
|
landblockId: deferredLandblock | 0x0001u);
|
|
(PositionTimestampDisposition disposition, AcceptedPhysicsTimestamps timestamps) =
|
|
MergeAccepted(runtime, controller, parkedUpdate);
|
|
Assert.Equal(PositionTimestampDisposition.ForcePosition, disposition);
|
|
|
|
RuntimeAcceptedPositionExecutionStatus parked =
|
|
drive.TryExecuteAcceptedLocalPosition(
|
|
record,
|
|
parkedUpdate,
|
|
disposition,
|
|
timestamps,
|
|
timestamps.PreviousTeleport);
|
|
Assert.Equal(RuntimeAcceptedPositionExecutionStatus.DeferredCell, parked);
|
|
Assert.Equal(1, drive.PendingCount);
|
|
ulong authorityAtPark = record.PositionAuthorityVersion;
|
|
Vector3 positionAtPark = controller.Position;
|
|
|
|
RuntimePlacementCancellationReceipt cancellation =
|
|
runtime.EntityObjects.Physics.SetPosition.Forget(record);
|
|
if (cancellation.IsValid)
|
|
{
|
|
runtime.EntityObjects.Physics.SetPosition
|
|
.PublishCancellation(cancellation);
|
|
}
|
|
|
|
// The precondition this branch is defined by: a bare Forget cancels
|
|
// the operation WITHOUT merging anything, so the accepted authority
|
|
// has not moved.
|
|
Assert.Equal(authorityAtPark, record.PositionAuthorityVersion);
|
|
|
|
drive.Advance();
|
|
|
|
// No re-issue: a re-issue against this still-unready destination would
|
|
// park AGAIN and leave PendingCount at 1 (that is exactly what the
|
|
// round-1 shape did here).
|
|
Assert.Equal(0, drive.PendingCount);
|
|
Assert.Equal(positionAtPark, controller.Position);
|
|
// Round 3 (2026-08-03): the packet's placement WAS begun and then
|
|
// died without committing, so retail's unconditional position event is
|
|
// owed and goes out here carrying the unchanged pose
|
|
// (SmartBox::BlipPlayer @0x00453940 discards SetPositionSimple's
|
|
// error; SmartBox::HandleReceivedPosition @0x00453FD0 acks at
|
|
// @0x00454091 regardless). Before round 3 this asserted Empty, which
|
|
// encoded the defect: neither the body moved NOR an ack left.
|
|
Assert.Single(gameActions);
|
|
|
|
// Repeated pumps stay silent — the funnel cleared, it did not park a
|
|
// retry marker for an authority nothing is waiting on, and retail
|
|
// never retries a force that failed.
|
|
drive.Advance();
|
|
drive.Advance();
|
|
Assert.Equal(0, drive.PendingCount);
|
|
Assert.Single(gameActions);
|
|
Assert.Equal(positionAtPark, controller.Position);
|
|
AssertConverged(runtime);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Round 2 unified rule, branch 2 of 3 — <b>ADVANCED, newest accepted
|
|
/// event is still a ForcePosition</b>; also the B1 regression. Exact
|
|
/// production shape: a park wakes and its <c>Place</c> is ACCEPTED, so the
|
|
/// operation leaves <c>_operations</c> but its completion is RETAINED;
|
|
/// <c>Forget</c> then early-returns
|
|
/// (<c>RuntimeSetPositionState.CancelCoreDeferred</c>'s
|
|
/// <c>_operations.Remove</c> guard) and the retained completion survives
|
|
/// the next packet's merge. That next ForcePosition therefore cannot
|
|
/// begin (<c>HasRetainedCompletion</c> → <c>Contention</c>) — and before
|
|
/// the unified funnel its correction was lost outright, because the next
|
|
/// pump consumed the OLD completion and acked the OLD pose with nothing
|
|
/// left pointing at the new one. The one-frame window is real on the
|
|
/// graphical host, whose inbound dispatch precedes <c>RetryPending</c>.
|
|
/// </summary>
|
|
[Fact]
|
|
public void Advanced_ReissuesWhenTheNewestAcceptedEventIsStillAForcePosition()
|
|
{
|
|
using StartedRuntime started = StartRuntime();
|
|
GameRuntime runtime = started.Runtime;
|
|
(RuntimeEntityRecord record, PlayerMovementController controller) =
|
|
EnterLocalPlayer(runtime);
|
|
RuntimeAcceptedPositionDriveController drive =
|
|
CreateAcceptedPositionDrive(runtime, out List<byte[]> gameActions);
|
|
|
|
const uint deferredLandblock = 0x02020000u;
|
|
var firstCorrection = new Vector3(10f, 10f, SpawnHeight);
|
|
WorldSession.EntityPositionUpdate parkedUpdate = ForceUpdate(
|
|
firstCorrection,
|
|
landblockId: deferredLandblock | 0x0001u);
|
|
(PositionTimestampDisposition parkedDisposition,
|
|
AcceptedPhysicsTimestamps parkedTimestamps) =
|
|
MergeAccepted(runtime, controller, parkedUpdate);
|
|
Assert.Equal(
|
|
PositionTimestampDisposition.ForcePosition, parkedDisposition);
|
|
Assert.Equal(
|
|
RuntimeAcceptedPositionExecutionStatus.DeferredCell,
|
|
drive.TryExecuteAcceptedLocalPosition(
|
|
record,
|
|
parkedUpdate,
|
|
parkedDisposition,
|
|
parkedTimestamps,
|
|
parkedTimestamps.PreviousTeleport));
|
|
|
|
// The park wakes and its Place is accepted, leaving a RETAINED
|
|
// completion. Deliberately no Advance() yet: this is the host frame in
|
|
// which the next packet arrives before the pump runs.
|
|
CommitLandblockCollision(runtime, deferredLandblock);
|
|
DrainPlacementFifo(runtime);
|
|
|
|
var secondCorrection = new Vector3(14f, 12f, SpawnHeight);
|
|
WorldSession.EntityPositionUpdate secondUpdate = ForceUpdate(
|
|
secondCorrection,
|
|
landblockId: deferredLandblock | 0x0001u,
|
|
positionSequence: 3,
|
|
forcePositionSequence: 2);
|
|
(PositionTimestampDisposition secondDisposition,
|
|
AcceptedPhysicsTimestamps secondTimestamps) =
|
|
MergeAccepted(runtime, controller, secondUpdate);
|
|
Assert.Equal(
|
|
PositionTimestampDisposition.ForcePosition, secondDisposition);
|
|
|
|
Assert.Equal(
|
|
RuntimeAcceptedPositionExecutionStatus.Contention,
|
|
drive.TryExecuteAcceptedLocalPosition(
|
|
record,
|
|
secondUpdate,
|
|
secondDisposition,
|
|
secondTimestamps,
|
|
secondTimestamps.PreviousTeleport));
|
|
|
|
// One pump: consume the older completion (its own reconcile + ack),
|
|
// then re-issue the newest accepted force — which the funnel proves by
|
|
// landing the body on the SECOND correction, not the first.
|
|
drive.Advance();
|
|
|
|
Assert.Equal(0, drive.PendingCount);
|
|
Assert.Equal(
|
|
secondCorrection + new Vector3(192f, 192f, 0f),
|
|
controller.Position);
|
|
// Round 3 (2026-08-03): the former `gameActions.Count <= 2` assertion
|
|
// was deleted here. It could not fail: this fixture's
|
|
// CommitLandblockCollision adds BOTH landblocks at worldOffsetX/Y 0f
|
|
// while Runtime's world frame places the deferred landblock at
|
|
// +192/+192, so the body lands over no terrain, resolves with
|
|
// InContact=false, and retail's own CanSendPositionEvent gate
|
|
// suppresses every ack — gameActions.Count is 0 here. It was also far
|
|
// too loose to encode "at most one per packet". The real
|
|
// discriminators (body landed on the SECOND correction, PendingCount)
|
|
// remain; the ack-count contract is pinned by
|
|
// TerminalWithoutCommit_SendsExactlyOnePositionEventAndLeavesTheBodyUnmoved
|
|
// and Committed_SendsExactlyOnePositionEventAcrossTheCommitAndTheSettle,
|
|
// whose fixtures genuinely satisfy the contact gate.
|
|
|
|
// Further pumps are no-ops: the funnel settled on the Equal branch.
|
|
drive.Advance();
|
|
Assert.Equal(0, drive.PendingCount);
|
|
Assert.Equal(
|
|
secondCorrection + new Vector3(192f, 192f, 0f),
|
|
controller.Position);
|
|
AssertConverged(runtime);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Round 2 unified rule, branch 3 of 3 — <b>ADVANCED, newest accepted
|
|
/// event is an ordinary Apply</b> (N2). The park is cancelled by the
|
|
/// ordinary echo's own merge-time <c>Forget</c>, and that echo — not the
|
|
/// force — now owns the accepted pose. Re-issuing here would apply the
|
|
/// force route's <c>Teleport|Slide</c> flags to an ordinary pose, send an
|
|
/// ack retail never sends on that branch, and skip the <c>ConstrainTo</c>
|
|
/// the ordinary branch runs
|
|
/// (<c>RuntimeAuthoritativePositionRouteClassifier.cs:368-388</c>). So the
|
|
/// funnel must clear without placing and without acking.
|
|
/// </summary>
|
|
[Fact]
|
|
public void Advanced_DoesNotReissueWhenTheNewestAcceptedEventIsAnOrdinaryApply()
|
|
{
|
|
using StartedRuntime started = StartRuntime();
|
|
GameRuntime runtime = started.Runtime;
|
|
(RuntimeEntityRecord record, PlayerMovementController controller) =
|
|
EnterLocalPlayer(runtime);
|
|
RuntimeAcceptedPositionDriveController drive =
|
|
CreateAcceptedPositionDrive(runtime, out List<byte[]> gameActions);
|
|
|
|
const uint deferredLandblock = 0x02020000u;
|
|
WorldSession.EntityPositionUpdate parkedUpdate = ForceUpdate(
|
|
new Vector3(10f, 10f, SpawnHeight),
|
|
landblockId: deferredLandblock | 0x0001u);
|
|
(PositionTimestampDisposition parkedDisposition,
|
|
AcceptedPhysicsTimestamps parkedTimestamps) =
|
|
MergeAccepted(runtime, controller, parkedUpdate);
|
|
Assert.Equal(
|
|
PositionTimestampDisposition.ForcePosition, parkedDisposition);
|
|
Assert.Equal(
|
|
RuntimeAcceptedPositionExecutionStatus.DeferredCell,
|
|
drive.TryExecuteAcceptedLocalPosition(
|
|
record,
|
|
parkedUpdate,
|
|
parkedDisposition,
|
|
parkedTimestamps,
|
|
parkedTimestamps.PreviousTeleport));
|
|
Assert.Equal(1, drive.PendingCount);
|
|
ulong authorityAtPark = record.PositionAuthorityVersion;
|
|
Vector3 positionAtPark = controller.Position;
|
|
|
|
// ACE's next ordinary broadcast, ~100-200 ms later. It merges (which
|
|
// Forgets the park and advances the accepted authority) and is NEVER
|
|
// dispatched to this route — both hosts gate the dispatch on
|
|
// ForcePosition.
|
|
var ordinaryPose = new Vector3(31f, 33f, SpawnHeight);
|
|
(PositionTimestampDisposition ordinaryDisposition, _) = MergeAccepted(
|
|
runtime,
|
|
controller,
|
|
OrdinaryUpdate(ordinaryPose, positionSequence: 3));
|
|
Assert.Equal(PositionTimestampDisposition.Apply, ordinaryDisposition);
|
|
Assert.NotEqual(authorityAtPark, record.PositionAuthorityVersion);
|
|
|
|
drive.Advance();
|
|
|
|
Assert.Equal(0, drive.PendingCount);
|
|
// The force route never ran again: the body is exactly where the
|
|
// cancelled park left it, and specifically NOT on the ordinary echo's
|
|
// pose — which is what a re-issue would have placed it on, with the
|
|
// force route's Teleport|Slide flags and no ConstrainTo.
|
|
Assert.Equal(positionAtPark, controller.Position);
|
|
Assert.NotEqual(ordinaryPose, controller.Position);
|
|
// Exactly ONE AutonomousPosition, and it belongs to the FORCE packet,
|
|
// not the ordinary echo: the force's placement was begun and died
|
|
// without committing, which retail still acknowledges
|
|
// (SmartBox::HandleReceivedPosition @0x00453FD0 acks @0x00454091 with
|
|
// whatever SetPositionSimple left the body at). The ordinary echo
|
|
// never reaches this route at all — retail's ordinary branch has no
|
|
// unconditional SendPositionEvent. Round 3 (2026-08-03) corrected this
|
|
// from Empty, which encoded the lost-ack defect.
|
|
Assert.Single(gameActions);
|
|
|
|
drive.Advance();
|
|
Assert.Equal(0, drive.PendingCount);
|
|
Assert.Equal(positionAtPark, controller.Position);
|
|
Assert.Single(gameActions);
|
|
AssertConverged(runtime);
|
|
}
|
|
|
|
/// <summary>
|
|
/// N1 regression (2026-08-03): ONE server correction must produce EXACTLY
|
|
/// one canonical placement and EXACTLY one outbound
|
|
/// <c>AutonomousPosition</c> — never two. The round-1 shape left a dead
|
|
/// <c>_pending</c> entry behind whenever a fresh packet's own placement
|
|
/// committed while an older park was still tracked, and the next pump
|
|
/// re-issued from that dead entry: a second placement and a second ack for
|
|
/// a single correction, which is the exact duplicate-authority class
|
|
/// <c>670f307c</c> deleted and this whole slice exists to remove.
|
|
/// </summary>
|
|
[Fact]
|
|
public void OneServerCorrectionProducesExactlyOnePlacementAndOneAck()
|
|
{
|
|
using StartedRuntime started = StartRuntime();
|
|
GameRuntime runtime = started.Runtime;
|
|
(RuntimeEntityRecord record, PlayerMovementController controller) =
|
|
EnterLocalPlayer(runtime);
|
|
RuntimeAcceptedPositionDriveController drive =
|
|
CreateAcceptedPositionDrive(runtime, out List<byte[]> gameActions);
|
|
|
|
// An earlier force parks on a landblock whose collision is not ready.
|
|
const uint deferredLandblock = 0x02020000u;
|
|
WorldSession.EntityPositionUpdate parkedUpdate = ForceUpdate(
|
|
new Vector3(10f, 10f, SpawnHeight),
|
|
landblockId: deferredLandblock | 0x0001u);
|
|
(PositionTimestampDisposition parkedDisposition,
|
|
AcceptedPhysicsTimestamps parkedTimestamps) =
|
|
MergeAccepted(runtime, controller, parkedUpdate);
|
|
Assert.Equal(
|
|
RuntimeAcceptedPositionExecutionStatus.DeferredCell,
|
|
drive.TryExecuteAcceptedLocalPosition(
|
|
record,
|
|
parkedUpdate,
|
|
parkedDisposition,
|
|
parkedTimestamps,
|
|
parkedTimestamps.PreviousTeleport));
|
|
Assert.Equal(1, drive.PendingCount);
|
|
Assert.Empty(gameActions);
|
|
|
|
// THE one server correction under test: a second force, into the
|
|
// already-ready spawn landblock, so it commits synchronously. Its
|
|
// merge Forgets the park.
|
|
var corrected = new Vector3(30f, 32f, SpawnHeight);
|
|
WorldSession.EntityPositionUpdate correction = ForceUpdate(
|
|
corrected,
|
|
positionSequence: 3,
|
|
forcePositionSequence: 2);
|
|
(PositionTimestampDisposition disposition, AcceptedPhysicsTimestamps timestamps) =
|
|
MergeAccepted(runtime, controller, correction);
|
|
Assert.Equal(PositionTimestampDisposition.ForcePosition, disposition);
|
|
|
|
Assert.Equal(
|
|
RuntimeAcceptedPositionExecutionStatus.Committed,
|
|
drive.TryExecuteAcceptedLocalPosition(
|
|
record,
|
|
correction,
|
|
disposition,
|
|
timestamps,
|
|
timestamps.PreviousTeleport));
|
|
|
|
Assert.Equal(0, drive.PendingCount);
|
|
Assert.Single(gameActions);
|
|
Assert.Equal(corrected, controller.Position);
|
|
ulong placementsAfterCorrection = record.PlacementCommitVersion;
|
|
|
|
// Every subsequent pump must be a no-op. Before the fix the FIRST of
|
|
// these re-issued the dead park entry: PlacementCommitVersion advanced
|
|
// again and a SECOND AutonomousPosition left for the same correction.
|
|
drive.Advance();
|
|
drive.Advance();
|
|
|
|
Assert.Equal(0, drive.PendingCount);
|
|
Assert.Single(gameActions);
|
|
Assert.Equal(corrected, controller.Position);
|
|
Assert.Equal(placementsAfterCorrection, record.PlacementCommitVersion);
|
|
AssertConverged(runtime);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Round 3 blocker (2026-08-03) — <b>the terminal-without-commit ack</b>.
|
|
/// Retail attempts the placement, and if it fails the body simply does not
|
|
/// move — but the packet is acknowledged regardless and never retried:
|
|
/// <c>SmartBox::BlipPlayer</c> @0x00453940 calls
|
|
/// <c>CPhysicsObj::SetPositionSimple</c> @0x005162B0, which returns an
|
|
/// <c>enum SetPositionError</c> that other retail sites test
|
|
/// (<c>== OK_SPE</c> @0x0055605D) and that <c>BlipPlayer</c> DISCARDS;
|
|
/// <c>BlipPlayer</c> returns <c>void</c>, and its caller
|
|
/// <c>SmartBox::HandleReceivedPosition</c> @0x00453FD0 then runs
|
|
/// <c>cmdinterp->SendPositionEvent()</c> @0x00454091 unconditionally
|
|
/// before returning @0x0045409D.
|
|
///
|
|
/// Unlike
|
|
/// <see cref="Equal_ClearsPendingWithoutReissuingWhenNoNewerAcceptedAuthorityArrived"/>
|
|
/// (whose subject is the no-re-issue decision) this test's subject is the
|
|
/// ack contract itself: EXACTLY one outbound <c>AutonomousPosition</c> for
|
|
/// the failed packet, carrying whatever pose the retired operation left
|
|
/// behind, with no further placement performed by the settle. Before round
|
|
/// 3 this path sent zero — the correction never took AND the server was
|
|
/// never told it had not taken.
|
|
/// </summary>
|
|
[Fact]
|
|
public void TerminalWithoutCommit_SendsExactlyOnePositionEventAndLeavesTheBodyUnmoved()
|
|
{
|
|
using StartedRuntime started = StartRuntime();
|
|
GameRuntime runtime = started.Runtime;
|
|
(RuntimeEntityRecord record, PlayerMovementController controller) =
|
|
EnterLocalPlayer(runtime);
|
|
RuntimeAcceptedPositionDriveController drive =
|
|
CreateAcceptedPositionDrive(runtime, out List<byte[]> gameActions);
|
|
|
|
// The body sits on the spawn landblock's flat terrain, so retail's own
|
|
// CanSendPositionEvent admission (Contact + OnWalkable) is genuinely
|
|
// satisfied — this fixture can observe the ack rather than silently
|
|
// measuring a suppression.
|
|
Assert.True(controller.CanSendPositionEvent);
|
|
|
|
// A force whose destination landblock has no published collision
|
|
// generation parks instead of committing.
|
|
const uint deferredLandblock = 0x02020000u;
|
|
WorldSession.EntityPositionUpdate correction = ForceUpdate(
|
|
new Vector3(10f, 10f, SpawnHeight),
|
|
landblockId: deferredLandblock | 0x0001u);
|
|
(PositionTimestampDisposition disposition, AcceptedPhysicsTimestamps timestamps) =
|
|
MergeAccepted(runtime, controller, correction);
|
|
Assert.Equal(PositionTimestampDisposition.ForcePosition, disposition);
|
|
Assert.Equal(
|
|
RuntimeAcceptedPositionExecutionStatus.DeferredCell,
|
|
drive.TryExecuteAcceptedLocalPosition(
|
|
record,
|
|
correction,
|
|
disposition,
|
|
timestamps,
|
|
timestamps.PreviousTeleport));
|
|
|
|
// Measured, not assumed: this park happens AFTER
|
|
// `_physics.Engine.SetPosition` has already run, so the canonical body
|
|
// already sits at the destination while the placement itself is
|
|
// withdrawn and parked. Specifically it is the engine-result deferral
|
|
// (RuntimeSetPositionState.cs, the park taken once `operation.Result`
|
|
// has been assigned) — NOT either `TryGetBlockingQuiescence` branch:
|
|
// `_collisionPrefixQuiescence` is populated only by
|
|
// `BeginCollisionPrefixQuiescence`, and this fixture's
|
|
// `CommitLandblockCollision` calls `BeginCollisionGeneration` instead,
|
|
// so that map is empty and both quiescence branches are unreachable
|
|
// here. Same side of the engine call either way; the distinction only
|
|
// matters so a future reader does not go looking in the wrong branch.
|
|
// The subject of this test is the TERMINAL SETTLE, so the
|
|
// unmoved/no-further-placement baselines are captured here, at the park.
|
|
Vector3 poseAtPark = controller.Position;
|
|
ulong placementVersionAtPark = record.PlacementCommitVersion;
|
|
|
|
// Nothing has been acknowledged yet: retail's ack follows BlipPlayer,
|
|
// and the placement has not reached any terminal outcome.
|
|
Assert.Empty(gameActions);
|
|
|
|
// The park is retired without ever committing — the exact
|
|
// RuntimeSetPositionState.Forget funnel every mid-session cancellation
|
|
// shares (supersession, the lost-cell deadline, ParkCollisionResidents,
|
|
// a generation change).
|
|
RuntimePlacementCancellationReceipt cancellation =
|
|
runtime.EntityObjects.Physics.SetPosition.Forget(record);
|
|
if (cancellation.IsValid)
|
|
{
|
|
runtime.EntityObjects.Physics.SetPosition
|
|
.PublishCancellation(cancellation);
|
|
}
|
|
|
|
drive.Advance();
|
|
|
|
// Retail's two simultaneous facts at @0x0045409D: the placement did
|
|
// not take (the settle performs no placement of its own — the body is
|
|
// exactly where the retired operation left it and no further
|
|
// placement committed), and the position event went out anyway,
|
|
// carrying that unchanged pose. Before round 3 this path sent zero.
|
|
Assert.Equal(poseAtPark, controller.Position);
|
|
Assert.Equal(placementVersionAtPark, record.PlacementCommitVersion);
|
|
Assert.Single(gameActions);
|
|
Assert.Equal(0, drive.PendingCount);
|
|
|
|
// Retail never retries a force whose placement failed, so no further
|
|
// pump may place OR acknowledge anything more for this packet.
|
|
drive.Advance();
|
|
drive.Advance();
|
|
Assert.Single(gameActions);
|
|
Assert.Equal(poseAtPark, controller.Position);
|
|
Assert.Equal(placementVersionAtPark, record.PlacementCommitVersion);
|
|
AssertConverged(runtime);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Round 3 companion invariant (2026-08-03): the terminal-without-commit
|
|
/// ack must not become a SECOND ack on the committed path. A commit runs
|
|
/// <c>ReconcileAndAcknowledge</c> and then immediately settles through the
|
|
/// same funnel, so a funnel that acknowledged unconditionally would send
|
|
/// two <c>AutonomousPosition</c> messages for one server correction — the
|
|
/// exact duplicate-ack class <c>670f307c</c> deleted. Retail sends exactly
|
|
/// one per handled packet (<c>SmartBox::HandleReceivedPosition</c>
|
|
/// @0x00453FD0 reaches <c>SendPositionEvent</c> @0x00454091 once, then
|
|
/// returns @0x0045409D).
|
|
/// </summary>
|
|
[Fact]
|
|
public void Committed_SendsExactlyOnePositionEventAcrossTheCommitAndTheSettle()
|
|
{
|
|
using StartedRuntime started = StartRuntime();
|
|
GameRuntime runtime = started.Runtime;
|
|
(RuntimeEntityRecord record, PlayerMovementController controller) =
|
|
EnterLocalPlayer(runtime);
|
|
RuntimeAcceptedPositionDriveController drive =
|
|
CreateAcceptedPositionDrive(runtime, out List<byte[]> gameActions);
|
|
|
|
// Within the already-published spawn landblock, so the placement
|
|
// commits synchronously AND the contact gate admits the ack.
|
|
var corrected = new Vector3(30f, 32f, SpawnHeight);
|
|
WorldSession.EntityPositionUpdate correction = ForceUpdate(corrected);
|
|
(PositionTimestampDisposition disposition, AcceptedPhysicsTimestamps timestamps) =
|
|
MergeAccepted(runtime, controller, correction);
|
|
Assert.Equal(PositionTimestampDisposition.ForcePosition, disposition);
|
|
|
|
Assert.Equal(
|
|
RuntimeAcceptedPositionExecutionStatus.Committed,
|
|
drive.TryExecuteAcceptedLocalPosition(
|
|
record,
|
|
correction,
|
|
disposition,
|
|
timestamps,
|
|
timestamps.PreviousTeleport));
|
|
|
|
// One commit, one ack — not two. The settle that runs immediately
|
|
// after the commit must recognise the ack already left.
|
|
Assert.Equal(corrected, controller.Position);
|
|
Assert.Single(gameActions);
|
|
Assert.Equal(0, drive.PendingCount);
|
|
|
|
drive.Advance();
|
|
drive.Advance();
|
|
Assert.Single(gameActions);
|
|
AssertConverged(runtime);
|
|
}
|
|
|
|
private static void AssertConverged(GameRuntime runtime)
|
|
{
|
|
RuntimeEntityObjectOwnershipSnapshot ownership =
|
|
runtime.EntityObjects.CaptureOwnership();
|
|
Assert.Equal(0, ownership.AcceptedPositionDrivePendingCount);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Performs the SAME upstream merge production runs BEFORE this route
|
|
/// ever sees a Position
|
|
/// (<see cref="RuntimeEntityObjectLifetime.TryApplyPosition"/>, called by
|
|
/// <c>LiveEntityInboundAuthorityGate.TryAcceptPosition</c> in App and
|
|
/// directly in <c>RuntimeLiveEntitySessionController.OnPositionUpdated</c>
|
|
/// in headless) — this is what actually admits the disposition via the
|
|
/// REAL <c>PhysicsTimestampGate</c> and substitutes the controller's
|
|
/// current heading into <c>record.Snapshot</c> for a ForcePosition
|
|
/// (contract §1c), rather than hand-rolling a disposition/timestamps pair
|
|
/// the seam's caller could never actually observe.
|
|
/// </summary>
|
|
private static (PositionTimestampDisposition Disposition, AcceptedPhysicsTimestamps Timestamps)
|
|
MergeAccepted(
|
|
GameRuntime runtime,
|
|
PlayerMovementController controller,
|
|
in WorldSession.EntityPositionUpdate update)
|
|
{
|
|
Assert.True(runtime.EntityObjects.TryApplyPosition(
|
|
update,
|
|
isLocalPlayer: true,
|
|
forcePositionRotation: controller.BodyOrientation,
|
|
currentLocalVelocity: controller.BodyVelocity,
|
|
projectionRequiresTeleportHook: false,
|
|
acknowledgeProjection: null,
|
|
out PositionTimestampDisposition disposition,
|
|
out _,
|
|
out AcceptedPhysicsTimestamps timestamps));
|
|
return (disposition, timestamps);
|
|
}
|
|
|
|
/// <summary>
|
|
/// A wire Position whose FORCE_POSITION_TS strictly advances, so the REAL
|
|
/// <see cref="PhysicsTimestampGate.TryAcceptPositionEvent"/> admits it as
|
|
/// <see cref="PositionTimestampDisposition.ForcePosition"/> (retail
|
|
/// <c>SmartBox::HandleReceivedPosition</c> @0x00453FD0's FORCE_POSITION
|
|
/// branch: fresh FORCE_POSITION_TS with an exactly-equal TELEPORT_TS).
|
|
/// The spawn seeds FORCE_POSITION_TS 0 / POSITION_TS 1, so the defaults
|
|
/// are the FIRST such packet; a session's SECOND force must raise
|
|
/// <paramref name="forcePositionSequence"/> again.
|
|
/// </summary>
|
|
private static WorldSession.EntityPositionUpdate ForceUpdate(
|
|
Vector3 position,
|
|
uint landblockId = SpawnLandblock | 0x0001u,
|
|
ushort positionSequence = 2,
|
|
ushort forcePositionSequence = 1) =>
|
|
new(
|
|
PlayerGuid,
|
|
new CreateObject.ServerPosition(
|
|
landblockId,
|
|
position.X,
|
|
position.Y,
|
|
position.Z,
|
|
1f,
|
|
0f,
|
|
0f,
|
|
0f),
|
|
Velocity: null,
|
|
PlacementId: null,
|
|
IsGrounded: true,
|
|
InstanceSequence: 1,
|
|
PositionSequence: positionSequence,
|
|
TeleportSequence: 0,
|
|
ForcePositionSequence: forcePositionSequence);
|
|
|
|
/// <summary>
|
|
/// An ORDINARY server position echo: FORCE_POSITION_TS does NOT advance,
|
|
/// POSITION_TS strictly does, so the same real gate admits it as
|
|
/// <see cref="PositionTimestampDisposition.Apply"/>. Neither host ever
|
|
/// dispatches this disposition to the drive — it merges (advancing
|
|
/// <c>PositionAuthorityVersion</c> and Forgetting any in-flight placement)
|
|
/// entirely behind the drive's back, which is exactly what makes it the
|
|
/// N2 case.
|
|
/// </summary>
|
|
private static WorldSession.EntityPositionUpdate OrdinaryUpdate(
|
|
Vector3 position,
|
|
ushort positionSequence,
|
|
ushort forcePositionSequence = 1,
|
|
uint landblockId = SpawnLandblock | 0x0001u) =>
|
|
ForceUpdate(
|
|
position,
|
|
landblockId,
|
|
positionSequence,
|
|
forcePositionSequence);
|
|
|
|
private static AcceptedPhysicsTimestamps Timestamps(ushort teleport) =>
|
|
new(
|
|
Instance: 1,
|
|
ServerControlledMove: 1,
|
|
Teleport: teleport,
|
|
ForcePosition: 1,
|
|
TeleportAdvanced: false,
|
|
TeleportHookRequired: false,
|
|
PreviousTeleport: teleport);
|
|
|
|
/// <summary>
|
|
/// Spawns the local player, drives its initial-Create residence to
|
|
/// completion, and returns the resulting canonical record + live
|
|
/// controller — the fixture every test above needs before a
|
|
/// ForcePosition can be route-2-eligible at all.
|
|
/// </summary>
|
|
private static (RuntimeEntityRecord Record, PlayerMovementController Controller)
|
|
EnterLocalPlayer(GameRuntime runtime)
|
|
{
|
|
runtime.PlayerIdentity.ServerGuid = PlayerGuid;
|
|
CommitLandblockCollision(runtime, SpawnLandblock);
|
|
RuntimeFirstEntryDriveController firstEntry = CreateFirstEntryDrive(runtime);
|
|
using var session = new WorldSession(
|
|
new IPEndPoint(IPAddress.Loopback, 9000),
|
|
new FixtureTransport());
|
|
var sessionController = new RuntimeLiveEntitySessionController(
|
|
runtime,
|
|
session,
|
|
worldProjection: new FixtureWorldProjection(firstEntry));
|
|
LiveEntitySessionSink sink = sessionController.CreateSink();
|
|
|
|
sink.Spawned(Spawn(PlayerGuid));
|
|
DrainFirstEntry(runtime, firstEntry);
|
|
|
|
RuntimeEntityRecord record = Assert.IsType<RuntimeEntityRecord>(
|
|
GetActive(runtime, PlayerGuid));
|
|
PlayerMovementController controller = Assert.IsType<PlayerMovementController>(
|
|
runtime.MovementOwner.Controller);
|
|
return (record, controller);
|
|
}
|
|
|
|
private static RuntimeEntityRecord GetActive(GameRuntime runtime, uint guid)
|
|
{
|
|
Assert.True(runtime.EntityObjects.Entities.TryGetActive(
|
|
guid, out RuntimeEntityRecord record));
|
|
return record;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Constructs the drive controller with a LIVE (deliberately never
|
|
/// disposed within this factory — it must outlive the whole test)
|
|
/// fixture <see cref="WorldSession"/> whose captured outbound game
|
|
/// actions the caller can assert against.
|
|
/// </summary>
|
|
private static RuntimeAcceptedPositionDriveController CreateAcceptedPositionDrive(
|
|
GameRuntime runtime,
|
|
out List<byte[]> gameActions)
|
|
{
|
|
var captured = new List<byte[]>();
|
|
gameActions = captured;
|
|
var liveSession = new WorldSession(
|
|
new IPEndPoint(IPAddress.Loopback, 9001),
|
|
new FixtureTransport())
|
|
{
|
|
GameActionCapture = body => captured.Add(body),
|
|
};
|
|
return new RuntimeAcceptedPositionDriveController(
|
|
runtime.EntityObjects,
|
|
runtime.Clock,
|
|
new UnusedCollisionSource(),
|
|
new LocalPlayerOutboundController((_, _, _, _, _, _) => { }),
|
|
() => runtime.Generation,
|
|
() => runtime.PlayerIdentity.ServerGuid,
|
|
() => runtime.MovementOwner.Controller,
|
|
() => runtime.CharacterOwner.UsePositionFromServer,
|
|
() => liveSession);
|
|
}
|
|
|
|
/// <summary>
|
|
/// A flat landblock whose terrain surface sits exactly at
|
|
/// <see cref="SpawnHeight"/> — every fixture position in this file uses
|
|
/// that Z so <c>CommitCanonical</c>'s contact resolve genuinely finds
|
|
/// ground (retail <c>CommandInterpreter::SendPositionEvent</c>'s own
|
|
/// admission gate requires Contact+OnWalkable —
|
|
/// <c>PlayerMovementController.CanSendPositionEvent</c> — so an airborne
|
|
/// fixture body would silently suppress every ack this suite asserts).
|
|
/// </summary>
|
|
private static void CommitLandblockCollision(
|
|
GameRuntime runtime,
|
|
uint landblockId)
|
|
{
|
|
// Mirrors HeadlessSessionHostTests.AddFlatLandblock's exact
|
|
// proven-working shape (every heightmap byte and every table entry
|
|
// participate) rather than a sparse table — a resolve near a
|
|
// landblock edge samples neighbouring grid entries too.
|
|
var heights = new byte[81];
|
|
Array.Fill(heights, (byte)SpawnHeight);
|
|
var heightTable = new float[256];
|
|
for (int index = 0; index < heightTable.Length; index++)
|
|
heightTable[index] = index;
|
|
runtime.EntityObjects.Physics.SetPosition.BeginCollisionGeneration(
|
|
landblockId, 1UL);
|
|
runtime.EntityObjects.Physics.Engine.AddLandblock(
|
|
landblockId,
|
|
new TerrainSurface(heights, heightTable),
|
|
Array.Empty<CellSurface>(),
|
|
Array.Empty<PortalPlane>(),
|
|
worldOffsetX: 0f,
|
|
worldOffsetY: 0f);
|
|
runtime.EntityObjects.Physics.SetPosition.CommitCollisionGeneration(
|
|
landblockId, 1UL, ready: true);
|
|
runtime.EntityObjects.Physics.ObserveLocalWorldFrame(
|
|
landblockId | 0x0001u,
|
|
teleportAdvanced: false);
|
|
}
|
|
|
|
private static RuntimeFirstEntryDriveController CreateFirstEntryDrive(
|
|
GameRuntime runtime) =>
|
|
new(
|
|
runtime.EntityObjects,
|
|
runtime.Clock,
|
|
new UnusedCollisionSource(),
|
|
() => PlayerMovementConstructionOptions.Fallback,
|
|
static _ => new RuntimeLocalPlayerPhysicsActivationPreparation(
|
|
Radius: 0.48f,
|
|
Height: 1.835f,
|
|
RuntimeLocalPlayerShadowDisposition.ProvenShapeless));
|
|
|
|
private static void DrainFirstEntry(
|
|
GameRuntime runtime,
|
|
RuntimeFirstEntryDriveController drive)
|
|
{
|
|
for (int attempt = 0; attempt < 8 && drive.PendingCount != 0; attempt++)
|
|
{
|
|
drive.DriveAll();
|
|
DrainPlacementFifo(runtime);
|
|
}
|
|
Assert.Equal(0, drive.PendingCount);
|
|
}
|
|
|
|
private static void DrainPlacementFifo(GameRuntime runtime)
|
|
{
|
|
while (runtime.EntityObjects.Physics.SetPosition.TryPeekProjection(
|
|
out RuntimePlacementProjectionSnapshot head))
|
|
{
|
|
if (!runtime.EntityObjects.Physics.SetPosition
|
|
.AcknowledgeProjection(head.Token))
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
private static WorldSession.EntitySpawn Spawn(uint guid)
|
|
{
|
|
var position = new CreateObject.ServerPosition(
|
|
SpawnLandblock | 0x0001u,
|
|
10f,
|
|
10f,
|
|
5f,
|
|
1f,
|
|
0f,
|
|
0f,
|
|
0f);
|
|
var timestamps = new PhysicsTimestamps(
|
|
Position: 1,
|
|
Movement: 1,
|
|
State: 1,
|
|
Vector: 1,
|
|
Teleport: 0,
|
|
ServerControlledMove: 1,
|
|
ForcePosition: 0,
|
|
ObjDesc: 1,
|
|
Instance: 1);
|
|
var physics = new PhysicsSpawnData(
|
|
RawState: (uint)PhysicsStateFlags.ReportCollisions,
|
|
Position: position,
|
|
Movement: null,
|
|
AnimationFrame: null,
|
|
SetupTableId: null,
|
|
MotionTableId: null,
|
|
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: timestamps);
|
|
return new WorldSession.EntitySpawn(
|
|
guid,
|
|
position,
|
|
null,
|
|
[],
|
|
[],
|
|
[],
|
|
null,
|
|
null,
|
|
"direct entity",
|
|
null,
|
|
null,
|
|
null,
|
|
PhysicsState: physics.RawState,
|
|
InstanceSequence: 1,
|
|
MovementSequence: 1,
|
|
ServerControlSequence: 1,
|
|
PositionSequence: 1,
|
|
Physics: physics);
|
|
}
|
|
|
|
private sealed class UnusedCollisionSource
|
|
: AcDream.Content.IPreparedCollisionSource
|
|
{
|
|
public AcDream.Content.PreparedAssetPresence ProbeCollision(
|
|
AcDream.Content.Pak.PakAssetType type,
|
|
uint sourceFileId) =>
|
|
AcDream.Content.PreparedAssetPresence.Available;
|
|
|
|
public AcDream.Content.PreparedCollisionReadResult<
|
|
FlatSetupCollision> ReadSetupCollision(
|
|
uint sourceFileId,
|
|
CancellationToken cancellationToken = default) =>
|
|
AcDream.Content.PreparedCollisionReadResult<
|
|
FlatSetupCollision>.Missing;
|
|
|
|
public AcDream.Content.PreparedCollisionReadResult<
|
|
FlatGfxObjCollisionAsset> ReadGfxObjCollision(
|
|
uint sourceFileId,
|
|
CancellationToken cancellationToken = default) =>
|
|
throw new NotSupportedException();
|
|
|
|
public AcDream.Content.PreparedCollisionReadResult<
|
|
FlatCellStructureCollisionAsset> ReadCellStructureCollision(
|
|
uint sourceFileId,
|
|
CancellationToken cancellationToken = default) =>
|
|
throw new NotSupportedException();
|
|
|
|
public AcDream.Content.PreparedCollisionReadResult<
|
|
FlatEnvCellTopology> ReadEnvCellTopology(
|
|
uint sourceFileId,
|
|
CancellationToken cancellationToken = default) =>
|
|
throw new NotSupportedException();
|
|
|
|
public AcDream.Content.PreparedCollisionSourceStats CollisionStats =>
|
|
default;
|
|
|
|
public void Dispose()
|
|
{
|
|
}
|
|
}
|
|
|
|
private sealed class FixtureTransport : IWorldSessionTransport
|
|
{
|
|
public void Send(ReadOnlySpan<byte> datagram)
|
|
{
|
|
}
|
|
|
|
public void Send(
|
|
IPEndPoint remote,
|
|
ReadOnlySpan<byte> datagram)
|
|
{
|
|
}
|
|
|
|
public int Receive(
|
|
Span<byte> destination,
|
|
TimeSpan timeout,
|
|
out IPEndPoint? from)
|
|
{
|
|
from = null;
|
|
return -1;
|
|
}
|
|
|
|
public ValueTask<NetReceiveResult> ReceiveAsync(
|
|
Memory<byte> destination,
|
|
CancellationToken cancellationToken) =>
|
|
ValueTask.FromException<NetReceiveResult>(
|
|
new OperationCanceledException(cancellationToken));
|
|
|
|
public void Dispose()
|
|
{
|
|
}
|
|
}
|
|
|
|
private sealed class FixtureWorldProjection : IRuntimeDirectWorldProjection
|
|
{
|
|
private readonly RuntimeFirstEntryDriveController _firstEntry;
|
|
|
|
internal FixtureWorldProjection(RuntimeFirstEntryDriveController firstEntry) =>
|
|
_firstEntry = firstEntry;
|
|
|
|
public void ProjectSpawn(RuntimeEntityRecord record, bool isLocalPlayer) =>
|
|
_firstEntry.DriveAll();
|
|
|
|
public void ProjectPosition(
|
|
RuntimeEntityRecord record,
|
|
bool isLocalPlayer,
|
|
PositionTimestampDisposition disposition)
|
|
{
|
|
}
|
|
|
|
public void CenterOnAcceptedForcePosition(RuntimeEntityRecord record)
|
|
{
|
|
}
|
|
|
|
public void BeginTeleport()
|
|
{
|
|
}
|
|
|
|
public RuntimeDestinationReadiness PrepareDestination(
|
|
long revealGeneration,
|
|
RuntimeTeleportDestination destination) =>
|
|
new(
|
|
revealGeneration,
|
|
destination.CellId,
|
|
IsIndoor: false,
|
|
IsUnhydratable: false,
|
|
RequiredRenderRadius: 1,
|
|
IsRenderNeighborhoodReady: true,
|
|
AreCompositeTexturesReady: true,
|
|
IsCollisionReady: true);
|
|
}
|
|
|
|
/// <summary>
|
|
/// C3c: initial-residence admission requires a live session generation
|
|
/// (RuntimeInitialCreateResidenceState.CanAcceptCreate), so this test
|
|
/// starts one through the same fixture-session shape
|
|
/// DirectGameRuntimeCommandAdapterTests / RuntimeLiveEntitySessionControllerTests use.
|
|
/// </summary>
|
|
private sealed class StartedRuntime : IDisposable
|
|
{
|
|
internal required GameRuntime Runtime { get; init; }
|
|
internal required LiveSessionHost Live { get; init; }
|
|
|
|
public void Dispose()
|
|
{
|
|
_ = Live.Stop(Runtime.Generation);
|
|
Runtime.Dispose();
|
|
}
|
|
}
|
|
|
|
private static StartedRuntime StartRuntime()
|
|
{
|
|
var operations = new FixtureGameplayOperations();
|
|
var sessionOperations = new FixtureSessionOperations();
|
|
var runtime = new GameRuntime(new GameRuntimeDependencies(
|
|
operations,
|
|
operations,
|
|
operations,
|
|
operations,
|
|
SessionOperations: sessionOperations));
|
|
operations.Bind(runtime);
|
|
var resetHost = new FixtureResetHost();
|
|
var options = new LiveSessionConnectOptions(
|
|
true,
|
|
"127.0.0.1",
|
|
9000,
|
|
"account",
|
|
"password");
|
|
var live = new LiveSessionHost(
|
|
runtime.Session,
|
|
new LiveSessionHostBindings(
|
|
new LiveSessionRoutingFactories(
|
|
_ => new FixtureEventRoute(),
|
|
_ => new FixtureCommandRoute()),
|
|
generation => runtime.ResetGeneration(generation, resetHost),
|
|
new LiveSessionSelectionBindings(
|
|
id => runtime.PlayerIdentity.ServerGuid = id,
|
|
_ => { },
|
|
runtime.CommunicationOwner.Chat.SetLocalPlayerGuid,
|
|
_ => { },
|
|
_ => { },
|
|
runtime.ActionOwner.Combat.Clear),
|
|
new LiveSessionEnteredWorldBindings(
|
|
_ => { },
|
|
() => { },
|
|
() => { },
|
|
_ => { },
|
|
() => { }),
|
|
(_, _, _) => { },
|
|
() => { }),
|
|
options);
|
|
LiveSessionStartResult startResult = live.Start(options);
|
|
Assert.Equal(LiveSessionStartStatus.Connected, startResult.Status);
|
|
Assert.NotEqual(0UL, runtime.Generation.Value);
|
|
return new StartedRuntime { Runtime = runtime, Live = live };
|
|
}
|
|
|
|
private sealed class FixtureSessionOperations : ILiveSessionOperations
|
|
{
|
|
public IPEndPoint ResolveEndpoint(string host, int port) =>
|
|
new(IPAddress.Loopback, port);
|
|
|
|
public WorldSession CreateSession(IPEndPoint endpoint) =>
|
|
new(endpoint, new FixtureTransport());
|
|
|
|
public void Connect(WorldSession session, string user, string password)
|
|
{
|
|
}
|
|
|
|
public CharacterList.Parsed GetCharacters(WorldSession session) =>
|
|
new(
|
|
0u,
|
|
[new CharacterList.Character(PlayerGuid, "Direct", 0u)],
|
|
[],
|
|
11,
|
|
"account",
|
|
true,
|
|
true);
|
|
|
|
public void EnterWorld(WorldSession session, int activeCharacterIndex)
|
|
{
|
|
}
|
|
|
|
public void Tick(WorldSession session)
|
|
{
|
|
}
|
|
|
|
public void DisposeSession(WorldSession session) =>
|
|
session.Dispose();
|
|
}
|
|
|
|
private sealed class FixtureEventRoute : ILiveSessionEventRouting
|
|
{
|
|
public void Attach()
|
|
{
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
}
|
|
}
|
|
|
|
private sealed class FixtureCommandRoute : ILiveSessionCommandRouting
|
|
{
|
|
public void Activate()
|
|
{
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
}
|
|
}
|
|
|
|
private sealed class FixtureResetHost : IRuntimeGenerationResetHost
|
|
{
|
|
public void RetireEntityProjection(RuntimeEntityRecord entity)
|
|
{
|
|
}
|
|
|
|
public void DrainEntityProjectionBoundary()
|
|
{
|
|
}
|
|
|
|
public void CompleteEntityProjectionRetirement()
|
|
{
|
|
}
|
|
}
|
|
|
|
private sealed class FixtureGameplayOperations
|
|
: IRuntimeCombatAttackOperations,
|
|
IRuntimeCombatTargetOperations,
|
|
IRuntimeCombatModeOperations,
|
|
IRuntimeSpellCastOperations
|
|
{
|
|
private GameRuntime? _runtime;
|
|
|
|
public void Bind(GameRuntime runtime) => _runtime = runtime;
|
|
public bool CanStartAttack() => false;
|
|
public void PrepareAttackRequest()
|
|
{
|
|
}
|
|
|
|
public bool SendAttack(AttackHeight height, float power) => false;
|
|
public void SendCancelAttack()
|
|
{
|
|
}
|
|
|
|
public bool IsDualWield => false;
|
|
public bool PlayerReadyForAttack => false;
|
|
public bool AutoRepeatAttack => false;
|
|
public bool AutoTarget => false;
|
|
public uint? SelectClosestTarget() => null;
|
|
public bool IsInWorld => _runtime?.Session.IsInWorld == true;
|
|
public IReadOnlyList<ClientObject> GetOrderedEquipment() => [];
|
|
public void NotifyExplicitCombatModeRequest()
|
|
{
|
|
}
|
|
|
|
public void SendChangeCombatMode(CombatMode mode)
|
|
{
|
|
}
|
|
|
|
public uint LocalPlayerId =>
|
|
_runtime?.PlayerIdentity.ServerGuid ?? 0u;
|
|
public bool CanSend => false;
|
|
public bool HasRequiredComponents(uint spellId) => false;
|
|
|
|
public bool IsTargetCompatible(
|
|
uint targetId,
|
|
SpellMetadata spell,
|
|
bool showMessage) => false;
|
|
|
|
public void StopCompletely()
|
|
{
|
|
}
|
|
|
|
public void SendUntargeted(uint spellId)
|
|
{
|
|
}
|
|
|
|
public void SendTargeted(uint targetId, uint spellId)
|
|
{
|
|
}
|
|
|
|
public void DisplayMessage(string message)
|
|
{
|
|
}
|
|
|
|
public void IncrementBusy()
|
|
{
|
|
}
|
|
}
|
|
}
|