refactor: Update Unity to 2022.3.62

This commit is contained in:
2025-06-21 01:22:02 +08:00
parent d71bf7d4a5
commit 283783954f
112 changed files with 778 additions and 907 deletions

View File

@@ -38,10 +38,10 @@ namespace Cryville.Crtr.Ruleset {
}
}
#region Settings
readonly Dictionary<Identifier, InputProxyEntry> _tproxies = new Dictionary<Identifier, InputProxyEntry>();
readonly Dictionary<InputSource, InputProxyEntry> _sproxies = new Dictionary<InputSource, InputProxyEntry>();
readonly Dictionary<Identifier, int> _use = new Dictionary<Identifier, int>();
readonly Dictionary<Identifier, List<Identifier>> _rev = new Dictionary<Identifier, List<Identifier>>();
readonly Dictionary<Identifier, InputProxyEntry> _tproxies = new();
readonly Dictionary<InputSource, InputProxyEntry> _sproxies = new();
readonly Dictionary<Identifier, int> _use = new();
readonly Dictionary<Identifier, List<Identifier>> _rev = new();
public event EventHandler<ProxyChangedEventArgs> ProxyChanged;
public void LoadFrom(Dictionary<string, RulesetConfig.InputEntry> config) {
foreach (var cfg in config) {
@@ -140,8 +140,7 @@ namespace Cryville.Crtr.Ruleset {
}
}
void BroadcastProxyChanged(Identifier name) {
var del = ProxyChanged;
if (del != null) del(this, this[name]);
ProxyChanged?.Invoke(this, this[name]);
}
public ProxyChangedEventArgs this[Identifier name] {
get {
@@ -230,8 +229,8 @@ namespace Cryville.Crtr.Ruleset {
int dim;
if (op.Type == PdtInternalType.Number) dim = 1;
else if (op.Type == PdtInternalType.Vector) {
int arrtype, _;
op.GetArraySuffix(out arrtype, out _);
int _;
op.GetArraySuffix(out int arrtype, out _);
if (arrtype != PdtInternalType.Number)
throw new InvalidCastException("Not a vector of numbers");
dim = Math.Min(3, (op.Length - sizeof(int)) / sizeof(float));
@@ -245,10 +244,10 @@ namespace Cryville.Crtr.Ruleset {
}
}
}
readonly Dictionary<InputHandler, double> _timeOrigins = new Dictionary<InputHandler, double>();
readonly Dictionary<Identifier, int> _targetActiveCount = new Dictionary<Identifier, int>();
readonly Dictionary<InputIdentifier, float> _vect = new Dictionary<InputIdentifier, float>();
readonly Dictionary<ProxiedInputIdentifier, Vector4> _vecs = new Dictionary<ProxiedInputIdentifier, Vector4>();
readonly Dictionary<InputHandler, double> _timeOrigins = new();
readonly Dictionary<Identifier, int> _targetActiveCount = new();
readonly Dictionary<InputIdentifier, float> _vect = new();
readonly Dictionary<ProxiedInputIdentifier, Vector4> _vecs = new();
double? _lockTime = null;
unsafe void OnInput(InputIdentifier id, InputFrame frame) {
var rc = id.Source.Handler.ReferenceCue;
@@ -264,10 +263,9 @@ namespace Cryville.Crtr.Ruleset {
Monitor.Enter(_etor);
try {
Profiler.BeginSample("InputProxy.OnInput");
InputProxyEntry proxy;
if (_sproxies.TryGetValue(id.Source, out proxy)) {
float ft, tt = (float)GetSyncedTime(frame.Time, id.Source.Handler);
if (!_vect.TryGetValue(id, out ft)) ft = tt;
if (_sproxies.TryGetValue(id.Source, out InputProxyEntry proxy)) {
float tt = (float)GetSyncedTime(frame.Time, id.Source.Handler);
if (!_vect.TryGetValue(id, out float ft)) ft = tt;
_etor.ContextCascadeInsert();
try {
if (frame.IsNull) {
@@ -293,7 +291,7 @@ namespace Cryville.Crtr.Ruleset {
}
static readonly int _var_fv = IdentifierManager.Shared.Request("input_vec_from");
static readonly int _var_tv = IdentifierManager.Shared.Request("input_vec_to");
readonly InputVectorSrc _vecsrc = new InputVectorSrc();
readonly InputVectorSrc _vecsrc = new();
unsafe void OnInput(InputIdentifier id, Identifier target, float ft, float tt, bool nullFlag, int depth = 0) {
if (depth >= MAX_DEPTH) throw new InputProxyException("Input propagation limit reached\nThe ruleset has invalid input definitions");
var def = _ruleset.inputs[target];
@@ -318,8 +316,8 @@ namespace Cryville.Crtr.Ruleset {
else {
var pid = new ProxiedInputIdentifier { Source = id, Target = target };
PropSrc fv, tv = _etor.ContextCascadeLookup(_var_input_vec);
bool hfv; Vector4 ifv;
if (hfv = _vecs.TryGetValue(pid, out ifv)) {
bool hfv;
if (hfv = _vecs.TryGetValue(pid, out RVector4 ifv)) {
_vecsrc.Set(ifv);
fv = _vecsrc;
}
@@ -352,11 +350,10 @@ namespace Cryville.Crtr.Ruleset {
lock (_etor) {
foreach (var vec in _vecs) {
if (vec.Key.Source.Source.Handler != handler) continue;
InputProxyEntry proxy;
if (!_sproxies.TryGetValue(vec.Key.Source.Source, out proxy)) continue;
if (!_sproxies.TryGetValue(vec.Key.Source.Source, out InputProxyEntry proxy)) continue;
float ft, tt = (float)GetSyncedTime(time, handler);
if (_vect.TryGetValue(vec.Key.Source, out ft) && ft < tt) {
float tt = (float)GetSyncedTime(time, handler);
if (_vect.TryGetValue(vec.Key.Source, out float ft) && ft < tt) {
_etor.ContextCascadeInsert();
_vecsrcs[0].Set(vec.Value);
_etor.ContextCascadeUpdate(_var_input_vec, _vecsrcs[0]);
@@ -434,17 +431,17 @@ namespace Cryville.Crtr.Ruleset {
public struct ProxiedInputIdentifier : IEquatable<ProxiedInputIdentifier> {
public InputIdentifier Source { get; set; }
public Identifier Target { get; set; }
public override bool Equals(object obj) {
if (obj == null || !(obj is ProxiedInputIdentifier)) return false;
return Equals((ProxiedInputIdentifier)obj);
public override readonly bool Equals(object obj) {
if (obj == null || obj is not ProxiedInputIdentifier other) return false;
return Equals(other);
}
public bool Equals(ProxiedInputIdentifier other) {
public readonly bool Equals(ProxiedInputIdentifier other) {
return Source == other.Source && Target == other.Target;
}
public override int GetHashCode() {
public override readonly int GetHashCode() {
return Source.GetHashCode() ^ Target.GetHashCode();
}
public override string ToString() {
public override readonly string ToString() {
return string.Format("{0}->{1}", Source, Target);
}
public static bool operator ==(ProxiedInputIdentifier lhs, ProxiedInputIdentifier rhs) {

View File

@@ -45,10 +45,8 @@ namespace Cryville.Crtr.Ruleset {
internal readonly PdtEvaluator _etor;
readonly PdtRuleset _rs;
internal Dictionary<Identifier, PdtExpression> _areaFuncs;
readonly Dictionary<Identifier, List<JudgeEvent>> evs
= new Dictionary<Identifier, List<JudgeEvent>>();
readonly Dictionary<Identifier, List<JudgeEvent>> activeEvs
= new Dictionary<Identifier, List<JudgeEvent>>();
readonly Dictionary<Identifier, List<JudgeEvent>> evs = new();
readonly Dictionary<Identifier, List<JudgeEvent>> activeEvs = new();
static readonly int _var_pause = IdentifierManager.Shared.Request("pause");
readonly JudgeDefinition _judgePause;
static readonly IComparer<JudgeEvent> _stcmp = new JudgeEventStartTimeComparer();
@@ -59,8 +57,9 @@ namespace Cryville.Crtr.Ruleset {
}
public Judge(ChartPlayer sys, PdtRuleset rs) {
_sys = sys;
_etor = new PdtEvaluator();
_etor.ContextJudge = this;
_etor = new PdtEvaluator {
ContextJudge = this
};
_rs = rs;
_areaFuncs = rs.areas;
_identop = new PropOp.Identifier(v => _identbuf = new Identifier(v));
@@ -88,10 +87,9 @@ namespace Cryville.Crtr.Ruleset {
var tev = (Chart.Judge)sev.Unstamped;
InsertEvent(tev, new Clip((float)sev.Time, (float)(sev.Time + sev.Duration)), tev.Id, handler);
}
void InsertEvent(Chart.Judge ev, Clip clip, Identifier id, NoteHandler handler, JudgeCallContext call = default(JudgeCallContext)) {
void InsertEvent(Chart.Judge ev, Clip clip, Identifier id, NoteHandler handler, JudgeCallContext call = default) {
if (id.Key == _var_pause) throw new InvalidOperationException("Cannot assign the special judge \"pause\" to notes");
JudgeDefinition def;
if (!_rs.judges.TryGetValue(id, out def)) {
if (!_rs.judges.TryGetValue(id, out JudgeDefinition def)) {
throw new ArgumentException(string.Format("The chart uses a judge named \"{0}\" that is undefined in the ruleset.", id));
}
_etor.Evaluate(_identop, def.input);
@@ -113,7 +111,7 @@ namespace Cryville.Crtr.Ruleset {
}
#endregion
#region Judge
internal readonly IntKeyedDictionary<int> judgeMap = new IntKeyedDictionary<int>();
internal readonly IntKeyedDictionary<int> judgeMap = new();
void InitJudges() {
foreach (var i in _rs.judges) {
var id = i.Key;
@@ -121,8 +119,8 @@ namespace Cryville.Crtr.Ruleset {
}
}
static bool _flag;
static readonly PropOp.Boolean _flagop = new PropOp.Boolean(v => _flag = v);
static readonly HitOp _hitop = new HitOp();
static readonly PropOp.Boolean _flagop = new(v => _flag = v);
static readonly HitOp _hitop = new();
class HitOp : PdtOperator {
const int MAX_SORTS = 16;
readonly float[] _buf = new float[MAX_SORTS];
@@ -171,18 +169,18 @@ namespace Cryville.Crtr.Ruleset {
static readonly int _var_ft = IdentifierManager.Shared.Request("input_time_from");
static readonly int _var_tt = IdentifierManager.Shared.Request("input_time_to");
readonly PropStores.Float
_numst1 = new PropStores.Float(),
_numst2 = new PropStores.Float(),
_numst3 = new PropStores.Float(),
_numst4 = new PropStores.Float();
_numst1 = new(),
_numst2 = new(),
_numst3 = new(),
_numst4 = new();
static readonly int _var_jt = IdentifierManager.Shared.Request("hit_time");
static readonly int _var_jdt = IdentifierManager.Shared.Request("hit_delta_time");
static readonly int _var_jv = IdentifierManager.Shared.Request("hit_vec");
readonly PropStores.Float
_jnumst = new PropStores.Float(),
_jdnumst = new PropStores.Float();
readonly PropStores.Vector4 _jvecst = new PropStores.Vector4();
_jnumst = new(),
_jdnumst = new();
readonly PropStores.Vector4 _jvecst = new();
// 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) {
@@ -370,17 +368,16 @@ namespace Cryville.Crtr.Ruleset {
}
#endregion
#region Score
readonly IntKeyedDictionary<int> scoreStringKeys = new IntKeyedDictionary<int>();
readonly IntKeyedDictionary<int> scoreStringKeysRev = new IntKeyedDictionary<int>();
readonly IntKeyedDictionary<PropSrc> scoreSrcs = new IntKeyedDictionary<PropSrc>();
readonly IntKeyedDictionary<PropOp> scoreOps = new IntKeyedDictionary<PropOp>();
readonly IntKeyedDictionary<ScoreDefinition> scoreDefs = new IntKeyedDictionary<ScoreDefinition>();
readonly IntKeyedDictionary<float> scores = new IntKeyedDictionary<float>();
readonly IntKeyedDictionary<string> scoreStringCache = new IntKeyedDictionary<string>();
readonly ArrayPool<byte> scoreStringPool = new ArrayPool<byte>();
readonly IntKeyedDictionary<string> scoreFormatCache = new IntKeyedDictionary<string>();
readonly TargetString scoreFullStr = new TargetString();
readonly StringBuffer scoreFullBuf = new StringBuffer();
readonly IntKeyedDictionary<int> scoreStringKeys = new();
readonly IntKeyedDictionary<int> scoreStringKeysRev = new();
readonly IntKeyedDictionary<PropSrc> scoreSrcs = new();
readonly IntKeyedDictionary<PropOp> scoreOps = new();
readonly IntKeyedDictionary<ScoreDefinition> scoreDefs = new();
readonly IntKeyedDictionary<float> scores = new();
readonly IntKeyedDictionary<string> scoreStringCache = new();
readonly ArrayPool<byte> scoreStringPool = new();
readonly IntKeyedDictionary<string> scoreFormatCache = new();
readonly StringBuffer scoreFullBuf = new();
void InitScores() {
foreach (var s in _rs.scores) {
var key = s.Key.Key;
@@ -404,7 +401,7 @@ namespace Cryville.Crtr.Ruleset {
public bool TryGetScoreSrc(int key, out PropSrc value) {
return scoreSrcs.TryGetValue(key, out value);
}
public TargetString GetFullFormattedScoreString() {
public int GetFullFormattedScoreString(ArrayPool<char> bufferPool, out char[] result) {
lock (_etor) {
bool flag = false;
scoreFullBuf.Clear();
@@ -414,17 +411,16 @@ namespace Cryville.Crtr.Ruleset {
scoreFullBuf.AppendFormat(scoreFormatCache[id], scores[id]);
flag = true;
}
scoreFullStr.Length = scoreFullBuf.Count;
var arr = scoreFullStr.TrustedAsArray();
scoreFullBuf.CopyTo(0, arr, 0, scoreFullBuf.Count);
return scoreFullStr;
result = bufferPool.Rent(scoreFullBuf.Count);
scoreFullBuf.CopyTo(0, result, 0, scoreFullBuf.Count);
return scoreFullBuf.Count;
}
}
class ScoreStringSrc : PropSrc {
readonly Func<float> _cb;
readonly string _format;
readonly ArrayPool<byte> _pool;
readonly StringBuffer _buf = new StringBuffer() { Culture = CultureInfo.InvariantCulture };
readonly StringBuffer _buf = new() { Culture = CultureInfo.InvariantCulture };
public ScoreStringSrc(ArrayPool<byte> pool, Func<float> cb, string format)
: base(PdtInternalType.String) {
_pool = pool;

View File

@@ -60,7 +60,7 @@ namespace Cryville.Crtr.Ruleset {
}
public override void Optimize(PdtEvaluatorBase etor, PdtExpression value) {
base.Optimize(etor, value);
if (_op.op != default(Identifier)) PdtExpression.PatchCompound(_op.name.Key, _op.op.Key, value);
if (_op.op != default) PdtExpression.PatchCompound(_op.name.Key, _op.op.Key, value);
}
internal override JudgeActionResult Execute(IJudge judge, JudgeEvent ev, float time, PdtExpression exp, bool onMiss, int depth, int index) {
judge.UpdateScore(_op, exp);

View File

@@ -23,10 +23,9 @@ namespace Cryville.Crtr.Ruleset {
public PdtRuleset Root { get; private set; }
public void LoadPdt(DirectoryInfo dir) {
using (StreamReader pdtreader = new StreamReader(Path.Combine(dir.FullName, data + ".pdt"), Encoding.UTF8)) {
var src = pdtreader.ReadToEnd();
Root = (PdtRuleset)new RulesetInterpreter(src, null).Interpret(typeof(PdtRuleset));
}
using StreamReader pdtreader = new(Path.Combine(dir.FullName, data + ".pdt"), Encoding.UTF8);
var src = pdtreader.ReadToEnd();
Root = (PdtRuleset)new RulesetInterpreter(src, null).Interpret(typeof(PdtRuleset));
}
}
@@ -99,7 +98,7 @@ namespace Cryville.Crtr.Ruleset {
#pragma warning disable IDE1006
public PairList<ScoreOperation, PdtExpression> scores {
set {
if (on_hit == null) on_hit = new PairList<JudgeAction, PdtExpression>();
on_hit ??= new PairList<JudgeAction, PdtExpression>();
int i = 0;
foreach (var s in value) {
on_hit.Insert(i++, new JudgeAction.Score(s.Key), s.Value);
@@ -108,13 +107,13 @@ namespace Cryville.Crtr.Ruleset {
}
public Identifier[] pass {
set {
if (on_hit == null) on_hit = new PairList<JudgeAction, PdtExpression>();
on_hit ??= new PairList<JudgeAction, PdtExpression>();
on_hit.Add(new JudgeAction.Pass(Enumerable.Empty<string>(), value), PdtExpression.Empty);
}
}
public Identifier[] miss {
set {
if (on_miss == null) on_miss = new PairList<JudgeAction, PdtExpression>();
on_miss ??= new PairList<JudgeAction, PdtExpression>();
on_miss.Add(new JudgeAction.Pass(Enumerable.Empty<string>(), value), PdtExpression.Empty);
}
}
@@ -134,7 +133,7 @@ namespace Cryville.Crtr.Ruleset {
op = new Identifier(m.Groups[2].Value);
}
public override string ToString() {
if (op == default(Identifier)) return name.ToString();
if (op == default) return name.ToString();
else return string.Format("{0} {1}", name, op);
}
}
@@ -144,11 +143,11 @@ namespace Cryville.Crtr.Ruleset {
public string format = "";
}
public class Constraint {
static readonly PropOp.Arbitrary _arbop = new PropOp.Arbitrary();
static readonly PropOp.Arbitrary _arbop = new();
[ElementList]
public PairList<RulesetSelectors, Constraint> Elements = new PairList<RulesetSelectors, Constraint>();
public PairList<RulesetSelectors, Constraint> Elements = new();
[PropertyList]
public PairList<ConstraintKey, PdtExpression> Properties = new PairList<ConstraintKey, PdtExpression>();
public PairList<ConstraintKey, PdtExpression> Properties = new();
public void Optimize(PdtEvaluatorBase etor) {
foreach (var e in Properties) {
etor.Optimize(e.Value);
@@ -160,14 +159,13 @@ namespace Cryville.Crtr.Ruleset {
}
public void PrePatch(ChartEvent ev) {
var etor = PdtEvaluator.Instance;
PropSrc src;
etor.ContextCascadeInsert();
etor.ContextEvent = ev;
foreach (var prop in Properties) {
var name = prop.Key.Name;
switch (prop.Key.Type) {
case ConstraintType.Property:
if (ev.PropSrcs.TryGetValue(name, out src))
if (ev.PropSrcs.TryGetValue(name, out PropSrc src))
etor.ContextSelfValue = src;
etor.Evaluate(ev.PropOps[name], prop.Value);
etor.ContextSelfValue = null;
@@ -196,13 +194,11 @@ namespace Cryville.Crtr.Ruleset {
Type = type;
Name = IdentifierManager.Shared.Request(name);
}
public override string ToString() {
switch (Type) {
case ConstraintType.Property: return (string)IdentifierManager.Shared.Retrieve(Name);
case ConstraintType.Variable: return string.Format("@var {0}", IdentifierManager.Shared.Retrieve(Name));
default: return string.Format("<{0}> {1}", Type, IdentifierManager.Shared.Retrieve(Name));
}
}
public override string ToString() => Type switch {
ConstraintType.Property => (string)IdentifierManager.Shared.Retrieve(Name),
ConstraintType.Variable => string.Format("@var {0}", IdentifierManager.Shared.Retrieve(Name)),
_ => string.Format("<{0}> {1}", Type, IdentifierManager.Shared.Retrieve(Name)),
};
}
public enum ConstraintType {
Property,

View File

@@ -8,8 +8,8 @@ namespace Cryville.Crtr.Ruleset {
internal class RulesetInterpreter : PdtInterpreter {
public RulesetInterpreter(string src, Binder binder) : base(src, binder) { }
readonly List<RulesetSelector> s = new List<RulesetSelector>();
readonly HashSet<string> a = new HashSet<string>();
readonly List<RulesetSelector> s = new();
readonly HashSet<string> a = new();
protected override object InterpretKey(Type type) {
if (PairCollection<JudgeAction, PdtExpression>.IsPairCollection(type))
return InterpretJudgeAction();

View File

@@ -46,8 +46,7 @@ namespace Cryville.Crtr.Ruleset {
return "$";
}
public override IEnumerable<ChartEvent> Match(ChartEvent ev) {
if (!(ev is EventList)) throw new ArgumentException("Event is not event list");
var tev = (EventList)ev;
if (ev is not EventList tev) throw new ArgumentException("Event is not event list");
var result = tev.Create();
tev.Events.Add(result); // TODO create at
return new ChartEvent[] { result };
@@ -60,8 +59,7 @@ namespace Cryville.Crtr.Ruleset {
return _type;
}
public override IEnumerable<ChartEvent> Match(ChartEvent ev) {
if (!(ev is EventContainer)) throw new ArgumentException("Event is not container");
var tev = (EventContainer)ev;
if (ev is not EventContainer tev) throw new ArgumentException("Event is not container");
return new ChartEvent[] { tev.GetEventsOfType(_type) };
}
}
@@ -70,8 +68,7 @@ namespace Cryville.Crtr.Ruleset {
return "#";
}
public override IEnumerable<ChartEvent> Match(ChartEvent ev) {
if (!(ev is EventList)) throw new ArgumentException("Event is not event list");
var tev = (EventList)ev;
if (ev is not EventList tev) throw new ArgumentException("Event is not event list");
return tev.Events; // TODO select at
}
}

View File

@@ -20,10 +20,9 @@ namespace Cryville.Crtr.Ruleset {
public PdtVirtualPlayerStrategy Root { get; private set; }
public void LoadPdt(DirectoryInfo dir) {
using (StreamReader pdtreader = new StreamReader(Path.Combine(dir.FullName, data + ".pdt"), Encoding.UTF8)) {
var src = pdtreader.ReadToEnd();
Root = (PdtVirtualPlayerStrategy)new RulesetInterpreter(src, null).Interpret(typeof(PdtVirtualPlayerStrategy));
}
using StreamReader pdtreader = new(Path.Combine(dir.FullName, data + ".pdt"), Encoding.UTF8);
var src = pdtreader.ReadToEnd();
Root = (PdtVirtualPlayerStrategy)new RulesetInterpreter(src, null).Interpret(typeof(PdtVirtualPlayerStrategy));
}
}
@@ -39,8 +38,8 @@ namespace Cryville.Crtr.Ruleset {
public class StrategyAction {
[ElementList]
public PairList<RulesetSelectors, StrategyAction> Elements = new PairList<RulesetSelectors, StrategyAction>();
public PairList<RulesetSelectors, StrategyAction> Elements = new();
[PropertyList]
public PairList<ConstraintKey, PdtExpression> Properties = new PairList<ConstraintKey, PdtExpression>();
public PairList<ConstraintKey, PdtExpression> Properties = new();
}
}