small merge needed for testing new animsys in 2.5 BGE, mixing own changes with merge...
[blender.git] / source / blender / blenkernel / intern / depsgraph.c
index d958c43aa40a276175f5fc1a4fb5a69ebfa03e71..dfe3b7ea27943f5d2ca8301c4290a21f683c7709 100644 (file)
 #include "BLI_winstuff.h"
 #endif
 
-//#include "BMF_Api.h"
-
 #include "BLI_blenlib.h"
 #include "BLI_arithb.h"
 
+#include "DNA_anim_types.h"
 #include "DNA_action_types.h"
 #include "DNA_armature_types.h"
 #include "DNA_curve_types.h"
@@ -54,7 +53,7 @@
 #include "DNA_object_types.h"
 #include "DNA_object_force.h"
 #include "DNA_object_fluidsim.h"
-#include "DNA_oops_types.h"
+#include "DNA_outliner_types.h"
 #include "DNA_particle_types.h"
 #include "DNA_scene_types.h"
 #include "DNA_screen_types.h"
 #include "BKE_scene.h"
 
 #include "MEM_guardedalloc.h"
-#include "blendef.h"
 
+#ifndef DISABLE_PYTHON
 #include "BPY_extern.h"
+#endif
 
  #include "depsgraph_private.h"
  
@@ -301,59 +301,49 @@ DagForest * dag_init()
        return forest;
 }
 
