content system now has a event system
This commit is contained in:
parent
46dc862aed
commit
0e4a4564cf
@ -11,8 +11,11 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace RhythmBullet.Zer01HD.Utilities.ContentSystem
|
namespace RhythmBullet.Zer01HD.Utilities.ContentSystem
|
||||||
{
|
{
|
||||||
|
public delegate void ContentUpdate(String fileName, float completed);
|
||||||
|
|
||||||
public class ContentSystem
|
public class ContentSystem
|
||||||
{
|
{
|
||||||
|
public event ContentUpdate UpdateEvent;
|
||||||
Thread thread;
|
Thread thread;
|
||||||
readonly ContentManager contentManager;
|
readonly ContentManager contentManager;
|
||||||
readonly Queue<LoadableContent> queue;
|
readonly Queue<LoadableContent> queue;
|
||||||
@ -64,7 +67,7 @@ namespace RhythmBullet.Zer01HD.Utilities.ContentSystem
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Debug.WriteLine("Did not queue asset due to asset with same name being loaded: " + assetName);
|
throw new InvalidOperationException("Did not queue asset due to asset with same name being loaded: " + assetName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -84,12 +87,16 @@ namespace RhythmBullet.Zer01HD.Utilities.ContentSystem
|
|||||||
|
|
||||||
private void LoadBatch()
|
private void LoadBatch()
|
||||||
{
|
{
|
||||||
|
int totalTasks = queue.Count;
|
||||||
|
int tasksCompleted = 0;
|
||||||
while (queue.Count != 0)
|
while (queue.Count != 0)
|
||||||
{
|
{
|
||||||
lock (queue)
|
lock (queue)
|
||||||
{
|
{
|
||||||
LoadableContent content = queue.Dequeue();
|
LoadableContent content = queue.Dequeue();
|
||||||
Load(content.assetName, content.type);
|
Load(content.assetName, content.type);
|
||||||
|
tasksCompleted++;
|
||||||
|
OnProgress(content.assetName, (float)tasksCompleted / totalTasks);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -142,5 +149,10 @@ namespace RhythmBullet.Zer01HD.Utilities.ContentSystem
|
|||||||
return queue.Count == 0;
|
return queue.Count == 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected virtual void OnProgress(string fileName, float progress)
|
||||||
|
{
|
||||||
|
UpdateEvent?.Invoke(fileName, progress);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user