[Bf-blender-cvs] [30b34735e31] master: Cleanup/refactor: Add a new flag for IDTypes that are not read in memfile undo.

Bastien Montagne noreply at git.blender.org
Tue Jan 24 18:15:10 CET 2023


Commit: 30b34735e3158afac21c04da62b7f048918e062c
Author: Bastien Montagne
Date:   Tue Jan 24 17:22:57 2023 +0100
Branches: master
https://developer.blender.org/rB30b34735e3158afac21c04da62b7f048918e062c

Cleanup/refactor: Add a new flag for IDTypes that are not read in memfile undo.

Currently only affects 'UI' IDs (WindowManager, Screen, etc.), but in
the future other types may be affected as well.

NOTE: this is only used in readfile code itself, not in the
post-processing performed by `setup_app_data`, as this code is too
specific for such generic handling.

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

M	source/blender/blenkernel/BKE_idtype.h
M	source/blender/blenkernel/intern/screen.c
M	source/blender/blenkernel/intern/workspace.cc
M	source/blender/blenloader/intern/readfile.cc
M	source/blender/windowmanager/intern/wm.c

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

diff --git a/source/blender/blenkernel/BKE_idtype.h b/source/blender/blenkernel/BKE_idtype.h
index 256ddec5505..be13a3c1d2a 100644
--- a/source/blender/blenkernel/BKE_idtype.h
+++ b/source/blender/blenkernel/BKE_idtype.h
@@ -39,6 +39,15 @@ enum {
   IDTYPE_FLAGS_APPEND_IS_REUSABLE = 1 << 3,
   /** Indicates that the given IDType does not have animation data. */
   IDTYPE_FLAGS_NO_ANIMDATA = 1 << 4,
+  /**
+   * Indicates that the given IDType is not handled through memfile (aka global) undo.
+   *
+   * \note This currently only affect local data-blocks.
+   *
+   * \note Current readfile undo code expects these data-blocks to not be used by any 'regular'
+   * data-blocks.
+   */
+  IDTYPE_FLAGS_NO_MEMFILE_UNDO = 1 << 5,
 };
 
 typedef struct IDCacheKey {
diff --git a/source/blender/blenkernel/intern/screen.c b/source/blender/blenkernel/intern/screen.c
index 2c896788b20..95ef6b7b925 100644
--- a/source/blender/blenkernel/intern/screen.c
+++ b/source/blender/blenkernel/intern/screen.c
@@ -279,7 +279,8 @@ IDTypeInfo IDType_ID_SCR = {
     .name = "Screen",
     .name_plural = "screens",
     .translation_context = BLT_I18NCONTEXT_ID_SCREEN,
-    .flags = IDTYPE_FLAGS_NO_COPY | IDTYPE_FLAGS_ONLY_APPEND | IDTYPE_FLAGS_NO_ANIMDATA,
+    .flags = IDTYPE_FLAGS_NO_COPY | IDTYPE_FLAGS_ONLY_APPEND | IDTYPE_FLAGS_NO_ANIMDATA |
+             IDTYPE_FLAGS_NO_MEMFILE_UNDO,
     .asset_type_info = NULL,
 
     .init_data = NULL,
diff --git a/source/blender/blenkernel/intern/workspace.cc b/source/blender/blenkernel/intern/workspace.cc
index 4b617a15e7e..fb5d4f09a2f 100644
--- a/source/blender/blenkernel/intern/workspace.cc
+++ b/source/blender/blenkernel/intern/workspace.cc
@@ -193,7 +193,8 @@ IDTypeInfo IDType_ID_WS = {
     /*name*/ "WorkSpace",
     /*name_plural*/ "workspaces",
     /*translation_context*/ BLT_I18NCONTEXT_ID_WORKSPACE,
-    /*flags*/ IDTYPE_FLAGS_NO_COPY | IDTYPE_FLAGS_ONLY_APPEND | IDTYPE_FLAGS_NO_ANIMDATA,
+    /*flags*/ IDTYPE_FLAGS_NO_COPY | IDTYPE_FLAGS_ONLY_APPEND | IDTYPE_FLAGS_NO_ANIMDATA |
+        IDTYPE_FLAGS_NO_MEMFILE_UNDO,
     /*asset_type_info*/ nullptr,
 
     /*init_data*/ workspace_init_data,
diff --git a/source/blender/blenloader/intern/readfile.cc b/source/blender/blenloader/intern/readfile.cc
index f4a5b6dd2fc..1b6c896458a 100644
--- a/source/blender/blenloader/intern/readfile.cc
+++ b/source/blender/blenloader/intern/readfile.cc
@@ -3195,7 +3195,7 @@ static bool read_libblock_undo_restore(
 {
   /* Get pointer to memory of new ID that we will be reading. */
   const ID *id = static_cast<const ID *>(peek_struct_undo(fd, bhead));
-  const short idcode = GS(id->name);
+  const IDTypeInfo *id_type = BKE_idtype_get_info_from_id(id);
 
   if (bhead->code == ID_LI) {
     /* Restore library datablock. */
@@ -3209,7 +3209,7 @@ static bool read_libblock_undo_restore(
       return true;
     }
   }
-  else if (ELEM(idcode, ID_WM, ID_SCR, ID_WS)) {
+  else if (id_type->flags & IDTYPE_FLAGS_NO_MEMFILE_UNDO) {
     /* Skip reading any UI datablocks, existing ones are kept. We don't
      * support pointers from other datablocks to UI datablocks so those
      * we also don't put UI datablocks in fd->libmap. */
diff --git a/source/blender/windowmanager/intern/wm.c b/source/blender/windowmanager/intern/wm.c
index bd480526f9f..aad7cc6ac93 100644
--- a/source/blender/windowmanager/intern/wm.c
+++ b/source/blender/windowmanager/intern/wm.c
@@ -265,7 +265,8 @@ IDTypeInfo IDType_ID_WM = {
     .name = "WindowManager",
     .name_plural = "window_managers",
     .translation_context = BLT_I18NCONTEXT_ID_WINDOWMANAGER,
-    .flags = IDTYPE_FLAGS_NO_COPY | IDTYPE_FLAGS_NO_LIBLINKING | IDTYPE_FLAGS_NO_ANIMDATA,
+    .flags = IDTYPE_FLAGS_NO_COPY | IDTYPE_FLAGS_NO_LIBLINKING | IDTYPE_FLAGS_NO_ANIMDATA |
+             IDTYPE_FLAGS_NO_MEMFILE_UNDO,
     .asset_type_info = NULL,
 
     .init_data = NULL,



More information about the Bf-blender-cvs mailing list