Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Goudey <h.goudey@me.com>2021-12-04 00:25:17 +0300
committerHans Goudey <h.goudey@me.com>2021-12-04 00:25:17 +0300
commit2d8606b36071dd14290aa8852451535a49d3096d (patch)
tree66674726756a859fa1a1e66e9b8eac84387ba2b8 /source/blender/editors/space_node/node_add.cc
parentca0dbf8c26fb637ad06bd170e4e25d200d7ca0f0 (diff)
Cleanup: Use references in node editor, other improvements
This helps to tell when a pointer is expected to be null, and avoid overly verbose code when dereferencing. This commit also includes a few other cleanups in this area: - Use const in a few places - Use `float2` instead of `float[2]` - Remove some unnecessary includes and old code The change can be continued further in the future.
Diffstat (limited to 'source/blender/editors/space_node/node_add.cc')
-rw-r--r--source/blender/editors/space_node/node_add.cc87
1 files changed, 43 insertions, 44 deletions
diff --git a/source/blender/editors/space_node/node_add.cc b/source/blender/editors/space_node/node_add.cc
index 2e3579caaa1..5276cc39e83 100644
--- a/source/blender/editors/space_node/node_add.cc
+++ b/source/blender/editors/space_node/node_add.cc
@@ -67,19 +67,19 @@
* Can be used with both custom and static nodes,
* if `idname == nullptr` the static int type will be used instead.
*/
-bNode *node_add_node(const bContext *C, const char *idname, int type, float locx, float locy)
+bNode *node_add_node(const bContext &C, const char *idname, int type, float locx, float locy)
{
- SpaceNode *snode = CTX_wm_space_node(C);
- Main *bmain = CTX_data_main(C);
+ SpaceNode &snode = *CTX_wm_space_node(&C);
+ Main &bmain = *CTX_data_main(&C);
bNode *node = nullptr;
node_deselect_all(snode);
if (idname) {
- node = nodeAddNode(C, snode->edittree, idname);
+ node = nodeAddNode(&C, snode.edittree, idname);
}
else {
- node = nodeAddStaticNode(C, snode->edittree, type);
+ node = nodeAddStaticNode(&C, snode.edittree, type);
}
BLI_assert(node && node->typeinfo);
@@ -89,13 +89,13 @@ bNode *node_add_node(const bContext *C, const char *idname, int type, float locx
nodeSetSelected(node, true);
- ntreeUpdateTree(bmain, snode->edittree);
- ED_node_set_active(bmain, snode, snode->edittree, node, nullptr);
+ ntreeUpdateTree(&bmain, snode.edittree);
+ ED_node_set_active(&bmain, &snode, snode.edittree, node, nullptr);
snode_update(snode, node);
- if (snode->nodetree->type == NTREE_TEXTURE) {
- ntreeTexCheckCyclics(snode->edittree);
+ if (snode.nodetree->type == NTREE_TEXTURE) {
+ ntreeTexCheckCyclics(snode.edittree);
}
return node;
@@ -107,7 +107,7 @@ bNode *node_add_node(const bContext *C, const char *idname, int type, float locx
/** \name Add Reroute Operator
* \{ */
-static bool add_reroute_intersect_check(bNodeLink *link,
+static bool add_reroute_intersect_check(const bNodeLink &link,
float mcoords[][2],
int tot,
float result[2])
@@ -224,9 +224,9 @@ static bNodeSocketLink *add_reroute_do_socket_section(bContext *C,
static int add_reroute_exec(bContext *C, wmOperator *op)
{
- SpaceNode *snode = CTX_wm_space_node(C);
- ARegion *region = CTX_wm_region(C);
- bNodeTree *ntree = snode->edittree;
+ SpaceNode &snode = *CTX_wm_space_node(C);
+ ARegion &region = *CTX_wm_region(C);
+ bNodeTree &ntree = *snode.edittree;
float mcoords[256][2];
int i = 0;
@@ -236,7 +236,7 @@ static int add_reroute_exec(bContext *C, wmOperator *op)
RNA_float_get_array(&itemptr, "loc", loc);
UI_view2d_region_to_view(
- &region->v2d, (short)loc[0], (short)loc[1], &mcoords[i][0], &mcoords[i][1]);
+ &region.v2d, (short)loc[0], (short)loc[1], &mcoords[i][0], &mcoords[i][1]);
i++;
if (i >= 256) {
break;
@@ -246,7 +246,6 @@ static int add_reroute_exec(bContext *C, wmOperator *op)
if (i > 1) {
ListBase output_links, input_links;
- bNodeLink *link;
bNodeSocketLink *socklink;
float insert_point[2];
@@ -259,11 +258,11 @@ static int add_reroute_exec(bContext *C, wmOperator *op)
BLI_listbase_clear(&output_links);
BLI_listbase_clear(&input_links);
- for (link = (bNodeLink *)ntree->links.first; link; link = link->next) {
- if (node_link_is_hidden_or_dimmed(&region->v2d, link)) {
+ LISTBASE_FOREACH (bNodeLink *, link, &ntree.links) {
+ if (node_link_is_hidden_or_dimmed(region.v2d, *link)) {
continue;
}
- if (add_reroute_intersect_check(link, mcoords, i, insert_point)) {
+ if (add_reroute_intersect_check(*link, mcoords, i, insert_point)) {
add_reroute_insert_socket_link(&output_links, link->fromsock, link, insert_point);
add_reroute_insert_socket_link(&input_links, link->tosock, link, insert_point);
@@ -288,9 +287,9 @@ static int add_reroute_exec(bContext *C, wmOperator *op)
BLI_freelistN(&input_links);
/* always last */
- ntreeUpdateTree(CTX_data_main(C), ntree);
- snode_notify(C, snode);
- snode_dag_update(C, snode);
+ ntreeUpdateTree(CTX_data_main(C), &ntree);
+ snode_notify(*C, snode);
+ snode_dag_update(*C, snode);
return OPERATOR_FINISHED;
}
@@ -377,7 +376,7 @@ static int node_add_group_exec(bContext *C, wmOperator *op)
ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C));
- bNode *group_node = node_add_node(C,
+ bNode *group_node = node_add_node(*C,
node_group_idname(C),
(node_group->type == NTREE_CUSTOM) ? NODE_CUSTOM_GROUP :
NODE_GROUP,
@@ -395,8 +394,8 @@ static int node_add_group_exec(bContext *C, wmOperator *op)
ntreeUpdateTree(bmain, node_group);
ntreeUpdateTree(bmain, ntree);
- snode_notify(C, snode);
- snode_dag_update(C, snode);
+ snode_notify(*C, *snode);
+ snode_dag_update(*C, *snode);
return OPERATOR_FINISHED;
}
@@ -469,7 +468,7 @@ static int node_add_object_exec(bContext *C, wmOperator *op)
ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C));
bNode *object_node = node_add_node(
- C, nullptr, GEO_NODE_OBJECT_INFO, snode->runtime->cursor[0], snode->runtime->cursor[1]);
+ *C, nullptr, GEO_NODE_OBJECT_INFO, snode->runtime->cursor[0], snode->runtime->cursor[1]);
if (!object_node) {
BKE_report(op->reports, RPT_WARNING, "Could not add node object");
return OPERATOR_CANCELLED;
@@ -488,8 +487,8 @@ static int node_add_object_exec(bContext *C, wmOperator *op)
nodeSetActive(ntree, object_node);
ntreeUpdateTree(bmain, ntree);
- snode_notify(C, snode);
- snode_dag_update(C, snode);
+ snode_notify(*C, *snode);
+ snode_dag_update(*C, *snode);
ED_node_tag_update_nodetree(bmain, ntree, object_node);
DEG_relations_tag_update(bmain);
@@ -580,7 +579,7 @@ static int node_add_texture_exec(bContext *C, wmOperator *op)
ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C));
- bNode *texture_node = node_add_node(C,
+ bNode *texture_node = node_add_node(*C,
nullptr,
GEO_NODE_LEGACY_ATTRIBUTE_SAMPLE_TEXTURE,
snode->runtime->cursor[0],
@@ -596,8 +595,8 @@ static int node_add_texture_exec(bContext *C, wmOperator *op)
nodeSetActive(ntree, texture_node);
ntreeUpdateTree(bmain, ntree);
- snode_notify(C, snode);
- snode_dag_update(C, snode);
+ snode_notify(*C, *snode);
+ snode_dag_update(*C, *snode);
DEG_relations_tag_update(bmain);
ED_node_tag_update_nodetree(bmain, ntree, texture_node);
@@ -680,8 +679,8 @@ static Collection *node_add_collection_get_and_poll_collection_node_tree(Main *b
static int node_add_collection_exec(bContext *C, wmOperator *op)
{
Main *bmain = CTX_data_main(C);
- SpaceNode *snode = CTX_wm_space_node(C);
- bNodeTree *ntree = snode->edittree;
+ SpaceNode &snode = *CTX_wm_space_node(C);
+ bNodeTree *ntree = snode.edittree;
Collection *collection;
if (!(collection = node_add_collection_get_and_poll_collection_node_tree(bmain, op))) {
@@ -691,7 +690,7 @@ static int node_add_collection_exec(bContext *C, wmOperator *op)
ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C));
bNode *collection_node = node_add_node(
- C, nullptr, GEO_NODE_COLLECTION_INFO, snode->runtime->cursor[0], snode->runtime->cursor[1]);
+ *C, nullptr, GEO_NODE_COLLECTION_INFO, snode.runtime->cursor[0], snode.runtime->cursor[1]);
if (!collection_node) {
BKE_report(op->reports, RPT_WARNING, "Could not add node collection");
return OPERATOR_CANCELLED;
@@ -710,8 +709,8 @@ static int node_add_collection_exec(bContext *C, wmOperator *op)
nodeSetActive(ntree, collection_node);
ntreeUpdateTree(bmain, ntree);
- snode_notify(C, snode);
- snode_dag_update(C, snode);
+ snode_notify(*C, snode);
+ snode_dag_update(*C, snode);
DEG_relations_tag_update(bmain);
ED_node_tag_update_nodetree(bmain, ntree, collection_node);
@@ -788,7 +787,7 @@ static bool node_add_file_poll(bContext *C)
static int node_add_file_exec(bContext *C, wmOperator *op)
{
Main *bmain = CTX_data_main(C);
- SpaceNode *snode = CTX_wm_space_node(C);
+ SpaceNode &snode = *CTX_wm_space_node(C);
bNode *node;
Image *ima;
int type = 0;
@@ -798,7 +797,7 @@ static int node_add_file_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
- switch (snode->nodetree->type) {
+ switch (snode.nodetree->type) {
case NTREE_SHADER:
type = SH_NODE_TEX_IMAGE;
break;
@@ -817,7 +816,7 @@ static int node_add_file_exec(bContext *C, wmOperator *op)
ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C));
- node = node_add_node(C, nullptr, type, snode->runtime->cursor[0], snode->runtime->cursor[1]);
+ node = node_add_node(*C, nullptr, type, snode.runtime->cursor[0], snode.runtime->cursor[1]);
if (!node) {
BKE_report(op->reports, RPT_WARNING, "Could not add an image node");
@@ -841,8 +840,8 @@ static int node_add_file_exec(bContext *C, wmOperator *op)
WM_event_add_notifier(C, NC_IMAGE | NA_EDITED, ima);
}
- snode_notify(C, snode);
- snode_dag_update(C, snode);
+ snode_notify(*C, snode);
+ snode_dag_update(*C, snode);
DEG_relations_tag_update(bmain);
return OPERATOR_FINISHED;
@@ -923,7 +922,7 @@ static bool node_add_mask_poll(bContext *C)
static int node_add_mask_exec(bContext *C, wmOperator *op)
{
Main *bmain = CTX_data_main(C);
- SpaceNode *snode = CTX_wm_space_node(C);
+ SpaceNode &snode = *CTX_wm_space_node(C);
bNode *node;
ID *mask = node_add_mask_get_and_poll_mask(bmain, op);
@@ -934,7 +933,7 @@ static int node_add_mask_exec(bContext *C, wmOperator *op)
ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C));
node = node_add_node(
- C, nullptr, CMP_NODE_MASK, snode->runtime->cursor[0], snode->runtime->cursor[1]);
+ *C, nullptr, CMP_NODE_MASK, snode.runtime->cursor[0], snode.runtime->cursor[1]);
if (!node) {
BKE_report(op->reports, RPT_WARNING, "Could not add a mask node");
@@ -944,8 +943,8 @@ static int node_add_mask_exec(bContext *C, wmOperator *op)
node->id = mask;
id_us_plus(mask);
- snode_notify(C, snode);
- snode_dag_update(C, snode);
+ snode_notify(*C, snode);
+ snode_dag_update(*C, snode);
DEG_relations_tag_update(bmain);
return OPERATOR_FINISHED;