diff options
author | Bastien Montagne <bastien@blender.org> | 2020-10-06 18:43:12 +0300 |
---|---|---|
committer | Bastien Montagne <bastien@blender.org> | 2020-10-07 12:09:36 +0300 |
commit | 874cf52c10d73911cfec709d9b0202ac690aab6f (patch) | |
tree | eb168090d49f83ac37bfd259a7b0e794e92b1937 /source/blender/blenkernel/intern/light.c | |
parent | 94f91827f8938153dad7d4b7f88fa8431f2f756c (diff) |
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.
Diffstat (limited to 'source/blender/blenkernel/intern/light.c')
-rw-r--r-- | source/blender/blenkernel/intern/light.c | 37 |
1 files changed, 9 insertions, 28 deletions
diff --git a/source/blender/blenkernel/intern/light.c b/source/blender/blenkernel/intern/light.c index 1ce079b006e..437e61a5fca 100644 --- a/source/blender/blenkernel/intern/light.c +++ b/source/blender/blenkernel/intern/light.c @@ -81,13 +81,21 @@ static void light_copy_data(Main *bmain, ID *id_dst, const ID *id_src, const int { Light *la_dst = (Light *)id_dst; const Light *la_src = (const Light *)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; la_dst->curfalloff = BKE_curvemapping_copy(la_src->curfalloff); if (la_src->nodetree) { - BKE_id_copy_ex(bmain, (ID *)la_src->nodetree, (ID **)&la_dst->nodetree, flag_private_id_data); + if (is_localized) { + la_dst->nodetree = ntreeLocalize(la_src->nodetree); + } + else { + BKE_id_copy_ex( + bmain, (ID *)la_src->nodetree, (ID **)&la_dst->nodetree, flag_private_id_data); + } } if ((flag & LIB_ID_COPY_NO_PREVIEW) == 0) { @@ -219,33 +227,6 @@ Light *BKE_light_copy(Main *bmain, const Light *la) return la_copy; } -Light *BKE_light_localize(Light *la) -{ - /* TODO(bastien): Replace with something like: - * - * Light *la_copy; - * BKE_id_copy_ex(bmain, &la->id, (ID **)&la_copy, - * LIB_ID_COPY_NO_MAIN | LIB_ID_COPY_NO_PREVIEW | LIB_ID_COPY_NO_USER_REFCOUNT, - * false); - * return la_copy; - * - * NOTE: Only possible once nested node trees are fully converted to that too. */ - - Light *lan = BKE_libblock_copy_for_localize(&la->id); - - lan->curfalloff = BKE_curvemapping_copy(la->curfalloff); - - if (la->nodetree) { - lan->nodetree = ntreeLocalize(la->nodetree); - } - - lan->preview = NULL; - - lan->id.tag |= LIB_TAG_LOCALIZED; - - return lan; -} - void BKE_light_eval(struct Depsgraph *depsgraph, Light *la) { DEG_debug_print_eval(depsgraph, __func__, la->id.name, la); |