diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-08-18 20:16:13 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-08-18 20:16:13 +0400 |
commit | 27b4b45543c0f7690a1978a60591a0b5c0f1adbb (patch) | |
tree | 14c54494059de30d8d4c8a24ec8400b8bcc83ff5 /source/blender/blenkernel | |
parent | e982e9b04f13be046d194643ed28aaedd6181f3b (diff) |
utility functions: BLI_findptr, BLI_rfindptr --- use for finding an item in a linked list by a pointer.
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/intern/anim.c | 6 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/group.c | 22 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/scene.c | 17 |
3 files changed, 18 insertions, 27 deletions
diff --git a/source/blender/blenkernel/intern/anim.c b/source/blender/blenkernel/intern/anim.c index 111ac68b345..33cdede6fce 100644 --- a/source/blender/blenkernel/intern/anim.c +++ b/source/blender/blenkernel/intern/anim.c @@ -1279,9 +1279,9 @@ static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *p if (part->dup_group == NULL || part->dup_group->gobject.first == NULL) return; - for (go = part->dup_group->gobject.first; go; go = go->next) - if (go->ob == par) - return; + if (BLI_findptr(&part->dup_group->gobject, par, offsetof(GroupObject, ob))) { + return; + } } /* if we have a hair particle system, use the path cache */ diff --git a/source/blender/blenkernel/intern/group.c b/source/blender/blenkernel/intern/group.c index 89341845615..500df1b7b75 100644 --- a/source/blender/blenkernel/intern/group.c +++ b/source/blender/blenkernel/intern/group.c @@ -161,11 +161,13 @@ static int add_to_group_internal(Group *group, Object *ob) { GroupObject *go; - if (group == NULL || ob == NULL) return 0; + if (group == NULL || ob == NULL) { + return FALSE; + } /* check if the object has been added already */ - for (go = group->gobject.first; go; go = go->next) { - if (go->ob == ob) return 0; + if (BLI_findptr(&group->gobject, ob, offsetof(GroupObject, ob))) { + return FALSE; } go = MEM_callocN(sizeof(GroupObject), "groupobject"); @@ -173,7 +175,7 @@ static int add_to_group_internal(Group *group, Object *ob) go->ob = ob; - return 1; + return TRUE; } int add_to_group(Group *group, Object *object, Scene *scene, Base *base) @@ -239,15 +241,11 @@ int rem_from_group(Group *group, Object *object, Scene *scene, Base *base) int object_in_group(Object *ob, Group *group) { - GroupObject *go; - - if (group == NULL || ob == NULL) return 0; - - for (go = group->gobject.first; go; go = go->next) { - if (go->ob == ob) - return 1; + if (group == NULL || ob == NULL) { + return FALSE; } - return 0; + + return (BLI_findptr(&group->gobject, ob, offsetof(GroupObject, ob)) != NULL); } Group *find_group(Object *ob, Group *group) diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c index 889792ad3f8..d476e90498c 100644 --- a/source/blender/blenkernel/intern/scene.c +++ b/source/blender/blenkernel/intern/scene.c @@ -550,14 +550,7 @@ Scene *BKE_scene_add(const char *name) Base *BKE_scene_base_find(Scene *scene, Object *ob) { - Base *base; - - base = scene->base.first; - while (base) { - if (base->object == ob) return base; - base = base->next; - } - return NULL; + return BLI_findptr(&scene->base, ob, offsetof(Base, object)); } void BKE_scene_set_background(Main *bmain, Scene *scene) @@ -582,10 +575,10 @@ void BKE_scene_set_background(Main *bmain, Scene *scene) /* group flags again */ for (group = bmain->group.first; group; group = group->id.next) { - go = group->gobject.first; - while (go) { - if (go->ob) go->ob->flag |= OB_FROMGROUP; - go = go->next; + for (go = group->gobject.first; go; go = go->next) { + if (go->ob) { + go->ob->flag |= OB_FROMGROUP; + } } } |