From 874cf52c10d73911cfec709d9b0202ac690aab6f Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Tue, 6 Oct 2020 17:43:12 +0200 Subject: Refactor: Remove `BKE_XXX_localize()`, in favor of using regular ID copying code. Besides the NodeTree case (which remains unchanged), the localize code is only used in one place (to generate previews of shading data-blocks). This commit introduces a new `LIB_ID_CREATE_LOCAL` option for ID creation/copying, which essentially implements the behavior of the removed `BKE_XXX_localize()` functions into regular mainstream ID copy code. When this option is set: - new ID is tagged with `LIB_TAG_LOCALIZED`; - Some ID copying callbacks have specific behaviors, mainly the root nodetree of shading IDs gets duplicated with specialized `ntreeLocalize()` function. Note that I would not consider getting rid of `ntreeLocalize` for now, this function is recursive, which should ideally never happen within ID management copying code (this introduces all kind of complications). No behavioral change expected from this commit. --- source/blender/blenkernel/intern/world.c | 41 +++++++------------------------- 1 file changed, 9 insertions(+), 32 deletions(-) (limited to 'source/blender/blenkernel/intern/world.c') diff --git a/source/blender/blenkernel/intern/world.c b/source/blender/blenkernel/intern/world.c index d5142e2d1a4..7590afeaaff 100644 --- a/source/blender/blenkernel/intern/world.c +++ b/source/blender/blenkernel/intern/world.c @@ -99,12 +99,19 @@ static void world_copy_data(Main *bmain, ID *id_dst, const ID *id_src, const int { World *wrld_dst = (World *)id_dst; const World *wrld_src = (const World *)id_src; + + const bool is_localized = (flag & LIB_ID_CREATE_LOCAL) != 0; /* We always need allocation of our private ID data. */ const int flag_private_id_data = flag & ~LIB_ID_CREATE_NO_ALLOCATE; if (wrld_src->nodetree) { - BKE_id_copy_ex( - bmain, (ID *)wrld_src->nodetree, (ID **)&wrld_dst->nodetree, flag_private_id_data); + if (is_localized) { + wrld_dst->nodetree = ntreeLocalize(wrld_src->nodetree); + } + else { + BKE_id_copy_ex( + bmain, (ID *)wrld_src->nodetree, (ID **)&wrld_dst->nodetree, flag_private_id_data); + } } BLI_listbase_clear(&wrld_dst->gpumaterial); @@ -210,36 +217,6 @@ World *BKE_world_add(Main *bmain, const char *name) return wrld; } -World *BKE_world_localize(World *wrld) -{ - /* TODO(bastien): Replace with something like: - * - * World *wrld_copy; - * BKE_id_copy_ex(bmain, &wrld->id, (ID **)&wrld_copy, - * LIB_ID_COPY_NO_MAIN | LIB_ID_COPY_NO_PREVIEW | LIB_ID_COPY_NO_USER_REFCOUNT, - * false); - * return wrld_copy; - * - * NOTE: Only possible once nested node trees are fully converted to that too. */ - - World *wrldn; - - wrldn = BKE_libblock_copy_for_localize(&wrld->id); - - if (wrld->nodetree) { - wrldn->nodetree = ntreeLocalize(wrld->nodetree); - } - - wrldn->preview = NULL; - - BLI_listbase_clear(&wrldn->gpumaterial); - BLI_listbase_clear((ListBase *)&wrldn->drawdata); - - wrldn->id.tag |= LIB_TAG_LOCALIZED; - - return wrldn; -} - void BKE_world_eval(struct Depsgraph *depsgraph, World *world) { DEG_debug_print_eval(depsgraph, __func__, world->id.name, world); -- cgit v1.2.3