Add judge priority.

This commit is contained in:
2022-11-14 13:55:10 +08:00
parent 7ce73186ae
commit c31c16792c

View File

@@ -16,19 +16,15 @@ namespace Cryville.Crtr {
struct JudgeEvent {
public float StartTime { get; set; }
public float EndTime { get; set; }
public float StartClip { get; set; }
public float EndClip { get; set; }
public JudgeDefinition Definition { get; set; }
public ContainerState State { get; set; }
}
static readonly IComparer<JudgeEvent> _stcmp = new JudgeEventStartTimeComparer();
class JudgeEventStartTimeComparer : IComparer<JudgeEvent> {
public int Compare(JudgeEvent x, JudgeEvent y) {
return x.StartTime.CompareTo(y.StartTime);
}
}
static readonly IComparer<JudgeEvent> _etcmp = new JudgeEventEndTimeComparer();
class JudgeEventEndTimeComparer : IComparer<JudgeEvent> {
public int Compare(JudgeEvent x, JudgeEvent y) {
return x.EndTime.CompareTo(y.EndTime);
return x.StartClip.CompareTo(y.StartClip);
}
}
public Judge(PdtRuleset rs) {
@@ -48,8 +44,10 @@ namespace Cryville.Crtr {
activeEvs.Add(input, new List<JudgeEvent>());
}
var ev = new JudgeEvent {
StartTime = st + def.clip[0],
EndTime = et + def.clip[1],
StartTime = st,
EndTime = et,
StartClip = st + def.clip[0],
EndClip = et + def.clip[1],
Definition = def,
State = container,
};
@@ -57,6 +55,20 @@ namespace Cryville.Crtr {
if (index < 0) index = ~index;
list.Insert(index, ev);
}
// Adopted from System.Collections.Generic.ArraySortHelper<T>.InternalBinarySearch(T[] array, int index, int length, T value, IComparer<T> comparer)
int BinarySearch(List<JudgeEvent> list, float time, int stack) {
int num = 0;
int num2 = list.Count - 1;
while (num <= num2) {
int num3 = num + (num2 - num >> 1);
int num4 = -list[num3].Definition.stack.CompareTo(stack);
if (num4 == 0) num4 = list[num3].StartClip.CompareTo(time);
if (num4 == 0) return num3;
else if (num4 < 0) num = num3 + 1;
else num2 = num3 - 1;
}
return ~num;
}
public void Feed(Identifier target, float ft, float tt) {
Forward(target, tt);
var actlist = activeEvs[target];
@@ -69,7 +81,7 @@ namespace Cryville.Crtr {
var actlist = activeEvs[target];
for (int i = actlist.Count - 1; i >= 0; i--) {
JudgeEvent ev = actlist[i];
if (tt > ev.EndTime) {
if (tt > ev.EndClip) {
actlist.RemoveAt(i);
// TODO miss ev
}
@@ -79,9 +91,9 @@ namespace Cryville.Crtr {
var list = evs[target];
var actlist = activeEvs[target];
JudgeEvent ev;
while (list.Count > 0 && (ev = list[0]).StartTime <= tt) {
while (list.Count > 0 && (ev = list[0]).StartClip <= tt) {
list.RemoveAt(0);
var index = actlist.BinarySearch(ev, _etcmp);
var index = BinarySearch(actlist, ev.StartClip, ev.Definition.stack);
if (index < 0) index = ~index;
actlist.Insert(index, ev);
// TODO priority?
@@ -122,6 +134,8 @@ namespace Cryville.Crtr {
public Identifier[] pass;
public Identifier miss;
public Dictionary<ScoreOperation, PdtExpression> scores;
public int stack;
public int prop = -1;
}
public class ScoreOperation {
public Identifier name;