using System; using System.Collections.Generic; using UnityEngine; namespace Pink.Environment { public static partial class Simulation { static HeapQueue events = new HeapQueue(); static public T Schedule(float tick = 0) where T : Event, new() { var ev = new T(); ev.tick = Time.time + tick; events.Push(ev); return ev; } static public void Clear() { events.Clear(); } static public T GetModel() where T : class, new() { return InstanceRegister.instance; } static public void SetModel(T instance) where T : class, new() { InstanceRegister.instance = instance; } static public void DestroyModel() where T : class, new() { InstanceRegister.instance = null; } static public int Tick() { var time = Time.time; var runEvents = 0; while(events.Count > 0 && events.Peek().tick <= time) { var ev = events.Pop(); var tick = ev.tick; ev.ExecuteEvent(); runEvents++; } return runEvents; } } }