diff options
Diffstat (limited to 'source/blender/depsgraph/intern')
33 files changed, 1538 insertions, 1767 deletions
diff --git a/source/blender/depsgraph/intern/builder/deg_builder.cc b/source/blender/depsgraph/intern/builder/deg_builder.cc index aedd00685b3..e3494e4756e 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder.cc +++ b/source/blender/depsgraph/intern/builder/deg_builder.cc @@ -30,15 +30,13 @@ #include "intern/builder/deg_builder.h" -// TODO(sergey): Use own wrapper over STD. -#include <stack> - #include "DNA_anim_types.h" #include "DNA_object_types.h" #include "DNA_ID.h" #include "BLI_utildefines.h" #include "BLI_ghash.h" +#include "BLI_stack.h" #include "intern/depsgraph.h" #include "intern/depsgraph_types.h" @@ -52,14 +50,6 @@ namespace DEG { -string deg_fcurve_id_name(const FCurve *fcu) -{ - char index_buf[32]; - // TODO(sergey): Use int-to-string utility or so. - BLI_snprintf(index_buf, sizeof(index_buf), "[%d]", fcu->array_index); - return string(fcu->rna_path) + index_buf; -} - static bool check_object_needs_evaluation(Object *object) { if (object->recalc & OB_RECALC_ALL) { @@ -77,72 +67,79 @@ static bool check_object_needs_evaluation(Object *object) return false; } -void deg_graph_build_finalize(Depsgraph *graph) +void deg_graph_build_flush_layers(Depsgraph *graph) { - /* STEP 1: Make sure new invisible dependencies are ready for use. - * - * TODO(sergey): This might do a bit of extra tagging, but it's kinda nice - * to do it ahead of a time and don't spend time on flushing updates on - * every frame change. - */ - GHASH_FOREACH_BEGIN(IDDepsNode *, id_node, graph->id_hash) - { - if (id_node->layers == 0) { - ID *id = id_node->id; - if (GS(id->name) == ID_OB) { - Object *object = (Object *)id; - if (check_object_needs_evaluation(object)) { - id_node->tag_update(graph); - } - } - } - } - GHASH_FOREACH_END(); - /* STEP 2: Flush visibility layers from children to parent. */ - std::stack<OperationDepsNode *> stack; + BLI_Stack *stack = BLI_stack_new(sizeof(OperationDepsNode *), + "DEG flush layers stack"); foreach (OperationDepsNode *node, graph->operations) { IDDepsNode *id_node = node->owner->owner; node->done = 0; node->num_links_pending = 0; foreach (DepsRelation *rel, node->outlinks) { - if ((rel->from->type == DEPSNODE_TYPE_OPERATION) && + if ((rel->from->type == DEG_NODE_TYPE_OPERATION) && (rel->flag & DEPSREL_FLAG_CYCLIC) == 0) { ++node->num_links_pending; } } if (node->num_links_pending == 0) { - stack.push(node); + BLI_stack_push(stack, &node); node->done = 1; } node->owner->layers = id_node->layers; id_node->id->tag |= LIB_TAG_DOIT; } - while (!stack.empty()) { - OperationDepsNode *node = stack.top(); - stack.pop(); + while (!BLI_stack_is_empty(stack)) { + OperationDepsNode *node; + BLI_stack_pop(stack, &node); /* Flush layers to parents. */ foreach (DepsRelation *rel, node->inlinks) { - if (rel->from->type == DEPSNODE_TYPE_OPERATION) { + if (rel->from->type == DEG_NODE_TYPE_OPERATION) { OperationDepsNode *from = (OperationDepsNode *)rel->from; from->owner->layers |= node->owner->layers; } } /* Schedule parent nodes. */ foreach (DepsRelation *rel, node->inlinks) { - if (rel->from->type == DEPSNODE_TYPE_OPERATION) { + if (rel->from->type == DEG_NODE_TYPE_OPERATION) { OperationDepsNode *from = (OperationDepsNode *)rel->from; if ((rel->flag & DEPSREL_FLAG_CYCLIC) == 0) { BLI_assert(from->num_links_pending > 0); --from->num_links_pending; } if (from->num_links_pending == 0 && from->done == 0) { - stack.push(from); + BLI_stack_push(stack, &from); from->done = 1; } } } } + BLI_stack_free(stack); +} + +void deg_graph_build_finalize(Depsgraph *graph) +{ + /* STEP 1: Make sure new invisible dependencies are ready for use. + * + * TODO(sergey): This might do a bit of extra tagging, but it's kinda nice + * to do it ahead of a time and don't spend time on flushing updates on + * every frame change. + */ + GHASH_FOREACH_BEGIN(IDDepsNode *, id_node, graph->id_hash) + { + if (id_node->layers == 0) { + ID *id = id_node->id; + if (GS(id->name) == ID_OB) { + Object *object = (Object *)id; + if (check_object_needs_evaluation(object)) { + id_node->tag_update(graph); + } + } + } + } + GHASH_FOREACH_END(); + /* STEP 2: Flush visibility layers from children to parent. */ + deg_graph_build_flush_layers(graph); /* STEP 3: Re-tag IDs for update if it was tagged before the relations * update tag. */ @@ -154,19 +151,21 @@ void deg_graph_build_finalize(Depsgraph *graph) } GHASH_FOREACH_END(); - ID *id = id_node->id; - if ((id->tag & LIB_TAG_ID_RECALC_ALL) && - (id->tag & LIB_TAG_DOIT)) - { - id_node->tag_update(graph); - id->tag &= ~LIB_TAG_DOIT; - } - else if (GS(id->name) == ID_OB) { - Object *object = (Object *)id; - if (object->recalc & OB_RECALC_ALL) { + if ((id_node->layers & graph->layers) != 0 || graph->layers == 0) { + ID *id = id_node->id; + if ((id->tag & LIB_TAG_ID_RECALC_ALL) && + (id->tag & LIB_TAG_DOIT)) + { id_node->tag_update(graph); id->tag &= ~LIB_TAG_DOIT; } + else if (GS(id->name) == ID_OB) { + Object *object = (Object *)id; + if (object->recalc & OB_RECALC_ALL) { + id_node->tag_update(graph); + id->tag &= ~LIB_TAG_DOIT; + } + } } id_node->finalize_build(); } diff --git a/source/blender/depsgraph/intern/builder/deg_builder.h b/source/blender/depsgraph/intern/builder/deg_builder.h index bdc030e3810..b8ea8c8e599 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder.h +++ b/source/blender/depsgraph/intern/builder/deg_builder.h @@ -38,9 +38,7 @@ namespace DEG { struct Depsgraph; -/* Get unique identifier for FCurves and Drivers */ -string deg_fcurve_id_name(const FCurve *fcu); - void deg_graph_build_finalize(struct Depsgraph *graph); +void deg_graph_build_flush_layers(struct Depsgraph *graph); } // namespace DEG diff --git a/source/blender/depsgraph/intern/builder/deg_builder_cycle.cc b/source/blender/depsgraph/intern/builder/deg_builder_cycle.cc index 9b37aaa12ff..3eed0697b5e 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder_cycle.cc +++ b/source/blender/depsgraph/intern/builder/deg_builder_cycle.cc @@ -32,11 +32,9 @@ // TOO(sergey): Use some wrappers over those? #include <cstdio> #include <cstdlib> -#include <stack> -extern "C" { #include "BLI_utildefines.h" -} +#include "BLI_stack.h" #include "util/deg_util_foreach.h" @@ -48,12 +46,6 @@ extern "C" { namespace DEG { -struct StackEntry { - OperationDepsNode *node; - StackEntry *from; - DepsRelation *via_relation; -}; - void deg_graph_detect_cycles(Depsgraph *graph) { enum { @@ -65,11 +57,19 @@ void deg_graph_detect_cycles(Depsgraph *graph) NODE_IN_STACK = 2, }; - std::stack<StackEntry> traversal_stack; + struct StackEntry { + OperationDepsNode *node; + StackEntry *from; + DepsRelation *via_relation; + }; + + BLI_Stack *traversal_stack = BLI_stack_new(sizeof(StackEntry), + "DEG detect cycles stack"); + foreach (OperationDepsNode *node, graph->operations) { bool has_inlinks = false; foreach (DepsRelation *rel, node->inlinks) { - if (rel->from->type == DEPSNODE_TYPE_OPERATION) { + if (rel->from->type == DEG_NODE_TYPE_OPERATION) { has_inlinks = true; } } @@ -78,7 +78,7 @@ void deg_graph_detect_cycles(Depsgraph *graph) entry.node = node; entry.from = NULL; entry.via_relation = NULL; - traversal_stack.push(entry); + BLI_stack_push(traversal_stack, &entry); node->tag = NODE_IN_STACK; } else { @@ -87,13 +87,13 @@ void deg_graph_detect_cycles(Depsgraph *graph) node->done = 0; } - while (!traversal_stack.empty()) { - StackEntry& entry = traversal_stack.top(); - OperationDepsNode *node = entry.node; + while (!BLI_stack_is_empty(traversal_stack)) { + StackEntry *entry = (StackEntry *)BLI_stack_peek(traversal_stack); + OperationDepsNode *node = entry->node; bool all_child_traversed = true; for (int i = node->done; i < node->outlinks.size(); ++i) { DepsRelation *rel = node->outlinks[i]; - if (rel->to->type == DEPSNODE_TYPE_OPERATION) { + if (rel->to->type == DEG_NODE_TYPE_OPERATION) { OperationDepsNode *to = (OperationDepsNode *)rel->to; if (to->tag == NODE_IN_STACK) { printf("Dependency cycle detected:\n"); @@ -102,7 +102,7 @@ void deg_graph_detect_cycles(Depsgraph *graph) node->full_identifier().c_str(), rel->name); - StackEntry *current = &entry; + StackEntry *current = entry; while (current->node != to) { BLI_assert(current != NULL); printf(" '%s' depends on '%s' through '%s'\n", @@ -117,9 +117,9 @@ void deg_graph_detect_cycles(Depsgraph *graph) else if (to->tag == NODE_NOT_VISITED) { StackEntry new_entry; new_entry.node = to; - new_entry.from = &entry; + new_entry.from = entry; new_entry.via_relation = rel; - traversal_stack.push(new_entry); + BLI_stack_push(traversal_stack, &new_entry); to->tag = NODE_IN_STACK; all_child_traversed = false; node->done = i; @@ -129,9 +129,11 @@ void deg_graph_detect_cycles(Depsgraph *graph) } if (all_child_traversed) { node->tag = NODE_VISITED; - traversal_stack.pop(); + BLI_stack_discard(traversal_stack); } } + + BLI_stack_free(traversal_stack); } } // namespace DEG diff --git a/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc b/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc index e312c4e0dcb..17f0c030bd0 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc +++ b/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc @@ -37,11 +37,11 @@ #include "MEM_guardedalloc.h" -extern "C" { #include "BLI_blenlib.h" #include "BLI_string.h" #include "BLI_utildefines.h" +extern "C" { #include "DNA_action_types.h" #include "DNA_anim_types.h" #include "DNA_armature_types.h" @@ -81,6 +81,7 @@ extern "C" { #include "BKE_lattice.h" #include "BKE_library.h" #include "BKE_main.h" +#include "BKE_mask.h" #include "BKE_material.h" #include "BKE_mesh.h" #include "BKE_mball.h" @@ -94,13 +95,13 @@ extern "C" { #include "BKE_tracking.h" #include "BKE_world.h" -#include "DEG_depsgraph.h" -#include "DEG_depsgraph_build.h" - #include "RNA_access.h" #include "RNA_types.h" } /* extern "C" */ +#include "DEG_depsgraph.h" +#include "DEG_depsgraph_build.h" + #include "intern/builder/deg_builder.h" #include "intern/nodes/deg_node.h" #include "intern/nodes/deg_node_component.h" @@ -121,7 +122,7 @@ struct BuilderWalkUserData { static void modifier_walk(void *user_data, struct Object * /*ob*/, struct Object **obpoin, - int /*cd_flag*/) + int /*cb_flag*/) { BuilderWalkUserData *data = (BuilderWalkUserData *)user_data; if (*obpoin) { @@ -160,55 +161,14 @@ DepsgraphNodeBuilder::~DepsgraphNodeBuilder() { } -RootDepsNode *DepsgraphNodeBuilder::add_root_node() -{ - return m_graph->add_root_node(); -} - IDDepsNode *DepsgraphNodeBuilder::add_id_node(ID *id) { return m_graph->add_id_node(id, id->name); } -TimeSourceDepsNode *DepsgraphNodeBuilder::add_time_source(ID *id) +TimeSourceDepsNode *DepsgraphNodeBuilder::add_time_source() { - /* determine which node to attach timesource to */ - if (id) { -#if 0 /* XXX TODO */ - /* get ID node */ - IDDepsNode id_node = m_graph->find_id_node(id); - - /* depends on what this is... */ - switch (GS(id->name)) { - case ID_SCE: /* Scene - Usually sequencer strip causing time remapping... */ - { - // TODO... - } - break; - - case ID_GR: /* Group */ - { - // TODO... - } - break; - - // XXX: time source... - - default: /* Unhandled */ - printf("%s(): Unhandled ID - %s \n", __func__, id->name); - break; - } -#endif - } - else { - /* root-node */ - RootDepsNode *root_node = m_graph->root_node; - if (root_node) { - return root_node->add_time_source("Time Source"); - } - } - - return NULL; + return m_graph->add_time_source(); } ComponentDepsNode *DepsgraphNodeBuilder::add_component_node( @@ -224,8 +184,7 @@ ComponentDepsNode *DepsgraphNodeBuilder::add_component_node( OperationDepsNode *DepsgraphNodeBuilder::add_operation_node( ComponentDepsNode *comp_node, - eDepsOperation_Type optype, - DepsEvalOperationCb op, + const DepsEvalOperationCb& op, eDepsOperation_Code opcode, const char *name, int name_tag) @@ -234,7 +193,7 @@ OperationDepsNode *DepsgraphNodeBuilder::add_operation_node( name, name_tag); if (op_node == NULL) { - op_node = comp_node->add_operation(optype, op, opcode, name, name_tag); + op_node = comp_node->add_operation(op, opcode, name, name_tag); m_graph->operations.push_back(op_node); } else { @@ -252,21 +211,19 @@ OperationDepsNode *DepsgraphNodeBuilder::add_operation_node( ID *id, eDepsNode_Type comp_type, const char *comp_name, - eDepsOperation_Type optype, - DepsEvalOperationCb op, + const DepsEvalOperationCb& op, eDepsOperation_Code opcode, const char *name, int name_tag) { ComponentDepsNode *comp_node = add_component_node(id, comp_type, comp_name); - return add_operation_node(comp_node, optype, op, opcode, name, name_tag); + return add_operation_node(comp_node, op, opcode, name, name_tag); } OperationDepsNode *DepsgraphNodeBuilder::add_operation_node( ID *id, eDepsNode_Type comp_type, - eDepsOperation_Type optype, - DepsEvalOperationCb op, + const DepsEvalOperationCb& op, eDepsOperation_Code opcode, const char *name, int name_tag) @@ -274,7 +231,6 @@ OperationDepsNode *DepsgraphNodeBuilder::add_operation_node( return add_operation_node(id, comp_type, "", - optype, op, opcode, name, @@ -320,6 +276,23 @@ OperationDepsNode *DepsgraphNodeBuilder::find_operation_node( /* **** Build functions for entity nodes **** */ +void DepsgraphNodeBuilder::begin_build(Main *bmain) { + /* LIB_TAG_DOIT is used to indicate whether node for given ID was already + * created or not. This flag is being set in add_id_node(), so functions + * shouldn't bother with setting it, they only might query this flag when + * needed. + */ + BKE_main_id_tag_all(bmain, LIB_TAG_DOIT, false); + /* XXX nested node trees are not included in tag-clearing above, + * so we need to do this manually. + */ + FOREACH_NODETREE(bmain, nodetree, id) { + if (id != (ID *)nodetree) { + nodetree->id.tag &= ~LIB_TAG_DOIT; + } + } FOREACH_NODETREE_END +} + void DepsgraphNodeBuilder::build_group(Scene *scene, Base *base, Group *group) @@ -335,41 +308,6 @@ void DepsgraphNodeBuilder::build_group(Scene *scene, } } -SubgraphDepsNode *DepsgraphNodeBuilder::build_subgraph(Group *group) -{ - /* sanity checks */ - if (!group) - return NULL; - - /* create new subgraph's data */ - Depsgraph *subgraph = reinterpret_cast<Depsgraph *>(DEG_graph_new()); - - DepsgraphNodeBuilder subgraph_builder(m_bmain, subgraph); - - /* add group objects */ - LINKLIST_FOREACH (GroupObject *, go, &group->gobject) { - /*Object *ob = go->ob;*/ - - /* Each "group object" is effectively a separate instance of the - * underlying object data. When the group is evaluated, the transform - * results and/or some other attributes end up getting overridden by - * the group. - */ - } - - /* Create a node for representing subgraph. */ - SubgraphDepsNode *subgraph_node = m_graph->add_subgraph_node(&group->id); - subgraph_node->graph = subgraph; - - /* Make a copy of the data this node will need? */ - /* XXX: do we do this now, or later? */ - /* TODO: need API function which queries graph's ID's hash, and duplicates - * those blocks thoroughly with all outside links removed. - */ - - return subgraph_node; -} - void DepsgraphNodeBuilder::build_object(Scene *scene, Base *base, Object *ob) { const bool has_object = (ob->id.tag & LIB_TAG_DOIT); @@ -383,8 +321,11 @@ void DepsgraphNodeBuilder::build_object(Scene *scene, Base *base, Object *ob) if (base != NULL) { id_node->layers |= base->lay; } - if (ob == scene->camera) { - /* Camera should always be updated, it used directly by viewport. */ + if (ob->type == OB_CAMERA) { + /* Camera should always be updated, it used directly by viewport. + * + * TODO(sergey): Make it only for active scene camera. + */ id_node->layers |= (unsigned int)(-1); } /* Skip rest of components if the ID node was already there. */ @@ -410,12 +351,11 @@ void DepsgraphNodeBuilder::build_object(Scene *scene, Base *base, Object *ob) BuilderWalkUserData data; data.builder = this; data.scene = scene; - modifiers_foreachObjectLink(ob, modifier_walk, &data); BKE_constraints_id_loop(&ob->constraints, constraint_walk, &data); } /* Object data. */ - if (ob->data) { + if (ob->data != NULL) { /* type-specific data... */ switch (ob->type) { case OB_MESH: /* Geometry */ @@ -473,27 +413,41 @@ void DepsgraphNodeBuilder::build_object(Scene *scene, Base *base, Object *ob) build_animdata(&ob->id); /* particle systems */ - if (ob->particlesystem.first) { + if (ob->particlesystem.first != NULL) { build_particles(scene, ob); } - /* grease pencil */ - if (ob->gpd) { + /* Grease pencil. */ + if (ob->gpd != NULL) { build_gpencil(ob->gpd); } + + /* Object that this is a proxy for. */ + if (ob->proxy) { + ob->proxy->proxy_from = ob; + build_object(scene, base, ob->proxy); + } + + /* Object dupligroup. */ + if (ob->dup_group != NULL) { + build_group(scene, base, ob->dup_group); + } } void DepsgraphNodeBuilder::build_object_transform(Scene *scene, Object *ob) { + OperationDepsNode *op_node; + /* local transforms (from transform channels - loc/rot/scale + deltas) */ - add_operation_node(&ob->id, DEPSNODE_TYPE_TRANSFORM, - DEPSOP_TYPE_INIT, function_bind(BKE_object_eval_local_transform, _1, scene, ob), - DEG_OPCODE_TRANSFORM_LOCAL); + op_node = add_operation_node(&ob->id, DEG_NODE_TYPE_TRANSFORM, + function_bind(BKE_object_eval_local_transform, _1, scene, ob), + DEG_OPCODE_TRANSFORM_LOCAL); + op_node->set_as_entry(); /* object parent */ if (ob->parent) { - add_operation_node(&ob->id, DEPSNODE_TYPE_TRANSFORM, - DEPSOP_TYPE_EXEC, function_bind(BKE_object_eval_parent, _1, scene, ob), + add_operation_node(&ob->id, DEG_NODE_TYPE_TRANSFORM, + function_bind(BKE_object_eval_parent, _1, scene, ob), DEG_OPCODE_TRANSFORM_PARENT); } @@ -509,14 +463,15 @@ void DepsgraphNodeBuilder::build_object_transform(Scene *scene, Object *ob) * * TODO(sergey): Get rid of this node. */ - add_operation_node(&ob->id, DEPSNODE_TYPE_TRANSFORM, - DEPSOP_TYPE_EXEC, function_bind(BKE_object_eval_uber_transform, _1, scene, ob), + add_operation_node(&ob->id, DEG_NODE_TYPE_TRANSFORM, + function_bind(BKE_object_eval_uber_transform, _1, scene, ob), DEG_OPCODE_OBJECT_UBEREVAL); /* object transform is done */ - add_operation_node(&ob->id, DEPSNODE_TYPE_TRANSFORM, - DEPSOP_TYPE_POST, function_bind(BKE_object_eval_done, _1, ob), - DEG_OPCODE_TRANSFORM_FINAL); + op_node = add_operation_node(&ob->id, DEG_NODE_TYPE_TRANSFORM, + function_bind(BKE_object_eval_done, _1, ob), + DEG_OPCODE_TRANSFORM_FINAL); + op_node->set_as_exit(); } /** @@ -539,8 +494,8 @@ void DepsgraphNodeBuilder::build_object_transform(Scene *scene, Object *ob) void DepsgraphNodeBuilder::build_object_constraints(Scene *scene, Object *ob) { /* create node for constraint stack */ - add_operation_node(&ob->id, DEPSNODE_TYPE_TRANSFORM, - DEPSOP_TYPE_EXEC, function_bind(BKE_object_eval_constraints, _1, scene, ob), + add_operation_node(&ob->id, DEG_NODE_TYPE_TRANSFORM, + function_bind(BKE_object_eval_constraints, _1, scene, ob), DEG_OPCODE_TRANSFORM_CONSTRAINTS); } @@ -562,8 +517,8 @@ void DepsgraphNodeBuilder::build_animdata(ID *id) /* actions and NLA - as a single unit for now, as it gets complicated to schedule otherwise */ if ((adt->action) || (adt->nla_tracks.first)) { /* create the node */ - add_operation_node(id, DEPSNODE_TYPE_ANIMATION, - DEPSOP_TYPE_EXEC, function_bind(BKE_animsys_eval_animdata, _1, id), + add_operation_node(id, DEG_NODE_TYPE_ANIMATION, + function_bind(BKE_animsys_eval_animdata, _1, id), DEG_OPCODE_ANIMATION, id->name); // TODO: for each channel affected, we might also want to add some support for running RNA update callbacks on them @@ -593,18 +548,17 @@ OperationDepsNode *DepsgraphNodeBuilder::build_driver(ID *id, FCurve *fcu) * and use some tagging magic instead. */ OperationDepsNode *driver_op = find_operation_node(id, - DEPSNODE_TYPE_PARAMETERS, + DEG_NODE_TYPE_PARAMETERS, DEG_OPCODE_DRIVER, - fcu->rna_path, + fcu->rna_path ? fcu->rna_path : "", fcu->array_index); if (driver_op == NULL) { driver_op = add_operation_node(id, - DEPSNODE_TYPE_PARAMETERS, - DEPSOP_TYPE_EXEC, + DEG_NODE_TYPE_PARAMETERS, function_bind(BKE_animsys_eval_driver, _1, id, fcu), DEG_OPCODE_DRIVER, - fcu->rna_path, + fcu->rna_path ? fcu->rna_path : "", fcu->array_index); } @@ -625,19 +579,20 @@ void DepsgraphNodeBuilder::build_world(World *world) return; } - /* world itself */ - IDDepsNode *world_node = add_id_node(world_id); /* world shading/params? */ - build_animdata(world_id); - /* TODO: other settings? */ + /* world itself */ + add_component_node(world_id, DEG_NODE_TYPE_PARAMETERS); + + add_operation_node(world_id, DEG_NODE_TYPE_PARAMETERS, NULL, + DEG_OPCODE_PLACEHOLDER, "Parameters Eval"); /* textures */ - build_texture_stack(world_node, world->mtex); + build_texture_stack(world->mtex); /* world's nodetree */ if (world->nodetree) { - build_nodetree(world_node, world->nodetree); + build_nodetree(world->nodetree); } } @@ -665,14 +620,14 @@ void DepsgraphNodeBuilder::build_rigidbody(Scene *scene) /* XXX: is this the right component, or do we want to use another one instead? */ /* init/rebuild operation */ - /*OperationDepsNode *init_node =*/ add_operation_node(&scene->id, DEPSNODE_TYPE_TRANSFORM, - DEPSOP_TYPE_REBUILD, function_bind(BKE_rigidbody_rebuild_sim, _1, scene), + /*OperationDepsNode *init_node =*/ add_operation_node(&scene->id, DEG_NODE_TYPE_TRANSFORM, + function_bind(BKE_rigidbody_rebuild_sim, _1, scene), DEG_OPCODE_RIGIDBODY_REBUILD); /* do-sim operation */ // XXX: what happens if we need to split into several groups? - OperationDepsNode *sim_node = add_operation_node(&scene->id, DEPSNODE_TYPE_TRANSFORM, - DEPSOP_TYPE_SIM, function_bind(BKE_rigidbody_eval_simulation, _1, scene), + OperationDepsNode *sim_node = add_operation_node(&scene->id, DEG_NODE_TYPE_TRANSFORM, + function_bind(BKE_rigidbody_eval_simulation, _1, scene), DEG_OPCODE_RIGIDBODY_SIM); /* XXX: For now, the sim node is the only one that really matters here. If any other @@ -692,8 +647,8 @@ void DepsgraphNodeBuilder::build_rigidbody(Scene *scene) /* 2) create operation for flushing results */ /* object's transform component - where the rigidbody operation lives */ - add_operation_node(&ob->id, DEPSNODE_TYPE_TRANSFORM, - DEPSOP_TYPE_EXEC, function_bind(BKE_rigidbody_object_sync_transforms, _1, scene, ob), + add_operation_node(&ob->id, DEG_NODE_TYPE_TRANSFORM, + function_bind(BKE_rigidbody_object_sync_transforms, _1, scene, ob), DEG_OPCODE_TRANSFORM_RIGIDBODY); } } @@ -717,7 +672,15 @@ void DepsgraphNodeBuilder::build_particles(Scene *scene, Object *ob) */ /* component for all particle systems */ - ComponentDepsNode *psys_comp = add_component_node(&ob->id, DEPSNODE_TYPE_EVAL_PARTICLES); + ComponentDepsNode *psys_comp = + add_component_node(&ob->id, DEG_NODE_TYPE_EVAL_PARTICLES); + + add_operation_node(psys_comp, + function_bind(BKE_particle_system_eval_init, + _1, + scene, + ob), + DEG_OPCODE_PSYS_EVAL_INIT); /* particle systems */ LINKLIST_FOREACH (ParticleSystem *, psys, &ob->particlesystem) { @@ -730,11 +693,7 @@ void DepsgraphNodeBuilder::build_particles(Scene *scene, Object *ob) /* this particle system */ // TODO: for now, this will just be a placeholder "ubereval" node add_operation_node(psys_comp, - DEPSOP_TYPE_EXEC, function_bind(BKE_particle_system_eval, - _1, - scene, - ob, - psys), + NULL, DEG_OPCODE_PSYS_EVAL, psys->name); } @@ -743,12 +702,25 @@ void DepsgraphNodeBuilder::build_particles(Scene *scene, Object *ob) // TODO... } +void DepsgraphNodeBuilder::build_cloth(Scene *scene, Object *object) +{ + ComponentDepsNode *cache_comp = add_component_node(&object->id, + DEG_NODE_TYPE_CACHE); + add_operation_node(cache_comp, + function_bind(BKE_object_eval_cloth, + _1, + scene, + object), + DEG_OPCODE_PLACEHOLDER, + "Cloth Modifier"); +} + /* Shapekeys */ void DepsgraphNodeBuilder::build_shapekeys(Key *key) { build_animdata(&key->id); - add_operation_node(&key->id, DEPSNODE_TYPE_GEOMETRY, DEPSOP_TYPE_EXEC, NULL, + add_operation_node(&key->id, DEG_NODE_TYPE_GEOMETRY, NULL, DEG_OPCODE_PLACEHOLDER, "Shapekey Eval"); } @@ -757,18 +729,19 @@ void DepsgraphNodeBuilder::build_shapekeys(Key *key) void DepsgraphNodeBuilder::build_obdata_geom(Scene *scene, Object *ob) { ID *obdata = (ID *)ob->data; + OperationDepsNode *op_node; /* TODO(sergey): This way using this object's properties as driver target * works fine. * * Does this depend on other nodes? */ - add_operation_node(&ob->id, - DEPSNODE_TYPE_PARAMETERS, - DEPSOP_TYPE_POST, - NULL, - DEG_OPCODE_PLACEHOLDER, - "Parameters Eval"); + op_node = add_operation_node(&ob->id, + DEG_NODE_TYPE_PARAMETERS, + NULL, + DEG_OPCODE_PLACEHOLDER, + "Parameters Eval"); + op_node->set_as_exit(); /* Temporary uber-update node, which does everything. * It is for the being we're porting old dependencies into the new system. @@ -777,42 +750,33 @@ void DepsgraphNodeBuilder::build_obdata_geom(Scene *scene, Object *ob) * * TODO(sergey): Get rid of this node. */ - add_operation_node(&ob->id, - DEPSNODE_TYPE_GEOMETRY, - DEPSOP_TYPE_POST, - function_bind(BKE_object_eval_uber_data, _1, scene, ob), - DEG_OPCODE_GEOMETRY_UBEREVAL); - - add_operation_node(&ob->id, - DEPSNODE_TYPE_GEOMETRY, - DEPSOP_TYPE_INIT, - NULL, - DEG_OPCODE_PLACEHOLDER, - "Eval Init"); + op_node = add_operation_node(&ob->id, + DEG_NODE_TYPE_GEOMETRY, + function_bind(BKE_object_eval_uber_data, _1, scene, ob), + DEG_OPCODE_GEOMETRY_UBEREVAL); + op_node->set_as_exit(); + + op_node = add_operation_node(&ob->id, + DEG_NODE_TYPE_GEOMETRY, + NULL, + DEG_OPCODE_PLACEHOLDER, + "Eval Init"); + op_node->set_as_entry(); // TODO: "Done" operation - /* Modifiers */ + /* Cloyth modifier. */ LINKLIST_FOREACH (ModifierData *, md, &ob->modifiers) { - add_operation_node(&ob->id, - DEPSNODE_TYPE_GEOMETRY, - DEPSOP_TYPE_EXEC, - function_bind(BKE_object_eval_modifier, - _1, - scene, - ob, - md), - DEG_OPCODE_GEOMETRY_MODIFIER, - md->name); + if (md->type == eModifierType_Cloth) { + build_cloth(scene, ob); + } } /* materials */ for (int a = 1; a <= ob->totcol; a++) { Material *ma = give_current_material(ob, a); if (ma != NULL) { - // XXX?! - ComponentDepsNode *geom_node = add_component_node(&ob->id, DEPSNODE_TYPE_GEOMETRY); - build_material(geom_node, ma); + build_material(ma); } } @@ -842,14 +806,14 @@ void DepsgraphNodeBuilder::build_obdata_geom(Scene *scene, Object *ob) //Mesh *me = (Mesh *)ob->data; /* evaluation operations */ - add_operation_node(obdata, - DEPSNODE_TYPE_GEOMETRY, - DEPSOP_TYPE_INIT, - function_bind(BKE_mesh_eval_geometry, - _1, - (Mesh *)obdata), - DEG_OPCODE_PLACEHOLDER, - "Geometry Eval"); + op_node = add_operation_node(obdata, + DEG_NODE_TYPE_GEOMETRY, + function_bind(BKE_mesh_eval_geometry, + _1, + (Mesh *)obdata), + DEG_OPCODE_PLACEHOLDER, + "Geometry Eval"); + op_node->set_as_entry(); break; } @@ -861,14 +825,14 @@ void DepsgraphNodeBuilder::build_obdata_geom(Scene *scene, Object *ob) if (mom == ob) { /* metaball evaluation operations */ /* NOTE: only the motherball gets evaluated! */ - add_operation_node(obdata, - DEPSNODE_TYPE_GEOMETRY, - DEPSOP_TYPE_INIT, - function_bind(BKE_mball_eval_geometry, - _1, - (MetaBall *)obdata), - DEG_OPCODE_PLACEHOLDER, - "Geometry Eval"); + op_node = add_operation_node(obdata, + DEG_NODE_TYPE_GEOMETRY, + function_bind(BKE_mball_eval_geometry, + _1, + (MetaBall *)obdata), + DEG_OPCODE_PLACEHOLDER, + "Geometry Eval"); + op_node->set_as_entry(); } break; } @@ -879,26 +843,14 @@ void DepsgraphNodeBuilder::build_obdata_geom(Scene *scene, Object *ob) { /* Curve/nurms evaluation operations. */ /* - calculate curve geometry (including path) */ - add_operation_node(obdata, - DEPSNODE_TYPE_GEOMETRY, - DEPSOP_TYPE_INIT, - function_bind(BKE_curve_eval_geometry, - _1, - (Curve *)obdata), - DEG_OPCODE_PLACEHOLDER, - "Geometry Eval"); - - /* Calculate curve path - this is used by constraints, etc. */ - if (ELEM(ob->type, OB_CURVE, OB_FONT)) { - add_operation_node(obdata, - DEPSNODE_TYPE_GEOMETRY, - DEPSOP_TYPE_EXEC, - function_bind(BKE_curve_eval_path, - _1, - (Curve *)obdata), - DEG_OPCODE_GEOMETRY_PATH, - "Path"); - } + op_node = add_operation_node(obdata, + DEG_NODE_TYPE_GEOMETRY, + function_bind(BKE_curve_eval_geometry, + _1, + (Curve *)obdata), + DEG_OPCODE_PLACEHOLDER, + "Geometry Eval"); + op_node->set_as_entry(); /* Make sure objects used for bevel.taper are in the graph. * NOTE: This objects might be not linked to the scene. @@ -919,24 +871,24 @@ void DepsgraphNodeBuilder::build_obdata_geom(Scene *scene, Object *ob) case OB_LATTICE: { /* Lattice evaluation operations. */ - add_operation_node(obdata, - DEPSNODE_TYPE_GEOMETRY, - DEPSOP_TYPE_INIT, - function_bind(BKE_lattice_eval_geometry, - _1, - (Lattice *)obdata), - DEG_OPCODE_PLACEHOLDER, - "Geometry Eval"); + op_node = add_operation_node(obdata, + DEG_NODE_TYPE_GEOMETRY, + function_bind(BKE_lattice_eval_geometry, + _1, + (Lattice *)obdata), + DEG_OPCODE_PLACEHOLDER, + "Geometry Eval"); + op_node->set_as_entry(); break; } } - add_operation_node(obdata, DEPSNODE_TYPE_GEOMETRY, - DEPSOP_TYPE_POST, NULL, - DEG_OPCODE_PLACEHOLDER, "Eval Done"); + op_node = add_operation_node(obdata, DEG_NODE_TYPE_GEOMETRY, NULL, + DEG_OPCODE_PLACEHOLDER, "Eval Done"); + op_node->set_as_exit(); /* Parameters for driver sources. */ - add_operation_node(obdata, DEPSNODE_TYPE_PARAMETERS, DEPSOP_TYPE_EXEC, NULL, + add_operation_node(obdata, DEG_NODE_TYPE_PARAMETERS, NULL, DEG_OPCODE_PLACEHOLDER, "Parameters Eval"); } @@ -952,15 +904,13 @@ void DepsgraphNodeBuilder::build_camera(Object *ob) build_animdata(&cam->id); - add_operation_node(camera_id, DEPSNODE_TYPE_PARAMETERS, DEPSOP_TYPE_EXEC, NULL, + add_operation_node(camera_id, DEG_NODE_TYPE_PARAMETERS, NULL, DEG_OPCODE_PLACEHOLDER, "Parameters Eval"); if (cam->dof_ob != NULL) { /* TODO(sergey): For now parametrs are on object level. */ - add_operation_node(&ob->id, DEPSNODE_TYPE_PARAMETERS, - DEPSOP_TYPE_EXEC, NULL, - DEG_OPCODE_PLACEHOLDER, - "Camera DOF"); + add_operation_node(&ob->id, DEG_NODE_TYPE_PARAMETERS, NULL, + DEG_OPCODE_PLACEHOLDER, "Camera DOF"); } } @@ -976,45 +926,47 @@ void DepsgraphNodeBuilder::build_lamp(Object *ob) build_animdata(&la->id); /* node for obdata */ - ComponentDepsNode *param_node = add_component_node(lamp_id, DEPSNODE_TYPE_PARAMETERS); + add_component_node(lamp_id, DEG_NODE_TYPE_PARAMETERS); /* TODO(sergey): Is it really how we're supposed to work with drivers? */ - add_operation_node(lamp_id, DEPSNODE_TYPE_PARAMETERS, DEPSOP_TYPE_EXEC, NULL, + add_operation_node(lamp_id, DEG_NODE_TYPE_PARAMETERS, NULL, DEG_OPCODE_PLACEHOLDER, "Parameters Eval"); /* lamp's nodetree */ if (la->nodetree) { - build_nodetree(param_node, la->nodetree); + build_nodetree(la->nodetree); } /* textures */ - build_texture_stack(param_node, la->mtex); + build_texture_stack(la->mtex); } -void DepsgraphNodeBuilder::build_nodetree(DepsNode *owner_node, bNodeTree *ntree) +void DepsgraphNodeBuilder::build_nodetree(bNodeTree *ntree) { if (!ntree) return; /* nodetree itself */ ID *ntree_id = &ntree->id; + OperationDepsNode *op_node; build_animdata(ntree_id); /* Parameters for drivers. */ - add_operation_node(ntree_id, DEPSNODE_TYPE_PARAMETERS, DEPSOP_TYPE_POST, NULL, - DEG_OPCODE_PLACEHOLDER, "Parameters Eval"); + op_node = add_operation_node(ntree_id, DEG_NODE_TYPE_PARAMETERS, NULL, + DEG_OPCODE_PLACEHOLDER, "Parameters Eval"); + op_node->set_as_exit(); /* nodetree's nodes... */ LINKLIST_FOREACH (bNode *, bnode, &ntree->nodes) { ID *id = bnode->id; if (id != NULL) { - short id_type = GS(id->name); + ID_Type id_type = GS(id->name); if (id_type == ID_MA) { - build_material(owner_node, (Material *)id); + build_material((Material *)id); } else if (id_type == ID_TE) { - build_texture(owner_node, (Tex *)id); + build_texture((Tex *)id); } else if (id_type == ID_IM) { build_image((Image *)id); @@ -1022,7 +974,7 @@ void DepsgraphNodeBuilder::build_nodetree(DepsNode *owner_node, bNodeTree *ntree else if (bnode->type == NODE_GROUP) { bNodeTree *group_ntree = (bNodeTree *)id; if ((group_ntree->id.tag & LIB_TAG_DOIT) == 0) { - build_nodetree(owner_node, group_ntree); + build_nodetree(group_ntree); } } } @@ -1032,7 +984,7 @@ void DepsgraphNodeBuilder::build_nodetree(DepsNode *owner_node, bNodeTree *ntree } /* Recursively build graph for material */ -void DepsgraphNodeBuilder::build_material(DepsNode *owner_node, Material *ma) +void DepsgraphNodeBuilder::build_material(Material *ma) { ID *ma_id = &ma->id; if (ma_id->tag & LIB_TAG_DOIT) { @@ -1042,22 +994,21 @@ void DepsgraphNodeBuilder::build_material(DepsNode *owner_node, Material *ma) /* material itself */ add_id_node(ma_id); - add_operation_node(ma_id, DEPSNODE_TYPE_SHADING, - DEPSOP_TYPE_EXEC, NULL, + add_operation_node(ma_id, DEG_NODE_TYPE_SHADING, NULL, DEG_OPCODE_PLACEHOLDER, "Material Update"); /* material animation */ build_animdata(ma_id); /* textures */ - build_texture_stack(owner_node, ma->mtex); + build_texture_stack(ma->mtex); /* material's nodetree */ - build_nodetree(owner_node, ma->nodetree); + build_nodetree(ma->nodetree); } /* Texture-stack attached to some shading datablock */ -void DepsgraphNodeBuilder::build_texture_stack(DepsNode *owner_node, MTex **texture_stack) +void DepsgraphNodeBuilder::build_texture_stack(MTex **texture_stack) { int i; @@ -1065,12 +1016,12 @@ void DepsgraphNodeBuilder::build_texture_stack(DepsNode *owner_node, MTex **text for (i = 0; i < MAX_MTEX; i++) { MTex *mtex = texture_stack[i]; if (mtex && mtex->tex) - build_texture(owner_node, mtex->tex); + build_texture(mtex->tex); } } /* Recursively build graph for texture */ -void DepsgraphNodeBuilder::build_texture(DepsNode *owner_node, Tex *tex) +void DepsgraphNodeBuilder::build_texture(Tex *tex) { ID *tex_id = &tex->id; if (tex_id->tag & LIB_TAG_DOIT) { @@ -1080,7 +1031,7 @@ void DepsgraphNodeBuilder::build_texture(DepsNode *owner_node, Tex *tex) /* Texture itself. */ build_animdata(tex_id); /* Texture's nodetree. */ - build_nodetree(owner_node, tex->nodetree); + build_nodetree(tex->nodetree); /* Special cases for different IDs which texture uses. */ if (tex->type == TEX_IMAGE) { if (tex->ima != NULL) { @@ -1099,8 +1050,7 @@ void DepsgraphNodeBuilder::build_image(Image *image) { add_id_node(image_id); /* Placeholder so we can add relations and tag ID node for update. */ add_operation_node(image_id, - DEPSNODE_TYPE_PARAMETERS, - DEPSOP_TYPE_EXEC, + DEG_NODE_TYPE_PARAMETERS, NULL, DEG_OPCODE_PLACEHOLDER, "Image Eval"); @@ -1111,11 +1061,11 @@ void DepsgraphNodeBuilder::build_compositor(Scene *scene) /* For now, just a plain wrapper? */ // TODO: create compositing component? // XXX: component type undefined! - //graph->get_node(&scene->id, NULL, DEPSNODE_TYPE_COMPOSITING, NULL); + //graph->get_node(&scene->id, NULL, DEG_NODE_TYPE_COMPOSITING, NULL); /* for now, nodetrees are just parameters; compositing occurs in internals of renderer... */ - ComponentDepsNode *owner_node = add_component_node(&scene->id, DEPSNODE_TYPE_PARAMETERS); - build_nodetree(owner_node, scene->nodetree); + add_component_node(&scene->id, DEG_NODE_TYPE_PARAMETERS); + build_nodetree(scene->nodetree); } void DepsgraphNodeBuilder::build_gpencil(bGPdata *gpd) @@ -1136,9 +1086,8 @@ void DepsgraphNodeBuilder::build_cachefile(CacheFile *cache_file) { ID *cache_file_id = &cache_file->id; - add_component_node(cache_file_id, DEPSNODE_TYPE_CACHE); - add_operation_node(cache_file_id, DEPSNODE_TYPE_CACHE, - DEPSOP_TYPE_EXEC, NULL, + add_component_node(cache_file_id, DEG_NODE_TYPE_CACHE); + add_operation_node(cache_file_id, DEG_NODE_TYPE_CACHE, NULL, DEG_OPCODE_PLACEHOLDER, "Cache File Update"); add_id_node(cache_file_id); @@ -1149,7 +1098,18 @@ void DepsgraphNodeBuilder::build_mask(Mask *mask) { ID *mask_id = &mask->id; add_id_node(mask_id); + /* F-Curve based animation/ */ build_animdata(mask_id); + /* Animation based on mask's shapes. */ + add_operation_node(mask_id, + DEG_NODE_TYPE_ANIMATION, + function_bind(BKE_mask_eval_animation, _1, mask), + DEG_OPCODE_MASK_ANIMATION); + /* Final mask evaluation. */ + add_operation_node(mask_id, + DEG_NODE_TYPE_PARAMETERS, + function_bind(BKE_mask_eval_update, _1, mask), + DEG_OPCODE_MASK_EVAL); } void DepsgraphNodeBuilder::build_movieclip(MovieClip *clip) { diff --git a/source/blender/depsgraph/intern/builder/deg_builder_nodes.h b/source/blender/depsgraph/intern/builder/deg_builder_nodes.h index 9cb8bc5d45c..a54b1c76c77 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder_nodes.h +++ b/source/blender/depsgraph/intern/builder/deg_builder_nodes.h @@ -61,8 +61,6 @@ namespace DEG { struct Depsgraph; struct DepsNode; -struct RootDepsNode; -struct SubgraphDepsNode; struct IDDepsNode; struct TimeSourceDepsNode; struct ComponentDepsNode; @@ -72,32 +70,30 @@ struct DepsgraphNodeBuilder { DepsgraphNodeBuilder(Main *bmain, Depsgraph *graph); ~DepsgraphNodeBuilder(); - RootDepsNode *add_root_node(); + void begin_build(Main *bmain); + IDDepsNode *add_id_node(ID *id); - TimeSourceDepsNode *add_time_source(ID *id); + TimeSourceDepsNode *add_time_source(); ComponentDepsNode *add_component_node(ID *id, eDepsNode_Type comp_type, const char *comp_name = ""); OperationDepsNode *add_operation_node(ComponentDepsNode *comp_node, - eDepsOperation_Type optype, - DepsEvalOperationCb op, + const DepsEvalOperationCb& op, eDepsOperation_Code opcode, const char *name = "", int name_tag = -1); OperationDepsNode *add_operation_node(ID *id, eDepsNode_Type comp_type, const char *comp_name, - eDepsOperation_Type optype, - DepsEvalOperationCb op, + const DepsEvalOperationCb& op, eDepsOperation_Code opcode, const char *name = "", int name_tag = -1); OperationDepsNode *add_operation_node(ID *id, eDepsNode_Type comp_type, - eDepsOperation_Type optype, - DepsEvalOperationCb op, + const DepsEvalOperationCb& op, eDepsOperation_Code opcode, const char *name = "", int name_tag = -1); @@ -123,14 +119,14 @@ struct DepsgraphNodeBuilder { int name_tag = -1); void build_scene(Main *bmain, Scene *scene); - SubgraphDepsNode *build_subgraph(Group *group); void build_group(Scene *scene, Base *base, Group *group); void build_object(Scene *scene, Base *base, Object *ob); void build_object_transform(Scene *scene, Object *ob); void build_object_constraints(Scene *scene, Object *ob); - void build_pose_constraints(Object *ob, bPoseChannel *pchan); + void build_pose_constraints(Scene *scene, Object *ob, bPoseChannel *pchan); void build_rigidbody(Scene *scene); void build_particles(Scene *scene, Object *ob); + void build_cloth(Scene *scene, Object *object); void build_animdata(ID *id); OperationDepsNode *build_driver(ID *id, FCurve *fcurve); void build_ik_pose(Scene *scene, @@ -147,10 +143,10 @@ struct DepsgraphNodeBuilder { void build_obdata_geom(Scene *scene, Object *ob); void build_camera(Object *ob); void build_lamp(Object *ob); - void build_nodetree(DepsNode *owner_node, bNodeTree *ntree); - void build_material(DepsNode *owner_node, Material *ma); - void build_texture(DepsNode *owner_node, Tex *tex); - void build_texture_stack(DepsNode *owner_node, MTex **texture_stack); + void build_nodetree(bNodeTree *ntree); + void build_material(Material *ma); + void build_texture(Tex *tex); + void build_texture_stack(MTex **texture_stack); void build_image(Image *image); void build_world(World *world); void build_compositor(Scene *scene); diff --git a/source/blender/depsgraph/intern/builder/deg_builder_nodes_rig.cc b/source/blender/depsgraph/intern/builder/deg_builder_nodes_rig.cc index 4a5f3dc8664..ceb2fd25f94 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder_nodes_rig.cc +++ b/source/blender/depsgraph/intern/builder/deg_builder_nodes_rig.cc @@ -37,11 +37,11 @@ #include "MEM_guardedalloc.h" -extern "C" { +#include "BLI_utildefines.h" #include "BLI_blenlib.h" #include "BLI_string.h" -#include "BLI_utildefines.h" +extern "C" { #include "DNA_anim_types.h" #include "DNA_armature_types.h" #include "DNA_constraint_types.h" @@ -49,10 +49,10 @@ extern "C" { #include "BKE_action.h" #include "BKE_armature.h" +} /* extern "C" */ #include "DEG_depsgraph.h" #include "DEG_depsgraph_build.h" -} /* extern "C" */ #include "intern/builder/deg_builder.h" #include "intern/nodes/deg_node.h" @@ -64,11 +64,11 @@ extern "C" { namespace DEG { -void DepsgraphNodeBuilder::build_pose_constraints(Object *ob, bPoseChannel *pchan) +void DepsgraphNodeBuilder::build_pose_constraints(Scene *scene, Object *ob, bPoseChannel *pchan) { /* create node for constraint stack */ - add_operation_node(&ob->id, DEPSNODE_TYPE_BONE, pchan->name, - DEPSOP_TYPE_EXEC, function_bind(BKE_pose_constraints_evaluate, _1, ob, pchan), + add_operation_node(&ob->id, DEG_NODE_TYPE_BONE, pchan->name, + function_bind(BKE_pose_constraints_evaluate, _1, scene, ob, pchan), DEG_OPCODE_BONE_CONSTRAINTS); } @@ -80,15 +80,15 @@ void DepsgraphNodeBuilder::build_ik_pose(Scene *scene, Object *ob, bPoseChannel /* Find the chain's root. */ bPoseChannel *rootchan = BKE_armature_ik_solver_find_root(pchan, data); - if (has_operation_node(&ob->id, DEPSNODE_TYPE_EVAL_POSE, rootchan->name, + if (has_operation_node(&ob->id, DEG_NODE_TYPE_EVAL_POSE, rootchan->name, DEG_OPCODE_POSE_IK_SOLVER)) { return; } /* Operation node for evaluating/running IK Solver. */ - add_operation_node(&ob->id, DEPSNODE_TYPE_EVAL_POSE, rootchan->name, - DEPSOP_TYPE_SIM, function_bind(BKE_pose_iktree_evaluate, _1, scene, ob, rootchan), + add_operation_node(&ob->id, DEG_NODE_TYPE_EVAL_POSE, rootchan->name, + function_bind(BKE_pose_iktree_evaluate, _1, scene, ob, rootchan), DEG_OPCODE_POSE_IK_SOLVER); } @@ -103,8 +103,8 @@ void DepsgraphNodeBuilder::build_splineik_pose(Scene *scene, Object *ob, bPoseCh /* Operation node for evaluating/running Spline IK Solver. * Store the "root bone" of this chain in the solver, so it knows where to start. */ - add_operation_node(&ob->id, DEPSNODE_TYPE_EVAL_POSE, rootchan->name, - DEPSOP_TYPE_SIM, function_bind(BKE_pose_splineik_evaluate, _1, scene, ob, rootchan), + add_operation_node(&ob->id, DEG_NODE_TYPE_EVAL_POSE, rootchan->name, + function_bind(BKE_pose_splineik_evaluate, _1, scene, ob, rootchan), DEG_OPCODE_POSE_SPLINE_IK_SOLVER); } @@ -112,6 +112,7 @@ void DepsgraphNodeBuilder::build_splineik_pose(Scene *scene, Object *ob, bPoseCh void DepsgraphNodeBuilder::build_rig(Scene *scene, Object *ob) { bArmature *arm = (bArmature *)ob->data; + OperationDepsNode *op_node; /* animation and/or drivers linking posebones to base-armature used to define them * NOTE: AnimData here is really used to control animated deform properties, @@ -119,7 +120,16 @@ void DepsgraphNodeBuilder::build_rig(Scene *scene, Object *ob) * Eventually, we need some type of proxy/isolation mechanism in-between here * to ensure that we can use same rig multiple times in same scene... */ - build_animdata(&arm->id); + if ((arm->id.tag & LIB_TAG_DOIT) == 0) { + build_animdata(&arm->id); + + /* Make sure pose is up-to-date with armature updates. */ + add_operation_node(&arm->id, + DEG_NODE_TYPE_PARAMETERS, + NULL, + DEG_OPCODE_PLACEHOLDER, + "Armature Eval"); + } /* Rebuild pose if not up to date. */ if (ob->pose == NULL || (ob->pose->flag & POSE_RECALC)) { @@ -141,14 +151,6 @@ void DepsgraphNodeBuilder::build_rig(Scene *scene, Object *ob) } } - /* Make sure pose is up-to-date with armature updates. */ - add_operation_node(&arm->id, - DEPSNODE_TYPE_PARAMETERS, - DEPSOP_TYPE_EXEC, - NULL, - DEG_OPCODE_PLACEHOLDER, - "Armature Eval"); - /** * Pose Rig Graph * ============== @@ -172,34 +174,46 @@ void DepsgraphNodeBuilder::build_rig(Scene *scene, Object *ob) */ /* pose eval context */ - add_operation_node(&ob->id, DEPSNODE_TYPE_EVAL_POSE, - DEPSOP_TYPE_INIT, function_bind(BKE_pose_eval_init, _1, scene, ob, ob->pose), DEG_OPCODE_POSE_INIT); - - add_operation_node(&ob->id, DEPSNODE_TYPE_EVAL_POSE, - DEPSOP_TYPE_POST, function_bind(BKE_pose_eval_flush, _1, scene, ob, ob->pose), DEG_OPCODE_POSE_DONE); + op_node = add_operation_node(&ob->id, + DEG_NODE_TYPE_EVAL_POSE, + function_bind(BKE_pose_eval_init, _1, scene, ob, ob->pose), + DEG_OPCODE_POSE_INIT); + op_node->set_as_entry(); + + op_node = add_operation_node(&ob->id, + DEG_NODE_TYPE_EVAL_POSE, + function_bind(BKE_pose_eval_init_ik, _1, scene, ob, ob->pose), + DEG_OPCODE_POSE_INIT_IK); + + op_node = add_operation_node(&ob->id, + DEG_NODE_TYPE_EVAL_POSE, + function_bind(BKE_pose_eval_flush, _1, scene, ob, ob->pose), + DEG_OPCODE_POSE_DONE); + op_node->set_as_exit(); /* bones */ LINKLIST_FOREACH (bPoseChannel *, pchan, &ob->pose->chanbase) { /* node for bone eval */ - add_operation_node(&ob->id, DEPSNODE_TYPE_BONE, pchan->name, - DEPSOP_TYPE_INIT, NULL, // XXX: BKE_pose_eval_bone_local - DEG_OPCODE_BONE_LOCAL); + op_node = add_operation_node(&ob->id, DEG_NODE_TYPE_BONE, pchan->name, NULL, + DEG_OPCODE_BONE_LOCAL); + op_node->set_as_entry(); - add_operation_node(&ob->id, DEPSNODE_TYPE_BONE, pchan->name, - DEPSOP_TYPE_EXEC, function_bind(BKE_pose_eval_bone, _1, scene, ob, pchan), // XXX: BKE_pose_eval_bone_pose + add_operation_node(&ob->id, DEG_NODE_TYPE_BONE, pchan->name, + function_bind(BKE_pose_eval_bone, _1, scene, ob, pchan), DEG_OPCODE_BONE_POSE_PARENT); - add_operation_node(&ob->id, DEPSNODE_TYPE_BONE, pchan->name, - DEPSOP_TYPE_OUT, NULL, /* NOTE: dedicated noop for easier relationship construction */ + add_operation_node(&ob->id, DEG_NODE_TYPE_BONE, pchan->name, + NULL, /* NOTE: dedicated noop for easier relationship construction */ DEG_OPCODE_BONE_READY); - add_operation_node(&ob->id, DEPSNODE_TYPE_BONE, pchan->name, - DEPSOP_TYPE_POST, function_bind(BKE_pose_bone_done, _1, pchan), - DEG_OPCODE_BONE_DONE); + op_node = add_operation_node(&ob->id, DEG_NODE_TYPE_BONE, pchan->name, + function_bind(BKE_pose_bone_done, _1, pchan), + DEG_OPCODE_BONE_DONE); + op_node->set_as_exit(); /* constraints */ if (pchan->constraints.first != NULL) { - build_pose_constraints(ob, pchan); + build_pose_constraints(scene, ob, pchan); } /** @@ -233,6 +247,8 @@ void DepsgraphNodeBuilder::build_rig(Scene *scene, Object *ob) void DepsgraphNodeBuilder::build_proxy_rig(Object *ob) { ID *obdata = (ID *)ob->data; + OperationDepsNode *op_node; + build_animdata(obdata); BLI_assert(ob->pose != NULL); @@ -243,31 +259,28 @@ void DepsgraphNodeBuilder::build_proxy_rig(Object *ob) BKE_pose_update_constraint_flags(ob->pose); } - add_operation_node(&ob->id, - DEPSNODE_TYPE_EVAL_POSE, - DEPSOP_TYPE_INIT, - function_bind(BKE_pose_eval_proxy_copy, _1, ob), - DEG_OPCODE_POSE_INIT); + op_node = add_operation_node(&ob->id, + DEG_NODE_TYPE_EVAL_POSE, + function_bind(BKE_pose_eval_proxy_copy, _1, ob), + DEG_OPCODE_POSE_INIT); + op_node->set_as_entry(); LINKLIST_FOREACH (bPoseChannel *, pchan, &ob->pose->chanbase) { - add_operation_node(&ob->id, DEPSNODE_TYPE_BONE, pchan->name, - DEPSOP_TYPE_INIT, NULL, - DEG_OPCODE_BONE_LOCAL); + op_node = add_operation_node(&ob->id, DEG_NODE_TYPE_BONE, pchan->name, + NULL, DEG_OPCODE_BONE_LOCAL); + op_node->set_as_entry(); - add_operation_node(&ob->id, DEPSNODE_TYPE_BONE, pchan->name, - DEPSOP_TYPE_EXEC, NULL, - DEG_OPCODE_BONE_READY); + add_operation_node(&ob->id, DEG_NODE_TYPE_BONE, pchan->name, + NULL, DEG_OPCODE_BONE_READY); - add_operation_node(&ob->id, DEPSNODE_TYPE_BONE, pchan->name, - DEPSOP_TYPE_POST, NULL, - DEG_OPCODE_BONE_DONE); + op_node = add_operation_node(&ob->id, DEG_NODE_TYPE_BONE, pchan->name, + NULL, DEG_OPCODE_BONE_DONE); + op_node->set_as_exit(); } - add_operation_node(&ob->id, - DEPSNODE_TYPE_EVAL_POSE, - DEPSOP_TYPE_POST, - NULL, - DEG_OPCODE_POSE_DONE); + op_node = add_operation_node(&ob->id, DEG_NODE_TYPE_EVAL_POSE, + NULL, DEG_OPCODE_POSE_DONE); + op_node->set_as_exit(); } } // namespace DEG diff --git a/source/blender/depsgraph/intern/builder/deg_builder_nodes_scene.cc b/source/blender/depsgraph/intern/builder/deg_builder_nodes_scene.cc index bcd4bc51448..521276bc608 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder_nodes_scene.cc +++ b/source/blender/depsgraph/intern/builder/deg_builder_nodes_scene.cc @@ -37,21 +37,21 @@ #include "MEM_guardedalloc.h" -extern "C" { +#include "BLI_utildefines.h" #include "BLI_blenlib.h" #include "BLI_string.h" -#include "BLI_utildefines.h" +extern "C" { #include "DNA_node_types.h" #include "DNA_object_types.h" #include "DNA_scene_types.h" #include "BKE_main.h" #include "BKE_node.h" +} /* extern "C" */ #include "DEG_depsgraph.h" #include "DEG_depsgraph_build.h" -} /* extern "C" */ #include "intern/builder/deg_builder.h" #include "intern/nodes/deg_node.h" @@ -65,25 +65,11 @@ namespace DEG { void DepsgraphNodeBuilder::build_scene(Main *bmain, Scene *scene) { - /* LIB_TAG_DOIT is used to indicate whether node for given ID was already - * created or not. This flag is being set in add_id_node(), so functions - * shouldn't bother with setting it, they only might query this flag when - * needed. - */ - BKE_main_id_tag_all(bmain, LIB_TAG_DOIT, false); - /* XXX nested node trees are not included in tag-clearing above, - * so we need to do this manually. - */ - FOREACH_NODETREE(bmain, nodetree, id) { - if (id != (ID *)nodetree) - nodetree->id.tag &= ~LIB_TAG_DOIT; - } FOREACH_NODETREE_END - /* scene ID block */ add_id_node(&scene->id); /* timesource */ - add_time_source(NULL); + add_time_source(); /* build subgraph for set, and link this in... */ // XXX: depending on how this goes, that scene itself could probably store its @@ -95,21 +81,7 @@ void DepsgraphNodeBuilder::build_scene(Main *bmain, Scene *scene) /* scene objects */ LINKLIST_FOREACH (Base *, base, &scene->base) { Object *ob = base->object; - - /* object itself */ build_object(scene, base, ob); - - /* object that this is a proxy for */ - // XXX: the way that proxies work needs to be completely reviewed! - if (ob->proxy) { - ob->proxy->proxy_from = ob; - build_object(scene, base, ob->proxy); - } - - /* Object dupligroup. */ - if (ob->dup_group) { - build_group(scene, base, ob->dup_group); - } } /* rigidbody */ @@ -154,6 +126,13 @@ void DepsgraphNodeBuilder::build_scene(Main *bmain, Scene *scene) LINKLIST_FOREACH (MovieClip *, clip, &bmain->movieclip) { build_movieclip(clip); } + + /* Parameters evaluation for scene relations mainly. */ + add_operation_node(&scene->id, + DEG_NODE_TYPE_PARAMETERS, + NULL, + DEG_OPCODE_PLACEHOLDER, + "Scene Eval"); } } // namespace DEG diff --git a/source/blender/depsgraph/intern/builder/deg_builder_pchanmap.cc b/source/blender/depsgraph/intern/builder/deg_builder_pchanmap.cc index f870a33fb68..59eb7ed8cf1 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder_pchanmap.cc +++ b/source/blender/depsgraph/intern/builder/deg_builder_pchanmap.cc @@ -33,10 +33,8 @@ #include <stdio.h> #include <string.h> -extern "C" { #include "BLI_utildefines.h" #include "BLI_ghash.h" -} namespace DEG { diff --git a/source/blender/depsgraph/intern/builder/deg_builder_relations.cc b/source/blender/depsgraph/intern/builder/deg_builder_relations.cc index dadb7f8917f..d42c4047691 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder_relations.cc +++ b/source/blender/depsgraph/intern/builder/deg_builder_relations.cc @@ -38,10 +38,10 @@ #include "MEM_guardedalloc.h" -extern "C" { -#include "BLI_blenlib.h" #include "BLI_utildefines.h" +#include "BLI_blenlib.h" +extern "C" { #include "DNA_action_types.h" #include "DNA_anim_types.h" #include "DNA_armature_types.h" @@ -92,13 +92,13 @@ extern "C" { #include "BKE_tracking.h" #include "BKE_world.h" -#include "DEG_depsgraph.h" -#include "DEG_depsgraph_build.h" - #include "RNA_access.h" #include "RNA_types.h" } /* extern "C" */ +#include "DEG_depsgraph.h" +#include "DEG_depsgraph_build.h" + #include "intern/builder/deg_builder.h" #include "intern/builder/deg_builder_pchanmap.h" @@ -113,6 +113,41 @@ extern "C" { namespace DEG { +namespace { + +struct BuilderWalkUserData { + DepsgraphRelationBuilder *builder; + Main *bmain; + Scene *scene; +}; + +static void modifier_walk(void *user_data, + struct Object * /*ob*/, + struct Object **obpoin, + int /*cb_flag*/) +{ + BuilderWalkUserData *data = (BuilderWalkUserData *)user_data; + if (*obpoin) { + data->builder->build_object(data->bmain, data->scene, *obpoin); + } +} + +void constraint_walk(bConstraint * /*con*/, + ID **idpoin, + bool /*is_reference*/, + void *user_data) +{ + BuilderWalkUserData *data = (BuilderWalkUserData *)user_data; + if (*idpoin) { + ID *id = *idpoin; + if (GS(id->name) == ID_OB) { + data->builder->build_object(data->bmain, data->scene, (Object *)id); + } + } +} + +} /* namespace */ + /* ***************** */ /* Relations Builder */ @@ -129,8 +164,8 @@ static bool python_driver_depends_on_time(ChannelDriver *driver) /* Function calls are considered dependent on a time. */ return true; } - if (strstr(driver->expression, "time") != NULL) { - /* Variable `time` depends on time. */ + if (strstr(driver->expression, "frame") != NULL) { + /* Variable `frame` depends on time. */ /* TODO(sergey): This is a bit weak, but not sure about better way of * handling this. */ @@ -163,13 +198,6 @@ DepsgraphRelationBuilder::DepsgraphRelationBuilder(Depsgraph *graph) : { } -RootDepsNode *DepsgraphRelationBuilder::find_node(const RootKey &key) const -{ - (void)key; - BLI_assert(!"Doesn't seem to be correct"); - return m_graph->root_node; -} - TimeSourceDepsNode *DepsgraphRelationBuilder::find_node( const TimeSourceKey &key) const { @@ -178,7 +206,7 @@ TimeSourceDepsNode *DepsgraphRelationBuilder::find_node( return NULL; } else { - return m_graph->root_node->time_source; + return m_graph->time_source; } } @@ -247,7 +275,7 @@ void DepsgraphRelationBuilder::add_time_relation(TimeSourceDepsNode *timesrc, const char *description) { if (timesrc && node_to) { - m_graph->add_new_relation(timesrc, node_to, DEPSREL_TYPE_TIME, description); + m_graph->add_new_relation(timesrc, node_to, description); } else { DEG_DEBUG_PRINTF("add_time_relation(%p = %s, %p = %s, %s) Failed\n", @@ -260,17 +288,16 @@ void DepsgraphRelationBuilder::add_time_relation(TimeSourceDepsNode *timesrc, void DepsgraphRelationBuilder::add_operation_relation( OperationDepsNode *node_from, OperationDepsNode *node_to, - eDepsRelation_Type type, const char *description) { if (node_from && node_to) { - m_graph->add_new_relation(node_from, node_to, type, description); + m_graph->add_new_relation(node_from, node_to, description); } else { - DEG_DEBUG_PRINTF("add_operation_relation(%p = %s, %p = %s, %d, %s) Failed\n", + DEG_DEBUG_PRINTF("add_operation_relation(%p = %s, %p = %s, %s) Failed\n", node_from, (node_from) ? node_from->identifier().c_str() : "<None>", node_to, (node_to) ? node_to->identifier().c_str() : "<None>", - type, description); + description); } } @@ -283,11 +310,11 @@ void DepsgraphRelationBuilder::add_collision_relations(const OperationKey &key, { Object *ob1 = collobjs[i]; - ComponentKey trf_key(&ob1->id, DEPSNODE_TYPE_TRANSFORM); - add_relation(trf_key, key, DEPSREL_TYPE_STANDARD, name); + ComponentKey trf_key(&ob1->id, DEG_NODE_TYPE_TRANSFORM); + add_relation(trf_key, key, name); - ComponentKey coll_key(&ob1->id, DEPSNODE_TYPE_GEOMETRY); - add_relation(coll_key, key, DEPSREL_TYPE_STANDARD, name); + ComponentKey coll_key(&ob1->id, DEG_NODE_TYPE_GEOMETRY); + add_relation(coll_key, key, name); } if (collobjs) @@ -301,31 +328,31 @@ void DepsgraphRelationBuilder::add_forcefield_relations(const OperationKey &key, if (effectors) { for (EffectorCache *eff = (EffectorCache *)effectors->first; eff; eff = eff->next) { if (eff->ob != ob) { - ComponentKey eff_key(&eff->ob->id, DEPSNODE_TYPE_TRANSFORM); - add_relation(eff_key, key, DEPSREL_TYPE_STANDARD, name); + ComponentKey eff_key(&eff->ob->id, DEG_NODE_TYPE_TRANSFORM); + add_relation(eff_key, key, name); } if (eff->psys) { if (eff->ob != ob) { - ComponentKey eff_key(&eff->ob->id, DEPSNODE_TYPE_EVAL_PARTICLES); - add_relation(eff_key, key, DEPSREL_TYPE_STANDARD, name); + ComponentKey eff_key(&eff->ob->id, DEG_NODE_TYPE_EVAL_PARTICLES); + add_relation(eff_key, key, name); /* TODO: remove this when/if EVAL_PARTICLES is sufficient for up to date particles */ - ComponentKey mod_key(&eff->ob->id, DEPSNODE_TYPE_GEOMETRY); - add_relation(mod_key, key, DEPSREL_TYPE_STANDARD, name); + ComponentKey mod_key(&eff->ob->id, DEG_NODE_TYPE_GEOMETRY); + add_relation(mod_key, key, name); } else if (eff->psys != psys) { - OperationKey eff_key(&eff->ob->id, DEPSNODE_TYPE_EVAL_PARTICLES, DEG_OPCODE_PSYS_EVAL, eff->psys->name); - add_relation(eff_key, key, DEPSREL_TYPE_STANDARD, name); + OperationKey eff_key(&eff->ob->id, DEG_NODE_TYPE_EVAL_PARTICLES, DEG_OPCODE_PSYS_EVAL, eff->psys->name); + add_relation(eff_key, key, name); } } if (eff->pd->forcefield == PFIELD_SMOKEFLOW && eff->pd->f_source) { - ComponentKey trf_key(&eff->pd->f_source->id, DEPSNODE_TYPE_TRANSFORM); - add_relation(trf_key, key, DEPSREL_TYPE_STANDARD, "Smoke Force Domain"); + ComponentKey trf_key(&eff->pd->f_source->id, DEG_NODE_TYPE_TRANSFORM); + add_relation(trf_key, key, "Smoke Force Domain"); - ComponentKey eff_key(&eff->pd->f_source->id, DEPSNODE_TYPE_GEOMETRY); - add_relation(eff_key, key, DEPSREL_TYPE_STANDARD, "Smoke Force Domain"); + ComponentKey eff_key(&eff->pd->f_source->id, DEG_NODE_TYPE_GEOMETRY); + add_relation(eff_key, key, "Smoke Force Domain"); } if (add_absorption && (eff->pd->flag & PFIELD_VISIBILITY)) { @@ -337,8 +364,29 @@ void DepsgraphRelationBuilder::add_forcefield_relations(const OperationKey &key, pdEndEffectors(&effectors); } +Depsgraph *DepsgraphRelationBuilder::getGraph() +{ + return m_graph; +} + /* **** Functions to build relations between entities **** */ +void DepsgraphRelationBuilder::begin_build(Main *bmain) +{ + /* LIB_TAG_DOIT is used to indicate whether node for given ID was already + * created or not. + */ + BKE_main_id_tag_all(bmain, LIB_TAG_DOIT, false); + /* XXX nested node trees are notr included in tag-clearing above, + * so we need to do this manually. + */ + FOREACH_NODETREE(bmain, nodetree, id) { + if (id != (ID *)nodetree) { + nodetree->id.tag &= ~LIB_TAG_DOIT; + } + } FOREACH_NODETREE_END +} + void DepsgraphRelationBuilder::build_group(Main *bmain, Scene *scene, Object *object, @@ -347,17 +395,14 @@ void DepsgraphRelationBuilder::build_group(Main *bmain, ID *group_id = &group->id; bool group_done = (group_id->tag & LIB_TAG_DOIT) != 0; OperationKey object_local_transform_key(&object->id, - DEPSNODE_TYPE_TRANSFORM, + DEG_NODE_TYPE_TRANSFORM, DEG_OPCODE_TRANSFORM_LOCAL); LINKLIST_FOREACH (GroupObject *, go, &group->gobject) { if (!group_done) { build_object(bmain, scene, go->ob); } - ComponentKey dupli_transform_key(&go->ob->id, DEPSNODE_TYPE_TRANSFORM); - add_relation(dupli_transform_key, - object_local_transform_key, - DEPSREL_TYPE_TRANSFORM, - "Dupligroup"); + ComponentKey dupli_transform_key(&go->ob->id, DEG_NODE_TYPE_TRANSFORM); + add_relation(dupli_transform_key, object_local_transform_key, "Dupligroup"); } group_id->tag |= LIB_TAG_DOIT; } @@ -371,60 +416,85 @@ void DepsgraphRelationBuilder::build_object(Main *bmain, Scene *scene, Object *o /* Object Transforms */ eDepsOperation_Code base_op = (ob->parent) ? DEG_OPCODE_TRANSFORM_PARENT : DEG_OPCODE_TRANSFORM_LOCAL; - OperationKey base_op_key(&ob->id, DEPSNODE_TYPE_TRANSFORM, base_op); + OperationKey base_op_key(&ob->id, DEG_NODE_TYPE_TRANSFORM, base_op); - OperationKey local_transform_key(&ob->id, DEPSNODE_TYPE_TRANSFORM, DEG_OPCODE_TRANSFORM_LOCAL); - OperationKey parent_transform_key(&ob->id, DEPSNODE_TYPE_TRANSFORM, DEG_OPCODE_TRANSFORM_PARENT); - OperationKey final_transform_key(&ob->id, DEPSNODE_TYPE_TRANSFORM, DEG_OPCODE_TRANSFORM_FINAL); + OperationKey local_transform_key(&ob->id, DEG_NODE_TYPE_TRANSFORM, DEG_OPCODE_TRANSFORM_LOCAL); + OperationKey parent_transform_key(&ob->id, DEG_NODE_TYPE_TRANSFORM, DEG_OPCODE_TRANSFORM_PARENT); + OperationKey final_transform_key(&ob->id, DEG_NODE_TYPE_TRANSFORM, DEG_OPCODE_TRANSFORM_FINAL); - OperationKey ob_ubereval_key(&ob->id, DEPSNODE_TYPE_TRANSFORM, DEG_OPCODE_OBJECT_UBEREVAL); + OperationKey ob_ubereval_key(&ob->id, DEG_NODE_TYPE_TRANSFORM, DEG_OPCODE_OBJECT_UBEREVAL); /* parenting */ - if (ob->parent) { + if (ob->parent != NULL) { /* parent relationship */ build_object_parent(ob); /* local -> parent */ - add_relation(local_transform_key, parent_transform_key, DEPSREL_TYPE_COMPONENT_ORDER, "[ObLocal -> ObParent]"); + add_relation(local_transform_key, parent_transform_key, "[ObLocal -> ObParent]"); + } + + if (ob->modifiers.first != NULL) { + BuilderWalkUserData data; + data.builder = this; + data.bmain = bmain; + data.scene = scene; + modifiers_foreachObjectLink(ob, modifier_walk, &data); + } + if (ob->constraints.first != NULL) { + BuilderWalkUserData data; + data.builder = this; + data.bmain = bmain; + data.scene = scene; + BKE_constraints_id_loop(&ob->constraints, constraint_walk, &data); } /* object constraints */ - if (ob->constraints.first) { - OperationKey constraint_key(&ob->id, DEPSNODE_TYPE_TRANSFORM, DEG_OPCODE_TRANSFORM_CONSTRAINTS); + if (ob->constraints.first != NULL) { + OperationKey constraint_key(&ob->id, + DEG_NODE_TYPE_TRANSFORM, + DEG_OPCODE_TRANSFORM_CONSTRAINTS); /* constraint relations */ // TODO: provide base op // XXX: this is broken - build_constraints(scene, &ob->id, DEPSNODE_TYPE_TRANSFORM, "", &ob->constraints, NULL); + build_constraints(scene, + &ob->id, + DEG_NODE_TYPE_TRANSFORM, + "", + &ob->constraints, + NULL); /* operation order */ - add_relation(base_op_key, constraint_key, DEPSREL_TYPE_COMPONENT_ORDER, "[ObBase-> Constraint Stack]"); - add_relation(constraint_key, final_transform_key, DEPSREL_TYPE_COMPONENT_ORDER, "[ObConstraints -> Done]"); + add_relation(base_op_key, constraint_key, "[ObBase-> Constraint Stack]"); + add_relation(constraint_key, final_transform_key, "[ObConstraints -> Done]"); // XXX - add_relation(constraint_key, ob_ubereval_key, DEPSREL_TYPE_COMPONENT_ORDER, "Temp Ubereval"); - add_relation(ob_ubereval_key, final_transform_key, DEPSREL_TYPE_COMPONENT_ORDER, "Temp Ubereval"); + add_relation(constraint_key, ob_ubereval_key, "Temp Ubereval"); + add_relation(ob_ubereval_key, final_transform_key, "Temp Ubereval"); } else { - /* operation order */ - add_relation(base_op_key, final_transform_key, DEPSREL_TYPE_COMPONENT_ORDER, "Object Transform"); - - // XXX - add_relation(base_op_key, ob_ubereval_key, DEPSREL_TYPE_COMPONENT_ORDER, "Temp Ubereval"); - add_relation(ob_ubereval_key, final_transform_key, DEPSREL_TYPE_COMPONENT_ORDER, "Temp Ubereval"); + /* NOTE: Keep an eye here, we skip some relations here to "streamline" + * dependencies and avoid transitive relations which causes overhead. + * But once we get rid of uber eval node this will need reconsideration. + */ + if (ob->rigidbody_object == NULL) { + /* Rigid body will hook up another node inbetween, so skip + * relation here to avoid transitive relation. + */ + add_relation(base_op_key, ob_ubereval_key, "Temp Ubereval"); + } + add_relation(ob_ubereval_key, final_transform_key, "Temp Ubereval"); } - /* AnimData */ build_animdata(&ob->id); // XXX: This should be hooked up by the build_animdata code if (needs_animdata_node(&ob->id)) { - ComponentKey adt_key(&ob->id, DEPSNODE_TYPE_ANIMATION); - add_relation(adt_key, local_transform_key, DEPSREL_TYPE_OPERATION, "Object Animation"); + ComponentKey adt_key(&ob->id, DEG_NODE_TYPE_ANIMATION); + add_relation(adt_key, local_transform_key, "Object Animation"); } - /* object data */ if (ob->data) { ID *obdata_id = (ID *)ob->data; @@ -465,44 +535,64 @@ void DepsgraphRelationBuilder::build_object(Main *bmain, Scene *scene, Object *o Key *key = BKE_key_from_object(ob); if (key != NULL) { - ComponentKey geometry_key((ID *)ob->data, DEPSNODE_TYPE_GEOMETRY); - ComponentKey key_key(&key->id, DEPSNODE_TYPE_GEOMETRY); - add_relation(key_key, geometry_key, DEPSREL_TYPE_GEOMETRY_EVAL, "Shapekeys"); + ComponentKey geometry_key((ID *)ob->data, DEG_NODE_TYPE_GEOMETRY); + ComponentKey key_key(&key->id, DEG_NODE_TYPE_GEOMETRY); + add_relation(key_key, geometry_key, "Shapekeys"); } } - /* particle systems */ - if (ob->particlesystem.first) { + /* Particle systems. */ + if (ob->particlesystem.first != NULL) { build_particles(scene, ob); } - /* grease pencil */ - if (ob->gpd) { - build_gpencil(&ob->id, ob->gpd); + /* Grease pencil. */ + if (ob->gpd != NULL) { + build_gpencil(ob->gpd); + } + + /* Object that this is a proxy for. */ + if (ob->proxy != NULL) { + ob->proxy->proxy_from = ob; + build_object(bmain, scene, ob->proxy); + /* TODO(sergey): This is an inverted relation, matches old depsgraph + * behavior and need to be investigated if it still need to be inverted. + */ + ComponentKey ob_pose_key(&ob->id, DEG_NODE_TYPE_EVAL_POSE); + ComponentKey proxy_pose_key(&ob->proxy->id, DEG_NODE_TYPE_EVAL_POSE); + add_relation(ob_pose_key, proxy_pose_key, "Proxy"); + } + + /* Object dupligroup. */ + if (ob->dup_group != NULL) { + build_group(bmain, scene, ob, ob->dup_group); } } void DepsgraphRelationBuilder::build_object_parent(Object *ob) { - /* XXX: for now, need to use the component key (not just direct to the parent op), or else the matrix doesn't get reset */ - // XXX: @sergey - it would be good if we got that backwards flushing working when tagging for updates - //OperationKey ob_key(&ob->id, DEPSNODE_TYPE_TRANSFORM, DEG_OPCODE_TRANSFORM_PARENT); - ComponentKey ob_key(&ob->id, DEPSNODE_TYPE_TRANSFORM); + /* XXX: for now, need to use the component key (not just direct to the parent op), + * or else the matrix doesn't get reset/ + */ + // XXX: @sergey - it would be good if we got that backwards flushing working + // when tagging for updates. + //OperationKey ob_key(&ob->id, DEG_NODE_TYPE_TRANSFORM, DEG_OPCODE_TRANSFORM_PARENT); + ComponentKey ob_key(&ob->id, DEG_NODE_TYPE_TRANSFORM); /* type-specific links */ switch (ob->partype) { case PARSKEL: /* Armature Deform (Virtual Modifier) */ { - ComponentKey parent_key(&ob->parent->id, DEPSNODE_TYPE_TRANSFORM); - add_relation(parent_key, ob_key, DEPSREL_TYPE_STANDARD, "Armature Deform Parent"); + ComponentKey parent_key(&ob->parent->id, DEG_NODE_TYPE_TRANSFORM); + add_relation(parent_key, ob_key, "Armature Deform Parent"); break; } case PARVERT1: /* Vertex Parent */ case PARVERT3: { - ComponentKey parent_key(&ob->parent->id, DEPSNODE_TYPE_GEOMETRY); - add_relation(parent_key, ob_key, DEPSREL_TYPE_GEOMETRY_EVAL, "Vertex Parent"); + ComponentKey parent_key(&ob->parent->id, DEG_NODE_TYPE_GEOMETRY); + add_relation(parent_key, ob_key, "Vertex Parent"); /* XXX not sure what this is for or how you could be done properly - lukas */ OperationDepsNode *parent_node = find_operation_node(parent_key); @@ -510,15 +600,21 @@ void DepsgraphRelationBuilder::build_object_parent(Object *ob) parent_node->customdata_mask |= CD_MASK_ORIGINDEX; } - ComponentKey transform_key(&ob->parent->id, DEPSNODE_TYPE_TRANSFORM); - add_relation(transform_key, ob_key, DEPSREL_TYPE_TRANSFORM, "Vertex Parent TFM"); + ComponentKey transform_key(&ob->parent->id, DEG_NODE_TYPE_TRANSFORM); + add_relation(transform_key, ob_key, "Vertex Parent TFM"); break; } case PARBONE: /* Bone Parent */ { - ComponentKey parent_key(&ob->parent->id, DEPSNODE_TYPE_BONE, ob->parsubstr); - add_relation(parent_key, ob_key, DEPSREL_TYPE_TRANSFORM, "Bone Parent"); + ComponentKey parent_bone_key(&ob->parent->id, + DEG_NODE_TYPE_BONE, + ob->parsubstr); + OperationKey parent_transform_key(&ob->parent->id, + DEG_NODE_TYPE_TRANSFORM, + DEG_OPCODE_TRANSFORM_FINAL); + add_relation(parent_bone_key, ob_key, "Bone Parent"); + add_relation(parent_transform_key, ob_key, "Armature Parent"); break; } @@ -527,33 +623,33 @@ void DepsgraphRelationBuilder::build_object_parent(Object *ob) if (ob->parent->type == OB_LATTICE) { /* Lattice Deform Parent - Virtual Modifier */ // XXX: no virtual modifiers should be left! - ComponentKey parent_key(&ob->parent->id, DEPSNODE_TYPE_TRANSFORM); - ComponentKey geom_key(&ob->parent->id, DEPSNODE_TYPE_GEOMETRY); + ComponentKey parent_key(&ob->parent->id, DEG_NODE_TYPE_TRANSFORM); + ComponentKey geom_key(&ob->parent->id, DEG_NODE_TYPE_GEOMETRY); - add_relation(parent_key, ob_key, DEPSREL_TYPE_STANDARD, "Lattice Deform Parent"); - add_relation(geom_key, ob_key, DEPSREL_TYPE_STANDARD, "Lattice Deform Parent Geom"); + add_relation(parent_key, ob_key, "Lattice Deform Parent"); + add_relation(geom_key, ob_key, "Lattice Deform Parent Geom"); } else if (ob->parent->type == OB_CURVE) { Curve *cu = (Curve *)ob->parent->data; if (cu->flag & CU_PATH) { /* Follow Path */ - ComponentKey parent_key(&ob->parent->id, DEPSNODE_TYPE_GEOMETRY); - add_relation(parent_key, ob_key, DEPSREL_TYPE_TRANSFORM, "Curve Follow Parent"); + ComponentKey parent_key(&ob->parent->id, DEG_NODE_TYPE_GEOMETRY); + add_relation(parent_key, ob_key, "Curve Follow Parent"); - ComponentKey transform_key(&ob->parent->id, DEPSNODE_TYPE_TRANSFORM); - add_relation(transform_key, ob_key, DEPSREL_TYPE_TRANSFORM, "Curve Follow TFM"); + ComponentKey transform_key(&ob->parent->id, DEG_NODE_TYPE_TRANSFORM); + add_relation(transform_key, ob_key, "Curve Follow TFM"); } else { /* Standard Parent */ - ComponentKey parent_key(&ob->parent->id, DEPSNODE_TYPE_TRANSFORM); - add_relation(parent_key, ob_key, DEPSREL_TYPE_TRANSFORM, "Curve Parent"); + ComponentKey parent_key(&ob->parent->id, DEG_NODE_TYPE_TRANSFORM); + add_relation(parent_key, ob_key, "Curve Parent"); } } else { /* Standard Parent */ - ComponentKey parent_key(&ob->parent->id, DEPSNODE_TYPE_TRANSFORM); - add_relation(parent_key, ob_key, DEPSREL_TYPE_TRANSFORM, "Parent"); + ComponentKey parent_key(&ob->parent->id, DEG_NODE_TYPE_TRANSFORM); + add_relation(parent_key, ob_key, "Parent"); } break; } @@ -565,112 +661,149 @@ void DepsgraphRelationBuilder::build_object_parent(Object *ob) } } -void DepsgraphRelationBuilder::build_constraints(Scene *scene, ID *id, eDepsNode_Type component_type, const char *component_subdata, - ListBase *constraints, RootPChanMap *root_map) +void DepsgraphRelationBuilder::build_constraints(Scene *scene, ID *id, + eDepsNode_Type component_type, + const char *component_subdata, + ListBase *constraints, + RootPChanMap *root_map) { - OperationKey constraint_op_key(id, component_type, component_subdata, - (component_type == DEPSNODE_TYPE_BONE) ? DEG_OPCODE_BONE_CONSTRAINTS : DEG_OPCODE_TRANSFORM_CONSTRAINTS); - - /* add dependencies for each constraint in turn */ + OperationKey constraint_op_key( + id, + component_type, + component_subdata, + (component_type == DEG_NODE_TYPE_BONE) + ? DEG_OPCODE_BONE_CONSTRAINTS + : DEG_OPCODE_TRANSFORM_CONSTRAINTS); + /* Add dependencies for each constraint in turn. */ for (bConstraint *con = (bConstraint *)constraints->first; con; con = con->next) { const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con); - - /* invalid constraint type... */ - if (cti == NULL) + /* Invalid constraint type. */ + if (cti == NULL) { continue; - - /* special case for camera tracking -- it doesn't use targets to define relations */ - // TODO: we can now represent dependencies in a much richer manner, so review how this is done... - if (ELEM(cti->type, CONSTRAINT_TYPE_FOLLOWTRACK, CONSTRAINT_TYPE_CAMERASOLVER, CONSTRAINT_TYPE_OBJECTSOLVER)) { + } + /* Special case for camera tracking -- it doesn't use targets to + * define relations. + */ + /* TODO: we can now represent dependencies in a much richer manner, + * so review how this is done. + */ + if (ELEM(cti->type, + CONSTRAINT_TYPE_FOLLOWTRACK, + CONSTRAINT_TYPE_CAMERASOLVER, + CONSTRAINT_TYPE_OBJECTSOLVER)) + { bool depends_on_camera = false; - if (cti->type == CONSTRAINT_TYPE_FOLLOWTRACK) { bFollowTrackConstraint *data = (bFollowTrackConstraint *)con->data; - - if (((data->clip) || (data->flag & FOLLOWTRACK_ACTIVECLIP)) && data->track[0]) + if (((data->clip) || + (data->flag & FOLLOWTRACK_ACTIVECLIP)) && data->track[0]) + { depends_on_camera = true; - + } if (data->depth_ob) { - // DAG_RL_DATA_OB | DAG_RL_OB_OB - ComponentKey depth_key(&data->depth_ob->id, DEPSNODE_TYPE_TRANSFORM); - add_relation(depth_key, constraint_op_key, DEPSREL_TYPE_TRANSFORM, cti->name); + ComponentKey depth_transform_key(&data->depth_ob->id, + DEG_NODE_TYPE_TRANSFORM); + ComponentKey depth_geometry_key(&data->depth_ob->id, + DEG_NODE_TYPE_GEOMETRY); + add_relation(depth_transform_key, constraint_op_key, cti->name); + add_relation(depth_geometry_key, constraint_op_key, cti->name); } } else if (cti->type == CONSTRAINT_TYPE_OBJECTSOLVER) { depends_on_camera = true; } - if (depends_on_camera && scene->camera) { - // DAG_RL_DATA_OB | DAG_RL_OB_OB - ComponentKey camera_key(&scene->camera->id, DEPSNODE_TYPE_TRANSFORM); - add_relation(camera_key, constraint_op_key, DEPSREL_TYPE_TRANSFORM, cti->name); + ComponentKey camera_key(&scene->camera->id, DEG_NODE_TYPE_TRANSFORM); + add_relation(camera_key, constraint_op_key, cti->name); } - - /* TODO(sergey): This is more a TimeSource -> MovieClip -> Constraint dependency chain. */ + /* TODO(sergey): This is more a TimeSource -> MovieClip -> + * Constraint dependency chain. + */ TimeSourceKey time_src_key; - add_relation(time_src_key, constraint_op_key, DEPSREL_TYPE_TIME, "[TimeSrc -> Animation]"); + add_relation(time_src_key, constraint_op_key, "[TimeSrc -> Animation]"); } else if (cti->type == CONSTRAINT_TYPE_TRANSFORM_CACHE) { - /* TODO(kevin): This is more a TimeSource -> CacheFile -> Constraint dependency chain. */ + /* TODO(kevin): This is more a TimeSource -> CacheFile -> Constraint + * dependency chain. + */ TimeSourceKey time_src_key; - add_relation(time_src_key, constraint_op_key, DEPSREL_TYPE_TIME, "[TimeSrc -> Animation]"); - + add_relation(time_src_key, constraint_op_key, "[TimeSrc -> Animation]"); bTransformCacheConstraint *data = (bTransformCacheConstraint *)con->data; - if (data->cache_file) { - ComponentKey cache_key(&data->cache_file->id, DEPSNODE_TYPE_CACHE); - add_relation(cache_key, constraint_op_key, DEPSREL_TYPE_CACHE, cti->name); + ComponentKey cache_key(&data->cache_file->id, DEG_NODE_TYPE_CACHE); + add_relation(cache_key, constraint_op_key, cti->name); } } else if (cti->get_constraint_targets) { ListBase targets = {NULL, NULL}; cti->get_constraint_targets(con, &targets); - LINKLIST_FOREACH (bConstraintTarget *, ct, &targets) { if (ct->tar == NULL) { continue; } - - if (ELEM(con->type, CONSTRAINT_TYPE_KINEMATIC, CONSTRAINT_TYPE_SPLINEIK)) { - /* ignore IK constraints - these are handled separately (on pose level) */ + if (ELEM(con->type, + CONSTRAINT_TYPE_KINEMATIC, + CONSTRAINT_TYPE_SPLINEIK)) + { + /* Ignore IK constraints - these are handled separately + * (on pose level). + */ } - else if (ELEM(con->type, CONSTRAINT_TYPE_FOLLOWPATH, CONSTRAINT_TYPE_CLAMPTO)) { - /* these constraints require path geometry data... */ - ComponentKey target_key(&ct->tar->id, DEPSNODE_TYPE_GEOMETRY); - add_relation(target_key, constraint_op_key, DEPSREL_TYPE_GEOMETRY_EVAL, cti->name); // XXX: type = geom_transform - // TODO: path dependency + else if (ELEM(con->type, + CONSTRAINT_TYPE_FOLLOWPATH, + CONSTRAINT_TYPE_CLAMPTO)) + { + /* These constraints require path geometry data. */ + ComponentKey target_key(&ct->tar->id, DEG_NODE_TYPE_GEOMETRY); + add_relation(target_key, constraint_op_key, cti->name); + ComponentKey target_transform_key(&ct->tar->id, + DEG_NODE_TYPE_TRANSFORM); + add_relation(target_transform_key, constraint_op_key, cti->name); } else if ((ct->tar->type == OB_ARMATURE) && (ct->subtarget[0])) { /* bone */ if (&ct->tar->id == id) { /* same armature */ eDepsOperation_Code target_key_opcode; - - /* Using "done" here breaks in-chain deps, while using "ready" here breaks most production rigs instead... - * So, we do a compromise here, and only do this when an IK chain conflict may occur + /* Using "done" here breaks in-chain deps, while using + * "ready" here breaks most production rigs instead. + * So, we do a compromise here, and only do this when an + * IK chain conflict may occur. */ - if (root_map->has_common_root(component_subdata, ct->subtarget)) { + if (root_map->has_common_root(component_subdata, + ct->subtarget)) + { target_key_opcode = DEG_OPCODE_BONE_READY; } else { target_key_opcode = DEG_OPCODE_BONE_DONE; } - - OperationKey target_key(&ct->tar->id, DEPSNODE_TYPE_BONE, ct->subtarget, target_key_opcode); - add_relation(target_key, constraint_op_key, DEPSREL_TYPE_TRANSFORM, cti->name); + OperationKey target_key(&ct->tar->id, + DEG_NODE_TYPE_BONE, + ct->subtarget, + target_key_opcode); + add_relation(target_key, constraint_op_key, cti->name); } else { - /* different armature - we can safely use the result of that */ - OperationKey target_key(&ct->tar->id, DEPSNODE_TYPE_BONE, ct->subtarget, DEG_OPCODE_BONE_DONE); - add_relation(target_key, constraint_op_key, DEPSREL_TYPE_TRANSFORM, cti->name); + /* Different armature - we can safely use the result + * of that. + */ + OperationKey target_key(&ct->tar->id, + DEG_NODE_TYPE_BONE, + ct->subtarget, + DEG_OPCODE_BONE_DONE); + add_relation(target_key, constraint_op_key, cti->name); } } - else if (ELEM(ct->tar->type, OB_MESH, OB_LATTICE) && (ct->subtarget[0])) { - /* vertex group */ - /* NOTE: for now, we don't need to represent vertex groups separately... */ - ComponentKey target_key(&ct->tar->id, DEPSNODE_TYPE_GEOMETRY); - add_relation(target_key, constraint_op_key, DEPSREL_TYPE_GEOMETRY_EVAL, cti->name); - + else if (ELEM(ct->tar->type, OB_MESH, OB_LATTICE) && + (ct->subtarget[0])) + { + /* Vertex group. */ + /* NOTE: for now, we don't need to represent vertex groups + * separately. + */ + ComponentKey target_key(&ct->tar->id, DEG_NODE_TYPE_GEOMETRY); + add_relation(target_key, constraint_op_key, cti->name); if (ct->tar->type == OB_MESH) { OperationDepsNode *node2 = find_operation_node(target_key); if (node2 != NULL) { @@ -680,39 +813,50 @@ void DepsgraphRelationBuilder::build_constraints(Scene *scene, ID *id, eDepsNode } else if (con->type == CONSTRAINT_TYPE_SHRINKWRAP) { /* Constraints which requires the target object surface. */ - ComponentKey target_key(&ct->tar->id, DEPSNODE_TYPE_GEOMETRY); - add_relation(target_key, constraint_op_key, DEPSREL_TYPE_TRANSFORM, cti->name); - - /* NOTE: obdata eval now doesn't necessarily depend on the object's transform... */ - ComponentKey target_transform_key(&ct->tar->id, DEPSNODE_TYPE_TRANSFORM); - add_relation(target_transform_key, constraint_op_key, DEPSREL_TYPE_TRANSFORM, cti->name); + ComponentKey target_key(&ct->tar->id, DEG_NODE_TYPE_GEOMETRY); + add_relation(target_key, constraint_op_key, cti->name); + /* NOTE: obdata eval now doesn't necessarily depend on the + * object's transform. + */ + ComponentKey target_transform_key(&ct->tar->id, + DEG_NODE_TYPE_TRANSFORM); + add_relation(target_transform_key, constraint_op_key, cti->name); } else { - /* standard object relation */ + /* Standard object relation. */ // TODO: loc vs rot vs scale? if (&ct->tar->id == id) { /* Constraint targetting own object: - * - This case is fine IFF we're dealing with a bone constraint pointing to - * its own armature. In that case, it's just transform -> bone. - * - If however it is a real self targetting case, just make it depend on the - * previous constraint (or the pre-constraint state)... + * - This case is fine IFF we're dealing with a bone + * constraint pointing to its own armature. In that + * case, it's just transform -> bone. + * - If however it is a real self targetting case, just + * make it depend on the previous constraint (or the + * pre-constraint state). */ - if ((ct->tar->type == OB_ARMATURE) && (component_type == DEPSNODE_TYPE_BONE)) { - OperationKey target_key(&ct->tar->id, DEPSNODE_TYPE_TRANSFORM, DEG_OPCODE_TRANSFORM_FINAL); - add_relation(target_key, constraint_op_key, DEPSREL_TYPE_TRANSFORM, cti->name); + if ((ct->tar->type == OB_ARMATURE) && + (component_type == DEG_NODE_TYPE_BONE)) + { + OperationKey target_key(&ct->tar->id, + DEG_NODE_TYPE_TRANSFORM, + DEG_OPCODE_TRANSFORM_FINAL); + add_relation(target_key, constraint_op_key, cti->name); } else { - OperationKey target_key(&ct->tar->id, DEPSNODE_TYPE_TRANSFORM, DEG_OPCODE_TRANSFORM_LOCAL); - add_relation(target_key, constraint_op_key, DEPSREL_TYPE_TRANSFORM, cti->name); + OperationKey target_key(&ct->tar->id, + DEG_NODE_TYPE_TRANSFORM, + DEG_OPCODE_TRANSFORM_LOCAL); + add_relation(target_key, constraint_op_key, cti->name); } } else { - /* normal object dependency */ - OperationKey target_key(&ct->tar->id, DEPSNODE_TYPE_TRANSFORM, DEG_OPCODE_TRANSFORM_FINAL); - add_relation(target_key, constraint_op_key, DEPSREL_TYPE_TRANSFORM, cti->name); + /* Normal object dependency. */ + OperationKey target_key(&ct->tar->id, + DEG_NODE_TYPE_TRANSFORM, + DEG_OPCODE_TRANSFORM_FINAL); + add_relation(target_key, constraint_op_key, cti->name); } } - /* Constraints which needs world's matrix for transform. * TODO(sergey): More constraints here? */ @@ -723,14 +867,14 @@ void DepsgraphRelationBuilder::build_constraints(Scene *scene, ID *id, eDepsNode CONSTRAINT_TYPE_TRANSLIKE)) { /* TODO(sergey): Add used space check. */ - ComponentKey target_transform_key(&ct->tar->id, DEPSNODE_TYPE_TRANSFORM); - add_relation(target_transform_key, constraint_op_key, DEPSREL_TYPE_TRANSFORM, cti->name); + ComponentKey target_transform_key(&ct->tar->id, + DEG_NODE_TYPE_TRANSFORM); + add_relation(target_transform_key, constraint_op_key, cti->name); } - } - - if (cti->flush_constraint_targets) + if (cti->flush_constraint_targets) { cti->flush_constraint_targets(con, &targets, 1); + } } } } @@ -742,13 +886,13 @@ void DepsgraphRelationBuilder::build_animdata(ID *id) if (adt == NULL) return; - ComponentKey adt_key(id, DEPSNODE_TYPE_ANIMATION); + ComponentKey adt_key(id, DEG_NODE_TYPE_ANIMATION); /* animation */ if (adt->action || adt->nla_tracks.first) { /* wire up dependency to time source */ TimeSourceKey time_src_key; - add_relation(time_src_key, adt_key, DEPSREL_TYPE_TIME, "[TimeSrc -> Animation]"); + add_relation(time_src_key, adt_key, "[TimeSrc -> Animation]"); // XXX: Hook up specific update callbacks for special properties which may need it... @@ -758,9 +902,9 @@ void DepsgraphRelationBuilder::build_animdata(ID *id) /* drivers */ LINKLIST_FOREACH (FCurve *, fcu, &adt->drivers) { OperationKey driver_key(id, - DEPSNODE_TYPE_PARAMETERS, + DEG_NODE_TYPE_PARAMETERS, DEG_OPCODE_DRIVER, - fcu->rna_path, + fcu->rna_path ? fcu->rna_path : "", fcu->array_index); /* create the driver's relations to targets */ @@ -782,7 +926,8 @@ void DepsgraphRelationBuilder::build_animdata(ID *id) FCurve *fcu_prev = NULL; LINKLIST_FOREACH (FCurve *, fcu_candidate, &adt->drivers) { /* Writing to different RNA paths is */ - if (!STREQ(fcu_candidate->rna_path, fcu->rna_path)) { + const char *rna_path = fcu->rna_path ? fcu->rna_path : ""; + if (!STREQ(fcu_candidate->rna_path, rna_path)) { continue; } /* We only do relation from previous fcurve to previous one. */ @@ -798,26 +943,22 @@ void DepsgraphRelationBuilder::build_animdata(ID *id) } if (fcu_prev != NULL) { OperationKey prev_driver_key(id, - DEPSNODE_TYPE_PARAMETERS, + DEG_NODE_TYPE_PARAMETERS, DEG_OPCODE_DRIVER, - fcu_prev->rna_path, + fcu_prev->rna_path ? fcu_prev->rna_path : "", fcu_prev->array_index); OperationKey driver_key(id, - DEPSNODE_TYPE_PARAMETERS, + DEG_NODE_TYPE_PARAMETERS, DEG_OPCODE_DRIVER, - fcu->rna_path, + fcu->rna_path ? fcu->rna_path : "", fcu->array_index); - add_relation(prev_driver_key, - driver_key, - DEPSREL_TYPE_OPERATION, - "[Driver Order]"); + add_relation(prev_driver_key, driver_key, "[Driver Order]"); } } /* prevent driver from occurring before own animation... */ if (adt->action || adt->nla_tracks.first) { - add_relation(adt_key, driver_key, DEPSREL_TYPE_OPERATION, - "[AnimData Before Drivers]"); + add_relation(adt_key, driver_key, "[AnimData Before Drivers]"); } } } @@ -826,26 +967,32 @@ void DepsgraphRelationBuilder::build_driver(ID *id, FCurve *fcu) { ChannelDriver *driver = fcu->driver; OperationKey driver_key(id, - DEPSNODE_TYPE_PARAMETERS, + DEG_NODE_TYPE_PARAMETERS, DEG_OPCODE_DRIVER, - fcu->rna_path, + fcu->rna_path ? fcu->rna_path : "", fcu->array_index); bPoseChannel *pchan = NULL; - /* create dependency between driver and data affected by it */ + const char *rna_path = fcu->rna_path ? fcu->rna_path : ""; + + /* Create dependency between driver and data affected by it. */ /* - direct property relationship... */ //RNAPathKey affected_key(id, fcu->rna_path); - //add_relation(driver_key, affected_key, DEPSREL_TYPE_DRIVER, "[Driver -> Data] DepsRel"); + //add_relation(driver_key, affected_key, "[Driver -> Data] DepsRel"); - /* driver -> data components (for interleaved evaluation - bones/constraints/modifiers) */ - // XXX: this probably should probably be moved out into a separate function - if (strstr(fcu->rna_path, "pose.bones[") != NULL) { + /* Driver -> data components (for interleaved evaluation + * bones/constraints/modifiers). + */ + // XXX: this probably should probably be moved out into a separate function. + if (strstr(rna_path, "pose.bones[") != NULL) { /* interleaved drivers during bone eval */ - // TODO: ideally, if this is for a constraint, it goes to said constraint + /* TODO: ideally, if this is for a constraint, it goes to said + * constraint. + */ Object *ob = (Object *)id; char *bone_name; - bone_name = BLI_str_quoted_substrN(fcu->rna_path, "pose.bones["); + bone_name = BLI_str_quoted_substrN(rna_path, "pose.bones["); pchan = BKE_pose_channel_find_name(ob->pose, bone_name); if (bone_name) { @@ -854,109 +1001,122 @@ void DepsgraphRelationBuilder::build_driver(ID *id, FCurve *fcu) } if (pchan) { - OperationKey bone_key(id, DEPSNODE_TYPE_BONE, pchan->name, DEG_OPCODE_BONE_LOCAL); - add_relation(driver_key, bone_key, DEPSREL_TYPE_DRIVER, "[Driver -> Bone]"); + OperationKey bone_key(id, + DEG_NODE_TYPE_BONE, + pchan->name, + DEG_OPCODE_BONE_LOCAL); + add_relation(driver_key, bone_key, "[Driver -> Bone]"); } else { fprintf(stderr, "Couldn't find bone name for driver path - '%s'\n", - fcu->rna_path); + rna_path); } } - else if (GS(id->name) == ID_AR && strstr(fcu->rna_path, "bones[")) { - /* drivers on armature-level bone settings (i.e. bbone stuff), - * which will affect the evaluation of corresponding pose bones + else if (GS(id->name) == ID_AR && strstr(rna_path, "bones[")) { + /* Drivers on armature-level bone settings (i.e. bbone stuff), + * which will affect the evaluation of corresponding pose bones. */ IDDepsNode *arm_node = m_graph->find_id_node(id); - char *bone_name = BLI_str_quoted_substrN(fcu->rna_path, "bones["); + char *bone_name = BLI_str_quoted_substrN(rna_path, "bones["); if (arm_node && bone_name) { - /* find objects which use this, and make their eval callbacks depend on this */ + /* Find objects which use this, and make their eval callbacks + * depend on this. + */ foreach (DepsRelation *rel, arm_node->outlinks) { IDDepsNode *to_node = (IDDepsNode *)rel->to; - - /* we only care about objects with pose data which use this... */ + /* We only care about objects with pose data which use this. */ if (GS(to_node->id->name) == ID_OB) { Object *ob = (Object *)to_node->id; - bPoseChannel *pchan = BKE_pose_channel_find_name(ob->pose, bone_name); // NOTE: ob->pose may be NULL - - if (pchan) { - OperationKey bone_key(&ob->id, DEPSNODE_TYPE_BONE, pchan->name, DEG_OPCODE_BONE_LOCAL); - add_relation(driver_key, bone_key, DEPSREL_TYPE_DRIVER, "[Arm Bone -> Driver -> Bone]"); + /* NOTE: ob->pose may be NULL. */ + bPoseChannel *pchan = BKE_pose_channel_find_name( + ob->pose, bone_name); + if (pchan != NULL) { + OperationKey bone_key(&ob->id, + DEG_NODE_TYPE_BONE, + pchan->name, + DEG_OPCODE_BONE_LOCAL); + add_relation(driver_key, + bone_key, + "[Arm Bone -> Driver -> Bone]"); } } } - - /* free temp data */ + /* Free temp data. */ MEM_freeN(bone_name); bone_name = NULL; } else { fprintf(stderr, "Couldn't find armature bone name for driver path - '%s'\n", - fcu->rna_path); + rna_path); } } - else if (GS(id->name) == ID_OB && strstr(fcu->rna_path, "modifiers[")) { - /* modifier driver - connect directly to the modifier */ - char *modifier_name = BLI_str_quoted_substrN(fcu->rna_path, "modifiers["); - if (modifier_name) { - OperationKey modifier_key(id, - DEPSNODE_TYPE_GEOMETRY, - DEG_OPCODE_GEOMETRY_MODIFIER, - modifier_name); - if (has_node(modifier_key)) { - add_relation(driver_key, modifier_key, DEPSREL_TYPE_DRIVER, "[Driver -> Modifier]"); - } - else { - printf("Unexisting driver RNA path: %s\n", fcu->rna_path); - } - - MEM_freeN(modifier_name); + else if (GS(id->name) == ID_OB && strstr(rna_path, "modifiers[")) { + OperationKey modifier_key(id, + DEG_NODE_TYPE_GEOMETRY, + DEG_OPCODE_GEOMETRY_UBEREVAL); + if (has_node(modifier_key)) { + add_relation(driver_key, modifier_key, "[Driver -> Modifier]"); + } + else { + printf("Unexisting driver RNA path: %s\n", rna_path); } } - else if (GS(id->name) == ID_KE && strstr(fcu->rna_path, "key_blocks[")) { - /* shape key driver - hook into the base geometry operation */ + else if (GS(id->name) == ID_KE && strstr(rna_path, "key_blocks[")) { + /* Shape key driver - hook into the base geometry operation. */ // XXX: double check where this points Key *shape_key = (Key *)id; - ComponentKey geometry_key(shape_key->from, DEPSNODE_TYPE_GEOMETRY); - add_relation(driver_key, geometry_key, DEPSREL_TYPE_DRIVER, "[Driver -> ShapeKey Geom]"); + ComponentKey geometry_key(shape_key->from, DEG_NODE_TYPE_GEOMETRY); + add_relation(driver_key, geometry_key, "[Driver -> ShapeKey Geom]"); } - else if (strstr(fcu->rna_path, "key_blocks[")) { - ComponentKey geometry_key(id, DEPSNODE_TYPE_GEOMETRY); - add_relation(driver_key, geometry_key, DEPSREL_TYPE_DRIVER, "[Driver -> ShapeKey Geom]"); + else if (strstr(rna_path, "key_blocks[")) { + ComponentKey geometry_key(id, DEG_NODE_TYPE_GEOMETRY); + add_relation(driver_key, geometry_key, "[Driver -> ShapeKey Geom]"); } else { if (GS(id->name) == ID_OB) { /* assume that driver affects a transform... */ - OperationKey local_transform_key(id, DEPSNODE_TYPE_TRANSFORM, DEG_OPCODE_TRANSFORM_LOCAL); - add_relation(driver_key, local_transform_key, DEPSREL_TYPE_OPERATION, "[Driver -> Transform]"); + OperationKey local_transform_key(id, + DEG_NODE_TYPE_TRANSFORM, + DEG_OPCODE_TRANSFORM_LOCAL); + add_relation(driver_key, + local_transform_key, + "[Driver -> Transform]"); } else if (GS(id->name) == ID_KE) { - ComponentKey geometry_key(id, DEPSNODE_TYPE_GEOMETRY); - add_relation(driver_key, geometry_key, DEPSREL_TYPE_GEOMETRY_EVAL, "[Driver -> Shapekey Geometry]"); + ComponentKey geometry_key(id, DEG_NODE_TYPE_GEOMETRY); + add_relation(driver_key, + geometry_key, + "[Driver -> Shapekey Geometry]"); } } - - /* ensure that affected prop's update callbacks will be triggered once done */ - // TODO: implement this once the functionality to add these links exists in RNA - // XXX: the data itself could also set this, if it were to be truly initialised later? - - /* loop over variables to get the target relationships */ + /* Ensure that affected prop's update callbacks will be triggered once + * done. + */ + /* TODO: Implement this once the functionality to add these links exists + * RNA. + */ + /* XXX: the data itself could also set this, if it were to be truly + * initialised later? + */ + /* Loop over variables to get the target relationships. */ LINKLIST_FOREACH (DriverVar *, dvar, &driver->variables) { - /* only used targets */ + /* Only used targets. */ DRIVER_TARGETS_USED_LOOPER(dvar) { - if (dtar->id == NULL) + if (dtar->id == NULL) { continue; - - /* special handling for directly-named bones */ + } + /* Special handling for directly-named bones. */ if ((dtar->flag & DTAR_FLAG_STRUCT_REF) && (dtar->pchan_name[0])) { Object *ob = (Object *)dtar->id; - bPoseChannel *target_pchan = BKE_pose_channel_find_name(ob->pose, dtar->pchan_name); + bPoseChannel *target_pchan = + BKE_pose_channel_find_name(ob->pose, dtar->pchan_name); if (target_pchan != NULL) { - /* get node associated with bone */ + /* Get node associated with bone. */ // XXX: watch the space! /* Some cases can't use final bone transform, for example: * - Driving the bone with itself (addressed here) @@ -968,61 +1128,81 @@ void DepsgraphRelationBuilder::build_driver(ID *id, FCurve *fcu) { continue; } - OperationKey target_key(dtar->id, DEPSNODE_TYPE_BONE, target_pchan->name, DEG_OPCODE_BONE_DONE); - add_relation(target_key, driver_key, DEPSREL_TYPE_DRIVER_TARGET, "[Bone Target -> Driver]"); + OperationKey target_key(dtar->id, + DEG_NODE_TYPE_BONE, + target_pchan->name, + DEG_OPCODE_BONE_DONE); + add_relation(target_key, + driver_key, + "[Bone Target -> Driver]"); } } else if (dtar->flag & DTAR_FLAG_STRUCT_REF) { - /* get node associated with the object's transforms */ - OperationKey target_key(dtar->id, DEPSNODE_TYPE_TRANSFORM, DEG_OPCODE_TRANSFORM_FINAL); - add_relation(target_key, driver_key, DEPSREL_TYPE_DRIVER_TARGET, "[Target -> Driver]"); + /* Get node associated with the object's transforms. */ + if (dtar->id == id) { + /* Ignore input dependency if we're driving properties of + * the same ID, otherwise we'll be ending up in a cyclic + * dependency here. + */ + continue; + } + OperationKey target_key(dtar->id, + DEG_NODE_TYPE_TRANSFORM, + DEG_OPCODE_TRANSFORM_FINAL); + add_relation(target_key, driver_key, "[Target -> Driver]"); } else if (dtar->rna_path && strstr(dtar->rna_path, "pose.bones[")) { - /* workaround for ensuring that local bone transforms don't end up - * having to wait for pose eval to finish (to prevent cycles) + /* Workaround for ensuring that local bone transforms don't end + * up having to wait for pose eval to finish (to prevent cycles). */ Object *ob = (Object *)dtar->id; - char *bone_name = BLI_str_quoted_substrN(dtar->rna_path, "pose.bones["); - bPoseChannel *target_pchan = BKE_pose_channel_find_name(ob->pose, bone_name); - if (bone_name) { + char *bone_name = BLI_str_quoted_substrN(dtar->rna_path, + "pose.bones["); + bPoseChannel *target_pchan = + BKE_pose_channel_find_name(ob->pose, bone_name); + if (bone_name != NULL) { MEM_freeN(bone_name); bone_name = NULL; } - if (target_pchan) { + if (target_pchan != NULL) { if (dtar->id == id && pchan != NULL && STREQ(pchan->name, target_pchan->name)) { continue; } - OperationKey bone_key(dtar->id, DEPSNODE_TYPE_BONE, target_pchan->name, DEG_OPCODE_BONE_LOCAL); - add_relation(bone_key, driver_key, DEPSREL_TYPE_DRIVER, "[RNA Bone -> Driver]"); + OperationKey bone_key(dtar->id, + DEG_NODE_TYPE_BONE, + target_pchan->name, + DEG_OPCODE_BONE_LOCAL); + add_relation(bone_key, driver_key, "[RNA Bone -> Driver]"); } } else { if (dtar->id == id) { - /* Ignore input dependency if we're driving properties of the same ID, - * otherwise we'll be ending up in a cyclic dependency here. + /* Ignore input dependency if we're driving properties of + * the same ID, otherwise we'll be ending up in a cyclic + * dependency here. */ continue; } - /* resolve path to get node */ - RNAPathKey target_key(dtar->id, dtar->rna_path ? dtar->rna_path : ""); - add_relation(target_key, driver_key, DEPSREL_TYPE_DRIVER_TARGET, "[RNA Target -> Driver]"); + /* Resolve path to get node. */ + RNAPathKey target_key(dtar->id, + dtar->rna_path ? dtar->rna_path : ""); + add_relation(target_key, driver_key, "[RNA Target -> Driver]"); } } DRIVER_TARGETS_LOOPER_END } - - /* It's quite tricky to detect if the driver actually depends on time or not, - * so for now we'll be quite conservative here about optimization and consider - * all python drivers to be depending on time. + /* It's quite tricky to detect if the driver actually depends on time or + * not, so for now we'll be quite conservative here about optimization and + * consider all python drivers to be depending on time. */ if ((driver->type == DRIVER_TYPE_PYTHON) && python_driver_depends_on_time(driver)) { TimeSourceKey time_src_key; - add_relation(time_src_key, driver_key, DEPSREL_TYPE_TIME, "[TimeSrc -> Driver]"); + add_relation(time_src_key, driver_key, "[TimeSrc -> Driver]"); } } @@ -1039,28 +1219,32 @@ void DepsgraphRelationBuilder::build_world(World *world) /* TODO: other settings? */ /* textures */ - build_texture_stack(world_id, world->mtex); + build_texture_stack(world->mtex); /* world's nodetree */ - build_nodetree(world_id, world->nodetree); + if (world->nodetree != NULL) { + build_nodetree(world->nodetree); + ComponentKey ntree_key(&world->nodetree->id, DEG_NODE_TYPE_PARAMETERS); + ComponentKey world_key(world_id, DEG_NODE_TYPE_PARAMETERS); + add_relation(ntree_key, world_key, "NTree->World Parameters"); + } } void DepsgraphRelationBuilder::build_rigidbody(Scene *scene) { RigidBodyWorld *rbw = scene->rigidbody_world; - OperationKey init_key(&scene->id, DEPSNODE_TYPE_TRANSFORM, DEG_OPCODE_RIGIDBODY_REBUILD); - OperationKey sim_key(&scene->id, DEPSNODE_TYPE_TRANSFORM, DEG_OPCODE_RIGIDBODY_SIM); + OperationKey init_key(&scene->id, DEG_NODE_TYPE_TRANSFORM, DEG_OPCODE_RIGIDBODY_REBUILD); + OperationKey sim_key(&scene->id, DEG_NODE_TYPE_TRANSFORM, DEG_OPCODE_RIGIDBODY_SIM); /* rel between the two sim-nodes */ - add_relation(init_key, sim_key, DEPSREL_TYPE_OPERATION, "Rigidbody [Init -> SimStep]"); + add_relation(init_key, sim_key, "Rigidbody [Init -> SimStep]"); /* set up dependencies between these operations and other builtin nodes --------------- */ /* time dependency */ TimeSourceKey time_src_key; - add_relation(time_src_key, init_key, DEPSREL_TYPE_TIME, "TimeSrc -> Rigidbody Reset/Rebuild (Optional)"); - add_relation(time_src_key, sim_key, DEPSREL_TYPE_TIME, "TimeSrc -> Rigidbody Sim Step"); + add_relation(time_src_key, init_key, "TimeSrc -> Rigidbody Reset/Rebuild (Optional)"); /* objects - simulation participants */ if (rbw->group) { @@ -1078,13 +1262,12 @@ void DepsgraphRelationBuilder::build_rigidbody(Scene *scene) * XXX: there's probably a difference between passive and active * - passive don't change, so may need to know full transform... */ - OperationKey rbo_key(&ob->id, DEPSNODE_TYPE_TRANSFORM, DEG_OPCODE_TRANSFORM_RIGIDBODY); + OperationKey rbo_key(&ob->id, DEG_NODE_TYPE_TRANSFORM, DEG_OPCODE_TRANSFORM_RIGIDBODY); eDepsOperation_Code trans_opcode = ob->parent ? DEG_OPCODE_TRANSFORM_PARENT : DEG_OPCODE_TRANSFORM_LOCAL; - OperationKey trans_op(&ob->id, DEPSNODE_TYPE_TRANSFORM, trans_opcode); + OperationKey trans_op(&ob->id, DEG_NODE_TYPE_TRANSFORM, trans_opcode); - add_relation(trans_op, rbo_key, DEPSREL_TYPE_OPERATION, "Base Ob Transform -> RBO Sync"); - add_relation(sim_key, rbo_key, DEPSREL_TYPE_COMPONENT_ORDER, "Rigidbody Sim Eval -> RBO Sync"); + add_relation(sim_key, rbo_key, "Rigidbody Sim Eval -> RBO Sync"); /* if constraints exist, those depend on the result of the rigidbody sim * - This allows constraints to modify the result of the sim (i.e. clamping) @@ -1095,22 +1278,25 @@ void DepsgraphRelationBuilder::build_rigidbody(Scene *scene) * to control whether rigidbody eval gets interleaved into the constraint stack */ if (ob->constraints.first) { - OperationKey constraint_key(&ob->id, DEPSNODE_TYPE_TRANSFORM, DEG_OPCODE_TRANSFORM_CONSTRAINTS); - add_relation(rbo_key, constraint_key, DEPSREL_TYPE_COMPONENT_ORDER, "RBO Sync -> Ob Constraints"); + OperationKey constraint_key(&ob->id, + DEG_NODE_TYPE_TRANSFORM, + DEG_OPCODE_TRANSFORM_CONSTRAINTS); + add_relation(rbo_key, constraint_key, "RBO Sync -> Ob Constraints"); } else { - /* final object transform depends on rigidbody */ - OperationKey done_key(&ob->id, DEPSNODE_TYPE_TRANSFORM, DEG_OPCODE_TRANSFORM_FINAL); - add_relation(rbo_key, done_key, DEPSREL_TYPE_COMPONENT_ORDER, "RBO Sync -> Done"); - - // XXX: ubereval will be removed eventually, but we still need it in the meantime - OperationKey uber_key(&ob->id, DEPSNODE_TYPE_TRANSFORM, DEG_OPCODE_OBJECT_UBEREVAL); - add_relation(rbo_key, uber_key, DEPSREL_TYPE_COMPONENT_ORDER, "RBO Sync -> Uber (Temp)"); + /* Final object transform depends on rigidbody. + * + * NOTE: Currently we consider final here an ubereval node. + * If it is gone we'll need to reconsider relation here. + */ + OperationKey uber_key(&ob->id, + DEG_NODE_TYPE_TRANSFORM, + DEG_OPCODE_OBJECT_UBEREVAL); + add_relation(rbo_key, uber_key, "RBO Sync -> Uber (Temp)"); } - - /* needed to get correct base values */ - add_relation(trans_op, sim_key, DEPSREL_TYPE_OPERATION, "Base Ob Transform -> Rigidbody Sim Eval"); + /* Needed to get correct base values. */ + add_relation(trans_op, sim_key, "Base Ob Transform -> Rigidbody Sim Eval"); } } @@ -1127,16 +1313,16 @@ void DepsgraphRelationBuilder::build_rigidbody(Scene *scene) /* final result of the constraint object's transform controls how the * constraint affects the physics sim for these objects */ - ComponentKey trans_key(&ob->id, DEPSNODE_TYPE_TRANSFORM); - OperationKey ob1_key(&rbc->ob1->id, DEPSNODE_TYPE_TRANSFORM, DEG_OPCODE_TRANSFORM_RIGIDBODY); - OperationKey ob2_key(&rbc->ob2->id, DEPSNODE_TYPE_TRANSFORM, DEG_OPCODE_TRANSFORM_RIGIDBODY); + ComponentKey trans_key(&ob->id, DEG_NODE_TYPE_TRANSFORM); + OperationKey ob1_key(&rbc->ob1->id, DEG_NODE_TYPE_TRANSFORM, DEG_OPCODE_TRANSFORM_RIGIDBODY); + OperationKey ob2_key(&rbc->ob2->id, DEG_NODE_TYPE_TRANSFORM, DEG_OPCODE_TRANSFORM_RIGIDBODY); /* - constrained-objects sync depends on the constraint-holder */ - add_relation(trans_key, ob1_key, DEPSREL_TYPE_TRANSFORM, "RigidBodyConstraint -> RBC.Object_1"); - add_relation(trans_key, ob2_key, DEPSREL_TYPE_TRANSFORM, "RigidBodyConstraint -> RBC.Object_2"); + add_relation(trans_key, ob1_key, "RigidBodyConstraint -> RBC.Object_1"); + add_relation(trans_key, ob2_key, "RigidBodyConstraint -> RBC.Object_2"); /* - ensure that sim depends on this constraint's transform */ - add_relation(trans_key, sim_key, DEPSREL_TYPE_TRANSFORM, "RigidBodyConstraint Transform -> RB Simulation"); + add_relation(trans_key, sim_key, "RigidBodyConstraint Transform -> RB Simulation"); } } } @@ -1145,8 +1331,15 @@ void DepsgraphRelationBuilder::build_particles(Scene *scene, Object *ob) { TimeSourceKey time_src_key; OperationKey obdata_ubereval_key(&ob->id, - DEPSNODE_TYPE_GEOMETRY, + DEG_NODE_TYPE_GEOMETRY, DEG_OPCODE_GEOMETRY_UBEREVAL); + OperationKey eval_init_key(&ob->id, + DEG_NODE_TYPE_EVAL_PARTICLES, + DEG_OPCODE_PSYS_EVAL_INIT); + /* TODO(sergey): Are all particle systems depends on time? + * Hair without dynamics i.e. + */ + add_relation(time_src_key, eval_init_key, "TimeSrc -> PSys"); /* particle systems */ LINKLIST_FOREACH (ParticleSystem *, psys, &ob->particlesystem) { @@ -1156,60 +1349,27 @@ void DepsgraphRelationBuilder::build_particles(Scene *scene, Object *ob) build_animdata(&part->id); /* this particle system */ - OperationKey psys_key(&ob->id, DEPSNODE_TYPE_EVAL_PARTICLES, DEG_OPCODE_PSYS_EVAL, psys->name); + OperationKey psys_key(&ob->id, DEG_NODE_TYPE_EVAL_PARTICLES, DEG_OPCODE_PSYS_EVAL, psys->name); /* XXX: if particle system is later re-enabled, we must do full rebuild? */ if (!psys_check_enabled(ob, psys, G.is_rendering)) continue; - /* TODO(sergey): Are all particle systems depends on time? - * Hair without dynamics i.e. - */ - add_relation(time_src_key, psys_key, - DEPSREL_TYPE_TIME, - "TimeSrc -> PSys"); + add_relation(eval_init_key, psys_key, "Init -> PSys"); /* TODO(sergey): Currently particle update is just a placeholder, * hook it to the ubereval node so particle system is getting updated * on playback. */ - add_relation(psys_key, - obdata_ubereval_key, - DEPSREL_TYPE_OPERATION, - "PSys -> UberEval"); - -#if 0 - if (ELEM(part->phystype, PART_PHYS_KEYED, PART_PHYS_BOIDS)) { - LINKLIST_FOREACH (ParticleTarget *, pt, &psys->targets) { - if (pt->ob && BLI_findlink(&pt->ob->particlesystem, pt->psys - 1)) { - node2 = dag_get_node(dag, pt->ob); - dag_add_relation(dag, node2, node, DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "Particle Targets"); - } - } - } - - if (part->ren_as == PART_DRAW_OB && part->dup_ob) { - node2 = dag_get_node(dag, part->dup_ob); - /* note that this relation actually runs in the wrong direction, the problem - * is that dupli system all have this (due to parenting), and the render - * engine instancing assumes particular ordering of objects in list */ - dag_add_relation(dag, node, node2, DAG_RL_OB_OB, "Particle Object Visualization"); - if (part->dup_ob->type == OB_MBALL) - dag_add_relation(dag, node, node2, DAG_RL_DATA_DATA, "Particle Object Visualization"); - } - - if (part->ren_as == PART_DRAW_GR && part->dup_group) { - LINKLIST_FOREACH (GroupObject *, go, &part->dup_group->gobject) { - node2 = dag_get_node(dag, go->ob); - dag_add_relation(dag, node2, node, DAG_RL_OB_OB, "Particle Group Visualization"); - } - } -#endif + add_relation(psys_key, obdata_ubereval_key, "PSys -> UberEval"); /* collisions */ if (part->type != PART_HAIR) { add_collision_relations(psys_key, scene, ob, part->collision_group, ob->lay, true, "Particle Collision"); } + else if ((psys->flag & PSYS_HAIR_DYNAMICS) && psys->clmd && psys->clmd->coll_parms) { + add_collision_relations(psys_key, scene, ob, psys->clmd->coll_parms->group, ob->lay | scene->lay, true, "Hair Collision"); + } /* effectors */ add_forcefield_relations(psys_key, scene, ob, psys, part->effector_weights, part->type == PART_HAIR, "Particle Field"); @@ -1225,19 +1385,16 @@ void DepsgraphRelationBuilder::build_particles(Scene *scene, Object *ob) ruleob = ((BoidRuleFollowLeader *)rule)->ob; if (ruleob) { - ComponentKey ruleob_key(&ruleob->id, DEPSNODE_TYPE_TRANSFORM); - add_relation(ruleob_key, psys_key, DEPSREL_TYPE_TRANSFORM, "Boid Rule"); + ComponentKey ruleob_key(&ruleob->id, DEG_NODE_TYPE_TRANSFORM); + add_relation(ruleob_key, psys_key, "Boid Rule"); } } } } if (part->ren_as == PART_DRAW_OB && part->dup_ob) { - ComponentKey dup_ob_key(&part->dup_ob->id, DEPSNODE_TYPE_TRANSFORM); - add_relation(dup_ob_key, - psys_key, - DEPSREL_TYPE_TRANSFORM, - "Particle Object Visualization"); + ComponentKey dup_ob_key(&part->dup_ob->id, DEG_NODE_TYPE_TRANSFORM); + add_relation(dup_ob_key, psys_key, "Particle Object Visualization"); } } @@ -1247,20 +1404,32 @@ void DepsgraphRelationBuilder::build_particles(Scene *scene, Object *ob) * TODO(sergey): This relation should be altered once real granular update * is implemented. */ - ComponentKey transform_key(&ob->id, DEPSNODE_TYPE_TRANSFORM); - add_relation(transform_key, - obdata_ubereval_key, - DEPSREL_TYPE_GEOMETRY_EVAL, - "Partcile Eval"); + ComponentKey transform_key(&ob->id, DEG_NODE_TYPE_TRANSFORM); + add_relation(transform_key, obdata_ubereval_key, "Partcile Eval"); /* pointcache */ // TODO... } +void DepsgraphRelationBuilder::build_cloth(Scene * /*scene*/, + Object *object, + ModifierData * /*md*/) +{ + OperationKey cache_key(&object->id, + DEG_NODE_TYPE_CACHE, + DEG_OPCODE_PLACEHOLDER, + "Cloth Modifier"); + /* Cache component affects on modifier. */ + OperationKey modifier_key(&object->id, + DEG_NODE_TYPE_GEOMETRY, + DEG_OPCODE_GEOMETRY_UBEREVAL); + add_relation(cache_key, modifier_key, "Cloth Cache -> Cloth"); +} + /* Shapekeys */ void DepsgraphRelationBuilder::build_shapekeys(ID *obdata, Key *key) { - ComponentKey obdata_key(obdata, DEPSNODE_TYPE_GEOMETRY); + ComponentKey obdata_key(obdata, DEG_NODE_TYPE_GEOMETRY); /* attach animdata to geometry */ build_animdata(&key->id); @@ -1268,8 +1437,8 @@ void DepsgraphRelationBuilder::build_shapekeys(ID *obdata, Key *key) if (key->adt) { // TODO: this should really be handled in build_animdata, since many of these cases will need it if (key->adt->action || key->adt->nla_tracks.first) { - ComponentKey adt_key(&key->id, DEPSNODE_TYPE_ANIMATION); - add_relation(adt_key, obdata_key, DEPSREL_TYPE_OPERATION, "Animation"); + ComponentKey adt_key(&key->id, DEG_NODE_TYPE_ANIMATION); + add_relation(adt_key, obdata_key, "Animation"); } /* NOTE: individual shapekey drivers are handled above already */ @@ -1277,8 +1446,8 @@ void DepsgraphRelationBuilder::build_shapekeys(ID *obdata, Key *key) /* attach to geometry */ // XXX: aren't shapekeys now done as a pseudo-modifier on object? - //ComponentKey key_key(&key->id, DEPSNODE_TYPE_GEOMETRY); // FIXME: this doesn't exist - //add_relation(key_key, obdata_key, DEPSREL_TYPE_GEOMETRY_EVAL, "Shapekeys"); + //ComponentKey key_key(&key->id, DEG_NODE_TYPE_GEOMETRY); // FIXME: this doesn't exist + //add_relation(key_key, obdata_key, "Shapekeys"); } /** @@ -1306,34 +1475,26 @@ void DepsgraphRelationBuilder::build_obdata_geom(Main *bmain, Scene *scene, Obje ID *obdata = (ID *)ob->data; /* Init operation of object-level geometry evaluation. */ - OperationKey geom_init_key(&ob->id, DEPSNODE_TYPE_GEOMETRY, DEG_OPCODE_PLACEHOLDER, "Eval Init"); + OperationKey geom_init_key(&ob->id, DEG_NODE_TYPE_GEOMETRY, DEG_OPCODE_PLACEHOLDER, "Eval Init"); /* get nodes for result of obdata's evaluation, and geometry evaluation on object */ - ComponentKey obdata_geom_key(obdata, DEPSNODE_TYPE_GEOMETRY); - ComponentKey geom_key(&ob->id, DEPSNODE_TYPE_GEOMETRY); + ComponentKey obdata_geom_key(obdata, DEG_NODE_TYPE_GEOMETRY); + ComponentKey geom_key(&ob->id, DEG_NODE_TYPE_GEOMETRY); /* link components to each other */ - add_relation(obdata_geom_key, geom_key, DEPSREL_TYPE_DATABLOCK, "Object Geometry Base Data"); + add_relation(obdata_geom_key, geom_key, "Object Geometry Base Data"); /* Modifiers */ - if (ob->modifiers.first) { - OperationKey prev_mod_key; + if (ob->modifiers.first != NULL) { + OperationKey obdata_ubereval_key(&ob->id, + DEG_NODE_TYPE_GEOMETRY, + DEG_OPCODE_GEOMETRY_UBEREVAL); LINKLIST_FOREACH (ModifierData *, md, &ob->modifiers) { const ModifierTypeInfo *mti = modifierType_getInfo((ModifierType)md->type); - OperationKey mod_key(&ob->id, DEPSNODE_TYPE_GEOMETRY, DEG_OPCODE_GEOMETRY_MODIFIER, md->name); - - if (md->prev) { - /* Stack relation: modifier depends on previous modifier in the stack */ - add_relation(prev_mod_key, mod_key, DEPSREL_TYPE_GEOMETRY_EVAL, "Modifier Stack"); - } - else { - /* Stack relation: first modifier depends on the geometry. */ - add_relation(geom_init_key, mod_key, DEPSREL_TYPE_GEOMETRY_EVAL, "Modifier Stack"); - } if (mti->updateDepsgraph) { - DepsNodeHandle handle = create_node_handle(mod_key); + DepsNodeHandle handle = create_node_handle(obdata_ubereval_key); mti->updateDepsgraph( md, bmain, @@ -1344,7 +1505,7 @@ void DepsgraphRelationBuilder::build_obdata_geom(Main *bmain, Scene *scene, Obje if (BKE_object_modifier_use_time(ob, md)) { TimeSourceKey time_src_key; - add_relation(time_src_key, mod_key, DEPSREL_TYPE_TIME, "Time Source"); + add_relation(time_src_key, obdata_ubereval_key, "Time Source"); /* Hacky fix for T45633 (Animated modifiers aren't updated) * @@ -1353,24 +1514,24 @@ void DepsgraphRelationBuilder::build_obdata_geom(Main *bmain, Scene *scene, Obje */ /* XXX: Remove this hack when these links are added as part of build_animdata() instead */ if (modifier_dependsOnTime(md) == false && needs_animdata_node(&ob->id)) { - ComponentKey animation_key(&ob->id, DEPSNODE_TYPE_ANIMATION); - add_relation(animation_key, mod_key, DEPSREL_TYPE_OPERATION, "Modifier Animation"); + ComponentKey animation_key(&ob->id, DEG_NODE_TYPE_ANIMATION); + add_relation(animation_key, obdata_ubereval_key, "Modifier Animation"); } } - prev_mod_key = mod_key; + if (md->type == eModifierType_Cloth) { + build_cloth(scene, ob, md); + } } } /* materials */ if (ob->totcol) { - int a; - - for (a = 1; a <= ob->totcol; a++) { + for (int a = 1; a <= ob->totcol; a++) { Material *ma = give_current_material(ob, a); - - if (ma) - build_material(&ob->id, ma); + if (ma != NULL) { + build_material(ma); + } } } @@ -1385,15 +1546,8 @@ void DepsgraphRelationBuilder::build_obdata_geom(Main *bmain, Scene *scene, Obje */ if (ob->type != OB_ARMATURE) { /* Armatures does no longer require uber node. */ - OperationKey obdata_ubereval_key(&ob->id, DEPSNODE_TYPE_GEOMETRY, DEG_OPCODE_GEOMETRY_UBEREVAL); - if (ob->modifiers.last) { - ModifierData *md = (ModifierData *)ob->modifiers.last; - OperationKey mod_key(&ob->id, DEPSNODE_TYPE_GEOMETRY, DEG_OPCODE_GEOMETRY_MODIFIER, md->name); - add_relation(mod_key, obdata_ubereval_key, DEPSREL_TYPE_OPERATION, "Object Geometry UberEval"); - } - else { - add_relation(geom_init_key, obdata_ubereval_key, DEPSREL_TYPE_OPERATION, "Object Geometry UberEval"); - } + OperationKey obdata_ubereval_key(&ob->id, DEG_NODE_TYPE_GEOMETRY, DEG_OPCODE_GEOMETRY_UBEREVAL); + add_relation(geom_init_key, obdata_ubereval_key, "Object Geometry UberEval"); } if (obdata->tag & LIB_TAG_DOIT) { @@ -1402,13 +1556,26 @@ void DepsgraphRelationBuilder::build_obdata_geom(Main *bmain, Scene *scene, Obje obdata->tag |= LIB_TAG_DOIT; /* Link object data evaluation node to exit operation. */ - OperationKey obdata_geom_eval_key(obdata, DEPSNODE_TYPE_GEOMETRY, DEG_OPCODE_PLACEHOLDER, "Geometry Eval"); - OperationKey obdata_geom_done_key(obdata, DEPSNODE_TYPE_GEOMETRY, DEG_OPCODE_PLACEHOLDER, "Eval Done"); - add_relation(obdata_geom_eval_key, obdata_geom_done_key, DEPSREL_TYPE_DATABLOCK, "ObData Geom Eval Done"); + OperationKey obdata_geom_eval_key(obdata, DEG_NODE_TYPE_GEOMETRY, DEG_OPCODE_PLACEHOLDER, "Geometry Eval"); + OperationKey obdata_geom_done_key(obdata, DEG_NODE_TYPE_GEOMETRY, DEG_OPCODE_PLACEHOLDER, "Eval Done"); + add_relation(obdata_geom_eval_key, obdata_geom_done_key, "ObData Geom Eval Done"); /* type-specific node/links */ switch (ob->type) { case OB_MESH: + /* NOTE: This is compatibility code to support particle systems + * + * for viewport being properly rendered in final render mode. + * This relation is similar to what dag_object_time_update_flags() + * was doing for mesh objects with particle system/ + * + * Ideally we need to get rid of this relation. + */ + if (ob->particlesystem.first != NULL) { + TimeSourceKey time_key; + OperationKey obdata_ubereval_key(&ob->id, DEG_NODE_TYPE_GEOMETRY, DEG_OPCODE_GEOMETRY_UBEREVAL); + add_relation(time_key, obdata_ubereval_key, "Legacy particle time"); + } break; case OB_MBALL: @@ -1418,10 +1585,10 @@ void DepsgraphRelationBuilder::build_obdata_geom(Main *bmain, Scene *scene, Obje /* motherball - mom depends on children! */ if (mom != ob) { /* non-motherball -> cannot be directly evaluated! */ - ComponentKey mom_key(&mom->id, DEPSNODE_TYPE_GEOMETRY); - ComponentKey transform_key(&ob->id, DEPSNODE_TYPE_TRANSFORM); - add_relation(geom_key, mom_key, DEPSREL_TYPE_GEOMETRY_EVAL, "Metaball Motherball"); - add_relation(transform_key, mom_key, DEPSREL_TYPE_GEOMETRY_EVAL, "Metaball Motherball"); + ComponentKey mom_key(&mom->id, DEG_NODE_TYPE_GEOMETRY); + ComponentKey transform_key(&ob->id, DEG_NODE_TYPE_TRANSFORM); + add_relation(geom_key, mom_key, "Metaball Motherball"); + add_relation(transform_key, mom_key, "Metaball Motherball"); } break; } @@ -1434,20 +1601,20 @@ void DepsgraphRelationBuilder::build_obdata_geom(Main *bmain, Scene *scene, Obje /* curve's dependencies */ // XXX: these needs geom data, but where is geom stored? if (cu->bevobj) { - ComponentKey bevob_key(&cu->bevobj->id, DEPSNODE_TYPE_GEOMETRY); + ComponentKey bevob_key(&cu->bevobj->id, DEG_NODE_TYPE_GEOMETRY); build_object(bmain, scene, cu->bevobj); - add_relation(bevob_key, geom_key, DEPSREL_TYPE_GEOMETRY_EVAL, "Curve Bevel"); + add_relation(bevob_key, geom_key, "Curve Bevel"); } if (cu->taperobj) { - ComponentKey taperob_key(&cu->taperobj->id, DEPSNODE_TYPE_GEOMETRY); + ComponentKey taperob_key(&cu->taperobj->id, DEG_NODE_TYPE_GEOMETRY); build_object(bmain, scene, cu->taperobj); - add_relation(taperob_key, geom_key, DEPSREL_TYPE_GEOMETRY_EVAL, "Curve Taper"); + add_relation(taperob_key, geom_key, "Curve Taper"); } if (ob->type == OB_FONT) { if (cu->textoncurve) { - ComponentKey textoncurve_key(&cu->textoncurve->id, DEPSNODE_TYPE_GEOMETRY); + ComponentKey textoncurve_key(&cu->textoncurve->id, DEG_NODE_TYPE_GEOMETRY); build_object(bmain, scene, cu->textoncurve); - add_relation(textoncurve_key, geom_key, DEPSREL_TYPE_GEOMETRY_EVAL, "Text on Curve"); + add_relation(textoncurve_key, geom_key, "Text on Curve"); } } break; @@ -1471,14 +1638,13 @@ void DepsgraphRelationBuilder::build_obdata_geom(Main *bmain, Scene *scene, Obje } if (needs_animdata_node(obdata)) { - ComponentKey animation_key(obdata, DEPSNODE_TYPE_ANIMATION); - ComponentKey parameters_key(obdata, DEPSNODE_TYPE_PARAMETERS); - add_relation(animation_key, parameters_key, - DEPSREL_TYPE_COMPONENT_ORDER, "Geom Parameters"); + ComponentKey animation_key(obdata, DEG_NODE_TYPE_ANIMATION); + ComponentKey parameters_key(obdata, DEG_NODE_TYPE_PARAMETERS); + add_relation(animation_key, parameters_key, "Geom Parameters"); /* Evaluation usually depends on animation. * TODO(sergey): Need to re-hook it after granular update is implemented.. */ - add_relation(animation_key, obdata_geom_eval_key, DEPSREL_TYPE_GEOMETRY_EVAL, "Animation"); + add_relation(animation_key, obdata_geom_eval_key, "Animation"); } } @@ -1493,19 +1659,18 @@ void DepsgraphRelationBuilder::build_camera(Object *ob) } camera_id->tag |= LIB_TAG_DOIT; - ComponentKey parameters_key(camera_id, DEPSNODE_TYPE_PARAMETERS); + ComponentKey parameters_key(camera_id, DEG_NODE_TYPE_PARAMETERS); if (needs_animdata_node(camera_id)) { - ComponentKey animation_key(camera_id, DEPSNODE_TYPE_ANIMATION); - add_relation(animation_key, parameters_key, - DEPSREL_TYPE_COMPONENT_ORDER, "Camera Parameters"); + ComponentKey animation_key(camera_id, DEG_NODE_TYPE_ANIMATION); + add_relation(animation_key, parameters_key, "Camera Parameters"); } /* DOF */ if (cam->dof_ob) { - ComponentKey ob_param_key(&ob->id, DEPSNODE_TYPE_PARAMETERS); - ComponentKey dof_ob_key(&cam->dof_ob->id, DEPSNODE_TYPE_TRANSFORM); - add_relation(dof_ob_key, ob_param_key, DEPSREL_TYPE_TRANSFORM, "Camera DOF"); + ComponentKey ob_param_key(&ob->id, DEG_NODE_TYPE_PARAMETERS); + ComponentKey dof_ob_key(&cam->dof_ob->id, DEG_NODE_TYPE_TRANSFORM); + add_relation(dof_ob_key, ob_param_key, "Camera DOF"); } } @@ -1519,27 +1684,25 @@ void DepsgraphRelationBuilder::build_lamp(Object *ob) } lamp_id->tag |= LIB_TAG_DOIT; - ComponentKey parameters_key(lamp_id, DEPSNODE_TYPE_PARAMETERS); + ComponentKey parameters_key(lamp_id, DEG_NODE_TYPE_PARAMETERS); if (needs_animdata_node(lamp_id)) { - ComponentKey animation_key(lamp_id, DEPSNODE_TYPE_ANIMATION); - add_relation(animation_key, parameters_key, - DEPSREL_TYPE_COMPONENT_ORDER, "Lamp Parameters"); + ComponentKey animation_key(lamp_id, DEG_NODE_TYPE_ANIMATION); + add_relation(animation_key, parameters_key, "Lamp Parameters"); } /* lamp's nodetree */ if (la->nodetree) { - build_nodetree(lamp_id, la->nodetree); - ComponentKey nodetree_key(&la->nodetree->id, DEPSNODE_TYPE_PARAMETERS); - add_relation(nodetree_key, parameters_key, - DEPSREL_TYPE_COMPONENT_ORDER, "NTree->Lamp Parameters"); + build_nodetree(la->nodetree); + ComponentKey nodetree_key(&la->nodetree->id, DEG_NODE_TYPE_PARAMETERS); + add_relation(nodetree_key, parameters_key, "NTree->Lamp Parameters"); } /* textures */ - build_texture_stack(lamp_id, la->mtex); + build_texture_stack(la->mtex); } -void DepsgraphRelationBuilder::build_nodetree(ID *owner, bNodeTree *ntree) +void DepsgraphRelationBuilder::build_nodetree(bNodeTree *ntree) { if (!ntree) return; @@ -1549,7 +1712,7 @@ void DepsgraphRelationBuilder::build_nodetree(ID *owner, bNodeTree *ntree) build_animdata(ntree_id); OperationKey parameters_key(ntree_id, - DEPSNODE_TYPE_PARAMETERS, + DEG_NODE_TYPE_PARAMETERS, DEG_OPCODE_PLACEHOLDER, "Parameters Eval"); @@ -1557,38 +1720,34 @@ void DepsgraphRelationBuilder::build_nodetree(ID *owner, bNodeTree *ntree) LINKLIST_FOREACH (bNode *, bnode, &ntree->nodes) { if (bnode->id) { if (GS(bnode->id->name) == ID_MA) { - build_material(owner, (Material *)bnode->id); + build_material((Material *)bnode->id); } else if (bnode->type == ID_TE) { - build_texture(owner, (Tex *)bnode->id); + build_texture((Tex *)bnode->id); } else if (bnode->type == NODE_GROUP) { bNodeTree *group_ntree = (bNodeTree *)bnode->id; if ((group_ntree->id.tag & LIB_TAG_DOIT) == 0) { - build_nodetree(owner, group_ntree); + build_nodetree(group_ntree); group_ntree->id.tag |= LIB_TAG_DOIT; } OperationKey group_parameters_key(&group_ntree->id, - DEPSNODE_TYPE_PARAMETERS, + DEG_NODE_TYPE_PARAMETERS, DEG_OPCODE_PLACEHOLDER, "Parameters Eval"); - add_relation(group_parameters_key, parameters_key, - DEPSREL_TYPE_COMPONENT_ORDER, "Group Node"); + add_relation(group_parameters_key, parameters_key, "Group Node"); } } } if (needs_animdata_node(ntree_id)) { - ComponentKey animation_key(ntree_id, DEPSNODE_TYPE_ANIMATION); - add_relation(animation_key, parameters_key, - DEPSREL_TYPE_COMPONENT_ORDER, "NTree Parameters"); + ComponentKey animation_key(ntree_id, DEG_NODE_TYPE_ANIMATION); + add_relation(animation_key, parameters_key, "NTree Parameters"); } - - // TODO: link from nodetree to owner_component? } /* Recursively build graph for material */ -void DepsgraphRelationBuilder::build_material(ID *owner, Material *ma) +void DepsgraphRelationBuilder::build_material(Material *ma) { ID *ma_id = &ma->id; if (ma_id->tag & LIB_TAG_DOIT) { @@ -1600,14 +1759,25 @@ void DepsgraphRelationBuilder::build_material(ID *owner, Material *ma) build_animdata(ma_id); /* textures */ - build_texture_stack(owner, ma->mtex); + build_texture_stack(ma->mtex); /* material's nodetree */ - build_nodetree(owner, ma->nodetree); + if (ma->nodetree != NULL) { + build_nodetree(ma->nodetree); + OperationKey ntree_key(&ma->nodetree->id, + DEG_NODE_TYPE_PARAMETERS, + DEG_OPCODE_PLACEHOLDER, + "Parameters Eval"); + OperationKey material_key(&ma->id, + DEG_NODE_TYPE_SHADING, + DEG_OPCODE_PLACEHOLDER, + "Material Update"); + add_relation(ntree_key, material_key, "Material's NTree"); + } } /* Recursively build graph for texture */ -void DepsgraphRelationBuilder::build_texture(ID *owner, Tex *tex) +void DepsgraphRelationBuilder::build_texture(Tex *tex) { ID *tex_id = &tex->id; if (tex_id->tag & LIB_TAG_DOIT) { @@ -1619,11 +1789,11 @@ void DepsgraphRelationBuilder::build_texture(ID *owner, Tex *tex) build_animdata(tex_id); /* texture's nodetree */ - build_nodetree(owner, tex->nodetree); + build_nodetree(tex->nodetree); } /* Texture-stack attached to some shading datablock */ -void DepsgraphRelationBuilder::build_texture_stack(ID *owner, MTex **texture_stack) +void DepsgraphRelationBuilder::build_texture_stack(MTex **texture_stack) { int i; @@ -1631,17 +1801,17 @@ void DepsgraphRelationBuilder::build_texture_stack(ID *owner, MTex **texture_sta for (i = 0; i < MAX_MTEX; i++) { MTex *mtex = texture_stack[i]; if (mtex && mtex->tex) - build_texture(owner, mtex->tex); + build_texture(mtex->tex); } } void DepsgraphRelationBuilder::build_compositor(Scene *scene) { /* For now, just a plain wrapper? */ - build_nodetree(&scene->id, scene->nodetree); + build_nodetree(scene->nodetree); } -void DepsgraphRelationBuilder::build_gpencil(ID *UNUSED(owner), bGPdata *gpd) +void DepsgraphRelationBuilder::build_gpencil(bGPdata *gpd) { /* animation */ build_animdata(&gpd->id); @@ -1665,8 +1835,18 @@ void DepsgraphRelationBuilder::build_cachefile(CacheFile *cache_file) { void DepsgraphRelationBuilder::build_mask(Mask *mask) { - /* Animation. */ - build_animdata(&mask->id); + ID *mask_id = &mask->id; + /* F-Curve animation. */ + build_animdata(mask_id); + /* Own mask animation. */ + OperationKey mask_animation_key(mask_id, + DEG_NODE_TYPE_ANIMATION, + DEG_OPCODE_MASK_ANIMATION); + TimeSourceKey time_src_key; + add_relation(time_src_key, mask_animation_key, "TimeSrc -> Mask Animation"); + /* Final mask evaluation. */ + ComponentKey parameters_key(mask_id, DEG_NODE_TYPE_PARAMETERS); + add_relation(mask_animation_key, parameters_key, "Mask Animation -> Mask Eval"); } void DepsgraphRelationBuilder::build_movieclip(MovieClip *clip) diff --git a/source/blender/depsgraph/intern/builder/deg_builder_relations.h b/source/blender/depsgraph/intern/builder/deg_builder_relations.h index 6e8485bee30..02f8fc69070 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder_relations.h +++ b/source/blender/depsgraph/intern/builder/deg_builder_relations.h @@ -58,6 +58,7 @@ struct Main; struct Mask; struct Material; struct MTex; +struct ModifierData; struct MovieClip; struct bNodeTree; struct Object; @@ -77,17 +78,12 @@ struct Depsgraph; struct DepsNode; struct DepsNodeHandle; struct RootDepsNode; -struct SubgraphDepsNode; struct IDDepsNode; struct TimeSourceDepsNode; struct ComponentDepsNode; struct OperationDepsNode; struct RootPChanMap; -struct RootKey { - RootKey(); -}; - struct TimeSourceKey { TimeSourceKey(); @@ -171,22 +167,21 @@ struct DepsgraphRelationBuilder { DepsgraphRelationBuilder(Depsgraph *graph); + void begin_build(Main *bmain); + template <typename KeyFrom, typename KeyTo> void add_relation(const KeyFrom& key_from, const KeyTo& key_to, - eDepsRelation_Type type, const char *description); template <typename KeyTo> void add_relation(const TimeSourceKey& key_from, const KeyTo& key_to, - eDepsRelation_Type type, const char *description); template <typename KeyType> void add_node_handle_relation(const KeyType& key_from, const DepsNodeHandle *handle, - eDepsRelation_Type type, const char *description); void build_scene(Main *bmain, Scene *scene); @@ -203,6 +198,7 @@ struct DepsgraphRelationBuilder void build_world(World *world); void build_rigidbody(Scene *scene); void build_particles(Scene *scene, Object *ob); + void build_cloth(Scene *scene, Object *object, ModifierData *md); void build_ik_pose(Object *ob, bPoseChannel *pchan, bConstraint *con, @@ -217,12 +213,12 @@ struct DepsgraphRelationBuilder void build_obdata_geom(Main *bmain, Scene *scene, Object *ob); void build_camera(Object *ob); void build_lamp(Object *ob); - void build_nodetree(ID *owner, bNodeTree *ntree); - void build_material(ID *owner, Material *ma); - void build_texture(ID *owner, Tex *tex); - void build_texture_stack(ID *owner, MTex **texture_stack); + void build_nodetree(bNodeTree *ntree); + void build_material(Material *ma); + void build_texture(Tex *tex); + void build_texture_stack(MTex **texture_stack); void build_compositor(Scene *scene); - void build_gpencil(ID *owner, bGPdata *gpd); + void build_gpencil(bGPdata *gpd); void build_cachefile(CacheFile *cache_file); void build_mask(Mask *mask); void build_movieclip(MovieClip *clip); @@ -233,8 +229,9 @@ struct DepsgraphRelationBuilder template <typename KeyType> OperationDepsNode *find_operation_node(const KeyType &key); + Depsgraph *getGraph(); + protected: - RootDepsNode *find_node(const RootKey &key) const; TimeSourceDepsNode *find_node(const TimeSourceKey &key) const; ComponentDepsNode *find_node(const ComponentKey &key) const; OperationDepsNode *find_node(const OperationKey &key) const; @@ -246,7 +243,6 @@ protected: const char *description); void add_operation_relation(OperationDepsNode *node_from, OperationDepsNode *node_to, - eDepsRelation_Type type, const char *description); template <typename KeyType> @@ -286,7 +282,6 @@ OperationDepsNode *DepsgraphRelationBuilder::find_operation_node(const KeyType& template <typename KeyFrom, typename KeyTo> void DepsgraphRelationBuilder::add_relation(const KeyFrom &key_from, const KeyTo &key_to, - eDepsRelation_Type type, const char *description) { DepsNode *node_from = find_node(key_from); @@ -294,27 +289,27 @@ void DepsgraphRelationBuilder::add_relation(const KeyFrom &key_from, OperationDepsNode *op_from = node_from ? node_from->get_exit_operation() : NULL; OperationDepsNode *op_to = node_to ? node_to->get_entry_operation() : NULL; if (op_from && op_to) { - add_operation_relation(op_from, op_to, type, description); + add_operation_relation(op_from, op_to, description); } else { if (!op_from) { /* XXX TODO handle as error or report if needed */ node_from = find_node(key_from); - fprintf(stderr, "add_relation(%d, %s) - Could not find op_from (%s)\n", - type, description, key_from.identifier().c_str()); + fprintf(stderr, "add_relation(%s) - Could not find op_from (%s)\n", + description, key_from.identifier().c_str()); } else { - fprintf(stderr, "add_relation(%d, %s) - Failed, but op_from (%s) was ok\n", - type, description, key_from.identifier().c_str()); + fprintf(stderr, "add_relation(%s) - Failed, but op_from (%s) was ok\n", + description, key_from.identifier().c_str()); } if (!op_to) { /* XXX TODO handle as error or report if needed */ - fprintf(stderr, "add_relation(%d, %s) - Could not find op_to (%s)\n", - type, description, key_to.identifier().c_str()); + fprintf(stderr, "add_relation(%s) - Could not find op_to (%s)\n", + description, key_to.identifier().c_str()); } else { - fprintf(stderr, "add_relation(%d, %s) - Failed, but op_to (%s) was ok\n", - type, description, key_to.identifier().c_str()); + fprintf(stderr, "add_relation(%s) - Failed, but op_to (%s) was ok\n", + description, key_to.identifier().c_str()); } } } @@ -322,11 +317,8 @@ void DepsgraphRelationBuilder::add_relation(const KeyFrom &key_from, template <typename KeyTo> void DepsgraphRelationBuilder::add_relation(const TimeSourceKey &key_from, const KeyTo &key_to, - eDepsRelation_Type type, const char *description) { - (void)type; /* Ignored in release builds. */ - BLI_assert(type == DEPSREL_TYPE_TIME); TimeSourceDepsNode *time_from = find_node(key_from); DepsNode *node_to = find_node(key_to); OperationDepsNode *op_to = node_to ? node_to->get_entry_operation() : NULL; @@ -341,23 +333,22 @@ template <typename KeyType> void DepsgraphRelationBuilder::add_node_handle_relation( const KeyType &key_from, const DepsNodeHandle *handle, - eDepsRelation_Type type, const char *description) { DepsNode *node_from = find_node(key_from); OperationDepsNode *op_from = node_from ? node_from->get_exit_operation() : NULL; OperationDepsNode *op_to = handle->node->get_entry_operation(); if (op_from && op_to) { - add_operation_relation(op_from, op_to, type, description); + add_operation_relation(op_from, op_to, description); } else { if (!op_from) { - fprintf(stderr, "add_node_handle_relation(%d, %s) - Could not find op_from (%s)\n", - type, description, key_from.identifier().c_str()); + fprintf(stderr, "add_node_handle_relation(%s) - Could not find op_from (%s)\n", + description, key_from.identifier().c_str()); } if (!op_to) { - fprintf(stderr, "add_node_handle_relation(%d, %s) - Could not find op_to (%s)\n", - type, description, key_from.identifier().c_str()); + fprintf(stderr, "add_node_handle_relation(%s) - Could not find op_to (%s)\n", + description, key_from.identifier().c_str()); } } } diff --git a/source/blender/depsgraph/intern/builder/deg_builder_relations_keys.cc b/source/blender/depsgraph/intern/builder/deg_builder_relations_keys.cc index feae8bca303..9d6ab3358a7 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder_relations_keys.cc +++ b/source/blender/depsgraph/intern/builder/deg_builder_relations_keys.cc @@ -35,13 +35,6 @@ namespace DEG { ///////////////////////////////////////// -// Root. - -RootKey::RootKey() -{ -} - -///////////////////////////////////////// // Time source. TimeSourceKey::TimeSourceKey() @@ -64,7 +57,7 @@ string TimeSourceKey::identifier() const ComponentKey::ComponentKey() : id(NULL), - type(DEPSNODE_TYPE_UNDEFINED), + type(DEG_NODE_TYPE_UNDEFINED), name("") { } @@ -90,7 +83,7 @@ string ComponentKey::identifier() const OperationKey::OperationKey() : id(NULL), - component_type(DEPSNODE_TYPE_UNDEFINED), + component_type(DEG_NODE_TYPE_UNDEFINED), component_name(""), opcode(DEG_OPCODE_OPERATION), name(""), diff --git a/source/blender/depsgraph/intern/builder/deg_builder_relations_rig.cc b/source/blender/depsgraph/intern/builder/deg_builder_relations_rig.cc index 2b4c000f483..ca548ed33d0 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder_relations_rig.cc +++ b/source/blender/depsgraph/intern/builder/deg_builder_relations_rig.cc @@ -38,10 +38,10 @@ #include "MEM_guardedalloc.h" -extern "C" { -#include "BLI_blenlib.h" #include "BLI_utildefines.h" +#include "BLI_blenlib.h" +extern "C" { #include "DNA_action_types.h" #include "DNA_anim_types.h" #include "DNA_armature_types.h" @@ -51,10 +51,10 @@ extern "C" { #include "BKE_action.h" #include "BKE_armature.h" +} /* extern "C" */ #include "DEG_depsgraph.h" #include "DEG_depsgraph_build.h" -} /* extern "C" */ #include "intern/builder/deg_builder.h" #include "intern/builder/deg_builder_pchanmap.h" @@ -83,7 +83,15 @@ void DepsgraphRelationBuilder::build_ik_pose(Object *ob, * - see notes on direction of rel below... */ bPoseChannel *rootchan = BKE_armature_ik_solver_find_root(pchan, data); - OperationKey solver_key(&ob->id, DEPSNODE_TYPE_EVAL_POSE, rootchan->name, DEG_OPCODE_POSE_IK_SOLVER); + OperationKey pchan_local_key(&ob->id, DEG_NODE_TYPE_BONE, + pchan->name, DEG_OPCODE_BONE_LOCAL); + OperationKey init_ik_key(&ob->id, DEG_NODE_TYPE_EVAL_POSE, DEG_OPCODE_POSE_INIT_IK); + OperationKey solver_key(&ob->id, DEG_NODE_TYPE_EVAL_POSE, + rootchan->name, + DEG_OPCODE_POSE_IK_SOLVER); + + add_relation(pchan_local_key, init_ik_key, "IK Constraint -> Init IK Tree"); + add_relation(init_ik_key, solver_key, "Init IK -> IK Solver"); /* IK target */ // XXX: this should get handled as part of the constraint code @@ -96,25 +104,25 @@ void DepsgraphRelationBuilder::build_ik_pose(Object *ob, * testing IK solver. */ // FIXME: geometry targets... - ComponentKey pose_key(&ob->id, DEPSNODE_TYPE_EVAL_POSE); + ComponentKey pose_key(&ob->id, DEG_NODE_TYPE_EVAL_POSE); if ((data->tar->type == OB_ARMATURE) && (data->subtarget[0])) { /* TODO(sergey): This is only for until granular update stores intermediate result. */ if (data->tar != ob) { /* different armature - can just read the results */ - ComponentKey target_key(&data->tar->id, DEPSNODE_TYPE_BONE, data->subtarget); - add_relation(target_key, pose_key, DEPSREL_TYPE_TRANSFORM, con->name); + ComponentKey target_key(&data->tar->id, DEG_NODE_TYPE_BONE, data->subtarget); + add_relation(target_key, pose_key, con->name); } else { /* same armature - we'll use the ready state only, just in case this bone is in the chain we're solving */ - OperationKey target_key(&data->tar->id, DEPSNODE_TYPE_BONE, data->subtarget, DEG_OPCODE_BONE_DONE); - add_relation(target_key, solver_key, DEPSREL_TYPE_TRANSFORM, con->name); + OperationKey target_key(&data->tar->id, DEG_NODE_TYPE_BONE, data->subtarget, DEG_OPCODE_BONE_DONE); + add_relation(target_key, solver_key, con->name); } } else if (ELEM(data->tar->type, OB_MESH, OB_LATTICE) && (data->subtarget[0])) { /* vertex group target */ /* NOTE: for now, we don't need to represent vertex groups separately... */ - ComponentKey target_key(&data->tar->id, DEPSNODE_TYPE_GEOMETRY); - add_relation(target_key, solver_key, DEPSREL_TYPE_GEOMETRY_EVAL, con->name); + ComponentKey target_key(&data->tar->id, DEG_NODE_TYPE_GEOMETRY); + add_relation(target_key, solver_key, con->name); if (data->tar->type == OB_MESH) { OperationDepsNode *node2 = find_operation_node(target_key); @@ -125,8 +133,8 @@ void DepsgraphRelationBuilder::build_ik_pose(Object *ob, } else { /* Standard Object Target */ - ComponentKey target_key(&data->tar->id, DEPSNODE_TYPE_TRANSFORM); - add_relation(target_key, pose_key, DEPSREL_TYPE_TRANSFORM, con->name); + ComponentKey target_key(&data->tar->id, DEG_NODE_TYPE_TRANSFORM); + add_relation(target_key, pose_key, con->name); } if ((data->tar == ob) && (data->subtarget[0])) { @@ -142,14 +150,14 @@ void DepsgraphRelationBuilder::build_ik_pose(Object *ob, if (data->poletar != NULL) { if ((data->poletar->type == OB_ARMATURE) && (data->polesubtarget[0])) { // XXX: same armature issues - ready vs done? - ComponentKey target_key(&data->poletar->id, DEPSNODE_TYPE_BONE, data->polesubtarget); - add_relation(target_key, solver_key, DEPSREL_TYPE_TRANSFORM, con->name); + ComponentKey target_key(&data->poletar->id, DEG_NODE_TYPE_BONE, data->polesubtarget); + add_relation(target_key, solver_key, con->name); } else if (ELEM(data->poletar->type, OB_MESH, OB_LATTICE) && (data->polesubtarget[0])) { /* vertex group target */ /* NOTE: for now, we don't need to represent vertex groups separately... */ - ComponentKey target_key(&data->poletar->id, DEPSNODE_TYPE_GEOMETRY); - add_relation(target_key, solver_key, DEPSREL_TYPE_GEOMETRY_EVAL, con->name); + ComponentKey target_key(&data->poletar->id, DEG_NODE_TYPE_GEOMETRY); + add_relation(target_key, solver_key, con->name); if (data->poletar->type == OB_MESH) { OperationDepsNode *node2 = find_operation_node(target_key); @@ -159,8 +167,8 @@ void DepsgraphRelationBuilder::build_ik_pose(Object *ob, } } else { - ComponentKey target_key(&data->poletar->id, DEPSNODE_TYPE_TRANSFORM); - add_relation(target_key, solver_key, DEPSREL_TYPE_TRANSFORM, con->name); + ComponentKey target_key(&data->poletar->id, DEG_NODE_TYPE_TRANSFORM); + add_relation(target_key, solver_key, con->name); } } @@ -170,19 +178,17 @@ void DepsgraphRelationBuilder::build_ik_pose(Object *ob, bPoseChannel *parchan = pchan; /* exclude tip from chain? */ if (!(data->flag & CONSTRAINT_IK_TIP)) { - OperationKey tip_transforms_key(&ob->id, DEPSNODE_TYPE_BONE, + OperationKey tip_transforms_key(&ob->id, DEG_NODE_TYPE_BONE, parchan->name, DEG_OPCODE_BONE_LOCAL); - add_relation(solver_key, tip_transforms_key, - DEPSREL_TYPE_TRANSFORM, "IK Solver Result"); + add_relation(solver_key, tip_transforms_key, "IK Solver Result"); parchan = pchan->parent; } root_map->add_bone(parchan->name, rootchan->name); - OperationKey parchan_transforms_key(&ob->id, DEPSNODE_TYPE_BONE, + OperationKey parchan_transforms_key(&ob->id, DEG_NODE_TYPE_BONE, parchan->name, DEG_OPCODE_BONE_READY); - add_relation(parchan_transforms_key, solver_key, - DEPSREL_TYPE_TRANSFORM, "IK Solver Owner"); + add_relation(parchan_transforms_key, solver_key, "IK Solver Owner"); /* Walk to the chain's root */ //size_t segcount = 0; @@ -196,15 +202,15 @@ void DepsgraphRelationBuilder::build_ik_pose(Object *ob, * grab the result with IK solver results... */ if (parchan != pchan) { - OperationKey parent_key(&ob->id, DEPSNODE_TYPE_BONE, parchan->name, DEG_OPCODE_BONE_READY); - add_relation(parent_key, solver_key, DEPSREL_TYPE_TRANSFORM, "IK Chain Parent"); + OperationKey parent_key(&ob->id, DEG_NODE_TYPE_BONE, parchan->name, DEG_OPCODE_BONE_READY); + add_relation(parent_key, solver_key, "IK Chain Parent"); - OperationKey done_key(&ob->id, DEPSNODE_TYPE_BONE, parchan->name, DEG_OPCODE_BONE_DONE); - add_relation(solver_key, done_key, DEPSREL_TYPE_TRANSFORM, "IK Chain Result"); + OperationKey done_key(&ob->id, DEG_NODE_TYPE_BONE, parchan->name, DEG_OPCODE_BONE_DONE); + add_relation(solver_key, done_key, "IK Chain Result"); } else { - OperationKey final_transforms_key(&ob->id, DEPSNODE_TYPE_BONE, parchan->name, DEG_OPCODE_BONE_DONE); - add_relation(solver_key, final_transforms_key, DEPSREL_TYPE_TRANSFORM, "IK Solver Result"); + OperationKey final_transforms_key(&ob->id, DEG_NODE_TYPE_BONE, parchan->name, DEG_OPCODE_BONE_DONE); + add_relation(solver_key, final_transforms_key, "IK Solver Result"); } parchan->flag |= POSE_DONE; @@ -219,8 +225,8 @@ void DepsgraphRelationBuilder::build_ik_pose(Object *ob, parchan = parchan->parent; } - OperationKey flush_key(&ob->id, DEPSNODE_TYPE_EVAL_POSE, DEG_OPCODE_POSE_DONE); - add_relation(solver_key, flush_key, DEPSREL_TYPE_OPERATION, "PoseEval Result-Bone Link"); + OperationKey flush_key(&ob->id, DEG_NODE_TYPE_EVAL_POSE, DEG_OPCODE_POSE_DONE); + add_relation(solver_key, flush_key, "PoseEval Result-Bone Link"); } /* Spline IK Eval Steps */ @@ -231,14 +237,14 @@ void DepsgraphRelationBuilder::build_splineik_pose(Object *ob, { bSplineIKConstraint *data = (bSplineIKConstraint *)con->data; bPoseChannel *rootchan = BKE_armature_splineik_solver_find_root(pchan, data); - OperationKey transforms_key(&ob->id, DEPSNODE_TYPE_BONE, pchan->name, DEG_OPCODE_BONE_READY); - OperationKey solver_key(&ob->id, DEPSNODE_TYPE_EVAL_POSE, rootchan->name, DEG_OPCODE_POSE_SPLINE_IK_SOLVER); + OperationKey transforms_key(&ob->id, DEG_NODE_TYPE_BONE, pchan->name, DEG_OPCODE_BONE_READY); + OperationKey solver_key(&ob->id, DEG_NODE_TYPE_EVAL_POSE, rootchan->name, DEG_OPCODE_POSE_SPLINE_IK_SOLVER); /* attach owner to IK Solver too * - assume that owner is always part of chain * - see notes on direction of rel below... */ - add_relation(transforms_key, solver_key, DEPSREL_TYPE_TRANSFORM, "Spline IK Solver Owner"); + add_relation(transforms_key, solver_key, "Spline IK Solver Owner"); /* attach path dependency to solver */ if (data->tar) { @@ -247,14 +253,14 @@ void DepsgraphRelationBuilder::build_splineik_pose(Object *ob, * See IK pose for a bit more information. */ // TODO: the bigggest point here is that we need the curve PATH and not just the general geometry... - ComponentKey target_key(&data->tar->id, DEPSNODE_TYPE_GEOMETRY); - ComponentKey pose_key(&ob->id, DEPSNODE_TYPE_EVAL_POSE); - add_relation(target_key, pose_key, DEPSREL_TYPE_TRANSFORM, "[Curve.Path -> Spline IK] DepsRel"); + ComponentKey target_key(&data->tar->id, DEG_NODE_TYPE_GEOMETRY); + ComponentKey pose_key(&ob->id, DEG_NODE_TYPE_EVAL_POSE); + add_relation(target_key, pose_key, "[Curve.Path -> Spline IK] DepsRel"); } pchan->flag |= POSE_DONE; - OperationKey final_transforms_key(&ob->id, DEPSNODE_TYPE_BONE, pchan->name, DEG_OPCODE_BONE_DONE); - add_relation(solver_key, final_transforms_key, DEPSREL_TYPE_TRANSFORM, "Spline IK Result"); + OperationKey final_transforms_key(&ob->id, DEG_NODE_TYPE_BONE, pchan->name, DEG_OPCODE_BONE_DONE); + add_relation(solver_key, final_transforms_key, "Spline IK Result"); root_map->add_bone(pchan->name, rootchan->name); @@ -270,16 +276,16 @@ void DepsgraphRelationBuilder::build_splineik_pose(Object *ob, * grab the result with IK solver results... */ if (parchan != pchan) { - OperationKey parent_key(&ob->id, DEPSNODE_TYPE_BONE, parchan->name, DEG_OPCODE_BONE_READY); - add_relation(parent_key, solver_key, DEPSREL_TYPE_TRANSFORM, "Spline IK Solver Update"); + OperationKey parent_key(&ob->id, DEG_NODE_TYPE_BONE, parchan->name, DEG_OPCODE_BONE_READY); + add_relation(parent_key, solver_key, "Spline IK Solver Update"); - OperationKey done_key(&ob->id, DEPSNODE_TYPE_BONE, parchan->name, DEG_OPCODE_BONE_DONE); - add_relation(solver_key, done_key, DEPSREL_TYPE_TRANSFORM, "IK Chain Result"); + OperationKey done_key(&ob->id, DEG_NODE_TYPE_BONE, parchan->name, DEG_OPCODE_BONE_DONE); + add_relation(solver_key, done_key, "IK Chain Result"); } parchan->flag |= POSE_DONE; - OperationKey final_transforms_key(&ob->id, DEPSNODE_TYPE_BONE, parchan->name, DEG_OPCODE_BONE_DONE); - add_relation(solver_key, final_transforms_key, DEPSREL_TYPE_TRANSFORM, "Spline IK Solver Result"); + OperationKey final_transforms_key(&ob->id, DEG_NODE_TYPE_BONE, parchan->name, DEG_OPCODE_BONE_DONE); + add_relation(solver_key, final_transforms_key, "Spline IK Solver Result"); root_map->add_bone(parchan->name, rootchan->name); @@ -288,8 +294,8 @@ void DepsgraphRelationBuilder::build_splineik_pose(Object *ob, if ((segcount == data->chainlen) || (segcount > 255)) break; /* 255 is weak */ } - OperationKey flush_key(&ob->id, DEPSNODE_TYPE_EVAL_POSE, DEG_OPCODE_POSE_DONE); - add_relation(solver_key, flush_key, DEPSREL_TYPE_OPERATION, "PoseEval Result-Bone Link"); + OperationKey flush_key(&ob->id, DEG_NODE_TYPE_EVAL_POSE, DEG_OPCODE_POSE_DONE); + add_relation(solver_key, flush_key, "PoseEval Result-Bone Link"); } /* Pose/Armature Bones Graph */ @@ -301,21 +307,23 @@ void DepsgraphRelationBuilder::build_rig(Scene *scene, Object *ob) // TODO: selection status? /* attach links between pose operations */ - OperationKey init_key(&ob->id, DEPSNODE_TYPE_EVAL_POSE, DEG_OPCODE_POSE_INIT); - OperationKey flush_key(&ob->id, DEPSNODE_TYPE_EVAL_POSE, DEG_OPCODE_POSE_DONE); + OperationKey init_key(&ob->id, DEG_NODE_TYPE_EVAL_POSE, DEG_OPCODE_POSE_INIT); + OperationKey init_ik_key(&ob->id, DEG_NODE_TYPE_EVAL_POSE, DEG_OPCODE_POSE_INIT_IK); + OperationKey flush_key(&ob->id, DEG_NODE_TYPE_EVAL_POSE, DEG_OPCODE_POSE_DONE); - add_relation(init_key, flush_key, DEPSREL_TYPE_COMPONENT_ORDER, "[Pose Init -> Pose Cleanup]"); + add_relation(init_key, init_ik_key, "Pose Init -> Pose Init IK"); + add_relation(init_ik_key, flush_key, "Pose Init IK -> Pose Cleanup"); /* Make sure pose is up-to-date with armature updates. */ OperationKey armature_key(&arm->id, - DEPSNODE_TYPE_PARAMETERS, + DEG_NODE_TYPE_PARAMETERS, DEG_OPCODE_PLACEHOLDER, "Armature Eval"); - add_relation(armature_key, init_key, DEPSREL_TYPE_COMPONENT_ORDER, "Data dependency"); + add_relation(armature_key, init_key, "Data dependency"); if (needs_animdata_node(&ob->id)) { - ComponentKey animation_key(&ob->id, DEPSNODE_TYPE_ANIMATION); - add_relation(animation_key, init_key, DEPSREL_TYPE_OPERATION, "Rig Animation"); + ComponentKey animation_key(&ob->id, DEG_NODE_TYPE_ANIMATION); + add_relation(animation_key, init_key, "Rig Animation"); } /* IK Solvers... @@ -370,26 +378,25 @@ void DepsgraphRelationBuilder::build_rig(Scene *scene, Object *ob) /* TODO(sergey): Once partial updates are possible use relation between * object transform and solver itself in it's build function. */ - ComponentKey pose_key(&ob->id, DEPSNODE_TYPE_EVAL_POSE); - ComponentKey local_transform_key(&ob->id, DEPSNODE_TYPE_TRANSFORM); - add_relation(local_transform_key, pose_key, DEPSREL_TYPE_TRANSFORM, "Local Transforms"); + ComponentKey pose_key(&ob->id, DEG_NODE_TYPE_EVAL_POSE); + ComponentKey local_transform_key(&ob->id, DEG_NODE_TYPE_TRANSFORM); + add_relation(local_transform_key, pose_key, "Local Transforms"); } - /* links between operations for each bone */ LINKLIST_FOREACH (bPoseChannel *, pchan, &ob->pose->chanbase) { - OperationKey bone_local_key(&ob->id, DEPSNODE_TYPE_BONE, pchan->name, DEG_OPCODE_BONE_LOCAL); - OperationKey bone_pose_key(&ob->id, DEPSNODE_TYPE_BONE, pchan->name, DEG_OPCODE_BONE_POSE_PARENT); - OperationKey bone_ready_key(&ob->id, DEPSNODE_TYPE_BONE, pchan->name, DEG_OPCODE_BONE_READY); - OperationKey bone_done_key(&ob->id, DEPSNODE_TYPE_BONE, pchan->name, DEG_OPCODE_BONE_DONE); + OperationKey bone_local_key(&ob->id, DEG_NODE_TYPE_BONE, pchan->name, DEG_OPCODE_BONE_LOCAL); + OperationKey bone_pose_key(&ob->id, DEG_NODE_TYPE_BONE, pchan->name, DEG_OPCODE_BONE_POSE_PARENT); + OperationKey bone_ready_key(&ob->id, DEG_NODE_TYPE_BONE, pchan->name, DEG_OPCODE_BONE_READY); + OperationKey bone_done_key(&ob->id, DEG_NODE_TYPE_BONE, pchan->name, DEG_OPCODE_BONE_DONE); pchan->flag &= ~POSE_DONE; /* pose init to bone local */ - add_relation(init_key, bone_local_key, DEPSREL_TYPE_OPERATION, "PoseEval Source-Bone Link"); + add_relation(init_key, bone_local_key, "PoseEval Source-Bone Link"); /* local to pose parenting operation */ - add_relation(bone_local_key, bone_pose_key, DEPSREL_TYPE_OPERATION, "Bone Local - PoseSpace Link"); + add_relation(bone_local_key, bone_pose_key, "Bone Local - PoseSpace Link"); /* parent relation */ if (pchan->parent != NULL) { @@ -403,26 +410,26 @@ void DepsgraphRelationBuilder::build_rig(Scene *scene, Object *ob) parent_key_opcode = DEG_OPCODE_BONE_DONE; } - OperationKey parent_key(&ob->id, DEPSNODE_TYPE_BONE, pchan->parent->name, parent_key_opcode); - add_relation(parent_key, bone_pose_key, DEPSREL_TYPE_TRANSFORM, "[Parent Bone -> Child Bone]"); + OperationKey parent_key(&ob->id, DEG_NODE_TYPE_BONE, pchan->parent->name, parent_key_opcode); + add_relation(parent_key, bone_pose_key, "[Parent Bone -> Child Bone]"); } /* constraints */ if (pchan->constraints.first != NULL) { /* constraints stack and constraint dependencies */ - build_constraints(scene, &ob->id, DEPSNODE_TYPE_BONE, pchan->name, &pchan->constraints, &root_map); + build_constraints(scene, &ob->id, DEG_NODE_TYPE_BONE, pchan->name, &pchan->constraints, &root_map); /* pose -> constraints */ - OperationKey constraints_key(&ob->id, DEPSNODE_TYPE_BONE, pchan->name, DEG_OPCODE_BONE_CONSTRAINTS); - add_relation(bone_pose_key, constraints_key, DEPSREL_TYPE_OPERATION, "Constraints Stack"); + OperationKey constraints_key(&ob->id, DEG_NODE_TYPE_BONE, pchan->name, DEG_OPCODE_BONE_CONSTRAINTS); + add_relation(bone_pose_key, constraints_key, "Constraints Stack"); /* constraints -> ready */ // TODO: when constraint stack is exploded, this step should occur before the first IK solver - add_relation(constraints_key, bone_ready_key, DEPSREL_TYPE_OPERATION, "Constraints -> Ready"); + add_relation(constraints_key, bone_ready_key, "Constraints -> Ready"); } else { /* pose -> ready */ - add_relation(bone_pose_key, bone_ready_key, DEPSREL_TYPE_OPERATION, "Pose -> Ready"); + add_relation(bone_pose_key, bone_ready_key, "Pose -> Ready"); } /* bone ready -> done @@ -430,25 +437,25 @@ void DepsgraphRelationBuilder::build_rig(Scene *scene, Object *ob) * For IK chains however, an additional rel is created from IK to done, * with transitive reduction removing this one... */ - add_relation(bone_ready_key, bone_done_key, DEPSREL_TYPE_OPERATION, "Ready -> Done"); + add_relation(bone_ready_key, bone_done_key, "Ready -> Done"); /* assume that all bones must be done for the pose to be ready (for deformers) */ - add_relation(bone_done_key, flush_key, DEPSREL_TYPE_OPERATION, "PoseEval Result-Bone Link"); + add_relation(bone_done_key, flush_key, "PoseEval Result-Bone Link"); } } void DepsgraphRelationBuilder::build_proxy_rig(Object *ob) { - OperationKey pose_init_key(&ob->id, DEPSNODE_TYPE_EVAL_POSE, DEG_OPCODE_POSE_INIT); - OperationKey pose_done_key(&ob->id, DEPSNODE_TYPE_EVAL_POSE, DEG_OPCODE_POSE_DONE); + OperationKey pose_init_key(&ob->id, DEG_NODE_TYPE_EVAL_POSE, DEG_OPCODE_POSE_INIT); + OperationKey pose_done_key(&ob->id, DEG_NODE_TYPE_EVAL_POSE, DEG_OPCODE_POSE_DONE); LINKLIST_FOREACH (bPoseChannel *, pchan, &ob->pose->chanbase) { - OperationKey bone_local_key(&ob->id, DEPSNODE_TYPE_BONE, pchan->name, DEG_OPCODE_BONE_LOCAL); - OperationKey bone_ready_key(&ob->id, DEPSNODE_TYPE_BONE, pchan->name, DEG_OPCODE_BONE_READY); - OperationKey bone_done_key(&ob->id, DEPSNODE_TYPE_BONE, pchan->name, DEG_OPCODE_BONE_DONE); - add_relation(pose_init_key, bone_local_key, DEPSREL_TYPE_OPERATION, "Pose Init -> Bone Local"); - add_relation(bone_local_key, bone_ready_key, DEPSREL_TYPE_OPERATION, "Local -> Ready"); - add_relation(bone_ready_key, bone_done_key, DEPSREL_TYPE_OPERATION, "Ready -> Done"); - add_relation(bone_done_key, pose_done_key, DEPSREL_TYPE_OPERATION, "Bone Done -> Pose Done"); + OperationKey bone_local_key(&ob->id, DEG_NODE_TYPE_BONE, pchan->name, DEG_OPCODE_BONE_LOCAL); + OperationKey bone_ready_key(&ob->id, DEG_NODE_TYPE_BONE, pchan->name, DEG_OPCODE_BONE_READY); + OperationKey bone_done_key(&ob->id, DEG_NODE_TYPE_BONE, pchan->name, DEG_OPCODE_BONE_DONE); + add_relation(pose_init_key, bone_local_key, "Pose Init -> Bone Local"); + add_relation(bone_local_key, bone_ready_key, "Local -> Ready"); + add_relation(bone_ready_key, bone_done_key, "Ready -> Done"); + add_relation(bone_done_key, pose_done_key, "Bone Done -> Pose Done"); } } diff --git a/source/blender/depsgraph/intern/builder/deg_builder_relations_scene.cc b/source/blender/depsgraph/intern/builder/deg_builder_relations_scene.cc index 6b51a957da0..6a9568e7e8d 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder_relations_scene.cc +++ b/source/blender/depsgraph/intern/builder/deg_builder_relations_scene.cc @@ -38,20 +38,20 @@ #include "MEM_guardedalloc.h" -extern "C" { -#include "BLI_blenlib.h" #include "BLI_utildefines.h" +#include "BLI_blenlib.h" +extern "C" { #include "DNA_node_types.h" #include "DNA_object_types.h" #include "DNA_scene_types.h" #include "BKE_main.h" #include "BKE_node.h" +} /* extern "C" */ #include "DEG_depsgraph.h" #include "DEG_depsgraph_build.h" -} /* extern "C" */ #include "intern/builder/deg_builder.h" #include "intern/builder/deg_builder_pchanmap.h" @@ -69,45 +69,14 @@ namespace DEG { void DepsgraphRelationBuilder::build_scene(Main *bmain, Scene *scene) { - /* LIB_TAG_DOIT is used to indicate whether node for given ID was already - * created or not. - */ - BKE_main_id_tag_all(bmain, LIB_TAG_DOIT, false); - /* XXX nested node trees are not included in tag-clearing above, - * so we need to do this manually. - */ - FOREACH_NODETREE(bmain, nodetree, id) { - if (id != (ID *)nodetree) - nodetree->id.tag &= ~LIB_TAG_DOIT; - } FOREACH_NODETREE_END - if (scene->set) { - // TODO: link set to scene, especially our timesource... + build_scene(bmain, scene->set); } /* scene objects */ LINKLIST_FOREACH (Base *, base, &scene->base) { Object *ob = base->object; - - /* object itself */ build_object(bmain, scene, ob); - - /* object that this is a proxy for */ - if (ob->proxy) { - ob->proxy->proxy_from = ob; - build_object(bmain, scene, ob->proxy); - /* TODO(sergey): This is an inverted relation, matches old depsgraph - * behavior and need to be investigated if it still need to be inverted. - */ - ComponentKey ob_pose_key(&ob->id, DEPSNODE_TYPE_EVAL_POSE); - ComponentKey proxy_pose_key(&ob->proxy->id, DEPSNODE_TYPE_EVAL_POSE); - add_relation(ob_pose_key, proxy_pose_key, DEPSREL_TYPE_TRANSFORM, "Proxy"); - } - - /* Object dupligroup. */ - if (ob->dup_group) { - build_group(bmain, scene, ob, ob->dup_group); - } } /* rigidbody */ @@ -132,7 +101,7 @@ void DepsgraphRelationBuilder::build_scene(Main *bmain, Scene *scene) /* grease pencil */ if (scene->gpd) { - build_gpencil(&scene->id, scene->gpd); + build_gpencil(scene->gpd); } /* Masks. */ diff --git a/source/blender/depsgraph/intern/builder/deg_builder_transitive.cc b/source/blender/depsgraph/intern/builder/deg_builder_transitive.cc index da71db09f3d..b12af21fc8d 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder_transitive.cc +++ b/source/blender/depsgraph/intern/builder/deg_builder_transitive.cc @@ -30,9 +30,7 @@ #include "intern/builder/deg_builder_transitive.h" -extern "C" { #include "MEM_guardedalloc.h" -} #include "intern/nodes/deg_node.h" #include "intern/nodes/deg_node_component.h" @@ -105,7 +103,7 @@ void deg_graph_transitive_reduction(Depsgraph *graph) /* Increment in advance, so we can safely remove the relation. */ ++it_rel; - if (rel->from->type == DEPSNODE_TYPE_TIMESOURCE) { + if (rel->from->type == DEG_NODE_TYPE_TIMESOURCE) { /* HACK: time source nodes don't get "done" flag set/cleared. */ /* TODO: there will be other types in future, so iterators above * need modifying. diff --git a/source/blender/depsgraph/intern/debug/deg_debug_graphviz.cc b/source/blender/depsgraph/intern/debug/deg_debug_graphviz.cc index 0d56ce71c7d..51d4ed91419 100644 --- a/source/blender/depsgraph/intern/debug/deg_debug_graphviz.cc +++ b/source/blender/depsgraph/intern/debug/deg_debug_graphviz.cc @@ -35,10 +35,10 @@ extern "C" { #include "DNA_listBase.h" +} /* extern "C" */ #include "DEG_depsgraph.h" #include "DEG_depsgraph_debug.h" -} /* extern "C" */ #include "intern/depsgraph_intern.h" #include "util/deg_util_foreach.h" @@ -77,20 +77,18 @@ static const char *deg_debug_colors_light[] = { #ifdef COLOR_SCHEME_NODE_TYPE static const int deg_debug_node_type_color_map[][2] = { - {DEPSNODE_TYPE_ROOT, 0}, - {DEPSNODE_TYPE_TIMESOURCE, 1}, - {DEPSNODE_TYPE_ID_REF, 2}, - {DEPSNODE_TYPE_SUBGRAPH, 3}, + {DEG_NODE_TYPE_TIMESOURCE, 0}, + {DEG_NODE_TYPE_ID_REF, 2}, /* Outer Types */ - {DEPSNODE_TYPE_PARAMETERS, 4}, - {DEPSNODE_TYPE_PROXY, 5}, - {DEPSNODE_TYPE_ANIMATION, 6}, - {DEPSNODE_TYPE_TRANSFORM, 7}, - {DEPSNODE_TYPE_GEOMETRY, 8}, - {DEPSNODE_TYPE_SEQUENCER, 9}, - {DEPSNODE_TYPE_SHADING, 10}, - {DEPSNODE_TYPE_CACHE, 11}, + {DEG_NODE_TYPE_PARAMETERS, 2}, + {DEG_NODE_TYPE_PROXY, 3}, + {DEG_NODE_TYPE_ANIMATION, 4}, + {DEG_NODE_TYPE_TRANSFORM, 5}, + {DEG_NODE_TYPE_GEOMETRY, 6}, + {DEG_NODE_TYPE_SEQUENCER, 7}, + {DEG_NODE_TYPE_SHADING, 8}, + {DEG_NODE_TYPE_CACHE, 9}, {-1, 0} }; #endif @@ -100,9 +98,9 @@ static int deg_debug_node_color_index(const DepsNode *node) #ifdef COLOR_SCHEME_NODE_CLASS /* Some special types. */ switch (node->type) { - case DEPSNODE_TYPE_ID_REF: + case DEG_NODE_TYPE_ID_REF: return 5; - case DEPSNODE_TYPE_OPERATION: + case DEG_NODE_TYPE_OPERATION: { OperationDepsNode *op_node = (OperationDepsNode *)node; if (op_node->is_noop()) @@ -115,9 +113,9 @@ static int deg_debug_node_color_index(const DepsNode *node) } /* Do others based on class. */ switch (node->tclass) { - case DEPSNODE_CLASS_OPERATION: + case DEG_NODE_CLASS_OPERATION: return 4; - case DEPSNODE_CLASS_COMPONENT: + case DEG_NODE_CLASS_COMPONENT: return 1; default: return 9; @@ -201,7 +199,7 @@ static void deg_debug_graphviz_node_color(const DebugContext &ctx, const char *color_update = "dodgerblue3"; const char *color = color_default; if (ctx.show_tags) { - if (node->tclass == DEPSNODE_CLASS_OPERATION) { + if (node->tclass == DEG_NODE_CLASS_OPERATION) { OperationDepsNode *op_node = (OperationDepsNode *)node; if (op_node->flag & DEPSOP_FLAG_DIRECTLY_MODIFIED) { color = color_modified; @@ -222,7 +220,7 @@ static void deg_debug_graphviz_node_penwidth(const DebugContext &ctx, float penwidth_update = 4.0f; float penwidth = penwidth_default; if (ctx.show_tags) { - if (node->tclass == DEPSNODE_CLASS_OPERATION) { + if (node->tclass == DEG_NODE_CLASS_OPERATION) { OperationDepsNode *op_node = (OperationDepsNode *)node; if (op_node->flag & DEPSOP_FLAG_DIRECTLY_MODIFIED) { penwidth = penwidth_modified; @@ -260,7 +258,7 @@ static void deg_debug_graphviz_node_style(const DebugContext &ctx, const DepsNod { const char *base_style = "filled"; /* default style */ if (ctx.show_tags) { - if (node->tclass == DEPSNODE_CLASS_OPERATION) { + if (node->tclass == DEG_NODE_CLASS_OPERATION) { OperationDepsNode *op_node = (OperationDepsNode *)node; if (op_node->flag & (DEPSOP_FLAG_DIRECTLY_MODIFIED | DEPSOP_FLAG_NEEDS_UPDATE)) { base_style = "striped"; @@ -268,13 +266,13 @@ static void deg_debug_graphviz_node_style(const DebugContext &ctx, const DepsNod } } switch (node->tclass) { - case DEPSNODE_CLASS_GENERIC: + case DEG_NODE_CLASS_GENERIC: deg_debug_fprintf(ctx, "\"%s\"", base_style); break; - case DEPSNODE_CLASS_COMPONENT: + case DEG_NODE_CLASS_COMPONENT: deg_debug_fprintf(ctx, "\"%s\"", base_style); break; - case DEPSNODE_CLASS_OPERATION: + case DEG_NODE_CLASS_OPERATION: deg_debug_fprintf(ctx, "\"%s,rounded\"", base_style); break; } @@ -286,13 +284,13 @@ static void deg_debug_graphviz_node_single(const DebugContext &ctx, const char *shape = "box"; string name = node->identifier(); float priority = -1.0f; - if (node->type == DEPSNODE_TYPE_ID_REF) { + if (node->type == DEG_NODE_TYPE_ID_REF) { IDDepsNode *id_node = (IDDepsNode *)node; char buf[256]; BLI_snprintf(buf, sizeof(buf), " (Layers: %u)", id_node->layers); name += buf; } - if (ctx.show_eval_priority && node->tclass == DEPSNODE_CLASS_OPERATION) { + if (ctx.show_eval_priority && node->tclass == DEG_NODE_CLASS_OPERATION) { priority = ((OperationDepsNode *)node)->eval_priority; } deg_debug_fprintf(ctx, "// %s\n", name.c_str()); @@ -322,7 +320,7 @@ static void deg_debug_graphviz_node_cluster_begin(const DebugContext &ctx, const DepsNode *node) { string name = node->identifier(); - if (node->type == DEPSNODE_TYPE_ID_REF) { + if (node->type == DEG_NODE_TYPE_ID_REF) { IDDepsNode *id_node = (IDDepsNode *)node; char buf[256]; BLI_snprintf(buf, sizeof(buf), " (Layers: %u)", id_node->layers); @@ -363,7 +361,7 @@ static void deg_debug_graphviz_node(const DebugContext &ctx, const DepsNode *node) { switch (node->type) { - case DEPSNODE_TYPE_ID_REF: + case DEG_NODE_TYPE_ID_REF: { const IDDepsNode *id_node = (const IDDepsNode *)node; if (BLI_ghash_size(id_node->components) == 0) { @@ -380,30 +378,17 @@ static void deg_debug_graphviz_node(const DebugContext &ctx, } break; } - case DEPSNODE_TYPE_SUBGRAPH: - { - SubgraphDepsNode *sub_node = (SubgraphDepsNode *)node; - if (sub_node->graph) { - deg_debug_graphviz_node_cluster_begin(ctx, node); - deg_debug_graphviz_graph_nodes(ctx, sub_node->graph); - deg_debug_graphviz_node_cluster_end(ctx); - } - else { - deg_debug_graphviz_node_single(ctx, node); - } - break; - } - case DEPSNODE_TYPE_PARAMETERS: - case DEPSNODE_TYPE_ANIMATION: - case DEPSNODE_TYPE_TRANSFORM: - case DEPSNODE_TYPE_PROXY: - case DEPSNODE_TYPE_GEOMETRY: - case DEPSNODE_TYPE_SEQUENCER: - case DEPSNODE_TYPE_EVAL_POSE: - case DEPSNODE_TYPE_BONE: - case DEPSNODE_TYPE_SHADING: - case DEPSNODE_TYPE_CACHE: - case DEPSNODE_TYPE_EVAL_PARTICLES: + case DEG_NODE_TYPE_PARAMETERS: + case DEG_NODE_TYPE_ANIMATION: + case DEG_NODE_TYPE_TRANSFORM: + case DEG_NODE_TYPE_PROXY: + case DEG_NODE_TYPE_GEOMETRY: + case DEG_NODE_TYPE_SEQUENCER: + case DEG_NODE_TYPE_EVAL_POSE: + case DEG_NODE_TYPE_BONE: + case DEG_NODE_TYPE_SHADING: + case DEG_NODE_TYPE_CACHE: + case DEG_NODE_TYPE_EVAL_PARTICLES: { ComponentDepsNode *comp_node = (ComponentDepsNode *)node; if (!comp_node->operations.empty()) { @@ -427,24 +412,19 @@ static void deg_debug_graphviz_node(const DebugContext &ctx, static bool deg_debug_graphviz_is_cluster(const DepsNode *node) { switch (node->type) { - case DEPSNODE_TYPE_ID_REF: + case DEG_NODE_TYPE_ID_REF: { const IDDepsNode *id_node = (const IDDepsNode *)node; return BLI_ghash_size(id_node->components) > 0; } - case DEPSNODE_TYPE_SUBGRAPH: - { - SubgraphDepsNode *sub_node = (SubgraphDepsNode *)node; - return sub_node->graph != NULL; - } - case DEPSNODE_TYPE_PARAMETERS: - case DEPSNODE_TYPE_ANIMATION: - case DEPSNODE_TYPE_TRANSFORM: - case DEPSNODE_TYPE_PROXY: - case DEPSNODE_TYPE_GEOMETRY: - case DEPSNODE_TYPE_SEQUENCER: - case DEPSNODE_TYPE_EVAL_POSE: - case DEPSNODE_TYPE_BONE: + case DEG_NODE_TYPE_PARAMETERS: + case DEG_NODE_TYPE_ANIMATION: + case DEG_NODE_TYPE_TRANSFORM: + case DEG_NODE_TYPE_PROXY: + case DEG_NODE_TYPE_GEOMETRY: + case DEG_NODE_TYPE_SEQUENCER: + case DEG_NODE_TYPE_EVAL_POSE: + case DEG_NODE_TYPE_BONE: { ComponentDepsNode *comp_node = (ComponentDepsNode *)node; return !comp_node->operations.empty(); @@ -458,14 +438,14 @@ static bool deg_debug_graphviz_is_owner(const DepsNode *node, const DepsNode *other) { switch (node->tclass) { - case DEPSNODE_CLASS_COMPONENT: + case DEG_NODE_CLASS_COMPONENT: { ComponentDepsNode *comp_node = (ComponentDepsNode *)node; if (comp_node->owner == other) return true; break; } - case DEPSNODE_CLASS_OPERATION: + case DEG_NODE_CLASS_OPERATION: { OperationDepsNode *op_node = (OperationDepsNode *)node; if (op_node->owner == other) @@ -517,15 +497,12 @@ static void deg_debug_graphviz_node_relations(const DebugContext &ctx, static void deg_debug_graphviz_graph_nodes(const DebugContext &ctx, const Depsgraph *graph) { - if (graph->root_node) { - deg_debug_graphviz_node(ctx, graph->root_node); - } GHASH_FOREACH_BEGIN (DepsNode *, node, graph->id_hash) { deg_debug_graphviz_node(ctx, node); } GHASH_FOREACH_END(); - TimeSourceDepsNode *time_source = graph->find_time_source(NULL); + TimeSourceDepsNode *time_source = graph->find_time_source(); if (time_source != NULL) { deg_debug_graphviz_node(ctx, time_source); } @@ -546,7 +523,7 @@ static void deg_debug_graphviz_graph_relations(const DebugContext &ctx, } GHASH_FOREACH_END(); - TimeSourceDepsNode *time_source = graph->find_time_source(NULL); + TimeSourceDepsNode *time_source = graph->find_time_source(); if (time_source != NULL) { deg_debug_graphviz_node_relations(ctx, time_source); } diff --git a/source/blender/depsgraph/intern/depsgraph.cc b/source/blender/depsgraph/intern/depsgraph.cc index 9a4a35a5a35..aa21f0995be 100644 --- a/source/blender/depsgraph/intern/depsgraph.cc +++ b/source/blender/depsgraph/intern/depsgraph.cc @@ -69,26 +69,22 @@ static DEG_EditorUpdateSceneCb deg_editor_update_scene_cb = NULL; static DEG_EditorUpdateScenePreCb deg_editor_update_scene_pre_cb = NULL; Depsgraph::Depsgraph() - : root_node(NULL), + : time_source(NULL), need_update(false), layers(0) { BLI_spin_init(&lock); id_hash = BLI_ghash_ptr_new("Depsgraph id hash"); - subgraphs = BLI_gset_ptr_new("Depsgraph subgraphs"); entry_tags = BLI_gset_ptr_new("Depsgraph entry_tags"); } Depsgraph::~Depsgraph() { - /* Free root node - it won't have been freed yet... */ clear_id_nodes(); - clear_subgraph_nodes(); BLI_ghash_free(id_hash, NULL, NULL); - BLI_gset_free(subgraphs, NULL); BLI_gset_free(entry_tags, NULL); - if (this->root_node != NULL) { - OBJECT_GUARDED_DELETE(this->root_node, RootDepsNode); + if (time_source != NULL) { + OBJECT_GUARDED_DELETE(time_source, TimeSourceDepsNode); } BLI_spin_end(&lock); } @@ -131,7 +127,7 @@ static bool pointer_to_component_node_criteria(const PointerRNA *ptr, bPoseChannel *pchan = (bPoseChannel *)ptr->data; /* Bone - generally, we just want the bone component... */ - *type = DEPSNODE_TYPE_BONE; + *type = DEG_NODE_TYPE_BONE; *subdata = pchan->name; return true; @@ -141,7 +137,7 @@ static bool pointer_to_component_node_criteria(const PointerRNA *ptr, /* armature-level bone, but it ends up going to bone component anyway */ // TODO: the ID in thise case will end up being bArmature, not Object as needed! - *type = DEPSNODE_TYPE_BONE; + *type = DEG_NODE_TYPE_BONE; *subdata = bone->name; //*id = ... @@ -155,7 +151,7 @@ static bool pointer_to_component_node_criteria(const PointerRNA *ptr, if (BLI_findindex(&ob->constraints, con) != -1) { /* object transform */ // XXX: for now, we can't address the specific constraint or the constraint stack... - *type = DEPSNODE_TYPE_TRANSFORM; + *type = DEG_NODE_TYPE_TRANSFORM; return true; } else if (ob->pose) { @@ -163,7 +159,7 @@ static bool pointer_to_component_node_criteria(const PointerRNA *ptr, for (pchan = (bPoseChannel *)ob->pose->chanbase.first; pchan; pchan = pchan->next) { if (BLI_findindex(&pchan->constraints, con) != -1) { /* bone transforms */ - *type = DEPSNODE_TYPE_BONE; + *type = DEG_NODE_TYPE_BONE; *subdata = pchan->name; return true; } @@ -178,7 +174,7 @@ static bool pointer_to_component_node_criteria(const PointerRNA *ptr, * so although we have unique ops for modifiers, * we can't lump them together */ - *type = DEPSNODE_TYPE_BONE; + *type = DEG_NODE_TYPE_BONE; //*subdata = md->name; return true; @@ -189,37 +185,44 @@ static bool pointer_to_component_node_criteria(const PointerRNA *ptr, /* Transforms props? */ if (prop) { const char *prop_identifier = RNA_property_identifier((PropertyRNA *)prop); - + /* TODO(sergey): How to optimize this? */ if (strstr(prop_identifier, "location") || strstr(prop_identifier, "rotation") || - strstr(prop_identifier, "scale")) + strstr(prop_identifier, "scale") || + strstr(prop_identifier, "matrix_")) { - *type = DEPSNODE_TYPE_TRANSFORM; + *type = DEG_NODE_TYPE_TRANSFORM; + return true; + } + else if (strstr(prop_identifier, "data")) { + /* We access object.data, most likely a geometry. + * Might be a bone tho.. + */ + *type = DEG_NODE_TYPE_GEOMETRY; return true; } } - // ... } else if (ptr->type == &RNA_ShapeKey) { Key *key = (Key *)ptr->id.data; /* ShapeKeys are currently handled as geometry on the geometry that owns it */ *id = key->from; // XXX - *type = DEPSNODE_TYPE_PARAMETERS; + *type = DEG_NODE_TYPE_PARAMETERS; return true; } else if (RNA_struct_is_a(ptr->type, &RNA_Sequence)) { Sequence *seq = (Sequence *)ptr->data; /* Sequencer strip */ - *type = DEPSNODE_TYPE_SEQUENCER; + *type = DEG_NODE_TYPE_SEQUENCER; *subdata = seq->name; // xxx? return true; } if (prop) { /* All unknown data effectively falls under "parameter evaluation" */ - *type = DEPSNODE_TYPE_PARAMETERS; + *type = DEG_NODE_TYPE_PARAMETERS; return true; } @@ -256,72 +259,18 @@ static void id_node_deleter(void *value) OBJECT_GUARDED_DELETE(id_node, IDDepsNode); } -RootDepsNode *Depsgraph::add_root_node() -{ - if (!root_node) { - DepsNodeFactory *factory = deg_get_node_factory(DEPSNODE_TYPE_ROOT); - root_node = (RootDepsNode *)factory->create_node(NULL, "", "Root (Scene)"); - } - return root_node; -} - -TimeSourceDepsNode *Depsgraph::find_time_source(const ID *id) const -{ - /* Search for one attached to a particular ID? */ - if (id) { - /* Check if it was added as a component - * (as may be done for subgraphs needing timeoffset). - */ - IDDepsNode *id_node = find_id_node(id); - if (id_node) { - // XXX: review this -// return id_node->find_component(DEPSNODE_TYPE_TIMESOURCE); - } - BLI_assert(!"Not implemented yet"); - } - else { - /* Use "official" timesource. */ - return root_node->time_source; - } - return NULL; -} - -SubgraphDepsNode *Depsgraph::add_subgraph_node(const ID *id) +TimeSourceDepsNode *Depsgraph::add_time_source() { - DepsNodeFactory *factory = deg_get_node_factory(DEPSNODE_TYPE_SUBGRAPH); - SubgraphDepsNode *subgraph_node = - (SubgraphDepsNode *)factory->create_node(id, "", id->name + 2); - - /* Add to subnodes list. */ - BLI_gset_insert(subgraphs, subgraph_node); - - /* if there's an ID associated, add to ID-nodes lookup too */ - if (id) { -#if 0 - /* XXX subgraph node is NOT a true IDDepsNode - what is this supposed to do? */ - // TODO: what to do if subgraph's ID has already been added? - BLI_assert(!graph->find_id_node(id)); - graph->id_hash[id] = this; -#endif + if (time_source == NULL) { + DepsNodeFactory *factory = deg_get_node_factory(DEG_NODE_TYPE_TIMESOURCE); + time_source = (TimeSourceDepsNode *)factory->create_node(NULL, "", "Time Source"); } - - return subgraph_node; -} - -void Depsgraph::remove_subgraph_node(SubgraphDepsNode *subgraph_node) -{ - BLI_gset_remove(subgraphs, subgraph_node, NULL); - OBJECT_GUARDED_DELETE(subgraph_node, SubgraphDepsNode); + return time_source; } -void Depsgraph::clear_subgraph_nodes() +TimeSourceDepsNode *Depsgraph::find_time_source() const { - GSET_FOREACH_BEGIN(SubgraphDepsNode *, subgraph_node, subgraphs) - { - OBJECT_GUARDED_DELETE(subgraph_node, SubgraphDepsNode); - } - GSET_FOREACH_END(); - BLI_gset_clear(subgraphs, NULL); + return time_source; } IDDepsNode *Depsgraph::find_id_node(const ID *id) const @@ -333,7 +282,7 @@ IDDepsNode *Depsgraph::add_id_node(ID *id, const char *name) { IDDepsNode *id_node = find_id_node(id); if (!id_node) { - DepsNodeFactory *factory = deg_get_node_factory(DEPSNODE_TYPE_ID_REF); + DepsNodeFactory *factory = deg_get_node_factory(DEG_NODE_TYPE_ID_REF); id_node = (IDDepsNode *)factory->create_node(id, "", name); id->tag |= LIB_TAG_DOIT; /* register */ @@ -342,16 +291,6 @@ IDDepsNode *Depsgraph::add_id_node(ID *id, const char *name) return id_node; } -void Depsgraph::remove_id_node(const ID *id) -{ - IDDepsNode *id_node = find_id_node(id); - if (id_node) { - /* unregister */ - BLI_ghash_remove(id_hash, id, NULL, NULL); - OBJECT_GUARDED_DELETE(id_node, IDDepsNode); - } -} - void Depsgraph::clear_id_nodes() { BLI_ghash_clear(id_hash, NULL, id_node_deleter); @@ -360,15 +299,14 @@ void Depsgraph::clear_id_nodes() /* Add new relationship between two nodes. */ DepsRelation *Depsgraph::add_new_relation(OperationDepsNode *from, OperationDepsNode *to, - eDepsRelation_Type type, const char *description) { /* Create new relation, and add it to the graph. */ - DepsRelation *rel = OBJECT_GUARDED_NEW(DepsRelation, from, to, type, description); + DepsRelation *rel = OBJECT_GUARDED_NEW(DepsRelation, from, to, description); /* TODO(sergey): Find a better place for this. */ #ifdef WITH_OPENSUBDIV ComponentDepsNode *comp_node = from->owner; - if (comp_node->type == DEPSNODE_TYPE_GEOMETRY) { + if (comp_node->type == DEG_NODE_TYPE_GEOMETRY) { IDDepsNode *id_to = to->owner->owner; IDDepsNode *id_from = from->owner->owner; if (id_to != id_from && (id_to->id->tag & LIB_TAG_ID_RECALC_ALL)) { @@ -384,11 +322,10 @@ DepsRelation *Depsgraph::add_new_relation(OperationDepsNode *from, /* Add new relation between two nodes */ DepsRelation *Depsgraph::add_new_relation(DepsNode *from, DepsNode *to, - eDepsRelation_Type type, const char *description) { /* Create new relation, and add it to the graph. */ - DepsRelation *rel = OBJECT_GUARDED_NEW(DepsRelation, from, to, type, description); + DepsRelation *rel = OBJECT_GUARDED_NEW(DepsRelation, from, to, description); return rel; } @@ -397,12 +334,10 @@ DepsRelation *Depsgraph::add_new_relation(DepsNode *from, DepsNode *to, DepsRelation::DepsRelation(DepsNode *from, DepsNode *to, - eDepsRelation_Type type, const char *description) : from(from), to(to), name(description), - type(type), flag(0) { #ifndef NDEBUG @@ -465,11 +400,10 @@ void Depsgraph::add_entry_tag(OperationDepsNode *node) void Depsgraph::clear_all_nodes() { clear_id_nodes(); - clear_subgraph_nodes(); BLI_ghash_clear(id_hash, NULL, NULL); - if (this->root_node) { - OBJECT_GUARDED_DELETE(this->root_node, RootDepsNode); - root_node = NULL; + if (time_source != NULL) { + OBJECT_GUARDED_DELETE(time_source, TimeSourceDepsNode); + time_source = NULL; } } diff --git a/source/blender/depsgraph/intern/depsgraph.h b/source/blender/depsgraph/intern/depsgraph.h index e668facd645..f72f8dd9311 100644 --- a/source/blender/depsgraph/intern/depsgraph.h +++ b/source/blender/depsgraph/intern/depsgraph.h @@ -49,10 +49,8 @@ struct PropertyRNA; namespace DEG { struct DepsNode; -struct RootDepsNode; struct TimeSourceDepsNode; struct IDDepsNode; -struct SubgraphDepsNode; struct ComponentDepsNode; struct OperationDepsNode; @@ -79,12 +77,10 @@ struct DepsRelation { /* relationship attributes */ const char *name; /* label for debugging */ - eDepsRelation_Type type; /* type */ int flag; /* (eDepsRelation_Flag) */ DepsRelation(DepsNode *from, DepsNode *to, - eDepsRelation_Type type, const char *description); ~DepsRelation(); @@ -111,28 +107,20 @@ struct Depsgraph { */ DepsNode *find_node_from_pointer(const PointerRNA *ptr, const PropertyRNA *prop) const; - RootDepsNode *add_root_node(); - - TimeSourceDepsNode *find_time_source(const ID *id = NULL) const; - - SubgraphDepsNode *add_subgraph_node(const ID *id); - void remove_subgraph_node(SubgraphDepsNode *subgraph_node); - void clear_subgraph_nodes(); + TimeSourceDepsNode *add_time_source(); + TimeSourceDepsNode *find_time_source() const; IDDepsNode *find_id_node(const ID *id) const; IDDepsNode *add_id_node(ID *id, const char *name = ""); - void remove_id_node(const ID *id); void clear_id_nodes(); /* Add new relationship between two nodes. */ DepsRelation *add_new_relation(OperationDepsNode *from, OperationDepsNode *to, - eDepsRelation_Type type, const char *description); DepsRelation *add_new_relation(DepsNode *from, DepsNode *to, - eDepsRelation_Type type, const char *description); /* Tag a specific node as needing updates. */ @@ -147,11 +135,8 @@ struct Depsgraph { * (for quick lookups). */ GHash *id_hash; - /* "root" node - the one where all evaluation enters from. */ - RootDepsNode *root_node; - - /* Subgraphs referenced in tree. */ - GSet *subgraphs; + /* Top-level time source node. */ + TimeSourceDepsNode *time_source; /* Indicates whether relations needs to be updated. */ bool need_update; diff --git a/source/blender/depsgraph/intern/depsgraph_build.cc b/source/blender/depsgraph/intern/depsgraph_build.cc index 9952f714145..47bf5e7ecbb 100644 --- a/source/blender/depsgraph/intern/depsgraph_build.cc +++ b/source/blender/depsgraph/intern/depsgraph_build.cc @@ -34,12 +34,6 @@ // #define DEBUG_TIME -extern "C" { -#include "DNA_cachefile_types.h" -#include "DNA_object_types.h" -#include "DNA_scene_types.h" -#include "DNA_object_force.h" - #include "BLI_utildefines.h" #include "BLI_ghash.h" @@ -48,17 +42,22 @@ extern "C" { # include "PIL_time_utildefines.h" #endif +extern "C" { +#include "DNA_cachefile_types.h" +#include "DNA_object_types.h" +#include "DNA_scene_types.h" +#include "DNA_object_force.h" + #include "BKE_main.h" #include "BKE_collision.h" #include "BKE_effect.h" #include "BKE_modifier.h" +} /* extern "C" */ #include "DEG_depsgraph.h" #include "DEG_depsgraph_debug.h" #include "DEG_depsgraph_build.h" -} /* extern "C" */ - #include "builder/deg_builder.h" #include "builder/deg_builder_cycle.h" #include "builder/deg_builder_nodes.h" @@ -81,29 +80,29 @@ static DEG::eDepsNode_Type deg_build_scene_component_type( eDepsSceneComponentType component) { switch (component) { - case DEG_SCENE_COMP_PARAMETERS: return DEG::DEPSNODE_TYPE_PARAMETERS; - case DEG_SCENE_COMP_ANIMATION: return DEG::DEPSNODE_TYPE_ANIMATION; - case DEG_SCENE_COMP_SEQUENCER: return DEG::DEPSNODE_TYPE_SEQUENCER; + case DEG_SCENE_COMP_PARAMETERS: return DEG::DEG_NODE_TYPE_PARAMETERS; + case DEG_SCENE_COMP_ANIMATION: return DEG::DEG_NODE_TYPE_ANIMATION; + case DEG_SCENE_COMP_SEQUENCER: return DEG::DEG_NODE_TYPE_SEQUENCER; } - return DEG::DEPSNODE_TYPE_UNDEFINED; + return DEG::DEG_NODE_TYPE_UNDEFINED; } static DEG::eDepsNode_Type deg_build_object_component_type( eDepsObjectComponentType component) { switch (component) { - case DEG_OB_COMP_PARAMETERS: return DEG::DEPSNODE_TYPE_PARAMETERS; - case DEG_OB_COMP_PROXY: return DEG::DEPSNODE_TYPE_PROXY; - case DEG_OB_COMP_ANIMATION: return DEG::DEPSNODE_TYPE_ANIMATION; - case DEG_OB_COMP_TRANSFORM: return DEG::DEPSNODE_TYPE_TRANSFORM; - case DEG_OB_COMP_GEOMETRY: return DEG::DEPSNODE_TYPE_GEOMETRY; - case DEG_OB_COMP_EVAL_POSE: return DEG::DEPSNODE_TYPE_EVAL_POSE; - case DEG_OB_COMP_BONE: return DEG::DEPSNODE_TYPE_BONE; - case DEG_OB_COMP_EVAL_PARTICLES: return DEG::DEPSNODE_TYPE_EVAL_PARTICLES; - case DEG_OB_COMP_SHADING: return DEG::DEPSNODE_TYPE_SHADING; - case DEG_OB_COMP_CACHE: return DEG::DEPSNODE_TYPE_CACHE; + case DEG_OB_COMP_PARAMETERS: return DEG::DEG_NODE_TYPE_PARAMETERS; + case DEG_OB_COMP_PROXY: return DEG::DEG_NODE_TYPE_PROXY; + case DEG_OB_COMP_ANIMATION: return DEG::DEG_NODE_TYPE_ANIMATION; + case DEG_OB_COMP_TRANSFORM: return DEG::DEG_NODE_TYPE_TRANSFORM; + case DEG_OB_COMP_GEOMETRY: return DEG::DEG_NODE_TYPE_GEOMETRY; + case DEG_OB_COMP_EVAL_POSE: return DEG::DEG_NODE_TYPE_EVAL_POSE; + case DEG_OB_COMP_BONE: return DEG::DEG_NODE_TYPE_BONE; + case DEG_OB_COMP_EVAL_PARTICLES: return DEG::DEG_NODE_TYPE_EVAL_PARTICLES; + case DEG_OB_COMP_SHADING: return DEG::DEG_NODE_TYPE_SHADING; + case DEG_OB_COMP_CACHE: return DEG::DEG_NODE_TYPE_CACHE; } - return DEG::DEPSNODE_TYPE_UNDEFINED; + return DEG::DEG_NODE_TYPE_UNDEFINED; } static DEG::DepsNodeHandle *get_handle(DepsNodeHandle *handle) @@ -121,7 +120,6 @@ void DEG_add_scene_relation(DepsNodeHandle *handle, DEG::DepsNodeHandle *deg_handle = get_handle(handle); deg_handle->builder->add_node_handle_relation(comp_key, deg_handle, - DEG::DEPSREL_TYPE_GEOMETRY_EVAL, description); } @@ -135,7 +133,6 @@ void DEG_add_object_relation(DepsNodeHandle *handle, DEG::DepsNodeHandle *deg_handle = get_handle(handle); deg_handle->builder->add_node_handle_relation(comp_key, deg_handle, - DEG::DEPSREL_TYPE_GEOMETRY_EVAL, description); } @@ -149,7 +146,6 @@ void DEG_add_object_cache_relation(DepsNodeHandle *handle, DEG::DepsNodeHandle *deg_handle = get_handle(handle); deg_handle->builder->add_node_handle_relation(comp_key, deg_handle, - DEG::DEPSREL_TYPE_CACHE, description); } @@ -167,10 +163,16 @@ void DEG_add_bone_relation(DepsNodeHandle *handle, */ deg_handle->builder->add_node_handle_relation(comp_key, deg_handle, - DEG::DEPSREL_TYPE_GEOMETRY_EVAL, description); } +struct Depsgraph *DEG_get_graph_from_handle(struct DepsNodeHandle *handle) +{ + DEG::DepsNodeHandle *deg_handle = get_handle(handle); + DEG::DepsgraphRelationBuilder *relation_builder = deg_handle->builder; + return reinterpret_cast<Depsgraph *>(relation_builder->getGraph()); +} + void DEG_add_special_eval_flag(Depsgraph *graph, ID *id, short flag) { DEG::Depsgraph *deg_graph = reinterpret_cast<DEG::Depsgraph *>(graph); @@ -205,28 +207,14 @@ void DEG_graph_build_from_scene(Depsgraph *graph, Main *bmain, Scene *scene) /* 1) Generate all the nodes in the graph first */ DEG::DepsgraphNodeBuilder node_builder(bmain, deg_graph); - /* create root node for scene first - * - this way it should be the first in the graph, - * reflecting its role as the entrypoint - */ - node_builder.add_root_node(); + node_builder.begin_build(bmain); node_builder.build_scene(bmain, scene); /* 2) Hook up relationships between operations - to determine evaluation * order. */ DEG::DepsgraphRelationBuilder relation_builder(deg_graph); - /* Hook scene up to the root node as entrypoint to graph. */ - /* XXX what does this relation actually mean? - * it doesnt add any operations anyway and is not clear what part of the - * scene is to be connected. - */ -#if 0 - relation_builder.add_relation(RootKey(), - IDKey(scene), - DEPSREL_TYPE_ROOT_TO_ACTIVE, - "Root to Active Scene"); -#endif + relation_builder.begin_build(bmain); relation_builder.build_scene(bmain, scene); /* Detect and solve cycles. */ diff --git a/source/blender/depsgraph/intern/depsgraph_debug.cc b/source/blender/depsgraph/intern/depsgraph_debug.cc index d3b48930779..388b692d742 100644 --- a/source/blender/depsgraph/intern/depsgraph_debug.cc +++ b/source/blender/depsgraph/intern/depsgraph_debug.cc @@ -35,11 +35,11 @@ extern "C" { #include "DNA_scene_types.h" +} /* extern "C" */ #include "DEG_depsgraph.h" #include "DEG_depsgraph_debug.h" #include "DEG_depsgraph_build.h" -} /* extern "C" */ #include "intern/eval/deg_eval_debug.h" #include "intern/depsgraph_intern.h" @@ -165,7 +165,7 @@ bool DEG_debug_consistency_check(Depsgraph *graph) return false; } foreach (DEG::DepsRelation *rel, node->outlinks) { - if (rel->to->type == DEG::DEPSNODE_TYPE_OPERATION) { + if (rel->to->type == DEG::DEG_NODE_TYPE_OPERATION) { DEG::OperationDepsNode *to = (DEG::OperationDepsNode *)rel->to; BLI_assert(to->num_links_pending < to->inlinks.size()); ++to->num_links_pending; @@ -177,7 +177,7 @@ bool DEG_debug_consistency_check(Depsgraph *graph) foreach (DEG::OperationDepsNode *node, deg_graph->operations) { int num_links_pending = 0; foreach (DEG::DepsRelation *rel, node->inlinks) { - if (rel->from->type == DEG::DEPSNODE_TYPE_OPERATION) { + if (rel->from->type == DEG::DEG_NODE_TYPE_OPERATION) { ++num_links_pending; } } @@ -232,7 +232,7 @@ void DEG_stats_simple(const Depsgraph *graph, size_t *r_outer, } GHASH_FOREACH_END(); - DEG::TimeSourceDepsNode *time_source = deg_graph->find_time_source(NULL); + DEG::TimeSourceDepsNode *time_source = deg_graph->find_time_source(); if (time_source != NULL) { tot_rels += time_source->inlinks.size(); } diff --git a/source/blender/depsgraph/intern/depsgraph_eval.cc b/source/blender/depsgraph/intern/depsgraph_eval.cc index c41f28b07e8..85a0d336d28 100644 --- a/source/blender/depsgraph/intern/depsgraph_eval.cc +++ b/source/blender/depsgraph/intern/depsgraph_eval.cc @@ -32,17 +32,17 @@ #include "MEM_guardedalloc.h" -extern "C" { -#include "DNA_scene_types.h" - #include "BLI_utildefines.h" #include "BLI_ghash.h" +extern "C" { +#include "DNA_scene_types.h" + #include "BKE_depsgraph.h" #include "BKE_scene.h" +} /* extern "C" */ #include "DEG_depsgraph.h" -} /* extern "C" */ #include "intern/eval/deg_eval.h" #include "intern/eval/deg_eval_flush.h" diff --git a/source/blender/depsgraph/intern/depsgraph_query.cc b/source/blender/depsgraph/intern/depsgraph_query.cc index 7f2f6a65f5e..e58a7a32407 100644 --- a/source/blender/depsgraph/intern/depsgraph_query.cc +++ b/source/blender/depsgraph/intern/depsgraph_query.cc @@ -35,9 +35,9 @@ extern "C" { #include "BKE_idcode.h" #include "BKE_main.h" +} /* extern "C" */ #include "DEG_depsgraph_query.h" -} /* extern "C" */ #include "intern/depsgraph_intern.h" diff --git a/source/blender/depsgraph/intern/depsgraph_tag.cc b/source/blender/depsgraph/intern/depsgraph_tag.cc index e8ed03666a6..5adcb3a11b3 100644 --- a/source/blender/depsgraph/intern/depsgraph_tag.cc +++ b/source/blender/depsgraph/intern/depsgraph_tag.cc @@ -34,15 +34,16 @@ #include <cstring> /* required for memset */ #include <queue> -extern "C" { #include "BLI_utildefines.h" +#include "BLI_task.h" +#include "BLI_listbase.h" +extern "C" { #include "DNA_object_types.h" #include "DNA_particle_types.h" #include "DNA_screen_types.h" #include "DNA_windowmanager_types.h" -#include "BLI_task.h" #include "BKE_idcode.h" #include "BKE_library.h" @@ -52,12 +53,12 @@ extern "C" { #define new new_ #include "BKE_screen.h" #undef new +} /* extern "C" */ #include "DEG_depsgraph.h" -} /* extern "C" */ +#include "intern/builder/deg_builder.h" #include "intern/eval/deg_eval_flush.h" - #include "intern/nodes/deg_node.h" #include "intern/nodes/deg_node_component.h" #include "intern/nodes/deg_node_operation.h" @@ -108,7 +109,7 @@ void lib_id_recalc_tag_flag(Main *bmain, ID *id, int flag) * nodes for update after relations update and after layer * visibility changes. */ - short idtype = GS(id->name); + ID_Type idtype = GS(id->name); if (idtype == ID_OB) { Object *object = (Object *)id; object->recalc |= (flag & OB_RECALC_ALL); @@ -276,15 +277,20 @@ void DEG_ids_flush_tagged(Main *bmain) scene != NULL; scene = (Scene *)scene->id.next) { - /* TODO(sergey): Only visible scenes? */ - if (scene->depsgraph != NULL) { - DEG::deg_graph_flush_updates( - bmain, - reinterpret_cast<DEG::Depsgraph *>(scene->depsgraph)); - } + DEG_scene_flush_update(bmain, scene); } } +void DEG_scene_flush_update(Main *bmain, Scene *scene) +{ + if (scene->depsgraph == NULL) { + return; + } + DEG::deg_graph_flush_updates( + bmain, + reinterpret_cast<DEG::Depsgraph *>(scene->depsgraph)); +} + /* Update dependency graph when visible scenes/layers changes. */ void DEG_graph_on_visible_update(Main *bmain, Scene *scene) { @@ -336,7 +342,7 @@ void DEG_graph_on_visible_update(Main *bmain, Scene *scene) { id_node->tag_update(graph); DEG::ComponentDepsNode *anim_comp = - id_node->find_component(DEG::DEPSNODE_TYPE_ANIMATION); + id_node->find_component(DEG::DEG_NODE_TYPE_ANIMATION); if (anim_comp != NULL && object->recalc & OB_RECALC_TIME) { anim_comp->tag_update(graph); } @@ -346,6 +352,37 @@ void DEG_graph_on_visible_update(Main *bmain, Scene *scene) GHASH_FOREACH_END(); } scene->lay_updated |= graph->layers; + /* If graph is tagged for update, we don't need to bother with updates here, + * nodes will be re-created. + */ + if (graph->need_update) { + return; + } + /* Special trick to get local view to work. */ + LINKLIST_FOREACH (Base *, base, &scene->base) { + Object *object = base->object; + DEG::IDDepsNode *id_node = graph->find_id_node(&object->id); + id_node->layers = 0; + } + LINKLIST_FOREACH (Base *, base, &scene->base) { + Object *object = base->object; + DEG::IDDepsNode *id_node = graph->find_id_node(&object->id); + id_node->layers |= base->lay; + if (object == scene->camera) { + /* Camera should always be updated, it used directly by viewport. */ + id_node->layers |= (unsigned int)(-1); + } + } + DEG::deg_graph_build_flush_layers(graph); + LINKLIST_FOREACH (Base *, base, &scene->base) { + Object *object = base->object; + DEG::IDDepsNode *id_node = graph->find_id_node(&object->id); + GHASH_FOREACH_BEGIN(DEG::ComponentDepsNode *, comp, id_node->components) + { + id_node->layers |= comp->layers; + } + GHASH_FOREACH_END(); + } } void DEG_on_visible_update(Main *bmain, const bool UNUSED(do_time)) diff --git a/source/blender/depsgraph/intern/depsgraph_type_defines.cc b/source/blender/depsgraph/intern/depsgraph_type_defines.cc index 4ce91516c84..e177c8c8ec0 100644 --- a/source/blender/depsgraph/intern/depsgraph_type_defines.cc +++ b/source/blender/depsgraph/intern/depsgraph_type_defines.cc @@ -32,12 +32,11 @@ #include <cstdlib> // for BLI_assert() -extern "C" { + #include "BLI_utildefines.h" #include "BLI_ghash.h" #include "DEG_depsgraph.h" -} /* extern "C" */ #include "intern/nodes/deg_node.h" #include "intern/nodes/deg_node_component.h" @@ -98,37 +97,31 @@ static const char *stringify_opcode(eDepsOperation_Code opcode) #define STRINGIFY_OPCODE(name) case DEG_OPCODE_##name: return #name STRINGIFY_OPCODE(OPERATION); STRINGIFY_OPCODE(PLACEHOLDER); - STRINGIFY_OPCODE(NOOP); STRINGIFY_OPCODE(ANIMATION); STRINGIFY_OPCODE(DRIVER); - //STRINGIFY_OPCODE(PROXY); STRINGIFY_OPCODE(TRANSFORM_LOCAL); STRINGIFY_OPCODE(TRANSFORM_PARENT); STRINGIFY_OPCODE(TRANSFORM_CONSTRAINTS); - //STRINGIFY_OPCODE(TRANSFORM_CONSTRAINTS_INIT); - //STRINGIFY_OPCODE(TRANSFORM_CONSTRAINT); - //STRINGIFY_OPCODE(TRANSFORM_CONSTRAINTS_DONE); STRINGIFY_OPCODE(RIGIDBODY_REBUILD); STRINGIFY_OPCODE(RIGIDBODY_SIM); STRINGIFY_OPCODE(TRANSFORM_RIGIDBODY); STRINGIFY_OPCODE(TRANSFORM_FINAL); STRINGIFY_OPCODE(OBJECT_UBEREVAL); STRINGIFY_OPCODE(GEOMETRY_UBEREVAL); - STRINGIFY_OPCODE(GEOMETRY_MODIFIER); - STRINGIFY_OPCODE(GEOMETRY_PATH); STRINGIFY_OPCODE(POSE_INIT); + STRINGIFY_OPCODE(POSE_INIT_IK); STRINGIFY_OPCODE(POSE_DONE); STRINGIFY_OPCODE(POSE_IK_SOLVER); STRINGIFY_OPCODE(POSE_SPLINE_IK_SOLVER); STRINGIFY_OPCODE(BONE_LOCAL); STRINGIFY_OPCODE(BONE_POSE_PARENT); STRINGIFY_OPCODE(BONE_CONSTRAINTS); - //STRINGIFY_OPCODE(BONE_CONSTRAINTS_INIT); - //STRINGIFY_OPCODE(BONE_CONSTRAINT); - //STRINGIFY_OPCODE(BONE_CONSTRAINTS_DONE); STRINGIFY_OPCODE(BONE_READY); STRINGIFY_OPCODE(BONE_DONE); STRINGIFY_OPCODE(PSYS_EVAL); + STRINGIFY_OPCODE(PSYS_EVAL_INIT); + STRINGIFY_OPCODE(MASK_ANIMATION); + STRINGIFY_OPCODE(MASK_EVAL); case DEG_NUM_OPCODES: return "SpecialCase"; #undef STRINGIFY_OPCODE @@ -145,7 +138,7 @@ DepsOperationStringifier::DepsOperationStringifier() const char *DepsOperationStringifier::operator[](eDepsOperation_Code opcode) { - BLI_assert((opcode > 0) && (opcode < DEG_NUM_OPCODES)); + BLI_assert((opcode >= 0) && (opcode < DEG_NUM_OPCODES)); if (opcode >= 0 && opcode < DEG_NUM_OPCODES) { return names_[opcode]; } diff --git a/source/blender/depsgraph/intern/depsgraph_types.h b/source/blender/depsgraph/intern/depsgraph_types.h index effd34a0eb9..ef7b32a8d83 100644 --- a/source/blender/depsgraph/intern/depsgraph_types.h +++ b/source/blender/depsgraph/intern/depsgraph_types.h @@ -44,9 +44,6 @@ #include <string> #include <vector> -using std::string; -using std::vector; - struct bAction; struct ChannelDriver; struct ModifierData; @@ -56,6 +53,9 @@ struct FCurve; namespace DEG { +using std::string; +using std::vector; + /* Evaluation Operation for atomic operation */ // XXX: move this to another header that can be exposed? typedef function<void(struct EvaluationContext *)> DepsEvalOperationCb; @@ -67,74 +67,66 @@ typedef enum eDepsNode_Class { /* Types generally unassociated with user-visible entities, * but needed for graph functioning. */ - DEPSNODE_CLASS_GENERIC = 0, + DEG_NODE_CLASS_GENERIC = 0, /* [Outer Node] An "aspect" of evaluating/updating an ID-Block, requiring * certain types of evaluation behavior. */ - DEPSNODE_CLASS_COMPONENT = 1, + DEG_NODE_CLASS_COMPONENT = 1, /* [Inner Node] A glorified function-pointer/callback for scheduling up * evaluation operations for components, subject to relationship * requirements. */ - DEPSNODE_CLASS_OPERATION = 2, + DEG_NODE_CLASS_OPERATION = 2, } eDepsNode_Class; /* Types of Nodes */ typedef enum eDepsNode_Type { /* Fallback type for invalid return value */ - DEPSNODE_TYPE_UNDEFINED = -1, + DEG_NODE_TYPE_UNDEFINED = -1, /* Inner Node (Operation) */ - DEPSNODE_TYPE_OPERATION = 0, + DEG_NODE_TYPE_OPERATION = 0, /* **** Generic Types **** */ - /* "Current Scene" - basically whatever kicks off the evaluation process. */ - DEPSNODE_TYPE_ROOT = 1, /* Time-Source */ - DEPSNODE_TYPE_TIMESOURCE = 2, + DEG_NODE_TYPE_TIMESOURCE, /* ID-Block reference - used as landmarks/collection point for components, * but not usually part of main graph. */ - DEPSNODE_TYPE_ID_REF = 3, - /* Isolated sub-graph - used for keeping instanced data separate from - * instances using them. - */ - DEPSNODE_TYPE_SUBGRAPH = 4, + DEG_NODE_TYPE_ID_REF, /* **** Outer Types **** */ /* Parameters Component - Default when nothing else fits * (i.e. just SDNA property setting). */ - DEPSNODE_TYPE_PARAMETERS = 11, - /* Generic "Proxy-Inherit" Component - * XXX: Also for instancing of subgraphs? - */ - DEPSNODE_TYPE_PROXY = 12, + DEG_NODE_TYPE_PARAMETERS, + /* Generic "Proxy-Inherit" Component. */ + DEG_NODE_TYPE_PROXY, /* Animation Component * * XXX: merge in with parameters? */ - DEPSNODE_TYPE_ANIMATION = 13, + DEG_NODE_TYPE_ANIMATION, /* Transform Component (Parenting/Constraints) */ - DEPSNODE_TYPE_TRANSFORM = 14, + DEG_NODE_TYPE_TRANSFORM, /* Geometry Component (DerivedMesh/Displist) */ - DEPSNODE_TYPE_GEOMETRY = 15, + DEG_NODE_TYPE_GEOMETRY, /* Sequencer Component (Scene Only) */ - DEPSNODE_TYPE_SEQUENCER = 16, + DEG_NODE_TYPE_SEQUENCER, /* **** Evaluation-Related Outer Types (with Subdata) **** */ /* Pose Component - Owner/Container of Bones Eval */ - DEPSNODE_TYPE_EVAL_POSE = 21, + DEG_NODE_TYPE_EVAL_POSE, /* Bone Component - Child/Subcomponent of Pose */ - DEPSNODE_TYPE_BONE = 22, + DEG_NODE_TYPE_BONE, /* Particle Systems Component */ - DEPSNODE_TYPE_EVAL_PARTICLES = 23, + DEG_NODE_TYPE_EVAL_PARTICLES, /* Material Shading Component */ - DEPSNODE_TYPE_SHADING = 24, + DEG_NODE_TYPE_SHADING, /* Cache Component */ - DEPSNODE_TYPE_CACHE = 25, + DEG_NODE_TYPE_CACHE, } eDepsNode_Type; /* Identifiers for common operations (as an enum). */ @@ -147,8 +139,6 @@ typedef enum eDepsOperation_Code { // XXX: Placeholder while porting depsgraph code DEG_OPCODE_PLACEHOLDER, - DEG_OPCODE_NOOP, - /* Animation, Drivers, etc. ------------------------ */ /* NLA + Action */ @@ -157,9 +147,6 @@ typedef enum eDepsOperation_Code { /* Driver */ DEG_OPCODE_DRIVER, - /* Proxy Inherit? */ - //DEG_OPCODE_PROXY, - /* Transform --------------------------------------- */ /* Transform entry point - local transforms only */ @@ -170,9 +157,6 @@ typedef enum eDepsOperation_Code { /* Constraints */ DEG_OPCODE_TRANSFORM_CONSTRAINTS, - //DEG_OPCODE_TRANSFORM_CONSTRAINTS_INIT, - //DEG_OPCODE_TRANSFORM_CONSTRAINT, - //DEG_OPCODE_TRANSFORM_CONSTRAINTS_DONE, /* Rigidbody Sim - Perform Sim */ DEG_OPCODE_RIGIDBODY_REBUILD, @@ -192,17 +176,14 @@ typedef enum eDepsOperation_Code { /* XXX: Placeholder - UberEval */ DEG_OPCODE_GEOMETRY_UBEREVAL, - /* Modifier */ - DEG_OPCODE_GEOMETRY_MODIFIER, - - /* Curve Objects - Path Calculation (used for path-following tools, */ - DEG_OPCODE_GEOMETRY_PATH, - /* Pose -------------------------------------------- */ - /* Init IK Trees, etc. */ + /* Init pose, clear flags, etc. */ DEG_OPCODE_POSE_INIT, + /* Initialize IK solver related pose stuff. */ + DEG_OPCODE_POSE_INIT_IK, + /* Free IK Trees + Compute Deform Matrices */ DEG_OPCODE_POSE_DONE, @@ -220,9 +201,6 @@ typedef enum eDepsOperation_Code { /* Constraints */ DEG_OPCODE_BONE_CONSTRAINTS, - //DEG_OPCODE_BONE_CONSTRAINTS_INIT, - //DEG_OPCODE_BONE_CONSTRAINT, - //DEG_OPCODE_BONE_CONSTRAINTS_DONE, /* Bone transforms are ready * @@ -241,8 +219,13 @@ typedef enum eDepsOperation_Code { /* Particles --------------------------------------- */ /* XXX: placeholder - Particle System eval */ + DEG_OPCODE_PSYS_EVAL_INIT, DEG_OPCODE_PSYS_EVAL, + /* Masks ------------------------------------------- */ + DEG_OPCODE_MASK_ANIMATION, + DEG_OPCODE_MASK_EVAL, + DEG_NUM_OPCODES, } eDepsOperation_Code; @@ -258,83 +241,4 @@ protected: /* String defines for these opcodes, defined in depsgraph_type_defines.cpp */ extern DepsOperationStringifier DEG_OPNAMES; -/* Type of operation */ -typedef enum eDepsOperation_Type { - /* **** Primary operation types **** */ - - /* Initialise evaluation data */ - DEPSOP_TYPE_INIT = 0, - /* Standard evaluation step */ - DEPSOP_TYPE_EXEC = 1, - /* Cleanup evaluation data + flush results */ - DEPSOP_TYPE_POST = 2, - - /* **** Additional operation types **** */ - /* Indicator for outputting a temporary result that other components - * can use. // XXX? - */ - DEPSOP_TYPE_OUT = 3, - /* Indicator for things like IK Solvers and Rigidbody Sim steps which - * modify final results of separate entities at once. - */ - DEPSOP_TYPE_SIM = 4, - /* Rebuild internal evaluation data - used for Rigidbody Reset and - * Armature Rebuild-On-Load. - */ - DEPSOP_TYPE_REBUILD = 5, -} eDepsOperation_Type; - -/* Types of relationships between nodes - * - * This is used to provide additional hints to use when filtering - * the graph, so that we can go without doing more extensive - * data-level checks... - */ -typedef enum eDepsRelation_Type { - /* relationship type unknown/irrelevant */ - DEPSREL_TYPE_STANDARD = 0, - - /* root -> active scene or entity (screen, image, etc.) */ - DEPSREL_TYPE_ROOT_TO_ACTIVE, - - /* general datablock dependency */ - DEPSREL_TYPE_DATABLOCK, - - /* time dependency */ - DEPSREL_TYPE_TIME, - - /* component depends on results of another */ - DEPSREL_TYPE_COMPONENT_ORDER, - - /* relationship is just used to enforce ordering of operations - * (e.g. "init()" callback done before "exec() and "cleanup()") - */ - DEPSREL_TYPE_OPERATION, - - /* relationship results from a property driver affecting property */ - DEPSREL_TYPE_DRIVER, - - /* relationship is something driver depends on */ - DEPSREL_TYPE_DRIVER_TARGET, - - /* relationship is used for transform stack - * (e.g. parenting, user transforms, constraints) - */ - DEPSREL_TYPE_TRANSFORM, - - /* relationship is used for geometry evaluation - * (e.g. metaball "motherball" or modifiers) - */ - DEPSREL_TYPE_GEOMETRY_EVAL, - - /* relationship is used to trigger a post-change validity updates */ - DEPSREL_TYPE_UPDATE, - - /* relationship is used to trigger editor/screen updates */ - DEPSREL_TYPE_UPDATE_UI, - - /* cache dependency */ - DEPSREL_TYPE_CACHE, -} eDepsRelation_Type; - } // namespace DEG diff --git a/source/blender/depsgraph/intern/eval/deg_eval.cc b/source/blender/depsgraph/intern/eval/deg_eval.cc index e926f83bcbe..98b10718404 100644 --- a/source/blender/depsgraph/intern/eval/deg_eval.cc +++ b/source/blender/depsgraph/intern/eval/deg_eval.cc @@ -34,16 +34,16 @@ #include "PIL_time.h" -extern "C" { #include "BLI_utildefines.h" #include "BLI_task.h" #include "BLI_ghash.h" +extern "C" { #include "BKE_depsgraph.h" #include "BKE_global.h" +} /* extern "C" */ #include "DEG_depsgraph.h" -} /* extern "C" */ #include "atomic_ops.h" @@ -53,6 +53,7 @@ extern "C" { #include "intern/nodes/deg_node_component.h" #include "intern/nodes/deg_node_operation.h" #include "intern/depsgraph.h" +#include "intern/depsgraph_intern.h" #include "util/deg_util_foreach.h" /* Unfinished and unused, and takes quite some pre-processing time. */ @@ -94,105 +95,40 @@ static void deg_task_run_func(TaskPool *pool, /* Should only be the case for NOOPs, which never get to this point. */ BLI_assert(node->evaluate); - while (true) { - /* Get context. */ - /* TODO: Who initialises this? "Init" operations aren't able to - * initialise it!!! - */ - /* TODO(sergey): We don't use component contexts at this moment. */ - /* ComponentDepsNode *comp = node->owner; */ - BLI_assert(node->owner != NULL); - - /* Since we're not leaving the thread for until the graph branches it is - * possible to have NO-OP on the way. for which evaluate() will be NULL. - * but that's all fine, we'll just scheduler it's children. - */ - if (node->evaluate) { + /* Get context. */ + /* TODO: Who initialises this? "Init" operations aren't able to + * initialise it!!! + */ + /* TODO(sergey): We don't use component contexts at this moment. */ + /* ComponentDepsNode *comp = node->owner; */ + BLI_assert(node->owner != NULL); + + /* Since we're not leaving the thread for until the graph branches it is + * possible to have NO-OP on the way. for which evaluate() will be NULL. + * but that's all fine, we'll just scheduler it's children. + */ + if (node->evaluate) { /* Take note of current time. */ #ifdef USE_DEBUGGER - double start_time = PIL_check_seconds_timer(); - DepsgraphDebug::task_started(state->graph, node); + double start_time = PIL_check_seconds_timer(); + DepsgraphDebug::task_started(state->graph, node); #endif - /* Perform operation. */ - node->evaluate(state->eval_ctx); + /* Perform operation. */ + node->evaluate(state->eval_ctx); /* Note how long this took. */ #ifdef USE_DEBUGGER - double end_time = PIL_check_seconds_timer(); - DepsgraphDebug::task_completed(state->graph, - node, - end_time - start_time); + double end_time = PIL_check_seconds_timer(); + DepsgraphDebug::task_completed(state->graph, + node, + end_time - start_time); #endif - } - - /* If there's only one outgoing link we try to immediately switch to - * that node evaluation, without leaving the thread. - * - * It's only doable if the child don't have extra relations or all they - * are satisfied. - * - * TODO(sergey): Checks here can be de-duplicated with the ones from - * schedule_node(), however, how to do it nicely? - */ - if (node->outlinks.size() == 1) { - DepsRelation *rel = node->outlinks[0]; - OperationDepsNode *child = (OperationDepsNode *)rel->to; - BLI_assert(child->type == DEPSNODE_TYPE_OPERATION); - if (!child->scheduled) { - unsigned int id_layers = child->owner->owner->layers; - if (!((child->flag & DEPSOP_FLAG_NEEDS_UPDATE) != 0 && - (id_layers & state->layers) != 0)) - { - /* Node does not need an update, so can;t continue with the - * chain and need to switch to another one by leaving the - * thread. - */ - break; - } - if ((rel->flag & DEPSREL_FLAG_CYCLIC) == 0) { - BLI_assert(child->num_links_pending > 0); - atomic_sub_and_fetch_uint32(&child->num_links_pending, 1); - } - if (child->num_links_pending == 0) { - bool is_scheduled = atomic_fetch_and_or_uint8( - (uint8_t *)&child->scheduled, (uint8_t)true); - if (!is_scheduled) { - /* Node was not scheduled, switch to it! */ - node = child; - } - else { - /* Someone else scheduled the node, leaving us - * unemployed in this thread, we're leaving. - */ - break; - } - } - else { - /* There are other dependencies on the child, can't do - * anything in the current thread. - */ - break; - } - } - else { - /* Happens when having cyclic dependencies. - * - * Nothing to do here, single child was already scheduled, we - * can leave the thread now. - */ - break; - } - } - else { - /* TODO(sergey): It's possible to use one of the outgoing relations - * as a chain which we'll try to keep alive, but it's a bit more - * involved change. - */ - schedule_children(pool, state->graph, node, state->layers, thread_id); - break; - } } + + BLI_task_pool_delayed_push_begin(pool, thread_id); + schedule_children(pool, state->graph, node, state->layers, thread_id); + BLI_task_pool_delayed_push_end(pool, thread_id); } typedef struct CalculatePengindData { @@ -216,7 +152,7 @@ static void calculate_pending_func(void *data_v, int i) (node->flag & DEPSOP_FLAG_NEEDS_UPDATE) != 0) { foreach (DepsRelation *rel, node->inlinks) { - if (rel->from->type == DEPSNODE_TYPE_OPERATION && + if (rel->from->type == DEG_NODE_TYPE_OPERATION && (rel->flag & DEPSREL_FLAG_CYCLIC) == 0) { OperationDepsNode *from = (OperationDepsNode *)rel->from; @@ -261,7 +197,7 @@ static void calculate_eval_priority(OperationDepsNode *node) foreach (DepsRelation *rel, node->outlinks) { OperationDepsNode *to = (OperationDepsNode *)rel->to; - BLI_assert(to->type == DEPSNODE_TYPE_OPERATION); + BLI_assert(to->type == DEG_NODE_TYPE_OPERATION); calculate_eval_priority(to); node->eval_priority += to->eval_priority; } @@ -304,7 +240,7 @@ static void schedule_node(TaskPool *pool, Depsgraph *graph, unsigned int layers, deg_task_run_func, node, false, - TASK_PRIORITY_LOW, + TASK_PRIORITY_HIGH, thread_id); } } @@ -329,7 +265,7 @@ static void schedule_children(TaskPool *pool, { foreach (DepsRelation *rel, node->outlinks) { OperationDepsNode *child = (OperationDepsNode *)rel->to; - BLI_assert(child->type == DEPSNODE_TYPE_OPERATION); + BLI_assert(child->type == DEG_NODE_TYPE_OPERATION); if (child->scheduled) { /* Happens when having cyclic dependencies. */ continue; @@ -362,6 +298,11 @@ void deg_evaluate_on_refresh(EvaluationContext *eval_ctx, return; } + DEG_DEBUG_PRINTF("%s: layers:%u, graph->layers:%u\n", + __func__, + layers, + graph->layers); + /* Set time for the current graph evaluation context. */ TimeSourceDepsNode *time_src = graph->find_time_source(); eval_ctx->ctime = time_src->cfra; @@ -372,12 +313,19 @@ void deg_evaluate_on_refresh(EvaluationContext *eval_ctx, state.graph = graph; state.layers = layers; - TaskScheduler *task_scheduler = BLI_task_scheduler_get(); - TaskPool *task_pool = BLI_task_pool_create(task_scheduler, &state); + TaskScheduler *task_scheduler; + bool need_free_scheduler; if (G.debug & G_DEBUG_DEPSGRAPH_NO_THREADS) { - BLI_pool_set_num_threads(task_pool, 1); + task_scheduler = BLI_task_scheduler_create(1); + need_free_scheduler = true; } + else { + task_scheduler = BLI_task_scheduler_get(); + need_free_scheduler = false; + } + + TaskPool *task_pool = BLI_task_pool_create_suspended(task_scheduler, &state); calculate_pending_parents(graph, layers); @@ -404,6 +352,10 @@ void deg_evaluate_on_refresh(EvaluationContext *eval_ctx, /* Clear any uncleared tags - just in case. */ deg_graph_clear_tags(graph); + + if (need_free_scheduler) { + BLI_task_scheduler_free(task_scheduler); + } } } // namespace DEG diff --git a/source/blender/depsgraph/intern/eval/deg_eval_debug.cc b/source/blender/depsgraph/intern/eval/deg_eval_debug.cc index 060544a4407..23f4adbaacd 100644 --- a/source/blender/depsgraph/intern/eval/deg_eval_debug.cc +++ b/source/blender/depsgraph/intern/eval/deg_eval_debug.cc @@ -34,16 +34,16 @@ #include <cstring> /* required for STREQ later on. */ -extern "C" { #include "BLI_listbase.h" #include "BLI_ghash.h" -#include "DEG_depsgraph_debug.h" - +extern "C" { #include "WM_api.h" #include "WM_types.h" } /* extern "C" */ +#include "DEG_depsgraph_debug.h" + #include "intern/nodes/deg_node.h" #include "intern/nodes/deg_node_component.h" #include "intern/nodes/deg_node_operation.h" diff --git a/source/blender/depsgraph/intern/eval/deg_eval_flush.cc b/source/blender/depsgraph/intern/eval/deg_eval_flush.cc index 7c6c25bef0d..0adbadeebba 100644 --- a/source/blender/depsgraph/intern/eval/deg_eval_flush.cc +++ b/source/blender/depsgraph/intern/eval/deg_eval_flush.cc @@ -35,16 +35,16 @@ // TODO(sergey): Use some sort of wrapper. #include <deque> -extern "C" { -#include "DNA_object_types.h" - #include "BLI_utildefines.h" #include "BLI_task.h" #include "BLI_ghash.h" -#include "DEG_depsgraph.h" +extern "C" { +#include "DNA_object_types.h" } /* extern "C" */ +#include "DEG_depsgraph.h" + #include "intern/nodes/deg_node.h" #include "intern/nodes/deg_node_component.h" #include "intern/nodes/deg_node_operation.h" @@ -54,6 +54,12 @@ extern "C" { namespace DEG { +enum { + COMPONENT_STATE_NONE = 0, + COMPONENT_STATE_SCHEDULED = 1, + COMPONENT_STATE_DONE = 2, +}; + namespace { // TODO(sergey): De-duplicate with depsgraph_tag,cc @@ -83,7 +89,7 @@ static void flush_init_func(void *data_v, int i) ComponentDepsNode *comp_node = node->owner; IDDepsNode *id_node = comp_node->owner; id_node->done = 0; - comp_node->done = 0; + comp_node->done = COMPONENT_STATE_NONE; node->scheduled = false; } @@ -139,18 +145,18 @@ void deg_graph_flush_updates(Main *bmain, Depsgraph *graph) IDDepsNode *id_node = comp_node->owner; ID *id = id_node->id; - if(id_node->done == 0) { + if (id_node->done == 0) { deg_editors_id_update(bmain, id); lib_id_recalc_tag(bmain, id); /* TODO(sergey): For until we've got proper data nodes in the graph. */ lib_id_recalc_data_tag(bmain, id); } - if(comp_node->done == 0) { + if (comp_node->done != COMPONENT_STATE_DONE) { Object *object = NULL; if (GS(id->name) == ID_OB) { object = (Object *)id; - if(id_node->done == 0) { + if (id_node->done == 0) { ++num_flushed_objects; } } @@ -164,22 +170,55 @@ void deg_graph_flush_updates(Main *bmain, Depsgraph *graph) * Plus it ensures visibility changes and relations and * layers visibility update has proper flags to work with. */ - if (comp_node->type == DEPSNODE_TYPE_ANIMATION) { - object->recalc |= OB_RECALC_TIME; + switch (comp_node->type) { + case DEG_NODE_TYPE_UNDEFINED: + case DEG_NODE_TYPE_OPERATION: + case DEG_NODE_TYPE_TIMESOURCE: + case DEG_NODE_TYPE_ID_REF: + case DEG_NODE_TYPE_PARAMETERS: + case DEG_NODE_TYPE_SEQUENCER: + /* Ignore, does not translate to object component. */ + break; + case DEG_NODE_TYPE_ANIMATION: + object->recalc |= OB_RECALC_TIME; + break; + case DEG_NODE_TYPE_TRANSFORM: + object->recalc |= OB_RECALC_OB; + break; + case DEG_NODE_TYPE_GEOMETRY: + case DEG_NODE_TYPE_EVAL_POSE: + case DEG_NODE_TYPE_BONE: + case DEG_NODE_TYPE_EVAL_PARTICLES: + case DEG_NODE_TYPE_SHADING: + case DEG_NODE_TYPE_CACHE: + case DEG_NODE_TYPE_PROXY: + object->recalc |= OB_RECALC_DATA; + break; } - else if (comp_node->type == DEPSNODE_TYPE_TRANSFORM) { - object->recalc |= OB_RECALC_OB; - } - else { - object->recalc |= OB_RECALC_DATA; + } + /* When some target changes bone, we might need to re-run the + * whole IK solver, otherwise result might be unpredictable. + */ + if (comp_node->type == DEG_NODE_TYPE_BONE) { + ComponentDepsNode *pose_comp = + id_node->find_component(DEG_NODE_TYPE_EVAL_POSE); + BLI_assert(pose_comp != NULL); + if (pose_comp->done == COMPONENT_STATE_NONE) { + queue.push_front(pose_comp->get_entry_operation()); + pose_comp->done = COMPONENT_STATE_SCHEDULED; } } } id_node->done = 1; - comp_node->done = 1; + comp_node->done = COMPONENT_STATE_DONE; /* Flush to nodes along links... */ + /* TODO(sergey): This is mainly giving speedup due ot less queue pushes, which + * reduces number of memory allocations. + * + * We should try solve the allocation issue instead of doing crazy things here. + */ if (node->outlinks.size() == 1) { OperationDepsNode *to_node = (OperationDepsNode *)node->outlinks[0]->to; if (to_node->scheduled == false) { diff --git a/source/blender/depsgraph/intern/nodes/deg_node.cc b/source/blender/depsgraph/intern/nodes/deg_node.cc index 57b25c10670..a15317586c1 100644 --- a/source/blender/depsgraph/intern/nodes/deg_node.cc +++ b/source/blender/depsgraph/intern/nodes/deg_node.cc @@ -41,15 +41,14 @@ extern "C" { #include "DNA_anim_types.h" #include "BKE_animsys.h" +} #include "DEG_depsgraph.h" -} #include "intern/nodes/deg_node_component.h" #include "intern/nodes/deg_node_operation.h" #include "intern/depsgraph_intern.h" #include "util/deg_util_foreach.h" -#include "util/deg_util_hash.h" namespace DEG { @@ -61,12 +60,12 @@ namespace DEG { DepsNode::TypeInfo::TypeInfo(eDepsNode_Type type, const char *tname) { this->type = type; - if (type == DEPSNODE_TYPE_OPERATION) - this->tclass = DEPSNODE_CLASS_OPERATION; - else if (type < DEPSNODE_TYPE_PARAMETERS) - this->tclass = DEPSNODE_CLASS_GENERIC; + if (type == DEG_NODE_TYPE_OPERATION) + this->tclass = DEG_NODE_CLASS_OPERATION; + else if (type < DEG_NODE_TYPE_PARAMETERS) + this->tclass = DEG_NODE_CLASS_GENERIC; else - this->tclass = DEPSNODE_CLASS_COMPONENT; + this->tclass = DEG_NODE_CLASS_COMPONENT; this->tname = tname; } @@ -110,34 +109,9 @@ void TimeSourceDepsNode::tag_update(Depsgraph *graph) } } - -/* Root Node ============================================== */ - -RootDepsNode::RootDepsNode() : scene(NULL), time_source(NULL) -{ -} - -RootDepsNode::~RootDepsNode() -{ - OBJECT_GUARDED_DELETE(time_source, TimeSourceDepsNode); -} - -TimeSourceDepsNode *RootDepsNode::add_time_source(const char *name) -{ - if (!time_source) { - DepsNodeFactory *factory = deg_get_node_factory(DEPSNODE_TYPE_TIMESOURCE); - time_source = (TimeSourceDepsNode *)factory->create_node(NULL, "", name); - /*time_source->owner = this;*/ // XXX - } - return time_source; -} - -DEG_DEPSNODE_DEFINE(RootDepsNode, DEPSNODE_TYPE_ROOT, "Root DepsNode"); -static DepsNodeFactoryImpl<RootDepsNode> DNTI_ROOT; - /* Time Source Node ======================================= */ -DEG_DEPSNODE_DEFINE(TimeSourceDepsNode, DEPSNODE_TYPE_TIMESOURCE, "Time Source"); +DEG_DEPSNODE_DEFINE(TimeSourceDepsNode, DEG_NODE_TYPE_TIMESOURCE, "Time Source"); static DepsNodeFactoryImpl<TimeSourceDepsNode> DNTI_TIMESOURCE; /* ID Node ================================================ */ @@ -158,8 +132,8 @@ static unsigned int id_deps_node_hash_key(const void *key_v) { const IDDepsNode::ComponentIDKey *key = reinterpret_cast<const IDDepsNode::ComponentIDKey *>(key_v); - return hash_combine(BLI_ghashutil_uinthash(key->type), - BLI_ghashutil_strhash_p(key->name)); + return BLI_ghashutil_combine_hash(BLI_ghashutil_uinthash(key->type), + BLI_ghashutil_strhash_p(key->name)); } static bool id_deps_node_hash_key_cmp(const void *a, const void *b) @@ -211,8 +185,9 @@ void IDDepsNode::init(const ID *id, const char *UNUSED(subdata)) /* Free 'id' node. */ IDDepsNode::~IDDepsNode() { - clear_components(); - BLI_ghash_free(components, id_deps_node_hash_key_free, NULL); + BLI_ghash_free(components, + id_deps_node_hash_key_free, + id_deps_node_hash_value_free); } ComponentDepsNode *IDDepsNode::find_component(eDepsNode_Type type, @@ -238,33 +213,13 @@ ComponentDepsNode *IDDepsNode::add_component(eDepsNode_Type type, return comp_node; } -void IDDepsNode::remove_component(eDepsNode_Type type, const char *name) -{ - ComponentDepsNode *comp_node = find_component(type, name); - if (comp_node) { - /* Unregister. */ - ComponentIDKey key(type, name); - BLI_ghash_remove(components, - &key, - id_deps_node_hash_key_free, - id_deps_node_hash_value_free); - } -} - -void IDDepsNode::clear_components() -{ - BLI_ghash_clear(components, - id_deps_node_hash_key_free, - id_deps_node_hash_value_free); -} - void IDDepsNode::tag_update(Depsgraph *graph) { GHASH_FOREACH_BEGIN(ComponentDepsNode *, comp_node, components) { /* TODO(sergey): What about drievrs? */ - bool do_component_tag = comp_node->type != DEPSNODE_TYPE_ANIMATION; - if (comp_node->type == DEPSNODE_TYPE_ANIMATION) { + bool do_component_tag = comp_node->type != DEG_NODE_TYPE_ANIMATION; + if (comp_node->type == DEG_NODE_TYPE_ANIMATION) { AnimData *adt = BKE_animdata_from_id(id); /* Animation data might be null if relations are tagged for update. */ if (adt != NULL && (adt->recalc & ADT_RECALC_ANIM)) { @@ -287,46 +242,13 @@ void IDDepsNode::finalize_build() GHASH_FOREACH_END(); } -DEG_DEPSNODE_DEFINE(IDDepsNode, DEPSNODE_TYPE_ID_REF, "ID Node"); +DEG_DEPSNODE_DEFINE(IDDepsNode, DEG_NODE_TYPE_ID_REF, "ID Node"); static DepsNodeFactoryImpl<IDDepsNode> DNTI_ID_REF; -/* Subgraph Node ========================================== */ - -/* Initialize 'subgraph' node - from pointer data given. */ -void SubgraphDepsNode::init(const ID *id, const char *UNUSED(subdata)) -{ - /* Store ID-ref if provided. */ - this->root_id = (ID *)id; - - /* NOTE: graph will need to be added manually, - * as we don't have any way of passing this down. - */ -} - -/* Free 'subgraph' node */ -SubgraphDepsNode::~SubgraphDepsNode() -{ - /* Only free if graph not shared, of if this node is the first - * reference to it... - */ - // XXX: prune these flags a bit... - if ((this->flag & SUBGRAPH_FLAG_FIRSTREF) || !(this->flag & SUBGRAPH_FLAG_SHARED)) { - /* Free the referenced graph. */ - DEG_graph_free(reinterpret_cast< ::Depsgraph* >(graph)); - graph = NULL; - } -} - -DEG_DEPSNODE_DEFINE(SubgraphDepsNode, DEPSNODE_TYPE_SUBGRAPH, "Subgraph Node"); -static DepsNodeFactoryImpl<SubgraphDepsNode> DNTI_SUBGRAPH; - void deg_register_base_depsnodes() { - deg_register_node_typeinfo(&DNTI_ROOT); deg_register_node_typeinfo(&DNTI_TIMESOURCE); - deg_register_node_typeinfo(&DNTI_ID_REF); - deg_register_node_typeinfo(&DNTI_SUBGRAPH); } } // namespace DEG diff --git a/source/blender/depsgraph/intern/nodes/deg_node.h b/source/blender/depsgraph/intern/nodes/deg_node.h index 7c2f53840b6..9f1b61faf24 100644 --- a/source/blender/depsgraph/intern/nodes/deg_node.h +++ b/source/blender/depsgraph/intern/nodes/deg_node.h @@ -127,22 +127,6 @@ struct TimeSourceDepsNode : public DepsNode { DEG_DEPSNODE_DECLARE; }; -/* Root Node. */ -struct RootDepsNode : public DepsNode { - RootDepsNode(); - ~RootDepsNode(); - - TimeSourceDepsNode *add_time_source(const char *name = ""); - - /* scene that this corresponds to */ - Scene *scene; - - /* Entrypoint node for time-changed. */ - TimeSourceDepsNode *time_source; - - DEG_DEPSNODE_DECLARE; -}; - /* ID-Block Reference */ struct IDDepsNode : public DepsNode { struct ComponentIDKey { @@ -160,8 +144,6 @@ struct IDDepsNode : public DepsNode { const char *name = "") const; ComponentDepsNode *add_component(eDepsNode_Type type, const char *name = ""); - void remove_component(eDepsNode_Type type, const char *name = ""); - void clear_components(); void tag_update(Depsgraph *graph); @@ -185,41 +167,6 @@ struct IDDepsNode : public DepsNode { DEG_DEPSNODE_DECLARE; }; -/* Subgraph Reference. */ -struct SubgraphDepsNode : public DepsNode { - void init(const ID *id, const char *subdata); - ~SubgraphDepsNode(); - - /* Instanced graph. */ - Depsgraph *graph; - - /* ID-block at root of subgraph (if applicable). */ - ID *root_id; - - /* Number of nodes which use/reference this subgraph - if just 1, it may be - * possible to merge into main, - */ - size_t num_users; - - /* (eSubgraphRef_Flag) assorted settings for subgraph node. */ - int flag; - - DEG_DEPSNODE_DECLARE; -}; - -/* Flags for subgraph node */ -typedef enum eSubgraphRef_Flag { - /* Subgraph referenced is shared with another reference, so shouldn't - * free on exit. - */ - SUBGRAPH_FLAG_SHARED = (1 << 0), - - /* Node is first reference to subgraph, so it can be freed when we are - * removed. - */ - SUBGRAPH_FLAG_FIRSTREF = (1 << 1), -} eSubgraphRef_Flag; - void deg_register_base_depsnodes(); } // namespace DEG diff --git a/source/blender/depsgraph/intern/nodes/deg_node_component.cc b/source/blender/depsgraph/intern/nodes/deg_node_component.cc index 06f91ac7fdc..e87c87813e3 100644 --- a/source/blender/depsgraph/intern/nodes/deg_node_component.cc +++ b/source/blender/depsgraph/intern/nodes/deg_node_component.cc @@ -33,9 +33,10 @@ #include <stdio.h> #include <cstring> /* required for STREQ later on. */ -extern "C" { #include "BLI_utildefines.h" +#include "BLI_ghash.h" +extern "C" { #include "DNA_object_types.h" #include "BKE_action.h" @@ -44,7 +45,6 @@ extern "C" { #include "intern/nodes/deg_node_operation.h" #include "intern/depsgraph_intern.h" #include "util/deg_util_foreach.h" -#include "util/deg_util_hash.h" namespace DEG { @@ -95,8 +95,8 @@ static unsigned int comp_node_hash_key(const void *key_v) { const ComponentDepsNode::OperationIDKey *key = reinterpret_cast<const ComponentDepsNode::OperationIDKey *>(key_v); - return hash_combine(BLI_ghashutil_uinthash(key->opcode), - BLI_ghashutil_strhash_p(key->name)); + return BLI_ghashutil_combine_hash(BLI_ghashutil_uinthash(key->opcode), + BLI_ghashutil_strhash_p(key->name)); } static bool comp_node_hash_key_cmp(const void *a, const void *b) @@ -198,32 +198,20 @@ OperationDepsNode *ComponentDepsNode::has_operation(eDepsOperation_Code opcode, return has_operation(key); } -OperationDepsNode *ComponentDepsNode::add_operation(eDepsOperation_Type optype, - DepsEvalOperationCb op, +OperationDepsNode *ComponentDepsNode::add_operation(const DepsEvalOperationCb& op, eDepsOperation_Code opcode, const char *name, int name_tag) { OperationDepsNode *op_node = has_operation(opcode, name, name_tag); if (!op_node) { - DepsNodeFactory *factory = deg_get_node_factory(DEPSNODE_TYPE_OPERATION); + DepsNodeFactory *factory = deg_get_node_factory(DEG_NODE_TYPE_OPERATION); op_node = (OperationDepsNode *)factory->create_node(this->owner->id, "", name); /* register opnode in this component's operation set */ OperationIDKey *key = OBJECT_GUARDED_NEW(OperationIDKey, opcode, name, name_tag); BLI_ghash_insert(operations_map, key, op_node); - /* set as entry/exit node of component (if appropriate) */ - if (optype == DEPSOP_TYPE_INIT) { - BLI_assert(this->entry_operation == NULL); - this->entry_operation = op_node; - } - else if (optype == DEPSOP_TYPE_POST) { - // XXX: review whether DEPSOP_TYPE_OUT is better than DEPSOP_TYPE_POST, or maybe have both? - BLI_assert(this->exit_operation == NULL); - this->exit_operation = op_node; - } - /* set backlink */ op_node->owner = this; } @@ -235,13 +223,24 @@ OperationDepsNode *ComponentDepsNode::add_operation(eDepsOperation_Type optype, /* attach extra data */ op_node->evaluate = op; - op_node->optype = optype; op_node->opcode = opcode; op_node->name = name; return op_node; } +void ComponentDepsNode::set_entry_operation(OperationDepsNode *op_node) +{ + BLI_assert(entry_operation == NULL); + entry_operation = op_node; +} + +void ComponentDepsNode::set_exit_operation(OperationDepsNode *op_node) +{ + BLI_assert(exit_operation == NULL); + exit_operation = op_node; +} + void ComponentDepsNode::clear_operations() { if (operations_map != NULL) { @@ -336,37 +335,37 @@ void ComponentDepsNode::finalize_build() /* Parameter Component Defines ============================ */ -DEG_DEPSNODE_DEFINE(ParametersComponentDepsNode, DEPSNODE_TYPE_PARAMETERS, "Parameters Component"); +DEG_DEPSNODE_DEFINE(ParametersComponentDepsNode, DEG_NODE_TYPE_PARAMETERS, "Parameters Component"); static DepsNodeFactoryImpl<ParametersComponentDepsNode> DNTI_PARAMETERS; /* Animation Component Defines ============================ */ -DEG_DEPSNODE_DEFINE(AnimationComponentDepsNode, DEPSNODE_TYPE_ANIMATION, "Animation Component"); +DEG_DEPSNODE_DEFINE(AnimationComponentDepsNode, DEG_NODE_TYPE_ANIMATION, "Animation Component"); static DepsNodeFactoryImpl<AnimationComponentDepsNode> DNTI_ANIMATION; /* Transform Component Defines ============================ */ -DEG_DEPSNODE_DEFINE(TransformComponentDepsNode, DEPSNODE_TYPE_TRANSFORM, "Transform Component"); +DEG_DEPSNODE_DEFINE(TransformComponentDepsNode, DEG_NODE_TYPE_TRANSFORM, "Transform Component"); static DepsNodeFactoryImpl<TransformComponentDepsNode> DNTI_TRANSFORM; /* Proxy Component Defines ================================ */ -DEG_DEPSNODE_DEFINE(ProxyComponentDepsNode, DEPSNODE_TYPE_PROXY, "Proxy Component"); +DEG_DEPSNODE_DEFINE(ProxyComponentDepsNode, DEG_NODE_TYPE_PROXY, "Proxy Component"); static DepsNodeFactoryImpl<ProxyComponentDepsNode> DNTI_PROXY; /* Geometry Component Defines ============================= */ -DEG_DEPSNODE_DEFINE(GeometryComponentDepsNode, DEPSNODE_TYPE_GEOMETRY, "Geometry Component"); +DEG_DEPSNODE_DEFINE(GeometryComponentDepsNode, DEG_NODE_TYPE_GEOMETRY, "Geometry Component"); static DepsNodeFactoryImpl<GeometryComponentDepsNode> DNTI_GEOMETRY; /* Sequencer Component Defines ============================ */ -DEG_DEPSNODE_DEFINE(SequencerComponentDepsNode, DEPSNODE_TYPE_SEQUENCER, "Sequencer Component"); +DEG_DEPSNODE_DEFINE(SequencerComponentDepsNode, DEG_NODE_TYPE_SEQUENCER, "Sequencer Component"); static DepsNodeFactoryImpl<SequencerComponentDepsNode> DNTI_SEQUENCER; /* Pose Component ========================================= */ -DEG_DEPSNODE_DEFINE(PoseComponentDepsNode, DEPSNODE_TYPE_EVAL_POSE, "Pose Eval Component"); +DEG_DEPSNODE_DEFINE(PoseComponentDepsNode, DEG_NODE_TYPE_EVAL_POSE, "Pose Eval Component"); static DepsNodeFactoryImpl<PoseComponentDepsNode> DNTI_EVAL_POSE; /* Bone Component ========================================= */ @@ -388,22 +387,22 @@ void BoneComponentDepsNode::init(const ID *id, const char *subdata) this->pchan = BKE_pose_channel_find_name(ob->pose, subdata); } -DEG_DEPSNODE_DEFINE(BoneComponentDepsNode, DEPSNODE_TYPE_BONE, "Bone Component"); +DEG_DEPSNODE_DEFINE(BoneComponentDepsNode, DEG_NODE_TYPE_BONE, "Bone Component"); static DepsNodeFactoryImpl<BoneComponentDepsNode> DNTI_BONE; /* Particles Component Defines ============================ */ -DEG_DEPSNODE_DEFINE(ParticlesComponentDepsNode, DEPSNODE_TYPE_EVAL_PARTICLES, "Particles Component"); +DEG_DEPSNODE_DEFINE(ParticlesComponentDepsNode, DEG_NODE_TYPE_EVAL_PARTICLES, "Particles Component"); static DepsNodeFactoryImpl<ParticlesComponentDepsNode> DNTI_EVAL_PARTICLES; /* Shading Component Defines ============================ */ -DEG_DEPSNODE_DEFINE(ShadingComponentDepsNode, DEPSNODE_TYPE_SHADING, "Shading Component"); +DEG_DEPSNODE_DEFINE(ShadingComponentDepsNode, DEG_NODE_TYPE_SHADING, "Shading Component"); static DepsNodeFactoryImpl<ShadingComponentDepsNode> DNTI_SHADING; /* Cache Component Defines ============================ */ -DEG_DEPSNODE_DEFINE(CacheComponentDepsNode, DEPSNODE_TYPE_CACHE, "Cache Component"); +DEG_DEPSNODE_DEFINE(CacheComponentDepsNode, DEG_NODE_TYPE_CACHE, "Cache Component"); static DepsNodeFactoryImpl<CacheComponentDepsNode> DNTI_CACHE; diff --git a/source/blender/depsgraph/intern/nodes/deg_node_component.h b/source/blender/depsgraph/intern/nodes/deg_node_component.h index 969771a29c9..4ef7dad3ac6 100644 --- a/source/blender/depsgraph/intern/nodes/deg_node_component.h +++ b/source/blender/depsgraph/intern/nodes/deg_node_component.h @@ -99,12 +99,18 @@ struct ComponentDepsNode : public DepsNode { * \param op: The operation to perform * \param name: Identifier for operation - used to find/locate it again */ - OperationDepsNode *add_operation(eDepsOperation_Type optype, - DepsEvalOperationCb op, + OperationDepsNode *add_operation(const DepsEvalOperationCb& op, eDepsOperation_Code opcode, const char *name, int name_tag); + /* Entry/exit operations management. + * + * Use those instead of direct set since this will perform sanity checks. + */ + void set_entry_operation(OperationDepsNode *op_node); + void set_exit_operation(OperationDepsNode *op_node); + void clear_operations(); void tag_update(Depsgraph *graph); diff --git a/source/blender/depsgraph/intern/nodes/deg_node_operation.cc b/source/blender/depsgraph/intern/nodes/deg_node_operation.cc index 9eed4dfe8d8..7467264f612 100644 --- a/source/blender/depsgraph/intern/nodes/deg_node_operation.cc +++ b/source/blender/depsgraph/intern/nodes/deg_node_operation.cc @@ -32,13 +32,11 @@ #include "MEM_guardedalloc.h" -extern "C" { #include "BLI_utildefines.h" -} /* extern "C" */ +#include "BLI_ghash.h" #include "intern/depsgraph.h" #include "intern/depsgraph_intern.h" -#include "util/deg_util_hash.h" namespace DEG { @@ -67,7 +65,7 @@ string OperationDepsNode::identifier() const string OperationDepsNode::full_identifier() const { string owner_str = ""; - if (owner->type == DEPSNODE_TYPE_BONE) { + if (owner->type == DEG_NODE_TYPE_BONE) { owner_str = string(owner->owner->name) + "." + owner->name; } else { @@ -86,7 +84,19 @@ void OperationDepsNode::tag_update(Depsgraph *graph) graph->add_entry_tag(this); } -DEG_DEPSNODE_DEFINE(OperationDepsNode, DEPSNODE_TYPE_OPERATION, "Operation"); +void OperationDepsNode::set_as_entry() +{ + BLI_assert(owner != NULL); + owner->set_entry_operation(this); +} + +void OperationDepsNode::set_as_exit() +{ + BLI_assert(owner != NULL); + owner->set_exit_operation(this); +} + +DEG_DEPSNODE_DEFINE(OperationDepsNode, DEG_NODE_TYPE_OPERATION, "Operation"); static DepsNodeFactoryImpl<OperationDepsNode> DNTI_OPERATION; void deg_register_operation_depsnodes() diff --git a/source/blender/depsgraph/intern/nodes/deg_node_operation.h b/source/blender/depsgraph/intern/nodes/deg_node_operation.h index 598393054db..1e5c3832d03 100644 --- a/source/blender/depsgraph/intern/nodes/deg_node_operation.h +++ b/source/blender/depsgraph/intern/nodes/deg_node_operation.h @@ -44,9 +44,6 @@ typedef enum eDepsOperation_Flag { DEPSOP_FLAG_NEEDS_UPDATE = (1 << 0), /* node was directly modified, causing need for update */ - /* XXX: intention is to make it easier to tell when we just need to - * take subgraphs. - */ DEPSOP_FLAG_DIRECTLY_MODIFIED = (1 << 1), /* Operation is evaluated using CPython; has GIL and security @@ -57,8 +54,6 @@ typedef enum eDepsOperation_Flag { /* Atomic Operation - Base type for all operations */ struct OperationDepsNode : public DepsNode { - - OperationDepsNode(); ~OperationDepsNode(); @@ -72,21 +67,21 @@ struct OperationDepsNode : public DepsNode { OperationDepsNode *get_entry_operation() { return this; } OperationDepsNode *get_exit_operation() { return this; } + /* Set this operation as compoonent's entry/exit operation. */ + void set_as_entry(); + void set_as_exit(); + /* Component that contains the operation. */ ComponentDepsNode *owner; /* Callback for operation. */ DepsEvalOperationCb evaluate; - /* How many inlinks are we still waiting on before we can be evaluated. */ uint32_t num_links_pending; float eval_priority; bool scheduled; - /* Stage of evaluation */ - eDepsOperation_Type optype; - /* Identifier for the operation being performed. */ eDepsOperation_Code opcode; |