[Bf-blender-cvs] [6cf99a07] depsgraph_refactor: Operations are now stored in the Component under a composite key (opcode + name)
Joshua Leung
noreply at git.blender.org
Wed Dec 17 04:41:11 CET 2014
Commit: 6cf99a0740db61bdf7faec148414f7d16e926650
Author: Joshua Leung
Date: Tue Dec 16 02:36:44 2014 +1300
Branches: depsgraph_refactor
https://developer.blender.org/rB6cf99a0740db61bdf7faec148414f7d16e926650
Operations are now stored in the Component under a composite key (opcode + name)
The code is adapted from what is used for handling components for ID nodes
===================================================================
M source/blender/depsgraph/intern/depsnode_component.cpp
M source/blender/depsgraph/intern/depsnode_component.h
===================================================================
diff --git a/source/blender/depsgraph/intern/depsnode_component.cpp b/source/blender/depsgraph/intern/depsnode_component.cpp
index 59306f8..404ef2d 100644
--- a/source/blender/depsgraph/intern/depsnode_component.cpp
+++ b/source/blender/depsgraph/intern/depsnode_component.cpp
@@ -59,6 +59,7 @@ void ComponentDepsNode::init(const ID *id, const string &subdata)
/* Copy 'component' node */
void ComponentDepsNode::copy(DepsgraphCopyContext *dcc, const ComponentDepsNode *src)
{
+#if 0 // XXX: remove all this
/* duplicate list of operation nodes */
this->operations.clear();
@@ -77,6 +78,7 @@ void ComponentDepsNode::copy(DepsgraphCopyContext *dcc, const ComponentDepsNode
/* copy evaluation contexts */
//
+#endif
}
/* Free 'component' node */
@@ -87,9 +89,10 @@ ComponentDepsNode::~ComponentDepsNode()
OperationDepsNode *ComponentDepsNode::find_operation(eDepsOperation_Code opcode, const string &name) const
{
- // FIXME: how to perform this lookup?
- OperationMap::const_iterator it = this->operations.find(name);
- return it != this->operations.end() ? it->second : NULL;
+ OperationIDKey key(opcode, name);
+ OperationMap::const_iterator it = this->operations.find(key);
+
+ return (it != this->operations.end()) ? it->second : NULL;
}
OperationDepsNode *ComponentDepsNode::add_operation(eDepsOperation_Type optype, DepsEvalOperationCb op, eDepsOperation_Code opcode, const string &name)
@@ -100,7 +103,7 @@ OperationDepsNode *ComponentDepsNode::add_operation(eDepsOperation_Type optype,
op_node = (OperationDepsNode *)factory->create_node(this->owner->id, "", name);
/* register */
- this->operations[name] = op_node;
+ this->operations[OperationIDKey(opcode, name)] = op_node;
op_node->owner = this;
}
@@ -113,12 +116,12 @@ OperationDepsNode *ComponentDepsNode::add_operation(eDepsOperation_Type optype,
return op_node;
}
-void ComponentDepsNode::remove_operation(const string &name)
+void ComponentDepsNode::remove_operation(eDepsOperation_Code opcode, const string &name)
{
- OperationDepsNode *op_node = find_operation(name);
+ OperationDepsNode *op_node = find_operation(opcode, name);
if (op_node) {
/* unregister */
- this->operations.erase(name);
+ this->operations.erase(OperationIDKey(opcode, name));
OBJECT_GUARDED_DELETE(op_node, OperationDepsNode);
}
}
diff --git a/source/blender/depsgraph/intern/depsnode_component.h b/source/blender/depsgraph/intern/depsnode_component.h
index 0d5403f..9601b18 100644
--- a/source/blender/depsgraph/intern/depsnode_component.h
+++ b/source/blender/depsgraph/intern/depsnode_component.h
@@ -33,6 +33,7 @@
#include "depsnode.h"
#include "depsnode_operation.h"
+#include "depsgraph_util_hash.h"
#include "depsgraph_util_map.h"
#include "depsgraph_util_set.h"
@@ -45,9 +46,46 @@ struct EvaluationContext;
struct OperationDepsNode;
struct BoneComponentDepsNode;
+
/* ID Component - Base type for all components */
struct ComponentDepsNode : public DepsNode {
- typedef unordered_map<string, OperationDepsNode *> OperationMap;
+ /* Key used to look up operations within a component */
+ struct OperationIDKey
+ {
+ eDepsOperation_Code opcode;
+ string name;
+
+
+ OperationIDKey() :
+ opcode(DEG_OPCODE_OPERATION), name("")
+ {}
+ OperationIDKey(eDepsOperation_Code opcode) :
+ opcode(opcode), name("")
+ {}
+ OperationIDKey(eDepsOperation_Code opcode, const string &name) :
+ opcode(opcode), name(name)
+ {}
+
+
+ bool operator==(const OperationIDKey &other) const
+ {
+ return (opcode == other.opcode) && (name == other.name);
+ }
+ };
+
+ /* XXX can't specialize std::hash for this purpose, because ComponentKey is a nested type ...
+ * http://stackoverflow.com/a/951245
+ */
+ struct operation_key_hash {
+ bool operator() (const OperationIDKey &key) const
+ {
+ return hash_combine(hash<int>()(key.opcode), hash<string>()(key.name));
+ }
+ };
+
+ /* Typedef for container of operations */
+ typedef unordered_map<OperationIDKey, OperationDepsNode *, operation_key_hash> OperationMap;
+
ComponentDepsNode();
@@ -68,7 +106,7 @@ struct ComponentDepsNode : public DepsNode {
*/
OperationDepsNode *add_operation(eDepsOperation_Type optype, DepsEvalOperationCb op, eDepsOperation_Code opcode, const string &name);
- void remove_operation(const string &name);
+ void remove_operation(eDepsOperation_Code opcode, const string &name);
void clear_operations();
void tag_update(Depsgraph *graph);
More information about the Bf-blender-cvs
mailing list