fix(streaming): preserve portal destination ownership
Detach old-world spatial ownership atomically, prioritize destination retirement dependencies, and reveal the viewport at the retail transition edge. Give private paperdoll views independent mesh ownership and retain dormant ACE entities so portal revisits preserve server objects without extending active GPU lifetimes.
This commit is contained in:
parent
2c848d4167
commit
823936ec31
57 changed files with 2551 additions and 324 deletions
|
|
@ -254,6 +254,119 @@ public sealed class GpuWorldStateVisibilityTests
|
|||
Assert.Empty(reloaded.Entities);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void OriginRecenterSpatialSwap_RetainsLiveIdentityAndReturnsExactReceipts()
|
||||
{
|
||||
const uint firstLandblock = 0x1010FFFFu;
|
||||
const uint secondLandblock = 0x1011FFFFu;
|
||||
const uint pendingLandblock = 0x2020FFFFu;
|
||||
const uint playerGuid = 0x50000001u;
|
||||
var firstStatic = Entity(100u, 0u);
|
||||
var secondStatic = Entity(101u, 0u);
|
||||
var remote = Entity(1u, 0x70000001u);
|
||||
var pending = Entity(2u, 0x70000002u);
|
||||
var player = Entity(3u, playerGuid);
|
||||
var state = new GpuWorldState();
|
||||
state.AddLandblock(new LoadedLandblock(
|
||||
firstLandblock,
|
||||
new LandBlock(),
|
||||
[firstStatic]));
|
||||
state.AddLandblock(new LoadedLandblock(
|
||||
secondLandblock,
|
||||
new LandBlock(),
|
||||
[secondStatic]));
|
||||
state.PlaceLiveEntityProjection(firstLandblock, remote);
|
||||
state.MarkPersistent(playerGuid);
|
||||
state.PlaceLiveEntityProjection(secondLandblock, player);
|
||||
state.PlaceLiveEntityProjection(pendingLandblock, pending);
|
||||
var edges = new List<(uint Guid, bool Visible)>();
|
||||
state.LiveProjectionVisibilityChanged += (guid, visible) =>
|
||||
edges.Add((guid, visible));
|
||||
|
||||
GpuWorldRecenterRetirement result =
|
||||
state.DetachAllForOriginRecenter();
|
||||
|
||||
Assert.Null(result.ObserverFailure);
|
||||
Assert.Equal(
|
||||
[firstLandblock, secondLandblock, pendingLandblock],
|
||||
result.Landblocks.Select(retirement => retirement.LandblockId));
|
||||
Assert.Contains(
|
||||
result.Landblocks.Single(
|
||||
retirement => retirement.LandblockId == firstLandblock).Entities,
|
||||
entity => ReferenceEquals(entity, firstStatic));
|
||||
Assert.Contains(
|
||||
result.Landblocks.Single(
|
||||
retirement => retirement.LandblockId == firstLandblock).Entities,
|
||||
entity => ReferenceEquals(entity, remote));
|
||||
Assert.Contains(
|
||||
result.Landblocks.Single(
|
||||
retirement => retirement.LandblockId == secondLandblock).Entities,
|
||||
entity => ReferenceEquals(entity, secondStatic));
|
||||
Assert.Contains(
|
||||
result.Landblocks.Single(
|
||||
retirement => retirement.LandblockId == secondLandblock).Entities,
|
||||
entity => ReferenceEquals(entity, player));
|
||||
Assert.Same(
|
||||
pending,
|
||||
Assert.Single(result.Landblocks.Single(
|
||||
retirement => retirement.LandblockId == pendingLandblock).Entities));
|
||||
|
||||
Assert.Empty(state.LoadedLandblockIds);
|
||||
Assert.Empty(state.Entities);
|
||||
Assert.Equal(2, state.PendingLiveEntityCount);
|
||||
Assert.Same(player, Assert.Single(state.DrainRescued()));
|
||||
Assert.Equal(
|
||||
[(remote.ServerGuid, false), (player.ServerGuid, false)],
|
||||
edges);
|
||||
|
||||
state.AddLandblock(new LoadedLandblock(
|
||||
firstLandblock,
|
||||
new LandBlock(),
|
||||
Array.Empty<WorldEntity>()));
|
||||
Assert.Same(remote, Assert.Single(state.Entities));
|
||||
state.AddLandblock(new LoadedLandblock(
|
||||
pendingLandblock,
|
||||
new LandBlock(),
|
||||
Array.Empty<WorldEntity>()));
|
||||
Assert.Contains(state.Entities, entity => ReferenceEquals(entity, pending));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void OriginRecenterSpatialSwap_PreservesCurrentLiveBucketOrder()
|
||||
{
|
||||
const uint landblock = 0x3030FFFFu;
|
||||
var staticEntity = Entity(100u, 0u);
|
||||
var removed = Entity(1u, 0x70000001u);
|
||||
var middle = Entity(2u, 0x70000002u);
|
||||
var movedTail = Entity(3u, 0x70000003u);
|
||||
var state = new GpuWorldState();
|
||||
state.AddLandblock(new LoadedLandblock(
|
||||
landblock,
|
||||
new LandBlock(),
|
||||
[staticEntity]));
|
||||
state.PlaceLiveEntityProjection(landblock, removed);
|
||||
state.PlaceLiveEntityProjection(landblock, middle);
|
||||
state.PlaceLiveEntityProjection(landblock, movedTail);
|
||||
|
||||
// Removing the first live projection swap-moves the tail into its
|
||||
// bucket slot. Dictionary insertion order is now intentionally
|
||||
// different from the canonical bucket order.
|
||||
state.RemoveLiveEntityProjection(removed);
|
||||
Assert.Equal(
|
||||
[staticEntity, movedTail, middle],
|
||||
state.Entities);
|
||||
|
||||
state.DetachAllForOriginRecenter();
|
||||
state.AddLandblock(new LoadedLandblock(
|
||||
landblock,
|
||||
new LandBlock(),
|
||||
[staticEntity]));
|
||||
|
||||
Assert.Equal(
|
||||
[staticEntity, movedTail, middle],
|
||||
state.Entities);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void BatchedVisibilityObserver_SeesCommittedFlatAndResidentViews()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -330,7 +330,7 @@ public sealed class LandblockConcretePresentationPipelineTests
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public void FullRetirement_DetachesFirstAndBalancesEveryConcreteOwner()
|
||||
public void FullRetirement_DetachesAndCleansStaticsWithoutMutatingLiveOwners()
|
||||
{
|
||||
var calls = new List<string>();
|
||||
ConcreteFixture fixture = Fixture(calls);
|
||||
|
|
@ -360,12 +360,13 @@ public sealed class LandblockConcretePresentationPipelineTests
|
|||
Assert.Equal(0, pipeline.PendingRetirementCount);
|
||||
Assert.Equal(0, fixture.Runner.ActiveOwnerCount);
|
||||
Assert.False(fixture.Poses.TryGetRootPose(staticEntity.Id, out _));
|
||||
Assert.Equal(0, fixture.Lights.RegisteredCount);
|
||||
Assert.Single(fixture.Lighting.GetOwnedLights(liveEntity.Id)!);
|
||||
Assert.Null(fixture.Lighting.GetOwnedLights(staticEntity.Id));
|
||||
Assert.False(fixture.Translucency.TryGetCurrentValue(
|
||||
staticEntity.Id,
|
||||
0u,
|
||||
out _));
|
||||
Assert.False(fixture.Translucency.TryGetCurrentValue(
|
||||
Assert.True(fixture.Translucency.TryGetCurrentValue(
|
||||
liveEntity.Id,
|
||||
0u,
|
||||
out _));
|
||||
|
|
|
|||
|
|
@ -101,7 +101,7 @@ public sealed class LandblockPresentationPipelineTests
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public void OriginRecenter_BlocksOriginAndBootstrapUntilEveryOldOwnerConverges()
|
||||
public void OriginRecenter_CommitsAfterDetachWhileOldOwnerCleanupContinues()
|
||||
{
|
||||
const uint centerId = 0x1919FFFFu;
|
||||
const uint neighborId = 0x191AFFFFu;
|
||||
|
|
@ -154,11 +154,63 @@ public sealed class LandblockPresentationPipelineTests
|
|||
Assert.True(Converge(recenter, controller, 0x19, 0x19));
|
||||
|
||||
Assert.Equal((0x22, 0x23), (origin.CenterX, origin.CenterY));
|
||||
Assert.Equal(0, controller.PendingRetirementCount);
|
||||
Assert.Equal(1, controller.PendingRetirementCount);
|
||||
controller.Tick(0x22, 0x23);
|
||||
Assert.Equal(0, controller.PendingRetirementCount);
|
||||
Assert.Equal([0x2223FFFFu], enqueued);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void OriginRecenter_DetachesFullTwentyFiveByTwentyFiveWindowAtomically()
|
||||
{
|
||||
const int radius = 12;
|
||||
const int side = radius * 2 + 1;
|
||||
const int residentCount = side * side;
|
||||
var state = new GpuWorldState();
|
||||
for (int x = 0x40 - radius; x <= 0x40 + radius; x++)
|
||||
for (int y = 0x40 - radius; y <= 0x40 + radius; y++)
|
||||
{
|
||||
uint id = ((uint)x << 24) | ((uint)y << 16) | 0xFFFFu;
|
||||
state.AddLandblock(new LoadedLandblock(
|
||||
id,
|
||||
new LandBlock(),
|
||||
Array.Empty<WorldEntity>()));
|
||||
}
|
||||
|
||||
var origin = new LiveWorldOriginState();
|
||||
Assert.True(origin.TryInitialize(0x40, 0x40));
|
||||
var controller = new StreamingController(
|
||||
enqueueLoad: static (_, _) => { },
|
||||
enqueueUnload: static _ => { },
|
||||
drainCompletions: static _ => Array.Empty<LandblockStreamResult>(),
|
||||
applyTerrain: static (_, _) => { },
|
||||
state,
|
||||
nearRadius: 0,
|
||||
farRadius: 0,
|
||||
workBudgetOptions: new StreamingWorkBudgetOptions(
|
||||
MaxUpdateMilliseconds: 100,
|
||||
MaxCompletionAdmissions: 1,
|
||||
MaxAdoptedCpuBytes: 1,
|
||||
MaxEntityOperations: 1,
|
||||
MaxGpuUploadBytes: 1,
|
||||
MaxGlRetireOperations: 1,
|
||||
DestinationReserveFraction: 0.5f));
|
||||
var recenter = new StreamingOriginRecenterCoordinator(controller, origin);
|
||||
|
||||
Assert.False(recenter.Begin(0x50, 0x50, isSealedDungeon: false));
|
||||
int frames = 0;
|
||||
while (!recenter.Advance() && frames < 8)
|
||||
{
|
||||
controller.Tick(0x40, 0x40);
|
||||
frames++;
|
||||
}
|
||||
|
||||
Assert.InRange(frames, 1, 4);
|
||||
Assert.Empty(state.LoadedLandblockIds);
|
||||
Assert.Equal(residentCount, controller.LastFullWindowRetirementLandblockCount);
|
||||
Assert.Equal((0x50, 0x50), (origin.CenterX, origin.CenterY));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void OriginRecenter_PreparationFailureBeforeDetachRetainsOldOriginAndResidents()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -463,6 +463,146 @@ public sealed class LandblockRetirementCoordinatorTests
|
|||
Assert.Equal(0, coordinator.PendingCount);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void OriginRecenterAdoption_DuplicateReceiptFailsBeforeLedgerMutation()
|
||||
{
|
||||
const uint landblockId = 0x4647FFFFu;
|
||||
var state = new GpuWorldState();
|
||||
int detachedCallbacks = 0;
|
||||
LandblockRetirementCoordinator coordinator =
|
||||
LandblockRetirementCoordinator.CreateBudgeted(
|
||||
state,
|
||||
ticket => AdvancePresentationStep(ticket),
|
||||
ticket => CompletePresentation(ticket),
|
||||
_ => detachedCallbacks++);
|
||||
GpuLandblockRetirement[] receipts =
|
||||
[
|
||||
new(
|
||||
landblockId,
|
||||
LandblockRetirementKind.Full,
|
||||
Array.Empty<WorldEntity>()),
|
||||
new(
|
||||
landblockId & 0xFFFF0000u,
|
||||
LandblockRetirementKind.Full,
|
||||
Array.Empty<WorldEntity>()),
|
||||
];
|
||||
|
||||
Assert.Throws<ArgumentException>(() =>
|
||||
coordinator.AdoptDetachedFull(receipts));
|
||||
|
||||
Assert.Equal(0, coordinator.PendingCount);
|
||||
Assert.False(coordinator.IsPending(landblockId));
|
||||
Assert.Equal(0, detachedCallbacks);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void OriginRecenterAdoption_ObserverFailureRetainsEveryCleanupReceipt()
|
||||
{
|
||||
uint[] landblockIds = [0x4648FFFFu, 0x4649FFFFu];
|
||||
var state = new GpuWorldState();
|
||||
int detachedCallbacks = 0;
|
||||
LandblockRetirementCoordinator coordinator =
|
||||
LandblockRetirementCoordinator.CreateBudgeted(
|
||||
state,
|
||||
ticket => AdvancePresentationStep(ticket),
|
||||
ticket => CompletePresentation(ticket),
|
||||
retirement =>
|
||||
{
|
||||
detachedCallbacks++;
|
||||
if (retirement.LandblockId == landblockIds[0])
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"injected detached observer failure");
|
||||
}
|
||||
});
|
||||
GpuLandblockRetirement[] receipts = landblockIds
|
||||
.Select(id => new GpuLandblockRetirement(
|
||||
id,
|
||||
LandblockRetirementKind.Full,
|
||||
Array.Empty<WorldEntity>()))
|
||||
.ToArray();
|
||||
|
||||
Exception? failure = coordinator.AdoptDetachedFull(receipts);
|
||||
|
||||
Assert.IsType<InvalidOperationException>(failure);
|
||||
Assert.Equal(2, detachedCallbacks);
|
||||
Assert.Equal(2, coordinator.PendingCount);
|
||||
Assert.All(landblockIds, id => Assert.True(coordinator.IsPending(id)));
|
||||
|
||||
int frames = 0;
|
||||
while (coordinator.PendingCount != 0 && frames++ < 64)
|
||||
{
|
||||
var meter = new StreamingWorkMeter(Budget(maxEntityOperations: 64));
|
||||
coordinator.Advance(meter);
|
||||
meter.FinishFrame();
|
||||
}
|
||||
|
||||
Assert.Equal(0, coordinator.PendingCount);
|
||||
Assert.All(landblockIds, id => Assert.False(coordinator.IsPending(id)));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DestinationDependency_CompletesOutOfOrder_WithoutReorderingCleanupFifo()
|
||||
{
|
||||
uint[] landblockIds =
|
||||
[
|
||||
0x5151FFFFu,
|
||||
0x5252FFFFu,
|
||||
0x5353FFFFu,
|
||||
];
|
||||
uint destinationId = landblockIds[2];
|
||||
var terrainOrder = new List<uint>();
|
||||
var state = new GpuWorldState();
|
||||
LandblockRetirementCoordinator coordinator =
|
||||
LandblockRetirementCoordinator.CreateBudgeted(
|
||||
state,
|
||||
ticket =>
|
||||
{
|
||||
if (ticket.NextIncompleteStage
|
||||
== LandblockRetirementStage.Terrain)
|
||||
{
|
||||
return ticket.RunOnceStep(
|
||||
LandblockRetirementStage.Terrain,
|
||||
() => terrainOrder.Add(ticket.LandblockId));
|
||||
}
|
||||
|
||||
return AdvancePresentationStep(ticket);
|
||||
},
|
||||
ticket => CompletePresentation(
|
||||
ticket,
|
||||
terrain: () => terrainOrder.Add(ticket.LandblockId)));
|
||||
GpuLandblockRetirement[] receipts = landblockIds
|
||||
.Select(id => new GpuLandblockRetirement(
|
||||
id,
|
||||
LandblockRetirementKind.Full,
|
||||
Array.Empty<WorldEntity>()))
|
||||
.ToArray();
|
||||
Assert.Null(coordinator.AdoptDetachedFull(receipts));
|
||||
|
||||
var destinationMeter = new StreamingWorkMeter(
|
||||
Budget(maxEntityOperations: 64),
|
||||
destinationReservationActive: true);
|
||||
using (destinationMeter.EnterLane(StreamingWorkLane.Destination))
|
||||
coordinator.AdvancePriority(destinationId, destinationMeter);
|
||||
destinationMeter.FinishFrame();
|
||||
|
||||
Assert.False(coordinator.IsPending(destinationId));
|
||||
Assert.True(coordinator.IsPending(landblockIds[0]));
|
||||
Assert.True(coordinator.IsPending(landblockIds[1]));
|
||||
Assert.Equal(2, coordinator.PendingCount);
|
||||
Assert.Equal([destinationId], terrainOrder);
|
||||
|
||||
var cleanupMeter = new StreamingWorkMeter(
|
||||
Budget(maxEntityOperations: 64));
|
||||
coordinator.Advance(cleanupMeter);
|
||||
cleanupMeter.FinishFrame();
|
||||
|
||||
Assert.Equal(0, coordinator.PendingCount);
|
||||
Assert.Equal(
|
||||
[destinationId, landblockIds[0], landblockIds[1]],
|
||||
terrainOrder);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ObserverFailure_DrainsReentrantDifferentIdBeginBeforeRethrow()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -255,6 +255,26 @@ public sealed class LocalPlayerTeleportControllerTests
|
|||
Assert.False(harness.Reveal.Snapshot.Cancelled);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ExitSound_ReleasesDestinationBeforeHidingTunnelButKeepsProtocolActive()
|
||||
{
|
||||
var order = new List<string>();
|
||||
var harness = new Harness(order: order);
|
||||
harness.Controller.OnTeleportStarted(91);
|
||||
harness.Controller.OfferDestination(
|
||||
Position(0x20210001u, 91, 4f, 5f, 6f),
|
||||
teleportTimestampAdvanced: true);
|
||||
harness.Streaming.ReservationEnds.Clear();
|
||||
harness.Presentation.Enqueue(TeleportAnimEvent.PlayExitSound);
|
||||
|
||||
harness.Controller.Tick(0.016f);
|
||||
|
||||
Assert.False(harness.Presentation.IsPortalViewportVisible);
|
||||
Assert.True(harness.Controller.IsActive);
|
||||
Assert.False(harness.Reveal.Snapshot.Completed);
|
||||
Assert.Single(harness.Streaming.ReservationEnds);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NewerStart_ReplacesOldDestinationWithoutReusingIt()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -110,6 +110,39 @@ public sealed class StreamingCompletionQueueTests
|
|||
Assert.Equal(0, snapshot.OldestAgeMilliseconds);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PriorityCeilingLeavesNearAndFarWorkRetained()
|
||||
{
|
||||
var queue = new StreamingCompletionQueue();
|
||||
StreamingQueuedCompletion near = Completion(
|
||||
new LandblockStreamResult.Failed(20, "near"),
|
||||
StreamingCompletionPriority.Near,
|
||||
sequence: 1);
|
||||
StreamingQueuedCompletion unload = Completion(
|
||||
new LandblockStreamResult.Unloaded(21),
|
||||
StreamingCompletionPriority.Unload,
|
||||
sequence: 2);
|
||||
queue.Enqueue(near);
|
||||
queue.Enqueue(unload);
|
||||
|
||||
Assert.True(queue.TryPeekNext(
|
||||
static _ => false,
|
||||
out StreamingQueuedCompletion? selected,
|
||||
StreamingCompletionPriority.Unload));
|
||||
Assert.Equal(unload.Sequence, selected?.Sequence);
|
||||
queue.RemoveHead(unload);
|
||||
|
||||
Assert.False(queue.TryPeekNext(
|
||||
static _ => false,
|
||||
out selected,
|
||||
StreamingCompletionPriority.Unload));
|
||||
Assert.Equal(1, queue.Count);
|
||||
Assert.True(queue.TryPeekNext(
|
||||
static _ => false,
|
||||
out selected));
|
||||
Assert.Equal(near.Sequence, selected?.Sequence);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ExactReferenceRemovalDoesNotConflateEqualRecords()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -11,6 +11,17 @@ namespace AcDream.App.Tests.Streaming;
|
|||
|
||||
public sealed class StreamingWorkBudgetTests
|
||||
{
|
||||
[Fact]
|
||||
public void DefaultProfile_UsesElapsedTimeAsTheMicroOperationGuard()
|
||||
{
|
||||
Assert.Equal(
|
||||
4_096,
|
||||
StreamingWorkBudgetOptions.Default.MaxEntityOperations);
|
||||
Assert.Equal(
|
||||
2.0,
|
||||
StreamingWorkBudgetOptions.Default.MaxUpdateMilliseconds);
|
||||
}
|
||||
|
||||
private static StreamingWorkBudget Budget(
|
||||
double milliseconds = 2,
|
||||
int completions = 4,
|
||||
|
|
@ -563,15 +574,17 @@ public sealed class StreamingWorkBudgetTests
|
|||
|
||||
Assert.Equal([center], applied);
|
||||
Assert.Equal(1, controller.WorkDiagnostics.DeferredCompletions);
|
||||
Assert.Equal(2, controller.WorkDiagnostics.LastFrame.YieldCount);
|
||||
Assert.Equal(1, controller.WorkDiagnostics.LastFrame.YieldCount);
|
||||
Assert.Equal(44, controller.WorkDiagnostics.LastFrame.Used.GpuUploadBytes);
|
||||
Assert.Equal(0, controller.WorkDiagnostics.LastFrame.Used.GlRetireOperations);
|
||||
|
||||
controller.Tick(32, 32);
|
||||
|
||||
Assert.Equal([center, ordinary], applied);
|
||||
Assert.Equal([center], applied);
|
||||
Assert.Equal(1, controller.WorkDiagnostics.DeferredCompletions);
|
||||
Assert.Equal(0, controller.WorkDiagnostics.LastFrame.Used.GlRetireOperations);
|
||||
|
||||
controller.EndDestinationReservation(1);
|
||||
for (int i = 0;
|
||||
i < 4
|
||||
&& (controller.WorkDiagnostics.DeferredCompletions != 0
|
||||
|
|
@ -586,13 +599,51 @@ public sealed class StreamingWorkBudgetTests
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public void StaleGenerationResultsConsumeAdmissionButRetainNoPayload()
|
||||
public void IncompleteReveal_DoesNotStarveOrdinaryWorkBeforeDestinationArrives()
|
||||
{
|
||||
uint center = StreamingRegion.EncodeLandblockIdForTest(32, 32);
|
||||
var source = new QueueCompletionSource(
|
||||
Loaded(center, generation: 1),
|
||||
Loaded(StreamingRegion.EncodeLandblockIdForTest(32, 33), generation: 1),
|
||||
Loaded(center));
|
||||
uint ordinary = StreamingRegion.EncodeLandblockIdForTest(33, 33);
|
||||
var source = new QueueCompletionSource(Loaded(ordinary));
|
||||
var applied = new List<uint>();
|
||||
StreamingController controller = Controller(
|
||||
source,
|
||||
id => applied.Add(id),
|
||||
WorkOptions(admissions: 4, cpuBytes: 1_000));
|
||||
controller.BeginDestinationReservation(1, center, 0);
|
||||
|
||||
controller.Tick(32, 32);
|
||||
|
||||
Assert.Equal([ordinary], applied);
|
||||
Assert.Equal(0, controller.WorkDiagnostics.NearBacklog);
|
||||
|
||||
source.Enqueue(Loaded(center));
|
||||
controller.Tick(32, 32);
|
||||
|
||||
Assert.Equal([ordinary, center], applied);
|
||||
Assert.Equal(0, controller.WorkDiagnostics.NearBacklog);
|
||||
|
||||
controller.EndDestinationReservation(1);
|
||||
controller.Tick(32, 32);
|
||||
|
||||
Assert.Equal([ordinary, center], applied);
|
||||
Assert.Equal(0, controller.WorkDiagnostics.DeferredCompletions);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void StaleGenerationResultsDrainWithoutStarvingCurrentGeneration()
|
||||
{
|
||||
uint center = StreamingRegion.EncodeLandblockIdForTest(32, 32);
|
||||
LandblockStreamResult[] results =
|
||||
[
|
||||
.. Enumerable.Range(0, 625)
|
||||
.Select(index => Loaded(
|
||||
StreamingRegion.EncodeLandblockIdForTest(
|
||||
32 + index % 25,
|
||||
32 + index / 25),
|
||||
generation: 1)),
|
||||
Loaded(center),
|
||||
];
|
||||
var source = new QueueCompletionSource(results);
|
||||
int applied = 0;
|
||||
StreamingController controller = Controller(
|
||||
source,
|
||||
|
|
@ -601,15 +652,12 @@ public sealed class StreamingWorkBudgetTests
|
|||
|
||||
controller.Tick(32, 32);
|
||||
|
||||
Assert.Equal(0, applied);
|
||||
Assert.Equal(1, source.BacklogCount);
|
||||
Assert.Equal(1, applied);
|
||||
Assert.Equal(0, source.BacklogCount);
|
||||
Assert.Equal(0, controller.WorkDiagnostics.DeferredCompletions);
|
||||
Assert.Equal(0, controller.WorkDiagnostics.DeferredAdoptedCpuBytes);
|
||||
Assert.Equal(2, controller.WorkDiagnostics.LastFrame.Used.CompletionAdmissions);
|
||||
Assert.Equal(0, controller.WorkDiagnostics.LastFrame.Used.AdoptedCpuBytes);
|
||||
|
||||
controller.Tick(32, 32);
|
||||
Assert.Equal(1, applied);
|
||||
Assert.Equal(1, controller.WorkDiagnostics.LastFrame.Used.CompletionAdmissions);
|
||||
Assert.Equal(44, controller.WorkDiagnostics.LastFrame.Used.AdoptedCpuBytes);
|
||||
}
|
||||
|
||||
private static StreamingController Controller(
|
||||
|
|
@ -688,6 +736,9 @@ public sealed class StreamingWorkBudgetTests
|
|||
|
||||
public int BacklogCount => _results.Count;
|
||||
|
||||
public void Enqueue(LandblockStreamResult result) =>
|
||||
_results.Enqueue(result);
|
||||
|
||||
public bool TryPeek(out LandblockStreamResult? result)
|
||||
{
|
||||
if (_results.TryPeek(out LandblockStreamResult? peeked))
|
||||
|
|
|
|||
|
|
@ -15,7 +15,8 @@ public sealed class WorldRevealCoordinatorTests
|
|||
|
||||
public WorldRevealCoordinator Build(
|
||||
List<string>? logs = null,
|
||||
IWorldRevealStreamingScheduler? streaming = null) => new(
|
||||
IWorldRevealStreamingScheduler? streaming = null,
|
||||
IWorldRevealRenderResourceScheduler? renderResources = null) => new(
|
||||
isRenderNeighborhoodReady: (_, _) => RenderReady,
|
||||
isSpawnCellReady: _ => CollisionReady,
|
||||
isTerrainNeighborhoodReady: (_, _) => CollisionReady,
|
||||
|
|
@ -28,7 +29,8 @@ public sealed class WorldRevealCoordinatorTests
|
|||
},
|
||||
isSpawnClaimUnhydratable: _ => false,
|
||||
log: logs is null ? null : new Action<string>(logs.Add),
|
||||
streaming: streaming);
|
||||
streaming: streaming,
|
||||
renderResources: renderResources);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -152,6 +154,47 @@ public sealed class WorldRevealCoordinatorTests
|
|||
Assert.Equal(1, audio.ResumeCalls);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PortalViewportReveal_ReopensWorldWithoutCompletingProtocolTail()
|
||||
{
|
||||
var availability = new WorldGenerationAvailabilityState();
|
||||
var world = new GpuWorldState(availability: availability);
|
||||
var audio = new RecordingAudioQuiescence();
|
||||
var quiescence = new WorldGenerationQuiescence(
|
||||
availability,
|
||||
new SelectionState(),
|
||||
world,
|
||||
audio);
|
||||
var scheduler = new RecordingDestinationScheduler();
|
||||
var coordinator = new WorldRevealCoordinator(
|
||||
isRenderNeighborhoodReady: (_, _) => true,
|
||||
isSpawnCellReady: _ => true,
|
||||
isTerrainNeighborhoodReady: (_, _) => true,
|
||||
areCompositeTexturesReady: () => true,
|
||||
prepareCompositeTextures: (_, _) => { },
|
||||
invalidateCompositeTextures: () => { },
|
||||
isSpawnClaimUnhydratable: _ => false,
|
||||
quiescence: quiescence,
|
||||
streaming: scheduler);
|
||||
long generation = coordinator.Begin(
|
||||
WorldRevealKind.Portal,
|
||||
0x3032001Cu);
|
||||
|
||||
coordinator.RevealWorldViewport();
|
||||
coordinator.RevealWorldViewport();
|
||||
|
||||
Assert.True(availability.IsWorldAvailable);
|
||||
Assert.False(coordinator.Snapshot.Completed);
|
||||
Assert.Equal(1, audio.ResumeCalls);
|
||||
Assert.Equal([generation], scheduler.Ends);
|
||||
|
||||
coordinator.Complete();
|
||||
|
||||
Assert.True(coordinator.Snapshot.Completed);
|
||||
Assert.Equal(1, audio.ResumeCalls);
|
||||
Assert.Equal([generation], scheduler.Ends);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RevealGeneration_OwnsExactDestinationReservationUntilCompletion()
|
||||
{
|
||||
|
|
@ -176,6 +219,28 @@ public sealed class WorldRevealCoordinatorTests
|
|||
Assert.Equal([second], scheduler.Ends);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RevealGeneration_OwnsRenderUploadProfileUntilViewportRelease()
|
||||
{
|
||||
var state = new State();
|
||||
var resources = new RecordingRenderResourceScheduler();
|
||||
WorldRevealCoordinator coordinator =
|
||||
state.Build(renderResources: resources);
|
||||
|
||||
long first = coordinator.Begin(
|
||||
WorldRevealKind.Portal,
|
||||
0x11340021u);
|
||||
long second = coordinator.Begin(
|
||||
WorldRevealKind.Portal,
|
||||
0x20210123u);
|
||||
|
||||
Assert.Equal([first, second], resources.Begins);
|
||||
coordinator.RevealWorldViewport();
|
||||
coordinator.Complete();
|
||||
|
||||
Assert.Equal([second], resources.Ends);
|
||||
}
|
||||
|
||||
private sealed class RecordingAudioQuiescence : AcDream.App.Audio.IWorldAudioQuiescence
|
||||
{
|
||||
public int SuspendCalls { get; private set; }
|
||||
|
|
@ -201,4 +266,17 @@ public sealed class WorldRevealCoordinatorTests
|
|||
public void EndDestinationReservation(long revealGeneration) =>
|
||||
Ends.Add(revealGeneration);
|
||||
}
|
||||
|
||||
private sealed class RecordingRenderResourceScheduler
|
||||
: IWorldRevealRenderResourceScheduler
|
||||
{
|
||||
public List<long> Begins { get; } = [];
|
||||
public List<long> Ends { get; } = [];
|
||||
|
||||
public void BeginDestinationReveal(long revealGeneration) =>
|
||||
Begins.Add(revealGeneration);
|
||||
|
||||
public void EndDestinationReveal(long revealGeneration) =>
|
||||
Ends.Add(revealGeneration);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue