diff --git a/RecrownedAthenaeum/DataTypes/TextureAtlas.cs b/RecrownedAthenaeum/DataTypes/TextureAtlas.cs index 4076d68..d675c68 100644 --- a/RecrownedAthenaeum/DataTypes/TextureAtlas.cs +++ b/RecrownedAthenaeum/DataTypes/TextureAtlas.cs @@ -2,16 +2,17 @@ using Microsoft.Xna.Framework.Graphics; using System; using System.Collections.Generic; +using System.Linq; namespace RecrownedAthenaeum.DataTypes { /// /// Holds information about an image file that contains various textures in various regions in the file. /// - public class TextureAtlas + public class TextureAtlas : IDisposable { private Texture2D texture; - + private bool disposed; private Dictionary dictionaryOfRegions = new Dictionary(); /// @@ -71,6 +72,40 @@ namespace RecrownedAthenaeum.DataTypes return dictionaryOfRegions[name].AsTexture2D(graphicsDevice); } + /// + /// Disposes unmanaged resources for the texture atlas. + /// + public void Dispose() + { + Dispose(true); + } + + /// + /// Overridable disposal method. + /// + /// Only true if user calls + public virtual void Dispose(bool disposing) + { + disposed = true; + if (!disposed && disposing) + { + texture.Dispose(); + for (int i = 0; i < dictionaryOfRegions.Count; i++) + { + dictionaryOfRegions.ElementAt(i).Value.Dispose(); + } + dictionaryOfRegions.Clear(); + } + } + + /// + /// Destructor. + /// + ~TextureAtlas() + { + Dispose(false); + } + /// /// A region of a . /// @@ -80,6 +115,7 @@ namespace RecrownedAthenaeum.DataTypes /// The name of the region. Mostly used to be refered to within the context of a . /// public readonly string name; + /// /// The location and dimensions of where the original texture resides on the texture representing the atlas. ///