Optimize context cascade in PDT evaluator.
This commit is contained in:
@@ -32,17 +32,15 @@ namespace Cryville.Crtr {
|
|||||||
RevokePotentialConstant();
|
RevokePotentialConstant();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
PropSrc.Arbitrary result;
|
PropSrc.Arbitrary result = ContextCascadeLookup(name);
|
||||||
for (int i = ContextCascade.Count - 1; i >= 0; i--) {
|
if (result != null) {
|
||||||
Dictionary<int, PropSrc.Arbitrary> cas = ContextCascade[i];
|
result.Get(out type, out value);
|
||||||
if (cas.TryGetValue(name, out result)) {
|
}
|
||||||
result.Get(out type, out value);
|
else {
|
||||||
return;
|
type = PdtInternalType.Undefined;
|
||||||
}
|
LoadNum(name);
|
||||||
|
value = _numbuf;
|
||||||
}
|
}
|
||||||
type = PdtInternalType.Undefined;
|
|
||||||
LoadNum(name);
|
|
||||||
value = _numbuf;
|
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -97,18 +95,31 @@ namespace Cryville.Crtr {
|
|||||||
public Judge ContextJudge { private get; set; }
|
public Judge ContextJudge { private get; set; }
|
||||||
public PropSrc ContextSelfValue { private get; set; }
|
public PropSrc ContextSelfValue { private get; set; }
|
||||||
|
|
||||||
readonly List<Dictionary<int, PropSrc.Arbitrary>> ContextCascade = new List<Dictionary<int, PropSrc.Arbitrary>>();
|
readonly Dictionary<int, PropSrc.Arbitrary>[] ContextCascade = new Dictionary<int, PropSrc.Arbitrary>[256];
|
||||||
|
int _cascadeHeight;
|
||||||
public void ContextCascadeInsert() {
|
public void ContextCascadeInsert() {
|
||||||
ContextCascade.Add(new Dictionary<int, PropSrc.Arbitrary>());
|
ContextCascade[_cascadeHeight++].Clear();
|
||||||
}
|
}
|
||||||
public void ContextCascadeUpdate(int key, PropSrc.Arbitrary value) {
|
public void ContextCascadeUpdate(int key, PropSrc.Arbitrary value) {
|
||||||
ContextCascade[ContextCascade.Count - 1][key] = value;
|
ContextCascade[_cascadeHeight - 1][key] = value;
|
||||||
|
}
|
||||||
|
public PropSrc.Arbitrary ContextCascadeLookup(int name) {
|
||||||
|
PropSrc.Arbitrary result;
|
||||||
|
for (int i = _cascadeHeight - 1; i >= 0; i--) {
|
||||||
|
Dictionary<int, PropSrc.Arbitrary> cas = ContextCascade[i];
|
||||||
|
if (cas.TryGetValue(name, out result)) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
public void ContextCascadeDiscard() {
|
public void ContextCascadeDiscard() {
|
||||||
ContextCascade.RemoveAt(ContextCascade.Count - 1);
|
--_cascadeHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PdtEvaluator() {
|
public PdtEvaluator() {
|
||||||
|
for (int i = 0; i < ContextCascade.Length; i++) ContextCascade[i] = new Dictionary<int, PropSrc.Arbitrary>();
|
||||||
|
|
||||||
_ctxops.Add(IdentifierManager.SharedInstance.Request("screen_edge"), new func_screen_edge(() => ContextTransform));
|
_ctxops.Add(IdentifierManager.SharedInstance.Request("screen_edge"), new func_screen_edge(() => ContextTransform));
|
||||||
_ctxops.Add(IdentifierManager.SharedInstance.Request("int"), new func_int(() => ContextSelfValue));
|
_ctxops.Add(IdentifierManager.SharedInstance.Request("int"), new func_int(() => ContextSelfValue));
|
||||||
_ctxops.Add(IdentifierManager.SharedInstance.Request("clamp"), new func_clamp(() => ContextSelfValue));
|
_ctxops.Add(IdentifierManager.SharedInstance.Request("clamp"), new func_clamp(() => ContextSelfValue));
|
||||||
|
Reference in New Issue
Block a user