Fix retained ADV text in menu layouts

This commit is contained in:
gamer147
2026-07-27 13:29:17 -04:00
parent 8bc60d89ad
commit b2f1b4a45e
11 changed files with 446 additions and 70 deletions

View File

@@ -36,6 +36,10 @@ public interface IHost
void EnterScriptContext(string scriptName) { }
void ExitScriptContext() { }
void ShowText(int offset, string text);
void ShowText(AdvLiveTextRun run, int glyphDelayMilliseconds)
=> ShowText(run.SourceOffset, run.Text);
int MessageGlyphDelayMilliseconds => 50;
void SetMessageGlyphDelayMilliseconds(int milliseconds) { }
// Native ADV text subsystem: op 0x7a updates the selected layout's last 20-byte cursor record;
// op 0x204 rasterizes a string into a numbered surface before 0x1fb binds that surface.
void SetAdvTextCursor(int layoutSlot, int x, int y) { }

View File

@@ -44,6 +44,26 @@ public readonly record struct AdvTextLayoutSnapshot(
int Right,
int Bottom);
/// <summary>
/// One live show-text run with the layout and raster state captured when the opcode executes.
/// Unlike <see cref="AdvTextHistoryRecord"/>, this presentation record exists even while History
/// backlog recording is suppressed.
/// </summary>
public sealed record AdvLiveTextRun(
int SourceOffset,
AdvTextLayoutSnapshot Layout,
AdvTextStyle Style,
string Text,
IReadOnlyList<string> ScriptStack)
{
public bool BelongsToScript(string scriptName)
{
foreach (string frame in ScriptStack)
if (string.Equals(frame, scriptName, StringComparison.OrdinalIgnoreCase)) return true;
return false;
}
}
/// <summary>
/// One semantic counterpart of AGE's 0x48-byte retained text record. Metadata uses
/// <see cref="Value"/> plus <see cref="AuxValue"/> as value/type; voice uses them as id/argument.
@@ -157,6 +177,19 @@ public sealed class AdvTextHistory
layout.OriginY = y;
}
/// <summary>
/// Advance to the next horizontal text line. Native resets x to the layout's configured reset cursor
/// and adds the primary font's pixel height plus the current extra line spacing to y.
/// </summary>
public void EndLine(int requestedSlot, AdvTextStyle style)
{
int slot = ResolveLayout(requestedSlot);
var layout = GetOrCreateLayout(slot);
int fontHeight = style.PrimaryFontSize > 0 ? style.PrimaryFontSize : 24;
layout.CursorX = layout.ResetCursorX;
layout.CursorY += fontHeight + style.LineSpacing;
}
public AdvTextLayoutSnapshot GetLayoutSnapshot(int requestedSlot)
=> SnapshotLayout(ResolveLayout(requestedSlot));

View File

@@ -82,6 +82,7 @@ public sealed class VirtualMachine
private volatile bool _advSkipServiceEnabled;
private bool _advReadSkipState;
private AdvTextStyle _advTextStyle = AdvTextStyle.Default;
private int _messageGlyphDelayMilliseconds;
private readonly Dictionary<string, int> _valueSwitchTargets = new(StringComparer.Ordinal);
// Native EngineCtx owns 11 lazily allocated integer FIFOs at +0x55130. ATSEEK/MVSEEK use
// slot zero as their packed-coordinate flood-fill worklist; op 0x132 replaces a slot.
@@ -125,6 +126,10 @@ public sealed class VirtualMachine
{
get { lock (_interactiveLock) return _rawInputFrame != null; }
}
public string? RawInputCallbackScriptName
{
get { lock (_interactiveLock) return _rawInputFrame?.Script.Name; }
}
public AdvTextHistory TextHistory { get; }
/// <summary>The currently executing recursive script frame and stack, or null outside VM execution.</summary>
@@ -151,6 +156,7 @@ public sealed class VirtualMachine
_sink = sink ?? NullTraceSink.Instance; TextHistory = textHistory ?? new AdvTextHistory();
_sharedProfile = sharedProfile ?? new SharedProfile();
_nativeDatStore = nativeDatStore;
_messageGlyphDelayMilliseconds = System.Math.Max(0, host.MessageGlyphDelayMilliseconds);
_accumulatedPlaySeconds = _sharedProfile.AccumulatedPlaySeconds;
_sessionStartTimestamp = System.Diagnostics.Stopwatch.GetTimestamp();
}
@@ -1808,15 +1814,19 @@ public sealed class VirtualMachine
RefreshAdvReadSkipState();
foreach (var o in a)
{
if (o.Type != T_STR) continue;
int off = (int)o.Value;
if (!IsStr(o)) continue;
int off = o.Type == T_STR ? (int)o.Value : ins.Offset;
_cur.EmitSeen.TryGetValue(off, out var c); c++; _cur.EmitSeen[off] = c;
if (c > _o.EmitCap) { HaltReason = $"LOOP:line@0x{off:x}×{c}"; return HALT; }
string text = _cur.Script.GetString(off);
string text = ReadStr(o);
Emitted.Add((off, text, _cur.Script.Name));
int layoutSlot = a.Count > 0 ? (int)Read(a[0]) : 0;
string[] scriptStack;
lock (_debugControlLock) scriptStack = _activeFrameNames.ToArray();
var liveRun = new AdvLiveTextRun(
off, TextHistory.GetLayoutSnapshot(layoutSlot), _advTextStyle, text, scriptStack);
TextHistory.AppendText(layoutSlot, off, text, _advTextStyle);
_host.ShowText(off, text);
_host.ShowText(liveRun, _messageGlyphDelayMilliseconds);
}
return pc + 1;
case "define-adv-text-layout": // 0x70: configure layout and begin a logical retained group
@@ -2235,10 +2245,20 @@ public sealed class VirtualMachine
case "get-message-window-alpha": // 0x131: host profile/config seam; default host currently supplies 0
case "u00415F70":
Write(a[0], _host.MessageWindowAlphaSetting); return pc + 1;
case "get-message-glyph-delay": // 0x7f
case "u00414C60":
Write(a[0], _messageGlyphDelayMilliseconds); return pc + 1;
case "set-message-glyph-delay": // 0x1b5
case "u0041B5F0":
_messageGlyphDelayMilliseconds = System.Math.Max(0, (int)Read(a[0]));
_host.SetMessageGlyphDelayMilliseconds(_messageGlyphDelayMilliseconds);
return pc + 1;
case "u00415BF0":
case "reset-message-skip-input": // 0x101 clears transient input/run bits, not op 0x88 state
return pc + 1;
case "end-text-line": case "set-font":
case "end-text-line":
TextHistory.EndLine((int)Read(a[0]), _advTextStyle); return pc + 1;
case "set-font":
case "comment": case "display-furigana": case "dev_ukn":
return pc + 1;
case "create-texture": // 0x1f8 (slot)(w)(h) — allocate a blank surface at the slot