Merging r39717 through r39983 from trunk into soc-2011-tomato
[blender.git] / source / blender / blenloader / intern / readfile.c
index 4a86de51d9cefd51c00cbe084080f5e8d9ffa8d3..b1e5f63e641efcd146ef833fe46b71b967f195fd 100644 (file)
@@ -90,6 +90,7 @@
 #include "DNA_space_types.h"
 #include "DNA_vfont_types.h"
 #include "DNA_world_types.h"
+#include "DNA_movieclip_types.h"
 
 #include "MEM_guardedalloc.h"
 
 #include "BKE_utildefines.h" // SWITCH_INT DATA ENDB DNA1 O_BINARY GLOB USER TEST REND
 #include "BKE_sound.h"
 
+#include "NOD_socket.h"
+
 //XXX #include "BIF_butspace.h" // badlevel, for do_versions, patching event codes
 //XXX #include "BIF_filelist.h" // badlevel too, where to move this? - elubie
 //XXX #include "BIF_previewrender.h" // bedlelvel, for struct RenderInfo
@@ -1034,6 +1037,8 @@ void blo_freefiledata(FileData *fd)
                        oldnewmap_free(fd->globmap);
                if (fd->imamap)
                        oldnewmap_free(fd->imamap);
+               if (fd->movieclipmap)
+                       oldnewmap_free(fd->movieclipmap);
                if (fd->libmap && !(fd->flags & FD_FLAGS_NOT_MY_LIBMAP))
                        oldnewmap_free(fd->libmap);
                if (fd->bheadmap)
@@ -1109,6 +1114,13 @@ static void *newimaadr(FileData *fd, void *adr)          /* used to restore image data a
        return NULL;
 }
 
+static void *newmclipadr(FileData *fd, void *adr)              /* used to restore movie clip data after undo */
+{
+       if(fd->movieclipmap && adr)
+               return oldnewmap_lookup_and_inc(fd->movieclipmap, adr);
+       return NULL;
+}
+
 
 static void *newlibadr(FileData *fd, void *lib, void *adr)             /* only lib data */
 {
@@ -1237,6 +1249,38 @@ void blo_end_image_pointer_map(FileData *fd, Main *oldmain)
        }
 }
 
+void blo_make_movieclip_pointer_map(FileData *fd, Main *oldmain)
+{
+       MovieClip *clip= oldmain->movieclip.first;
+
+       fd->movieclipmap= oldnewmap_new();
+
+       for(;clip; clip= clip->id.next) {
+               if(clip->cache)
+                       oldnewmap_insert(fd->movieclipmap, clip->cache, clip->cache, 0);
+       }
+}
+
+/* set old main movie clips caches to zero if it has been restored */
+/* this works because freeing old main only happens after this call */
+void blo_end_movieclip_pointer_map(FileData *fd, Main *oldmain)
+{
+       OldNew *entry= fd->movieclipmap->entries;
+       MovieClip *clip= oldmain->movieclip.first;
+       int i;
+
+       /* used entries were restored, so we put them to zero */
+       for (i=0; i<fd->movieclipmap->nentries; i++, entry++) {
+               if (entry->nr>0)
+                               entry->newp= NULL;
+       }
+
+       for(;clip; clip= clip->id.next) {
+               clip->cache= newmclipadr(fd, clip->cache);
+       }
+}
+
+
 /* undo file support: add all library pointers in lookup */
 void blo_add_library_pointer_map(ListBase *mainlist, FileData *fd)
 {
@@ -2052,10 +2096,21 @@ static void lib_link_nodetree(FileData *fd, Main *main)
        }
 }
 
+static void lib_nodetree_init_types_cb(void *UNUSED(data), ID *UNUSED(id), bNodeTree *ntree)
+{
+       bNode *node;
+       
+       ntreeInitTypes(ntree);
+       
+       /* XXX could be replaced by do_versions for new nodes */
+       for (node=ntree->nodes.first; node; node=node->next)
+               node_verify_socket_templates(ntree, node);
+}
+
 /* updates group node socket own_index so that
  * external links to/from the group node are preserved.
  */
