Cleanup: Add const in various places in node code

Also includes some various other minor cleanups, like using bool
instead of int in a couple places.
This commit is contained in:
Hans Goudey 2021-01-15 10:48:22 -06:00
parent 20a54347ee
commit 237e27e161
8 changed files with 85 additions and 82 deletions

View File

@ -463,8 +463,8 @@ void ntreeSetOutput(struct bNodeTree *ntree);
void ntreeFreeCache(struct bNodeTree *ntree);
bool ntreeNodeExists(struct bNodeTree *ntree, struct bNode *testnode);
bool ntreeOutputExists(struct bNode *node, struct bNodeSocket *testsock);
bool ntreeNodeExists(const struct bNodeTree *ntree, const struct bNode *testnode);
bool ntreeOutputExists(const struct bNode *node, const struct bNodeSocket *testsock);
void ntreeNodeFlagSet(const bNodeTree *ntree, const int flag, const bool enable);
struct bNodeTree *ntreeLocalize(struct bNodeTree *ntree);
void ntreeLocalSync(struct bNodeTree *localtree, struct bNodeTree *ntree);
@ -501,7 +501,7 @@ struct bNodeSocket *ntreeInsertSocketInterfaceFromSocket(struct bNodeTree *ntree
struct bNodeSocket *from_sock);
void ntreeRemoveSocketInterface(struct bNodeTree *ntree, struct bNodeSocket *sock);
struct StructRNA *ntreeInterfaceTypeGet(struct bNodeTree *ntree, int create);
struct StructRNA *ntreeInterfaceTypeGet(struct bNodeTree *ntree, bool create);
void ntreeInterfaceTypeFree(struct bNodeTree *ntree);
void ntreeInterfaceTypeUpdate(struct bNodeTree *ntree);
@ -624,12 +624,12 @@ struct bNodeLink *nodeAddLink(struct bNodeTree *ntree,
struct bNodeSocket *tosock);
void nodeRemLink(struct bNodeTree *ntree, struct bNodeLink *link);
void nodeRemSocketLinks(struct bNodeTree *ntree, struct bNodeSocket *sock);
bool nodeLinkIsHidden(struct bNodeLink *link);
bool nodeLinkIsHidden(const struct bNodeLink *link);
void nodeInternalRelink(struct bNodeTree *ntree, struct bNode *node);
void nodeToView(struct bNode *node, float x, float y, float *rx, float *ry);
void nodeFromView(struct bNode *node, float x, float y, float *rx, float *ry);
bool nodeAttachNodeCheck(struct bNode *node, struct bNode *parent);
void nodeToView(const struct bNode *node, float x, float y, float *rx, float *ry);
void nodeFromView(const struct bNode *node, float x, float y, float *rx, float *ry);
bool nodeAttachNodeCheck(const struct bNode *node, const struct bNode *parent);
void nodeAttachNode(struct bNode *node, struct bNode *parent);
void nodeDetachNode(struct bNode *node);
@ -661,9 +661,9 @@ void nodeChainIterBackwards(const bNodeTree *ntree,
void nodeParentsIter(bNode *node, bool (*callback)(bNode *, void *), void *userdata);
struct bNodeLink *nodeFindLink(struct bNodeTree *ntree,
struct bNodeSocket *from,
struct bNodeSocket *to);
int nodeCountSocketLinks(struct bNodeTree *ntree, struct bNodeSocket *sock);
const struct bNodeSocket *from,
const struct bNodeSocket *to);
int nodeCountSocketLinks(const struct bNodeTree *ntree, const struct bNodeSocket *sock);
void nodeSetSelected(struct bNode *node, bool select);
void nodeSetActive(struct bNodeTree *ntree, struct bNode *node);
@ -678,11 +678,11 @@ void nodeUpdate(struct bNodeTree *ntree, struct bNode *node);
bool nodeUpdateID(struct bNodeTree *ntree, struct ID *id);
void nodeUpdateInternalLinks(struct bNodeTree *ntree, struct bNode *node);
int nodeSocketIsHidden(struct bNodeSocket *sock);
int nodeSocketIsHidden(const struct bNodeSocket *sock);
void ntreeTagUsedSockets(struct bNodeTree *ntree);
void nodeSetSocketAvailability(struct bNodeSocket *sock, bool is_available);
int nodeSocketLinkLimit(struct bNodeSocket *sock);
int nodeSocketLinkLimit(const struct bNodeSocket *sock);
/* Node Clipboard */
void BKE_node_clipboard_init(struct bNodeTree *ntree);
@ -767,7 +767,7 @@ BLI_INLINE bool BKE_node_instance_hash_iterator_done(bNodeInstanceHashIterator *
/* Node Previews */
int BKE_node_preview_used(struct bNode *node);
bool BKE_node_preview_used(const struct bNode *node);
bNodePreview *BKE_node_preview_verify(
struct bNodeInstanceHash *previews, bNodeInstanceKey key, int xsize, int ysize, bool create);
bNodePreview *BKE_node_preview_copy(struct bNodePreview *preview);

View File

@ -2149,7 +2149,7 @@ void nodeRemSocketLinks(bNodeTree *ntree, bNodeSocket *sock)
ntree->update |= NTREE_UPDATE_LINKS;
}
bool nodeLinkIsHidden(bNodeLink *link)
bool nodeLinkIsHidden(const bNodeLink *link)
{
return nodeSocketIsHidden(link->fromsock) || nodeSocketIsHidden(link->tosock);
}
@ -2200,7 +2200,7 @@ void nodeInternalRelink(bNodeTree *ntree, bNode *node)
}
}
void nodeToView(bNode *node, float x, float y, float *rx, float *ry)
void nodeToView(const bNode *node, float x, float y, float *rx, float *ry)
{
if (node->parent) {
nodeToView(node->parent, x + node->locx, y + node->locy, rx, ry);
@ -2211,7 +2211,7 @@ void nodeToView(bNode *node, float x, float y, float *rx, float *ry)
}
}
void nodeFromView(bNode *node, float x, float y, float *rx, float *ry)
void nodeFromView(const bNode *node, float x, float y, float *rx, float *ry)
{
if (node->parent) {
nodeFromView(node->parent, x, y, rx, ry);
@ -2224,10 +2224,10 @@ void nodeFromView(bNode *node, float x, float y, float *rx, float *ry)
}
}
bool nodeAttachNodeCheck(bNode *node, bNode *parent)
bool nodeAttachNodeCheck(const bNode *node, const bNode *parent)
{
for (bNode *parent_recurse = node; parent_recurse; parent_recurse = parent_recurse->parent) {
if (parent_recurse == parent) {
for (const bNode *parent_iter = node; parent_iter; parent_iter = parent_iter->parent) {
if (parent_iter == parent) {
return true;
}
}
@ -2317,8 +2317,6 @@ void nodePositionPropagate(bNode *node)
bNodeTree *ntreeAddTree(Main *bmain, const char *name, const char *idname)
{
bNodeTree *ntree;
/* trees are created as local trees for compositor, material or texture nodes,
* node groups and other tree types are created as library data.
*/
@ -2327,7 +2325,7 @@ bNodeTree *ntreeAddTree(Main *bmain, const char *name, const char *idname)
if (is_embedded) {
flag |= LIB_ID_CREATE_NO_MAIN;
}
ntree = BKE_libblock_alloc(bmain, ID_NT, name, flag);
bNodeTree *ntree = BKE_libblock_alloc(bmain, ID_NT, name, flag);
if (is_embedded) {
ntree->id.flag |= LIB_EMBEDDED_DATA;
}
@ -2362,7 +2360,7 @@ bNodeTree *ntreeCopyTree(Main *bmain, const bNodeTree *ntree)
* using BKE_node_preview_init_tree to set up previews for a whole node tree in advance.
* This should be left more to the individual node tree implementations.
*/
int BKE_node_preview_used(bNode *node)
bool BKE_node_preview_used(const bNode *node)
{
/* XXX check for closed nodes? */
return (node->typeinfo->flag & NODE_PREVIEW) != 0;
@ -2959,9 +2957,9 @@ ID *BKE_node_tree_find_owner_ID(Main *bmain, struct bNodeTree *ntree)
return NULL;
}
bool ntreeNodeExists(bNodeTree *ntree, bNode *testnode)
bool ntreeNodeExists(const bNodeTree *ntree, const bNode *testnode)
{
LISTBASE_FOREACH (bNode *, node, &ntree->nodes) {
LISTBASE_FOREACH (const bNode *, node, &ntree->nodes) {
if (node == testnode) {
return true;
}
@ -2969,9 +2967,9 @@ bool ntreeNodeExists(bNodeTree *ntree, bNode *testnode)
return false;
}
bool ntreeOutputExists(bNode *node, bNodeSocket *testsock)
bool ntreeOutputExists(const bNode *node, const bNodeSocket *testsock)
{
LISTBASE_FOREACH (bNodeSocket *, sock, &node->outputs) {
LISTBASE_FOREACH (const bNodeSocket *, sock, &node->outputs) {
if (sock == testsock) {
return true;
}
@ -3246,7 +3244,7 @@ static void ntree_interface_type_create(bNodeTree *ntree)
}
}
StructRNA *ntreeInterfaceTypeGet(bNodeTree *ntree, int create)
StructRNA *ntreeInterfaceTypeGet(bNodeTree *ntree, bool create)
{
if (ntree->interface_type) {
/* strings are generated from base string + ID name, sizes are sufficient */
@ -3333,7 +3331,7 @@ bool ntreeHasTree(const bNodeTree *ntree, const bNodeTree *lookup)
return false;
}
bNodeLink *nodeFindLink(bNodeTree *ntree, bNodeSocket *from, bNodeSocket *to)
bNodeLink *nodeFindLink(bNodeTree *ntree, const bNodeSocket *from, const bNodeSocket *to)
{
LISTBASE_FOREACH (bNodeLink *, link, &ntree->links) {
if (link->fromsock == from && link->tosock == to) {
@ -3346,10 +3344,10 @@ bNodeLink *nodeFindLink(bNodeTree *ntree, bNodeSocket *from, bNodeSocket *to)
return NULL;
}
int nodeCountSocketLinks(bNodeTree *ntree, bNodeSocket *sock)
int nodeCountSocketLinks(const bNodeTree *ntree, const bNodeSocket *sock)
{
int tot = 0;
LISTBASE_FOREACH (bNodeLink *, link, &ntree->links) {
LISTBASE_FOREACH (const bNodeLink *, link, &ntree->links) {
if (link->fromsock == sock || link->tosock == sock) {
tot++;
}
@ -3515,7 +3513,7 @@ void nodeSetActive(bNodeTree *ntree, bNode *node)
}
}
int nodeSocketIsHidden(bNodeSocket *sock)
int nodeSocketIsHidden(const bNodeSocket *sock)
{
return ((sock->flag & (SOCK_HIDDEN | SOCK_UNAVAIL)) != 0);
}
@ -3530,7 +3528,7 @@ void nodeSetSocketAvailability(bNodeSocket *sock, bool is_available)
}
}
int nodeSocketLinkLimit(struct bNodeSocket *sock)
int nodeSocketLinkLimit(const bNodeSocket *sock)
{
bNodeSocketType *stype = sock->typeinfo;
if (stype != NULL && stype->use_link_limits_of_type) {

View File

@ -231,7 +231,7 @@ struct View2D *UI_view2d_fromcontext(const struct bContext *C);
struct View2D *UI_view2d_fromcontext_rwin(const struct bContext *C);
void UI_view2d_scroller_size_get(const struct View2D *v2d, float *r_x, float *r_y);
void UI_view2d_scale_get(struct View2D *v2d, float *r_x, float *r_y);
void UI_view2d_scale_get(const struct View2D *v2d, float *r_x, float *r_y);
float UI_view2d_scale_get_x(const struct View2D *v2d);
float UI_view2d_scale_get_y(const struct View2D *v2d);
void UI_view2d_scale_get_inverse(const struct View2D *v2d, float *r_x, float *r_y);

View File

@ -1895,7 +1895,7 @@ void UI_view2d_scroller_size_get(const View2D *v2d, float *r_x, float *r_y)
*
* \param r_x, r_y: scale on each axis
*/
void UI_view2d_scale_get(View2D *v2d, float *r_x, float *r_y)
void UI_view2d_scale_get(const View2D *v2d, float *r_x, float *r_y)
{
if (r_x) {
*r_x = UI_view2d_scale_get_x(v2d);

View File

@ -3817,9 +3817,9 @@ void draw_nodespace_back_pix(const bContext *C,
}
/* return quadratic beziers points for a given nodelink and clip if v2d is not NULL. */
static bool node_link_bezier_handles(View2D *v2d,
SpaceNode *snode,
bNodeLink *link,
static bool node_link_bezier_handles(const View2D *v2d,
const SpaceNode *snode,
const bNodeLink *link,
float vec[4][2])
{
float cursor[2] = {0.0f, 0.0f};
@ -3912,8 +3912,11 @@ static bool node_link_bezier_handles(View2D *v2d,
}
/* if v2d not NULL, it clips and returns 0 if not visible */
bool node_link_bezier_points(
View2D *v2d, SpaceNode *snode, bNodeLink *link, float coord_array[][2], int resol)
bool node_link_bezier_points(const View2D *v2d,
const SpaceNode *snode,
const bNodeLink *link,
float coord_array[][2],
const int resol)
{
float vec[4][2];
@ -4076,7 +4079,7 @@ static char nodelink_get_color_id(int th_col)
return 0;
}
static void nodelink_batch_draw(SpaceNode *snode)
static void nodelink_batch_draw(const SpaceNode *snode)
{
if (g_batch_link.count == 0) {
return;
@ -4116,7 +4119,7 @@ void nodelink_batch_end(SpaceNode *snode)
g_batch_link.enabled = false;
}
static void nodelink_batch_add_link(SpaceNode *snode,
static void nodelink_batch_add_link(const SpaceNode *snode,
const float p0[2],
const float p1[2],
const float p2[2],
@ -4148,8 +4151,12 @@ static void nodelink_batch_add_link(SpaceNode *snode,
}
/* don't do shadows if th_col3 is -1. */
void node_draw_link_bezier(
View2D *v2d, SpaceNode *snode, bNodeLink *link, int th_col1, int th_col2, int th_col3)
void node_draw_link_bezier(const View2D *v2d,
const SpaceNode *snode,
const bNodeLink *link,
int th_col1,
int th_col2,
int th_col3)
{
float vec[4][2];

View File

@ -317,14 +317,14 @@ static void node_uiblocks_init(const bContext *C, bNodeTree *ntree)
}
}
void node_to_view(struct bNode *node, float x, float y, float *rx, float *ry)
void node_to_view(const bNode *node, float x, float y, float *rx, float *ry)
{
nodeToView(node, x, y, rx, ry);
*rx *= UI_DPI_FAC;
*ry *= UI_DPI_FAC;
}
void node_to_updated_rect(struct bNode *node, rctf *r_rect)
void node_to_updated_rect(const bNode *node, rctf *r_rect)
{
node_to_view(node, node->offsetx, node->offsety, &r_rect->xmin, &r_rect->ymax);
node_to_view(node,
@ -334,7 +334,7 @@ void node_to_updated_rect(struct bNode *node, rctf *r_rect)
&r_rect->ymin);
}
void node_from_view(struct bNode *node, float x, float y, float *rx, float *ry)
void node_from_view(const bNode *node, float x, float y, float *rx, float *ry)
{
x /= UI_DPI_FAC;
y /= UI_DPI_FAC;
@ -689,11 +689,11 @@ int node_get_colorid(bNode *node)
/* note: in cmp_util.c is similar code, for node_compo_pass_on()
* the same goes for shader and texture nodes. */
/* note: in node_edit.c is similar code, for untangle node */
static void node_draw_mute_line(View2D *v2d, SpaceNode *snode, bNode *node)
static void node_draw_mute_line(const View2D *v2d, const SpaceNode *snode, const bNode *node)
{
GPU_blend(GPU_BLEND_ALPHA);
LISTBASE_FOREACH (bNodeLink *, link, &node->internal_links) {
LISTBASE_FOREACH (const bNodeLink *, link, &node->internal_links) {
node_draw_link_bezier(v2d, snode, link, TH_REDALERT, TH_REDALERT, -1);
}
@ -947,14 +947,14 @@ static void node_toggle_button_cb(struct bContext *C, void *node_argv, void *op_
WM_operator_name_call(C, opname, WM_OP_INVOKE_DEFAULT, NULL);
}
void node_draw_shadow(SpaceNode *snode, bNode *node, float radius, float alpha)
void node_draw_shadow(const SpaceNode *snode, const bNode *node, float radius, float alpha)
{
rctf *rct = &node->totr;
const rctf *rct = &node->totr;
UI_draw_roundbox_corner_set(UI_CNR_ALL);
ui_draw_dropshadow(rct, radius, snode->aspect, alpha, node->flag & SELECT);
}
void node_draw_sockets(View2D *v2d,
void node_draw_sockets(const View2D *v2d,
const bContext *C,
bNodeTree *ntree,
bNode *node,
@ -1118,8 +1118,8 @@ void node_draw_sockets(View2D *v2d,
}
static void node_draw_basis(const bContext *C,
ARegion *region,
SpaceNode *snode,
const View2D *v2d,
const SpaceNode *snode,
bNodeTree *ntree,
bNode *node,
bNodeInstanceKey key)
@ -1127,8 +1127,6 @@ static void node_draw_basis(const bContext *C,
/* float socket_size = NODE_SOCKSIZE*U.dpi/72; */ /* UNUSED */
float iconbutw = 0.8f * UI_UNIT_X;
View2D *v2d = &region->v2d;
/* skip if out of view */
if (BLI_rctf_isect(&node->totr, &v2d->cur, NULL) == false) {
UI_block_end(C, node->block);
@ -1343,8 +1341,8 @@ static void node_draw_basis(const bContext *C,
}
static void node_draw_hidden(const bContext *C,
ARegion *region,
SpaceNode *snode,
const View2D *v2d,
const SpaceNode *snode,
bNodeTree *ntree,
bNode *node,
bNodeInstanceKey UNUSED(key))
@ -1353,8 +1351,6 @@ static void node_draw_hidden(const bContext *C,
float centy = BLI_rctf_cent_y(rct);
float hiddenrad = BLI_rctf_size_y(rct) / 2.0f;
View2D *v2d = &region->v2d;
float scale;
UI_view2d_scale_get(v2d, &scale, NULL);
@ -1438,7 +1434,7 @@ static void node_draw_hidden(const bContext *C,
/* disable lines */
if (node->flag & NODE_MUTED) {
node_draw_mute_line(&region->v2d, snode, node);
node_draw_mute_line(v2d, snode, node);
}
char showname[128]; /* 128 is used below */
@ -1550,11 +1546,12 @@ void node_draw_default(const bContext *C,
bNode *node,
bNodeInstanceKey key)
{
const View2D *v2d = &region->v2d;
if (node->flag & NODE_HIDDEN) {
node_draw_hidden(C, region, snode, ntree, node, key);
node_draw_hidden(C, v2d, snode, ntree, node, key);
}
else {
node_draw_basis(C, region, snode, ntree, node, key);
node_draw_basis(C, v2d, snode, ntree, node, key);
}
}
@ -1607,8 +1604,7 @@ void node_draw_nodetree(const bContext *C,
#endif
/* draw background nodes, last nodes in front */
int a = 0;
LISTBASE_FOREACH_INDEX (bNode *, node, &ntree->nodes, a) {
LISTBASE_FOREACH (bNode *, node, &ntree->nodes) {
#ifdef USE_DRAW_TOT_UPDATE
/* unrelated to background nodes, update the v2d->tot,
* can be anywhere before we draw the scroll bars */
@ -1635,8 +1631,7 @@ void node_draw_nodetree(const bContext *C,
GPU_blend(GPU_BLEND_NONE);
/* draw foreground nodes, last nodes in front */
a = 0;
LISTBASE_FOREACH_INDEX (bNode *, node, &ntree->nodes, a) {
LISTBASE_FOREACH (bNode *, node, &ntree->nodes) {
if (node->flag & NODE_BACKGROUND) {
continue;
}
@ -1686,8 +1681,8 @@ static void draw_nodetree(const bContext *C,
/* shade the parent node group and add a uiBlock to clip mouse events */
static void draw_group_overlay(const bContext *C, ARegion *region)
{
View2D *v2d = &region->v2d;
rctf rect = v2d->cur;
const View2D *v2d = &region->v2d;
const rctf rect = v2d->cur;
float color[4];
/* shade node groups to separate them visually */

View File

@ -61,14 +61,17 @@ void space_node_group_offset(struct SpaceNode *snode, float *x, float *y);
/* node_draw.c */
int node_get_colorid(struct bNode *node);
int node_get_resize_cursor(int directions);
void node_draw_shadow(struct SpaceNode *snode, struct bNode *node, float radius, float alpha);
void node_draw_shadow(const struct SpaceNode *snode,
const struct bNode *node,
float radius,
float alpha);
void node_draw_default(const struct bContext *C,
struct ARegion *region,
struct SpaceNode *snode,
struct bNodeTree *ntree,
struct bNode *node,
bNodeInstanceKey key);
void node_draw_sockets(struct View2D *v2d,
void node_draw_sockets(const struct View2D *v2d,
const struct bContext *C,
struct bNodeTree *ntree,
struct bNode *node,
@ -92,9 +95,9 @@ void node_draw_space(const bContext *C, ARegion *region);
void node_set_cursor(struct wmWindow *win, struct SpaceNode *snode, float cursor[2]);
/* DPI scaled coords */
void node_to_view(struct bNode *node, float x, float y, float *rx, float *ry);
void node_to_updated_rect(struct bNode *node, rctf *r_rect);
void node_from_view(struct bNode *node, float x, float y, float *rx, float *ry);
void node_to_view(const struct bNode *node, float x, float y, float *rx, float *ry);
void node_to_updated_rect(const struct bNode *node, rctf *r_rect);
void node_from_view(const struct bNode *node, float x, float y, float *rx, float *ry);
/* node_buttons.c */
void node_buttons_register(struct ARegionType *art);
@ -145,17 +148,17 @@ void nodelink_batch_start(struct SpaceNode *snode);
void nodelink_batch_end(struct SpaceNode *snode);
void node_draw_link(struct View2D *v2d, struct SpaceNode *snode, struct bNodeLink *link);
void node_draw_link_bezier(struct View2D *v2d,
struct SpaceNode *snode,
struct bNodeLink *link,
void node_draw_link_bezier(const struct View2D *v2d,
const struct SpaceNode *snode,
const struct bNodeLink *link,
int th_col1,
int th_col2,
int th_col3);
bool node_link_bezier_points(struct View2D *v2d,
struct SpaceNode *snode,
struct bNodeLink *link,
bool node_link_bezier_points(const struct View2D *v2d,
const struct SpaceNode *snode,
const struct bNodeLink *link,
float coord_array[][2],
int resol);
const int resol);
void draw_nodespace_back_pix(const struct bContext *C,
struct ARegion *region,
struct SpaceNode *snode,

View File

@ -58,7 +58,7 @@
static bool ntree_has_drivers(bNodeTree *ntree)
{
AnimData *adt = BKE_animdata_from_id(&ntree->id);
const AnimData *adt = BKE_animdata_from_id(&ntree->id);
if (adt == NULL) {
return false;
}