test: replace render source freezes

This commit is contained in:
Erik 2026-08-18 14:58:25 +02:00
parent c31a9ac411
commit 5a33369074
7 changed files with 425 additions and 345 deletions

View file

@ -1,9 +1,11 @@
using System.Numerics;
using System.Reflection;
using AcDream.App.Composition;
using AcDream.App.Rendering;
using AcDream.App.Rendering.Selection;
using AcDream.App.Rendering.Vfx;
using AcDream.App.Streaming;
using AcDream.App.Tests.Architecture;
using AcDream.Core.Rendering;
using AcDream.Core.World;
using AcDream.Runtime;
@ -326,20 +328,46 @@ public sealed class WorldSceneRendererTests
[Fact]
public void GameWindow_DelegatesWorldRenderingWithoutOwningDrawBranches()
{
string source = File.ReadAllText(Path.Combine(
FindRepoRoot(),
"src",
"AcDream.App",
"Composition",
"FrameRootComposition.cs"));
MethodInfo compose = typeof(FrameRootCompositionPhase).GetMethod(
"ComposeCore",
BindingFlags.Instance | BindingFlags.NonPublic)!;
IReadOnlyList<CompiledCall> calls = CompiledCallGraph.Read(compose);
Assert.Contains("new WorldSceneRenderer(", source);
Assert.Contains("new RenderFrameOrchestrator(", source);
Assert.DoesNotContain("_worldSceneRenderer", source);
Assert.DoesNotContain("_retailPViewRenderer.DrawInside(", source);
Assert.DoesNotContain("_retailAlphaQueue.BeginFrame();", source);
Assert.DoesNotContain("_terrainDrawDiagnostics!.Begin();", source);
Assert.DoesNotContain("SkipWorldGeometry:", source);
int worldRenderer = RequiredCallIndex(
calls,
typeof(WorldSceneRenderer),
".ctor");
int frameOrchestrator = RequiredCallIndex(
calls,
typeof(RenderFrameOrchestrator),
".ctor");
Assert.True(worldRenderer < frameOrchestrator);
Assert.Single(
calls,
call => call.Target.DeclaringType == typeof(WorldSceneRenderer)
&& call.Target.Name == ".ctor");
Assert.Single(
calls,
call => call.Target.DeclaringType == typeof(RenderFrameOrchestrator)
&& call.Target.Name == ".ctor");
FieldInfo[] windowFields = typeof(GameWindow).GetFields(
BindingFlags.Instance
| BindingFlags.Public
| BindingFlags.NonPublic
| BindingFlags.DeclaredOnly);
Assert.DoesNotContain(
windowFields,
field => field.FieldType == typeof(WorldSceneRenderer)
|| field.FieldType == typeof(RetailPViewRenderer)
|| field.FieldType == typeof(TerrainDrawDiagnosticsController)
|| field.FieldType == typeof(RenderFrameOrchestrator));
FieldInfo worldPhase = Assert.Single(
typeof(RenderFrameOrchestrator).GetFields(
BindingFlags.Instance | BindingFlags.NonPublic),
field => field.FieldType == typeof(IWorldSceneFramePhase));
Assert.Equal("_world", worldPhase.Name);
}
[Fact]
@ -771,28 +799,13 @@ public sealed class WorldSceneRendererTests
[]);
}
private static int CountOccurrences(string source, string value)
private static int RequiredCallIndex(
IReadOnlyList<CompiledCall> calls,
Type declaringType,
string methodName)
{
int count = 0;
int cursor = 0;
while ((cursor = source.IndexOf(value, cursor, StringComparison.Ordinal)) >= 0)
{
count++;
cursor += value.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.");
int index = CompiledCallGraph.IndexOf(calls, declaringType, methodName);
Assert.True(index >= 0, $"Missing compiled call: {declaringType.Name}.{methodName}");
return index;
}
}