using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using RecrownedAthenaeum.ContentSystem;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
namespace RecrownedAthenaeum.ContentSystem
{
///
/// Wrapper for the content manager that helps with controlling it by adding automated multithreaded content loading.
///
public class ContentManagerController
{
Thread thread;
readonly ContentManager contentManager;
readonly Queue queue;
Dictionary assets;
///
/// Path modifiers to change the path in which the content manager looks to load a file. Used for better organizing things while not needing to type entire path.
///
public readonly Dictionary contentPathModifier;
///
/// Used when no path modifier is defined for that specific type.
///
public IContentPathResolver normalPathModifier = new NormalContentResolver();
volatile float progress;
volatile bool running;
///
/// Whether or not the queue is empty and all content is loaded.
///
public bool Done { get { return !running && queue.Count == 0; } }
///
/// The progress of the loading. 1 is complete while 0 is incomplete.
///
public float Progress { get { return progress; } }
///
/// Wraps the .
///
/// The manager to wrap.
public ContentManagerController(ContentManager contentManager)
{
this.contentManager = contentManager;
assets = new Dictionary();
queue = new Queue();
contentPathModifier = new Dictionary();
}
private void Load(string assetName, Type type, bool usePathModifier)
{
Debug.WriteLine("Loading asset: " + assetName);
string path = assetName;
if (usePathModifier)
{
IContentPathResolver handler;
if (contentPathModifier.ContainsKey(type))
{
handler = contentPathModifier[type];
}
else
{
handler = normalPathModifier;
}
path = handler.Modify(assetName);
}
assets.Add(assetName, contentManager.Load