feat(a2b): first-pass texture render — full-screen event-CG layer

Wire asset resolution into a live Godot render. VM executes set-texture ->
ResourceMap resolves (scene,resId) -> files[section_base+resId] across all
archives -> pre-converted BMP -> composite behind the dialogue. The full-screen
event-CG layer (EV052*) renders end-to-end from the executed bytecode.

- Age.Engine/Sys4/ResourceMap.cs: Resolve + BMP TexturePath; Paths: asset JSONs
- GodotAdvHost: create/set/draw-texture -> TextureRect in a _stage layer
- IHost.DrawTexture + VM dispatch extended with dst x/y (draw-texture args 7/8)
- project.godot 800x600; convert_agf.py all-archive + --scene batch
- engine 8/8, C# --selftest still byte-matches vm0 trace (VM behaviour unchanged)

Known limitations (next chunk = graphics geometry/blend subsystem):
- sprites + BG* via the CG-load subroutine get garbage dst/size — native ops
  stubbed (0x208 get-texture-size + sprite position/anim chain)
- AE* fades draw opaque/instant (no alpha); no chromakey
- slot model approximates the game's immediate-mode blit-onto-slot-0 canvas
- AGF pre-converted to BMP offline (runtime decoder deferred)
See docs/phase-a-slice-plan.md (A2b section).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
gamer147
2026-07-06 21:22:42 -04:00
parent a61c0c9abd
commit 10f6656c2d
15 changed files with 232 additions and 41 deletions

View File

@@ -1,15 +1,22 @@
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) => _main = main;
public GodotAdvHost(Main main, ResourceMap res, string scene)
{
_main = main; _res = res; _scene = scene;
}
public void ShowText(int offset, string text)
{
@@ -31,4 +38,19 @@ public sealed class GodotAdvHost : IHost
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);
}
}

View File

@@ -0,0 +1 @@
uid://b6bhdmtc2387h

View File

@@ -7,6 +7,8 @@ using Age.Engine.Vm;
public partial class Main : Godot.Control
{
private Control _stage = null!; // texture layer (behind the text)
private readonly Dictionary<int, TextureRect> _slots = new();
private Label _text = null!;
private Label _status = null!;
private VirtualMachine _vm = null!;
@@ -17,6 +19,12 @@ public partial class Main : Godot.Control
public override void _Ready()
{
// texture stage, added first so it draws BEHIND the dialogue text
_stage = new Control();
_stage.SetAnchorsAndOffsetsPreset(LayoutPreset.FullRect);
_stage.MouseFilter = MouseFilterEnum.Ignore;
AddChild(_stage);
_text = new Label { AutowrapMode = TextServer.AutowrapMode.WordSmart };
_text.SetAnchorsAndOffsetsPreset(LayoutPreset.FullRect);
_text.OffsetLeft = 40; _text.OffsetTop = 40; _text.OffsetRight = -40; _text.OffsetBottom = -80;
@@ -46,7 +54,7 @@ public partial class Main : Godot.Control
var table = OpcodeTableJson.Load(Paths.OpcodesJson);
var script = Sys4Loader.Load(Paths.Scripts()["SC0000.BIN"], table);
_host = new GodotAdvHost(this);
_host = new GodotAdvHost(this, ResourceMap.Load(), "SC0000");
_vm = new VirtualMachine(script, table, _host);
_ = Task.Run(() => { _vm.Run(); _done = true; });
@@ -77,6 +85,30 @@ public partial class Main : Godot.Control
public override void _ExitTree() { _host?.SignalInput(); }
// ---- UI methods invoked on the main thread via CallDeferred ----
// Composite a resolved texture into a slot at (x,y) sized (w,h). One TextureRect per slot,
// layered in draw order (backgrounds are drawn before sprites, so they sit behind).
public void DrawSlot(int slot, string bmpPath, int x, int y, int w, int h)
{
var img = new Image();
var err = img.LoadBmpFromBuffer(System.IO.File.ReadAllBytes(bmpPath));
if (err != Error.Ok) { GD.Print($"BMP load failed {bmpPath}: {err}"); return; }
if (!_slots.TryGetValue(slot, out var tr))
{
tr = new TextureRect
{
ExpandMode = TextureRect.ExpandModeEnum.IgnoreSize,
StretchMode = TextureRect.StretchModeEnum.Scale,
MouseFilter = MouseFilterEnum.Ignore,
};
_stage.AddChild(tr);
_slots[slot] = tr;
}
tr.Texture = ImageTexture.CreateFromImage(img);
tr.Position = new Vector2(x, y);
tr.Size = new Vector2(w > 0 ? w : img.GetWidth(), h > 0 ? h : img.GetHeight());
tr.Visible = true;
}
public void AppendLine(string text) => _text.Text += text + "\n";
public void PageBreak() => _status.Text = "▼ click / Enter";
public void ClearPage() { _text.Text = ""; _status.Text = ""; }

View File

@@ -4,5 +4,9 @@ config_version=5
config/name="Himegari (age-reimpl A2a)"
run/main_scene="res://Main.tscn"
[display]
window/size/viewport_width=800
window/size/viewport_height=600
[dotnet]
project/assembly_name="Himegari"