Depsgraph: Add additional relations/id update tags
authorSergey Sharybin <sergey.vfx@gmail.com>
Tue, 12 May 2015 08:29:00 +0000 (13:29 +0500)
committerSergey Sharybin <sergey.vfx@gmail.com>
Tue, 12 May 2015 11:06:36 +0000 (16:06 +0500)
This calls are not strictly speaking needed for the old dependency graph, but
due to more granular nature of upcoming depsgraph more actions requires update
of relations of IDs.

On the one hand this extra tags could be wrapped with if() statements, but on
the other hand it makes sense to keep tag in sync so it's clear if some issue
is caused by missing/extra tag or by depsgraph itself.

12 files changed:
source/blender/editors/animation/anim_channels_edit.c
source/blender/editors/animation/anim_deps.c
source/blender/editors/animation/drivers.c
source/blender/editors/animation/keyframing.c
source/blender/editors/object/object_constraint.c
source/blender/editors/object/object_edit.c
source/blender/editors/object/object_modifier.c
source/blender/editors/space_node/node_draw.c
source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp
source/blender/makesrna/intern/rna_animation.c
source/blender/makesrna/intern/rna_camera.c
source/blender/makesrna/intern/rna_object.c

index 67485248bf12c010ab511092a2f0384301929c11..fd7551abab3c4d0278639f8b91116bbb235f61dd 100644 (file)
@@ -34,6 +34,7 @@
 
 #include "MEM_guardedalloc.h"
 
+#include "BKE_depsgraph.h"
 #include "BLI_blenlib.h"
 #include "BLI_utildefines.h"
 #include "BLI_listbase.h"
@@ -1707,7 +1708,8 @@ static int animchannels_delete_exec(bContext *C, wmOperator *UNUSED(op))
        
        /* send notifier that things have changed */
        WM_event_add_notifier(C, NC_ANIMATION | ND_ANIMCHAN | NA_EDITED, NULL);
-       
+       DAG_relations_tag_update(CTX_data_main(C));
+
        return OPERATOR_FINISHED;
 }
  
index eb57907c9ec8a565a7b8683707812f551b1349b2..a38f5dbc8ea2851656190ef412591e6d2fbf1910 100644 (file)
@@ -73,8 +73,10 @@ void ANIM_list_elem_update(Scene *scene, bAnimListElem *ale)
        
        /* tag AnimData for refresh so that other views will update in realtime with these changes */
        adt = BKE_animdata_from_id(id);
-       if (adt)
+       if (adt) {
                adt->recalc |= ADT_RECALC_ANIM;
+               DAG_id_tag_update(id, OB_RECALC_TIME);
+       }
 
        /* update data */
        fcu = (ale->datatype == ALE_FCURVE) ? ale->key_data : NULL;
index 08e0daf8eb93296485be8a5d69b8a19406aac28c..b2a34d7c31720f3da47894b247a25dbbb36b6b51 100644 (file)
@@ -42,6 +42,7 @@
 #include "DNA_texture_types.h"
 
 #include "BKE_animsys.h"
+#include "BKE_depsgraph.h"
 #include "BKE_fcurve.h"
 #include "BKE_context.h"
 #include "BKE_report.h"
@@ -450,7 +451,7 @@ static int add_driver_button_exec(bContext *C, wmOperator *op)
        if (success) {
                /* send updates */
                UI_context_update_anim_flag(C);
-               
+               DAG_relations_tag_update(CTX_data_main(C));
                WM_event_add_notifier(C, NC_ANIMATION | ND_FCURVES_ORDER, NULL); // XXX
        }
        
@@ -504,7 +505,7 @@ static int remove_driver_button_exec(bContext *C, wmOperator *op)
        if (success) {
                /* send updates */
                UI_context_update_anim_flag(C);
-               
+               DAG_relations_tag_update(CTX_data_main(C));
                WM_event_add_notifier(C, NC_ANIMATION | ND_FCURVES_ORDER, NULL);  // XXX
        }
        
index 092408d7de553ce608d3ee3d419d0cd34af6e700..cd7a326ffd5ff725aa649113c79198bebea90b73 100644 (file)
@@ -152,6 +152,10 @@ bAction *verify_adt_action(ID *id, short add)
                 * to the wrong places
                 */
                adt->action->idroot = GS(id->name);
+
+               /* tag depsgraph to be rebuilt to include time dependency */
+               /* XXX: we probably should have bmain passed down, but that involves altering too many API's */
+               DAG_relations_tag_update(G.main);
        }
                
        /* return the action */
index 22db0936e39fe490311495a0ce8ef67cd937ce7a..e14674ef5172321655d9ea17c75cde337e392bc0 100644 (file)
@@ -1260,7 +1260,10 @@ static int constraint_delete_exec(bContext *C, wmOperator *UNUSED(op))
                /* there's no active constraint now, so make sure this is the case */
                BKE_constraints_active_set(&ob->constraints, NULL);
                ED_object_constraint_update(ob); /* needed to set the flags on posebones correctly */
