[Bf-blender-cvs] [638de722775] master: Cleanup: remove some G.main usages.

Bastien Montagne noreply at git.blender.org
Sat Jun 9 15:17:10 CEST 2018


Commit: 638de722775fc43c3543a30aaa888372fe93fe98
Author: Bastien Montagne
Date:   Sat Jun 9 15:16:44 2018 +0200
Branches: master
https://developer.blender.org/rB638de722775fc43c3543a30aaa888372fe93fe98

Cleanup: remove some G.main usages.

===================================================================

M	source/blender/blenkernel/BKE_modifier.h
M	source/blender/blenkernel/intern/modifier.c
M	source/blender/editors/include/ED_node.h
M	source/blender/editors/space_node/node_draw.c
M	source/blender/editors/space_node/node_edit.c
M	source/blender/editors/space_node/node_group.c
M	source/blender/editors/space_node/node_intern.h
M	source/blender/editors/space_node/node_relationships.c
M	source/blender/editors/space_node/node_templates.c
M	source/blender/editors/space_view3d/drawobject.c
M	source/blender/editors/transform/transform_conversions.c
M	source/blender/makesdna/DNA_ID.h
M	source/blender/modifiers/intern/MOD_fluidsim_util.c
M	source/blender/modifiers/intern/MOD_meshcache.c
M	source/blender/modifiers/intern/MOD_ocean.c

===================================================================

diff --git a/source/blender/blenkernel/BKE_modifier.h b/source/blender/blenkernel/BKE_modifier.h
index aacd2f99ff5..e9ce91996e0 100644
--- a/source/blender/blenkernel/BKE_modifier.h
+++ b/source/blender/blenkernel/BKE_modifier.h
@@ -431,7 +431,7 @@ void modifier_mdef_compact_influences(struct ModifierData *md);
 
 void        modifier_path_init(char *path, int path_maxlen, const char *name);
 const char *modifier_path_relbase(struct Main *bmain, struct Object *ob);
-
+const char *modifier_path_relbase_from_global(struct Object *ob);
 
 /* wrappers for modifier callbacks */
 
diff --git a/source/blender/blenkernel/intern/modifier.c b/source/blender/blenkernel/intern/modifier.c
index 0cf10f7590c..368a691e778 100644
--- a/source/blender/blenkernel/intern/modifier.c
+++ b/source/blender/blenkernel/intern/modifier.c
@@ -777,6 +777,18 @@ const char *modifier_path_relbase(Main *bmain, Object *ob)
 	}
 }
 
+const char *modifier_path_relbase_from_global(Object *ob)
+{
+	if (G.relbase_valid || ID_IS_LINKED(ob)) {
+		return ID_BLEND_PATH_FROM_GLOBAL(&ob->id);
+	}
+	else {
+		/* last resort, better then using "" which resolves to the current
+		 * working directory */
+		return BKE_tempdir_session();
+	}
+}
+
 /* initializes the path with either */
 void modifier_path_init(char *path, int path_maxlen, const char *name)
 {
diff --git a/source/blender/editors/include/ED_node.h b/source/blender/editors/include/ED_node.h
index b4d4ffe44dd..c8e89afc18a 100644
--- a/source/blender/editors/include/ED_node.h
+++ b/source/blender/editors/include/ED_node.h
@@ -86,7 +86,7 @@ float ED_node_grid_size(void);
 
 /* node_relationships.c */
 void ED_node_link_intersect_test(struct ScrArea *sa, int test);
-void ED_node_link_insert(struct ScrArea *sa);
+void ED_node_link_insert(struct Main *bmain, struct ScrArea *sa);
 
 /* node_edit.c */
 void ED_node_set_tree_type(struct SpaceNode *snode, struct bNodeTreeType *typeinfo);
diff --git a/source/blender/editors/space_node/node_draw.c b/source/blender/editors/space_node/node_draw.c
index d1374aab02c..3b6a227d124 100644
--- a/source/blender/editors/space_node/node_draw.c
+++ b/source/blender/editors/space_node/node_draw.c
@@ -160,7 +160,7 @@ void ED_node_tag_update_nodetree(Main *bmain, bNodeTree *ntree, bNode *node)
 
 	bool do_tag_update = true;
 	if (node != NULL) {
-		if (!node_connected_to_output(ntree, node)) {
+		if (!node_connected_to_output(bmain, ntree, node)) {
 			do_tag_update = false;
 		}
 	}
diff --git a/source/blender/editors/space_node/node_edit.c b/source/blender/editors/space_node/node_edit.c
index 59cfbac2e25..1cb387bb527 100644
--- a/source/blender/editors/space_node/node_edit.c
+++ b/source/blender/editors/space_node/node_edit.c
@@ -1132,6 +1132,7 @@ static void node_duplicate_reparent_recursive(bNode *node)
 
 static int node_duplicate_exec(bContext *C, wmOperator *op)
 {
+	Main *bmain = CTX_data_main(C);
 	SpaceNode *snode = CTX_wm_space_node(C);
 	bNodeTree *ntree = snode->edittree;
 	bNode *node, *newnode, *lastnode;
@@ -1139,7 +1140,7 @@ static int node_duplicate_exec(bContext *C, wmOperator *op)
 	const bool keep_inputs = RNA_boolean_get(op->ptr, "keep_inputs");
 	bool do_tag_update = false;
 
-	ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C));
+	ED_preview_kill_jobs(CTX_wm_manager(C), bmain);
 
 	lastnode = ntree->nodes.last;
 	for (node = ntree->nodes.first; node; node = node->next) {
@@ -1216,7 +1217,7 @@ static int node_duplicate_exec(bContext *C, wmOperator *op)
 			node->flag &= ~NODE_ACTIVE;
 			nodeSetSelected(newnode, true);
 
-			do_tag_update |= (do_tag_update || node_connected_to_output(ntree, newnode));
+			do_tag_update |= (do_tag_update || node_connected_to_output(bmain, ntree, newnode));
 		}
 
 		/* make sure we don't copy new nodes again! */
@@ -1586,18 +1587,19 @@ void NODE_OT_hide_socket_toggle(wmOperatorType *ot)
 
 static int node_mute_exec(bContext *C, wmOperator *UNUSED(op))
 {
+	Main *bmain = CTX_data_main(C);
 	SpaceNode *snode = CTX_wm_space_node(C);
 	bNode *node;
 	bool do_tag_update = false;
 
-	ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C));
+	ED_preview_kill_jobs(CTX_wm_manager(C), bmain);
 
 	for (node = snode->edittree->nodes.first; node; node = node->next) {
 		/* Only allow muting of nodes having a mute func! */
 		if ((node->flag & SELECT) && node->typeinfo->update_internal_links) {
 			node->flag ^= NODE_MUTED;
 			snode_update(snode, node);
-			do_tag_update |= (do_tag_update || node_connected_to_output(snode->edittree, node));
+			do_tag_update |= (do_tag_update || node_connected_to_output(bmain, snode->edittree, node));
 		}
 	}
 
@@ -1628,17 +1630,18 @@ void NODE_OT_mute_toggle(wmOperatorType *ot)
 
 static int node_delete_exec(bContext *C, wmOperator *UNUSED(op))
 {
+	Main *bmain = CTX_data_main(C);
 	SpaceNode *snode = CTX_wm_space_node(C);
 	bNode *node, *next;
 	bool do_tag_update = false;
 
-	ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C));
+	ED_preview_kill_jobs(CTX_wm_manager(C), bmain);
 
 	for (node = snode->edittree->nodes.first; node; node = next) {
 		next = node->next;
 		if (node->flag & SELECT) {
 			/* check id user here, nodeFreeNode is called for free dbase too */
-			do_tag_update |= (do_tag_update || node_connected_to_output(snode->edittree, node));
+			do_tag_update |= (do_tag_update || node_connected_to_output(bmain, snode->edittree, node));
 			if (node->id)
 				id_us_min(node->id);
 			nodeFreeNode(snode->edittree, node);
diff --git a/source/blender/editors/space_node/node_group.c b/source/blender/editors/space_node/node_group.c
index 7da3d0bf93d..5d326a0be38 100644
--- a/source/blender/editors/space_node/node_group.c
+++ b/source/blender/editors/space_node/node_group.c
@@ -181,7 +181,7 @@ void NODE_OT_group_edit(wmOperatorType *ot)
 /* ******************** Ungroup operator ********************** */
 
 /* returns 1 if its OK */
-static int node_group_ungroup(bNodeTree *ntree, bNode *gnode)
+static int node_group_ungroup(Main *bmain, bNodeTree *ntree, bNode *gnode)
 {
 	bNodeLink *link, *linkn, *tlink;
 	bNode *node, *nextnode;
@@ -200,7 +200,7 @@ static int node_group_ungroup(bNodeTree *ntree, bNode *gnode)
 	 * - ngroup (i.e. the source NodeTree) is left unscathed
 	 * - temp copy. don't change ID usercount
 	 */
-	wgroup = ntreeCopyTree_ex(ngroup, G.main, false);
+	wgroup = ntreeCopyTree_ex(ngroup, bmain, false);
 
 	/* Add the nodes into the ntree */
 	for (node = wgroup->nodes.first; node; node = nextnode) {
@@ -257,7 +257,7 @@ static int node_group_ungroup(bNodeTree *ntree, bNode *gnode)
 		bAction *waction;
 
 		/* firstly, wgroup needs to temporary dummy action that can be destroyed, as it shares copies */
-		waction = wgroup->adt->action = BKE_action_copy(G.main, wgroup->adt->action);
+		waction = wgroup->adt->action = BKE_action_copy(bmain, wgroup->adt->action);
 
 		/* now perform the moving */
 		BKE_animdata_separate_by_basepath(&wgroup->id, &ntree->id, &anim_basepaths);
@@ -272,13 +272,13 @@ static int node_group_ungroup(bNodeTree *ntree, bNode *gnode)
 
 		/* free temp action too */
 		if (waction) {
-			BKE_libblock_free(G.main, waction);
+			BKE_libblock_free(bmain, waction);
 			wgroup->adt->action = NULL;
 		}
 	}
 
 	/* free the group tree (takes care of user count) */
-	BKE_libblock_free(G.main, wgroup);
+	BKE_libblock_free(bmain, wgroup);
 
 	/* restore external links to and from the gnode */
 	/* note: the nodes have been copied to intermediate wgroup first (so need to use new_node),
@@ -354,18 +354,19 @@ static int node_group_ungroup(bNodeTree *ntree, bNode *gnode)
 
 static int node_group_ungroup_exec(bContext *C, wmOperator *op)
 {
+	Main *bmain = CTX_data_main(C);
 	SpaceNode *snode = CTX_wm_space_node(C);
 	const char *node_idname = group_node_idname(C);
 	bNode *gnode;
 
-	ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C));
+	ED_preview_kill_jobs(CTX_wm_manager(C), bmain);
 
 	gnode = node_group_get_active(C, node_idname);
 	if (!gnode)
 		return OPERATOR_CANCELLED;
 
-	if (gnode->id && node_group_ungroup(snode->edittree, gnode)) {
-		ntreeUpdateTree(CTX_data_main(C), snode->nodetree);
+	if (gnode->id && node_group_ungroup(bmain, snode->edittree, gnode)) {
+		ntreeUpdateTree(bmain, snode->nodetree);
 	}
 	else {
 		BKE_report(op->reports, RPT_WARNING, "Cannot ungroup");
diff --git a/source/blender/editors/space_node/node_intern.h b/source/blender/editors/space_node/node_intern.h
index f2ed1d1b4ec..9bcbe94d287 100644
--- a/source/blender/editors/space_node/node_intern.h
+++ b/source/blender/editors/space_node/node_intern.h
@@ -41,6 +41,7 @@ struct ARegion;
 struct ARegionType;
 struct View2D;
 struct bContext;
+struct Main;
 struct wmWindow;
 struct bNode;
 struct bNodeSocket;
@@ -156,7 +157,7 @@ void NODE_OT_group_edit(struct wmOperatorType *ot);
 
 
 /* node_relationships.c */
-bool node_connected_to_output(struct bNodeTree *ntree, struct bNode *node);
+bool node_connected_to_output(struct Main *bmain, struct bNodeTree *ntree, struct bNode *node);
 
 void NODE_OT_link(struct wmOperatorType *ot);
 void NODE_OT_link_make(struct wmOperatorType *ot);
diff --git a/source/blender/editors/space_node/node_relationships.c b/source/blender/editors/space_node/node_relationships.c
index 682174ebbed..e4c59bc9508 100644
--- a/source/blender/editors/space_node/node_relationships.c
+++ b/source/blender/editors/space_node/node_relationships.c
@@ -131,9 +131,8 @@ static bool node_group_has_output_dfs(bNode *node)
 	return false;
 }
 
-static bool node_group_has_output(bNode *node)
+static bool node_group_has_output(Main *bmain, bNode *node)
 {
-	Main *bmain = G.main;
 	BLI_assert(node->type == NODE_GROUP);
 	bNodeTree *ntree = (bNodeTree *)node->id;
 	if (ntree == NULL) {
@@ -143,7 +142,7 @@ static bool node_group_has_output(bNode *node)
 	return node_group_has_output_dfs(node);
 }
 
-bool node_connected_to_output(bNodeTree *ntree, bNode *node)
+bool node_connected_to_output(Main *bmain, bNodeTree *ntree, bNode *node)
 {
 	/* Special case for drivers: if node tree has any drivers we assume it is
 	 * always to be tagged for update when node changes. Otherwise we will be
@@ -170,7 +169,7 @@ bool node_connected_to_output(bNodeTree *ntree, bNode *node)
 				return true;
 			}
 			if (ntree_c

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list