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>
400 lines
16 KiB
C#
400 lines
16 KiB
C#
using AcDream.App.Spells;
|
|
using AcDream.App.UI;
|
|
using AcDream.App.UI.Layout;
|
|
using AcDream.Core.Items;
|
|
using AcDream.Core.Selection;
|
|
using AcDream.Core.Spells;
|
|
using AcDream.Runtime.Gameplay;
|
|
|
|
namespace AcDream.App.Tests.UI.Layout;
|
|
|
|
public sealed class SpellcastingUiControllerTests
|
|
{
|
|
private static (uint, int, int) NoTex(uint _) => (0u, 0, 0);
|
|
|
|
[Fact]
|
|
public void ImportedFixture_UsesRetailEmptyCells_ShortcutDigits_AndCompleteCastButton()
|
|
{
|
|
ImportedLayout layout = LayoutImporter.Build(
|
|
FixtureLoader.LoadCombatInfos(), NoTex, datFont: null);
|
|
RetailCombatLayout.FitFavoriteSlots(layout);
|
|
var spellbook = new Spellbook();
|
|
spellbook.OnSpellLearned(42u, 1f);
|
|
spellbook.SetFavorite(0, 0, 42u);
|
|
var objects = new ClientObjectTable();
|
|
objects.AddOrUpdate(new ClientObject { ObjectId = 1u, Name = "Player" });
|
|
uint[] regular = [101u, 102u, 103u, 104u, 105u, 106u, 107u, 108u, 109u];
|
|
uint[] ghosted = [201u, 202u, 203u, 204u, 205u, 206u, 207u, 208u, 209u];
|
|
uint[] empty = [301u, 302u, 303u, 304u, 305u, 306u, 307u, 308u, 309u];
|
|
var digits = new UiShortcutDigitGraphics(regular, ghosted, empty);
|
|
|
|
using SpellcastingUiController controller = Bind(
|
|
layout, spellbook, objects, _ => { },
|
|
shortcutDigits: digits,
|
|
emptySlotSprite: 0x06001A97u)!;
|
|
|
|
UiElement group = layout.FindElement(0x100000AAu)!;
|
|
UiItemList list = Descendants(group).OfType<UiItemList>().First();
|
|
UiScrollbar scrollbar = Descendants(group).OfType<UiScrollbar>().Single(
|
|
candidate => candidate.DatElementId == SpellcastingUiController.FavoriteScrollbarId);
|
|
Assert.True(list.SingleRow);
|
|
Assert.True(list.HorizontalScroll);
|
|
Assert.True(list.FillVisibleEmptySlots);
|
|
Assert.Same(list.Scroll, scrollbar.Model);
|
|
Assert.True(scrollbar.Horizontal);
|
|
Assert.True(scrollbar.HideWhenDisabled);
|
|
Assert.Equal(23f, scrollbar.DecrementButtonExtent);
|
|
Assert.Equal(23f, scrollbar.IncrementButtonExtent);
|
|
Assert.Equal(0x06004CDEu, scrollbar.UpSprite);
|
|
Assert.Equal(0x06004CDFu, scrollbar.UpRolloverSprite);
|
|
Assert.Equal(0x06004CDCu, scrollbar.DownSprite);
|
|
Assert.Equal(0x06004CDDu, scrollbar.DownRolloverSprite);
|
|
Assert.False(scrollbar.IsPresentationVisible);
|
|
Assert.Equal(576f, list.Width);
|
|
Assert.Equal(18, list.GetNumUIItems());
|
|
|
|
UiCatalogSlot favorite = Assert.IsType<UiCatalogSlot>(list.GetItem(0));
|
|
Assert.Equal(42u, favorite.EntryId);
|
|
Assert.Equal(0, favorite.ShortcutNum);
|
|
Assert.Same(regular, favorite.ActiveDigitArray());
|
|
|
|
for (int i = 1; i < 9; i++)
|
|
{
|
|
UiCatalogSlot slot = Assert.IsType<UiCatalogSlot>(list.GetItem(i));
|
|
Assert.True(slot.IsEmptySlot);
|
|
Assert.Equal(0x06001A97u, slot.EmptySprite);
|
|
Assert.Equal(i, slot.ShortcutNum);
|
|
Assert.Same(empty, slot.ActiveDigitArray());
|
|
}
|
|
for (int i = 9; i < 18; i++)
|
|
{
|
|
Assert.Equal(0x06001A97u, list.GetItem(i)!.EmptySprite);
|
|
Assert.Equal(-1, list.GetItem(i)!.ShortcutNum);
|
|
}
|
|
|
|
var cast = Assert.IsType<UiButton>(
|
|
layout.FindElement(SpellcastingUiController.CastButtonId));
|
|
Assert.Equal((662f, 75f), (cast.Left, cast.Width));
|
|
Assert.Equal(3, cast.FaceSegmentCount);
|
|
Assert.Equal(
|
|
[
|
|
new UiPixelRect(0, 0, 31, 31),
|
|
new UiPixelRect(32, 0, 42, 31),
|
|
new UiPixelRect(43, 0, 74, 31),
|
|
],
|
|
cast.FaceSegmentRectsForTest());
|
|
}
|
|
|
|
[Fact]
|
|
public void FavoriteOverflow_ArrowButtonsStepOneCell_AndSelectionScrollsIntoView()
|
|
{
|
|
ImportedLayout layout = LayoutImporter.Build(
|
|
FixtureLoader.LoadCombatInfos(), NoTex, datFont: null);
|
|
RetailCombatLayout.FitFavoriteSlots(layout);
|
|
var spellbook = new Spellbook();
|
|
for (uint spellId = 1u; spellId <= 20u; spellId++)
|
|
{
|
|
spellbook.OnSpellLearned(spellId, 1f);
|
|
spellbook.SetFavorite(0, (int)spellId - 1, spellId);
|
|
}
|
|
var objects = new ClientObjectTable();
|
|
objects.AddOrUpdate(new ClientObject { ObjectId = 1u, Name = "Player" });
|
|
|
|
using SpellcastingUiController controller = Bind(
|
|
layout, spellbook, objects, _ => { })!;
|
|
|
|
UiElement group = layout.FindElement(0x100000AAu)!;
|
|
UiItemList list = Descendants(group).OfType<UiItemList>().Single();
|
|
UiScrollbar scrollbar = Descendants(group).OfType<UiScrollbar>().Single(
|
|
candidate => candidate.DatElementId == SpellcastingUiController.FavoriteScrollbarId);
|
|
Assert.True(scrollbar.IsPresentationVisible);
|
|
Assert.Equal(64, list.Scroll.MaxScroll);
|
|
|
|
Assert.True(scrollbar.OnEvent(new UiEvent(
|
|
0u, scrollbar, UiEventType.MouseDown, Data1: (int)scrollbar.Width - 1)));
|
|
Assert.Equal(32, list.Scroll.ScrollY);
|
|
Assert.True(scrollbar.OnEvent(new UiEvent(
|
|
0u, scrollbar, UiEventType.MouseDown, Data1: 0)));
|
|
Assert.Equal(0, list.Scroll.ScrollY);
|
|
|
|
controller.AddFavorite(20u);
|
|
|
|
Assert.Equal(list.Scroll.MaxScroll, list.Scroll.ScrollY);
|
|
|
|
Assert.True(scrollbar.OnEvent(new UiEvent(
|
|
0u, scrollbar, UiEventType.MouseDown, Data1: 0)));
|
|
int manualOffset = list.Scroll.ScrollY;
|
|
objects.AddOrUpdate(new ClientObject { ObjectId = 99u, Name = "Unrelated" });
|
|
controller.Tick();
|
|
|
|
Assert.Equal(manualOffset, list.Scroll.ScrollY);
|
|
}
|
|
|
|
[Fact]
|
|
public void ImportedFixture_BindsAllTabs_AndTracksEquippedEndowment()
|
|
{
|
|
ImportedLayout layout = LayoutImporter.Build(
|
|
FixtureLoader.LoadCombatInfos(), NoTex, datFont: null);
|
|
var spellbook = new Spellbook();
|
|
var objects = new ClientObjectTable();
|
|
objects.AddOrUpdate(new ClientObject { ObjectId = 1u, Name = "Player" });
|
|
var used = new List<uint>();
|
|
using SpellcastingUiController? controller = Bind(
|
|
layout, spellbook, objects, used.Add);
|
|
|
|
Assert.True(controller is not null, DescribeBinding(layout));
|
|
objects.AddOrUpdate(new ClientObject
|
|
{
|
|
ObjectId = 2u,
|
|
Name = "Orb",
|
|
Type = ItemType.Caster,
|
|
WielderId = 1u,
|
|
CurrentlyEquippedLocation = EquipMask.Held,
|
|
SpellId = 2670u,
|
|
IconId = 0x06001234u,
|
|
});
|
|
controller.Tick();
|
|
|
|
UiElement host = Assert.IsAssignableFrom<UiElement>(
|
|
layout.FindElement(SpellcastingUiController.EndowmentId));
|
|
Assert.True(host.Visible);
|
|
UiCatalogSlot slot = Assert.IsType<UiCatalogSlot>(host.Children[^1]);
|
|
Assert.Equal(2u, slot.EntryId);
|
|
Assert.Equal(2670u, slot.CatalogIconTexture);
|
|
Assert.Equal(2u, slot.CatalogOverlayTexture);
|
|
|
|
slot.OnEvent(new UiEvent(0, slot, UiEventType.Click));
|
|
var cast = Assert.IsType<UiButton>(
|
|
layout.FindElement(SpellcastingUiController.CastButtonId));
|
|
cast.OnEvent(new UiEvent(0, cast, UiEventType.Click));
|
|
Assert.Equal([2u], used);
|
|
}
|
|
|
|
[Fact]
|
|
public void FavoriteDrop_IgnoresForeignInventoryPayload()
|
|
{
|
|
ImportedLayout layout = LayoutImporter.Build(
|
|
FixtureLoader.LoadCombatInfos(), NoTex, datFont: null);
|
|
var spellbook = new Spellbook();
|
|
spellbook.OnSpellLearned(42u, 1f);
|
|
spellbook.SetFavorite(0, 0, 42u);
|
|
var objects = new ClientObjectTable();
|
|
objects.AddOrUpdate(new ClientObject { ObjectId = 1u, Name = "Player" });
|
|
using SpellcastingUiController? controller = Bind(
|
|
layout, spellbook, objects, _ => { });
|
|
|
|
Assert.True(controller is not null, DescribeBinding(layout));
|
|
controller.Tick();
|
|
UiElement group = Assert.IsAssignableFrom<UiElement>(layout.FindElement(0x100000AAu));
|
|
UiItemList list = Descendants(group).OfType<UiItemList>().First();
|
|
UiCatalogSlot slot = Assert.IsType<UiCatalogSlot>(list.GetItem(0));
|
|
var foreign = new ItemDragPayload(9u, ItemDragSource.Inventory, 0, new UiItemSlot(), null);
|
|
|
|
bool handled = slot.OnEvent(new UiEvent(
|
|
0, slot, UiEventType.DropReleased, Payload: foreign));
|
|
|
|
Assert.True(handled);
|
|
Assert.Equal([42u], spellbook.GetFavorites(0));
|
|
}
|
|
|
|
[Fact]
|
|
public void SpellbookShortcutDrop_AddsToOpenTabWithoutRemovingLearnedSpell()
|
|
{
|
|
ImportedLayout layout = LayoutImporter.Build(
|
|
FixtureLoader.LoadCombatInfos(), NoTex, datFont: null);
|
|
var spellbook = new Spellbook();
|
|
spellbook.OnSpellLearned(42u, 1f);
|
|
var objects = new ClientObjectTable();
|
|
objects.AddOrUpdate(new ClientObject { ObjectId = 1u, Name = "Player" });
|
|
var added = new List<(int Tab, int Position, uint Spell)>();
|
|
using SpellcastingUiController controller = Bind(
|
|
layout, spellbook, objects, _ => { },
|
|
(tab, position, spell) => added.Add((tab, position, spell)))!;
|
|
UiElement group = Assert.IsAssignableFrom<UiElement>(layout.FindElement(0x100000AAu));
|
|
UiItemList list = Descendants(group).OfType<UiItemList>().First();
|
|
|
|
bool handled = list.OnEvent(new UiEvent(
|
|
0,
|
|
list,
|
|
UiEventType.DropReleased,
|
|
Data1: 5,
|
|
Payload: new SpellbookShortcutDragPayload(42u)));
|
|
|
|
Assert.True(handled);
|
|
Assert.Equal([(0, 0, 42u)], added);
|
|
Assert.Equal([42u], spellbook.GetFavorites(0));
|
|
Assert.True(spellbook.Knows(42u));
|
|
}
|
|
|
|
[Fact]
|
|
public void UnrelatedObjectUpdate_DoesNotRecreateFavoriteSlots()
|
|
{
|
|
ImportedLayout layout = LayoutImporter.Build(
|
|
FixtureLoader.LoadCombatInfos(), NoTex, datFont: null);
|
|
var spellbook = new Spellbook();
|
|
spellbook.OnSpellLearned(42u, 1f);
|
|
spellbook.SetFavorite(0, 0, 42u);
|
|
var objects = new ClientObjectTable();
|
|
objects.AddOrUpdate(new ClientObject { ObjectId = 1u, Name = "Player" });
|
|
using SpellcastingUiController controller = Bind(
|
|
layout, spellbook, objects, _ => { })!;
|
|
UiElement group = layout.FindElement(0x100000AAu)!;
|
|
UiItemList list = Descendants(group).OfType<UiItemList>().First();
|
|
UiItemSlot before = list.GetItem(0)!;
|
|
|
|
objects.AddOrUpdate(new ClientObject { ObjectId = 99u, Name = "Rock" });
|
|
controller.Tick();
|
|
|
|
Assert.Same(before, list.GetItem(0));
|
|
}
|
|
|
|
[Fact]
|
|
public void ObjectTableClear_RemovesEquippedEndowmentAndCannotUseStaleGuid()
|
|
{
|
|
ImportedLayout layout = LayoutImporter.Build(
|
|
FixtureLoader.LoadCombatInfos(), NoTex, datFont: null);
|
|
var spellbook = new Spellbook();
|
|
var objects = new ClientObjectTable();
|
|
objects.AddOrUpdate(new ClientObject { ObjectId = 1u, Name = "Player" });
|
|
objects.AddOrUpdate(new ClientObject
|
|
{
|
|
ObjectId = 2u,
|
|
Name = "Orb",
|
|
Type = ItemType.Caster,
|
|
WielderId = 1u,
|
|
CurrentlyEquippedLocation = EquipMask.Held,
|
|
SpellId = 2670u,
|
|
});
|
|
var used = new List<uint>();
|
|
using SpellcastingUiController controller = Bind(
|
|
layout, spellbook, objects, used.Add)!;
|
|
UiElement host = layout.FindElement(SpellcastingUiController.EndowmentId)!;
|
|
UiCatalogSlot slot = Assert.IsType<UiCatalogSlot>(host.Children[^1]);
|
|
slot.OnEvent(new UiEvent(0, slot, UiEventType.Click));
|
|
|
|
objects.Clear();
|
|
controller.Tick();
|
|
|
|
Assert.False(host.Visible);
|
|
Assert.Equal(0u, slot.EntryId);
|
|
slot.OnEvent(new UiEvent(0, slot, UiEventType.DoubleClick));
|
|
Assert.Empty(used);
|
|
}
|
|
|
|
[Fact]
|
|
public void FavoritePressSelectsImmediately_AndRightClickExaminesLocally()
|
|
{
|
|
ImportedLayout layout = LayoutImporter.Build(
|
|
FixtureLoader.LoadCombatInfos(), NoTex, datFont: null);
|
|
var spellbook = new Spellbook();
|
|
spellbook.OnSpellLearned(42u, 1f);
|
|
spellbook.OnSpellLearned(43u, 1f);
|
|
spellbook.SetFavorite(0, 0, 42u);
|
|
spellbook.SetFavorite(0, 1, 43u);
|
|
var objects = new ClientObjectTable();
|
|
objects.AddOrUpdate(new ClientObject { ObjectId = 1u, Name = "Player" });
|
|
var selection = new SelectionState();
|
|
var examined = new List<uint>();
|
|
using SpellcastingUiController controller = Bind(
|
|
layout,
|
|
spellbook,
|
|
objects,
|
|
_ => { },
|
|
selection: selection,
|
|
examineSpell: examined.Add)!;
|
|
UiElement group = layout.FindElement(0x100000AAu)!;
|
|
UiItemList list = Descendants(group).OfType<UiItemList>().First();
|
|
UiCatalogSlot first = Assert.IsType<UiCatalogSlot>(list.GetItem(0));
|
|
UiCatalogSlot second = Assert.IsType<UiCatalogSlot>(list.GetItem(1));
|
|
Assert.True(first.Selected);
|
|
|
|
second.OnEvent(new UiEvent(0u, second, UiEventType.MouseDown));
|
|
|
|
Assert.False(first.Selected);
|
|
Assert.True(second.Selected);
|
|
Assert.Null(selection.SelectedObjectId);
|
|
|
|
second.OnEvent(new UiEvent(0u, second, UiEventType.RightClick));
|
|
|
|
Assert.Equal(new uint[] { 43u }, examined);
|
|
Assert.Null(selection.SelectedObjectId);
|
|
}
|
|
|
|
private static SpellcastingUiController? Bind(
|
|
ImportedLayout layout,
|
|
Spellbook spellbook,
|
|
ClientObjectTable objects,
|
|
Action<uint> useItem,
|
|
Action<int, int, uint>? addFavorite = null,
|
|
UiShortcutDigitGraphics? shortcutDigits = null,
|
|
uint emptySlotSprite = 0u,
|
|
SelectionState? selection = null,
|
|
Action<uint>? examineSpell = null)
|
|
{
|
|
SelectionState selectionState = selection ?? new SelectionState();
|
|
var casting = new RuntimeSpellCastState(
|
|
spellbook,
|
|
selectionState,
|
|
new NoopSpellCastOperations());
|
|
return SpellcastingUiController.Bind(
|
|
layout, spellbook, casting, objects, () => 1u,
|
|
spellId => spellId,
|
|
item => item.ObjectId,
|
|
useItem,
|
|
selectionState,
|
|
(tab, position, spellId) =>
|
|
{
|
|
spellbook.SetFavorite(tab, position, spellId);
|
|
addFavorite?.Invoke(tab, position, spellId);
|
|
},
|
|
(tab, spellId) => spellbook.RemoveFavorite(tab, spellId),
|
|
shortcutDigits,
|
|
emptySlotSprite,
|
|
examineSpell);
|
|
}
|
|
|
|
private sealed class NoopSpellCastOperations : IRuntimeSpellCastOperations
|
|
{
|
|
public uint LocalPlayerId => 1u;
|
|
public bool CanSend => true;
|
|
public bool HasRequiredComponents(uint spellId) => true;
|
|
public bool IsTargetCompatible(
|
|
uint targetId,
|
|
SpellMetadata spell,
|
|
bool showMessage) => true;
|
|
public void StopCompletely() { }
|
|
public void SendUntargeted(uint spellId) { }
|
|
public void SendTargeted(uint targetId, uint spellId) { }
|
|
public void DisplayMessage(string message) { }
|
|
public void IncrementBusy() { }
|
|
}
|
|
|
|
private static void ApplyAnchors(UiElement parent)
|
|
{
|
|
foreach (UiElement child in parent.Children)
|
|
{
|
|
child.ApplyAnchor(parent.Width, parent.Height);
|
|
ApplyAnchors(child);
|
|
}
|
|
}
|
|
|
|
private static IEnumerable<UiElement> Descendants(UiElement root)
|
|
{
|
|
foreach (UiElement child in root.Children)
|
|
{
|
|
yield return child;
|
|
foreach (UiElement nested in Descendants(child)) yield return nested;
|
|
}
|
|
}
|
|
|
|
private static string DescribeBinding(ImportedLayout layout)
|
|
{
|
|
uint[] ids =
|
|
[
|
|
SpellcastingUiController.CastButtonId, SpellcastingUiController.EndowmentId,
|
|
0x100000A3u, 0x100000AAu, 0x100005C2u, 0x100005C3u,
|
|
];
|
|
return string.Join(", ", ids.Select(id =>
|
|
$"{id:X8}={layout.FindElement(id)?.GetType().Name ?? "missing"}"));
|
|
}
|
|
}
|