Testing for the need to quick cache was causing slowdowns on files with many duplis.
authorJanne Karhu <jhkarh@gmail.com>
Tue, 13 Apr 2010 20:06:55 +0000 (20:06 +0000)
committerJanne Karhu <jhkarh@gmail.com>
Tue, 13 Apr 2010 20:06:55 +0000 (20:06 +0000)
* The test is now only done when some object that uses cache has actually changed.
* The added scene->physics_settings->quick_cache_step is only an internal counter, not a user changeable value.

source/blender/blenkernel/intern/object.c
source/blender/blenkernel/intern/pointcache.c
source/blender/blenkernel/intern/scene.c
source/blender/makesdna/DNA_scene_types.h

index ac679adb9c118e748d9b0a3453f34338e2cf70ac..ef630a18ab4c4c39c90a44a47de0060aa404d28c 100644 (file)
@@ -2489,6 +2489,8 @@ void object_handle_update(Scene *scene, Object *ob)
                        ID *data_id= (ID *)ob->data;
                        AnimData *adt= BKE_animdata_from_id(data_id);
                        float ctime= (float)scene->r.cfra; // XXX this is bad...
                        ID *data_id= (ID *)ob->data;
                        AnimData *adt= BKE_animdata_from_id(data_id);
                        float ctime= (float)scene->r.cfra; // XXX this is bad...
+                       ListBase pidlist;
+                       PTCacheID *pid;
                        
                        if (G.f & G_DEBUG)
                                printf("recalcdata %s\n", ob->id.name+2);
                        
                        if (G.f & G_DEBUG)
                                printf("recalcdata %s\n", ob->id.name+2);
@@ -2577,6 +2579,24 @@ void object_handle_update(Scene *scene, Object *ob)
                                                psys_get_modifier(ob, psys)->flag &= ~eParticleSystemFlag_psys_updated;
                                }
                        }
                                                psys_get_modifier(ob, psys)->flag &= ~eParticleSystemFlag_psys_updated;
                                }
                        }
+
+                       /* check if quick cache is needed */
+                       BKE_ptcache_ids_from_object(&pidlist, ob, scene, MAX_DUPLI_RECUR);
+
+                       for(pid=pidlist.first; pid; pid=pid->next) {
+                               if((pid->cache->flag & PTCACHE_BAKED)
+                                       || (pid->cache->flag & PTCACHE_QUICK_CACHE)==0)
+                                       continue;
+
+                               if(pid->cache->flag & PTCACHE_OUTDATED || (pid->cache->flag & PTCACHE_SIMULATION_VALID)==0) {
+                                       scene->physics_settings.quick_cache_step =
+                                               scene->physics_settings.quick_cache_step ?
+                                               MIN2(scene->physics_settings.quick_cache_step, pid->cache->step) :
+                                               pid->cache->step;
+                               }
+                       }
+
+                       BLI_freelistN(&pidlist);
                }
 
                /* the no-group proxy case, we call update */
                }
 
                /* the no-group proxy case, we call update */
index 6b8d5b3b70f597ac4fd6acc7d50a0305aaca63e2..515d1f820aa285db247cd02b04c2d68777713669 100644 (file)
@@ -2325,39 +2325,6 @@ PointCache *BKE_ptcache_copy_list(ListBase *ptcaches_new, ListBase *ptcaches_old
 
 
 /* Baking */
 
 
 /* Baking */
-static int count_quick_cache(Scene *scene, int *quick_step)
-{
-       Base *base;
-       PTCacheID *pid;
-       ListBase pidlist;
-       int autocache_count= 0;
-       Scene *sce; /* for macro only */
-
-       for(SETLOOPER(scene, base)) {
-               if(base->object) {
-                       BKE_ptcache_ids_from_object(&pidlist, base->object, scene, MAX_DUPLI_RECUR);
-
-                       for(pid=pidlist.first; pid; pid=pid->next) {
-                               if((pid->cache->flag & PTCACHE_BAKED)
-                                       || (pid->cache->flag & PTCACHE_QUICK_CACHE)==0)
-                                       continue;
-
-                               if(pid->cache->flag & PTCACHE_OUTDATED || (pid->cache->flag & PTCACHE_SIMULATION_VALID)==0) {
-                                       if(!autocache_count)
-                                               *quick_step = pid->cache->step;
-                                       else
-                                               *quick_step = MIN2(*quick_step, pid->cache->step);
-
-                                       autocache_count++;
-                               }
-                       }
-
-                       BLI_freelistN(&pidlist);
-               }
-       }
-
-       return autocache_count;
-}
 void BKE_ptcache_quick_cache_all(Scene *scene)
 {
        PTCacheBaker baker;
 void BKE_ptcache_quick_cache_all(Scene *scene)
 {
        PTCacheBaker baker;
@@ -2372,9 +2339,9 @@ void BKE_ptcache_quick_cache_all(Scene *scene)
        baker.render=0;
        baker.anim_init = 0;
        baker.scene=scene;
        baker.render=0;
        baker.anim_init = 0;
        baker.scene=scene;
+       baker.quick_step=scene->physics_settings.quick_cache_step;
 
 
-       if(count_quick_cache(scene, &baker.quick_step))
-               BKE_ptcache_make_cache(&baker);
+       BKE_ptcache_make_cache(&baker);
 }
 
 /* Simulation thread, no need for interlocks as data written in both threads
 }
 
 /* Simulation thread, no need for interlocks as data written in both threads
index fc6b7e7d7891e54ba33f64e39fcc8e22d32bd930..e5d9686a18d6da456c1a2f6a6b47d23c7ba62093 100644 (file)
@@ -924,6 +924,8 @@ void scene_update_tagged(Scene *scene)
        Object *ob;
        float ctime = frame_to_float(scene, scene->r.cfra); 
 
        Object *ob;
        float ctime = frame_to_float(scene, scene->r.cfra); 
 
+       scene->physics_settings.quick_cache_step= 0;
+
        /* update all objects: drivers, matrices, displists, etc. flags set
           by depgraph or manual, no layer check here, gets correct flushed */
 
        /* update all objects: drivers, matrices, displists, etc. flags set
           by depgraph or manual, no layer check here, gets correct flushed */
 
@@ -957,8 +959,8 @@ void scene_update_tagged(Scene *scene)
                        BKE_animsys_evaluate_animdata(&scene->id, adt, ctime, 0);
        }
 
                        BKE_animsys_evaluate_animdata(&scene->id, adt, ctime, 0);
        }
 
-       /* XXX - this is called far to often, should be made apart of the depgraph */
-       BKE_ptcache_quick_cache_all(scene);
+       if(scene->physics_settings.quick_cache_step)
+               BKE_ptcache_quick_cache_all(scene);
 
        /* in the future this should handle updates for all datablocks, not
           only objects and scenes. - brecht */
 
        /* in the future this should handle updates for all datablocks, not
           only objects and scenes. - brecht */
index 7d7af0ddf8221d4be07194c853b22a32fbf65f81..44cf139849578c9679d5ab64c42973d8dc2fb1f6 100644 (file)
@@ -735,7 +735,7 @@ typedef struct UnitSettings {
 
 typedef struct PhysicsSettings {
        float gravity[3];
 
 typedef struct PhysicsSettings {
        float gravity[3];
-       int flag;
+       int flag, quick_cache_step, rt;
 } PhysicsSettings;
 
 typedef struct Scene {
 } PhysicsSettings;
 
 typedef struct Scene {