using System.Diagnostics;
|
|
|
|
namespace Smoll {
|
|
public class Layer
|
|
{
|
|
public Layer(DrawMode drawMode = DrawMode.Normal) {
|
|
this.drawMode = drawMode;
|
|
actionables = new List<IActionable>();
|
|
watch = new Stopwatch();
|
|
}
|
|
|
|
public bool mustReorder = false;
|
|
|
|
internal Engine attachedEngine;
|
|
|
|
internal List<IActionable> actionables;
|
|
|
|
public enum DrawMode {
|
|
Normal,
|
|
Debug,
|
|
Tools
|
|
}
|
|
|
|
DrawMode drawMode = DrawMode.Normal;
|
|
|
|
Stopwatch watch;
|
|
|
|
public void Attach(Entity entity) {
|
|
entity.layers.Add(this);
|
|
actionables.Add(entity);
|
|
}
|
|
|
|
public float Update() {
|
|
float deltaTime;
|
|
if(! watch.IsRunning) {
|
|
watch.Start();
|
|
deltaTime = 0;
|
|
} else {
|
|
deltaTime = (float)(watch.Elapsed.TotalMicroseconds/1000000.0f);
|
|
watch.Reset();
|
|
watch.Start();
|
|
}
|
|
actionables.RemoveAll(x => x.ScheduledForRemoval());
|
|
for (int i = 0; i < actionables.Count; i++)
|
|
{
|
|
actionables[i].Update(deltaTime);
|
|
}
|
|
if(mustReorder) {
|
|
actionables.Sort();
|
|
}
|
|
return deltaTime;
|
|
}
|
|
public void Draw() {
|
|
foreach (var elem in actionables)
|
|
{
|
|
elem.Draw(drawMode);
|
|
}
|
|
}
|
|
}
|
|
}
|