1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-05-29 03:23:37 +02:00

made the texture packer disposable and resettable

This commit is contained in:
Ell 2021-02-11 01:35:27 +01:00
parent 2cf912255d
commit b34172d043

View file

@ -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 <see cref="TextureRegion"/> instances.
/// </summary>
public class RuntimeTexturePacker {
public class RuntimeTexturePacker : IDisposable {
private readonly List<Request> textures = new List<Request>();
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();
}
/// <summary>
/// Resets this texture packer, disposing its <see cref="PackedTexture"/> and readying it to be re-used
/// </summary>
public void Reset() {
this.PackedTexture?.Dispose();
this.PackedTexture = null;
this.textures.Clear();
this.LastCalculationTime = TimeSpan.Zero;
this.LastPackTime = TimeSpan.Zero;
}
/// <inheritdoc />
public void Dispose() {
this.Reset();
}
private Rectangle FindFreeArea(Point size) {