Implement tiled surface edge opcode

This commit is contained in:
gamer147
2026-07-29 14:03:51 -04:00
parent feef18d411
commit 0c7d77805e
7 changed files with 183 additions and 35 deletions

View File

@@ -0,0 +1,44 @@
using Age.Engine.Model;
using Age.Engine.Sys4;
using Age.Engine.Vm;
using Xunit;
public class TiledSurfaceEdgeOpcodeTests
{
private static Operand I(long value) => new(0, value);
[Fact]
public void OpcodeRetainsSystem4EdgeWhileModeOneSurfaceUsesPortableBackend()
{
var table = OpcodeTableJson.Load(Paths.OpcodesJson);
var scene = ScriptAssembler.Assemble(table, "TILED-SURFACE", new List<(int, Operand[])>
{
(0x248, new[] { I(128) }),
(0x249, new[] { I(0x32da), I(0x3e), I(0) }),
(0x2, System.Array.Empty<Operand>()),
}, System.Array.Empty<string>());
var host = new RecordingHost();
var vm = new VirtualMachine(scene, table, host);
vm.Run();
Assert.Equal(128, vm.Gfx.TiledSurfaceEdgeLength);
Assert.Equal((0x32daL, 0x3e), Assert.Single(host.Textures));
var surface = Assert.Single(vm.Gfx.CapturePersistenceSnapshot().Surfaces);
Assert.Equal((0x3e, 0x32daL), (surface.Slot, surface.ResourceId));
}
[Fact]
public void SettingReplacesSignedDwordAndSurvivesSceneContextReset()
{
var gfx = new GfxState();
Assert.Equal(0, gfx.TiledSurfaceEdgeLength);
gfx.SetTiledSurfaceEdgeLength(-1);
Assert.Equal(-1, gfx.TiledSurfaceEdgeLength);
gfx.SetTiledSurfaceEdgeLength(128);
gfx.ResetSceneContext();
Assert.Equal(128, gfx.TiledSurfaceEdgeLength);
}
}

View File

@@ -205,6 +205,9 @@ public sealed class GfxState
public int DefaultObjectSlot { get; private set; }
/// <summary>The D3D render target selected by op 0x20d. -1 denotes the main backbuffer.</summary>
public int CurrentRenderTargetSlot { get; private set; } = -1;
/// <summary>Legacy mode-1 surface tile edge selected by op 0x248. The portable backend retains
/// the native process-global value for parity but stores every surface as one contiguous image.</summary>
public int TiledSurfaceEdgeLength { get; private set; }
// ---- Separate global animation service clock (op 0x238; ctx+0x51b7c total / +0x51b78 elapsed).
// Retained for its opcode family; 0x21e scale and 0x220 translation use frame-time directly instead. ----
@@ -250,6 +253,13 @@ public sealed class GfxState
lock (_lock) DefaultObjectSlot = slot;
}
public void SetTiledSurfaceEdgeLength(long edgeLength)
{
// Native stores the complete operand in one signed dword. It does not invalidate or rebuild
// already-created mode-1 surfaces, nor does it mark the retained compositor dirty.
lock (_lock) TiledSurfaceEdgeLength = unchecked((int)edgeLength);
}
public void SetObjectAnchor(long handle, (long X, long Y, long Z) anchor)
{
lock (_lock) GetOrCreate(handle).V18 = anchor;

View File

@@ -2367,6 +2367,10 @@ public sealed class VirtualMachine
_host.SetTexture(resourceId, (int)Read(a[1]), colorKey);
return pc + 1; // host still tracks dims for get-texture-size
}
case "u00422E80": // pre-reference compatibility
case "set-tiled-surface-edge-length": // 0x248 (edge pixels)
Gfx.SetTiledSurfaceEdgeLength(Read(a[0]));
return pc + 1;
case "u00422EB0": // pre-reference compatibility
case "load-raw-texture-surface": // 0x249 (packed resource id)(slot)(colorkey)
{