diff options
author | Bastien Montagne <bastien@blender.org> | 2021-09-14 18:43:41 +0300 |
---|---|---|
committer | Bastien Montagne <bastien@blender.org> | 2021-09-14 18:49:35 +0300 |
commit | cddb7920210f10b4c4b8595f80499cbbc5d5f57c (patch) | |
tree | 2158ae361e6d2800627173ceba590536fc6db3a5 /source/blender/blenkernel/intern/lib_remap.c | |
parent | 2d13c823ee1c336e3c8cbd01f8b3b21672bfd0e4 (diff) |
ID management: Add new version of `relink_to_newid` using proper new remapping code.
Current `BKE_libblock_relink_to_newid` is using its own simplistic,
limited and not really correct version of ID remapping.
While doing a full replacement would have been ideal, this is
risky/time-constrained for Blender 3.0 release, so for now we'll have
both versions co-existing.
Diffstat (limited to 'source/blender/blenkernel/intern/lib_remap.c')
-rw-r--r-- | source/blender/blenkernel/intern/lib_remap.c | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/lib_remap.c b/source/blender/blenkernel/intern/lib_remap.c index bba15a3bcdf..250b8d4d515 100644 --- a/source/blender/blenkernel/intern/lib_remap.c +++ b/source/blender/blenkernel/intern/lib_remap.c @@ -699,6 +699,9 @@ static int id_relink_to_newid_looper(LibraryIDLinkCallbackData *cb_data) * * Very specific usage, not sure we'll keep it on the long run, * currently only used in Object/Collection duplication code... + * + * WARNING: This is a deprecated version of this function, should not be used by new code. See + * #BKE_libblock_relink_to_newid_new below. */ void BKE_libblock_relink_to_newid(ID *id) { @@ -708,3 +711,53 @@ void BKE_libblock_relink_to_newid(ID *id) BKE_library_foreach_ID_link(NULL, id, id_relink_to_newid_looper, NULL, 0); } + +/* ************************ + * FIXME: Port all usages of #BKE_libblock_relink_to_newid to this + * #BKE_libblock_relink_to_newid_new new code and remove old one. + ************************** */ +static int id_relink_to_newid_looper_new(LibraryIDLinkCallbackData *cb_data) +{ + const int cb_flag = cb_data->cb_flag; + if (cb_flag & IDWALK_CB_EMBEDDED) { + return IDWALK_RET_NOP; + } + + Main *bmain = cb_data->bmain; + ID *id_owner = cb_data->id_owner; + ID **id_pointer = cb_data->id_pointer; + ID *id = *id_pointer; + if (id) { + /* See: NEW_ID macro */ + if (id->newid != NULL) { + BKE_libblock_relink_ex(bmain, id_owner, id, id->newid, ID_REMAP_SKIP_INDIRECT_USAGE); + id = id->newid; + } + if (id->tag & LIB_TAG_NEW) { + id->tag &= ~LIB_TAG_NEW; + BKE_libblock_relink_to_newid_new(bmain, id); + } + } + return IDWALK_RET_NOP; +} + +/** + * Remaps ID usages of given ID to their `id->newid` pointer if not None, and proceeds recursively + * in the dependency tree of IDs for all data-blocks tagged with `LIB_TAG_NEW`. + * + * NOTE: `LIB_TAG_NEW` is cleared + * + * Very specific usage, not sure we'll keep it on the long run, + * currently only used in Object/Collection duplication code... + */ +void BKE_libblock_relink_to_newid_new(Main *bmain, ID *id) +{ + if (ID_IS_LINKED(id)) { + return; + } + /* We do not want to have those cached relationship data here. */ + BLI_assert(bmain->relations == NULL); + + id->tag &= ~LIB_TAG_NEW; + BKE_library_foreach_ID_link(bmain, id, id_relink_to_newid_looper_new, NULL, 0); +} |