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

@@ -8,7 +8,7 @@ namespace Cryville.Crtr.Event {
protected override TransformHandler Parent { get { return null; } }
readonly Chart chart;
readonly List<LibavFileAudioSource> sounds = new List<LibavFileAudioSource>();
readonly List<LibavFileAudioSource> sounds = new();
public ChartHandler(Chart _chart) {
chart = _chart;
@@ -25,8 +25,7 @@ namespace Cryville.Crtr.Event {
if (s.CloneType == 16) {
if (ev == null) { }
else if (ev.Unstamped == null) { }
else if (ev.Unstamped is Chart.Sound) {
Chart.Sound tev = (Chart.Sound)ev.Unstamped;
else if (ev.Unstamped is Chart.Sound tev) {
var dir = new DirectoryInfo(Path.Combine(Game.GameDataPath, "songs", StringUtils.EscapeFileName(tev.id)));
var files = dir.GetFiles();
var source = new LibavFileAudioSource(files[0].FullName);

View File

@@ -41,7 +41,7 @@ namespace Cryville.Crtr.Event {
protected Transform RootTransform;
readonly List<SkinComponent> _comps = new List<SkinComponent>();
readonly List<SkinComponent> _comps = new();
protected IEnumerable<SkinComponent> Components { get { return _comps; } }
public Vector3 Position { get; protected set; }
@@ -68,7 +68,7 @@ namespace Cryville.Crtr.Event {
static readonly int _var_current_time = IdentifierManager.Shared.Request("current_time");
static readonly int _var_invisible_bounds = IdentifierManager.Shared.Request("invisible_bounds");
public readonly IntKeyedDictionary<PropSrc> PropSrcs = new IntKeyedDictionary<PropSrc>();
public readonly IntKeyedDictionary<PropSrc> PropSrcs = new();
SkinContainer skinContainer;
protected Judge judge;
public void AttachSystems(PdtSkin skin, Judge judge) {
@@ -76,9 +76,9 @@ namespace Cryville.Crtr.Event {
this.judge = judge;
}
public readonly IntKeyedDictionary<List<Anchor>> Anchors = new IntKeyedDictionary<List<Anchor>>();
public readonly IntKeyedDictionary<Anchor> DynamicAnchors = new IntKeyedDictionary<Anchor>();
public readonly IntKeyedDictionary<double> DynamicAnchorSetTime = new IntKeyedDictionary<double>();
public readonly IntKeyedDictionary<List<Anchor>> Anchors = new();
public readonly IntKeyedDictionary<Anchor> DynamicAnchors = new();
public readonly IntKeyedDictionary<double> DynamicAnchorSetTime = new();
Anchor a_cur;
Anchor a_head;
Anchor a_tail;
@@ -98,8 +98,7 @@ namespace Cryville.Crtr.Event {
DynamicAnchors.Add(name, result);
DynamicAnchorSetTime.Add(name, double.NaN);
}
List<Anchor> list;
if (!Anchors.TryGetValue(name, out list))
if (!Anchors.TryGetValue(name, out List<Anchor> list))
Anchors.Add(name, list = new List<Anchor>());
list.Add(result);
return result;
@@ -158,8 +157,7 @@ namespace Cryville.Crtr.Event {
}
#endregion
public virtual void Update(ContainerState s, StampedEvent ev) {
if (ev is StampedEvent.Anchor) {
var tev = (StampedEvent.Anchor)ev;
if (ev is StampedEvent.Anchor tev) {
if (tev.Target == a_head) {
if (s.CloneType == 2) SetGraphicalActive(true, s);
else SetPreGraphicalActive(true, s);
@@ -234,7 +232,7 @@ namespace Cryville.Crtr.Event {
}
}
static readonly SimpleObjectPool<StampedEvent.Anchor> anchorEvPool
= new SimpleObjectPool<StampedEvent.Anchor>(1024);
= new(1024);
void PushAnchorEvent(ContainerState state, double time, Anchor anchor, int priority = 0, bool forced = false) {
var tev = anchorEvPool.Rent();
tev.Time = time;
@@ -245,8 +243,8 @@ namespace Cryville.Crtr.Event {
state.Bus.PushTempEvent(tev);
}
public virtual void Discard(ContainerState s, StampedEvent ev) {
if (ev is StampedEvent.Anchor) {
ReturnAnchorEvent((StampedEvent.Anchor)ev);
if (ev is StampedEvent.Anchor anchor) {
ReturnAnchorEvent(anchor);
}
}
void ReturnAnchorEvent(StampedEvent.Anchor ev) {
@@ -264,8 +262,7 @@ namespace Cryville.Crtr.Event {
Anchor _openedAnchor;
public int OpenedAnchorName { get { return _openedAnchor == null ? 0 : _openedAnchor.Name; } }
public bool TryGetAnchorsByName(int name, out IReadOnlyCollection<Anchor> result) {
List<Anchor> anchors;
var ret = Anchors.TryGetValue(name, out anchors);
var ret = Anchors.TryGetValue(name, out List<Anchor> anchors);
result = anchors;
return ret;
}

View File

@@ -19,11 +19,11 @@ namespace Cryville.Crtr.Event {
public ushort Depth;
public Dictionary<EventContainer, ContainerState> Children
= new Dictionary<EventContainer, ContainerState>();
= new();
HashSet<EventContainer> ActiveChildren
= new HashSet<EventContainer>();
= new();
public Dictionary<Type, List<ContainerState>> TypedChildren
= new Dictionary<Type, List<ContainerState>>();
= new();
public ContainerState GetChild(int index, Type handlerType) {
var list = TypedChildren[handlerType];
@@ -110,8 +110,7 @@ namespace Cryville.Crtr.Event {
void AddChild(EventContainer c, ContainerState parent) {
parent.Children.Add(c, this);
Type t = c.GetType();
List<ContainerState> tc;
if (!parent.TypedChildren.TryGetValue(t, out tc))
if (!parent.TypedChildren.TryGetValue(t, out List<ContainerState> tc))
parent.TypedChildren.Add(t, tc = new List<ContainerState>());
tc.Add(this);
}
@@ -159,15 +158,13 @@ namespace Cryville.Crtr.Event {
if (dest.m_active) dest.Bus.NotifyActiveChanged(dest);
foreach (var mv in Values) {
RealtimeMotionValue dv;
if (dest.Values.TryGetValue(mv.Key, out dv)) mv.Value.CopyTo(dv, false);
if (dest.Values.TryGetValue(mv.Key, out RealtimeMotionValue dv)) mv.Value.CopyTo(dv, false);
else dest.Values.Add(mv.Key, mv.Value.Clone());
}
foreach (var cv in dest.CachedValues) cv.Value.Valid = false;
foreach (var cv in CachedValues) {
MotionCache dv;
if (!dest.CachedValues.TryGetValue(cv.Key, out dv)) {
if (!dest.CachedValues.TryGetValue(cv.Key, out MotionCache dv)) {
dest.CachedValues.Add(cv.Key, dv = dest._mcpa.Rent(cv.Key));
}
cv.Value.CopyTo(dv);
@@ -229,13 +226,12 @@ namespace Cryville.Crtr.Event {
#region Motion
readonly CategorizedPoolAccessor<int, RealtimeMotionValue> _rmvpa;
readonly CategorizedPoolAccessor<int, MotionCache> _mcpa;
Dictionary<StampedEvent, RealtimeMotionValue> PlayingMotions = new Dictionary<StampedEvent, RealtimeMotionValue>(4);
Dictionary<StampedEvent, RealtimeMotionValue> PlayingMotions = new(4);
IntKeyedDictionary<RealtimeMotionValue> Values;
IntKeyedDictionary<MotionCache> CachedValues;
void InvalidateMotion(int name) {
MotionCache cache;
if (!CachedValues.TryGetValue(name, out cache))
if (!CachedValues.TryGetValue(name, out MotionCache cache))
CachedValues.Add(name, cache = _mcpa.Rent(name));
cache.Valid = false;
foreach (var c in ActiveChildren)
@@ -243,8 +239,7 @@ namespace Cryville.Crtr.Event {
}
public Vector GetComputedValue(int key) {
MotionCache tr;
if (!CachedValues.TryGetValue(key, out tr))
if (!CachedValues.TryGetValue(key, out MotionCache tr))
CachedValues.Add(key, tr = _mcpa.Rent(key));
Vector r = tr.Value;
if (tr.Valid) return r;
@@ -322,8 +317,8 @@ namespace Cryville.Crtr.Event {
public void Discard(StampedEvent ev) {
Handler.Discard(this, ev);
if (ev is StampedEvent.RelativeMotion) {
ReturnRelativeMotionEvent((StampedEvent.RelativeMotion)ev);
if (ev is StampedEvent.RelativeMotion motion) {
ReturnRelativeMotionEvent(motion);
}
else if (ev.Origin is StampedEvent.RelativeMotion) {
ReturnEndRelativeMotionEvent((StampedEvent.Temporary)ev);
@@ -345,8 +340,7 @@ namespace Cryville.Crtr.Event {
_rmvpa.Return(mv);
}
}
else if (ev is StampedEvent.RelativeMotion) {
var tev = (StampedEvent.RelativeMotion)ev;
else if (ev is StampedEvent.RelativeMotion tev) {
var mv = _rmvpa.Rent(tev.Name);
mv.CloneTypeFlag = CloneType;
Values[tev.Name].CopyTo(mv, true);
@@ -369,13 +363,13 @@ namespace Cryville.Crtr.Event {
}
else if (ev.Origin != null) {
var oev = ev.Origin;
if (oev is StampedEvent.RelativeMotion) {
if (oev is StampedEvent.RelativeMotion motion) {
Update(ev);
var mv = PlayingMotions[oev];
if (mv.CloneTypeFlag == CloneType) _rmvpa.Return(mv);
PlayingMotions.Remove(oev);
ReturnEndRelativeMotionEvent((StampedEvent.Temporary)ev);
ReturnRelativeMotionEvent((StampedEvent.RelativeMotion)oev);
ReturnRelativeMotionEvent(motion);
}
else {
var nev = oev.Unstamped;
@@ -385,8 +379,7 @@ namespace Cryville.Crtr.Event {
if (mv.CloneTypeFlag == CloneType) _rmvpa.Return(mv);
PlayingMotions.Remove(oev);
}
else if (nev is EventContainer) {
var cev = (EventContainer)nev;
else if (nev is EventContainer cev) {
var ccs = Children[cev];
UpdateMotions();
ccs.LogicalActive = false;
@@ -455,8 +448,8 @@ namespace Cryville.Crtr.Event {
}
}
}
static readonly PropStores.Float _ttimest = new PropStores.Float();
static readonly PropStores.Vector4 _transst = new PropStores.Vector4();
static readonly PropStores.Float _ttimest = new();
static readonly PropStores.Vector4 _transst = new();
Vector4 GetTransition(float time, PdtExpression transition) {
if (time >= 1) return Vector4.one;
if (transition == null) return new Vector4(time, time, time, time);
@@ -495,9 +488,9 @@ namespace Cryville.Crtr.Event {
}
static readonly SimpleObjectPool<StampedEvent.RelativeMotion> relmEvPool
= new SimpleObjectPool<StampedEvent.RelativeMotion>(1024);
= new(1024);
static readonly SimpleObjectPool<StampedEvent.Temporary> erelmEvPool
= new SimpleObjectPool<StampedEvent.Temporary>(1024);
= new(1024);
public void PreAnchor() {
PushRelativeMotions(Handler.ns.Bus);
Handler.PreAnchor();

View File

@@ -9,7 +9,7 @@ namespace Cryville.Crtr.Event {
private set;
}
readonly List<StampedEvent> queue = new List<StampedEvent>();
readonly List<StampedEvent> queue = new();
public int Count {
get { return queue.Count; }
}

View File

@@ -12,16 +12,16 @@ namespace Cryville.Crtr.Event {
readonly Chart chart;
ContainerState rootState;
readonly Dictionary<ChartEvent, ContainerState> containerMap
= new Dictionary<ChartEvent, ContainerState>();
= new();
readonly Dictionary<EventContainer, ContainerState> stateMap
= new Dictionary<EventContainer, ContainerState>();
= new();
readonly Dictionary<ChartEvent, StampedEvent> map
= new Dictionary<ChartEvent, StampedEvent>();
= new();
readonly Dictionary<EventContainer, List<StampedEvent>> coeventMap
= new Dictionary<EventContainer, List<StampedEvent>>();
readonly HashSet<ChartEvent> coevents = new HashSet<ChartEvent>();
readonly List<StampedEvent> stampedEvents = new List<StampedEvent>();
readonly List<EventBatch> batches = new List<EventBatch>();
= new();
readonly HashSet<ChartEvent> coevents = new();
readonly List<StampedEvent> stampedEvents = new();
readonly List<EventBatch> batches = new();
double beat;
float tempo;
@@ -58,8 +58,8 @@ namespace Cryville.Crtr.Event {
}
Events.Add(ev);
containerMap.Add(ev, cs);
if (ev is EventContainer)
AddEventContainer((EventContainer)ev, cs);
if (ev is EventContainer container)
AddEventContainer(container, cs);
}
}
@@ -104,17 +104,16 @@ namespace Cryville.Crtr.Event {
var pev = map[oev];
pev.ReleaseEvent = sev;
sev.Origin = pev;
if (oev is EventContainer) {
if (oev is EventContainer container) {
stampedEvents.Add(new StampedEvent.ClipAhead {
Container = con,
Origin = pev,
Time = etime + ((EventContainer)oev).Clip.Ahead,
Time = etime + container.Clip.Ahead,
});
}
}
if (con != null && coevents.Contains(ev)) {
List<StampedEvent> cevs;
if (!coeventMap.TryGetValue(con, out cevs)) {
if (!coeventMap.TryGetValue(con, out List<StampedEvent> cevs)) {
coeventMap.Add(con, cevs = new List<StampedEvent>());
}
cevs.Add(sev);
@@ -168,9 +167,8 @@ namespace Cryville.Crtr.Event {
}
void BatchCoevents(StampedEvent ev, List<StampedEvent> ocevs = null) {
if (!(ev.Unstamped is EventContainer)) return;
List<StampedEvent> cevs;
if (coeventMap.TryGetValue((EventContainer)ev.Unstamped, out cevs)) {
if (ev.Unstamped is not EventContainer container) return;
if (coeventMap.TryGetValue(container, out List<StampedEvent> cevs)) {
var rootFlag = ocevs == null;
if (rootFlag) ev.Coevents = ocevs = new List<StampedEvent>();
foreach (var cev in cevs) {

View File

@@ -12,11 +12,11 @@ namespace Cryville.Crtr.Event {
}
Dictionary<EventContainer, ContainerState> states
= new Dictionary<EventContainer, ContainerState>();
= new();
HashSet<ContainerState> activeStates
= new HashSet<ContainerState>();
= new();
HashSet<ContainerState> invalidatedStates
= new HashSet<ContainerState>();
= new();
public int ActiveStateCount { get { return activeStates.Count; } }
public EventBus(ContainerState root, List<EventBatch> b) : base(b) {
@@ -84,14 +84,14 @@ namespace Cryville.Crtr.Event {
s.Value.AttachSystems(skin, judge);
}
List<StampedEvent.Temporary> tempEvents = new List<StampedEvent.Temporary>();
List<StampedEvent.Temporary> tempEvents = new();
public void PushTempEvent(StampedEvent.Temporary ev) {
var index = tempEvents.BinarySearch(ev);
if (index < 0) index = ~index;
tempEvents.Insert(index, ev);
}
readonly StampedEvent.Temporary _dummyEvent = new StampedEvent.Temporary();
readonly StampedEvent.Temporary _dummyEvent = new();
public void StripTempEvents() {
_dummyEvent.Time = Time;
var index = tempEvents.BinarySearch(_dummyEvent);

View File

@@ -39,7 +39,7 @@ namespace Cryville.Crtr.Event {
}
class Vector3Operator : IVectorOperator<Vector3> {
public static Vector3Operator Instance = new Vector3Operator();
public static Vector3Operator Instance = new();
public Vector3 Add(Vector3 lhs, Vector3 rhs) {
return lhs + rhs;

View File

@@ -21,8 +21,9 @@ namespace Cryville.Crtr.Event {
_reg = ChartPlayer.motionRegistry[name];
}
protected override MotionCache Construct() {
var result = new MotionCache();
result.Value = (Vector)Activator.CreateInstance(_reg.Type);
var result = new MotionCache {
Value = (Vector)Activator.CreateInstance(_reg.Type)
};
return result;
}
protected override void Reset(MotionCache obj) {

View File

@@ -17,15 +17,15 @@ namespace Cryville.Crtr.Event {
public override string TypeName { get { return "note"; } }
SectionalGameObject[] sgos;
readonly Dictionary<Chart.Judge, JudgeState> judges = new Dictionary<Chart.Judge, JudgeState>();
readonly Dictionary<Chart.Judge, JudgeState> judges = new();
class JudgeState {
static readonly int _var_judge_result = IdentifierManager.Shared.Request("judge_result");
static readonly int _var_judge_time_absolute = IdentifierManager.Shared.Request("judge_time_absolute");
static readonly int _var_judge_time_relative = IdentifierManager.Shared.Request("judge_time_relative");
public Anchor StaticAnchor { get; private set; }
readonly PropStores.Float _jtabsst = new PropStores.Float();
readonly PropStores.Float _jtrelst = new PropStores.Float();
readonly PropStores.Identifier _resultst = new PropStores.Identifier();
readonly PropStores.Float _jtabsst = new();
readonly PropStores.Float _jtrelst = new();
readonly PropStores.Identifier _resultst = new();
public JudgeState(NoteHandler handler, int name) {
StaticAnchor = handler.RegisterAnchor(handler.judge.judgeMap[name], false, 3);
}
@@ -147,8 +147,7 @@ namespace Cryville.Crtr.Event {
}
internal void ReportJudge(JudgeEvent ev, float time, Identifier result) {
JudgeState state;
if (!judges.TryGetValue(ev.BaseEvent, out state)) return;
if (!judges.TryGetValue(ev.BaseEvent, out JudgeState state)) return;
state.MarkJudged(time, (float)(ev.StartTime - time), result.Key);
}
}

View File

@@ -48,21 +48,19 @@ namespace Cryville.Crtr.Event {
}
public MotionNode GetRelativeNode(short id) {
MotionNode result;
RelativeNodes.TryGetValue(id, out result);
RelativeNodes.TryGetValue(id, out MotionNode result);
return result;
}
public void SetRelativeNode(MotionNode node) {
MotionNode cnode;
if (!RelativeNodes.TryGetValue(node.Id, out cnode)) {
if (!RelativeNodes.TryGetValue(node.Id, out MotionNode cnode)) {
cnode = MotionNodePool.Shared.Rent(_type);
cnode.Id = node.Id;
RelativeNodes.Add(node.Id, cnode);
}
if (node.Time != null) node.Time.CopyTo(cnode.Time);
if (node.EndTime != null) node.EndTime.CopyTo(cnode.EndTime);
if (node.Value != null) node.Value.CopyTo(cnode.Value);
node.Time?.CopyTo(cnode.Time);
node.EndTime?.CopyTo(cnode.EndTime);
node.Value?.CopyTo(cnode.Value);
}
/// <summary>

View File

@@ -7,7 +7,7 @@ namespace Cryville.Crtr.Event {
protected abstract TransformHandler Parent { get; }
public override void Init() {
base.Init();
sgos = Components.Where(c => c is SectionalGameObject).Cast<SectionalGameObject>().ToArray();
sgos = Components.OfType<SectionalGameObject>().ToArray();
}
SectionalGameObject[] sgos;