Adding a cache for loading in textures

Splitting the code for Gleed2D into seperate files
master
Nathan Adams 2012-05-12 17:45:03 -05:00
parent 44cb32048d
commit b43a0fad34
7 changed files with 23 additions and 12 deletions

View File

@ -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
*
*/

View File

@ -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<string, Texture2D> cache)
{
base.load(cm, world);
base.load(cm, world, ref cache);
_body = BodyFactory.CreateCircle(world, Radius, 1f);
_body.Position = Position;

View File

@ -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).
/// </summary>
public virtual void load(ContentManager cm, World world)
public virtual void load(ContentManager cm, World world, ref Dictionary<string, Texture2D> cache)
{
}

View File

@ -38,12 +38,15 @@ namespace Axios.Engine.Glee2D
/// </summary>
public SerializableDictionary CustomProperties;
private Dictionary<string, Texture2D> _texturecache;
public Level()
{
Visible = true;
Layers = new List<Layer>();
CustomProperties = new SerializableDictionary();
_texturecache = new Dictionary<string, Texture2D>();
}
public Level(World world)
@ -52,9 +55,10 @@ namespace Axios.Engine.Glee2D
Layers = new List<Layer>();
CustomProperties = new SerializableDictionary();
_world = world;
_texturecache = new Dictionary<string, Texture2D>();
}
public static Level FromFile(string filename, ContentManager cm, World world)
public static Level FromFile(string filename, ContentManager cm, World world, ref Dictionary<string, Texture2D> 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);
}
}

View File

@ -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<string, Texture2D> cache)
{
base.load(cm, world);
base.load(cm, world, ref cache);
Vertices v = new Vertices(WorldPoints.Length);
foreach (Vector2 vec in WorldPoints)

View File

@ -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<string, Texture2D> cache)
{
base.load(cm, world);
base.load(cm, world, ref cache);
_body = BodyFactory.CreateRectangle(world, Width, Height, 1f);
_body.Position = Position;

View File

@ -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.
/// </summary>
public override void load(ContentManager cm, World world)
public override void load(ContentManager cm, World world, ref Dictionary<string, Texture2D> cache)
{
//throw new NotImplementedException();
@ -85,7 +85,12 @@ namespace Axios.Engine.Glee2D
//for example:
//this.texture = Texture2D.FromFile(<GraphicsDevice>, texture_filename);
//or by using the Content Pipeline:
this.texture = cm.Load<Texture2D>(asset_name);
if (!cache.ContainsKey(asset_name))
{
cache[asset_name] = cm.Load<Texture2D>(asset_name);
}
this.texture = cache[asset_name];
//this.texture = cm.Load<Texture2D>(asset_name);
}