style cleanup
[blender.git] / source / blender / blenloader / intern / writefile.c
index 297eb6027ae36e82e68fc3cc6cb4e5b9d351c5a5..b73485add3db1f1831d1897642aa79b0314a8d92 100644 (file)
 
 
 /*
-FILEFORMAT: IFF-style structure  (but not IFF compatible!)
-
-start file:
      BLENDER_V100    12 bytes  (versie 1.00)
                                      V = big endian, v = little endian
                                      _ = 4 byte pointer, - = 8 byte pointer
-
-datablocks:            also see struct BHead
      <bh.code>                       4 chars
      <bh.len>                        int,  len data after BHead
      <bh.old>                        void,  old pointer
      <bh.SDNAnr>                     int
      <bh.nr>                         int, in case of array: amount of structs
      data
      ...
      ...
-
-Almost all data in Blender are structures. Each struct saved
-gets a BHead header.  With BHead the struct can be linked again
-and compared with StructDNA .
-
-WRITE
-
-Preferred writing order: (not really a must, but why would you do it random?)
-Any case: direct data is ALWAYS after the lib block
-
-(Local file data)
-- for each LibBlock
      - write LibBlock
      - write associated direct data
-(External file data)
-- per library
      - write library block
      - per LibBlock
              - write the ID of LibBlock
-- write TEST (128x128, blend file preview, optional)
-- write FileGlobal (some global vars)
-- write SDNA
-- write USER if filename is ~/X.XX/config/startup.blend
-*/
+ * FILEFORMAT: IFF-style structure  (but not IFF compatible!)
+ *
+ * start file:
*     BLENDER_V100    12 bytes  (versie 1.00)
*                     V = big endian, v = little endian
*                     _ = 4 byte pointer, - = 8 byte pointer
+ *
+ * datablocks:     also see struct BHead
*     <bh.code>           4 chars
*     <bh.len>            int,  len data after BHead
*     <bh.old>            void,  old pointer
*     <bh.SDNAnr>         int
*     <bh.nr>             int, in case of array: amount of structs
*     data
*     ...
*     ...
+ *
+ * Almost all data in Blender are structures. Each struct saved
+ * gets a BHead header.  With BHead the struct can be linked again
+ * and compared with StructDNA .
+ *
+ * WRITE
+ *
+ * Preferred writing order: (not really a must, but why would you do it random?)
+ * Any case: direct data is ALWAYS after the lib block
+ *
+ * (Local file data)
+ * - for each LibBlock
*     - write LibBlock
*     - write associated direct data
+ * (External file data)
+ * - per library
*     - write library block
*     - per LibBlock
*         - write the ID of LibBlock
+ * - write TEST (128x128, blend file preview, optional)
+ * - write FileGlobal (some global vars)
+ * - write SDNA
+ * - write USER if filename is ~/X.XX/config/startup.blend
+ */
 
 
 #include <math.h>
@@ -133,6 +133,7 @@ Any case: direct data is ALWAYS after the lib block
 #include "DNA_world_types.h"
 #include "DNA_windowmanager_types.h"
 #include "DNA_movieclip_types.h"
+#include "DNA_mask_types.h"
 
 #include "MEM_guardedalloc.h" // MEM_freeN
 #include "BLI_bitmap.h"
@@ -153,7 +154,6 @@ Any case: direct data is ALWAYS after the lib block
 #include "BKE_report.h"
 #include "BKE_sequencer.h"
 #include "BKE_subsurf.h"
-#include "BKE_utildefines.h"
 #include "BKE_modifier.h"
 #include "BKE_fcurve.h"
 #include "BKE_pointcache.h"
@@ -162,6 +162,7 @@ Any case: direct data is ALWAYS after the lib block
 #include "BLO_writefile.h"
 #include "BLO_readfile.h"
 #include "BLO_undofile.h"
+#include "BLO_blend_defs.h"
 
 #include "readfile.h"
 
