style cleanup
[blender.git] / source / blender / blenloader / intern / writefile.c
index 7c9945ef51738a986393db7f0499dd33caee8fb2..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>
@@ -154,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"
@@ -163,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"
 
@@ -646,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);
@@ -716,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);
@@ -724,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);
                }
@@ -1380,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;
@@ -1815,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);
 
@@ -1958,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) {
@@ -2087,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)
 {
@@ -2152,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;
                                                }
@@ -2184,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
                                
@@ -2232,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 */
@@ -2493,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;
 
@@ -2762,25 +2801,30 @@ static void write_masks(WriteData *wd, ListBase *idbase)
        mask = idbase->first;
        while (mask) {
                if (mask->id.us > 0 || wd->current) {
-                       MaskObject *maskobj;
+                       MaskLayer *masklay;
 
                        writestruct(wd, ID_MSK, "Mask", 1, mask);
 
                        if (mask->adt)
                                write_animdata(wd, mask->adt);
 
-                       for (maskobj = mask->maskobjs.first; maskobj; maskobj = maskobj->next) {
+                       for (masklay = mask->masklayers.first; masklay; masklay = masklay->next) {
                                MaskSpline *spline;
-                               MaskObjectShape *maskobj_shape;
+                               MaskLayerShape *masklay_shape;
 
-                               writestruct(wd, DATA, "MaskObject", 1, maskobj);
+                               writestruct(wd, DATA, "MaskLayer", 1, masklay);
 
-                               for (spline = maskobj->splines.first; spline; spline = spline->next) {
+                               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];
 
@@ -2789,9 +2833,9 @@ static void write_masks(WriteData *wd, ListBase *idbase)
                                        }
                                }
 
-                               for (maskobj_shape = maskobj->splines_shapes.first; maskobj_shape; maskobj_shape = maskobj_shape->next) {
-                                       writestruct(wd, DATA, "MaskObjectShape", 1, maskobj_shape);
-                                       writedata(wd, DATA, maskobj_shape->tot_vert * sizeof(float) * MASK_OBJECT_SHAPE_ELEM_SIZE, maskobj_shape->data);
+                               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);
                                }
                        }
                }
@@ -2886,7 +2930,6 @@ static int write_file_handle(Main *mainvar, int handle, MemFile *compare, MemFil
                write_windowmanagers(wd, &mainvar->wm);
                write_screens  (wd, &mainvar->screen);
        }
-       write_gpencils (wd, &mainvar->gpencil);
        write_movieclips (wd, &mainvar->movieclip);
        write_masks    (wd, &mainvar->mask);
        write_scenes   (wd, &mainvar->scene);
@@ -2913,6 +2956,7 @@ static int write_file_handle(Main *mainvar, int handle, MemFile *compare, MemFil
        write_nodetrees(wd, &mainvar->nodetree);
        write_brushes  (wd, &mainvar->brush);
        write_scripts  (wd, &mainvar->script);
+       write_gpencils (wd, &mainvar->gpencil);
        write_libraries(wd,  mainvar->next);
 
        if (write_user_block) {
@@ -2979,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;
        }
 
@@ -3030,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;
                }
        }
@@ -3047,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;
        }