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
|
|
@ -84,4 +84,121 @@ public class WorldEventsTests
|
|||
Assert.Contains(1u, seen);
|
||||
Assert.Contains(3u, seen);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RehydratedEntity_ReplacesReplaySnapshotInsteadOfAppendingHistory()
|
||||
{
|
||||
var events = new WorldEvents();
|
||||
events.FireEntitySpawned(S(1));
|
||||
events.FireEntitySpawned(S(1) with { SourceId = 0x01000001u });
|
||||
|
||||
var seen = new List<WorldEntitySnapshot>();
|
||||
events.EntitySpawned += seen.Add;
|
||||
|
||||
WorldEntitySnapshot replay = Assert.Single(seen);
|
||||
Assert.Equal(0x01000001u, replay.SourceId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ForgottenEntity_IsNotReplayedToLateSubscriber()
|
||||
{
|
||||
var events = new WorldEvents();
|
||||
events.FireEntitySpawned(S(1));
|
||||
events.FireEntitySpawned(S(2));
|
||||
|
||||
Assert.True(events.ForgetEntity(1));
|
||||
|
||||
var seen = new List<uint>();
|
||||
events.EntitySpawned += e => seen.Add(e.Id);
|
||||
Assert.Equal(new uint[] { 2 }, seen);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ClearCurrent_LeavesNoReplayHistory()
|
||||
{
|
||||
var events = new WorldEvents();
|
||||
events.FireEntitySpawned(S(1));
|
||||
events.FireEntitySpawned(S(2));
|
||||
events.ClearCurrent();
|
||||
|
||||
var seen = new List<uint>();
|
||||
events.EntitySpawned += e => seen.Add(e.Id);
|
||||
Assert.Empty(seen);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task LiveEventDuringReplay_IsDeliveredAfterSnapshotWithoutStaleReordering()
|
||||
{
|
||||
var events = new WorldEvents();
|
||||
events.FireEntitySpawned(S(1));
|
||||
using var replayEntered = new ManualResetEventSlim();
|
||||
using var releaseReplay = new ManualResetEventSlim();
|
||||
var seen = new List<uint>();
|
||||
Action<WorldEntitySnapshot> handler = snapshot =>
|
||||
{
|
||||
lock (seen)
|
||||
seen.Add(snapshot.SourceId);
|
||||
if (snapshot.SourceId == 0x01000000u)
|
||||
{
|
||||
replayEntered.Set();
|
||||
releaseReplay.Wait();
|
||||
}
|
||||
};
|
||||
|
||||
Task subscribe = Task.Run(() => events.EntitySpawned += handler);
|
||||
Assert.True(replayEntered.Wait(5_000));
|
||||
events.FireEntitySpawned(S(1) with { SourceId = 0x01000001u });
|
||||
releaseReplay.Set();
|
||||
await subscribe;
|
||||
|
||||
lock (seen)
|
||||
Assert.Equal(new uint[] { 0x01000000u, 0x01000001u }, seen);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ClearCurrent_DropsLiveEventsQueuedBehindAnActiveReplay()
|
||||
{
|
||||
var events = new WorldEvents();
|
||||
events.FireEntitySpawned(S(1));
|
||||
using var replayEntered = new ManualResetEventSlim();
|
||||
using var releaseReplay = new ManualResetEventSlim();
|
||||
var seen = new List<uint>();
|
||||
Action<WorldEntitySnapshot> handler = snapshot =>
|
||||
{
|
||||
lock (seen)
|
||||
seen.Add(snapshot.Id);
|
||||
if (snapshot.Id == 1)
|
||||
{
|
||||
replayEntered.Set();
|
||||
releaseReplay.Wait();
|
||||
}
|
||||
};
|
||||
|
||||
Task subscribe = Task.Run(() => events.EntitySpawned += handler);
|
||||
Assert.True(replayEntered.Wait(5_000));
|
||||
events.FireEntitySpawned(S(2));
|
||||
events.ClearCurrent();
|
||||
releaseReplay.Set();
|
||||
await subscribe;
|
||||
|
||||
lock (seen)
|
||||
Assert.Equal(new uint[] { 1 }, seen);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UpsertCurrent_RestoresLateReplayWithoutNotifyingExistingSubscriber()
|
||||
{
|
||||
var events = new WorldEvents();
|
||||
var existing = new List<uint>();
|
||||
events.EntitySpawned += snapshot => existing.Add(snapshot.Id);
|
||||
events.FireEntitySpawned(S(1));
|
||||
events.ForgetEntity(1);
|
||||
|
||||
events.UpsertCurrent(S(1) with { SourceId = 0x01000001u });
|
||||
|
||||
Assert.Equal(new uint[] { 1 }, existing);
|
||||
var late = new List<WorldEntitySnapshot>();
|
||||
events.EntitySpawned += late.Add;
|
||||
Assert.Equal(0x01000001u, Assert.Single(late).SourceId);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
50
tests/AcDream.Core.Tests/Plugins/WorldGameStateTests.cs
Normal file
50
tests/AcDream.Core.Tests/Plugins/WorldGameStateTests.cs
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
using System.Numerics;
|
||||
using AcDream.Core.Plugins;
|
||||
using AcDream.Plugin.Abstractions;
|
||||
|
||||
namespace AcDream.Core.Tests.Plugins;
|
||||
|
||||
public sealed class WorldGameStateTests
|
||||
{
|
||||
private static WorldEntitySnapshot S(uint id, uint sourceId = 0x01000000u) =>
|
||||
new(id, sourceId, Vector3.Zero, Quaternion.Identity);
|
||||
|
||||
[Fact]
|
||||
public void Add_ReplacesExistingProjectionById()
|
||||
{
|
||||
var state = new WorldGameState();
|
||||
state.Add(S(1));
|
||||
state.Add(S(1, 0x01000001u));
|
||||
|
||||
WorldEntitySnapshot current = Assert.Single(state.Entities);
|
||||
Assert.Equal(0x01000001u, current.SourceId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RemoveById_CompactsIndexWithoutLosingOtherEntities()
|
||||
{
|
||||
var state = new WorldGameState();
|
||||
state.Add(S(1));
|
||||
state.Add(S(2));
|
||||
state.Add(S(3));
|
||||
|
||||
Assert.True(state.RemoveById(2));
|
||||
state.Add(S(3, 0x01000003u));
|
||||
|
||||
Assert.Equal(2, state.Entities.Count);
|
||||
Assert.DoesNotContain(state.Entities, entity => entity.Id == 2);
|
||||
Assert.Equal(0x01000003u, Assert.Single(state.Entities, entity => entity.Id == 3).SourceId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Clear_RemovesCurrentProjectionAndIndex()
|
||||
{
|
||||
var state = new WorldGameState();
|
||||
state.Add(S(1));
|
||||
state.Clear();
|
||||
state.Add(S(1, 0x01000001u));
|
||||
|
||||
WorldEntitySnapshot current = Assert.Single(state.Entities);
|
||||
Assert.Equal(0x01000001u, current.SourceId);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue