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