Fix AE001H spritesheet animation

This commit is contained in:
gamer147
2026-07-11 20:37:26 -04:00
parent 2a49a0697c
commit ca562da209
9 changed files with 93 additions and 51 deletions

View File

@@ -62,7 +62,8 @@ public class AnimChannelTests
vm.Run();
var o = vm.Gfx.TryGet(0x1000)!;
Assert.True(o.SrcAnim);
Assert.Equal(4, o.SrcGridW);
Assert.Equal(4, o.SrcFrameCount);
Assert.Equal(1, o.SrcColumns);
Assert.Equal(2, o.SrcCell);
}
@@ -78,9 +79,9 @@ public class AnimChannelTests
public void SetSrcRect_StoresGridCellPeriod()
{
var g = VisibleObj(0x100);
g.SetSrcRect(0x100, gridW: 4, gridH: 1, cell: 2, period: 800);
g.SetSrcRect(0x100, frameCount: 4, columns: 1, cell: 2, period: 800);
var o = g.TryGet(0x100)!;
Assert.Equal(4, o.SrcGridW);
Assert.Equal(4, o.SrcFrameCount);
Assert.Equal(2, o.SrcCell);
Assert.Equal(800, o.SrcPeriod);
Assert.True(o.SrcAnim);
@@ -91,10 +92,10 @@ public class AnimChannelTests
public void SetSrcRect_ClampsGridToAtLeastOne()
{
var g = VisibleObj(0x100);
g.SetSrcRect(0x100, gridW: 0, gridH: 0, cell: 0, period: 0);
g.SetSrcRect(0x100, frameCount: 0, columns: 0, cell: 0, period: 0);
var o = g.TryGet(0x100)!;
Assert.Equal(1, o.SrcGridW);
Assert.Equal(1, o.SrcGridH);
Assert.Equal(1, o.SrcFrameCount);
Assert.Equal(1, o.SrcColumns);
}
[Fact]

View File

@@ -8,7 +8,7 @@ public class AnimInterpolatorTests
{
var g = new GfxState();
g.SetSurface(1, resId: 5, colorKey: -1);
g.BindDraw(handle, 1, 0, 0, 256, 64, 100, 100); // 256x64 sheet, base pos (100,100)
g.BindDraw(handle, 1, 0, 0, 64, 64, 100, 100); // one 64x64 cell, base pos (100,100)
return g;
}
@@ -24,22 +24,24 @@ public class AnimInterpolatorTests
public void SrcRect_StaticCell_SelectsSubRect()
{
var g = VisibleObj(0x100);
g.SetSrcRect(0x100, gridW: 4, gridH: 1, cell: 2, period: 0); // static cell 2 of 4 across 256px
g.SetSrcRect(0x100, frameCount: 4, columns: 4, cell: 2, period: 0);
var ro = g.SnapshotVisibleObjects(0).Single();
Assert.Equal(128, ro.SrcX); // cell 2 * 64
Assert.Equal(64, ro.W);
}
[Fact]
public void SrcRect_Animated_PingPongsCellAcrossGrid()
public void SrcRect_Animated_AdvancesOneCellPerPeriodAndWraps()
{
var g = VisibleObj(0x100);
g.SetSrcRect(0x100, gridW: 4, gridH: 1, cell: 0, period: 1000);
g.SetSrcRect(0x100, frameCount: 4, columns: 4, cell: 0, period: 100);
g.SnapshotVisibleObjects(0); // seeds start=0
var half = g.SnapshotVisibleObjects(500).Single();
Assert.Equal(192, half.SrcX); // t=1 -> last cell (3) * 64
var back = g.SnapshotVisibleObjects(1000).Single();
Assert.Equal(0, back.SrcX); // ping-ponged back to cell 0
var second = g.SnapshotVisibleObjects(100).Single();
Assert.Equal(64, second.SrcX);
var fourth = g.SnapshotVisibleObjects(300).Single();
Assert.Equal(192, fourth.SrcX);
var wrapped = g.SnapshotVisibleObjects(400).Single();
Assert.Equal(0, wrapped.SrcX);
}
[Fact]

View File

@@ -82,6 +82,27 @@ public class GfxAnimationTests
Assert.True(rotation.HasActiveVisualPresentation(1000));
}
[Fact]
public void LoopingSpritesheet_PreservesCellSize_AdvancesRowMajor_AndWraps()
{
var g = new GfxState();
g.SetSurface(4, 0x37, -1);
g.BindDraw(0xcf3a, 4, 0, 0, 200, 200, 300, 100); // AE001H: 800x400, eight 200x200 cells
g.SetSrcRect(0xcf3a, frameCount: 8, columns: 4, cell: 0, period: 100);
var first = g.SnapshotVisibleObjects(1000).Single();
var second = g.SnapshotVisibleObjects(1100).Single();
var fifth = g.SnapshotVisibleObjects(1400).Single();
var eighth = g.SnapshotVisibleObjects(1700).Single();
var wrapped = g.SnapshotVisibleObjects(1800).Single();
Assert.Equal((0, 0, 200, 200), (first.SrcX, first.SrcY, first.W, first.H));
Assert.Equal((200, 0, 200, 200), (second.SrcX, second.SrcY, second.W, second.H));
Assert.Equal((0, 200, 200, 200), (fifth.SrcX, fifth.SrcY, fifth.W, fifth.H));
Assert.Equal((600, 200, 200, 200), (eighth.SrcX, eighth.SrcY, eighth.W, eighth.H));
Assert.Equal((0, 0, 200, 200), (wrapped.SrcX, wrapped.SrcY, wrapped.W, wrapped.H));
}
[Fact]
public void OneShotRotation_SharesMatrixClockAndMatchesNativeSample()
{