Merge branch 'master' into blender2.8
authorCampbell Barton <ideasman42@gmail.com>
Sat, 14 Apr 2018 12:04:24 +0000 (14:04 +0200)
committerCampbell Barton <ideasman42@gmail.com>
Sat, 14 Apr 2018 12:10:27 +0000 (14:10 +0200)
1  2 
source/blender/blenkernel/intern/undo_system.c
source/blender/blenloader/intern/writefile.c
source/blender/editors/undo/memfile_undo.c

index 40c54e04ec7f7dbef0ad36bf031e61575c86e854,9727f6f0011206b219e54a81a4dae04aa7c17d0f..7f4e7fdc646ad79f2e6585f57572322a068af9a3
@@@ -3216,22 -3154,9 +3253,22 @@@ static void write_sound(WriteData *wd, 
        }
  }
  
-       if (prb->id.us > 0 || wd->current) {
 +static void write_probe(WriteData *wd, LightProbe *prb)
 +{
++      if (prb->id.us > 0 || wd->use_memfile) {
 +              /* write LibData */
 +              writestruct(wd, ID_LP, LightProbe, 1, prb);
 +              write_iddata(wd, &prb->id);
 +
 +              if (prb->adt) {
 +                      write_animdata(wd, prb->adt);
 +              }
 +      }
 +}
 +
  static void write_group(WriteData *wd, Group *group)
  {
-       if (group->id.us > 0 || wd->current) {
+       if (group->id.us > 0 || wd->use_memfile) {
                /* write LibData */
                writestruct(wd, ID_GR, Group, 1, group);
                write_iddata(wd, &group->id);
@@@ -3853,11 -3765,9 +3890,11 @@@ static void write_libraries(WriteData *
   * - for undofile, curscene needs to be saved */
  static void write_global(WriteData *wd, int fileflags, Main *mainvar)
  {
-       const bool is_undo = (wd->current != NULL);
+       const bool is_undo = wd->use_memfile;
        FileGlobal fg;
        bScreen *screen;
 +      Scene *scene;
 +      ViewLayer *render_layer;
        char subvstr[8];
  
        /* prevent mem checkers from complaining */
@@@ -3953,159 -3867,131 +3996,159 @@@ static bool write_file_handle
         * avoid thumbnail detecting changes because of this. */
        mywrite_flush(wd);
  
-       OverrideStaticStorage *override_storage = !wd->current ? BKE_override_static_operations_store_initialize() : NULL;
 -      ListBase *lbarray[MAX_LIBARRAY];
 -      int a = set_listbasepointers(mainvar, lbarray);
 -      while (a--) {
 -              ID *id = lbarray[a]->first;
++      OverrideStaticStorage *override_storage = wd->use_memfile ? NULL : BKE_override_static_operations_store_initialize();
  
 -              if (id && GS(id->name) == ID_LI) {
 -                      continue;  /* Libraries are handled separately below. */
 -              }
 +      /* This outer loop allows to save first datablocks from real mainvar, then the temp ones from override process,
 +       * if needed, without duplicating whole code. */
 +      Main *bmain = mainvar;
 +      do {
 +              ListBase *lbarray[MAX_LIBARRAY];
 +              int a = set_listbasepointers(bmain, lbarray);
 +              while (a--) {
 +                      ID *id = lbarray[a]->first;
  
 -              for (; id; id = id->next) {
 -                      /* We should never attempt to write non-regular IDs (i.e. all kind of temp/runtime ones). */
 -                      BLI_assert((id->tag & (LIB_TAG_NO_MAIN | LIB_TAG_NO_USER_REFCOUNT | LIB_TAG_NOT_ALLOCATED)) == 0);
 +                      if (id && GS(id->name) == ID_LI) {
 +                              continue;  /* Libraries are handled separately below. */
 +                      }
  
 -                      switch ((ID_Type)GS(id->name)) {
 -                              case ID_WM:
 -                                      write_windowmanager(wd, (wmWindowManager *)id);
 -                                      break;
 -                              case ID_SCR:
 -                                      write_screen(wd, (bScreen *)id);
 -                                      break;
 -                              case ID_MC:
 -                                      write_movieclip(wd, (MovieClip *)id);
 -                                      break;
 -                              case ID_MSK:
 -                                      write_mask(wd, (Mask *)id);
 -                                      break;
 -                              case ID_SCE:
 -                                      write_scene(wd, (Scene *)id);
 -                                      break;
 -                              case ID_CU:
 -                                      write_curve(wd, (Curve *)id);
 -                                      break;
 -                              case ID_MB:
 -                                      write_mball(wd, (MetaBall *)id);
 -                                      break;
 -                              case ID_IM:
 -                                      write_image(wd, (Image *)id);
 -                                      break;
 -                              case ID_CA:
 -                                      write_camera(wd, (Camera *)id);
 -                                      break;
 -                              case ID_LA:
 -                                      write_lamp(wd, (Lamp *)id);
 -                                      break;
 -                              case ID_LT:
 -                                      write_lattice(wd, (Lattice *)id);
 -                                      break;
 -                              case ID_VF:
 -                                      write_vfont(wd, (VFont *)id);
 -                                      break;
 -                              case ID_KE:
 -                                      write_key(wd, (Key *)id);
 -                                      break;
 -                              case ID_WO:
 -                                      write_world(wd, (World *)id);
 -                                      break;
 -                              case ID_TXT:
 -                                      write_text(wd, (Text *)id);
 -                                      break;
 -                              case ID_SPK:
 -                                      write_speaker(wd, (Speaker *)id);
 -                                      break;
 -                              case ID_SO:
 -                                      write_sound(wd, (bSound *)id);
 -                                      break;
 -                              case ID_GR:
 -                                      write_group(wd, (Group *)id);
 -                                      break;
 -                              case ID_AR:
 -                                      write_armature(wd, (bArmature *)id);
 -                                      break;
 -                              case ID_AC:
 -                                      write_action(wd, (bAction *)id);
 -                                      break;
 -                              case ID_OB:
 -                                      write_object(wd, (Object *)id);
 -                                      break;
 -                              case ID_MA:
 -                                      write_material(wd, (Material *)id);
 -                                      break;
 -                              case ID_TE:
 -                                      write_texture(wd, (Tex *)id);
 -                                      break;
 -                              case ID_ME:
 -                                      write_mesh(wd, (Mesh *)id);
 -                                      break;
 -                              case ID_PA:
 -                                      write_particlesettings(wd, (ParticleSettings *)id);
 -                                      break;
 -                              case ID_NT:
 -                                      write_nodetree(wd, (bNodeTree *)id);
 -                                      break;
 -                              case ID_BR:
 -                                      write_brush(wd, (Brush *)id);
 -                                      break;
 -                              case ID_PAL:
 -                                      write_palette(wd, (Palette *)id);
 -                                      break;
 -                              case ID_PC:
 -                                      write_paintcurve(wd, (PaintCurve *)id);
 -                                      break;
 -                              case ID_GD:
 -                                      write_gpencil(wd, (bGPdata *)id);
 -                                      break;
 -                              case ID_LS:
 -                                      write_linestyle(wd, (FreestyleLineStyle *)id);
 -                                      break;
 -                              case ID_CF:
 -                                      write_cachefile(wd, (CacheFile *)id);
 -                                      break;
 -                              case ID_LI:
 -                                      /* Do nothing, handled below - and should never be reached. */
 -                                      BLI_assert(0);
 -                                      break;
 -                              case ID_IP:
 -                                      /* Do nothing, deprecated. */
 -                                      break;
 -                              default:
 -                                      /* Should never be reached. */
 -                                      BLI_assert(0);
 -                                      break;
 +                      for (; id; id = id->next) {
 +                              /* We should never attempt to write non-regular IDs (i.e. all kind of temp/runtime ones). */
 +                              BLI_assert((id->tag & (LIB_TAG_NO_MAIN | LIB_TAG_NO_USER_REFCOUNT | LIB_TAG_NOT_ALLOCATED)) == 0);
 +
 +                              const bool do_override = !ELEM(override_storage, NULL, bmain) && id->override_static;
 +
 +                              if (do_override) {
 +                                      BKE_override_static_operations_store_start(override_storage, id);
 +                              }
 +
 +                              switch ((ID_Type)GS(id->name)) {
 +                                      case ID_WM:
 +                                              write_windowmanager(wd, (wmWindowManager *)id);
 +                                              break;
 +                                      case ID_WS:
 +                                              write_workspace(wd, (WorkSpace *)id);
 +                                              break;
 +                                      case ID_SCR:
 +                                              write_screen(wd, (bScreen *)id);
 +                                              break;
 +                                      case ID_MC:
 +                                              write_movieclip(wd, (MovieClip *)id);
 +                                              break;
 +                                      case ID_MSK:
 +                                              write_mask(wd, (Mask *)id);
 +                                              break;
 +                                      case ID_SCE:
 +                                              write_scene(wd, (Scene *)id);
 +                                              break;
 +                                      case ID_CU:
 +                                              write_curve(wd, (Curve *)id);
 +                                              break;
 +                                      case ID_MB:
 +                                              write_mball(wd, (MetaBall *)id);
 +                                              break;
 +                                      case ID_IM:
 +                                              write_image(wd, (Image *)id);
 +                                              break;
 +                                      case ID_CA:
 +                                              write_camera(wd, (Camera *)id);
 +                                              break;
 +                                      case ID_LA:
 +                                              write_lamp(wd, (Lamp *)id);
 +                                              break;
 +                                      case ID_LT:
 +                                              write_lattice(wd, (Lattice *)id);
 +                                              break;
 +                                      case ID_VF:
 +                                              write_vfont(wd, (VFont *)id);
 +                                              break;
 +                                      case ID_KE:
 +                                              write_key(wd, (Key *)id);
 +                                              break;
 +                                      case ID_WO:
 +                                              write_world(wd, (World *)id);
 +                                              break;
 +                                      case ID_TXT:
 +                                              write_text(wd, (Text *)id);
 +                                              break;
 +                                      case ID_SPK:
 +                                              write_speaker(wd, (Speaker *)id);
 +                                              break;
 +                                      case ID_LP:
 +                                              write_probe(wd, (LightProbe *)id);
 +                                              break;
 +                                      case ID_SO:
 +                                              write_sound(wd, (bSound *)id);
 +                                              break;
 +                                      case ID_GR:
 +                                              write_group(wd, (Group *)id);
 +                                              break;
 +                                      case ID_AR:
 +                                              write_armature(wd, (bArmature *)id);
 +                                              break;
 +                                      case ID_AC:
 +                                              write_action(wd, (bAction *)id);
 +                                              break;
 +                                      case ID_OB:
 +                                              write_object(wd, (Object *)id);
 +                                              break;
 +                                      case ID_MA:
 +                                              write_material(wd, (Material *)id);
 +                                              break;
 +                                      case ID_TE:
 +                                              write_texture(wd, (Tex *)id);
 +                                              break;
 +                                      case ID_ME:
 +                                              write_mesh(wd, (Mesh *)id);
 +                                              break;
 +                                      case ID_PA:
 +                                              write_particlesettings(wd, (ParticleSettings *)id);
 +                                              break;
 +                                      case ID_NT:
 +                                              write_nodetree(wd, (bNodeTree *)id);
 +                                              break;
 +                                      case ID_BR:
 +                                              write_brush(wd, (Brush *)id);
 +                                              break;
 +                                      case ID_PAL:
 +                                              write_palette(wd, (Palette *)id);
 +                                              break;
 +                                      case ID_PC:
 +                                              write_paintcurve(wd, (PaintCurve *)id);
 +                                              break;
 +                                      case ID_GD:
 +                                              write_gpencil(wd, (bGPdata *)id);
 +                                              break;
 +                                      case ID_LS:
 +                                              write_linestyle(wd, (FreestyleLineStyle *)id);
 +                                              break;
 +                                      case ID_CF:
 +                                              write_cachefile(wd, (CacheFile *)id);
 +                                              break;
 +                                      case ID_LI:
 +                                              /* Do nothing, handled below - and should never be reached. */
 +                                              BLI_assert(0);
 +                                              break;
 +                                      case ID_IP:
 +                                              /* Do nothing, deprecated. */
 +                                              break;
 +                                      default:
 +                                              /* Should never be reached. */
 +                                              BLI_assert(0);
 +                                              break;
 +                              }
 +
 +                              if (do_override) {
 +                                      BKE_override_static_operations_store_end(override_storage, id);
 +                              }
                        }
 +
 +                      mywrite_flush(wd);
                }
 +      } while ((bmain != override_storage) && (bmain = override_storage));
  
 -              mywrite_flush(wd);
 +      if (override_storage) {
 +              BKE_override_static_operations_store_finalize(override_storage);
 +              override_storage = NULL;
        }
  
        /* Special handling, operating over split Mains... */
index f4ed96f98f3d17eddca8af6c1c3c8fcddc0aa791,bb81da74f88720b2803098313eeaff03a5291d92..511f4bc72f1a6d57f51508c1900fc2e715a304c2
@@@ -70,12 -70,12 +70,13 @@@ static bool memfile_undosys_step_encode
  
        /* Important we only use 'main' from the context (see: BKE_undosys_stack_init_from_main). */
        struct Main *bmain = CTX_data_main(C);
+       UndoStack *ustack = ED_undo_stack_get();
  
        /* can be NULL, use when set. */
-       MemFileUndoStep *us_prev = (MemFileUndoStep *)BKE_undosys_step_same_type_prev(us_p);
+       MemFileUndoStep *us_prev = (MemFileUndoStep *)BKE_undosys_step_find_by_type(ustack, BKE_UNDOSYS_TYPE_MEMFILE);
        us->data = BKE_memfile_undo_encode(bmain, us_prev ? us_prev->data : NULL);
        us->step.data_size = us->data->undo_size;
 +
        return true;
  }