diff options
author | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2018-04-12 19:43:43 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2018-04-13 12:31:19 +0300 |
commit | d8bdd7b261d2ac6936e16fd04845d0e491931a87 (patch) | |
tree | 4780862cc14449c84e079d1d24dc778d9a7053dc /source/blender/editors/physics/physics_pointcache.c | |
parent | b92d78553b1889ff5bfbea17b35cf8fda586a062 (diff) |
Cleanup: add utility function to find a single point cache ID.
Diffstat (limited to 'source/blender/editors/physics/physics_pointcache.c')
-rw-r--r-- | source/blender/editors/physics/physics_pointcache.c | 54 |
1 files changed, 12 insertions, 42 deletions
diff --git a/source/blender/editors/physics/physics_pointcache.c b/source/blender/editors/physics/physics_pointcache.c index b1d870a43ae..fdafd6c28ed 100644 --- a/source/blender/editors/physics/physics_pointcache.c +++ b/source/blender/editors/physics/physics_pointcache.c @@ -177,18 +177,7 @@ static PTCacheBaker *ptcache_baker_create(bContext *C, wmOperator *op, bool all) PointerRNA ptr = CTX_data_pointer_get_type(C, "point_cache", &RNA_PointCache); Object *ob = ptr.id.data; PointCache *cache = ptr.data; - - ListBase pidlist; - BKE_ptcache_ids_from_object(&pidlist, ob, baker->scene, MAX_DUPLI_RECUR); - - for (PTCacheID *pid = pidlist.first; pid; pid = pid->next) { - if (pid->cache == cache) { - baker->pid = *pid; - break; - } - } - - BLI_freelistN(&pidlist); + baker->pid = BKE_ptcache_id_find(ob, baker->scene, cache); } return baker; @@ -391,22 +380,14 @@ static int ptcache_add_new_exec(bContext *C, wmOperator *UNUSED(op)) PointerRNA ptr= CTX_data_pointer_get_type(C, "point_cache", &RNA_PointCache); Object *ob= ptr.id.data; PointCache *cache= ptr.data; - PTCacheID *pid; - ListBase pidlist; + PTCacheID pid = BKE_ptcache_id_find(ob, scene, cache); - BKE_ptcache_ids_from_object(&pidlist, ob, scene, MAX_DUPLI_RECUR); - - for (pid=pidlist.first; pid; pid=pid->next) { - if (pid->cache == cache) { - PointCache *cache_new = BKE_ptcache_add(pid->ptcaches); - cache_new->step = pid->default_step; - *(pid->cache_ptr) = cache_new; - break; - } + if (pid.cache) { + PointCache *cache_new = BKE_ptcache_add(pid.ptcaches); + cache_new->step = pid.default_step; + *(pid.cache_ptr) = cache_new; } - BLI_freelistN(&pidlist); - WM_event_add_notifier(C, NC_SCENE|ND_FRAME, scene); WM_event_add_notifier(C, NC_OBJECT|ND_POINTCACHE, ob); @@ -418,26 +399,15 @@ static int ptcache_remove_exec(bContext *C, wmOperator *UNUSED(op)) Scene *scene= CTX_data_scene(C); Object *ob= ptr.id.data; PointCache *cache= ptr.data; - PTCacheID *pid; - ListBase pidlist; - - BKE_ptcache_ids_from_object(&pidlist, ob, scene, MAX_DUPLI_RECUR); - - for (pid=pidlist.first; pid; pid=pid->next) { - if (pid->cache == cache) { - if (pid->ptcaches->first == pid->ptcaches->last) - continue; /* don't delete last cache */ - - BLI_remlink(pid->ptcaches, pid->cache); - BKE_ptcache_free(pid->cache); - *(pid->cache_ptr) = pid->ptcaches->first; + PTCacheID pid = BKE_ptcache_id_find(ob, scene, cache); - break; - } + /* don't delete last cache */ + if (pid.cache && pid.ptcaches->first != pid.ptcaches->last) { + BLI_remlink(pid.ptcaches, pid.cache); + BKE_ptcache_free(pid.cache); + *(pid.cache_ptr) = pid.ptcaches->first; } - BLI_freelistN(&pidlist); - WM_event_add_notifier(C, NC_OBJECT|ND_POINTCACHE, ob); return OPERATOR_FINISHED; |