Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/collection.c
| Show First 20 Lines • Show All 137 Lines • ▼ Show 20 Lines | static void collection_free_data(ID *id) | ||||
| BKE_collection_object_cache_free(collection); | BKE_collection_object_cache_free(collection); | ||||
| } | } | ||||
| static void collection_foreach_id(ID *id, LibraryForeachIDData *data) | static void collection_foreach_id(ID *id, LibraryForeachIDData *data) | ||||
| { | { | ||||
| Collection *collection = (Collection *)id; | Collection *collection = (Collection *)id; | ||||
| BKE_LIB_FOREACHID_PROCESS_ID( | |||||
| data, collection->owner_id, IDWALK_CB_LOOPBACK | IDWALK_CB_NEVER_SELF); | |||||
| LISTBASE_FOREACH (CollectionObject *, cob, &collection->gobject) { | LISTBASE_FOREACH (CollectionObject *, cob, &collection->gobject) { | ||||
| BKE_LIB_FOREACHID_PROCESS_IDSUPER(data, cob->ob, IDWALK_CB_USER); | BKE_LIB_FOREACHID_PROCESS_IDSUPER(data, cob->ob, IDWALK_CB_USER); | ||||
| } | } | ||||
| LISTBASE_FOREACH (CollectionChild *, child, &collection->children) { | LISTBASE_FOREACH (CollectionChild *, child, &collection->children) { | ||||
| BKE_LIB_FOREACHID_PROCESS_IDSUPER( | BKE_LIB_FOREACHID_PROCESS_IDSUPER( | ||||
| data, child->collection, IDWALK_CB_NEVER_SELF | IDWALK_CB_USER); | data, child->collection, IDWALK_CB_NEVER_SELF | IDWALK_CB_USER); | ||||
| } | } | ||||
| LISTBASE_FOREACH (CollectionParent *, parent, &collection->parents) { | LISTBASE_FOREACH (CollectionParent *, parent, &collection->parents) { | ||||
| /* XXX This is very weak. The whole idea of keeping pointers to private IDs is very bad | /* XXX This is very weak. The whole idea of keeping pointers to private IDs is very bad | ||||
| * anyway... */ | * anyway... */ | ||||
| const int cb_flag = ((parent->collection != NULL && | const int cb_flag = ((parent->collection != NULL && | ||||
| (parent->collection->id.flag & LIB_EMBEDDED_DATA) != 0) ? | (parent->collection->id.flag & LIB_EMBEDDED_DATA) != 0) ? | ||||
| IDWALK_CB_EMBEDDED : | IDWALK_CB_EMBEDDED : | ||||
| IDWALK_CB_NOP); | IDWALK_CB_NOP); | ||||
| BKE_LIB_FOREACHID_PROCESS_IDSUPER( | BKE_LIB_FOREACHID_PROCESS_IDSUPER( | ||||
| data, parent->collection, IDWALK_CB_NEVER_SELF | IDWALK_CB_LOOPBACK | cb_flag); | data, parent->collection, IDWALK_CB_NEVER_SELF | IDWALK_CB_LOOPBACK | cb_flag); | ||||
| } | } | ||||
| } | } | ||||
| static ID *collection_owner_get(Main *bmain, ID *id, ID *owner_id_hint) | static ID *collection_owner_get(Main *bmain, ID *id, ID *UNUSED(owner_id_hint)) | ||||
brecht: This `owner_id_hint` parameter can now be eliminated from `IDTypeEmbeddedOwnerGetFunction`? | |||||
mont29AuthorUnsubmitted Done Inline ActionsIndeed, but will do in a separate 'cleanup' commit. mont29: Indeed, but will do in a separate 'cleanup' commit. | |||||
| { | { | ||||
| if ((id->flag & LIB_EMBEDDED_DATA) == 0) { | if ((id->flag & LIB_EMBEDDED_DATA) == 0) { | ||||
| return id; | return id; | ||||
| } | } | ||||
| BLI_assert((id->tag & LIB_TAG_NO_MAIN) == 0); | BLI_assert((id->tag & LIB_TAG_NO_MAIN) == 0); | ||||
| Collection *master_collection = (Collection *)id; | Collection *master_collection = (Collection *)id; | ||||
| BLI_assert((master_collection->flag & COLLECTION_IS_MASTER) != 0); | BLI_assert((master_collection->flag & COLLECTION_IS_MASTER) != 0); | ||||
| BLI_assert(master_collection->owner_id != NULL); | |||||
| if (owner_id_hint != NULL && GS(owner_id_hint->name) == ID_SCE && | #ifndef NDEBUG | ||||
| ((Scene *)owner_id_hint)->master_collection == master_collection) { | bool is_owner_found = false; | ||||
| return owner_id_hint; | |||||
| } | |||||
| LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) { | LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) { | ||||
| if (scene->master_collection == master_collection) { | if (scene->master_collection == master_collection) { | ||||
| return &scene->id; | BLI_assert(master_collection->owner_id == &scene->id); | ||||
| BLI_assert(!is_owner_found); | |||||
| is_owner_found = true; | |||||
| } | } | ||||
| } | } | ||||
| BLI_assert(is_owner_found); | |||||
| #endif | |||||
| BLI_assert_msg(0, "Embedded collection with no owner. Critical Main inconsistency."); | return master_collection->owner_id; | ||||
| return NULL; | |||||
| } | } | ||||
| void BKE_collection_blend_write_nolib(BlendWriter *writer, Collection *collection) | void BKE_collection_blend_write_nolib(BlendWriter *writer, Collection *collection) | ||||
| { | { | ||||
| BKE_id_blend_write(writer, &collection->id); | BKE_id_blend_write(writer, &collection->id); | ||||
| /* Shared function for collection data-blocks and scene master collection. */ | /* Shared function for collection data-blocks and scene master collection. */ | ||||
| BKE_previewimg_blend_write(writer, collection->preview); | BKE_previewimg_blend_write(writer, collection->preview); | ||||
| Show All 32 Lines | void BKE_collection_compat_blend_read_data(BlendDataReader *reader, SceneCollection *sc) | ||||
| BLO_read_list(reader, &sc->scene_collections); | BLO_read_list(reader, &sc->scene_collections); | ||||
| LISTBASE_FOREACH (SceneCollection *, nsc, &sc->scene_collections) { | LISTBASE_FOREACH (SceneCollection *, nsc, &sc->scene_collections) { | ||||
| BKE_collection_compat_blend_read_data(reader, nsc); | BKE_collection_compat_blend_read_data(reader, nsc); | ||||
| } | } | ||||
| } | } | ||||
| #endif | #endif | ||||
| void BKE_collection_blend_read_data(BlendDataReader *reader, Collection *collection) | void BKE_collection_blend_read_data(BlendDataReader *reader, Collection *collection, ID *owner_id) | ||||
| { | { | ||||
| /* Special case for this pointer, do not rely on regular `lib_link` process here. Avoids needs | |||||
| * for do_versioning, and ensures coherence of data in any case. */ | |||||
| BLI_assert((collection->id.flag & LIB_EMBEDDED_DATA) != 0 || owner_id == NULL); | |||||
| collection->owner_id = owner_id; | |||||
| BLO_read_list(reader, &collection->gobject); | BLO_read_list(reader, &collection->gobject); | ||||
| BLO_read_list(reader, &collection->children); | BLO_read_list(reader, &collection->children); | ||||
| BLO_read_data_address(reader, &collection->preview); | BLO_read_data_address(reader, &collection->preview); | ||||
| BKE_previewimg_blend_read(reader, collection->preview); | BKE_previewimg_blend_read(reader, collection->preview); | ||||
| collection->flag &= ~COLLECTION_HAS_OBJECT_CACHE; | collection->flag &= ~COLLECTION_HAS_OBJECT_CACHE; | ||||
| collection->flag &= ~COLLECTION_HAS_OBJECT_CACHE_INSTANCED; | collection->flag &= ~COLLECTION_HAS_OBJECT_CACHE_INSTANCED; | ||||
| Show All 14 Lines | if (collection->view_layer != NULL) { | ||||
| BKE_view_layer_blend_read_data(reader, collection->view_layer); | BKE_view_layer_blend_read_data(reader, collection->view_layer); | ||||
| } | } | ||||
| #endif | #endif | ||||
| } | } | ||||
| static void collection_blend_read_data(BlendDataReader *reader, ID *id) | static void collection_blend_read_data(BlendDataReader *reader, ID *id) | ||||
| { | { | ||||
| Collection *collection = (Collection *)id; | Collection *collection = (Collection *)id; | ||||
| BKE_collection_blend_read_data(reader, collection); | BKE_collection_blend_read_data(reader, collection, NULL); | ||||
| } | } | ||||
| static void lib_link_collection_data(BlendLibReader *reader, Library *lib, Collection *collection) | static void lib_link_collection_data(BlendLibReader *reader, Library *lib, Collection *collection) | ||||
| { | { | ||||
| LISTBASE_FOREACH_MUTABLE (CollectionObject *, cob, &collection->gobject) { | LISTBASE_FOREACH_MUTABLE (CollectionObject *, cob, &collection->gobject) { | ||||
| BLO_read_id_address(reader, lib, &cob->ob); | BLO_read_id_address(reader, lib, &cob->ob); | ||||
| if (cob->ob == NULL) { | if (cob->ob == NULL) { | ||||
| ▲ Show 20 Lines • Show All 567 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Scene Master Collection | /** \name Scene Master Collection | ||||
| * \{ */ | * \{ */ | ||||
| Collection *BKE_collection_master_add() | Collection *BKE_collection_master_add(Scene *scene) | ||||
| { | { | ||||
| BLI_assert(scene != NULL && scene->master_collection == NULL); | |||||
| /* Not an actual datablock, but owned by scene. */ | /* Not an actual datablock, but owned by scene. */ | ||||
| Collection *master_collection = BKE_libblock_alloc( | Collection *master_collection = BKE_libblock_alloc( | ||||
| NULL, ID_GR, BKE_SCENE_COLLECTION_NAME, LIB_ID_CREATE_NO_MAIN); | NULL, ID_GR, BKE_SCENE_COLLECTION_NAME, LIB_ID_CREATE_NO_MAIN); | ||||
| master_collection->id.flag |= LIB_EMBEDDED_DATA; | master_collection->id.flag |= LIB_EMBEDDED_DATA; | ||||
| master_collection->owner_id = &scene->id; | |||||
| master_collection->flag |= COLLECTION_IS_MASTER; | master_collection->flag |= COLLECTION_IS_MASTER; | ||||
| master_collection->color_tag = COLLECTION_COLOR_NONE; | master_collection->color_tag = COLLECTION_COLOR_NONE; | ||||
| return master_collection; | return master_collection; | ||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Cyclic Checks | /** \name Cyclic Checks | ||||
| * \{ */ | * \{ */ | ||||
| ▲ Show 20 Lines • Show All 1,237 Lines • Show Last 20 Lines | |||||
This owner_id_hint parameter can now be eliminated from IDTypeEmbeddedOwnerGetFunction?