diff options
Diffstat (limited to 'source/blender/blenkernel/intern/main.c')
-rw-r--r-- | source/blender/blenkernel/intern/main.c | 102 |
1 files changed, 45 insertions, 57 deletions
diff --git a/source/blender/blenkernel/intern/main.c b/source/blender/blenkernel/intern/main.c index 5afa5890f14..e55b05ce797 100644 --- a/source/blender/blenkernel/intern/main.c +++ b/source/blender/blenkernel/intern/main.c @@ -217,29 +217,45 @@ static int main_relations_create_idlink_cb(LibraryIDLinkCallbackData *cb_data) const int cb_flag = cb_data->cb_flag; if (*id_pointer) { - MainIDRelationsEntry *entry, **entry_p; - - entry = BLI_mempool_alloc(bmain_relations->entry_pool); - if (BLI_ghash_ensure_p(bmain_relations->id_user_to_used, id_self, (void ***)&entry_p)) { - entry->next = *entry_p; - } - else { - entry->next = NULL; + MainIDRelationsEntry **entry_p; + + /* Add `id_pointer` as child of `id_self`. */ + { + if (!BLI_ghash_ensure_p( + bmain_relations->relations_from_pointers, id_self, (void ***)&entry_p)) { + *entry_p = MEM_callocN(sizeof(**entry_p), __func__); + (*entry_p)->session_uuid = id_self->session_uuid; + } + else { + BLI_assert((*entry_p)->session_uuid == id_self->session_uuid); + } + MainIDRelationsEntryItem *to_id_entry = BLI_mempool_alloc(bmain_relations->entry_items_pool); + to_id_entry->next = (*entry_p)->to_ids; + to_id_entry->id_pointer.to = id_pointer; + to_id_entry->session_uuid = (*id_pointer != NULL) ? (*id_pointer)->session_uuid : + MAIN_ID_SESSION_UUID_UNSET; + to_id_entry->usage_flag = cb_flag; + (*entry_p)->to_ids = to_id_entry; } - entry->id_pointer = id_pointer; - entry->usage_flag = cb_flag; - *entry_p = entry; - entry = BLI_mempool_alloc(bmain_relations->entry_pool); - if (BLI_ghash_ensure_p(bmain_relations->id_used_to_user, *id_pointer, (void ***)&entry_p)) { - entry->next = *entry_p; - } - else { - entry->next = NULL; + /* Add `id_self` as parent of `id_pointer`. */ + if (*id_pointer != NULL) { + if (!BLI_ghash_ensure_p( + bmain_relations->relations_from_pointers, *id_pointer, (void ***)&entry_p)) { + *entry_p = MEM_callocN(sizeof(**entry_p), __func__); + (*entry_p)->session_uuid = (*id_pointer)->session_uuid; + } + else { + BLI_assert((*entry_p)->session_uuid == (*id_pointer)->session_uuid); + } + MainIDRelationsEntryItem *from_id_entry = BLI_mempool_alloc( + bmain_relations->entry_items_pool); + from_id_entry->next = (*entry_p)->from_ids; + from_id_entry->id_pointer.from = id_self; + from_id_entry->session_uuid = id_self->session_uuid; + from_id_entry->usage_flag = cb_flag; + (*entry_p)->from_ids = from_id_entry; } - entry->id_pointer = (ID **)id_self; - entry->usage_flag = cb_flag; - *entry_p = entry; } return IDWALK_RET_NOP; @@ -253,12 +269,12 @@ void BKE_main_relations_create(Main *bmain, const short flag) } bmain->relations = MEM_mallocN(sizeof(*bmain->relations), __func__); - bmain->relations->id_used_to_user = BLI_ghash_new( - BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, __func__); - bmain->relations->id_user_to_used = BLI_ghash_new( + bmain->relations->relations_from_pointers = BLI_ghash_new( BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, __func__); - bmain->relations->entry_pool = BLI_mempool_create( - sizeof(MainIDRelationsEntry), 128, 128, BLI_MEMPOOL_NOP); + bmain->relations->entry_items_pool = BLI_mempool_create( + sizeof(MainIDRelationsEntryItem), 128, 128, BLI_MEMPOOL_NOP); + + bmain->relations->flag = flag; ID *id; FOREACH_MAIN_ID_BEGIN (bmain, id) { @@ -268,49 +284,21 @@ void BKE_main_relations_create(Main *bmain, const short flag) NULL, id, main_relations_create_idlink_cb, bmain->relations, idwalk_flag); } FOREACH_MAIN_ID_END; - - bmain->relations->flag = flag; } void BKE_main_relations_free(Main *bmain) { - if (bmain->relations) { - if (bmain->relations->id_used_to_user) { - BLI_ghash_free(bmain->relations->id_used_to_user, NULL, NULL); - } - if (bmain->relations->id_user_to_used) { - BLI_ghash_free(bmain->relations->id_user_to_used, NULL, NULL); + if (bmain->relations != NULL) { + if (bmain->relations->relations_from_pointers != NULL) { + BLI_ghash_free(bmain->relations->relations_from_pointers, NULL, MEM_freeN); } - BLI_mempool_destroy(bmain->relations->entry_pool); + BLI_mempool_destroy(bmain->relations->entry_items_pool); MEM_freeN(bmain->relations); bmain->relations = NULL; } } /** - * Remove an ID from the relations (the two entries for that ID, not the ID from entries in other - * IDs' relationships). - * - * Does not free any allocated memory. - * Allows to use those relations as a way to mark an ID as already processed, without requiring any - * additional tagging or GSet. - * Obviously, relations should be freed after use then, since this will make them fully invalid. - */ -void BKE_main_relations_ID_remove(Main *bmain, ID *id) -{ - if (bmain->relations) { - /* Note: we do not free the entries from the mempool, those will be dealt with when finally - * freeing the whole relations. */ - if (bmain->relations->id_used_to_user) { - BLI_ghash_remove(bmain->relations->id_used_to_user, id, NULL, NULL); - } - if (bmain->relations->id_user_to_used) { - BLI_ghash_remove(bmain->relations->id_user_to_used, id, NULL, NULL); - } - } -} - -/** * Create a GSet storing all IDs present in given \a bmain, by their pointers. * * \param gset: If not NULL, given GSet will be extended with IDs from given \a bmain, |