@@ -645,15 +646,21 @@ static void write_animdata(WriteData *wd, AnimData *adt)
        write_nladata(wd, &adt->nla_tracks);
 }
 
-static void write_curvemapping(WriteData *wd, CurveMapping *cumap)
+static void write_curvemapping_curves(WriteData *wd, CurveMapping *cumap)
 {
        int a;
-       
-       writestruct(wd, DATA, "CurveMapping", 1, cumap);
-       for (a=0; a<CM_TOT; a++)
+
+       for (a = 0; a < CM_TOT; a++)
                writestruct(wd, DATA, "CurveMapPoint", cumap->cm[a].totpoint, cumap->cm[a].curve);
 }
 
+static void write_curvemapping(WriteData *wd, CurveMapping *cumap)
+{
+       writestruct(wd, DATA, "CurveMapping", 1, cumap);
+
+       write_curvemapping_curves(wd, cumap);
+}
+
 static void write_node_socket(WriteData *wd, bNodeSocket *sock)
 {
        bNodeSocketType *stype= ntreeGetSocketType(sock->type);
@@ -715,7 +722,7 @@ static void write_nodetree(WriteData *wd, bNodeTree *ntree)
                        write_node_socket(wd, sock);
 
                
-               if (node->storage && node->type!=NODE_DYNAMIC) {
+               if (node->storage) {
                        /* could be handlerized at some point, now only 1 exception still */
                        if (ntree->type==NTREE_SHADER && (node->type==SH_NODE_CURVE_VEC || node->type==SH_NODE_CURVE_RGB))
                                write_curvemapping(wd, node->storage);
@@ -723,8 +730,9 @@ static void write_nodetree(WriteData *wd, bNodeTree *ntree)
                                write_curvemapping(wd, node->storage);
                        else if (ntree->type==NTREE_TEXTURE && (node->type==TEX_NODE_CURVE_RGB || node->type==TEX_NODE_CURVE_TIME) )
                                write_curvemapping(wd, node->storage);
-                       else if (ntree->type==NTREE_COMPOSIT && node->type==CMP_NODE_MOVIEDISTORTION)
-                               /* pass */;
+                       else if (ntree->type==NTREE_COMPOSIT && node->type==CMP_NODE_MOVIEDISTORTION) {
+                               /* pass */
+                       }
                        else
                                writestruct(wd, DATA, node->typeinfo->storagename, 1, node->storage);
                }
@@ -1379,14 +1387,14 @@ static void write_modifiers(WriteData *wd, ListBase *modbase)
                } 
                else if (md->type==eModifierType_Collision) {
                        
-                       /*
+#if 0
                        CollisionModifierData *collmd = (CollisionModifierData*) md;
                        // TODO: CollisionModifier should use pointcache 
                        // + have proper reset events before enabling this
                        writestruct(wd, DATA, "MVert", collmd->numverts, collmd->x);
                        writestruct(wd, DATA, "MVert", collmd->numverts, collmd->xnew);
                        writestruct(wd, DATA, "MFace", collmd->numfaces, collmd->mfaces);
-                       */
+#endif
                }
                else if (md->type==eModifierType_MeshDeform) {
                        MeshDeformModifierData *mmd = (MeshDeformModifierData*) md;
@@ -1662,17 +1670,17 @@ static void write_mdisps(WriteData *wd, int count, MDisps *mdlist, int external)
 
 static void write_grid_paint_mask(WriteData *wd, int count, GridPaintMask *grid_paint_mask)
 {
-       if(grid_paint_mask) {
+       if (grid_paint_mask) {
                int i;
                
                writestruct(wd, DATA, "GridPaintMask", count, grid_paint_mask);
-               for(i = 0; i < count; ++i) {
+               for (i = 0; i < count; ++i) {
                        GridPaintMask *gpm = &grid_paint_mask[i];
-                       if(gpm->data) {
+                       if (gpm->data) {
                                const int gridsize = ccg_gridsize(gpm->level);
                                writedata(wd, DATA,
-                                                 sizeof(*gpm->data) * gridsize * gridsize,
-                                                 gpm->data);
+                                         sizeof(*gpm->data) * gridsize * gridsize,
+                                         gpm->data);
                        }
                }
        }
@@ -1814,7 +1822,7 @@ static void write_meshs(WriteData *wd, ListBase *idbase)
                                /* backup */
 
 
-                               /* now fill in polys to mfaces*/
+                               /* now fill in polys to mfaces */
                                mesh->totface = BKE_mesh_mpoly_to_mface(&mesh->fdata, &backup_mesh.ldata, &backup_mesh.pdata,
                                                                        mesh->totface, backup_mesh.totloop, backup_mesh.totpoly);
 
@@ -1957,7 +1965,6 @@ static void write_textures(WriteData *wd, ListBase *idbase)
                        if (tex->adt) write_animdata(wd, tex->adt);
 
                        /* direct data */
-                       if (tex->type == TEX_PLUGIN && tex->plugin) writestruct(wd, DATA, "PluginTex", 1, tex->plugin);
                        if (tex->coba) writestruct(wd, DATA, "ColorBand", 1, tex->coba);
                        if (tex->type == TEX_ENVMAP && tex->env) writestruct(wd, DATA, "EnvMap", 1, tex->env);
                        if (tex->type == TEX_POINTDENSITY && tex->pd) {
@@ -2086,6 +2093,39 @@ static void write_lamps(WriteData *wd, ListBase *idbase)
        }
 }
 
+static void write_sequence_modifiers(WriteData *wd, ListBase *modbase)
+{
+       SequenceModifierData *smd;
+
+       for (smd = modbase->first; smd; smd = smd->next) {
+               SequenceModifierTypeInfo *smti = BKE_sequence_modifier_type_info_get(smd->type);
+
+               if (smti) {
+                       writestruct(wd, DATA, smti->struct_name, 1, smd);
+
+                       if (smd->type == seqModifierType_Curves) {
+                               CurvesModifierData *cmd = (CurvesModifierData *) smd;
+
+                               write_curvemapping(wd, &cmd->curve_mapping);
+                       }
+                       else if (smd->type == seqModifierType_HueCorrect) {
+                               HueCorrectModifierData *hcmd = (HueCorrectModifierData *) smd;
+
+                               write_curvemapping(wd, &hcmd->curve_mapping);
+                       }
+               }
+               else {
+                       writestruct(wd, DATA, "SequenceModifierData", 1, smd);
+               }
+       }
+}
+
+static void write_view_settings(WriteData *wd, ColorManagedViewSettings *view_settings)
+{
+       if (view_settings->curve_mapping) {
+               write_curvemapping(wd, view_settings->curve_mapping);
+       }
+}
 
 static void write_scenes(WriteData *wd, ListBase *scebase)
 {
@@ -2151,22 +2191,21 @@ static void write_scenes(WriteData *wd, ListBase *scebase)
                                if (seq->strip && seq->strip->done==0) {
                                        /* write strip with 'done' at 0 because readfile */
                                        
-                                       if (seq->plugin) writestruct(wd, DATA, "PluginSeq", 1, seq->plugin);
                                        if (seq->effectdata) {
                                                switch (seq->type) {
-                                               case SEQ_COLOR:
+                                               case SEQ_TYPE_COLOR:
                                                        writestruct(wd, DATA, "SolidColorVars", 1, seq->effectdata);
                                                        break;
-                                               case SEQ_SPEED:
+                                               case SEQ_TYPE_SPEED:
                                                        writestruct(wd, DATA, "SpeedControlVars", 1, seq->effectdata);
                                                        break;
-                                               case SEQ_WIPE:
+                                               case SEQ_TYPE_WIPE:
                                                        writestruct(wd, DATA, "WipeVars", 1, seq->effectdata);
                                                        break;
-                                               case SEQ_GLOW:
+                                               case SEQ_TYPE_GLOW:
                                                        writestruct(wd, DATA, "GlowVars", 1, seq->effectdata);
                                                        break;
-                                               case SEQ_TRANSFORM:
+                                               case SEQ_TYPE_TRANSFORM:
                                                        writestruct(wd, DATA, "TransformVars", 1, seq->effectdata);
                                                        break;
                                                }
@@ -2183,16 +2222,15 @@ static void write_scenes(WriteData *wd, ListBase *scebase)
                                        if (seq->flag & SEQ_USE_PROXY && strip->proxy) {
                                                writestruct(wd, DATA, "StripProxy", 1, strip->proxy);
                                        }
-                                       if (seq->flag & SEQ_USE_COLOR_BALANCE && strip->color_balance) {
-                                               writestruct(wd, DATA, "StripColorBalance", 1, strip->color_balance);
-                                       }
-                                       if (seq->type==SEQ_IMAGE)
+                                       if (seq->type==SEQ_TYPE_IMAGE)
                                                writestruct(wd, DATA, "StripElem", MEM_allocN_len(strip->stripdata) / sizeof(struct StripElem), strip->stripdata);
-                                       else if (seq->type==SEQ_MOVIE || seq->type==SEQ_RAM_SOUND || seq->type == SEQ_HD_SOUND)
+                                       else if (seq->type==SEQ_TYPE_MOVIE || seq->type==SEQ_TYPE_SOUND_RAM || seq->type == SEQ_TYPE_SOUND_HD)
                                                writestruct(wd, DATA, "StripElem", 1, strip->stripdata);
                                        
                                        strip->done = TRUE;
                                }
+
+                               write_sequence_modifiers(wd, &seq->modifiers);
                        }
                        SEQ_END
                                
@@ -2231,7 +2269,9 @@ static void write_scenes(WriteData *wd, ListBase *scebase)
                        writestruct(wd, DATA, "bNodeTree", 1, sce->nodetree);
                        write_nodetree(wd, sce->nodetree);
                }
-               
+
+               write_view_settings(wd, &sce->view_settings);
+
                sce= sce->id.next;
        }
        /* flush helps the compression for undo-save */
@@ -2492,7 +2532,7 @@ static void write_libraries(WriteData *wd, Main *main)
        }
 }
 
-static void write_bone(WriteData *wd, Bonebone)
+static void write_bone(WriteData *wd, Bone *bone)
 {
        Bone*   cbone;
 
@@ -2754,6 +2794,59 @@ static void write_movieclips(WriteData *wd, ListBase *idbase)
        mywrite(wd, MYWRITE_FLUSH, 0);
 }
 
+static void write_masks(WriteData *wd, ListBase *idbase)
+{
+       Mask *mask;
+
+       mask = idbase->first;
+       while (mask) {
+               if (mask->id.us > 0 || wd->current) {
+                       MaskLayer *masklay;
+
+                       writestruct(wd, ID_MSK, "Mask", 1, mask);
+
+                       if (mask->adt)
+                               write_animdata(wd, mask->adt);
+
+                       for (masklay = mask->masklayers.first; masklay; masklay = masklay->next) {
+                               MaskSpline *spline;
+                               MaskLayerShape *masklay_shape;
+
+                               writestruct(wd, DATA, "MaskLayer", 1, masklay);
+
+                               for (spline = masklay->splines.first; spline; spline = spline->next) {
+                                       int i;
+
+                                       void *points_deform = spline->points_deform;
+                                       spline->points_deform = NULL;
+
+                                       writestruct(wd, DATA, "MaskSpline", 1, spline);
+                                       writestruct(wd, DATA, "MaskSplinePoint", spline->tot_point, spline->points);
+
+                                       spline->points_deform = points_deform;
+
+                                       for (i = 0; i < spline->tot_point; i++) {
+                                               MaskSplinePoint *point = &spline->points[i];
+
+                                               if (point->tot_uw)
+                                                       writestruct(wd, DATA, "MaskSplinePointUW", point->tot_uw, point->uw);
+                                       }
+                               }
+
+                               for (masklay_shape = masklay->splines_shapes.first; masklay_shape; masklay_shape = masklay_shape->next) {
+                                       writestruct(wd, DATA, "MaskLayerShape", 1, masklay_shape);
+                                       writedata(wd, DATA, masklay_shape->tot_vert * sizeof(float) * MASK_OBJECT_SHAPE_ELEM_SIZE, masklay_shape->data);
+                               }
+                       }
+               }
+
+               mask = mask->id.next;
+       }
+
+       /* flush helps the compression for undo-save */
+       mywrite(wd, MYWRITE_FLUSH, 0);
+}
+
 /* context is usually defined by WM, two cases where no WM is available:
  * - for forward compatibility, curscreen has to be saved
  * - for undofile, curscene needs to be saved */
@@ -2838,6 +2931,7 @@ static int write_file_handle(Main *mainvar, int handle, MemFile *compare, MemFil
                write_screens  (wd, &mainvar->screen);
        }
        write_movieclips (wd, &mainvar->movieclip);
+       write_masks    (wd, &mainvar->mask);
        write_scenes   (wd, &mainvar->scene);
        write_curves   (wd, &mainvar->curve);
        write_mballs   (wd, &mainvar->mball);
@@ -2929,7 +3023,7 @@ int BLO_write_file(Main *mainvar, const char *filepath, int write_flags, ReportL
 
        file = BLI_open(tempname, O_BINARY+O_WRONLY+O_CREAT+O_TRUNC, 0666);
        if (file == -1) {
-               BKE_reportf(reports, RPT_ERROR, "Can't open file %s for writing: %s.", tempname, strerror(errno));
+               BKE_reportf(reports, RPT_ERROR, "Can't open file %s for writing: %s", tempname, strerror(errno));
                return 0;
        }
 
@@ -2980,7 +3074,7 @@ int BLO_write_file(Main *mainvar, const char *filepath, int write_flags, ReportL
        if (write_flags & G_FILE_HISTORY) { 
                int err_hist = do_history(filepath, reports);
                if (err_hist) {
-                       BKE_report(reports, RPT_ERROR, "Version backup failed. File saved with @");
+                       BKE_report(reports, RPT_ERROR, "Version backup failed (file saved with @)");
                        return 0;
                }
        }
@@ -2997,23 +3091,23 @@ int BLO_write_file(Main *mainvar, const char *filepath, int write_flags, ReportL
                if (0==ret) {
                        /* now rename to real file name, and delete temp @ file too */
                        if (BLI_rename(gzname, filepath) != 0) {
-                               BKE_report(reports, RPT_ERROR, "Can't change old file. File saved with @.");
+                               BKE_report(reports, RPT_ERROR, "Can't change old file (file saved with @)");
                                return 0;
                        }
 
                        BLI_delete(tempname, 0, 0);
                }
                else if (-1==ret) {
-                       BKE_report(reports, RPT_ERROR, "Failed opening .gz file.");
+                       BKE_report(reports, RPT_ERROR, "Failed opening .gz file");
                        return 0;
                }
                else if (-2==ret) {
-                       BKE_report(reports, RPT_ERROR, "Failed opening .blend file for compression.");
+                       BKE_report(reports, RPT_ERROR, "Failed opening .blend file for compression");
                        return 0;
                }
        }
        else if (BLI_rename(tempname, filepath) != 0) {
-               BKE_report(reports, RPT_ERROR, "Can't change old file. File saved with @");
+               BKE_report(reports, RPT_ERROR, "Can't change old file (file saved with @)");
                return 0;
        }