acdream/tests/AcDream.App.Tests/Rendering/GameWindowRenderLeafCompositionTests.cs
Erik bc6f09f987 refactor(render): extract frame resource preparation
Move ordered resource begin, clear/state setup, live upload/reveal, weather timing, and display pacing behind focused owners while preserving the accepted frame order and retryable shutdown ownership.

Co-authored-by: Codex <codex@openai.com>
2026-07-22 05:23:46 +02:00

188 lines
6.8 KiB
C#

using AcDream.App.Rendering;
namespace AcDream.App.Tests.Rendering;
public sealed class GameWindowRenderLeafCompositionTests
{
[Fact]
public void ProductionRender_PreservesPrivatePresentationAndCaptureOrder()
{
string source = GameWindowSource();
AssertAppearsInOrder(
source,
"_localPlayerTeleport?.DrawPortalViewport(",
"_paperdollFramePresenter?.Render();",
"_retailUiRuntime.Tick(deltaSeconds);",
"_devToolsFramePresenter?.Render(",
"_frameScreenshots?.CapturePending() == true;",
"_renderFrameDiagnostics?.Publish(");
}
[Fact]
public void ProductionRender_Prepares_resources_then_devtools_weather_and_world()
{
string source = GameWindowSource();
AssertAppearsInOrder(
source,
"_renderFrameResources!.Prepare(frameInput);",
"_devToolsFramePresenter?.BeginFrame((float)deltaSeconds);",
"_renderWeatherFrame!.Tick(deltaSeconds);",
"_retailSelectionScene?.BeginFrame();");
Assert.DoesNotContain("_wbDrawDispatcher?.BeginFrame(", source);
Assert.DoesNotContain("_wbMeshAdapter?.Tick();", source);
Assert.DoesNotContain("_particleRenderer?.BeginFrame(", source);
}
[Fact]
public void Composition_transfers_portal_tunnel_before_constructing_frame_borrowers()
{
string source = GameWindowSource();
AssertAppearsInOrder(
source,
"new AcDream.App.Streaming.LocalPlayerTeleportController(",
"_portalTunnel = null;",
"_localPlayerTeleportSink.Bind(_localPlayerTeleport);",
"new AcDream.App.Rendering.LocalPlayerTeleportRenderStateSource(",
"new AcDream.App.Rendering.RenderFrameResourceController(");
}
[Fact]
public void ProductionComposition_RemovesLegacyLeafOwnership()
{
string source = GameWindowSource();
string[] removed =
[
"_imguiBootstrap",
"_panelHost",
"_paperdollDollDirty",
"RefreshPaperdollDoll",
"ApplyPaperdollPose",
"ResolvePaperdollPoseDid",
"EnumerateDebugPanel",
"ResetPanelLayout",
"SetPanelLayout",
"_lastRenderSignature",
"private void EmitRenderSignatureIfChanged(",
"private void EmitRetailPViewDiagnostics(",
"EmitGlStateTripwireIfChanged();",
"EmitClipRouteScissorProbe(scissor",
"_lastVisibleLandblocks",
"_perfAccum",
"_entityUploadTiming",
"_weatherAccum",
"TryGetLoginWorldCell",
"ApplyFramePacingPreference",
"RefreshActiveMonitorFramePacing",
"private void OnFrameRendered(",
];
foreach (string identifier in removed)
Assert.DoesNotContain(identifier, source, StringComparison.Ordinal);
Assert.Contains("new AcDream.App.Rendering.PaperdollFramePresenter(", source);
Assert.Contains("new AcDream.App.Rendering.DevToolsFramePresenter(", source);
Assert.Contains("new AcDream.App.Rendering.RenderFrameResourceController(", source);
Assert.Contains("new AcDream.App.Rendering.RenderWeatherFrameController(", source);
Assert.Contains("new DisplayFramePacingController(", source);
Assert.Contains("_inputCapture.WantCaptureMouse", source);
}
[Fact]
public void Shutdown_PreservesBorrowedDevtoolsLifetimeAndDrainsGpuBeforeFrontends()
{
string source = GameWindowSource();
AssertAppearsInOrder(
source,
"new ResourceShutdownStage(\"submitted GPU work\"",
"new ResourceShutdownStage(\"render frontends\"",
"new(\"frame composition\"",
"new(\"portal tunnel\"",
"new(\"paperdoll viewport\"",
"new ResourceShutdownStage(\"OpenGL context\"");
Assert.Contains("_renderFrameResources = null;", source);
Assert.Contains("_renderFrameLivePreparation = null;", source);
Assert.Contains("_renderWeatherFrame = null;", source);
AssertAppearsInOrder(
source,
"new(\"frame pacing\", _displayFramePacing.Dispose)",
"new(\"frame profiler\", _frameProfiler.Dispose)");
Assert.DoesNotContain("_devToolsBackend?.Dispose()", source);
}
[Fact]
public void ProductionOutcome_UsesObservedWorldAndScreenshotFacts()
{
string source = GameWindowSource();
Assert.Contains("bool normalWorldDrawn = false;", source);
AssertAppearsInOrder(
source,
"if (IsLiveModeWaitingForLogin)",
"goto SkipWorldGeometry;",
"normalWorldDrawn = true;",
"bool screenshotCaptured = _frameScreenshots?.CapturePending() == true;",
"normalWorldDrawn),",
"screenshotCaptured)));");
}
[Fact]
public void PaperdollComposition_SkipsEitherMissingOptionalUiSurface()
{
string source = GameWindowSource();
AssertAppearsInOrder(
source,
"PaperdollViewportWidget is { } paperdollViewport",
"InventoryFrame is { } paperdollInventoryFrame",
"new AcDream.App.Rendering.PaperdollFramePresenter(");
Assert.DoesNotContain("Paperdoll inventory frame is required.", source);
}
[Fact]
public void TerrainAndFrameDiagnostics_CommitOneSharedCadenceAfterBothWrites()
{
string source = GameWindowSource();
AssertAppearsInOrder(
source,
"_worldRenderDiagnostics?.PublishTerrainDiagnostics(",
"PublishFrameDiagnostics();",
"_frameDiagLastPublicationMilliseconds = now;");
}
private static string GameWindowSource() => File.ReadAllText(Path.Combine(
FindRepoRoot(),
"src",
"AcDream.App",
"Rendering",
"GameWindow.cs"));
private static void AssertAppearsInOrder(string source, params string[] needles)
{
int cursor = -1;
foreach (string needle in needles)
{
int next = source.IndexOf(needle, cursor + 1, StringComparison.Ordinal);
Assert.True(next >= 0, $"Missing expected source fragment: {needle}");
Assert.True(next > cursor, $"Out-of-order source fragment: {needle}");
cursor = next;
}
}
private static string FindRepoRoot()
{
DirectoryInfo? directory = new(AppContext.BaseDirectory);
while (directory is not null)
{
if (File.Exists(Path.Combine(directory.FullName, "AcDream.slnx")))
return directory.FullName;
directory = directory.Parent;
}
throw new DirectoryNotFoundException("Could not find AcDream.slnx.");
}
}