备份,准备做双端

This commit is contained in:
FloatGaming
2026-07-30 23:15:58 +08:00
parent add675e45d
commit ec4ec53545
88 changed files with 4050 additions and 872 deletions
+12 -3
View File
@@ -9,6 +9,11 @@ public class SkillDefinition : ScriptableObject
// Cache compiled RPN for formulas to avoid re-tokenizing every trigger.
private static readonly Dictionary<string, List<Token>> s_rpnCache = new Dictionary<string, List<Token>>();
private static readonly HashSet<string> s_badFormulaCache = new HashSet<string>();
// Reused across EvalRPN calls to avoid a per-evaluation allocation. Formula eval runs
// synchronously on the main thread and is not re-entrant, so a shared instance is safe.
private static readonly Stack<float> s_evalStack = new Stack<float>();
// Warn once per unknown variable name instead of on every evaluation.
private static readonly HashSet<string> s_warnedUnknownVars = new HashSet<string>();
public enum SkillTrigger
{
None,
@@ -301,7 +306,8 @@ public class SkillDefinition : ScriptableObject
private static float EvalRPN(List<Token> rpn, Dictionary<string, float> vars)
{
var st = new Stack<float>();
var st = s_evalStack;
st.Clear();
foreach (var t in rpn)
{
if (t.type == TokType.Number)
@@ -314,8 +320,11 @@ public class SkillDefinition : ScriptableObject
if (vars != null && vars.TryGetValue(t.text, out float v)) st.Push(v);
else
{
// unknown identifiers treat as 0 but warn
Debug.LogWarning($"SkillDefinition: unknown variable '{t.text}' in formula, treated as 0");
// unknown identifiers treat as 0 but warn (once per unique name)
if (s_warnedUnknownVars.Add(t.text))
{
Debug.LogWarning($"SkillDefinition: unknown variable '{t.text}' in formula, treated as 0");
}
st.Push(0f);
}
}