Commit: 57a5f2ef443d79d4394cf028a422392f1b7c1515 Author: Dalai Felinto Date: Fri Dec 16 18:22:05 2016 +0100 Branches: render-layers https://developer.blender.org/rB57a5f2ef443d79d4394cf028a422392f1b7c1515
Iterator util function =================================================================== M source/blender/blenkernel/BKE_collection.h M source/blender/blenkernel/intern/collection.c M source/blender/blenkernel/intern/library_query.c A source/blender/blenlib/BLI_iterator.h M source/blender/blenlib/CMakeLists.txt A source/blender/blenlib/intern/BLI_iterator.c M source/blender/editors/object/object_relations.c =================================================================== diff --git a/source/blender/blenkernel/BKE_collection.h b/source/blender/blenkernel/BKE_collection.h index 0d3f190..61d53da 100644 --- a/source/blender/blenkernel/BKE_collection.h +++ b/source/blender/blenkernel/BKE_collection.h @@ -27,10 +27,13 @@ * \ingroup bke */ +#include "BLI_iterator.h" + #ifdef __cplusplus extern "C" { #endif +struct Iterator; struct SceneCollection; struct Object; struct Scene; @@ -45,6 +48,15 @@ void BKE_collection_object_remove(struct Scene *scene, struct SceneCollection *s typedef void (*BKE_scene_objects_Cb)(struct Object *ob, void *data); void BKE_scene_objects_callback(struct Scene *scene, BKE_scene_objects_Cb callback, void *data); +/* iterators */ +void BKE_scene_objects_Iterator_begin(struct Iterator *iter, void *data); + +#define SCENE_OBJECTS_BEGIN(scene, _ob) \ + ITER_BEGIN(BKE_scene_objects_Iterator_begin, scene, _ob) + +#define SCENE_OBJECTS_END \ + ITER_END + #ifdef __cplusplus } #endif diff --git a/source/blender/blenkernel/intern/collection.c b/source/blender/blenkernel/intern/collection.c index 4562583..8a7393b 100644 --- a/source/blender/blenkernel/intern/collection.c +++ b/source/blender/blenkernel/intern/collection.c @@ -25,6 +25,7 @@ */ #include "BLI_blenlib.h" +#include "BLI_iterator.h" #include "BLI_listbase.h" #include "BLT_translation.h" @@ -248,3 +249,52 @@ void BKE_scene_objects_callback(Scene *scene, BKE_scene_objects_Cb callback, voi collection_objects_callback(sc, object_tag_clear, NULL); collection_objects_callback(sc, callback, data); } + + +/* ---------------------------------------------------------------------- */ +/* Iteractors */ + +/* sequence strip iterator: + * - builds a full array, recursively into meta strips + */ + +static void scene_objects_count(Object *UNUSED(ob), void *data) +{ + int *tot = data; + (*tot)++; +} + +static void scene_objects_build_array(Object *ob, void *data) +{ + Object ***array = data; + **array = ob; + (*array)++; +} + +static void scene_objects_array(Scene *scene, Object ***objects_array, int *tot) +{ + Object **array; + + *objects_array = NULL; + *tot = 0; + + if (scene == NULL) + return; + + BKE_scene_objects_callback(scene, scene_objects_count, tot); + + if (*tot == 0) + return; + + *objects_array = array = MEM_mallocN(sizeof(Object *) * (*tot), "ObjectsArray"); + BKE_scene_objects_callback(scene, scene_objects_build_array, &array); +} + +/* + * Only use this in non-performance critical situations + * (it iterates over all scene collections twice) + */ +void BKE_scene_objects_Iterator_begin(Iterator *iter, void *data) +{ + scene_objects_array(data, (Object ***)&iter->array, &iter->tot); +} diff --git a/source/blender/blenkernel/intern/library_query.c b/source/blender/blenkernel/intern/library_query.c index a161d9c..1601348 100644 --- a/source/blender/blenkernel/intern/library_query.c +++ b/source/blender/blenkernel/intern/library_query.c @@ -68,6 +68,7 @@ #include "BLI_linklist_stack.h" #include "BKE_animsys.h" +#include "BKE_collection.h" #include "BKE_constraint.h" #include "BKE_fcurve.h" #include "BKE_library.h" @@ -385,6 +386,15 @@ void BKE_library_foreach_ID_link(ID *id, LibraryIDLinkCallback callback, void *u CALLBACK_INVOKE(base->object, IDWALK_USER); } + { + Object* ob; + SCENE_OBJECTS_BEGIN(scene, ob) + { + CALLBACK_INVOKE(ob, IDWALK_USER); + } + SCENE_OBJECTS_END + } + for (TimeMarker *marker = scene->markers.first; marker; marker = marker->next) { CALLBACK_INVOKE(marker->camera, IDWALK_NOP); } diff --git a/source/blender/blenlib/BLI_iterator.h b/source/blender/blenlib/BLI_iterator.h new file mode 100644 index 0000000..86b885f --- /dev/null +++ b/source/blender/blenlib/BLI_iterator.h @@ -0,0 +1,58 @@ +/* + * ***** 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): Dalai Felinto + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#ifndef __BLI_ITERATOR_H__ +#define __BLI_ITERATOR_H__ + +/** \file BLI_iterator.h + * \ingroup bli + */ + +typedef struct Iterator { + void **array; + int tot, cur; + + void *data; + int valid; +} Iterator; + +typedef void (*IteratorCb)(Iterator *iter, void *data); + +void BLI_iterator_begin(Iterator *iter, IteratorCb callback, void *data); +void BLI_iterator_next(Iterator *iter); +void BLI_iterator_end(Iterator *iter); + +#define ITER_BEGIN(callback, _data_in, _data_out) \ + { \ + Iterator iter_macro; \ + for (BLI_iterator_begin(&iter_macro, callback, _data_in); \ + iter_macro.valid; \ + BLI_iterator_next(&iter_macro)) \ + { \ + _data_out = iter_macro.data; + +#define ITER_END \ + } \ + BLI_iterator_end(&iter_macro); \ + } + +#endif /* __BLI_ITERATOR_H__ */ diff --git a/source/blender/blenlib/CMakeLists.txt b/source/blender/blenlib/CMakeLists.txt index 6e717a3..003ad9b 100644 --- a/source/blender/blenlib/CMakeLists.txt +++ b/source/blender/blenlib/CMakeLists.txt @@ -47,6 +47,7 @@ set(SRC intern/BLI_ghash.c intern/BLI_heap.c intern/BLI_kdopbvh.c + intern/BLI_iterator.c intern/BLI_kdtree.c intern/BLI_linklist.c intern/BLI_memarena.c @@ -154,6 +155,7 @@ set(SRC BLI_hash_md5.h BLI_hash_mm2a.h BLI_heap.h + BLI_iterator.h BLI_jitter.h BLI_kdopbvh.h BLI_kdtree.h diff --git a/source/blender/blenlib/intern/BLI_iterator.c b/source/blender/blenlib/intern/BLI_iterator.c new file mode 100644 index 0000000..83097de --- /dev/null +++ b/source/blender/blenlib/intern/BLI_iterator.c @@ -0,0 +1,63 @@ +/* + * ***** 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): Dalai Felinto + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/blenlib/intern/iterator.c + * \ingroup bli + * + * Iterator defines + */ + +#include <string.h> + +#include "BLI_iterator.h" +#include "MEM_guardedalloc.h" + +void BLI_iterator_begin(Iterator *iter, IteratorCb callback, void *data) +{ + memset(iter, 0, sizeof(*iter)); + callback(iter, data); + + if (iter->tot) { + iter->cur = 0; + iter->data = iter->array[iter->cur]; + iter->valid = 1; + } +} + +void BLI_iterator_next(Iterator *iter) +{ + if (++iter->cur < iter->tot) { + iter->data = iter->array[iter->cur]; + } + else { + iter->valid = 0; + } +} + +void BLI_iterator_end(Iterator *iter) +{ + if (iter->array) { + MEM_freeN(iter->array); + } + iter->valid = 0; +} + diff --git a/source/blender/editors/object/object_relations.c b/source/blender/editors/object/object_relations.c index eb410ac..6722c8d 100644 --- a/source/blender/editors/object/object_relations.c +++ b/source/blender/editors/object/object_relations.c @@ -1849,17 +1849,20 @@ static void single_object_users(Main *bmain, Scene *scene, View3D *v3d, const in TODO_LAYER_SYNC_FILTER } -static void object_untag_OB_DONE(Object *ob, void *UNUSED(data)) -{ - ob->flag &= ~OB_DONE; -} - /* not an especially efficient function, only added so the single user * button can be functional.*/ void ED_object_single_user(Main *bmain, Scene *scene, Object *ob) { - BKE_scene_objects_callback(scene, object_untag_OB_DONE, NULL); + Object *ob_iter; + SCENE_OBJECTS_BEGIN(scene, ob_iter) + { + ob_iter->flag &= ~OB_DONE; + } + SCENE_OBJECTS_END + + /* tag only the one object */ ob->flag |= OB_DONE; + single_object_users(bmain, scene, NULL, OB_DONE, false); BKE_main_id_clear_newpoins(bmain); } _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org https://lists.blender.org/mailman/listinfo/bf-blender-cvs