fix(rendering): bound portal resource lifetime
Separate logical ownership, render publication, and GPU retirement across live entities, landblocks, particles, textures, mesh arenas, portal/UI teardown, and per-frame scratch storage. Add bounded DAT/texture caches, upload budgets, three-frame fence retirement, exact-incarnation appearance reconciliation, frame pacing, and extensive lifetime conformance coverage.\n\nThe seven-destination connected route now cuts peak working/private memory roughly in half, returns Caul to 125-153 FPS locally, and produces no WER or AMD reset.\n\nCo-authored-by: OpenAI Codex <codex@openai.com>
This commit is contained in:
parent
3971997689
commit
749e8ceeb1
225 changed files with 29107 additions and 3914 deletions
|
|
@ -0,0 +1,77 @@
|
|||
using System.Numerics;
|
||||
using AcDream.App.Streaming;
|
||||
using AcDream.Core.World;
|
||||
using DatReaderWriter.DBObjs;
|
||||
|
||||
namespace AcDream.App.Tests.Streaming;
|
||||
|
||||
public sealed class GpuWorldStateAnimatedIndexTests
|
||||
{
|
||||
private const uint Landblock = 0x0101FFFFu;
|
||||
|
||||
[Fact]
|
||||
public void StableLandblock_ReusesAnimatedIndexAcrossFrames()
|
||||
{
|
||||
var state = new GpuWorldState();
|
||||
WorldEntity entity = Entity(1u, 0u);
|
||||
state.AddLandblock(Loaded(entity));
|
||||
|
||||
IReadOnlyDictionary<uint, WorldEntity>? first = SingleIndex(state);
|
||||
IReadOnlyDictionary<uint, WorldEntity>? second = SingleIndex(state);
|
||||
|
||||
Assert.Same(first, second);
|
||||
Assert.Same(entity, first![entity.Id]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ReplacedLandblockRecord_RebuildsOnlyThatGeneration()
|
||||
{
|
||||
var state = new GpuWorldState();
|
||||
WorldEntity original = Entity(1u, 0u);
|
||||
WorldEntity live = Entity(2u, 0x70000002u);
|
||||
state.AddLandblock(Loaded(original));
|
||||
IReadOnlyDictionary<uint, WorldEntity>? first = SingleIndex(state);
|
||||
|
||||
state.PlaceLiveEntityProjection(Landblock, live);
|
||||
IReadOnlyDictionary<uint, WorldEntity>? second = SingleIndex(state);
|
||||
|
||||
Assert.NotSame(first, second);
|
||||
Assert.Same(original, second![original.Id]);
|
||||
Assert.Same(live, second[live.Id]);
|
||||
Assert.Same(second, SingleIndex(state));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RemoveThenReload_DoesNotRetainRemovedGeneration()
|
||||
{
|
||||
var state = new GpuWorldState();
|
||||
WorldEntity removed = Entity(1u, 0u);
|
||||
state.AddLandblock(Loaded(removed));
|
||||
IReadOnlyDictionary<uint, WorldEntity>? first = SingleIndex(state);
|
||||
|
||||
state.RemoveLandblock(Landblock);
|
||||
WorldEntity replacement = Entity(2u, 0u);
|
||||
state.AddLandblock(Loaded(replacement));
|
||||
IReadOnlyDictionary<uint, WorldEntity>? second = SingleIndex(state);
|
||||
|
||||
Assert.NotSame(first, second);
|
||||
Assert.False(second!.ContainsKey(removed.Id));
|
||||
Assert.Same(replacement, second[replacement.Id]);
|
||||
}
|
||||
|
||||
private static IReadOnlyDictionary<uint, WorldEntity>? SingleIndex(GpuWorldState state) =>
|
||||
Assert.Single(state.LandblockEntries).AnimatedById;
|
||||
|
||||
private static LoadedLandblock Loaded(params WorldEntity[] entities) =>
|
||||
new(Landblock, new LandBlock(), entities);
|
||||
|
||||
private static WorldEntity Entity(uint id, uint serverGuid) => new()
|
||||
{
|
||||
Id = id,
|
||||
ServerGuid = serverGuid,
|
||||
SourceGfxObjOrSetupId = 0x02000001u,
|
||||
Position = Vector3.Zero,
|
||||
Rotation = Quaternion.Identity,
|
||||
MeshRefs = Array.Empty<MeshRef>(),
|
||||
};
|
||||
}
|
||||
|
|
@ -11,6 +11,361 @@ namespace AcDream.App.Tests.Streaming;
|
|||
|
||||
public sealed class GpuWorldStateVisibilityTests
|
||||
{
|
||||
[Fact]
|
||||
public void PendingSpawnFlood_DoesNotPublishOrRebuildLoadedView()
|
||||
{
|
||||
const uint landblock = 0x0101FFFFu;
|
||||
const int count = 10_000;
|
||||
var state = new GpuWorldState();
|
||||
int edges = 0;
|
||||
state.LiveProjectionVisibilityChanged += (_, _) => edges++;
|
||||
long commitsBefore = state.VisibilityCommitCount;
|
||||
|
||||
using (state.BeginMutationBatch())
|
||||
{
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
state.PlaceLiveEntityProjection(
|
||||
landblock,
|
||||
Entity((uint)(i + 1), 0x70000000u + (uint)i));
|
||||
}
|
||||
|
||||
Assert.Empty(state.Entities);
|
||||
Assert.Equal(count, state.PendingLiveEntityCount);
|
||||
Assert.Equal(commitsBefore, state.VisibilityCommitCount);
|
||||
Assert.Equal(0, edges);
|
||||
}
|
||||
|
||||
Assert.Empty(state.Entities);
|
||||
Assert.Equal(count, state.PendingLiveEntityCount);
|
||||
Assert.Equal(commitsBefore + 1, state.VisibilityCommitCount);
|
||||
Assert.Equal(0, edges);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LoadedSpawnFlood_AppendsInPlaceAndPublishesOneBatch()
|
||||
{
|
||||
const uint landblock = 0x0101FFFFu;
|
||||
const int count = 10_000;
|
||||
var state = new GpuWorldState();
|
||||
state.AddLandblock(new LoadedLandblock(
|
||||
landblock,
|
||||
new LandBlock(),
|
||||
Array.Empty<WorldEntity>()));
|
||||
Assert.True(state.TryGetLandblock(landblock, out LoadedLandblock? loaded));
|
||||
IReadOnlyList<WorldEntity> residentBucket = loaded!.Entities;
|
||||
int edges = 0;
|
||||
state.LiveProjectionVisibilityChanged += (_, visible) =>
|
||||
{
|
||||
Assert.True(visible);
|
||||
edges++;
|
||||
};
|
||||
long commitsBefore = state.VisibilityCommitCount;
|
||||
|
||||
using (state.BeginMutationBatch())
|
||||
{
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
state.PlaceLiveEntityProjection(
|
||||
landblock,
|
||||
Entity((uint)(i + 1), 0x71000000u + (uint)i));
|
||||
}
|
||||
|
||||
Assert.Same(residentBucket, loaded.Entities);
|
||||
Assert.Equal(count, residentBucket.Count);
|
||||
Assert.Equal(count, state.Entities.Count);
|
||||
Assert.Equal(0, edges);
|
||||
Assert.Equal(commitsBefore, state.VisibilityCommitCount);
|
||||
}
|
||||
|
||||
Assert.Equal(count, edges);
|
||||
Assert.Equal(commitsBefore + 1, state.VisibilityCommitCount);
|
||||
Assert.Equal(count, state.Entities.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DenseSameBucketRebucketAndDelete_PreserveEveryProjectionIndex()
|
||||
{
|
||||
const uint sourceLandblock = 0x0101FFFFu;
|
||||
const uint targetLandblock = 0x0202FFFFu;
|
||||
const int count = 10_000;
|
||||
var state = new GpuWorldState();
|
||||
state.AddLandblock(new LoadedLandblock(
|
||||
sourceLandblock,
|
||||
new LandBlock(),
|
||||
Array.Empty<WorldEntity>()));
|
||||
state.AddLandblock(new LoadedLandblock(
|
||||
targetLandblock,
|
||||
new LandBlock(),
|
||||
Array.Empty<WorldEntity>()));
|
||||
var entities = new WorldEntity[count];
|
||||
using (state.BeginMutationBatch())
|
||||
{
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
entities[i] = Entity((uint)(i + 1), 0x72000000u + (uint)i);
|
||||
state.PlaceLiveEntityProjection(sourceLandblock, entities[i]);
|
||||
}
|
||||
}
|
||||
|
||||
using (state.BeginMutationBatch())
|
||||
{
|
||||
for (int i = 0; i < count; i++)
|
||||
state.RebucketLiveEntity(entities[i], targetLandblock);
|
||||
}
|
||||
|
||||
Assert.True(state.TryGetLandblock(sourceLandblock, out LoadedLandblock? source));
|
||||
Assert.True(state.TryGetLandblock(targetLandblock, out LoadedLandblock? target));
|
||||
Assert.Empty(source!.Entities);
|
||||
Assert.Equal(count, target!.Entities.Count);
|
||||
Assert.Equal(count, state.Entities.Count);
|
||||
|
||||
using (state.BeginMutationBatch())
|
||||
{
|
||||
for (int i = 0; i < count; i++)
|
||||
state.RemoveLiveEntityProjection(entities[i]);
|
||||
}
|
||||
|
||||
Assert.Empty(target.Entities);
|
||||
Assert.Empty(state.Entities);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DenseDemotion_CompactsLiveEntriesAndKeepsTheirIndexesValid()
|
||||
{
|
||||
const uint sourceLandblock = 0x0101FFFFu;
|
||||
const uint targetLandblock = 0x0202FFFFu;
|
||||
const int liveCount = 2_000;
|
||||
var state = new GpuWorldState();
|
||||
var mixed = new List<WorldEntity>(liveCount * 2);
|
||||
var live = new List<WorldEntity>(liveCount);
|
||||
for (int i = 0; i < liveCount; i++)
|
||||
{
|
||||
mixed.Add(Entity(0xC1000000u + (uint)i, 0u));
|
||||
WorldEntity projection = Entity((uint)(i + 1), 0x73000000u + (uint)i);
|
||||
mixed.Add(projection);
|
||||
live.Add(projection);
|
||||
}
|
||||
state.AddLandblock(new LoadedLandblock(
|
||||
sourceLandblock,
|
||||
new LandBlock(),
|
||||
mixed));
|
||||
state.AddLandblock(new LoadedLandblock(
|
||||
targetLandblock,
|
||||
new LandBlock(),
|
||||
Array.Empty<WorldEntity>()));
|
||||
|
||||
state.RemoveEntitiesFromLandblock(sourceLandblock);
|
||||
|
||||
Assert.True(state.TryGetLandblock(sourceLandblock, out LoadedLandblock? source));
|
||||
Assert.Equal(liveCount, source!.Entities.Count);
|
||||
Assert.All(source.Entities, entity => Assert.NotEqual(0u, entity.ServerGuid));
|
||||
|
||||
using (state.BeginMutationBatch())
|
||||
{
|
||||
foreach (WorldEntity entity in live)
|
||||
state.RebucketLiveEntity(entity, targetLandblock);
|
||||
}
|
||||
|
||||
Assert.Empty(source.Entities);
|
||||
Assert.True(state.TryGetLandblock(targetLandblock, out LoadedLandblock? target));
|
||||
Assert.Equal(liveCount, target!.Entities.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PendingDemotion_CompactsMixedStaticAndLiveEntriesAndKeepsLiveIndexesValid()
|
||||
{
|
||||
const uint pendingLandblock = 0x0101FFFFu;
|
||||
const uint targetLandblock = 0x0202FFFFu;
|
||||
var state = new GpuWorldState();
|
||||
WorldEntity first = Entity(1u, 0x73500001u);
|
||||
WorldEntity second = Entity(2u, 0x73500002u);
|
||||
WorldEntity[] mixed =
|
||||
[
|
||||
Entity(0xC1000001u, 0u),
|
||||
first,
|
||||
Entity(0xC1000002u, 0u),
|
||||
second,
|
||||
];
|
||||
|
||||
Assert.False(state.AddEntitiesToExistingLandblock(pendingLandblock, mixed));
|
||||
Assert.Equal(4, state.PendingLiveEntityCount);
|
||||
|
||||
state.RemoveEntitiesFromLandblock(pendingLandblock);
|
||||
|
||||
Assert.Equal(2, state.PendingLiveEntityCount);
|
||||
state.AddLandblock(new LoadedLandblock(
|
||||
pendingLandblock,
|
||||
new LandBlock(),
|
||||
Array.Empty<WorldEntity>()));
|
||||
state.AddLandblock(new LoadedLandblock(
|
||||
targetLandblock,
|
||||
new LandBlock(),
|
||||
Array.Empty<WorldEntity>()));
|
||||
|
||||
Assert.True(state.TryGetLandblock(pendingLandblock, out LoadedLandblock? pending));
|
||||
Assert.Equal([first, second], pending!.Entities);
|
||||
|
||||
state.RebucketLiveEntity(first, targetLandblock);
|
||||
state.RebucketLiveEntity(second, targetLandblock);
|
||||
|
||||
Assert.Empty(pending.Entities);
|
||||
Assert.True(state.TryGetLandblock(targetLandblock, out LoadedLandblock? target));
|
||||
Assert.Equal(2, target!.Entities.Count);
|
||||
Assert.Contains(first, target.Entities);
|
||||
Assert.Contains(second, target.Entities);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UnloadToPendingThenReload_PreservesProjectionIdentityAndVisibilityEdges()
|
||||
{
|
||||
const uint landblock = 0x0101FFFFu;
|
||||
var state = new GpuWorldState();
|
||||
state.AddLandblock(new LoadedLandblock(
|
||||
landblock,
|
||||
new LandBlock(),
|
||||
Array.Empty<WorldEntity>()));
|
||||
WorldEntity entity = Entity(1u, 0x73600001u);
|
||||
state.PlaceLiveEntityProjection(landblock, entity);
|
||||
var edges = new List<(uint Guid, bool Visible)>();
|
||||
state.LiveProjectionVisibilityChanged += (guid, visible) => edges.Add((guid, visible));
|
||||
|
||||
state.RemoveLandblock(landblock);
|
||||
|
||||
Assert.Empty(state.Entities);
|
||||
Assert.Equal(1, state.PendingLiveEntityCount);
|
||||
Assert.False(state.IsLiveEntityVisible(entity.ServerGuid));
|
||||
|
||||
state.AddLandblock(new LoadedLandblock(
|
||||
landblock,
|
||||
new LandBlock(),
|
||||
Array.Empty<WorldEntity>()));
|
||||
|
||||
Assert.Same(entity, Assert.Single(state.Entities));
|
||||
Assert.True(state.TryGetLandblock(landblock, out LoadedLandblock? reloaded));
|
||||
Assert.Same(entity, Assert.Single(reloaded!.Entities));
|
||||
Assert.True(state.IsLiveEntityVisible(entity.ServerGuid));
|
||||
Assert.Equal(
|
||||
[(entity.ServerGuid, false), (entity.ServerGuid, true)],
|
||||
edges);
|
||||
|
||||
state.RemoveLiveEntityProjection(entity);
|
||||
Assert.Empty(state.Entities);
|
||||
Assert.Empty(reloaded.Entities);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void BatchedVisibilityObserver_SeesCommittedFlatAndResidentViews()
|
||||
{
|
||||
const uint landblock = 0x0101FFFFu;
|
||||
var state = new GpuWorldState();
|
||||
state.AddLandblock(new LoadedLandblock(
|
||||
landblock,
|
||||
new LandBlock(),
|
||||
Array.Empty<WorldEntity>()));
|
||||
WorldEntity entity = Entity(1u, 0x73700001u);
|
||||
int callbacks = 0;
|
||||
state.LiveProjectionVisibilityChanged += (guid, visible) =>
|
||||
{
|
||||
callbacks++;
|
||||
Assert.Equal(entity.ServerGuid, guid);
|
||||
Assert.True(visible);
|
||||
Assert.True(state.IsLiveEntityVisible(guid));
|
||||
Assert.Same(entity, Assert.Single(state.Entities));
|
||||
Assert.True(state.TryGetLandblock(landblock, out LoadedLandblock? loaded));
|
||||
Assert.Same(entity, Assert.Single(loaded!.Entities));
|
||||
};
|
||||
|
||||
using (state.BeginMutationBatch())
|
||||
{
|
||||
state.PlaceLiveEntityProjection(landblock, entity);
|
||||
Assert.Equal(0, callbacks);
|
||||
}
|
||||
|
||||
Assert.Equal(1, callbacks);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LoadedToLoadedRebucket_EmitsNoVisibilityPulse()
|
||||
{
|
||||
const uint sourceLandblock = 0x0101FFFFu;
|
||||
const uint targetLandblock = 0x0202FFFFu;
|
||||
var state = new GpuWorldState();
|
||||
state.AddLandblock(new LoadedLandblock(
|
||||
sourceLandblock,
|
||||
new LandBlock(),
|
||||
Array.Empty<WorldEntity>()));
|
||||
state.AddLandblock(new LoadedLandblock(
|
||||
targetLandblock,
|
||||
new LandBlock(),
|
||||
Array.Empty<WorldEntity>()));
|
||||
WorldEntity entity = Entity(1u, 0x73800001u);
|
||||
state.PlaceLiveEntityProjection(sourceLandblock, entity);
|
||||
var edges = new List<(uint Guid, bool Visible)>();
|
||||
state.LiveProjectionVisibilityChanged += (guid, visible) => edges.Add((guid, visible));
|
||||
|
||||
state.RebucketLiveEntity(entity, targetLandblock);
|
||||
|
||||
Assert.Empty(edges);
|
||||
Assert.True(state.IsLiveEntityVisible(entity.ServerGuid));
|
||||
Assert.True(state.TryGetLandblock(sourceLandblock, out LoadedLandblock? source));
|
||||
Assert.Empty(source!.Entities);
|
||||
Assert.True(state.TryGetLandblock(targetLandblock, out LoadedLandblock? target));
|
||||
Assert.Same(entity, Assert.Single(target!.Entities));
|
||||
Assert.Same(entity, Assert.Single(state.Entities));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SameGuidOverlap_ExactRemovalPromotesSecondaryWithoutVisibilityPulse()
|
||||
{
|
||||
const uint landblock = 0x0101FFFFu;
|
||||
const uint guid = 0x73900001u;
|
||||
var state = new GpuWorldState();
|
||||
state.AddLandblock(new LoadedLandblock(
|
||||
landblock,
|
||||
new LandBlock(),
|
||||
Array.Empty<WorldEntity>()));
|
||||
WorldEntity first = Entity(1u, guid);
|
||||
WorldEntity second = Entity(2u, guid);
|
||||
state.PlaceLiveEntityProjection(landblock, first);
|
||||
state.PlaceLiveEntityProjection(landblock, second);
|
||||
var edges = new List<(uint Guid, bool Visible)>();
|
||||
state.LiveProjectionVisibilityChanged += (edgeGuid, visible) =>
|
||||
edges.Add((edgeGuid, visible));
|
||||
|
||||
state.RemoveLiveEntityProjection(first);
|
||||
|
||||
Assert.Empty(edges);
|
||||
Assert.True(state.IsLiveEntityVisible(guid));
|
||||
Assert.Same(second, Assert.Single(state.Entities));
|
||||
|
||||
state.RemoveLiveEntityProjection(guid);
|
||||
|
||||
Assert.Equal([(guid, false)], edges);
|
||||
Assert.False(state.IsLiveEntityVisible(guid));
|
||||
Assert.Empty(state.Entities);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DuplicateDirectPlacement_IsRejectedBeforeAnyBucketMutation()
|
||||
{
|
||||
const uint landblock = 0x0101FFFFu;
|
||||
var state = new GpuWorldState();
|
||||
state.AddLandblock(new LoadedLandblock(
|
||||
landblock,
|
||||
new LandBlock(),
|
||||
Array.Empty<WorldEntity>()));
|
||||
WorldEntity entity = Entity(1u, 0x74000001u);
|
||||
state.PlaceLiveEntityProjection(landblock, entity);
|
||||
|
||||
Assert.Throws<InvalidOperationException>(() =>
|
||||
state.PlaceLiveEntityProjection(landblock, entity));
|
||||
|
||||
Assert.Same(entity, Assert.Single(state.Entities));
|
||||
Assert.True(state.TryGetLandblock(landblock, out LoadedLandblock? loaded));
|
||||
Assert.Same(entity, Assert.Single(loaded!.Entities));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ThrowingObserver_DoesNotStrandLaterSubscribersOrQueuedOwnerEdges()
|
||||
{
|
||||
|
|
@ -80,6 +435,42 @@ public sealed class GpuWorldStateVisibilityTests
|
|||
Assert.Equal(0, state.PendingVisibilityTransitionCount);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CopyLiveEntitiesNearLandblock_UsesBoundedNeighborhoodAndSkipsStatics()
|
||||
{
|
||||
var centerLive = Entity(1, 0x70000001u);
|
||||
var neighborLive = Entity(2, 0x70000002u);
|
||||
var farLive = Entity(3, 0x70000003u);
|
||||
WorldEntity[] staticEntities = Enumerable.Range(0, 20_000)
|
||||
.Select(index => Entity((uint)(index + 10), 0u))
|
||||
.ToArray();
|
||||
var state = new GpuWorldState();
|
||||
state.AddLandblock(new LoadedLandblock(
|
||||
0x1010FFFFu,
|
||||
new LandBlock(),
|
||||
staticEntities.Append(centerLive).ToArray()));
|
||||
state.AddLandblock(new LoadedLandblock(
|
||||
0x1110FFFFu,
|
||||
new LandBlock(),
|
||||
new[] { neighborLive }));
|
||||
state.AddLandblock(new LoadedLandblock(
|
||||
0x1310FFFFu,
|
||||
new LandBlock(),
|
||||
new[] { farLive }));
|
||||
var destination = new List<KeyValuePair<uint, WorldEntity>>
|
||||
{
|
||||
new(0xDEADBEEFu, farLive),
|
||||
};
|
||||
|
||||
state.CopyLiveEntitiesNearLandblock(0x10100001u, 1, destination);
|
||||
|
||||
Assert.Equal(2, destination.Count);
|
||||
Assert.Contains(destination, pair => pair.Key == centerLive.ServerGuid);
|
||||
Assert.Contains(destination, pair => pair.Key == neighborLive.ServerGuid);
|
||||
Assert.DoesNotContain(destination, pair => pair.Key == farLive.ServerGuid);
|
||||
Assert.DoesNotContain(destination, pair => pair.Key == 0u);
|
||||
}
|
||||
|
||||
private static WorldEntity Entity(uint id, uint guid) => new()
|
||||
{
|
||||
Id = id,
|
||||
|
|
|
|||
|
|
@ -0,0 +1,202 @@
|
|||
using System.Numerics;
|
||||
using AcDream.App.Streaming;
|
||||
using AcDream.Core.Terrain;
|
||||
using AcDream.Core.World;
|
||||
using DatReaderWriter.DBObjs;
|
||||
using Xunit;
|
||||
|
||||
namespace AcDream.App.Tests.Streaming;
|
||||
|
||||
public sealed class LandblockRetirementCoordinatorTests
|
||||
{
|
||||
[Fact]
|
||||
public void EntityStageFailure_DetachesImmediately_AndResumesAtFailedEntity()
|
||||
{
|
||||
const uint landblockId = 0x2020FFFFu;
|
||||
var state = new GpuWorldState();
|
||||
state.AddLandblock(new LoadedLandblock(
|
||||
landblockId,
|
||||
new LandBlock(),
|
||||
new[] { Entity(1), Entity(2), Entity(3) }));
|
||||
|
||||
var calls = new Dictionary<uint, int>();
|
||||
bool failEntityTwo = true;
|
||||
var coordinator = new LandblockRetirementCoordinator(
|
||||
state,
|
||||
ticket => CompletePresentation(
|
||||
ticket,
|
||||
lighting: entity =>
|
||||
{
|
||||
calls[entity.Id] = calls.GetValueOrDefault(entity.Id) + 1;
|
||||
if (entity.Id == 2 && failEntityTwo)
|
||||
{
|
||||
failEntityTwo = false;
|
||||
throw new InvalidOperationException("injected owner failure");
|
||||
}
|
||||
}));
|
||||
|
||||
coordinator.BeginFull(landblockId);
|
||||
|
||||
Assert.False(state.IsLoaded(landblockId));
|
||||
Assert.Equal(1, coordinator.PendingCount);
|
||||
Assert.Equal(1, calls[1]);
|
||||
Assert.Equal(1, calls[2]);
|
||||
Assert.False(calls.ContainsKey(3));
|
||||
|
||||
coordinator.Advance();
|
||||
|
||||
Assert.Equal(0, coordinator.PendingCount);
|
||||
Assert.Equal(1, calls[1]);
|
||||
Assert.Equal(2, calls[2]);
|
||||
Assert.Equal(1, calls[3]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ForceReload_RetiresEveryLoadedId_WhenOneOwnerRemainsPending()
|
||||
{
|
||||
uint[] ids = [0x2020FFFFu, 0x2121FFFFu, 0x2222FFFFu];
|
||||
var state = new GpuWorldState();
|
||||
foreach (uint id in ids)
|
||||
state.AddLandblock(new LoadedLandblock(id, new LandBlock(), Array.Empty<WorldEntity>()));
|
||||
|
||||
bool failOnce = true;
|
||||
var coordinator = new LandblockRetirementCoordinator(
|
||||
state,
|
||||
ticket => CompletePresentation(
|
||||
ticket,
|
||||
terrain: () =>
|
||||
{
|
||||
if (ticket.LandblockId == ids[1] && failOnce)
|
||||
{
|
||||
failOnce = false;
|
||||
throw new InvalidOperationException("injected terrain failure");
|
||||
}
|
||||
}));
|
||||
var controller = Controller(state, coordinator);
|
||||
|
||||
controller.ForceReloadWindow();
|
||||
|
||||
foreach (uint id in ids)
|
||||
Assert.False(state.IsLoaded(id));
|
||||
Assert.Equal(1, coordinator.PendingCount);
|
||||
|
||||
coordinator.Advance();
|
||||
Assert.Equal(0, coordinator.PendingCount);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ReplacementPublication_WaitsForSameIdRetirementFence()
|
||||
{
|
||||
const uint landblockId = 0x3232FFFFu;
|
||||
var state = new GpuWorldState();
|
||||
state.AddLandblock(new LoadedLandblock(
|
||||
landblockId,
|
||||
new LandBlock(),
|
||||
Array.Empty<WorldEntity>()));
|
||||
|
||||
int terrainAttempts = 0;
|
||||
var coordinator = new LandblockRetirementCoordinator(
|
||||
state,
|
||||
ticket => CompletePresentation(
|
||||
ticket,
|
||||
terrain: () =>
|
||||
{
|
||||
terrainAttempts++;
|
||||
if (terrainAttempts <= 2)
|
||||
throw new InvalidOperationException("injected terrain failure");
|
||||
}));
|
||||
|
||||
var pending = new Queue<LandblockStreamResult>();
|
||||
int applyCount = 0;
|
||||
var controller = Controller(
|
||||
state,
|
||||
coordinator,
|
||||
drain: max => Drain(pending, max),
|
||||
apply: (_, _) => applyCount++);
|
||||
controller.ForceReloadWindow(); // generation 1, first retirement attempt
|
||||
|
||||
var replacement = new LoadedLandblock(
|
||||
landblockId,
|
||||
new LandBlock(),
|
||||
Array.Empty<WorldEntity>());
|
||||
pending.Enqueue(new LandblockStreamResult.Loaded(
|
||||
landblockId,
|
||||
LandblockStreamTier.Near,
|
||||
replacement,
|
||||
EmptyMesh(),
|
||||
generation: 1));
|
||||
|
||||
controller.Tick(0x32, 0x32); // second failure; publication stays deferred
|
||||
Assert.Equal(0, applyCount);
|
||||
Assert.False(state.IsLoaded(landblockId));
|
||||
Assert.True(coordinator.IsPending(landblockId));
|
||||
|
||||
controller.Tick(0x32, 0x32); // third attempt completes, then publishes once
|
||||
Assert.Equal(1, applyCount);
|
||||
Assert.True(state.IsLoaded(landblockId));
|
||||
Assert.False(coordinator.IsPending(landblockId));
|
||||
}
|
||||
|
||||
private static StreamingController Controller(
|
||||
GpuWorldState state,
|
||||
LandblockRetirementCoordinator coordinator,
|
||||
Func<int, IReadOnlyList<LandblockStreamResult>>? drain = null,
|
||||
Action<LandblockBuild, LandblockMeshData>? apply = null) =>
|
||||
new(
|
||||
enqueueLoad: (_, _, _) => { },
|
||||
enqueueUnload: (_, _) => { },
|
||||
drainCompletions: drain ?? (_ => Array.Empty<LandblockStreamResult>()),
|
||||
applyTerrain: apply ?? ((_, _) => { }),
|
||||
state: state,
|
||||
nearRadius: 0,
|
||||
farRadius: 0,
|
||||
retirementCoordinator: coordinator);
|
||||
|
||||
private static IReadOnlyList<LandblockStreamResult> Drain(
|
||||
Queue<LandblockStreamResult> pending,
|
||||
int max)
|
||||
{
|
||||
var result = new List<LandblockStreamResult>(max);
|
||||
while (result.Count < max && pending.TryDequeue(out LandblockStreamResult? item))
|
||||
result.Add(item);
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void CompletePresentation(
|
||||
LandblockRetirementTicket ticket,
|
||||
Action<WorldEntity>? lighting = null,
|
||||
Action? terrain = null)
|
||||
{
|
||||
ticket.RunForEachEntity(
|
||||
LandblockRetirementStage.EntityLighting,
|
||||
static _ => true,
|
||||
lighting ?? (_ => { }));
|
||||
ticket.RunForEachEntity(
|
||||
LandblockRetirementStage.EntityTranslucency,
|
||||
static _ => true,
|
||||
static _ => { });
|
||||
ticket.RunForEachEntity(
|
||||
LandblockRetirementStage.PluginProjection,
|
||||
static entity => entity.ServerGuid == 0,
|
||||
static _ => { });
|
||||
if (ticket.Kind == LandblockRetirementKind.Full)
|
||||
ticket.RunOnce(LandblockRetirementStage.Terrain, terrain ?? (() => { }));
|
||||
ticket.RunOnce(LandblockRetirementStage.Physics, static () => { });
|
||||
ticket.RunOnce(LandblockRetirementStage.CellVisibility, static () => { });
|
||||
ticket.RunOnce(LandblockRetirementStage.BuildingRegistry, static () => { });
|
||||
ticket.RunOnce(LandblockRetirementStage.EnvironmentCells, static () => { });
|
||||
}
|
||||
|
||||
private static WorldEntity Entity(uint id) => new()
|
||||
{
|
||||
Id = id,
|
||||
SourceGfxObjOrSetupId = 0x01000000u + id,
|
||||
Position = Vector3.Zero,
|
||||
Rotation = Quaternion.Identity,
|
||||
MeshRefs = Array.Empty<MeshRef>(),
|
||||
};
|
||||
|
||||
private static LandblockMeshData EmptyMesh() => new(
|
||||
Array.Empty<TerrainVertex>(),
|
||||
Array.Empty<uint>());
|
||||
}
|
||||
|
|
@ -327,7 +327,7 @@ public sealed class StreamingControllerReadinessTests
|
|||
var outbox = new Queue<LandblockStreamResult>();
|
||||
int ensureCalls = 0;
|
||||
var appliedBuilds = new List<LandblockBuild>();
|
||||
var demotedWhileStaticPresent = new List<uint>();
|
||||
var demotedAfterStaticDetach = new List<uint>();
|
||||
var shell = new EnvCellShellPlacement(
|
||||
0x12360001u,
|
||||
geometryId,
|
||||
|
|
@ -374,8 +374,8 @@ public sealed class StreamingControllerReadinessTests
|
|||
farRadius: 3,
|
||||
demoteNearLayer: demotedId =>
|
||||
{
|
||||
Assert.Contains(staticEntity, state.Entities);
|
||||
demotedWhileStaticPresent.Add(demotedId);
|
||||
Assert.DoesNotContain(staticEntity, state.Entities);
|
||||
demotedAfterStaticDetach.Add(demotedId);
|
||||
},
|
||||
ensureEnvCellMeshes: _ => ensureCalls++);
|
||||
|
||||
|
|
@ -396,7 +396,7 @@ public sealed class StreamingControllerReadinessTests
|
|||
Assert.Equal(1, ensureCalls);
|
||||
Assert.DoesNotContain(geometryId, meshes.ReferenceCounts);
|
||||
Assert.DoesNotContain(staticEntity, state.Entities);
|
||||
Assert.Equal(new[] { id }, demotedWhileStaticPresent);
|
||||
Assert.Equal(new[] { id }, demotedAfterStaticDetach);
|
||||
Assert.True(state.IsLoaded(id));
|
||||
Assert.False(state.IsNearTier(id));
|
||||
Assert.Equal(2, appliedBuilds.Count);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue