From e2eeb46a1bda8cf49a70e78a45d12fede27a1af9 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 7 Apr 2015 11:01:47 +1000 Subject: Cleanup: rename treehash -> outliner_treehash This is an API specifically for the outliner, not some generic hierarchical hash structure. --- source/blender/blenkernel/BKE_outliner_treehash.h | 51 ++++++ source/blender/blenkernel/BKE_treehash.h | 51 ------ source/blender/blenkernel/CMakeLists.txt | 8 +- .../blender/blenkernel/intern/outliner_treehash.c | 174 +++++++++++++++++++++ source/blender/blenkernel/intern/treehash.c | 174 --------------------- source/blender/blenloader/intern/readfile.c | 6 +- .../blender/editors/space_outliner/outliner_tree.c | 14 +- .../editors/space_outliner/space_outliner.c | 4 +- 8 files changed, 241 insertions(+), 241 deletions(-) create mode 100644 source/blender/blenkernel/BKE_outliner_treehash.h delete mode 100644 source/blender/blenkernel/BKE_treehash.h create mode 100644 source/blender/blenkernel/intern/outliner_treehash.c delete mode 100644 source/blender/blenkernel/intern/treehash.c (limited to 'source') diff --git a/source/blender/blenkernel/BKE_outliner_treehash.h b/source/blender/blenkernel/BKE_outliner_treehash.h new file mode 100644 index 00000000000..454edb40c4e --- /dev/null +++ b/source/blender/blenkernel/BKE_outliner_treehash.h @@ -0,0 +1,51 @@ +/* + * ***** 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. + * + * Contributor(s): Blender Foundation 2013 + * + * ***** END GPL LICENSE BLOCK ***** + */ +#ifndef __BKE_OUTLINER_TREEHASH_H__ +#define __BKE_OUTLINER_TREEHASH_H__ + +/** \file BKE_outliner_treehash.h + * \ingroup bke + */ + +struct ID; +struct BLI_mempool; +struct TreeStoreElem; + +/* create and fill hashtable with treestore elements */ +void *BKE_outliner_treehash_create_from_treestore(struct BLI_mempool *treestore); + +/* full rebuild for already allocated hashtable */ +void *BKE_outliner_treehash_rebuild_from_treestore(void *treehash, struct BLI_mempool *treestore); + +/* full rebuild for already allocated hashtable */ +void BKE_outliner_treehash_add_element(void *treehash, struct TreeStoreElem *elem); + +/* find first unused element with specific type, nr and id */ +struct TreeStoreElem *BKE_outliner_treehash_lookup_unused(void *treehash, short type, short nr, struct ID *id); + +/* find user or unused element with specific type, nr and id */ +struct TreeStoreElem *BKE_outliner_treehash_lookup_any(void *treehash, short type, short nr, struct ID *id); + +/* free treehash structure */ +void BKE_outliner_treehash_free(void *treehash); + +#endif diff --git a/source/blender/blenkernel/BKE_treehash.h b/source/blender/blenkernel/BKE_treehash.h deleted file mode 100644 index 16ab02c0965..00000000000 --- a/source/blender/blenkernel/BKE_treehash.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * ***** 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. - * - * Contributor(s): Blender Foundation 2013 - * - * ***** END GPL LICENSE BLOCK ***** - */ -#ifndef __BKE_TREEHASH_H__ -#define __BKE_TREEHASH_H__ - -/** \file BKE_treehash.h - * \ingroup bke - */ - -struct ID; -struct BLI_mempool; -struct TreeStoreElem; - -/* create and fill hashtable with treestore elements */ -void *BKE_treehash_create_from_treestore(struct BLI_mempool *treestore); - -/* full rebuild for already allocated hashtable */ -void *BKE_treehash_rebuild_from_treestore(void *treehash, struct BLI_mempool *treestore); - -/* full rebuild for already allocated hashtable */ -void BKE_treehash_add_element(void *treehash, struct TreeStoreElem *elem); - -/* find first unused element with specific type, nr and id */ -struct TreeStoreElem *BKE_treehash_lookup_unused(void *treehash, short type, short nr, struct ID *id); - -/* find user or unused element with specific type, nr and id */ -struct TreeStoreElem *BKE_treehash_lookup_any(void *treehash, short type, short nr, struct ID *id); - -/* free treehash structure */ -void BKE_treehash_free(void *treehash); - -#endif diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt index f19c1066766..67c8f0fc558 100644 --- a/source/blender/blenkernel/CMakeLists.txt +++ b/source/blender/blenkernel/CMakeLists.txt @@ -135,6 +135,7 @@ set(SRC intern/object_deform.c intern/object_dupli.c intern/ocean.c + intern/outliner_treehash.c intern/packedFile.c intern/paint.c intern/particle.c @@ -172,7 +173,6 @@ set(SRC intern/tracking_solver.c intern/tracking_stabilize.c intern/tracking_util.c - intern/treehash.c intern/unit.c intern/world.c intern/writeavi.c @@ -211,6 +211,8 @@ set(SRC BKE_depsgraph.h BKE_displist.h BKE_dynamicpaint.h + BKE_editmesh.h + BKE_editmesh_bvh.h BKE_effect.h BKE_fcurve.h BKE_fluidsim.h @@ -246,6 +248,7 @@ set(SRC BKE_object.h BKE_object_deform.h BKE_ocean.h + BKE_outliner_treehash.h BKE_packedFile.h BKE_paint.h BKE_particle.h @@ -266,12 +269,9 @@ set(SRC BKE_speaker.h BKE_subsurf.h BKE_suggestions.h - BKE_editmesh.h - BKE_editmesh_bvh.h BKE_text.h BKE_texture.h BKE_tracking.h - BKE_treehash.h BKE_unit.h BKE_utildefines.h BKE_world.h diff --git a/source/blender/blenkernel/intern/outliner_treehash.c b/source/blender/blenkernel/intern/outliner_treehash.c new file mode 100644 index 00000000000..1cce61561e0 --- /dev/null +++ b/source/blender/blenkernel/intern/outliner_treehash.c @@ -0,0 +1,174 @@ +/* + * ***** 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. + * + * Contributor(s): Blender Foundation 2013 + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file outliner_treehash.c + * \ingroup bke + * + * Tree hash for the outliner space. + */ + +#include + +#include "BKE_outliner_treehash.h" + +#include "BLI_utildefines.h" +#include "BLI_ghash.h" +#include "BLI_mempool.h" + +#include "DNA_outliner_types.h" + +#include "MEM_guardedalloc.h" + +typedef struct TseGroup +{ + TreeStoreElem **elems; + int size; + int allocated; +} TseGroup; + +/* Allocate structure for TreeStoreElements; + * Most of elements in treestore have no duplicates, + * so there is no need to preallocate memory for more than one pointer */ +static TseGroup *tse_group_create(void) +{ + TseGroup *tse_group = MEM_mallocN(sizeof(TseGroup), "TseGroup"); + tse_group->elems = MEM_mallocN(sizeof(TreeStoreElem *), "TseGroupElems"); + tse_group->size = 0; + tse_group->allocated = 1; + return tse_group; +} + +static void tse_group_add(TseGroup *tse_group, TreeStoreElem *elem) +{ + if (UNLIKELY(tse_group->size == tse_group->allocated)) { + tse_group->allocated *= 2; + tse_group->elems = MEM_reallocN(tse_group->elems, sizeof(TreeStoreElem *) * tse_group->allocated); + } + tse_group->elems[tse_group->size] = elem; + tse_group->size++; +} + +static void tse_group_free(TseGroup *tse_group) +{ + MEM_freeN(tse_group->elems); + MEM_freeN(tse_group); +} + +static unsigned int tse_hash(const void *ptr) +{ + const TreeStoreElem *tse = ptr; + union { + short h_pair[2]; + unsigned int u_int; + } hash; + + BLI_assert(tse->type || !tse->nr); + + hash.h_pair[0] = tse->type; + hash.h_pair[1] = tse->nr; + + hash.u_int ^= BLI_ghashutil_ptrhash(tse->id); + + return hash.u_int; +} + +static bool tse_cmp(const void *a, const void *b) +{ + const TreeStoreElem *tse_a = a; + const TreeStoreElem *tse_b = b; + return tse_a->type != tse_b->type || tse_a->nr != tse_b->nr || tse_a->id != tse_b->id; +} + +static void fill_treehash(void *treehash, BLI_mempool *treestore) +{ + TreeStoreElem *tselem; + BLI_mempool_iter iter; + BLI_mempool_iternew(treestore, &iter); + while ((tselem = BLI_mempool_iterstep(&iter))) { + BKE_outliner_treehash_add_element(treehash, tselem); + } +} + +void *BKE_outliner_treehash_create_from_treestore(BLI_mempool *treestore) +{ + GHash *treehash = BLI_ghash_new_ex(tse_hash, tse_cmp, "treehash", BLI_mempool_count(treestore)); + fill_treehash(treehash, treestore); + return treehash; +} + +static void free_treehash_group(void *key) +{ + tse_group_free(key); +} + +void *BKE_outliner_treehash_rebuild_from_treestore(void *treehash, BLI_mempool *treestore) +{ + BLI_ghash_clear_ex(treehash, NULL, free_treehash_group, BLI_mempool_count(treestore)); + fill_treehash(treehash, treestore); + return treehash; +} + +void BKE_outliner_treehash_add_element(void *treehash, TreeStoreElem *elem) +{ + TseGroup *group; + void **val_p; + + if (!BLI_ghash_ensure_p(treehash, elem, &val_p)) { + *val_p = tse_group_create(); + } + group = *val_p; + tse_group_add(group, elem); +} + +static TseGroup *BKE_outliner_treehash_lookup_group(GHash *th, short type, short nr, struct ID *id) +{ + TreeStoreElem tse_template; + tse_template.type = type; + tse_template.nr = type ? nr : 0; // we're picky! :) + tse_template.id = id; + return BLI_ghash_lookup(th, &tse_template); +} + +TreeStoreElem *BKE_outliner_treehash_lookup_unused(void *treehash, short type, short nr, struct ID *id) +{ + TseGroup *group = BKE_outliner_treehash_lookup_group(treehash, type, nr, id); + if (group) { + int i; + for (i = 0; i < group->size; i++) { + if (!group->elems[i]->used) { + return group->elems[i]; + } + } + } + return NULL; +} + +TreeStoreElem *BKE_outliner_treehash_lookup_any(void *treehash, short type, short nr, struct ID *id) +{ + TseGroup *group = BKE_outliner_treehash_lookup_group(treehash, type, nr, id); + return group ? group->elems[0] : NULL; +} + +void BKE_outliner_treehash_free(void *treehash) +{ + BLI_ghash_free(treehash, NULL, free_treehash_group); +} diff --git a/source/blender/blenkernel/intern/treehash.c b/source/blender/blenkernel/intern/treehash.c deleted file mode 100644 index 43eeae7329e..00000000000 --- a/source/blender/blenkernel/intern/treehash.c +++ /dev/null @@ -1,174 +0,0 @@ -/* - * ***** 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. - * - * Contributor(s): Blender Foundation 2013 - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file treehash.c - * \ingroup bke - * - * Tree hash for the outliner space. - */ - -#include - -#include "BKE_treehash.h" - -#include "BLI_utildefines.h" -#include "BLI_ghash.h" -#include "BLI_mempool.h" - -#include "DNA_outliner_types.h" - -#include "MEM_guardedalloc.h" - -typedef struct TseGroup -{ - TreeStoreElem **elems; - int size; - int allocated; -} TseGroup; - -/* Allocate structure for TreeStoreElements; - * Most of elements in treestore have no duplicates, - * so there is no need to preallocate memory for more than one pointer */ -static TseGroup *tse_group_create(void) -{ - TseGroup *tse_group = MEM_mallocN(sizeof(TseGroup), "TseGroup"); - tse_group->elems = MEM_mallocN(sizeof(TreeStoreElem *), "TseGroupElems"); - tse_group->size = 0; - tse_group->allocated = 1; - return tse_group; -} - -static void tse_group_add(TseGroup *tse_group, TreeStoreElem *elem) -{ - if (UNLIKELY(tse_group->size == tse_group->allocated)) { - tse_group->allocated *= 2; - tse_group->elems = MEM_reallocN(tse_group->elems, sizeof(TreeStoreElem *) * tse_group->allocated); - } - tse_group->elems[tse_group->size] = elem; - tse_group->size++; -} - -static void tse_group_free(TseGroup *tse_group) -{ - MEM_freeN(tse_group->elems); - MEM_freeN(tse_group); -} - -static unsigned int tse_hash(const void *ptr) -{ - const TreeStoreElem *tse = ptr; - union { - short h_pair[2]; - unsigned int u_int; - } hash; - - BLI_assert(tse->type || !tse->nr); - - hash.h_pair[0] = tse->type; - hash.h_pair[1] = tse->nr; - - hash.u_int ^= BLI_ghashutil_ptrhash(tse->id); - - return hash.u_int; -} - -static bool tse_cmp(const void *a, const void *b) -{ - const TreeStoreElem *tse_a = a; - const TreeStoreElem *tse_b = b; - return tse_a->type != tse_b->type || tse_a->nr != tse_b->nr || tse_a->id != tse_b->id; -} - -static void fill_treehash(void *treehash, BLI_mempool *treestore) -{ - TreeStoreElem *tselem; - BLI_mempool_iter iter; - BLI_mempool_iternew(treestore, &iter); - while ((tselem = BLI_mempool_iterstep(&iter))) { - BKE_treehash_add_element(treehash, tselem); - } -} - -void *BKE_treehash_create_from_treestore(BLI_mempool *treestore) -{ - GHash *treehash = BLI_ghash_new_ex(tse_hash, tse_cmp, "treehash", BLI_mempool_count(treestore)); - fill_treehash(treehash, treestore); - return treehash; -} - -static void free_treehash_group(void *key) -{ - tse_group_free(key); -} - -void *BKE_treehash_rebuild_from_treestore(void *treehash, BLI_mempool *treestore) -{ - BLI_ghash_clear_ex(treehash, NULL, free_treehash_group, BLI_mempool_count(treestore)); - fill_treehash(treehash, treestore); - return treehash; -} - -void BKE_treehash_add_element(void *treehash, TreeStoreElem *elem) -{ - TseGroup *group; - void **val_p; - - if (!BLI_ghash_ensure_p(treehash, elem, &val_p)) { - *val_p = tse_group_create(); - } - group = *val_p; - tse_group_add(group, elem); -} - -static TseGroup *BKE_treehash_lookup_group(GHash *th, short type, short nr, struct ID *id) -{ - TreeStoreElem tse_template; - tse_template.type = type; - tse_template.nr = type ? nr : 0; // we're picky! :) - tse_template.id = id; - return BLI_ghash_lookup(th, &tse_template); -} - -TreeStoreElem *BKE_treehash_lookup_unused(void *treehash, short type, short nr, struct ID *id) -{ - TseGroup *group = BKE_treehash_lookup_group(treehash, type, nr, id); - if (group) { - int i; - for (i = 0; i < group->size; i++) { - if (!group->elems[i]->used) { - return group->elems[i]; - } - } - } - return NULL; -} - -TreeStoreElem *BKE_treehash_lookup_any(void *treehash, short type, short nr, struct ID *id) -{ - TseGroup *group = BKE_treehash_lookup_group(treehash, type, nr, id); - return group ? group->elems[0] : NULL; -} - -void BKE_treehash_free(void *treehash) -{ - BLI_ghash_free(treehash, NULL, free_treehash_group); -} diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 4eb7413adc1..9a269cad756 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -139,7 +139,7 @@ #include "BKE_scene.h" #include "BKE_screen.h" #include "BKE_sequencer.h" -#include "BKE_treehash.h" +#include "BKE_outliner_treehash.h" #include "BKE_sound.h" @@ -6041,7 +6041,7 @@ static void lib_link_screen(FileData *fd, Main *main) } if (so->treehash) { /* rebuild hash table, because it depends on ids too */ - BKE_treehash_rebuild_from_treestore(so->treehash, so->treestore); + BKE_outliner_treehash_rebuild_from_treestore(so->treehash, so->treestore); } } } @@ -6392,7 +6392,7 @@ void blo_lib_link_screen_restore(Main *newmain, bScreen *curscreen, Scene *cursc } if (so->treehash) { /* rebuild hash table, because it depends on ids too */ - BKE_treehash_rebuild_from_treestore(so->treehash, so->treestore); + BKE_outliner_treehash_rebuild_from_treestore(so->treehash, so->treestore); } } } diff --git a/source/blender/editors/space_outliner/outliner_tree.c b/source/blender/editors/space_outliner/outliner_tree.c index 9239d9cb27e..17a6e952ee1 100644 --- a/source/blender/editors/space_outliner/outliner_tree.c +++ b/source/blender/editors/space_outliner/outliner_tree.c @@ -66,7 +66,7 @@ #include "BKE_modifier.h" #include "BKE_sequencer.h" #include "BKE_idcode.h" -#include "BKE_treehash.h" +#include "BKE_outliner_treehash.h" #include "ED_armature.h" #include "ED_screen.h" @@ -114,7 +114,7 @@ static void outliner_storage_cleanup(SpaceOops *soops) BLI_mempool_destroy(ts); soops->treestore = NULL; if (soops->treehash) { - BKE_treehash_free(soops->treehash); + BKE_outliner_treehash_free(soops->treehash); soops->treehash = NULL; } } @@ -133,7 +133,7 @@ static void outliner_storage_cleanup(SpaceOops *soops) soops->treestore = new_ts; if (soops->treehash) { /* update hash table to fix broken pointers */ - BKE_treehash_rebuild_from_treestore(soops->treehash, soops->treestore); + BKE_outliner_treehash_rebuild_from_treestore(soops->treehash, soops->treestore); } } } @@ -151,12 +151,12 @@ static void check_persistent(SpaceOops *soops, TreeElement *te, ID *id, short ty } if (soops->treehash == NULL) { - soops->treehash = BKE_treehash_create_from_treestore(soops->treestore); + soops->treehash = BKE_outliner_treehash_create_from_treestore(soops->treestore); } /* find any unused tree element in treestore and mark it as used * (note that there may be multiple unused elements in case of linked objects) */ - tselem = BKE_treehash_lookup_unused(soops->treehash, type, nr, id); + tselem = BKE_outliner_treehash_lookup_unused(soops->treehash, type, nr, id); if (tselem) { te->store_elem = tselem; tselem->used = 1; @@ -171,7 +171,7 @@ static void check_persistent(SpaceOops *soops, TreeElement *te, ID *id, short ty tselem->used = 0; tselem->flag = TSE_CLOSED; te->store_elem = tselem; - BKE_treehash_add_element(soops->treehash, tselem); + BKE_outliner_treehash_add_element(soops->treehash, tselem); } /* ********************************************************* */ @@ -216,7 +216,7 @@ TreeElement *outliner_find_tse(SpaceOops *soops, TreeStoreElem *tse) if (tse->id == NULL) return NULL; /* check if 'tse' is in treestore */ - tselem = BKE_treehash_lookup_any(soops->treehash, tse->type, tse->nr, tse->id); + tselem = BKE_outliner_treehash_lookup_any(soops->treehash, tse->type, tse->nr, tse->id); if (tselem) return outliner_find_tree_element(&soops->tree, tselem); diff --git a/source/blender/editors/space_outliner/space_outliner.c b/source/blender/editors/space_outliner/space_outliner.c index e1aea8892b5..7b1ec174a6b 100644 --- a/source/blender/editors/space_outliner/space_outliner.c +++ b/source/blender/editors/space_outliner/space_outliner.c @@ -41,7 +41,7 @@ #include "BKE_context.h" #include "BKE_screen.h" #include "BKE_scene.h" -#include "BKE_treehash.h" +#include "BKE_outliner_treehash.h" #include "ED_space_api.h" #include "ED_screen.h" @@ -464,7 +464,7 @@ static void outliner_free(SpaceLink *sl) BLI_mempool_destroy(soutliner->treestore); } if (soutliner->treehash) { - BKE_treehash_free(soutliner->treehash); + BKE_outliner_treehash_free(soutliner->treehash); } } -- cgit v1.2.3