From b34172d043679012292140bfacadfe1425b1060a Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Thu, 11 Feb 2021 01:35:27 +0100 Subject: [PATCH] made the texture packer disposable and resettable --- MLEM.Data/RuntimeTexturePacker.cs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/MLEM.Data/RuntimeTexturePacker.cs b/MLEM.Data/RuntimeTexturePacker.cs index 2c9b892..0824a3a 100644 --- a/MLEM.Data/RuntimeTexturePacker.cs +++ b/MLEM.Data/RuntimeTexturePacker.cs @@ -13,7 +13,7 @@ namespace MLEM.Data { /// Packing textures in this manner allows for faster rendering, as fewer texture swaps are required. /// The resulting texture segments are returned as instances. /// - public class RuntimeTexturePacker { + public class RuntimeTexturePacker : IDisposable { private readonly List textures = new List(); private readonly bool autoIncreaseMaxWidth; @@ -129,6 +129,23 @@ namespace MLEM.Data { // invoke callbacks foreach (var request in this.textures) request.Result.Invoke(new TextureRegion(this.PackedTexture, request.PackedArea)); + this.textures.Clear(); + } + + /// + /// Resets this texture packer, disposing its and readying it to be re-used + /// + public void Reset() { + this.PackedTexture?.Dispose(); + this.PackedTexture = null; + this.textures.Clear(); + this.LastCalculationTime = TimeSpan.Zero; + this.LastPackTime = TimeSpan.Zero; + } + + /// + public void Dispose() { + this.Reset(); } private Rectangle FindFreeArea(Point size) {