-static void dag_add_driver_relation(Ipo *ipo, DagForest *dag, DagNode *node, int isdata)
+/* isdata = object data... */
+// XXX this needs to be extended to be more flexible (so that not only objects are evaluated via depsgraph)...
+static void dag_add_driver_relation(AnimData *adt, DagForest *dag, DagNode *node, int isdata)
 {
-       IpoCurve *icu;
+       FCurve *fcu;
        DagNode *node1;
        
-       for(icu= ipo->curve.first; icu; icu= icu->next) {
-               if(icu->driver) {
-
-                       if (icu->driver->type == IPO_DRIVER_TYPE_PYTHON) {
-
-                               if ((icu->driver->flag & IPO_DRIVER_FLAG_INVALID) || (icu->driver->name[0] == '\0'))
-                                       continue; /* empty or invalid expression */
-                               else {
-                                       /* now we need refs to all objects mentioned in this
-                                        * pydriver expression, to call 'dag_add_relation'
-                                        * for each of them */
-                                       Object **obarray = BPY_pydriver_get_objects(icu->driver);
-                                       if (obarray) {
-                                               Object *ob, **oba = obarray;
-
-                                               while (*oba) {
-                                                       ob = *oba;
-                                                       node1 = dag_get_node(dag, ob);
-                                                       if (ob->type == OB_ARMATURE)
-                                                               dag_add_relation(dag, node1, node, isdata?DAG_RL_DATA_DATA:DAG_RL_DATA_OB, "Python Ipo Driver");
-                                                       else
-                                                               dag_add_relation(dag, node1, node, isdata?DAG_RL_OB_DATA:DAG_RL_OB_OB, "Python Ipo Driver");
-                                                       oba++;
-                                               }
-
-                                               MEM_freeN(obarray);
-                                       }
+       for (fcu= adt->drivers.first; fcu; fcu= fcu->next) {
+               ChannelDriver *driver= fcu->driver;
+               DriverTarget *dtar;
+               
+               /* loop over targets, adding relationships as appropriate */
+               for (dtar= driver->targets.first; dtar; dtar= dtar->next) {
+                       if (dtar->id) {
+                               if (GS(dtar->id->name)==ID_OB) {
+                                       Object *ob= (Object *)dtar->id;
+                                       
+                                       /* normal channel-drives-channel */
+                                       node1 = dag_get_node(dag, dtar->id);
+                                       
+                                       /* check if bone... */
+                                       if ((ob->type==OB_ARMATURE) && dtar->rna_path && strstr(dtar->rna_path, "pose.pose_channels["))
+                                               dag_add_relation(dag, node1, node, isdata?DAG_RL_DATA_DATA:DAG_RL_DATA_OB, "Driver");
+                                       /* check if ob data */
+                                       else if (dtar->rna_path && strstr(dtar->rna_path, "data."))
+                                               dag_add_relation(dag, node1, node, isdata?DAG_RL_DATA_DATA:DAG_RL_DATA_OB, "Driver");
+                                       /* normal */
+                                       else
+                                               dag_add_relation(dag, node1, node, isdata?DAG_RL_OB_DATA:DAG_RL_OB_OB, "Driver");
                                }
                        }
-                       else if (icu->driver->ob) {
-                               node1 = dag_get_node(dag, icu->driver->ob);
-                               if(icu->driver->blocktype==ID_AR)
-                                       dag_add_relation(dag, node1, node, isdata?DAG_RL_DATA_DATA:DAG_RL_DATA_OB, "Ipo Driver");
-                               else
-                                       dag_add_relation(dag, node1, node, isdata?DAG_RL_OB_DATA:DAG_RL_OB_OB, "Ipo Driver");
-                       }
                }
        }
 }
 
-static void dag_add_collision_field_relation(DagForest *dag, Object *ob, DagNode *node)
+static void dag_add_collision_field_relation(DagForest *dag, Scene *scene, Object *ob, DagNode *node)
 {
        Base *base;
        DagNode *node2;
 
        // would be nice to have a list of colliders here
        // so for now walk all objects in scene check 'same layer rule'
-       for(base = G.scene->base.first; base; base= base->next) {
+       for(base = scene->base.first; base; base= base->next) {
                if((base->lay & ob->lay) && base->object->pd) {
                        Object *ob1= base->object;
                        if((ob1->pd->deflect || ob1->pd->forcefield) && (ob1 != ob))  {
@@ -364,10 +354,9 @@ static void dag_add_collision_field_relation(DagForest *dag, Object *ob, DagNode
        }
 }
 
-static void build_dag_object(DagForest *dag, DagNode *scenenode, Object *ob, int mask)
+static void build_dag_object(DagForest *dag, DagNode *scenenode, Scene *scene, Object *ob, int mask)
 {
        bConstraint *con;
-       bConstraintChannel *conchan;
        DagNode * node;
        DagNode * node2;
        DagNode * node3;
@@ -422,35 +411,11 @@ static void build_dag_object(DagForest *dag, DagNode *scenenode, Object *ob, int
        }
        
        /* driver dependencies, nla modifiers */
-       if(ob->ipo) 
-               dag_add_driver_relation(ob->ipo, dag, node, 0);
-       
-       key= ob_get_key(ob);
-       if(key && key->ipo)
-               dag_add_driver_relation(key->ipo, dag, node, 1);
-       
-       for (conchan=ob->constraintChannels.first; conchan; conchan=conchan->next)
-               if(conchan->ipo)
-                       dag_add_driver_relation(conchan->ipo, dag, node, 0);
-
-       if(ob->action) {
-               bActionChannel *chan;
-               for (chan = ob->action->chanbase.first; chan; chan=chan->next){
-                       if(chan->ipo)
-                               dag_add_driver_relation(chan->ipo, dag, node, 1);
-                       for (conchan=chan->constraintChannels.first; conchan; conchan=conchan->next)
-                               if(conchan->ipo)
-                                       dag_add_driver_relation(conchan->ipo, dag, node, 1);
-               }
-       }
+#if 0 // XXX old animation system
        if(ob->nlastrips.first) {
                bActionStrip *strip;
                bActionChannel *chan;
                for(strip= ob->nlastrips.first; strip; strip= strip->next) {
-                       if(strip->act && strip->act!=ob->action)
-                               for (chan = strip->act->chanbase.first; chan; chan=chan->next)
-                                       if(chan->ipo)
-                                               dag_add_driver_relation(chan->ipo, dag, node, 1);
                        if(strip->modifiers.first) {
                                bActionModifier *amod;
                                for(amod= strip->modifiers.first; amod; amod= amod->next) {
@@ -462,13 +427,21 @@ static void build_dag_object(DagForest *dag, DagNode *scenenode, Object *ob, int
                        }
                }
        }
+#endif // XXX old animation system
+       if (ob->adt)
+               dag_add_driver_relation(ob->adt, dag, node, (ob->type == OB_ARMATURE)); // XXX isdata arg here doesn't give an accurate picture of situation
+               
+       key= ob_get_key(ob);
+       if (key && key->adt)
+               dag_add_driver_relation(key->adt, dag, node, 1);
+
        if (ob->modifiers.first) {
                ModifierData *md;
                
                for(md=ob->modifiers.first; md; md=md->next) {
                        ModifierTypeInfo *mti = modifierType_getInfo(md->type);
                        
-                       if (mti->updateDepgraph) mti->updateDepgraph(md, dag, ob, node);
+                       if (mti->updateDepgraph) mti->updateDepgraph(md, dag, scene, ob, node);
                }
        }
        if (ob->parent) {
@@ -491,8 +464,8 @@ static void build_dag_object(DagForest *dag, DagNode *scenenode, Object *ob, int
                                        else
                                                dag_add_relation(dag,node2,node,DAG_RL_OB_OB, "Curve Parent");
                                }
-                                       else
-                                               dag_add_relation(dag,node2,node,DAG_RL_OB_OB, "Curve Parent");
+                               else
+                                       dag_add_relation(dag,node2,node,DAG_RL_OB_OB, "Parent");
                }
                /* exception case: parent is duplivert */
                if(ob->type==OB_MBALL && (ob->parent->transflag & OB_DUPLIVERTS)) {
@@ -511,11 +484,12 @@ static void build_dag_object(DagForest *dag, DagNode *scenenode, Object *ob, int
                dag_add_relation(dag, node, node2, DAG_RL_DATA_DATA|DAG_RL_OB_OB, "Proxy");
                /* inverted relation, so addtoroot shouldn't be set to zero */
        }
+       
+
        if (ob->type==OB_CAMERA) {
                Camera *cam = (Camera *)ob->data;
-               if (cam->ipo) {
-                       dag_add_driver_relation(cam->ipo, dag, node, 1);
-               }
+               if (cam->adt)
+                       dag_add_driver_relation(cam->adt, dag, node, 1);
                if (cam->dof_ob) {
                        node2 = dag_get_node(dag, cam->dof_ob);
                        dag_add_relation(dag,node2,node,DAG_RL_OB_OB, "Camera DoF");
@@ -523,10 +497,10 @@ static void build_dag_object(DagForest *dag, DagNode *scenenode, Object *ob, int
        }
        if (ob->type==OB_LAMP) {
                Lamp *la = (Lamp *)ob->data;
-               if (la->ipo) {
-                       dag_add_driver_relation(la->ipo, dag, node, 1);
-               }
+               if (la->adt)
+                       dag_add_driver_relation(la->adt, dag, node, 1);
        }
+       
        if (ob->transflag & OB_DUPLI) {
                if((ob->transflag & OB_DUPLIGROUP) && ob->dup_group) {
                        GroupObject *go;
@@ -543,10 +517,10 @@ static void build_dag_object(DagForest *dag, DagNode *scenenode, Object *ob, int
        /* softbody collision  */
        if((ob->type==OB_MESH) || (ob->type==OB_CURVE) || (ob->type==OB_LATTICE))
                if(modifiers_isSoftbodyEnabled(ob) || modifiers_isClothEnabled(ob))
-                       dag_add_collision_field_relation(dag, ob, node);
+                       dag_add_collision_field_relation(dag, scene, ob, node);
                
        if (ob->type==OB_MBALL) {
-               Object *mom= find_basis_mball(ob);
+               Object *mom= find_basis_mball(scene, ob);
                if(mom!=ob) {
                        node2 = dag_get_node(dag, mom);
                        dag_add_relation(dag,node,node2,DAG_RL_DATA_DATA|DAG_RL_OB_DATA, "Metaball");  // mom depends on children!
@@ -562,9 +536,8 @@ static void build_dag_object(DagForest *dag, DagNode *scenenode, Object *ob, int
                        node2 = dag_get_node(dag, cu->taperobj);
                        dag_add_relation(dag,node2,node,DAG_RL_DATA_DATA|DAG_RL_OB_DATA, "Curve Taper");
                }
-               if(cu->ipo)
-                       dag_add_driver_relation(cu->ipo, dag, node, 1);
-
+               if (cu->adt)
+                       dag_add_driver_relation(cu->adt, dag, node, 1);
        }
        else if(ob->type==OB_FONT) {
                Curve *cu= ob->data;
@@ -609,7 +582,7 @@ static void build_dag_object(DagForest *dag, DagNode *scenenode, Object *ob, int
 
                        if(psys->effectors.first)
                                psys_end_effectors(psys);
-                       psys_init_effectors(ob,psys->part->eff_group,psys);
+                       psys_init_effectors(scene, ob, psys->part->eff_group, psys);
 
                        if(psys->effectors.first) {
                                for(nec= psys->effectors.first; nec; nec= nec->next) {
@@ -704,9 +677,9 @@ struct DagForest *build_dag(struct Scene *sce, short mask)
        for(base = sce->base.first; base; base= base->next) {
                ob= base->object;
                
-               build_dag_object(dag, scenenode, ob, mask);
+               build_dag_object(dag, scenenode, sce, ob, mask);
                if(ob->proxy)
-                       build_dag_object(dag, scenenode, ob->proxy, mask);
+                       build_dag_object(dag, scenenode, sce, ob->proxy, mask);
                
                /* handled in next loop */
                if(ob->dup_group) 
@@ -717,7 +690,7 @@ struct DagForest *build_dag(struct Scene *sce, short mask)
        for(group= G.main->group.first; group; group= group->id.next) {
                if(group->id.flag & LIB_DOIT) {
                        for(go= group->gobject.first; go; go= go->next) {
-                               build_dag_object(dag, scenenode, go->ob, mask);
+                               build_dag_object(dag, scenenode, sce, go->ob, mask);
                        }
                        group->id.flag &= ~LIB_DOIT;
                }
@@ -865,12 +838,12 @@ DagNode * dag_get_sub_node (DagForest *forest,void * fob)
        return node;
 }
 
-void dag_add_relation(DagForest *forest, DagNode *fob1, DagNode *fob2, short rel, char *name) 
+static void dag_add_parent_relation(DagForest *forest, DagNode *fob1, DagNode *fob2, short rel, char *name) 
 {
-       DagAdjList *itA = fob1->child;
+       DagAdjList *itA = fob2->parent;
        
        while (itA) { /* search if relation exist already */
-               if (itA->node == fob2) {
+               if (itA->node == fob1) {
                        itA->type |= rel;
                        itA->count += 1;
                        return;
@@ -879,20 +852,23 @@ void dag_add_relation(DagForest *forest, DagNode *fob1, DagNode *fob2, short rel
        }
        /* create new relation and insert at head. MALLOC alert! */
        itA = MEM_mallocN(sizeof(DagAdjList),"DAG adj list");
-       itA->node = fob2;
+       itA->node = fob1;
        itA->type = rel;
        itA->count = 1;
-       itA->next = fob1->child;
+       itA->next = fob2->parent;
        itA->name = name;
-       fob1->child = itA;
+       fob2->parent = itA;
 }
 
-static void dag_add_parent_relation(DagForest *forest, DagNode *fob1, DagNode *fob2, short rel, char *name) 
+void dag_add_relation(DagForest *forest, DagNode *fob1, DagNode *fob2, short rel, char *name) 
 {
-       DagAdjList *itA = fob2->parent;
+       DagAdjList *itA = fob1->child;
        
+       /* parent relation is for cycle checking */
+       dag_add_parent_relation(forest, fob1, fob2, rel, name);
+
        while (itA) { /* search if relation exist already */
-               if (itA->node == fob1) {
+               if (itA->node == fob2) {
                        itA->type |= rel;
                        itA->count += 1;
                        return;
@@ -901,12 +877,12 @@ static void dag_add_parent_relation(DagForest *forest, DagNode *fob1, DagNode *f
        }
        /* create new relation and insert at head. MALLOC alert! */
        itA = MEM_mallocN(sizeof(DagAdjList),"DAG adj list");
-       itA->node = fob1;
+       itA->node = fob2;
        itA->type = rel;
        itA->count = 1;
-       itA->next = fob2->parent;
+       itA->next = fob1->child;
        itA->name = name;
-       fob2->parent = itA;
+       fob1->child = itA;
 }
 
 static char *dag_node_name(DagNode *node)
@@ -966,6 +942,63 @@ static void dag_node_print_dependency_cycle(DagForest *dag, DagNode *startnode,
        printf("\n");
 }
 
+static int dag_node_recurs_level(DagNode *node, int level)
+{
+       DagAdjList *itA;
+       int newlevel;
+
+       node->color= DAG_BLACK; /* done */
+       newlevel= ++level;
+       
+       for(itA= node->parent; itA; itA= itA->next) {
+               if(itA->node->color==DAG_WHITE) {
+                       itA->node->ancestor_count= dag_node_recurs_level(itA->node, level);
+                       newlevel= MAX2(newlevel, level+itA->node->ancestor_count);
+               }
+               else
+                       newlevel= MAX2(newlevel, level+itA->node->ancestor_count);
+       }
+       
+       return newlevel;
+}
+
+static void dag_check_cycle(DagForest *dag)
+{
+       DagNode *node;
+       DagAdjList *itA;
+
+       /* tag nodes unchecked */
+       for(node = dag->DagNode.first; node; node= node->next)
+               node->color= DAG_WHITE;
+       
+       for(node = dag->DagNode.first; node; node= node->next) {
+               if(node->color==DAG_WHITE) {
+                       node->ancestor_count= dag_node_recurs_level(node, 0);
+               }
+       }
+       
+       /* check relations, and print errors */
+       for(node = dag->DagNode.first; node; node= node->next) {
+               for(itA= node->parent; itA; itA= itA->next) {
+                       if(itA->node->ancestor_count > node->ancestor_count) {
+                               if(node->ob && itA->node->ob) {
+                                       printf("Dependency cycle detected:\n");
+                                       dag_node_print_dependency_cycle(dag, itA->node, node, itA->name);
+                               }
+                       }
+               }
+       }
+
+       /* parent relations are only needed for cycle checking, so free now */
+       for(node = dag->DagNode.first; node; node= node->next) {
+               while (node->parent) {
+                       itA = node->parent->next;
+                       MEM_freeN(node->parent);                        
+                       node->parent = itA;
+               }
+       }
+}
+
 /*
  * MainDAG is the DAG of all objects in current scene
  * used only for drawing there is one also in each scene
@@ -1603,6 +1636,8 @@ void DAG_scene_sort(struct Scene *sce)
        
        build_dag(sce, DAG_RL_ALL_BUT_DATA);
        
+       dag_check_cycle(sce->theDag);
+
        nqueue = queue_create(DAGQUEUEALLOC);
        
        for(node = sce->theDag->DagNode.first; node; node= node->next) {
@@ -1699,7 +1734,7 @@ static void flush_update_node(DagNode *node, unsigned int layer, int curtime)
                for(itA = node->child; itA; itA= itA->next) {
                        all_layer |= itA->lay;
                        /* the relationship is visible */
-                       if((itA->lay & layer) || (itA->node->ob == G.obedit)) {
+                       if((itA->lay & layer)) { // XXX || (itA->node->ob == obedit)
                                if(itA->node->type==ID_OB) {
                                        obc= itA->node->ob;
                                        oldflag= obc->recalc;
@@ -1730,7 +1765,7 @@ static void flush_update_node(DagNode *node, unsigned int layer, int curtime)
                        }
                }
                /* even nicer, we can clear recalc flags...  */
-               if((all_layer & layer)==0 && (ob != G.obedit)) {
+               if((all_layer & layer)==0) { // XXX && (ob != obedit)) {
                        /* but existing displaylists or derivedmesh should be freed */
                        if(ob->recalc & OB_RECALC_DATA)
                                object_free_display(ob);
@@ -1744,7 +1779,7 @@ static void flush_update_node(DagNode *node, unsigned int layer, int curtime)
        /* could merge this in with loop above...? (ton) */
        for(itA = node->child; itA; itA= itA->next) {
                /* the relationship is visible */
-               if((itA->lay & layer) || (itA->node->ob == G.obedit)) {
+               if((itA->lay & layer)) {                // XXX  || (itA->node->ob == obedit)
                        if(itA->node->type==ID_OB) {
                                obc= itA->node->ob;
                                /* child moves */
@@ -1887,25 +1922,28 @@ static int object_modifiers_use_time(Object *ob)
        return 0;
 }
 
-static int exists_channel(Object *ob, char *name)
+static short animdata_use_time(AnimData *adt)
 {
-       bActionStrip *strip;
+       NlaTrack *nlt;
        
-       if(ob->action)
-               if(get_action_channel(ob->action, name))
-                       return 1;
+       if(adt==NULL) return 0;
+       
+       /* check action - only if assigned, and it has anim curves */
+       if (adt->action && adt->action->curves.first)
+               return 1;
        
-       for (strip=ob->nlastrips.first; strip; strip=strip->next)
-               if(get_action_channel(strip->act, name))
+       /* check NLA tracks + strips */
+       for (nlt= adt->nla_tracks.first; nlt; nlt= nlt->next) {
+               if (nlt->strips.first)
                        return 1;
+       }
+       
        return 0;
 }
 
 static void dag_object_time_update_flags(Object *ob)
 {
-       
-       if(ob->ipo) ob->recalc |= OB_RECALC_OB;
-       else if(ob->constraints.first) {
+       if(ob->constraints.first) {
                bConstraint *con;
                for (con = ob->constraints.first; con; con=con->next) {
                        bConstraintTypeInfo *cti= constraint_get_typeinfo(con);
@@ -1935,14 +1973,9 @@ static void dag_object_time_update_flags(Object *ob)
                if(ob->parent->type==OB_CURVE || ob->parent->type==OB_ARMATURE) ob->recalc |= OB_RECALC_OB;
        }
        
-       if(ob->action || ob->nlastrips.first) {
-               /* since actions now are mixed, we set the recalcs on the safe side */
-               ob->recalc |= OB_RECALC_OB;
-               if(ob->type==OB_ARMATURE)
-                       ob->recalc |= OB_RECALC_DATA;
-               else if(exists_channel(ob, "Shape"))
-                       ob->recalc |= OB_RECALC_DATA;
-               else if(ob->dup_group) {
+#if 0 // XXX old animation system
+       if(ob->nlastrips.first) {
+               if(ob->dup_group) {
                        bActionStrip *strip;
                        /* this case is for groups with nla, whilst nla target has no action or nla */
                        for(strip= ob->nlastrips.first; strip; strip= strip->next) {
@@ -1951,6 +1984,14 @@ static void dag_object_time_update_flags(Object *ob)
                        }
                }
        }
+#endif // XXX old animation system
+       
+       if(animdata_use_time(ob->adt)) {
+               ob->recalc |= OB_RECALC;
+               ob->adt->recalc |= ADT_RECALC_ANIM;
+       }
+       
+       if((ob->adt) && (ob->type==OB_ARMATURE)) ob->recalc |= OB_RECALC_DATA;
        
        if(object_modifiers_use_time(ob)) ob->recalc |= OB_RECALC_DATA;
        if((ob->pose) && (ob->pose->flag & POSE_CONSTRAINTS_TIMEDEPEND)) ob->recalc |= OB_RECALC_DATA;
@@ -1969,12 +2010,6 @@ static void dag_object_time_update_flags(Object *ob)
                                                ob->shapeflag &= ~OB_SHAPE_TEMPLOCK;
                                        }
                                }
-                               if((ob->fluidsimFlag & OB_FLUIDSIM_ENABLE) && (ob->fluidsimSettings)) {
-                                       // fluidsimSettings might not be initialized during load...
-                                       if(ob->fluidsimSettings->type & (OB_FLUIDSIM_DOMAIN|OB_FLUIDSIM_PARTICLE)) {
-                                               ob->recalc |= OB_RECALC_DATA; // NT FSPARTICLE
-                                       }
-                               }
                                if(ob->particlesystem.first)
                                        ob->recalc |= OB_RECALC_DATA;
                                break;
@@ -2078,22 +2113,6 @@ void DAG_scene_update_flags(Scene *scene, unsigned int lay)
        
 }
 
-/* for depgraph updating, all layers visible in a screen */
-/* this is a copy from editscreen.c... I need to think over a more proper solution for this */
-/* probably the DAG_object_flush_update() should give layer too? */
-/* or some kind of dag context... (DAG_set_layer) */
-static unsigned int dag_screen_view3d_layers(void)
-{
-       ScrArea *sa;
-       int layer= 0;
-       
-       for(sa= G.curscreen->areabase.first; sa; sa= sa->next) {
-               if(sa->spacetype==SPACE_VIEW3D)
-                       layer |= ((View3D *)sa->spacedata.first)->lay;
-       }
-       return layer;
-}
-
 
 /* flag this object and all its relations to recalc */
 /* if you need to do more objects, tag object yourself and
@@ -2127,9 +2146,9 @@ void DAG_object_flush_update(Scene *sce, Object *ob, short flag)
                }
        }
        
-       if(G.curscreen)
-               DAG_scene_flush_update(sce, dag_screen_view3d_layers(), 0);
-       else
+// XXX if(G.curscreen)
+//             DAG_scene_flush_update(sce, dag_screen_view3d_layers(), 0);
+//     else
                DAG_scene_flush_update(sce, sce->lay, 0);
 }
 
@@ -2212,57 +2231,6 @@ void DAG_object_update_flags(Scene *sce, Object *ob, unsigned int lay)
 
 /* ******************* DAG FOR ARMATURE POSE ***************** */
 
-static int node_recurs_level(DagNode *node, int level)
-{
-       DagAdjList *itA;
-       int newlevel;
-
-       node->color= DAG_BLACK; /* done */
-       newlevel= ++level;
-       
-       for(itA= node->parent; itA; itA= itA->next) {
-               if(itA->node->color==DAG_WHITE) {
-                       itA->node->ancestor_count= node_recurs_level(itA->node, level);
-                       newlevel= MAX2(newlevel, level+itA->node->ancestor_count);
-               }
-               else
-                       newlevel= MAX2(newlevel, level+itA->node->ancestor_count);
-       }
-       
-       return newlevel;
-}
-
-static void pose_check_cycle(DagForest *dag)
-{
-       DagNode *node;
-       DagAdjList *itA;
-
-       /* tag nodes unchecked */
-       for(node = dag->DagNode.first; node; node= node->next)
-               node->color= DAG_WHITE;
-       
-       for(node = dag->DagNode.first; node; node= node->next) {
-               if(node->color==DAG_WHITE) {
-                       node->ancestor_count= node_recurs_level(node, 0);
-               }
-       }
-       
-       /* check relations, and print errors */
-       for(node = dag->DagNode.first; node; node= node->next) {
-               for(itA= node->parent; itA; itA= itA->next) {
-                       if(itA->node->ancestor_count > node->ancestor_count) {
-                               bPoseChannel *pchan= (bPoseChannel *)node->ob;
-                               bPoseChannel *parchan= (bPoseChannel *)itA->node->ob;
-                               
-                               if(pchan && parchan)  {
-                                       printf("Cycle detected:\n");
-                                       dag_node_print_dependency_cycle(dag, itA->node, node, itA->name);
-                               }
-                       }
-               }
-       }
-}
-
 /* we assume its an armature with pose */
 void DAG_pose_sort(Object *ob)
 {
@@ -2292,7 +2260,6 @@ void DAG_pose_sort(Object *ob)
                if(pchan->parent) {
                        node2 = dag_get_node(dag, pchan->parent);
                        dag_add_relation(dag, node2, node, 0, "Parent Relation");
-                       dag_add_parent_relation(dag, node2, node, 0, "Parent Relation");
                        addtoroot = 0;
                }
                for (con = pchan->constraints.first; con; con=con->next) {
@@ -2300,6 +2267,7 @@ void DAG_pose_sort(Object *ob)
                        ListBase targets = {NULL, NULL};
                        bConstraintTarget *ct;
                        
+#if 0 // XXX old animation system... driver stuff to watch out for
                        if(con->ipo) {
                                IpoCurve *icu;
                                for(icu= con->ipo->curve.first; icu; icu= icu->next) {
@@ -2311,8 +2279,7 @@ void DAG_pose_sort(Object *ob)
                                                if(target) {
                                                        node2 = dag_get_node(dag, target);
                                                        dag_add_relation(dag, node2, node, 0, "Ipo Driver");
-                                                       dag_add_parent_relation(dag, node2, node, 0, "Ipo Driver");
-
+                                                       
                                                        /* uncommented this line, results in dependencies
                                                         * not being added properly for this constraint,
                                                         * what is the purpose of this? - brecht */
@@ -2321,6 +2288,7 @@ void DAG_pose_sort(Object *ob)
                                        }
                                }
                        }
+#endif // XXX old animation system... driver stuff to watch out for
                        
                        if (cti && cti->get_constraint_targets) {
                                cti->get_constraint_targets(con, &targets);
@@ -2331,7 +2299,6 @@ void DAG_pose_sort(Object *ob)
                                                if (target) {
                                                        node2= dag_get_node(dag, target);
                                                        dag_add_relation(dag, node2, node, 0, "IK Constraint");
-                                                       dag_add_parent_relation(dag, node2, node, 0, "IK Constraint");
 
                                                        if (con->type==CONSTRAINT_TYPE_KINEMATIC) {
                                                                bKinematicConstraint *data = (bKinematicConstraint *)con->data;
@@ -2348,7 +2315,6 @@ void DAG_pose_sort(Object *ob)
                                                                while (parchan) {
                                                                        node3= dag_get_node(dag, parchan);
                                                                        dag_add_relation(dag, node2, node3, 0, "IK Constraint");
-                                                                       dag_add_parent_relation(dag, node2, node3, 0, "IK Constraint");
                                                                        
                                                                        segcount++;
                                                                        if (segcount==data->rootbone || segcount>255) break; // 255 is weak
@@ -2365,11 +2331,10 @@ void DAG_pose_sort(Object *ob)
                }
                if (addtoroot == 1 ) {
                        dag_add_relation(dag, rootnode, node, 0, "Root Bone Relation");
-                       dag_add_parent_relation(dag, rootnode, node, 0, "Root Bone Relation");
                }
        }
 
-       pose_check_cycle(dag);
+       dag_check_cycle(dag);
        
        /* now we try to sort... */
        tempbase.first= tempbase.last= NULL;