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>
189 lines
7.6 KiB
C#
189 lines
7.6 KiB
C#
using DatReaderWriter;
|
|
using AcDream.Content;
|
|
|
|
namespace AcDream.App.UI.Layout;
|
|
|
|
/// <summary>
|
|
/// Instantiates retail's category and component listbox templates from LayoutDesc
|
|
/// 0x21000033. This is the retained equivalent of
|
|
/// <c>UIElement_ListBox::AddItemFromTemplateList</c> used by
|
|
/// <c>gmSpellComponentUI::UpdateComponents @ 0x0048A910</c>.
|
|
/// </summary>
|
|
public sealed class ComponentBookTemplateFactory
|
|
{
|
|
public const uint LayoutId = 0x21000033u;
|
|
public const uint CategoryTemplateId = 0x10000466u;
|
|
public const uint ComponentTemplateId = 0x10000467u;
|
|
public const uint IconId = 0x10000468u;
|
|
public const uint NameId = 0x10000469u;
|
|
public const uint OwnedCountId = 0x1000046Au;
|
|
public const uint DesiredCountId = 0x1000046Bu;
|
|
|
|
private const uint LocalStringTableId = 0x23000001u;
|
|
private const uint HighlightState = UiButtonStateMachine.Highlight;
|
|
|
|
private static readonly (string Key, string Fallback)[] CategoryStrings =
|
|
[
|
|
("ID_SpellComp_Category_Scarabs", "SCARABS"),
|
|
("ID_SpellComp_Category_Herbs", "HERBS"),
|
|
("ID_SpellComp_Category_Gems", "POWDERED GEMS"),
|
|
("ID_SpellComp_Category_Alchemical", "ALCHEMICAL SUBSTANCES"),
|
|
("ID_SpellComp_Category_Talismans", "TALISMANS"),
|
|
("ID_SpellComp_Category_Tapers", "TAPERS"),
|
|
("ID_SpellComp_Category_Peas", "PEAS"),
|
|
];
|
|
|
|
private readonly ElementInfo _categoryTemplate;
|
|
private readonly ElementInfo _componentTemplate;
|
|
private readonly Func<uint, (uint tex, int w, int h)> _resolveSprite;
|
|
private readonly UiDatFont? _defaultFont;
|
|
private readonly IReadOnlyDictionary<uint, UiDatFont?> _fonts;
|
|
private readonly string[] _categoryNames;
|
|
|
|
public ComponentBookTemplateFactory(
|
|
ElementInfo categoryTemplate,
|
|
ElementInfo componentTemplate,
|
|
Func<uint, (uint tex, int w, int h)> resolveSprite,
|
|
UiDatFont? defaultFont,
|
|
IReadOnlyDictionary<uint, UiDatFont?>? fonts = null,
|
|
IReadOnlyList<string>? categoryNames = null)
|
|
{
|
|
_categoryTemplate = categoryTemplate;
|
|
_componentTemplate = componentTemplate;
|
|
_resolveSprite = resolveSprite;
|
|
_defaultFont = defaultFont;
|
|
_fonts = fonts ?? new Dictionary<uint, UiDatFont?>();
|
|
_categoryNames = categoryNames?.ToArray()
|
|
?? CategoryStrings.Select(value => value.Fallback).ToArray();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Loads and resolves the two template definitions while the caller holds the
|
|
/// shared DAT lock. Fonts and localized category strings are captured eagerly,
|
|
/// so later inventory refreshes instantiate rows without reading DAT files.
|
|
/// </summary>
|
|
public static ComponentBookTemplateFactory? TryLoad(
|
|
IDatReaderWriter dats,
|
|
Func<uint, (uint tex, int w, int h)> resolveSprite,
|
|
UiDatFont? defaultFont,
|
|
Func<uint, UiDatFont?>? resolveFont)
|
|
{
|
|
ElementInfo? category = LayoutImporter.ImportInfos(
|
|
dats, LayoutId, CategoryTemplateId);
|
|
ElementInfo? component = LayoutImporter.ImportInfos(
|
|
dats, LayoutId, ComponentTemplateId);
|
|
if (category is null || component is null)
|
|
return null;
|
|
|
|
var fonts = new Dictionary<uint, UiDatFont?>();
|
|
CaptureFonts(category, resolveFont, fonts);
|
|
CaptureFonts(component, resolveFont, fonts);
|
|
|
|
var strings = new DatStringResolver(dats);
|
|
string[] categoryNames = CategoryStrings
|
|
.Select(value => strings.Resolve(
|
|
LocalStringTableId,
|
|
DatStringResolver.ComputeHash(value.Key))
|
|
?? value.Fallback)
|
|
.ToArray();
|
|
|
|
return new ComponentBookTemplateFactory(
|
|
category, component, resolveSprite, defaultFont, fonts, categoryNames);
|
|
}
|
|
|
|
public UiTemplateListSlot CreateCategoryRow(uint category)
|
|
{
|
|
ImportedLayout content = Build(_categoryTemplate);
|
|
if (content.Root is not UiText title)
|
|
throw new InvalidOperationException(
|
|
"Retail component category template did not resolve to UIElement_Text.");
|
|
|
|
string label = category < _categoryNames.Length
|
|
? _categoryNames[category]
|
|
: "OTHER COMPONENTS";
|
|
title.LinesProvider = () => [new UiText.Line(label, title.DefaultColor)];
|
|
|
|
return new UiTemplateListSlot(
|
|
content, uint.MaxValue, content.Root is IUiDatStateful stateful
|
|
? stateful.ActiveRetailStateId
|
|
: UiStateInfo.DirectStateId, selectedState: null);
|
|
}
|
|
|
|
public ComponentRow CreateComponentRow(
|
|
uint componentId,
|
|
uint iconTexture,
|
|
string name,
|
|
int ownedCount,
|
|
uint desiredCount)
|
|
{
|
|
ImportedLayout content = Build(_componentTemplate);
|
|
UiElement iconHost = Required(content, IconId);
|
|
UiText nameText = Required<UiText>(content, NameId);
|
|
UiText ownedText = Required<UiText>(content, OwnedCountId);
|
|
UiField desiredField = Required<UiField>(content, DesiredCountId);
|
|
|
|
var icon = new UiTextureElement
|
|
{
|
|
Width = iconHost.Width,
|
|
Height = iconHost.Height,
|
|
Anchors = AnchorEdges.Left | AnchorEdges.Top
|
|
| AnchorEdges.Right | AnchorEdges.Bottom,
|
|
Texture = iconTexture,
|
|
};
|
|
iconHost.AddChild(icon);
|
|
|
|
nameText.LinesProvider = () => [new UiText.Line(name, nameText.DefaultColor)];
|
|
ownedText.LinesProvider = () =>
|
|
[new UiText.Line(ownedCount.ToString(System.Globalization.CultureInfo.InvariantCulture),
|
|
ownedText.DefaultColor)];
|
|
|
|
// NumberInputFilter + the 0..5000 validation are installed by the controller,
|
|
// matching gmSpellComponentUI::ListenToElementMessage @ 0x0048A420.
|
|
desiredField.ClearOnSubmit = false;
|
|
desiredField.RecordHistory = false;
|
|
desiredField.SelectAllOnFocus = true;
|
|
desiredField.CharacterFilter = char.IsAsciiDigit;
|
|
desiredField.SetText(desiredCount.ToString(
|
|
System.Globalization.CultureInfo.InvariantCulture));
|
|
|
|
uint normalState = content.Root is IUiDatStateful stateful
|
|
? stateful.ActiveRetailStateId
|
|
: UiStateInfo.DirectStateId;
|
|
var slot = new UiTemplateListSlot(
|
|
content, componentId, normalState, HighlightState);
|
|
return new ComponentRow(slot, desiredField);
|
|
}
|
|
|
|
private ImportedLayout Build(ElementInfo template)
|
|
=> LayoutImporter.Build(
|
|
template,
|
|
_resolveSprite,
|
|
_defaultFont,
|
|
did => _fonts.TryGetValue(did, out UiDatFont? font) ? font : _defaultFont);
|
|
|
|
private static T Required<T>(ImportedLayout content, uint id)
|
|
where T : UiElement
|
|
=> content.FindElement(id) as T
|
|
?? throw new InvalidOperationException(
|
|
$"Retail component template element 0x{id:X8} did not resolve to {typeof(T).Name}.");
|
|
|
|
private static UiElement Required(ImportedLayout content, uint id)
|
|
=> content.FindElement(id)
|
|
?? throw new InvalidOperationException(
|
|
$"Retail component template element 0x{id:X8} is missing.");
|
|
|
|
private static void CaptureFonts(
|
|
ElementInfo info,
|
|
Func<uint, UiDatFont?>? resolveFont,
|
|
Dictionary<uint, UiDatFont?> fonts)
|
|
{
|
|
if (info.FontDid != 0u && !fonts.ContainsKey(info.FontDid))
|
|
fonts[info.FontDid] = resolveFont?.Invoke(info.FontDid);
|
|
foreach (ElementInfo child in info.Children)
|
|
CaptureFonts(child, resolveFont, fonts);
|
|
}
|
|
|
|
public readonly record struct ComponentRow(
|
|
UiTemplateListSlot Slot,
|
|
UiField DesiredField);
|
|
}
|