Merging r46111 through r46136 from trunk into soc-2011-tomato
[blender.git] / source / blender / blenloader / intern / writefile.c
index 0f2990a..0cd57ee 100644 (file)
@@ -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"
@@ -239,7 +240,7 @@ static void writedata_free(WriteData *wd)
  
 #define MYWRITE_FLUSH          NULL
 
-static void mywrite( WriteData *wd, const void *adr, int len)
+static void mywrite(WriteData *wd, const void *adr, int len)
 {
        if (wd->error) return;
 
@@ -757,24 +758,30 @@ static void current_screen_compat(Main *mainvar, bScreen **screen)
        *screen= (window)? window->screen: NULL;
 }
 
+typedef struct RenderInfo {
+       int sfra;
+       int efra;
+       char scene_name[MAX_ID_NAME - 2];
+} RenderInfo;
+
 static void write_renderinfo(WriteData *wd, Main *mainvar)             /* for renderdeamon */
 {
        bScreen *curscreen;
        Scene *sce;
-       int data[8];
+       RenderInfo data;
 
        /* XXX in future, handle multiple windows with multiple screnes? */
        current_screen_compat(mainvar, &curscreen);
 
        for (sce= mainvar->scene.first; sce; sce= sce->id.next) {
                if (sce->id.lib==NULL  && ( sce==curscreen->scene || (sce->r.scemode & R_BG_RENDER)) ) {
-                       data[0]= sce->r.sfra;
-                       data[1]= sce->r.efra;
+                       data.sfra = sce->r.sfra;
+                       data.efra = sce->r.efra;
+                       memset(data.scene_name, 0, sizeof(data.scene_name));
 
-                       memset(data+2, 0, sizeof(int)*6);
-                       BLI_strncpy((char *)(data+2), sce->id.name+2, sizeof(sce->id.name)-2);
+                       BLI_strncpy(data.scene_name, sce->id.name + 2, sizeof(data.scene_name));
 
-                       writedata(wd, REND, 32, data);
+                       writedata(wd, REND, sizeof(data), &data);
                }
        }
 }
@@ -831,7 +838,7 @@ static void write_boid_state(WriteData *wd, BoidState *state)
        writestruct(wd, DATA, "BoidState", 1, state);
 
        for (; rule; rule=rule->next) {
-               switch(rule->type) {
+               switch (rule->type) {
                        case eBoidRuleType_Goal:
                        case eBoidRuleType_Avoid:
                                writestruct(wd, DATA, "BoidRuleGoalAvoid", 1, rule);
@@ -968,7 +975,7 @@ static void write_particlesystems(WriteData *wd, ListBase *particles)
                writestruct(wd, DATA, "ParticleSystem", 1, psys);
 
                if (psys->particles) {
-                       writestruct(wd, DATA, "ParticleData", psys->totpart ,psys->particles);
+                       writestruct(wd, DATA, "ParticleData", psys->totpartpsys->particles);
 
                        if (psys->particles->hair) {
                                ParticleData *pa = psys->particles;
@@ -987,7 +994,7 @@ static void write_particlesystems(WriteData *wd, ListBase *particles)
                for (; pt; pt=pt->next)
                        writestruct(wd, DATA, "ParticleTarget", 1, pt);
 
-               if (psys->child) writestruct(wd, DATA, "ChildParticle", psys->totchild ,psys->child);
+               if (psys->child) writestruct(wd, DATA, "ChildParticle", psys->totchildpsys->child);
 
                if (psys->clmd) {
                        writestruct(wd, DATA, "ClothModifierData", 1, psys->clmd);
@@ -1024,7 +1031,7 @@ static void write_sensors(WriteData *wd, ListBase *lb)
 
                writedata(wd, DATA, sizeof(void *)*sens->totlinks, sens->links);
 
-               switch(sens->type) {
+               switch (sens->type) {
                case SENS_NEAR:
                        writestruct(wd, DATA, "bNearSensor", 1, sens->data);
                        break;
@@ -1085,7 +1092,7 @@ static void write_controllers(WriteData *wd, ListBase *lb)
 
                writedata(wd, DATA, sizeof(void *)*cont->totlinks, cont->links);
 
-               switch(cont->type) {
+               switch (cont->type) {
                case CONT_EXPRESSION:
                        writestruct(wd, DATA, "bExpressionCont", 1, cont->data);
                        break;
@@ -1108,7 +1115,7 @@ static void write_actuators(WriteData *wd, ListBase *lb)
        while (act) {
                writestruct(wd, DATA, "bActuator", 1, act);
 
-               switch(act->type) {
+               switch (act->type) {
                case ACT_ACTION:
                case ACT_SHAPEACTION:
                        writestruct(wd, DATA, "bActionActuator", 1, act->data);
@@ -1310,10 +1317,8 @@ static void write_modifiers(WriteData *wd, ListBase *modbase)
                else if (md->type==eModifierType_Smoke) {
                        SmokeModifierData *smd = (SmokeModifierData*) md;
                        
-                       if (smd->type & MOD_SMOKE_TYPE_DOMAIN)
-                       {
-                               if (smd->domain)
-                               {
+                       if (smd->type & MOD_SMOKE_TYPE_DOMAIN) {
+                               if (smd->domain) {
                                        write_pointcaches(wd, &(smd->domain->ptcaches[0]));
 
                                        /* create fake pointcache so that old blender versions can read it */
@@ -1347,8 +1352,7 @@ static void write_modifiers(WriteData *wd, ListBase *modbase)
                else if (md->type==eModifierType_DynamicPaint) {
                        DynamicPaintModifierData *pmd = (DynamicPaintModifierData*) md;
                        
-                       if (pmd->canvas)
-                       {
+                       if (pmd->canvas) {
                                DynamicPaintSurface *surface;
                                writestruct(wd, DATA, "DynamicPaintCanvasSettings", 1, pmd->canvas);
                                
@@ -1362,8 +1366,7 @@ static void write_modifiers(WriteData *wd, ListBase *modbase)
                                        writestruct(wd, DATA, "EffectorWeights", 1, surface->effector_weights);
                                }
                        }
-                       if (pmd->brush)
-                       {
+                       if (pmd->brush) {
                                writestruct(wd, DATA, "DynamicPaintBrushSettings", 1, pmd->brush);
                                writestruct(wd, DATA, "ColorBand", 1, pmd->brush->paint_ramp);
                                writestruct(wd, DATA, "ColorBand", 1, pmd->brush->vel_ramp);
@@ -2106,19 +2109,21 @@ static void write_scenes(WriteData *wd, ListBase *scebase)
                        
                        /* reset write flags too */
                        
-                       SEQ_BEGIN(ed, seq) {
+                       SEQ_BEGIN (ed, seq)
+                       {
                                if (seq->strip) seq->strip->done= 0;
                                writestruct(wd, DATA, "Sequence", 1, seq);
                        }
                        SEQ_END
                        
-                       SEQ_BEGIN(ed, seq) {
+                       SEQ_BEGIN (ed, seq)
+                       {
                                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) {
+                                               switch (seq->type) {
                                                case SEQ_COLOR:
                                                        writestruct(wd, DATA, "SolidColorVars", 1, seq->effectdata);
                                                        break;
@@ -2252,7 +2257,7 @@ static void write_region(WriteData *wd, ARegion *ar, int spacetype)
        writestruct(wd, DATA, "ARegion", 1, ar);
        
        if (ar->regiondata) {
-               switch(spacetype) {
+               switch (spacetype) {
                        case SPACE_VIEW3D:
                                if (ar->regiontype==RGN_TYPE_WINDOW) {
                                        RegionView3D *rv3d= ar->regiondata;
@@ -2675,6 +2680,18 @@ static void write_movieTracks(WriteData *wd, ListBase *tracks)
        }
 }
 
+static void write_movieDopesheet(WriteData *wd, MovieTrackingDopesheet *dopesheet)
+{
+       MovieTrackingDopesheetChannel *channel;
+
+       channel = dopesheet->channels.first;
+       while (channel) {
+               writestruct(wd, DATA, "MovieTrackingDopesheetChannel", 1, channel);
+
+               channel = channel->next;
+       }
+}
+
 static void write_movieReconstruction(WriteData *wd, MovieTrackingReconstruction *reconstruction)
 {
        if (reconstruction->camnr)
@@ -2707,6 +2724,8 @@ static void write_movieclips(WriteData *wd, ListBase *idbase)
 
                                object= object->next;
                        }
+
+                       write_movieDopesheet(wd, &tracking->dopesheet);
                }
 
                clip= clip->id.next;
@@ -2716,6 +2735,54 @@ 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) {
+                       MaskShape *shape;
+
+                       writestruct(wd, ID_MSK, "Mask", 1, mask);
+
+                       if (mask->adt)
+                               write_animdata(wd, mask->adt);
+
+                       shape = mask->shapes.first;
+                       while (shape) {
+                               MaskSpline *spline;
+
+                               writestruct(wd, DATA, "MaskShape", 1, shape);
+
+                               spline = shape->splines.first;
+                               while (spline) {
+                                       int i;
+
+                                       writestruct(wd, DATA, "MaskSpline", 1, spline);
+                                       writestruct(wd, DATA, "MaskSplinePoint", spline->tot_point, spline->points);
+
+                                       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);
+                                       }
+
+                                       spline = spline->next;
+                               }
+
+                               shape = shape->next;
+                       }
+               }
+
+               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 */
@@ -2800,6 +2867,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);
@@ -2889,7 +2957,7 @@ int BLO_write_file(Main *mainvar, const char *filepath, int write_flags, ReportL
        /* open temporary file, so we preserve the original in case we crash */
        BLI_snprintf(tempname, sizeof(tempname), "%s@", filepath);
 
-       file = BLI_open(tempname,O_BINARY+O_WRONLY+O_CREAT+O_TRUNC, 0666);
+       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));
                return 0;
@@ -2927,7 +2995,7 @@ int BLO_write_file(Main *mainvar, const char *filepath, int write_flags, ReportL
                makeFilesRelative(mainvar, filepath, NULL); /* note, making relative to something OTHER then G.main->name */
 
        /* actual file writing */
-       err= write_file_handle(mainvar, file, NULL,NULL, write_user_block, write_flags, thumb);
+       err= write_file_handle(mainvar, file, NULL, NULL, write_user_block, write_flags, thumb);
        close(file);
 
        if (err) {