Wire audio end-to-end (OGG plays natively in Godot; no Frida, no decode):
- IHost.PlayBgm/PlayVoice + VM dispatch for play-bgm(0xbf)/play-voice(0xc4).
Non-Godot hosts no-op them so --selftest + engine 8/8 stay byte-identical.
- GodotAdvHost resolves id->OGG; Main plays via two AudioStreamPlayer nodes
(BGM looping; voice interrupt-on-new).
Key finding (by-ear, systematic-debugging): the two audio ops use DIFFERENT
addressing — the earlier "unified manifest" assumption was wrong for BGM.
- play-voice -> per-scene manifest files[base+id] (offset 0, same as textures).
Confirmed by ear; upgraded med->HIGH.
- play-bgm -> DIRECT LITERAL NAME BGM{id:03d}.OGG, NOT the manifest.
Real game: play-bgm 5->BGM005, 8->BGM008 (manifest gave +1). Proven by
play-bgm 0x23->BGM035 (real standalone track; BGM set skips 030-034) that the
manifest mis-resolved to a graphics entry. Fix is BGM-only:
ResourceMap.BgmPathById; voices/textures unchanged.
Also: Lily's silence root-caused as correct form-gating (G[0xa57/0xa58/0xa59]),
left unseeded by choice (no dummy state). Added diagnostic
`Age.Cli audio <SCENE.BIN> [0xADDR=VAL ...]`. Corrected opcodes.toml (play-bgm
direct-name, play-voice HIGH) + docs/memory (dropped the bogus unified-manifest
/ Frida-BGM006 claims).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
72 lines
2.4 KiB
C#
72 lines
2.4 KiB
C#
using System.Collections.Generic;
|
|
using System.Threading;
|
|
using Age.Engine.Hosting;
|
|
using Age.Engine.Sys4;
|
|
|
|
public sealed class GodotAdvHost : IHost
|
|
{
|
|
private readonly Main _main;
|
|
private readonly ResourceMap _res;
|
|
private readonly string _scene; // e.g. "SC0000" — for section_base
|
|
private readonly Dictionary<int, string?> _slotBmp = new(); // slot -> pre-converted BMP path
|
|
private readonly SemaphoreSlim _gate = new(0, 1);
|
|
public volatile bool IsWaiting;
|
|
public readonly List<(int Offset, string Text)> Captured = new();
|
|
|
|
public GodotAdvHost(Main main, ResourceMap res, string scene)
|
|
{
|
|
_main = main; _res = res; _scene = scene;
|
|
}
|
|
|
|
public void ShowText(int offset, string text)
|
|
{
|
|
Captured.Add((offset, text));
|
|
_main.CallDeferred("AppendLine", text);
|
|
}
|
|
|
|
public void WaitForInput()
|
|
{
|
|
_main.CallDeferred("PageBreak");
|
|
IsWaiting = true;
|
|
_gate.Wait();
|
|
IsWaiting = false;
|
|
_main.CallDeferred("ClearPage");
|
|
}
|
|
|
|
// called from the main thread (click) or the selftest auto-clicker
|
|
public void SignalInput() { if (_gate.CurrentCount == 0) _gate.Release(); }
|
|
|
|
public void CallScript(long id) { }
|
|
public void OnStub(int opcode) { }
|
|
|
|
// ---- texture ops (run on the VM thread; marshal Godot node work to the main thread) ----
|
|
public void CreateTexture(int slot, int width, int height) => _slotBmp[slot] = null;
|
|
|
|
public void SetTexture(long resourceId, int slot)
|
|
{
|
|
var asset = _res.Resolve(_scene, resourceId);
|
|
_slotBmp[slot] = asset != null ? ResourceMap.TexturePath(asset) : null;
|
|
}
|
|
|
|
public void DrawTexture(int slot, int srcX, int srcY, int width, int height, int dstX, int dstY)
|
|
{
|
|
if (_slotBmp.TryGetValue(slot, out var bmp) && bmp != null)
|
|
_main.CallDeferred("DrawSlot", slot, bmp, dstX, dstY, width, height);
|
|
}
|
|
|
|
// ---- audio ops (OGG plays natively in Godot) ----
|
|
// BGM: addressed by direct name (BGM{id:D3}.OGG), NOT the manifest. Voice: via the per-scene manifest.
|
|
public void PlayBgm(long id)
|
|
{
|
|
var path = _res.BgmPathById(id);
|
|
if (path != null) _main.CallDeferred("PlayBgm", path);
|
|
}
|
|
|
|
public void PlayVoice(long id)
|
|
{
|
|
var asset = _res.Resolve(_scene, id);
|
|
var path = asset != null ? ResourceMap.AudioPath(asset) : null;
|
|
if (path != null) _main.CallDeferred("PlayVoice", path);
|
|
}
|
|
}
|