From 20220d47e38c4ad22ad89481fd40b804cc2fd1ef Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Thu, 21 Feb 2013 19:33:04 +0000 Subject: Dependency Graph: some refactoring which should have no user visible impact besides performance in some cases. * DAG_scene_sort is now removed and replaced by DAG_relations_tag_update in most cases. This will clear the dependency graph, and only rebuild it right before it's needed again when the scene is re-evaluated. This is done because DAG_scene_sort is slow when called many times from python operators. Further the scene argument is not needed because most operations can potentially affect more than the current scene. * DAG_scene_relations_update will now rebuild the dependency graph if it's not there yet, and DAG_scene_relations_rebuild will force a rebuild for the rare cases that need it. * Remove various places where ob->recalc was set manually. This should go through DAG_id_tag_update() in nearly all cases instead since this is now a fast operation. Also removed DAG_ids_flush_update that goes along with such manual tagging of ob->recalc. --- source/blender/blenkernel/intern/depsgraph.c | 57 ++++++++++++++++++---------- 1 file changed, 38 insertions(+), 19 deletions(-) (limited to 'source/blender/blenkernel/intern/depsgraph.c') diff --git a/source/blender/blenkernel/intern/depsgraph.c b/source/blender/blenkernel/intern/depsgraph.c index 99d0c5ed964..56600069aa0 100644 --- a/source/blender/blenkernel/intern/depsgraph.c +++ b/source/blender/blenkernel/intern/depsgraph.c @@ -837,7 +837,6 @@ DagForest *build_dag(Main *bmain, Scene *sce, short mask) DagAdjList *itA; dag = sce->theDag; - sce->dagisvalid = 1; if (dag) free_forest(dag); else { @@ -1846,8 +1845,18 @@ static void scene_sort_groups(Main *bmain, Scene *sce) } } +/* free the depency graph */ +static void dag_scene_free(Scene *sce) +{ + if (sce->theDag) { + free_forest(sce->theDag); + MEM_freeN(sce->theDag); + sce->theDag = NULL; + } +} + /* sort the base list on dependency order */ -void DAG_scene_sort(Main *bmain, Scene *sce) +static void dag_scene_build(Main *bmain, Scene *sce) { DagNode *node, *rootnode; DagNodeQueue *nqueue; @@ -1856,7 +1865,7 @@ void DAG_scene_sort(Main *bmain, Scene *sce) int skip = 0; ListBase tempbase; Base *base; - + tempbase.first = tempbase.last = NULL; build_dag(bmain, sce, DAG_RL_ALL_BUT_DATA); @@ -1936,10 +1945,34 @@ void DAG_scene_sort(Main *bmain, Scene *sce) printf(" %s\n", base->object->id.name); } } + /* temporal...? */ sce->recalc |= SCE_PRV_CHANGED; /* test for 3d preview */ } +/* clear all dependency graphs */ +void DAG_relations_tag_update(Main *bmain) +{ + Scene *sce; + + for (sce = bmain->scene.first; sce; sce = sce->id.next) + dag_scene_free(sce); +} + +/* rebuild dependency graph only for a given scene */ +void DAG_scene_relations_rebuild(Main *bmain, Scene *sce) +{ + dag_scene_free(sce); + DAG_scene_relations_update(bmain, sce); +} + +/* create dependency graph if it was cleared or didn't exist yet */ +void DAG_scene_relations_update(Main *bmain, Scene *sce) +{ + if (!sce->theDag) + dag_scene_build(bmain, sce); +} + static void lib_id_recalc_tag(Main *bmain, ID *id) { id->flag |= LIB_ID_RECALC; @@ -2177,7 +2210,7 @@ void DAG_scene_flush_update(Main *bmain, Scene *sce, unsigned int lay, const sho if (sce->theDag == NULL) { printf("DAG zero... not allowed to happen!\n"); - DAG_scene_sort(bmain, sce); + DAG_scene_relations_update(bmain, sce); } firstnode = sce->theDag->DagNode.first; /* always scene node */ @@ -2545,20 +2578,6 @@ static void dag_current_scene_layers(Main *bmain, ListBase *lb) } } -void DAG_ids_flush_update(Main *bmain, int time) -{ - ListBase listbase; - DagSceneLayer *dsl; - - /* get list of visible scenes and layers */ - dag_current_scene_layers(bmain, &listbase); - - for (dsl = listbase.first; dsl; dsl = dsl->next) - DAG_scene_flush_update(bmain, dsl->scene, dsl->layer, time); - - BLI_freelistN(&listbase); -} - void DAG_on_visible_update(Main *bmain, const short do_time) { ListBase listbase; @@ -3169,7 +3188,7 @@ void DAG_print_dependencies(Main *bmain, Scene *scene, Object *ob) } else { printf("\nDEPENDENCY RELATIONS for %s\n\n", scene->id.name + 2); - DAG_scene_sort(bmain, scene); + DAG_scene_relations_rebuild(bmain, scene); } dag_print_dependencies = 0; -- cgit v1.2.3