3 Commits

Author SHA1 Message Date
05664a2994 Code cleanup. 2022-11-14 16:05:44 +08:00
ba6166068b Implement score update. 2022-11-14 16:05:21 +08:00
d5d6465806 Implement compound operator patching. 2022-11-14 16:03:35 +08:00
7 changed files with 54 additions and 16 deletions

View File

@@ -34,6 +34,16 @@ namespace Cryville.Common.Pdt {
} }
} }
/// <summary> /// <summary>
/// Patches an expression with a lefthand variable and a compound operator.
/// </summary>
/// <param name="target">The name of the lefthand variable.</param>
/// <param name="op">The name of the compound operator.</param>
/// <param name="exp">The expression.</param>
public void PatchCompound(int target, int op, PdtExpression exp) {
exp.Instructions.AddFirst(new PdtInstruction.PushVariable(target));
exp.Instructions.AddLast(new PdtInstruction.Operate(op, 2));
}
/// <summary>
/// Optimizes an expression by merging its instructions. /// Optimizes an expression by merging its instructions.
/// </summary> /// </summary>
/// <param name="exp">The expression to optimize.</param> /// <param name="exp">The expression to optimize.</param>

View File

@@ -51,9 +51,8 @@ namespace Cryville.Common.Pdt {
} }
public class PushVariable : PdtInstruction { public class PushVariable : PdtInstruction {
public int Name { get; private set; } public int Name { get; private set; }
public PushVariable(string name) { public PushVariable(int name) { Name = name; }
Name = IdentifierManager.SharedInstance.Request(name); public PushVariable(string name) : this(IdentifierManager.SharedInstance.Request(name)) { }
}
internal override void Execute(PdtEvaluatorBase etor) { internal override void Execute(PdtEvaluatorBase etor) {
etor.PushVariable(Name); etor.PushVariable(Name);
} }
@@ -63,6 +62,9 @@ namespace Cryville.Common.Pdt {
} }
public class Operate : PdtInstruction { public class Operate : PdtInstruction {
public PdtOperatorSignature Signature { get; private set; } public PdtOperatorSignature Signature { get; private set; }
public Operate(int name, int paramCount) {
Signature = new PdtOperatorSignature(name, paramCount);
}
public Operate(string name, int paramCount) { public Operate(string name, int paramCount) {
Signature = new PdtOperatorSignature(name, paramCount); Signature = new PdtOperatorSignature(name, paramCount);
} }

View File

@@ -504,11 +504,11 @@ namespace Cryville.Crtr {
cbus = batcher.Batch(); cbus = batcher.Batch();
Logger.Log("main", 0, "Load/WorkerThread", "Batched {0} event batches", cbus.events.Count); Logger.Log("main", 0, "Load/WorkerThread", "Batched {0} event batches", cbus.events.Count);
LoadSkin(info.skinFile);
judge = new Judge(pruleset); judge = new Judge(pruleset);
etor.ContextJudge = judge; etor.ContextJudge = judge;
LoadSkin(info.skinFile);
cbus.AttachSystems(pskin, judge); cbus.AttachSystems(pskin, judge);
Logger.Log("main", 0, "Load/WorkerThread", "Attaching handlers"); Logger.Log("main", 0, "Load/WorkerThread", "Attaching handlers");
var ch = new ChartHandler(chart, dir); var ch = new ChartHandler(chart, dir);

View File

@@ -96,6 +96,7 @@ namespace Cryville.Crtr.Components {
float sum_x; float sum_x;
void UpdateMeshes() { void UpdateMeshes() {
// TODO optimize GC
if (meshes.Count == 0) return; if (meshes.Count == 0) return;
sum_x = 0; sum_x = 0;
int vc = m_value.Length * 4; int vc = m_value.Length * 4;

View File

@@ -31,9 +31,12 @@ namespace Cryville.Crtr {
_etor = ChartPlayer.etor; _etor = ChartPlayer.etor;
_rs = rs; _rs = rs;
foreach (var s in rs.scores) { foreach (var s in rs.scores) {
var name = s.Key.Key; var key = s.Key;
scoreDefs.Add(name, s.Value); scoreSrcs.Add(key.Key, new PropSrc.Float(() => scores[key.Key]));
scores.Add(name, s.Value.init); scoreOps.Add(key.Key, new PropOp.Float(v => scores[key.Key] = v));
scoreFmtKeys.Add(key.Key, IdentifierManager.SharedInstance.Request("_score_" + (string)key.Name));
scoreDefs.Add(key.Key, s.Value);
scores.Add(key.Key, s.Value.init);
} }
} }
public void Prepare(float st, float et, Identifier input, JudgeDefinition def, ContainerState container) { public void Prepare(float st, float et, Identifier input, JudgeDefinition def, ContainerState container) {
@@ -115,7 +118,6 @@ namespace Cryville.Crtr {
if (_flag) { if (_flag) {
if (def.scores != null) UpdateScore(def.scores); if (def.scores != null) UpdateScore(def.scores);
if (def.pass != null) Pass(def.pass); if (def.pass != null) Pass(def.pass);
Logger.Log("main", 0, "Judge", "hit {0}", i);
return true; return true;
} }
} }
@@ -143,12 +145,24 @@ namespace Cryville.Crtr {
actlist.Insert(index, ev); actlist.Insert(index, ev);
} }
} }
void UpdateScore(Dictionary<ScoreOperation, PdtExpression> scores) { void UpdateScore(Dictionary<ScoreOperation, PdtExpression> scoreops) {
foreach (var score in scores) { foreach (var scoreop in scoreops) {
// TODO var key = scoreop.Key;
_etor.ContextSelfValue = scoreSrcs[key.name.Key];
_etor.Evaluate(scoreOps[key.name.Key], scoreop.Value);
foreach (var s in _rs.scores) {
if (s.Value.value != null) {
_etor.ContextSelfValue = scoreSrcs[s.Key.Key];
_etor.Evaluate(scoreOps[s.Key.Key], s.Value.value);
}
}
} }
ScoreCache.Clear();
} }
public readonly Dictionary<int, ScoreDefinition> scoreDefs = new Dictionary<int, ScoreDefinition>(); readonly Dictionary<int, int> scoreFmtKeys = new Dictionary<int, int>();
readonly Dictionary<int, PropSrc> scoreSrcs = new Dictionary<int, PropSrc>();
readonly Dictionary<int, PropOp> scoreOps = new Dictionary<int, PropOp>();
readonly Dictionary<int, ScoreDefinition> scoreDefs = new Dictionary<int, ScoreDefinition>();
public readonly Dictionary<int, float> scores = new Dictionary<int, float>(); public readonly Dictionary<int, float> scores = new Dictionary<int, float>();
readonly Dictionary<int, string> ScoreCache = new Dictionary<int, string>(); readonly Dictionary<int, string> ScoreCache = new Dictionary<int, string>();
readonly object _lock = new object(); readonly object _lock = new object();
@@ -156,7 +170,7 @@ namespace Cryville.Crtr {
lock (_lock) { lock (_lock) {
if (ScoreCache.Count == 0) { if (ScoreCache.Count == 0) {
foreach (var s in scores) foreach (var s in scores)
ScoreCache.Add(s.Key, s.Value.ToString(scoreDefs[s.Key].format)); ScoreCache.Add(scoreFmtKeys[s.Key], s.Value.ToString(scoreDefs[s.Key].format));
} }
return ScoreCache; return ScoreCache;
} }

View File

@@ -24,6 +24,7 @@ namespace Cryville.Crtr {
var id = new Identifier(name); var id = new Identifier(name);
PropSrc prop; PropSrc prop;
string str; string str;
float num;
if (ContextEvent != null && ContextEvent.PropSrcs.TryGetValue(name, out prop)) { if (ContextEvent != null && ContextEvent.PropSrcs.TryGetValue(name, out prop)) {
prop.Get(out type, out value); prop.Get(out type, out value);
} }
@@ -31,6 +32,12 @@ namespace Cryville.Crtr {
var vec = ContextState.GetRawValue(id); var vec = ContextState.GetRawValue(id);
new VectorSrc(() => vec).Get(out type, out value); new VectorSrc(() => vec).Get(out type, out value);
} }
else if (ContextJudge != null && ContextJudge.scores.TryGetValue(name, out num)) {
type = PdtInternalType.Number;
LoadNum(num);
value = _numbuf;
RevokePotentialConstant();
}
else if (ContextJudge != null && ContextJudge.GetFormattedScoreStrings().TryGetValue(name, out str)) { else if (ContextJudge != null && ContextJudge.GetFormattedScoreStrings().TryGetValue(name, out str)) {
type = PdtInternalType.String; type = PdtInternalType.String;
value = GetBytes(str); value = GetBytes(str);

View File

@@ -45,8 +45,12 @@ namespace Cryville.Crtr {
} }
foreach (var j in judges.Values) { foreach (var j in judges.Values) {
if (j.hit != null) etor.Optimize(j.hit); if (j.hit != null) etor.Optimize(j.hit);
if (j.scores != null) foreach (var e in j.scores.Values) { if (j.scores != null) {
etor.Optimize(e); foreach (var s in j.scores) {
if (s.Key.op != default(Identifier))
etor.PatchCompound(s.Key.name.Key, s.Key.op.Key, s.Value);
etor.Optimize(s.Value);
}
} }
} }
foreach (var s in scores.Values) { foreach (var s in scores.Values) {