Optimize GC while preparing judge events.

This commit is contained in:
2023-05-20 22:58:05 +08:00
parent ca928eb731
commit 3fb123ff30

View File

@@ -52,6 +52,8 @@ namespace Cryville.Crtr {
_numsrc2 = new PropSrc.Float(() => _numbuf2); _numsrc2 = new PropSrc.Float(() => _numbuf2);
_numsrc3 = new PropSrc.Float(() => _numbuf3); _numsrc3 = new PropSrc.Float(() => _numbuf3);
_numsrc4 = new PropSrc.Float(() => _numbuf4); _numsrc4 = new PropSrc.Float(() => _numbuf4);
_identop = new PropOp.Identifier(v => _identbuf = new Identifier(v));
_clipop = new PropOp.Clip(v => _clipbuf = v);
_rs.judges.Judges.TryGetValue(new Identifier(_var_pause), out _judgePause); _rs.judges.Judges.TryGetValue(new Identifier(_var_pause), out _judgePause);
foreach (var i in rs.inputs) { foreach (var i in rs.inputs) {
var id = i.Key; var id = i.Key;
@@ -69,28 +71,30 @@ namespace Cryville.Crtr {
InitJudges(); InitJudges();
InitScores(); InitScores();
} }
Identifier _identbuf; readonly PropOp _identop;
Clip _clipbuf; readonly PropOp _clipop;
public void Prepare(StampedEvent sev, NoteHandler handler) { public void Prepare(StampedEvent sev, NoteHandler handler) {
var tev = (Chart.Judge)sev.Unstamped; var tev = (Chart.Judge)sev.Unstamped;
if (tev.Id.Key == _var_pause) throw new InvalidOperationException("Cannot assign the special judge \"pause\" to notes"); InsertEvent(tev, new Clip((float)sev.Time, (float)(sev.Time + sev.Duration)), tev.Id, handler);
Identifier input = default(Identifier); }
Clip clip = default(Clip); void InsertEvent(Chart.Judge ev, Clip clip, Identifier id, NoteHandler handler) {
var def = _rs.judges.Judges[tev.Id]; if (id.Key == _var_pause) throw new InvalidOperationException("Cannot assign the special judge \"pause\" to notes");
_etor.Evaluate(new PropOp.Identifier(v => input = new Identifier(v)), def.input); var def = _rs.judges.Judges[id];
_etor.Evaluate(new PropOp.Clip(v => clip = v), def.clip); _etor.Evaluate(_identop, def.input);
double st = sev.Time, et = st + sev.Duration; _etor.Evaluate(_clipop, def.clip);
var list = evs[input]; var list = evs[_identbuf];
var ev = new JudgeEvent { var jev = new JudgeEvent {
StartTime = st, StartTime = clip.Behind,
EndTime = et, EndTime = clip.Ahead,
StartClip = st + clip.Behind, StartClip = clip.Behind + _clipbuf.Behind,
EndClip = et + clip.Ahead, EndClip = clip.Ahead + _clipbuf.Ahead,
BaseEvent = tev, BaseEvent = ev,
Definition = def, Definition = def,
Handler = handler, Handler = handler,
}; };
var index = list.BinarySearch(ev, _stcmp); var index = list.BinarySearch(jev, _stcmp);
if (index < 0) index = ~index; if (index < 0) index = ~index;
list.Insert(index, ev); list.Insert(index, jev);
} }
#endregion #endregion
#region Judge #region Judge