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.
This commit is contained in:
Bastien Montagne 2023-01-24 17:22:57 +01:00
parent e308b891c8
commit 30b34735e3
5 changed files with 17 additions and 5 deletions

View File

@ -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 {

View File

@ -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,

View File

@ -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,

View File

@ -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. */

View File

@ -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,