Depsgraph: Cleanup, make it easier to create relations with flags
authorSergey Sharybin <sergey.vfx@gmail.com>
Thu, 22 Nov 2018 13:54:08 +0000 (14:54 +0100)
committerSergey Sharybin <sergey.vfx@gmail.com>
Thu, 22 Nov 2018 15:17:18 +0000 (16:17 +0100)
source/blender/depsgraph/intern/builder/deg_builder_relations.cc
source/blender/depsgraph/intern/builder/deg_builder_relations.h
source/blender/depsgraph/intern/builder/deg_builder_relations_impl.h
source/blender/depsgraph/intern/builder/deg_builder_relations_rig.cc
source/blender/depsgraph/intern/depsgraph.cc
source/blender/depsgraph/intern/depsgraph.h

index ab4acef6668337bc81d3399df7b139b2673fb882..8f579216518c60e51965f46c8d839324656ad348 100644 (file)
@@ -304,10 +304,12 @@ DepsRelation *DepsgraphRelationBuilder::add_time_relation(
         TimeSourceDepsNode *timesrc,
         DepsNode *node_to,
         const char *description,
-        bool check_unique)
+        bool check_unique,
+        int flags)
 {
        if (timesrc && node_to) {
-               return graph_->add_new_relation(timesrc, node_to, description, check_unique);
+               return graph_->add_new_relation(
+                       timesrc, node_to, description, check_unique, flags);
        }
        else {
                DEG_DEBUG_PRINTF((::Depsgraph *)graph_,
@@ -323,13 +325,15 @@ DepsRelation *DepsgraphRelationBuilder::add_operation_relation(
         OperationDepsNode *node_from,
         OperationDepsNode *node_to,
         const char *description,
-        bool check_unique)
+        bool check_unique,
+        int flags)
 {
        if (node_from && node_to) {
                return graph_->add_new_relation(node_from,
                                                node_to,
                                                description,
-                                               check_unique);
+                                               check_unique,
+                                               flags);
        }
        else {
                DEG_DEBUG_PRINTF((::Depsgraph *)graph_,
@@ -2499,10 +2503,10 @@ void DepsgraphRelationBuilder::build_copy_on_write_relations(IDDepsNode *id_node
                                OperationKey data_copy_on_write_key(object_data_id,
                                                                    DEG_NODE_TYPE_COPY_ON_WRITE,
                                                                    DEG_OPCODE_COPY_ON_WRITE);
-                               DepsRelation *rel = add_relation(data_copy_on_write_key,
-                                                                copy_on_write_key,
-                                                                "Eval Order");
-                               rel->flag |= DEPSREL_FLAG_GODMODE;
+                               add_relation(data_copy_on_write_key,
+                                            copy_on_write_key,
+                                            "Eval Order",
+                                            DEPSREL_FLAG_GODMODE);
                        }
                }
                else {
index 81f21f5bf771b399168c5e4274523b1e50df6c39..c6db975c6c2907e21b453d37b518a32c44966d0d 100644 (file)
@@ -44,6 +44,7 @@
 #include "BLI_string.h"
 
 #include "intern/builder/deg_builder_map.h"
+#include "intern/depsgraph.h"
 #include "intern/nodes/deg_node.h"
 #include "intern/nodes/deg_node_component.h"
 #include "intern/nodes/deg_node_operation.h"
@@ -186,19 +187,28 @@ struct DepsgraphRelationBuilder
        DepsRelation *add_relation(const KeyFrom& key_from,
                                   const KeyTo& key_to,
                                   const char *description,
-                                  bool check_unique = false);
+                                  bool check_unique = false,
+                                  int flags = 0);
+
+       template <typename KeyFrom, typename KeyTo>
+       DepsRelation *add_relation(const KeyFrom& key_from,
+                                  const KeyTo& key_to,
+                                  const char *description,
+                                  eDepsRelation_Flag flag);
 
        template <typename KeyTo>
        DepsRelation *add_relation(const TimeSourceKey& key_from,
                                   const KeyTo& key_to,
                                   const char *description,
-                                  bool check_unique = false);
+                                  bool check_unique = false,
+                                  int flags = 0);
 
        template <typename KeyType>
        DepsRelation *add_node_handle_relation(const KeyType& key_from,
                                               const DepsNodeHandle *handle,
                                               const char *description,
-                                              bool check_unique = false);
+                                              bool check_unique = false,
+                                              int flags = 0);
 
        void add_customdata_mask(const ComponentKey &key, uint64_t mask);
        void add_special_eval_flag(ID *object, uint32_t flag);
@@ -306,11 +316,13 @@ protected:
        DepsRelation *add_time_relation(TimeSourceDepsNode *timesrc,
                                        DepsNode *node_to,
                                        const char *description,
-                                       bool check_unique = false);
+                                       bool check_unique = false,
+                                       int flags = 0);
        DepsRelation *add_operation_relation(OperationDepsNode *node_from,
                                             OperationDepsNode *node_to,
                                             const char *description,
-                                            bool check_unique = false);
+                                            bool check_unique = false,
+                                            int flags = 0);
 
        template <typename KeyType>
        DepsNodeHandle create_node_handle(const KeyType& key,
index 894d4172c0041f9006c6e8201987a1ecc1d6d5c8..726393f39b955a866f8d71248953f71aa3fba072 100644 (file)
@@ -49,14 +49,16 @@ template <typename KeyFrom, typename KeyTo>
 DepsRelation *DepsgraphRelationBuilder::add_relation(const KeyFrom &key_from,
                                                      const KeyTo &key_to,
                                                      const char *description,
-                                                     bool check_unique)
+                                                     bool check_unique,
+                                                     int flags)
 {
        DepsNode *node_from = get_node(key_from);
        DepsNode *node_to = get_node(key_to);
        OperationDepsNode *op_from = node_from ? node_from->get_exit_operation() : NULL;
        OperationDepsNode *op_to = node_to ? node_to->get_entry_operation() : NULL;
        if (op_from && op_to) {
-               return add_operation_relation(op_from, op_to, description, check_unique);
+               return add_operation_relation(
+                       op_from, op_to, description, check_unique, flags);
        }
        else {
                if (!op_from) {
@@ -81,18 +83,31 @@ DepsRelation *DepsgraphRelationBuilder::add_relation(const KeyFrom &key_from,
        return NULL;
 }
 
+template <typename KeyFrom, typename KeyTo>
+DepsRelation *DepsgraphRelationBuilder::add_relation(
+        const KeyFrom& key_from,
+        const KeyTo& key_to,
+        const char *description,
+        eDepsRelation_Flag flag)
+{
+       return add_relation(
+               key_from, key_to, description, false, static_cast<int>(flag));
+}
+
 template <typename KeyTo>
 DepsRelation *DepsgraphRelationBuilder::add_relation(
         const TimeSourceKey &key_from,
         const KeyTo &key_to,
         const char *description,
-        bool check_unique)
+        bool check_unique,
+        int flags)
 {
        TimeSourceDepsNode *time_from = get_node(key_from);
        DepsNode *node_to = get_node(key_to);
        OperationDepsNode *op_to = node_to ? node_to->get_entry_operation() : NULL;
        if (time_from != NULL && op_to != NULL) {
-               return add_time_relation(time_from, op_to, description, check_unique);
+               return add_time_relation(
+                       time_from, op_to, description, check_unique, flags);
        }
        return NULL;
 }
@@ -102,13 +117,15 @@ DepsRelation *DepsgraphRelationBuilder::add_node_handle_relation(
         const KeyType &key_from,
         const DepsNodeHandle *handle,
         const char *description,
-        bool check_unique)
+        bool check_unique,
+        int flags)
 {
        DepsNode *node_from = get_node(key_from);
        OperationDepsNode *op_from = node_from ? node_from->get_exit_operation() : NULL;
        OperationDepsNode *op_to = handle->node->get_entry_operation();
        if (op_from != NULL && op_to != NULL) {
-               return add_operation_relation(op_from, op_to, description, check_unique);
+               return add_operation_relation(
+                       op_from, op_to, description, check_unique, flags);
        }
        else {
                if (!op_from) {
index d9f07955123bc9829afe28bc25cbf78ea61c1996..f95060ee6ece13b8f0d5966d1f4da2420c06da4a 100644 (file)
@@ -341,8 +341,7 @@ void DepsgraphRelationBuilder::build_rig(Object *object)
         * Unsolved Issues:
         * - Care is needed to ensure that multi-headed trees work out the same as
         *   in ik-tree building
-        * - Animated chain-lengths are a problem...
-        */
+        * - Animated chain-lengths are a problem. */
        RootPChanMap root_map;
        bool pose_depends_on_local_transform = false;
        LISTBASE_FOREACH (bPoseChannel *, pchan, &object->pose->chanbase) {
@@ -359,8 +358,7 @@ void DepsgraphRelationBuilder::build_rig(Object *object)
                                        break;
 
                                /* Constraints which needs world's matrix for transform.
-                                * TODO(sergey): More constraints here?
-                                */
+                                * TODO(sergey): More constraints here? */
                                case CONSTRAINT_TYPE_ROTLIKE:
                                case CONSTRAINT_TYPE_SIZELIKE:
                                case CONSTRAINT_TYPE_LOCLIKE:
@@ -377,15 +375,13 @@ void DepsgraphRelationBuilder::build_rig(Object *object)
        //root_map.print_debug();
        if (pose_depends_on_local_transform) {
                /* TODO(sergey): Once partial updates are possible use relation between
-                * object transform and solver itself in it's build function.
-                */
+                * object transform and solver itself in it's build function. */
                ComponentKey pose_key(&object->id, DEG_NODE_TYPE_EVAL_POSE);
                ComponentKey local_transform_key(&object->id, DEG_NODE_TYPE_TRANSFORM);
                add_relation(local_transform_key, pose_key, "Local Transforms");
        }
        /* Links between operations for each bone. */
        LISTBASE_FOREACH (bPoseChannel *, pchan, &object->pose->chanbase) {
-               DepsRelation *relation;
                OperationKey bone_local_key(&object->id,
                                            DEG_NODE_TYPE_BONE,
                                            pchan->name,
@@ -404,18 +400,17 @@ void DepsgraphRelationBuilder::build_rig(Object *object)
                                           DEG_OPCODE_BONE_DONE);
                pchan->flag &= ~POSE_DONE;
                /* Pose init to bone local. */
-               relation = add_relation(
-                       pose_init_key, bone_local_key, "Pose Init - Bone Local");
-               relation->flag |= DEPSREL_FLAG_GODMODE;
+               add_relation(pose_init_key,
+                            bone_local_key,
+                            "Pose Init - Bone Local",
+                            DEPSREL_FLAG_GODMODE);
                /* Local to pose parenting operation. */
                add_relation(bone_local_key, bone_pose_key, "Bone Local - Bone Pose");
                /* Parent relation. */
                if (pchan->parent != NULL) {
                        eDepsOperation_Code parent_key_opcode;
-
                        /* NOTE: this difference in handling allows us to prevent lockups
-                        * while ensuring correct poses for separate chains.
-                        */
+                        * while ensuring correct poses for separate chains. */
                        if (root_map.has_common_root(pchan->name, pchan->parent->name)) {
                                parent_key_opcode = DEG_OPCODE_BONE_READY;
                        }
@@ -449,8 +444,7 @@ void DepsgraphRelationBuilder::build_rig(Object *object)
                        add_relation(bone_pose_key, constraints_key, "Constraints Stack");
                        /* Constraints -> ready/ */
                        /* TODO(sergey): When constraint stack is exploded, this step should
-                        * occur before the first IK solver.
-                        */
+                        * occur before the first IK solver.  */
                        add_relation(
                                constraints_key, bone_ready_key, "Constraints -> Ready");
                }
@@ -461,12 +455,10 @@ void DepsgraphRelationBuilder::build_rig(Object *object)
                /* Bone ready -> Bone done.
                 * NOTE: For bones without IK, this is all that's needed.
                 *       For IK chains however, an additional rel is created from IK
-                *       to done, with transitive reduction removing this one..
-                */
+                *       to done, with transitive reduction removing this one. */
                add_relation(bone_ready_key, bone_done_key, "Ready -> Done");
-               /* assume that all bones must be done for the pose to be ready
-                * (for deformers)
-                */
+               /* Assume that all bones must be done for the pose to be ready
+                * (for deformers). */
                add_relation(bone_done_key, pose_done_key, "PoseEval Result-Bone Link");
                add_relation(bone_done_key, pose_cleanup_key, "Cleanup dependency");
                /* Custom shape. */
index 7f47dce9f472760d7ca6b6c46ab4be9540b382e0..6dd7ae97073d5e1abc04a3bc9c9aac3e66a7aabc 100644 (file)
@@ -393,34 +393,40 @@ void Depsgraph::clear_id_nodes()
 DepsRelation *Depsgraph::add_new_relation(OperationDepsNode *from,
                                           OperationDepsNode *to,
                                           const char *description,
-                                          bool check_unique)
+                                          bool check_unique,
+                                          int flags)
 {
        DepsRelation *rel = NULL;
        if (check_unique) {
                rel = check_nodes_connected(from, to, description);
        }
        if (rel != NULL) {
+               rel->flag |= flags;
                return rel;
        }
        /* Create new relation, and add it to the graph. */
        rel = OBJECT_GUARDED_NEW(DepsRelation, from, to, description);
+       rel->flag |= flags;
        return rel;
 }
 
 /* Add new relation between two nodes */
 DepsRelation *Depsgraph::add_new_relation(DepsNode *from, DepsNode *to,
                                           const char *description,
-                                          bool check_unique)
+                                          bool check_unique,
+                                          int flags)
 {
        DepsRelation *rel = NULL;
        if (check_unique) {
                rel = check_nodes_connected(from, to, description);
        }
        if (rel != NULL) {
+               rel->flag |= flags;
                return rel;
        }
        /* Create new relation, and add it to the graph. */
        rel = OBJECT_GUARDED_NEW(DepsRelation, from, to, description);
+       rel->flag |= flags;
        return rel;
 }
 
index 5097ae33d4c2b3420f390ac49e3f55a2d2b6f070..fd45c482bb59d42ca7c83f475dc4aac9862a342b 100644 (file)
@@ -141,12 +141,14 @@ struct Depsgraph {
        DepsRelation *add_new_relation(OperationDepsNode *from,
                                       OperationDepsNode *to,
                                       const char *description,
-                                      bool check_unique = false);
+                                      bool check_unique = false,
+                                      int flags = 0);
 
        DepsRelation *add_new_relation(DepsNode *from,
                                       DepsNode *to,
                                       const char *description,
-                                      bool check_unique = false);
+                                      bool check_unique = false,
+                                      int flags = 0);
 
        /* Check whether two nodes are connected by relation with given
         * description. Description might be NULL to check ANY relation between