[Bf-blender-cvs] [ac2d342d882] blender-v2.82-release: Cleanup: ED_editors_flush_* functions

Campbell Barton noreply at git.blender.org
Thu Jan 30 06:48:58 CET 2020


Commit: ac2d342d88299d6fb61492dc824aa006e3bd7557
Author: Campbell Barton
Date:   Thu Jan 30 16:46:09 2020 +1100
Branches: blender-v2.82-release
https://developer.blender.org/rBac2d342d88299d6fb61492dc824aa006e3bd7557

Cleanup: ED_editors_flush_* functions

- Remove the only_render arg from ED_editors_flush_edits
  was only used in one place, the '_ex' version can be used instead.

- Split out the single object version of this function as currently
  flushing is being done in-line, often only accounting for edit-mode,
  ignoring sculpt mode for e.g.

===================================================================

M	source/blender/editors/include/ED_util.h
M	source/blender/editors/render/render_internal.c
M	source/blender/editors/scene/scene_edit.c
M	source/blender/editors/util/ed_util.c
M	source/blender/windowmanager/intern/wm_files.c
M	source/blender/windowmanager/intern/wm_init_exit.c

===================================================================

diff --git a/source/blender/editors/include/ED_util.h b/source/blender/editors/include/ED_util.h
index 003e84bbf05..8cce8fa973a 100644
--- a/source/blender/editors/include/ED_util.h
+++ b/source/blender/editors/include/ED_util.h
@@ -35,8 +35,14 @@ void ED_editors_init_for_undo(struct Main *bmain);
 void ED_editors_init(struct bContext *C);
 void ED_editors_exit(struct Main *bmain, bool do_undo_system);
 
+bool ED_editors_flush_edits_for_object_ex(struct Main *bmain,
+                                          struct Object *ob,
+                                          bool for_render,
+                                          bool check_needs_flush);
+bool ED_editors_flush_edits_for_object(struct Main *bmain, struct Object *ob);
+
 bool ED_editors_flush_edits_ex(struct Main *bmain, bool for_render, bool check_needs_flush);
-bool ED_editors_flush_edits(struct Main *bmain, bool for_render);
+bool ED_editors_flush_edits(struct Main *bmain);
 
 void ED_spacedata_id_remap(struct ScrArea *sa,
                            struct SpaceLink *sl,
diff --git a/source/blender/editors/render/render_internal.c b/source/blender/editors/render/render_internal.c
index 5740dacd05f..11821fcdc45 100644
--- a/source/blender/editors/render/render_internal.c
+++ b/source/blender/editors/render/render_internal.c
@@ -955,7 +955,7 @@ static int screen_render_invoke(bContext *C, wmOperator *op, const wmEvent *even
   WM_cursor_wait(1);
 
   /* flush sculpt and editmode changes */
-  ED_editors_flush_edits(bmain, true);
+  ED_editors_flush_edits_ex(bmain, true, false);
 
   /* cleanup sequencer caches before starting user triggered render.
    * otherwise, invalidated cache entries can make their way into
diff --git a/source/blender/editors/scene/scene_edit.c b/source/blender/editors/scene/scene_edit.c
index 7705278443f..22c91686bbf 100644
--- a/source/blender/editors/scene/scene_edit.c
+++ b/source/blender/editors/scene/scene_edit.c
@@ -65,7 +65,7 @@ Scene *ED_scene_add(Main *bmain, bContext *C, wmWindow *win, eSceneCopyMethod me
 
     /* these can't be handled in blenkernel currently, so do them here */
     if (method == SCE_COPY_FULL) {
-      ED_editors_flush_edits(bmain, false);
+      ED_editors_flush_edits(bmain);
       ED_object_single_users(bmain, scene_new, true, true);
     }
   }
diff --git a/source/blender/editors/util/ed_util.c b/source/blender/editors/util/ed_util.c
index 1a33b50ff10..b4b89c31414 100644
--- a/source/blender/editors/util/ed_util.c
+++ b/source/blender/editors/util/ed_util.c
@@ -228,6 +228,63 @@ void ED_editors_exit(Main *bmain, bool do_undo_system)
   ED_mesh_mirror_topo_table(NULL, NULL, 'e');
 }
 
+bool ED_editors_flush_edits_for_object_ex(Main *bmain,
+                                          Object *ob,
+                                          bool for_render,
+                                          bool check_needs_flush)
+{
+  bool has_edited = false;
+  if (ob->mode & OB_MODE_SCULPT) {
+    /* Don't allow flushing while in the middle of a stroke (frees data in use).
+     * Auto-save prevents this from happening but scripts
+     * may cause a flush on saving: T53986. */
+    if ((ob->sculpt && ob->sculpt->cache) == 0) {
+
+      {
+        char *needs_flush_ptr = &ob->sculpt->needs_flush_to_id;
+        if (check_needs_flush && (*needs_flush_ptr == 0)) {
+          return false;
+        }
+        *needs_flush_ptr = 0;
+      }
+
+      /* flush multires changes (for sculpt) */
+      multires_flush_sculpt_updates(ob);
+      has_edited = true;
+
+      if (for_render) {
+        /* flush changes from dynamic topology sculpt */
+        BKE_sculptsession_bm_to_me_for_render(ob);
+      }
+      else {
+        /* Set reorder=false so that saving the file doesn't reorder
+         * the BMesh's elements */
+        BKE_sculptsession_bm_to_me(ob, false);
+      }
+    }
+  }
+  else if (ob->mode & OB_MODE_EDIT) {
+
+    char *needs_flush_ptr = BKE_object_data_editmode_flush_ptr_get(ob->data);
+    if (needs_flush_ptr != NULL) {
+      if (check_needs_flush && (*needs_flush_ptr == 0)) {
+        return false;
+      }
+      *needs_flush_ptr = 0;
+    }
+
+    /* get editmode results */
+    has_edited = true;
+    ED_object_editmode_load(bmain, ob);
+  }
+  return has_edited;
+}
+
+bool ED_editors_flush_edits_for_object(Main *bmain, Object *ob)
+{
+  return ED_editors_flush_edits_for_object_ex(bmain, ob, false, false);
+}
+
 /* flush any temp data from object editing to DNA before writing files,
  * rendering, copying, etc. */
 bool ED_editors_flush_edits_ex(Main *bmain, bool for_render, bool check_needs_flush)
@@ -239,49 +296,7 @@ bool ED_editors_flush_edits_ex(Main *bmain, bool for_render, bool check_needs_fl
    * exiting we might not have a context for edit object and multiple sculpt
    * objects can exist at the same time */
   for (ob = bmain->objects.first; ob; ob = ob->id.next) {
-    if (ob->mode & OB_MODE_SCULPT) {
-      /* Don't allow flushing while in the middle of a stroke (frees data in use).
-       * Auto-save prevents this from happening but scripts
-       * may cause a flush on saving: T53986. */
-      if ((ob->sculpt && ob->sculpt->cache) == 0) {
-
-        {
-          char *needs_flush_ptr = &ob->sculpt->needs_flush_to_id;
-          if (check_needs_flush && (*needs_flush_ptr == 0)) {
-            continue;
-          }
-          *needs_flush_ptr = 0;
-        }
-
-        /* flush multires changes (for sculpt) */
-        multires_flush_sculpt_updates(ob);
-        has_edited = true;
-
-        if (for_render) {
-          /* flush changes from dynamic topology sculpt */
-          BKE_sculptsession_bm_to_me_for_render(ob);
-        }
-        else {
-          /* Set reorder=false so that saving the file doesn't reorder
-           * the BMesh's elements */
-          BKE_sculptsession_bm_to_me(ob, false);
-        }
-      }
-    }
-    else if (ob->mode & OB_MODE_EDIT) {
-
-      char *needs_flush_ptr = BKE_object_data_editmode_flush_ptr_get(ob->data);
-      if (needs_flush_ptr != NULL) {
-        if (check_needs_flush && (*needs_flush_ptr == 0)) {
-          continue;
-        }
-        *needs_flush_ptr = 0;
-      }
-
-      /* get editmode results */
-      has_edited = true;
-      ED_object_editmode_load(bmain, ob);
-    }
+    has_edited |= ED_editors_flush_edits_for_object_ex(bmain, ob, for_render, check_needs_flush);
   }
 
   bmain->is_memfile_undo_flush_needed = false;
@@ -289,9 +304,9 @@ bool ED_editors_flush_edits_ex(Main *bmain, bool for_render, bool check_needs_fl
   return has_edited;
 }
 
-bool ED_editors_flush_edits(Main *bmain, bool for_render)
+bool ED_editors_flush_edits(Main *bmain)
 {
-  return ED_editors_flush_edits_ex(bmain, for_render, false);
+  return ED_editors_flush_edits_ex(bmain, false, false);
 }
 
 /* ***** XXX: functions are using old blender names, cleanup later ***** */
@@ -472,7 +487,7 @@ void ED_spacedata_id_remap(struct ScrArea *sa, struct SpaceLink *sl, ID *old_id,
 static int ed_flush_edits_exec(bContext *C, wmOperator *UNUSED(op))
 {
   Main *bmain = CTX_data_main(C);
-  ED_editors_flush_edits(bmain, false);
+  ED_editors_flush_edits(bmain);
   return OPERATOR_FINISHED;
 }
 
diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c
index aa74aa81a74..0835f128f51 100644
--- a/source/blender/windowmanager/intern/wm_files.c
+++ b/source/blender/windowmanager/intern/wm_files.c
@@ -1386,7 +1386,7 @@ static bool wm_file_write(bContext *C, const char *filepath, int fileflags, Repo
   /* don't forget not to return without! */
   WM_cursor_wait(1);
 
-  ED_editors_flush_edits(bmain, false);
+  ED_editors_flush_edits(bmain);
 
   fileflags |= G_FILE_HISTORY; /* write file history */
 
@@ -1527,7 +1527,7 @@ void wm_autosave_timer(const bContext *C, wmWindowManager *wm, wmTimer *UNUSED(w
     Main *bmain = CTX_data_main(C);
     int fileflags = G.fileflags & ~(G_FILE_COMPRESS | G_FILE_HISTORY);
 
-    ED_editors_flush_edits(bmain, false);
+    ED_editors_flush_edits(bmain);
 
     /* Error reporting into console */
     BLO_write_file(bmain, filepath, fileflags, NULL, NULL);
@@ -1655,7 +1655,7 @@ static int wm_homefile_write_exec(bContext *C, wmOperator *op)
 
   printf("Writing homefile: '%s' ", filepath);
 
-  ED_editors_flush_edits(bmain, false);
+  ED_editors_flush_edits(bmain);
 
   /*  force save as regular blend file */
   fileflags = G.fileflags & ~(G_FILE_COMPRESS | G_FILE_HISTORY);
diff --git a/source/blender/windowmanager/intern/wm_init_exit.c b/source/blender/windowmanager/intern/wm_init_exit.c
index 42433c9f843..2f4abbe20d8 100644
--- a/source/blender/windowmanager/intern/wm_init_exit.c
+++ b/source/blender/windowmanager/intern/wm_init_exit.c
@@ -499,7 +499,7 @@ void WM_exit_ex(bContext *C, const bool do_python)
 
         BLI_make_file_string("/", filename, BKE_tempdir_base(), BLENDER_QUIT_FILE);
 
-        has_edited = ED_editors_flush_edits(bmain, false);
+        has_edited = ED_editors_flush_edits(bmain);
 
         if ((has_edited && BLO_write_file(bmain, filename, fileflags, NULL, NULL)) ||
             (undo_memfile && BLO_memfile_write_file(undo_memfile, filename))) {



More information about the Bf-blender-cvs mailing list