[Bf-blender-cvs] [37166ac] depsgraph_refactor: First steps towards a 2-pass builder system.

Lukas Tönne noreply at git.blender.org
Mon Apr 7 18:29:59 CEST 2014


Commit: 37166ac2e81bda20ccca1d88af0911ec9df21ca8
Author: Lukas Tönne
Date:   Mon Apr 7 18:09:14 2014 +0200
https://developer.blender.org/rB37166ac2e81bda20ccca1d88af0911ec9df21ca8

First steps towards a 2-pass builder system.

Idea is to separate the construction of nodes from the declaration of
relations between them. This gives a cleaner structure and allows better
error handling.

Two "builder" classes define the API for each build pass. This way the
context variables (graph) can be accessed during building without having
to pass them explicitly to every function.

Specifying nodes in the relations pass works using keys rather than
direct node pointers. This way the builder can perform error handling
if one or both ends of the relation don't exist. Keys also don't require
all the details necessary for actual construction of nodes
(e.g. operation callback functions, description strings). This avoids
redundant or conflicting information in graph->get_node calls and
simplifies the code.

Old build code has been moved to a (not included) source file
depsgraph_build_deprecated.c to make porting more manageable.

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

M	source/blender/depsgraph/CMakeLists.txt
M	source/blender/depsgraph/intern/depsgraph.cpp
M	source/blender/depsgraph/intern/depsgraph.h
M	source/blender/depsgraph/intern/depsgraph_build.cpp
A	source/blender/depsgraph/intern/depsgraph_build.h
A	source/blender/depsgraph/intern/depsgraph_build_deprecated.cpp
M	source/blender/depsgraph/intern/depsgraph_types.h

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

diff --git a/source/blender/depsgraph/CMakeLists.txt b/source/blender/depsgraph/CMakeLists.txt
index 2fa624c..9124b7d 100644
--- a/source/blender/depsgraph/CMakeLists.txt
+++ b/source/blender/depsgraph/CMakeLists.txt
@@ -60,6 +60,7 @@ set(SRC
 	intern/depsnode.h
 	intern/depsnode_component.h
 	intern/depsnode_operation.h
+	intern/depsgraph_build.h
 	intern/depsgraph_eval.h
 	intern/depsgraph_intern.h
 	intern/depsgraph_queue.h
diff --git a/source/blender/depsgraph/intern/depsgraph.cpp b/source/blender/depsgraph/intern/depsgraph.cpp
index 7cf78e1..8b69208 100644
--- a/source/blender/depsgraph/intern/depsgraph.cpp
+++ b/source/blender/depsgraph/intern/depsgraph.cpp
@@ -241,7 +241,7 @@ IDDepsNode *Depsgraph::find_id_node(const ID *id) const
 	return it != this->id_hash.end() ? it->second : NULL;
 }
 
-IDDepsNode *Depsgraph::get_id_node(ID *id, const string &name)
+IDDepsNode *Depsgraph::get_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 e4f60d2..cdbf0b3 100644
--- a/source/blender/depsgraph/intern/depsgraph.h
+++ b/source/blender/depsgraph/intern/depsgraph.h
@@ -52,63 +52,13 @@ struct DepsNode;
 struct RootDepsNode;
 struct IDDepsNode;
 struct SubgraphDepsNode;
+struct ComponentDepsNode;
 struct OperationDepsNode;
 
 
 /* ************************************* */
 /* Relationships Between Nodes */
 
-/* Types of relationships between nodes 
- *
- * This is used to provide additional hints to use when filtering
- * the graph, so that we can go without doing more extensive
- * data-level checks...
- */
-typedef enum eDepsRelation_Type {
-	/* reationship type unknown/irrelevant */
-	DEPSREL_TYPE_STANDARD = 0,
-	
-	/* root -> active scene or entity (screen, image, etc.) */
-	DEPSREL_TYPE_ROOT_TO_ACTIVE,
-	
-	/* general datablock dependency */
-	DEPSREL_TYPE_DATABLOCK,
-	
-	/* time dependency */
-	DEPSREL_TYPE_TIME,
-	
-	/* component depends on results of another */
-	DEPSREL_TYPE_COMPONENT_ORDER,
-	
-	/* relationship is just used to enforce ordering of operations
-	 * (e.g. "init()" callback done before "exec() and "cleanup()")
-	 */
-	DEPSREL_TYPE_OPERATION,
-	
-	/* relationship results from a property driver affecting property */
-	DEPSREL_TYPE_DRIVER,
-	
-	/* relationship is something driver depends on */
-	DEPSREL_TYPE_DRIVER_TARGET,
-	
-	/* relationship is used for transform stack 
-	 * (e.g. parenting, user transforms, constraints)
-	 */
-	DEPSREL_TYPE_TRANSFORM,
-	
-	/* relationship is used for geometry evaluation 
-	 * (e.g. metaball "motherball" or modifiers)
-	 */
-	DEPSREL_TYPE_GEOMETRY_EVAL,
-	
-	/* relationship is used to trigger a post-change validity updates */
-	DEPSREL_TYPE_UPDATE,
-	
-	/* relationship is used to trigger editor/screen updates */
-	DEPSREL_TYPE_UPDATE_UI,
-} eDepsRelation_Type;
-
-
 /* Settings/Tags on Relationship */
 typedef enum eDepsRelation_Flag {
 	/* "touched" tag is used when filtering, to know which to collect */
@@ -219,10 +169,17 @@ struct Depsgraph {
 	                                 DepsEvalOperationCb op, const string &name);
 	
 	IDDepsNode *find_id_node(const ID *id) const;
-	IDDepsNode *get_id_node(ID *id, const string &name = "");
+	IDDepsNode *get_id_node(const ID *id, const string &name = "");
 	void remove_id_node(const ID *id);
 	void clear_id_nodes();
 	
+	ComponentDepsNode *find_component_node(const ID *id, eDepsNode_Type type, const string &subdata = "");
+	OperationDepsNode *find_operation_node(const ID *id, const string &subdata, eDepsNode_Type type);
+	OperationDepsNode *find_operation_node(const ID *id, eDepsNode_Type type)
+	{
+		return find_operation_node(id, "", type);
+	}
+	
 	/* Remove node from graph, but don't free any of its data */
 	void remove_node(DepsNode *node);
 	
diff --git a/source/blender/depsgraph/intern/depsgraph_build.cpp b/source/blender/depsgraph/intern/depsgraph_build.cpp
index 9d63be8..96d1447 100644
--- a/source/blender/depsgraph/intern/depsgraph_build.cpp
+++ b/source/blender/depsgraph/intern/depsgraph_build.cpp
@@ -92,6 +92,7 @@ extern "C" {
 #include "depsnode_component.h"
 #include "depsnode_operation.h"
 #include "depsgraph_types.h"
+#include "depsgraph_build.h"
 #include "depsgraph_eval.h"
 #include "depsgraph_intern.h"
 
@@ -154,1273 +155,159 @@ void DEG_add_object_relation(DepsNodeHandle *handle, struct Object *ob, eDepsObj
 }
 
 /* ************************************************* */
-/* AnimData */
+/* Node Builder */
 
-/* Build graph node(s) for Driver
- * < id: ID-Block that driver is attached to
- * < fcu: Driver-FCurve
- */
-static DepsNode *deg_build_driver_rel(Depsgraph *graph, ID *id, FCurve *fcu)
+static bool is_id_tagged(ConstIDPtr id)
 {
-	ChannelDriver *driver = fcu->driver;
-	DriverVar *dvar;
-	
-	OperationDepsNode *driver_op = NULL;
-	DepsNode *driver_node = NULL; /* same as driver_op, just cast to the relevant type */
-	DepsNode *affected_node = NULL;
-	
-	
-	/* create data node for this driver ..................................... */
-	string name = string_format("Driver @ %p", driver);
-	
-	driver_op = graph->add_operation(id, NULL, DEPSNODE_TYPE_OP_DRIVER,
-	                                 DEPSOP_TYPE_EXEC, BKE_animsys_eval_driver,
-	                                 name);
-	driver_node = (DepsNode *)driver_op;
-	
-	/* RNA pointer to driver, to provide as context for execution */
-	RNA_pointer_create(id, &RNA_FCurve, fcu, &driver_op->ptr);
-	
-	/* tag "scripted expression" drivers as needing Python (due to GIL issues, etc.) */
-	if (driver->type == DRIVER_TYPE_PYTHON) {
-		driver_node->flag |= DEPSOP_FLAG_USES_PYTHON;
-	}
-	
-	/* create dependency between driver and data affected by it */
-	// XXX: this should return a parameter context for dealing with this...
-	affected_node = graph->get_node_from_rna_path(id, fcu->rna_path);
-	if (affected_node) {
-		/* make data dependent on driver */
-		graph->add_new_relation(driver_node, affected_node, DEPSREL_TYPE_DRIVER, 
-		                     "[Driver -> Data] DepsRel");
-		
-		/* ensure that affected prop's update callbacks will be triggered once done */
-		// TODO: implement this once the functionality to add these links exists in RNA
-		// XXX: the data itself could also set this, if it were to be truly initialised later?
-	}
-	
-	/* loop over variables to get the target relationships */
-	for (dvar = (DriverVar *)driver->variables.first; dvar; dvar = dvar->next) {
-		/* only used targets */
-		DRIVER_TARGETS_USED_LOOPER(dvar) 
-		{
-			if (dtar->id) {
-				DepsNode *target_node = NULL;
-				
-				/* special handling for directly-named bones... */
-				if ((dtar->flag & DTAR_FLAG_STRUCT_REF) && (dtar->pchan_name[0])) {
-					Object *ob = (Object *)dtar->id;
-					bPoseChannel *pchan = BKE_pose_channel_find_name(ob->pose, dtar->pchan_name);
-					
-					/* get node associated with bone */
-					target_node = graph->get_node(dtar->id, pchan->name, DEPSNODE_TYPE_BONE, NULL);
-				}
-				else {
-					/* resolve path to get node... */
-					target_node = graph->get_node_from_rna_path(dtar->id, dtar->rna_path);
-				}
-				
-				/* make driver dependent on this node */
-				graph->add_new_relation(target_node, driver_node, DEPSREL_TYPE_DRIVER_TARGET,
-				                     "[Target -> Driver] DepsRel");
-			}
-		}
-		DRIVER_TARGETS_LOOPER_END
-	}
-	
-	/* return driver node created */
-	return driver_node;
-}
-
-/* Build graph nodes for AnimData block 
- * < scene_node: Scene that ID-block this lives on belongs to
- * < id: ID-Block which hosts the AnimData
- */
-static void deg_build_animdata_graph(Depsgraph *graph, Scene *scene, ID *id)
-{
-	AnimData *adt = BKE_animdata_from_id(id);
-	DepsNode *adt_node = NULL;
-	FCurve *fcu;
-	
-	if (adt == NULL)
-		return;
-	
-	/* animation */
-	if (adt->action || adt->nla_tracks.first) {
-		DepsNode *time_src;
-		
-		/* create "animation" data node for this block */
-		adt_node = graph->get_node(id, NULL, DEPSNODE_TYPE_ANIMATION, "Animation");
-		
-		/* wire up dependency to time source */
-		// NOTE: this assumes that timesource was already added as one of first steps!
-		time_src = graph->find_node(NULL, NULL, DEPSNODE_TYPE_TIMESOURCE, NULL);
-		graph->add_new_relation(time_src, adt_node, DEPSREL_TYPE_TIME, 
-		                     "[TimeSrc -> Animation] DepsRel");
-		                     
-		// XXX: Hook up specific update callbacks for special properties which may need it...
-	}
-	
-	/* drivers */
-	for (fcu = (FCurve *)adt->drivers.first; fcu; fcu = fcu->next) {
-		/* create driver */
-		DepsNode *driver_node = deg_build_driver_rel(graph, id, fcu);
-		
-		/* hook up update callback associated with F-Curve */
-		// ...
-		
-		/* prevent driver from occurring before own animation... */
-		// NOTE: probably not strictly needed (anim before parameters anyway)...
-		if (adt_node) {
-			graph->add_new_relation(adt_node, driver_node, DEPSREL_TYPE_OPERATION, 
-			                     "[AnimData Before Drivers] DepsRel");
-		}
-	}
+	return id->flag & LIB_DOIT;
 }
 
-
-/* ************************************************* */
-/* Rigs */
-
-/* Constraints - Objects or Bones 
- * < container: (ComponentDepsNode) component that constraint nodes will operate within
- *               Typically this will either be Transform or Bone components.
- */
-static void deg_build_constraints_graph(Depsgraph *graph, Scene *scene, 
-                                        Object *ob, bPoseChannel *pchan,
-                                        ListBase *constraints, 
-                                        DepsNode *container)
+static void id_tag_set(IDPtr id)
 {
-	OperationDepsNode *constraintStackOp;
-	DepsNode *constraintStackNode;
-	eDepsNode_Type stackNodeType;
-	string subdata_name;
-	
-	bConstraint *con;
-	
-	
-	/* == Constraints Graph Notes ==
-	 * For constraints, we currently only add a operation node to the Transform
-	 * or Bone components (depending on whichever type of owner we have).
-	 * This represents the entire constraints stack, which is for now just
-	 * executed as a single monolithic block. At least initially, this should
-	 * be sufficient for ensuring that the porting/refactoring proce

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list