Depsgraph: Be consistent about id type variable name
[blender.git] / source / blender / depsgraph / intern / depsgraph_tag.cc
index 883eadedb39603c6fdf5f90ebd81b2fd999bbba5..ce80f30f3597079693ef4bd830d84ca560960d40 100644 (file)
@@ -67,6 +67,13 @@ extern "C" {
 #include "intern/depsgraph_intern.h"
 #include "util/deg_util_foreach.h"
 
+/* Define this in order to have more strict sanitization of what tagging flags
+ * are used for ID databnlocks. Ideally, we would always want this, but there
+ * are cases in generic modules (like IR remapping) where we don't want to spent
+ * lots of time trying to guess which components are to be updated.
+ */
+// #define STRICT_COMPONENT_TAGGING
+
 /* *********************** */
 /* Update Tagging/Flushing */
 
@@ -101,8 +108,8 @@ void lib_id_recalc_tag_flag(Main *bmain, ID *id, int flag)
         * after relations update and after layer visibility changes.
         */
        if (flag) {
-               short idtype = GS(id->name);
-               if (idtype == ID_OB) {
+               short id_type = GS(id->name);
+               if (id_type == ID_OB) {
                        Object *object = (Object *)id;
                        object->recalc |= (flag & OB_RECALC_ALL);
                }
@@ -131,9 +138,11 @@ void id_tag_update_object_transform(Depsgraph *graph, IDDepsNode *id_node)
        ComponentDepsNode *transform_comp =
                id_node->find_component(DEG_NODE_TYPE_TRANSFORM);
        if (transform_comp == NULL) {
+#ifdef STRICT_COMPONENT_TAGGING
                DEG_ERROR_PRINTF("ERROR: Unable to find transform component for %s\n",
                                 id_node->id_orig->name);
                BLI_assert(!"This is not supposed to happen!");
+#endif
                return;
        }
        transform_comp->tag_update(graph);
@@ -142,9 +151,9 @@ void id_tag_update_object_transform(Depsgraph *graph, IDDepsNode *id_node)
 /* Tag corresponding to OB_RECALC_DATA. */
 void id_tag_update_object_data(Depsgraph *graph, IDDepsNode *id_node)
 {
-       const short idtype = GS(id_node->id_orig->name);
+       const short id_type = GS(id_node->id_orig->name);
        ComponentDepsNode *data_comp = NULL;
-       switch (idtype) {
+       switch (id_type) {
                case ID_OB:
                {
                        const Object *object = (Object *)id_node->id_orig;
@@ -170,12 +179,27 @@ void id_tag_update_object_data(Depsgraph *graph, IDDepsNode *id_node)
                        return;
        }
        if (data_comp == NULL) {
+#ifdef STRICT_COMPONENT_TAGGING
                DEG_ERROR_PRINTF("ERROR: Unable to find data component for %s\n",
                                 id_node->id_orig->name);
                BLI_assert(!"This is not supposed to happen!");
+#endif
                return;
        }
        data_comp->tag_update(graph);
+       /* Special legacy compatibility code, tag data ID for update when object
+        * is tagged for data update.
+        */
+       if (id_type == ID_OB) {
+               Object *object = (Object *)id_node->id_orig;
+               ID *data_id = (ID *)object->data;
+               if (data_id != NULL) {
+                       IDDepsNode *data_id_node = graph->find_id_node(data_id);
+                       BLI_assert(data_id_node != NULL);
+                       /* TODO(sergey): Do we want more granular tags here? */
+                       data_id_node->tag_update(graph);
+               }
+       }
 }
 
 /* Tag corresponding to OB_RECALC_TIME. */
@@ -193,19 +217,38 @@ void id_tag_update_object_time(Depsgraph *graph, IDDepsNode *id_node)
        /* TODO(sergey): More components to tag here? */
 }
 
-void id_tag_update_particle(Depsgraph *graph, IDDepsNode *id_node)
+void id_tag_update_particle(Depsgraph *graph, IDDepsNode *id_node, int tag)
 {
        ComponentDepsNode *particle_comp =
                id_node->find_component(DEG_NODE_TYPE_PARAMETERS);
+       ParticleSettings *particle_settings = (ParticleSettings *)id_node->id_orig;
+       particle_settings->recalc |= (tag & PSYS_RECALC);
        if (particle_comp == NULL) {
+#ifdef STRICT_COMPONENT_TAGGING
                DEG_ERROR_PRINTF("ERROR: Unable to find particle component for %s\n",
                                 id_node->id_orig->name);
                BLI_assert(!"This is not supposed to happen!");
+#endif
                return;
        }
        particle_comp->tag_update(graph);
 }
 
+void id_tag_update_shading(Depsgraph *graph, IDDepsNode *id_node)
+{
+       ComponentDepsNode *shading_comp =
+               id_node->find_component(DEG_NODE_TYPE_SHADING);
+       if (shading_comp == NULL) {
+#ifdef STRICT_COMPONENT_TAGGING
+               DEG_ERROR_PRINTF("ERROR: Unable to find shading component for %s\n",
+                                id_node->id_orig->name);
+               BLI_assert(!"This is not supposed to happen!");
+#endif
+               return;
+       }
+       shading_comp->tag_update(graph);
+}
+
 #ifdef WITH_COPY_ON_WRITE
 /* Tag corresponding to DEG_TAG_COPY_ON_WRITE. */
 void id_tag_update_copy_on_write(Depsgraph *graph, IDDepsNode *id_node)
@@ -214,7 +257,6 @@ void id_tag_update_copy_on_write(Depsgraph *graph, IDDepsNode *id_node)
                id_node->find_component(DEG_NODE_TYPE_COPY_ON_WRITE);
        OperationDepsNode *cow_node = cow_comp->get_entry_operation();
        cow_node->tag_update(graph);
-       cow_node->flag |= DEPSOP_FLAG_SKIP_FLUSH;
 }
 #endif
 
@@ -243,8 +285,10 @@ void deg_graph_id_tag_update(Main *bmain, Depsgraph *graph, ID *id, int flag)
                id_tag_update_object_time(graph, id_node);
        }
        if (flag & PSYS_RECALC) {
-               /* TODO(sergey): Differentiate between different particle updates tags. */
-               id_tag_update_particle(graph, id_node);
+               id_tag_update_particle(graph, id_node, flag);
+       }
+       if (flag & DEG_TAG_SHADING_UPDATE) {
+               id_tag_update_shading(graph, id_node);
        }
 #ifdef WITH_COPY_ON_WRITE
        if (flag & DEG_TAG_COPY_ON_WRITE) {
@@ -272,8 +316,8 @@ void deg_graph_on_visible_update(Main *bmain, Scene *scene, Depsgraph *graph)
        /* Make sure objects are up to date. */
        GHASH_FOREACH_BEGIN(DEG::IDDepsNode *, id_node, graph->id_hash)
        {
-               const short idtype = GS(id_node->id_orig->name);
-               if (idtype != ID_OB) {
+               const short id_type = GS(id_node->id_orig->name);
+               if (id_type != ID_OB) {
                        /* Ignore non-object nodes on visibility changes. */
                        continue;
                }
@@ -284,7 +328,7 @@ void deg_graph_on_visible_update(Main *bmain, Scene *scene, Depsgraph *graph)
                 *
                 * TODO(sergey): Need to generalize this somehow.
                 */
-               if (idtype == ID_OB) {
+               if (id_type == ID_OB) {
                        Object *object = (Object *)id_node->id_orig;
                        flag |= OB_RECALC_OB;
                        if (ELEM(object->type, OB_MESH,
@@ -326,9 +370,9 @@ void DEG_id_tag_update_ex(Main *bmain, ID *id, int flag)
 }
 
 /* Tag given ID type for update. */
-void DEG_id_type_tag(Main *bmain, short idtype)
+void DEG_id_type_tag(Main *bmain, short id_type)
 {
-       if (idtype == ID_NT) {
+       if (id_type == ID_NT) {
                /* Stupid workaround so parent datablocks of nested nodetree get looped
                 * over when we loop over tagged datablock types.
                 */
@@ -339,7 +383,7 @@ void DEG_id_type_tag(Main *bmain, short idtype)
                DEG_id_type_tag(bmain, ID_SCE);
        }
 
-       bmain->id_tag_update[BKE_idcode_to_index(idtype)] = 1;
+       bmain->id_tag_update[BKE_idcode_to_index(id_type)] = 1;
 }
 
 /* Recursively push updates out to all nodes dependent on this,