Merged changes in the trunk up to revision 54802.
[blender.git] / source / blender / blenloader / intern / writefile.c
index 8208cca981ebc468ae4cac6cb62864360b531558..50e1e229ebac89449eafb47f9e1ab5542be33568 100644 (file)
@@ -89,6 +89,8 @@
 #  include "BLI_winstuff.h"
 #endif
 
+#include "BLI_utildefines.h"
+
 /* allow writefile to use deprecated functionality (for forward compatibility code) */
 #define DNA_DEPRECATED_ALLOW
 
 #include "DNA_key_types.h"
 #include "DNA_lattice_types.h"
 #include "DNA_lamp_types.h"
-#include "DNA_linestyle_types.h"
+#ifdef WITH_FREESTYLE
+#  include "DNA_linestyle_types.h"
+#endif
 #include "DNA_meta_types.h"
 #include "DNA_mesh_types.h"
 #include "DNA_meshdata_types.h"
 #include "DNA_packedFile_types.h"
 #include "DNA_particle_types.h"
 #include "DNA_property_types.h"
+#include "DNA_rigidbody_types.h"
 #include "DNA_scene_types.h"
 #include "DNA_sdna_types.h"
 #include "DNA_sequence_types.h"
@@ -198,7 +203,7 @@ static WriteData *writedata_new(int file)
 
        if (wd == NULL) return NULL;
 
-       wd->sdna = DNA_sdna_from_data(DNAstr, DNAlen, 0);
+       wd->sdna = DNA_sdna_from_data(DNAstr, DNAlen, false);
 
        wd->file= file;
 
@@ -851,8 +856,12 @@ static void write_userdef(WriteData *wd)
                        write_keymapitem(wd, kmi);
        }
 
-       for (bext= U.addons.first; bext; bext=bext->next)
+       for (bext= U.addons.first; bext; bext=bext->next) {
                writestruct(wd, DATA, "bAddon", 1, bext);
+               if (bext->prop) {
+                       IDP_WriteProperty(bext->prop, wd);
+               }
+       }
        
        for (style= U.uistyles.first; style; style= style->next) {
                writestruct(wd, DATA, "uiStyle", 1, style);
@@ -1229,7 +1238,7 @@ static void write_constraints(WriteData *wd, ListBase *conlist)
        bConstraint *con;
 
        for (con=conlist->first; con; con=con->next) {
-               bConstraintTypeInfo *cti= constraint_get_typeinfo(con);
+               bConstraintTypeInfo *cti= BKE_constraint_get_typeinfo(con);
                
                /* Write the specific data */
                if (cti && con->data) {
@@ -1417,8 +1426,8 @@ static void write_modifiers(WriteData *wd, ListBase *modbase)
                        int size = mmd->dyngridsize;
 
                        writestruct(wd, DATA, "MDefInfluence", mmd->totinfluence, mmd->bindinfluences);
-                       writedata(wd, DATA, sizeof(int)*(mmd->totvert+1), mmd->bindoffsets);
-                       writedata(wd, DATA, sizeof(float)*3*mmd->totcagevert,
+                       writedata(wd, DATA, sizeof(int) * (mmd->totvert + 1), mmd->bindoffsets);
+                       writedata(wd, DATA, sizeof(float) * 3 * mmd->totcagevert,
                                mmd->bindcagecos);
                        writestruct(wd, DATA, "MDefCell", size*size*size, mmd->dyngrid);
                        writestruct(wd, DATA, "MDefInfluence", mmd->totinfluence, mmd->dyninfluences);
@@ -1484,6 +1493,14 @@ static void write_objects(WriteData *wd, ListBase *idbase)
                        }
                        writestruct(wd, DATA, "BulletSoftBody", 1, ob->bsoft);
                        
+                       if (ob->rigidbody_object) {
+                               // TODO: if any extra data is added to handle duplis, will need separate function then
+                               writestruct(wd, DATA, "RigidBodyOb", 1, ob->rigidbody_object);
+                       }
+                       if (ob->rigidbody_constraint) {
+                               writestruct(wd, DATA, "RigidBodyCon", 1, ob->rigidbody_constraint);
+                       }
+
                        write_particlesystems(wd, &ob->particlesystem);
                        write_modifiers(wd, &ob->modifiers);
                }
@@ -1675,7 +1692,7 @@ static void write_mdisps(WriteData *wd, int count, MDisps *mdlist, int external)
                        MDisps *md = &mdlist[i];
                        if (md->disps) {
                                if (!external)
-                                       writedata(wd, DATA, sizeof(float)*3*md->totdisp, md->disps);
+                                       writedata(wd, DATA, sizeof(float) * 3 * md->totdisp, md->disps);
                        }
                        
                        if (md->hidden)
@@ -2160,8 +2177,6 @@ static void write_scenes(WriteData *wd, ListBase *scebase)
        TimeMarker *marker;
        TransformOrientation *ts;
        SceneRenderLayer *srl;
-       FreestyleModuleConfig *fmc;
-       FreestyleLineSet *fls;
        ToolSettings *tos;
        
        sce= scebase->first;
@@ -2289,14 +2304,21 @@ static void write_scenes(WriteData *wd, ListBase *scebase)
                for (srl = sce->r.layers.first; srl; srl = srl->next) {
                        writestruct(wd, DATA, "SceneRenderLayer", 1, srl);
                        
-                       for(fmc = srl->freestyleConfig.modules.first; fmc; fmc = fmc->next) {
-                               writestruct(wd, DATA, "FreestyleModuleConfig", 1, fmc);
-                       }
+#ifdef WITH_FREESTYLE
+                       {
+                               FreestyleModuleConfig *fmc;
+                               FreestyleLineSet *fls;
+
+                               for(fmc = srl->freestyleConfig.modules.first; fmc; fmc = fmc->next) {
+                                       writestruct(wd, DATA, "FreestyleModuleConfig", 1, fmc);
+                               }
                        
-                       for(fls = srl->freestyleConfig.linesets.first; fls; fls = fls->next) {
-                               writestruct(wd, DATA, "FreestyleLineSet", 1, fls);
-                       }
+                               for(fls = srl->freestyleConfig.linesets.first; fls; fls = fls->next) {
+                                       writestruct(wd, DATA, "FreestyleLineSet", 1, fls);
+                               }
 
+                       }
+#endif
                }
                
                if (sce->nodetree) {
@@ -2305,7 +2327,14 @@ static void write_scenes(WriteData *wd, ListBase *scebase)
                }
 
                write_view_settings(wd, &sce->view_settings);
-
+               
+               /* writing RigidBodyWorld data to the blend file */
+               if (sce->rigidbody_world) {
+                       writestruct(wd, DATA, "RigidBodyWorld", 1, sce->rigidbody_world);
+                       writestruct(wd, DATA, "EffectorWeights", 1, sce->rigidbody_world->effector_weights);
+                       write_pointcaches(wd, &(sce->rigidbody_world->ptcaches));
+               }
+               
                sce= sce->id.next;
        }
        /* flush helps the compression for undo-save */
@@ -2408,6 +2437,7 @@ static void write_screens(WriteData *wd, ListBase *scrbase)
                for (sa= sc->areabase.first; sa; sa= sa->next) {
                        SpaceLink *sl;
                        Panel *pa;
+                       uiList *ui_list;
                        ARegion *ar;
                        
                        writestruct(wd, DATA, "ScrArea", 1, sa);
@@ -2417,6 +2447,9 @@ static void write_screens(WriteData *wd, ListBase *scrbase)
                                
                                for (pa= ar->panels.first; pa; pa= pa->next)
                                        writestruct(wd, DATA, "Panel", 1, pa);
+                               
+                               for (ui_list = ar->ui_lists.first; ui_list; ui_list = ui_list->next)
+                                       writestruct(wd, DATA, "uiList", 1, ui_list);
                        }
                        
                        sl= sa->spacedata.first;
@@ -2544,20 +2577,35 @@ static void write_libraries(WriteData *wd, Main *main)
                a=tot= set_listbasepointers(main, lbarray);
 
                /* test: is lib being used */
-               foundone = FALSE;
-               while (tot--) {
-                       for (id= lbarray[tot]->first; id; id= id->next) {
-                               if (id->us>0 && (id->flag & LIB_EXTERN)) {
-                                       foundone = TRUE;
-                                       break;
+               if (main->curlib && main->curlib->packedfile)
+                       foundone = TRUE;
+               else {
+                       foundone = FALSE;
+                       while (tot--) {
+                               for (id= lbarray[tot]->first; id; id= id->next) {
+                                       if (id->us>0 && (id->flag & LIB_EXTERN)) {
+                                               foundone = TRUE;
+                                               break;
+                                       }
                                }
+                               if (foundone) break;
                        }
-                       if (foundone) break;
                }
-
+               
+               /* to be able to restore quit.blend and temp saves, the packed blend has to be in undo buffers... */
+               /* XXX needs rethink, just like save UI in undo files now - would be nice to append things only for the]
+                  quit.blend and temp saves */
                if (foundone) {
                        writestruct(wd, ID_LI, "Library", 1, main->curlib);
 
+                       if (main->curlib->packedfile) {
+                               PackedFile *pf = main->curlib->packedfile;
+                               writestruct(wd, DATA, "PackedFile", 1, pf);
+                               writedata(wd, DATA, pf->size, pf->data);
+                               if (wd->current == NULL)
+                                       printf("write packed .blend: %s\n", main->curlib->name);
+                       }
+                       
                        while (a--) {
                                for (id= lbarray[a]->first; id; id= id->next) {
                                        if (id->us>0 && (id->flag & LIB_EXTERN)) {
@@ -2876,6 +2924,7 @@ static void write_masks(WriteData *wd, ListBase *idbase)
        mywrite(wd, MYWRITE_FLUSH, 0);
 }
 
+#ifdef WITH_FREESTYLE
 static void write_linestyle_color_modifiers(WriteData *wd, ListBase *modifiers)
 {
        LineStyleModifier *m;
@@ -3076,6 +3125,7 @@ static void write_linestyles(WriteData *wd, ListBase *idbase)
                }
        }
 }
+#endif
 
 /* context is usually defined by WM, two cases where no WM is available:
  * - for forward compatibility, curscreen has to be saved
@@ -3183,7 +3233,9 @@ static int write_file_handle(Main *mainvar, int handle, MemFile *compare, MemFil
        write_brushes  (wd, &mainvar->brush);
        write_scripts  (wd, &mainvar->script);
        write_gpencils (wd, &mainvar->gpencil);
+#ifdef WITH_FREESTYLE
        write_linestyles(wd, &mainvar->linestyle);
+#endif
        write_libraries(wd,  mainvar->next);
 
        if (write_user_block) {