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.
This commit is contained in:
parent
2d13c823ee
commit
cddb792021
Notes:
blender-bot
2023-02-14 09:48:25 +01:00
Referenced by issue #91413, Remove deprecated `BKE_libblock_relink_to_newid` usages
|
@ -112,6 +112,7 @@ void BKE_libblock_relink_ex(struct Main *bmain,
|
|||
const short remap_flags) ATTR_NONNULL(1, 2);
|
||||
|
||||
void BKE_libblock_relink_to_newid(struct ID *id) ATTR_NONNULL();
|
||||
void BKE_libblock_relink_to_newid_new(struct Main *bmain, struct ID *id) ATTR_NONNULL();
|
||||
|
||||
typedef void (*BKE_library_free_notifier_reference_cb)(const void *);
|
||||
typedef void (*BKE_library_remap_editor_id_reference_cb)(struct ID *, struct ID *);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue