From 6dda931bc0a0c772a13047827a003300d3cb0050 Mon Sep 17 00:00:00 2001 From: gamer147 Date: Tue, 7 Jul 2026 19:46:21 -0400 Subject: [PATCH] feat(gfx): draw-texture records a retained layer in GfxState Co-Authored-By: Claude Opus 4.8 --- .../Age.Engine.Tests/GfxCommandBufferTests.cs | 20 +++++++++++++++++++ engine/Age.Engine/Vm/VirtualMachine.cs | 2 ++ 2 files changed, 22 insertions(+) diff --git a/engine/Age.Engine.Tests/GfxCommandBufferTests.cs b/engine/Age.Engine.Tests/GfxCommandBufferTests.cs index 566c1c5..8a433d4 100644 --- a/engine/Age.Engine.Tests/GfxCommandBufferTests.cs +++ b/engine/Age.Engine.Tests/GfxCommandBufferTests.cs @@ -92,4 +92,24 @@ public class GfxCommandBufferTests Assert.Equal((100L, 500L), (vm.Globals[10], vm.Globals[11])); // A intact Assert.Equal((300L, 100L), (vm.Globals[20], vm.Globals[21])); // B intact, no cross-contamination } + + private static (int, Operand[]) DrawTex(int handle, int slot, int w, int h, int dx, int dy) + => (0x1fb, new[] { G(handle), G(slot), I(0), I(0), G(w), G(h), G(dx), G(dy) }); + + [Fact] + public void DrawTextureRecordsARetainedLayer() + { + var t = T(); + var scene = ScriptAssembler.Assemble(t, "GFX", new List<(int, Operand[])> + { + MovGI(1, 0xA), MovGI(2, 4), MovGI(3, 800), MovGI(4, 600), MovGI(5, 0), MovGI(6, 0), + DrawTex(1, 2, 3, 4, 5, 6), Exit(), + }, System.Array.Empty()); + var vm = new VirtualMachine(scene, t, new RecordingHost()); + vm.Run(); + var layers = vm.Gfx.SnapshotLayers(); + Assert.Single(layers); + Assert.Equal(0xA, layers[0].Handle); + Assert.Equal((800, 600, 0, 0), (layers[0].W, layers[0].H, layers[0].DstX, layers[0].DstY)); + } } diff --git a/engine/Age.Engine/Vm/VirtualMachine.cs b/engine/Age.Engine/Vm/VirtualMachine.cs index 47d79da..488a5d6 100644 --- a/engine/Age.Engine/Vm/VirtualMachine.cs +++ b/engine/Age.Engine/Vm/VirtualMachine.cs @@ -216,6 +216,8 @@ public sealed class VirtualMachine case "set-texture": _host.SetTexture(Read(a[0]), (int)Read(a[1])); return pc + 1; case "draw-texture": // (handle, slot, srcX, srcY, w, h, dstX, dstY) + Gfx.AddOrUpdateLayer(new DrawLayer(Read(a[0]), (int)Read(a[1]), (int)Read(a[2]), (int)Read(a[3]), + (int)Read(a[4]), (int)Read(a[5]), (int)Read(a[6]), (int)Read(a[7]))); _host.DrawTexture((int)Read(a[1]), (int)Read(a[2]), (int)Read(a[3]), (int)Read(a[4]), (int)Read(a[5]), (int)Read(a[6]), (int)Read(a[7])); return pc + 1; case "get-texture-size": // 0x208 (slot) (out_w) (out_h)