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>
276 lines
9.6 KiB
C#
276 lines
9.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using AcDream.UI.Abstractions.Panels.Settings;
|
|
|
|
namespace AcDream.App.UI;
|
|
|
|
/// <summary>
|
|
/// Bridges typed retained-window lifecycle events to per-character,
|
|
/// per-resolution settings. It deliberately ignores the temporary pre-login
|
|
/// <c>default</c> character key so startup layout cannot overwrite a real
|
|
/// character's state.
|
|
/// </summary>
|
|
public sealed class RetailWindowLayoutPersistence : IDisposable
|
|
{
|
|
private readonly RetailWindowManager _manager;
|
|
private readonly SettingsStore _store;
|
|
private readonly Func<string> _characterKey;
|
|
private readonly Func<(int Width, int Height)> _screenSize;
|
|
private readonly HashSet<string> _stateManagedVisibilityWindows;
|
|
private readonly List<RetailWindowHandle> _attached = new();
|
|
private bool _restoring;
|
|
private bool _disposed;
|
|
|
|
public RetailWindowLayoutPersistence(
|
|
RetailWindowManager manager,
|
|
SettingsStore store,
|
|
Func<string> characterKey,
|
|
Func<(int Width, int Height)> screenSize,
|
|
IEnumerable<string>? stateManagedVisibilityWindows = null)
|
|
{
|
|
_manager = manager ?? throw new ArgumentNullException(nameof(manager));
|
|
_store = store ?? throw new ArgumentNullException(nameof(store));
|
|
_characterKey = characterKey ?? throw new ArgumentNullException(nameof(characterKey));
|
|
_screenSize = screenSize ?? throw new ArgumentNullException(nameof(screenSize));
|
|
_stateManagedVisibilityWindows = stateManagedVisibilityWindows is null
|
|
? new HashSet<string>(StringComparer.Ordinal)
|
|
: new HashSet<string>(stateManagedVisibilityWindows, StringComparer.Ordinal);
|
|
|
|
foreach (RetailWindowHandle handle in manager.Windows)
|
|
Attach(handle);
|
|
}
|
|
|
|
/// <summary>Restore all registered windows after character and screen are known.</summary>
|
|
public void RestoreAll()
|
|
{
|
|
ObjectDisposedException.ThrowIf(_disposed, this);
|
|
string character = _characterKey();
|
|
if (!CanPersist(character)) return;
|
|
var screen = ValidScreenSize();
|
|
string resolution = ResolutionKey(screen);
|
|
|
|
_restoring = true;
|
|
try
|
|
{
|
|
foreach (RetailWindowHandle handle in _attached)
|
|
{
|
|
UiWindowLayout fallback = Capture(handle);
|
|
UiWindowLayout? saved = _store.LoadWindowLayout(
|
|
character, resolution, handle.Name, fallback);
|
|
if (saved is not { } layout) continue;
|
|
layout = MigrateAuthoredGeometry(
|
|
layout,
|
|
AuthoredGeometry(handle, fallback));
|
|
|
|
Apply(
|
|
handle,
|
|
layout,
|
|
screen,
|
|
restoreVisibility: !_stateManagedVisibilityWindows.Contains(handle.Name));
|
|
// Lazily migrate legacy position-only entries into the complete schema.
|
|
_store.SaveWindowLayout(character, resolution, handle.Name, Capture(handle));
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
_restoring = false;
|
|
}
|
|
}
|
|
|
|
/// <summary>Force-save every attached window to the current automatic profile.</summary>
|
|
public void SaveAll()
|
|
{
|
|
ObjectDisposedException.ThrowIf(_disposed, this);
|
|
string character = _characterKey();
|
|
if (!CanPersist(character)) return;
|
|
var screen = ValidScreenSize();
|
|
string resolution = ResolutionKey(screen);
|
|
foreach (RetailWindowHandle handle in _attached)
|
|
_store.SaveWindowLayout(character, resolution, handle.Name, Capture(handle));
|
|
}
|
|
|
|
/// <summary>Save every attached window to a portable named retail UI profile.</summary>
|
|
public void SaveNamed(string profileName)
|
|
{
|
|
ObjectDisposedException.ThrowIf(_disposed, this);
|
|
ArgumentNullException.ThrowIfNull(profileName);
|
|
foreach (RetailWindowHandle handle in _attached)
|
|
_store.SaveNamedWindowLayout(profileName, handle.Name, Capture(handle));
|
|
}
|
|
|
|
/// <summary>Restore every window found in a portable named retail UI profile.</summary>
|
|
public void RestoreNamed(string profileName)
|
|
{
|
|
ObjectDisposedException.ThrowIf(_disposed, this);
|
|
ArgumentNullException.ThrowIfNull(profileName);
|
|
var screen = ValidScreenSize();
|
|
|
|
_restoring = true;
|
|
try
|
|
{
|
|
foreach (RetailWindowHandle handle in _attached)
|
|
{
|
|
UiWindowLayout? saved = _store.LoadNamedWindowLayout(
|
|
profileName, handle.Name, Capture(handle));
|
|
if (saved is not { } layout) continue;
|
|
UiWindowLayout fallback = Capture(handle);
|
|
layout = MigrateAuthoredGeometry(
|
|
layout,
|
|
AuthoredGeometry(handle, fallback));
|
|
Apply(
|
|
handle,
|
|
layout,
|
|
screen,
|
|
restoreVisibility: !_stateManagedVisibilityWindows.Contains(handle.Name));
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
_restoring = false;
|
|
}
|
|
}
|
|
|
|
private void Attach(RetailWindowHandle handle)
|
|
{
|
|
_attached.Add(handle);
|
|
handle.Moved += OnChanged;
|
|
handle.Resized += OnChanged;
|
|
if (!_stateManagedVisibilityWindows.Contains(handle.Name))
|
|
{
|
|
handle.Shown += OnChanged;
|
|
handle.Hidden += OnChanged;
|
|
}
|
|
}
|
|
|
|
private void OnChanged(RetailWindowHandle handle)
|
|
{
|
|
if (_restoring || _disposed) return;
|
|
string character = _characterKey();
|
|
if (!CanPersist(character)) return;
|
|
|
|
try
|
|
{
|
|
var screen = ValidScreenSize();
|
|
_store.SaveWindowLayout(
|
|
character,
|
|
ResolutionKey(screen),
|
|
handle.Name,
|
|
Capture(handle));
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine($"settings: window layout save failed [{handle.Name}]: {ex.Message}");
|
|
}
|
|
}
|
|
|
|
private static UiWindowLayout Capture(RetailWindowHandle handle)
|
|
{
|
|
RetainedWindowState state = handle.StateController?.CaptureWindowState() ?? default;
|
|
return new UiWindowLayout(
|
|
handle.Left,
|
|
state.PersistedTop ?? handle.Top,
|
|
handle.Width,
|
|
state.PersistedHeight ?? handle.Height,
|
|
handle.IsVisible,
|
|
state.Collapsed,
|
|
state.Maximized,
|
|
handle.AuthoredGeometryRevision);
|
|
}
|
|
|
|
private static UiWindowLayout MigrateAuthoredGeometry(
|
|
UiWindowLayout saved,
|
|
UiWindowLayout authored)
|
|
{
|
|
if (saved.AuthoredGeometryRevision >= authored.AuthoredGeometryRevision)
|
|
return saved;
|
|
|
|
return saved with
|
|
{
|
|
Width = authored.Width,
|
|
Height = authored.Height,
|
|
AuthoredGeometryRevision = authored.AuthoredGeometryRevision,
|
|
};
|
|
}
|
|
|
|
private static UiWindowLayout AuthoredGeometry(
|
|
RetailWindowHandle handle,
|
|
UiWindowLayout current) => current with
|
|
{
|
|
Width = handle.AuthoredWidth,
|
|
Height = handle.AuthoredHeight,
|
|
AuthoredGeometryRevision = handle.AuthoredGeometryRevision,
|
|
};
|
|
|
|
private static void Apply(
|
|
RetailWindowHandle handle,
|
|
UiWindowLayout layout,
|
|
(int Width, int Height) screen,
|
|
bool restoreVisibility)
|
|
{
|
|
UiElement frame = handle.OuterFrame;
|
|
float width = ClampDimension(layout.Width, frame.Width, frame.MinWidth, frame.MaxWidth, screen.Width);
|
|
float height = ClampDimension(layout.Height, frame.Height, frame.MinHeight, frame.MaxHeight, screen.Height);
|
|
handle.ResizeTo(width, height);
|
|
|
|
float maxX = MathF.Max(0f, screen.Width - handle.Width);
|
|
float maxY = MathF.Max(0f, screen.Height - handle.Height);
|
|
float x = Math.Clamp(FiniteOr(layout.X, handle.Left), 0f, maxX);
|
|
float y = Math.Clamp(FiniteOr(layout.Y, handle.Top), 0f, maxY);
|
|
handle.MoveTo(x, y);
|
|
|
|
handle.StateController?.RestoreWindowState(new RetainedWindowState(
|
|
Collapsed: layout.Collapsed,
|
|
Maximized: layout.Maximized));
|
|
|
|
if (restoreVisibility)
|
|
{
|
|
if (layout.Visible) handle.Show();
|
|
else handle.Hide();
|
|
}
|
|
}
|
|
|
|
private (int Width, int Height) ValidScreenSize()
|
|
{
|
|
var screen = _screenSize();
|
|
return (Math.Max(1, screen.Width), Math.Max(1, screen.Height));
|
|
}
|
|
|
|
private static float ClampDimension(
|
|
float saved,
|
|
float current,
|
|
float minimum,
|
|
float maximum,
|
|
int screenExtent)
|
|
{
|
|
float value = FiniteOr(saved, current);
|
|
float upper = MathF.Max(minimum, MathF.Min(maximum, screenExtent));
|
|
return Math.Clamp(value, minimum, upper);
|
|
}
|
|
|
|
private static float FiniteOr(float value, float fallback)
|
|
=> float.IsFinite(value) ? value : fallback;
|
|
|
|
private static string ResolutionKey((int Width, int Height) screen)
|
|
=> $"{screen.Width}x{screen.Height}";
|
|
|
|
private static bool CanPersist(string key)
|
|
=> !string.IsNullOrWhiteSpace(key)
|
|
&& !string.Equals(key, "default", StringComparison.OrdinalIgnoreCase);
|
|
|
|
public void Dispose()
|
|
{
|
|
if (_disposed) return;
|
|
_disposed = true;
|
|
foreach (RetailWindowHandle handle in _attached)
|
|
{
|
|
handle.Moved -= OnChanged;
|
|
handle.Resized -= OnChanged;
|
|
if (!_stateManagedVisibilityWindows.Contains(handle.Name))
|
|
{
|
|
handle.Shown -= OnChanged;
|
|
handle.Hidden -= OnChanged;
|
|
}
|
|
}
|
|
_attached.Clear();
|
|
}
|
|
}
|