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>
283 lines
11 KiB
C#
283 lines
11 KiB
C#
using AcDream.Core.Combat;
|
|
using AcDream.Runtime.Gameplay;
|
|
using AcDream.UI.Abstractions.Panels.Settings;
|
|
|
|
namespace AcDream.App.UI.Layout;
|
|
|
|
/// <summary>
|
|
/// Binds the imported retail <c>gmCombatUI</c> layout to the client combat
|
|
/// state machine. No panel geometry is synthesized here: every control is the
|
|
/// authored element from LayoutDesc <c>0x21000073</c>.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Retail references: <c>gmCombatUI::RecvNotice_AttackHeightChanged</c>
|
|
/// (0x004CC080), <c>RecvNotice_SetPowerbarLevel</c> (0x004CC0E0),
|
|
/// <c>RecvNotice_DesiredAttackPowerChanged</c> (0x004CC110),
|
|
/// <c>ListenToElementMessage</c> (0x004CC430), and
|
|
/// <c>RecvNotice_SetCombatMode</c> (0x004CC620).
|
|
/// </remarks>
|
|
public sealed class CombatUiController : IRetainedPanelController
|
|
{
|
|
public const uint LayoutId = 0x21000073u;
|
|
public const uint BasicPanelId = 0x1000005Cu;
|
|
public const uint SpellcastingPanelId = 0x10000061u;
|
|
public const uint AdvancedPanelId = SpellcastingPanelId;
|
|
public const uint PowerControlId = 0x1000004Fu;
|
|
public const uint SpeedLabelId = 0x10000051u;
|
|
public const uint PowerLabelId = 0x10000052u;
|
|
public const uint RepeatAttacksId = 0x10000053u;
|
|
public const uint AutoTargetId = 0x10000054u;
|
|
public const uint KeepInViewId = 0x10000055u;
|
|
public const uint HighButtonId = 0x10000057u;
|
|
public const uint MediumButtonId = 0x10000058u;
|
|
public const uint LowButtonId = 0x10000059u;
|
|
|
|
public const uint MeleeState = 0x10000003u;
|
|
public const uint MissileState = 0x10000004u;
|
|
|
|
private readonly UiElement _root;
|
|
private readonly UiElement _basicPanel;
|
|
private readonly UiElement _spellcastingPanel;
|
|
private readonly UiScrollbar _powerControl;
|
|
private readonly UiButton _high;
|
|
private readonly UiButton _medium;
|
|
private readonly UiButton _low;
|
|
private readonly UiButton _repeatAttacks;
|
|
private readonly UiButton _autoTarget;
|
|
private readonly UiButton _keepInView;
|
|
private readonly CombatState _combat;
|
|
private readonly RuntimeCombatAttackState _attacks;
|
|
private readonly Func<GameplaySettings> _gameplay;
|
|
private readonly Action<GameplaySettings> _setGameplay;
|
|
private readonly Action<bool> _setWindowVisible;
|
|
private bool _disposed;
|
|
|
|
private CombatUiController(
|
|
ImportedLayout layout,
|
|
UiElement basicPanel,
|
|
UiElement spellcastingPanel,
|
|
UiScrollbar powerControl,
|
|
UiButton high,
|
|
UiButton medium,
|
|
UiButton low,
|
|
UiButton repeatAttacks,
|
|
UiButton autoTarget,
|
|
UiButton keepInView,
|
|
CombatState combat,
|
|
RuntimeCombatAttackState attacks,
|
|
Func<GameplaySettings> gameplay,
|
|
Action<GameplaySettings> setGameplay,
|
|
CombatUiLabels labels,
|
|
Action<bool> setWindowVisible)
|
|
{
|
|
_root = layout.Root;
|
|
_basicPanel = basicPanel;
|
|
_spellcastingPanel = spellcastingPanel;
|
|
_powerControl = powerControl;
|
|
_high = high;
|
|
_medium = medium;
|
|
_low = low;
|
|
_repeatAttacks = repeatAttacks;
|
|
_autoTarget = autoTarget;
|
|
_keepInView = keepInView;
|
|
_combat = combat;
|
|
_attacks = attacks;
|
|
_gameplay = gameplay;
|
|
_setGameplay = setGameplay;
|
|
_setWindowVisible = setWindowVisible;
|
|
|
|
// Retail layout 0x21000073 contains two sibling pages: gmCombatUI's
|
|
// physical-attack controls and gmSpellcastingUI's favorite-spell bar.
|
|
_basicPanel.Visible = true;
|
|
_spellcastingPanel.Visible = false;
|
|
|
|
_powerControl.SetScalarPosition(_attacks.DesiredPower);
|
|
_powerControl.ScalarChanged = _attacks.SetDesiredPower;
|
|
_powerControl.ScalarFill = () => _attacks.PowerBarLevel;
|
|
|
|
BindAttackButton(_high, AttackHeight.High);
|
|
BindAttackButton(_medium, AttackHeight.Medium);
|
|
BindAttackButton(_low, AttackHeight.Low);
|
|
|
|
_high.Label = labels.High;
|
|
_medium.Label = labels.Medium;
|
|
_low.Label = labels.Low;
|
|
_repeatAttacks.Label = labels.RepeatAttacks;
|
|
_autoTarget.Label = labels.AutoTarget;
|
|
_keepInView.Label = labels.KeepInView;
|
|
UiText? speedLabel = layout.FindElement(SpeedLabelId) as UiText;
|
|
UiText? powerLabel = layout.FindElement(PowerLabelId) as UiText;
|
|
SetStaticText(speedLabel, labels.Speed, rightAligned: false);
|
|
SetStaticText(powerLabel, labels.Power, rightAligned: true);
|
|
|
|
_repeatAttacks.OnClick = () =>
|
|
_setGameplay(_gameplay() with { AutoRepeatAttack = _repeatAttacks.Selected });
|
|
_autoTarget.OnClick = () =>
|
|
_setGameplay(_gameplay() with { AutoTarget = _autoTarget.Selected });
|
|
_keepInView.OnClick = () =>
|
|
_setGameplay(_gameplay() with { ViewCombatTarget = _keepInView.Selected });
|
|
|
|
_combat.CombatModeChanged += OnCombatModeChanged;
|
|
_attacks.StateChanged += OnAttackStateChanged;
|
|
SyncControls();
|
|
}
|
|
|
|
public static CombatUiController? Bind(
|
|
ImportedLayout layout,
|
|
CombatState combat,
|
|
RuntimeCombatAttackState attacks,
|
|
Func<GameplaySettings> gameplay,
|
|
Action<GameplaySettings> setGameplay,
|
|
CombatUiLabels labels,
|
|
Action<bool> setWindowVisible)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(layout);
|
|
ArgumentNullException.ThrowIfNull(combat);
|
|
ArgumentNullException.ThrowIfNull(attacks);
|
|
ArgumentNullException.ThrowIfNull(gameplay);
|
|
ArgumentNullException.ThrowIfNull(setGameplay);
|
|
ArgumentNullException.ThrowIfNull(labels);
|
|
ArgumentNullException.ThrowIfNull(setWindowVisible);
|
|
|
|
if (layout.FindElement(BasicPanelId) is not { } basic
|
|
|| layout.FindElement(SpellcastingPanelId) is not { } spellcasting
|
|
|| layout.FindElement(PowerControlId) is not UiScrollbar power
|
|
|| layout.FindElement(HighButtonId) is not UiButton high
|
|
|| layout.FindElement(MediumButtonId) is not UiButton medium
|
|
|| layout.FindElement(LowButtonId) is not UiButton low
|
|
|| layout.FindElement(RepeatAttacksId) is not UiButton repeatAttacks
|
|
|| layout.FindElement(AutoTargetId) is not UiButton autoTarget
|
|
|| layout.FindElement(KeepInViewId) is not UiButton keepInView)
|
|
return null;
|
|
|
|
return new CombatUiController(
|
|
layout, basic, spellcasting, power, high, medium, low,
|
|
repeatAttacks, autoTarget, keepInView,
|
|
combat, attacks, gameplay, setGameplay, labels, setWindowVisible);
|
|
}
|
|
|
|
public void SyncVisibility() => OnCombatModeChanged(_combat.CurrentMode);
|
|
|
|
private void BindAttackButton(UiButton button, AttackHeight height)
|
|
{
|
|
button.OnPressed = () => _attacks.PressAttack(height);
|
|
button.OnReleased = _attacks.ReleaseAttack;
|
|
}
|
|
|
|
private void OnCombatModeChanged(CombatMode mode)
|
|
{
|
|
bool visible = mode is CombatMode.Melee or CombatMode.Missile or CombatMode.Magic;
|
|
_basicPanel.Visible = mode is CombatMode.Melee or CombatMode.Missile;
|
|
_spellcastingPanel.Visible = mode == CombatMode.Magic;
|
|
if (_root is IUiDatStateful stateful)
|
|
{
|
|
if (mode == CombatMode.Melee)
|
|
stateful.TrySetRetailState(MeleeState);
|
|
else if (mode == CombatMode.Missile)
|
|
stateful.TrySetRetailState(MissileState);
|
|
}
|
|
_setWindowVisible(visible);
|
|
SyncControls();
|
|
}
|
|
|
|
private void OnAttackStateChanged() => SyncControls();
|
|
|
|
private void SyncControls()
|
|
{
|
|
_powerControl.SetScalarPosition(_attacks.DesiredPower);
|
|
_high.Selected = _attacks.RequestedHeight == AttackHeight.High;
|
|
_medium.Selected = _attacks.RequestedHeight == AttackHeight.Medium;
|
|
_low.Selected = _attacks.RequestedHeight == AttackHeight.Low;
|
|
GameplaySettings gameplay = _gameplay();
|
|
_repeatAttacks.Selected = gameplay.AutoRepeatAttack;
|
|
_autoTarget.Selected = gameplay.AutoTarget;
|
|
_keepInView.Selected = gameplay.ViewCombatTarget;
|
|
}
|
|
|
|
private static void SetStaticText(UiText? text, string value, bool rightAligned)
|
|
{
|
|
if (text is null) return;
|
|
// Retail UIElement_Text starts with zero margins; these 15px-high
|
|
// gmCombatUI captions are single authored lines. The scrollback path's
|
|
// generic 4px inset would leave less than one glyph row and clip them all.
|
|
text.OneLine = true;
|
|
text.Padding = 0f;
|
|
text.Centered = false;
|
|
text.RightAligned = rightAligned;
|
|
UiText.Line[] line = [new UiText.Line(value, text.DefaultColor)];
|
|
text.LinesProvider = () => line;
|
|
}
|
|
|
|
public void OnShown() => SyncControls();
|
|
|
|
public void Dispose()
|
|
{
|
|
if (_disposed) return;
|
|
_disposed = true;
|
|
_combat.CombatModeChanged -= OnCombatModeChanged;
|
|
_attacks.StateChanged -= OnAttackStateChanged;
|
|
_powerControl.ScalarChanged = null;
|
|
_powerControl.ScalarFill = () => null;
|
|
_high.OnPressed = null;
|
|
_high.OnReleased = null;
|
|
_medium.OnPressed = null;
|
|
_medium.OnReleased = null;
|
|
_low.OnPressed = null;
|
|
_low.OnReleased = null;
|
|
_repeatAttacks.OnClick = null;
|
|
_autoTarget.OnClick = null;
|
|
_keepInView.OnClick = null;
|
|
}
|
|
}
|
|
|
|
/// <summary>Localized labels assigned by retail <c>gmCombatUI::PostInit</c>.</summary>
|
|
public sealed record CombatUiLabels(
|
|
string Speed,
|
|
string Power,
|
|
string RepeatAttacks,
|
|
string AutoTarget,
|
|
string KeepInView,
|
|
string High,
|
|
string Medium,
|
|
string Low)
|
|
{
|
|
private const uint UiStringTable = 0x23000001u;
|
|
|
|
public static CombatUiLabels Resolve(ElementInfo root, DatStringResolver strings)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(root);
|
|
ArgumentNullException.ThrowIfNull(strings);
|
|
|
|
return new CombatUiLabels(
|
|
ElementString(CombatUiController.SpeedLabelId, UiStateInfo.DirectStateId, "Speed"),
|
|
ElementString(CombatUiController.PowerLabelId, CombatUiController.MeleeState, "Power"),
|
|
RuntimeString("ID_CombatPanelOption_AutoRepeatAttack", "Repeat Attacks"),
|
|
RuntimeString("ID_CombatPanelOption_AutoTarget", "Auto Target"),
|
|
RuntimeString("ID_CombatPanelOption_ViewCombatTarget", "Keep in View"),
|
|
ElementString(CombatUiController.HighButtonId, UiStateInfo.DirectStateId, "High"),
|
|
ElementString(CombatUiController.MediumButtonId, UiStateInfo.DirectStateId, "Medium"),
|
|
ElementString(CombatUiController.LowButtonId, UiStateInfo.DirectStateId, "Low"));
|
|
|
|
string RuntimeString(string id, string fallback)
|
|
=> strings.Resolve(UiStringTable, DatStringResolver.ComputeHash(id)) ?? fallback;
|
|
|
|
string ElementString(uint elementId, uint stateId, string fallback)
|
|
{
|
|
ElementInfo? element = Find(root, elementId);
|
|
if (element is null
|
|
|| !element.TryGetEffectiveProperty(0x17u, out var property, stateId)
|
|
|| property.Kind != UiPropertyKind.StringInfo)
|
|
return fallback;
|
|
return strings.Resolve(property.StringInfoValue) ?? fallback;
|
|
}
|
|
}
|
|
|
|
private static ElementInfo? Find(ElementInfo element, uint id)
|
|
{
|
|
if (element.Id == id) return element;
|
|
foreach (ElementInfo child in element.Children)
|
|
if (Find(child, id) is { } found)
|
|
return found;
|
|
return null;
|
|
}
|
|
}
|