From c89e103348414feb3396c7b10abb594c77d8c333 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Fri, 24 Jan 2020 11:11:38 +0100 Subject: Depsgrapg: Refactor, move Relation to own file --- source/blender/depsgraph/CMakeLists.txt | 2 + .../depsgraph/intern/builder/deg_builder.cc | 1 + .../depsgraph/intern/builder/deg_builder_cycle.cc | 1 + .../intern/builder/deg_builder_relations.cc | 1 + .../intern/builder/deg_builder_relations_rig.cc | 1 + .../intern/builder/deg_builder_transitive.cc | 1 + .../intern/debug/deg_debug_relations_graphviz.cc | 2 + source/blender/depsgraph/intern/depsgraph.cc | 38 +---------- source/blender/depsgraph/intern/depsgraph.h | 40 +----------- source/blender/depsgraph/intern/depsgraph_build.cc | 1 + source/blender/depsgraph/intern/depsgraph_debug.cc | 1 + .../depsgraph/intern/depsgraph_query_foreach.cc | 1 + .../blender/depsgraph/intern/depsgraph_relation.cc | 73 ++++++++++++++++++++++ .../blender/depsgraph/intern/depsgraph_relation.h | 63 +++++++++++++++++++ source/blender/depsgraph/intern/eval/deg_eval.cc | 1 + .../depsgraph/intern/eval/deg_eval_flush.cc | 1 + source/blender/depsgraph/intern/node/deg_node.cc | 1 + .../blender/depsgraph/intern/node/deg_node_time.cc | 1 + 18 files changed, 154 insertions(+), 76 deletions(-) create mode 100644 source/blender/depsgraph/intern/depsgraph_relation.cc create mode 100644 source/blender/depsgraph/intern/depsgraph_relation.h (limited to 'source') diff --git a/source/blender/depsgraph/CMakeLists.txt b/source/blender/depsgraph/CMakeLists.txt index 7f3c7d5043f..f98b4caf08e 100644 --- a/source/blender/depsgraph/CMakeLists.txt +++ b/source/blender/depsgraph/CMakeLists.txt @@ -83,6 +83,7 @@ set(SRC intern/depsgraph_query.cc intern/depsgraph_query_foreach.cc intern/depsgraph_query_iter.cc + intern/depsgraph_relation.cc intern/depsgraph_registry.cc intern/depsgraph_tag.cc intern/depsgraph_type.cc @@ -129,6 +130,7 @@ set(SRC intern/depsgraph.h intern/depsgraph_physics.h intern/depsgraph_registry.h + intern/depsgraph_relation.h intern/depsgraph_tag.h intern/depsgraph_type.h intern/depsgraph_update.h diff --git a/source/blender/depsgraph/intern/builder/deg_builder.cc b/source/blender/depsgraph/intern/builder/deg_builder.cc index fb7104e7556..440d9dd07f6 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder.cc +++ b/source/blender/depsgraph/intern/builder/deg_builder.cc @@ -42,6 +42,7 @@ extern "C" { } #include "intern/depsgraph.h" +#include "intern/depsgraph_relation.h" #include "intern/depsgraph_tag.h" #include "intern/depsgraph_type.h" #include "intern/builder/deg_builder_cache.h" diff --git a/source/blender/depsgraph/intern/builder/deg_builder_cycle.cc b/source/blender/depsgraph/intern/builder/deg_builder_cycle.cc index bea59eceea2..f18583beb9c 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder_cycle.cc +++ b/source/blender/depsgraph/intern/builder/deg_builder_cycle.cc @@ -35,6 +35,7 @@ #include "intern/node/deg_node_operation.h" #include "intern/depsgraph.h" +#include "intern/depsgraph_relation.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 bc428dd755f..bc441676c86 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder_relations.cc +++ b/source/blender/depsgraph/intern/builder/deg_builder_relations.cc @@ -114,6 +114,7 @@ extern "C" { #include "intern/node/deg_node_operation.h" #include "intern/node/deg_node_time.h" +#include "intern/depsgraph_relation.h" #include "intern/depsgraph_type.h" namespace DEG { 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 e254f8df0d2..484a4d828e3 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder_relations_rig.cc +++ b/source/blender/depsgraph/intern/builder/deg_builder_relations_rig.cc @@ -58,6 +58,7 @@ extern "C" { #include "intern/node/deg_node_operation.h" #include "intern/depsgraph_type.h" +#include "intern/depsgraph_relation.h" namespace DEG { diff --git a/source/blender/depsgraph/intern/builder/deg_builder_transitive.cc b/source/blender/depsgraph/intern/builder/deg_builder_transitive.cc index 13cf8e63832..fc7c546e294 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder_transitive.cc +++ b/source/blender/depsgraph/intern/builder/deg_builder_transitive.cc @@ -30,6 +30,7 @@ #include "intern/node/deg_node_operation.h" #include "intern/depsgraph.h" +#include "intern/depsgraph_relation.h" #include "intern/debug/deg_debug.h" namespace DEG { diff --git a/source/blender/depsgraph/intern/debug/deg_debug_relations_graphviz.cc b/source/blender/depsgraph/intern/debug/deg_debug_relations_graphviz.cc index ee3959a0861..45d15c230d7 100644 --- a/source/blender/depsgraph/intern/debug/deg_debug_relations_graphviz.cc +++ b/source/blender/depsgraph/intern/debug/deg_debug_relations_graphviz.cc @@ -36,6 +36,8 @@ extern "C" { #include "DEG_depsgraph_debug.h" #include "intern/depsgraph.h" +#include "intern/depsgraph_relation.h" + #include "intern/node/deg_node_component.h" #include "intern/node/deg_node_id.h" #include "intern/node/deg_node_operation.h" diff --git a/source/blender/depsgraph/intern/depsgraph.cc b/source/blender/depsgraph/intern/depsgraph.cc index 190ff4e929f..0e929f4e8b6 100644 --- a/source/blender/depsgraph/intern/depsgraph.cc +++ b/source/blender/depsgraph/intern/depsgraph.cc @@ -46,6 +46,7 @@ extern "C" { #include "intern/depsgraph_update.h" #include "intern/depsgraph_physics.h" +#include "intern/depsgraph_relation.h" #include "intern/depsgraph_registry.h" #include "intern/eval/deg_eval_copy_on_write.h" @@ -220,43 +221,6 @@ Relation *Depsgraph::check_nodes_connected(const Node *from, return NULL; } -/* ************************ */ -/* Relationships Management */ - -Relation::Relation(Node *from, Node *to, const char *description) - : from(from), to(to), name(description), flag(0) -{ - /* Hook it up to the nodes which use it. - * - * NOTE: We register relation in the nodes which this link connects to here - * in constructor but we don't unregister it in the destructor. - * - * Reasoning: - * - * - Destructor is currently used on global graph destruction, so there's no - * real need in avoiding dangling pointers, all the memory is to be freed - * anyway. - * - * - Unregistering relation is not a cheap operation, so better to have it - * as an explicit call if we need this. */ - from->outlinks.push_back(this); - to->inlinks.push_back(this); -} - -Relation::~Relation() -{ - /* Sanity check. */ - BLI_assert(from != NULL && to != NULL); -} - -void Relation::unlink() -{ - /* Sanity check. */ - BLI_assert(from != NULL && to != NULL); - remove_from_vector(&from->outlinks, this); - remove_from_vector(&to->inlinks, this); -} - /* Low level tagging -------------------------------------- */ /* Tag a specific node as needing updates. */ diff --git a/source/blender/depsgraph/intern/depsgraph.h b/source/blender/depsgraph/intern/depsgraph.h index 71603334530..89c5af9c798 100644 --- a/source/blender/depsgraph/intern/depsgraph.h +++ b/source/blender/depsgraph/intern/depsgraph.h @@ -53,47 +53,9 @@ namespace DEG { struct IDNode; struct Node; struct OperationNode; +struct Relation; struct TimeSourceNode; -/* *************************** */ -/* Relationships Between Nodes */ - -/* Settings/Tags on Relationship. - * NOTE: Is a bitmask, allowing accumulation. */ -enum RelationFlag { - /* "cyclic" link - when detecting cycles, this relationship was the one - * which triggers a cyclic relationship to exist in the graph. */ - RELATION_FLAG_CYCLIC = (1 << 0), - /* Update flush will not go through this relation. */ - RELATION_FLAG_NO_FLUSH = (1 << 1), - /* Only flush along the relation is update comes from a node which was - * affected by user input. */ - RELATION_FLAG_FLUSH_USER_EDIT_ONLY = (1 << 2), - /* The relation can not be killed by the cyclic dependencies solver. */ - RELATION_FLAG_GODMODE = (1 << 4), - /* Relation will check existence before being added. */ - RELATION_CHECK_BEFORE_ADD = (1 << 5), -}; - -/* B depends on A (A -> B) */ -struct Relation { - Relation(Node *from, Node *to, const char *description); - ~Relation(); - - void unlink(); - - /* the nodes in the relationship (since this is shared between the nodes) */ - Node *from; /* A */ - Node *to; /* B */ - - /* relationship attributes */ - const char *name; /* label for debugging */ - int flag; /* Bitmask of RelationFlag) */ -}; - -/* ********* */ -/* Depsgraph */ - /* Dependency Graph object */ struct Depsgraph { // TODO(sergey): Go away from C++ container and use some native BLI. diff --git a/source/blender/depsgraph/intern/depsgraph_build.cc b/source/blender/depsgraph/intern/depsgraph_build.cc index 0acf777e2f0..4ecb8b8068c 100644 --- a/source/blender/depsgraph/intern/depsgraph_build.cc +++ b/source/blender/depsgraph/intern/depsgraph_build.cc @@ -59,6 +59,7 @@ extern "C" { #include "intern/node/deg_node_id.h" #include "intern/node/deg_node_operation.h" +#include "intern/depsgraph_relation.h" #include "intern/depsgraph_registry.h" #include "intern/depsgraph_type.h" diff --git a/source/blender/depsgraph/intern/depsgraph_debug.cc b/source/blender/depsgraph/intern/depsgraph_debug.cc index 51267491458..4cf3a150eac 100644 --- a/source/blender/depsgraph/intern/depsgraph_debug.cc +++ b/source/blender/depsgraph/intern/depsgraph_debug.cc @@ -38,6 +38,7 @@ extern "C" { #include "DEG_depsgraph_query.h" #include "intern/depsgraph.h" +#include "intern/depsgraph_relation.h" #include "intern/depsgraph_type.h" #include "intern/debug/deg_debug.h" #include "intern/node/deg_node_component.h" diff --git a/source/blender/depsgraph/intern/depsgraph_query_foreach.cc b/source/blender/depsgraph/intern/depsgraph_query_foreach.cc index b7a40fb69bd..cd5e8f8a8d9 100644 --- a/source/blender/depsgraph/intern/depsgraph_query_foreach.cc +++ b/source/blender/depsgraph/intern/depsgraph_query_foreach.cc @@ -40,6 +40,7 @@ extern "C" { #include "DEG_depsgraph_query.h" #include "intern/depsgraph.h" +#include "intern/depsgraph_relation.h" #include "intern/node/deg_node.h" #include "intern/node/deg_node_component.h" #include "intern/node/deg_node_id.h" diff --git a/source/blender/depsgraph/intern/depsgraph_relation.cc b/source/blender/depsgraph/intern/depsgraph_relation.cc new file mode 100644 index 00000000000..387582ca4e0 --- /dev/null +++ b/source/blender/depsgraph/intern/depsgraph_relation.cc @@ -0,0 +1,73 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2020 Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup depsgraph + */ + +#include "intern/depsgraph_relation.h" /* own include */ + +#include "BLI_utildefines.h" + +#include "intern/depsgraph_type.h" +#include "intern/node/deg_node.h" + +namespace DEG { + +/* TODO(sergey): Find a better place for this. */ +template static void remove_from_vector(vector *vector, const T &value) +{ + vector->erase(std::remove(vector->begin(), vector->end(), value), vector->end()); +} + +Relation::Relation(Node *from, Node *to, const char *description) + : from(from), to(to), name(description), flag(0) +{ + /* Hook it up to the nodes which use it. + * + * NOTE: We register relation in the nodes which this link connects to here + * in constructor but we don't unregister it in the destructor. + * + * Reasoning: + * + * - Destructor is currently used on global graph destruction, so there's no + * real need in avoiding dangling pointers, all the memory is to be freed + * anyway. + * + * - Unregistering relation is not a cheap operation, so better to have it + * as an explicit call if we need this. */ + from->outlinks.push_back(this); + to->inlinks.push_back(this); +} + +Relation::~Relation() +{ + /* Sanity check. */ + BLI_assert(from != NULL && to != NULL); +} + +void Relation::unlink() +{ + /* Sanity check. */ + BLI_assert(from != NULL && to != NULL); + remove_from_vector(&from->outlinks, this); + remove_from_vector(&to->inlinks, this); +} + +} // namespace DEG diff --git a/source/blender/depsgraph/intern/depsgraph_relation.h b/source/blender/depsgraph/intern/depsgraph_relation.h new file mode 100644 index 00000000000..9195e9abfbd --- /dev/null +++ b/source/blender/depsgraph/intern/depsgraph_relation.h @@ -0,0 +1,63 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2020 Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup depsgraph + */ + +#pragma once + +namespace DEG { + +class Node; + +/* Settings/Tags on Relationship. + * NOTE: Is a bitmask, allowing accumulation. */ +enum RelationFlag { + /* "cyclic" link - when detecting cycles, this relationship was the one + * which triggers a cyclic relationship to exist in the graph. */ + RELATION_FLAG_CYCLIC = (1 << 0), + /* Update flush will not go through this relation. */ + RELATION_FLAG_NO_FLUSH = (1 << 1), + /* Only flush along the relation is update comes from a node which was + * affected by user input. */ + RELATION_FLAG_FLUSH_USER_EDIT_ONLY = (1 << 2), + /* The relation can not be killed by the cyclic dependencies solver. */ + RELATION_FLAG_GODMODE = (1 << 4), + /* Relation will check existence before being added. */ + RELATION_CHECK_BEFORE_ADD = (1 << 5), +}; + +/* B depends on A (A -> B) */ +struct Relation { + Relation(Node *from, Node *to, const char *description); + ~Relation(); + + void unlink(); + + /* the nodes in the relationship (since this is shared between the nodes) */ + Node *from; /* A */ + Node *to; /* B */ + + /* relationship attributes */ + const char *name; /* label for debugging */ + int flag; /* Bitmask of RelationFlag) */ +}; + +} // namespace DEG diff --git a/source/blender/depsgraph/intern/eval/deg_eval.cc b/source/blender/depsgraph/intern/eval/deg_eval.cc index ff30bf7571a..bf0df085e36 100644 --- a/source/blender/depsgraph/intern/eval/deg_eval.cc +++ b/source/blender/depsgraph/intern/eval/deg_eval.cc @@ -52,6 +52,7 @@ #include "intern/node/deg_node_operation.h" #include "intern/node/deg_node_time.h" #include "intern/depsgraph.h" +#include "intern/depsgraph_relation.h" namespace DEG { diff --git a/source/blender/depsgraph/intern/eval/deg_eval_flush.cc b/source/blender/depsgraph/intern/eval/deg_eval_flush.cc index 96e2974a7ab..cf9b1259e4e 100644 --- a/source/blender/depsgraph/intern/eval/deg_eval_flush.cc +++ b/source/blender/depsgraph/intern/eval/deg_eval_flush.cc @@ -49,6 +49,7 @@ extern "C" { #include "intern/debug/deg_debug.h" #include "intern/depsgraph.h" +#include "intern/depsgraph_relation.h" #include "intern/depsgraph_update.h" #include "intern/node/deg_node.h" #include "intern/node/deg_node_component.h" diff --git a/source/blender/depsgraph/intern/node/deg_node.cc b/source/blender/depsgraph/intern/node/deg_node.cc index 16c934e72fe..5002f2890ae 100644 --- a/source/blender/depsgraph/intern/node/deg_node.cc +++ b/source/blender/depsgraph/intern/node/deg_node.cc @@ -28,6 +28,7 @@ #include "BLI_utildefines.h" #include "intern/depsgraph.h" +#include "intern/depsgraph_relation.h" #include "intern/eval/deg_eval_copy_on_write.h" #include "intern/node/deg_node_component.h" #include "intern/node/deg_node_factory.h" diff --git a/source/blender/depsgraph/intern/node/deg_node_time.cc b/source/blender/depsgraph/intern/node/deg_node_time.cc index cae98ef56c0..ff3e950bb44 100644 --- a/source/blender/depsgraph/intern/node/deg_node_time.cc +++ b/source/blender/depsgraph/intern/node/deg_node_time.cc @@ -26,6 +26,7 @@ #include "DNA_scene_types.h" #include "intern/depsgraph.h" +#include "intern/depsgraph_relation.h" namespace DEG { -- cgit v1.2.3