-static void lib_node_do_versions_group(bNode *gnode)
+static void lib_node_do_versions_group_indices(bNode *gnode)
 {
        bNodeTree *ngroup= (bNodeTree*)gnode->id;
        bNode *intnode;
@@ -2088,92 +2143,101 @@ static void lib_node_do_versions_group(bNode *gnode)
 }
 
 /* updates external links for all group nodes in a tree */
-static void lib_nodetree_do_versions_group(bNodeTree *ntree)
+static void lib_nodetree_do_versions_group_indices_cb(void *UNUSED(data), ID *UNUSED(id), bNodeTree *ntree)
 {
        bNode *node;
        
        for (node=ntree->nodes.first; node; node=node->next) {
                if (node->type==NODE_GROUP) {
                        bNodeTree *ngroup= (bNodeTree*)node->id;
-                       if (ngroup && (ngroup->flag & NTREE_DO_VERSIONS))
-                               lib_node_do_versions_group(node);
+                       if (ngroup && (ngroup->flag & NTREE_DO_VERSIONS_GROUP_EXPOSE))
+                               lib_node_do_versions_group_indices(node);
                }
        }
 }
 
+/* make an update call for the tree */
+static void lib_nodetree_do_versions_update_cb(void *UNUSED(data), ID *UNUSED(id), bNodeTree *ntree)
+{
+       if (ntree->update)
+               ntreeUpdateTree(ntree);
+}
+
 /* verify types for nodes and groups, all data has to be read */
 /* open = 0: appending/linking, open = 1: open new file (need to clean out dynamic
 * typedefs*/
 static void lib_verify_nodetree(Main *main, int UNUSED(open))
 {
-       Scene *sce;
-       Material *ma;
-       Tex *tx;
        bNodeTree *ntree;
-       
+       int i;
+       bNodeTreeType *ntreetype;
+
        /* this crashes blender on undo/redo
                if(open==1) {
                        reinit_nodesystem();
                }*/
        
-       /* now create the own typeinfo structs an verify nodes */
-       /* here we still assume no groups in groups */
-       for(ntree= main->nodetree.first; ntree; ntree= ntree->id.next) {
-               ntreeVerifyTypes(ntree);                /* internal nodes, no groups! */
+       /* set node->typeinfo pointers */
+       for (i=0; i < NUM_NTREE_TYPES; ++i) {
+               ntreetype= ntreeGetType(i);
+               if (ntreetype && ntreetype->foreach_nodetree)
+                       ntreetype->foreach_nodetree(main, NULL, lib_nodetree_init_types_cb);
        }
+       for(ntree= main->nodetree.first; ntree; ntree= ntree->id.next)
+               ntreeInitTypes(ntree);
        
        {
-               /*int has_old_groups=0;*/ /*UNUSED*/
+               int has_old_groups=0;
                /* XXX this should actually be part of do_versions, but since we need
                 * finished library linking, it is not possible there. Instead in do_versions
                 * we have set the NTREE_DO_VERSIONS flag, so at this point we can do the
                 * actual group node updates.
                 */
                for(ntree= main->nodetree.first; ntree; ntree= ntree->id.next) {
-                       if (ntree->flag & NTREE_DO_VERSIONS) {
+                       if (ntree->flag & NTREE_DO_VERSIONS_GROUP_EXPOSE) {
                                /* this adds copies and links from all unlinked internal sockets to group inputs/outputs. */
-                               nodeGroupExposeAllSockets(ntree);
-                               /*has_old_groups = 1;*/ /*UNUSED*/
+                               node_group_expose_all_sockets(ntree);
+                               has_old_groups = 1;
                        }
                }
-               /* now verify all types in material trees, groups are set OK now */
-               for(ma= main->mat.first; ma; ma= ma->id.next) {
-                       if(ma->nodetree)
-                               lib_nodetree_do_versions_group(ma->nodetree);
-               }
-               /* and scene trees */
-               for(sce= main->scene.first; sce; sce= sce->id.next) {
-                       if(sce->nodetree)
-                               lib_nodetree_do_versions_group(sce->nodetree);
-               }
-               /* and texture trees */
-               for(tx= main->tex.first; tx; tx= tx->id.next) {
-                       if(tx->nodetree)
-                               lib_nodetree_do_versions_group(tx->nodetree);
+               
+               if (has_old_groups) {
+                       for (i=0; i < NUM_NTREE_TYPES; ++i) {
+                               ntreetype= ntreeGetType(i);
+                               if (ntreetype && ntreetype->foreach_nodetree)
+                                       ntreetype->foreach_nodetree(main, NULL, lib_nodetree_do_versions_group_indices_cb);
+                       }
                }
                
                for(ntree= main->nodetree.first; ntree; ntree= ntree->id.next)
-                       ntree->flag &= ~NTREE_DO_VERSIONS;
-       }
-
-       /* now verify all types in material trees, groups are set OK now */
-       for(ma= main->mat.first; ma; ma= ma->id.next) {
-               if(ma->nodetree)
-                       ntreeVerifyTypes(ma->nodetree);
+                       ntree->flag &= ~NTREE_DO_VERSIONS_GROUP_EXPOSE;
        }
-       /* and scene trees */
-       for(sce= main->scene.first; sce; sce= sce->id.next) {
-               if(sce->nodetree)
-                       ntreeVerifyTypes(sce->nodetree);
+       
+       /* verify all group user nodes */
+       for(ntree= main->nodetree.first; ntree; ntree= ntree->id.next) {
+               ntreeVerifyNodes(main, &ntree->id);
        }
-       /* and texture trees */
-       for(tx= main->tex.first; tx; tx= tx->id.next) {
-               if(tx->nodetree)
-                       ntreeVerifyTypes(tx->nodetree);
+       
+       /* make update calls where necessary */
+       {
+               for(ntree= main->nodetree.first; ntree; ntree= ntree->id.next)
+                       if (ntree->update)
+                               ntreeUpdateTree(ntree);
+               for (i=0; i < NUM_NTREE_TYPES; ++i) {
+                       ntreetype= ntreeGetType(i);
+                       if (ntreetype && ntreetype->foreach_nodetree)
+                               ntreetype->foreach_nodetree(main, NULL, lib_nodetree_do_versions_update_cb);
+               }
        }
 }
 
-
+static void direct_link_node_socket(FileData *fd, bNodeSocket *sock)
+{
+       sock->link= newdataadr(fd, sock->link);
+       sock->storage= newdataadr(fd, sock->storage);
+       sock->default_value= newdataadr(fd, sock->default_value);
+       sock->cache= NULL;
+}
 
 /* ntree itself has been read! */
 static void direct_link_nodetree(FileData *fd, bNodeTree *ntree)
@@ -2185,6 +2249,7 @@ static void direct_link_nodetree(FileData *fd, bNodeTree *ntree)
        
        ntree->init= 0;         /* to set callbacks and force setting types */
        ntree->progress= NULL;
+       ntree->execdata= NULL;
        
        ntree->adt= newdataadr(fd, ntree->adt);
        direct_link_animdata(fd, ntree->adt);
@@ -2194,12 +2259,15 @@ static void direct_link_nodetree(FileData *fd, bNodeTree *ntree)
                if(node->type == NODE_DYNAMIC) {
                        node->custom1= 0;
                        node->custom1= BSET(node->custom1, NODE_DYNAMIC_LOADED);
-                       node->typeinfo= NULL;
                }
+
+               node->typeinfo= NULL;
+               
+               link_list(fd, &node->inputs);
+               link_list(fd, &node->outputs);
                
                node->storage= newdataadr(fd, node->storage);
                if(node->storage) {
-                       
                        /* could be handlerized at some point */
                        if(ntree->type==NTREE_SHADER && (node->type==SH_NODE_CURVE_VEC || node->type==SH_NODE_CURVE_RGB))
                                direct_link_curvemapping(fd, node->storage);
@@ -2216,8 +2284,6 @@ static void direct_link_nodetree(FileData *fd, bNodeTree *ntree)
                                        ((ImageUser *)node->storage)->ok= 1;
                        }
                }
-               link_list(fd, &node->inputs);
-               link_list(fd, &node->outputs);
        }
        link_list(fd, &ntree->links);
        
@@ -2227,15 +2293,19 @@ static void direct_link_nodetree(FileData *fd, bNodeTree *ntree)
        
        /* and we connect the rest */
        for(node= ntree->nodes.first; node; node= node->next) {
+               node->parent = newdataadr(fd, node->parent);
                node->preview= newimaadr(fd, node->preview);
                node->lasty= 0;
+               
                for(sock= node->inputs.first; sock; sock= sock->next)
-                       sock->link= newdataadr(fd, sock->link);
+                       direct_link_node_socket(fd, sock);
                for(sock= node->outputs.first; sock; sock= sock->next)
-                       sock->ns.data= NULL;
+                       direct_link_node_socket(fd, sock);
        }
+       for(sock= ntree->inputs.first; sock; sock= sock->next)
+               direct_link_node_socket(fd, sock);
        for(sock= ntree->outputs.first; sock; sock= sock->next)
-               sock->link= newdataadr(fd, sock->link);
+               direct_link_node_socket(fd, sock);
        
        for(link= ntree->links.first; link; link= link->next) {
                link->fromnode= newdataadr(fd, link->fromnode);
@@ -4691,6 +4761,7 @@ static void direct_link_scene(FileData *fd, Scene *sce)
        if(sce->nodetree)
                direct_link_nodetree(fd, sce->nodetree);
        
+       sce->clip= newlibadr_us(fd, sce->id.lib, sce->clip);
 }
 
 /* ************ READ WM ***************** */
@@ -4845,6 +4916,7 @@ static void lib_link_screen(FileData *fd, Main *main)
 
                                                for(bgpic= v3d->bgpicbase.first; bgpic; bgpic= bgpic->next) {
                                                        bgpic->ima= newlibadr_us(fd, sc->id.lib, bgpic->ima);
+                                                       bgpic->clip= newlibadr_us(fd, sc->id.lib, bgpic->clip);
                                                }
                                                if(v3d->localvd) {
                                                        v3d->localvd->camera= newlibadr(fd, sc->id.lib, v3d->localvd->camera);
@@ -4957,19 +5029,34 @@ static void lib_link_screen(FileData *fd, Main *main)
                                                SpaceNode *snode= (SpaceNode *)sl;
                                                
                                                snode->id= newlibadr(fd, sc->id.lib, snode->id);
+                                               snode->edittree= NULL;
                                                
-                                               /* internal data, a bit patchy */
-                                               if(snode->id) {
-                                                       if(GS(snode->id->name)==ID_MA)
-                                                               snode->nodetree= ((Material *)snode->id)->nodetree;
-                                                       else if(GS(snode->id->name)==ID_SCE)
-                                                               snode->nodetree= ((Scene *)snode->id)->nodetree;
-                                                       else if(GS(snode->id->name)==ID_TE)
-                                                               snode->nodetree= ((Tex *)snode->id)->nodetree;
+                                               if (ELEM3(snode->treetype, NTREE_COMPOSIT, NTREE_SHADER, NTREE_TEXTURE)) {
+                                                       /* internal data, a bit patchy */
+                                                       snode->nodetree= NULL;
+                                                       if(snode->id) {
+                                                               if(GS(snode->id->name)==ID_MA)
+                                                                       snode->nodetree= ((Material *)snode->id)->nodetree;
+                                                               else if(GS(snode->id->name)==ID_SCE)
+                                                                       snode->nodetree= ((Scene *)snode->id)->nodetree;
+                                                               else if(GS(snode->id->name)==ID_TE)
+                                                                       snode->nodetree= ((Tex *)snode->id)->nodetree;
+                                                       }
+                                               }
+                                               else {
+                                                       snode->nodetree= newlibadr_us(fd, sc->id.lib, snode->nodetree);
                                                }
                                                
                                                snode->linkdrag.first = snode->linkdrag.last = NULL;
                                        }
+                                       else if(sl->spacetype==SPACE_CLIP) {
+                                               SpaceClip *sclip= (SpaceClip *)sl;
+
+                                               sclip->clip= newlibadr_us(fd, sc->id.lib, sclip->clip);
+
+                                               sclip->scopes.track_preview = NULL;
+                                               sclip->scopes.ok = 0;
+                                       }
                                }
                                sa= sa->next;
                        }
@@ -5056,6 +5143,7 @@ void lib_link_screen_restore(Main *newmain, bScreen *curscreen, Scene *curscene)
                                        
                                        for(bgpic= v3d->bgpicbase.first; bgpic; bgpic= bgpic->next) {
                                                bgpic->ima= restore_pointer_by_name(newmain, (ID *)bgpic->ima, 1);
+                                               bgpic->clip= restore_pointer_by_name(newmain, (ID *)bgpic->clip, 1);
                                        }
                                        if(v3d->localvd) {
                                                /*Base *base;*/
@@ -5185,17 +5273,28 @@ void lib_link_screen_restore(Main *newmain, bScreen *curscreen, Scene *curscene)
                                        snode->id= restore_pointer_by_name(newmain, snode->id, 1);
                                        snode->edittree= NULL;
                                        
-                                       if(snode->id==NULL)
+                                       if (ELEM3(snode->treetype, NTREE_COMPOSIT, NTREE_SHADER, NTREE_TEXTURE)) {
                                                snode->nodetree= NULL;
+                                               if(snode->id) {
+                                                       if(GS(snode->id->name)==ID_MA)
+                                                               snode->nodetree= ((Material *)snode->id)->nodetree;
+                                                       else if(GS(snode->id->name)==ID_SCE)
+                                                               snode->nodetree= ((Scene *)snode->id)->nodetree;
+                                                       else if(GS(snode->id->name)==ID_TE)
+                                                               snode->nodetree= ((Tex *)snode->id)->nodetree;
+                                               }
+                                       }
                                        else {
-                                               if(GS(snode->id->name)==ID_MA)
-                                                       snode->nodetree= ((Material *)snode->id)->nodetree;
-                                               else if(GS(snode->id->name)==ID_SCE)
-                                                       snode->nodetree= ((Scene *)snode->id)->nodetree;
-                                               else if(GS(snode->id->name)==ID_TE)
-                                                       snode->nodetree= ((Tex *)snode->id)->nodetree;
+                                               snode->nodetree= restore_pointer_by_name(newmain, &snode->nodetree->id, 1);
                                        }
                                }
+                               else if(sl->spacetype==SPACE_CLIP) {
+                                       SpaceClip *sclip= (SpaceClip *)sl;
+
+                                       sclip->clip= restore_pointer_by_name(newmain, (ID *)sclip->clip, 1);
+
+                                       sclip->scopes.ok = 0;
+                               }
                        }
                        sa= sa->next;
                }
@@ -5422,7 +5521,6 @@ static void direct_link_screen(FileData *fd, bScreen *sc)
                                        snode->gpd= newdataadr(fd, snode->gpd);
                                        direct_link_gpencil(fd, snode->gpd);
                                }
-                               snode->nodetree= snode->edittree= NULL;
                        }
                        else if(sl->spacetype==SPACE_TIME) {
                                SpaceTime *stime= (SpaceTime *)sl;
@@ -5675,6 +5773,51 @@ static void lib_link_group(FileData *fd, Main *main)
        }
 }
 
+/* ***************** READ MOVIECLIP *************** */
+
+static void direct_link_movieclip(FileData *fd, MovieClip *clip)
+{
+       MovieTracking *tracking= &clip->tracking;
+       MovieTrackingTrack *track;
+
+       if(fd->movieclipmap) clip->cache= newmclipadr(fd, clip->cache);
+       else clip->cache= NULL;
+
+       tracking->reconstruction.cameras= newdataadr(fd, tracking->reconstruction.cameras);
+
+       link_list(fd, &tracking->tracks);
+
+       track= tracking->tracks.first;
+       while(track) {
+               track->markers= newdataadr(fd, track->markers);
+
+               track= track->next;
+       }
+
+       clip->tracking.act_track= newdataadr(fd, clip->tracking.act_track);
+
+       clip->anim= NULL;
+       clip->tracking_context= NULL;
+
+       clip->tracking.stabilization.ok= 0;
+       clip->tracking.stabilization.scaleibuf= NULL;
+}
+
+static void lib_link_movieclip(FileData *fd, Main *main)
+{
+       MovieClip *clip;
+
+       clip= main->movieclip.first;
+       while(clip) {
+               if(clip->id.flag & LIB_NEEDLINK) {
+                       clip->gpd= newlibadr_us(fd, clip->id.lib, clip->gpd);
+
+                       clip->id.flag -= LIB_NEEDLINK;
+               }
+               clip= clip->id.next;
+       }
+}
+
 /* ************** GENERAL & MAIN ******************** */
 
 
@@ -5709,6 +5852,7 @@ static const char *dataname(short id_code)
                case ID_BR: return "Data from BR";
                case ID_PA: return "Data from PA";
                case ID_GD: return "Data from GD";
+               case ID_MC: return "Data from MC";
        }
        return "Data from Lib Block";
        
@@ -5878,6 +6022,9 @@ static BHead *read_libblock(FileData *fd, Main *main, BHead *bhead, int flag, ID
                case ID_GD:
                        direct_link_gpencil(fd, (bGPdata *)id);
                        break;
+               case ID_MC:
+                       direct_link_movieclip(fd, (MovieClip *)id);
+                       break;
        }
        
        /*link direct data of ID properties*/
@@ -6931,6 +7078,62 @@ static void do_version_bone_roll_256(Bone *bone)
                do_version_bone_roll_256(child);
 }
 
+static void do_versions_socket_default_value(bNodeSocket *sock)
+{
+       bNodeSocketValueFloat *valfloat;
+       bNodeSocketValueVector *valvector;
+       bNodeSocketValueRGBA *valrgba;
+       
+       if (sock->default_value)
+               return;
+       
+       switch (sock->type) {
+       case SOCK_FLOAT:
+               valfloat = sock->default_value = MEM_callocN(sizeof(bNodeSocketValueFloat), "default socket value");
+               valfloat->value = sock->ns.vec[0];
+               valfloat->min = sock->ns.min;
+               valfloat->max = sock->ns.max;
+               valfloat->subtype = PROP_NONE;
+               break;
+       case SOCK_VECTOR:
+               valvector = sock->default_value = MEM_callocN(sizeof(bNodeSocketValueVector), "default socket value");
+               copy_v3_v3(valvector->value, sock->ns.vec);
+               valvector->min = sock->ns.min;
+               valvector->max = sock->ns.max;
+               valvector->subtype = PROP_NONE;
+               break;
+       case SOCK_RGBA:
+               valrgba = sock->default_value = MEM_callocN(sizeof(bNodeSocketValueRGBA), "default socket value");
+               copy_v4_v4(valrgba->value, sock->ns.vec);
+               break;
+       }
+}
+
+static void do_versions_nodetree_default_value(bNodeTree *ntree)
+{
+       bNode *node;
+       bNodeSocket *sock;
+       for (node=ntree->nodes.first; node; node=node->next) {
+               for (sock=node->inputs.first; sock; sock=sock->next)
+                       do_versions_socket_default_value(sock);
+               for (sock=node->outputs.first; sock; sock=sock->next)
+                       do_versions_socket_default_value(sock);
+       }
+       for (sock=ntree->inputs.first; sock; sock=sock->next)
+               do_versions_socket_default_value(sock);
+       for (sock=ntree->outputs.first; sock; sock=sock->next)
+               do_versions_socket_default_value(sock);
+}
+
+static void do_versions_nodetree_dynamic_sockets(bNodeTree *ntree)
+{
+       bNodeSocket *sock;
+       for (sock=ntree->inputs.first; sock; sock=sock->next)
+               sock->flag |= SOCK_DYNAMIC;
+       for (sock=ntree->outputs.first; sock; sock=sock->next)
+               sock->flag |= SOCK_DYNAMIC;
+}
+
 static void do_versions(FileData *fd, Library *lib, Main *main)
 {
        /* WATCH IT!!!: pointers from libdata have not been converted */
@@ -10081,7 +10284,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                                           !(seq->flag & SEQ_USE_PROXY_CUSTOM_DIR))
                                        {
                                                
-                                               snprintf(seq->strip->proxy->dir, 
+                                               BLI_snprintf(seq->strip->proxy->dir, 
                                                         FILE_MAXDIR, "%s/BL_proxy", 
                                                         seq->strip->dir);
                                        }
@@ -11582,7 +11785,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                         * is done in lib_verify_nodetree, because at this point the internal
                         * nodes may not be up-to-date! (missing lib-link)
                         */
-                       ntree->flag |= NTREE_DO_VERSIONS;
+                       ntree->flag |= NTREE_DO_VERSIONS_GROUP_EXPOSE;
                }
        }
 
