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>
210 lines
8.4 KiB
C#
210 lines
8.4 KiB
C#
using AcDream.App.Combat;
|
|
using AcDream.App.UI;
|
|
using AcDream.App.UI.Layout;
|
|
using AcDream.Core.Combat;
|
|
using AcDream.Runtime.Gameplay;
|
|
using AcDream.UI.Abstractions.Panels.Settings;
|
|
|
|
namespace AcDream.App.Tests.UI.Layout;
|
|
|
|
public sealed class CombatUiControllerTests
|
|
{
|
|
private static (uint, int, int) NoTex(uint _) => (0u, 0, 0);
|
|
|
|
[Fact]
|
|
public void CombatMode_ShowsPhysicalAndMagicPages_AndSelectsMediumByDefault()
|
|
{
|
|
double now = 0d;
|
|
var combat = new CombatState();
|
|
using var attacks = CreateAttacks(combat, () => now, []);
|
|
var (layout, basic, spellcasting, power, high, medium, low) = BuildLayout();
|
|
var visibility = new List<bool>();
|
|
GameplaySettings gameplay = GameplaySettings.Default;
|
|
using var controller = CombatUiController.Bind(
|
|
layout, combat, attacks, () => gameplay, value => gameplay = value,
|
|
Labels, visibility.Add)!;
|
|
|
|
controller.SyncVisibility();
|
|
combat.SetCombatMode(CombatMode.Melee);
|
|
combat.SetCombatMode(CombatMode.Magic);
|
|
|
|
Assert.Equal([false, true, true], visibility);
|
|
Assert.False(basic.Visible);
|
|
Assert.True(spellcasting.Visible);
|
|
Assert.False(high.Selected);
|
|
Assert.True(medium.Selected);
|
|
Assert.False(low.Selected);
|
|
Assert.Equal(RuntimeCombatAttackState.InitialDesiredPower, power.ScalarPosition);
|
|
}
|
|
|
|
[Fact]
|
|
public void AuthoredHeightButton_PressChargesAndReleaseSendsThroughSharedController()
|
|
{
|
|
double now = 4d;
|
|
var sent = new List<(AttackHeight Height, float Power)>();
|
|
var combat = new CombatState();
|
|
using var attacks = CreateAttacks(combat, () => now, sent);
|
|
var (layout, basic, advanced, power, high, _, _) = BuildLayout();
|
|
GameplaySettings gameplay = GameplaySettings.Default;
|
|
using var controller = CombatUiController.Bind(
|
|
layout, combat, attacks, () => gameplay, value => gameplay = value,
|
|
Labels, _ => { })!;
|
|
combat.SetCombatMode(CombatMode.Melee);
|
|
|
|
high.OnEvent(new UiEvent(0, high, UiEventType.MouseDown, Data1: 2, Data2: 2));
|
|
now = 4.5d;
|
|
Assert.Equal(0.5f, power.ScalarFill()!.Value, 3);
|
|
high.OnEvent(new UiEvent(0, high, UiEventType.MouseUp, Data1: 2, Data2: 2));
|
|
|
|
var attack = Assert.Single(sent);
|
|
Assert.Equal(AttackHeight.High, attack.Height);
|
|
Assert.Equal(0.5f, attack.Power, 3);
|
|
Assert.True(basic.Visible);
|
|
Assert.False(advanced.Visible);
|
|
}
|
|
|
|
[Fact]
|
|
public void AuthoredOptionCheckbox_TogglesPersistedGameplayValue()
|
|
{
|
|
var combat = new CombatState();
|
|
using var attacks = CreateAttacks(combat, () => 0d, []);
|
|
var (layout, _, _, _, _, _, _) = BuildLayout();
|
|
GameplaySettings gameplay = GameplaySettings.Default;
|
|
using var controller = CombatUiController.Bind(
|
|
layout, combat, attacks, () => gameplay, value => gameplay = value,
|
|
Labels, _ => { })!;
|
|
var autoTarget = Assert.IsType<UiButton>(layout.FindElement(CombatUiController.AutoTargetId));
|
|
|
|
autoTarget.OnEvent(new UiEvent(0, autoTarget, UiEventType.MouseDown, Data1: 3, Data2: 3));
|
|
autoTarget.OnEvent(new UiEvent(0, autoTarget, UiEventType.MouseUp, Data1: 3, Data2: 3));
|
|
autoTarget.OnEvent(new UiEvent(0, autoTarget, UiEventType.Click, Data1: 3, Data2: 3));
|
|
|
|
Assert.False(gameplay.AutoTarget);
|
|
}
|
|
|
|
[Fact]
|
|
public void AuthoredPowerLabels_KeepGrayTrackAtSides_AndUseRetailAlignment()
|
|
{
|
|
var combat = new CombatState();
|
|
using var attacks = CreateAttacks(combat, () => 0d, []);
|
|
var (layout, _, _, power, _, _, _) = BuildLayout();
|
|
GameplaySettings gameplay = GameplaySettings.Default;
|
|
using var controller = CombatUiController.Bind(
|
|
layout, combat, attacks, () => gameplay, value => gameplay = value,
|
|
Labels, _ => { })!;
|
|
|
|
var speed = Assert.IsType<UiText>(layout.FindElement(CombatUiController.SpeedLabelId));
|
|
var powerLabel = Assert.IsType<UiText>(layout.FindElement(CombatUiController.PowerLabelId));
|
|
Assert.False(speed.Centered);
|
|
Assert.False(speed.RightAligned);
|
|
Assert.False(powerLabel.Centered);
|
|
Assert.True(powerLabel.RightAligned);
|
|
}
|
|
|
|
[Fact]
|
|
public void ImportedFixture_ReflowUpdatesCenteredDarkRange()
|
|
{
|
|
ElementInfo info = FixtureLoader.LoadCombatInfos();
|
|
ImportedLayout layout = LayoutImporter.Build(info, NoTex, datFont: null);
|
|
var combat = new CombatState();
|
|
using var attacks = CreateAttacks(combat, () => 0d, []);
|
|
GameplaySettings gameplay = GameplaySettings.Default;
|
|
using var controller = CombatUiController.Bind(
|
|
layout, combat, attacks, () => gameplay, value => gameplay = value,
|
|
Labels, _ => { })!;
|
|
|
|
ApplyAnchors(layout.Root);
|
|
|
|
var power = Assert.IsType<UiScrollbar>(
|
|
layout.FindElement(CombatUiController.PowerControlId));
|
|
Assert.Equal((50f, 407f), power.ScalarRangeRect());
|
|
}
|
|
|
|
private static readonly CombatUiLabels Labels = new(
|
|
"Speed", "Power", "Repeat Attacks", "Auto Target", "Keep in View",
|
|
"High", "Medium", "Low");
|
|
|
|
private static RuntimeCombatAttackState CreateAttacks(
|
|
CombatState combat,
|
|
Func<double> now,
|
|
List<(AttackHeight Height, float Power)> sent)
|
|
=> new(
|
|
combat,
|
|
() => true,
|
|
(height, power) =>
|
|
{
|
|
sent.Add((height, power));
|
|
return true;
|
|
},
|
|
autoRepeatAttack: () => false,
|
|
now: now);
|
|
|
|
private static (
|
|
ImportedLayout Layout,
|
|
UiElement Basic,
|
|
UiElement Advanced,
|
|
UiScrollbar Power,
|
|
UiButton High,
|
|
UiButton Medium,
|
|
UiButton Low) BuildLayout()
|
|
{
|
|
var root = new UiPanel { Width = 610, Height = 90 };
|
|
var basic = new UiPanel();
|
|
var advanced = new UiPanel();
|
|
var power = new UiScrollbar
|
|
{
|
|
Left = 13,
|
|
Top = 14,
|
|
Width = 507,
|
|
Height = 14,
|
|
Horizontal = true,
|
|
};
|
|
var speedLabel = new UiText { Left = 17, Top = 14, Width = 100, Height = 15 };
|
|
var powerLabel = new UiText { Left = 416, Top = 14, Width = 100, Height = 15 };
|
|
UiButton Button(uint id) => new(
|
|
new ElementInfo { Id = id, Type = 1, Width = 72, Height = 19 }, NoTex)
|
|
{
|
|
Width = 72,
|
|
Height = 19,
|
|
};
|
|
UiButton ToggleButton(uint id)
|
|
{
|
|
var info = new ElementInfo { Id = id, Type = 0x10000035u, Width = 100, Height = 14 };
|
|
var state = new UiStateInfo { Id = UiStateInfo.DirectStateId };
|
|
state.Properties.Values[0x0Bu] = new UiPropertyValue
|
|
{ Kind = UiPropertyKind.Bool, BoolValue = true };
|
|
info.States[UiStateInfo.DirectStateId] = state;
|
|
return new UiButton(info, NoTex) { Width = 100, Height = 14 };
|
|
}
|
|
var high = Button(CombatUiController.HighButtonId);
|
|
var medium = Button(CombatUiController.MediumButtonId);
|
|
var low = Button(CombatUiController.LowButtonId);
|
|
var repeat = ToggleButton(CombatUiController.RepeatAttacksId);
|
|
var autoTarget = ToggleButton(CombatUiController.AutoTargetId);
|
|
var keepInView = ToggleButton(CombatUiController.KeepInViewId);
|
|
var byId = new Dictionary<uint, UiElement>
|
|
{
|
|
[CombatUiController.BasicPanelId] = basic,
|
|
[CombatUiController.AdvancedPanelId] = advanced,
|
|
[CombatUiController.PowerControlId] = power,
|
|
[CombatUiController.SpeedLabelId] = speedLabel,
|
|
[CombatUiController.PowerLabelId] = powerLabel,
|
|
[CombatUiController.HighButtonId] = high,
|
|
[CombatUiController.MediumButtonId] = medium,
|
|
[CombatUiController.LowButtonId] = low,
|
|
[CombatUiController.RepeatAttacksId] = repeat,
|
|
[CombatUiController.AutoTargetId] = autoTarget,
|
|
[CombatUiController.KeepInViewId] = keepInView,
|
|
};
|
|
return (new ImportedLayout(root, byId), basic, advanced, power, high, medium, low);
|
|
}
|
|
|
|
private static void ApplyAnchors(UiElement parent)
|
|
{
|
|
foreach (UiElement child in parent.Children)
|
|
{
|
|
child.ApplyAnchor(parent.Width, parent.Height);
|
|
ApplyAnchors(child);
|
|
}
|
|
}
|
|
}
|