[Bf-blender-cvs] [2aa9f5e] depsgraph_refactor: Removed the bone_hash and associated methods from the pose component.

Lukas Tönne noreply at git.blender.org
Mon May 26 12:42:02 CEST 2014


Commit: 2aa9f5eaaec4d454e6baa5b2071ab91fa700c63f
Author: Lukas Tönne
Date:   Mon May 26 12:32:21 2014 +0200
https://developer.blender.org/rB2aa9f5eaaec4d454e6baa5b2071ab91fa700c63f

Removed the bone_hash and associated methods from the pose component.

Instead for storing bones in a separate hash table, which adds
complexity and ambiguity, they are now stored as regular components in
the ID node component map as well, with a string identifier to
distinguish them.

Looking up bones from the pose component by name can be done just as
well on the ID level, by using a combined key of
(DEPSNODE_TYPE_BONE, bone name)
This key extension (subdata) can be a general optional feature of
components, useful e.g. for modifiers, constraints, particle systems.
It saves us the work of implementing and maintaining individual hashes
for all these sub-component types and streamlines the API quite a bit.

Looping/filtering bones can work just as easily by looping over an ID
block's components instead of the bone hash table of the pose component.
The overhead is negligible, the number of other components in a single
ID block would not scale as much as the number of ID blocks in general.
Such loops would be an exception anyway.

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

M	source/blender/depsgraph/intern/depsgraph_debug.cpp
M	source/blender/depsgraph/intern/depsgraph_query.cpp
M	source/blender/depsgraph/intern/depsnode_component.cpp
M	source/blender/depsgraph/intern/depsnode_component.h

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

diff --git a/source/blender/depsgraph/intern/depsgraph_debug.cpp b/source/blender/depsgraph/intern/depsgraph_debug.cpp
index d1e18e6..9184e5b 100644
--- a/source/blender/depsgraph/intern/depsgraph_debug.cpp
+++ b/source/blender/depsgraph/intern/depsgraph_debug.cpp
@@ -448,7 +448,10 @@ static void deg_debug_graphviz_node(const DebugContext &ctx, const DepsNode *nod
 		case DEPSNODE_TYPE_TRANSFORM:
 		case DEPSNODE_TYPE_PROXY:
 		case DEPSNODE_TYPE_GEOMETRY:
-		case DEPSNODE_TYPE_SEQUENCER: {
+		case DEPSNODE_TYPE_SEQUENCER:
+		case DEPSNODE_TYPE_EVAL_POSE:
+		case DEPSNODE_TYPE_BONE:
+		{
 			ComponentDepsNode *comp_node = (ComponentDepsNode *)node;
 			if (!comp_node->operations.empty()) {
 				deg_debug_graphviz_node_cluster_begin(ctx, node);
@@ -464,22 +467,6 @@ static void deg_debug_graphviz_node(const DebugContext &ctx, const DepsNode *nod
 			break;
 		}
 		
-		case DEPSNODE_TYPE_EVAL_POSE: {
-			PoseComponentDepsNode *pose_node = (PoseComponentDepsNode *)node;
-			if (!pose_node->bone_hash.empty()) {
-				deg_debug_graphviz_node_cluster_begin(ctx, node);
-				for (PoseComponentDepsNode::BoneComponentMap::const_iterator it = pose_node->bone_hash.begin(); it != pose_node->bone_hash.end(); ++it) {
-					const DepsNode *bone_comp = it->second;
-					deg_debug_graphviz_node(ctx, bone_comp);
-				}
-				deg_debug_graphviz_node_cluster_end(ctx);
-			}
-			else {
-				deg_debug_graphviz_node_single(ctx, node);
-			}
-			break;
-		}
-		
 		default: {
 			deg_debug_graphviz_node_single(ctx, node);
 		}
@@ -504,16 +491,14 @@ static bool deg_debug_graphviz_is_cluster(const DepsNode *node)
 		case DEPSNODE_TYPE_TRANSFORM:
 		case DEPSNODE_TYPE_PROXY:
 		case DEPSNODE_TYPE_GEOMETRY:
-		case DEPSNODE_TYPE_SEQUENCER: {
+		case DEPSNODE_TYPE_SEQUENCER:
+		case DEPSNODE_TYPE_EVAL_POSE:
+		case DEPSNODE_TYPE_BONE:
+		{
 			ComponentDepsNode *comp_node = (ComponentDepsNode *)node;
 			return !comp_node->operations.empty();
 		}
 		
-		case DEPSNODE_TYPE_EVAL_POSE: {
-			PoseComponentDepsNode *pose_node = (PoseComponentDepsNode *)node;
-			return !pose_node->bone_hash.empty();
-		}
-		
 		default:
 			return false;
 	}
diff --git a/source/blender/depsgraph/intern/depsgraph_query.cpp b/source/blender/depsgraph/intern/depsgraph_query.cpp
index 5632a5a..234d9d9 100644
--- a/source/blender/depsgraph/intern/depsgraph_query.cpp
+++ b/source/blender/depsgraph/intern/depsgraph_query.cpp
@@ -236,31 +236,6 @@ static DepsNode *deg_find_inner_node(Depsgraph *graph, const ID *id, const strin
 	return NULL;
 }
 
-/* helper for finding bone component nodes by their names */
-static DepsNode *deg_find_bone_node(Depsgraph *graph, const ID *id, const string &subdata,
-                                    eDepsNode_Type type, const string &name)
-{
-	PoseComponentDepsNode *pose_comp;
-	
-	pose_comp = (PoseComponentDepsNode *)graph->find_node(id, "", DEPSNODE_TYPE_EVAL_POSE, "");
-	if (pose_comp)  {
-		/* lookup bone component with matching name */
-		BoneComponentDepsNode *bone_node = pose_comp->find_bone_component(subdata);
-		
-		if (type == DEPSNODE_TYPE_BONE) {
-			/* bone component is what we want */
-			return (DepsNode *)bone_node;
-		}
-		else if (type == DEPSNODE_TYPE_OP_BONE) {
-			/* now lookup relevant operation node */
-			return bone_node->find_operation(name);
-		}
-	}
-	
-	/* no match */
-	return NULL;
-}
-
 /* Find matching node */
 DepsNode *Depsgraph::find_node(const ID *id, const string &subdata, eDepsNode_Type type, const string &name)
 {
@@ -311,23 +286,17 @@ DepsNode *Depsgraph::find_node(const ID *id, const string &subdata, eDepsNode_Ty
 		case DEPSNODE_TYPE_GEOMETRY:
 		case DEPSNODE_TYPE_SEQUENCER:
 		case DEPSNODE_TYPE_EVAL_POSE:
+		case DEPSNODE_TYPE_BONE:
 		case DEPSNODE_TYPE_EVAL_PARTICLES:
 		{
 			/* Each ID-Node knows the set of components that are associated with it */
 			IDDepsNode *id_node = this->find_id_node(id);
 			
 			if (id_node) {
-				result = id_node->find_component(type);
+				result = id_node->find_component(type, subdata);
 			}
 		}
 			break;
-			
-		case DEPSNODE_TYPE_BONE:       /* Bone Component */
-		{
-			/* this will find the bone component */
-			result = deg_find_bone_node(this, id, subdata, type, name);
-		}
-			break;
 		
 		/* "Inner" Nodes ---------------------------- */
 		
@@ -361,7 +330,7 @@ DepsNode *Depsgraph::find_node(const ID *id, const string &subdata, eDepsNode_Ty
 			result = deg_find_inner_node(this, id, subdata, DEPSNODE_TYPE_EVAL_POSE, type, name);
 			break;
 		case DEPSNODE_TYPE_OP_BONE:       /* Bone */
-			result = deg_find_bone_node(this, id, subdata, type, name);
+			result = deg_find_inner_node(this, id, subdata, DEPSNODE_TYPE_BONE, type, name);
 			break;
 			
 		case DEPSNODE_TYPE_OP_PARTICLE:  /* Particle System/Step */
diff --git a/source/blender/depsgraph/intern/depsnode_component.cpp b/source/blender/depsgraph/intern/depsnode_component.cpp
index abb2a53..0466593 100644
--- a/source/blender/depsgraph/intern/depsnode_component.cpp
+++ b/source/blender/depsgraph/intern/depsnode_component.cpp
@@ -176,71 +176,6 @@ static DepsNodeFactoryImpl<SequencerComponentDepsNode> DNTI_SEQUENCER;
 
 /* Pose Component ========================================= */
 
-BoneComponentDepsNode *PoseComponentDepsNode::find_bone_component(const string &name) const
-{
-	BoneComponentMap::const_iterator it = this->bone_hash.find(name);
-	return it != this->bone_hash.end() ? it->second : NULL;
-}
-
-
-BoneComponentDepsNode *PoseComponentDepsNode::add_bone_component(const string &name)
-{
-	BoneComponentDepsNode *bone_node = find_bone_component(name);
-	if (!bone_node) {
-		DepsNodeFactory *factory = DEG_get_node_factory(DEPSNODE_TYPE_BONE);
-		bone_node = (BoneComponentDepsNode *)factory->create_node(this->owner->id, name, name);
-		
-		/* register */
-		this->bone_hash[name] = bone_node;
-		bone_node->owner = this->owner;
-		bone_node->pose_owner = this;
-	}
-	return bone_node;
-}
-
-void PoseComponentDepsNode::remove_bone_component(const string &name)
-{
-	BoneComponentDepsNode *bone_node = find_bone_component(name);
-	if (bone_node) {
-		/* unregister */
-		this->bone_hash.erase(name);
-		
-		delete bone_node;
-	}
-}
-
-void PoseComponentDepsNode::clear_bone_components()
-{
-	for (BoneComponentMap::const_iterator it = bone_hash.begin(); it != bone_hash.end(); ++it) {
-		BoneComponentDepsNode *bone_node = it->second;
-		delete bone_node;
-	}
-	bone_hash.clear();
-}
-
-/* Initialise 'pose eval' node - from pointer data given */
-void PoseComponentDepsNode::init(const ID *id, const string &subdata)
-{
-	/* generic component-node... */
-	ComponentDepsNode::init(id, subdata);
-}
-
-/* Copy 'pose eval' node */
-void PoseComponentDepsNode::copy(DepsgraphCopyContext *dcc, const PoseComponentDepsNode *src)
-{
-	/* generic component node... */
-	ComponentDepsNode::copy(dcc, src);
-	
-	/* pose-specific data... */
-	// copy bonehash...
-}
-
-/* Free 'pose eval' node */
-PoseComponentDepsNode::~PoseComponentDepsNode()
-{
-	clear_bone_components();
-}
-
 DEG_DEPSNODE_DEFINE(PoseComponentDepsNode, DEPSNODE_TYPE_EVAL_POSE, "Pose Eval Component");
 static DepsNodeFactoryImpl<PoseComponentDepsNode> DNTI_EVAL_POSE;
 
diff --git a/source/blender/depsgraph/intern/depsnode_component.h b/source/blender/depsgraph/intern/depsnode_component.h
index 52be789..593c0ac 100644
--- a/source/blender/depsgraph/intern/depsnode_component.h
+++ b/source/blender/depsgraph/intern/depsnode_component.h
@@ -119,21 +119,7 @@ struct SequencerComponentDepsNode : public ComponentDepsNode {
 	DEG_DEPSNODE_DECLARE;
 };
 
-/* Pose Evaluation - Sub-data needed */
 struct PoseComponentDepsNode : public ComponentDepsNode {
-	typedef unordered_map<string, BoneComponentDepsNode *> BoneComponentMap;
-	
-	BoneComponentDepsNode *find_bone_component(const string &name) const;
-	BoneComponentDepsNode *add_bone_component(const string &name);
-	void remove_bone_component(const string &name);
-	void clear_bone_components();
-	
-	void init(const ID *id, const string &subdata);
-	void copy(DepsgraphCopyContext *dcc, const PoseComponentDepsNode *src);
-	~PoseComponentDepsNode();
-	
-	BoneComponentMap bone_hash; /* hash for quickly finding bone components */
-	
 	DEG_DEPSNODE_DECLARE;
 };
 
@@ -141,7 +127,6 @@ struct PoseComponentDepsNode : public ComponentDepsNode {
 struct BoneComponentDepsNode : public ComponentDepsNode {
 	void init(const ID *id, const string &subdata);
 	
-	PoseComponentDepsNode *pose_owner;
 	struct bPoseChannel *pchan;     /* the bone that this component represents */
 	
 	DEG_DEPSNODE_DECLARE;




More information about the Bf-blender-cvs mailing list