acdream/tests/AcDream.App.Tests/Rendering/GameWindowRenderLeafCompositionTests.cs
Erik 844cf092a1 feat(render): Campaign V slice V11 commit 1 - delete ImGui, Studio, and the DevTools frontend
The ImGui developer-tools stack (AcDream.UI.ImGui), UI Studio
(src/AcDream.App/Studio), and the DevToolsFramePresenter/
SettingsDevToolsCompositionPhase ImGui composition machinery are removed.
Vulkan never composed a DevTools frontend (DevToolsEnabled already forced
false whenever the backend was Vulkan); this commit makes that permanent by
deleting the only implementation rather than leaving a dead branch behind.

What moved: Studio/SampleData.cs is a live production dependency
(InteractionRetainedUiComposition's character-sheet fallback, plus three
UI.Layout test files) - git mv'd to src/AcDream.App/UI/Layout/SampleData.cs,
namespace AcDream.App.UI.Layout, and trimmed to the SampleCharacter API that
is actually still called (BuildObjectTable/AddItem/AddEquipped/the item-guid
and icon constants had zero callers left once the Studio fixture provider
that used them was deleted).

What survives as backend-neutral seams, per the tests that still exercise
them: IDevToolsFrameLifecycle (moved into RenderFramePreparationController.cs,
now always bound to null), IFramebufferDevToolsTarget/FramebufferDevToolsBinding
in FramebufferResizeController.cs (its concrete DevToolsFramebufferTarget
adapter is deleted), and IDevToolsGameplayCommands in
GameplayInputCommandController.cs (DevToolsGameplayCommands becomes a
documented no-op instead of forwarding to the deleted presenter). A follow-up
re-homes Settings/Debug onto the retained UI through IPanelRenderer; until
then keybind remapping falls back to editing keybinds.json.

DevToolsEnabled is now `private const bool DevToolsEnabled = false`.
RuntimeOptions.DevTools is unchanged and still reaches VulkanGraphicsContext
for the optional debug-utils extensions; Program.cs now logs one line when
ACDREAM_DEVTOOLS=1 explaining that the ImGui UI is gone and the flag is
Vulkan-only now.

Removed: AcDream.UI.ImGui (project + ImGui.NET/Silk.NET.OpenGL.Extensions.ImGui
package refs), src/AcDream.App/Studio (minus SampleData.cs),
DevToolsFramePresenter.cs and everything only it constructed
(ISettingsDevToolsCompositionFactory, RetailSettingsDevToolsCompositionFactory,
DevToolsCompositionOwner, IGameWindowSettingsDevToolsPublication,
SettingsDevToolsOptionalDependencies, the "developer tools" shutdown-ledger
stage and its DevTools-typed fields on IngressShutdownRoots/
RenderShutdownRoots), the ui-studio Program.cs verb, and the cimgui native
manifest entries in GraphicalHostPlatformServices. GameWindow.cs's DevTools
composition branch, its _vitalsVm/_debugVm/_devToolsComposition/
_devToolsFramePresenter/_devToolsCommandBus fields, and every settingsDevTools
.DevTools?.* access across FrameRootComposition.cs/SessionPlayerComposition.cs
are gone with it.

Build green; complete Release solution suite 8,830 / 5 skips (App Tests
4,097/3 skips run standalone - one #250-family zero-allocation test flakes
under the full parallel `dotnet test AcDream.slnx` run, a pre-existing,
documented class unrelated to this change).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-28 23:56:04 +02:00

303 lines
11 KiB
C#

using AcDream.App.Rendering;
namespace AcDream.App.Tests.Rendering;
public sealed class GameWindowRenderLeafCompositionTests
{
[Fact]
public void ProductionRender_PreservesPrivatePresentationAndCaptureOrder()
{
string presentation = Source("PrivatePresentationRenderer.cs");
string orchestrator = Source("RenderFrameOrchestrator.cs");
AssertAppearsInOrder(
presentation,
"_portal.Draw(",
"_entityViewports?.Render();",
"_gameplayUi?.Render(",
"_devTools?.Render(",
"_screenshots?.CapturePending(");
AssertAppearsInOrder(
orchestrator,
"_world.Render(input);",
"_presentation.Render(input, world);",
"_diagnostics.Publish(input, outcome);");
}
[Fact]
public void ProductionRender_Prepares_resources_then_devtools_weather_and_world()
{
string source = Source("RenderFramePreparationController.cs");
AssertAppearsInOrder(
source,
"_resources.Prepare(input);",
"_devTools?.BeginFrame((float)input.DeltaSeconds);",
"_weather.Tick(input.DeltaSeconds);");
}
[Fact]
public void Composition_transfers_portal_tunnel_before_constructing_frame_borrowers()
{
string phase = File.ReadAllText(Path.Combine(
FindRepoRoot(),
"src",
"AcDream.App",
"Composition",
"SessionPlayerComposition.cs"));
string source = GameWindowSource();
string framePhase = FrameRootSource();
AssertAppearsInOrder(
phase,
"d.PortalTunnelFallback.Transfer(",
"new LocalPlayerTeleportController(",
"new LocalPlayerTeleportPresentation(portalTunnel)",
"d.TeleportSink.BindOwned(localTeleport)",
"_publication.PublishSessionPlayer(result);");
AssertAppearsInOrder(
source,
"new SessionPlayerCompositionPhase(",
"new FrameRootCompositionPhase(");
AssertAppearsInOrder(
framePhase,
"new LocalPlayerTeleportRenderStateSource(",
"new RenderFrameResourceController(",
"new PrivatePresentationRenderer(",
"new RenderFrameOrchestrator(");
}
[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(",
"private AcDream.App.Rendering.WorldRenderDiagnostics? _worldRenderDiagnostics",
"private AcDream.App.Rendering.WorldRenderFrameBuilder?",
"private AcDream.App.Rendering.SkyPesFrameController?",
"private AcDream.App.Rendering.RetailPViewRenderer?",
"private AcDream.App.Rendering.RetailPViewPassExecutor?",
"private AcDream.App.Rendering.RetailPViewCellSource?",
"private AcDream.App.Rendering.TerrainDrawDiagnosticsController?",
];
foreach (string identifier in removed)
Assert.DoesNotContain(identifier, source, StringComparison.Ordinal);
Assert.Contains("new PaperdollFramePresenter(", LivePresentationSource());
string framePhase = FrameRootSource();
Assert.Contains("new RenderFrameResourceController(", framePhase);
Assert.Contains("new RenderWeatherFrameController(", framePhase);
Assert.Contains("new PrivatePresentationRenderer(", framePhase);
Assert.Contains("new RenderFrameOrchestrator(", framePhase);
Assert.Contains("new DisplayFramePacingController(", source);
string pointerSource = File.ReadAllText(Path.Combine(
FindRepoRoot(),
"src",
"AcDream.App",
"Input",
"CameraPointerInputController.cs"));
Assert.Contains("_capture.WantCaptureMouse", pointerSource);
}
[Fact]
public void Shutdown_DrainsGpuBeforeFrontendsAndPreservesFrameBorrowerOrder()
{
// Campaign V slice V11 removed the ImGui developer-tools frontend and
// its "developer tools" shutdown stage entry along with it; this test
// used to pin that entry's position and is now renamed to pin what
// survives it.
string source = GameWindowLifetimeSource();
AssertAppearsInOrder(
source,
"new ResourceShutdownStage(\"submitted GPU work\"",
"new ResourceShutdownStage(\"render frontends\"",
"Hard(\"portal tunnel\"",
"Hard(\"paperdoll viewport\"",
"new ResourceShutdownStage(\"OpenGL context\"");
AssertAppearsInOrder(
source,
"new ResourceShutdownStage(\"frame borrowers\"",
"frame.FrameGraphPublication?.Dispose()",
"frame.FrameBindings?.Dispose()",
"new ResourceShutdownStage(\"session dependents\"");
AssertAppearsInOrder(
source,
"Hard(\"frame pacing\", render.FramePacing.Dispose)",
"Hard(\"frame profiler\", render.FrameProfiler.Dispose)");
AssertAppearsInOrder(
source,
"frame.FrameGraphPublication?.Dispose()",
"new ResourceShutdownStage(\"render frontends\"",
"new ResourceShutdownStage(\"input context\"",
"platform.Input?.Dispose()",
"new ResourceShutdownStage(\"OpenGL context\"");
}
[Fact]
public void ProductionOutcome_UsesObservedWorldAndScreenshotFacts()
{
string presentation = Source("PrivatePresentationRenderer.cs");
string orchestrator = Source("RenderFrameOrchestrator.cs");
AssertAppearsInOrder(
presentation,
"_foundation.Foundation.PortalViewportVisible;",
"_portal.Draw(",
"bool screenshotCaptured = _screenshots?.CapturePending(",
"portalViewportVisible,",
"screenshotCaptured);");
AssertAppearsInOrder(
orchestrator,
"_gpuMeasurement.BeginFrame();",
"world = _world.Render(input);",
"_presentation.Render(input, world);",
"_gpuMeasurement.EndFrame();",
"new RenderFrameOutcome(world, presentation);",
"_diagnostics.Publish(input, outcome);");
}
[Fact]
public void GameWindow_OnRenderIsOneImmutableOrchestratorHandoff()
{
string source = GameWindowSource();
int start = source.IndexOf(
"private void OnRender(double deltaSeconds)",
StringComparison.Ordinal);
int end = source.IndexOf(
"private void OnFramebufferResize(",
start,
StringComparison.Ordinal);
Assert.True(start >= 0 && end > start);
string body = source[start..end];
Assert.Equal(1, CountOccurrences(body, "_frameGraphs.Render("));
Assert.DoesNotContain("_gpuFrameFlights", body);
Assert.DoesNotContain("_worldScene", body);
Assert.DoesNotContain("_devToolsFramePresenter", body);
Assert.DoesNotContain("_retailUiRuntime", body);
Assert.DoesNotContain("_frameScreenshots", body);
}
[Fact]
public void PaperdollComposition_SkipsEitherMissingOptionalUiSurface()
{
string source = LivePresentationSource();
AssertAppearsInOrder(
source,
"PaperdollViewportWidget is { } viewport",
"InventoryFrame is { } inventoryFrame",
"new PaperdollFramePresenter(");
Assert.DoesNotContain("Paperdoll inventory frame is required.", source);
}
[Fact]
public void TerrainAndFrameDiagnostics_AreComposedAsOneFocusedOwner()
{
string source = FrameRootSource();
Assert.Contains(
"new TerrainDrawDiagnosticsController(",
source);
Assert.Contains("new WorldScenePassExecutor(", source);
Assert.DoesNotContain("_terrainDrawDiagnostics!.Begin();", source);
Assert.DoesNotContain("_terrainDrawDiagnostics.Complete();", source);
}
private static string GameWindowSource() => File.ReadAllText(Path.Combine(
FindRepoRoot(),
"src",
"AcDream.App",
"Rendering",
"GameWindow.cs"));
private static string GameWindowLifetimeSource() => File.ReadAllText(Path.Combine(
FindRepoRoot(),
"src",
"AcDream.App",
"Rendering",
"GameWindowLifetime.cs"));
private static string LivePresentationSource() => File.ReadAllText(Path.Combine(
FindRepoRoot(),
"src",
"AcDream.App",
"Composition",
"LivePresentationComposition.cs"));
private static string FrameRootSource() => File.ReadAllText(Path.Combine(
FindRepoRoot(),
"src",
"AcDream.App",
"Composition",
"FrameRootComposition.cs"));
private static string Source(string fileName) => File.ReadAllText(Path.Combine(
FindRepoRoot(),
"src",
"AcDream.App",
"Rendering",
fileName));
private static int CountOccurrences(string source, string value)
{
int count = 0;
int cursor = 0;
while ((cursor = source.IndexOf(value, cursor, StringComparison.Ordinal)) >= 0)
{
count++;
cursor += value.Length;
}
return count;
}
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.");
}
}