diff options
Diffstat (limited to 'source/blender/blenkernel/intern/main.c')
-rw-r--r-- | source/blender/blenkernel/intern/main.c | 73 |
1 files changed, 11 insertions, 62 deletions
diff --git a/source/blender/blenkernel/intern/main.c b/source/blender/blenkernel/intern/main.c index 11150f827e2..a4500e6616d 100644 --- a/source/blender/blenkernel/intern/main.c +++ b/source/blender/blenkernel/intern/main.c @@ -173,12 +173,6 @@ static int main_relations_create_idlink_cb(void *user_data, ID *id_self, ID **id return IDWALK_RET_NOP; } -static bool main_relations_create_id_cb(Main *bmain, ID *id, void *UNUSED(user_data)) -{ - BKE_library_foreach_ID_link(NULL, id, main_relations_create_idlink_cb, bmain->relations, IDWALK_READONLY); - return true; -} - /** Generate the mappings between used IDs and their users, and vice-versa. */ void BKE_main_relations_create(Main *bmain) { @@ -191,7 +185,12 @@ void BKE_main_relations_create(Main *bmain) bmain->relations->id_user_to_used = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, __func__); bmain->relations->entry_pool = BLI_mempool_create(sizeof(MainIDRelationsEntry), 128, 128, BLI_MEMPOOL_NOP); - BKE_main_foreach_id(bmain, false, main_relations_create_id_cb, NULL); + ID *id; + FOREACH_MAIN_ID_BEGIN(bmain, id) + { + BKE_library_foreach_ID_link(NULL, id, main_relations_create_idlink_cb, bmain->relations, IDWALK_READONLY); + } + FOREACH_MAIN_ID_END; } void BKE_main_relations_free(Main *bmain) @@ -209,13 +208,6 @@ void BKE_main_relations_free(Main *bmain) } } -static bool main_gset_create(Main *UNUSED(bmain), ID *id, void *user_data) -{ - GSet *gset = user_data; - BLI_gset_add(gset, id); - return true; -} - /** * Create a GSet storing all IDs present in given \a bmain, by their pointers. * @@ -226,57 +218,14 @@ GSet *BKE_main_gset_create(Main *bmain, GSet *gset) if (gset == NULL) { gset = BLI_gset_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, __func__); } - BKE_main_foreach_id(bmain, false, main_gset_create, gset); - return gset; -} - -/** - * Call given callback over every IDs of given \a lb listbase (assumed to be part of given \a bmain). - * - * \return false if the iteration was iterrupted by the callback. - * - * \warning \a callback may affect the ID, but DO NOT change the listbase or Main database (add/remove/reorder its IDs). - */ -bool BKE_main_listbase_foreach_id( - Main *bmain, ListBase *lb, - MainForeachIDCallback callback, void *user_data) -{ - bool keep_looping = true; - for (ID *id = lb->first; id; id = id->next) { - if (!(keep_looping = callback(bmain, id, user_data))) { - return keep_looping; - } - } - return keep_looping; -} - -/** - * Call given callback over every IDs of given \a bmain Main database. - * - * \param reverse_type_order: Allow to reverse order in which ID *types* are handled - * (i.e. does not reverse the order in which IDs themselves are handled whithin a give listbase). - * Note that in most cases, you want to set that parameter to true. - * \return false if the iteration was iterrupted by the callback. - * - * \warning \a callback may affect the ID, but DO NOT change the Main database (add/remove/reorder its IDs). - */ -bool BKE_main_foreach_id( - Main *bmain, const bool reverse_type_order, - MainForeachIDCallback callback, void *user_data) -{ - ListBase *lbarray[MAX_LIBARRAY]; - const int nbr_types = set_listbasepointers(bmain, lbarray); - bool keep_looping = true; - for (int i = reverse_type_order ? nbr_types - 1 : 0; - reverse_type_order ? i >= 0 : i < nbr_types; - reverse_type_order ? i-- : i++) + ID *id; + FOREACH_MAIN_ID_BEGIN(bmain, id) { - if (!(keep_looping = BKE_main_listbase_foreach_id(bmain, lbarray[i], callback, user_data))) { - return keep_looping; - } + BLI_gset_add(gset, id); } - return keep_looping; + FOREACH_MAIN_ID_END; + return gset; } /** |