@@ -11707,10 +11910,10 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                                if(tex->pd) {
                                        if (tex->pd->falloff_speed_scale == 0.0f)
                                                tex->pd->falloff_speed_scale = 100.0f;
-
+                                       
                                        if (!tex->pd->falloff_curve) {
                                                tex->pd->falloff_curve = curvemapping_add(1, 0, 0, 1, 1);
-
+                                               
                                                tex->pd->falloff_curve->preset = CURVE_PRESET_LINE;
                                                tex->pd->falloff_curve->cm->flag &= ~CUMA_EXTEND_EXTRAPOLATE;
                                                curvemap_reset(tex->pd->falloff_curve->cm, &tex->pd->falloff_curve->clipr, tex->pd->falloff_curve->preset, CURVEMAP_SLOPE_POSITIVE);
@@ -11861,10 +12064,111 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                }
        }
 
+       if (main->versionfile < 259 || (main->versionfile == 259 && main->subversionfile < 2)){
+               {
+                       /* Convert default socket values from bNodeStack */
+                       Scene *sce;
+                       Material *mat;
+                       Tex *tex;
+                       bNodeTree *ntree;
+                       for (ntree=main->nodetree.first; ntree; ntree=ntree->id.next) {
+                               do_versions_nodetree_default_value(ntree);
+                               ntree->update |= NTREE_UPDATE;
+                       }
+                       for (sce=main->scene.first; sce; sce=sce->id.next)
+                               if (sce->nodetree) {
+                               do_versions_nodetree_default_value(sce->nodetree);
+                               sce->nodetree->update |= NTREE_UPDATE;
+                       }
+                       for (mat=main->mat.first; mat; mat=mat->id.next)
+                               if (mat->nodetree) {
+                               do_versions_nodetree_default_value(mat->nodetree);
+                               mat->nodetree->update |= NTREE_UPDATE;
+                       }
+                       for (tex=main->tex.first; tex; tex=tex->id.next)
+                               if (tex->nodetree) {
+                               do_versions_nodetree_default_value(tex->nodetree);
+                               tex->nodetree->update |= NTREE_UPDATE;
+                       }
+               }
+
+               /* add SOCK_DYNAMIC flag to existing group sockets */
+               {
+                       bNodeTree *ntree;
+                       /* only need to do this for trees in main, local trees are not used as groups */
+                       for (ntree=main->nodetree.first; ntree; ntree=ntree->id.next) {
+                               do_versions_nodetree_dynamic_sockets(ntree);
+                               ntree->update |= NTREE_UPDATE;
+                       }
+               }
+
+               {
+                       /* Initialize group tree nodetypes.
+                        * These are used to distinguish tree types and
+                        * associate them with specific node types for polling.
+                        */
+                       bNodeTree *ntree;
+                       /* all node trees in main->nodetree are considered groups */
+                       for (ntree=main->nodetree.first; ntree; ntree=ntree->id.next)
+                               ntree->nodetype = NODE_GROUP;
+               }
+       }
+
        /* put compatibility code here until next subversion bump */
 
        {
+               bScreen *sc;
+               Camera *cam;
+               MovieClip *clip;
 
+               for (sc= main->screen.first; sc; sc= sc->id.next) {
+                       ScrArea *sa;
+                       for (sa= sc->areabase.first; sa; sa= sa->next) {
+                               SpaceLink *sl;
+                               for (sl= sa->spacedata.first; sl; sl= sl->next) {
+                                       if(sl->spacetype==SPACE_VIEW3D) {
+                                               View3D *v3d= (View3D *)sl;
+
+                                               if(v3d->bundle_size==0.0f) {
+                                                       v3d->bundle_size= 0.1f;
+                                                       v3d->flag2 |= V3D_SHOW_RECONSTRUCTION;
+                                               }
+
+                                               if(v3d->bundle_drawtype==0)
+                                                       v3d->bundle_drawtype= OB_EMPTY_SPHERE;
+                                       }
+                                       else if(sl->spacetype==SPACE_CLIP) {
+                                               SpaceClip *sclip= (SpaceClip *)sl;
+                                               if(sclip->scopes.track_preview_height==0)
+                                                       sclip->scopes.track_preview_height= 120;
+                                       }
+                               }
+                       }
+               }
+
+               for (clip= main->movieclip.first; clip; clip= clip->id.next) {
+                       if(clip->aspx<1.0f) {
+                               clip->aspx= 1.0f;
+                               clip->aspy= 1.0f;
+                       }
+
+                       /* XXX: a bit hacky, probably include imbuf and use real constants are nicer */
+                       clip->proxy.build_tc_flags= 7;
+                       if(clip->proxy.build_size_flags==0)
+                               clip->proxy.build_size_flags= 1;
+
+                       if(clip->proxy.quality==0)
+                               clip->proxy.quality= 90;
+
+                       if(clip->tracking.camera.pixel_aspect<0.01f)
+                               clip->tracking.camera.pixel_aspect= 1.f;
+               }
+
+               for(cam= main->camera.first; cam; cam= cam->id.next) {
+                       if (cam->sensor_x < 0.01f) {
+                               cam->sensor_x = 32.f;
+                       }
+               }
        }
 
        /* WATCH IT!!!: pointers from libdata have not been converted yet here! */
@@ -11911,6 +12215,7 @@ static void lib_link_all(FileData *fd, Main *main)
        lib_link_nodetree(fd, main);    /* has to be done after scene/materials, this will verify group nodes */
        lib_link_brush(fd, main);
        lib_link_particlesettings(fd, main);
+       lib_link_movieclip(fd, main);
 
        lib_link_mesh(fd, main);                /* as last: tpage images with users at zero */