This reverts ceec3bc4. Two independent reasons, either sufficient.
The rendering regression. The slice deleted TextRenderGlStateScope, which
saved GL_MULTISAMPLE and GL_SAMPLE_ALPHA_TO_COVERAGE on entry, disabled them
for the text pass, and restored them on exit (TextRenderGlStateScope.cs:111-112
and 153-154 at the parent commit). Its replacement bakes that state into the
text pipeline but nothing restores it, and GlGpuPassEncoder.Dispose does not
either. Every world renderer is still raw GL at this point in the campaign, so
from the first UI frame onward the world drew with multisampling disabled.
The offline pixel gate caught it: 1,791 of 563,200 compared pixels differed,
0.318% against a 0.001 threshold. The commit message attributed this to
wall-clock-driven ambient animation shifting phase, and committed through the
failure. That explanation does not survive its own control: capturing twice at
the reverted-to commit differs by 19 pixels and twice at the slice's own commit
by 8, while base-versus-head differs by 1,791 - a 224x gap that no shared-noise
source explains. An amplified difference image settles it visually: the changed
pixels are the silhouette edges of every tree, building and rock, with terrain
interiors, water and the entire UI untouched. That is the signature of losing
edge antialiasing, not of animated sprites.
This is the exact failure mode two existing memory notes already warn about -
a mid-frame renderer must set every GL state it uses rather than inherit it,
and issue #52's lesson that a rendering migration must audit per-pass GL state
before declaring itself done.
The scope. The brief was three small leaf renderers plus additive frame-
lifecycle wiring, roughly ten files. The commit changed 334 files with 3,665
insertions and 3,845 deletions, including 323 public-to-internal visibility
conversions across the App assembly, 55 test files, two retired conformance
tests, and a self-described temporary escape hatch for bridging raw-GL viewport
textures. Even without the regression, that is not separable into the part
worth keeping and the part worth dropping.
Reverting rather than patching because the good work here - the RHI frame
lifecycle wiring and a genuine render-state-cache staleness fix - is small
enough to redo cleanly against a tightened spec, while untangling it from 300+
files of unrelated churn is not.
Post-revert: Release build clean, App suite back to 3,843 passed / 3 skipped,
offline pixel gate passing at 19 differing pixels.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
188 lines
6.9 KiB
C#
188 lines
6.9 KiB
C#
using AcDream.App.Studio;
|
|
using AcDream.App.UI;
|
|
|
|
namespace AcDream.App.Tests.Studio;
|
|
|
|
/// <summary>
|
|
/// Tests for <see cref="DumpLayout"/> — parsing the retail UI dump JSON and
|
|
/// building a <see cref="UiElement"/> tree from it.
|
|
///
|
|
/// These tests load the real dump file from the source tree
|
|
/// (<c>docs/research/2026-06-25-retail-ui-layout-dump.json</c>). The test
|
|
/// skips cleanly when the file is absent (should not happen in a normal dev
|
|
/// checkout, but guards against stripped CI machines).
|
|
/// </summary>
|
|
public class DumpLayoutTests
|
|
{
|
|
private static string DumpPath()
|
|
{
|
|
// Walk up from the test output directory to the solution root,
|
|
// mirroring ConformanceDats.SolutionRoot().
|
|
var dir = AppContext.BaseDirectory;
|
|
while (!string.IsNullOrEmpty(dir))
|
|
{
|
|
if (File.Exists(Path.Combine(dir, "AcDream.slnx")))
|
|
return Path.Combine(dir, "docs", "research",
|
|
"2026-06-25-retail-ui-layout-dump.json");
|
|
dir = Path.GetDirectoryName(dir);
|
|
}
|
|
// Fallback: try a relative path (won't find it but skip rather than throw)
|
|
return Path.Combine(AppContext.BaseDirectory,
|
|
"docs", "research", "2026-06-25-retail-ui-layout-dump.json");
|
|
}
|
|
|
|
private static (uint, int, int) NoTex(uint _) => (1u, 1, 1);
|
|
|
|
// ── Helpers ──────────────────────────────────────────────────────────
|
|
|
|
/// <summary>Depth-first search for an element with the given EventId.</summary>
|
|
private static UiElement? FindById(UiElement root, uint id)
|
|
{
|
|
if (root.EventId == id) return root;
|
|
foreach (var c in root.Children)
|
|
{
|
|
var found = FindById(c, id);
|
|
if (found is not null) return found;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
/// <summary>Count the total elements in the tree (self + all descendants).</summary>
|
|
private static int CountAll(UiElement root)
|
|
{
|
|
int n = 1;
|
|
foreach (var c in root.Children) n += CountAll(c);
|
|
return n;
|
|
}
|
|
|
|
// ── Tests ─────────────────────────────────────────────────────────────
|
|
|
|
/// <summary>
|
|
/// Loading the "inventory" slug should succeed and the returned tree should
|
|
/// contain an element with EventId == 0x100001D5 (the doll viewport node)
|
|
/// and at least 40 elements in total.
|
|
/// </summary>
|
|
[Fact]
|
|
public void Load_Inventory_ReturnsTreeWithDollViewport()
|
|
{
|
|
var path = DumpPath();
|
|
if (!File.Exists(path))
|
|
return; // Skip: dump not available.
|
|
|
|
var root = DumpLayout.Load(path, "inventory", NoTex, out var err);
|
|
|
|
Assert.NotNull(root);
|
|
Assert.Null(err);
|
|
|
|
// The doll viewport element must appear somewhere in the tree.
|
|
const uint dollViewportId = 0x100001D5u;
|
|
var found = FindById(root!, dollViewportId);
|
|
Assert.NotNull(found);
|
|
|
|
// The full tree must be reasonably deep — 59 dump nodes → >= 40 elements.
|
|
int total = CountAll(root!);
|
|
Assert.True(total >= 40,
|
|
$"Expected >= 40 elements in inventory tree; got {total}");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Loading an unknown slug must return null and a non-empty error string.
|
|
/// </summary>
|
|
[Fact]
|
|
public void Load_UnknownSlug_ReturnsNullWithError()
|
|
{
|
|
var path = DumpPath();
|
|
if (!File.Exists(path))
|
|
return; // Skip.
|
|
|
|
var root = DumpLayout.Load(path, "this_slug_does_not_exist", NoTex, out var err);
|
|
|
|
Assert.Null(root);
|
|
Assert.NotNull(err);
|
|
Assert.NotEmpty(err!);
|
|
}
|
|
|
|
/// <summary>
|
|
/// The root element's Left/Top should be (0,0) (the panel's rect offset has
|
|
/// been stripped so the tree sits at the window origin), and its Width/Height
|
|
/// should match the dump panel dimensions.
|
|
/// </summary>
|
|
[Fact]
|
|
public void Load_Inventory_RootAtOrigin()
|
|
{
|
|
var path = DumpPath();
|
|
if (!File.Exists(path))
|
|
return; // Skip.
|
|
|
|
var root = DumpLayout.Load(path, "inventory", NoTex, out _);
|
|
Assert.NotNull(root);
|
|
|
|
// Root always placed at (0,0) by DumpLayout (origin of the UiHost).
|
|
Assert.Equal(0f, root!.Left);
|
|
Assert.Equal(0f, root.Top);
|
|
// Width/Height come from the panel record in the dump.
|
|
Assert.True(root.Width > 0, "Root width must be > 0");
|
|
Assert.True(root.Height > 0, "Root height must be > 0");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Children must use parent-relative coordinates (the dump rects are absolute;
|
|
/// DumpLayout subtracts the parent rect to produce parent-local offsets).
|
|
/// Verify that at least the direct children of the root have Left/Top values
|
|
/// that are NOT equal to the absolute rect they had in the dump (since the root
|
|
/// was at x>0 in screen space but we place it at 0,0).
|
|
/// </summary>
|
|
[Fact]
|
|
public void Load_Inventory_ChildrenAreParentRelative()
|
|
{
|
|
var path = DumpPath();
|
|
if (!File.Exists(path))
|
|
return; // Skip.
|
|
|
|
var root = DumpLayout.Load(path, "inventory", NoTex, out _);
|
|
Assert.NotNull(root);
|
|
|
|
// If the dump has children at absolute x>=500 but the root is at 0,
|
|
// a correct parent-relative placement will give children x < 500.
|
|
// (The inventory panel root is at absolute x=500; children in the dump
|
|
// also start at x=500 — after subtraction they should land near x=0.)
|
|
bool anyChildAtAbsoluteX = false;
|
|
foreach (var child in root!.Children)
|
|
{
|
|
if (child.Left >= 490f) // would indicate absolute not relative
|
|
{
|
|
anyChildAtAbsoluteX = true;
|
|
break;
|
|
}
|
|
}
|
|
Assert.False(anyChildAtAbsoluteX,
|
|
"Children appear to have absolute coords (Left >= 490) — " +
|
|
"DumpLayout must subtract the parent rect.");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Every panel slug known in the dump must load without error.
|
|
/// This is a smoke test that the JSON parse + tree build does not
|
|
/// crash on any of the 26 panels.
|
|
/// </summary>
|
|
[Fact]
|
|
public void Load_AllSlugs_Succeed()
|
|
{
|
|
var path = DumpPath();
|
|
if (!File.Exists(path))
|
|
return; // Skip.
|
|
|
|
var slugs = UiDumpModel.ListSlugs(path);
|
|
Assert.True(slugs.Count >= 20,
|
|
$"Expected >= 20 panel slugs in dump; got {slugs.Count}");
|
|
|
|
foreach (var slug in slugs)
|
|
{
|
|
var root = DumpLayout.Load(path, slug, NoTex, out var err);
|
|
Assert.True(root is not null || err is not null,
|
|
$"Load('{slug}') returned both null root AND null error — one must be set.");
|
|
if (root is null)
|
|
Assert.Fail($"Slug '{slug}' failed with error: {err}");
|
|
}
|
|
}
|
|
}
|