-               
+
+               /* relatiols */
+               DAG_relations_tag_update(CTX_data_main(C));
+
                /* notifiers */
                WM_event_add_notifier(C, NC_OBJECT | ND_CONSTRAINT | NA_REMOVED, ob);
                
index 706ca5fbdfe1169bbd0d235186effb21703b9765..5e2bd438031cad401407e70f01616cc988df1dd6 100644 (file)
@@ -65,6 +65,7 @@
 #include "BKE_curve.h"
 #include "BKE_effect.h"
 #include "BKE_depsgraph.h"
+#include "BKE_global.h"
 #include "BKE_image.h"
 #include "BKE_lattice.h"
 #include "BKE_library.h"
@@ -318,7 +319,7 @@ void OBJECT_OT_hide_render_set(wmOperatorType *ot)
  * Load EditMode data back into the object,
  * optionally freeing the editmode data.
  */
-static bool ED_object_editmode_load_ex(Object *obedit, const bool freedata)
+static bool ED_object_editmode_load_ex(Main *bmain, Object *obedit, const bool freedata)
 {
        if (obedit == NULL) {
                return false;
@@ -348,6 +349,11 @@ static bool ED_object_editmode_load_ex(Object *obedit, const bool freedata)
                ED_armature_from_edit(obedit->data);
                if (freedata)
                        ED_armature_edit_free(obedit->data);
+               /* TODO(sergey): Pose channels might have been changed, so need
+                * to inform dependency graph about this. But is it really the
+                * best place to do this?
+                */
+               DAG_relations_tag_update(bmain);
        }
        else if (ELEM(obedit->type, OB_CURVE, OB_SURF)) {
                load_editNurb(obedit);
@@ -376,7 +382,8 @@ static bool ED_object_editmode_load_ex(Object *obedit, const bool freedata)
 
 bool ED_object_editmode_load(Object *obedit)
 {
-       return ED_object_editmode_load_ex(obedit, false);
+       /* TODO(sergey): use proper main here? */
+       return ED_object_editmode_load_ex(G.main, obedit, false);
 }
 
 void ED_object_editmode_exit(bContext *C, int flag)
@@ -389,7 +396,7 @@ void ED_object_editmode_exit(bContext *C, int flag)
 
        if (flag & EM_WAITCURSOR) waitcursor(1);
 
-       if (ED_object_editmode_load_ex(obedit, freedata) == false) {
+       if (ED_object_editmode_load_ex(CTX_data_main(C), obedit, freedata) == false) {
                /* in rare cases (background mode) its possible active object
                 * is flagged for editmode, without 'obedit' being set [#35489] */
                if (UNLIKELY(scene->basact && (scene->basact->object->mode & OB_MODE_EDIT))) {
index 1cee54c33faaa956ab908c744688c3c48704a4a4..c88f125793658cfc4f33f81119f46e3fbfc844c0 100644 (file)
@@ -152,10 +152,10 @@ ModifierData *ED_object_modifier_add(ReportList *reports, Main *bmain, Scene *sc
                                ob->pd = object_add_collision_fields(0);
                        
                        ob->pd->deflect = 1;
-                       DAG_relations_tag_update(bmain);
                }
-               else if (type == eModifierType_Surface)
-                       DAG_relations_tag_update(bmain);
+               else if (type == eModifierType_Surface) {
+                       /* pass */
+               }
                else if (type == eModifierType_Multires) {
                        /* set totlvl from existing MDISPS layer if object already had it */
                        multiresModifier_set_levels_from_disps((MultiresModifierData *)new_md, ob);
@@ -172,6 +172,7 @@ ModifierData *ED_object_modifier_add(ReportList *reports, Main *bmain, Scene *sc
        }
 
        DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+       DAG_relations_tag_update(bmain);
 
        return new_md;
 }
@@ -319,6 +320,8 @@ static bool object_modifier_remove(Main *bmain, Object *ob, ModifierData *md,
                ob->mode &= ~OB_MODE_PARTICLE_EDIT;
        }
 
+       DAG_relations_tag_update(bmain);
+
        BLI_remlink(&ob->modifiers, md);
        modifier_free(md);
 
index e27cb041dc53ac417fe93b0d4dc06543e2a84b55..c89bf8dd13a2b83adffc59ae84a564fda3ca9518 100644 (file)
@@ -123,7 +123,14 @@ void ED_node_tag_update_id(ID *id)
        bNodeTree *ntree = node_tree_from_ID(id);
        if (id == NULL || ntree == NULL)
                return;
-       
+
+       /* TODO(sergey): With the new dependency graph it
+        * should be just enough to ony tag ntree itself,
+        * all the users of this tree will have update
+        * flushed from the tree,
+        */
+       DAG_id_tag_update(&ntree->id, 0);
+
        if (ntree->type == NTREE_SHADER) {
                DAG_id_tag_update(id, 0);
                
index 1ddc311b1ae585da009d27407caa1eeeae328ce9..cfa0c45b1e3108a305f5d67284814cb401de4a89 100644 (file)
@@ -127,6 +127,7 @@ BlenderStrokeRenderer::BlenderStrokeRenderer(Render *re, int render_count) : Str
 
        // Camera
        Object *object_camera = BKE_object_add(freestyle_bmain, freestyle_scene, OB_CAMERA, NULL);
+       DAG_relations_tag_update(freestyle_bmain);
 
        Camera *camera = (Camera *)object_camera->data;
        camera->type = CAM_ORTHO;
@@ -506,6 +507,7 @@ void BlenderStrokeRenderer::RenderStrokeRepBasic(StrokeRep *iStrokeRep) const
                // If still no material, create one
                if (!has_mat) {
                        Material *ma = BKE_material_add(freestyle_bmain, "stroke_material");
+                       DAG_relations_tag_update(freestyle_bmain);
                        ma->mode |= MA_VERTEXCOLP;
                        ma->mode |= MA_TRANSP;
                        ma->mode |= MA_SHLESS;
@@ -668,6 +670,7 @@ void BlenderStrokeRenderer::GenerateStrokeMesh(StrokeGroup *group, bool hasTex)
 {
 #if 0
        Object *object_mesh = BKE_object_add(freestyle_bmain, freestyle_scene, OB_MESH);
+       DAG_relations_tag_update(freestyle_bmain);
 #else
        Object *object_mesh = NewMesh();
 #endif
@@ -938,6 +941,7 @@ Object *BlenderStrokeRenderer::NewMesh() const
        ob->lay = 1;
 
        base = BKE_scene_base_add(freestyle_scene, ob);
+       DAG_relations_tag_update(freestyle_bmain);
 #if 0
        BKE_scene_base_deselect_all(scene);
        BKE_scene_base_select(scene, base);
index df1e6dd55dd2df877cbdcc9e3a815ab20334789e..ac30c6154385d8c564ddc0f7cc90fd34c34d1be2 100644 (file)
@@ -112,6 +112,7 @@ static void rna_AnimData_action_set(PointerRNA *ptr, PointerRNA value)
        adt = BKE_animdata_from_id(ownerId);
        if (adt) {
                adt->recalc |= ADT_RECALC_ANIM;
+               DAG_id_tag_update(ownerId, OB_RECALC_TIME);
        }
 }
 
index 2baaa5f7cec339e0e2e3a940f5ed3f78e6e34e14..16f74a05f7bf1199c556b820679d386a9f68b747 100644 (file)
@@ -87,6 +87,13 @@ static void rna_Camera_update(Main *UNUSED(bmain), Scene *UNUSED(scene), Pointer
        DAG_id_tag_update(&camera->id, 0);
 }
 
+static void rna_Camera_dependency_update(Main *bmain, Scene *UNUSED(scene), PointerRNA *ptr)
+{
+       Camera *camera = (Camera *)ptr->id.data;
+       DAG_relations_tag_update(bmain);
+       DAG_id_tag_update(&camera->id, 0);
+}
+
 #else
 
 static void rna_def_camera_stereo_data(BlenderRNA *brna)
@@ -356,7 +363,7 @@ void RNA_def_camera(BlenderRNA *brna)
        RNA_def_property_pointer_sdna(prop, NULL, "dof_ob");
        RNA_def_property_flag(prop, PROP_EDITABLE);
        RNA_def_property_ui_text(prop, "DOF Object", "Use this object to define the depth of field focal point");
-       RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, NULL);
+       RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_Camera_dependency_update");
 
        prop = RNA_def_property(srna, "gpu_dof", PROP_POINTER, PROP_NONE);
        RNA_def_property_struct_type(prop, "GPUDOFSettings");
index 8bb3e9c265b939cf1f45b64b80e177aaacbd7821..2ef5c6ec12e9c1d7b6b8db696a52cfb77f057935 100644 (file)
@@ -949,6 +949,7 @@ static void rna_MaterialSlot_update(Main *bmain, Scene *scene, PointerRNA *ptr)
 
        WM_main_add_notifier(NC_OBJECT | ND_OB_SHADING, ptr->id.data);
        WM_main_add_notifier(NC_MATERIAL | ND_SHADING_LINKS, NULL);
+       DAG_relations_tag_update(bmain);
 }
 
 static char *rna_MaterialSlot_path(PointerRNA *ptr)