70 lines
1.4 KiB
C#
70 lines
1.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace Cryville.Crtr {
|
|
public abstract class StateBase<T> {
|
|
public int EventId;
|
|
public double Time;
|
|
public List<T> events;
|
|
|
|
bool breakflag = false;
|
|
|
|
public StateBase(List<T> evs) {
|
|
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() {
|
|
ForwardToTime(double.PositiveInfinity);
|
|
}
|
|
|
|
public void ForwardByTime(double time) {
|
|
ForwardToTime(Time + time);
|
|
}
|
|
|
|
public void ForwardOnceByTime(double time) {
|
|
ForwardOnceToTime(Time + time);
|
|
}
|
|
|
|
public void ForwardToTime(double toTime) {
|
|
breakflag = false;
|
|
ForwardOnceToTime(Time);
|
|
while (Time < toTime) {
|
|
ForwardOnceToTime(toTime);
|
|
if (breakflag) break;
|
|
}
|
|
}
|
|
|
|
public void ForwardStepByTime(double time, double step) {
|
|
ForwardStepToTime(Time + time, step);
|
|
}
|
|
|
|
public void ForwardStepToTime(double toTime, double step) {
|
|
breakflag = false;
|
|
ForwardOnceToTime(Time);
|
|
while (Time < toTime) {
|
|
double next = Time + step;
|
|
ForwardOnceToTime(next < toTime ? next : toTime);
|
|
if (breakflag) break;
|
|
}
|
|
}
|
|
|
|
public abstract void ForwardOnceToTime(double toTime);
|
|
}
|
|
}
|