diff --git a/axios/Axios_settings.cs b/axios/Axios_settings.cs index d54ed88..72e2666 100644 --- a/axios/Axios_settings.cs +++ b/axios/Axios_settings.cs @@ -69,7 +69,9 @@ * - Adding SplitFlat extension for Texture2D * - Removing uneeded Game Screen checking code * - Adding SplitFlat extension with offsets for Texture2D - * - Adding support for Glee2D + * - Adding support for Gleed2D + * - Splitting the code for Gleed2D into seperate files + * - Adding a cache for loading in textures for Gleed2D * */ diff --git a/axios/Engine/Glee2D/CircleItem.cs b/axios/Engine/Glee2D/CircleItem.cs index 4b71bd9..a50b270 100644 --- a/axios/Engine/Glee2D/CircleItem.cs +++ b/axios/Engine/Glee2D/CircleItem.cs @@ -23,9 +23,9 @@ namespace Axios.Engine.Glee2D { } - public override void load(ContentManager cm, World world) + public override void load(ContentManager cm, World world, ref Dictionary cache) { - base.load(cm, world); + base.load(cm, world, ref cache); _body = BodyFactory.CreateCircle(world, Radius, 1f); _body.Position = Position; diff --git a/axios/Engine/Glee2D/Item.cs b/axios/Engine/Glee2D/Item.cs index edea7e9..3f3577d 100644 --- a/axios/Engine/Glee2D/Item.cs +++ b/axios/Engine/Glee2D/Item.cs @@ -49,7 +49,7 @@ namespace Axios.Engine.Glee2D /// Called by Level.FromFile(filename) on each Item after the deserialization process. /// Should be overriden and can be used to load anything needed by the Item (e.g. a texture). /// - public virtual void load(ContentManager cm, World world) + public virtual void load(ContentManager cm, World world, ref Dictionary cache) { } diff --git a/axios/Engine/Glee2D/Level.cs b/axios/Engine/Glee2D/Level.cs index 9d98e0d..1dde762 100644 --- a/axios/Engine/Glee2D/Level.cs +++ b/axios/Engine/Glee2D/Level.cs @@ -38,12 +38,15 @@ namespace Axios.Engine.Glee2D /// public SerializableDictionary CustomProperties; + private Dictionary _texturecache; + public Level() { Visible = true; Layers = new List(); CustomProperties = new SerializableDictionary(); + _texturecache = new Dictionary(); } public Level(World world) @@ -52,9 +55,10 @@ namespace Axios.Engine.Glee2D Layers = new List(); CustomProperties = new SerializableDictionary(); _world = world; + _texturecache = new Dictionary(); } - public static Level FromFile(string filename, ContentManager cm, World world) + public static Level FromFile(string filename, ContentManager cm, World world, ref Dictionary cache) { FileStream stream = System.IO.File.Open(filename, FileMode.Open); XmlSerializer serializer = new XmlSerializer(typeof(Level)); @@ -66,7 +70,7 @@ namespace Axios.Engine.Glee2D foreach (Item item in layer.Items) { item.CustomProperties.RestoreItemAssociations(level); - item.load(cm, world); + item.load(cm, world, ref cache); } } diff --git a/axios/Engine/Glee2D/PathItem.cs b/axios/Engine/Glee2D/PathItem.cs index 0c2c1d6..bc982ad 100644 --- a/axios/Engine/Glee2D/PathItem.cs +++ b/axios/Engine/Glee2D/PathItem.cs @@ -26,9 +26,9 @@ namespace Axios.Engine.Glee2D { } - public override void load(ContentManager cm, World world) + public override void load(ContentManager cm, World world, ref Dictionary cache) { - base.load(cm, world); + base.load(cm, world, ref cache); Vertices v = new Vertices(WorldPoints.Length); foreach (Vector2 vec in WorldPoints) diff --git a/axios/Engine/Glee2D/RectangleItem.cs b/axios/Engine/Glee2D/RectangleItem.cs index 15741e3..e08b5ab 100644 --- a/axios/Engine/Glee2D/RectangleItem.cs +++ b/axios/Engine/Glee2D/RectangleItem.cs @@ -24,9 +24,9 @@ namespace Axios.Engine.Glee2D { } - public override void load(ContentManager cm, World world) + public override void load(ContentManager cm, World world, ref Dictionary cache) { - base.load(cm, world); + base.load(cm, world, ref cache); _body = BodyFactory.CreateRectangle(world, Width, Height, 1f); _body.Position = Position; diff --git a/axios/Engine/Glee2D/TextureItem.cs b/axios/Engine/Glee2D/TextureItem.cs index 31d36fb..7348f48 100644 --- a/axios/Engine/Glee2D/TextureItem.cs +++ b/axios/Engine/Glee2D/TextureItem.cs @@ -77,7 +77,7 @@ namespace Axios.Engine.Glee2D /// You must provide your own implementation. However, you can rely on all public fields being /// filled by the level deserialization process. /// - public override void load(ContentManager cm, World world) + public override void load(ContentManager cm, World world, ref Dictionary cache) { //throw new NotImplementedException(); @@ -85,7 +85,12 @@ namespace Axios.Engine.Glee2D //for example: //this.texture = Texture2D.FromFile(, texture_filename); //or by using the Content Pipeline: - this.texture = cm.Load(asset_name); + if (!cache.ContainsKey(asset_name)) + { + cache[asset_name] = cm.Load(asset_name); + } + this.texture = cache[asset_name]; + //this.texture = cm.Load(asset_name); }