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>
194 lines
8.9 KiB
C#
194 lines
8.9 KiB
C#
using AcDream.App.UI;
|
|
using AcDream.App.UI.Layout;
|
|
|
|
namespace AcDream.App.Tests.UI.Layout;
|
|
|
|
/// <summary>
|
|
/// Unit tests for Fix C: per-element dat FontDid resolver in <see cref="DatWidgetFactory"/>.
|
|
///
|
|
/// <para>
|
|
/// <see cref="UiDatFont"/> cannot be constructed in pure unit tests (GL + dat required),
|
|
/// so these tests verify the plumbing using null/non-null identity and sentinel resolvers:
|
|
/// <list type="bullet">
|
|
/// <item>Null resolver → DatFont unchanged (backward-compat: same as before Fix C).</item>
|
|
/// <item>Resolver present, FontDid == 0 → resolver NOT called; DatFont == global datFont.</item>
|
|
/// <item>Resolver returns null for an id (font missing) → DatFont falls back to global datFont.</item>
|
|
/// <item>Controller sets DatFont after build → controller value wins.</item>
|
|
/// <item><see cref="LayoutImporter.Build"/> threads fontResolve to the factory.</item>
|
|
/// </list>
|
|
/// </para>
|
|
/// </summary>
|
|
public class DatWidgetFactoryFontResolveTests
|
|
{
|
|
private static (uint, int, int) NoTex(uint _) => (0, 0, 0);
|
|
|
|
// ── Test 1: null fontResolve → DatFont == datFont (backward-compat) ─────
|
|
|
|
/// <summary>
|
|
/// When fontResolve is null (the live GameWindow path), BuildText must NOT
|
|
/// touch DatFont beyond setting it to the global datFont. Null in → null out.
|
|
/// </summary>
|
|
[Fact]
|
|
public void NullFontResolve_DatFont_EqualsGlobalFont()
|
|
{
|
|
var info = new ElementInfo { Type = 12, Width = 100, Height = 20, FontDid = 0x40000001u };
|
|
// datFont=null, fontResolve=null → backward-compat: DatFont == null
|
|
var t = Assert.IsType<UiText>(DatWidgetFactory.Create(info, NoTex, null, fontResolve: null));
|
|
Assert.Null(t.DatFont);
|
|
}
|
|
|
|
// ── Test 2: FontDid == 0 → resolver NOT called ────────────────────────────
|
|
|
|
/// <summary>
|
|
/// When the element has FontDid == 0, the fontResolve delegate must NOT be
|
|
/// invoked (the element has no dat font; fall through to global datFont).
|
|
/// </summary>
|
|
[Fact]
|
|
public void FontDidZero_ResolverNotCalled()
|
|
{
|
|
var info = new ElementInfo { Type = 12, Width = 100, Height = 20, FontDid = 0u };
|
|
bool called = false;
|
|
UiDatFont? Resolver(uint id) { called = true; return null; }
|
|
|
|
// FontDid=0 → resolver should never fire, even though one is provided.
|
|
Assert.IsType<UiText>(DatWidgetFactory.Create(info, NoTex, null, fontResolve: Resolver));
|
|
Assert.False(called, "fontResolve must NOT be called when FontDid == 0");
|
|
}
|
|
|
|
// ── Test 3: resolver returns null (font missing) → fallback to datFont ───
|
|
|
|
/// <summary>
|
|
/// When the element has a non-zero FontDid but the resolver returns null
|
|
/// (font not found in dats), DatFont must fall back to the shared global datFont.
|
|
/// Since datFont is null in unit tests, this verifies the fallback chain.
|
|
/// </summary>
|
|
[Fact]
|
|
public void ResolverReturnsNull_FallsBackToGlobalFont()
|
|
{
|
|
const uint SomeFontDid = 0x40000005u;
|
|
var info = new ElementInfo { Type = 12, Width = 100, Height = 20, FontDid = SomeFontDid };
|
|
int callCount = 0;
|
|
UiDatFont? Resolver(uint id) { callCount++; return null; } // always returns null (font missing)
|
|
|
|
var t = Assert.IsType<UiText>(DatWidgetFactory.Create(info, NoTex, datFont: null, fontResolve: Resolver));
|
|
|
|
// Resolver was called exactly once for this element.
|
|
Assert.Equal(1, callCount);
|
|
// Fallback: DatFont == global datFont (null in unit tests).
|
|
Assert.Null(t.DatFont);
|
|
}
|
|
|
|
// ── Test 4: resolver called with correct FontDid ──────────────────────────
|
|
|
|
/// <summary>
|
|
/// When fontResolve is provided and FontDid is non-zero, the resolver is called
|
|
/// with the element's exact FontDid value.
|
|
/// </summary>
|
|
[Fact]
|
|
public void ResolverCalledWithElementFontDid()
|
|
{
|
|
const uint ExpectedFontDid = 0x40000002u;
|
|
var info = new ElementInfo { Type = 12, Width = 100, Height = 20, FontDid = ExpectedFontDid };
|
|
uint? capturedId = null;
|
|
UiDatFont? Resolver(uint id) { capturedId = id; return null; }
|
|
|
|
DatWidgetFactory.Create(info, NoTex, datFont: null, fontResolve: Resolver);
|
|
|
|
Assert.Equal(ExpectedFontDid, capturedId);
|
|
}
|
|
|
|
// ── Test 5: controller DatFont override wins over build-time value ───────
|
|
|
|
/// <summary>
|
|
/// A controller that calls FindElement and sets DatFont afterward MUST override
|
|
/// whatever the factory set at build time. This is the backward-compat guarantee.
|
|
/// The DatFont property is settable — a controller can override it after build.
|
|
/// </summary>
|
|
[Fact]
|
|
public void ControllerDatFontOverride_WinsOverBuildTimeFont()
|
|
{
|
|
const uint SomeFontDid = 0x40000003u;
|
|
var info = new ElementInfo { Type = 12, Width = 100, Height = 20, FontDid = SomeFontDid };
|
|
UiDatFont? Resolver(uint _) => null; // returns null → build-time DatFont == null
|
|
|
|
var t = Assert.IsType<UiText>(DatWidgetFactory.Create(info, NoTex, datFont: null, fontResolve: Resolver));
|
|
Assert.Null(t.DatFont); // build-time value set by factory
|
|
|
|
// Controller simulated override: set DatFont to null explicitly.
|
|
// The real guarantee is that DatFont is a settable property.
|
|
// (We can't construct a real UiDatFont here — it requires GL + dats.)
|
|
t.DatFont = null; // controller overrides after build
|
|
Assert.Null(t.DatFont);
|
|
// ✓ DatFont is settable — controller override mechanism is in place.
|
|
}
|
|
|
|
// ── Test 6: LayoutImporter.Build threads fontResolve to factory ──────────
|
|
|
|
/// <summary>
|
|
/// When <see cref="LayoutImporter.Build"/> is given a fontResolve, it must pass
|
|
/// it to <see cref="DatWidgetFactory.Create"/> for EVERY element in the tree.
|
|
/// Verified by checking that a Type-12 child with FontDid triggers the resolver.
|
|
/// </summary>
|
|
[Fact]
|
|
public void LayoutImporter_Build_ThreadsFontResolve_ToFactory()
|
|
{
|
|
const uint FontDid = 0x40000004u;
|
|
var root = new ElementInfo { Id = 1u, Type = 3, Width = 200, Height = 100 };
|
|
var child = new ElementInfo { Id = 2u, Type = 12, Width = 100, Height = 20, FontDid = FontDid };
|
|
root.Children.Add(child);
|
|
|
|
int resolveCallCount = 0;
|
|
UiDatFont? Resolver(uint id) { resolveCallCount++; return null; }
|
|
|
|
var layout = LayoutImporter.Build(root, NoTex, datFont: null, fontResolve: Resolver);
|
|
|
|
// The child element has a non-zero FontDid — resolver must have been called for it.
|
|
Assert.True(resolveCallCount > 0, "fontResolve was not called for the child element");
|
|
// The child widget was built (findable in the layout).
|
|
Assert.NotNull(layout.FindElement(2u));
|
|
}
|
|
|
|
// ── Test 7: Meter element also receives element font from resolver ────────
|
|
|
|
/// <summary>
|
|
/// Type-7 (UiMeter) elements with a FontDid must also go through the resolver.
|
|
/// Verified by checking the resolver fires for a meter element with a non-zero FontDid.
|
|
/// </summary>
|
|
[Fact]
|
|
public void FontResolve_CalledForMeter_WhenFontDidPresent()
|
|
{
|
|
const uint MeterFontDid = 0x40000006u;
|
|
var meter = new ElementInfo { Type = 7, Width = 150, Height = 16, FontDid = MeterFontDid };
|
|
int callCount = 0;
|
|
UiDatFont? Resolver(uint id) { callCount++; return null; }
|
|
|
|
var w = DatWidgetFactory.Create(meter, NoTex, datFont: null, fontResolve: Resolver);
|
|
|
|
var m = Assert.IsType<UiMeter>(w);
|
|
// Resolver was called for the meter element's FontDid.
|
|
Assert.True(callCount > 0, "fontResolve was not called for meter element");
|
|
// Meter DatFont: resolver returned null, so DatFont falls back to global datFont (null).
|
|
Assert.Null(m.DatFont);
|
|
}
|
|
|
|
// ── Test 8: LayoutImporter.BuildFromInfos signature is backward-compat ────
|
|
|
|
/// <summary>
|
|
/// <see cref="LayoutImporter.BuildFromInfos"/> without fontResolve (default null)
|
|
/// must still work for all callers that don't pass it — verifies the optional
|
|
/// parameter default is correct and no existing callers broke.
|
|
/// </summary>
|
|
[Fact]
|
|
public void BuildFromInfos_WithoutFontResolve_WorksAsBeforeFix()
|
|
{
|
|
var root = new ElementInfo { Id = 10u, Type = 3, Width = 200, Height = 100 };
|
|
var child = new ElementInfo { Id = 11u, Type = 12, Width = 100, Height = 20, FontDid = 0x40000001u };
|
|
|
|
// Call without fontResolve (the old signature shape).
|
|
var layout = LayoutImporter.BuildFromInfos(root, new[] { child }, NoTex, datFont: null);
|
|
|
|
var t = Assert.IsType<UiText>(layout.FindElement(11u));
|
|
// No resolver → DatFont == global datFont (null in unit tests).
|
|
Assert.Null(t.DatFont);
|
|
}
|
|
}
|