From bf2a54b0584c1e568af7ecf67ae2a623bc5263fe Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Sat, 15 Sep 2018 15:32:40 +0300 Subject: Support evaluating simple driver expressions without Python interpreter. Recently @sergey found that hard-coding evaluation of certain very common driver expressions without calling the Python interpreter produces a 30-40% performance improvement. Since hard-coding is obviously not suitable for production, I implemented a proper parser and interpreter for simple arithmetic expressions in C. The evaluator supports +, -, *, /, (), ==, !=, <, <=, >, >=, and, or, not, ternary if; driver variables, frame, pi, True, False, and a subset of standard math functions that seem most useful. Booleans are represented as numbers, since within the supported operation set it seems to be impossible to distinguish True/False from 1.0/0.0. Boolean operations properly implement lazy evaluation with jumps, and comparisons support chaining like 'a < b < c...'. Expressions are parsed into a very simple stack machine program that can then be safely evaluated in multiple threads. Reviewers: sergey, campbellbarton Differential Revision: https://developer.blender.org/D3698 --- source/blender/makesdna/DNA_anim_types.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source/blender/makesdna/DNA_anim_types.h') diff --git a/source/blender/makesdna/DNA_anim_types.h b/source/blender/makesdna/DNA_anim_types.h index 22067b87ff8..edf137ca386 100644 --- a/source/blender/makesdna/DNA_anim_types.h +++ b/source/blender/makesdna/DNA_anim_types.h @@ -415,6 +415,8 @@ typedef struct ChannelDriver { char expression[256]; /* expression to compile for evaluation */ void *expr_comp; /* PyObject - compiled expression, don't save this */ + struct ParsedSimpleExpr *expr_simple; /* compiled simple arithmetic expression */ + float curval; /* result of previous evaluation */ float influence; /* influence of driver on result */ // XXX to be implemented... this is like the constraint influence setting -- cgit v1.2.3