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) {