mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-22 04:53:29 +01:00
added additional texture packer tests
This commit is contained in:
parent
1d4a2ebdf7
commit
e623eff02d
1 changed files with 41 additions and 1 deletions
|
@ -1,4 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
using MLEM.Data;
|
using MLEM.Data;
|
||||||
using MLEM.Textures;
|
using MLEM.Textures;
|
||||||
|
@ -15,7 +17,7 @@ public class TexturePackerTests {
|
||||||
[SetUp]
|
[SetUp]
|
||||||
public void SetUp() {
|
public void SetUp() {
|
||||||
this.game = TestGame.Create();
|
this.game = TestGame.Create();
|
||||||
this.testTexture = new Texture2D(this.game.GraphicsDevice, 256, 256);
|
this.testTexture = new Texture2D(this.game.GraphicsDevice, 2048, 2048);
|
||||||
this.disposedTestTexture = new Texture2D(this.game.GraphicsDevice, 16, 16);
|
this.disposedTestTexture = new Texture2D(this.game.GraphicsDevice, 16, 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,6 +43,24 @@ public class TexturePackerTests {
|
||||||
Assert.AreEqual(packer.PackedTexture.Height, 64);
|
Assert.AreEqual(packer.PackedTexture.Height, 64);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestOverlap() {
|
||||||
|
var packed = new List<TextureRegion>();
|
||||||
|
using (var packer = new RuntimeTexturePacker()) {
|
||||||
|
for (var i = 1; i <= 1000; i++)
|
||||||
|
packer.Add(new TextureRegion(this.testTexture, 0, 0, i % 239, i % 673), packed.Add);
|
||||||
|
packer.Pack(this.game.GraphicsDevice);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var r1 in packed) {
|
||||||
|
foreach (var r2 in packed) {
|
||||||
|
if (r1 == r2)
|
||||||
|
continue;
|
||||||
|
Assert.False(r1.Area.Intersects(r2.Area));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestDisposal() {
|
public void TestDisposal() {
|
||||||
using var packer = new RuntimeTexturePacker(128, disposeTextures: true);
|
using var packer = new RuntimeTexturePacker(128, disposeTextures: true);
|
||||||
|
@ -104,6 +124,26 @@ public class TexturePackerTests {
|
||||||
Assert.AreEqual(2 * 11 + 1, results);
|
Assert.AreEqual(2 * 11 + 1, results);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestPackTimes() {
|
||||||
|
for (var total = 1; total <= 1001; total += 100) {
|
||||||
|
using var sameSizePacker = new RuntimeTexturePacker();
|
||||||
|
using var diffSizePacker = new RuntimeTexturePacker();
|
||||||
|
for (var i = 0; i < total; i++) {
|
||||||
|
sameSizePacker.Add(new TextureRegion(this.testTexture, 0, 0, 10, 10), TexturePackerTests.StubResult);
|
||||||
|
diffSizePacker.Add(new TextureRegion(this.testTexture, 0, 0, 10 + i % 129, 10 * (i % 5 + 1)), TexturePackerTests.StubResult);
|
||||||
|
}
|
||||||
|
sameSizePacker.Pack(this.game.GraphicsDevice);
|
||||||
|
diffSizePacker.Pack(this.game.GraphicsDevice);
|
||||||
|
|
||||||
|
TestContext.WriteLine($"""
|
||||||
|
{total} regions,
|
||||||
|
same-size {sameSizePacker.LastCalculationTime.TotalMilliseconds} calc, {sameSizePacker.LastPackTime.TotalMilliseconds} pack, {sameSizePacker.LastTotalTime.TotalMilliseconds} total,
|
||||||
|
diff-size {diffSizePacker.LastCalculationTime.TotalMilliseconds} calc, {diffSizePacker.LastPackTime.TotalMilliseconds} pack, {diffSizePacker.LastTotalTime.TotalMilliseconds} total
|
||||||
|
""");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static void StubResult(TextureRegion region) {}
|
private static void StubResult(TextureRegion region) {}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue