Implement score update.

This commit is contained in:
2022-11-14 16:04:58 +08:00
parent d5d6465806
commit ba6166068b
4 changed files with 38 additions and 12 deletions

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

@@ -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) {
@@ -143,12 +146,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);
} }
} }
public readonly Dictionary<int, ScoreDefinition> scoreDefs = new Dictionary<int, ScoreDefinition>(); }
ScoreCache.Clear();
}
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 +171,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) {