using System; using System.Collections.Generic; namespace Cryville.Crtr { public abstract class StateBase { public int EventId; public float Time; public Chart chart; public List events; bool breakflag = false; public StateBase(Chart c, List evs) { chart = c; events = evs; EventId = 0; Time = 0; } public virtual StateBase Clone() { return (StateBase)base.MemberwiseClone(); } public virtual void CopyTo(StateBase dest) { dest.EventId = EventId; dest.Time = Time; dest.breakflag = breakflag; } public virtual void Break() { breakflag = true; } public void Forward(Action callback = null) { ForwardToTime(float.PositiveInfinity, ev => { if (callback != null) callback(ev); }); } public void ForwardByTime(float time, Action callback = null) { ForwardToTime(Time + time, ev => { if (callback != null) callback(ev); }); } public void ForwardOnceByTime(float time, Action callback = null) { ForwardOnceToTime(Time + time, callback); } public void ForwardToTime(float toTime, Action callback = null) { breakflag = false; ForwardOnceToTime(Time, callback); while (Time < toTime) { ForwardOnceToTime(toTime, callback); if (breakflag) break; } } public void ForwardStepByTime(float time, float step, Action callback = null) { ForwardStepToTime(Time + time, step, callback); } public void ForwardStepToTime(float toTime, float step, Action callback = null) { breakflag = false; ForwardOnceToTime(Time, callback); while (Time < toTime) { float next = Time + step; ForwardOnceToTime(next < toTime ? next : toTime, callback); if (breakflag) break; } } public abstract void ForwardOnceToTime(float toTime, Action callback = null); } }