Implement optimization for collapse instruction.

This commit is contained in:
2022-10-30 01:39:22 +08:00
parent 0a0be73ea7
commit 13131b0f31
4 changed files with 84 additions and 5 deletions

View File

@@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Text;
using System.Xml.Linq;
namespace Cryville.Crtr {
public class Ruleset {
@@ -35,6 +36,24 @@ namespace Cryville.Crtr {
public Dictionary<string, JudgeDefinition> judges;
public Dictionary<string, ScoreDefinition> scores;
public Constraint constraints;
public void Optimize(PdtEvaluatorBase etor) {
foreach (var i in inputs.Values) {
if (i.pass != null) foreach (var e in i.pass.Values) {
etor.Optimize(e);
}
}
foreach (var j in judges.Values) {
if (j.clip != null) etor.Optimize(j.clip);
if (j.hit != null) etor.Optimize(j.hit);
if (j.scores != null) foreach (var e in j.scores.Values) {
etor.Optimize(e);
}
}
foreach (var s in scores.Values) {
if (s.value != null) etor.Optimize(s.value);
}
constraints.Optimize(etor);
}
public void PrePatch(Chart chart) {
constraints.PrePatch(chart);
}
@@ -54,6 +73,15 @@ namespace Cryville.Crtr {
public Dictionary<RulesetSelectors, Constraint> Elements = new Dictionary<RulesetSelectors, Constraint>();
[PropertyList]
public Dictionary<PropertyKey, PdtExpression> Properties = new Dictionary<PropertyKey, PdtExpression>();
public void Optimize(PdtEvaluatorBase etor) {
foreach (var e in Properties.Values) {
etor.Optimize(e);
}
foreach (var e in Elements) {
e.Key.Optimize(etor);
e.Value.Optimize(etor);
}
}
public void PrePatch(ChartEvent ev) {
var etor = ChartPlayer.etor;
PropSrc src;

View File

@@ -1,9 +1,7 @@
using Cryville.Common.Pdt;
using Cryville.Crtr.Components;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
namespace Cryville.Crtr {
public class RulesetSelectors {
@@ -11,6 +9,11 @@ namespace Cryville.Crtr {
public RulesetSelectors(IEnumerable<RulesetSelector> s) {
selectors = s.ToArray();
}
public void Optimize(PdtEvaluatorBase etor) {
for (int i = 0; i < selectors.Length; i++) {
selectors[i].Optimize(etor);
}
}
public IEnumerable<ChartEvent> Match(ChartEvent ev) {
IEnumerable<ChartEvent> result = new ChartEvent[] { ev };
foreach (var sel in selectors) {
@@ -36,6 +39,7 @@ namespace Cryville.Crtr {
}
public abstract class RulesetSelector {
public virtual void Optimize(PdtEvaluatorBase etor) { }
public abstract IEnumerable<ChartEvent> Match(ChartEvent ev);
public class CreateItem : RulesetSelector {
public override string ToString() {
@@ -82,6 +86,9 @@ namespace Cryville.Crtr {
public override string ToString() {
return string.Format("> {{{0}}}", _exp);
}
public override void Optimize(PdtEvaluatorBase etor) {
etor.Optimize(_exp);
}
public override IEnumerable<ChartEvent> Match(ChartEvent ev) {
ChartPlayer.etor.ContextEvent = ev;
ChartPlayer.etor.Evaluate(_op, _exp);