Is the class so necessary?
public class ContentCache { private readonly ContentManager _content; private readonly Dictionary<string, Texture2D> _textureCache = new Dictionary<string, Texture2D>(); public ContentCache(ContentManager content) { _content = content; } public Texture2D Load(string assetName) { Texture2D texture = null; if (!_textureCache.TryGetValue(assetName, out texture)) { _textureCache[assetName] = texture = _content.Load<Texture2D>(assetName); } return texture; } }
I am curious if ContentManager.Load<Texture2D>()
performs internal caching. I do not want to duplicate things.
Note:
Our game is XNA 2D and is going to run on WP7 and Windows, as well as iOS and OSX, using MonoGame .
MonoGame may work differently than XNA on Windows, but I can probably look at its source to find out.
source share