Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Montagne <bastien@blender.org>2021-02-25 12:17:31 +0300
committerBastien Montagne <bastien@blender.org>2021-02-25 13:39:10 +0300
commitde25b79ff5c4da7d2d604eaa33b8c520c246679b (patch)
treecf5f47ff016802ca3c90171d290ad0a2edb9a361 /source/blender/blenkernel/intern/collection.c
parentb5d39f9b469e6a1688bb4498f6635bd5e23a35ef (diff)
Refactor: IDTypeInfo: Add `owner_get` to get owner of embedded IDs.
This concerns currently only collections (`master_collection` of scenes) and root node trees. It removes the matching type-specific helpers (`BKE_collection_master_scene_search` and `BKE_node_tree_find_owner_ID`). No functional change expected here. NOTE: Current implementation of `owner_get` is far from optimal, we could probably do it better, see {T69169}. NOTE: While it could also have it, shapekeys IDTypeInfo was left out of this change for now. Mainly because it sould not be used currently, and we ultimately want to demote shape keys from ID status anyway.
Diffstat (limited to 'source/blender/blenkernel/intern/collection.c')
-rw-r--r--source/blender/blenkernel/intern/collection.c34
1 files changed, 21 insertions, 13 deletions
diff --git a/source/blender/blenkernel/intern/collection.c b/source/blender/blenkernel/intern/collection.c
index dd0572f9b12..28b91dcc8ce 100644
--- a/source/blender/blenkernel/intern/collection.c
+++ b/source/blender/blenkernel/intern/collection.c
@@ -172,6 +172,26 @@ static void collection_foreach_id(ID *id, LibraryForeachIDData *data)
}
}
+static ID *collection_owner_get(Main *bmain, ID *id)
+{
+ if ((id->flag & LIB_EMBEDDED_DATA) == 0) {
+ return id;
+ }
+ BLI_assert((id->tag & LIB_TAG_NO_MAIN) == 0);
+
+ Collection *master_collection = (Collection *)id;
+ BLI_assert((master_collection->flag & COLLECTION_IS_MASTER) != 0);
+
+ for (Scene *scene = bmain->scenes.first; scene != NULL; scene = scene->id.next) {
+ if (scene->master_collection == master_collection) {
+ return &scene->id;
+ }
+ }
+
+ BLI_assert(!"Embedded collection with no owner. Critical Main inconsistency.");
+ return NULL;
+}
+
void BKE_collection_blend_write_nolib(BlendWriter *writer, Collection *collection)
{
BKE_id_blend_write(writer, &collection->id);
@@ -355,6 +375,7 @@ IDTypeInfo IDType_ID_GR = {
.make_local = NULL,
.foreach_id = collection_foreach_id,
.foreach_cache = NULL,
+ .owner_get = collection_owner_get,
.blend_write = collection_blend_write,
.blend_read_data = collection_blend_read_data,
@@ -839,19 +860,6 @@ Collection *BKE_collection_master_add()
return master_collection;
}
-Scene *BKE_collection_master_scene_search(const Main *bmain, const Collection *master_collection)
-{
- BLI_assert((master_collection->flag & COLLECTION_IS_MASTER) != 0);
-
- for (Scene *scene = bmain->scenes.first; scene != NULL; scene = scene->id.next) {
- if (scene->master_collection == master_collection) {
- return scene;
- }
- }
-
- return NULL;
-}
-
/** \} */
/* -------------------------------------------------------------------- */