diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2013-08-19 13:25:24 +0400 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2013-08-19 13:25:24 +0400 |
commit | 527ddb0a5bcb9cd0b132a449b40987f70817bb31 (patch) | |
tree | 6e5851c32d5bb95d96108599f20978737ab0f9ad /source/blender/blenkernel/intern/object.c | |
parent | 0312b183194e703d778e6b989caccdfa35059d13 (diff) |
Move bevel list and path from Curve to Object datablock
I know this is not so much nice to have this guys hanging
around in a general Object datablock and ideally they better
be wrapped around into a structure like DerivedMesh or
something like this. But this is pure runtime only stuff and
we could re-wrap them around later.
Main purpose of this is making curves more thread safe,
so no separate threads will ever start freeing the same path
or the same bevel list.
It also makes sense because path and bevel shall include
deformation coming from modifiers which are applying on
pre-tesselation point and different objects could have
different set of modifiers. This used to be really confusing
in the past and now data which depends on object is stored
in an object, making things clear for understanding even.
This doesn't make curve code fully thread-safe due to
pre-tesselation modifiers still modifies actual nurbs and
lock is still needed in makeDispListsCurveTypes, but this
change makes usage of paths safe for threading.
Once modifiers will stop modifying actual nurbs, curves
will be fully safe for threading.
Actually, this commit also contains wrapping runtime curve
members into own structure
This allows easier assignment on file loading, keeps curve-
specific runtime data grouped and saves couple of bytes in
Object for non-curve types.
--
svn merge -r57938:57939 ^/branches/soc-2013-depsgraph_mt
svn merge -r57957:57958^/branches/soc-2013-depsgraph_mt
Diffstat (limited to 'source/blender/blenkernel/intern/object.c')
-rw-r--r-- | source/blender/blenkernel/intern/object.c | 44 |
1 files changed, 34 insertions, 10 deletions
diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index d1d755bd697..c3da7aef4b4 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -167,6 +167,19 @@ void BKE_object_free_bulletsoftbody(Object *ob) } } +void BKE_object_free_curve_cache(Object *ob) +{ + if (ob->curve_cache) { + BKE_displist_free(&ob->curve_cache->disp); + BLI_freelistN(&ob->curve_cache->bev); + if (ob->curve_cache->path) { + free_path(ob->curve_cache->path); + } + MEM_freeN(ob->curve_cache); + ob->curve_cache = NULL; + } +} + void BKE_object_free_modifiers(Object *ob) { while (ob->modifiers.first) { @@ -267,7 +280,9 @@ void BKE_object_free_derived_caches(Object *ob) ob->derivedDeform = NULL; } - BKE_displist_free(&ob->disp); + if (ob->curve_cache) { + BKE_displist_free(&ob->curve_cache->disp); + } } /* do not free object itself */ @@ -337,6 +352,14 @@ void BKE_object_free(Object *ob) free_sculptsession(ob); if (ob->pc_ids.first) BLI_freelistN(&ob->pc_ids); + + /* Free runtime curves data. */ + if (ob->curve_cache) { + BLI_freelistN(&ob->curve_cache->bev); + if (ob->curve_cache->path) + free_path(ob->curve_cache->path); + MEM_freeN(ob->curve_cache); + } } static void unlink_object__unlinkModifierLinks(void *userData, Object *ob, Object **obpoin) @@ -1256,8 +1279,6 @@ Object *BKE_object_copy_ex(Main *bmain, Object *ob, int copy_caches) for (a = 0; a < obn->totcol; a++) id_us_plus((ID *)obn->mat[a]); - obn->disp.first = obn->disp.last = NULL; - if (ob->pd) { obn->pd = MEM_dupallocN(ob->pd); if (obn->pd->tex) @@ -1279,7 +1300,10 @@ Object *BKE_object_copy_ex(Main *bmain, Object *ob, int copy_caches) obn->pc_ids.first = obn->pc_ids.last = NULL; obn->mpath = NULL; - + + /* Copy runtime surve data. */ + obn->curve_cache = NULL; + return obn; } @@ -1772,9 +1796,9 @@ static void ob_parcurve(Scene *scene, Object *ob, Object *par, float mat[4][4]) unit_m4(mat); cu = par->data; - if (cu->path == NULL || cu->path->data == NULL) /* only happens on reload file, but violates depsgraph still... fix! */ + if (ELEM3(NULL, par->curve_cache, par->curve_cache->path, par->curve_cache->path->data)) /* only happens on reload file, but violates depsgraph still... fix! */ BKE_displist_make_curveTypes(scene, par, 0); - if (cu->path == NULL) return; + if (par->curve_cache->path == NULL) return; /* catch exceptions: feature for nla stride editing */ if (ob->ipoflag & OB_DISABLE_PATH) { @@ -1805,7 +1829,7 @@ static void ob_parcurve(Scene *scene, Object *ob, Object *par, float mat[4][4]) /* time calculus is correct, now apply distance offset */ if (cu->flag & CU_OFFS_PATHDIST) { - ctime += timeoffs / cu->path->totdist; + ctime += timeoffs / par->curve_cache->path->totdist; /* restore */ SWAP(float, sf_orig, ob->sf); @@ -1962,7 +1986,7 @@ static void give_parvert(Object *par, int nr, float vec[3]) } else if (par->type == OB_LATTICE) { Lattice *latt = par->data; - DispList *dl = BKE_displist_find(&par->disp, DL_VERTS); + DispList *dl = par->curve_cache ? BKE_displist_find(&par->curve_cache->disp, DL_VERTS) : NULL; float (*co)[3] = dl ? (float (*)[3])dl->verts : NULL; int tot; @@ -2519,10 +2543,10 @@ void BKE_object_foreach_display_point( func_cb(co, user_data); } } - else if (ob->disp.first) { + else if (ob->curve_cache && ob->curve_cache->disp.first) { DispList *dl; - for (dl = ob->disp.first; dl; dl = dl->next) { + for (dl = ob->curve_cache->disp.first; dl; dl = dl->next) { float *v3 = dl->verts; int totvert = dl->nr; int i; |