diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-11-17 11:08:09 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-11-17 11:08:09 +0400 |
commit | db44a92a11bc1dff94f8aa162c19429a1fdafa5f (patch) | |
tree | 6df872547dada2786a99ceb6b33442e773425fdb /source/blender/python | |
parent | 1cfbde0eb469f7d827b73667d7406eddc0065ceb (diff) |
pydrivers: 'frame' is now in the driver namespace,
- no need to link to scenes when using a frame from the pydriver, this made linking rigs for eg, quite messy.
- advantage that we get subframe values (where scenes from was fixed to a whole number).
Diffstat (limited to 'source/blender/python')
-rw-r--r-- | source/blender/python/BPY_extern.h | 2 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_driver.c | 35 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_driver.h | 2 |
3 files changed, 36 insertions, 3 deletions
diff --git a/source/blender/python/BPY_extern.h b/source/blender/python/BPY_extern.h index 29e0185c2f2..51f9063c289 100644 --- a/source/blender/python/BPY_extern.h +++ b/source/blender/python/BPY_extern.h @@ -74,7 +74,7 @@ void BPY_modules_load_user(struct bContext *C); void BPY_app_handlers_reset(const short do_all); void BPY_driver_reset(void); -float BPY_driver_exec(struct ChannelDriver *driver); +float BPY_driver_exec(struct ChannelDriver *driver, const float evaltime); int BPY_button_exec(struct bContext *C, const char *expr, double *value, const short verbose); int BPY_string_exec(struct bContext *C, const char *expr); diff --git a/source/blender/python/intern/bpy_driver.c b/source/blender/python/intern/bpy_driver.c index 12fb5ed43b4..2aad4d8f2fe 100644 --- a/source/blender/python/intern/bpy_driver.c +++ b/source/blender/python/intern/bpy_driver.c @@ -91,6 +91,29 @@ int bpy_pydriver_create_dict(void) return 0; } +/* note, this function should do nothing most runs, only when changing frame */ +static PyObject *bpy_pydriver_InternStr__frame= NULL; + +static void bpy_pydriver_update_dict(const float evaltime) +{ + /* not thread safe but neither is python */ + static float evaltime_prev= FLT_MAX; + + if (evaltime_prev != evaltime) { + + /* currently only update the frame */ + if (bpy_pydriver_InternStr__frame == NULL) { + bpy_pydriver_InternStr__frame= PyUnicode_FromString("frame"); + } + + PyDict_SetItem(bpy_pydriver_Dict, + bpy_pydriver_InternStr__frame, + PyFloat_FromDouble(evaltime)); + + evaltime_prev= evaltime; + } +} + /* Update function, it gets rid of pydrivers global dictionary, forcing * BPY_driver_exec to recreate it. This function is used to force * reloading the Blender text module "pydrivers.py", if available, so @@ -110,6 +133,11 @@ void BPY_driver_reset(void) bpy_pydriver_Dict= NULL; } + if (bpy_pydriver_InternStr__frame) { + Py_DECREF(bpy_pydriver_InternStr__frame); + bpy_pydriver_InternStr__frame= NULL; + } + if (use_gil) PyGILState_Release(gilstate); @@ -139,7 +167,7 @@ static void pydriver_error(ChannelDriver *driver) * now release the GIL on python operator execution instead, using * PyEval_SaveThread() / PyEval_RestoreThread() so we dont lock up blender. */ -float BPY_driver_exec(ChannelDriver *driver) +float BPY_driver_exec(ChannelDriver *driver, const float evaltime) { PyObject *driver_vars=NULL; PyObject *retval= NULL; @@ -183,6 +211,10 @@ float BPY_driver_exec(ChannelDriver *driver) } } + /* update global namespace */ + bpy_pydriver_update_dict(evaltime); + + if (driver->expr_comp==NULL) driver->flag |= DRIVER_FLAG_RECOMPILE; @@ -246,6 +278,7 @@ float BPY_driver_exec(ChannelDriver *driver) } } + #if 0 // slow, with this can avoid all Py_CompileString above. /* execute expression to get a value */ retval= PyRun_String(expr, Py_eval_input, bpy_pydriver_Dict, driver_vars); diff --git a/source/blender/python/intern/bpy_driver.h b/source/blender/python/intern/bpy_driver.h index 3e38cacf6d1..802a3649e20 100644 --- a/source/blender/python/intern/bpy_driver.h +++ b/source/blender/python/intern/bpy_driver.h @@ -33,7 +33,7 @@ int bpy_pydriver_create_dict(void); extern PyObject *bpy_pydriver_Dict; /* externals */ -float BPY_driver_exec(struct ChannelDriver *driver); +float BPY_driver_exec(struct ChannelDriver *driver, const float evaltime); void BPY_driver_reset(void); #endif // BPY_DRIVER_H |