[Bf-blender-cvs] [ba30d2d] depsgraph_refactor: Removed the add_to_graph virtual function from nodes.

Lukas Tönne noreply at git.blender.org
Sun Apr 13 10:41:52 CEST 2014


Commit: ba30d2d40ea921b1ddfcdcee28b393eeabfc3751
Author: Lukas Tönne
Date:   Sat Apr 12 17:01:25 2014 +0200
https://developer.blender.org/rBba30d2d40ea921b1ddfcdcee28b393eeabfc3751

Removed the add_to_graph virtual function from nodes.

All functionality implemented in these functions is now in the
respective owner node types when using one of the explicit `add` methods
such as id_node->add_component, comp_node->add_operation, etc.

There are a few loose ends here, in particular for subgraphs and time
source nodes, but these existed before and have to be looked at later.

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

M	source/blender/depsgraph/intern/depsgraph.cpp
M	source/blender/depsgraph/intern/depsgraph.h
M	source/blender/depsgraph/intern/depsgraph_build.cpp
M	source/blender/depsgraph/intern/depsgraph_build_nodes.cpp
M	source/blender/depsgraph/intern/depsnode.cpp
M	source/blender/depsgraph/intern/depsnode.h
M	source/blender/depsgraph/intern/depsnode_component.cpp
M	source/blender/depsgraph/intern/depsnode_component.h
M	source/blender/depsgraph/intern/depsnode_operation.cpp
M	source/blender/depsgraph/intern/depsnode_operation.h

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

