fix for own but in recent driver optimization [#20580] Driver Crasher rev [25763]

recalculate names when needed
This commit is contained in:
Campbell Barton 2010-01-06 22:42:13 +00:00
parent e49e9289f0
commit d3a718dc2f
4 changed files with 41 additions and 6 deletions

@ -1097,6 +1097,12 @@ void driver_free_variable (ChannelDriver *driver, DriverVar *dvar)
BLI_freelinkN(&driver->variables, dvar);
else
MEM_freeN(dvar);
#ifndef DISABLE_PYTHON
/* since driver variables are cached, the expression needs re-compiling too */
if(driver->type==DRIVER_TYPE_PYTHON)
driver->flag |= DRIVER_FLAG_RENAMEVAR;
#endif
}
/* Change the type of driver variable */
@ -1149,6 +1155,12 @@ DriverVar *driver_add_new_variable (ChannelDriver *driver)
/* set the default type to 'single prop' */
driver_change_variable_type(dvar, DVAR_TYPE_SINGLE_PROP);
#ifndef DISABLE_PYTHON
/* since driver variables are cached, the expression needs re-compiling too */
if(driver->type==DRIVER_TYPE_PYTHON)
driver->flag |= DRIVER_FLAG_RENAMEVAR;
#endif
/* return the target */
return dvar;
}

@ -371,7 +371,9 @@ typedef enum eDriver_Flags {
// TODO: this needs to be implemented at some stage or left out...
//DRIVER_FLAG_LAYERING = (1<<2),
/* use when the expression needs to be recompiled */
DRIVER_FLAG_RECOMPILE = (1<<3),
DRIVER_FLAG_RECOMPILE = (1<<3),
/* the names are cached so they dont need have python unicode versions created each time */
DRIVER_FLAG_RENAMEVAR = (1<<4),
} eDriver_Flags;
/* F-Curves -------------------------------------- */

@ -129,6 +129,15 @@ static void rna_DriverTarget_update_data(Main *bmain, Scene *scene, PointerRNA *
}
}
static void rna_DriverTarget_update_name(Main *bmain, Scene *scene, PointerRNA *ptr)
{
ChannelDriver *driver= ptr->data;
rna_DriverTarget_update_data(bmain, scene, ptr);
driver->flag |= DRIVER_FLAG_RENAMEVAR;
}
/* ----------- */
static StructRNA *rna_DriverTarget_id_typef(PointerRNA *ptr)
@ -764,7 +773,7 @@ static void rna_def_drivervar(BlenderRNA *brna)
prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
RNA_def_struct_name_property(srna, prop);
RNA_def_property_ui_text(prop, "Name", "Name to use in scripted expressions/functions. (No spaces or dots are allowed. Also, must not start with a symbol or digit)");
RNA_def_property_update(prop, 0, "rna_DriverTarget_update_data"); // XXX
RNA_def_property_update(prop, 0, "rna_DriverTarget_update_name"); // XXX
/* Enums */
prop= RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);

@ -177,14 +177,29 @@ float BPY_pydriver_eval (ChannelDriver *driver)
}
}
if(driver->expr_comp==NULL)
driver->flag |= DRIVER_FLAG_RECOMPILE;
/* compile the expression first if it hasn't been compiled or needs to be rebuilt */
if((driver->flag & DRIVER_FLAG_RECOMPILE) || (driver->expr_comp==NULL)) {
if(driver->flag & DRIVER_FLAG_RECOMPILE) {
Py_XDECREF(driver->expr_comp);
driver->expr_comp= PyTuple_New(2);
expr_code= Py_CompileString(expr, "<bpy driver>", Py_eval_input);
PyTuple_SET_ITEM(((PyObject *)driver->expr_comp), 0, expr_code);
driver->flag &= ~DRIVER_FLAG_RECOMPILE;
driver->flag |= DRIVER_FLAG_RENAMEVAR; /* maybe this can be removed but for now best keep until were sure */
}
else {
expr_code= PyTuple_GET_ITEM(((PyObject *)driver->expr_comp), 0);
}
if(driver->flag & DRIVER_FLAG_RENAMEVAR) {
/* may not be set */
expr_vars= PyTuple_GET_ITEM(((PyObject *)driver->expr_comp), 1);
Py_XDECREF(expr_vars);
/* intern the arg names so creating the namespace for every run is faster */
expr_vars= PyTuple_New(BLI_countlist(&driver->variables));
PyTuple_SET_ITEM(((PyObject *)driver->expr_comp), 1, expr_vars);
@ -192,11 +207,8 @@ float BPY_pydriver_eval (ChannelDriver *driver)
for (dvar= driver->variables.first, i=0; dvar; dvar= dvar->next) {
PyTuple_SET_ITEM(expr_vars, i++, PyUnicode_InternFromString(dvar->name));
}
driver->flag &= ~DRIVER_FLAG_RECOMPILE;
}
else {
expr_code= PyTuple_GET_ITEM(((PyObject *)driver->expr_comp), 0);
expr_vars= PyTuple_GET_ITEM(((PyObject *)driver->expr_comp), 1);
}