[Bf-blender-cvs] [f23113cd6b2] undo-experiments-swap-reread-datablocks: undoexp: Better handling of recalc flags in undo/redo case.

Bastien Montagne noreply at git.blender.org
Thu Jan 30 12:36:26 CET 2020


Commit: f23113cd6b2e0936ea8b11ee3207b0a4c2f7e100
Author: Bastien Montagne
Date:   Thu Jan 30 12:10:57 2020 +0100
Branches: undo-experiments-swap-reread-datablocks
https://developer.blender.org/rBf23113cd6b2e0936ea8b11ee3207b0a4c2f7e100

undoexp: Better handling of recalc flags in undo/redo case.

Main idea here is to accumulate all recalc flags used on an ID over the
whole time between two memfile savings.

Since our IDs are now almost never fully re-evaluated in depsgraph on
undo, this should give us a best 'precise' info required to update
actually changed things in the DEG update just after the undo.

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

M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/writefile.c
M	source/blender/depsgraph/intern/depsgraph_tag.cc
M	source/blender/makesdna/DNA_ID.h

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

diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index a476d37208d..a5c08caadf9 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -9591,14 +9591,21 @@ static BHead *read_libblock(FileData *fd,
    * the version the file has been saved with. */
   if (!fd->memfile) {
     id->recalc = 0;
-    id->recalc_undo_future = 0;
+    id->recalc_undo_accumulated = 0;
   }
   else {
-    /* We are coming from the future (i.e. do an actual undo, and not a redo), and we found an old
-     * (aka existing) ID: we use its 'last saved recalc flags' as 'future undo recalc flags' of our
-     * newly read ID. */
-    if (id_old != NULL && fd->undo_direction < 0) {
-      id->recalc = id_old->recalc_undo_future;
+    if (fd->undo_direction < 0) {
+      /* We are coming from the future (i.e. do an actual undo, and not a redo), and we found an
+       * old (aka existing) ID: we use its 'accumulated recalc flags since last memfile undo step
+       * saving' as recalc flags of our newly read ID. */
+      if (id_old != NULL) {
+        id->recalc = id_old->recalc_undo_accumulated;
+      }
+    }
+    else {
+      /* We are coming from the past (i.e. do a redo), and we found an, we use saved 'accumulated
+       * recalc flags since last memfile undo step saving' as recalc flags of our newly read ID. */
+      id->recalc = id->recalc_undo_accumulated;
     }
   }
 
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index 9c27ec3d269..cb72e115c10 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -703,7 +703,7 @@ void IDP_WriteProperty(const IDProperty *prop, void *wd)
   IDP_WriteProperty_OnlyData(prop, wd);
 }
 
-static void write_iddata(void *wd, const ID *id)
+static void write_iddata(WriteData *wd, ID *id)
 {
   /* ID_WM's id->properties are considered runtime only, and never written in .blend file. */
   if (id->properties && !ELEM(GS(id->name), ID_WM)) {
@@ -731,6 +731,11 @@ static void write_iddata(void *wd, const ID *id)
       }
     }
   }
+
+  /* Clear the accumulated recalc flags in case of undo step saving. */
+  if (wd->use_memfile) {
+    id->recalc_undo_accumulated = 0;
+  }
 }
 
 static void write_previews(WriteData *wd, const PreviewImage *prv_orig)
@@ -1102,6 +1107,11 @@ static void write_nodetree_nolib(WriteData *wd, bNodeTree *ntree)
   for (sock = ntree->outputs.first; sock; sock = sock->next) {
     write_node_socket_interface(wd, sock);
   }
+
+  /* Clear the accumulated recalc flags in case of undo step saving. */
+  if (wd->use_memfile) {
+    ntree->id.recalc_undo_accumulated = 0;
+  }
 }
 
 /**
@@ -2358,6 +2368,11 @@ static void write_collection_nolib(WriteData *wd, Collection *collection)
   for (CollectionChild *child = collection->children.first; child; child = child->next) {
     writestruct(wd, DATA, CollectionChild, 1, child);
   }
+
+  /* Clear the accumulated recalc flags in case of undo step saving. */
+  if (wd->use_memfile) {
+    collection->id.recalc_undo_accumulated = 0;
+  }
 }
 
 static void write_collection(WriteData *wd, Collection *collection)
diff --git a/source/blender/depsgraph/intern/depsgraph_tag.cc b/source/blender/depsgraph/intern/depsgraph_tag.cc
index 2bf641964d6..8decb9f6b87 100644
--- a/source/blender/depsgraph/intern/depsgraph_tag.cc
+++ b/source/blender/depsgraph/intern/depsgraph_tag.cc
@@ -814,15 +814,13 @@ void DEG_ids_check_recalc(
 
 static void deg_graph_clear_id_recalc_flags(ID *id)
 {
-  /* Keep track of used recalc flags, to get proper update when undoing.
-   * Note: we may actually want to accumulate those flags instead - and reset after each undo step
-   * is written ? */
-  id->recalc_undo_future = id->recalc;
+  /* Keep incremental track of used recalc flags, to get proper update when undoing. */
+  id->recalc_undo_accumulated |= id->recalc;
   id->recalc &= ~ID_RECALC_ALL;
   bNodeTree *ntree = ntreeFromID(id);
   /* Clear embedded node trees too. */
   if (ntree) {
-    ntree->id.recalc_undo_future = ntree->id.recalc;
+    ntree->id.recalc_undo_accumulated |= ntree->id.recalc;
     ntree->id.recalc &= ~ID_RECALC_ALL;
   }
   /* XXX And what about scene's master collection here? */
diff --git a/source/blender/makesdna/DNA_ID.h b/source/blender/makesdna/DNA_ID.h
index 0908fb7aef0..149c418dbba 100644
--- a/source/blender/makesdna/DNA_ID.h
+++ b/source/blender/makesdna/DNA_ID.h
@@ -264,7 +264,7 @@ typedef struct ID {
   /* Used by undo code. Value of recalc is stored there when reading an ID from memfile, and not
    * touched by anything, which means it can be used as 'reference' recalc value for the next undo
    * step, when going backward (i.e. actual undo, redo can just use recalc value directly). */
-  int recalc_undo_future;
+  int recalc_undo_accumulated;
   IDProperty *properties;
 
   /** Reference linked ID which this one overrides. */



More information about the Bf-blender-cvs mailing list