From 48b268d07f55643b74845ab42d360991af0c21d3 Mon Sep 17 00:00:00 2001 From: illua1 Date: Tue, 18 Apr 2023 20:11:55 +0300 Subject: [PATCH 1/6] init commit --- source/blender/blenkernel/intern/node.cc | 530 ++++++++++++----------- 1 file changed, 271 insertions(+), 259 deletions(-) diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc index c35d20c4ccd..34b0b6d4429 100644 --- a/source/blender/blenkernel/intern/node.cc +++ b/source/blender/blenkernel/intern/node.cc @@ -125,15 +125,15 @@ static void node_socket_interface_free(bNodeTree * /*ntree*/, static void ntree_init_data(ID *id) { - bNodeTree *ntree = (bNodeTree *)id; + bNodeTree *ntree = reinterpret_cast(id); ntree->runtime = MEM_new(__func__); ntree_set_typeinfo(ntree, nullptr); } static void ntree_copy_data(Main * /*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; + bNodeTree *ntree_dst = reinterpret_cast(id_dst); + const bNodeTree *ntree_src = reinterpret_cast(id_src); /* We never handle user-count here for own data. */ const int flag_subdata = flag | LIB_ID_CREATE_NO_USER_REFCOUNT; @@ -157,7 +157,7 @@ static void ntree_copy_data(Main * /*bmain*/, ID *id_dst, const ID *id_src, cons /* copy links */ BLI_listbase_clear(&ntree_dst->links); LISTBASE_FOREACH (const bNodeLink *, src_link, &ntree_src->links) { - bNodeLink *dst_link = (bNodeLink *)MEM_dupallocN(src_link); + bNodeLink *dst_link = reinterpret_cast(MEM_dupallocN(src_link)); dst_link->fromnode = dst_runtime.nodes_by_id.lookup_key_as(src_link->fromnode->identifier); dst_link->fromsock = socket_map.lookup(src_link->fromsock); dst_link->tonode = dst_runtime.nodes_by_id.lookup_key_as(src_link->tonode->identifier); @@ -177,13 +177,13 @@ static void ntree_copy_data(Main * /*bmain*/, ID *id_dst, const ID *id_src, cons /* copy interface sockets */ BLI_listbase_clear(&ntree_dst->inputs); LISTBASE_FOREACH (const bNodeSocket *, src_socket, &ntree_src->inputs) { - bNodeSocket *dst_socket = (bNodeSocket *)MEM_dupallocN(src_socket); + bNodeSocket *dst_socket = reinterpret_cast(MEM_dupallocN(src_socket)); node_socket_copy(dst_socket, src_socket, flag_subdata); BLI_addtail(&ntree_dst->inputs, dst_socket); } BLI_listbase_clear(&ntree_dst->outputs); LISTBASE_FOREACH (const bNodeSocket *, src_socket, &ntree_src->outputs) { - bNodeSocket *dst_socket = (bNodeSocket *)MEM_dupallocN(src_socket); + bNodeSocket *dst_socket = reinterpret_cast(MEM_dupallocN(src_socket)); node_socket_copy(dst_socket, src_socket, flag_subdata); BLI_addtail(&ntree_dst->outputs, dst_socket); } @@ -224,7 +224,7 @@ static void ntree_copy_data(Main * /*bmain*/, ID *id_dst, const ID *id_src, cons static void ntree_free_data(ID *id) { - bNodeTree *ntree = (bNodeTree *)id; + bNodeTree *ntree = reinterpret_cast(id); /* XXX hack! node trees should not store execution graphs at all. * This should be removed when old tree types no longer require it. @@ -281,31 +281,33 @@ static void library_foreach_node_socket(LibraryForeachIDData *data, bNodeSocket IDP_foreach_property( sock->prop, IDP_TYPE_FILTER_ID, BKE_lib_query_idpropertiesForeachIDLink_callback, data)); - switch ((eNodeSocketDatatype)sock->type) { + switch (static_cast(sock->type)) { case SOCK_OBJECT: { - bNodeSocketValueObject *default_value = (bNodeSocketValueObject *)sock->default_value; - BKE_LIB_FOREACHID_PROCESS_IDSUPER(data, default_value->value, IDWALK_CB_USER); + bNodeSocketValueObject &default_value = *sock->default_value_typed(); + BKE_LIB_FOREACHID_PROCESS_IDSUPER(data, default_value.value, IDWALK_CB_USER); break; } case SOCK_IMAGE: { - bNodeSocketValueImage *default_value = (bNodeSocketValueImage *)sock->default_value; - BKE_LIB_FOREACHID_PROCESS_IDSUPER(data, default_value->value, IDWALK_CB_USER); + bNodeSocketValueImage &default_value = *sock->default_value_typed(); + BKE_LIB_FOREACHID_PROCESS_IDSUPER(data, default_value.value, IDWALK_CB_USER); break; } case SOCK_COLLECTION: { - bNodeSocketValueCollection *default_value = (bNodeSocketValueCollection *) - sock->default_value; - BKE_LIB_FOREACHID_PROCESS_IDSUPER(data, default_value->value, IDWALK_CB_USER); + bNodeSocketValueCollection &default_value = + *sock->default_value_typed(); + BKE_LIB_FOREACHID_PROCESS_IDSUPER(data, default_value.value, IDWALK_CB_USER); break; } case SOCK_TEXTURE: { - bNodeSocketValueTexture *default_value = (bNodeSocketValueTexture *)sock->default_value; - BKE_LIB_FOREACHID_PROCESS_IDSUPER(data, default_value->value, IDWALK_CB_USER); + bNodeSocketValueTexture &default_value = + *sock->default_value_typed(); + BKE_LIB_FOREACHID_PROCESS_IDSUPER(data, default_value.value, IDWALK_CB_USER); break; } case SOCK_MATERIAL: { - bNodeSocketValueMaterial *default_value = (bNodeSocketValueMaterial *)sock->default_value; - BKE_LIB_FOREACHID_PROCESS_IDSUPER(data, default_value->value, IDWALK_CB_USER); + bNodeSocketValueMaterial &default_value = + *sock->default_value_typed(); + BKE_LIB_FOREACHID_PROCESS_IDSUPER(data, default_value.value, IDWALK_CB_USER); break; } case SOCK_FLOAT: @@ -324,7 +326,7 @@ static void library_foreach_node_socket(LibraryForeachIDData *data, bNodeSocket static void node_foreach_id(ID *id, LibraryForeachIDData *data) { - bNodeTree *ntree = (bNodeTree *)id; + bNodeTree *ntree = reinterpret_cast(id); BKE_LIB_FOREACHID_PROCESS_ID(data, ntree->owner_id, IDWALK_CB_LOOPBACK); @@ -359,21 +361,21 @@ static void node_foreach_cache(ID *id, IDTypeForeachCacheFunctionCallback function_callback, void *user_data) { - bNodeTree *nodetree = (bNodeTree *)id; + bNodeTree *nodetree = reinterpret_cast(id); IDCacheKey key = {0}; key.id_session_uuid = id->session_uuid; key.offset_in_ID = offsetof(bNodeTree, previews); /* TODO: see also `direct_link_nodetree()` in readfile.c. */ #if 0 - function_callback(id, &key, (void **)&nodetree->previews, 0, user_data); + function_callback(id, &key, reinterpret_cast(&nodetree->previews), 0, user_data); #endif if (nodetree->type == NTREE_COMPOSIT) { for (bNode *node : nodetree->all_nodes()) { if (node->type == CMP_NODE_MOVIEDISTORTION) { key.offset_in_ID = size_t(BLI_ghashutil_strhash_p(node->name)); - function_callback(id, &key, (void **)&node->storage, 0, user_data); + function_callback(id, &key, reinterpret_cast(&node->storage), 0, user_data); } } } @@ -423,7 +425,7 @@ static void write_node_socket_default_value(BlendWriter *writer, bNodeSocket *so return; } - switch ((eNodeSocketDatatype)sock->type) { + switch (static_cast(sock->type)) { case SOCK_FLOAT: BLO_write_struct(writer, bNodeSocketValueFloat, sock->default_value); break; @@ -481,6 +483,7 @@ static void write_node_socket(BlendWriter *writer, bNodeSocket *sock) write_node_socket_default_value(writer, sock); } + static void write_node_socket_interface(BlendWriter *writer, bNodeSocket *sock) { BLO_write_struct(writer, bNodeSocket, sock); @@ -519,10 +522,11 @@ void ntreeBlendWrite(BlendWriter *writer, bNodeTree *ntree) if (node->storage) { if (ELEM(ntree->type, NTREE_SHADER, NTREE_GEOMETRY) && ELEM(node->type, SH_NODE_CURVE_VEC, SH_NODE_CURVE_RGB, SH_NODE_CURVE_FLOAT)) { - BKE_curvemapping_blend_write(writer, (const CurveMapping *)node->storage); + BKE_curvemapping_blend_write(writer, + reinterpret_cast(node->storage)); } else if (ntree->type == NTREE_SHADER && (node->type == SH_NODE_SCRIPT)) { - NodeShaderScript *nss = (NodeShaderScript *)node->storage; + NodeShaderScript *nss = reinterpret_cast(node->storage); if (nss->bytecode) { BLO_write_string(writer, nss->bytecode); } @@ -533,11 +537,13 @@ void ntreeBlendWrite(BlendWriter *writer, bNodeTree *ntree) CMP_NODE_CURVE_VEC, CMP_NODE_CURVE_RGB, CMP_NODE_HUECORRECT)) { - BKE_curvemapping_blend_write(writer, (const CurveMapping *)node->storage); + BKE_curvemapping_blend_write(writer, + reinterpret_cast(node->storage)); } else if ((ntree->type == NTREE_TEXTURE) && ELEM(node->type, TEX_NODE_CURVE_RGB, TEX_NODE_CURVE_TIME)) { - BKE_curvemapping_blend_write(writer, (const CurveMapping *)node->storage); + BKE_curvemapping_blend_write(writer, + reinterpret_cast(node->storage)); } else if ((ntree->type == NTREE_COMPOSIT) && (node->type == CMP_NODE_MOVIEDISTORTION)) { /* pass */ @@ -545,7 +551,7 @@ void ntreeBlendWrite(BlendWriter *writer, bNodeTree *ntree) else if ((ntree->type == NTREE_COMPOSIT) && (node->type == CMP_NODE_GLARE)) { /* Simple forward compatibility for fix for #50736. * Not ideal (there is no ideal solution here), but should do for now. */ - NodeGlare *ndg = (NodeGlare *)node->storage; + NodeGlare *ndg = reinterpret_cast(node->storage); /* Not in undo case. */ if (!BLO_write_is_undo(writer)) { switch (ndg->type) { @@ -563,7 +569,7 @@ void ntreeBlendWrite(BlendWriter *writer, bNodeTree *ntree) } else if ((ntree->type == NTREE_COMPOSIT) && ELEM(node->type, CMP_NODE_CRYPTOMATTE, CMP_NODE_CRYPTOMATTE_LEGACY)) { - NodeCryptomatte *nc = (NodeCryptomatte *)node->storage; + NodeCryptomatte *nc = reinterpret_cast(node->storage); BLO_write_string(writer, nc->matte_id); LISTBASE_FOREACH (CryptomatteEntry *, entry, &nc->entries) { BLO_write_struct(writer, CryptomatteEntry, entry); @@ -571,7 +577,7 @@ void ntreeBlendWrite(BlendWriter *writer, bNodeTree *ntree) BLO_write_struct_by_name(writer, node->typeinfo->storagename, node->storage); } else if (node->type == FN_NODE_INPUT_STRING) { - NodeInputString *storage = (NodeInputString *)node->storage; + NodeInputString *storage = reinterpret_cast(node->storage); if (storage->string) { BLO_write_string(writer, storage->string); } @@ -588,7 +594,8 @@ void ntreeBlendWrite(BlendWriter *writer, bNodeTree *ntree) BKE_image_format_blend_write(writer, &nimf->format); LISTBASE_FOREACH (bNodeSocket *, sock, &node->inputs) { - NodeImageMultiFileSocket *sockdata = (NodeImageMultiFileSocket *)sock->storage; + NodeImageMultiFileSocket *sockdata = reinterpret_cast( + sock->storage); BLO_write_struct(writer, NodeImageMultiFileSocket, sockdata); BKE_image_format_blend_write(writer, &sockdata->format); } @@ -617,7 +624,7 @@ void ntreeBlendWrite(BlendWriter *writer, bNodeTree *ntree) static void ntree_blend_write(BlendWriter *writer, ID *id, const void *id_address) { - bNodeTree *ntree = (bNodeTree *)id; + bNodeTree *ntree = reinterpret_cast(id); /* Clean up, important in undo case to reduce false detection of changed datablocks. */ ntree->typeinfo = nullptr; @@ -720,26 +727,27 @@ void ntreeBlendReadData(BlendDataReader *reader, ID *owner_id, bNodeTree *ntree) case CMP_NODE_HUECORRECT: case TEX_NODE_CURVE_RGB: case TEX_NODE_CURVE_TIME: { - BKE_curvemapping_blend_read(reader, (CurveMapping *)node->storage); + BKE_curvemapping_blend_read(reader, reinterpret_cast(node->storage)); break; } case SH_NODE_SCRIPT: { - NodeShaderScript *nss = (NodeShaderScript *)node->storage; + NodeShaderScript *nss = reinterpret_cast(node->storage); BLO_read_data_address(reader, &nss->bytecode); break; } case SH_NODE_TEX_POINTDENSITY: { - NodeShaderTexPointDensity *npd = (NodeShaderTexPointDensity *)node->storage; + NodeShaderTexPointDensity *npd = reinterpret_cast( + node->storage); npd->pd = blender::dna::shallow_zero_initialize(); break; } case SH_NODE_TEX_IMAGE: { - NodeTexImage *tex = (NodeTexImage *)node->storage; + NodeTexImage *tex = reinterpret_cast(node->storage); tex->iuser.scene = nullptr; break; } case SH_NODE_TEX_ENVIRONMENT: { - NodeTexEnvironment *tex = (NodeTexEnvironment *)node->storage; + NodeTexEnvironment *tex = reinterpret_cast(node->storage); tex->iuser.scene = nullptr; break; } @@ -747,30 +755,30 @@ void ntreeBlendReadData(BlendDataReader *reader, ID *owner_id, bNodeTree *ntree) case CMP_NODE_R_LAYERS: case CMP_NODE_VIEWER: case CMP_NODE_SPLITVIEWER: { - ImageUser *iuser = (ImageUser *)node->storage; + ImageUser *iuser = reinterpret_cast(node->storage); iuser->scene = nullptr; break; } case CMP_NODE_CRYPTOMATTE_LEGACY: case CMP_NODE_CRYPTOMATTE: { - NodeCryptomatte *nc = (NodeCryptomatte *)node->storage; + NodeCryptomatte *nc = reinterpret_cast(node->storage); BLO_read_data_address(reader, &nc->matte_id); BLO_read_list(reader, &nc->entries); BLI_listbase_clear(&nc->runtime.layers); break; } case TEX_NODE_IMAGE: { - ImageUser *iuser = (ImageUser *)node->storage; + ImageUser *iuser = reinterpret_cast(node->storage); iuser->scene = nullptr; break; } case CMP_NODE_OUTPUT_FILE: { - NodeImageMultiFile *nimf = (NodeImageMultiFile *)node->storage; + NodeImageMultiFile *nimf = reinterpret_cast(node->storage); BKE_image_format_blend_read_data(reader, &nimf->format); break; } case FN_NODE_INPUT_STRING: { - NodeInputString *storage = (NodeInputString *)node->storage; + NodeInputString *storage = reinterpret_cast(node->storage); BLO_read_data_address(reader, &storage->string); break; } @@ -796,7 +804,8 @@ void ntreeBlendReadData(BlendDataReader *reader, ID *owner_id, bNodeTree *ntree) /* Socket storage. */ if (node->type == CMP_NODE_OUTPUT_FILE) { LISTBASE_FOREACH (bNodeSocket *, sock, &node->inputs) { - NodeImageMultiFileSocket *sockdata = (NodeImageMultiFileSocket *)sock->storage; + NodeImageMultiFileSocket *sockdata = reinterpret_cast( + sock->storage); BKE_image_format_blend_read_data(reader, &sockdata->format); } } @@ -830,7 +839,7 @@ void ntreeBlendReadData(BlendDataReader *reader, ID *owner_id, bNodeTree *ntree) static void ntree_blend_read_data(BlendDataReader *reader, ID *id) { - bNodeTree *ntree = (bNodeTree *)id; + bNodeTree *ntree = reinterpret_cast(id); ntreeBlendReadData(reader, nullptr, ntree); } @@ -845,31 +854,29 @@ static void lib_link_node_socket(BlendLibReader *reader, Library *lib, bNodeSock return; } - switch ((eNodeSocketDatatype)sock->type) { + switch (static_cast(sock->type)) { case SOCK_OBJECT: { - bNodeSocketValueObject *default_value = (bNodeSocketValueObject *)sock->default_value; - BLO_read_id_address(reader, lib, &default_value->value); + BLO_read_id_address( + reader, lib, &sock->default_value_typed()->value); break; } case SOCK_IMAGE: { - bNodeSocketValueImage *default_value = (bNodeSocketValueImage *)sock->default_value; - BLO_read_id_address(reader, lib, &default_value->value); + BLO_read_id_address(reader, lib, &sock->default_value_typed()->value); break; } case SOCK_COLLECTION: { - bNodeSocketValueCollection *default_value = (bNodeSocketValueCollection *) - sock->default_value; - BLO_read_id_address(reader, lib, &default_value->value); + BLO_read_id_address( + reader, lib, &sock->default_value_typed()->value); break; } case SOCK_TEXTURE: { - bNodeSocketValueTexture *default_value = (bNodeSocketValueTexture *)sock->default_value; - BLO_read_id_address(reader, lib, &default_value->value); + BLO_read_id_address( + reader, lib, &sock->default_value_typed()->value); break; } case SOCK_MATERIAL: { - bNodeSocketValueMaterial *default_value = (bNodeSocketValueMaterial *)sock->default_value; - BLO_read_id_address(reader, lib, &default_value->value); + BLO_read_id_address( + reader, lib, &sock->default_value_typed()->value); break; } case SOCK_FLOAT: @@ -934,7 +941,7 @@ void ntreeBlendReadLib(BlendLibReader *reader, bNodeTree *ntree) static void ntree_blend_read_lib(BlendLibReader *reader, ID *id) { - bNodeTree *ntree = (bNodeTree *)id; + bNodeTree *ntree = reinterpret_cast(id); ntreeBlendReadLib(reader, ntree); } @@ -943,46 +950,41 @@ static void expand_node_socket(BlendExpander *expander, bNodeSocket *sock) IDP_BlendReadExpand(expander, sock->prop); if (sock->default_value != nullptr) { + return; + } - switch ((eNodeSocketDatatype)sock->type) { - case SOCK_OBJECT: { - bNodeSocketValueObject *default_value = (bNodeSocketValueObject *)sock->default_value; - BLO_expand(expander, default_value->value); - break; - } - case SOCK_IMAGE: { - bNodeSocketValueImage *default_value = (bNodeSocketValueImage *)sock->default_value; - BLO_expand(expander, default_value->value); - break; - } - case SOCK_COLLECTION: { - bNodeSocketValueCollection *default_value = (bNodeSocketValueCollection *) - sock->default_value; - BLO_expand(expander, default_value->value); - break; - } - case SOCK_TEXTURE: { - bNodeSocketValueTexture *default_value = (bNodeSocketValueTexture *)sock->default_value; - BLO_expand(expander, default_value->value); - break; - } - case SOCK_MATERIAL: { - bNodeSocketValueMaterial *default_value = (bNodeSocketValueMaterial *)sock->default_value; - BLO_expand(expander, default_value->value); - break; - } - case SOCK_FLOAT: - case SOCK_VECTOR: - case SOCK_RGBA: - case SOCK_BOOLEAN: - case SOCK_INT: - case SOCK_STRING: - case __SOCK_MESH: - case SOCK_CUSTOM: - case SOCK_SHADER: - case SOCK_GEOMETRY: - break; + switch (static_cast(sock->type)) { + case SOCK_OBJECT: { + BLO_expand(expander, &sock->default_value_typed()->value); + break; } + case SOCK_IMAGE: { + BLO_expand(expander, &sock->default_value_typed()->value); + break; + } + case SOCK_COLLECTION: { + BLO_expand(expander, &sock->default_value_typed()->value); + break; + } + case SOCK_TEXTURE: { + BLO_expand(expander, &sock->default_value_typed()->value); + break; + } + case SOCK_MATERIAL: { + BLO_expand(expander, &sock->default_value_typed()->value); + break; + } + case SOCK_FLOAT: + case SOCK_VECTOR: + case SOCK_RGBA: + case SOCK_BOOLEAN: + case SOCK_INT: + case SOCK_STRING: + case __SOCK_MESH: + case SOCK_CUSTOM: + case SOCK_SHADER: + case SOCK_GEOMETRY: + break; } } @@ -1017,7 +1019,7 @@ void ntreeBlendReadExpand(BlendExpander *expander, bNodeTree *ntree) static void ntree_blend_read_expand(BlendExpander *expander, ID *id) { - bNodeTree *ntree = (bNodeTree *)id; + bNodeTree *ntree = reinterpret_cast(id); ntreeBlendReadExpand(expander, ntree); } @@ -1025,7 +1027,7 @@ namespace blender::bke { static void node_tree_asset_pre_save(void *asset_ptr, AssetMetaData *asset_data) { - bNodeTree &node_tree = *static_cast(asset_ptr); + bNodeTree &node_tree = *reinterpret_cast(asset_ptr); BKE_asset_metadata_idprop_ensure(asset_data, idprop::create("type", node_tree.type).release()); auto inputs = idprop::create_group("inputs"); @@ -1149,7 +1151,7 @@ static void node_init(const bContext *C, bNodeTree *ntree, bNode *node) if (ntype->initfunc_api) { PointerRNA ptr; - RNA_pointer_create((ID *)ntree, &RNA_Node, node, &ptr); + RNA_pointer_create(&ntree->id, &RNA_Node, node, &ptr); /* XXX WARNING: context can be nullptr in case nodes are added in do_versions. * Delayed init is not supported for nodes with context-based `initfunc_api` at the moment. */ @@ -1305,7 +1307,8 @@ static GHash *nodesockettypes_hash = nullptr; bNodeTreeType *ntreeTypeFind(const char *idname) { if (idname[0]) { - bNodeTreeType *nt = (bNodeTreeType *)BLI_ghash_lookup(nodetreetypes_hash, idname); + bNodeTreeType *nt = reinterpret_cast( + BLI_ghash_lookup(nodetreetypes_hash, idname)); if (nt) { return nt; } @@ -1325,7 +1328,7 @@ void ntreeTypeAdd(bNodeTreeType *nt) static void ntree_free_type(void *treetype_v) { - bNodeTreeType *treetype = (bNodeTreeType *)treetype_v; + bNodeTreeType *treetype = reinterpret_cast(treetype_v); /* XXX pass Main to unregister function? */ /* Probably not. It is pretty much expected we want to update G_MAIN here I think - * or we'd want to update *all* active Mains, which we cannot do anyway currently. */ @@ -1351,7 +1354,7 @@ GHashIterator *ntreeTypeGetIterator() bNodeType *nodeTypeFind(const char *idname) { if (idname[0]) { - bNodeType *nt = (bNodeType *)BLI_ghash_lookup(nodetypes_hash, idname); + bNodeType *nt = reinterpret_cast(BLI_ghash_lookup(nodetypes_hash, idname)); if (nt) { return nt; } @@ -1362,7 +1365,7 @@ bNodeType *nodeTypeFind(const char *idname) static void node_free_type(void *nodetype_v) { - bNodeType *nodetype = (bNodeType *)nodetype_v; + bNodeType *nodetype = reinterpret_cast(nodetype_v); /* XXX pass Main to unregister function? */ /* Probably not. It is pretty much expected we want to update G_MAIN here I think - * or we'd want to update *all* active Mains, which we cannot do anyway currently. */ @@ -1432,7 +1435,8 @@ GHashIterator *nodeTypeGetIterator() bNodeSocketType *nodeSocketTypeFind(const char *idname) { if (idname[0]) { - bNodeSocketType *st = (bNodeSocketType *)BLI_ghash_lookup(nodesockettypes_hash, idname); + bNodeSocketType *st = reinterpret_cast( + BLI_ghash_lookup(nodesockettypes_hash, idname)); if (st) { return st; } @@ -1443,7 +1447,7 @@ bNodeSocketType *nodeSocketTypeFind(const char *idname) static void node_free_socket_type(void *socktype_v) { - bNodeSocketType *socktype = (bNodeSocketType *)socktype_v; + bNodeSocketType *socktype = reinterpret_cast(socktype_v); /* XXX pass Main to unregister function? */ /* Probably not. It is pretty much expected we want to update G_MAIN here I think - * or we'd want to update *all* active Mains, which we cannot do anyway currently. */ @@ -1454,7 +1458,7 @@ static void node_free_socket_type(void *socktype_v) void nodeRegisterSocketType(bNodeSocketType *st) { - BLI_ghash_insert(nodesockettypes_hash, (void *)st->idname, st); + BLI_ghash_insert(nodesockettypes_hash, reinterpret_cast(st->idname), st); /* XXX pass Main to register function? */ /* Probably not. It is pretty much expected we want to update G_MAIN here I think - * or we'd want to update *all* active Mains, which we cannot do anyway currently. */ @@ -1536,7 +1540,7 @@ bNodeSocket *node_find_enabled_output_socket(bNode &node, const StringRef name) static bool unique_identifier_check(void *arg, const char *identifier) { - const ListBase *lb = (const ListBase *)arg; + const ListBase *lb = reinterpret_cast(arg); LISTBASE_FOREACH (bNodeSocket *, sock, lb) { if (STREQ(sock->identifier, identifier)) { return true; @@ -1587,31 +1591,33 @@ static bNodeSocket *make_socket(bNodeTree *ntree, static void socket_id_user_increment(bNodeSocket *sock) { - switch ((eNodeSocketDatatype)sock->type) { + switch (static_cast(sock->type)) { case SOCK_OBJECT: { - bNodeSocketValueObject *default_value = (bNodeSocketValueObject *)sock->default_value; - id_us_plus((ID *)default_value->value); + bNodeSocketValueObject &default_value = *sock->default_value_typed(); + id_us_plus(reinterpret_cast(default_value.value)); break; } case SOCK_IMAGE: { - bNodeSocketValueImage *default_value = (bNodeSocketValueImage *)sock->default_value; - id_us_plus((ID *)default_value->value); + bNodeSocketValueImage &default_value = *sock->default_value_typed(); + id_us_plus(reinterpret_cast(default_value.value)); break; } case SOCK_COLLECTION: { - bNodeSocketValueCollection *default_value = (bNodeSocketValueCollection *) - sock->default_value; - id_us_plus((ID *)default_value->value); + bNodeSocketValueCollection &default_value = + *sock->default_value_typed(); + id_us_plus(reinterpret_cast(default_value.value)); break; } case SOCK_TEXTURE: { - bNodeSocketValueTexture *default_value = (bNodeSocketValueTexture *)sock->default_value; - id_us_plus((ID *)default_value->value); + bNodeSocketValueTexture &default_value = + *sock->default_value_typed(); + id_us_plus(reinterpret_cast(default_value.value)); break; } case SOCK_MATERIAL: { - bNodeSocketValueMaterial *default_value = (bNodeSocketValueMaterial *)sock->default_value; - id_us_plus((ID *)default_value->value); + bNodeSocketValueMaterial &default_value = + *sock->default_value_typed(); + id_us_plus(reinterpret_cast(default_value.value)); break; } case SOCK_FLOAT: @@ -1631,47 +1637,34 @@ static void socket_id_user_increment(bNodeSocket *sock) /** \return True if the socket had an ID default value. */ static bool socket_id_user_decrement(bNodeSocket *sock) { - switch ((eNodeSocketDatatype)sock->type) { + switch (static_cast(sock->type)) { case SOCK_OBJECT: { - bNodeSocketValueObject *default_value = (bNodeSocketValueObject *)sock->default_value; - if (default_value->value != nullptr) { - id_us_min(&default_value->value->id); - return true; - } - break; + bNodeSocketValueObject &socket_value = *sock->default_value_typed(); + id_us_min(reinterpret_cast(socket_value.value)); + return socket_value.value != nullptr; } case SOCK_IMAGE: { - bNodeSocketValueImage *default_value = (bNodeSocketValueImage *)sock->default_value; - if (default_value->value != nullptr) { - id_us_min(&default_value->value->id); - return true; - } - break; + bNodeSocketValueImage &socket_value = *sock->default_value_typed(); + id_us_min(reinterpret_cast(socket_value.value)); + return socket_value.value != nullptr; } case SOCK_COLLECTION: { - bNodeSocketValueCollection *default_value = (bNodeSocketValueCollection *) - sock->default_value; - if (default_value->value != nullptr) { - id_us_min(&default_value->value->id); - return true; - } - break; + bNodeSocketValueCollection &socket_value = + *sock->default_value_typed(); + id_us_min(reinterpret_cast(socket_value.value)); + return socket_value.value != nullptr; } case SOCK_TEXTURE: { - bNodeSocketValueTexture *default_value = (bNodeSocketValueTexture *)sock->default_value; - if (default_value->value != nullptr) { - id_us_min(&default_value->value->id); - return true; - } - break; + bNodeSocketValueTexture &socket_value = + *sock->default_value_typed(); + id_us_min(reinterpret_cast(socket_value.value)); + return socket_value.value != nullptr; } case SOCK_MATERIAL: { - bNodeSocketValueMaterial *default_value = (bNodeSocketValueMaterial *)sock->default_value; - if (default_value->value != nullptr) { - id_us_min(&default_value->value->id); - return true; - } - break; + bNodeSocketValueMaterial &socket_value = + *sock->default_value_typed(); + id_us_min(reinterpret_cast(socket_value.value)); + return socket_value.value != nullptr; } case SOCK_FLOAT: case SOCK_VECTOR: @@ -1711,7 +1704,7 @@ void nodeModifySocketType(bNodeTree *ntree, } else { /* Update the socket subtype when the storage isn't freed and recreated. */ - switch (eNodeSocketDatatype(sock->type)) { + switch (static_cast(sock->type)) { case SOCK_FLOAT: { sock->default_value_typed()->subtype = socktype->subtype; break; @@ -1794,9 +1787,9 @@ bool nodeIsStaticSocketType(const bNodeSocketType *stype) const char *nodeStaticSocketType(const int type, const int subtype) { - switch (type) { + switch (static_cast(type)) { case SOCK_FLOAT: - switch (subtype) { + switch (static_cast(subtype)) { case PROP_UNSIGNED: return "NodeSocketFloatUnsigned"; case PROP_PERCENTAGE: @@ -1816,7 +1809,7 @@ const char *nodeStaticSocketType(const int type, const int subtype) return "NodeSocketFloat"; } case SOCK_INT: - switch (subtype) { + switch (static_cast(subtype)) { case PROP_UNSIGNED: return "NodeSocketIntUnsigned"; case PROP_PERCENTAGE: @@ -1830,7 +1823,7 @@ const char *nodeStaticSocketType(const int type, const int subtype) case SOCK_BOOLEAN: return "NodeSocketBool"; case SOCK_VECTOR: - switch (subtype) { + switch (static_cast(subtype)) { case PROP_TRANSLATION: return "NodeSocketVectorTranslation"; case PROP_DIRECTION: @@ -1865,15 +1858,17 @@ const char *nodeStaticSocketType(const int type, const int subtype) return "NodeSocketTexture"; case SOCK_MATERIAL: return "NodeSocketMaterial"; + default: + break; } return nullptr; } const char *nodeStaticSocketInterfaceType(const int type, const int subtype) { - switch (type) { + switch (static_cast(type)) { case SOCK_FLOAT: - switch (subtype) { + switch (static_cast(subtype)) { case PROP_UNSIGNED: return "NodeSocketInterfaceFloatUnsigned"; case PROP_PERCENTAGE: @@ -1893,7 +1888,7 @@ const char *nodeStaticSocketInterfaceType(const int type, const int subtype) return "NodeSocketInterfaceFloat"; } case SOCK_INT: - switch (subtype) { + switch (static_cast(subtype)) { case PROP_UNSIGNED: return "NodeSocketInterfaceIntUnsigned"; case PROP_PERCENTAGE: @@ -1907,7 +1902,7 @@ const char *nodeStaticSocketInterfaceType(const int type, const int subtype) case SOCK_BOOLEAN: return "NodeSocketInterfaceBool"; case SOCK_VECTOR: - switch (subtype) { + switch (static_cast(subtype)) { case PROP_TRANSLATION: return "NodeSocketInterfaceVectorTranslation"; case PROP_DIRECTION: @@ -1942,13 +1937,15 @@ const char *nodeStaticSocketInterfaceType(const int type, const int subtype) return "NodeSocketInterfaceTexture"; case SOCK_MATERIAL: return "NodeSocketInterfaceMaterial"; + default: + break; } return nullptr; } const char *nodeStaticSocketLabel(const int type, const int /*subtype*/) { - switch (type) { + switch (static_cast(type)) { case SOCK_FLOAT: return "Float"; case SOCK_INT: @@ -1975,6 +1972,8 @@ const char *nodeStaticSocketLabel(const int type, const int /*subtype*/) return "Texture"; case SOCK_MATERIAL: return "Material"; + default: + break; } return nullptr; } @@ -2077,7 +2076,7 @@ void nodeRemoveAllSockets(bNodeTree *ntree, bNode *node) bNode *nodeFindNodebyName(bNodeTree *ntree, const char *name) { - return (bNode *)BLI_findstring(&ntree->nodes, name, offsetof(bNode, name)); + return reinterpret_cast(BLI_findstring(&ntree->nodes, name, offsetof(bNode, name))); } void nodeFindNode(bNodeTree *ntree, bNodeSocket *sock, bNode **r_node, int *r_sockindex) @@ -2345,7 +2344,7 @@ static void node_socket_copy(bNodeSocket *sock_dst, const bNodeSocket *sock_src, } } - sock_dst->default_attribute_name = static_cast( + sock_dst->default_attribute_name = reinterpret_cast( MEM_dupallocN(sock_src->default_attribute_name)); sock_dst->stack_index = 0; @@ -2359,7 +2358,7 @@ bNode *node_copy_with_mapping(bNodeTree *dst_tree, const bool use_unique, Map &socket_map) { - bNode *node_dst = (bNode *)MEM_mallocN(sizeof(bNode), __func__); + bNode *node_dst = reinterpret_cast(MEM_mallocN(sizeof(bNode), __func__)); *node_dst = node_src; node_dst->runtime = MEM_new(__func__); @@ -2375,7 +2374,7 @@ bNode *node_copy_with_mapping(bNodeTree *dst_tree, BLI_listbase_clear(&node_dst->inputs); LISTBASE_FOREACH (const bNodeSocket *, src_socket, &node_src.inputs) { - bNodeSocket *dst_socket = (bNodeSocket *)MEM_dupallocN(src_socket); + bNodeSocket *dst_socket = reinterpret_cast(MEM_dupallocN(src_socket)); node_socket_copy(dst_socket, src_socket, flag); BLI_addtail(&node_dst->inputs, dst_socket); socket_map.add_new(src_socket, dst_socket); @@ -2383,7 +2382,7 @@ bNode *node_copy_with_mapping(bNodeTree *dst_tree, BLI_listbase_clear(&node_dst->outputs); LISTBASE_FOREACH (const bNodeSocket *, src_socket, &node_src.outputs) { - bNodeSocket *dst_socket = (bNodeSocket *)MEM_dupallocN(src_socket); + bNodeSocket *dst_socket = reinterpret_cast(MEM_dupallocN(src_socket)); node_socket_copy(dst_socket, src_socket, flag); BLI_addtail(&node_dst->outputs, dst_socket); socket_map.add_new(src_socket, dst_socket); @@ -2417,7 +2416,7 @@ bNode *node_copy_with_mapping(bNodeTree *dst_tree, * for cases like the dependency graph and localization. */ if (node_dst->typeinfo->copyfunc_api && !(flag & LIB_ID_CREATE_NO_MAIN)) { PointerRNA ptr; - RNA_pointer_create((ID *)dst_tree, &RNA_Node, node_dst, &ptr); + RNA_pointer_create(reinterpret_cast(dst_tree), &RNA_Node, node_dst, &ptr); node_dst->typeinfo->copyfunc_api(&ptr, &node_src); } @@ -2556,7 +2555,8 @@ bNodeLink *nodeAddLink( BLI_assert(ntree->all_nodes().contains(tonode)); bNodeLink *link = nullptr; - if (fromsock->in_out == SOCK_OUT && tosock->in_out == SOCK_IN) { + if (static_cast(fromsock->in_out) == SOCK_OUT && + static_cast(tosock->in_out) == SOCK_IN) { link = MEM_cnew("link"); if (ntree) { BLI_addtail(&ntree->links, link); @@ -2566,7 +2566,8 @@ bNodeLink *nodeAddLink( link->tonode = tonode; link->tosock = tosock; } - else if (fromsock->in_out == SOCK_IN && tosock->in_out == SOCK_OUT) { + else if (static_cast(fromsock->in_out) == SOCK_IN && + static_cast(tosock->in_out) == SOCK_OUT) { /* OK but flip */ link = MEM_cnew("link"); if (ntree) { @@ -2781,7 +2782,7 @@ void nodePositionRelative(bNode *from_node, int tot_sock_idx; /* Socket to plug into. */ - if (SOCK_IN == to_sock->in_out) { + if (static_cast(to_sock->in_out) == SOCK_IN) { offset_x = -(from_node->typeinfo->width + 50); tot_sock_idx = BLI_listbase_count(&to_node->outputs); tot_sock_idx += BLI_findindex(&to_node->inputs, to_sock); @@ -2797,7 +2798,7 @@ void nodePositionRelative(bNode *from_node, /* Output socket. */ if (from_sock) { - if (SOCK_IN == from_sock->in_out) { + if (static_cast(from_sock->in_out) == SOCK_IN) { tot_sock_idx = BLI_listbase_count(&from_node->outputs); tot_sock_idx += BLI_findindex(&from_node->inputs, from_sock); } @@ -2835,7 +2836,7 @@ static bNodeTree *ntreeAddTree_do( if (is_embedded || bmain == nullptr) { flag |= LIB_ID_CREATE_NO_MAIN; } - bNodeTree *ntree = (bNodeTree *)BKE_libblock_alloc(bmain, ID_NT, name, flag); + bNodeTree *ntree = reinterpret_cast(BKE_libblock_alloc(bmain, ID_NT, name, flag)); BKE_libblock_init_empty(&ntree->id); if (is_embedded) { BLI_assert(owner_id != nullptr); @@ -2872,7 +2873,8 @@ bNodeTree *ntreeCopyTree_ex(const bNodeTree *ntree, Main *bmain, const bool do_i { const int flag = do_id_user ? 0 : LIB_ID_CREATE_NO_USER_REFCOUNT | LIB_ID_CREATE_NO_MAIN; - bNodeTree *ntree_copy = (bNodeTree *)BKE_id_copy_ex(bmain, (ID *)ntree, nullptr, flag); + bNodeTree *ntree_copy = reinterpret_cast( + BKE_id_copy_ex(bmain, reinterpret_cast(ntree), nullptr, flag)); return ntree_copy; } bNodeTree *ntreeCopyTree(Main *bmain, const bNodeTree *ntree) @@ -2899,7 +2901,8 @@ bNodePreview *BKE_node_preview_verify(bNodeInstanceHash *previews, const int ysize, const bool create) { - bNodePreview *preview = (bNodePreview *)BKE_node_instance_hash_lookup(previews, key); + bNodePreview *preview = reinterpret_cast( + BKE_node_instance_hash_lookup(previews, key)); if (!preview) { if (create) { preview = MEM_cnew("node preview"); @@ -2924,8 +2927,8 @@ bNodePreview *BKE_node_preview_verify(bNodeInstanceHash *previews, } if (preview->rect == nullptr) { - preview->rect = (uchar *)MEM_callocN(4 * xsize + xsize * ysize * sizeof(char[4]), - "node preview rect"); + preview->rect = reinterpret_cast( + MEM_callocN(4 * xsize + xsize * ysize * sizeof(char[4]), "node preview rect")); preview->xsize = xsize; preview->ysize = ysize; } @@ -2936,9 +2939,9 @@ bNodePreview *BKE_node_preview_verify(bNodeInstanceHash *previews, bNodePreview *BKE_node_preview_copy(bNodePreview *preview) { - bNodePreview *new_preview = (bNodePreview *)MEM_dupallocN(preview); + bNodePreview *new_preview = reinterpret_cast(MEM_dupallocN(preview)); if (preview->rect) { - new_preview->rect = (uchar *)MEM_dupallocN(preview->rect); + new_preview->rect = reinterpret_cast(MEM_dupallocN(preview->rect)); } return new_preview; } @@ -2967,8 +2970,9 @@ static void node_preview_init_tree_recursive(bNodeInstanceHash *previews, BKE_node_preview_verify(previews, key, xsize, ysize, false); } - if (node->type == NODE_GROUP && node->id) { - node_preview_init_tree_recursive(previews, (bNodeTree *)node->id, key, xsize, ysize); + bNodeTree *group = reinterpret_cast(node->id); + if (node->is_group() && group != nullptr) { + node_preview_init_tree_recursive(previews, group, key, xsize, ysize); } } } @@ -2997,8 +3001,9 @@ static void node_preview_tag_used_recursive(bNodeInstanceHash *previews, BKE_node_instance_hash_tag_key(previews, key); } - if (node->type == NODE_GROUP && node->id) { - node_preview_tag_used_recursive(previews, (bNodeTree *)node->id, key); + bNodeTree *group = reinterpret_cast(node->id); + if (node->is_group() && group != nullptr) { + node_preview_tag_used_recursive(previews, group, key); } } } @@ -3013,8 +3018,8 @@ void BKE_node_preview_remove_unused(bNodeTree *ntree) BKE_node_instance_hash_clear_tags(ntree->previews); node_preview_tag_used_recursive(ntree->previews, ntree, NODE_INSTANCE_KEY_BASE); - BKE_node_instance_hash_remove_untagged(ntree->previews, - (bNodeInstanceValueFP)BKE_node_preview_free); + BKE_node_instance_hash_remove_untagged( + ntree->previews, reinterpret_cast(BKE_node_preview_free)); } void BKE_node_preview_clear(bNodePreview *preview) @@ -3032,7 +3037,8 @@ void BKE_node_preview_clear_tree(bNodeTree *ntree) bNodeInstanceHashIterator iter; NODE_INSTANCE_HASH_ITER (iter, ntree->previews) { - bNodePreview *preview = (bNodePreview *)BKE_node_instance_hash_iterator_get_value(&iter); + bNodePreview *preview = reinterpret_cast( + BKE_node_instance_hash_iterator_get_value(&iter)); BKE_node_preview_clear(preview); } } @@ -3042,7 +3048,8 @@ void BKE_node_preview_merge_tree(bNodeTree *to_ntree, bNodeTree *from_ntree, boo if (remove_old || !to_ntree->previews) { /* free old previews */ if (to_ntree->previews) { - BKE_node_instance_hash_free(to_ntree->previews, (bNodeInstanceValueFP)BKE_node_preview_free); + BKE_node_instance_hash_free(to_ntree->previews, + reinterpret_cast(BKE_node_preview_free)); } /* transfer previews */ @@ -3057,11 +3064,14 @@ void BKE_node_preview_merge_tree(bNodeTree *to_ntree, bNodeTree *from_ntree, boo bNodeInstanceHashIterator iter; NODE_INSTANCE_HASH_ITER (iter, from_ntree->previews) { bNodeInstanceKey key = BKE_node_instance_hash_iterator_get_key(&iter); - bNodePreview *preview = (bNodePreview *)BKE_node_instance_hash_iterator_get_value(&iter); + bNodePreview *preview = reinterpret_cast( + BKE_node_instance_hash_iterator_get_value(&iter)); /* replace existing previews */ BKE_node_instance_hash_remove( - to_ntree->previews, key, (bNodeInstanceValueFP)BKE_node_preview_free); + to_ntree->previews, + key, + reinterpret_cast(BKE_node_preview_free)); BKE_node_instance_hash_insert(to_ntree->previews, key, preview); } @@ -3190,6 +3200,7 @@ void ntreeFreeLocalNode(bNodeTree *ntree, bNode *node) void nodeRemoveNode(Main *bmain, bNodeTree *ntree, bNode *node, const bool do_id_user) { + BLI_assert(ntree != nullptr); /* This function is not for localized node trees, we do not want * do to ID user reference-counting and removal of animdation data then. */ BLI_assert((ntree->id.tag & LIB_TAG_LOCALIZED) == 0); @@ -3200,7 +3211,7 @@ void nodeRemoveNode(Main *bmain, bNodeTree *ntree, bNode *node, const bool do_id /* Free callback for NodeCustomGroup. */ if (node->typeinfo->freefunc_api) { PointerRNA ptr; - RNA_pointer_create((ID *)ntree, &RNA_Node, node, &ptr); + RNA_pointer_create(&ntree->id, &RNA_Node, node, &ptr); node->typeinfo->freefunc_api(&ptr); } @@ -3226,7 +3237,7 @@ void nodeRemoveNode(Main *bmain, bNodeTree *ntree, bNode *node, const bool do_id BLI_str_escape(propname_esc, node->name, sizeof(propname_esc)); BLI_snprintf(prefix, sizeof(prefix), "nodes[\"%s\"]", propname_esc); - if (BKE_animdata_fix_paths_remove((ID *)ntree, prefix)) { + if (BKE_animdata_fix_paths_remove(&ntree->id, prefix)) { if (bmain != nullptr) { DEG_relations_tag_update(bmain); } @@ -3279,8 +3290,8 @@ static void free_localized_node_groups(bNodeTree *ntree) } LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { - if (ELEM(node->type, NODE_GROUP, NODE_CUSTOM_GROUP) && node->id) { - bNodeTree *ngroup = (bNodeTree *)node->id; + bNodeTree *ngroup = reinterpret_cast(node->id); + if (node->is_group() && ngroup != nullptr) { ntreeFreeTree(ngroup); MEM_freeN(ngroup); } @@ -3377,19 +3388,19 @@ bNodeTree **BKE_ntree_ptr_from_id(ID *id) { switch (GS(id->name)) { case ID_MA: - return &((Material *)id)->nodetree; + return &reinterpret_cast(id)->nodetree; case ID_LA: - return &((Light *)id)->nodetree; + return &reinterpret_cast(id)->nodetree; case ID_WO: - return &((World *)id)->nodetree; + return &reinterpret_cast(id)->nodetree; case ID_TE: - return &((Tex *)id)->nodetree; + return &reinterpret_cast(id)->nodetree; case ID_SCE: - return &((Scene *)id)->nodetree; + return &reinterpret_cast(id)->nodetree; case ID_LS: - return &((FreestyleLineStyle *)id)->nodetree; + return &reinterpret_cast(id)->nodetree; case ID_SIM: - return &((Simulation *)id)->nodetree; + return &reinterpret_cast(id)->nodetree; default: return nullptr; } @@ -3421,22 +3432,23 @@ bNodeTree *ntreeLocalize(bNodeTree *ntree) /* Make full copy outside of Main database. * NOTE: previews are not copied here. */ - bNodeTree *ltree = (bNodeTree *)BKE_id_copy_ex( - nullptr, &ntree->id, nullptr, (LIB_ID_COPY_LOCALIZE | LIB_ID_COPY_NO_ANIMDATA)); + bNodeTree *ltree = reinterpret_cast(BKE_id_copy_ex( + nullptr, &ntree->id, nullptr, (LIB_ID_COPY_LOCALIZE | LIB_ID_COPY_NO_ANIMDATA))); ltree->id.tag |= LIB_TAG_LOCALIZED; LISTBASE_FOREACH (bNode *, node, <ree->nodes) { - if (ELEM(node->type, NODE_GROUP, NODE_CUSTOM_GROUP) && node->id) { - node->id = (ID *)ntreeLocalize((bNodeTree *)node->id); + bNodeTree *group = reinterpret_cast(node->id); + if (node->is_group() && group != nullptr) { + node->id = reinterpret_cast(ntreeLocalize(group)); } } /* Ensures only a single output node is enabled. */ ntreeSetOutput(ntree); - bNode *node_src = (bNode *)ntree->nodes.first; - bNode *node_local = (bNode *)ltree->nodes.first; + bNode *node_src = reinterpret_cast(ntree->nodes.first); + bNode *node_local = reinterpret_cast(ltree->nodes.first); while (node_src != nullptr) { node_local->runtime->original = node_src; node_src = node_src->next; @@ -3477,8 +3489,8 @@ static bNodeSocket *make_socket_interface(bNodeTree *ntree, bNodeSocket *sock = MEM_cnew("socket template"); sock->runtime = MEM_new(__func__); BLI_strncpy(sock->idname, stype->idname, sizeof(sock->idname)); - sock->in_out = in_out; - sock->type = SOCK_CUSTOM; /* int type undefined by default */ + sock->in_out = int(in_out); + sock->type = int(SOCK_CUSTOM); /* int type undefined by default */ node_socket_set_typeinfo(ntree, sock, stype); /* assign new unique index */ @@ -3561,7 +3573,7 @@ bNodeSocket *ntreeAddSocketInterfaceFromSocketWithName(bNodeTree *ntree, const char *name) { bNodeSocket *iosock = ntreeAddSocketInterface( - ntree, static_cast(from_sock->in_out), idname, DATA_(name)); + ntree, eNodeSocketInOut(from_sock->in_out), idname, DATA_(name)); if (iosock == nullptr) { return nullptr; } @@ -3577,11 +3589,7 @@ bNodeSocket *ntreeInsertSocketInterfaceFromSocket(bNodeTree *ntree, const bNodeSocket *from_sock) { bNodeSocket *iosock = ntreeInsertSocketInterface( - ntree, - static_cast(from_sock->in_out), - from_sock->idname, - next_sock, - from_sock->name); + ntree, eNodeSocketInOut(from_sock->in_out), from_sock->idname, next_sock, from_sock->name); if (iosock) { if (iosock->typeinfo->interface_from_socket) { iosock->typeinfo->interface_from_socket(ntree, iosock, from_node, from_sock); @@ -3757,7 +3765,8 @@ int nodeSocketLinkLimit(const bNodeSocket *sock) if (!stype.use_link_limits_of_type) { return sock->limit; } - return sock->in_out == SOCK_IN ? stype.input_link_limit : stype.output_link_limit; + return eNodeSocketInOut(sock->in_out) == SOCK_IN ? stype.input_link_limit : + stype.output_link_limit; } static void update_socket_declarations(ListBase *sockets, @@ -3874,20 +3883,21 @@ bNodeInstanceKey BKE_node_instance_key(bNodeInstanceKey parent_key, static uint node_instance_hash_key(const void *key) { - return ((const bNodeInstanceKey *)key)->value; + return reinterpret_cast(key)->value; } static bool node_instance_hash_key_cmp(const void *a, const void *b) { - uint value_a = ((const bNodeInstanceKey *)a)->value; - uint value_b = ((const bNodeInstanceKey *)b)->value; + uint value_a = reinterpret_cast(a)->value; + uint value_b = reinterpret_cast(b)->value; return (value_a != value_b); } bNodeInstanceHash *BKE_node_instance_hash_new(const char *info) { - bNodeInstanceHash *hash = (bNodeInstanceHash *)MEM_mallocN(sizeof(bNodeInstanceHash), info); + bNodeInstanceHash *hash = reinterpret_cast( + MEM_mallocN(sizeof(bNodeInstanceHash), info)); hash->ghash = BLI_ghash_new( node_instance_hash_key, node_instance_hash_key_cmp, "node instance hash ghash"); return hash; @@ -3895,13 +3905,13 @@ bNodeInstanceHash *BKE_node_instance_hash_new(const char *info) void BKE_node_instance_hash_free(bNodeInstanceHash *hash, bNodeInstanceValueFP valfreefp) { - BLI_ghash_free(hash->ghash, nullptr, (GHashValFreeFP)valfreefp); + BLI_ghash_free(hash->ghash, nullptr, reinterpret_cast(valfreefp)); MEM_freeN(hash); } void BKE_node_instance_hash_insert(bNodeInstanceHash *hash, bNodeInstanceKey key, void *value) { - bNodeInstanceHashEntry *entry = (bNodeInstanceHashEntry *)value; + bNodeInstanceHashEntry *entry = reinterpret_cast(value); entry->key = key; entry->tag = 0; BLI_ghash_insert(hash->ghash, &entry->key, value); @@ -3916,12 +3926,12 @@ int BKE_node_instance_hash_remove(bNodeInstanceHash *hash, bNodeInstanceKey key, bNodeInstanceValueFP valfreefp) { - return BLI_ghash_remove(hash->ghash, &key, nullptr, (GHashValFreeFP)valfreefp); + return BLI_ghash_remove(hash->ghash, &key, nullptr, reinterpret_cast(valfreefp)); } void BKE_node_instance_hash_clear(bNodeInstanceHash *hash, bNodeInstanceValueFP valfreefp) { - BLI_ghash_clear(hash->ghash, nullptr, (GHashValFreeFP)valfreefp); + BLI_ghash_clear(hash->ghash, nullptr, reinterpret_cast(valfreefp)); } void *BKE_node_instance_hash_pop(bNodeInstanceHash *hash, bNodeInstanceKey key) @@ -3944,8 +3954,8 @@ void BKE_node_instance_hash_clear_tags(bNodeInstanceHash *hash) bNodeInstanceHashIterator iter; NODE_INSTANCE_HASH_ITER (iter, hash) { - bNodeInstanceHashEntry *value = (bNodeInstanceHashEntry *) - BKE_node_instance_hash_iterator_get_value(&iter); + bNodeInstanceHashEntry *value = reinterpret_cast( + BKE_node_instance_hash_iterator_get_value(&iter)); value->tag = 0; } @@ -3953,14 +3963,14 @@ void BKE_node_instance_hash_clear_tags(bNodeInstanceHash *hash) void BKE_node_instance_hash_tag(bNodeInstanceHash * /*hash*/, void *value) { - bNodeInstanceHashEntry *entry = (bNodeInstanceHashEntry *)value; + bNodeInstanceHashEntry *entry = reinterpret_cast(value); entry->tag = 1; } bool BKE_node_instance_hash_tag_key(bNodeInstanceHash *hash, bNodeInstanceKey key) { - bNodeInstanceHashEntry *entry = (bNodeInstanceHashEntry *)BKE_node_instance_hash_lookup(hash, - key); + bNodeInstanceHashEntry *entry = reinterpret_cast( + BKE_node_instance_hash_lookup(hash, key)); if (entry) { entry->tag = 1; @@ -3976,14 +3986,14 @@ void BKE_node_instance_hash_remove_untagged(bNodeInstanceHash *hash, /* NOTE: Hash must not be mutated during iterating! * Store tagged entries in a separate list and remove items afterward. */ - bNodeInstanceKey *untagged = (bNodeInstanceKey *)MEM_mallocN( - sizeof(bNodeInstanceKey) * BKE_node_instance_hash_size(hash), - "temporary node instance key list"); + bNodeInstanceKey *untagged = reinterpret_cast( + MEM_mallocN(sizeof(bNodeInstanceKey) * BKE_node_instance_hash_size(hash), + "temporary node instance key list")); bNodeInstanceHashIterator iter; int num_untagged = 0; NODE_INSTANCE_HASH_ITER (iter, hash) { - bNodeInstanceHashEntry *value = (bNodeInstanceHashEntry *) - BKE_node_instance_hash_iterator_get_value(&iter); + bNodeInstanceHashEntry *value = reinterpret_cast( + BKE_node_instance_hash_iterator_get_value(&iter)); if (!value->tag) { untagged[num_untagged++] = BKE_node_instance_hash_iterator_get_key(&iter); @@ -4142,8 +4152,8 @@ struct SocketTemplateIdentifierCallbackData { static bool unique_socket_template_identifier_check(void *arg, const char *name) { - const SocketTemplateIdentifierCallbackData *data = (const SocketTemplateIdentifierCallbackData *) - arg; + const SocketTemplateIdentifierCallbackData *data = + reinterpret_cast(arg); for (bNodeSocketTemplate *ntemp = data->list; ntemp->type >= 0; ntemp++) { if (ntemp != data->ntemp) { @@ -4320,44 +4330,45 @@ void BKE_node_tree_iter_init(NodeTreeIterStore *ntreeiter, Main *bmain) bool BKE_node_tree_iter_step(NodeTreeIterStore *ntreeiter, bNodeTree **r_nodetree, ID **r_id) { if (ntreeiter->ngroup) { - *r_nodetree = (bNodeTree *)ntreeiter->ngroup; - *r_id = (ID *)ntreeiter->ngroup; - ntreeiter->ngroup = (bNodeTree *)ntreeiter->ngroup->id.next; + bNodeTree &node_tree = *reinterpret_cast(ntreeiter->ngroup); + *r_nodetree = &node_tree; + *r_id = &node_tree.id; + ntreeiter->ngroup = reinterpret_cast(node_tree.id.next); } else if (ntreeiter->scene) { - *r_nodetree = (bNodeTree *)ntreeiter->scene->nodetree; - *r_id = (ID *)ntreeiter->scene; - ntreeiter->scene = (Scene *)ntreeiter->scene->id.next; + *r_nodetree = reinterpret_cast(ntreeiter->scene->nodetree); + *r_id = &ntreeiter->scene->id; + ntreeiter->scene = reinterpret_cast(ntreeiter->scene->id.next); } else if (ntreeiter->mat) { - *r_nodetree = (bNodeTree *)ntreeiter->mat->nodetree; - *r_id = (ID *)ntreeiter->mat; - ntreeiter->mat = (Material *)ntreeiter->mat->id.next; + *r_nodetree = reinterpret_cast(ntreeiter->mat->nodetree); + *r_id = &ntreeiter->mat->id; + ntreeiter->mat = reinterpret_cast(ntreeiter->mat->id.next); } else if (ntreeiter->tex) { - *r_nodetree = (bNodeTree *)ntreeiter->tex->nodetree; - *r_id = (ID *)ntreeiter->tex; - ntreeiter->tex = (Tex *)ntreeiter->tex->id.next; + *r_nodetree = reinterpret_cast(ntreeiter->tex->nodetree); + *r_id = &ntreeiter->tex->id; + ntreeiter->tex = reinterpret_cast(ntreeiter->tex->id.next); } else if (ntreeiter->light) { - *r_nodetree = (bNodeTree *)ntreeiter->light->nodetree; - *r_id = (ID *)ntreeiter->light; - ntreeiter->light = (Light *)ntreeiter->light->id.next; + *r_nodetree = reinterpret_cast(ntreeiter->light->nodetree); + *r_id = &ntreeiter->light->id; + ntreeiter->light = reinterpret_cast(ntreeiter->light->id.next); } else if (ntreeiter->world) { - *r_nodetree = (bNodeTree *)ntreeiter->world->nodetree; - *r_id = (ID *)ntreeiter->world; - ntreeiter->world = (World *)ntreeiter->world->id.next; + *r_nodetree = reinterpret_cast(ntreeiter->world->nodetree); + *r_id = &ntreeiter->world->id; + ntreeiter->world = reinterpret_cast(ntreeiter->world->id.next); } else if (ntreeiter->linestyle) { - *r_nodetree = (bNodeTree *)ntreeiter->linestyle->nodetree; - *r_id = (ID *)ntreeiter->linestyle; - ntreeiter->linestyle = (FreestyleLineStyle *)ntreeiter->linestyle->id.next; + *r_nodetree = reinterpret_cast(ntreeiter->linestyle->nodetree); + *r_id = &ntreeiter->linestyle->id; + ntreeiter->linestyle = reinterpret_cast(ntreeiter->linestyle->id.next); } else if (ntreeiter->simulation) { - *r_nodetree = (bNodeTree *)ntreeiter->simulation->nodetree; - *r_id = (ID *)ntreeiter->simulation; - ntreeiter->simulation = (Simulation *)ntreeiter->simulation->id.next; + *r_nodetree = reinterpret_cast(ntreeiter->simulation->nodetree); + *r_id = &ntreeiter->simulation->id; + ntreeiter->simulation = reinterpret_cast(ntreeiter->simulation->id.next); } else { return false; @@ -4369,8 +4380,9 @@ bool BKE_node_tree_iter_step(NodeTreeIterStore *ntreeiter, bNodeTree **r_nodetre void BKE_nodetree_remove_layer_n(bNodeTree *ntree, Scene *scene, const int layer_index) { BLI_assert(layer_index != -1); + BLI_assert(scene != nullptr); for (bNode *node : ntree->all_nodes()) { - if (node->type == CMP_NODE_R_LAYERS && (Scene *)node->id == scene) { + if (node->type != CMP_NODE_R_LAYERS && node->id == &scene->id) { if (node->custom1 == layer_index) { node->custom1 = 0; } -- 2.30.2 From 63cbd35cd1e0406952a108be72af7ba500dd4643 Mon Sep 17 00:00:00 2001 From: illua1 Date: Tue, 18 Apr 2023 20:19:26 +0300 Subject: [PATCH 2/6] progress --- source/blender/blenkernel/intern/node.cc | 44 ++++++++++++------------ 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc index 34b0b6d4429..c7b27358c4e 100644 --- a/source/blender/blenkernel/intern/node.cc +++ b/source/blender/blenkernel/intern/node.cc @@ -281,7 +281,7 @@ static void library_foreach_node_socket(LibraryForeachIDData *data, bNodeSocket IDP_foreach_property( sock->prop, IDP_TYPE_FILTER_ID, BKE_lib_query_idpropertiesForeachIDLink_callback, data)); - switch (static_cast(sock->type)) { + switch (eNodeSocketDatatype(sock->type)) { case SOCK_OBJECT: { bNodeSocketValueObject &default_value = *sock->default_value_typed(); BKE_LIB_FOREACHID_PROCESS_IDSUPER(data, default_value.value, IDWALK_CB_USER); @@ -425,7 +425,7 @@ static void write_node_socket_default_value(BlendWriter *writer, bNodeSocket *so return; } - switch (static_cast(sock->type)) { + switch (eNodeSocketDatatype(sock->type)) { case SOCK_FLOAT: BLO_write_struct(writer, bNodeSocketValueFloat, sock->default_value); break; @@ -854,7 +854,7 @@ static void lib_link_node_socket(BlendLibReader *reader, Library *lib, bNodeSock return; } - switch (static_cast(sock->type)) { + switch (eNodeSocketDatatype(sock->type)) { case SOCK_OBJECT: { BLO_read_id_address( reader, lib, &sock->default_value_typed()->value); @@ -953,7 +953,7 @@ static void expand_node_socket(BlendExpander *expander, bNodeSocket *sock) return; } - switch (static_cast(sock->type)) { + switch (eNodeSocketDatatype(sock->type)) { case SOCK_OBJECT: { BLO_expand(expander, &sock->default_value_typed()->value); break; @@ -1591,7 +1591,7 @@ static bNodeSocket *make_socket(bNodeTree *ntree, static void socket_id_user_increment(bNodeSocket *sock) { - switch (static_cast(sock->type)) { + switch (eNodeSocketDatatype(sock->type)) { case SOCK_OBJECT: { bNodeSocketValueObject &default_value = *sock->default_value_typed(); id_us_plus(reinterpret_cast(default_value.value)); @@ -1637,7 +1637,7 @@ static void socket_id_user_increment(bNodeSocket *sock) /** \return True if the socket had an ID default value. */ static bool socket_id_user_decrement(bNodeSocket *sock) { - switch (static_cast(sock->type)) { + switch (eNodeSocketDatatype(sock->type)) { case SOCK_OBJECT: { bNodeSocketValueObject &socket_value = *sock->default_value_typed(); id_us_min(reinterpret_cast(socket_value.value)); @@ -1704,7 +1704,7 @@ void nodeModifySocketType(bNodeTree *ntree, } else { /* Update the socket subtype when the storage isn't freed and recreated. */ - switch (static_cast(sock->type)) { + switch (eNodeSocketDatatype(sock->type)) { case SOCK_FLOAT: { sock->default_value_typed()->subtype = socktype->subtype; break; @@ -1787,9 +1787,9 @@ bool nodeIsStaticSocketType(const bNodeSocketType *stype) const char *nodeStaticSocketType(const int type, const int subtype) { - switch (static_cast(type)) { + switch (eNodeSocketDatatype(type)) { case SOCK_FLOAT: - switch (static_cast(subtype)) { + switch (PropertySubType(subtype)) { case PROP_UNSIGNED: return "NodeSocketFloatUnsigned"; case PROP_PERCENTAGE: @@ -1809,7 +1809,7 @@ const char *nodeStaticSocketType(const int type, const int subtype) return "NodeSocketFloat"; } case SOCK_INT: - switch (static_cast(subtype)) { + switch (PropertySubType(subtype)) { case PROP_UNSIGNED: return "NodeSocketIntUnsigned"; case PROP_PERCENTAGE: @@ -1823,7 +1823,7 @@ const char *nodeStaticSocketType(const int type, const int subtype) case SOCK_BOOLEAN: return "NodeSocketBool"; case SOCK_VECTOR: - switch (static_cast(subtype)) { + switch (PropertySubType(subtype)) { case PROP_TRANSLATION: return "NodeSocketVectorTranslation"; case PROP_DIRECTION: @@ -1866,9 +1866,9 @@ const char *nodeStaticSocketType(const int type, const int subtype) const char *nodeStaticSocketInterfaceType(const int type, const int subtype) { - switch (static_cast(type)) { + switch (eNodeSocketDatatype(type)) { case SOCK_FLOAT: - switch (static_cast(subtype)) { + switch (PropertySubType(subtype)) { case PROP_UNSIGNED: return "NodeSocketInterfaceFloatUnsigned"; case PROP_PERCENTAGE: @@ -1888,7 +1888,7 @@ const char *nodeStaticSocketInterfaceType(const int type, const int subtype) return "NodeSocketInterfaceFloat"; } case SOCK_INT: - switch (static_cast(subtype)) { + switch (PropertySubType(subtype)) { case PROP_UNSIGNED: return "NodeSocketInterfaceIntUnsigned"; case PROP_PERCENTAGE: @@ -1902,7 +1902,7 @@ const char *nodeStaticSocketInterfaceType(const int type, const int subtype) case SOCK_BOOLEAN: return "NodeSocketInterfaceBool"; case SOCK_VECTOR: - switch (static_cast(subtype)) { + switch (PropertySubType(subtype)) { case PROP_TRANSLATION: return "NodeSocketInterfaceVectorTranslation"; case PROP_DIRECTION: @@ -1945,7 +1945,7 @@ const char *nodeStaticSocketInterfaceType(const int type, const int subtype) const char *nodeStaticSocketLabel(const int type, const int /*subtype*/) { - switch (static_cast(type)) { + switch (eNodeSocketDatatype(type)) { case SOCK_FLOAT: return "Float"; case SOCK_INT: @@ -2555,8 +2555,8 @@ bNodeLink *nodeAddLink( BLI_assert(ntree->all_nodes().contains(tonode)); bNodeLink *link = nullptr; - if (static_cast(fromsock->in_out) == SOCK_OUT && - static_cast(tosock->in_out) == SOCK_IN) { + if (eNodeSocketInOut(fromsock->in_out) == SOCK_OUT && + eNodeSocketInOut(tosock->in_out) == SOCK_IN) { link = MEM_cnew("link"); if (ntree) { BLI_addtail(&ntree->links, link); @@ -2566,8 +2566,8 @@ bNodeLink *nodeAddLink( link->tonode = tonode; link->tosock = tosock; } - else if (static_cast(fromsock->in_out) == SOCK_IN && - static_cast(tosock->in_out) == SOCK_OUT) { + else if (eNodeSocketInOut(fromsock->in_out) == SOCK_IN && + eNodeSocketInOut(tosock->in_out) == SOCK_OUT) { /* OK but flip */ link = MEM_cnew("link"); if (ntree) { @@ -2782,7 +2782,7 @@ void nodePositionRelative(bNode *from_node, int tot_sock_idx; /* Socket to plug into. */ - if (static_cast(to_sock->in_out) == SOCK_IN) { + if (eNodeSocketInOut(to_sock->in_out) == SOCK_IN) { offset_x = -(from_node->typeinfo->width + 50); tot_sock_idx = BLI_listbase_count(&to_node->outputs); tot_sock_idx += BLI_findindex(&to_node->inputs, to_sock); @@ -2798,7 +2798,7 @@ void nodePositionRelative(bNode *from_node, /* Output socket. */ if (from_sock) { - if (static_cast(from_sock->in_out) == SOCK_IN) { + if (eNodeSocketInOut(from_sock->in_out) == SOCK_IN) { tot_sock_idx = BLI_listbase_count(&from_node->outputs); tot_sock_idx += BLI_findindex(&from_node->inputs, from_sock); } -- 2.30.2 From 8005ec261ed2523246ed689445aa15be1be5efd4 Mon Sep 17 00:00:00 2001 From: illua1 Date: Tue, 18 Apr 2023 20:24:26 +0300 Subject: [PATCH 3/6] progress --- source/blender/blenkernel/intern/node.cc | 33 ++++++++++++------------ 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc index c7b27358c4e..07e7600791e 100644 --- a/source/blender/blenkernel/intern/node.cc +++ b/source/blender/blenkernel/intern/node.cc @@ -1110,6 +1110,7 @@ static void node_add_sockets_from_type(bNodeTree *ntree, bNode *node, bNodeType */ static void node_init(const bContext *C, bNodeTree *ntree, bNode *node) { + BLI_assert(ntree != nullptr); bNodeType *ntype = node->typeinfo; if (ntype == &NodeTypeUndefined) { return; @@ -1639,32 +1640,32 @@ static bool socket_id_user_decrement(bNodeSocket *sock) { switch (eNodeSocketDatatype(sock->type)) { case SOCK_OBJECT: { - bNodeSocketValueObject &socket_value = *sock->default_value_typed(); - id_us_min(reinterpret_cast(socket_value.value)); - return socket_value.value != nullptr; + bNodeSocketValueObject &default_value = *sock->default_value_typed(); + id_us_min(reinterpret_cast(default_value.value)); + return default_value.value != nullptr; } case SOCK_IMAGE: { - bNodeSocketValueImage &socket_value = *sock->default_value_typed(); - id_us_min(reinterpret_cast(socket_value.value)); - return socket_value.value != nullptr; + bNodeSocketValueImage &default_value = *sock->default_value_typed(); + id_us_min(reinterpret_cast(default_value.value)); + return default_value.value != nullptr; } case SOCK_COLLECTION: { - bNodeSocketValueCollection &socket_value = + bNodeSocketValueCollection &default_value = *sock->default_value_typed(); - id_us_min(reinterpret_cast(socket_value.value)); - return socket_value.value != nullptr; + id_us_min(reinterpret_cast(default_value.value)); + return default_value.value != nullptr; } case SOCK_TEXTURE: { - bNodeSocketValueTexture &socket_value = + bNodeSocketValueTexture &default_value = *sock->default_value_typed(); - id_us_min(reinterpret_cast(socket_value.value)); - return socket_value.value != nullptr; + id_us_min(reinterpret_cast(default_value.value)); + return default_value.value != nullptr; } case SOCK_MATERIAL: { - bNodeSocketValueMaterial &socket_value = + bNodeSocketValueMaterial &default_value = *sock->default_value_typed(); - id_us_min(reinterpret_cast(socket_value.value)); - return socket_value.value != nullptr; + id_us_min(reinterpret_cast(default_value.value)); + return default_value.value != nullptr; } case SOCK_FLOAT: case SOCK_VECTOR: @@ -4382,7 +4383,7 @@ void BKE_nodetree_remove_layer_n(bNodeTree *ntree, Scene *scene, const int layer BLI_assert(layer_index != -1); BLI_assert(scene != nullptr); for (bNode *node : ntree->all_nodes()) { - if (node->type != CMP_NODE_R_LAYERS && node->id == &scene->id) { + if (node->type == CMP_NODE_R_LAYERS && node->id == &scene->id) { if (node->custom1 == layer_index) { node->custom1 = 0; } -- 2.30.2 From 2a18b2e479caf82bc98e89d02ec563d160cd0c91 Mon Sep 17 00:00:00 2001 From: illua1 Date: Tue, 18 Apr 2023 23:15:42 +0300 Subject: [PATCH 4/6] back static_cast --- source/blender/blenkernel/intern/node.cc | 48 ++++++++++++------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc index 07e7600791e..e2c232f8f3c 100644 --- a/source/blender/blenkernel/intern/node.cc +++ b/source/blender/blenkernel/intern/node.cc @@ -157,7 +157,7 @@ static void ntree_copy_data(Main * /*bmain*/, ID *id_dst, const ID *id_src, cons /* copy links */ BLI_listbase_clear(&ntree_dst->links); LISTBASE_FOREACH (const bNodeLink *, src_link, &ntree_src->links) { - bNodeLink *dst_link = reinterpret_cast(MEM_dupallocN(src_link)); + bNodeLink *dst_link = static_cast(MEM_dupallocN(src_link)); dst_link->fromnode = dst_runtime.nodes_by_id.lookup_key_as(src_link->fromnode->identifier); dst_link->fromsock = socket_map.lookup(src_link->fromsock); dst_link->tonode = dst_runtime.nodes_by_id.lookup_key_as(src_link->tonode->identifier); @@ -177,13 +177,13 @@ static void ntree_copy_data(Main * /*bmain*/, ID *id_dst, const ID *id_src, cons /* copy interface sockets */ BLI_listbase_clear(&ntree_dst->inputs); LISTBASE_FOREACH (const bNodeSocket *, src_socket, &ntree_src->inputs) { - bNodeSocket *dst_socket = reinterpret_cast(MEM_dupallocN(src_socket)); + bNodeSocket *dst_socket = static_cast(MEM_dupallocN(src_socket)); node_socket_copy(dst_socket, src_socket, flag_subdata); BLI_addtail(&ntree_dst->inputs, dst_socket); } BLI_listbase_clear(&ntree_dst->outputs); LISTBASE_FOREACH (const bNodeSocket *, src_socket, &ntree_src->outputs) { - bNodeSocket *dst_socket = reinterpret_cast(MEM_dupallocN(src_socket)); + bNodeSocket *dst_socket = static_cast(MEM_dupallocN(src_socket)); node_socket_copy(dst_socket, src_socket, flag_subdata); BLI_addtail(&ntree_dst->outputs, dst_socket); } @@ -368,14 +368,14 @@ static void node_foreach_cache(ID *id, /* TODO: see also `direct_link_nodetree()` in readfile.c. */ #if 0 - function_callback(id, &key, reinterpret_cast(&nodetree->previews), 0, user_data); + function_callback(id, &key, static_cast(&nodetree->previews), 0, user_data); #endif if (nodetree->type == NTREE_COMPOSIT) { for (bNode *node : nodetree->all_nodes()) { if (node->type == CMP_NODE_MOVIEDISTORTION) { key.offset_in_ID = size_t(BLI_ghashutil_strhash_p(node->name)); - function_callback(id, &key, reinterpret_cast(&node->storage), 0, user_data); + function_callback(id, &key, static_cast(&node->storage), 0, user_data); } } } @@ -1027,7 +1027,7 @@ namespace blender::bke { static void node_tree_asset_pre_save(void *asset_ptr, AssetMetaData *asset_data) { - bNodeTree &node_tree = *reinterpret_cast(asset_ptr); + bNodeTree &node_tree = *static_cast(asset_ptr); BKE_asset_metadata_idprop_ensure(asset_data, idprop::create("type", node_tree.type).release()); auto inputs = idprop::create_group("inputs"); @@ -1329,7 +1329,7 @@ void ntreeTypeAdd(bNodeTreeType *nt) static void ntree_free_type(void *treetype_v) { - bNodeTreeType *treetype = reinterpret_cast(treetype_v); + bNodeTreeType *treetype = static_cast(treetype_v); /* XXX pass Main to unregister function? */ /* Probably not. It is pretty much expected we want to update G_MAIN here I think - * or we'd want to update *all* active Mains, which we cannot do anyway currently. */ @@ -1366,7 +1366,7 @@ bNodeType *nodeTypeFind(const char *idname) static void node_free_type(void *nodetype_v) { - bNodeType *nodetype = reinterpret_cast(nodetype_v); + bNodeType *nodetype = static_cast(nodetype_v); /* XXX pass Main to unregister function? */ /* Probably not. It is pretty much expected we want to update G_MAIN here I think - * or we'd want to update *all* active Mains, which we cannot do anyway currently. */ @@ -1448,7 +1448,7 @@ bNodeSocketType *nodeSocketTypeFind(const char *idname) static void node_free_socket_type(void *socktype_v) { - bNodeSocketType *socktype = reinterpret_cast(socktype_v); + bNodeSocketType *socktype = static_cast(socktype_v); /* XXX pass Main to unregister function? */ /* Probably not. It is pretty much expected we want to update G_MAIN here I think - * or we'd want to update *all* active Mains, which we cannot do anyway currently. */ @@ -1541,7 +1541,7 @@ bNodeSocket *node_find_enabled_output_socket(bNode &node, const StringRef name) static bool unique_identifier_check(void *arg, const char *identifier) { - const ListBase *lb = reinterpret_cast(arg); + const ListBase *lb = static_cast(arg); LISTBASE_FOREACH (bNodeSocket *, sock, lb) { if (STREQ(sock->identifier, identifier)) { return true; @@ -2345,7 +2345,7 @@ static void node_socket_copy(bNodeSocket *sock_dst, const bNodeSocket *sock_src, } } - sock_dst->default_attribute_name = reinterpret_cast( + sock_dst->default_attribute_name = static_cast( MEM_dupallocN(sock_src->default_attribute_name)); sock_dst->stack_index = 0; @@ -2359,7 +2359,7 @@ bNode *node_copy_with_mapping(bNodeTree *dst_tree, const bool use_unique, Map &socket_map) { - bNode *node_dst = reinterpret_cast(MEM_mallocN(sizeof(bNode), __func__)); + bNode *node_dst = static_cast(MEM_mallocN(sizeof(bNode), __func__)); *node_dst = node_src; node_dst->runtime = MEM_new(__func__); @@ -2375,7 +2375,7 @@ bNode *node_copy_with_mapping(bNodeTree *dst_tree, BLI_listbase_clear(&node_dst->inputs); LISTBASE_FOREACH (const bNodeSocket *, src_socket, &node_src.inputs) { - bNodeSocket *dst_socket = reinterpret_cast(MEM_dupallocN(src_socket)); + bNodeSocket *dst_socket = static_cast(MEM_dupallocN(src_socket)); node_socket_copy(dst_socket, src_socket, flag); BLI_addtail(&node_dst->inputs, dst_socket); socket_map.add_new(src_socket, dst_socket); @@ -2383,7 +2383,7 @@ bNode *node_copy_with_mapping(bNodeTree *dst_tree, BLI_listbase_clear(&node_dst->outputs); LISTBASE_FOREACH (const bNodeSocket *, src_socket, &node_src.outputs) { - bNodeSocket *dst_socket = reinterpret_cast(MEM_dupallocN(src_socket)); + bNodeSocket *dst_socket = static_cast(MEM_dupallocN(src_socket)); node_socket_copy(dst_socket, src_socket, flag); BLI_addtail(&node_dst->outputs, dst_socket); socket_map.add_new(src_socket, dst_socket); @@ -2940,9 +2940,9 @@ bNodePreview *BKE_node_preview_verify(bNodeInstanceHash *previews, bNodePreview *BKE_node_preview_copy(bNodePreview *preview) { - bNodePreview *new_preview = reinterpret_cast(MEM_dupallocN(preview)); + bNodePreview *new_preview = static_cast(MEM_dupallocN(preview)); if (preview->rect) { - new_preview->rect = reinterpret_cast(MEM_dupallocN(preview->rect)); + new_preview->rect = static_cast(MEM_dupallocN(preview->rect)); } return new_preview; } @@ -3884,20 +3884,20 @@ bNodeInstanceKey BKE_node_instance_key(bNodeInstanceKey parent_key, static uint node_instance_hash_key(const void *key) { - return reinterpret_cast(key)->value; + return static_cast(key)->value; } static bool node_instance_hash_key_cmp(const void *a, const void *b) { - uint value_a = reinterpret_cast(a)->value; - uint value_b = reinterpret_cast(b)->value; + uint value_a = static_cast(a)->value; + uint value_b = static_cast(b)->value; return (value_a != value_b); } bNodeInstanceHash *BKE_node_instance_hash_new(const char *info) { - bNodeInstanceHash *hash = reinterpret_cast( + bNodeInstanceHash *hash = static_cast( MEM_mallocN(sizeof(bNodeInstanceHash), info)); hash->ghash = BLI_ghash_new( node_instance_hash_key, node_instance_hash_key_cmp, "node instance hash ghash"); @@ -3912,7 +3912,7 @@ void BKE_node_instance_hash_free(bNodeInstanceHash *hash, bNodeInstanceValueFP v void BKE_node_instance_hash_insert(bNodeInstanceHash *hash, bNodeInstanceKey key, void *value) { - bNodeInstanceHashEntry *entry = reinterpret_cast(value); + bNodeInstanceHashEntry *entry = static_cast(value); entry->key = key; entry->tag = 0; BLI_ghash_insert(hash->ghash, &entry->key, value); @@ -3964,7 +3964,7 @@ void BKE_node_instance_hash_clear_tags(bNodeInstanceHash *hash) void BKE_node_instance_hash_tag(bNodeInstanceHash * /*hash*/, void *value) { - bNodeInstanceHashEntry *entry = reinterpret_cast(value); + bNodeInstanceHashEntry *entry = static_cast(value); entry->tag = 1; } @@ -3987,7 +3987,7 @@ void BKE_node_instance_hash_remove_untagged(bNodeInstanceHash *hash, /* NOTE: Hash must not be mutated during iterating! * Store tagged entries in a separate list and remove items afterward. */ - bNodeInstanceKey *untagged = reinterpret_cast( + bNodeInstanceKey *untagged = static_cast( MEM_mallocN(sizeof(bNodeInstanceKey) * BKE_node_instance_hash_size(hash), "temporary node instance key list")); bNodeInstanceHashIterator iter; @@ -4154,7 +4154,7 @@ struct SocketTemplateIdentifierCallbackData { static bool unique_socket_template_identifier_check(void *arg, const char *name) { const SocketTemplateIdentifierCallbackData *data = - reinterpret_cast(arg); + static_cast(arg); for (bNodeSocketTemplate *ntemp = data->list; ntemp->type >= 0; ntemp++) { if (ntemp != data->ntemp) { -- 2.30.2 From ff3092120021f0ca56e64eb6516f34ba9bf90f15 Mon Sep 17 00:00:00 2001 From: illua1 Date: Wed, 19 Apr 2023 20:38:54 +0300 Subject: [PATCH 5/6] progress --- source/blender/blenkernel/intern/node.cc | 55 +++++++++++------------- 1 file changed, 25 insertions(+), 30 deletions(-) diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc index e2c232f8f3c..7e4bc81fe6a 100644 --- a/source/blender/blenkernel/intern/node.cc +++ b/source/blender/blenkernel/intern/node.cc @@ -389,11 +389,11 @@ static void node_foreach_path(ID *id, BPathForeachPathData *bpath_data) case NTREE_SHADER: { for (bNode *node : ntree->all_nodes()) { if (node->type == SH_NODE_SCRIPT) { - NodeShaderScript *nss = reinterpret_cast(node->storage); + NodeShaderScript *nss = static_cast(node->storage); BKE_bpath_foreach_path_fixed_process(bpath_data, nss->filepath); } else if (node->type == SH_NODE_TEX_IES) { - NodeShaderTexIES *ies = reinterpret_cast(node->storage); + NodeShaderTexIES *ies = static_cast(node->storage); BKE_bpath_foreach_path_fixed_process(bpath_data, ies->filepath); } } @@ -522,11 +522,10 @@ void ntreeBlendWrite(BlendWriter *writer, bNodeTree *ntree) if (node->storage) { if (ELEM(ntree->type, NTREE_SHADER, NTREE_GEOMETRY) && ELEM(node->type, SH_NODE_CURVE_VEC, SH_NODE_CURVE_RGB, SH_NODE_CURVE_FLOAT)) { - BKE_curvemapping_blend_write(writer, - reinterpret_cast(node->storage)); + BKE_curvemapping_blend_write(writer, static_cast(node->storage)); } else if (ntree->type == NTREE_SHADER && (node->type == SH_NODE_SCRIPT)) { - NodeShaderScript *nss = reinterpret_cast(node->storage); + NodeShaderScript *nss = static_cast(node->storage); if (nss->bytecode) { BLO_write_string(writer, nss->bytecode); } @@ -537,13 +536,11 @@ void ntreeBlendWrite(BlendWriter *writer, bNodeTree *ntree) CMP_NODE_CURVE_VEC, CMP_NODE_CURVE_RGB, CMP_NODE_HUECORRECT)) { - BKE_curvemapping_blend_write(writer, - reinterpret_cast(node->storage)); + BKE_curvemapping_blend_write(writer, static_cast(node->storage)); } else if ((ntree->type == NTREE_TEXTURE) && ELEM(node->type, TEX_NODE_CURVE_RGB, TEX_NODE_CURVE_TIME)) { - BKE_curvemapping_blend_write(writer, - reinterpret_cast(node->storage)); + BKE_curvemapping_blend_write(writer, static_cast(node->storage)); } else if ((ntree->type == NTREE_COMPOSIT) && (node->type == CMP_NODE_MOVIEDISTORTION)) { /* pass */ @@ -551,7 +548,7 @@ void ntreeBlendWrite(BlendWriter *writer, bNodeTree *ntree) else if ((ntree->type == NTREE_COMPOSIT) && (node->type == CMP_NODE_GLARE)) { /* Simple forward compatibility for fix for #50736. * Not ideal (there is no ideal solution here), but should do for now. */ - NodeGlare *ndg = reinterpret_cast(node->storage); + NodeGlare *ndg = static_cast(node->storage); /* Not in undo case. */ if (!BLO_write_is_undo(writer)) { switch (ndg->type) { @@ -569,7 +566,7 @@ void ntreeBlendWrite(BlendWriter *writer, bNodeTree *ntree) } else if ((ntree->type == NTREE_COMPOSIT) && ELEM(node->type, CMP_NODE_CRYPTOMATTE, CMP_NODE_CRYPTOMATTE_LEGACY)) { - NodeCryptomatte *nc = reinterpret_cast(node->storage); + NodeCryptomatte *nc = static_cast(node->storage); BLO_write_string(writer, nc->matte_id); LISTBASE_FOREACH (CryptomatteEntry *, entry, &nc->entries) { BLO_write_struct(writer, CryptomatteEntry, entry); @@ -577,7 +574,7 @@ void ntreeBlendWrite(BlendWriter *writer, bNodeTree *ntree) BLO_write_struct_by_name(writer, node->typeinfo->storagename, node->storage); } else if (node->type == FN_NODE_INPUT_STRING) { - NodeInputString *storage = reinterpret_cast(node->storage); + NodeInputString *storage = static_cast(node->storage); if (storage->string) { BLO_write_string(writer, storage->string); } @@ -594,7 +591,7 @@ void ntreeBlendWrite(BlendWriter *writer, bNodeTree *ntree) BKE_image_format_blend_write(writer, &nimf->format); LISTBASE_FOREACH (bNodeSocket *, sock, &node->inputs) { - NodeImageMultiFileSocket *sockdata = reinterpret_cast( + NodeImageMultiFileSocket *sockdata = static_cast( sock->storage); BLO_write_struct(writer, NodeImageMultiFileSocket, sockdata); BKE_image_format_blend_write(writer, &sockdata->format); @@ -727,27 +724,26 @@ void ntreeBlendReadData(BlendDataReader *reader, ID *owner_id, bNodeTree *ntree) case CMP_NODE_HUECORRECT: case TEX_NODE_CURVE_RGB: case TEX_NODE_CURVE_TIME: { - BKE_curvemapping_blend_read(reader, reinterpret_cast(node->storage)); + BKE_curvemapping_blend_read(reader, static_cast(node->storage)); break; } case SH_NODE_SCRIPT: { - NodeShaderScript *nss = reinterpret_cast(node->storage); + NodeShaderScript *nss = static_cast(node->storage); BLO_read_data_address(reader, &nss->bytecode); break; } case SH_NODE_TEX_POINTDENSITY: { - NodeShaderTexPointDensity *npd = reinterpret_cast( - node->storage); + NodeShaderTexPointDensity *npd = static_cast(node->storage); npd->pd = blender::dna::shallow_zero_initialize(); break; } case SH_NODE_TEX_IMAGE: { - NodeTexImage *tex = reinterpret_cast(node->storage); + NodeTexImage *tex = static_cast(node->storage); tex->iuser.scene = nullptr; break; } case SH_NODE_TEX_ENVIRONMENT: { - NodeTexEnvironment *tex = reinterpret_cast(node->storage); + NodeTexEnvironment *tex = static_cast(node->storage); tex->iuser.scene = nullptr; break; } @@ -755,30 +751,30 @@ void ntreeBlendReadData(BlendDataReader *reader, ID *owner_id, bNodeTree *ntree) case CMP_NODE_R_LAYERS: case CMP_NODE_VIEWER: case CMP_NODE_SPLITVIEWER: { - ImageUser *iuser = reinterpret_cast(node->storage); + ImageUser *iuser = static_cast(node->storage); iuser->scene = nullptr; break; } case CMP_NODE_CRYPTOMATTE_LEGACY: case CMP_NODE_CRYPTOMATTE: { - NodeCryptomatte *nc = reinterpret_cast(node->storage); + NodeCryptomatte *nc = static_cast(node->storage); BLO_read_data_address(reader, &nc->matte_id); BLO_read_list(reader, &nc->entries); BLI_listbase_clear(&nc->runtime.layers); break; } case TEX_NODE_IMAGE: { - ImageUser *iuser = reinterpret_cast(node->storage); + ImageUser *iuser = static_cast(node->storage); iuser->scene = nullptr; break; } case CMP_NODE_OUTPUT_FILE: { - NodeImageMultiFile *nimf = reinterpret_cast(node->storage); + NodeImageMultiFile *nimf = static_cast(node->storage); BKE_image_format_blend_read_data(reader, &nimf->format); break; } case FN_NODE_INPUT_STRING: { - NodeInputString *storage = reinterpret_cast(node->storage); + NodeInputString *storage = static_cast(node->storage); BLO_read_data_address(reader, &storage->string); break; } @@ -804,7 +800,7 @@ void ntreeBlendReadData(BlendDataReader *reader, ID *owner_id, bNodeTree *ntree) /* Socket storage. */ if (node->type == CMP_NODE_OUTPUT_FILE) { LISTBASE_FOREACH (bNodeSocket *, sock, &node->inputs) { - NodeImageMultiFileSocket *sockdata = reinterpret_cast( + NodeImageMultiFileSocket *sockdata = static_cast( sock->storage); BKE_image_format_blend_read_data(reader, &sockdata->format); } @@ -1308,8 +1304,7 @@ static GHash *nodesockettypes_hash = nullptr; bNodeTreeType *ntreeTypeFind(const char *idname) { if (idname[0]) { - bNodeTreeType *nt = reinterpret_cast( - BLI_ghash_lookup(nodetreetypes_hash, idname)); + bNodeTreeType *nt = static_cast(BLI_ghash_lookup(nodetreetypes_hash, idname)); if (nt) { return nt; } @@ -1355,7 +1350,7 @@ GHashIterator *ntreeTypeGetIterator() bNodeType *nodeTypeFind(const char *idname) { if (idname[0]) { - bNodeType *nt = reinterpret_cast(BLI_ghash_lookup(nodetypes_hash, idname)); + bNodeType *nt = static_cast(BLI_ghash_lookup(nodetypes_hash, idname)); if (nt) { return nt; } @@ -1436,7 +1431,7 @@ GHashIterator *nodeTypeGetIterator() bNodeSocketType *nodeSocketTypeFind(const char *idname) { if (idname[0]) { - bNodeSocketType *st = reinterpret_cast( + bNodeSocketType *st = static_cast( BLI_ghash_lookup(nodesockettypes_hash, idname)); if (st) { return st; @@ -1459,7 +1454,7 @@ static void node_free_socket_type(void *socktype_v) void nodeRegisterSocketType(bNodeSocketType *st) { - BLI_ghash_insert(nodesockettypes_hash, reinterpret_cast(st->idname), st); + BLI_ghash_insert(nodesockettypes_hash, st->idname, st); /* XXX pass Main to register function? */ /* Probably not. It is pretty much expected we want to update G_MAIN here I think - * or we'd want to update *all* active Mains, which we cannot do anyway currently. */ -- 2.30.2 From ed2b05acf8691afc0bb5ad19a3691f96e5c8bbba Mon Sep 17 00:00:00 2001 From: illua1 Date: Wed, 19 Apr 2023 20:54:02 +0300 Subject: [PATCH 6/6] also --- source/blender/blenkernel/intern/node.cc | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc index 7e4bc81fe6a..62ee3dd83e9 100644 --- a/source/blender/blenkernel/intern/node.cc +++ b/source/blender/blenkernel/intern/node.cc @@ -196,7 +196,8 @@ static void ntree_copy_data(Main * /*bmain*/, ID *id_dst, const ID *id_src, cons NODE_INSTANCE_HASH_ITER (iter, ntree_src->previews) { bNodeInstanceKey key = BKE_node_instance_hash_iterator_get_key(&iter); - bNodePreview *preview = (bNodePreview *)BKE_node_instance_hash_iterator_get_value(&iter); + bNodePreview *preview = static_cast( + BKE_node_instance_hash_iterator_get_value(&iter)); BKE_node_instance_hash_insert(ntree_dst->previews, key, BKE_node_preview_copy(preview)); } } @@ -2897,7 +2898,7 @@ bNodePreview *BKE_node_preview_verify(bNodeInstanceHash *previews, const int ysize, const bool create) { - bNodePreview *preview = reinterpret_cast( + bNodePreview *preview = static_cast( BKE_node_instance_hash_lookup(previews, key)); if (!preview) { if (create) { @@ -3033,7 +3034,7 @@ void BKE_node_preview_clear_tree(bNodeTree *ntree) bNodeInstanceHashIterator iter; NODE_INSTANCE_HASH_ITER (iter, ntree->previews) { - bNodePreview *preview = reinterpret_cast( + bNodePreview *preview = static_cast( BKE_node_instance_hash_iterator_get_value(&iter)); BKE_node_preview_clear(preview); } @@ -3060,7 +3061,7 @@ void BKE_node_preview_merge_tree(bNodeTree *to_ntree, bNodeTree *from_ntree, boo bNodeInstanceHashIterator iter; NODE_INSTANCE_HASH_ITER (iter, from_ntree->previews) { bNodeInstanceKey key = BKE_node_instance_hash_iterator_get_key(&iter); - bNodePreview *preview = reinterpret_cast( + bNodePreview *preview = static_cast( BKE_node_instance_hash_iterator_get_value(&iter)); /* replace existing previews */ @@ -3950,7 +3951,7 @@ void BKE_node_instance_hash_clear_tags(bNodeInstanceHash *hash) bNodeInstanceHashIterator iter; NODE_INSTANCE_HASH_ITER (iter, hash) { - bNodeInstanceHashEntry *value = reinterpret_cast( + bNodeInstanceHashEntry *value = static_cast( BKE_node_instance_hash_iterator_get_value(&iter)); value->tag = 0; @@ -3965,7 +3966,7 @@ void BKE_node_instance_hash_tag(bNodeInstanceHash * /*hash*/, void *value) bool BKE_node_instance_hash_tag_key(bNodeInstanceHash *hash, bNodeInstanceKey key) { - bNodeInstanceHashEntry *entry = reinterpret_cast( + bNodeInstanceHashEntry *entry = static_cast( BKE_node_instance_hash_lookup(hash, key)); if (entry) { @@ -3988,7 +3989,7 @@ void BKE_node_instance_hash_remove_untagged(bNodeInstanceHash *hash, bNodeInstanceHashIterator iter; int num_untagged = 0; NODE_INSTANCE_HASH_ITER (iter, hash) { - bNodeInstanceHashEntry *value = reinterpret_cast( + bNodeInstanceHashEntry *value = static_cast( BKE_node_instance_hash_iterator_get_value(&iter)); if (!value->tag) { -- 2.30.2