fix: complete retail parity stability pass
All checks were successful
CI / linux-portable (push) Successful in 3m41s
CI / windows-gate (push) Successful in 6m49s
CI / release (push) Successful in 3m22s

This commit is contained in:
Erik 2026-08-28 20:01:39 +02:00
parent d3df4cb20a
commit f7aa8e0eb7
131 changed files with 7765 additions and 1190 deletions

View file

@ -116,6 +116,73 @@ public sealed class RuntimeSetPositionStateTests
Assert.Equal(1, ownership.PreparedMoverCount);
}
[Fact]
public void WarmedPendingProjectionRetryDoesNotAllocateSnapshotArray()
{
PhysicsEngine engine = FlatEngine(SourceLandblock, 0f);
using var lifetime = new RuntimeEntityObjectLifetime(engine);
RuntimeEntityRecord record = CreateRecord(lifetime, 0x70001042u, 1);
_ = AttachBody(lifetime, record, SourceCell);
var observer = new CountingPlacementObserver();
using IDisposable subscription = lifetime.Events.SubscribePlacement(observer);
RuntimeSetPositionOutcome outcome = lifetime.Physics.SetPosition.Apply(
record,
record.PositionAuthorityVersion,
Command(Request(SourceCell, new Vector3(13f, 18f, 7f))));
// Prime both retained retry scratch and the event stream's dispatch
// storage before measuring the normal N>0 per-tick path.
lifetime.Physics.SetPosition.RetryPendingProjections();
const int iterations = 256;
_ = GC.GetAllocatedBytesForCurrentThread();
long before = GC.GetAllocatedBytesForCurrentThread();
for (int iteration = 0; iteration < iterations; iteration++)
lifetime.Physics.SetPosition.RetryPendingProjections();
long allocated = GC.GetAllocatedBytesForCurrentThread() - before;
// The event stream itself currently costs 72 B/publication. The old
// Values.ToArray snapshot raised this exact fixture to 424 B/retry;
// keep enough runtime variance for the dispatch floor while making a
// fresh projection array (or equivalent regression) fail loudly.
Assert.InRange(allocated / iterations, 0L, 128L);
Assert.Equal(iterations + 2, observer.Count);
Assert.True(lifetime.Physics.SetPosition.AcknowledgeProjection(
outcome.Projection));
}
[Fact]
public void PendingProjectionRetryKeepsIndependentSnapshotWhenReentered()
{
PhysicsEngine engine = FlatEngine(SourceLandblock, 0f);
using var lifetime = new RuntimeEntityObjectLifetime(engine);
RuntimeEntityRecord record = CreateRecord(lifetime, 0x70001044u, 1);
_ = AttachBody(lifetime, record, SourceCell);
bool retrying = false;
bool nested = false;
var observer = new PlacementObserver(_ =>
{
if (!retrying || nested)
return;
nested = true;
lifetime.Physics.SetPosition.RetryPendingProjections();
});
using IDisposable subscription = lifetime.Events.SubscribePlacement(observer);
RuntimeSetPositionOutcome outcome = lifetime.Physics.SetPosition.Apply(
record,
record.PositionAuthorityVersion,
Command(Request(SourceCell, new Vector3(13f, 19f, 7f))));
retrying = true;
lifetime.Physics.SetPosition.RetryPendingProjections();
Assert.True(nested);
Assert.Equal(3, observer.Deltas.Count);
Assert.All(observer.Deltas,
delta => Assert.Equal(outcome.Projection, delta.Placement.Token));
Assert.True(lifetime.Physics.SetPosition.AcknowledgeProjection(
outcome.Projection));
}
[Theory]
[InlineData(PhysicsStateFlags.Hidden)]
[InlineData(PhysicsStateFlags.Hidden | PhysicsStateFlags.NoDraw)]
@ -3648,6 +3715,13 @@ public sealed class RuntimeSetPositionStateTests
}
}
private sealed class CountingPlacementObserver : IRuntimePlacementObserver
{
internal int Count { get; private set; }
public void OnPlacement(in RuntimePlacementDelta delta) => Count++;
}
/// <summary>
/// C0-3 test double: a minimal <see cref="IPreparedCollisionSource"/>
/// serving exactly one Setup id (matching <c>CanonicalSetupTableId</c>'s