Closed AristurtleDev closed 7 months ago
Benchmarks for those that are curious for this pull request. Two benchmarks were performed. Each benchmark used the following aseprite file
The first benchmark measure loading the Aseprite file from disk, parsing, and creating the AsepriteFile
class instance containing all the data parsed from the file
The Benchmark Code
using BenchmarkDotNet.Attributes;
using Nez.Aseprite;
namespace Benchmark;
[SimpleJob(BenchmarkDotNet.Jobs.RuntimeMoniker.Net70)]
[MemoryDiagnoser(true)]
public class AsepriteLoadBenchmark
{
[Benchmark]
public AsepriteFile LoadAsepriteFile()
{
AsepriteFile aseFile = AsepriteFileLoader.Load("adventurer.aseprite");
return aseFile;
}
}
The Result
The second benchmark does a presetup that preloads the Aseprite file and creates a fake MonoGame Game class using GraphicsDevice.ReferenceAdapter
so that a GraphicsDevice
can be created. Then the actual benchmark measure taking that Aseprite file and converting it to a SpritAtlas
in Nez which performs the following steps
Color[]
representing a packed texture atlasTexture2D
from the Color[]
dataRectangle
source rects for each frame packed into the texture atlasSpriteAtlas
instance with the generated dataThe Benchmark Code
using BenchmarkDotNet.Attributes;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Nez.Aseprite;
using Nez.Sprites;
namespace Benchmark;
[SimpleJob(BenchmarkDotNet.Jobs.RuntimeMoniker.Net70)]
[MemoryDiagnoser(true)]
public class AsepriteBenchmarks
{
private AsepriteFile _aseFile;
private Game _game;
private GraphicsDeviceManager _gdm;
private GraphicsDevice _gd;
[GlobalSetup]
public void Setup()
{
_aseFile = AsepriteFileLoader.Load("adventurer.aseprite");
_game = new FakeGame();
_gdm = new GraphicsDeviceManager(_game);
_gdm.GraphicsProfile = GraphicsProfile.HiDef;
((IGraphicsDeviceManager)_game.Services.GetService(typeof(IGraphicsDeviceManager))).CreateDevice();
_gd = _game.GraphicsDevice;
}
[Benchmark]
public void ConvertToSpriteAtlas()
{
SpriteAtlas atlas = _aseFile.ToSpriteAtlas(_gd);
}
}
The result
This pull request adds support for loading the contents of an Aseprite file in Nez through the use of the new
AsepriteFileLoader
. Using this will create a newAsepriteFile
class instance that contains the data read from the Aseprite file.Example: Load Aseprite File
This PR also adds support for translating the data loaded from the Aseprite file into the already built in Nez
SpriteAtlas
class, which can then be used to load into aSpriteAnimator
component to turn the Aseprite file animation tags into an animated sprite in Nez.Example: Create
SpriteAnimator
Component