[Bf-blender-cvs] [c9975088a90] master: Move volume to new cache management system for undo.

Bastien Montagne noreply at git.blender.org
Fri Jul 3 15:28:14 CEST 2020


Commit: c9975088a908d0321271185661309e23e8bc1fb4
Author: Bastien Montagne
Date:   Fri Jul 3 15:27:12 2020 +0200
Branches: master
https://developer.blender.org/rBc9975088a908d0321271185661309e23e8bc1fb4

Move volume to new cache management system for undo.

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

M	source/blender/blenkernel/intern/volume.cc
M	source/blender/blenloader/intern/readblenentry.c
M	source/blender/blenloader/intern/readfile.c

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

diff --git a/source/blender/blenkernel/intern/volume.cc b/source/blender/blenkernel/intern/volume.cc
index 39c04d117e2..18859869b4e 100644
--- a/source/blender/blenkernel/intern/volume.cc
+++ b/source/blender/blenkernel/intern/volume.cc
@@ -483,6 +483,20 @@ static void volume_foreach_id(ID *id, LibraryForeachIDData *data)
   }
 }
 
+static void volume_foreach_cache(ID *id,
+                                 IDTypeForeachCacheFunctionCallback function_callback,
+                                 void *user_data)
+{
+  Volume *volume = (Volume *)id;
+  IDCacheKey key = {
+      /* id_session_uuid */ id->session_uuid,
+      /*offset_in_ID*/ offsetof(Volume, runtime.grids),
+      /* cache_v */ volume->runtime.grids,
+  };
+
+  function_callback(id, &key, (void **)&volume->runtime.grids, user_data);
+}
+
 IDTypeInfo IDType_ID_VO = {
     /* id_code */ ID_VO,
     /* id_filter */ FILTER_ID_VO,
@@ -498,6 +512,7 @@ IDTypeInfo IDType_ID_VO = {
     /* free_data */ volume_free_data,
     /* make_local */ nullptr,
     /* foreach_id */ volume_foreach_id,
+    /* foreach_cache */ volume_foreach_cache,
 };
 
 void BKE_volume_init_grids(Volume *volume)
diff --git a/source/blender/blenloader/intern/readblenentry.c b/source/blender/blenloader/intern/readblenentry.c
index 4af9399573a..e1350f9de66 100644
--- a/source/blender/blenloader/intern/readblenentry.c
+++ b/source/blender/blenloader/intern/readblenentry.c
@@ -399,9 +399,6 @@ BlendFileData *BLO_read_from_memfile(Main *oldmain,
     /* makes lookup of existing video clips in old main */
     blo_make_movieclip_pointer_map(fd, oldmain);
 
-    /* make lookups of existing volume data in old main */
-    blo_make_volume_pointer_map(fd, oldmain);
-
     /* removed packed data from this trick - it's internal data that needs saves */
 
     blo_cache_storage_init(fd, oldmain);
@@ -419,9 +416,6 @@ BlendFileData *BLO_read_from_memfile(Main *oldmain,
     /* ensures relinked movie clips are not freed */
     blo_end_movieclip_pointer_map(fd, oldmain);
 
-    /* ensures relinked volumes are not freed */
-    blo_end_volume_pointer_map(fd, oldmain);
-
     /* Still in-use libraries have already been moved from oldmain to new mainlist,
      * but oldmain itself shall *never* be 'transferred' to new mainlist! */
     BLI_assert(old_mainlist.first == oldmain);
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 31843efaaf8..5a2b8da6ef9 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -4360,9 +4360,10 @@ static void direct_link_text(BlendDataReader *reader, Text *text)
 
 static void lib_link_image(BlendLibReader *UNUSED(reader), Image *ima)
 {
-  /* Images have some kind of 'main' cache, when NULL we should also clear all others.
-   * XXX It is not ideal to do that from here, but for now it will do. We have to do it after all
-   * cache pointers have been potentially remapped (in undo case) or NULL-ified. */
+  /* Images have some kind of 'main' cache, when NULL we should also clear all others. */
+  /* Needs to be done *after* cache pointers are restored (call to
+   * `foreach_cache`/`blo_cache_storage_entry_restore_in_new`), easier for now to do it in
+   * lib_link... */
   if (ima->cache == NULL) {
     BKE_image_free_buffers(ima);
   }
@@ -8946,6 +8947,11 @@ static void direct_link_pointcloud(BlendDataReader *reader, PointCloud *pointclo
 
 static void lib_link_volume(BlendLibReader *reader, Volume *volume)
 {
+  /* Needs to be done *after* cache pointers are restored (call to
+   * `foreach_cache`/`blo_cache_storage_entry_restore_in_new`), easier for now to do it in
+   * lib_link... */
+  BKE_volume_init_grids(volume);
+
   for (int a = 0; a < volume->totcol; a++) {
     BLO_read_id_address(reader, volume->id.lib, &volume->mat[a]);
   }
@@ -8957,11 +8963,7 @@ static void direct_link_volume(BlendDataReader *reader, Volume *volume)
   direct_link_animdata(reader, volume->adt);
 
   volume->packedfile = direct_link_packedfile(reader, volume->packedfile);
-  volume->runtime.grids = (reader->fd->volumemap) ?
-                              newvolumeadr(reader->fd, volume->runtime.grids) :
-                              NULL;
   volume->runtime.frame = 0;
-  BKE_volume_init_grids(volume);
 
   /* materials */
   BLO_read_pointer_array(reader, (void **)&volume->mat);



More information about the Bf-blender-cvs mailing list