Merging r44140 through r44226 from trunk into soc-2011-tomato
[blender.git] / source / blender / blenloader / intern / readfile.c
index fa15590..d50a063 100644 (file)
@@ -97,9 +97,9 @@
 
 #include "MEM_guardedalloc.h"
 
+#include "BLI_utildefines.h"
 #include "BLI_blenlib.h"
 #include "BLI_math.h"
-#include "BLI_utildefines.h"
 
 #include "BKE_anim.h"
 #include "BKE_action.h"
@@ -3838,7 +3838,7 @@ static void direct_link_mesh(FileData *fd, Mesh *mesh)
        
        if((fd->flags & FD_FLAGS_SWITCH_ENDIAN) && mesh->tface) {
                TFace *tf= mesh->tface;
-               unsigned int i;
+               int i;
 
                for (i=0; i< (mesh->totface); i++, tf++) {
                        SWITCH_INT(tf->col[0]);
@@ -4769,8 +4769,8 @@ static void lib_link_scene(FileData *fd, Main *main)
                        (void)marker;
 #endif
 
-                       if(sce->ed)
-                               seq_update_muting(sce->ed);
+                       seq_update_muting(sce->ed);
+                       seq_update_sound_bounds_all(sce);
                        
                        if(sce->nodetree) {
                                lib_link_ntree(fd, &sce->id, sce->nodetree);
@@ -5273,6 +5273,7 @@ static void lib_link_screen(FileData *fd, Main *main)
                                                sclip->clip= newlibadr_us(fd, sc->id.lib, sclip->clip);
 
                                                sclip->scopes.track_preview = NULL;
+                                               sclip->draw_context = NULL;
                                                sclip->scopes.ok = 0;
                                        }
                                }
@@ -5309,6 +5310,30 @@ static void *restore_pointer_by_name(Main *mainp, ID *id, int user)
        return NULL;
 }
 
+static int lib_link_seq_clipboard_cb(Sequence *seq, void *arg_pt)
+{
+       Main *newmain = (Main *)arg_pt;
+
+       if(seq->sound) {
+               seq->sound = restore_pointer_by_name(newmain, (ID *)seq->sound, 0);
+               seq->sound->id.us++;
+       }
+
+       if(seq->scene)
+               seq->scene = restore_pointer_by_name(newmain, (ID *)seq->scene, 1);
+
+       if(seq->scene_camera)
+               seq->scene_camera = restore_pointer_by_name(newmain, (ID *)seq->scene_camera, 1);
+
+       return 1;
+}
+
+static void lib_link_clipboard_restore(Main *newmain)
+{
+       /* update IDs stored in sequencer clipboard */
+       seqbase_recursive_apply(&seqbase_clipboard, lib_link_seq_clipboard_cb, newmain);
+}
+
 /* called from kernel/blender.c */
 /* used to link a file (without UI) to the current UI */
 /* note that it assumes the old pointers in UI are still valid, so old Main is not freed */
@@ -5516,6 +5541,9 @@ void lib_link_screen_restore(Main *newmain, bScreen *curscreen, Scene *curscene)
                        sa= sa->next;
                }
        }
+
+       /* update IDs stored in all possible clipboards */
+       lib_link_clipboard_restore(newmain);
 }
 
 static void direct_link_region(FileData *fd, ARegion *ar, int spacetype)
@@ -6023,6 +6051,8 @@ static void direct_link_movieclip(FileData *fd, MovieClip *clip)
        MovieTracking *tracking= &clip->tracking;
        MovieTrackingObject *object;
 
+       clip->adt= newdataadr(fd, clip->adt);
+
        if(fd->movieclipmap) clip->cache= newmclipadr(fd, clip->cache);
        else clip->cache= NULL;
 
@@ -6060,6 +6090,9 @@ static void lib_link_movieclip(FileData *fd, Main *main)
        clip= main->movieclip.first;
        while(clip) {
                if(clip->id.flag & LIB_NEEDLINK) {
+                       if (clip->adt)
+                               lib_link_animdata(fd, &clip->id, clip->adt);
+
                        clip->gpd= newlibadr_us(fd, clip->id.lib, clip->gpd);
 
                        clip->id.flag -= LIB_NEEDLINK;
@@ -7465,15 +7498,16 @@ static void do_versions_nodetree_convert_angle(bNodeTree *ntree)
 
 void do_versions_image_settings_2_60(Scene *sce)
 {
-       /* note: rd->subimtype is moved into indervidual settings now and no longer
+       /* note: rd->subimtype is moved into individual settings now and no longer
         * exists */
        RenderData *rd= &sce->r;
        ImageFormatData *imf= &sce->r.im_format;
 
-       imf->imtype= rd->imtype;
-       imf->planes= rd->planes;
-       imf->compress= rd->quality;
-       imf->quality= rd->quality;
+       /* we know no data loss happens here, the old values were in char range */
+       imf->imtype=   (char)rd->imtype;
+       imf->planes=   (char)rd->planes;
+       imf->compress= (char)rd->quality;
+       imf->quality=  (char)rd->quality;
 
        /* default, was stored in multiple places, may override later */
        imf->depth= R_IMF_CHAN_DEPTH_8;
@@ -13019,8 +13053,37 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                }
        }
        
-       /* put compatibility code here until next subversion bump */
+       if (main->versionfile < 261 || (main->versionfile == 261 && main->subversionfile < 4))
        {
+               {
+                       /* set fluidsim rate */
+                       Object *ob;
+                       for (ob = main->object.first; ob; ob = ob->id.next) {
+                               ModifierData *md;
+                               for (md = ob->modifiers.first; md; md = md->next) {
+                                       if (md->type == eModifierType_Fluidsim) {
+                                               FluidsimSettings *fss = (FluidsimSettings *)md;
+                                               fss->animRate = 1.0f;
+                                       }
+                               }
+                       }
+               }
+       }
+
+       if (main->versionfile < 262)
+       {
+               Object *ob;
+               for(ob=main->object.first; ob; ob= ob->id.next) {
+                       ModifierData *md;
+
+                       for (md=ob->modifiers.first; md; md=md->next) {
+                               if (md->type==eModifierType_Cloth) {
+                                       ClothModifierData *clmd = (ClothModifierData*) md;
+                                       if(clmd->sim_parms)
+                                               clmd->sim_parms->vel_damping = 1.0f;
+                               }
+                       }
+               }
        }
 
        /* WATCH IT!!!: pointers from libdata have not been converted yet here! */
@@ -14024,6 +14087,11 @@ static void expand_sound(FileData *fd, Main *mainvar, bSound *snd)
        expand_doit(fd, mainvar, snd->ipo); // XXX depreceated - old animation system
 }
 
+static void expand_movieclip(FileData *fd, Main *mainvar, MovieClip *clip)
+{
+       if (clip->adt)
+               expand_animdata(fd, mainvar, clip->adt);
+}
 
 static void expand_main(FileData *fd, Main *mainvar)
 {
@@ -14107,6 +14175,10 @@ static void expand_main(FileData *fd, Main *mainvar)
                                                break;
                                        case ID_PA:
                                                expand_particlesettings(fd, mainvar, (ParticleSettings *)id);
+                                               break;
+                                       case ID_MC:
+                                               expand_movieclip(fd, mainvar, (MovieClip *)id);
+                                               break;
                                        }
 
                                        doit= 1;