[Bf-blender-cvs] [fec9a4e] depsgraph_cleanup: Depsgraph: Move some of the utilities to DEG namespace

Sergey Sharybin noreply at git.blender.org
Thu May 26 10:02:30 CEST 2016


Commit: fec9a4e043c2adba6bc1d73111bdca2d1628b750
Author: Sergey Sharybin
Date:   Wed May 25 16:16:39 2016 +0200
Branches: depsgraph_cleanup
https://developer.blender.org/rBfec9a4e043c2adba6bc1d73111bdca2d1628b750

Depsgraph: Move some of the utilities to DEG namespace

===================================================================

M	source/blender/depsgraph/intern/builder/deg_builder_nodes.h
M	source/blender/depsgraph/intern/builder/deg_builder_relations.h
M	source/blender/depsgraph/intern/depsgraph_build.cc
M	source/blender/depsgraph/util/depsgraph_util_cycle.cc
M	source/blender/depsgraph/util/depsgraph_util_cycle.h
M	source/blender/depsgraph/util/depsgraph_util_pchanmap.cc
M	source/blender/depsgraph/util/depsgraph_util_pchanmap.h
M	source/blender/depsgraph/util/depsgraph_util_transitive.cc
M	source/blender/depsgraph/util/depsgraph_util_transitive.h

===================================================================

diff --git a/source/blender/depsgraph/intern/builder/deg_builder_nodes.h b/source/blender/depsgraph/intern/builder/deg_builder_nodes.h
index e375d18..4e819b5 100644
--- a/source/blender/depsgraph/intern/builder/deg_builder_nodes.h
+++ b/source/blender/depsgraph/intern/builder/deg_builder_nodes.h
@@ -62,7 +62,6 @@ struct IDDepsNode;
 struct TimeSourceDepsNode;
 struct ComponentDepsNode;
 struct OperationDepsNode;
