acdream/src/AcDream.App/UI/Layout/RetailWindowFrame.cs
Erik 9aaf97e785 Revert "Campaign V slice V4a" - it lost world multisampling
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>
2026-07-27 18:29:28 +02:00

202 lines
8.4 KiB
C#

using System;
namespace AcDream.App.UI.Layout;
/// <summary>How a production retained window obtains its outer chrome.</summary>
public enum RetailWindowChrome
{
/// <summary>The imported root already is the complete retail outer frame.</summary>
Imported,
/// <summary>Wrap imported content in the shared retail nine-slice frame.</summary>
NineSlice,
/// <summary>Use the shared frame variant with the toolbar's two height stops.</summary>
CollapsibleNineSlice,
}
/// <summary>
/// The single mount path for production retained windows. It owns the distinction
/// between DAT roots that already contain chrome and content roots that require the
/// shared nine-slice wrapper, applies exact resize/opacity/visibility policy, mounts
/// the outer frame, and returns its registered typed handle.
/// </summary>
public static class RetailWindowFrame
{
public sealed record Options
{
public required string WindowName { get; init; }
public RetailWindowChrome Chrome { get; init; } = RetailWindowChrome.NineSlice;
/// <summary>Initial outer-frame position in screen pixels.</summary>
public float Left { get; init; }
public float Top { get; init; }
/// <summary>
/// Optional mounted content extent. Used when a LayoutDesc root shares a
/// larger auxiliary coordinate space (the main chat root is cropped to 490px).
/// </summary>
public float? ContentWidth { get; init; }
public float? ContentHeight { get; init; }
public bool RebaseContentLayout { get; init; }
/// <summary>
/// Optional DAT element whose effective 0x3C..0x3F properties provide
/// max-height, max-width, min-height, and min-width respectively. Explicit
/// option values win; wrapper chrome is added to DAT content constraints.
/// </summary>
public ElementInfo? DatConstraintSource { get; init; }
public float? MinWidth { get; init; }
public float? MinHeight { get; init; }
public float? MaxWidth { get; init; }
public float? MaxHeight { get; init; }
public bool Draggable { get; init; } = true;
public bool Resizable { get; init; } = true;
public bool ResizeX { get; init; } = true;
public bool ResizeY { get; init; } = true;
public ResizeEdges ResizableEdges { get; init; } =
ResizeEdges.Left | ResizeEdges.Right | ResizeEdges.Top | ResizeEdges.Bottom;
public bool ConstrainDragToParent { get; init; }
public bool ConstrainResizeToParent { get; init; }
public float Opacity { get; init; } = 1f;
public bool DrawChromeCenter { get; init; } = true;
public bool Visible { get; init; } = true;
/// <summary>
/// Increment when the authored default extent changes incompatibly.
/// Persistence preserves position and window state while resetting stale
/// saved dimensions to this mount's current DAT-authored extent.
/// </summary>
public int AuthoredGeometryRevision { get; init; }
/// <summary>
/// Top-level desktop anchors. Most movable windows are unanchored; fixed
/// retail HUD roots can preserve their authored screen-edge margins.
/// </summary>
public AnchorEdges OuterAnchors { get; init; } = AnchorEdges.None;
public AnchorEdges ContentAnchors { get; init; } =
AnchorEdges.Left | AnchorEdges.Top | AnchorEdges.Right | AnchorEdges.Bottom;
public bool? ContentClickThrough { get; init; }
public IRetainedPanelController? Controller { get; init; }
public IRetainedWindowStateController? StateController { get; init; }
}
public static RetailWindowHandle Mount(
UiRoot root,
UiElement content,
Func<uint, (uint handle, int w, int h)> resolveChrome,
Options options)
{
ArgumentNullException.ThrowIfNull(root);
ArgumentNullException.ThrowIfNull(content);
ArgumentNullException.ThrowIfNull(resolveChrome);
ArgumentNullException.ThrowIfNull(options);
ArgumentException.ThrowIfNullOrWhiteSpace(options.WindowName);
float contentWidth = options.ContentWidth ?? content.Width;
float contentHeight = options.ContentHeight ?? content.Height;
bool wrapped = options.Chrome != RetailWindowChrome.Imported;
int inset = wrapped ? 2 * RetailChromeSprites.Border : 0;
float outerWidth = contentWidth + inset;
float outerHeight = contentHeight + inset;
UiElement outerFrame;
if (wrapped)
{
outerFrame = options.Chrome switch
{
RetailWindowChrome.NineSlice => new UiNineSlicePanel(resolveChrome),
RetailWindowChrome.CollapsibleNineSlice => new UiCollapsibleFrame(resolveChrome),
_ => throw new ArgumentOutOfRangeException(nameof(options.Chrome)),
};
if (outerFrame is UiNineSlicePanel nineSlice)
nineSlice.DrawCenterFill = options.DrawChromeCenter;
const int border = RetailChromeSprites.Border;
content.Left = border;
content.Top = border;
content.Width = contentWidth;
content.Height = contentHeight;
content.Anchors = options.ContentAnchors;
content.Draggable = false;
content.Resizable = false;
if (options.ContentClickThrough is { } clickThrough)
content.ClickThrough = clickThrough;
if (options.RebaseContentLayout)
content.RebaseChildLayoutBaselines();
outerFrame.AddChild(content);
}
else
{
outerFrame = content;
content.Width = contentWidth;
content.Height = contentHeight;
content.Anchors = AnchorEdges.None;
if (options.ContentClickThrough is { } clickThrough)
content.ClickThrough = clickThrough;
if (options.RebaseContentLayout)
content.RebaseChildLayoutBaselines();
}
outerFrame.Left = options.Left;
outerFrame.Top = options.Top;
outerFrame.Width = outerWidth;
outerFrame.Height = outerHeight;
outerFrame.Anchors = options.OuterAnchors;
outerFrame.Draggable = options.Draggable;
outerFrame.Resizable = options.Resizable;
outerFrame.ResizeX = options.ResizeX;
outerFrame.ResizeY = options.ResizeY;
outerFrame.ResizableEdges = options.ResizableEdges;
outerFrame.ConstrainDragToParent = options.ConstrainDragToParent;
outerFrame.ConstrainResizeToParent = options.ConstrainResizeToParent;
outerFrame.Opacity = Math.Clamp(options.Opacity, 0f, 1f);
outerFrame.Visible = options.Visible;
outerFrame.MinWidth = ResolveConstraint(
options.MinWidth, options.DatConstraintSource, 0x3Fu, outerWidth, inset);
outerFrame.MinHeight = ResolveConstraint(
options.MinHeight, options.DatConstraintSource, 0x3Eu, outerHeight, inset);
outerFrame.MaxWidth = Math.Max(
outerFrame.MinWidth,
ResolveConstraint(options.MaxWidth, options.DatConstraintSource, 0x3Du, float.MaxValue, inset));
outerFrame.MaxHeight = Math.Max(
outerFrame.MinHeight,
ResolveConstraint(options.MaxHeight, options.DatConstraintSource, 0x3Cu, float.MaxValue, inset));
// Capture the wrapper/content baseline at the mounted design extent now,
// so a resize that occurs before the first draw uses the same margins as a
// resize after rendering one frame.
if (wrapped)
content.ApplyAnchor(outerWidth, outerHeight);
root.AddChild(outerFrame);
return root.RegisterWindow(
options.WindowName,
outerFrame,
content,
options.Controller,
options.StateController,
options.AuthoredGeometryRevision);
}
private static float ResolveConstraint(
float? explicitValue,
ElementInfo? datSource,
uint propertyId,
float fallback,
int chromeInset)
{
if (explicitValue is { } value)
return value;
if (datSource is not null
&& datSource.TryGetEffectiveInteger(propertyId, out int datValue)
&& datValue >= 0)
return datValue + chromeInset;
return fallback;
}
}