Depsgraph: Add extra name tag for operation nodes
authorSergey Sharybin <sergey.vfx@gmail.com>
Thu, 3 Nov 2016 13:31:27 +0000 (14:31 +0100)
committerSergey Sharybin <sergey.vfx@gmail.com>
Mon, 7 Nov 2016 10:04:49 +0000 (11:04 +0100)
The idea here is to address issue that name on it's own is not
always unique: for example, when adding driver operations the
name used for nodes is the RNA path (and multiple drivers can
write to different array indices of the path). Basically, now
it's possible to pass extra integer value to distinguish
operations in such cases.

So now we've already switched from sprintf() to construct unique
operation name to pass RNA path and array index.

There should be no functional changes yet, but this work is
required for further work about replacing string with const
char*.

source/blender/depsgraph/intern/builder/deg_builder_nodes.cc
source/blender/depsgraph/intern/builder/deg_builder_nodes.h
source/blender/depsgraph/intern/builder/deg_builder_relations.cc
source/blender/depsgraph/intern/builder/deg_builder_relations.h
source/blender/depsgraph/intern/nodes/deg_node_component.cc
source/blender/depsgraph/intern/nodes/deg_node_component.h

index ea319cbe8fdad0174e0fb163bf3b032e7558f262..63dd915b7f0a5b26c816208bdd8b39080e990cf4 100644 (file)
@@ -190,11 +190,14 @@ OperationDepsNode *DepsgraphNodeBuilder::add_operation_node(
         eDepsOperation_Type optype,
         DepsEvalOperationCb op,
         eDepsOperation_Code opcode,
-        const string &name)
+        const string &name,
+        int name_tag)
 {
-       OperationDepsNode *op_node = comp_node->has_operation(opcode, name);
+       OperationDepsNode *op_node = comp_node->has_operation(opcode,
+                                                             name,
+                                                             name_tag);
        if (op_node == NULL) {
-               op_node = comp_node->add_operation(optype, op, opcode, name);
+               op_node = comp_node->add_operation(optype, op, opcode, name, name_tag);
                m_graph->operations.push_back(op_node);
        }
        else {
@@ -215,10 +218,11 @@ OperationDepsNode *DepsgraphNodeBuilder::add_operation_node(
         eDepsOperation_Type optype,
         DepsEvalOperationCb op,
         eDepsOperation_Code opcode,
-        const string &name)
+        const string &name,
+        int name_tag)
 {
        ComponentDepsNode *comp_node = add_component_node(id, comp_type, comp_name);
-       return add_operation_node(comp_node, optype, op, opcode, name);
+       return add_operation_node(comp_node, optype, op, opcode, name, name_tag);
 }
 
 OperationDepsNode *DepsgraphNodeBuilder::add_operation_node(
@@ -227,22 +231,32 @@ OperationDepsNode *DepsgraphNodeBuilder::add_operation_node(
         eDepsOperation_Type optype,
         DepsEvalOperationCb op,
         eDepsOperation_Code opcode,
-        const string& name)
+        const string& name,
+        int name_tag)
 {
-       return add_operation_node(id, comp_type, "", optype, op, opcode, name);
+       return add_operation_node(id,
+                                 comp_type,
+                                 "",
+                                 optype,
+                                 op,
+                                 opcode,
+                                 name,
+                                 name_tag);
 }
 
 bool DepsgraphNodeBuilder::has_operation_node(ID *id,
                                               eDepsNode_Type comp_type,
                                               const char *comp_name,
                                               eDepsOperation_Code opcode,
-                                              const string &name)
+                                              const string &name,
+                                              int name_tag)
 {
        return find_operation_node(id,
                                   comp_type,
                                   comp_name,
                                   opcode,
-                                  name) != NULL;
+                                  name,
+                                  name_tag) != NULL;
 }
 
 OperationDepsNode *DepsgraphNodeBuilder::find_operation_node(
@@ -250,19 +264,21 @@ OperationDepsNode *DepsgraphNodeBuilder::find_operation_node(
         eDepsNode_Type comp_type,
         const char *comp_name,
         eDepsOperation_Code opcode,
-        const string &name)
+        const string &name,
+        int name_tag)
 {
        ComponentDepsNode *comp_node = add_component_node(id, comp_type, comp_name);
-       return comp_node->has_operation(opcode, name);
+       return comp_node->has_operation(opcode, name, name_tag);
 }
 
 OperationDepsNode *DepsgraphNodeBuilder::find_operation_node(
         ID *id,
         eDepsNode_Type comp_type,
         eDepsOperation_Code opcode,
-        const string& name)
+        const string& name,
+        int name_tag)
 {
-       return find_operation_node(id, comp_type, "", opcode, name);
+       return find_operation_node(id, comp_type, "", opcode, name, name_tag);
 }
 
 /* **** Build functions for entity nodes **** */
@@ -620,12 +636,17 @@ OperationDepsNode *DepsgraphNodeBuilder::build_driver(ID *id, FCurve *fcu)
        OperationDepsNode *driver_op = find_operation_node(id,
                                                           DEPSNODE_TYPE_PARAMETERS,
                                                           DEG_OPCODE_DRIVER,
-                                                          deg_fcurve_id_name(fcu));
+                                                          fcu->rna_path,
+                                                          fcu->array_index);
 
        if (driver_op == NULL) {
-               driver_op = add_operation_node(id, DEPSNODE_TYPE_PARAMETERS,
-                                              DEPSOP_TYPE_EXEC, function_bind(BKE_animsys_eval_driver, _1, id, fcu),
-                                              DEG_OPCODE_DRIVER, deg_fcurve_id_name(fcu));
+               driver_op = add_operation_node(id,
+                                              DEPSNODE_TYPE_PARAMETERS,
+                                              DEPSOP_TYPE_EXEC,
+                                              function_bind(BKE_animsys_eval_driver, _1, id, fcu),
+                                              DEG_OPCODE_DRIVER,
+                                              fcu->rna_path,
+                                              fcu->array_index);
        }
 
        /* tag "scripted expression" drivers as needing Python (due to GIL issues, etc.) */
index 539543cfde3fa3692b51adb17fcb4c454bd63215..e93dedc36d5a2fe9fbca4e97d8bbc7ba32df534b 100644 (file)
@@ -82,37 +82,43 @@ struct DepsgraphNodeBuilder {
                                              eDepsOperation_Type optype,
                                              DepsEvalOperationCb op,
                                              eDepsOperation_Code opcode,
-                                             const string& name = "");
+                                             const string& name = "",
+                                             int name_tag = -1);
        OperationDepsNode *add_operation_node(ID *id,
                                              eDepsNode_Type comp_type,
                                              const char *comp_name,
                                              eDepsOperation_Type optype,
                                              DepsEvalOperationCb op,
                                              eDepsOperation_Code opcode,
-                                             const string& name = "");
+                                             const string& name = "",
+                                             int name_tag = -1);
        OperationDepsNode *add_operation_node(ID *id,
                                              eDepsNode_Type comp_type,
                                              eDepsOperation_Type optype,
                                              DepsEvalOperationCb op,
                                              eDepsOperation_Code opcode,
-                                             const string& name = "");
+                                             const string& name = "",
+                                             int name_tag = -1);
 
        bool has_operation_node(ID *id,
                                eDepsNode_Type comp_type,
                                const char *comp_name,
                                eDepsOperation_Code opcode,
-                               const string& name = "");
+                               const string& name = "",
+                               int name_tag = -1);
 
        OperationDepsNode *find_operation_node(ID *id,
                                               eDepsNode_Type comp_type,
                                               const char *comp_name,
                                               eDepsOperation_Code opcode,
-                                              const string &name = "");
+                                              const string &name = "",
+                                              int name_tag = -1);
 
        OperationDepsNode *find_operation_node(ID *id,
                                               eDepsNode_Type comp_type,
                                               eDepsOperation_Code opcode,
-                                              const string &name = "");
+                                              const string &name = "",
+                                              int name_tag = -1);
 
        void build_scene(Main *bmain, Scene *scene);
        SubgraphDepsNode *build_subgraph(Group *group);
index 86e222075fe90b02b538a52717fa86ebe2c1c045..61275ff02f2f978c82dbc4b15a66f2b41d3963d5 100644 (file)
@@ -209,7 +209,9 @@ OperationDepsNode *DepsgraphRelationBuilder::find_node(
                return NULL;
        }
 
-       OperationDepsNode *op_node = comp_node->find_operation(key.opcode, key.name);
+       OperationDepsNode *op_node = comp_node->find_operation(key.opcode,
+                                                              key.name,
+                                                              key.name_tag);
        if (!op_node) {
                fprintf(stderr, "find_node_operation: Failed for (%s, '%s')\n",
                        DEG_OPNAMES[key.opcode], key.name.c_str());
@@ -234,7 +236,7 @@ OperationDepsNode *DepsgraphRelationBuilder::has_node(
        if (!comp_node) {
                return NULL;
        }
-       return comp_node->has_operation(key.opcode, key.name);
+       return comp_node->has_operation(key.opcode, key.name, key.name_tag);
 }
 
 void DepsgraphRelationBuilder::add_time_relation(TimeSourceDepsNode *timesrc,
@@ -835,7 +837,11 @@ void DepsgraphRelationBuilder::build_animdata(ID *id)
 
        /* drivers */
        for (FCurve *fcu = (FCurve *)adt->drivers.first; fcu; fcu = fcu->next) {
-               OperationKey driver_key(id, DEPSNODE_TYPE_PARAMETERS, DEG_OPCODE_DRIVER, deg_fcurve_id_name(fcu));
+               OperationKey driver_key(id,
+                                       DEPSNODE_TYPE_PARAMETERS,
+                                       DEG_OPCODE_DRIVER,
+                                       fcu->rna_path,
+                                       fcu->array_index);
 
                /* create the driver's relations to targets */
                build_driver(id, fcu);
@@ -877,11 +883,13 @@ void DepsgraphRelationBuilder::build_animdata(ID *id)
                                OperationKey prev_driver_key(id,
                                                             DEPSNODE_TYPE_PARAMETERS,
                                                             DEG_OPCODE_DRIVER,
-                                                            deg_fcurve_id_name(fcu_prev));
+                                                            fcu_prev->rna_path,
+                                                            fcu_prev->array_index);
                                OperationKey driver_key(id,
                                                        DEPSNODE_TYPE_PARAMETERS,
                                                        DEG_OPCODE_DRIVER,
-                                                       deg_fcurve_id_name(fcu));
+                                                       fcu->rna_path,
+                                                       fcu->array_index);
                                add_relation(prev_driver_key,
                                             driver_key,
                                             DEPSREL_TYPE_OPERATION,
@@ -900,7 +908,11 @@ void DepsgraphRelationBuilder::build_animdata(ID *id)
 void DepsgraphRelationBuilder::build_driver(ID *id, FCurve *fcu)
 {
        ChannelDriver *driver = fcu->driver;
-       OperationKey driver_key(id, DEPSNODE_TYPE_PARAMETERS, DEG_OPCODE_DRIVER, deg_fcurve_id_name(fcu));
+       OperationKey driver_key(id,
+                               DEPSNODE_TYPE_PARAMETERS,
+                               DEG_OPCODE_DRIVER,
+                               fcu->rna_path,
+                               fcu->array_index);
        bPoseChannel *pchan = NULL;
 
        /* create dependency between driver and data affected by it */
index d60499e9cbe3af492eb6a33776d8e5d7201095d9..ce9f36ca092c7d3716a73ea77d0b5f571a95a2cd 100644 (file)
@@ -125,29 +125,85 @@ struct ComponentKey
 
 struct OperationKey
 {
-       OperationKey() :
-           id(NULL), component_type(DEPSNODE_TYPE_UNDEFINED), component_name(""), opcode(DEG_OPCODE_OPERATION), name("")
+       OperationKey()
+               : id(NULL),
+                 component_type(DEPSNODE_TYPE_UNDEFINED),
+                 component_name(""),
+                 opcode(DEG_OPCODE_OPERATION),
+                 name(""),
+                 name_tag(-1)
        {}
 
-       OperationKey(ID *id, eDepsNode_Type component_type, const string &name) :
-           id(id), component_type(component_type), component_name(""), opcode(DEG_OPCODE_OPERATION), name(name)
+       OperationKey(ID *id,
+                    eDepsNode_Type component_type,
+                    const string &name,
+                    int name_tag = -1)
+               : id(id),
+                 component_type(component_type),
+                 component_name(""),
+                 opcode(DEG_OPCODE_OPERATION),
+                 name(name),
+                 name_tag(name_tag)
        {}
-       OperationKey(ID *id, eDepsNode_Type component_type, const string &component_name, const string &name) :
-           id(id), component_type(component_type), component_name(component_name), opcode(DEG_OPCODE_OPERATION), name(name)
+       OperationKey(ID *id,
+                    eDepsNode_Type component_type,
+                    const string &component_name,
+                    const string &name,
+                    int name_tag)
+               : id(id),
+                 component_type(component_type),
+                 component_name(component_name),
+                 opcode(DEG_OPCODE_OPERATION),
+                 name(name),
+                 name_tag(name_tag)
        {}
 
-       OperationKey(ID *id, eDepsNode_Type component_type, eDepsOperation_Code opcode) :
-           id(id), component_type(component_type), component_name(""), opcode(opcode), name("")
+       OperationKey(ID *id,
+                    eDepsNode_Type component_type,
+                    eDepsOperation_Code opcode)
+               : id(id),
+                 component_type(component_type),
+                 component_name(""),
+                 opcode(opcode),
+                 name(""),
+                 name_tag(-1)
        {}
-       OperationKey(ID *id, eDepsNode_Type component_type, const string &component_name, eDepsOperation_Code opcode) :
-           id(id), component_type(component_type), component_name(component_name), opcode(opcode), name("")
+       OperationKey(ID *id,
+                    eDepsNode_Type component_type,
+                    const string &component_name,
+                    eDepsOperation_Code opcode)
+               : id(id),
+                 component_type(component_type),
+                 component_name(component_name),
+                 opcode(opcode),
+                 name(""),
+                 name_tag(-1)
        {}
 
-       OperationKey(ID *id, eDepsNode_Type component_type, eDepsOperation_Code opcode, const string &name) :
-           id(id), component_type(component_type), component_name(""), opcode(opcode), name(name)
+       OperationKey(ID *id,
+                   eDepsNode_Type component_type,
+                   eDepsOperation_Code opcode,
+                   const string &name,
+                   int name_tag = -1)
+               : id(id),
+                 component_type(component_type),
+                 component_name(""),
+                 opcode(opcode),
+                 name(name),
+                 name_tag(name_tag)
        {}
-       OperationKey(ID *id, eDepsNode_Type component_type, const string &component_name, eDepsOperation_Code opcode, const string &name) :
-           id(id), component_type(component_type), component_name(component_name), opcode(opcode), name(name)
+       OperationKey(ID *id,
+                    eDepsNode_Type component_type,
+                    const string &component_name,
+                    eDepsOperation_Code opcode,
+                    const string &name,
+                    int name_tag = -1)
+               : id(id),
+                 component_type(component_type),
+                 component_name(component_name),
+                 opcode(opcode),
+                 name(name),
+                 name_tag(name_tag)
        {}
 
        string identifier() const
@@ -164,6 +220,7 @@ struct OperationKey
        string component_name;
        eDepsOperation_Code opcode;
        string name;
+       int name_tag;
 };
 
 struct RNAPathKey
index 1f32756da610aa834d4c3017057b0a02a8be46b9..4c88b38b6f0df66101f62c3a7d2ec6e15554968f 100644 (file)
@@ -138,9 +138,11 @@ OperationDepsNode *ComponentDepsNode::find_operation(OperationIDKey key) const
        }
 }
 
-OperationDepsNode *ComponentDepsNode::find_operation(eDepsOperation_Code opcode, const string &name) const
+OperationDepsNode *ComponentDepsNode::find_operation(eDepsOperation_Code opcode,
+                                                     const string &name,
+                                                     int name_tag) const
 {
-       OperationIDKey key(opcode, name);
+       OperationIDKey key(opcode, name, name_tag);
        return find_operation(key);
 }
 
@@ -150,21 +152,26 @@ OperationDepsNode *ComponentDepsNode::has_operation(OperationIDKey key) const
 }
 
 OperationDepsNode *ComponentDepsNode::has_operation(eDepsOperation_Code opcode,
-                                                    const string &name) const
+                                                    const string &name,
+                                                    int name_tag) const
 {
-       OperationIDKey key(opcode, name);
+       OperationIDKey key(opcode, name, name_tag);
        return has_operation(key);
 }
 
-OperationDepsNode *ComponentDepsNode::add_operation(eDepsOperation_Type optype, DepsEvalOperationCb op, eDepsOperation_Code opcode, const string &name)
+OperationDepsNode *ComponentDepsNode::add_operation(eDepsOperation_Type optype,
+                                                    DepsEvalOperationCb op,
+                                                    eDepsOperation_Code opcode,
+                                                    const string &name,
+                                                    int name_tag)
 {
-       OperationDepsNode *op_node = has_operation(opcode, name);
+       OperationDepsNode *op_node = has_operation(opcode, name, name_tag);
        if (!op_node) {
                DepsNodeFactory *factory = deg_get_node_factory(DEPSNODE_TYPE_OPERATION);
                op_node = (OperationDepsNode *)factory->create_node(this->owner->id, "", name);
 
                /* register opnode in this component's operation set */
-               OperationIDKey *key = OBJECT_GUARDED_NEW(OperationIDKey, opcode, name);
+               OperationIDKey *key = OBJECT_GUARDED_NEW(OperationIDKey, opcode, name, name_tag);
                BLI_ghash_insert(operations_map, key, op_node);
 
                /* set as entry/exit node of component (if appropriate) */
index 6c13c33dc16a2095d45148a12c5c0cc75c2c2c86..e0d425a2c14a0dd873fc108efc7dbeca2ed05f3b 100644 (file)
@@ -54,16 +54,24 @@ struct ComponentDepsNode : public DepsNode {
        {
                eDepsOperation_Code opcode;
                string name;
+               int name_tag;
 
-
-               OperationIDKey() :
-                       opcode(DEG_OPCODE_OPERATION), name("")
+               OperationIDKey()
+                       : opcode(DEG_OPCODE_OPERATION),
+                         name(""),
+                         name_tag(-1)
                {}
-               OperationIDKey(eDepsOperation_Code opcode) :
-                       opcode(opcode), name("")
+               OperationIDKey(eDepsOperation_Code opcode)
+                       : opcode(opcode),
+                         name(""),
+                         name_tag(-1)
                {}
-               OperationIDKey(eDepsOperation_Code opcode, const string &name) :
-                  opcode(opcode), name(name)
+               OperationIDKey(eDepsOperation_Code opcode,
+                              const string &name,
+                              int name_tag)
+                      : opcode(opcode),
+                        name(name),
+                        name_tag(name_tag)
                {}
 
                string identifier() const
@@ -76,7 +84,9 @@ struct ComponentDepsNode : public DepsNode {
 
                bool operator==(const OperationIDKey &other) const
                {
-                       return (opcode == other.opcode) && (name == other.name);
+                       return (opcode == other.opcode) &&
+                              (name == other.name) &&
+                              (name_tag == other.name_tag);
                }
        };
 
@@ -91,12 +101,14 @@ struct ComponentDepsNode : public DepsNode {
        /* Find an existing operation, will throw an assert() if it does not exist. */
        OperationDepsNode *find_operation(OperationIDKey key) const;
        OperationDepsNode *find_operation(eDepsOperation_Code opcode,
-                                         const string &name) const;
+                                         const string &name,
+                                         int name_tag) const;
 
        /* Check operation exists and return it. */
        OperationDepsNode *has_operation(OperationIDKey key) const;
        OperationDepsNode *has_operation(eDepsOperation_Code opcode,
-                                        const string &name) const;
+                                        const string &name,
+                                        int name_tag) const;
 
        /**
         * Create a new node for representing an operation and add this to graph
@@ -114,7 +126,8 @@ struct ComponentDepsNode : public DepsNode {
        OperationDepsNode *add_operation(eDepsOperation_Type optype,
                                         DepsEvalOperationCb op,
                                         eDepsOperation_Code opcode,
-                                        const string &name);
+                                        const string &name,
+                                        int name_tag);
 
        void clear_operations();