Depsgraph: Make component traversal more granular
authorSergey Sharybin <sergey.vfx@gmail.com>
Thu, 4 Jul 2019 13:13:26 +0000 (15:13 +0200)
committerSergey Sharybin <sergey.vfx@gmail.com>
Fri, 5 Jul 2019 14:06:12 +0000 (16:06 +0200)
Now it is possible to start traversal from a given component.

source/blender/depsgraph/DEG_depsgraph_build.h
source/blender/depsgraph/DEG_depsgraph_query.h
source/blender/depsgraph/intern/depsgraph_query_foreach.cc
source/blender/depsgraph/intern/node/deg_node.cc

index ee2d4b7be549a132e81b4a64365bda1185ec0769..18e06410adfc96a8e55712999997b7950ffe41d1 100644 (file)
@@ -110,6 +110,9 @@ typedef enum eDepsSceneComponentType {
 } eDepsSceneComponentType;
 
 typedef enum eDepsObjectComponentType {
+  /* Used in query API, to denote which component caller is interested in. */
+  DEG_OB_COMP_ANY,
+
   /* Parameters Component - Default when nothing else fits
    * (i.e. just SDNA property setting). */
   DEG_OB_COMP_PARAMETERS,
index 35176284abb6b04156dbff8ed6343622e474d486..27891acb6669a6a8cb2015186efa19be454a3195 100644 (file)
@@ -235,8 +235,11 @@ void DEG_foreach_dependent_ID(const Depsgraph *depsgraph,
                               DEGForeachIDCallback callback,
                               void *user_data);
 
+/* Starts traversal from given component of the given ID, invokes callback for every other
+ * component  which is directly on indirectly dependent on the source one. */
 void DEG_foreach_dependent_ID_component(const Depsgraph *depsgraph,
                                         const ID *id,
+                                        eDepsObjectComponentType source_component,
                                         DEGForeachIDComponentCallback callback,
                                         void *user_data);
 
index f5fcdf8e5d11d7fe23834ff2ce636b449c960fb7..7bc55b52172fdd8efbf8d9ecd323bf0105b135a3 100644 (file)
@@ -70,6 +70,7 @@ void deg_foreach_clear_flags(const Depsgraph *graph)
 
 void deg_foreach_dependent_operation(const Depsgraph *graph,
                                      const ID *id,
+                                     eDepsObjectComponentType source_component,
                                      DEGForeachOperation callback,
                                      void *user_data)
 {
@@ -85,6 +86,10 @@ void deg_foreach_dependent_operation(const Depsgraph *graph,
   /* Start with scheduling all operations from ID node. */
   TraversalQueue queue;
   GHASH_FOREACH_BEGIN (ComponentNode *, comp_node, target_id_node->components) {
+    if (source_component != DEG_OB_COMP_ANY &&
+        nodeTypeToObjectComponent(comp_node->type) != source_component) {
+      continue;
+    }
     for (OperationNode *op_node : comp_node->operations) {
       queue.push_back(op_node);
       op_node->scheduled = true;
@@ -144,13 +149,15 @@ void deg_foreach_dependent_component_callback(OperationNode *op_node, void *user
 
 void deg_foreach_dependent_ID_component(const Depsgraph *graph,
                                         const ID *id,
+                                        eDepsObjectComponentType source_component,
                                         DEGForeachIDComponentCallback callback,
                                         void *user_data)
 {
   ForeachIDComponentData data;
   data.callback = callback;
   data.user_data = user_data;
-  deg_foreach_dependent_operation(graph, id, deg_foreach_dependent_component_callback, &data);
+  deg_foreach_dependent_operation(
+      graph, id, source_component, deg_foreach_dependent_component_callback, &data);
 }
 
 struct ForeachIDData {
@@ -177,7 +184,8 @@ void deg_foreach_dependent_ID(const Depsgraph *graph,
   ForeachIDData data;
   data.callback = callback;
   data.user_data = user_data;
-  deg_foreach_dependent_operation(graph, id, deg_foreach_dependent_ID_callback, &data);
+  deg_foreach_dependent_operation(
+      graph, id, DEG_OB_COMP_ANY, deg_foreach_dependent_ID_callback, &data);
 }
 
 void deg_foreach_ancestor_ID(const Depsgraph *graph,
@@ -269,11 +277,12 @@ void DEG_foreach_dependent_ID(const Depsgraph *depsgraph,
 
 void DEG_foreach_dependent_ID_component(const Depsgraph *depsgraph,
                                         const ID *id,
+                                        eDepsObjectComponentType source_component,
                                         DEGForeachIDComponentCallback callback,
                                         void *user_data)
 {
   DEG::deg_foreach_dependent_ID_component(
-      (const DEG::Depsgraph *)depsgraph, id, callback, user_data);
+      (const DEG::Depsgraph *)depsgraph, id, source_component, callback, user_data);
 }
 
 void DEG_foreach_ancestor_ID(const Depsgraph *depsgraph,
index f53caca00a94b87377e97823882b63f1c5c76d0d..701344c2405b94138b40c71e838c8a92fdb6c9d6 100644 (file)
@@ -177,6 +177,8 @@ eDepsSceneComponentType nodeTypeToSceneComponent(NodeType type)
 NodeType nodeTypeFromObjectComponent(eDepsObjectComponentType component)
 {
   switch (component) {
+    case DEG_OB_COMP_ANY:
+      return NodeType::UNDEFINED;
     case DEG_OB_COMP_PARAMETERS:
       return NodeType::PARAMETERS;
     case DEG_OB_COMP_PROXY: