diff --git a/CHANGELOG.md b/CHANGELOG.md index 8675743..fcce781 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -58,6 +58,7 @@ Improvements - Premultiply textures when using RawContentManager - Allow enumerating all region names of a DataTextureAtlas - Cache RuntimeTexturePacker texture data while packing to improve performance +- Improve RuntimeTexturePacker performance by checking against packed textures in the same order as packing Fixes - Fixed SoundEffectReader incorrectly claiming it could read ogg and mp3 files diff --git a/MLEM.Data/RuntimeTexturePacker.cs b/MLEM.Data/RuntimeTexturePacker.cs index 56de3fa..2b848f6 100644 --- a/MLEM.Data/RuntimeTexturePacker.cs +++ b/MLEM.Data/RuntimeTexturePacker.cs @@ -152,9 +152,12 @@ namespace MLEM.Data { if (this.PackedTexture != null) throw new InvalidOperationException("Cannot pack a texture packer that is already packed"); + // we pack larger textures first, so that smaller textures can fit in the gaps that larger ones leave + this.textures.Sort((r1, r2) => (r2.Texture.Width * r2.Texture.Height).CompareTo(r1.Texture.Width * r1.Texture.Height)); + // set pack areas for each request var stopwatch = Stopwatch.StartNew(); - foreach (var request in this.textures.OrderByDescending(t => t.Texture.Width * t.Texture.Height)) + foreach (var request in this.textures) request.PackedArea = this.FindFreeArea(request); stopwatch.Stop(); this.LastCalculationTime = stopwatch.Elapsed;