From 604398cae2110ad697e5a9d0dea4b7d75134c07e Mon Sep 17 00:00:00 2001 From: PopSlime Date: Sat, 12 Nov 2022 16:56:27 +0800 Subject: [PATCH] Add judge feed and cleanup stub. --- Assets/Cryville/Crtr/Judge.cs | 52 +++++++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 9 deletions(-) diff --git a/Assets/Cryville/Crtr/Judge.cs b/Assets/Cryville/Crtr/Judge.cs index e00b86c..18a7d7d 100644 --- a/Assets/Cryville/Crtr/Judge.cs +++ b/Assets/Cryville/Crtr/Judge.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; namespace Cryville.Crtr { public class Judge { + readonly PdtEvaluator _etor; readonly PdtRuleset _rs; readonly Dictionary ct = new Dictionary(); @@ -24,7 +25,14 @@ namespace Cryville.Crtr { return x.StartTime.CompareTo(y.StartTime); } } + static IComparer _etcmp = new JudgeEventEndTimeComparer(); + class JudgeEventEndTimeComparer : IComparer { + public int Compare(JudgeEvent x, JudgeEvent y) { + return x.EndTime.CompareTo(y.EndTime); + } + } public Judge(PdtRuleset rs) { + _etor = ChartPlayer.etor; _rs = rs; foreach (var s in rs.scores) { var name = s.Key.Key; @@ -49,11 +57,37 @@ namespace Cryville.Crtr { if (index < 0) index = ~index; list.Insert(index, ev); } - public void Feed(string target, float ft, float tt) { - Logger.Log("main", 0, "Judge", "Feed {0}: {1}->{2}", target, ft, tt); + public void Feed(Identifier target, float ft, float tt) { + Forward(target, tt); + var actlist = activeEvs[target]; + foreach (var ev in actlist) { + // TODO judge ev + } } - public void Cleanup(string target, float ft, float tt) { - Logger.Log("main", 0, "Judge", "Cleanup {0}: {1}->{2}", target, ft, tt); + public void Cleanup(Identifier target, float ft, float tt) { + Forward(target, tt); + var actlist = activeEvs[target]; + for (int i = actlist.Count - 1; i >= 0; i--) { + JudgeEvent ev = actlist[i]; + if (tt > ev.EndTime) { + actlist.RemoveAt(i); + Logger.Log("main", 0, "Judge", "miss {0}", target); + // TODO miss ev + } + } + } + void Forward(Identifier target, float tt) { + var list = evs[target]; + var actlist = activeEvs[target]; + JudgeEvent ev; + while (list.Count > 0 && (ev = list[0]).StartTime <= tt) { + list.RemoveAt(0); + var index = actlist.BinarySearch(ev, _etcmp); + if (index < 0) index = ~index; + actlist.Insert(index, ev); + Logger.Log("main", 0, "Judge", "active {0}", target); + // TODO priority? + } } public readonly Dictionary scoreDefs = new Dictionary(); public readonly Dictionary scores = new Dictionary(); @@ -61,12 +95,12 @@ namespace Cryville.Crtr { readonly object _lock = new object(); public Dictionary GetFormattedScoreStrings() { lock (_lock) { - if (ScoreCache.Count == 0) { - foreach (var s in scores) - ScoreCache.Add(s.Key, s.Value.ToString(scoreDefs[s.Key].format)); + if (ScoreCache.Count == 0) { + foreach (var s in scores) + ScoreCache.Add(s.Key, s.Value.ToString(scoreDefs[s.Key].format)); + } + return ScoreCache; } - return ScoreCache; - } } public string GetFullFormattedScoreString() { bool flag = false;