Cleanup: LibOverride: group logically utils static functions.

This commit is contained in:
Bastien Montagne
2021-02-01 17:39:00 +01:00
parent 198ff4703f
commit 2262e18269

View File

@@ -368,6 +368,46 @@ bool BKE_lib_override_library_create_from_tag(Main *bmain)
return success;
}
/* Tag all IDs in dependency relationships within an override hierarchy/group.
*
* Note: this is typically called to complete `lib_override_linked_group_tag()`.
* Note: BMain's relations mapping won't be valid anymore after that call.
*/
static bool lib_override_hierarchy_dependencies_recursive_tag(Main *bmain,
ID *id,
const uint tag,
const uint missing_tag)
{
MainIDRelationsEntry *entry = BLI_ghash_lookup(bmain->relations->relations_from_pointers, id);
BLI_assert(entry != NULL);
if (entry->tags & MAINIDRELATIONS_ENTRY_TAGS_PROCESSED) {
/* This ID has already been processed. */
return (*(uint *)&id->tag & tag) != 0;
}
/* This way we won't process again that ID, should we encounter it again through another
* relationship hierarchy. */
entry->tags |= MAINIDRELATIONS_ENTRY_TAGS_PROCESSED;
for (MainIDRelationsEntryItem *to_id_entry = entry->to_ids; to_id_entry != NULL;
to_id_entry = to_id_entry->next) {
if ((to_id_entry->usage_flag & IDWALK_CB_LOOPBACK) != 0) {
/* Never consider 'loop back' relationships ('from', 'parents', 'owner' etc. pointers) as
* actual dependencies. */
continue;
}
/* We only consider IDs from the same library. */
ID *to_id = *to_id_entry->id_pointer.to;
if (to_id != NULL && to_id->lib == id->lib) {
if (lib_override_hierarchy_dependencies_recursive_tag(bmain, to_id, tag, missing_tag)) {
id->tag |= tag;
}
}
}
return (*(uint *)&id->tag & tag) != 0;
}
typedef struct LibOverrideGroupTagData {
ID *id_root;
uint tag;
@@ -422,46 +462,6 @@ static int lib_override_linked_group_tag_cb(LibraryIDLinkCallbackData *cb_data)
return IDWALK_RET_NOP;
}
/* Tag all IDs in dependency relationships within an override hierarchy/group.
*
* Note: this is typically called to complete `lib_override_linked_group_tag()`.
* Note: BMain's relations mapping won't be valid anymore after that call.
*/
static bool lib_override_hierarchy_dependencies_recursive_tag(Main *bmain,
ID *id,
const uint tag,
const uint missing_tag)
{
MainIDRelationsEntry *entry = BLI_ghash_lookup(bmain->relations->relations_from_pointers, id);
BLI_assert(entry != NULL);
if (entry->tags & MAINIDRELATIONS_ENTRY_TAGS_PROCESSED) {
/* This ID has already been processed. */
return (*(uint *)&id->tag & tag) != 0;
}
/* This way we won't process again that ID, should we encounter it again through another
* relationship hierarchy. */
entry->tags |= MAINIDRELATIONS_ENTRY_TAGS_PROCESSED;
for (MainIDRelationsEntryItem *to_id_entry = entry->to_ids; to_id_entry != NULL;
to_id_entry = to_id_entry->next) {
if ((to_id_entry->usage_flag & IDWALK_CB_LOOPBACK) != 0) {
/* Never consider 'loop back' relationships ('from', 'parents', 'owner' etc. pointers) as
* actual dependencies. */
continue;
}
/* We only consider IDs from the same library. */
ID *to_id = *to_id_entry->id_pointer.to;
if (to_id != NULL && to_id->lib == id->lib) {
if (lib_override_hierarchy_dependencies_recursive_tag(bmain, to_id, tag, missing_tag)) {
id->tag |= tag;
}
}
}
return (*(uint *)&id->tag & tag) != 0;
}
/* This will tag at least all 'boundary' linked IDs for a potential override group.
*
* Note that you will then need to call #lib_override_hierarchy_dependencies_recursive_tag to