diff --git a/source/blender/depsgraph/intern/depsgraph.cpp b/source/blender/depsgraph/intern/depsgraph.cpp
index ba3b051..604985a 100644
--- a/source/blender/depsgraph/intern/depsgraph.cpp
+++ b/source/blender/depsgraph/intern/depsgraph.cpp
@@ -113,12 +113,6 @@ DepsNode *Depsgraph::add_new_node(const ID *id, const string &subdata,
 	/* create node data... */
 	node = factory->create_node(id, subdata, name);
 	
-	/* add node to graph 
-	 * NOTE: additional nodes may be created in order to add this node to the graph
-	 *       (i.e. parent/owner nodes) where applicable...
-	 */
-	node->add_to_graph(this, id);
-	
 	/* add node to operation-node list if it plays a part in the evaluation process */
 	if (ELEM(node->tclass, DEPSNODE_CLASS_GENERIC, DEPSNODE_CLASS_OPERATION)) {
 		this->all_opnodes.push_back(node);
@@ -174,13 +168,42 @@ DepsNode *Depsgraph::find_node_from_pointer(const PointerRNA *ptr, const Propert
 
 /* Convenience Functions ---------------------------- */
 
+RootDepsNode *Depsgraph::add_root_node()
+{
+	if (!root_node) {
+		DepsNodeFactory *factory = DEG_get_node_factory(DEPSNODE_TYPE_ROOT);
+		root_node = (RootDepsNode *)factory->create_node(NULL, "", "Root (Scene)");
+	}
+	return root_node;
+}
+
+SubgraphDepsNode *Depsgraph::add_subgraph_node(const ID *id)
+{
+	DepsNodeFactory *factory = DEG_get_node_factory(DEPSNODE_TYPE_SUBGRAPH);
+	SubgraphDepsNode *subgraph_node = (SubgraphDepsNode *)factory->create_node(id, "", id->name+2);
+	
+	/* add to subnodes list */
+	this->subgraphs.insert(subgraph_node);
+	
+	/* if there's an ID associated, add to ID-nodes lookup too */
+	if (id) {
+#if 0 /* XXX subgraph node is NOT a true IDDepsNode - what is this supposed to do? */
+		// TODO: what to do if subgraph's ID has already been added?
+		BLI_assert(!graph->find_id_node(id));
+		graph->id_hash[id] = this;
+#endif
+	}
+	
+	return subgraph_node;
+}
+
 IDDepsNode *Depsgraph::find_id_node(const ID *id) const
 {
 	IDNodeMap::const_iterator it = this->id_hash.find(id);
 	return it != this->id_hash.end() ? it->second : NULL;
 }
 
-IDDepsNode *Depsgraph::get_id_node(const ID *id, const string &name)
+IDDepsNode *Depsgraph::add_id_node(const ID *id, const string &name)
 {
 	IDDepsNode *id_node = find_id_node(id);
 	if (!id_node) {
diff --git a/source/blender/depsgraph/intern/depsgraph.h b/source/blender/depsgraph/intern/depsgraph.h
index e98e558..ef7b170 100644
--- a/source/blender/depsgraph/intern/depsgraph.h
+++ b/source/blender/depsgraph/intern/depsgraph.h
@@ -50,6 +50,7 @@ struct PropertyRNA;
 
 struct DepsNode;
 struct RootDepsNode;
+struct TimeSourceDepsNode;
 struct IDDepsNode;
 struct SubgraphDepsNode;
 struct ComponentDepsNode;
@@ -140,8 +141,11 @@ struct Depsgraph {
 	DepsNode *add_new_node(const ID *id, const string &subdata,
 	                       eDepsNode_Type type, const string &name);
 	
+	RootDepsNode *add_root_node();
+	SubgraphDepsNode *add_subgraph_node(const ID *id);
+	
 	IDDepsNode *find_id_node(const ID *id) const;
-	IDDepsNode *get_id_node(const ID *id, const string &name = "");
+	IDDepsNode *add_id_node(const ID *id, const string &name = "");
 	void remove_id_node(const ID *id);
 	void clear_id_nodes();
 	
diff --git a/source/blender/depsgraph/intern/depsgraph_build.cpp b/source/blender/depsgraph/intern/depsgraph_build.cpp
index 8903104..386fe97 100644
--- a/source/blender/depsgraph/intern/depsgraph_build.cpp
+++ b/source/blender/depsgraph/intern/depsgraph_build.cpp
@@ -170,20 +170,16 @@ DepsgraphNodeBuilder::~DepsgraphNodeBuilder()
 
 RootDepsNode *DepsgraphNodeBuilder::add_root_node()
 {
-	RootDepsNode *root_node = (RootDepsNode *)m_graph->get_node(NULL, "", DEPSNODE_TYPE_ROOT, "Root (Scene)");
-	m_graph->root_node = root_node;
-	return root_node;
+	return m_graph->add_root_node();
 }
 
 IDDepsNode *DepsgraphNodeBuilder::add_id_node(IDPtr id)
 {
-	return m_graph->get_id_node(id);
+	return m_graph->add_id_node(id);
 }
 
 TimeSourceDepsNode *DepsgraphNodeBuilder::add_time_source(IDPtr id)
 {
-	TimeSourceDepsNode *time_source = (TimeSourceDepsNode *)m_graph->get_node(id, "", DEPSNODE_TYPE_TIMESOURCE, string_format("%s Time Source", id->name+2));
-
 	/* determine which node to attach timesource to */
 	if (id) {
 #if 0 /* XXX TODO */
@@ -215,16 +211,17 @@ TimeSourceDepsNode *DepsgraphNodeBuilder::add_time_source(IDPtr id)
 	else {
 		/* root-node */
 		RootDepsNode *root_node = m_graph->root_node;
-		root_node->time_source = time_source;
-		/*time_source->owner = root_node;*/
+		if (root_node) {
+			return root_node->add_time_source("Time Source");
+		}
 	}
 	
-	return time_source;
+	return NULL;
 }
 
 ComponentDepsNode *DepsgraphNodeBuilder::add_component_node(IDDepsNode *id_node, eDepsNode_Type comp_type, const string &subdata)
 {
-	ComponentDepsNode *comp_node = id_node->get_component(comp_type);
+	ComponentDepsNode *comp_node = id_node->add_component(comp_type);
 	comp_node->owner = id_node;
 	return comp_node;
 }
diff --git a/source/blender/depsgraph/intern/depsgraph_build_nodes.cpp b/source/blender/depsgraph/intern/depsgraph_build_nodes.cpp
index fb6c70e..f633da6 100644
--- a/source/blender/depsgraph/intern/depsgraph_build_nodes.cpp
+++ b/source/blender/depsgraph/intern/depsgraph_build_nodes.cpp
@@ -205,7 +205,7 @@ SubgraphDepsNode *DepsgraphNodeBuilder::build_subgraph(Group *group)
 	subgraph_builder.build_group(group);
 	
 	/* create a node for representing subgraph */
-	SubgraphDepsNode *subgraph_node = (SubgraphDepsNode *)m_graph->add_new_node(&group->id, "", DEPSNODE_TYPE_SUBGRAPH, group->id.name+2);
+	SubgraphDepsNode *subgraph_node = m_graph->add_subgraph_node(&group->id);
 	subgraph_node->graph = subgraph;
 	
 	/* make a copy of the data this node will need? */
diff --git a/source/blender/depsgraph/intern/depsnode.cpp b/source/blender/depsgraph/intern/depsnode.cpp
index 00fae83..dcbc1a7 100644
--- a/source/blender/depsgraph/intern/depsnode.cpp
+++ b/source/blender/depsgraph/intern/depsnode.cpp
@@ -83,13 +83,6 @@ DepsNode::~DepsNode()
 
 /* Root Node ============================================== */
 
-/* Add 'root' node to graph */
-void RootDepsNode::add_to_graph(Depsgraph *graph, const ID *UNUSED(id))
-{
-	BLI_assert(graph->root_node == NULL);
-	graph->root_node = this;
-}
-
 /* Remove 'root' node from graph */
 void RootDepsNode::remove_from_graph(Depsgraph *graph)
 {
@@ -97,49 +90,21 @@ void RootDepsNode::remove_from_graph(Depsgraph *graph)
 	graph->root_node = NULL;
 }
 
+TimeSourceDepsNode *RootDepsNode::add_time_source(const string &name)
+{
+	if (!time_source) {
+		DepsNodeFactory *factory = DEG_get_node_factory(DEPSNODE_TYPE_TIMESOURCE);
+		time_source = (TimeSourceDepsNode *)factory->create_node(NULL, "", name);
+		/*time_source->owner = this;*/ // XXX
+	}
+	return time_source;
+}
+
 DEG_DEPSNODE_DEFINE(RootDepsNode, DEPSNODE_TYPE_ROOT, "Root DepsNode");
 static DepsNodeFactoryImpl<RootDepsNode> DNTI_ROOT;
 
 /* Time Source Node ======================================= */
 
-///* Add 'time source' node to graph */
-void TimeSourceDepsNode::add_to_graph(Depsgraph *graph, const ID *id)
-{
-#if 0
-	/* determine which node to attach timesource to */
-	if (id) {
-		/* get ID node */
-//		DepsNode *id_node = graph->get_node(id, "", DEPSNODE_TYPE_ID_REF, "");
-		
-		/* depends on what this is... */
-		switch (GS(id->name)) {
-			case ID_SCE: /* Scene - Usually sequencer strip causing time remapping... */
-			{
-				// TODO...
-			}
-			break;
-			
-			case ID_GR: /* Group */
-			{
-				// TODO...
-			}
-			break;
-			
-			// XXX: time source...
-			
-			default:     /* Unhandled */
-				printf("%s(): Unhandled ID - %s \n", __func__, id->name);
-				break;
-		}
-	}
-	else {
-		/* root-node */
-		graph->root_node->time_source = this;
-		this->owner = graph->root_node;
-	}
-#endif
-}
-
 /* Remove 'time source' node from graph */
 void TimeSourceDepsNode::remove_from_graph(Depsgraph *graph)
 {
@@ -215,7 +180,7 @@ ComponentDepsNode *IDDepsNode::find_component(eDepsNode_Type type, const string
 	return it != components.end() ? it->second : NULL;
 }
 
-ComponentDepsNode *IDDepsNode::get_component(eDepsNode_Type type, const string &name)
+ComponentDepsNode *IDDepsNode::add_component(eDepsNode_Type type, const string &name)
 {
 	ComponentDepsNode *comp_node = find_component(type);
 	if (!comp_node) {
@@ -224,6 +189,7 @@ ComponentDepsNode *IDDepsNode::get_component(eDepsNode_Type type, const string &
 		
 		/* register */
 		this->components[type] = comp_node;
+		comp_node->owner = this;
 	}
 	return comp_node;
 }
@@ -248,13 +214,6 @@ void IDDepsNode::clear_components()
 	components.clear();
 }
 
-/* Add 'id' node to graph */
-void IDDepsNode::add_to_graph(Depsgraph *graph, const ID *id)
-{
-	/* add to hash so that it can be found */
-	graph->id_hash[id] = this;
-}
-
 /* Remove 'id' node from graph */
 void IDDepsNode::remove_from_graph(Depsgraph *graph)
 {
@@ -366,22 +325,6 @@ void SubgraphDepsNode::copy(DepsgraphCopyContext *dcc, const SubgraphDepsNode *s
 	/* for now, subgraph itself isn't copied... */
 }
 
-/* Add 'subgraph' node to graph */
-void SubgraphDepsNode::add_to_graph(Depsgraph *graph, const ID *id)
-{
-	/* add to subnodes list */
-	graph->subgraphs.insert(this);
-	
-	/* if there's an ID associated, add to ID-nodes lookup too */
-	if (id) {
-#if 0 /* XXX subgraph node is NOT a true IDDepsNode - what is this supposed to do? */
-		// TODO: what to do if subgraph's ID has already been added?
-		BLI_assert(!graph->find_id_node(id));
-		graph->id_hash[id] = this;
-#endif
-	}
-}
-
 /* Remove 'subgraph' node from graph */
 void SubgraphDepsNode::remove_from_graph(Depsgraph *graph)
 {
diff --git a/source/blender/depsgraph/intern/depsnode.h b/source/blender/depsgraph/intern/depsnode.h
index 225a0e0..56b8b32 100644
--- a/source/blender/depsgraph/intern/depsnode.h
+++ b/source/blender/depsgraph/intern/depsnode.h
@@ -106,10 +106,6 @@ public:
 	virtual void init(const ID *id, const string &subdata) {}
 	virtual void copy(DepsgraphCopyContext *dcc, const DepsNode *src) {}
 	
-	/* Add node to graph - Will add additional inbetween nodes as needed
-	 * < (id): ID-Block that node is associated with (if applicable)
-	 */
-	virtual void add_to_graph(Depsgraph *graph, const ID *id) = 0;
 	/* Remove node from graph - Only use 

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list