[Bf-blender-cvs] [31782f7] depsgraph_refactor: Extended keys for components, using an optional name string.

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


Commit: 31782f73f0b160782ce0feae31e33037925f01d9
Author: Lukas Tönne
Date:   Mon May 26 11:50:17 2014 +0200
https://developer.blender.org/rB31782f73f0b160782ce0feae31e33037925f01d9

Extended keys for components, using an optional name string.

This will replace the current sub-component hashes for bones (and later
could be used for modifiers, constraints, particle systems etc.).

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

M	source/blender/depsgraph/intern/depsgraph_build.cpp
M	source/blender/depsgraph/intern/depsgraph_build.h
M	source/blender/depsgraph/intern/depsnode.cpp
M	source/blender/depsgraph/intern/depsnode.h

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

diff --git a/source/blender/depsgraph/intern/depsgraph_build.cpp b/source/blender/depsgraph/intern/depsgraph_build.cpp
index 33d7769..bc1f7bc 100644
--- a/source/blender/depsgraph/intern/depsgraph_build.cpp
+++ b/source/blender/depsgraph/intern/depsgraph_build.cpp
@@ -209,9 +209,9 @@ TimeSourceDepsNode *DepsgraphNodeBuilder::add_time_source(IDPtr id)
 	return NULL;
 }
 
-ComponentDepsNode *DepsgraphNodeBuilder::add_component_node(IDDepsNode *id_node, eDepsNode_Type comp_type, const string &subdata)
+ComponentDepsNode *DepsgraphNodeBuilder::add_component_node(IDDepsNode *id_node, eDepsNode_Type comp_type, const string &comp_name)
 {
-	ComponentDepsNode *comp_node = id_node->add_component(comp_type);
+	ComponentDepsNode *comp_node = id_node->add_component(comp_type, comp_name);
 	comp_node->owner = id_node;
 	return comp_node;
 }
@@ -351,7 +351,7 @@ ComponentDepsNode *DepsgraphRelationBuilder::find_node(const ComponentKey &key)
 	if (!id_node)
 		return NULL;
 	
-	ComponentDepsNode *node = id_node->find_component(key.type);
+	ComponentDepsNode *node = id_node->find_component(key.type, key.name);
 	return node;
 }
 
@@ -362,7 +362,7 @@ OperationDepsNode *DepsgraphRelationBuilder::find_node(const OperationKey &key)
 		return NULL;
 	
 	DepsNodeFactory *factory = DEG_get_node_factory(key.type);
-	ComponentDepsNode *comp_node = id_node->find_component(factory->component_type());
+	ComponentDepsNode *comp_node = id_node->find_component(factory->component_type(), key.component_name);
 	if (!comp_node)
 		return NULL;
 	
diff --git a/source/blender/depsgraph/intern/depsgraph_build.h b/source/blender/depsgraph/intern/depsgraph_build.h
index 423bd6a..f586001 100644
--- a/source/blender/depsgraph/intern/depsgraph_build.h
+++ b/source/blender/depsgraph/intern/depsgraph_build.h
@@ -66,7 +66,7 @@ struct DepsgraphNodeBuilder {
 	RootDepsNode *add_root_node();
 	IDDepsNode *add_id_node(IDPtr id);
 	TimeSourceDepsNode *add_time_source(IDPtr id);
-	ComponentDepsNode *add_component_node(IDDepsNode *id_node, eDepsNode_Type comp_type, const string &subdata = "");
+	ComponentDepsNode *add_component_node(IDDepsNode *id_node, eDepsNode_Type comp_type, const string &comp_name = "");
 	OperationDepsNode *add_operation_node(ComponentDepsNode *comp_node, eDepsNode_Type type,
 	                                      eDepsOperation_Type optype, DepsEvalOperationCb op, const string &description,
 	                                      PointerRNA ptr);
@@ -123,26 +123,26 @@ struct TimeSourceKey
 
 struct ComponentKey
 {
-	ComponentKey() : id(NULL), type(DEPSNODE_TYPE_UNDEFINED), subdata("") {}
-	ComponentKey(IDPtr id, eDepsNode_Type type, const string &subdata = "") : id(id), type(type), subdata(subdata) {}
+	ComponentKey() : id(NULL), type(DEPSNODE_TYPE_UNDEFINED), name("") {}
+	ComponentKey(IDPtr id, eDepsNode_Type type, const string &name = "") : id(id), type(type), name(name) {}
 	
 	IDPtr id;
 	eDepsNode_Type type;
-	string subdata;
+	string name;
 };
 
 struct OperationKey
 {
-	OperationKey() : id(NULL), component_subdata(""), type(DEPSNODE_TYPE_UNDEFINED), name("") {}
+	OperationKey() : id(NULL), component_name(""), type(DEPSNODE_TYPE_UNDEFINED), name("") {}
 	OperationKey(IDPtr id, eDepsNode_Type type, const string &name) :
-	    id(id), component_subdata(""), type(type), name(name)
+	    id(id), component_name(""), type(type), name(name)
 	{}
-	OperationKey(IDPtr id, const string &component_subdata, eDepsNode_Type type, const string &name) :
-	    id(id), component_subdata(component_subdata), type(type), name(name)
+	OperationKey(IDPtr id, const string &component_name, eDepsNode_Type type, const string &name) :
+	    id(id), component_name(component_name), type(type), name(name)
 	{}
 	
 	IDPtr id;
-	string component_subdata;
+	string component_name;
 	eDepsNode_Type type;
 	string name;
 };
diff --git a/source/blender/depsgraph/intern/depsnode.cpp b/source/blender/depsgraph/intern/depsnode.cpp
index b95a697..ff872cd 100644
--- a/source/blender/depsgraph/intern/depsnode.cpp
+++ b/source/blender/depsgraph/intern/depsnode.cpp
@@ -115,46 +115,48 @@ void IDDepsNode::copy(DepsgraphCopyContext *dcc, const IDDepsNode *src)
 	/* iterate over items in original hash, adding them to new hash */
 	for (IDDepsNode::ComponentMap::const_iterator it = this->components.begin(); it != this->components.end(); ++it) {
 		/* get current <type : component> mapping */
-		eDepsNode_Type c_type   = it->first;
+		ComponentKey c_key      = it->first;
 		DepsNode *old_component = it->second;
 		
 		/* make a copy of component */
 		ComponentDepsNode *component     = (ComponentDepsNode *)DEG_copy_node(dcc, old_component);
 		
 		/* add new node to hash... */
-		this->components[c_type] = component;
+		this->components[c_key] = component;
 	}
 	
 	// TODO: perform a second loop to fix up links?
 }
 
-ComponentDepsNode *IDDepsNode::find_component(eDepsNode_Type type, const string &subdata) const
+ComponentDepsNode *IDDepsNode::find_component(eDepsNode_Type type, const string &name) const
 {
-	#pragma message("DEPSGRAPH PORTING XXX: subdata has to be handled here somehow!")
-	ComponentMap::const_iterator it = components.find(type);
+	ComponentKey key(type, name);
+	ComponentMap::const_iterator it = components.find(key);
 	return it != components.end() ? it->second : NULL;
 }
 
 ComponentDepsNode *IDDepsNode::add_component(eDepsNode_Type type, const string &name)
 {
-	ComponentDepsNode *comp_node = find_component(type);
+	ComponentKey key(type, name);
+	ComponentDepsNode *comp_node = find_component(type, name);
 	if (!comp_node) {
 		DepsNodeFactory *factory = DEG_get_node_factory(type);
 		comp_node = (ComponentDepsNode *)factory->create_node(this->id, "", name);
 		
 		/* register */
-		this->components[type] = comp_node;
+		this->components[key] = comp_node;
 		comp_node->owner = this;
 	}
 	return comp_node;
 }
 
-void IDDepsNode::remove_component(eDepsNode_Type type)
+void IDDepsNode::remove_component(eDepsNode_Type type, const string &name)
 {
-	ComponentDepsNode *comp_node = find_component(type);
+	ComponentKey key(type, name);
+	ComponentDepsNode *comp_node = find_component(type, name);
 	if (comp_node) {
 		/* unregister */
-		this->components.erase(type);
+		this->components.erase(key);
 		
 		delete comp_node;
 	}
diff --git a/source/blender/depsgraph/intern/depsnode.h b/source/blender/depsgraph/intern/depsnode.h
index 58794bf..e907fbb 100644
--- a/source/blender/depsgraph/intern/depsnode.h
+++ b/source/blender/depsgraph/intern/depsnode.h
@@ -31,6 +31,7 @@
 
 #include "depsgraph_types.h"
 
+#include "depsgraph_util_hash.h"
 #include "depsgraph_util_map.h"
 #include "depsgraph_util_set.h"
 #include "depsgraph_util_string.h"
@@ -110,15 +111,37 @@ struct RootDepsNode : public DepsNode {
 
 /* ID-Block Reference */
 struct IDDepsNode : public DepsNode {
-	typedef unordered_map<eDepsNode_Type, ComponentDepsNode *, hash<int> > ComponentMap;
+	struct ComponentKey {
+		ComponentKey(eDepsNode_Type type_, const string &name_ = "") : type(type_), name(name_) {}
+		
+		bool operator== (const ComponentKey &other) const
+		{
+			return type == other.type && name == other.name;
+		}
+		
+		eDepsNode_Type type;
+		string name;
+	};
+	
+	/* XXX can't specialize std::hash for this purpose, because ComponentKey is a nested type ...
+	 * http://stackoverflow.com/a/951245
+	 */
+	struct component_key_hash {
+		bool operator() (const ComponentKey &key) const
+		{
+			return hash_combine(hash<int>()(key.type), hash<string>()(key.name));
+		}
+	};
+	
+	typedef unordered_map<ComponentKey, ComponentDepsNode *, component_key_hash> ComponentMap;
 	
 	void init(const ID *id, const string &subdata);
 	void copy(DepsgraphCopyContext *dcc, const IDDepsNode *src);
 	~IDDepsNode();
 	
-	ComponentDepsNode *find_component(eDepsNode_Type type, const string &subdata = "") const;
+	ComponentDepsNode *find_component(eDepsNode_Type type, const string &name = "") const;
 	ComponentDepsNode *add_component(eDepsNode_Type type, const string &name = "");
-	void remove_component(eDepsNode_Type type);
+	void remove_component(eDepsNode_Type type, const string &name = "");
 	void clear_components();
 	
 	void tag_update(Depsgraph *graph);




More information about the Bf-blender-cvs mailing list