refactor(render): extract frame presentation diagnostics
This commit is contained in:
parent
7e4cfb37c3
commit
733126a272
20 changed files with 3767 additions and 1021 deletions
|
|
@ -0,0 +1,167 @@
|
|||
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_BeginsDevToolsBeforeWorldAndBeginsDispatcherOnce()
|
||||
{
|
||||
string source = GameWindowSource();
|
||||
|
||||
AssertAppearsInOrder(
|
||||
source,
|
||||
"_devToolsFramePresenter?.BeginFrame((float)deltaSeconds);",
|
||||
"Weather.Tick(nowSeconds: _weatherAccum",
|
||||
"_retailSelectionScene?.BeginFrame();");
|
||||
Assert.Equal(1, CountOccurrences(source, "_wbDrawDispatcher?.BeginFrame("));
|
||||
}
|
||||
|
||||
[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",
|
||||
];
|
||||
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("_inputCapture.WantCaptureMouse", source);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Shutdown_PreservesBorrowedDevtoolsLifetimeAndDrainsGpuBeforeFrontends()
|
||||
{
|
||||
string source = GameWindowSource();
|
||||
|
||||
AssertAppearsInOrder(
|
||||
source,
|
||||
"new ResourceShutdownStage(\"submitted GPU work\"",
|
||||
"new ResourceShutdownStage(\"render frontends\"",
|
||||
"new(\"portal tunnel\"",
|
||||
"new(\"paperdoll viewport\"",
|
||||
"new ResourceShutdownStage(\"OpenGL context\"");
|
||||
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 int CountOccurrences(string source, string needle)
|
||||
{
|
||||
int count = 0;
|
||||
int cursor = 0;
|
||||
while ((cursor = source.IndexOf(needle, cursor, StringComparison.Ordinal)) >= 0)
|
||||
{
|
||||
count++;
|
||||
cursor += needle.Length;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
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.");
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue