diff options
Diffstat (limited to 'source/blender/depsgraph/intern/nodes')
6 files changed, 65 insertions, 183 deletions
diff --git a/source/blender/depsgraph/intern/nodes/deg_node.cc b/source/blender/depsgraph/intern/nodes/deg_node.cc index b1d5b538e25..a15317586c1 100644 --- a/source/blender/depsgraph/intern/nodes/deg_node.cc +++ b/source/blender/depsgraph/intern/nodes/deg_node.cc @@ -41,9 +41,9 @@ 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" @@ -60,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; } @@ -109,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 ================================================ */ @@ -210,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, @@ -237,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)) { @@ -286,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 136c66b9516..e87c87813e3 100644 --- a/source/blender/depsgraph/intern/nodes/deg_node_component.cc +++ b/source/blender/depsgraph/intern/nodes/deg_node_component.cc @@ -33,10 +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" @@ -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 cbf397bc7a9..7467264f612 100644 --- a/source/blender/depsgraph/intern/nodes/deg_node_operation.cc +++ b/source/blender/depsgraph/intern/nodes/deg_node_operation.cc @@ -65,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 { @@ -84,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; |