Code cleanup.

This commit is contained in:
2023-02-18 14:46:08 +08:00
parent 274a823d02
commit a1f7418d32
10 changed files with 78 additions and 66 deletions

View File

@@ -496,6 +496,7 @@ namespace Cryville.Crtr {
if (tbus != null) { tbus.Dispose(); tbus = null; } if (tbus != null) { tbus.Dispose(); tbus = null; }
if (bbus != null) { bbus.Dispose(); bbus = null; } if (bbus != null) { bbus.Dispose(); bbus = null; }
if (cbus != null) { cbus.Dispose(); cbus.DisposeAll(); cbus = null; } if (cbus != null) { cbus.Dispose(); cbus.DisposeAll(); cbus = null; }
etor = null;
Logger.Log("main", 1, "Game", "Stopped"); Logger.Log("main", 1, "Game", "Stopped");
} }
catch (Exception ex) { catch (Exception ex) {

View File

@@ -104,10 +104,11 @@ namespace Cryville.Crtr.Components {
void UpdateMeshes() { void UpdateMeshes() {
if (meshes.Count == 0) return; if (meshes.Count == 0) return;
sum_x = 0; sum_x = 0;
foreach (var t in meshes.Keys) { foreach (var t in meshes) {
verts[t].Clear(); var key = t.Key;
uvs[t].Clear(); verts[key].Clear();
tris[t].Clear(); uvs[key].Clear();
tris[key].Clear();
} }
foreach (var c in m_value) { foreach (var c in m_value) {
var f = m_frames[c]; var f = m_frames[c];
@@ -123,11 +124,12 @@ namespace Cryville.Crtr.Components {
uvs[t].Add(f.Frame.GetUV(new Vector2(0, 1))); uvs[t].Add(f.Frame.GetUV(new Vector2(0, 1)));
sum_x += w + m_spacing; sum_x += w + m_spacing;
} }
foreach (var t in meshes.Keys) { foreach (var t in meshes) {
var m = meshes[t].Mesh; var key = t.Key;
var m = meshes[key].Mesh;
m.Clear(); m.Clear();
int cc = verts[t].Count / 4; int cc = verts[key].Count / 4;
var _tris = tris[t]; var _tris = tris[key];
for (int i = 0; i < cc; i++) { for (int i = 0; i < cc; i++) {
_tris.Add(i * 4); _tris.Add(i * 4);
_tris.Add(i * 4 + 3); _tris.Add(i * 4 + 3);
@@ -136,9 +138,9 @@ namespace Cryville.Crtr.Components {
_tris.Add(i * 4 + 3); _tris.Add(i * 4 + 3);
_tris.Add(i * 4 + 2); _tris.Add(i * 4 + 2);
} }
m.SetVertices(verts[t]); m.SetVertices(verts[key]);
m.SetUVs(0, uvs[t]); m.SetUVs(0, uvs[key]);
m.SetTriangles(tris[t], 0); m.SetTriangles(tris[key], 0);
m.RecalculateNormals(); m.RecalculateNormals();
} }
sum_x -= m_spacing; sum_x -= m_spacing;
@@ -166,10 +168,10 @@ namespace Cryville.Crtr.Components {
} }
void UpdateOpacity() { void UpdateOpacity() {
if (!mesh.Initialized) return; if (!mesh.Initialized) return;
foreach (var m in meshes.Values) { foreach (var m in meshes) {
var c = m.Renderer.material.color; var c = m.Value.Renderer.material.color;
c.a = _opacity; c.a = _opacity;
m.Renderer.material.color = c; m.Value.Renderer.material.color = c;
} }
} }

View File

@@ -200,8 +200,8 @@ namespace Cryville.Crtr.Event {
#endregion #endregion
#region Anchor #region Anchor
public virtual void Anchor() { public virtual void Anchor() {
foreach (var p in PropSrcs.Values) p.Invalidate(); foreach (var p in PropSrcs) p.Value.Invalidate();
foreach (var a in DynamicAnchors.Keys) DynamicAnchorSetTime[a] = double.NaN; foreach (var a in DynamicAnchors) DynamicAnchorSetTime[a.Key] = double.NaN;
atime_head = cs.StampedContainer.Time; atime_head = cs.StampedContainer.Time;
atime_tail = atime_head + cs.StampedContainer.Duration; atime_tail = atime_head + cs.StampedContainer.Duration;
MatchDynamic(cs, 0); MatchDynamic(cs, 0);
@@ -217,7 +217,7 @@ namespace Cryville.Crtr.Event {
else forced = false; else forced = false;
PushAnchorEvent(t.Value, DynamicAnchors[t.Key], priority, forced); PushAnchorEvent(t.Value, DynamicAnchors[t.Key], priority, forced);
} }
foreach (var anchors in Anchors.Values) foreach (var anchor in anchors) anchor.Transform.gameObject.SetActive(false); foreach (var anchors in Anchors) foreach (var anchor in anchors.Value) anchor.Transform.gameObject.SetActive(false);
} }
static readonly SimpleObjectPool<StampedEvent.Anchor> anchorEvPool static readonly SimpleObjectPool<StampedEvent.Anchor> anchorEvPool
= new SimpleObjectPool<StampedEvent.Anchor>(1024); = new SimpleObjectPool<StampedEvent.Anchor>(1024);

View File

@@ -434,14 +434,14 @@ namespace Cryville.Crtr.Event {
public void BroadcastPreInit() { public void BroadcastPreInit() {
Handler.PreInit(); Handler.PreInit();
foreach (var c in Children.Values) { foreach (var c in Children) {
c.BroadcastPreInit(); c.Value.BroadcastPreInit();
} }
} }
public void BroadcastPostInit() { public void BroadcastPostInit() {
Handler.PostInit(); Handler.PostInit();
foreach (var c in Children.Values) { foreach (var c in Children) {
c.BroadcastPostInit(); c.Value.BroadcastPostInit();
} }
} }
@@ -461,8 +461,8 @@ namespace Cryville.Crtr.Event {
public void Anchor() { public void Anchor() {
Handler.Anchor(); Handler.Anchor();
foreach (var ls in Children.Values) { foreach (var ls in Children) {
if (ls.Handler.Alive) ls.Anchor(); if (ls.Value.Handler.Alive) ls.Value.Anchor();
} }
} }
#endregion #endregion

View File

@@ -63,8 +63,8 @@ namespace Cryville.Crtr.Event {
s = RootState; s = RootState;
} }
AddState(s); AddState(s);
foreach (var c in s.Children.Values) foreach (var c in s.Children)
Expand(c); Expand(c.Value);
} }
public void AddState(ContainerState s) { public void AddState(ContainerState s) {
@@ -73,13 +73,13 @@ namespace Cryville.Crtr.Event {
} }
void AttachBus() { void AttachBus() {
foreach (var s in states.Values) foreach (var s in states)
s.Bus = this; s.Value.Bus = this;
} }
public void AttachSystems(PdtSkin skin, Judge judge) { public void AttachSystems(PdtSkin skin, Judge judge) {
foreach (var s in states.Values) foreach (var s in states)
s.AttachSystems(skin, judge); s.Value.AttachSystems(skin, judge);
} }
List<StampedEvent.Temporary> tempEvents = new List<StampedEvent.Temporary>(); List<StampedEvent.Temporary> tempEvents = new List<StampedEvent.Temporary>();

View File

@@ -164,8 +164,8 @@ namespace Cryville.Crtr {
protected void Dispose(bool disposing) { protected void Dispose(bool disposing) {
if (disposing) { if (disposing) {
Deactivate(); Deactivate();
foreach (var proxy in _tproxies.Values) { foreach (var proxy in _tproxies) {
proxy.Source.Value.Handler.OnInput -= OnInput; proxy.Value.Source.Value.Handler.OnInput -= OnInput;
} }
} }
} }
@@ -236,13 +236,14 @@ namespace Cryville.Crtr {
} }
} }
public void SyncTime(double time) { public void SyncTime(double time) {
foreach (var s in _sproxies.Keys) { foreach (var s in _sproxies) {
var h = s.Handler; var h = s.Key.Handler;
_timeOrigins[h] = h.GetCurrentTimestamp() - time; _timeOrigins[h] = h.GetCurrentTimestamp() - time;
} }
} }
public void ForceTick() { public void ForceTick() {
foreach (var src in _sproxies.Keys) { foreach (var s in _sproxies) {
var src = s.Key;
if (_activeCounts[src] == 0) { if (_activeCounts[src] == 0) {
OnInput(new InputIdentifier { Source = src, Id = 0 }, new InputVector(_lockTime != null ? _lockTime.Value : src.Handler.GetCurrentTimestamp())); OnInput(new InputIdentifier { Source = src, Id = 0 }, new InputVector(_lockTime != null ? _lockTime.Value : src.Handler.GetCurrentTimestamp()));
} }
@@ -250,7 +251,8 @@ namespace Cryville.Crtr {
} }
public double GetTimestampAverage() { public double GetTimestampAverage() {
double result = 0; double result = 0;
foreach (var src in _sproxies.Keys) { foreach (var s in _sproxies) {
var src = s.Key;
result += src.Handler.GetCurrentTimestamp() - _timeOrigins[src.Handler]; result += src.Handler.GetCurrentTimestamp() - _timeOrigins[src.Handler];
} }
return result / _sproxies.Count; return result / _sproxies.Count;

View File

@@ -42,11 +42,12 @@ namespace Cryville.Crtr {
_numsrc3 = new PropSrc.Float(() => _numbuf3); _numsrc3 = new PropSrc.Float(() => _numbuf3);
_numsrc4 = new PropSrc.Float(() => _numbuf4); _numsrc4 = new PropSrc.Float(() => _numbuf4);
_rs.judges.TryGetValue(new Identifier(_var_pause), out _judgePause); _rs.judges.TryGetValue(new Identifier(_var_pause), out _judgePause);
foreach (var i in rs.inputs.Keys) { foreach (var i in rs.inputs) {
var id = i.Key;
var l = new List<JudgeEvent>(); var l = new List<JudgeEvent>();
evs.Add(i, l); evs.Add(id, l);
activeEvs.Add(i, new List<JudgeEvent>()); activeEvs.Add(id, new List<JudgeEvent>());
if (_judgePause != null && i.Key == _var_pause) { if (_judgePause != null && id.Key == _var_pause) {
l.Add(new JudgeEvent { l.Add(new JudgeEvent {
StartTime = double.NegativeInfinity, EndTime = double.PositiveInfinity, StartTime = double.NegativeInfinity, EndTime = double.PositiveInfinity,
StartClip = double.NegativeInfinity, EndClip = double.PositiveInfinity, StartClip = double.NegativeInfinity, EndClip = double.PositiveInfinity,
@@ -82,8 +83,9 @@ namespace Cryville.Crtr {
#region Judge #region Judge
internal readonly Dictionary<int, int> judgeMap = new Dictionary<int, int>(); internal readonly Dictionary<int, int> judgeMap = new Dictionary<int, int>();
void InitJudges() { void InitJudges() {
foreach (var i in _rs.judges.Keys) { foreach (var i in _rs.judges) {
judgeMap.Add(i.Key, IdentifierManager.SharedInstance.Request("judge_" + i.Name)); var id = i.Key;
judgeMap.Add(id.Key, IdentifierManager.SharedInstance.Request("judge_" + id.Name));
} }
} }
static bool _flag; static bool _flag;
@@ -247,9 +249,10 @@ namespace Cryville.Crtr {
public TargetString GetFullFormattedScoreString() { public TargetString GetFullFormattedScoreString() {
bool flag = false; bool flag = false;
scoreFullBuf.Clear(); scoreFullBuf.Clear();
foreach (var s in scores.Keys) { foreach (var s in scores) {
scoreFullBuf.AppendFormat(flag ? "\n{0}: " : "{0}: ", (string)IdentifierManager.SharedInstance.Retrieve(s)); var id = s.Key;
scoreFullBuf.AppendFormat(scoreFormatCache[s], scores[s]); scoreFullBuf.AppendFormat(flag ? "\n{0}: " : "{0}: ", (string)IdentifierManager.SharedInstance.Retrieve(id));
scoreFullBuf.AppendFormat(scoreFormatCache[id], scores[id]);
flag = true; flag = true;
} }
scoreFullStr.Length = scoreFullBuf.Count; scoreFullStr.Length = scoreFullBuf.Count;

View File

@@ -58,7 +58,7 @@ namespace Cryville.Crtr {
public override void Init() { public override void Init() {
base.Init(); base.Init();
sgos = gogroup.GetComponentsInChildren<SectionalGameObject>(); sgos = gogroup.GetComponentsInChildren<SectionalGameObject>();
foreach (var judge in judges.Values) judge.InitPropSrcs(); foreach (var judge in judges) judge.Value.InitPropSrcs();
} }
public override void StartPhysicalUpdate(ContainerState s) { public override void StartPhysicalUpdate(ContainerState s) {

View File

@@ -34,23 +34,26 @@ namespace Cryville.Crtr {
public Dictionary<Identifier, ScoreDefinition> scores; public Dictionary<Identifier, ScoreDefinition> scores;
public Constraint constraints; public Constraint constraints;
public void Optimize(PdtEvaluatorBase etor) { public void Optimize(PdtEvaluatorBase etor) {
foreach (var i in inputs.Values) { foreach (var i in inputs) {
if (i.pass != null) foreach (var e in i.pass.Values) { var input = i.Value;
etor.Optimize(e); if (input.pass != null) foreach (var e in input.pass) {
etor.Optimize(e.Value);
} }
} }
foreach (var j in judges.Values) { foreach (var j in judges) {
if (j.hit != null) etor.Optimize(j.hit); var judge = j.Value;
if (j.scores != null) { if (judge.hit != null) etor.Optimize(judge.hit);
foreach (var s in j.scores) { if (judge.scores != null) {
foreach (var s in judge.scores) {
if (s.Key.op != default(Identifier)) if (s.Key.op != default(Identifier))
etor.PatchCompound(s.Key.name.Key, s.Key.op.Key, s.Value); etor.PatchCompound(s.Key.name.Key, s.Key.op.Key, s.Value);
etor.Optimize(s.Value); etor.Optimize(s.Value);
} }
} }
} }
foreach (var s in scores.Values) { foreach (var s in scores) {
if (s.value != null) etor.Optimize(s.value); var score = s.Value;
if (score.value != null) etor.Optimize(score.value);
} }
constraints.Optimize(etor); constraints.Optimize(etor);
} }
@@ -65,8 +68,8 @@ namespace Cryville.Crtr {
[PropertyList] [PropertyList]
public Dictionary<PropertyKey, PdtExpression> Properties = new Dictionary<PropertyKey, PdtExpression>(); public Dictionary<PropertyKey, PdtExpression> Properties = new Dictionary<PropertyKey, PdtExpression>();
public void Optimize(PdtEvaluatorBase etor) { public void Optimize(PdtEvaluatorBase etor) {
foreach (var e in Properties.Values) { foreach (var e in Properties) {
etor.Optimize(e); etor.Optimize(e.Value);
} }
foreach (var e in Elements) { foreach (var e in Elements) {
e.Key.Optimize(etor); e.Key.Optimize(etor);

View File

@@ -53,10 +53,11 @@ namespace Cryville.Crtr {
public SkinElement elements; public SkinElement elements;
public void Optimize(PdtEvaluator etor) { public void Optimize(PdtEvaluator etor) {
foreach (var animation in animations.Values) { foreach (var a in animations) {
animation.Optimize(etor); a.Value.Optimize(etor);
} }
foreach (var effect in effects.Values) { foreach (var e in effects) {
var effect = e.Value;
etor.ContextCascadeInsert(); etor.ContextCascadeInsert();
if (effect.args != null) foreach (var i in effect.args) { if (effect.args != null) foreach (var i in effect.args) {
etor.ContextCascadeUpdate(i.Key, PropSrc.Error); etor.ContextCascadeUpdate(i.Key, PropSrc.Error);
@@ -85,9 +86,9 @@ namespace Cryville.Crtr {
public void Optimize(PdtEvaluatorBase etor) { public void Optimize(PdtEvaluatorBase etor) {
IsDynamic = true; IsDynamic = true;
foreach (var e in properties.Values) { foreach (var e in properties) {
etor.Optimize(e); etor.Optimize(e.Value);
if (!e.IsConstant) if (!e.Value.IsConstant)
IsDynamic = true; IsDynamic = true;
} }
foreach (var e in elements) { foreach (var e in elements) {
@@ -115,11 +116,11 @@ namespace Cryville.Crtr {
= new Dictionary<SkinPropertyKey, PdtExpression>(); = new Dictionary<SkinPropertyKey, PdtExpression>();
public void Optimize(PdtEvaluator etor) { public void Optimize(PdtEvaluator etor) {
foreach (var p in properties.Values) { foreach (var p in properties) {
etor.Optimize(p); etor.Optimize(p.Value);
} }
foreach (var e in spans.Values) { foreach (var e in spans) {
e.Optimize(etor); e.Value.Optimize(etor);
} }
} }
} }