using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
namespace RecrownedGTK.Assets
{
///
/// Wrapper for the content manager that helps with controlling it by adding automated multithreaded content loading.
///
public class AssetManager
{
Thread thread;
readonly AssetManager 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.
///
private readonly Dictionary contentPathModifier;
///
/// Used when no path modifier is defined for that specific type.
///
public IAssetPathResolver normalPathModifier = new NormalAssetPathResolver();
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 AssetManager()
{
assets = new Dictionary();
queue = new Queue();
contentPathModifier = new Dictionary();
}
///
/// Adds a to this handler.
///
///
///
public void AddContentPathResolver(Type assetType, IAssetPathResolver contentResolver) {
contentPathModifier.Add(assetType, contentResolver);
}
///
/// Removes the for the key.
///
///
public void RemoveContentResolver(Type assetType) {
contentPathModifier.Remove(assetType);
}
private void Load(string assetName, Type type, bool usePathModifier)
{
Debug.WriteLine("Loading asset: " + assetName);
string path = assetName;
if (usePathModifier)
{
IAssetPathResolver handler;
if (contentPathModifier.ContainsKey(type))
{
handler = contentPathModifier[type];
}
else
{
handler = normalPathModifier;
}
path = handler.Modify(assetName);
}
assets.Add(assetName, contentManager.Load