acdream/tests/AcDream.App.Tests/Rendering/ViewconeCullerReuseTests.cs
Erik 749e8ceeb1 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>
2026-07-18 21:35:16 +02:00

60 lines
2.1 KiB
C#

using System.Numerics;
using AcDream.App.Rendering;
using Xunit;
namespace AcDream.App.Tests.Rendering;
public sealed class ViewconeCullerReuseTests
{
[Fact]
public void ReusedCuller_ReplacesPriorCellAndOutsideState()
{
const uint firstCell = 0xA9B40100;
const uint secondCell = 0xA9B40101;
var clipFrame = ClipFrame.NoClip();
var assemblyScratch = new ClipFrameAssembly();
var culler = new ViewconeCuller();
var first = Frame(firstCell, includeOutside: true);
ClipFrameAssembly firstAssembly = ClipFrameAssembler.Assemble(
clipFrame,
first,
assemblyScratch);
Assert.Same(culler, ViewconeCuller.Build(firstAssembly, Matrix4x4.Identity, culler));
Assert.True(culler.SphereVisibleInCell(firstCell, Vector3.Zero, 0f));
Assert.True(culler.SphereVisibleOutside(Vector3.Zero, 0f));
var second = Frame(secondCell, includeOutside: false);
ClipFrameAssembly secondAssembly = ClipFrameAssembler.Assemble(
clipFrame,
second,
assemblyScratch);
Assert.Same(culler, ViewconeCuller.Build(secondAssembly, Matrix4x4.Identity, culler));
Assert.False(culler.SphereVisibleInCell(firstCell, Vector3.Zero, 0f));
Assert.True(culler.SphereVisibleInCell(secondCell, Vector3.Zero, 0f));
Assert.False(culler.SphereVisibleInCell(secondCell, new Vector3(2f, 0f, 0f), 0f));
Assert.False(culler.SphereVisibleOutside(Vector3.Zero, 0f));
}
private static PortalVisibilityFrame Frame(uint cellId, bool includeOutside)
{
var result = new PortalVisibilityFrame();
var cellView = new CellView();
cellView.Add(Square(0.5f));
result.CellViews.Add(cellId, cellView);
result.OrderedVisibleCells.Add(cellId);
if (includeOutside)
result.OutsideView.Add(Square(0.5f));
return result;
}
private static ViewPolygon Square(float half)
=> new(new[]
{
new Vector2(-half, -half),
new Vector2(half, -half),
new Vector2(half, half),
new Vector2(-half, half),
});
}