Merge branch 'master' into blender2.8
[blender.git] / source / blender / editors / physics / physics_pointcache.c
index dadd086..4517277 100644 (file)
@@ -42,6 +42,7 @@
 #include "BKE_context.h"
 #include "BKE_screen.h"
 #include "BKE_global.h"
+#include "BKE_layer.h"
 #include "BKE_main.h"
 #include "BKE_particle.h"
 #include "BKE_pointcache.h"
@@ -165,6 +166,8 @@ static PTCacheBaker *ptcache_baker_create(bContext *C, wmOperator *op, bool all)
 
        baker->main = CTX_data_main(C);
        baker->scene = CTX_data_scene(C);
+       baker->view_layer = CTX_data_view_layer(C);
+       baker->depsgraph = CTX_data_depsgraph(C);
        baker->bake = RNA_boolean_get(op->ptr, "bake");
        baker->render = 0;
        baker->anim_init = 0;
@@ -174,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;
@@ -253,22 +245,23 @@ static void ptcache_bake_cancel(bContext *C, wmOperator *op)
 
 static int ptcache_free_bake_all_exec(bContext *C, wmOperator *UNUSED(op))
 {
-       Scene *scene= CTX_data_scene(C);
-       Base *base;
+       Scene *scene = CTX_data_scene(C);
        PTCacheID *pid;
        ListBase pidlist;
 
-       for (base=scene->base.first; base; base= base->next) {
-               BKE_ptcache_ids_from_object(&pidlist, base->object, scene, MAX_DUPLI_RECUR);
+       FOREACH_SCENE_OBJECT_BEGIN(scene, ob)
+       {
+               BKE_ptcache_ids_from_object(&pidlist, ob, scene, MAX_DUPLI_RECUR);
 
-               for (pid=pidlist.first; pid; pid=pid->next) {
+               for (pid = pidlist.first; pid; pid = pid->next) {
                        ptcache_free_bake(pid->cache);
                }
 
                BLI_freelistN(&pidlist);
 
-               WM_event_add_notifier(C, NC_OBJECT|ND_POINTCACHE, base->object);
+               WM_event_add_notifier(C, NC_OBJECT|ND_POINTCACHE, ob);
        }
+       FOREACH_SCENE_OBJECT_END;
 
        WM_event_add_notifier(C, NC_SCENE|ND_FRAME, scene);
 
@@ -387,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;
-
-       BKE_ptcache_ids_from_object(&pidlist, ob, scene, MAX_DUPLI_RECUR);
+       PTCacheID pid = BKE_ptcache_id_find(ob, scene, cache);
 
-       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);
 
@@ -414,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);
+       PTCacheID pid = BKE_ptcache_id_find(ob, scene, cache);
 
-       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;
-
-                       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;