Remove callback parameters on states.

This commit is contained in:
2023-01-03 12:09:16 +08:00
parent 7c77ba83f8
commit 723ec937ad
4 changed files with 23 additions and 28 deletions

View File

@@ -312,7 +312,7 @@ namespace Cryville.Crtr.Event {
Working = false; Working = false;
} }
public void Handle(StampedEvent ev, Action<StampedEvent> callback = null) { public void Handle(StampedEvent ev) {
if (breakflag) return; if (breakflag) return;
if (ev != null) { if (ev != null) {
if (ev.Unstamped is Chart.Motion) { if (ev.Unstamped is Chart.Motion) {
@@ -321,7 +321,7 @@ namespace Cryville.Crtr.Event {
mv.CloneTypeFlag = CloneType; mv.CloneTypeFlag = CloneType;
GetMotionValue(tev.Name).CopyTo(mv); GetMotionValue(tev.Name).CopyTo(mv);
PlayingMotions.Add(ev, mv); PlayingMotions.Add(ev, mv);
Callback(ev, callback); Update(ev);
if (!ev.Unstamped.IsLong) { if (!ev.Unstamped.IsLong) {
PlayingMotions.Remove(ev); PlayingMotions.Remove(ev);
RMVPool.Return(mv); RMVPool.Return(mv);
@@ -344,7 +344,7 @@ namespace Cryville.Crtr.Event {
if (tev.IsRelease) { if (tev.IsRelease) {
var nev = tev.Original; var nev = tev.Original;
if (nev is Chart.Motion) { if (nev is Chart.Motion) {
Callback(ev, callback); Update(ev);
var mv = PlayingMotions[ev.Origin]; var mv = PlayingMotions[ev.Origin];
if (mv.CloneTypeFlag == CloneType) RMVPool.Return(mv); if (mv.CloneTypeFlag == CloneType) RMVPool.Return(mv);
PlayingMotions.Remove(ev.Origin); PlayingMotions.Remove(ev.Origin);
@@ -359,15 +359,13 @@ namespace Cryville.Crtr.Event {
} }
} }
} }
Callback(ev.Unstamped == null || ev.Unstamped.Priority >= 0 ? ev : null, callback); Update(ev.Unstamped == null || ev.Unstamped.Priority >= 0 ? ev : null);
} }
else Callback(null, callback); else Update(null);
} }
void Callback(StampedEvent ev, Action<StampedEvent> callback) { void Update(StampedEvent ev) {
UpdateMotions(); UpdateMotions();
if (callback != null)
callback(ev);
if (ev == null || ev.Unstamped != null) Handler.Update(this, ev); if (ev == null || ev.Unstamped != null) Handler.Update(this, ev);
else Handler.ExUpdate(this, ev); else Handler.ExUpdate(this, ev);
foreach (var m in PlayingMotions) foreach (var m in PlayingMotions)

View File

@@ -56,7 +56,7 @@ namespace Cryville.Crtr.Event {
} }
} }
public override void ForwardOnceToTime(double toTime, Action<ChartEvent> callback) { public override void ForwardOnceToTime(double toTime) {
double toBeat = Math.Round(beat + (toTime - Time) * tempo / 60f, 6); double toBeat = Math.Round(beat + (toTime - Time) * tempo / 60f, 6);
if (EventId >= events.Count) if (EventId >= events.Count)
goto return_ahead; goto return_ahead;
@@ -84,7 +84,6 @@ namespace Cryville.Crtr.Event {
} }
stampedEvents.Add(sev); stampedEvents.Add(sev);
if (ev.Priority >= 0) { if (ev.Priority >= 0) {
if (callback != null) callback(ev);
flag = true; flag = true;
} }
if (ev is Chart.Signature) { if (ev is Chart.Signature) {
@@ -93,12 +92,10 @@ namespace Cryville.Crtr.Event {
} }
EventId++; EventId++;
} }
if (callback != null && !flag) callback(batch.First());
return; return;
return_ahead: return_ahead:
Time = toTime; Time = toTime;
beat = toBeat; beat = toBeat;
if (callback != null) callback(null);
} }
IOrderedEnumerable<ChartEvent> GetEventBatch() { IOrderedEnumerable<ChartEvent> GetEventBatch() {

View File

@@ -107,7 +107,7 @@ namespace Cryville.Crtr.Event {
tempEvents.Insert(index, ev); tempEvents.Insert(index, ev);
} }
public override void ForwardOnceToTime(double toTime, Action<EventBatch> callback = null) { public override void ForwardOnceToTime(double toTime) {
double time1 = EventId < events.Count ? events[EventId].Time : double.PositiveInfinity; double time1 = EventId < events.Count ? events[EventId].Time : double.PositiveInfinity;
double time2 = tempEvents.Count > 0 ? tempEvents[0].Time : double.PositiveInfinity; double time2 = tempEvents.Count > 0 ? tempEvents[0].Time : double.PositiveInfinity;
double time0 = Math.Min(time1, time2); double time0 = Math.Min(time1, time2);

View File

@@ -31,41 +31,41 @@ namespace Cryville.Crtr {
breakflag = true; breakflag = true;
} }
public void Forward(Action<T> callback = null) { public void Forward() {
ForwardToTime(double.PositiveInfinity, callback); ForwardToTime(double.PositiveInfinity);
} }
public void ForwardByTime(double time, Action<T> callback = null) { public void ForwardByTime(double time) {
ForwardToTime(Time + time, callback); ForwardToTime(Time + time);
} }
public void ForwardOnceByTime(double time, Action<T> callback = null) { public void ForwardOnceByTime(double time) {
ForwardOnceToTime(Time + time, callback); ForwardOnceToTime(Time + time);
} }
public void ForwardToTime(double toTime, Action<T> callback = null) { public void ForwardToTime(double toTime) {
breakflag = false; breakflag = false;
ForwardOnceToTime(Time, callback); ForwardOnceToTime(Time);
while (Time < toTime) { while (Time < toTime) {
ForwardOnceToTime(toTime, callback); ForwardOnceToTime(toTime);
if (breakflag) break; if (breakflag) break;
} }
} }
public void ForwardStepByTime(double time, double step, Action<T> callback = null) { public void ForwardStepByTime(double time, double step) {
ForwardStepToTime(Time + time, step, callback); ForwardStepToTime(Time + time, step);
} }
public void ForwardStepToTime(double toTime, double step, Action<T> callback = null) { public void ForwardStepToTime(double toTime, double step) {
breakflag = false; breakflag = false;
ForwardOnceToTime(Time, callback); ForwardOnceToTime(Time);
while (Time < toTime) { while (Time < toTime) {
double next = Time + step; double next = Time + step;
ForwardOnceToTime(next < toTime ? next : toTime, callback); ForwardOnceToTime(next < toTime ? next : toTime);
if (breakflag) break; if (breakflag) break;
} }
} }
public abstract void ForwardOnceToTime(double toTime, Action<T> callback = null); public abstract void ForwardOnceToTime(double toTime);
} }
} }