62 lines
2.5 KiB
C#
62 lines
2.5 KiB
C#
using System.Linq;
|
|
using Age.Engine.Model;
|
|
using Xunit;
|
|
|
|
public class AnimInterpolatorTests
|
|
{
|
|
private static GfxState VisibleObj(long handle)
|
|
{
|
|
var g = new GfxState();
|
|
g.SetSurface(1, resId: 5, colorKey: -1);
|
|
g.BindDraw(handle, 1, 0, 0, 64, 64, 100, 100); // one 64x64 cell, base pos (100,100)
|
|
return g;
|
|
}
|
|
|
|
[Fact]
|
|
public void PingPong_FoldsAtHalfPeriod()
|
|
{
|
|
Assert.Equal(0, BlendMath.PingPong(now: 0, start: 0, period: 1000));
|
|
Assert.Equal(500, BlendMath.PingPong(now: 500, start: 0, period: 1000)); // peak at half
|
|
Assert.Equal(0, BlendMath.PingPong(now: 1000, start: 0, period: 1000)); // back to base
|
|
}
|
|
|
|
[Fact]
|
|
public void SrcRect_StaticCell_SelectsSubRect()
|
|
{
|
|
var g = VisibleObj(0x100);
|
|
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_AdvancesOneCellPerPeriodAndWraps()
|
|
{
|
|
var g = VisibleObj(0x100);
|
|
g.SetSrcRect(0x100, frameCount: 4, columns: 4, cell: 0, period: 100);
|
|
g.SnapshotVisibleObjects(0); // seeds start=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]
|
|
public void ColorAnim_PingPongsTintStrength_ObjectStaysOpaque()
|
|
{
|
|
var g = VisibleObj(0x100);
|
|
// base = no tint (strength 0); target = full-strength (alpha 0xff) red glow => strength pulses 0<->255
|
|
g.SetColorAnim(0x100, period: 1000, target: GfxState.PackColor(0xFF, 0xFF0000));
|
|
g.SnapshotVisibleObjects(0); // seeds start=0
|
|
var baseFrame = g.SnapshotVisibleObjects(0).Single();
|
|
Assert.Equal(255, baseFrame.Alpha); // object opacity ALWAYS opaque (never the color alpha)
|
|
Assert.Equal(0, baseFrame.TintStrength); // t=0 -> no tint
|
|
var peak = g.SnapshotVisibleObjects(500).Single();
|
|
Assert.Equal(255, peak.Alpha); // still opaque
|
|
Assert.Equal(255, peak.TintStrength); // t=1 -> full tint strength (the glow peak)
|
|
}
|
|
}
|