2nd try at committing to trunk (instead of particles branch) :)
authorJanne Karhu <jhkarh@gmail.com>
Thu, 29 Nov 2007 21:09:16 +0000 (21:09 +0000)
committerJanne Karhu <jhkarh@gmail.com>
Thu, 29 Nov 2007 21:09:16 +0000 (21:09 +0000)
Fixes for bugs in #7833
- Hair softbody cache was reset on rendering.
- When Alt-a playback is synced to audio frames are skipped. This caused dynamics caching to go crazy. Now the first loop of playback goes through all frames if there are non cached dynamic systems.

Invalid point caches weren't cleared when new systems were created. This caused messed up shapes when softbody was added.

source/blender/blenkernel/BKE_pointcache.h
source/blender/blenkernel/intern/particle_system.c
source/blender/blenkernel/intern/pointcache.c
source/blender/src/buttons_object.c
source/blender/src/drawview.c

index 46d240a41833a2e54d1b40daea3774e15c1038e7..efd727d21411f63346fd931cf809c9e006a5f086 100644 (file)
@@ -44,5 +44,6 @@
 int            BKE_ptcache_id_filename(struct ID *id, char *filename, int cfra, int stack_index, short do_path, short do_ext);
 FILE * BKE_ptcache_id_fopen(struct ID *id, char mode, int cfra, int stack_index);
 void   BKE_ptcache_id_clear(struct ID *id, char mode, int cfra, int stack_index);
+int            BKE_ptcache_id_exist(struct ID *id, int cfra, int stack_index);
 
 #endif
index 5d3a4332b5da96194783bd50fde1e280b595b669..1c7d235cd90ada028a4f8d6116cfd7b67a75d88a 100644 (file)
@@ -4271,7 +4271,7 @@ void psys_to_softbody(Object *ob, ParticleSystem *psys, int force_recalc)
 
        if((psys->softflag&OB_SB_ENABLE)==0) return;
 
-       if((ob->recalc&OB_RECALC_TIME)==0)
+       if(ob->recalc && (ob->recalc&OB_RECALC_TIME)==0)
                psys->softflag|=OB_SB_REDO;
 
        /* let's replace the object's own softbody with the particle softbody */
index 9492754260c4d79bd8cf773b1eff3f67030d7c32..c4ef437019eb56989e590e5dc38b159d277fe42f 100644 (file)
@@ -183,3 +183,11 @@ void BKE_ptcache_id_clear(struct ID *id, char mode, int cfra, int stack_index)
        return;
 }
 
+int BKE_ptcache_id_exist(struct ID *id, int cfra, int stack_index)
+{
+       char filename[(FILE_MAXDIR+FILE_MAXFILE)*2];
+       
+       BKE_ptcache_id_filename(id, filename, cfra, stack_index, 1, 1);
+
+       return BLI_exists(filename);
+}
index b5733a89a0ed458b599ed0d69624f6dcf29c10ac..a6651e4a77cdfb278f6da3d1ed32f6398ce84367 100644 (file)
@@ -3248,6 +3248,7 @@ static void object_softbodies__enable(void *ob_v, void *arg2)
                if (!ob->soft) {
                        ob->soft= sbNew();
                        ob->softflag |= OB_SB_GOAL|OB_SB_EDGES;
+                       softbody_clear_cache(ob, CFRA);
                }
        }
        /* needed so that initial state is cached correctly */
@@ -3281,6 +3282,7 @@ static void object_softbodies__enable_psys(void *ob_v, void *psys_v)
                        psys->soft= sbNew();
                        psys->softflag |= OB_SB_GOAL|OB_SB_EDGES;
                        psys->soft->particles=psys;
+                       clear_particles_from_cache(ob, psys, CFRA);
                }
                psys->softflag |= OB_SB_ENABLE;
        }
index 14690b08d480da47a937232d379c9e893c2e3199..bfccd0b77ffecd5aebc5fb55fe06eb82645f3195 100644 (file)
@@ -70,6 +70,8 @@
 #include "DNA_mesh_types.h"
 #include "DNA_meshdata_types.h"
 #include "DNA_meta_types.h"
+#include "DNA_modifier_types.h"
+#include "DNA_object_force.h"
 #include "DNA_object_types.h"
 #include "DNA_particle_types.h"
 #include "DNA_screen_types.h"
 #include "BKE_key.h"
 #include "BKE_main.h"
 #include "BKE_mesh.h"
+#include "BKE_modifier.h"
 #include "BKE_object.h"
 #include "BKE_particle.h"
+#include "BKE_pointcache.h"
 #include "BKE_scene.h"
 #include "BKE_texture.h"
 #include "BKE_utildefines.h"
@@ -3292,10 +3296,50 @@ static void inner_play_prefetch_shutdown(int mode)
        seq_stop_threads();
 }
 
+static int cached_dynamics(int sfra, int efra)
+{
+       Base *base = G.scene->base.first;
+       Object *ob;
+       ModifierData *md;
+       ParticleSystem *psys;
+       int i, stack_index, cached=1;
+
+       while(base && cached) {
+               ob = base->object;
+               if(ob->softflag & OB_SB_ENABLE && ob->soft) {
+                       for(i=0, md=ob->modifiers.first; md; i++, md=md->next) {
+                               if(md->type == eModifierType_Softbody) {
+                                       stack_index = i;
+                                       break;
+                               }
+                       }
+                       for(i=sfra; i<=efra && cached; i++)
+                               cached &= BKE_ptcache_id_exist(&ob->id,i,stack_index);
+               }
+
+               for(psys=ob->particlesystem.first; psys; psys=psys->next) {
+                       stack_index = modifiers_indexInObject(ob,(ModifierData*)psys_get_modifier(ob,psys));
+                       if(psys->part->type==PART_HAIR) {
+                               if(psys->softflag & OB_SB_ENABLE && psys->soft);
+                               else
+                                       stack_index = -1;
+                       }
+
+                       if(stack_index >= 0)
+                               for(i=sfra; i<=efra && cached; i++)
+                                       cached &= BKE_ptcache_id_exist(&ob->id,i,stack_index);
+               }
+               
+               base = base->next;
+       }
+
+       return cached;
+}
 void inner_play_anim_loop(int init, int mode)
 {
        ScrArea *sa;
        static int last_cfra = -1;
+       static int cached = 0;
 
        /* init */
        if(init) {
@@ -3304,7 +3348,7 @@ void inner_play_anim_loop(int init, int mode)
                tottime= 0.0;
                curmode= mode;
                last_cfra = -1;
-
+               cached = cached_dynamics(PSFRA,PEFRA);
                return;
        }
 
@@ -3380,8 +3424,10 @@ void inner_play_anim_loop(int init, int mode)
                CFRA = PSFRA;
                audiostream_stop();
                audiostream_start( CFRA );
+               cached = cached_dynamics(PSFRA,PEFRA);
        } else {
-               if (U.mixbufsize 
+               if (cached
+                       && U.mixbufsize 
                    && (G.scene->audio.flag & AUDIO_SYNC)) {
                        CFRA = audiostream_pos();
                } else {