diff options
author | Dalai Felinto <dalai@blender.org> | 2020-04-03 20:15:01 +0300 |
---|---|---|
committer | Dalai Felinto <dalai@blender.org> | 2020-04-03 20:27:46 +0300 |
commit | d138cbfb47e379edc1ee915a8c6ff65b01f000d6 (patch) | |
tree | f4773ecce897c32eaf75295dd5f6a8e730d471ed /source/blender/blenkernel | |
parent | b0c1184875d39abac4a65a5d20e263ea6d841009 (diff) |
Code Quality: Replace for loops with LISTBASE_FOREACH
Note this only changes cases where the variable was declared inside
the for loop. To handle it outside as well is a different challenge.
Differential Revision: https://developer.blender.org/D7320
Diffstat (limited to 'source/blender/blenkernel')
38 files changed, 195 insertions, 224 deletions
diff --git a/source/blender/blenkernel/intern/anim_data.c b/source/blender/blenkernel/intern/anim_data.c index cd56796c3cf..41bfc5b59e4 100644 --- a/source/blender/blenkernel/intern/anim_data.c +++ b/source/blender/blenkernel/intern/anim_data.c @@ -1130,7 +1130,7 @@ bool BKE_animdata_fix_paths_remove(ID *id, const char *prefix) /* free drivers - stored as a list of F-Curves */ any_removed |= fcurves_path_remove_fix(prefix, &adt->drivers); /* NLA Data - Animation Data for Strips */ - for (NlaTrack *nlt = adt->nla_tracks.first; nlt; nlt = nlt->next) { + LISTBASE_FOREACH (NlaTrack *, nlt, &adt->nla_tracks) { any_removed |= nlastrips_path_remove_fix(prefix, &nlt->strips); } } diff --git a/source/blender/blenkernel/intern/anim_sys.c b/source/blender/blenkernel/intern/anim_sys.c index 69efac37fbf..18320ef0f8d 100644 --- a/source/blender/blenkernel/intern/anim_sys.c +++ b/source/blender/blenkernel/intern/anim_sys.c @@ -542,7 +542,7 @@ static void animsys_evaluate_fcurves(PointerRNA *ptr, bool flush_to_original) { /* Calculate then execute each curve. */ - for (FCurve *fcu = list->first; fcu; fcu = fcu->next) { + LISTBASE_FOREACH (FCurve *, fcu, list) { /* Check if this F-Curve doesn't belong to a muted group. */ if ((fcu->grp != NULL) && (fcu->grp->flag & AGRP_MUTED)) { continue; @@ -1095,7 +1095,7 @@ static void nlaeval_free(NlaEvalData *nlaeval) nlaeval_snapshot_free_data(&nlaeval->eval_snapshot); /* Delete channels. */ - for (NlaEvalChannel *nec = nlaeval->channels.first; nec; nec = nec->next) { + LISTBASE_FOREACH (NlaEvalChannel *, nec, &nlaeval->channels) { nlaevalchan_free_data(nec); } @@ -1954,7 +1954,7 @@ void nladata_flush_channels(PointerRNA *ptr, } /* for each channel with accumulated values, write its value on the property it affects */ - for (NlaEvalChannel *nec = channels->channels.first; nec; nec = nec->next) { + LISTBASE_FOREACH (NlaEvalChannel *, nec, &channels->channels) { NlaEvalChannelSnapshot *nec_snapshot = nlaeval_snapshot_find_channel(snapshot, nec); PathResolvedRNA rna = {nec->key.ptr, nec->key.prop, -1}; @@ -1985,7 +1985,7 @@ static void nla_eval_domain_action(PointerRNA *ptr, return; } - for (FCurve *fcu = act->curves.first; fcu; fcu = fcu->next) { + LISTBASE_FOREACH (FCurve *, fcu, &act->curves) { /* check if this curve should be skipped */ if (fcu->flag & (FCURVE_MUTED | FCURVE_DISABLED)) { continue; @@ -2020,7 +2020,7 @@ static void nla_eval_domain_strips(PointerRNA *ptr, ListBase *strips, GSet *touched_actions) { - for (NlaStrip *strip = strips->first; strip; strip = strip->next) { + LISTBASE_FOREACH (NlaStrip *, strip, strips) { /* check strip's action */ if (strip->act) { nla_eval_domain_action(ptr, channels, strip->act, touched_actions); @@ -2044,7 +2044,7 @@ static void animsys_evaluate_nla_domain(PointerRNA *ptr, NlaEvalData *channels, } /* NLA Data - Animation Data for Strips */ - for (NlaTrack *nlt = adt->nla_tracks.first; nlt; nlt = nlt->next) { + LISTBASE_FOREACH (NlaTrack *, nlt, &adt->nla_tracks) { /* solo and muting are mutually exclusive... */ if (adt->flag & ADT_NLA_SOLO_TRACK) { /* skip if there is a solo track, but this isn't it */ @@ -2430,7 +2430,7 @@ bool BKE_animsys_nla_remap_keyframe_values(struct NlaKeyframingContext *context, */ void BKE_animsys_free_nla_keyframing_context_cache(struct ListBase *cache) { - for (NlaKeyframingContext *ctx = cache->first; ctx; ctx = ctx->next) { + LISTBASE_FOREACH (NlaKeyframingContext *, ctx, cache) { MEM_SAFE_FREE(ctx->eval_strip); nlaeval_free(&ctx->nla_channels); } @@ -2738,7 +2738,7 @@ void BKE_animsys_update_driver_array(ID *id) adt->driver_array = MEM_mallocN(sizeof(FCurve *) * num_drivers, "adt->driver_array"); int driver_index = 0; - for (FCurve *fcu = adt->drivers.first; fcu; fcu = fcu->next) { + LISTBASE_FOREACH (FCurve *, fcu, &adt->drivers) { adt->driver_array[driver_index++] = fcu; } } diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c index b8d0f8c8c92..daf364432f4 100644 --- a/source/blender/blenkernel/intern/armature.c +++ b/source/blender/blenkernel/intern/armature.c @@ -190,7 +190,7 @@ bArmature *BKE_armature_from_object(Object *ob) int BKE_armature_bonelist_count(ListBase *lb) { int i = 0; - for (Bone *bone = lb->first; bone; bone = bone->next) { + LISTBASE_FOREACH (Bone *, bone, lb) { i += 1 + BKE_armature_bonelist_count(&bone->childbase); } @@ -303,7 +303,7 @@ static void armature_transform_recurse(ListBase *bonebase, const Bone *bone_parent, const float arm_mat_parent_inv[4][4]) { - for (Bone *bone = bonebase->first; bone; bone = bone->next) { + LISTBASE_FOREACH (Bone *, bone, bonebase) { /* Store the initial bone roll in a matrix, this is needed even for child bones * so any change in head/tail doesn't cause the roll to change. @@ -424,7 +424,7 @@ Bone *BKE_armature_find_bone_name(bArmature *arm, const char *name) static void armature_bone_from_name_insert_recursive(GHash *bone_hash, ListBase *lb) { - for (Bone *bone = lb->first; bone; bone = bone->next) { + LISTBASE_FOREACH (Bone *, bone, lb) { BLI_ghash_insert(bone_hash, bone->name, bone); armature_bone_from_name_insert_recursive(bone_hash, &bone->childbase); } @@ -474,7 +474,7 @@ bool BKE_armature_bone_flag_test_recursive(const Bone *bone, int flag) static void armature_refresh_layer_used_recursive(bArmature *arm, ListBase *bones) { - for (Bone *bone = bones->first; bone; bone = bone->next) { + LISTBASE_FOREACH (Bone *, bone, bones) { arm->layer_used |= bone->layer; armature_refresh_layer_used_recursive(arm, &bone->childbase); } @@ -2701,7 +2701,7 @@ static int rebuild_pose_bone(bPose *pose, Bone *bone, bPoseChannel *parchan, int */ void BKE_pose_clear_pointers(bPose *pose) { - for (bPoseChannel *pchan = pose->chanbase.first; pchan; pchan = pchan->next) { + LISTBASE_FOREACH (bPoseChannel *, pchan, &pose->chanbase) { pchan->bone = NULL; pchan->child = NULL; } @@ -2709,7 +2709,7 @@ void BKE_pose_clear_pointers(bPose *pose) void BKE_pose_remap_bone_pointers(bArmature *armature, bPose *pose) { - for (bPoseChannel *pchan = pose->chanbase.first; pchan; pchan = pchan->next) { + LISTBASE_FOREACH (bPoseChannel *, pchan, &pose->chanbase) { pchan->bone = BKE_armature_find_bone_name(armature, pchan->name); } } diff --git a/source/blender/blenkernel/intern/blender.c b/source/blender/blenkernel/intern/blender.c index 70ab52828f2..b3a4de02451 100644 --- a/source/blender/blenkernel/intern/blender.c +++ b/source/blender/blenkernel/intern/blender.c @@ -182,7 +182,7 @@ static void userdef_free_keymaps(UserDef *userdef) { for (wmKeyMap *km = userdef->user_keymaps.first, *km_next; km; km = km_next) { km_next = km->next; - for (wmKeyMapDiffItem *kmdi = km->diff_items.first; kmdi; kmdi = kmdi->next) { + LISTBASE_FOREACH (wmKeyMapDiffItem *, kmdi, &km->diff_items) { if (kmdi->add_item) { keymap_item_free(kmdi->add_item); MEM_freeN(kmdi->add_item); @@ -193,7 +193,7 @@ static void userdef_free_keymaps(UserDef *userdef) } } - for (wmKeyMapItem *kmi = km->items.first; kmi; kmi = kmi->next) { + LISTBASE_FOREACH (wmKeyMapItem *, kmi, &km->items) { keymap_item_free(kmi); } @@ -250,7 +250,7 @@ void BKE_blender_userdef_data_free(UserDef *userdef, bool clear_fonts) userdef_free_addons(userdef); if (clear_fonts) { - for (uiFont *font = userdef->uifonts.first; font; font = font->next) { + LISTBASE_FOREACH (uiFont *, font, &userdef->uifonts) { BLF_unload_id(font->blf_id); } BLF_default_set(-1); diff --git a/source/blender/blenkernel/intern/blender_user_menu.c b/source/blender/blenkernel/intern/blender_user_menu.c index ad34ef03e04..edd89357fd5 100644 --- a/source/blender/blenkernel/intern/blender_user_menu.c +++ b/source/blender/blenkernel/intern/blender_user_menu.c @@ -38,7 +38,7 @@ bUserMenu *BKE_blender_user_menu_find(ListBase *lb, char space_type, const char *context) { - for (bUserMenu *um = lb->first; um; um = um->next) { + LISTBASE_FOREACH (bUserMenu *, um, lb) { if ((space_type == um->space_type) && (STREQ(context, um->context))) { return um; } diff --git a/source/blender/blenkernel/intern/blendfile.c b/source/blender/blenkernel/intern/blendfile.c index 6bf47a8c280..d862132480a 100644 --- a/source/blender/blenkernel/intern/blendfile.c +++ b/source/blender/blenkernel/intern/blendfile.c @@ -345,7 +345,7 @@ static void setup_app_data(bContext *C, wmWindowManager *wm = bmain->wm.first; if (wm) { - for (wmWindow *win = wm->windows.first; win; win = win->next) { + LISTBASE_FOREACH (wmWindow *, win, &wm->windows) { if (win->scene && win->scene != curscene) { BKE_scene_set_background(bmain, win->scene); } diff --git a/source/blender/blenkernel/intern/camera.c b/source/blender/blenkernel/intern/camera.c index 323bb597127..71a2b6f703a 100644 --- a/source/blender/blenkernel/intern/camera.c +++ b/source/blender/blenkernel/intern/camera.c @@ -912,7 +912,7 @@ static Object *camera_multiview_advanced(const Scene *scene, Object *camera, con name[0] = '\0'; /* we need to take the better match, thus the len_suffix_max test */ - for (const SceneRenderView *srv = scene->r.views.first; srv; srv = srv->next) { + LISTBASE_FOREACH (const SceneRenderView *, srv, &scene->r.views) { const int len_suffix = strlen(srv->suffix); if ((len_suffix < len_suffix_max) || (len_name < len_suffix)) { diff --git a/source/blender/blenkernel/intern/collection.c b/source/blender/blenkernel/intern/collection.c index d39df4cc6a3..83a6949430e 100644 --- a/source/blender/blenkernel/intern/collection.c +++ b/source/blender/blenkernel/intern/collection.c @@ -106,10 +106,10 @@ static void collection_copy_data(Main *bmain, ID *id_dst, const ID *id_src, cons BLI_listbase_clear(&collection_dst->children); BLI_listbase_clear(&collection_dst->parents); - for (CollectionChild *child = collection_src->children.first; child; child = child->next) { + LISTBASE_FOREACH (CollectionChild *, child, &collection_src->children) { collection_child_add(collection_dst, child->collection, flag, false); } - for (CollectionObject *cob = collection_src->gobject.first; cob; cob = cob->next) { + LISTBASE_FOREACH (CollectionObject *, cob, &collection_src->gobject) { collection_object_add(bmain, collection_dst, cob->ob, flag, false); } } @@ -223,9 +223,8 @@ bool BKE_collection_delete(Main *bmain, Collection *collection, bool hierarchy) } else { /* Link child collections into parent collection. */ - for (CollectionChild *child = collection->children.first; child; child = child->next) { - for (CollectionParent *cparent = collection->parents.first; cparent; - cparent = cparent->next) { + LISTBASE_FOREACH (CollectionChild *, child, &collection->children) { + LISTBASE_FOREACH (CollectionParent *, cparent, &collection->parents) { Collection *parent = cparent->collection; collection_child_add(parent, child->collection, 0, true); } @@ -234,8 +233,7 @@ bool BKE_collection_delete(Main *bmain, Collection *collection, bool hierarchy) CollectionObject *cob = collection->gobject.first; while (cob != NULL) { /* Link child object into parent collections. */ - for (CollectionParent *cparent = collection->parents.first; cparent; - cparent = cparent->next) { + LISTBASE_FOREACH (CollectionParent *, cparent, &collection->parents) { Collection *parent = cparent->collection; collection_object_add(bmain, parent, cob->ob, 0, true); } @@ -305,7 +303,7 @@ static Collection *collection_duplicate_recursive(Main *bmain, if (do_objects) { /* We can loop on collection_old's objects, that list is currently identical the collection_new * objects, and won't be changed here. */ - for (CollectionObject *cob = collection_old->gobject.first; cob; cob = cob->next) { + LISTBASE_FOREACH (CollectionObject *, cob, &collection_old->gobject) { Object *ob_old = cob->ob; Object *ob_new = (Object *)ob_old->id.newid; @@ -321,7 +319,7 @@ static Collection *collection_duplicate_recursive(Main *bmain, /* We can loop on collection_old's children, * that list is currently identical the collection_new' children, and won't be changed here. */ - for (CollectionChild *child = collection_old->children.first; child; child = child->next) { + LISTBASE_FOREACH (CollectionChild *, child, &collection_old->children) { Collection *child_collection_old = child->collection; collection_duplicate_recursive( @@ -440,7 +438,7 @@ static void collection_object_cache_fill(ListBase *lb, Collection *collection, i { int child_restrict = collection->flag | parent_restrict; - for (CollectionObject *cob = collection->gobject.first; cob; cob = cob->next) { + LISTBASE_FOREACH (CollectionObject *, cob, &collection->gobject) { Base *base = BLI_findptr(lb, cob->ob, offsetof(Base, object)); if (base == NULL) { @@ -460,7 +458,7 @@ static void collection_object_cache_fill(ListBase *lb, Collection *collection, i } } - for (CollectionChild *child = collection->children.first; child; child = child->next) { + LISTBASE_FOREACH (CollectionChild *, child, &collection->children) { collection_object_cache_fill(lb, child->collection, child_restrict); } } @@ -487,7 +485,7 @@ static void collection_object_cache_free(Collection *collection) collection->flag &= ~COLLECTION_HAS_OBJECT_CACHE; BLI_freelistN(&collection->object_cache); - for (CollectionParent *parent = collection->parents.first; parent; parent = parent->next) { + LISTBASE_FOREACH (CollectionParent *, parent, &collection->parents) { collection_object_cache_free(parent->collection); } } @@ -645,8 +643,7 @@ static void collection_tag_update_parent_recursive(Main *bmain, DEG_id_tag_update_ex(bmain, &collection->id, flag); - for (CollectionParent *collection_parent = collection->parents.first; collection_parent; - collection_parent = collection_parent->next) { + LISTBASE_FOREACH (CollectionParent *, collection_parent, &collection->parents) { if (collection_parent->collection->flag & COLLECTION_IS_MASTER) { /* We don't care about scene/master collection here. */ continue; @@ -952,7 +949,7 @@ bool BKE_collection_is_in_scene(Collection *collection) return true; } - for (CollectionParent *cparent = collection->parents.first; cparent; cparent = cparent->next) { + LISTBASE_FOREACH (CollectionParent *, cparent, &collection->parents) { if (BKE_collection_is_in_scene(cparent->collection)) { return true; } @@ -977,7 +974,7 @@ bool BKE_collection_find_cycle(Collection *new_ancestor, Collection *collection) return true; } - for (CollectionParent *parent = new_ancestor->parents.first; parent; parent = parent->next) { + LISTBASE_FOREACH (CollectionParent *, parent, &new_ancestor->parents) { if (BKE_collection_find_cycle(parent->collection, collection)) { return true; } @@ -993,7 +990,7 @@ static CollectionChild *collection_find_child(Collection *parent, Collection *co static bool collection_find_child_recursive(Collection *parent, Collection *collection) { - for (CollectionChild *child = parent->children.first; child; child = child->next) { + LISTBASE_FOREACH (CollectionChild *, child, &parent->children) { if (child->collection == collection) { return true; } @@ -1168,7 +1165,7 @@ static Collection *collection_from_index_recursive(Collection *collection, (*index_current)++; - for (CollectionChild *child = collection->children.first; child; child = child->next) { + LISTBASE_FOREACH (CollectionChild *, child, &collection->children) { Collection *nested = collection_from_index_recursive(child->collection, index, index_current); if (nested != NULL) { return nested; @@ -1197,7 +1194,7 @@ static bool collection_objects_select(ViewLayer *view_layer, Collection *collect return false; } - for (CollectionObject *cob = collection->gobject.first; cob; cob = cob->next) { + LISTBASE_FOREACH (CollectionObject *, cob, &collection->gobject) { Base *base = BKE_view_layer_base_find(view_layer, cob->ob); if (base) { @@ -1216,7 +1213,7 @@ static bool collection_objects_select(ViewLayer *view_layer, Collection *collect } } - for (CollectionChild *child = collection->children.first; child; child = child->next) { + LISTBASE_FOREACH (CollectionChild *, child, &collection->children) { if (collection_objects_select(view_layer, collection, deselect)) { changed = true; } @@ -1289,8 +1286,7 @@ bool BKE_collection_move(Main *bmain, GHash *view_layer_hash = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, __func__); for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) { - for (ViewLayer *view_layer = scene->view_layers.first; view_layer; - view_layer = view_layer->next) { + LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) { LayerCollection *layer_collection = BKE_layer_collection_first_from_scene_collection( view_layer, collection); @@ -1352,7 +1348,7 @@ static void scene_collection_callback(Collection *collection, { callback(collection, data); - for (CollectionChild *child = collection->children.first; child; child = child->next) { + LISTBASE_FOREACH (CollectionChild *, child, &collection->children) { scene_collection_callback(child->collection, callback, data); } } diff --git a/source/blender/blenkernel/intern/collision.c b/source/blender/blenkernel/intern/collision.c index 9230746cd1d..7cc40007e26 100644 --- a/source/blender/blenkernel/intern/collision.c +++ b/source/blender/blenkernel/intern/collision.c @@ -1380,7 +1380,7 @@ Object **BKE_collision_objects_create(Depsgraph *depsgraph, int num = 0; Object **objects = MEM_callocN(sizeof(Object *) * maxnum, __func__); - for (CollisionRelation *relation = relations->first; relation; relation = relation->next) { + LISTBASE_FOREACH (CollisionRelation *, relation, relations) { /* Get evaluated object. */ Object *ob = (Object *)DEG_get_evaluated_id(depsgraph, &relation->ob->id); @@ -1418,7 +1418,7 @@ ListBase *BKE_collider_cache_create(Depsgraph *depsgraph, Object *self, Collecti return NULL; } - for (CollisionRelation *relation = relations->first; relation; relation = relation->next) { + LISTBASE_FOREACH (CollisionRelation *, relation, relations) { /* Get evaluated object. */ Object *ob = (Object *)DEG_get_evaluated_id(depsgraph, &relation->ob->id); diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c index 28ce62c3de2..c91bf4e7f5b 100644 --- a/source/blender/blenkernel/intern/constraint.c +++ b/source/blender/blenkernel/intern/constraint.c @@ -2513,7 +2513,7 @@ static void armdef_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *targ /* Process all targets. This can't use ct->matrix, as armdef_get_tarmat is not * called in solve for efficiency because the constraint needs bone data anyway. */ - for (bConstraintTarget *ct = targets->first; ct; ct = ct->next) { + LISTBASE_FOREACH (bConstraintTarget *, ct, targets) { if (ct->weight <= 0.0f) { continue; } @@ -5497,7 +5497,7 @@ void BKE_constraints_active_set(ListBase *list, bConstraint *con) static bConstraint *constraint_list_find_from_target(ListBase *constraints, bConstraintTarget *tgt) { - for (bConstraint *con = constraints->first; con; con = con->next) { + LISTBASE_FOREACH (bConstraint *, con, constraints) { ListBase *targets = NULL; if (con->type == CONSTRAINT_TYPE_PYTHON) { @@ -5531,7 +5531,7 @@ bConstraint *BKE_constraint_find_from_target(Object *ob, } if (ob->pose != NULL) { - for (bPoseChannel *pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) { + LISTBASE_FOREACH (bPoseChannel *, pchan, &ob->pose->chanbase) { result = constraint_list_find_from_target(&pchan->constraints, tgt); if (result != NULL) { diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c index 51912e3375a..5b463059f18 100644 --- a/source/blender/blenkernel/intern/curve.c +++ b/source/blender/blenkernel/intern/curve.c @@ -4612,7 +4612,7 @@ void BKE_nurb_direction_switch(Nurb *nu) void BKE_curve_nurbs_vert_coords_get(ListBase *lb, float (*vert_coords)[3], int vert_len) { float *co = vert_coords[0]; - for (Nurb *nu = lb->first; nu; nu = nu->next) { + LISTBASE_FOREACH (Nurb *, nu, lb) { if (nu->type == CU_BEZIER) { BezTriple *bezt = nu->bezt; for (int i = 0; i < nu->pntsu; i++, bezt++) { @@ -4692,7 +4692,7 @@ void BKE_curve_nurbs_vert_coords_apply(ListBase *lb, { const float *co = vert_coords[0]; - for (Nurb *nu = lb->first; nu; nu = nu->next) { + LISTBASE_FOREACH (Nurb *, nu, lb) { if (nu->type == CU_BEZIER) { BezTriple *bezt = nu->bezt; @@ -4730,7 +4730,7 @@ float (*BKE_curve_nurbs_key_vert_coords_alloc(ListBase *lb, float *key, int *r_v float(*cos)[3] = MEM_malloc_arrayN(vert_len, sizeof(*cos), __func__); float *co = cos[0]; - for (Nurb *nu = lb->first; nu; nu = nu->next) { + LISTBASE_FOREACH (Nurb *, nu, lb) { if (nu->type == CU_BEZIER) { BezTriple *bezt = nu->bezt; @@ -5168,7 +5168,7 @@ bool BKE_curve_minmax(Curve *cu, bool use_radius, float min[3], float max[3]) use_radius = false; } /* Do bounding box based on splines. */ - for (Nurb *nu = nurb_lb->first; nu; nu = nu->next) { + LISTBASE_FOREACH (Nurb *, nu, nurb_lb) { BKE_nurb_minmax(nu, use_radius, min, max); } const bool result = (BLI_listbase_is_empty(nurb_lb) == false); diff --git a/source/blender/blenkernel/intern/effect.c b/source/blender/blenkernel/intern/effect.c index 984a7a12b94..e1e818a5a34 100644 --- a/source/blender/blenkernel/intern/effect.c +++ b/source/blender/blenkernel/intern/effect.c @@ -247,7 +247,7 @@ ListBase *BKE_effector_relations_create(Depsgraph *depsgraph, add_effector_relation(relations, ob, NULL, ob->pd); } - for (ParticleSystem *psys = ob->particlesystem.first; psys; psys = psys->next) { + LISTBASE_FOREACH (ParticleSystem *, psys, &ob->particlesystem) { ParticleSettings *part = psys->part; if (psys_check_enabled(ob, psys, for_render)) { @@ -286,7 +286,7 @@ ListBase *BKE_effectors_create(Depsgraph *depsgraph, return NULL; } - for (EffectorRelation *relation = relations->first; relation; relation = relation->next) { + LISTBASE_FOREACH (EffectorRelation *, relation, relations) { /* Get evaluated object. */ Object *ob = (Object *)DEG_get_evaluated_id(depsgraph, &relation->ob->id); @@ -329,7 +329,7 @@ ListBase *BKE_effectors_create(Depsgraph *depsgraph, void BKE_effectors_free(ListBase *lb) { if (lb) { - for (EffectorCache *eff = lb->first; eff; eff = eff->next) { + LISTBASE_FOREACH (EffectorCache *, eff, lb) { if (eff->guide_data) { MEM_freeN(eff->guide_data); } diff --git a/source/blender/blenkernel/intern/fcurve.c b/source/blender/blenkernel/intern/fcurve.c index fbca09001d6..439992a4113 100644 --- a/source/blender/blenkernel/intern/fcurve.c +++ b/source/blender/blenkernel/intern/fcurve.c @@ -1944,7 +1944,7 @@ void driver_variables_copy(ListBase *dst_vars, const ListBase *src_vars) BLI_assert(BLI_listbase_is_empty(dst_vars)); BLI_duplicatelist(dst_vars, src_vars); - for (DriverVar *dvar = dst_vars->first; dvar; dvar = dvar->next) { + LISTBASE_FOREACH (DriverVar *, dvar, dst_vars) { /* need to go over all targets so that we don't leave any dangling paths */ DRIVER_TARGETS_LOOPER_BEGIN (dvar) { /* make a copy of target's rna path if available */ @@ -2167,7 +2167,7 @@ static ExprPyLike_Parsed *driver_compile_simple_expr_impl(ChannelDriver *driver) names[VAR_INDEX_FRAME] = "frame"; - for (DriverVar *dvar = driver->variables.first; dvar; dvar = dvar->next) { + LISTBASE_FOREACH (DriverVar *, dvar, &driver->variables) { names[i++] = dvar->name; } @@ -2192,7 +2192,7 @@ static bool driver_evaluate_simple_expr(ChannelDriver *driver, vars[VAR_INDEX_FRAME] = time; - for (DriverVar *dvar = driver->variables.first; dvar; dvar = dvar->next) { + LISTBASE_FOREACH (DriverVar *, dvar, &driver->variables) { vars[i++] = driver_get_variable_value(driver, dvar); } diff --git a/source/blender/blenkernel/intern/fmodifier.c b/source/blender/blenkernel/intern/fmodifier.c index 1d5a908e226..c85283e3653 100644 --- a/source/blender/blenkernel/intern/fmodifier.c +++ b/source/blender/blenkernel/intern/fmodifier.c @@ -1358,7 +1358,7 @@ uint evaluate_fmodifiers_storage_size_per_modifier(ListBase *modifiers) uint max_size = 0; - for (FModifier *fcm = modifiers->first; fcm; fcm = fcm->next) { + LISTBASE_FOREACH (FModifier *, fcm, modifiers) { const FModifierTypeInfo *fmi = fmodifier_get_typeinfo(fcm); if (fmi == NULL) { diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c index b2fc91fd0a6..a0fa07f4a41 100644 --- a/source/blender/blenkernel/intern/gpencil.c +++ b/source/blender/blenkernel/intern/gpencil.c @@ -644,7 +644,7 @@ bGPDframe *BKE_gpencil_frame_duplicate(const bGPDframe *gpf_src) /* copy strokes */ BLI_listbase_clear(&gpf_dst->strokes); - for (bGPDstroke *gps_src = gpf_src->strokes.first; gps_src; gps_src = gps_src->next) { + LISTBASE_FOREACH (bGPDstroke *, gps_src, &gpf_src->strokes) { /* make copy of source stroke */ gps_dst = BKE_gpencil_stroke_duplicate(gps_src, true); BLI_addtail(&gpf_dst->strokes, gps_dst); @@ -665,7 +665,7 @@ void BKE_gpencil_frame_copy_strokes(bGPDframe *gpf_src, struct bGPDframe *gpf_ds /* copy strokes */ BLI_listbase_clear(&gpf_dst->strokes); - for (bGPDstroke *gps_src = gpf_src->strokes.first; gps_src; gps_src = gps_src->next) { + LISTBASE_FOREACH (bGPDstroke *, gps_src, &gpf_src->strokes) { /* make copy of source stroke */ gps_dst = BKE_gpencil_stroke_duplicate(gps_src, true); BLI_addtail(&gpf_dst->strokes, gps_dst); diff --git a/source/blender/blenkernel/intern/gpencil_geom.c b/source/blender/blenkernel/intern/gpencil_geom.c index 6bdcc9cfbcb..874672f4a73 100644 --- a/source/blender/blenkernel/intern/gpencil_geom.c +++ b/source/blender/blenkernel/intern/gpencil_geom.c @@ -1685,7 +1685,7 @@ static Collection *gpencil_get_parent_collection(Scene *scene, Object *ob) { Collection *mycol = NULL; FOREACH_SCENE_COLLECTION_BEGIN (scene, collection) { - for (CollectionObject *cob = collection->gobject.first; cob; cob = cob->next) { + LISTBASE_FOREACH (CollectionObject *, cob, &collection->gobject) { if ((mycol == NULL) && (cob->ob == ob)) { mycol = collection; } @@ -1976,7 +1976,7 @@ void BKE_gpencil_convert_curve(Main *bmain, bGPDframe *gpf = BKE_gpencil_layer_frame_get(gpl, CFRA, GP_GETFRAME_ADD_COPY); /* Read all splines of the curve and create a stroke for each. */ - for (Nurb *nu = cu->nurb.first; nu; nu = nu->next) { + LISTBASE_FOREACH (Nurb *, nu, &cu->nurb) { gpencil_convert_spline(bmain, ob_gp, ob_cu, gpencil_lines, only_stroke, gpf, nu); } diff --git a/source/blender/blenkernel/intern/idprop.c b/source/blender/blenkernel/intern/idprop.c index 554b8d93db3..5530a126ffc 100644 --- a/source/blender/blenkernel/intern/idprop.c +++ b/source/blender/blenkernel/intern/idprop.c @@ -800,7 +800,7 @@ void IDP_RelinkProperty(struct IDProperty *prop) switch (prop->type) { case IDP_GROUP: { - for (IDProperty *loop = prop->data.group.first; loop; loop = loop->next) { + LISTBASE_FOREACH (IDProperty *, loop, &prop->data.group) { IDP_RelinkProperty(loop); } break; diff --git a/source/blender/blenkernel/intern/idprop_utils.c b/source/blender/blenkernel/intern/idprop_utils.c index 629fecf42f4..f8a1113f69b 100644 --- a/source/blender/blenkernel/intern/idprop_utils.c +++ b/source/blender/blenkernel/intern/idprop_utils.c @@ -167,7 +167,7 @@ static void idp_repr_fn_recursive(struct ReprState *state, const IDProperty *pro } case IDP_GROUP: { STR_APPEND_STR("{"); - for (const IDProperty *subprop = prop->data.group.first; subprop; subprop = subprop->next) { + LISTBASE_FOREACH (const IDProperty *, subprop, &prop->data.group) { if (subprop != prop->data.group.first) { STR_APPEND_STR(", "); } diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c index 0fb70869ac0..f58e7c06d7f 100644 --- a/source/blender/blenkernel/intern/image.c +++ b/source/blender/blenkernel/intern/image.c @@ -3101,7 +3101,7 @@ static void image_walk_ntree_all_users( { switch (ntree->type) { case NTREE_SHADER: - for (bNode *node = ntree->nodes.first; node; node = node->next) { + LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { if (node->id) { if (node->type == SH_NODE_TEX_IMAGE) { NodeTexImage *tex = node->storage; @@ -3117,7 +3117,7 @@ static void image_walk_ntree_all_users( } break; case NTREE_TEXTURE: - for (bNode *node = ntree->nodes.first; node; node = node->next) { + LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { if (node->id && node->type == TEX_NODE_IMAGE) { Image *ima = (Image *)node->id; ImageUser *iuser = node->storage; @@ -3126,7 +3126,7 @@ static void image_walk_ntree_all_users( } break; case NTREE_COMPOSIT: - for (bNode *node = ntree->nodes.first; node; node = node->next) { + LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { if (node->id && node->type == CMP_NODE_IMAGE) { Image *ima = (Image *)node->id; ImageUser *iuser = node->storage; @@ -3189,17 +3189,17 @@ static void image_walk_id_all_users( } case ID_CA: { Camera *cam = (Camera *)id; - for (CameraBGImage *bgpic = cam->bg_images.first; bgpic; bgpic = bgpic->next) { + LISTBASE_FOREACH (CameraBGImage *, bgpic, &cam->bg_images) { callback(bgpic->ima, NULL, &bgpic->iuser, customdata); } break; } case ID_WM: { wmWindowManager *wm = (wmWindowManager *)id; - for (wmWindow *win = wm->windows.first; win; win = win->next) { + LISTBASE_FOREACH (wmWindow *, win, &wm->windows) { const bScreen *screen = BKE_workspace_active_screen_get(win->workspace_hook); - for (ScrArea *area = screen->areabase.first; area; area = area->next) { + LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) { if (area->spacetype == SPACE_IMAGE) { SpaceImage *sima = area->spacedata.first; callback(sima->image, NULL, &sima->iuser, customdata); @@ -3761,7 +3761,7 @@ static void image_init_multilayer_multiview(Image *ima, RenderResult *rr) BKE_image_free_views(ima); if (rr) { - for (RenderView *rv = rr->views.first; rv; rv = rv->next) { + LISTBASE_FOREACH (RenderView *, rv, &rr->views) { ImageView *iv = MEM_callocN(sizeof(ImageView), "Viewer Image View"); STRNCPY(iv->name, rv->name); BLI_addtail(&ima->views, iv); diff --git a/source/blender/blenkernel/intern/keyconfig.c b/source/blender/blenkernel/intern/keyconfig.c index 84f48441cf9..ada5fc5b6aa 100644 --- a/source/blender/blenkernel/intern/keyconfig.c +++ b/source/blender/blenkernel/intern/keyconfig.c @@ -209,7 +209,7 @@ void BKE_keyconfig_pref_filter_items(struct UserDef *userdef, bool (*filter_fn)(wmKeyMapItem *kmi, void *user_data), void *user_data) { - for (wmKeyMap *keymap = userdef->user_keymaps.first; keymap; keymap = keymap->next) { + LISTBASE_FOREACH (wmKeyMap *, keymap, &userdef->user_keymaps) { BKE_keyconfig_keymap_filter_item(keymap, params, filter_fn, user_data); } } diff --git a/source/blender/blenkernel/intern/layer.c b/source/blender/blenkernel/intern/layer.c index ffa1eecc87b..d8f0bda8c22 100644 --- a/source/blender/blenkernel/intern/layer.c +++ b/source/blender/blenkernel/intern/layer.c @@ -83,7 +83,7 @@ static void layer_collection_free(ViewLayer *view_layer, LayerCollection *lc) view_layer->active_collection = NULL; } - for (LayerCollection *nlc = lc->layer_collections.first; nlc; nlc = nlc->next) { + LISTBASE_FOREACH (LayerCollection *, nlc, &lc->layer_collections) { layer_collection_free(view_layer, nlc); } @@ -109,8 +109,7 @@ static Base *object_base_new(Object *ob) * none linked to the workspace yet. */ ViewLayer *BKE_view_layer_default_view(const Scene *scene) { - for (ViewLayer *view_layer = scene->view_layers.first; view_layer; - view_layer = view_layer->next) { + LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) { if (!(view_layer->flag & VIEW_LAYER_RENDER)) { return view_layer; } @@ -123,8 +122,7 @@ ViewLayer *BKE_view_layer_default_view(const Scene *scene) /* Returns the default view layer to render if we need to render just one. */ ViewLayer *BKE_view_layer_default_render(const Scene *scene) { - for (ViewLayer *view_layer = scene->view_layers.first; view_layer; - view_layer = view_layer->next) { + LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) { if (view_layer->flag & VIEW_LAYER_RENDER) { return view_layer; } @@ -137,8 +135,7 @@ ViewLayer *BKE_view_layer_default_render(const Scene *scene) /* Returns view layer with matching name, or NULL if not found. */ ViewLayer *BKE_view_layer_find(const Scene *scene, const char *layer_name) { - for (ViewLayer *view_layer = scene->view_layers.first; view_layer; - view_layer = view_layer->next) { + LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) { if (STREQ(view_layer->name, layer_name)) { return view_layer; } @@ -262,12 +259,12 @@ void BKE_view_layer_free_ex(ViewLayer *view_layer, const bool do_id_user) BLI_ghash_free(view_layer->object_bases_hash, NULL, NULL); } - for (LayerCollection *lc = view_layer->layer_collections.first; lc; lc = lc->next) { + LISTBASE_FOREACH (LayerCollection *, lc, &view_layer->layer_collections) { layer_collection_free(view_layer, lc); } BLI_freelistN(&view_layer->layer_collections); - for (ViewLayerEngineData *sled = view_layer->drawdata.first; sled; sled = sled->next) { + LISTBASE_FOREACH (ViewLayerEngineData *, sled, &view_layer->drawdata) { if (sled->storage) { if (sled->free) { sled->free(sled->storage); @@ -295,7 +292,7 @@ void BKE_view_layer_free_ex(ViewLayer *view_layer, const bool do_id_user) */ void BKE_view_layer_selected_objects_tag(ViewLayer *view_layer, const int tag) { - for (Base *base = view_layer->object_bases.first; base; base = base->next) { + LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) { if ((base->flag & BASE_SELECTED) != 0) { base->object->flag |= tag; } @@ -307,7 +304,7 @@ void BKE_view_layer_selected_objects_tag(ViewLayer *view_layer, const int tag) static bool find_scene_collection_in_scene_collections(ListBase *lb, const LayerCollection *lc) { - for (LayerCollection *lcn = lb->first; lcn; lcn = lcn->next) { + LISTBASE_FOREACH (LayerCollection *, lcn, lb) { if (lcn == lc) { return true; } @@ -327,7 +324,7 @@ static bool find_scene_collection_in_scene_collections(ListBase *lb, const Layer */ Object *BKE_view_layer_camera_find(ViewLayer *view_layer) { - for (Base *base = view_layer->object_bases.first; base; base = base->next) { + LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) { if (base->object->type == OB_CAMERA) { return base->object; } @@ -341,8 +338,7 @@ Object *BKE_view_layer_camera_find(ViewLayer *view_layer) */ ViewLayer *BKE_view_layer_find_from_collection(const Scene *scene, LayerCollection *lc) { - for (ViewLayer *view_layer = scene->view_layers.first; view_layer; - view_layer = view_layer->next) { + LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) { if (find_scene_collection_in_scene_collections(&view_layer->layer_collections, lc)) { return view_layer; } @@ -364,7 +360,7 @@ static void view_layer_bases_hash_create(ViewLayer *view_layer) view_layer->object_bases_hash = BLI_ghash_new( BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, __func__); - for (Base *base = view_layer->object_bases.first; base; base = base->next) { + LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) { if (base->object) { BLI_ghash_insert(view_layer->object_bases_hash, base->object, base); } @@ -455,7 +451,7 @@ void BKE_view_layer_copy_data(Scene *scene_dst, /* Copy layer collections and object bases. */ /* Inline 'BLI_duplicatelist' and update the active base. */ BLI_listbase_clear(&view_layer_dst->object_bases); - for (Base *base_src = view_layer_src->object_bases.first; base_src; base_src = base_src->next) { + LISTBASE_FOREACH (Base *, base_src, &view_layer_src->object_bases) { Base *base_dst = MEM_dupallocN(base_src); BLI_addtail(&view_layer_dst->object_bases, base_dst); if (view_layer_src->basact == base_src) { @@ -506,7 +502,7 @@ void BKE_view_layer_rename(Main *bmain, Scene *scene, ViewLayer *view_layer, con /* WM can be missing on startup. */ wmWindowManager *wm = bmain->wm.first; if (wm) { - for (wmWindow *win = wm->windows.first; win; win = win->next) { + LISTBASE_FOREACH (wmWindow *, win, &wm->windows) { if (win->scene == scene && STREQ(win->view_layer_name, oldname)) { STRNCPY(win->view_layer_name, view_layer->name); } @@ -524,7 +520,7 @@ void BKE_view_layer_rename(Main *bmain, Scene *scene, ViewLayer *view_layer, con */ static LayerCollection *collection_from_index(ListBase *lb, const int number, int *i) { - for (LayerCollection *lc = lb->first; lc; lc = lc->next) { + LISTBASE_FOREACH (LayerCollection *, lc, lb) { if (*i == number) { return lc; } @@ -532,7 +528,7 @@ static LayerCollection *collection_from_index(ListBase *lb, const int number, in (*i)++; } - for (LayerCollection *lc = lb->first; lc; lc = lc->next) { + LISTBASE_FOREACH (LayerCollection *, lc, lb) { LayerCollection *lc_nested = collection_from_index(&lc->layer_collections, number, i); if (lc_nested) { return lc_nested; @@ -635,7 +631,7 @@ LayerCollection *BKE_layer_collection_activate_parent(ViewLayer *view_layer, Lay static int collection_count(ListBase *lb) { int i = 0; - for (LayerCollection *lc = lb->first; lc; lc = lc->next) { + LISTBASE_FOREACH (LayerCollection *, lc, lb) { i += collection_count(&lc->layer_collections) + 1; } return i; @@ -655,7 +651,7 @@ int BKE_layer_collection_count(ViewLayer *view_layer) */ static int index_from_collection(ListBase *lb, const LayerCollection *lc, int *i) { - for (LayerCollection *lcol = lb->first; lcol; lcol = lcol->next) { + LISTBASE_FOREACH (LayerCollection *, lcol, lb) { if (lcol == lc) { return *i; } @@ -663,7 +659,7 @@ static int index_from_collection(ListBase *lb, const LayerCollection *lc, int *i (*i)++; } - for (LayerCollection *lcol = lb->first; lcol; lcol = lcol->next) { + LISTBASE_FOREACH (LayerCollection *, lcol, lb) { int i_nested = index_from_collection(&lcol->layer_collections, lc, i); if (i_nested != -1) { return i_nested; @@ -733,7 +729,7 @@ static short layer_collection_sync(ViewLayer *view_layer, ListBase new_lb_layer = {NULL, NULL}; short runtime_flag = 0; - for (const CollectionChild *child = lb_scene->first; child; child = child->next) { + LISTBASE_FOREACH (const CollectionChild *, child, lb_scene) { Collection *collection = child->collection; LayerCollection *lc = BLI_findptr(lb_layer, collection, offsetof(LayerCollection, collection)); @@ -792,7 +788,7 @@ static short layer_collection_sync(ViewLayer *view_layer, } /* Sync objects, except if collection was excluded. */ - for (CollectionObject *cob = collection->gobject.first; cob; cob = cob->next) { + LISTBASE_FOREACH (CollectionObject *, cob, &collection->gobject) { if (cob->ob == NULL) { continue; } @@ -877,7 +873,7 @@ void BKE_layer_collection_sync(const Scene *scene, ViewLayer *view_layer) } /* Clear visible and selectable flags to be reset. */ - for (Base *base = view_layer->object_bases.first; base; base = base->next) { + LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) { base->flag &= ~g_base_collection_flags; base->flag_from_collection &= ~g_base_collection_flags; } @@ -898,7 +894,7 @@ void BKE_layer_collection_sync(const Scene *scene, ViewLayer *view_layer) ~(0)); /* Any remaining object bases are to be removed. */ - for (Base *base = view_layer->object_bases.first; base; base = base->next) { + LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) { if (view_layer->basact == base) { view_layer->basact = NULL; } @@ -911,7 +907,7 @@ void BKE_layer_collection_sync(const Scene *scene, ViewLayer *view_layer) BLI_freelistN(&view_layer->object_bases); view_layer->object_bases = new_object_bases; - for (Base *base = view_layer->object_bases.first; base; base = base->next) { + LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) { BKE_base_eval_flags(base); } @@ -927,8 +923,7 @@ void BKE_layer_collection_sync(const Scene *scene, ViewLayer *view_layer) void BKE_scene_collection_sync(const Scene *scene) { - for (ViewLayer *view_layer = scene->view_layers.first; view_layer; - view_layer = view_layer->next) { + LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) { BKE_layer_collection_sync(scene, view_layer); } } @@ -951,8 +946,7 @@ void BKE_main_collection_sync_remap(const Main *bmain) /* TODO: try to make this faster */ for (const Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) { - for (ViewLayer *view_layer = scene->view_layers.first; view_layer; - view_layer = view_layer->next) { + LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) { MEM_SAFE_FREE(view_layer->object_bases_array); if (view_layer->object_bases_hash) { @@ -988,7 +982,7 @@ bool BKE_layer_collection_objects_select(ViewLayer *view_layer, LayerCollection bool changed = false; if (!(lc->flag & LAYER_COLLECTION_EXCLUDE)) { - for (CollectionObject *cob = lc->collection->gobject.first; cob; cob = cob->next) { + LISTBASE_FOREACH (CollectionObject *, cob, &lc->collection->gobject) { Base *base = BKE_view_layer_base_find(view_layer, cob->ob); if (base) { @@ -1008,7 +1002,7 @@ bool BKE_layer_collection_objects_select(ViewLayer *view_layer, LayerCollection } } - for (LayerCollection *iter = lc->layer_collections.first; iter; iter = iter->next) { + LISTBASE_FOREACH (LayerCollection *, iter, &lc->layer_collections) { changed |= BKE_layer_collection_objects_select(view_layer, iter, deselect); } @@ -1022,7 +1016,7 @@ bool BKE_layer_collection_has_selected_objects(ViewLayer *view_layer, LayerColle } if (!(lc->flag & LAYER_COLLECTION_EXCLUDE)) { - for (CollectionObject *cob = lc->collection->gobject.first; cob; cob = cob->next) { + LISTBASE_FOREACH (CollectionObject *, cob, &lc->collection->gobject) { Base *base = BKE_view_layer_base_find(view_layer, cob->ob); if (base && (base->flag & BASE_SELECTED) && (base->flag & BASE_VISIBLE_DEPSGRAPH)) { @@ -1031,7 +1025,7 @@ bool BKE_layer_collection_has_selected_objects(ViewLayer *view_layer, LayerColle } } - for (LayerCollection *iter = lc->layer_collections.first; iter; iter = iter->next) { + LISTBASE_FOREACH (LayerCollection *, iter, &lc->layer_collections) { if (BKE_layer_collection_has_selected_objects(view_layer, iter)) { return true; } @@ -1047,8 +1041,7 @@ bool BKE_layer_collection_has_layer_collection(LayerCollection *lc_parent, return true; } - for (LayerCollection *lc_iter = lc_parent->layer_collections.first; lc_iter; - lc_iter = lc_iter->next) { + LISTBASE_FOREACH (LayerCollection *, lc_iter, &lc_parent->layer_collections) { if (BKE_layer_collection_has_layer_collection(lc_iter, lc_child)) { return true; } @@ -1063,7 +1056,7 @@ void BKE_base_set_visible(Scene *scene, ViewLayer *view_layer, Base *base, bool { if (!extend) { /* Make only one base visible. */ - for (Base *other = view_layer->object_bases.first; other; other = other->next) { + LISTBASE_FOREACH (Base *, other, &view_layer->object_bases) { other->flag |= BASE_HIDDEN; } @@ -1134,7 +1127,7 @@ bool BKE_object_is_visible_in_viewport(const struct View3D *v3d, const struct Ob static void layer_collection_flag_set_recursive(LayerCollection *lc, const int flag) { lc->flag |= flag; - for (LayerCollection *lc_iter = lc->layer_collections.first; lc_iter; lc_iter = lc_iter->next) { + LISTBASE_FOREACH (LayerCollection *, lc_iter, &lc->layer_collections) { layer_collection_flag_set_recursive(lc_iter, flag); } } @@ -1142,7 +1135,7 @@ static void layer_collection_flag_set_recursive(LayerCollection *lc, const int f static void layer_collection_flag_unset_recursive(LayerCollection *lc, const int flag) { lc->flag &= ~flag; - for (LayerCollection *lc_iter = lc->layer_collections.first; lc_iter; lc_iter = lc_iter->next) { + LISTBASE_FOREACH (LayerCollection *, lc_iter, &lc->layer_collections) { layer_collection_flag_unset_recursive(lc_iter, flag); } } @@ -1165,8 +1158,7 @@ void BKE_layer_collection_isolate_global(Scene *scene, if (!extend) { /* Hide all collections . */ - for (LayerCollection *lc_iter = lc_master->layer_collections.first; lc_iter; - lc_iter = lc_iter->next) { + LISTBASE_FOREACH (LayerCollection *, lc_iter, &lc_master->layer_collections) { layer_collection_flag_set_recursive(lc_iter, LAYER_COLLECTION_HIDE); } } @@ -1177,8 +1169,7 @@ void BKE_layer_collection_isolate_global(Scene *scene, } else { LayerCollection *lc_parent = lc; - for (LayerCollection *lc_iter = lc_master->layer_collections.first; lc_iter; - lc_iter = lc_iter->next) { + LISTBASE_FOREACH (LayerCollection *, lc_iter, &lc_master->layer_collections) { if (BKE_layer_collection_has_layer_collection(lc_iter, lc)) { lc_parent = lc_iter; break; @@ -1188,8 +1179,7 @@ void BKE_layer_collection_isolate_global(Scene *scene, while (lc_parent != lc) { lc_parent->flag &= ~LAYER_COLLECTION_HIDE; - for (LayerCollection *lc_iter = lc_parent->layer_collections.first; lc_iter; - lc_iter = lc_iter->next) { + LISTBASE_FOREACH (LayerCollection *, lc_iter, &lc_parent->layer_collections) { if (BKE_layer_collection_has_layer_collection(lc_iter, lc)) { lc_parent = lc_iter; break; @@ -1210,8 +1200,7 @@ static void layer_collection_local_visibility_set_recursive(LayerCollection *lay const int local_collections_uuid) { layer_collection->local_collections_bits |= local_collections_uuid; - for (LayerCollection *child = layer_collection->layer_collections.first; child; - child = child->next) { + LISTBASE_FOREACH (LayerCollection *, child, &layer_collection->layer_collections) { layer_collection_local_visibility_set_recursive(child, local_collections_uuid); } } @@ -1220,8 +1209,7 @@ static void layer_collection_local_visibility_unset_recursive(LayerCollection *l const int local_collections_uuid) { layer_collection->local_collections_bits &= ~local_collections_uuid; - for (LayerCollection *child = layer_collection->layer_collections.first; child; - child = child->next) { + LISTBASE_FOREACH (LayerCollection *, child, &layer_collection->layer_collections) { layer_collection_local_visibility_unset_recursive(child, local_collections_uuid); } } @@ -1236,8 +1224,7 @@ static void layer_collection_local_sync(ViewLayer *view_layer, } if (visible) { - for (CollectionObject *cob = layer_collection->collection->gobject.first; cob; - cob = cob->next) { + LISTBASE_FOREACH (CollectionObject *, cob, &layer_collection->collection->gobject) { BLI_assert(cob->ob); Base *base = BKE_view_layer_base_find(view_layer, cob->ob); base->local_collections_bits |= local_collections_uuid; @@ -1256,7 +1243,7 @@ void BKE_layer_collection_local_sync(ViewLayer *view_layer, View3D *v3d) const unsigned short local_collections_uuid = v3d->local_collections_uuid; /* Reset flags and set the bases visible by default. */ - for (Base *base = view_layer->object_bases.first; base; base = base->next) { + LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) { base->local_collections_bits &= ~local_collections_uuid; } @@ -1280,8 +1267,7 @@ void BKE_layer_collection_isolate_local(ViewLayer *view_layer, if (!extend) { /* Hide all collections. */ - for (LayerCollection *lc_iter = lc_master->layer_collections.first; lc_iter; - lc_iter = lc_iter->next) { + LISTBASE_FOREACH (LayerCollection *, lc_iter, &lc_master->layer_collections) { layer_collection_local_visibility_unset_recursive(lc_iter, v3d->local_collections_uuid); } } @@ -1292,8 +1278,7 @@ void BKE_layer_collection_isolate_local(ViewLayer *view_layer, } else { LayerCollection *lc_parent = lc; - for (LayerCollection *lc_iter = lc_master->layer_collections.first; lc_iter; - lc_iter = lc_iter->next) { + LISTBASE_FOREACH (LayerCollection *, lc_iter, &lc_master->layer_collections) { if (BKE_layer_collection_has_layer_collection(lc_iter, lc)) { lc_parent = lc_iter; break; @@ -1303,8 +1288,7 @@ void BKE_layer_collection_isolate_local(ViewLayer *view_layer, while (lc_parent != lc) { lc_parent->local_collections_bits |= v3d->local_collections_uuid; - for (LayerCollection *lc_iter = lc_parent->layer_collections.first; lc_iter; - lc_iter = lc_iter->next) { + LISTBASE_FOREACH (LayerCollection *, lc_iter, &lc_parent->layer_collections) { if (BKE_layer_collection_has_layer_collection(lc_iter, lc)) { lc_parent = lc_iter; break; @@ -1322,12 +1306,12 @@ void BKE_layer_collection_isolate_local(ViewLayer *view_layer, static void layer_collection_bases_show_recursive(ViewLayer *view_layer, LayerCollection *lc) { if ((lc->flag & LAYER_COLLECTION_EXCLUDE) == 0) { - for (CollectionObject *cob = lc->collection->gobject.first; cob; cob = cob->next) { + LISTBASE_FOREACH (CollectionObject *, cob, &lc->collection->gobject) { Base *base = BKE_view_layer_base_find(view_layer, cob->ob); base->flag &= ~BASE_HIDDEN; } } - for (LayerCollection *lc_iter = lc->layer_collections.first; lc_iter; lc_iter = lc_iter->next) { + LISTBASE_FOREACH (LayerCollection *, lc_iter, &lc->layer_collections) { layer_collection_bases_show_recursive(view_layer, lc_iter); } } @@ -1335,12 +1319,12 @@ static void layer_collection_bases_show_recursive(ViewLayer *view_layer, LayerCo static void layer_collection_bases_hide_recursive(ViewLayer *view_layer, LayerCollection *lc) { if ((lc->flag & LAYER_COLLECTION_EXCLUDE) == 0) { - for (CollectionObject *cob = lc->collection->gobject.first; cob; cob = cob->next) { + LISTBASE_FOREACH (CollectionObject *, cob, &lc->collection->gobject) { Base *base = BKE_view_layer_base_find(view_layer, cob->ob); base->flag |= BASE_HIDDEN; } } - for (LayerCollection *lc_iter = lc->layer_collections.first; lc_iter; lc_iter = lc_iter->next) { + LISTBASE_FOREACH (LayerCollection *, lc_iter, &lc->layer_collections) { layer_collection_bases_hide_recursive(view_layer, lc_iter); } } @@ -1384,7 +1368,7 @@ static LayerCollection *find_layer_collection_by_scene_collection(LayerCollectio return lc; } - for (LayerCollection *nlc = lc->layer_collections.first; nlc; nlc = nlc->next) { + LISTBASE_FOREACH (LayerCollection *, nlc, &lc->layer_collections) { LayerCollection *found = find_layer_collection_by_scene_collection(nlc, collection); if (found) { return found; @@ -1425,8 +1409,7 @@ bool BKE_view_layer_has_collection(ViewLayer *view_layer, const Collection *coll */ bool BKE_scene_has_object(Scene *scene, Object *ob) { - for (ViewLayer *view_layer = scene->view_layers.first; view_layer; - view_layer = view_layer->next) { + LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) { Base *base = BKE_view_layer_base_find(view_layer, ob); if (base) { return true; @@ -1768,7 +1751,7 @@ static void layer_eval_view_layer(struct Depsgraph *depsgraph, view_layer->object_bases_array = MEM_malloc_arrayN( num_object_bases, sizeof(Base *), "view_layer->object_bases_array"); int base_index = 0; - for (Base *base = view_layer->object_bases.first; base; base = base->next) { + LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) { view_layer->object_bases_array[base_index++] = base; } } diff --git a/source/blender/blenkernel/intern/lib_id.c b/source/blender/blenkernel/intern/lib_id.c index 21e27784684..286ee4a8723 100644 --- a/source/blender/blenkernel/intern/lib_id.c +++ b/source/blender/blenkernel/intern/lib_id.c @@ -901,7 +901,7 @@ void BKE_main_id_flag_all(Main *bmain, const int flag, const bool value) void BKE_main_id_repair_duplicate_names_listbase(ListBase *lb) { int lb_len = 0; - for (ID *id = lb->first; id; id = id->next) { + LISTBASE_FOREACH (ID *, id, lb) { if (id->lib == NULL) { lb_len += 1; } @@ -914,7 +914,7 @@ void BKE_main_id_repair_duplicate_names_listbase(ListBase *lb) ID **id_array = MEM_mallocN(sizeof(*id_array) * lb_len, __func__); GSet *gset = BLI_gset_str_new_ex(__func__, lb_len); int i = 0; - for (ID *id = lb->first; id; id = id->next) { + LISTBASE_FOREACH (ID *, id, lb) { if (id->lib == NULL) { id_array[i] = id; i++; @@ -2218,14 +2218,14 @@ void BKE_id_ordered_list(ListBase *ordered_lb, const ListBase *lb) { BLI_listbase_clear(ordered_lb); - for (ID *id = lb->first; id; id = id->next) { + LISTBASE_FOREACH (ID *, id, lb) { BLI_addtail(ordered_lb, BLI_genericNodeN(id)); } BLI_listbase_sort(ordered_lb, id_order_compare); int num = 0; - for (LinkData *link = ordered_lb->first; link; link = link->next) { + LISTBASE_FOREACH (LinkData *, link, ordered_lb) { int *order = id_order_get(link->data); if (order) { *order = num++; @@ -2250,7 +2250,7 @@ void BKE_id_reorder(const ListBase *lb, ID *id, ID *relative, bool after) if (after) { /* Insert after. */ - for (ID *other = lb->first; other; other = other->next) { + LISTBASE_FOREACH (ID *, other, lb) { int *order = id_order_get(other); if (*order > relative_order) { (*order)++; @@ -2261,7 +2261,7 @@ void BKE_id_reorder(const ListBase *lb, ID *id, ID *relative, bool after) } else { /* Insert before. */ - for (ID *other = lb->first; other; other = other->next) { + LISTBASE_FOREACH (ID *, other, lb) { int *order = id_order_get(other); if (*order < relative_order) { (*order)--; diff --git a/source/blender/blenkernel/intern/lib_override.c b/source/blender/blenkernel/intern/lib_override.c index 42d1806a41a..5b75b8ac181 100644 --- a/source/blender/blenkernel/intern/lib_override.c +++ b/source/blender/blenkernel/intern/lib_override.c @@ -153,7 +153,7 @@ void BKE_lib_override_library_clear(IDOverrideLibrary *override, const bool do_i BLI_ghash_clear(override->runtime, NULL, NULL); } - for (IDOverrideLibraryProperty *op = override->properties.first; op; op = op->next) { + LISTBASE_FOREACH (IDOverrideLibraryProperty *, op, &override->properties) { lib_override_library_property_clear(op); } BLI_freelistN(&override->properties); @@ -371,7 +371,7 @@ void lib_override_library_property_clear(IDOverrideLibraryProperty *op) MEM_freeN(op->rna_path); - for (IDOverrideLibraryPropertyOperation *opop = op->operations.first; opop; opop = opop->next) { + LISTBASE_FOREACH (IDOverrideLibraryPropertyOperation *, opop, &op->operations) { lib_override_library_property_operation_clear(opop); } BLI_freelistN(&op->operations); diff --git a/source/blender/blenkernel/intern/lib_query.c b/source/blender/blenkernel/intern/lib_query.c index 21d7bb137fc..9c0fa33157c 100644 --- a/source/blender/blenkernel/intern/lib_query.c +++ b/source/blender/blenkernel/intern/lib_query.c @@ -182,7 +182,7 @@ static void library_foreach_idproperty_ID_link(LibraryForeachIDData *data, switch (prop->type) { case IDP_GROUP: { - for (IDProperty *loop = prop->data.group.first; loop; loop = loop->next) { + LISTBASE_FOREACH (IDProperty *, loop, &prop->data.group) { library_foreach_idproperty_ID_link(data, loop, flag); } break; @@ -338,7 +338,7 @@ static void library_foreach_bone(LibraryForeachIDData *data, Bone *bone) { library_foreach_idproperty_ID_link(data, bone->prop, IDWALK_CB_USER); - for (Bone *curbone = bone->childbase.first; curbone; curbone = curbone->next) { + LISTBASE_FOREACH (Bone *, curbone, &bone->childbase) { library_foreach_bone(data, curbone); } @@ -347,7 +347,7 @@ static void library_foreach_bone(LibraryForeachIDData *data, Bone *bone) static void library_foreach_layer_collection(LibraryForeachIDData *data, ListBase *lb) { - for (LayerCollection *lc = lb->first; lc; lc = lc->next) { + LISTBASE_FOREACH (LayerCollection *, lc, lb) { /* XXX This is very weak. The whole idea of keeping pointers to private IDs is very bad * anyway... */ const int cb_flag = (lc->collection != NULL && @@ -365,13 +365,13 @@ static void library_foreach_layer_collection(LibraryForeachIDData *data, ListBas */ static void library_foreach_collection(LibraryForeachIDData *data, Collection *collection) { - for (CollectionObject *cob = collection->gobject.first; cob; cob = cob->next) { + LISTBASE_FOREACH (CollectionObject *, cob, &collection->gobject) { FOREACH_CALLBACK_INVOKE(data, cob->ob, IDWALK_CB_USER); } - for (CollectionChild *child = collection->children.first; child; child = child->next) { + LISTBASE_FOREACH (CollectionChild *, child, &collection->children) { FOREACH_CALLBACK_INVOKE(data, child->collection, IDWALK_CB_NEVER_SELF | IDWALK_CB_USER); } - for (CollectionParent *parent = collection->parents.first; parent; parent = parent->next) { + LISTBASE_FOREACH (CollectionParent *, parent, &collection->parents) { /* XXX This is very weak. The whole idea of keeping pointers to private IDs is very bad * anyway... */ const int cb_flag = ((parent->collection != NULL && @@ -399,7 +399,7 @@ static void library_foreach_screen_area(LibraryForeachIDData *data, ScrArea *are { FOREACH_CALLBACK_INVOKE(data, area->full, IDWALK_CB_NOP); - for (SpaceLink *sl = area->spacedata.first; sl; sl = sl->next) { + LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) { switch (sl->spacetype) { case SPACE_VIEW3D: { View3D *v3d = (View3D *)sl; @@ -678,7 +678,7 @@ static void library_foreach_ID_link(Main *bmain, CALLBACK_INVOKE(seq->mask, IDWALK_CB_USER); CALLBACK_INVOKE(seq->sound, IDWALK_CB_USER); library_foreach_idproperty_ID_link(&data, seq->prop, IDWALK_CB_USER); - for (SequenceModifierData *smd = seq->modifiers.first; smd; smd = smd->next) { + LISTBASE_FOREACH (SequenceModifierData *, smd, &seq->modifiers) { CALLBACK_INVOKE(smd->mask_id, IDWALK_CB_USER); } @@ -699,21 +699,19 @@ static void library_foreach_ID_link(Main *bmain, for (view_layer = scene->view_layers.first; view_layer; view_layer = view_layer->next) { CALLBACK_INVOKE(view_layer->mat_override, IDWALK_CB_USER); - for (Base *base = view_layer->object_bases.first; base; base = base->next) { + LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) { CALLBACK_INVOKE(base->object, IDWALK_CB_NOP); } library_foreach_layer_collection(&data, &view_layer->layer_collections); - for (FreestyleModuleConfig *fmc = view_layer->freestyle_config.modules.first; fmc; - fmc = fmc->next) { + LISTBASE_FOREACH (FreestyleModuleConfig *, fmc, &view_layer->freestyle_config.modules) { if (fmc->script) { CALLBACK_INVOKE(fmc->script, IDWALK_CB_NOP); } } - for (FreestyleLineSet *fls = view_layer->freestyle_config.linesets.first; fls; - fls = fls->next) { + LISTBASE_FOREACH (FreestyleLineSet *, fls, &view_layer->freestyle_config.linesets) { if (fls->group) { CALLBACK_INVOKE(fls->group, IDWALK_CB_USER); } @@ -724,7 +722,7 @@ static void library_foreach_ID_link(Main *bmain, } } - for (TimeMarker *marker = scene->markers.first; marker; marker = marker->next) { + LISTBASE_FOREACH (TimeMarker *, marker, &scene->markers) { CALLBACK_INVOKE(marker->camera, IDWALK_CB_NOP); } @@ -881,7 +879,7 @@ static void library_foreach_ID_link(Main *bmain, case ID_AR: { bArmature *arm = (bArmature *)id; - for (Bone *bone = arm->bonebase.first; bone; bone = bone->next) { + LISTBASE_FOREACH (Bone *, bone, &arm->bonebase) { library_foreach_bone(&data, bone); } break; @@ -968,7 +966,7 @@ static void library_foreach_ID_link(Main *bmain, case ID_CA: { Camera *camera = (Camera *)id; CALLBACK_INVOKE(camera->dof.focus_object, IDWALK_CB_NOP); - for (CameraBGImage *bgpic = camera->bg_images.first; bgpic; bgpic = bgpic->next) { + LISTBASE_FOREACH (CameraBGImage *, bgpic, &camera->bg_images) { if (bgpic->source == CAM_BGIMG_SOURCE_IMAGE) { CALLBACK_INVOKE(bgpic->ima, IDWALK_CB_USER); } @@ -1100,7 +1098,7 @@ static void library_foreach_ID_link(Main *bmain, } } - for (ParticleDupliWeight *dw = psett->instance_weights.first; dw; dw = dw->next) { + LISTBASE_FOREACH (ParticleDupliWeight *, dw, &psett->instance_weights) { CALLBACK_INVOKE(dw->ob, IDWALK_CB_NOP); } break; @@ -1195,7 +1193,7 @@ static void library_foreach_ID_link(Main *bmain, case ID_AC: { bAction *act = (bAction *)id; - for (TimeMarker *marker = act->markers.first; marker; marker = marker->next) { + LISTBASE_FOREACH (TimeMarker *, marker, &act->markers) { CALLBACK_INVOKE(marker->camera, IDWALK_CB_NOP); } break; @@ -1204,7 +1202,7 @@ static void library_foreach_ID_link(Main *bmain, case ID_WM: { wmWindowManager *wm = (wmWindowManager *)id; - for (wmWindow *win = wm->windows.first; win; win = win->next) { + LISTBASE_FOREACH (wmWindow *, win, &wm->windows) { CALLBACK_INVOKE(win->scene, IDWALK_CB_USER_ONE); /* This pointer can be NULL during old files reading, better be safe than sorry. */ @@ -1215,7 +1213,7 @@ static void library_foreach_ID_link(Main *bmain, BKE_workspace_active_set(win->workspace_hook, (WorkSpace *)workspace); } if (data.flag & IDWALK_INCLUDE_UI) { - for (ScrArea *area = win->global_areas.areabase.first; area; area = area->next) { + LISTBASE_FOREACH (ScrArea *, area, &win->global_areas.areabase) { library_foreach_screen_area(&data, area); } } @@ -1227,7 +1225,7 @@ static void library_foreach_ID_link(Main *bmain, WorkSpace *workspace = (WorkSpace *)id; ListBase *layouts = BKE_workspace_layouts_get(workspace); - for (WorkSpaceLayout *layout = layouts->first; layout; layout = layout->next) { + LISTBASE_FOREACH (WorkSpaceLayout *, layout, layouts) { bScreen *screen = BKE_workspace_layout_screen_get(layout); /* CALLBACK_INVOKE expects an actual pointer, not a variable holding the pointer. @@ -1280,7 +1278,7 @@ static void library_foreach_ID_link(Main *bmain, if (data.flag & IDWALK_INCLUDE_UI) { bScreen *screen = (bScreen *)id; - for (ScrArea *area = screen->areabase.first; area; area = area->next) { + LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) { library_foreach_screen_area(&data, area); } } @@ -1710,7 +1708,7 @@ void BKE_library_indirectly_used_data_tag_clear(Main *bmain) do_loop = false; while (i--) { - for (ID *id = lb_array[i]->first; id; id = id->next) { + LISTBASE_FOREACH (ID *, id, lb_array[i]) { if (id->lib == NULL || id->tag & LIB_TAG_DOIT) { /* Local or non-indirectly-used ID (so far), no need to check it further. */ continue; diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c index bcf4b29ec07..5516e877b10 100644 --- a/source/blender/blenkernel/intern/material.c +++ b/source/blender/blenkernel/intern/material.c @@ -1121,7 +1121,7 @@ static bool ntree_foreach_texnode_recursive(bNodeTree *nodetree, ForEachTexNodeCallback callback, void *userdata) { - for (bNode *node = nodetree->nodes.first; node; node = node->next) { + LISTBASE_FOREACH (bNode *, node, &nodetree->nodes) { if (node->typeinfo->nclass == NODE_CLASS_TEXTURE && node->typeinfo->type == SH_NODE_TEX_IMAGE && node->id) { if (!callback(node, userdata)) { diff --git a/source/blender/blenkernel/intern/mball.c b/source/blender/blenkernel/intern/mball.c index 79e70ad2741..4294d279c36 100644 --- a/source/blender/blenkernel/intern/mball.c +++ b/source/blender/blenkernel/intern/mball.c @@ -430,9 +430,8 @@ Object *BKE_mball_basis_find(Scene *scene, Object *basis) BLI_split_name_num(basisname, &basisnr, basis->id.name + 2, '.'); - for (ViewLayer *view_layer = scene->view_layers.first; view_layer; - view_layer = view_layer->next) { - for (Base *base = view_layer->object_bases.first; base; base = base->next) { + LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) { + LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) { Object *ob = base->object; if ((ob->type == OB_MBALL) && !(base->flag & BASE_FROM_DUPLI)) { if (ob != bob) { @@ -463,7 +462,7 @@ bool BKE_mball_minmax_ex( INIT_MINMAX(min, max); - for (const MetaElem *ml = mb->elems.first; ml; ml = ml->next) { + LISTBASE_FOREACH (const MetaElem *, ml, &mb->elems) { if ((ml->flag & flag) == flag) { const float scale_mb = (ml->rad * 0.5f) * scale; int i; @@ -493,7 +492,7 @@ bool BKE_mball_minmax(const MetaBall *mb, float min[3], float max[3]) { INIT_MINMAX(min, max); - for (const MetaElem *ml = mb->elems.first; ml; ml = ml->next) { + LISTBASE_FOREACH (const MetaElem *, ml, &mb->elems) { minmax_v3v3_v3(min, max, &ml->x); } @@ -506,7 +505,7 @@ bool BKE_mball_center_median(const MetaBall *mb, float r_cent[3]) zero_v3(r_cent); - for (const MetaElem *ml = mb->elems.first; ml; ml = ml->next) { + LISTBASE_FOREACH (const MetaElem *, ml, &mb->elems) { add_v3_v3(r_cent, &ml->x); total++; } @@ -538,7 +537,7 @@ void BKE_mball_transform(MetaBall *mb, const float mat[4][4], const bool do_prop mat4_to_quat(quat, mat); - for (MetaElem *ml = mb->elems.first; ml; ml = ml->next) { + LISTBASE_FOREACH (MetaElem *, ml, &mb->elems) { mul_m4_v3(mat, &ml->x); mul_qt_qtqt(ml->quat, quat, ml->quat); @@ -558,7 +557,7 @@ void BKE_mball_transform(MetaBall *mb, const float mat[4][4], const bool do_prop void BKE_mball_translate(MetaBall *mb, const float offset[3]) { - for (MetaElem *ml = mb->elems.first; ml; ml = ml->next) { + LISTBASE_FOREACH (MetaElem *, ml, &mb->elems) { add_v3_v3(&ml->x, offset); } } @@ -567,7 +566,7 @@ void BKE_mball_translate(MetaBall *mb, const float offset[3]) int BKE_mball_select_count(const MetaBall *mb) { int sel = 0; - for (const MetaElem *ml = mb->editelems->first; ml; ml = ml->next) { + LISTBASE_FOREACH (const MetaElem *, ml, mb->editelems) { if (ml->flag & SELECT) { sel++; } @@ -589,7 +588,7 @@ int BKE_mball_select_count_multi(Base **bases, int bases_len) bool BKE_mball_select_all(MetaBall *mb) { bool changed = false; - for (MetaElem *ml = mb->editelems->first; ml; ml = ml->next) { + LISTBASE_FOREACH (MetaElem *, ml, mb->editelems) { if ((ml->flag & SELECT) == 0) { ml->flag |= SELECT; changed = true; @@ -612,7 +611,7 @@ bool BKE_mball_select_all_multi_ex(Base **bases, int bases_len) bool BKE_mball_deselect_all(MetaBall *mb) { bool changed = false; - for (MetaElem *ml = mb->editelems->first; ml; ml = ml->next) { + LISTBASE_FOREACH (MetaElem *, ml, mb->editelems) { if ((ml->flag & SELECT) != 0) { ml->flag &= ~SELECT; changed = true; @@ -636,7 +635,7 @@ bool BKE_mball_deselect_all_multi_ex(Base **bases, int bases_len) bool BKE_mball_select_swap(MetaBall *mb) { bool changed = false; - for (MetaElem *ml = mb->editelems->first; ml; ml = ml->next) { + LISTBASE_FOREACH (MetaElem *, ml, mb->editelems) { ml->flag ^= SELECT; changed = true; } diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c index 98a7673c9d5..c3c538f3424 100644 --- a/source/blender/blenkernel/intern/node.c +++ b/source/blender/blenkernel/intern/node.c @@ -113,7 +113,7 @@ static void ntree_copy_data(Main *UNUSED(bmain), ID *id_dst, const ID *id_src, c /* Since source nodes and sockets are unique pointers we can put everything in a single map. */ GHash *new_pointers = BLI_ghash_ptr_new(__func__); - for (const bNode *node_src = ntree_src->nodes.first; node_src; node_src = node_src->next) { + LISTBASE_FOREACH (const bNode *, node_src, &ntree_src->nodes) { bNode *new_node = BKE_node_copy_ex(ntree_dst, node_src, flag_subdata, true); BLI_ghash_insert(new_pointers, (void *)node_src, new_node); /* Store mapping to inputs. */ @@ -1634,7 +1634,7 @@ void nodePositionRelative(bNode *from_node, void nodePositionPropagate(bNode *node) { - for (bNodeSocket *nsock = node->inputs.first; nsock; nsock = nsock->next) { + LISTBASE_FOREACH (bNodeSocket *, nsock, &node->inputs) { if (nsock->link != NULL) { bNodeLink *link = nsock->link; nodePositionRelative(link->fromnode, link->tonode, link->fromsock, link->tosock); @@ -2662,7 +2662,7 @@ void ntreeInterfaceTypeUpdate(bNodeTree *ntree) bNode *ntreeFindType(const bNodeTree *ntree, int type) { if (ntree) { - for (bNode *node = ntree->nodes.first; node; node = node->next) { + LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { if (node->type == type) { return node; } @@ -3396,7 +3396,7 @@ void ntreeUpdateAllNew(Main *main) * might have been set in file reading or versioning. */ FOREACH_NODETREE_BEGIN (main, ntree, owner_id) { if (owner_id->tag & LIB_TAG_NEW) { - for (bNode *node = ntree->nodes.first; node; node = node->next) { + LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { if (node->typeinfo->group_update_func) { node->typeinfo->group_update_func(ntree, node); } @@ -3414,7 +3414,7 @@ void ntreeUpdateAllUsers(Main *main, ID *ngroup) FOREACH_NODETREE_BEGIN (main, ntree, owner_id) { bool need_update = false; - for (bNode *node = ntree->nodes.first; node; node = node->next) { + LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { if (node->id == ngroup) { if (node->typeinfo->group_update_func) { node->typeinfo->group_update_func(ntree, node); @@ -4245,7 +4245,7 @@ bool BKE_node_tree_iter_step(struct NodeTreeIterStore *ntreeiter, void BKE_nodetree_remove_layer_n(bNodeTree *ntree, Scene *scene, const int layer_index) { BLI_assert(layer_index != -1); - for (bNode *node = ntree->nodes.first; node; node = node->next) { + LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { if (node->type == CMP_NODE_R_LAYERS && (Scene *)node->id == scene) { if (node->custom1 == layer_index) { node->custom1 = 0; diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c index 87ac4428594..587dd5be2f2 100644 --- a/source/blender/blenkernel/intern/particle.c +++ b/source/blender/blenkernel/intern/particle.c @@ -479,7 +479,7 @@ void psys_find_group_weights(ParticleSettings *part) instance_collection_objects = BKE_collection_object_cache_get(part->instance_collection); } - for (ParticleDupliWeight *dw = part->instance_weights.first; dw; dw = dw->next) { + LISTBASE_FOREACH (ParticleDupliWeight *, dw, &part->instance_weights) { if (dw->ob == NULL) { Base *base = BLI_findlink(&instance_collection_objects, dw->index); if (base != NULL) { diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c index b1cff53d399..78e7dec9f38 100644 --- a/source/blender/blenkernel/intern/pointcache.c +++ b/source/blender/blenkernel/intern/pointcache.c @@ -1839,7 +1839,7 @@ PTCacheID BKE_ptcache_id_find(Object *ob, Scene *scene, PointCache *cache) ListBase pidlist; BKE_ptcache_ids_from_object(&pidlist, ob, scene, MAX_DUPLI_RECUR); - for (PTCacheID *pid = pidlist.first; pid; pid = pid->next) { + LISTBASE_FOREACH (PTCacheID *, pid, &pidlist) { if (pid->cache == cache) { result = *pid; break; diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c index 8cbc1ba4d8e..20f7add0c74 100644 --- a/source/blender/blenkernel/intern/scene.c +++ b/source/blender/blenkernel/intern/scene.c @@ -669,10 +669,9 @@ Scene *BKE_scene_copy(Main *bmain, Scene *sce, int type) if (type == SCE_COPY_FULL) { /* Copy Freestyle LineStyle datablocks. */ - for (ViewLayer *view_layer_dst = sce_copy->view_layers.first; view_layer_dst; - view_layer_dst = view_layer_dst->next) { - for (FreestyleLineSet *lineset = view_layer_dst->freestyle_config.linesets.first; lineset; - lineset = lineset->next) { + LISTBASE_FOREACH (ViewLayer *, view_layer_dst, &sce_copy->view_layers) { + LISTBASE_FOREACH ( + FreestyleLineSet *, lineset, &view_layer_dst->freestyle_config.linesets) { if (lineset->linestyle) { id_us_min(&lineset->linestyle->id); BKE_id_copy_ex( @@ -732,8 +731,7 @@ Scene *BKE_scene_add(Main *bmain, const char *name) */ bool BKE_scene_object_find(Scene *scene, Object *ob) { - for (ViewLayer *view_layer = scene->view_layers.first; view_layer; - view_layer = view_layer->next) { + LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) { if (BLI_findptr(&view_layer->object_bases, ob, offsetof(Base, object))) { return true; } @@ -743,9 +741,8 @@ bool BKE_scene_object_find(Scene *scene, Object *ob) Object *BKE_scene_object_find_by_name(const Scene *scene, const char *name) { - for (ViewLayer *view_layer = scene->view_layers.first; view_layer; - view_layer = view_layer->next) { - for (Base *base = view_layer->object_bases.first; base; base = base->next) { + LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) { + LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) { if (STREQ(base->object->id.name + 2, name)) { return base->object; } @@ -773,9 +770,8 @@ void BKE_scene_set_background(Main *bmain, Scene *scene) } /* copy layers and flags from bases to objects */ - for (ViewLayer *view_layer = scene->view_layers.first; view_layer; - view_layer = view_layer->next) { - for (Base *base = view_layer->object_bases.first; base; base = base->next) { + LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) { + LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) { ob = base->object; /* collection patch... */ BKE_scene_object_base_flag_sync_from_base(base); @@ -929,7 +925,7 @@ int BKE_scene_base_iter_next( Scene *BKE_scene_find_from_collection(const Main *bmain, const Collection *collection) { for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) { - for (ViewLayer *layer = scene->view_layers.first; layer; layer = layer->next) { + LISTBASE_FOREACH (ViewLayer *, layer, &scene->view_layers) { if (BKE_view_layer_has_collection(layer, collection)) { return scene; } @@ -955,7 +951,7 @@ Object *BKE_scene_camera_switch_find(Scene *scene) Object *camera = NULL; Object *first_camera = NULL; - for (TimeMarker *m = scene->markers.first; m; m = m->next) { + LISTBASE_FOREACH (TimeMarker *, m, &scene->markers) { if (m->camera && (m->camera->restrictflag & OB_RESTRICT_RENDER) == 0) { if ((m->frame <= cfra) && (m->frame > frame)) { camera = m->camera; diff --git a/source/blender/blenkernel/intern/screen.c b/source/blender/blenkernel/intern/screen.c index 37ea6c2cb4d..38bd0211d15 100644 --- a/source/blender/blenkernel/intern/screen.c +++ b/source/blender/blenkernel/intern/screen.c @@ -724,7 +724,7 @@ void BKE_screen_remove_unused_scrverts(bScreen *screen) ARegion *BKE_area_find_region_type(const ScrArea *area, int region_type) { if (area) { - for (ARegion *region = area->regionbase.first; region; region = region->next) { + LISTBASE_FOREACH (ARegion *, region, &area->regionbase) { if (region->regiontype == region_type) { return region; } @@ -771,7 +771,7 @@ ARegion *BKE_area_find_region_xy(ScrArea *area, const int regiontype, int x, int ARegion *BKE_screen_find_region_xy(bScreen *screen, const int regiontype, int x, int y) { ARegion *region_found = NULL; - for (ARegion *region = screen->regionbase.first; region; region = region->next) { + LISTBASE_FOREACH (ARegion *, region, &screen->regionbase) { if ((regiontype == RGN_TYPE_ANY) || (region->regiontype == regiontype)) { if (BLI_rcti_isect_pt(®ion->winrct, x, y)) { region_found = region; @@ -828,7 +828,7 @@ ScrArea *BKE_screen_area_map_find_area_xy(const ScrAreaMap *areamap, int x, int y) { - for (ScrArea *area = areamap->areabase.first; area; area = area->next) { + LISTBASE_FOREACH (ScrArea *, area, &areamap->areabase) { if (BLI_rcti_isect_pt(&area->totrct, x, y)) { if ((spacetype == SPACE_TYPE_ANY) || (area->spacetype == spacetype)) { return area; @@ -915,8 +915,8 @@ bool BKE_screen_is_used(const bScreen *screen) void BKE_screen_header_alignment_reset(bScreen *screen) { int alignment = (U.uiflag & USER_HEADER_BOTTOM) ? RGN_ALIGN_BOTTOM : RGN_ALIGN_TOP; - for (ScrArea *area = screen->areabase.first; area; area = area->next) { - for (ARegion *region = area->regionbase.first; region; region = region->next) { + LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) { + LISTBASE_FOREACH (ARegion *, region, &area->regionbase) { if (ELEM(region->regiontype, RGN_TYPE_HEADER, RGN_TYPE_TOOL_HEADER)) { if (ELEM(area->spacetype, SPACE_FILE, SPACE_USERPREF, SPACE_OUTLINER, SPACE_PROPERTIES)) { region->alignment = RGN_ALIGN_TOP; diff --git a/source/blender/blenkernel/intern/seqeffects.c b/source/blender/blenkernel/intern/seqeffects.c index c471a6d254c..6acc50f30e9 100644 --- a/source/blender/blenkernel/intern/seqeffects.c +++ b/source/blender/blenkernel/intern/seqeffects.c @@ -3166,7 +3166,6 @@ void BKE_sequence_effect_speed_rebuild_map(Scene *scene, Sequence *seq, bool for /* XXX - new in 2.5x. should we use the animation system this way? * The fcurve is needed because many frames need evaluating at once - campbell */ fcu = id_data_find_fcurve(&scene->id, seq, &RNA_Sequence, "speed_factor", 0, NULL); - if (!v->frameMap || v->length != seq->len) { if (v->frameMap) { MEM_freeN(v->frameMap); diff --git a/source/blender/blenkernel/intern/sequencer.c b/source/blender/blenkernel/intern/sequencer.c index 996a9f34b61..0e558db57cb 100644 --- a/source/blender/blenkernel/intern/sequencer.c +++ b/source/blender/blenkernel/intern/sequencer.c @@ -1459,7 +1459,7 @@ static int evaluate_seq_frame_gen(Sequence **seq_arr, ListBase *seqbase, int cfr memset(seq_arr, 0, sizeof(Sequence *) * (MAXSEQ + 1)); - for (Sequence *seq = seqbase->first; seq; seq = seq->next) { + LISTBASE_FOREACH (Sequence *, seq, seqbase) { if ((seq->startdisp <= cfra) && (seq->enddisp > cfra)) { if ((seq->type & SEQ_TYPE_EFFECT) && !(seq->flag & SEQ_MUTE)) { diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c index 94c41777cea..3cdf3b40ce3 100644 --- a/source/blender/blenkernel/intern/text.c +++ b/source/blender/blenkernel/intern/text.c @@ -164,7 +164,7 @@ static void text_copy_data(Main *UNUSED(bmain), text_dst->compiled = NULL; /* Walk down, reconstructing. */ - for (TextLine *line_src = text_src->lines.first; line_src; line_src = line_src->next) { + LISTBASE_FOREACH (TextLine *, line_src, &text_src->lines) { TextLine *line_dst = MEM_mallocN(sizeof(*line_dst), __func__); line_dst->line = BLI_strdup(line_src->line); @@ -1311,12 +1311,12 @@ void txt_sel_set(Text *text, int startl, int startc, int endl, int endc) char *txt_to_buf_for_undo(Text *text, int *r_buf_len) { int buf_len = 0; - for (const TextLine *l = text->lines.first; l; l = l->next) { + LISTBASE_FOREACH (const TextLine *, l, &text->lines) { buf_len += l->len + 1; } char *buf = MEM_mallocN(buf_len, __func__); char *buf_step = buf; - for (const TextLine *l = text->lines.first; l; l = l->next) { + LISTBASE_FOREACH (const TextLine *, l, &text->lines) { memcpy(buf_step, l->line, l->len); buf_step += l->len; *buf_step++ = '\n'; diff --git a/source/blender/blenkernel/intern/texture.c b/source/blender/blenkernel/intern/texture.c index fd85e5ca212..fe10861f96e 100644 --- a/source/blender/blenkernel/intern/texture.c +++ b/source/blender/blenkernel/intern/texture.c @@ -697,7 +697,7 @@ static void texture_nodes_fetch_images_for_pool(Tex *texture, bNodeTree *ntree, struct ImagePool *pool) { - for (bNode *node = ntree->nodes.first; node; node = node->next) { + LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { if (node->type == SH_NODE_TEX_IMAGE && node->id != NULL) { Image *image = (Image *)node->id; BKE_image_pool_acquire_ibuf(image, &texture->iuser, pool); diff --git a/source/blender/blenkernel/intern/tracking_solver.c b/source/blender/blenkernel/intern/tracking_solver.c index 5c1f6caad9d..46870a03e62 100644 --- a/source/blender/blenkernel/intern/tracking_solver.c +++ b/source/blender/blenkernel/intern/tracking_solver.c @@ -600,7 +600,7 @@ static void tracking_scale_reconstruction(ListBase *tracksbase, sub_v3_v3(camera->mat[3], first_camera_delta); } - for (MovieTrackingTrack *track = tracksbase->first; track; track = track->next) { + LISTBASE_FOREACH (MovieTrackingTrack *, track, tracksbase) { if (track->flag & TRACK_HAS_BUNDLE) { mul_v3_v3(track->bundle_pos, scale); sub_v3_v3(track->bundle_pos, first_camera_delta); diff --git a/source/blender/blenkernel/intern/undo_system.c b/source/blender/blenkernel/intern/undo_system.c index 847522a0a66..e776e9bedb0 100644 --- a/source/blender/blenkernel/intern/undo_system.c +++ b/source/blender/blenkernel/intern/undo_system.c @@ -110,7 +110,7 @@ static ListBase g_undo_types = {NULL, NULL}; static const UndoType *BKE_undosys_type_from_context(bContext *C) { - for (const UndoType *ut = g_undo_types.first; ut; ut = ut->next) { + LISTBASE_FOREACH (const UndoType *, ut, &g_undo_types) { /* No poll means we don't check context. */ if (ut->poll && ut->poll(C)) { return ut; @@ -143,7 +143,7 @@ static void undosys_id_ref_resolve(void *user_data, UndoRefID *id_ref) * for now it's not too bad since it only runs when we access undo! */ Main *bmain = user_data; ListBase *lb = which_libbase(bmain, GS(id_ref->name)); - for (ID *id = lb->first; id; id = id->next) { + LISTBASE_FOREACH (ID *, id, lb) { if (STREQ(id_ref->name, id->name) && (id->lib == NULL)) { id_ref->ptr = id; break; @@ -857,7 +857,7 @@ static void UNUSED_FUNCTION(BKE_undosys_foreach_ID_ref(UndoStack *ustack, UndoTypeForEachIDRefFn foreach_ID_ref_fn, void *user_data)) { - for (UndoStep *us = ustack->steps.first; us; us = us->next) { + LISTBASE_FOREACH (UndoStep *, us, &ustack->steps) { const UndoType *ut = us->type; if (ut->step_foreach_ID_ref != NULL) { ut->step_foreach_ID_ref(us, foreach_ID_ref_fn, user_data); @@ -876,7 +876,7 @@ void BKE_undosys_print(UndoStack *ustack) printf("Undo %d Steps (*: active, #=applied, M=memfile-active, S=skip)\n", BLI_listbase_count(&ustack->steps)); int index = 0; - for (UndoStep *us = ustack->steps.first; us; us = us->next) { + LISTBASE_FOREACH (UndoStep *, us, &ustack->steps) { printf("[%c%c%c%c] %3d {%p} type='%s', name='%s'\n", (us == ustack->step_active) ? '*' : ' ', us->is_applied ? '#' : ' ', diff --git a/source/blender/blenkernel/intern/workspace.c b/source/blender/blenkernel/intern/workspace.c index 66a3c2cdced..c65d55785c1 100644 --- a/source/blender/blenkernel/intern/workspace.c +++ b/source/blender/blenkernel/intern/workspace.c @@ -396,7 +396,7 @@ void BKE_workspace_id_tag_all_visible(Main *bmain, int tag) { BKE_main_id_tag_listbase(&bmain->workspaces, tag, false); wmWindowManager *wm = bmain->wm.first; - for (wmWindow *win = wm->windows.first; win; win = win->next) { + LISTBASE_FOREACH (wmWindow *, win, &wm->windows) { WorkSpace *workspace = BKE_workspace_active_get(win->workspace_hook); workspace->id.tag |= tag; } |