Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Gavrilov <angavrilov@gmail.com>2018-09-15 15:32:40 +0300
committerAlexander Gavrilov <angavrilov@gmail.com>2018-09-18 13:25:28 +0300
commitbf2a54b0584c1e568af7ecf67ae2a623bc5263fe (patch)
treef123a9ca55d475dd676351d635bf944a31a27200 /source/blender/makesrna/intern/rna_fcurve.c
parent34ee9ab97c0cf629987f8f3f72b529ca7e73e027 (diff)
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
Diffstat (limited to 'source/blender/makesrna/intern/rna_fcurve.c')
-rw-r--r--source/blender/makesrna/intern/rna_fcurve.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/source/blender/makesrna/intern/rna_fcurve.c b/source/blender/makesrna/intern/rna_fcurve.c
index 3141e788d8d..efd571d2b18 100644
--- a/source/blender/makesrna/intern/rna_fcurve.c
+++ b/source/blender/makesrna/intern/rna_fcurve.c
@@ -132,6 +132,13 @@ static StructRNA *rna_FModifierType_refine(struct PointerRNA *ptr)
#include "DEG_depsgraph.h"
#include "DEG_depsgraph_build.h"
+static bool rna_ChannelDriver_is_simple_expression_get(PointerRNA *ptr)
+{
+ ChannelDriver *driver = ptr->data;
+
+ return BKE_driver_has_simple_expression(driver);
+}
+
static void rna_ChannelDriver_update_data(Main *bmain, Scene *scene, PointerRNA *ptr)
{
ID *id = ptr->id.data;
@@ -151,7 +158,7 @@ static void rna_ChannelDriver_update_expr(Main *bmain, Scene *scene, PointerRNA
ChannelDriver *driver = ptr->data;
/* tag driver as needing to be recompiled */
- driver->flag |= DRIVER_FLAG_RECOMPILE;
+ BKE_driver_invalidate_expression(driver, true, false);
/* update_data() clears invalid flag and schedules for updates */
rna_ChannelDriver_update_data(bmain, scene, ptr);
@@ -184,8 +191,7 @@ static void rna_DriverTarget_update_name(Main *bmain, Scene *scene, PointerRNA *
ChannelDriver *driver = ptr->data;
rna_DriverTarget_update_data(bmain, scene, ptr);
- driver->flag |= DRIVER_FLAG_RENAMEVAR;
-
+ BKE_driver_invalidate_expression(driver, false, true);
}
/* ----------- */
@@ -1675,6 +1681,10 @@ static void rna_def_channeldriver(BlenderRNA *brna)
RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", DRIVER_FLAG_INVALID);
RNA_def_property_ui_text(prop, "Invalid", "Driver could not be evaluated in past, so should be skipped");
+ prop = RNA_def_property(srna, "is_simple_expression", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+ RNA_def_property_boolean_funcs(prop, "rna_ChannelDriver_is_simple_expression_get", NULL);
+ RNA_def_property_ui_text(prop, "Simple Expression", "The scripted expression can be evaluated without using the full python interpreter");
/* Functions */
RNA_api_drivers(srna);