Commit: f9c7442479a9969ae8c366270c12cd12306750da Author: Bastien Montagne Date: Fri Mar 6 14:57:26 2020 +0100 Branches: master https://developer.blender.org/rBf9c7442479a9969ae8c366270c12cd12306750da
Cleanup: bNodeTree: Move to IDTypeInfo and remove unused BKE API. =================================================================== M source/blender/blenkernel/BKE_idtype.h M source/blender/blenkernel/BKE_node.h M source/blender/blenkernel/intern/idtype.c M source/blender/blenkernel/intern/lib_id.c M source/blender/blenkernel/intern/lib_id_delete.c M source/blender/blenkernel/intern/node.c =================================================================== diff --git a/source/blender/blenkernel/BKE_idtype.h b/source/blender/blenkernel/BKE_idtype.h index 75c8a0aafd4..0baf4010a4f 100644 --- a/source/blender/blenkernel/BKE_idtype.h +++ b/source/blender/blenkernel/BKE_idtype.h @@ -147,7 +147,7 @@ extern IDTypeInfo IDType_ID_WO; // extern IDTypeInfo IDType_ID_GR; // extern IDTypeInfo IDType_ID_AR; // extern IDTypeInfo IDType_ID_AC; -// extern IDTypeInfo IDType_ID_NT; +extern IDTypeInfo IDType_ID_NT; extern IDTypeInfo IDType_ID_BR; // extern IDTypeInfo IDType_ID_PA; // extern IDTypeInfo IDType_ID_GD; diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h index 163f48d7bbb..ad8a1b82fd1 100644 --- a/source/blender/blenkernel/BKE_node.h +++ b/source/blender/blenkernel/BKE_node.h @@ -381,17 +381,12 @@ struct GHashIterator *ntreeTypeGetIterator(void); void ntreeSetTypes(const struct bContext *C, struct bNodeTree *ntree); -void ntreeInitDefault(struct bNodeTree *ntree); struct bNodeTree *ntreeAddTree(struct Main *bmain, const char *name, const char *idname); /* copy/free funcs, need to manage ID users */ void ntreeFreeTree(struct bNodeTree *ntree); /* Free tree which is owned byt another datablock. */ void ntreeFreeNestedTree(struct bNodeTree *ntree); -void BKE_node_tree_copy_data(struct Main *bmain, - struct bNodeTree *ntree_dst, - const struct bNodeTree *ntree_src, - const int flag); struct bNodeTree *ntreeCopyTree_ex(const struct bNodeTree *ntree, struct Main *bmain, const bool do_id_user); @@ -404,7 +399,6 @@ struct bNodeTree **BKE_ntree_ptr_from_id(struct ID *id); struct bNodeTree *ntreeFromID(struct ID *id); struct ID *BKE_node_tree_find_owner_ID(struct Main *bmain, struct bNodeTree *ntree); -void ntreeMakeLocal(struct Main *bmain, struct bNodeTree *ntree, const int flags); void ntreeFreeLocalNode(struct bNodeTree *ntree, struct bNode *node); void ntreeFreeLocalTree(struct bNodeTree *ntree); struct bNode *ntreeFindType(const struct bNodeTree *ntree, int type); diff --git a/source/blender/blenkernel/intern/idtype.c b/source/blender/blenkernel/intern/idtype.c index fb3d967a0bb..37449e89774 100644 --- a/source/blender/blenkernel/intern/idtype.c +++ b/source/blender/blenkernel/intern/idtype.c @@ -74,7 +74,7 @@ static void id_type_init(void) // INIT_TYPE(ID_GR); // INIT_TYPE(ID_AR); // INIT_TYPE(ID_AC); - // INIT_TYPE(ID_NT); + INIT_TYPE(ID_NT); INIT_TYPE(ID_BR); // INIT_TYPE(ID_PA); // INIT_TYPE(ID_GD); diff --git a/source/blender/blenkernel/intern/lib_id.c b/source/blender/blenkernel/intern/lib_id.c index b092029c538..954f1d51b6f 100644 --- a/source/blender/blenkernel/intern/lib_id.c +++ b/source/blender/blenkernel/intern/lib_id.c @@ -555,9 +555,7 @@ bool BKE_lib_id_make_local(Main *bmain, ID *id, const bool test, const int flags } return true; case ID_NT: - if (!test) { - ntreeMakeLocal(bmain, (bNodeTree *)id, flags); - } + BLI_assert(0); return true; case ID_BR: BLI_assert(0); @@ -773,7 +771,7 @@ bool BKE_id_copy_ex(Main *bmain, const ID *id, ID **r_newid, const int flag) BKE_action_copy_data(bmain, (bAction *)*r_newid, (bAction *)id, flag); break; case ID_NT: - BKE_node_tree_copy_data(bmain, (bNodeTree *)*r_newid, (bNodeTree *)id, flag); + BLI_assert(0); break; case ID_BR: BLI_assert(0); @@ -1400,7 +1398,7 @@ void BKE_libblock_init_empty(ID *id) /* Nothing to do. */ break; case ID_NT: - ntreeInitDefault((bNodeTree *)id); + BLI_assert(0); break; case ID_BR: BLI_assert(0); diff --git a/source/blender/blenkernel/intern/lib_id_delete.c b/source/blender/blenkernel/intern/lib_id_delete.c index b245f500f1a..4292531d47a 100644 --- a/source/blender/blenkernel/intern/lib_id_delete.c +++ b/source/blender/blenkernel/intern/lib_id_delete.c @@ -209,7 +209,7 @@ void BKE_libblock_free_datablock(ID *id, const int UNUSED(flag)) BKE_action_free((bAction *)id); break; case ID_NT: - ntreeFreeTree((bNodeTree *)id); + BLI_assert(0); break; case ID_BR: BLI_assert(0); diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c index 05f971ec367..a2bd1296c2b 100644 --- a/source/blender/blenkernel/intern/node.c +++ b/source/blender/blenkernel/intern/node.c @@ -53,6 +53,7 @@ #include "BKE_animsys.h" #include "BKE_global.h" #include "BKE_idprop.h" +#include "BKE_idtype.h" #include "BKE_lib_id.h" #include "BKE_main.h" #include "BKE_node.h" @@ -80,6 +81,190 @@ bNodeSocketType NodeSocketTypeUndefined; static CLG_LogRef LOG = {"bke.node"}; +static void ntree_set_typeinfo(bNodeTree *ntree, bNodeTreeType *typeinfo); +static void node_socket_copy(bNodeSocket *sock_dst, const bNodeSocket *sock_src, const int flag); +static void free_localized_node_groups(bNodeTree *ntree); +static void node_free_node(bNodeTree *ntree, bNode *node); +static void node_socket_interface_free(bNodeTree *UNUSED(ntree), bNodeSocket *sock); + +static void ntree_init_data(ID *id) +{ + bNodeTree *ntree = (bNodeTree *)id; + ntree_set_typeinfo(ntree, NULL); +} + +static void ntree_copy_data(Main *UNUSED(bmain), ID *id_dst, const ID *id_src, const int flag) +{ + bNodeTree *ntree_dst = (bNodeTree *)id_dst; + const bNodeTree *ntree_src = (const bNodeTree *)id_src; + bNodeSocket *sock_dst, *sock_src; + bNodeLink *link_dst; + + /* We never handle usercount here for own data. */ + const int flag_subdata = flag | LIB_ID_CREATE_NO_USER_REFCOUNT; + + /* in case a running nodetree is copied */ + ntree_dst->execdata = NULL; + + BLI_listbase_clear(&ntree_dst->nodes); + BLI_listbase_clear(&ntree_dst->links); + + /* Since source nodes and sockets are unique pointers we can put everything in a single map. */ + GHash *new_pointers = BLI_ghash_ptr_new(__func__); + + for (const bNode *node_src = ntree_src->nodes.first; node_src; node_src = node_src->next) { + bNode *new_node = BKE_node_copy_ex(ntree_dst, node_src, flag_subdata, true); + BLI_ghash_insert(new_pointers, (void *)node_src, new_node); + /* Store mapping to inputs. */ + bNodeSocket *new_input_sock = new_node->inputs.first; + const bNodeSocket *input_sock_src = node_src->inputs.first; + while (new_input_sock != NULL) { + BLI_ghash_insert(new_pointers, (void *)input_sock_src, new_input_sock); + new_input_sock = new_input_sock->next; + input_sock_src = input_sock_src->next; + } + /* Store mapping to outputs. */ + bNodeSocket *new_output_sock = new_node->outputs.first; + const bNodeSocket *output_sock_src = node_src->outputs.first; + while (new_output_sock != NULL) { + BLI_ghash_insert(new_pointers, (void *)output_sock_src, new_output_sock); + new_output_sock = new_output_sock->next; + output_sock_src = output_sock_src->next; + } + } + + /* copy links */ + BLI_duplicatelist(&ntree_dst->links, &ntree_src->links); + for (link_dst = ntree_dst->links.first; link_dst; link_dst = link_dst->next) { + link_dst->fromnode = BLI_ghash_lookup_default(new_pointers, link_dst->fromnode, NULL); + link_dst->fromsock = BLI_ghash_lookup_default(new_pointers, link_dst->fromsock, NULL); + link_dst->tonode = BLI_ghash_lookup_default(new_pointers, link_dst->tonode, NULL); + link_dst->tosock = BLI_ghash_lookup_default(new_pointers, link_dst->tosock, NULL); + /* update the link socket's pointer */ + if (link_dst->tosock) { + link_dst->tosock->link = link_dst; + } + } + + /* copy interface sockets */ + BLI_duplicatelist(&ntree_dst->inputs, &ntree_src->inputs); + for (sock_dst = ntree_dst->inputs.first, sock_src = ntree_src->inputs.first; sock_dst != NULL; + sock_dst = sock_dst->next, sock_src = sock_src->next) { + node_socket_copy(sock_dst, sock_src, flag_subdata); + } + + BLI_duplicatelist(&ntree_dst->outputs, &ntree_src->outputs); + for (sock_dst = ntree_dst->outputs.first, sock_src = ntree_src->outputs.first; sock_dst != NULL; + sock_dst = sock_dst->next, sock_src = sock_src->next) { + node_socket_copy(sock_dst, sock_src, flag_subdata); + } + + /* copy preview hash */ + if (ntree_src->previews && (flag & LIB_ID_COPY_NO_PREVIEW) == 0) { + bNodeInstanceHashIterator iter; + + ntree_dst->previews = BKE_node_instance_hash_new("node previews"); + + NODE_INSTANCE_HASH_ITER (iter, ntree_src->previews) { + bNodeInstanceKey key = BKE_node_instance_hash_iterator_get_key(&iter); + bNodePreview *preview = BKE_node_instance_hash_iterator_get_value(&iter); + BKE_node_instance_hash_insert(ntree_dst->previews, key, BKE_node_preview_copy(preview)); + } + } + else { + ntree_dst->previews = NULL; + } + + /* update node->parent pointers */ + for (bNode *node_dst = ntree_dst->nodes.first, *node_src = ntree_src->nodes.first; node_dst; + node_dst = node_dst->next, node_src = node_src->next) { + if (node_dst->parent) { + node_dst->parent = BLI_ghash_lookup_default(new_pointers, node_dst->parent, NULL); + } + } + + BLI_ghash_free(new_pointers, NULL, NULL); + + /* node tree will generate its own interface type */ + ntree_dst->interface_type = NULL; +} + +static void ntree_free_data(ID *id) +{ + bNodeTree *ntree = (bNodeTree *)id; + bNode *node, *next; + bNodeSocket *sock, *nextsock; + + BKE_animdata_free((ID *)ntree, false); + + /* XXX hack! node trees should not store execution graphs at all. + * This should be removed when old tree types no longer require it. + * Currently the execution data for texture nodes remains in the tree + * after execution, until the node tree is updated or freed. + */ + if (ntree->execdata) { + switch (ntree->type) { + case NTREE_SHADER: + ntreeShaderEndExecTree(ntree->execdata); + break; + case NTREE_TEXTURE: + ntreeTexEndExecTree(ntree->execdata); + ntree->execdata = NULL; + break; + } + } + + /* XXX not nice, but needed to free localized node groups properly */ + free_localized_node_groups(ntree) @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org https://lists.blender.org/mailman/listinfo/bf-blender-cvs