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
|
|
@ -179,6 +179,36 @@ public class ChatWindowControllerTests
|
|||
Assert.Contains(ctrl!.Input, bar!.Children);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TranscriptLayout_IsReusedUntilContentOrWidthChanges()
|
||||
{
|
||||
var (rootInfo, layout, vm) = BuildTestTree();
|
||||
var bus = new CaptureBus();
|
||||
var ctrl = ChatWindowController.Bind(
|
||||
rootInfo, layout, vm, () => bus, null, null, NoTex)!;
|
||||
|
||||
vm.ShowSystemMessage("one wrapped transcript line");
|
||||
IReadOnlyList<UiText.Line> first = ctrl.Transcript.LinesProvider();
|
||||
IReadOnlyList<UiText.Line> unchanged = ctrl.Transcript.LinesProvider();
|
||||
|
||||
Assert.Same(first, unchanged);
|
||||
Assert.Equal(1, ctrl.TranscriptLayoutBuildCount);
|
||||
|
||||
vm.ShowSystemMessage("second line");
|
||||
IReadOnlyList<UiText.Line> appended = ctrl.Transcript.LinesProvider();
|
||||
Assert.NotSame(first, appended);
|
||||
Assert.Equal(2, ctrl.TranscriptLayoutBuildCount);
|
||||
|
||||
ctrl.Transcript.Width -= 40f;
|
||||
IReadOnlyList<UiText.Line> resized = ctrl.Transcript.LinesProvider();
|
||||
Assert.NotSame(appended, resized);
|
||||
Assert.Equal(3, ctrl.TranscriptLayoutBuildCount);
|
||||
|
||||
vm.Clear();
|
||||
Assert.Empty(ctrl.Transcript.LinesProvider());
|
||||
Assert.Equal(4, ctrl.TranscriptLayoutBuildCount);
|
||||
}
|
||||
|
||||
// ── Test 4: Input.OnSubmit publishes SendChatCmd via the capture bus ─────
|
||||
|
||||
[Fact]
|
||||
|
|
|
|||
|
|
@ -187,6 +187,55 @@ public sealed class RadarSnapshotProviderTests
|
|||
Assert.Equal(monster, Assert.Single(snapshot.Blips).ObjectId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void BuildSnapshot_UsesBoundedSpatialCandidatesBeforeRetailProjection()
|
||||
{
|
||||
const uint player = 40u;
|
||||
const uint nearby = 41u;
|
||||
const uint unrelated = 42u;
|
||||
var objects = new ClientObjectTable();
|
||||
objects.Ingest(Weenie(player, "Player", ItemType.Creature));
|
||||
objects.Ingest(Weenie(nearby, "Nearby", ItemType.Creature) with
|
||||
{
|
||||
RadarBehavior = (byte)RadarBehavior.ShowAlways,
|
||||
});
|
||||
objects.Ingest(Weenie(unrelated, "Unrelated", ItemType.Creature) with
|
||||
{
|
||||
RadarBehavior = (byte)RadarBehavior.ShowAlways,
|
||||
});
|
||||
var entities = new Dictionary<uint, WorldEntity>
|
||||
{
|
||||
[player] = Entity(player, Vector3.Zero, Quaternion.Identity),
|
||||
[nearby] = Entity(nearby, new Vector3(5f, 0f, 0f), Quaternion.Identity),
|
||||
[unrelated] = Entity(unrelated, new Vector3(6f, 0f, 0f), Quaternion.Identity),
|
||||
};
|
||||
var spawns = entities.Keys.ToDictionary(guid => guid, Spawn);
|
||||
uint copiedCell = 0;
|
||||
int copiedRadius = -1;
|
||||
var provider = new RadarSnapshotProvider(
|
||||
objects,
|
||||
() => entities,
|
||||
() => spawns,
|
||||
playerGuid: () => player,
|
||||
playerYawRadians: () => 0f,
|
||||
playerCellId: () => 0xA9B40001u,
|
||||
selectedGuid: () => null,
|
||||
coordinatesOnRadar: () => true,
|
||||
uiLocked: () => false,
|
||||
copySpatialCandidates: (cell, radius, destination) =>
|
||||
{
|
||||
copiedCell = cell;
|
||||
copiedRadius = radius;
|
||||
destination.Add(new KeyValuePair<uint, WorldEntity>(nearby, entities[nearby]));
|
||||
});
|
||||
|
||||
UiRadarSnapshot snapshot = provider.BuildSnapshot();
|
||||
|
||||
Assert.Equal(0xA9B40001u, copiedCell);
|
||||
Assert.Equal(1, copiedRadius);
|
||||
Assert.Equal(nearby, Assert.Single(snapshot.Blips).ObjectId);
|
||||
}
|
||||
|
||||
private static WorldEntity Entity(uint guid, Vector3 position, Quaternion rotation) => new()
|
||||
{
|
||||
Id = guid,
|
||||
|
|
|
|||
118
tests/AcDream.App.Tests/UI/UiCompositeShutdownTests.cs
Normal file
118
tests/AcDream.App.Tests/UI/UiCompositeShutdownTests.cs
Normal file
|
|
@ -0,0 +1,118 @@
|
|||
using AcDream.App.Rendering;
|
||||
using AcDream.App.UI;
|
||||
|
||||
namespace AcDream.App.Tests.UI;
|
||||
|
||||
public sealed class UiCompositeShutdownTests
|
||||
{
|
||||
[Fact]
|
||||
public void UiHostShutdownRetainsFailedInputAndProtectsDependentOwners()
|
||||
{
|
||||
var calls = new List<string>();
|
||||
bool failInput = true;
|
||||
ResourceShutdownTransaction transaction = UiHost.CreateShutdownTransaction(
|
||||
[
|
||||
() => calls.Add("last-input"),
|
||||
() =>
|
||||
{
|
||||
calls.Add("failed-input");
|
||||
if (failInput)
|
||||
throw new InvalidOperationException("synthetic unsubscribe failure");
|
||||
},
|
||||
],
|
||||
() => calls.Add("input-state"),
|
||||
() => calls.Add("windows"),
|
||||
() => calls.Add("text"));
|
||||
|
||||
Assert.Throws<AggregateException>(transaction.CompleteOrThrow);
|
||||
|
||||
Assert.Equal(1, calls.Count(call => call == "last-input"));
|
||||
Assert.Equal(3, calls.Count(call => call == "failed-input"));
|
||||
Assert.DoesNotContain("input-state", calls);
|
||||
Assert.DoesNotContain("windows", calls);
|
||||
Assert.DoesNotContain("text", calls);
|
||||
|
||||
failInput = false;
|
||||
transaction.CompleteOrThrow();
|
||||
|
||||
Assert.True(transaction.IsComplete);
|
||||
Assert.Equal(1, calls.Count(call => call == "last-input"));
|
||||
Assert.Equal(4, calls.Count(call => call == "failed-input"));
|
||||
Assert.Equal(1, calls.Count(call => call == "input-state"));
|
||||
Assert.Equal(1, calls.Count(call => call == "windows"));
|
||||
Assert.Equal(1, calls.Count(call => call == "text"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UiHostShutdownRetriesRendererWithoutReplayingWindowManager()
|
||||
{
|
||||
int windowCalls = 0;
|
||||
int rendererCalls = 0;
|
||||
bool failRenderer = true;
|
||||
ResourceShutdownTransaction transaction = UiHost.CreateShutdownTransaction(
|
||||
[],
|
||||
() => { },
|
||||
() => windowCalls++,
|
||||
() =>
|
||||
{
|
||||
rendererCalls++;
|
||||
if (failRenderer)
|
||||
throw new InvalidOperationException("synthetic renderer failure");
|
||||
});
|
||||
|
||||
Assert.Throws<AggregateException>(transaction.CompleteOrThrow);
|
||||
Assert.Equal(1, windowCalls);
|
||||
Assert.Equal(2, rendererCalls);
|
||||
|
||||
failRenderer = false;
|
||||
transaction.CompleteOrThrow();
|
||||
|
||||
Assert.True(transaction.IsComplete);
|
||||
Assert.Equal(1, windowCalls);
|
||||
Assert.Equal(3, rendererCalls);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RetailRuntimeShutdownReentersSafelyAndGatesHostBehindControllers()
|
||||
{
|
||||
var calls = new List<string>();
|
||||
bool failGameplay = true;
|
||||
ResourceShutdownTransaction? transaction = null;
|
||||
transaction = RetailUiRuntime.CreateShutdownTransaction(
|
||||
() => calls.Add("persistence"),
|
||||
() => calls.Add("visibility"),
|
||||
() =>
|
||||
{
|
||||
calls.Add("item");
|
||||
transaction!.CompleteOrThrow();
|
||||
},
|
||||
() =>
|
||||
{
|
||||
calls.Add("gameplay");
|
||||
if (failGameplay)
|
||||
throw new InvalidOperationException("synthetic controller failure");
|
||||
},
|
||||
() => calls.Add("dialogs"),
|
||||
() => calls.Add("panels"),
|
||||
() => calls.Add("host"));
|
||||
|
||||
Assert.Throws<AggregateException>(transaction.CompleteOrThrow);
|
||||
|
||||
Assert.Equal(1, calls.Count(call => call == "persistence"));
|
||||
Assert.Equal(1, calls.Count(call => call == "visibility"));
|
||||
Assert.Equal(1, calls.Count(call => call == "item"));
|
||||
Assert.Equal(3, calls.Count(call => call == "gameplay"));
|
||||
Assert.DoesNotContain("dialogs", calls);
|
||||
Assert.DoesNotContain("panels", calls);
|
||||
Assert.DoesNotContain("host", calls);
|
||||
|
||||
failGameplay = false;
|
||||
transaction.CompleteOrThrow();
|
||||
|
||||
Assert.True(transaction.IsComplete);
|
||||
Assert.Equal(1, calls.Count(call => call == "item"));
|
||||
Assert.Equal(1, calls.Count(call => call == "dialogs"));
|
||||
Assert.Equal(1, calls.Count(call => call == "panels"));
|
||||
Assert.Equal(1, calls.Count(call => call == "host"));
|
||||
}
|
||||
}
|
||||
67
tests/AcDream.App.Tests/UI/UiElementChildOrderTests.cs
Normal file
67
tests/AcDream.App.Tests/UI/UiElementChildOrderTests.cs
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
using AcDream.App.UI;
|
||||
|
||||
namespace AcDream.App.Tests.UI;
|
||||
|
||||
public sealed class UiElementChildOrderTests
|
||||
{
|
||||
[Fact]
|
||||
public void StableTree_ReusesBothTraversalSnapshots()
|
||||
{
|
||||
var parent = new TestElement();
|
||||
parent.AddChild(new TestElement { ZOrder = 2 });
|
||||
parent.AddChild(new TestElement { ZOrder = 1 });
|
||||
|
||||
UiElement[] drawFirst = parent.ChildrenBackToFrontSnapshot();
|
||||
UiElement[] drawSecond = parent.ChildrenBackToFrontSnapshot();
|
||||
UiElement[] hitFirst = parent.ChildrenFrontToBackSnapshot();
|
||||
UiElement[] hitSecond = parent.ChildrenFrontToBackSnapshot();
|
||||
|
||||
Assert.Same(drawFirst, drawSecond);
|
||||
Assert.Same(hitFirst, hitSecond);
|
||||
Assert.Equal([1, 2], drawFirst.Select(child => child.ZOrder).ToArray());
|
||||
Assert.Equal([2, 1], hitFirst.Select(child => child.ZOrder).ToArray());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ChildZOrderChange_InvalidatesBothTraversalSnapshots()
|
||||
{
|
||||
var parent = new TestElement();
|
||||
var first = new TestElement { ZOrder = 1 };
|
||||
var second = new TestElement { ZOrder = 2 };
|
||||
parent.AddChild(first);
|
||||
parent.AddChild(second);
|
||||
UiElement[] oldDraw = parent.ChildrenBackToFrontSnapshot();
|
||||
UiElement[] oldHit = parent.ChildrenFrontToBackSnapshot();
|
||||
|
||||
first.ZOrder = 3;
|
||||
UiElement[] newDraw = parent.ChildrenBackToFrontSnapshot();
|
||||
UiElement[] newHit = parent.ChildrenFrontToBackSnapshot();
|
||||
|
||||
Assert.NotSame(oldDraw, newDraw);
|
||||
Assert.NotSame(oldHit, newHit);
|
||||
Assert.Same(second, newDraw[0]);
|
||||
Assert.Same(first, newDraw[1]);
|
||||
Assert.Same(first, newHit[0]);
|
||||
Assert.Same(second, newHit[1]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MembershipChange_InvalidatesSnapshotsWithoutMutatingPriorWalk()
|
||||
{
|
||||
var parent = new TestElement();
|
||||
var first = new TestElement { ZOrder = 1 };
|
||||
var second = new TestElement { ZOrder = 2 };
|
||||
parent.AddChild(first);
|
||||
UiElement[] prior = parent.ChildrenBackToFrontSnapshot();
|
||||
|
||||
parent.AddChild(second);
|
||||
UiElement[] current = parent.ChildrenBackToFrontSnapshot();
|
||||
|
||||
Assert.Single(prior);
|
||||
Assert.Same(first, prior[0]);
|
||||
Assert.Equal(2, current.Length);
|
||||
Assert.NotSame(prior, current);
|
||||
}
|
||||
|
||||
private sealed class TestElement : UiElement;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue