Commit: 18fb8ed3fbd81f1239b4707fbb751585f43224ea Author: Jacques Lucke Date: Thu Feb 20 11:09:43 2020 +0100 Branches: simulation-tree https://developer.blender.org/rB18fb8ed3fbd81f1239b4707fbb751585f43224ea
unify socket type freeing =================================================================== M source/blender/blenkernel/BKE_node.h M source/blender/blenkernel/intern/node.c M source/blender/makesrna/intern/rna_nodetree.c M source/blender/nodes/intern/node_socket.c M source/blender/simulations/nodes/my_test_node.cc =================================================================== diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h index 98a6ff743ee..ae32093674b 100644 --- a/source/blender/blenkernel/BKE_node.h +++ b/source/blender/blenkernel/BKE_node.h @@ -148,7 +148,9 @@ typedef struct bNodeSocketType { /* Custom data that can be passed into callbacks. */ void *userdata; - void (*free_userdata)(void *userdata); + + /* Callback to free the socket type. */ + void (*free_self)(struct bNodeSocketType *stype); } bNodeSocketType; typedef void *(*NodeInitExecFunction)(struct bNodeExecContext *context, diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c index e06cd7665f8..4c66da6eed8 100644 --- a/source/blender/blenkernel/intern/node.c +++ b/source/blender/blenkernel/intern/node.c @@ -468,10 +468,7 @@ static void node_free_socket_type(void *socktype_v) * or we'd want to update *all* active Mains, which we cannot do anyway currently. */ update_typeinfo(G_MAIN, NULL, NULL, NULL, socktype, true); - if (socktype->free_userdata != NULL) { - socktype->free_userdata(socktype->userdata); - } - MEM_freeN(socktype); + socktype->free_self(socktype); } void nodeRegisterSocketType(bNodeSocketType *st) diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c index 43aa7e6d347..db2315ea804 100644 --- a/source/blender/makesrna/intern/rna_nodetree.c +++ b/source/blender/makesrna/intern/rna_nodetree.c @@ -2215,6 +2215,8 @@ static StructRNA *rna_NodeSocket_register(Main *UNUSED(bmain), nodeRegisterSocketType(st); } + st->free_self = (void (*)(bNodeSocketType * stype)) MEM_freeN; + /* if RNA type is already registered, unregister first */ if (st->ext_socket.srna) { StructRNA *srna = st->ext_socket.srna; @@ -2529,6 +2531,8 @@ static StructRNA *rna_NodeSocketInterface_register(Main *UNUSED(bmain), nodeRegisterSocketType(st); } + st->free_self = (void (*)(bNodeSocketType * stype)) MEM_freeN; + /* if RNA type is already registered, unregister first */ if (st->ext_interface.srna) { StructRNA *srna = st->ext_interface.srna; diff --git a/source/blender/nodes/intern/node_socket.c b/source/blender/nodes/intern/node_socket.c index 13f9039379d..740e45bc5e1 100644 --- a/source/blender/nodes/intern/node_socket.c +++ b/source/blender/nodes/intern/node_socket.c @@ -403,6 +403,7 @@ static bNodeSocketType *make_standard_socket_type(int type, int subtype) StructRNA *srna; stype = MEM_callocN(sizeof(bNodeSocketType), "node socket C type"); + stype->free_self = (void (*)(bNodeSocketType * stype)) MEM_freeN; BLI_strncpy(stype->idname, socket_idname, sizeof(stype->idname)); /* set the RNA type @@ -441,6 +442,7 @@ static bNodeSocketType *make_socket_type_virtual(void) StructRNA *srna; stype = MEM_callocN(sizeof(bNodeSocketType), "node socket C type"); + stype->free_self = (void (*)(bNodeSocketType * stype)) MEM_freeN; BLI_strncpy(stype->idname, socket_idname, sizeof(stype->idname)); /* set the RNA type diff --git a/source/blender/simulations/nodes/my_test_node.cc b/source/blender/simulations/nodes/my_test_node.cc index 9c3f9185dab..b9493832f53 100644 --- a/source/blender/simulations/nodes/my_test_node.cc +++ b/source/blender/simulations/nodes/my_test_node.cc @@ -355,6 +355,7 @@ class SocketTypeDefinition { const char *text) { uiItemL(layout, text, 0); }; m_stype.draw_color = SocketTypeDefinition::get_draw_color; + m_stype.free_self = [](bNodeSocketType *UNUSED(stype)) {}; m_stype.userdata = (void *)this; } @@ -643,30 +644,6 @@ void register_node_type_my_test_node() } } -static bNodeSocketType *register_new_simple_socket_type(StringRefNull idname, rgba_f color) -{ - bNodeSocketType *stype = (bNodeSocketType *)MEM_callocN(sizeof(bNodeSocketType), __func__); - BLI_strncpy(stype->idname, idname.data(), sizeof(stype->idname)); - stype->draw = [](struct bContext *UNUSED(C), - struct uiLayout *layout, - struct PointerRNA *UNUSED(ptr), - struct PointerRNA *UNUSED(node_ptr), - const char *text) { uiItemL(layout, text, 0); }; - - stype->userdata = new rgba_f(color); - stype->free_userdata = [](void *userdata) { delete (rgba_f *)userdata; }; - - stype->draw_color = [](struct bContext *UNUSED(C), - struct PointerRNA *ptr, - struct PointerRNA *UNUSED(node_ptr), - float *r_color) { - rgba_f color = *(rgba_f *)((bNodeSocket *)ptr->data)->typeinfo->userdata; - *(rgba_f *)r_color = color; - }; - nodeRegisterSocketType(stype); - return stype; -} - void init_socket_data_types() { { @@ -674,8 +651,11 @@ void init_socket_data_types() stype.set_color({0.63, 0.63, 0.63, 0.5}); stype.register_type(); } - // register_new_simple_socket_type("NodeSocketFloatList", {0.63, 0.63, 0.63, 0.5}); - register_new_simple_socket_type("NodeSocketIntList", {0.06, 0.52, 0.15, 0.5}); + { + static SocketTypeDefinition stype("NodeSocketIntList"); + stype.set_color({0.06, 0.52, 0.15, 0.5}); + stype.register_type(); + } data_socket_float = new BaseSocketDataType("Float", nodeSocketTypeFind("NodeSocketFloat")); data_socket_int = new BaseSocketDataType("Integer", nodeSocketTypeFind("NodeSocketInt")); _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org https://lists.blender.org/mailman/listinfo/bf-blender-cvs