-struct RootPChanMap;
 
 namespace DEG {
 
diff --git a/source/blender/depsgraph/intern/builder/deg_builder_relations.h b/source/blender/depsgraph/intern/builder/deg_builder_relations.h
index 91079f7..37f61a7 100644
--- a/source/blender/depsgraph/intern/builder/deg_builder_relations.h
+++ b/source/blender/depsgraph/intern/builder/deg_builder_relations.h
@@ -75,11 +75,11 @@ struct IDDepsNode;
 struct TimeSourceDepsNode;
 struct ComponentDepsNode;
 struct OperationDepsNode;
-struct RootPChanMap;
 
 namespace DEG {
 
 struct DepsNodeHandle;
+struct RootPChanMap;
 
 struct RootKey
 {
diff --git a/source/blender/depsgraph/intern/depsgraph_build.cc b/source/blender/depsgraph/intern/depsgraph_build.cc
index 2e3a8b4..3c92ecc 100644
--- a/source/blender/depsgraph/intern/depsgraph_build.cc
+++ b/source/blender/depsgraph/intern/depsgraph_build.cc
@@ -203,8 +203,12 @@ void DEG_add_special_eval_flag(Depsgraph *graph, ID *id, short flag)
 /* ******************** */
 /* Graph Building API's */
 
-/* Build depsgraph for the given scene, and dump results in given graph container */
-// XXX: assume that this is called from outside, given the current scene as the "main" scene
+/* Build depsgraph for the given scene, and dump results in given
+ * graph container.
+ */
+/* XXX: assume that this is called from outside, given the current scene as
+ * the "main" scene.
+ */
 void DEG_graph_build_from_scene(Depsgraph *graph, Main *bmain, Scene *scene)
 {
 	/* 1) Generate all the nodes in the graph first */
@@ -216,22 +220,33 @@ void DEG_graph_build_from_scene(Depsgraph *graph, Main *bmain, Scene *scene)
 	node_builder.add_root_node();
 	node_builder.build_scene(bmain, scene);
 
-	/* 2) Hook up relationships between operations - to determine evaluation order */
+	/* 2) Hook up relationships between operations - to determine evaluation
+	 *    order.
+	 */
 	DEG::DepsgraphRelationBuilder relation_builder(graph);
-	/* hook scene up to the root node as entrypoint to 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.
+	 * it doesnt add any operations anyway and is not clear what part of the
+	 * scene is to be connected.
 	 */
-	//relation_builder.add_relation(RootKey(), IDKey(scene), DEPSREL_TYPE_ROOT_TO_ACTIVE, "Root to Active Scene");
+#if 0
+	relation_builder.add_relation(RootKey(),
+	                              IDKey(scene),
+	                              DEPSREL_TYPE_ROOT_TO_ACTIVE,
+	                              "Root to Active Scene");
+#endif
 	relation_builder.build_scene(bmain, scene);
 
 	/* Detect and solve cycles. */
-	deg_graph_detect_cycles(graph);
+	DEG::deg_graph_detect_cycles(graph);
 
-	/* 3) Simplify the graph by removing redundant relations (to optimise traversal later) */
-	// TODO: it would be useful to have an option to disable this in cases where it is causing trouble
+	/* 3) Simplify the graph by removing redundant relations (to optimize
+	 *    traversal later). */
+	/* TODO: it would be useful to have an option to disable this in cases where
+	 *       it is causing trouble.
+	 */
 	if (G.debug_value == 799) {
-		deg_graph_transitive_reduction(graph);
+		DEG::deg_graph_transitive_reduction(graph);
 	}
 
 	/* 4) Flush visibility layer and re-schedule nodes for update. */
diff --git a/source/blender/depsgraph/util/depsgraph_util_cycle.cc b/source/blender/depsgraph/util/depsgraph_util_cycle.cc
index 5eae8c0..bbc4a17 100644
--- a/source/blender/depsgraph/util/depsgraph_util_cycle.cc
+++ b/source/blender/depsgraph/util/depsgraph_util_cycle.cc
@@ -27,6 +27,7 @@
  *  \ingroup depsgraph
  */
 
+// TOO(sergey): Use some wrappers over those?
 #include <cstdio>
 #include <cstdlib>
 #include <stack>
@@ -41,11 +42,15 @@ extern "C" {
 }
 
 #include "depsgraph_util_cycle.h"
+#include "depsgraph_util_foreach.h"
+
 #include "depsgraph.h"
 #include "depsnode.h"
 #include "depsnode_component.h"
 #include "depsnode_operation.h"
 
+namespace DEG {
+
 struct StackEntry {
 	OperationDepsNode *node;
 	StackEntry *from;
@@ -62,17 +67,9 @@ void deg_graph_detect_cycles(Depsgraph *graph)
 	const int NODE_IN_STACK = 2;
 
 	std::stack<StackEntry> traversal_stack;
-	for (Depsgraph::OperationNodes::const_iterator it_op = graph->operations.begin();
-	     it_op != graph->operations.end();
-	     ++it_op)
-	{
-		OperationDepsNode *node = *it_op;
+	foreach (OperationDepsNode *node, graph->operations) {
 		bool has_inlinks = false;
-		for (OperationDepsNode::Relations::const_iterator it_rel = node->inlinks.begin();
-		     it_rel != node->inlinks.end();
-		     ++it_rel)
-		{
-			DepsRelation *rel = *it_rel;
+		foreach (DepsRelation *rel, node->inlinks) {
 			if (rel->from->type == DEPSNODE_TYPE_OPERATION) {
 				has_inlinks = true;
 			}
@@ -94,11 +91,7 @@ void deg_graph_detect_cycles(Depsgraph *graph)
 		StackEntry &entry = traversal_stack.top();
 		OperationDepsNode *node = entry.node;
 		bool all_child_traversed = true;
-		for (OperationDepsNode::Relations::const_iterator it_rel = node->outlinks.begin();
-		     it_rel != node->outlinks.end();
-		     ++it_rel)
-		{
-			DepsRelation *rel = *it_rel;
+		foreach (DepsRelation *rel, node->outlinks) {
 			if (rel->to->type == DEPSNODE_TYPE_OPERATION) {
 				OperationDepsNode *to = (OperationDepsNode *)rel->to;
 				if (to->done == NODE_IN_STACK) {
@@ -138,3 +131,5 @@ void deg_graph_detect_cycles(Depsgraph *graph)
 		}
 	}
 }
+
+}  // namespace DEG
diff --git a/source/blender/depsgraph/util/depsgraph_util_cycle.h b/source/blender/depsgraph/util/depsgraph_util_cycle.h
index fac38b6..6a29d18 100644
--- a/source/blender/depsgraph/util/depsgraph_util_cycle.h
+++ b/source/blender/depsgraph/util/depsgraph_util_cycle.h
@@ -27,11 +27,13 @@
  *  \ingroup depsgraph
  */
 
-#ifndef __DEPSGRAPH_UTIL_CYCLE_H__
-#define __DEPSGRAPH_UTIL_CYCLE_H__
+
+#pragma once
 
 struct Depsgraph;
 
+namespace DEG {
+
 void deg_graph_detect_cycles(Depsgraph *graph);
 
-#endif  /* __DEPSGRAPH_UTIL_CYCLE_H__ */
+}  // namespace DEG
diff --git a/source/blender/depsgraph/util/depsgraph_util_pchanmap.cc b/source/blender/depsgraph/util/depsgraph_util_pchanmap.cc
index 80b37ec..0997463 100644
--- a/source/blender/depsgraph/util/depsgraph_util_pchanmap.cc
+++ b/source/blender/depsgraph/util/depsgraph_util_pchanmap.cc
@@ -38,6 +38,8 @@ extern "C" {
 #include "BLI_ghash.h"
 }
 
+namespace DEG {
+
 static void free_rootpchanmap_valueset(void *val)
 {
 	/* Just need to free the set itself - the names stored are all references. */
@@ -48,13 +50,13 @@ static void free_rootpchanmap_valueset(void *val)
 RootPChanMap::RootPChanMap()
 {
 	/* Just create empty map. */
-	m_map = BLI_ghash_str_new("RootPChanMap");
+	map_ = BLI_ghash_str_new("RootPChanMap");
 }
 
 RootPChanMap::~RootPChanMap()
 {
 	/* Free the map, and all the value sets. */
-	BLI_ghash_free(m_map, NULL, free_rootpchanmap_valueset);
+	BLI_ghash_free(map_, NULL, free_rootpchanmap_valueset);
 }
 
 /* Debug contents of map */
@@ -64,7 +66,7 @@ void RootPChanMap::print_debug()
 	GSetIterator it2;
 
 	printf("Root PChan Map:\n");
-	GHASH_ITER(it1, m_map) {
+	GHASH_ITER(it1, map_) {
 		const char *item = (const char *)BLI_ghashIterator_getKey(&it1);
 		GSet *values = (GSet *)BLI_ghashIterator_getValue(&it1);
 
@@ -80,11 +82,11 @@ void RootPChanMap::print_debug()
 /* Add a mapping. */
 void RootPChanMap::add_bone(const char *bone, const char *root)
 {
-	if (BLI_ghash_haskey(m_map, bone)) {
+	if (BLI_ghash_haskey(map_, bone)) {
 		/* Add new entry, but only add the root if it doesn't already
 		 * exist in there.
 		 */
-		GSet *values = (GSet *)BLI_ghash_lookup(m_map, bone);
+		GSet *values = (GSet *)BLI_ghash_lookup(map_, bone);
 		BLI_gset_add(values, (void *)root);
 	}
 	else {
@@ -92,7 +94,7 @@ void RootPChanMap::add_bone(const char *bone, const char *root)
 		GSet *values = BLI_gset_new(BLI_ghashutil_strhash_p,
 		                            BLI_ghashutil_strcmp,
 		                            "RootPChanMap Value Set");
-		BLI_ghash_insert(m_map, (void *)bone, (void *)values);
+		BLI_ghash_insert(map_, (void *)bone, (void *)values);
 
 		/* Add new entry now. */
 		BLI_gset_insert(values, (void *)root);
@@ -103,20 +105,20 @@ void RootPChanMap::add_bone(const char *bone, const char *root)
 bool RootPChanMap::has_common_root(const char *bone1, const char *bone2)
 {
 	/* Ensure that both are in the map... */
-	if (BLI_ghash_haskey(m_map, bone1) == false) {
+	if (BLI_ghash_haskey(map_, bone1) == false) {
 		//fprintf("RootPChanMap: bone1 '%s' not found (%s => %s)\n", bone1, bone1, bone2);
 		//print_debug();
 		return false;
 	}
 
-	if (BLI_ghash_haskey(m_map, bone2) == false) {
+	if (BLI_ghash_haskey(map_, bone2) == false) {
 		//fprintf("RootPChanMap: bone2 '%s' not found (%s => %s)\n", bone2, bone1, bone2);
 		//print_debug();
 		return false;
 	}
 
-	GSet *bone1_roots = (GSet *)BLI_ghash_lookup(m_map, (void *)bone1);
-	GSet *bone2_roots = (GSet *)BLI_ghash_lookup(m_map, (void *)bone2);
+	GSet *bone1_roots = (GSet *)BLI_ghash_lookup(map_, (void *)bone1);
+	GSet *bone2_roots = (GSet *)BLI_ghash_lookup(map_, (void *)bone2);
 
 	GSetIterator it1, it2;
 	GSET_ITER(it1, bone1_roots) {
@@ -134,3 +136,5 @@ bool RootPChanMap::has_common_root(const char *bone1, const char *bone2)
 	//fprintf("RootPChanMap: No common root found (%s => %s)\n", bone1, bone2);
 	return false;
 }
+
+}  // namespace DEG
diff --git a/source/blender/depsgraph/util/depsgraph_util_pchanmap.h b/source/blender/depsgraph/util/depsgraph_util_pchanmap.h
index b7f4c49..4ea7d48 100644
--- a/source/blender/depsgraph/util/depsgraph_util_pchanmap.h
+++ b/source/blender/depsgraph/util/depsgraph_util_pchanmap.h
@@ -28,8 +28,11 @@
  *  \ingroup depsgraph
  */
 
-#ifndef __DEPSGRAPH_UTIL_P

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list