[Bf-blender-cvs] [9386798] depsgraph_refactor: Depsgraph: Move root pchan map to own file
Sergey Sharybin
noreply at git.blender.org
Wed Jan 28 16:07:31 CET 2015
Commit: 9386798b08c5ec63ff750180a9ffc4178e31d034
Author: Sergey Sharybin
Date: Wed Jan 28 20:06:42 2015 +0500
Branches: depsgraph_refactor
https://developer.blender.org/rB9386798b08c5ec63ff750180a9ffc4178e31d034
Depsgraph: Move root pchan map to own file
===================================================================
M source/blender/depsgraph/CMakeLists.txt
M source/blender/depsgraph/intern/depsgraph_build.h
M source/blender/depsgraph/intern/depsgraph_build_relations.cpp
A source/blender/depsgraph/util/depsgraph_util_pchanmap.cpp
A source/blender/depsgraph/util/depsgraph_util_pchanmap.h
===================================================================
diff --git a/source/blender/depsgraph/CMakeLists.txt b/source/blender/depsgraph/CMakeLists.txt
index fee966d..a66c523 100644
--- a/source/blender/depsgraph/CMakeLists.txt
+++ b/source/blender/depsgraph/CMakeLists.txt
@@ -57,6 +57,7 @@ set(SRC
intern/depsgraph_queue.cpp
intern/depsgraph_tag.cpp
intern/depsgraph_type_defines.cpp
+ util/depsgraph_util_pchanmap.cpp
DEG_depsgraph.h
DEG_depsgraph_build.h
@@ -79,6 +80,7 @@ set(SRC
util/depsgraph_util_hash.h
util/depsgraph_util_id.h
util/depsgraph_util_map.h
+ util/depsgraph_util_pchanmap.h
util/depsgraph_util_set.h
)
diff --git a/source/blender/depsgraph/intern/depsgraph_build.h b/source/blender/depsgraph/intern/depsgraph_build.h
index 1680ec3..47aa525 100644
--- a/source/blender/depsgraph/intern/depsgraph_build.h
+++ b/source/blender/depsgraph/intern/depsgraph_build.h
@@ -57,6 +57,7 @@ struct IDDepsNode;
struct TimeSourceDepsNode;
struct ComponentDepsNode;
struct OperationDepsNode;
+struct RootPChanMap;
struct DepsgraphNodeBuilder {
DepsgraphNodeBuilder(Main *bmain, Depsgraph *graph);
@@ -219,31 +220,6 @@ struct RNAPathKey
struct DepsgraphRelationBuilder
{
- struct RootPChanMap {
- /* ctor and dtor - Create and free the internal map respectively */
- RootPChanMap();
- ~RootPChanMap();
-
- /* Debug contents of map */
- void print_debug();
-
- /* Add a mapping */
- void add_bone(const char *bone, const char *root);
-
- /* Check if there's a common root bone between two bones */
- bool has_common_root(const char *bone1, const char *bone2);
-
- private:
- /* The actual map:
- * - Keys are "strings" (const char *) - not dynamically allocated
- * - Values are "sets" (const char *) - not dynamically allocated
- *
- * We don't use the C++ maps here, as it's more convenient to use
- * Blender's GHash and be able to compare by-value instead of by-ref
- */
- struct GHash *m_map;
- };
-
DepsgraphRelationBuilder(Depsgraph *graph);
template <typename KeyFrom, typename KeyTo>
diff --git a/source/blender/depsgraph/intern/depsgraph_build_relations.cpp b/source/blender/depsgraph/intern/depsgraph_build_relations.cpp
index c1f9023..a079062 100644
--- a/source/blender/depsgraph/intern/depsgraph_build_relations.cpp
+++ b/source/blender/depsgraph/intern/depsgraph_build_relations.cpp
@@ -34,7 +34,6 @@
extern "C" {
#include "BLI_blenlib.h"
-#include "BLI_ghash.h"
#include "BLI_string.h"
#include "BLI_utildefines.h"
@@ -99,6 +98,8 @@ extern "C" {
#include "depsgraph_intern.h"
#include "depsgraph_types.h"
+#include "depsgraph_util_pchanmap.h"
+
#include "stubs.h" // XXX: REMOVE THIS INCLUDE ONCE DEPSGRAPH REFACTOR PROJECT IS DONE!!!
namespace {
@@ -155,103 +156,6 @@ bool modifier_check_depends_on_time(Object *ob, ModifierData *md)
} /* namespace */
/* ***************** */
-/* Pose Channels "Root" Map */
-
-DepsgraphRelationBuilder::RootPChanMap::RootPChanMap()
-{
- /* just create empty map */
- m_map = BLI_ghash_str_new("RootPChanMap");
-}
-
-static void free_rootpchanmap_valueset(void *val)
-{
- /* just need to free the set itself - the names stored are all references */
- GSet *values = (GSet *)val;
- BLI_gset_free(values, NULL);
-}
-
-DepsgraphRelationBuilder::RootPChanMap::~RootPChanMap()
-{
- /* free the map, and all the value sets */
- BLI_ghash_free(m_map, NULL, free_rootpchanmap_valueset);
-}
-
-/* Debug contents of map */
-void DepsgraphRelationBuilder::RootPChanMap::print_debug()
-{
- GHashIterator it1;
- GSetIterator it2;
-
- printf("Root PChan Map:\n");
- GHASH_ITER(it1, m_map) {
- const char *item = (const char *)BLI_ghashIterator_getKey(&it1);
- GSet *values = (GSet *)BLI_ghashIterator_getValue(&it1);
-
- printf(" %s : { ", item);
- GSET_ITER(it2, values) {
- const char *val = (const char *)BLI_gsetIterator_getKey(&it2);
- printf("%s, ", val);
- }
- printf("}\n");
- }
-}
-
-/* Add a mapping */
-void DepsgraphRelationBuilder::RootPChanMap::add_bone(const char *bone, const char *root)
-{
- if (BLI_ghash_haskey(m_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);
- BLI_gset_add(values, (void *)root);
- }
- else {
- /* create new set and mapping */
- GSet *values = BLI_gset_new(BLI_ghashutil_strhash_p, BLI_ghashutil_strcmp, "RootPChanMap Value Set");
- BLI_ghash_insert(m_map, (void *)bone, (void *)values);
-
- /* add new entry now */
- BLI_gset_insert(values, (void *)root);
- }
-}
-
-/* Check if there's a common root bone between two bones */
-bool DepsgraphRelationBuilder::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) {
- //fprintf("RootPChanMap: bone1 '%s' not found (%s => %s)\n", bone1, bone1, bone2);
- //print_debug();
- return false;
- }
-
- if (BLI_ghash_haskey(m_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);
-
- GSetIterator it1, it2;
- GSET_ITER(it1, bone1_roots) {
- GSET_ITER(it2, bone2_roots) {
- const char *v1 = (const char *)BLI_gsetIterator_getKey(&it1);
- const char *v2 = (const char *)BLI_gsetIterator_getKey(&it2);
-
- if (strcmp(v1, v2) == 0) {
- //fprintf("RootPchanMap: %s in common for %s => %s\n", v1, bone1, bone2);
- return true;
- }
- }
- }
-
- //fprintf("RootPChanMap: No common root found (%s => %s)\n", bone1, bone2);
- return false;
-}
-
-
-/* ***************** */
/* Relations Builder */
void DepsgraphRelationBuilder::build_scene(Scene *scene)
diff --git a/source/blender/depsgraph/util/depsgraph_util_pchanmap.cpp b/source/blender/depsgraph/util/depsgraph_util_pchanmap.cpp
new file mode 100644
index 0000000..4af3f9b
--- /dev/null
+++ b/source/blender/depsgraph/util/depsgraph_util_pchanmap.cpp
@@ -0,0 +1,131 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * 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) 2015 Blender Foundation.
+ * All rights reserved.
+ *
+ * Original Author: Sergey Sharybin
+ * Contributor(s): Jushua Leung
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#include "depsgraph_util_pchanmap.h"
+
+#include <string.h>
+
+extern "C" {
+#include "BLI_utildefines.h"
+#include "BLI_ghash.h"
+}
+
+static void free_rootpchanmap_valueset(void *val)
+{
+ /* Just need to free the set itself - the names stored are all references. */
+ GSet *values = (GSet *)val;
+ BLI_gset_free(values, NULL);
+}
+
+RootPChanMap::RootPChanMap()
+{
+ /* just create empty map. */
+ m_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);
+}
+
+/* Debug contents of map */
+void RootPChanMap::print_debug()
+{
+ GHashIterator it1;
+ GSetIterator it2;
+
+ printf("Root PChan Map:\n");
+ GHASH_ITER(it1, m_map) {
+ const char *item = (const char *)BLI_ghashIterator_getKey(&it1);
+ GSet *values = (GSet *)BLI_ghashIterator_getValue(&it1);
+
+ printf(" %s : { ", item);
+ GSET_ITER(it2, values) {
+ const char *val = (const char *)BLI_gsetIterator_getKey(&it2);
+ printf("%s, ", val);
+ }
+ printf("}\n");
+ }
+}
+
+/* Add a mapping */
+void RootPChanMap::add_bone(const char *bone, const char *root)
+{
+ if (BLI_ghash_haskey(m_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);
+ BLI_gset_add(values, (void *)root);
+ }
+ else {
+ /* Create new set and mapping. */
+ GSet *values = BLI_gset_new(BLI_ghashutil_strhash_p,
+ BLI_ghashutil_strcmp,
+ "RootPChanMap Value Set");
+ BLI_ghash_insert(m_map, (void *)bone, (void *)values);
+
+ /* Add new entry now. */
+ BLI_gset_insert(values, (void *)root);
+ }
+}
+
+/* Check if there's a common root bone between two bones */
+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) {
+ //fprintf("RootPChanMap: bone1 '%s' not found (%s => %s)\n", bone1, bone1, bone2);
+ //print_debug();
+ return false;
+ }
+
+ if (BLI_ghash_haskey(m_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);
+
+ GSetIterator it1, it2;
+ GSET_ITER(it1, bone1_roots) {
+ GSET_ITER(it2, bone2_roots) {
+ const char *v1 = (const char *)BLI_gsetIterator_getKey(&it1);
+ const char *v2 = (const char *)BLI_gsetIterator_getKey(&it2);
+
+ if (strcmp(v1, v2) == 0) {
+ //fprintf("RootPchanMap: %s in common for %s => %s\n", v1, bone1, bone2);
+ return true;
+ }
+ }
+ }
+
+ //fprintf("RootPChanMap: No common root found (%s => %s)\n", bone1, bone2);
+ return false;
+}
diff --git a/source/blender/depsgraph/util/depsgraph_util_pchanmap.h b/source/blender/depsgraph/util/depsgraph_util_pchanmap.h
new file mode 100644
index 0000000..a9b7844
--- /dev/null
+++ b/source/blender/depsgraph/util/depsgraph_util_pchanmap.h
@@ -0,0 +1,55 @@
+/*
+ * ***** BEGIN GPL LICENSE B
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list