diff --git a/source/blender/blenkernel/intern/action.cc b/source/blender/blenkernel/intern/action.cc index 81518b36482..b50bd8e9a1c 100644 --- a/source/blender/blenkernel/intern/action.cc +++ b/source/blender/blenkernel/intern/action.cc @@ -364,15 +364,13 @@ bActionGroup *get_active_actiongroup(bAction *act) void set_active_action_group(bAction *act, bActionGroup *agrp, short select) { - bActionGroup *grp; - /* sanity checks */ if (act == nullptr) { return; } /* Deactivate all others */ - for (grp = static_cast(act->groups.first); grp; grp = grp->next) { + LISTBASE_FOREACH (bActionGroup *, grp, &act->groups) { if ((grp == agrp) && (select)) { grp->flag |= AGRP_ACTIVE; } @@ -598,15 +596,13 @@ bActionGroup *BKE_action_group_find_name(bAction *act, const char name[]) void action_groups_clear_tempflags(bAction *act) { - bActionGroup *agrp; - /* sanity checks */ if (ELEM(nullptr, act, act->groups.first)) { return; } /* flag clearing loop */ - for (agrp = static_cast(act->groups.first); agrp; agrp = agrp->next) { + LISTBASE_FOREACH (bActionGroup *, agrp, &act->groups) { agrp->flag &= ~AGRP_TEMP; } } @@ -706,14 +702,12 @@ bool BKE_pose_is_layer_visible(const bArmature *arm, const bPoseChannel *pchan) bPoseChannel *BKE_pose_channel_active(Object *ob, const bool check_arm_layer) { bArmature *arm = static_cast((ob) ? ob->data : nullptr); - bPoseChannel *pchan; - if (ELEM(nullptr, ob, ob->pose, arm)) { return nullptr; } /* find active */ - for (pchan = static_cast(ob->pose->chanbase.first); pchan; pchan = pchan->next) { + LISTBASE_FOREACH (bPoseChannel *, pchan, &ob->pose->chanbase) { if ((pchan->bone) && (pchan->bone == arm->act_bone)) { if (!check_arm_layer || BKE_pose_is_layer_visible(arm, pchan)) { return pchan; @@ -742,7 +736,7 @@ bPoseChannel *BKE_pose_channel_active_or_first_selected(Object *ob) return pchan; } - for (pchan = static_cast(ob->pose->chanbase.first); pchan; pchan = pchan->next) { + LISTBASE_FOREACH (bPoseChannel *, pchan, &ob->pose->chanbase) { if (pchan->bone != nullptr) { if ((pchan->bone->flag & BONE_SELECTED) && PBONE_VISIBLE(arm, pchan->bone)) { return pchan; @@ -784,7 +778,6 @@ void BKE_pose_copy_data_ex(bPose **dst, const bool copy_constraints) { bPose *outPose; - bPoseChannel *pchan; ListBase listb; if (!src) { @@ -810,7 +803,7 @@ void BKE_pose_copy_data_ex(bPose **dst, outPose->ikparam = MEM_dupallocN(src->ikparam); outPose->avs = src->avs; - for (pchan = static_cast(outPose->chanbase.first); pchan; pchan = pchan->next) { + LISTBASE_FOREACH (bPoseChannel *, pchan, &outPose->chanbase) { if ((flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0) { id_us_plus((ID *)pchan->custom); } @@ -900,12 +893,9 @@ void BKE_pose_ikparam_init(bPose *pose) /* only for real IK, not for auto-IK */ static bool pose_channel_in_IK_chain(Object *ob, bPoseChannel *pchan, int level) { - bConstraint *con; - Bone *bone; - /* No need to check if constraint is active (has influence), * since all constraints with CONSTRAINT_IK_AUTO are active */ - for (con = static_cast(pchan->constraints.first); con; con = con->next) { + LISTBASE_FOREACH (bConstraint *, con, &pchan->constraints) { if (con->type == CONSTRAINT_TYPE_KINEMATIC) { bKinematicConstraint *data = static_cast(con->data); if ((data->rootbone == 0) || (data->rootbone > level)) { @@ -915,7 +905,7 @@ static bool pose_channel_in_IK_chain(Object *ob, bPoseChannel *pchan, int level) } } } - for (bone = static_cast(pchan->bone->childbase.first); bone; bone = bone->next) { + LISTBASE_FOREACH (Bone *, bone, &pchan->bone->childbase) { pchan = BKE_pose_channel_find_name(ob->pose, bone->name); if (pchan && pose_channel_in_IK_chain(ob, pchan, level + 1)) { return true; @@ -932,10 +922,8 @@ bool BKE_pose_channel_in_IK_chain(Object *ob, bPoseChannel *pchan) void BKE_pose_channels_hash_ensure(bPose *pose) { if (!pose->chanhash) { - bPoseChannel *pchan; - pose->chanhash = BLI_ghash_str_new("make_pose_chan gh"); - for (pchan = static_cast(pose->chanbase.first); pchan; pchan = pchan->next) { + LISTBASE_FOREACH (bPoseChannel *, pchan, &pose->chanbase) { BLI_ghash_insert(pose->chanhash, pchan->name, pchan); } } @@ -971,7 +959,6 @@ void BKE_pose_channels_remove(Object *ob, /* Erase any associated pose channel, along with any references to them */ if (ob->pose) { bPoseChannel *pchan, *pchan_next; - bConstraint *con; for (pchan = static_cast(ob->pose->chanbase.first); pchan; pchan = pchan_next) { @@ -988,12 +975,10 @@ void BKE_pose_channels_remove(Object *ob, } else { /* Maybe something the bone references is being removed instead? */ - for (con = static_cast(pchan->constraints.first); con; con = con->next) { + LISTBASE_FOREACH (bConstraint *, con, &pchan->constraints) { ListBase targets = {nullptr, nullptr}; - bConstraintTarget *ct; - if (BKE_constraint_targets_get(con, &targets)) { - for (ct = static_cast(targets.first); ct; ct = ct->next) { + LISTBASE_FOREACH (bConstraintTarget *, ct, &targets) { if (ct->tar == ob) { if (ct->subtarget[0]) { if (filter_fn(ct->subtarget, user_data)) { @@ -1090,10 +1075,8 @@ void BKE_pose_channel_free(bPoseChannel *pchan) void BKE_pose_channels_free_ex(bPose *pose, bool do_id_user) { - bPoseChannel *pchan; - - if (pose->chanbase.first) { - for (pchan = static_cast(pose->chanbase.first); pchan; pchan = pchan->next) { + if (!BLI_listbase_is_empty(&pose->chanbase)) { + LISTBASE_FOREACH (bPoseChannel *, pchan, &pose->chanbase) { BKE_pose_channel_free_ex(pchan, do_id_user); } @@ -1199,18 +1182,17 @@ void BKE_pose_channel_copy_data(bPoseChannel *pchan, const bPoseChannel *pchan_f void BKE_pose_update_constraint_flags(bPose *pose) { - bPoseChannel *pchan, *parchan; - bConstraint *con; + bPoseChannel *parchan; /* clear */ - for (pchan = static_cast(pose->chanbase.first); pchan; pchan = pchan->next) { + LISTBASE_FOREACH (bPoseChannel *, pchan, &pose->chanbase) { pchan->constflag = 0; } pose->flag &= ~POSE_CONSTRAINTS_TIMEDEPEND; /* detect */ - for (pchan = static_cast(pose->chanbase.first); pchan; pchan = pchan->next) { - for (con = static_cast(pchan->constraints.first); con; con = con->next) { + LISTBASE_FOREACH (bPoseChannel *, pchan, &pose->chanbase) { + LISTBASE_FOREACH (bConstraint *, con, &pchan->constraints) { if (con->type == CONSTRAINT_TYPE_KINEMATIC) { bKinematicConstraint *data = (bKinematicConstraint *)con->data; @@ -1291,7 +1273,6 @@ bActionGroup *BKE_pose_add_group(bPose *pose, const char *name) void BKE_pose_remove_group(bPose *pose, bActionGroup *grp, const int index) { - bPoseChannel *pchan; int idx = index; if (idx < 1) { @@ -1304,7 +1285,7 @@ void BKE_pose_remove_group(bPose *pose, bActionGroup *grp, const int index) * - firstly, make sure nothing references it * - also, make sure that those after this item get corrected */ - for (pchan = static_cast(pose->chanbase.first); pchan; pchan = pchan->next) { + LISTBASE_FOREACH (bPoseChannel *, pchan, &pose->chanbase) { if (pchan->agrp_index == idx) { pchan->agrp_index = 0; } @@ -1342,11 +1323,9 @@ void BKE_pose_remove_group_index(bPose *pose, const int index) bool BKE_action_has_motion(const bAction *act) { - FCurve *fcu; - /* return on the first F-Curve that has some keyframes/samples defined */ if (act) { - for (fcu = static_cast(act->curves.first); fcu; fcu = fcu->next) { + LISTBASE_FOREACH (FCurve *, fcu, &act->curves) { if (fcu->totvert) { return true; } @@ -1404,12 +1383,11 @@ void BKE_action_frame_range_calc(const bAction *act, float *r_start, float *r_end) { - FCurve *fcu; float min = 999999999.0f, max = -999999999.0f; short foundvert = 0, foundmod = 0; if (act) { - for (fcu = static_cast(act->curves.first); fcu; fcu = fcu->next) { + LISTBASE_FOREACH (FCurve *, fcu, &act->curves) { /* if curve has keyframes, consider them first */ if (fcu->totvert) { float nmin, nmax; @@ -1516,7 +1494,6 @@ eAction_TransformFlags BKE_action_get_item_transform_flags(bAction *act, ListBase *curves) { PointerRNA ptr; - FCurve *fcu; char *basePath = nullptr; short flags = 0; @@ -1540,7 +1517,7 @@ eAction_TransformFlags BKE_action_get_item_transform_flags(bAction *act, /* search F-Curves for the given properties * - we cannot use the groups, since they may not be grouped in that way... */ - for (fcu = static_cast(act->curves.first); fcu; fcu = fcu->next) { + LISTBASE_FOREACH (FCurve *, fcu, &act->curves) { const char *bPtr = nullptr, *pPtr = nullptr; /* If enough flags have been found, @@ -1645,8 +1622,6 @@ eAction_TransformFlags BKE_action_get_item_transform_flags(bAction *act, void BKE_pose_rest(bPose *pose, bool selected_bones_only) { - bPoseChannel *pchan; - if (!pose) { return; } @@ -1654,7 +1629,7 @@ void BKE_pose_rest(bPose *pose, bool selected_bones_only) memset(pose->stride_offset, 0, sizeof(pose->stride_offset)); memset(pose->cyclic_offset, 0, sizeof(pose->cyclic_offset)); - for (pchan = static_cast(pose->chanbase.first); pchan; pchan = pchan->next) { + LISTBASE_FOREACH (bPoseChannel *, pchan, &pose->chanbase) { if (selected_bones_only && pchan->bone != nullptr && (pchan->bone->flag & BONE_SELECTED) == 0) { continue; @@ -1710,8 +1685,6 @@ void BKE_pose_copy_pchan_result(bPoseChannel *pchanto, const bPoseChannel *pchan bool BKE_pose_copy_result(bPose *to, bPose *from) { - bPoseChannel *pchanto, *pchanfrom; - if (to == nullptr || from == nullptr) { CLOG_ERROR( &LOG, "Pose copy error, pose to:%p from:%p", (void *)to, (void *)from); /* debug temp */ @@ -1723,10 +1696,8 @@ bool BKE_pose_copy_result(bPose *to, bPose *from) return false; } - for (pchanfrom = static_cast(from->chanbase.first); pchanfrom; - pchanfrom = pchanfrom->next) - { - pchanto = BKE_pose_channel_find_name(to, pchanfrom->name); + LISTBASE_FOREACH (bPoseChannel *, pchanfrom, &from->chanbase) { + bPoseChannel *pchanto = BKE_pose_channel_find_name(to, pchanfrom->name); if (pchanto != nullptr) { BKE_pose_copy_pchan_result(pchanto, pchanfrom); } diff --git a/source/blender/blenkernel/intern/anim_data.cc b/source/blender/blenkernel/intern/anim_data.cc index 1e7075b4a27..106199b1fac 100644 --- a/source/blender/blenkernel/intern/anim_data.cc +++ b/source/blender/blenkernel/intern/anim_data.cc @@ -469,13 +469,9 @@ void BKE_animdata_merge_copy( * - This assumes that the src ID is being merged into the dst ID */ if (fix_drivers) { - FCurve *fcu; - - for (fcu = static_cast(drivers.first); fcu; fcu = fcu->next) { + LISTBASE_FOREACH (FCurve *, fcu, &drivers) { ChannelDriver *driver = fcu->driver; - DriverVar *dvar; - - for (dvar = static_cast(driver->variables.first); dvar; dvar = dvar->next) { + LISTBASE_FOREACH (DriverVar *, dvar, &driver->variables) { DRIVER_TARGETS_USED_LOOPER_BEGIN (dvar) { if (dtar->id == src_id) { dtar->id = dst_id; @@ -782,10 +778,9 @@ static bool fcurves_path_rename_fix(ID *owner_id, ListBase *curves, bool verify_paths) { - FCurve *fcu; bool is_changed = false; /* We need to check every curve. */ - for (fcu = static_cast(curves->first); fcu; fcu = fcu->next) { + LISTBASE_FOREACH (FCurve *, fcu, curves) { if (fcu->rna_path == nullptr) { continue; } @@ -819,9 +814,8 @@ static bool drivers_path_rename_fix(ID *owner_id, bool verify_paths) { bool is_changed = false; - FCurve *fcu; /* We need to check every curve - drivers are F-Curves too. */ - for (fcu = static_cast(curves->first); fcu; fcu = fcu->next) { + LISTBASE_FOREACH (FCurve *, fcu, curves) { /* firstly, handle the F-Curve's own path */ if (fcu->rna_path != nullptr) { const char *old_rna_path = fcu->rna_path; @@ -833,9 +827,8 @@ static bool drivers_path_rename_fix(ID *owner_id, continue; } ChannelDriver *driver = fcu->driver; - DriverVar *dvar; /* driver variables */ - for (dvar = static_cast(driver->variables.first); dvar; dvar = dvar->next) { + LISTBASE_FOREACH (DriverVar *, dvar, &driver->variables) { /* only change the used targets, since the others will need fixing manually anyway */ DRIVER_TARGETS_USED_LOOPER_BEGIN (dvar) { /* rename RNA path */ @@ -872,10 +865,9 @@ static bool nlastrips_path_rename_fix(ID *owner_id, ListBase *strips, bool verify_paths) { - NlaStrip *strip; bool is_changed = false; /* Recursively check strips, fixing only actions. */ - for (strip = static_cast(strips->first); strip; strip = strip->next) { + LISTBASE_FOREACH (NlaStrip *, strip, strips) { /* fix strip's action */ if (strip->act != nullptr) { is_changed |= fcurves_path_rename_fix( @@ -1003,7 +995,6 @@ void BKE_animdata_fix_paths_rename(ID *owner_id, int newSubscript, bool verify_paths) { - NlaTrack *nlt; char *oldN, *newN; /* If no AnimData, no need to proceed. */ if (ELEM(nullptr, owner_id, adt)) { @@ -1048,7 +1039,7 @@ void BKE_animdata_fix_paths_rename(ID *owner_id, is_self_changed |= drivers_path_rename_fix( owner_id, ref_id, prefix, oldName, newName, oldN, newN, &adt->drivers, verify_paths); /* NLA Data - Animation Data for Strips */ - for (nlt = static_cast(adt->nla_tracks.first); nlt; nlt = nlt->next) { + LISTBASE_FOREACH (NlaTrack *, nlt, &adt->nla_tracks) { is_self_changed |= nlastrips_path_rename_fix( owner_id, prefix, oldName, newName, oldN, newN, &nlt->strips, verify_paths); } @@ -1090,11 +1081,10 @@ static bool fcurves_path_remove_fix(const char *prefix, ListBase *curves) /* Check RNA-Paths for a list of F-Curves */ static bool nlastrips_path_remove_fix(const char *prefix, ListBase *strips) { - NlaStrip *strip; bool any_removed = false; /* recursively check strips, fixing only actions... */ - for (strip = static_cast(strips->first); strip; strip = strip->next) { + LISTBASE_FOREACH (NlaStrip *, strip, strips) { /* fix strip's action */ if (strip->act) { any_removed |= fcurves_path_remove_fix(prefix, &strip->act->curves); @@ -1150,9 +1140,7 @@ static void fcurves_apply_cb(ID *id, ID_FCurve_Edit_Callback func, void *user_data) { - FCurve *fcu; - - for (fcu = static_cast(fcurves->first); fcu; fcu = fcu->next) { + LISTBASE_FOREACH (FCurve *, fcu, fcurves) { func(id, fcu, user_data); } } @@ -1160,9 +1148,7 @@ static void fcurves_apply_cb(ID *id, /* Helper for adt_apply_all_fcurves_cb() - Recursively go through each NLA strip */ static void nlastrips_apply_all_curves_cb(ID *id, ListBase *strips, AllFCurvesCbWrapper *wrapper) { - NlaStrip *strip; - - for (strip = static_cast(strips->first); strip; strip = strip->next) { + LISTBASE_FOREACH (NlaStrip *, strip, strips) { /* fix strip's action */ if (strip->act) { fcurves_apply_cb(id, &strip->act->curves, wrapper->func, wrapper->user_data); @@ -1177,7 +1163,6 @@ static void nlastrips_apply_all_curves_cb(ID *id, ListBase *strips, AllFCurvesCb static void adt_apply_all_fcurves_cb(ID *id, AnimData *adt, void *wrapper_data) { AllFCurvesCbWrapper *wrapper = static_cast(wrapper_data); - NlaTrack *nlt; if (adt->action) { fcurves_apply_cb(id, &adt->action->curves, wrapper->func, wrapper->user_data); @@ -1191,7 +1176,7 @@ static void adt_apply_all_fcurves_cb(ID *id, AnimData *adt, void *wrapper_data) fcurves_apply_cb(id, &adt->drivers, wrapper->func, wrapper->user_data); /* NLA Data - Animation Data for Strips */ - for (nlt = static_cast(adt->nla_tracks.first); nlt; nlt = nlt->next) { + LISTBASE_FOREACH (NlaTrack *, nlt, &adt->nla_tracks) { nlastrips_apply_all_curves_cb(id, &nlt->strips, wrapper); } } diff --git a/source/blender/blenkernel/intern/anim_sys.cc b/source/blender/blenkernel/intern/anim_sys.cc index 899a94b7f45..16f42b1b628 100644 --- a/source/blender/blenkernel/intern/anim_sys.cc +++ b/source/blender/blenkernel/intern/anim_sys.cc @@ -79,8 +79,6 @@ KS_Path *BKE_keyingset_find_path(KeyingSet *ks, int array_index, int /*group_mode*/) { - KS_Path *ksp; - /* sanity checks */ if (ELEM(nullptr, ks, rna_path, id)) { return nullptr; @@ -89,7 +87,7 @@ KS_Path *BKE_keyingset_find_path(KeyingSet *ks, /* loop over paths in the current KeyingSet, finding the first one where all settings match * (i.e. the first one where none of the checks fail and equal 0) */ - for (ksp = static_cast(ks->paths.first); ksp; ksp = ksp->next) { + LISTBASE_FOREACH (KS_Path *, ksp, &ks->paths) { short eq_id = 1, eq_path = 1, eq_index = 1, eq_group = 1; /* id */ @@ -235,15 +233,12 @@ void BKE_keyingset_free_path(KeyingSet *ks, KS_Path *ksp) void BKE_keyingsets_copy(ListBase *newlist, const ListBase *list) { - KeyingSet *ksn; - KS_Path *kspn; - BLI_duplicatelist(newlist, list); - for (ksn = static_cast(newlist->first); ksn; ksn = ksn->next) { + LISTBASE_FOREACH (KeyingSet *, ksn, newlist) { BLI_duplicatelist(&ksn->paths, &ksn->paths); - for (kspn = static_cast(ksn->paths.first); kspn; kspn = kspn->next) { + LISTBASE_FOREACH (KS_Path *, kspn, &ksn->paths) { kspn->rna_path = static_cast(MEM_dupallocN(kspn->rna_path)); } } @@ -251,8 +246,8 @@ void BKE_keyingsets_copy(ListBase *newlist, const ListBase *list) void BKE_keyingsets_foreach_id(LibraryForeachIDData *data, const ListBase *keyingsets) { - for (KeyingSet *ksn = static_cast(keyingsets->first); ksn; ksn = ksn->next) { - for (KS_Path *kspn = static_cast(ksn->paths.first); kspn; kspn = kspn->next) { + LISTBASE_FOREACH (KeyingSet *, ksn, keyingsets) { + LISTBASE_FOREACH (KS_Path *, kspn, &ksn->paths) { BKE_LIB_FOREACHID_PROCESS_ID(data, kspn->id, IDWALK_CB_NOP); } } @@ -773,12 +768,10 @@ static void animsys_evaluate_drivers(PointerRNA *ptr, AnimData *adt, const AnimationEvalContext *anim_eval_context) { - FCurve *fcu; - /* drivers are stored as F-Curves, but we cannot use the standard code, as we need to check if * the depsgraph requested that this driver be evaluated... */ - for (fcu = static_cast(adt->drivers.first); fcu; fcu = fcu->next) { + LISTBASE_FOREACH (FCurve *, fcu, &adt->drivers) { ChannelDriver *driver = fcu->driver; bool ok = false; @@ -981,13 +974,13 @@ NlaEvalStrip *nlastrips_ctime_get_strip(ListBase *list, const AnimationEvalContext *anim_eval_context, const bool flush_to_original) { - NlaStrip *strip, *estrip = nullptr; + NlaStrip *estrip = nullptr; NlaEvalStrip *nes; short side = 0; float ctime = anim_eval_context->eval_time; /* loop over strips, checking if they fall within the range */ - for (strip = static_cast(strips->first); strip; strip = strip->next) { + LISTBASE_FOREACH (NlaStrip *, strip, strips) { /* Check if current time occurs within this strip. */ if (IN_RANGE_INCL(ctime, strip->start, strip->end) || (strip->flag & NLASTRIP_FLAG_NO_TIME_MAP)) { @@ -2608,8 +2601,6 @@ static void nlasnapshot_from_action(PointerRNA *ptr, const float evaltime, NlaEvalSnapshot *r_snapshot) { - FCurve *fcu; - action_idcode_patch_check(ptr->owner_id, action); /* Evaluate modifiers which modify time to evaluate the base curves at. */ @@ -2621,7 +2612,7 @@ static void nlasnapshot_from_action(PointerRNA *ptr, const float modified_evaltime = evaluate_time_fmodifiers( &storage, modifiers, nullptr, 0.0f, evaltime); - for (fcu = static_cast(action->curves.first); fcu; fcu = fcu->next) { + LISTBASE_FOREACH (FCurve *, fcu, &action->curves) { if (!is_fcurve_evaluatable(fcu)) { continue; } @@ -3329,14 +3320,12 @@ static bool is_action_track_evaluated_without_nla(const AnimData *adt, */ static NlaTrack *nlatrack_find_tweaked(const AnimData *adt) { - NlaTrack *nlt; - if (adt == nullptr) { return nullptr; } /* Since the track itself gets disabled, we want the first disabled. */ - for (nlt = static_cast(adt->nla_tracks.first); nlt; nlt = nlt->next) { + LISTBASE_FOREACH (NlaTrack *, nlt, &adt->nla_tracks) { if (nlt->flag & NLATRACK_DISABLED) { return nlt; } @@ -3402,7 +3391,7 @@ static bool animsys_evaluate_nla_for_flush(NlaEvalData *echannels, nlastrips_ctime_get_strip_single(&estrips, &action_strip, anim_eval_context, flush_to_original); /* Per strip, evaluate and accumulate on top of existing channels. */ - for (nes = static_cast(estrips.first); nes; nes = nes->next) { + LISTBASE_FOREACH (NlaEvalStrip *, nes, &estrips) { nlasnapshot_blend_strip(ptr, echannels, nullptr, @@ -3537,7 +3526,7 @@ static void animsys_evaluate_nla_for_keyframing(PointerRNA *ptr, } /* For each strip, evaluate then accumulate on top of existing channels. */ - for (nes = static_cast(lower_estrips.first); nes; nes = nes->next) { + LISTBASE_FOREACH (NlaEvalStrip *, nes, &lower_estrips) { nlasnapshot_blend_strip(ptr, &r_context->lower_eval_data, nullptr, @@ -3871,10 +3860,8 @@ void BKE_animsys_free_nla_keyframing_context_cache(ListBase *cache) /* Evaluate Overrides */ static void animsys_evaluate_overrides(PointerRNA *ptr, AnimData *adt) { - AnimOverride *aor; - /* for each override, simply execute... */ - for (aor = static_cast(adt->overrides.first); aor; aor = aor->next) { + LISTBASE_FOREACH (AnimOverride *, aor, &adt->overrides) { PathResolvedRNA anim_rna; if (BKE_animsys_rna_path_resolve(ptr, aor->rna_path, aor->array_index, &anim_rna)) { BKE_animsys_write_to_rna_path(&anim_rna, aor->value); diff --git a/source/blender/blenkernel/intern/armature.cc b/source/blender/blenkernel/intern/armature.cc index bbc33b25bee..aa4e4c3bbf5 100644 --- a/source/blender/blenkernel/intern/armature.cc +++ b/source/blender/blenkernel/intern/armature.cc @@ -364,9 +364,7 @@ int BKE_armature_bonelist_count(const ListBase *lb) void BKE_armature_bonelist_free(ListBase *lb, const bool do_id_user) { - Bone *bone; - - for (bone = static_cast(lb->first); bone; bone = bone->next) { + LISTBASE_FOREACH (Bone *, bone, lb) { if (bone->prop) { IDP_FreeProperty_ex(bone->prop, do_id_user); } @@ -583,14 +581,12 @@ void BKE_armature_transform(bArmature *arm, const float mat[4][4], const bool do static Bone *get_named_bone_bonechildren(ListBase *lb, const char *name) { - Bone *curBone, *rbone; - - for (curBone = static_cast(lb->first); curBone; curBone = curBone->next) { + LISTBASE_FOREACH (Bone *, curBone, lb) { if (STREQ(curBone->name, name)) { return curBone; } - rbone = get_named_bone_bonechildren(&curBone->childbase, name); + Bone *rbone = get_named_bone_bonechildren(&curBone->childbase, name); if (rbone) { return rbone; } @@ -2288,10 +2284,8 @@ void BKE_armature_where_is_bone(Bone *bone, const Bone *bone_parent, const bool void BKE_armature_where_is(bArmature *arm) { - Bone *bone; - /* hierarchical from root to children */ - for (bone = static_cast(arm->bonebase.first); bone; bone = bone->next) { + LISTBASE_FOREACH (Bone *, bone, &arm->bonebase) { BKE_armature_where_is_bone(bone, nullptr, true); } } @@ -2388,9 +2382,7 @@ void BKE_pose_channels_clear_with_null_bone(bPose *pose, const bool do_id_user) void BKE_pose_rebuild(Main *bmain, Object *ob, bArmature *arm, const bool do_id_user) { - Bone *bone; bPose *pose; - bPoseChannel *pchan; int counter = 0; /* only done here */ @@ -2408,7 +2400,7 @@ void BKE_pose_rebuild(Main *bmain, Object *ob, bArmature *arm, const bool do_id_ /* first step, check if all channels are there */ Bone *prev_bone = nullptr; - for (bone = static_cast(arm->bonebase.first); bone; bone = bone->next) { + LISTBASE_FOREACH (Bone *, bone, &arm->bonebase) { counter = rebuild_pose_bone(pose, bone, nullptr, counter, &prev_bone); } @@ -2417,7 +2409,7 @@ void BKE_pose_rebuild(Main *bmain, Object *ob, bArmature *arm, const bool do_id_ BKE_pose_channels_hash_ensure(pose); - for (pchan = static_cast(pose->chanbase.first); pchan; pchan = pchan->next) { + LISTBASE_FOREACH (bPoseChannel *, pchan, &pose->chanbase) { /* Find the custom B-Bone handles. */ BKE_pchan_rebuild_bbone_handles(pose, pchan); /* Re-validate that we are still using a valid pchan form custom transform. */ @@ -2566,7 +2558,6 @@ void BKE_pose_where_is(Depsgraph *depsgraph, Scene *scene, Object *ob) { bArmature *arm; Bone *bone; - bPoseChannel *pchan; float imat[4][4]; float ctime; @@ -2586,8 +2577,7 @@ void BKE_pose_where_is(Depsgraph *depsgraph, Scene *scene, Object *ob) /* In edit-mode or rest-position we read the data from the bones. */ if (arm->edbo || (arm->flag & ARM_RESTPOS)) { - for (pchan = static_cast(ob->pose->chanbase.first); pchan; pchan = pchan->next) - { + LISTBASE_FOREACH (bPoseChannel *, pchan, &ob->pose->chanbase) { bone = pchan->bone; if (bone) { copy_m4_m4(pchan->pose_mat, bone->arm_mat); @@ -2600,8 +2590,7 @@ void BKE_pose_where_is(Depsgraph *depsgraph, Scene *scene, Object *ob) invert_m4_m4(ob->world_to_object, ob->object_to_world); /* world_to_object is needed */ /* 1. clear flags */ - for (pchan = static_cast(ob->pose->chanbase.first); pchan; pchan = pchan->next) - { + LISTBASE_FOREACH (bPoseChannel *, pchan, &ob->pose->chanbase) { pchan->flag &= ~(POSE_DONE | POSE_CHAIN | POSE_IKTREE | POSE_IKSPLINE); } @@ -2615,8 +2604,7 @@ void BKE_pose_where_is(Depsgraph *depsgraph, Scene *scene, Object *ob) BKE_pose_splineik_init_tree(scene, ob, ctime); /* 3. the main loop, channels are already hierarchical sorted from root to children */ - for (pchan = static_cast(ob->pose->chanbase.first); pchan; pchan = pchan->next) - { + LISTBASE_FOREACH (bPoseChannel *, pchan, &ob->pose->chanbase) { /* 4a. if we find an IK root, we handle it separated */ if (pchan->flag & POSE_IKTREE) { BIK_execute_tree(depsgraph, scene, ob, pchan, ctime); @@ -2635,7 +2623,7 @@ void BKE_pose_where_is(Depsgraph *depsgraph, Scene *scene, Object *ob) } /* calculating deform matrices */ - for (pchan = static_cast(ob->pose->chanbase.first); pchan; pchan = pchan->next) { + LISTBASE_FOREACH (bPoseChannel *, pchan, &ob->pose->chanbase) { if (pchan->bone) { invert_m4_m4(imat, pchan->bone->arm_mat); mul_m4_m4m4(pchan->chan_mat, pchan->pose_mat, imat); @@ -2651,11 +2639,9 @@ void BKE_pose_where_is(Depsgraph *depsgraph, Scene *scene, Object *ob) static int minmax_armature(Object *ob, float r_min[3], float r_max[3]) { - bPoseChannel *pchan; - /* For now, we assume BKE_pose_where_is has already been called * (hence we have valid data in pachan). */ - for (pchan = static_cast(ob->pose->chanbase.first); pchan; pchan = pchan->next) { + LISTBASE_FOREACH (bPoseChannel *, pchan, &ob->pose->chanbase) { minmax_v3v3_v3(r_min, r_max, pchan->pose_head); minmax_v3v3_v3(r_min, r_max, pchan->pose_tail); } @@ -2745,10 +2731,8 @@ bool BKE_pose_minmax(Object *ob, float r_min[3], float r_max[3], bool use_hidden if (ob->pose) { bArmature *arm = static_cast(ob->data); - bPoseChannel *pchan; - for (pchan = static_cast(ob->pose->chanbase.first); pchan; pchan = pchan->next) - { + LISTBASE_FOREACH (bPoseChannel *, pchan, &ob->pose->chanbase) { /* XXX pchan->bone may be nullptr for duplicated bones, see duplicateEditBoneObjects() * comment (editarmature.c:2592)... Skip in this case too! */ if (pchan->bone && (!((use_hidden == false) && (PBONE_VISIBLE(arm, pchan->bone) == false)) && diff --git a/source/blender/blenkernel/intern/armature_update.cc b/source/blender/blenkernel/intern/armature_update.cc index 46c09b6b577..0f9029e7d24 100644 --- a/source/blender/blenkernel/intern/armature_update.cc +++ b/source/blender/blenkernel/intern/armature_update.cc @@ -182,11 +182,9 @@ static void splineik_init_tree_from_pchan(Scene * /*scene*/, /* Tag which bones are members of Spline IK chains. */ static void splineik_init_tree(Scene *scene, Object *ob, float /*ctime*/) { - bPoseChannel *pchan; - /* Find the tips of Spline IK chains, * which are simply the bones which have been tagged as such. */ - for (pchan = static_cast(ob->pose->chanbase.first); pchan; pchan = pchan->next) { + LISTBASE_FOREACH (bPoseChannel *, pchan, &ob->pose->chanbase) { if (pchan->constflag & PCHAN_HAS_SPLINEIK) { splineik_init_tree_from_pchan(scene, ob, pchan); } diff --git a/source/blender/blenkernel/intern/blendfile.cc b/source/blender/blenkernel/intern/blendfile.cc index 084b5939b64..686cbdd2655 100644 --- a/source/blender/blenkernel/intern/blendfile.cc +++ b/source/blender/blenkernel/intern/blendfile.cc @@ -205,8 +205,7 @@ static void clean_paths(Main *bmain) static bool wm_scene_is_visible(wmWindowManager *wm, Scene *scene) { - wmWindow *win; - for (win = static_cast(wm->windows.first); win; win = win->next) { + LISTBASE_FOREACH (wmWindow *, win, &wm->windows) { if (win->scene == scene) { return true; } diff --git a/source/blender/blenkernel/intern/boids.cc b/source/blender/blenkernel/intern/boids.cc index 319c1db9d77..df8bbb1d9fe 100644 --- a/source/blender/blenkernel/intern/boids.cc +++ b/source/blender/blenkernel/intern/boids.cc @@ -74,7 +74,7 @@ static bool rule_goal_avoid(BoidRule *rule, BoidBrainData *bbd, BoidValues *val, BoidParticle *bpa = pa->boid; EffectedPoint epoint; ListBase *effectors = bbd->sim->psys->effectors; - EffectorCache *cur, *eff = nullptr; + EffectorCache *eff = nullptr; EffectorCache temp_eff; EffectorData efd, cur_efd; float mul = (rule->type == eBoidRuleType_Avoid ? 1.0 : -1.0); @@ -88,7 +88,7 @@ static bool rule_goal_avoid(BoidRule *rule, BoidBrainData *bbd, BoidValues *val, /* first find out goal/predator with highest priority */ if (effectors) { - for (cur = static_cast(effectors->first); cur; cur = cur->next) { + LISTBASE_FOREACH (EffectorCache *, cur, effectors) { Object *eob = cur->ob; PartDeflect *pd = cur->pd; @@ -211,9 +211,7 @@ static bool rule_avoid_collision(BoidRule *rule, const int raycast_flag = BVH_RAYCAST_DEFAULT & ~BVH_RAYCAST_WATERTIGHT; BoidRuleAvoidCollision *acbr = (BoidRuleAvoidCollision *)rule; KDTreeNearest_3d *ptn = nullptr; - ParticleTarget *pt; BoidParticle *bpa = pa->boid; - ColliderCache *coll; float vec[3] = {0.0f, 0.0f, 0.0f}, loc[3] = {0.0f, 0.0f, 0.0f}; float co1[3], vel1[3], co2[3], vel2[3]; float len, t, inp, t_min = 2.0f; @@ -237,8 +235,7 @@ static bool rule_avoid_collision(BoidRule *rule, hit.dist = col.original_ray_length = normalize_v3(ray_dir); /* find out closest deflector object */ - for (coll = static_cast(bbd->sim->colliders->first); coll; coll = coll->next) - { + LISTBASE_FOREACH (ColliderCache *, coll, bbd->sim->colliders) { /* don't check with current ground object */ if (coll->ob == bpa->ground) { continue; @@ -335,7 +332,7 @@ static bool rule_avoid_collision(BoidRule *rule, MEM_SAFE_FREE(ptn); /* check boids in other systems */ - for (pt = static_cast(bbd->sim->psys->targets.first); pt; pt = pt->next) { + LISTBASE_FOREACH (ParticleTarget *, pt, &bbd->sim->psys->targets) { ParticleSystem *epsys = psys_get_target_system(bbd->sim->ob, pt); if (epsys) { @@ -404,7 +401,6 @@ static bool rule_separate(BoidRule * /*rule*/, ParticleData *pa) { KDTreeNearest_3d *ptn = nullptr; - ParticleTarget *pt; float len = 2.0f * val->personal_space * pa->size + 1.0f; float vec[3] = {0.0f, 0.0f, 0.0f}; int neighbors = BLI_kdtree_3d_range_search( @@ -422,7 +418,7 @@ static bool rule_separate(BoidRule * /*rule*/, MEM_SAFE_FREE(ptn); /* check other boid systems */ - for (pt = static_cast(bbd->sim->psys->targets.first); pt; pt = pt->next) { + LISTBASE_FOREACH (ParticleTarget *, pt, &bbd->sim->psys->targets) { ParticleSystem *epsys = psys_get_target_system(bbd->sim->ob, pt); if (epsys) { @@ -679,7 +675,6 @@ static bool rule_fight(BoidRule *rule, BoidBrainData *bbd, BoidValues *val, Part { BoidRuleFight *fbr = (BoidRuleFight *)rule; KDTreeNearest_3d *ptn = nullptr; - ParticleTarget *pt; ParticleData *epars; ParticleData *enemy_pa = nullptr; BoidParticle *bpa; @@ -704,7 +699,7 @@ static bool rule_fight(BoidRule *rule, BoidBrainData *bbd, BoidValues *val, Part MEM_SAFE_FREE(ptn); /* add other friendlies and calculate enemy strength and find closest enemy */ - for (pt = static_cast(bbd->sim->psys->targets.first); pt; pt = pt->next) { + LISTBASE_FOREACH (ParticleTarget *, pt, &bbd->sim->psys->targets) { ParticleSystem *epsys = psys_get_target_system(bbd->sim->ob, pt); if (epsys) { epars = epsys->particles; @@ -853,7 +848,6 @@ static Object *boid_find_ground(BoidBrainData *bbd, const float zvec[3] = {0.0f, 0.0f, 2000.0f}; ParticleCollision col; - ColliderCache *coll; BVHTreeRayHit hit; float radius = 0.0f, t, ray_dir[3]; @@ -872,7 +866,7 @@ static Object *boid_find_ground(BoidBrainData *bbd, hit.dist = col.original_ray_length = normalize_v3(ray_dir); col.pce.inside = 0; - for (coll = static_cast(bbd->sim->colliders->first); coll; coll = coll->next) { + LISTBASE_FOREACH (ColliderCache *, coll, bbd->sim->colliders) { col.current = coll->ob; col.md = coll->collmd; col.fac1 = col.fac2 = 0.0f; @@ -905,7 +899,7 @@ static Object *boid_find_ground(BoidBrainData *bbd, hit.index = -1; hit.dist = col.original_ray_length = normalize_v3(ray_dir); - for (coll = static_cast(bbd->sim->colliders->first); coll; coll = coll->next) { + LISTBASE_FOREACH (ColliderCache *, coll, bbd->sim->colliders) { col.current = coll->ob; col.md = coll->collmd; @@ -956,10 +950,8 @@ static bool boid_rule_applies(ParticleData *pa, BoidSettings * /*boids*/, BoidRu } void boids_precalc_rules(ParticleSettings *part, float cfra) { - BoidState *state = static_cast(part->boids->states.first); - BoidRule *rule; - for (; state; state = state->next) { - for (rule = static_cast(state->rules.first); rule; rule = rule->next) { + LISTBASE_FOREACH (BoidState *, state, &part->boids->states) { + LISTBASE_FOREACH (BoidRule *, rule, &state->rules) { if (rule->type == eBoidRuleType_FollowLeader) { BoidRuleFollowLeader *flbr = (BoidRuleFollowLeader *)rule; @@ -1093,7 +1085,7 @@ void boid_brain(BoidBrainData *bbd, int p, ParticleData *pa) /* go through rules */ switch (state->ruleset_type) { case eBoidRulesetType_Fuzzy: { - for (rule = static_cast(state->rules.first); rule; rule = rule->next) { + LISTBASE_FOREACH (BoidRule *, rule, &state->rules) { if (apply_boid_rule(bbd, rule, &val, pa, state->rule_fuzziness)) { break; /* only first nonzero rule that comes through fuzzy rule is applied */ } @@ -1112,7 +1104,7 @@ void boid_brain(BoidBrainData *bbd, int p, ParticleData *pa) case eBoidRulesetType_Average: { float wanted_co[3] = {0.0f, 0.0f, 0.0f}, wanted_speed = 0.0f; int n = 0; - for (rule = static_cast(state->rules.first); rule; rule = rule->next) { + LISTBASE_FOREACH (BoidRule *, rule, &state->rules) { if (apply_boid_rule(bbd, rule, &val, pa, -1.0f)) { add_v3_v3(wanted_co, bbd->wanted_co); wanted_speed += bbd->wanted_speed; diff --git a/source/blender/blenkernel/intern/cachefile.cc b/source/blender/blenkernel/intern/cachefile.cc index 77461ef58ed..91f4a81aef4 100644 --- a/source/blender/blenkernel/intern/cachefile.cc +++ b/source/blender/blenkernel/intern/cachefile.cc @@ -438,9 +438,7 @@ bool BKE_cache_file_uses_render_procedural(const CacheFile *cache_file, Scene *s CacheFileLayer *BKE_cachefile_add_layer(CacheFile *cache_file, const char filepath[1024]) { - for (CacheFileLayer *layer = static_cast(cache_file->layers.first); layer; - layer = layer->next) - { + LISTBASE_FOREACH (CacheFileLayer *, layer, &cache_file->layers) { if (STREQ(layer->filepath, filepath)) { return nullptr; } diff --git a/source/blender/blenkernel/intern/collection.cc b/source/blender/blenkernel/intern/collection.cc index f96277e9f3f..0c9423f4583 100644 --- a/source/blender/blenkernel/intern/collection.cc +++ b/source/blender/blenkernel/intern/collection.cc @@ -1976,9 +1976,7 @@ bool BKE_collection_validate(Collection *collection) /* Check that children have each collection used/referenced only once. */ GSet *processed_collections = BLI_gset_ptr_new(__func__); - for (CollectionChild *child = static_cast(collection->children.first); child; - child = child->next) - { + LISTBASE_FOREACH (CollectionChild *, child, &collection->children) { void **r_key; if (BLI_gset_ensure_p_ex(processed_collections, child->collection, &r_key)) { is_ok = false; @@ -1990,11 +1988,7 @@ bool BKE_collection_validate(Collection *collection) /* Check that parents have each collection used/referenced only once. */ BLI_gset_clear(processed_collections, nullptr); - for (CollectionParent *parent = - static_cast(collection->runtime.parents.first); - parent; - parent = parent->next) - { + LISTBASE_FOREACH (CollectionParent *, parent, &collection->runtime.parents) { void **r_key; if (BLI_gset_ensure_p_ex(processed_collections, parent->collection, &r_key)) { is_ok = false; diff --git a/source/blender/blenkernel/intern/constraint.cc b/source/blender/blenkernel/intern/constraint.cc index c3605289d78..5801a62dc76 100644 --- a/source/blender/blenkernel/intern/constraint.cc +++ b/source/blender/blenkernel/intern/constraint.cc @@ -6300,8 +6300,6 @@ void BKE_constraint_targets_for_solving_get( const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con); if (cti && cti->get_constraint_targets) { - bConstraintTarget *ct; - /* get targets * - constraints should use ct->matrix, not directly accessing values * - ct->matrix members have not yet been calculated here! @@ -6317,12 +6315,12 @@ void BKE_constraint_targets_for_solving_get( * - calculate if possible, otherwise just initialize as identity matrix */ if (cti->get_target_matrix) { - for (ct = static_cast(targets->first); ct; ct = ct->next) { + LISTBASE_FOREACH (bConstraintTarget *, ct, targets) { cti->get_target_matrix(depsgraph, con, cob, ct, ctime); } } else { - for (ct = static_cast(targets->first); ct; ct = ct->next) { + LISTBASE_FOREACH (bConstraintTarget *, ct, targets) { unit_m4(ct->matrix); } } @@ -6355,7 +6353,6 @@ void BKE_constraints_solve(Depsgraph *depsgraph, bConstraintOb *cob, float ctime) { - bConstraint *con; float oldmat[4][4]; float enf; @@ -6365,7 +6362,7 @@ void BKE_constraints_solve(Depsgraph *depsgraph, } /* loop over available constraints, solving and blending them */ - for (con = static_cast(conlist->first); con; con = con->next) { + LISTBASE_FOREACH (bConstraint *, con, conlist) { const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con); ListBase targets = {nullptr, nullptr}; diff --git a/source/blender/blenkernel/intern/data_transfer.cc b/source/blender/blenkernel/intern/data_transfer.cc index e24c4d760fa..4aad34759a8 100644 --- a/source/blender/blenkernel/intern/data_transfer.cc +++ b/source/blender/blenkernel/intern/data_transfer.cc @@ -1511,13 +1511,9 @@ bool BKE_object_data_transfer_ex(Depsgraph *depsgraph, tolayers, space_transform)) { - CustomDataTransferLayerMap *lay_mapit; - changed |= (lay_map.first != nullptr); - for (lay_mapit = static_cast(lay_map.first); lay_mapit; - lay_mapit = lay_mapit->next) - { + LISTBASE_FOREACH (CustomDataTransferLayerMap *, lay_mapit, &lay_map) { CustomData_data_transfer(&geom_map[VDATA], lay_mapit); } @@ -1600,13 +1596,9 @@ bool BKE_object_data_transfer_ex(Depsgraph *depsgraph, tolayers, space_transform)) { - CustomDataTransferLayerMap *lay_mapit; - changed |= (lay_map.first != nullptr); - for (lay_mapit = static_cast(lay_map.first); lay_mapit; - lay_mapit = lay_mapit->next) - { + LISTBASE_FOREACH (CustomDataTransferLayerMap *, lay_mapit, &lay_map) { CustomData_data_transfer(&geom_map[EDATA], lay_mapit); } @@ -1704,13 +1696,9 @@ bool BKE_object_data_transfer_ex(Depsgraph *depsgraph, tolayers, space_transform)) { - CustomDataTransferLayerMap *lay_mapit; - changed |= (lay_map.first != nullptr); - for (lay_mapit = static_cast(lay_map.first); lay_mapit; - lay_mapit = lay_mapit->next) - { + LISTBASE_FOREACH (CustomDataTransferLayerMap *, lay_mapit, &lay_map) { CustomData_data_transfer(&geom_map[LDATA], lay_mapit); } @@ -1793,13 +1781,9 @@ bool BKE_object_data_transfer_ex(Depsgraph *depsgraph, tolayers, space_transform)) { - CustomDataTransferLayerMap *lay_mapit; - changed |= (lay_map.first != nullptr); - for (lay_mapit = static_cast(lay_map.first); lay_mapit; - lay_mapit = lay_mapit->next) - { + LISTBASE_FOREACH (CustomDataTransferLayerMap *, lay_mapit, &lay_map) { CustomData_data_transfer(&geom_map[PDATA], lay_mapit); } diff --git a/source/blender/blenkernel/intern/deform.cc b/source/blender/blenkernel/intern/deform.cc index 20969cf6092..e4002e89533 100644 --- a/source/blender/blenkernel/intern/deform.cc +++ b/source/blender/blenkernel/intern/deform.cc @@ -684,9 +684,8 @@ int BKE_object_defgroup_flip_index(const Object *ob, int index, const bool use_d static bool defgroup_find_name_dupe(const char *name, bDeformGroup *dg, Object *ob) { const ListBase *defbase = BKE_object_defgroup_list(ob); - bDeformGroup *curdef; - for (curdef = static_cast(defbase->first); curdef; curdef = curdef->next) { + LISTBASE_FOREACH (bDeformGroup *, curdef, defbase) { if (dg != curdef) { if (STREQ(curdef->name, name)) { return true; diff --git a/source/blender/blenkernel/intern/effect.cc b/source/blender/blenkernel/intern/effect.cc index 25bd75e5cc7..5dd92af5873 100644 --- a/source/blender/blenkernel/intern/effect.cc +++ b/source/blender/blenkernel/intern/effect.cc @@ -479,7 +479,6 @@ static float eff_calc_visibility(ListBase *colliders, { const int raycast_flag = BVH_RAYCAST_DEFAULT & ~BVH_RAYCAST_WATERTIGHT; ListBase *colls = colliders; - ColliderCache *col; float norm[3], len = 0.0; float visibility = 1.0, absorption = 0.0; @@ -497,7 +496,7 @@ static float eff_calc_visibility(ListBase *colliders, len = normalize_v3(norm); /* check all collision objects */ - for (col = static_cast(colls->first); col; col = col->next) { + LISTBASE_FOREACH (ColliderCache *, col, colls) { CollisionModifierData *collmd = col->collmd; if (col->ob == eff->ob) { @@ -1152,7 +1151,6 @@ void BKE_effectors_apply(ListBase *effectors, * (particles are guided along a curve bezier or old nurbs) * (is independent of other effectors) */ - EffectorCache *eff; EffectorData efd; int p = 0, tot = 1, step = 1; @@ -1160,7 +1158,7 @@ void BKE_effectors_apply(ListBase *effectors, /* Check for min distance here? (yes would be cool to add that, ton) */ if (effectors) { - for (eff = static_cast(effectors->first); eff; eff = eff->next) { + LISTBASE_FOREACH (EffectorCache *, eff, effectors) { /* object effectors were fully checked to be OK to evaluate! */ get_effector_tot(eff, &efd, point, &tot, &p, &step); diff --git a/source/blender/blenkernel/intern/fcurve.cc b/source/blender/blenkernel/intern/fcurve.cc index fd114d1bf05..ddc89295894 100644 --- a/source/blender/blenkernel/intern/fcurve.cc +++ b/source/blender/blenkernel/intern/fcurve.cc @@ -1766,9 +1766,7 @@ void BKE_fcurve_merge_duplicate_keys(FCurve *fcu, const int sel_flag, const bool bool found = false; /* If there's another selected frame here, merge it */ - for (tRetainedKeyframe *rk = static_cast(retained_keys.last); rk; - rk = rk->prev) - { + LISTBASE_FOREACH_BACKWARD (tRetainedKeyframe *, rk, &retained_keys) { if (IS_EQT(rk->frame, bezt->vec[1][0], BEZT_BINARYSEARCH_THRESH)) { rk->val += bezt->vec[1][1]; rk->tot_count++; @@ -1819,9 +1817,7 @@ void BKE_fcurve_merge_duplicate_keys(FCurve *fcu, const int sel_flag, const bool /* Is this keyframe a candidate for deletion? */ /* TODO: Replace loop with an O(1) lookup instead */ - for (tRetainedKeyframe *rk = static_cast(retained_keys.last); rk; - rk = rk->prev) - { + LISTBASE_FOREACH_BACKWARD (tRetainedKeyframe *, rk, &retained_keys) { if (IS_EQT(bezt->vec[1][0], rk->frame, BEZT_BINARYSEARCH_THRESH)) { /* Selected keys are treated with greater care than unselected ones... */ if (BEZT_ISSEL_ANY(bezt)) { diff --git a/source/blender/blenkernel/intern/fcurve_driver.cc b/source/blender/blenkernel/intern/fcurve_driver.cc index 361ef054a17..1d13dc464b2 100644 --- a/source/blender/blenkernel/intern/fcurve_driver.cc +++ b/source/blender/blenkernel/intern/fcurve_driver.cc @@ -1264,7 +1264,7 @@ static void evaluate_driver_sum(const AnimationEvalContext *anim_eval_context, int tot = 0; /* Loop through targets, adding (hopefully we don't get any overflow!). */ - for (dvar = static_cast(driver->variables.first); dvar; dvar = dvar->next) { + LISTBASE_FOREACH (DriverVar *, dvar, &driver->variables) { value += driver_get_variable_value(anim_eval_context, driver, dvar); tot++; } @@ -1281,11 +1281,10 @@ static void evaluate_driver_sum(const AnimationEvalContext *anim_eval_context, static void evaluate_driver_min_max(const AnimationEvalContext *anim_eval_context, ChannelDriver *driver) { - DriverVar *dvar; float value = 0.0f; /* Loop through the variables, getting the values and comparing them to existing ones. */ - for (dvar = static_cast(driver->variables.first); dvar; dvar = dvar->next) { + LISTBASE_FOREACH (DriverVar *, dvar, &driver->variables) { /* Get value. */ float tmp_val = driver_get_variable_value(anim_eval_context, driver, dvar); diff --git a/source/blender/blenkernel/intern/fmodifier.cc b/source/blender/blenkernel/intern/fmodifier.cc index ffd0ce59a33..6d1c243f5ff 100644 --- a/source/blender/blenkernel/intern/fmodifier.cc +++ b/source/blender/blenkernel/intern/fmodifier.cc @@ -1240,15 +1240,13 @@ void free_fmodifiers(ListBase *modifiers) FModifier *find_active_fmodifier(ListBase *modifiers) { - FModifier *fcm; - /* sanity checks */ if (ELEM(nullptr, modifiers, modifiers->first)) { return nullptr; } /* loop over modifiers until 'active' one is found */ - for (fcm = static_cast(modifiers->first); fcm; fcm = fcm->next) { + LISTBASE_FOREACH (FModifier *, fcm, modifiers) { if (fcm->flag & FMODIFIER_FLAG_ACTIVE) { return fcm; } @@ -1260,15 +1258,13 @@ FModifier *find_active_fmodifier(ListBase *modifiers) void set_active_fmodifier(ListBase *modifiers, FModifier *fcm) { - FModifier *fm; - /* sanity checks */ if (ELEM(nullptr, modifiers, modifiers->first)) { return; } /* deactivate all, and set current one active */ - for (fm = static_cast(modifiers->first); fm; fm = fm->next) { + LISTBASE_FOREACH (FModifier *, fm, modifiers) { fm->flag &= ~FMODIFIER_FLAG_ACTIVE; } @@ -1280,8 +1276,6 @@ void set_active_fmodifier(ListBase *modifiers, FModifier *fcm) bool list_has_suitable_fmodifier(const ListBase *modifiers, int mtype, short acttype) { - FModifier *fcm; - /* if there are no specific filtering criteria, just skip */ if ((mtype == 0) && (acttype == 0)) { return (modifiers && modifiers->first); @@ -1293,7 +1287,7 @@ bool list_has_suitable_fmodifier(const ListBase *modifiers, int mtype, short act } /* Find the first modifier fitting these criteria. */ - for (fcm = static_cast(modifiers->first); fcm; fcm = fcm->next) { + LISTBASE_FOREACH (FModifier *, fcm, modifiers) { const FModifierTypeInfo *fmi = fmodifier_get_typeinfo(fcm); short mOk = 1, aOk = 1; /* by default 1, so that when only one test, won't fail */ diff --git a/source/blender/blenkernel/intern/freestyle.cc b/source/blender/blenkernel/intern/freestyle.cc index ff424630121..e1db4ea23e1 100644 --- a/source/blender/blenkernel/intern/freestyle.cc +++ b/source/blender/blenkernel/intern/freestyle.cc @@ -40,9 +40,7 @@ void BKE_freestyle_config_init(FreestyleConfig *config) void BKE_freestyle_config_free(FreestyleConfig *config, const bool do_id_user) { - FreestyleLineSet *lineset; - - for (lineset = (FreestyleLineSet *)config->linesets.first; lineset; lineset = lineset->next) { + LISTBASE_FOREACH (FreestyleLineSet *, lineset, &config->linesets) { if (lineset->group) { if (do_id_user) { id_us_min(&lineset->group->id); @@ -64,8 +62,8 @@ void BKE_freestyle_config_copy(FreestyleConfig *new_config, const FreestyleConfig *config, const int flag) { - FreestyleLineSet *lineset, *new_lineset; - FreestyleModuleConfig *module, *new_module; + FreestyleLineSet *new_lineset; + FreestyleModuleConfig *new_module; new_config->mode = config->mode; new_config->flags = config->flags; @@ -74,14 +72,14 @@ void BKE_freestyle_config_copy(FreestyleConfig *new_config, new_config->crease_angle = config->crease_angle; BLI_listbase_clear(&new_config->linesets); - for (lineset = (FreestyleLineSet *)config->linesets.first; lineset; lineset = lineset->next) { + LISTBASE_FOREACH (FreestyleLineSet *, lineset, &config->linesets) { new_lineset = alloc_lineset(); copy_lineset(new_lineset, lineset, flag); BLI_addtail(&new_config->linesets, (void *)new_lineset); } BLI_listbase_clear(&new_config->modules); - for (module = (FreestyleModuleConfig *)config->modules.first; module; module = module->next) { + LISTBASE_FOREACH (FreestyleModuleConfig *, module, &config->modules) { new_module = alloc_module(); copy_module(new_module, module); BLI_addtail(&new_config->modules, (void *)new_module); @@ -211,9 +209,7 @@ bool BKE_freestyle_lineset_delete(FreestyleConfig *config, FreestyleLineSet *lin FreestyleLineSet *BKE_freestyle_lineset_get_active(FreestyleConfig *config) { - FreestyleLineSet *lineset; - - for (lineset = (FreestyleLineSet *)config->linesets.first; lineset; lineset = lineset->next) { + LISTBASE_FOREACH (FreestyleLineSet *, lineset, &config->linesets) { if (lineset->flags & FREESTYLE_LINESET_CURRENT) { return lineset; } diff --git a/source/blender/blenkernel/intern/gpencil_geom_legacy.cc b/source/blender/blenkernel/intern/gpencil_geom_legacy.cc index 4ce54d5e2e4..1d1ba31a740 100644 --- a/source/blender/blenkernel/intern/gpencil_geom_legacy.cc +++ b/source/blender/blenkernel/intern/gpencil_geom_legacy.cc @@ -397,7 +397,7 @@ static void stroke_defvert_create_nr_list(MDeformVert *dv_list, for (j = 0; j < dv->totweight; j++) { bool found = false; dw = &dv->dw[j]; - for (ld = (LinkData *)result->first; ld; ld = ld->next) { + LISTBASE_FOREACH (LinkData *, ld, result) { if (ld->data == POINTER_FROM_INT(dw->def_nr)) { found = true; break; @@ -418,7 +418,6 @@ static void stroke_defvert_create_nr_list(MDeformVert *dv_list, static MDeformVert *stroke_defvert_new_count(int count, int totweight, ListBase *def_nr_list) { int i, j; - LinkData *ld; MDeformVert *dst = (MDeformVert *)MEM_mallocN(count * sizeof(MDeformVert), "new_deformVert"); for (i = 0; i < count; i++) { @@ -427,7 +426,7 @@ static MDeformVert *stroke_defvert_new_count(int count, int totweight, ListBase dst[i].totweight = totweight; j = 0; /* re-assign deform groups */ - for (ld = (LinkData *)def_nr_list->first; ld; ld = ld->next) { + LISTBASE_FOREACH (LinkData *, ld, def_nr_list) { dst[i].dw[j].def_nr = POINTER_AS_INT(ld->data); j++; } diff --git a/source/blender/blenkernel/intern/gpencil_legacy.cc b/source/blender/blenkernel/intern/gpencil_legacy.cc index a06be450da3..353f21cd70f 100644 --- a/source/blender/blenkernel/intern/gpencil_legacy.cc +++ b/source/blender/blenkernel/intern/gpencil_legacy.cc @@ -1220,12 +1220,10 @@ bool BKE_gpencil_layer_is_editable(const bGPDlayer *gpl) bGPDframe *BKE_gpencil_layer_frame_find(bGPDlayer *gpl, int cframe) { - bGPDframe *gpf; - /* Search in reverse order, since this is often used for playback/adding, * where it's less likely that we're interested in the earlier frames */ - for (gpf = static_cast(gpl->frames.last); gpf; gpf = gpf->prev) { + LISTBASE_FOREACH_BACKWARD (bGPDframe *, gpf, &gpl->frames) { if (gpf->framenum == cframe) { return gpf; } @@ -1583,15 +1581,13 @@ bGPDlayer *BKE_gpencil_layer_active_get(bGPdata *gpd) bGPDlayer *BKE_gpencil_layer_get_by_name(bGPdata *gpd, const char *name, int first_if_not_found) { - bGPDlayer *gpl; - /* error checking */ if (ELEM(nullptr, gpd, gpd->layers.first)) { return nullptr; } /* loop over layers until found (assume only one active) */ - for (gpl = static_cast(gpd->layers.first); gpl; gpl = gpl->next) { + LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) { if (STREQ(name, gpl->info)) { return gpl; } diff --git a/source/blender/blenkernel/intern/image.cc b/source/blender/blenkernel/intern/image.cc index c3ab70a2b1b..21007e20ef6 100644 --- a/source/blender/blenkernel/intern/image.cc +++ b/source/blender/blenkernel/intern/image.cc @@ -365,8 +365,7 @@ static void image_blend_write(BlendWriter *writer, ID *id, const void *id_addres BLO_write_id_struct(writer, Image, id_address, &ima->id); BKE_id_blend_write(writer, &ima->id); - for (imapf = static_cast(ima->packedfiles.first); imapf; imapf = imapf->next) - { + LISTBASE_FOREACH (ImagePackedFile *, imapf, &ima->packedfiles) { BLO_write_struct(writer, ImagePackedFile, imapf); BKE_packedfile_blend_write(writer, imapf->packedfile); } @@ -2685,8 +2684,7 @@ static void image_viewer_create_views(const RenderData *rd, Image *ima) image_add_view(ima, "", ""); } else { - for (SceneRenderView *srv = static_cast(rd->views.first); srv; - srv = srv->next) { + LISTBASE_FOREACH (SceneRenderView *, srv, &rd->views) { if (BKE_scene_multiview_is_render_view_active(rd, srv) == false) { continue; } @@ -2711,11 +2709,8 @@ void BKE_image_ensure_viewer_views(const RenderData *rd, Image *ima, ImageUser * /* multiview also needs to be sure all the views are synced */ if (is_multiview && !do_reset) { - SceneRenderView *srv; - ImageView *iv; - - for (iv = static_cast(ima->views.first); iv; iv = iv->next) { - srv = static_cast( + LISTBASE_FOREACH (ImageView *, iv, &ima->views) { + SceneRenderView *srv = static_cast( BLI_findstring(&rd->views, iv->name, offsetof(SceneRenderView, name))); if ((srv == nullptr) || (BKE_scene_multiview_is_render_view_active(rd, srv) == false)) { do_reset = true; @@ -3151,9 +3146,7 @@ void BKE_image_signal(Main *bmain, Image *ima, ImageUser *iuser, int signal) BKE_image_packfiles(nullptr, ima, ID_BLEND_PATH(bmain, &ima->id)); } else { - ImagePackedFile *imapf; - for (imapf = static_cast(ima->packedfiles.first); imapf; - imapf = imapf->next) { + LISTBASE_FOREACH (ImagePackedFile *, imapf, &ima->packedfiles) { PackedFile *pf; pf = BKE_packedfile_new(nullptr, imapf->filepath, ID_BLEND_PATH(bmain, &ima->id)); if (pf) { @@ -4774,11 +4767,9 @@ void BKE_image_pool_free(ImagePool *pool) BLI_INLINE ImBuf *image_pool_find_item( ImagePool *pool, Image *image, int entry, int index, bool *found) { - ImagePoolItem *item; - *found = false; - for (item = static_cast(pool->image_buffers.first); item; item = item->next) { + LISTBASE_FOREACH (ImagePoolItem *, item, &pool->image_buffers) { if (item->image == image && item->entry == entry && item->index == index) { *found = true; return item->ibuf; @@ -5365,7 +5356,6 @@ ImBuf *BKE_image_get_first_ibuf(Image *image) static void image_update_views_format(Image *ima, ImageUser *iuser) { - SceneRenderView *srv; ImageView *iv; Scene *scene = iuser->scene; const bool is_multiview = ((scene->r.scemode & R_MULTIVIEW) != 0) && @@ -5399,7 +5389,7 @@ static void image_update_views_format(Image *ima, ImageUser *iuser) } /* create all the image views */ - for (srv = static_cast(scene->r.views.first); srv; srv = srv->next) { + LISTBASE_FOREACH (SceneRenderView *, srv, &scene->r.views) { if (BKE_scene_multiview_is_render_view_active(&scene->r, srv)) { char filepath_view[FILE_MAX]; SNPRINTF(filepath_view, "%s%s%s", prefix, srv->suffix, ext); diff --git a/source/blender/blenkernel/intern/ipo.cc b/source/blender/blenkernel/intern/ipo.cc index 11b0661c2af..d1e3dc7b9a1 100644 --- a/source/blender/blenkernel/intern/ipo.cc +++ b/source/blender/blenkernel/intern/ipo.cc @@ -1727,7 +1727,7 @@ static void ipo_to_animato(ID *id, } /* loop over IPO-Curves, freeing as we progress */ - for (icu = static_cast(ipo->curve.first); icu; icu = icu->next) { + LISTBASE_FOREACH (IpoCurve *, icu, &ipo->curve) { /* Since an IPO-Curve may end up being made into many F-Curves (i.e. bitflag curves), * we figure out the best place to put the channel, * then tell the curve-converter to just dump there. */ @@ -2107,8 +2107,6 @@ void do_versions_ipos_to_animato(Main *bmain) /* objects */ for (id = static_cast(bmain->objects.first); id; id = static_cast(id->next)) { Object *ob = (Object *)id; - bPoseChannel *pchan; - bConstraint *con; bConstraintChannel *conchan, *conchann; if (G.debug & G_DEBUG) { @@ -2166,9 +2164,8 @@ void do_versions_ipos_to_animato(Main *bmain) /* Verify if there's AnimData block */ BKE_animdata_ensure_id(id); - for (pchan = static_cast(ob->pose->chanbase.first); pchan; - pchan = pchan->next) { - for (con = static_cast(pchan->constraints.first); con; con = con->next) { + LISTBASE_FOREACH (bPoseChannel *, pchan, &ob->pose->chanbase) { + LISTBASE_FOREACH (bConstraint *, con, &pchan->constraints) { /* if constraint has own IPO, convert add these to Object * (NOTE: they're most likely to be drivers too) */ @@ -2185,7 +2182,7 @@ void do_versions_ipos_to_animato(Main *bmain) } /* check constraints for local IPO's */ - for (con = static_cast(ob->constraints.first); con; con = con->next) { + LISTBASE_FOREACH (bConstraint *, con, &ob->constraints) { /* if constraint has own IPO, convert add these to Object * (NOTE: they're most likely to be drivers too) */ diff --git a/source/blender/blenkernel/intern/key.cc b/source/blender/blenkernel/intern/key.cc index b328d8813de..39df7f7f247 100644 --- a/source/blender/blenkernel/intern/key.cc +++ b/source/blender/blenkernel/intern/key.cc @@ -306,7 +306,6 @@ Key *BKE_key_add(Main *bmain, ID *id) /* common function */ void BKE_key_sort(Key *key) { KeyBlock *kb; - KeyBlock *kb2; /* locate the key which is out of position */ for (kb = static_cast(key->block.first); kb; kb = kb->next) { @@ -321,7 +320,7 @@ void BKE_key_sort(Key *key) BLI_remlink(&key->block, kb); /* find the right location and insert before */ - for (kb2 = static_cast(key->block.first); kb2; kb2 = kb2->next) { + LISTBASE_FOREACH (KeyBlock *, kb2, &key->block) { if (kb2->pos > kb->pos) { BLI_insertlinkafter(&key->block, kb2->prev, kb); break; @@ -1879,8 +1878,7 @@ KeyBlock *BKE_keyblock_add_ctime(Key *key, const char *name, const bool do_force * won't have to systematically use retiming func (and have ordering issues, too). See #39897. */ if (!do_force && (key->type != KEY_RELATIVE)) { - KeyBlock *it_kb; - for (it_kb = static_cast(key->block.first); it_kb; it_kb = it_kb->next) { + LISTBASE_FOREACH (KeyBlock *, it_kb, &key->block) { /* Use epsilon to avoid floating point precision issues. * 1e-3 because the position is stored as frame * 1e-2. */ if (compare_ff(it_kb->pos, cpos, 1e-3f)) { @@ -2063,7 +2061,6 @@ int BKE_keyblock_curve_element_count(const ListBase *nurb) void BKE_keyblock_update_from_curve(const Curve * /*cu*/, KeyBlock *kb, const ListBase *nurb) { - Nurb *nu; BezTriple *bezt; BPoint *bp; float *fp; @@ -2078,7 +2075,7 @@ void BKE_keyblock_update_from_curve(const Curve * /*cu*/, KeyBlock *kb, const Li } fp = static_cast(kb->data); - for (nu = static_cast(nurb->first); nu; nu = nu->next) { + LISTBASE_FOREACH (Nurb *, nu, nurb) { if (nu->bezt) { for (a = nu->pntsu, bezt = nu->bezt; a; a--, bezt++) { for (int i = 0; i < 3; i++) { @@ -2107,7 +2104,7 @@ void BKE_keyblock_curve_data_transform(const ListBase *nurb, { const float *src = static_cast(src_data); float *dst = static_cast(dst_data); - for (Nurb *nu = static_cast(nurb->first); nu; nu = nu->next) { + LISTBASE_FOREACH (Nurb *, nu, nurb) { if (nu->bezt) { for (int a = nu->pntsu; a; a--) { for (int i = 0; i < 3; i++) { @@ -2348,11 +2345,10 @@ void BKE_keyblock_update_from_vertcos(const Object *ob, KeyBlock *kb, const floa } else if (ELEM(ob->type, OB_CURVES_LEGACY, OB_SURF)) { const Curve *cu = (const Curve *)ob->data; - const Nurb *nu; const BezTriple *bezt; const BPoint *bp; - for (nu = static_cast(cu->nurb.first); nu; nu = nu->next) { + LISTBASE_FOREACH (const Nurb *, nu, &cu->nurb) { if (nu->bezt) { for (a = nu->pntsu, bezt = nu->bezt; a; a--, bezt++) { for (int i = 0; i < 3; i++, co++) { @@ -2438,11 +2434,10 @@ float (*BKE_keyblock_convert_to_vertcos(const Object *ob, const KeyBlock *kb))[3 } else if (ELEM(ob->type, OB_CURVES_LEGACY, OB_SURF)) { const Curve *cu = (const Curve *)ob->data; - const Nurb *nu; const BezTriple *bezt; const BPoint *bp; - for (nu = static_cast(cu->nurb.first); nu; nu = nu->next) { + LISTBASE_FOREACH (Nurb *, nu, &cu->nurb) { if (nu->bezt) { for (a = nu->pntsu, bezt = nu->bezt; a; a--, bezt++) { for (int i = 0; i < 3; i++, co++) { @@ -2475,11 +2470,10 @@ void BKE_keyblock_update_from_offset(const Object *ob, KeyBlock *kb, const float } else if (ELEM(ob->type, OB_CURVES_LEGACY, OB_SURF)) { const Curve *cu = (const Curve *)ob->data; - const Nurb *nu; const BezTriple *bezt; const BPoint *bp; - for (nu = static_cast(cu->nurb.first); nu; nu = nu->next) { + LISTBASE_FOREACH (const Nurb *, nu, &cu->nurb) { if (nu->bezt) { for (a = nu->pntsu, bezt = nu->bezt; a; a--, bezt++) { for (int i = 0; i < 3; i++, ofs++) { diff --git a/source/blender/blenkernel/intern/lattice.cc b/source/blender/blenkernel/intern/lattice.cc index 158d4ab9ddf..503a3275170 100644 --- a/source/blender/blenkernel/intern/lattice.cc +++ b/source/blender/blenkernel/intern/lattice.cc @@ -705,9 +705,7 @@ void BKE_lattice_transform(Lattice *lt, const float mat[4][4], bool do_keys) } if (do_keys && lt->key) { - KeyBlock *kb; - - for (kb = static_cast(lt->key->block.first); kb; kb = kb->next) { + LISTBASE_FOREACH (KeyBlock *, kb, <->key->block) { float *fp = static_cast(kb->data); for (i = kb->totelem; i--; fp += 3) { mul_m4_v3(mat, fp); @@ -735,9 +733,7 @@ void BKE_lattice_translate(Lattice *lt, const float offset[3], bool do_keys) } if (do_keys && lt->key) { - KeyBlock *kb; - - for (kb = static_cast(lt->key->block.first); kb; kb = kb->next) { + LISTBASE_FOREACH (KeyBlock *, kb, <->key->block) { float *fp = static_cast(kb->data); for (i = kb->totelem; i--; fp += 3) { add_v3_v3(fp, offset); diff --git a/source/blender/blenkernel/intern/layer.cc b/source/blender/blenkernel/intern/layer.cc index 63894db46a5..6d4f6c385d8 100644 --- a/source/blender/blenkernel/intern/layer.cc +++ b/source/blender/blenkernel/intern/layer.cc @@ -566,10 +566,9 @@ void BKE_view_layer_rename(Main *bmain, Scene *scene, ViewLayer *view_layer, con sizeof(view_layer->name)); if (scene->nodetree) { - bNode *node; int index = BLI_findindex(&scene->view_layers, view_layer); - for (node = static_cast(scene->nodetree->nodes.first); node; node = node->next) { + LISTBASE_FOREACH (bNode *, node, &scene->nodetree->nodes) { if (node->type == CMP_NODE_R_LAYERS && node->id == nullptr) { if (node->custom1 == index) { STRNCPY(node->name, view_layer->name); diff --git a/source/blender/blenkernel/intern/linestyle.cc b/source/blender/blenkernel/intern/linestyle.cc index 5f31fa4c710..55088d35dd8 100644 --- a/source/blender/blenkernel/intern/linestyle.cc +++ b/source/blender/blenkernel/intern/linestyle.cc @@ -76,36 +76,23 @@ static void linestyle_copy_data(Main *bmain, ID *id_dst, const ID *id_src, const linestyle_dst->nodetree->owner_id = &linestyle_dst->id; } - LineStyleModifier *linestyle_modifier; BLI_listbase_clear(&linestyle_dst->color_modifiers); - for (linestyle_modifier = (LineStyleModifier *)linestyle_src->color_modifiers.first; - linestyle_modifier; - linestyle_modifier = linestyle_modifier->next) - { + LISTBASE_FOREACH (LineStyleModifier *, linestyle_modifier, &linestyle_src->color_modifiers) { BKE_linestyle_color_modifier_copy(linestyle_dst, linestyle_modifier, flag_subdata); } BLI_listbase_clear(&linestyle_dst->alpha_modifiers); - for (linestyle_modifier = (LineStyleModifier *)linestyle_src->alpha_modifiers.first; - linestyle_modifier; - linestyle_modifier = linestyle_modifier->next) - { + LISTBASE_FOREACH (LineStyleModifier *, linestyle_modifier, &linestyle_src->alpha_modifiers) { BKE_linestyle_alpha_modifier_copy(linestyle_dst, linestyle_modifier, flag_subdata); } BLI_listbase_clear(&linestyle_dst->thickness_modifiers); - for (linestyle_modifier = (LineStyleModifier *)linestyle_src->thickness_modifiers.first; - linestyle_modifier; - linestyle_modifier = linestyle_modifier->next) - { + LISTBASE_FOREACH (LineStyleModifier *, linestyle_modifier, &linestyle_src->thickness_modifiers) { BKE_linestyle_thickness_modifier_copy(linestyle_dst, linestyle_modifier, flag_subdata); } BLI_listbase_clear(&linestyle_dst->geometry_modifiers); - for (linestyle_modifier = (LineStyleModifier *)linestyle_src->geometry_modifiers.first; - linestyle_modifier; - linestyle_modifier = linestyle_modifier->next) - { + LISTBASE_FOREACH (LineStyleModifier *, linestyle_modifier, &linestyle_src->geometry_modifiers) { BKE_linestyle_geometry_modifier_copy(linestyle_dst, linestyle_modifier, flag_subdata); } } @@ -187,9 +174,7 @@ static void linestyle_foreach_id(ID *id, LibraryForeachIDData *data) static void write_linestyle_color_modifiers(BlendWriter *writer, ListBase *modifiers) { - LineStyleModifier *m; - - for (m = static_cast(modifiers->first); m; m = m->next) { + LISTBASE_FOREACH (LineStyleModifier *, m, modifiers) { int struct_nr; switch (m->type) { case LS_MODIFIER_ALONG_STROKE: @@ -221,7 +206,7 @@ static void write_linestyle_color_modifiers(BlendWriter *writer, ListBase *modif } BLO_write_struct_by_id(writer, struct_nr, m); } - for (m = static_cast(modifiers->first); m; m = m->next) { + LISTBASE_FOREACH (LineStyleModifier *, m, modifiers) { switch (m->type) { case LS_MODIFIER_ALONG_STROKE: BLO_write_struct(writer, ColorBand, ((LineStyleColorModifier_AlongStroke *)m)->color_ramp); @@ -256,9 +241,7 @@ static void write_linestyle_color_modifiers(BlendWriter *writer, ListBase *modif static void write_linestyle_alpha_modifiers(BlendWriter *writer, ListBase *modifiers) { - LineStyleModifier *m; - - for (m = static_cast(modifiers->first); m; m = m->next) { + LISTBASE_FOREACH (LineStyleModifier *, m, modifiers) { int struct_nr; switch (m->type) { case LS_MODIFIER_ALONG_STROKE: @@ -290,7 +273,7 @@ static void write_linestyle_alpha_modifiers(BlendWriter *writer, ListBase *modif } BLO_write_struct_by_id(writer, struct_nr, m); } - for (m = static_cast(modifiers->first); m; m = m->next) { + LISTBASE_FOREACH (LineStyleModifier *, m, modifiers) { switch (m->type) { case LS_MODIFIER_ALONG_STROKE: BKE_curvemapping_blend_write(writer, ((LineStyleAlphaModifier_AlongStroke *)m)->curve); @@ -324,9 +307,7 @@ static void write_linestyle_alpha_modifiers(BlendWriter *writer, ListBase *modif static void write_linestyle_thickness_modifiers(BlendWriter *writer, ListBase *modifiers) { - LineStyleModifier *m; - - for (m = static_cast(modifiers->first); m; m = m->next) { + LISTBASE_FOREACH (LineStyleModifier *, m, modifiers) { int struct_nr; switch (m->type) { case LS_MODIFIER_ALONG_STROKE: @@ -361,7 +342,7 @@ static void write_linestyle_thickness_modifiers(BlendWriter *writer, ListBase *m } BLO_write_struct_by_id(writer, struct_nr, m); } - for (m = static_cast(modifiers->first); m; m = m->next) { + LISTBASE_FOREACH (LineStyleModifier *, m, modifiers) { switch (m->type) { case LS_MODIFIER_ALONG_STROKE: BKE_curvemapping_blend_write(writer, ((LineStyleThicknessModifier_AlongStroke *)m)->curve); @@ -393,9 +374,7 @@ static void write_linestyle_thickness_modifiers(BlendWriter *writer, ListBase *m static void write_linestyle_geometry_modifiers(BlendWriter *writer, ListBase *modifiers) { - LineStyleModifier *m; - - for (m = static_cast(modifiers->first); m; m = m->next) { + LISTBASE_FOREACH (LineStyleModifier *, m, modifiers) { int struct_nr; switch (m->type) { case LS_MODIFIER_SAMPLING: @@ -1921,13 +1900,12 @@ bool BKE_linestyle_geometry_modifier_move(FreestyleLineStyle *linestyle, void BKE_linestyle_modifier_list_color_ramps(FreestyleLineStyle *linestyle, ListBase *listbase) { - LineStyleModifier *m; ColorBand *color_ramp; LinkData *link; BLI_listbase_clear(listbase); - for (m = (LineStyleModifier *)linestyle->color_modifiers.first; m; m = m->next) { + LISTBASE_FOREACH (LineStyleModifier *, m, &linestyle->color_modifiers) { switch (m->type) { case LS_MODIFIER_ALONG_STROKE: color_ramp = ((LineStyleColorModifier_AlongStroke *)m)->color_ramp; @@ -1952,10 +1930,9 @@ void BKE_linestyle_modifier_list_color_ramps(FreestyleLineStyle *linestyle, List char *BKE_linestyle_path_to_color_ramp(FreestyleLineStyle *linestyle, ColorBand *color_ramp) { - LineStyleModifier *m; bool found = false; - for (m = (LineStyleModifier *)linestyle->color_modifiers.first; m; m = m->next) { + LISTBASE_FOREACH (LineStyleModifier *, m, &linestyle->color_modifiers) { switch (m->type) { case LS_MODIFIER_ALONG_STROKE: if (color_ramp == ((LineStyleColorModifier_AlongStroke *)m)->color_ramp) { @@ -2013,10 +1990,7 @@ bool BKE_linestyle_use_textures(FreestyleLineStyle *linestyle, const bool use_sh { if (use_shading_nodes) { if (linestyle && linestyle->use_nodes && linestyle->nodetree) { - bNode *node; - - for (node = static_cast(linestyle->nodetree->nodes.first); node; node = node->next) - { + LISTBASE_FOREACH (bNode *, node, &linestyle->nodetree->nodes) { if (node->typeinfo->nclass == NODE_CLASS_TEXTURE) { return true; } diff --git a/source/blender/blenkernel/intern/material.cc b/source/blender/blenkernel/intern/material.cc index 28e9e547412..d91784199ff 100644 --- a/source/blender/blenkernel/intern/material.cc +++ b/source/blender/blenkernel/intern/material.cc @@ -1377,12 +1377,9 @@ bool BKE_object_material_slot_remove(Main *bmain, Object *ob) static bNode *nodetree_uv_node_recursive(bNode *node) { - bNode *inode; - bNodeSocket *sock; - - for (sock = static_cast(node->inputs.first); sock; sock = sock->next) { + LISTBASE_FOREACH (bNodeSocket *, sock, &node->inputs) { if (sock->link) { - inode = sock->link->fromnode; + bNode *inode = sock->link->fromnode; if (inode->typeinfo->nclass == NODE_CLASS_INPUT && inode->typeinfo->type == SH_NODE_UVMAP) { return inode; } diff --git a/source/blender/blenkernel/intern/movieclip.cc b/source/blender/blenkernel/intern/movieclip.cc index d8017858d59..bb3175f300e 100644 --- a/source/blender/blenkernel/intern/movieclip.cc +++ b/source/blender/blenkernel/intern/movieclip.cc @@ -166,11 +166,7 @@ static void write_movieTracks(BlendWriter *writer, ListBase *tracks) static void write_moviePlaneTracks(BlendWriter *writer, ListBase *plane_tracks_base) { - MovieTrackingPlaneTrack *plane_track; - - for (plane_track = static_cast(plane_tracks_base->first); plane_track; - plane_track = plane_track->next) - { + LISTBASE_FOREACH (MovieTrackingPlaneTrack *, plane_track, plane_tracks_base) { BLO_write_struct(writer, MovieTrackingPlaneTrack, plane_track); BLO_write_pointer_array(writer, plane_track->point_tracksnr, plane_track->point_tracks); diff --git a/source/blender/blenkernel/intern/nla.cc b/source/blender/blenkernel/intern/nla.cc index 09582e01f02..b01f5bdd05c 100644 --- a/source/blender/blenkernel/intern/nla.cc +++ b/source/blender/blenkernel/intern/nla.cc @@ -138,7 +138,7 @@ NlaStrip *BKE_nlastrip_copy(Main *bmain, const int flag) { NlaStrip *strip_d; - NlaStrip *cs, *cs_d; + NlaStrip *cs_d; const bool do_id_user = (flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0; @@ -172,7 +172,7 @@ NlaStrip *BKE_nlastrip_copy(Main *bmain, /* make a copy of all the child-strips, one at a time */ BLI_listbase_clear(&strip_d->strips); - for (cs = static_cast(strip->strips.first); cs; cs = cs->next) { + LISTBASE_FOREACH (NlaStrip *, cs, &strip->strips) { cs_d = BKE_nlastrip_copy(bmain, cs, use_same_action, flag); BLI_addtail(&strip_d->strips, cs_d); } @@ -186,7 +186,7 @@ NlaTrack *BKE_nlatrack_copy(Main *bmain, const bool use_same_actions, const int flag) { - NlaStrip *strip, *strip_d; + NlaStrip *strip_d; NlaTrack *nlt_d; /* sanity check */ @@ -201,7 +201,7 @@ NlaTrack *BKE_nlatrack_copy(Main *bmain, /* make a copy of all the strips, one at a time */ BLI_listbase_clear(&nlt_d->strips); - for (strip = static_cast(nlt->strips.first); strip; strip = strip->next) { + LISTBASE_FOREACH (NlaStrip *, strip, &nlt->strips) { strip_d = BKE_nlastrip_copy(bmain, strip, use_same_actions, flag); BLI_addtail(&nlt_d->strips, strip_d); } @@ -212,7 +212,7 @@ NlaTrack *BKE_nlatrack_copy(Main *bmain, void BKE_nla_tracks_copy(Main *bmain, ListBase *dst, const ListBase *src, const int flag) { - NlaTrack *nlt, *nlt_d; + NlaTrack *nlt_d; /* sanity checks */ if (ELEM(nullptr, dst, src)) { @@ -223,7 +223,7 @@ void BKE_nla_tracks_copy(Main *bmain, ListBase *dst, const ListBase *src, const BLI_listbase_clear(dst); /* copy each NLA-track, one at a time */ - for (nlt = static_cast(src->first); nlt; nlt = nlt->next) { + LISTBASE_FOREACH (NlaTrack *, nlt, src) { /* make a copy, and add the copy to the destination list */ /* XXX: we need to fix this sometime. */ nlt_d = BKE_nlatrack_copy(bmain, nlt, true, flag); @@ -759,8 +759,6 @@ float BKE_nla_tweakedit_remap(AnimData *adt, float cframe, short mode) bool BKE_nlastrips_has_space(ListBase *strips, float start, float end) { - NlaStrip *strip; - /* sanity checks */ if ((strips == nullptr) || IS_EQF(start, end)) { return false; @@ -771,7 +769,7 @@ bool BKE_nlastrips_has_space(ListBase *strips, float start, float end) } /* loop over NLA strips checking for any overlaps with this area... */ - for (strip = static_cast(strips->first); strip; strip = strip->next) { + LISTBASE_FOREACH (NlaStrip *, strip, strips) { /* if start frame of strip is past the target end-frame, that means that * we've gone past the window we need to check for, so things are fine */ @@ -794,7 +792,7 @@ bool BKE_nlastrips_has_space(ListBase *strips, float start, float end) void BKE_nlastrips_sort_strips(ListBase *strips) { ListBase tmp = {nullptr, nullptr}; - NlaStrip *strip, *sstrip, *stripn; + NlaStrip *strip, *stripn; /* sanity checks */ if (ELEM(nullptr, strips, strips->first)) { @@ -814,7 +812,7 @@ void BKE_nlastrips_sort_strips(ListBase *strips) */ BLI_remlink(strips, strip); - for (sstrip = static_cast(tmp.last); sstrip; sstrip = sstrip->prev) { + LISTBASE_FOREACH_BACKWARD (NlaStrip *, sstrip, &tmp) { /* check if add after */ if (sstrip->start <= strip->start) { BLI_insertlinkafter(&tmp, sstrip, strip); @@ -836,14 +834,13 @@ void BKE_nlastrips_sort_strips(ListBase *strips) void BKE_nlastrips_add_strip_unsafe(ListBase *strips, NlaStrip *strip) { - NlaStrip *ns; bool not_added = true; /* sanity checks */ BLI_assert(!ELEM(nullptr, strips, strip)); /* find the right place to add the strip to the nominated track */ - for (ns = static_cast(strips->first); ns; ns = ns->next) { + LISTBASE_FOREACH (NlaStrip *, ns, strips) { /* if current strip occurs after the new strip, add it before */ if (ns->start >= strip->start) { BLI_insertlinkbefore(strips, ns, strip); @@ -1023,7 +1020,6 @@ bool BKE_nlameta_add_strip(NlaStrip *mstrip, NlaStrip *strip) void BKE_nlameta_flush_transforms(NlaStrip *mstrip) { - NlaStrip *strip; float oStart, oEnd, offset; float oLen, nLen; short scaleChanged = 0; @@ -1061,7 +1057,7 @@ void BKE_nlameta_flush_transforms(NlaStrip *mstrip) } /* for each child-strip, calculate new start/end points based on this new info */ - for (strip = static_cast(mstrip->strips.first); strip; strip = strip->next) { + LISTBASE_FOREACH (NlaStrip *, strip, &mstrip->strips) { if (scaleChanged) { float p1, p2; @@ -1088,7 +1084,7 @@ void BKE_nlameta_flush_transforms(NlaStrip *mstrip) } /* apply a second pass over child strips, to finish up unfinished business */ - for (strip = static_cast(mstrip->strips.first); strip; strip = strip->next) { + LISTBASE_FOREACH (NlaStrip *, strip, &mstrip->strips) { /* only if scale changed, need to perform RNA updates */ if (scaleChanged) { PointerRNA ptr; @@ -1109,15 +1105,13 @@ void BKE_nlameta_flush_transforms(NlaStrip *mstrip) NlaTrack *BKE_nlatrack_find_active(ListBase *tracks) { - NlaTrack *nlt; - /* sanity check */ if (ELEM(nullptr, tracks, tracks->first)) { return nullptr; } /* try to find the first active track */ - for (nlt = static_cast(tracks->first); nlt; nlt = nlt->next) { + LISTBASE_FOREACH (NlaTrack *, nlt, tracks) { if (nlt->flag & NLATRACK_ACTIVE) { return nlt; } @@ -1129,15 +1123,13 @@ NlaTrack *BKE_nlatrack_find_active(ListBase *tracks) NlaTrack *BKE_nlatrack_find_tweaked(AnimData *adt) { - NlaTrack *nlt; - /* sanity check */ if (adt == nullptr) { return nullptr; } /* Since the track itself gets disabled, we want the first disabled... */ - for (nlt = static_cast(adt->nla_tracks.first); nlt; nlt = nlt->next) { + LISTBASE_FOREACH (NlaTrack *, nlt, &adt->nla_tracks) { if (nlt->flag & (NLATRACK_ACTIVE | NLATRACK_DISABLED)) { /* For good measure, make sure that strip actually exists there */ if (BLI_findindex(&nlt->strips, adt->actstrip) != -1) { @@ -1160,15 +1152,13 @@ NlaTrack *BKE_nlatrack_find_tweaked(AnimData *adt) void BKE_nlatrack_solo_toggle(AnimData *adt, NlaTrack *nlt) { - NlaTrack *nt; - /* sanity check */ if (ELEM(nullptr, adt, adt->nla_tracks.first)) { return; } /* firstly, make sure 'solo' flag for all tracks is disabled */ - for (nt = static_cast(adt->nla_tracks.first); nt; nt = nt->next) { + LISTBASE_FOREACH (NlaTrack *, nt, &adt->nla_tracks) { if (nt != nlt) { nt->flag &= ~NLATRACK_SOLO; } @@ -1194,15 +1184,13 @@ void BKE_nlatrack_solo_toggle(AnimData *adt, NlaTrack *nlt) void BKE_nlatrack_set_active(ListBase *tracks, NlaTrack *nlt_a) { - NlaTrack *nlt; - /* sanity check */ if (ELEM(nullptr, tracks, tracks->first)) { return; } /* deactivate all the rest */ - for (nlt = static_cast(tracks->first); nlt; nlt = nlt->next) { + LISTBASE_FOREACH (NlaTrack *, nlt, tracks) { nlt->flag &= ~NLATRACK_ACTIVE; } @@ -1411,17 +1399,14 @@ void BKE_nlastrip_remove_and_free(ListBase *strips, NlaStrip *strip, const bool void BKE_nlastrip_set_active(AnimData *adt, NlaStrip *strip) { - NlaTrack *nlt; - NlaStrip *nls; - /* sanity checks */ if (adt == nullptr) { return; } /* Loop over tracks, deactivating. */ - for (nlt = static_cast(adt->nla_tracks.first); nlt; nlt = nlt->next) { - for (nls = static_cast(nlt->strips.first); nls; nls = nls->next) { + LISTBASE_FOREACH (NlaTrack *, nlt, &adt->nla_tracks) { + LISTBASE_FOREACH (NlaStrip *, nls, &nlt->strips) { if (nls != strip) { nls->flag &= ~NLASTRIP_FLAG_ACTIVE; } @@ -1646,15 +1631,13 @@ void BKE_nlastrip_recalculate_blend(NlaStrip *strip) bool BKE_nlatrack_has_animated_strips(NlaTrack *nlt) { - NlaStrip *strip; - /* sanity checks */ if (ELEM(nullptr, nlt, nlt->strips.first)) { return false; } /* check each strip for F-Curves only (don't care about whether the flags are set) */ - for (strip = static_cast(nlt->strips.first); strip; strip = strip->next) { + LISTBASE_FOREACH (NlaStrip *, strip, &nlt->strips) { if (strip->fcurves.first) { return true; } @@ -1666,15 +1649,13 @@ bool BKE_nlatrack_has_animated_strips(NlaTrack *nlt) bool BKE_nlatracks_have_animated_strips(ListBase *tracks) { - NlaTrack *nlt; - /* sanity checks */ if (ELEM(nullptr, tracks, tracks->first)) { return false; } /* check each track, stopping on the first hit */ - for (nlt = static_cast(tracks->first); nlt; nlt = nlt->next) { + LISTBASE_FOREACH (NlaTrack *, nlt, tracks) { if (BKE_nlatrack_has_animated_strips(nlt)) { return true; } @@ -1790,8 +1771,6 @@ static bool nla_editbone_name_check(void *arg, const char *name) void BKE_nlastrip_validate_name(AnimData *adt, NlaStrip *strip) { GHash *gh; - NlaStrip *tstrip; - NlaTrack *nlt; /* sanity checks */ if (ELEM(nullptr, adt, strip)) { @@ -1822,8 +1801,8 @@ void BKE_nlastrip_validate_name(AnimData *adt, NlaStrip *strip) */ gh = BLI_ghash_str_new("nlastrip_validate_name gh"); - for (nlt = static_cast(adt->nla_tracks.first); nlt; nlt = nlt->next) { - for (tstrip = static_cast(nlt->strips.first); tstrip; tstrip = tstrip->next) { + LISTBASE_FOREACH (NlaTrack *, nlt, &adt->nla_tracks) { + LISTBASE_FOREACH (NlaStrip *, tstrip, &nlt->strips) { /* don't add the strip of interest */ if (tstrip == strip) { continue; @@ -1862,13 +1841,11 @@ static void nlastrip_get_endpoint_overlaps(NlaStrip *strip, float **start, float **end) { - NlaStrip *nls; - /* find strips that overlap over the start/end of the given strip, * but which don't cover the entire length */ /* TODO: this scheme could get quite slow for doing this on many strips... */ - for (nls = static_cast(track->strips.first); nls; nls = nls->next) { + LISTBASE_FOREACH (NlaStrip *, nls, &track->strips) { /* Check if strip overlaps (extends over or exactly on) * the entire range of the strip we're validating. */ if ((nls->start <= strip->start) && (nls->end >= strip->end)) { @@ -1984,8 +1961,6 @@ static bool nlastrip_validate_transition_start_end(ListBase *strips, NlaStrip *s void BKE_nla_validate_state(AnimData *adt) { - NlaTrack *nlt; - /* sanity checks */ if (ELEM(nullptr, adt, adt->nla_tracks.first)) { return; @@ -1993,7 +1968,7 @@ void BKE_nla_validate_state(AnimData *adt) /* Adjust blending values for auto-blending, * and also do an initial pass to find the earliest strip. */ - for (nlt = static_cast(adt->nla_tracks.first); nlt; nlt = nlt->next) { + LISTBASE_FOREACH (NlaTrack *, nlt, &adt->nla_tracks) { LISTBASE_FOREACH_MUTABLE (NlaStrip *, strip, &nlt->strips) { if (!nlastrip_validate_transition_start_end(&nlt->strips, strip)) { @@ -2017,12 +1992,9 @@ void BKE_nla_validate_state(AnimData *adt) bool BKE_nla_action_is_stashed(AnimData *adt, bAction *act) { - NlaTrack *nlt; - NlaStrip *strip; - - for (nlt = static_cast(adt->nla_tracks.first); nlt; nlt = nlt->next) { + LISTBASE_FOREACH (NlaTrack *, nlt, &adt->nla_tracks) { if (strstr(nlt->name, STASH_TRACK_NAME)) { - for (strip = static_cast(nlt->strips.first); strip; strip = strip->next) { + LISTBASE_FOREACH (NlaStrip *, strip, &nlt->strips) { if (strip->act == act) { return true; } @@ -2162,13 +2134,13 @@ static void nla_tweakmode_find_active(const ListBase /* NlaTrack */ *nla_tracks, NlaTrack **r_track_of_active_strip, NlaStrip **r_active_strip) { - NlaTrack *nlt, *activeTrack = nullptr; - NlaStrip *strip, *activeStrip = nullptr; + NlaTrack *activeTrack = nullptr; + NlaStrip *activeStrip = nullptr; /* go over the tracks, finding the active one, and its active strip * - if we cannot find both, then there's nothing to do */ - for (nlt = static_cast(nla_tracks->first); nlt; nlt = nlt->next) { + LISTBASE_FOREACH (NlaTrack *, nlt, nla_tracks) { /* check if active */ if (nlt->flag & NLATRACK_ACTIVE) { /* store reference to this active track */ @@ -2188,7 +2160,7 @@ static void nla_tweakmode_find_active(const ListBase /* NlaTrack */ *nla_tracks, */ if (activeTrack == nullptr) { /* try last selected track for active strip */ - for (nlt = static_cast(nla_tracks->last); nlt; nlt = nlt->prev) { + LISTBASE_FOREACH_BACKWARD (NlaTrack *, nlt, nla_tracks) { if (nlt->flag & NLATRACK_SELECTED) { /* assume this is the active track */ activeTrack = nlt; @@ -2202,7 +2174,7 @@ static void nla_tweakmode_find_active(const ListBase /* NlaTrack */ *nla_tracks, if ((activeTrack) && (activeStrip == nullptr)) { /* No active strip in active or last selected track; * compromise for first selected (assuming only single). */ - for (strip = static_cast(activeTrack->strips.first); strip; strip = strip->next) { + LISTBASE_FOREACH (NlaStrip *, strip, &activeTrack->strips) { if (strip->flag & (NLASTRIP_FLAG_SELECT | NLASTRIP_FLAG_ACTIVE)) { activeStrip = strip; break; @@ -2217,7 +2189,7 @@ static void nla_tweakmode_find_active(const ListBase /* NlaTrack */ *nla_tracks, bool BKE_nla_tweakmode_enter(AnimData *adt) { NlaTrack *nlt, *activeTrack = nullptr; - NlaStrip *strip, *activeStrip = nullptr; + NlaStrip *activeStrip = nullptr; /* verify that data is valid */ if (ELEM(nullptr, adt, adt->nla_tracks.first)) { @@ -2243,8 +2215,8 @@ bool BKE_nla_tweakmode_enter(AnimData *adt) /* Go over all the tracks, tagging each strip that uses the same * action as the active strip, but leaving everything else alone. */ - for (nlt = static_cast(adt->nla_tracks.first); nlt; nlt = nlt->next) { - for (strip = static_cast(nlt->strips.first); strip; strip = strip->next) { + LISTBASE_FOREACH (NlaTrack *, nlt, &adt->nla_tracks) { + LISTBASE_FOREACH (NlaStrip *, strip, &nlt->strips) { if (strip->act == activeStrip->act) { strip->flag |= NLASTRIP_FLAG_TWEAKUSER; } @@ -2291,7 +2263,6 @@ bool BKE_nla_tweakmode_enter(AnimData *adt) void BKE_nla_tweakmode_exit(AnimData *adt) { NlaStrip *strip; - NlaTrack *nlt; /* verify that data is valid */ if (ELEM(nullptr, adt, adt->nla_tracks.first)) { @@ -2319,10 +2290,10 @@ void BKE_nla_tweakmode_exit(AnimData *adt) /* for all Tracks, clear the 'disabled' flag * for all Strips, clear the 'tweak-user' flag */ - for (nlt = static_cast(adt->nla_tracks.first); nlt; nlt = nlt->next) { + LISTBASE_FOREACH (NlaTrack *, nlt, &adt->nla_tracks) { nlt->flag &= ~NLATRACK_DISABLED; - for (strip = static_cast(nlt->strips.first); strip; strip = strip->next) { + LISTBASE_FOREACH (NlaStrip *, strip, &nlt->strips) { /* sync strip extents if this strip uses the same action */ if ((adt->actstrip) && (adt->actstrip->act == strip->act) && (strip->flag & NLASTRIP_FLAG_SYNC_LENGTH)) diff --git a/source/blender/blenkernel/intern/object.cc b/source/blender/blenkernel/intern/object.cc index 9ce34ebdb72..5f116a6aa14 100644 --- a/source/blender/blenkernel/intern/object.cc +++ b/source/blender/blenkernel/intern/object.cc @@ -5250,8 +5250,7 @@ static Object *obrel_armature_find(Object *ob) ob_arm = ob->parent; } else { - ModifierData *mod; - for (mod = (ModifierData *)ob->modifiers.first; mod; mod = mod->next) { + LISTBASE_FOREACH (ModifierData *, mod, &ob->modifiers) { if (mod->type == eModifierType_Armature) { ob_arm = ((ArmatureModifierData *)mod)->object; } diff --git a/source/blender/blenkernel/intern/object_deform.cc b/source/blender/blenkernel/intern/object_deform.cc index fca4edf05a4..d3f835958e7 100644 --- a/source/blender/blenkernel/intern/object_deform.cc +++ b/source/blender/blenkernel/intern/object_deform.cc @@ -53,10 +53,6 @@ static Lattice *object_defgroup_lattice_get(ID *id) void BKE_object_defgroup_remap_update_users(Object *ob, const int *map) { - ModifierData *md; - ParticleSystem *psys; - int a; - /* these cases don't use names to refer to vertex groups, so when * they get removed the numbers get out of sync, this corrects that */ @@ -64,7 +60,7 @@ void BKE_object_defgroup_remap_update_users(Object *ob, const int *map) ob->soft->vertgroup = map[ob->soft->vertgroup]; } - for (md = static_cast(ob->modifiers.first); md; md = md->next) { + LISTBASE_FOREACH (ModifierData *, md, &ob->modifiers) { if (md->type == eModifierType_Explode) { ExplodeModifierData *emd = (ExplodeModifierData *)md; emd->vgroup = map[emd->vgroup]; @@ -81,8 +77,8 @@ void BKE_object_defgroup_remap_update_users(Object *ob, const int *map) } } - for (psys = static_cast(ob->particlesystem.first); psys; psys = psys->next) { - for (a = 0; a < PSYS_TOT_VG; a++) { + LISTBASE_FOREACH (ParticleSystem *, psys, &ob->particlesystem) { + for (int a = 0; a < PSYS_TOT_VG; a++) { psys->vgroup[a] = map[psys->vgroup[a]]; } } @@ -207,12 +203,11 @@ bool BKE_object_defgroup_clear(Object *ob, bDeformGroup *dg, const bool use_sele bool BKE_object_defgroup_clear_all(Object *ob, const bool use_selection) { - bDeformGroup *dg; bool changed = false; const ListBase *defbase = BKE_object_defgroup_list(ob); - for (dg = static_cast(defbase->first); dg; dg = dg->next) { + LISTBASE_FOREACH (bDeformGroup *, dg, defbase) { if (BKE_object_defgroup_clear(ob, dg, use_selection)) { changed = true; } @@ -564,7 +559,7 @@ bool *BKE_object_defgroup_validmap_get(Object *ob, const int defbase_tot) gh = BLI_ghash_str_new_ex(__func__, defbase_tot); /* add all names to a hash table */ - for (dg = static_cast(defbase->first); dg; dg = dg->next) { + LISTBASE_FOREACH (bDeformGroup *, dg, defbase) { BLI_ghash_insert(gh, dg->name, nullptr); } @@ -585,9 +580,8 @@ bool *BKE_object_defgroup_validmap_get(Object *ob, const int defbase_tot) if (amd->object && amd->object->pose) { bPose *pose = amd->object->pose; - bPoseChannel *chan; - for (chan = static_cast(pose->chanbase.first); chan; chan = chan->next) { + LISTBASE_FOREACH (bPoseChannel *, chan, &pose->chanbase) { void **val_p; if (chan->bone->flag & BONE_NO_DEFORM) { continue; diff --git a/source/blender/blenkernel/intern/particle.cc b/source/blender/blenkernel/intern/particle.cc index 71ced39f5ca..4dd97a90d88 100644 --- a/source/blender/blenkernel/intern/particle.cc +++ b/source/blender/blenkernel/intern/particle.cc @@ -622,13 +622,11 @@ static ParticleCacheKey **psys_alloc_path_cache_buffers(ListBase *bufs, int tot, static void psys_free_path_cache_buffers(ParticleCacheKey **cache, ListBase *bufs) { - LinkData *buf; - if (cache) { MEM_freeN(cache); } - for (buf = static_cast(bufs->first); buf; buf = buf->next) { + LISTBASE_FOREACH (LinkData *, buf, bufs) { MEM_freeN(buf->data); } BLI_freelistN(bufs); @@ -640,12 +638,11 @@ static void psys_free_path_cache_buffers(ParticleCacheKey **cache, ListBase *buf ParticleSystem *psys_get_current(Object *ob) { - ParticleSystem *psys; if (ob == nullptr) { return nullptr; } - for (psys = static_cast(ob->particlesystem.first); psys; psys = psys->next) { + LISTBASE_FOREACH (ParticleSystem *, psys, &ob->particlesystem) { if (psys->flag & PSYS_CURRENT) { return psys; } @@ -915,7 +912,7 @@ void psys_check_group_weights(ParticleSettings *part) /* Ensure there is an element marked as current. */ int current = 0; - for (dw = static_cast(part->instance_weights.first); dw; dw = dw->next) { + LISTBASE_FOREACH (ParticleDupliWeight *, dw, &part->instance_weights) { if (dw->flag & PART_DUPLIW_CURRENT) { current = 1; break; @@ -1083,7 +1080,6 @@ void psys_free(Object *ob, ParticleSystem *psys) { if (psys) { int nr = 0; - ParticleSystem *tpsys; psys_free_path_cache(psys, nullptr); @@ -1116,8 +1112,7 @@ void psys_free(Object *ob, ParticleSystem *psys) } /* check if we are last non-visible particle system */ - for (tpsys = static_cast(ob->particlesystem.first); tpsys; - tpsys = tpsys->next) { + LISTBASE_FOREACH (ParticleSystem *, tpsys, &ob->particlesystem) { if (tpsys->part) { if (ELEM(tpsys->part->ren_as, PART_DRAW_OB, PART_DRAW_GR)) { nr++; @@ -1355,10 +1350,9 @@ static int get_pointcache_times_for_particle(PointCache *cache, float *r_start, float *r_dietime) { - PTCacheMem *pm; int ret = 0; - for (pm = static_cast(cache->mem_cache.first); pm; pm = pm->next) { + LISTBASE_FOREACH (PTCacheMem *, pm, &cache->mem_cache) { if (BKE_ptcache_mem_index_find(pm, index) >= 0) { *r_start = pm->frame; ret++; @@ -1366,7 +1360,7 @@ static int get_pointcache_times_for_particle(PointCache *cache, } } - for (pm = static_cast(cache->mem_cache.last); pm; pm = pm->prev) { + LISTBASE_FOREACH_BACKWARD (PTCacheMem *, pm, &cache->mem_cache) { if (BKE_ptcache_mem_index_find(pm, index) >= 0) { /* Die *after* the last available frame. */ *r_dietime = pm->frame + 1; @@ -1380,10 +1374,9 @@ static int get_pointcache_times_for_particle(PointCache *cache, float psys_get_dietime_from_cache(PointCache *cache, int index) { - PTCacheMem *pm; int dietime = 10000000; /* some max value so that we can default to pa->time+lifetime */ - for (pm = static_cast(cache->mem_cache.last); pm; pm = pm->prev) { + LISTBASE_FOREACH_BACKWARD (PTCacheMem *, pm, &cache->mem_cache) { if (BKE_ptcache_mem_index_find(pm, index) >= 0) { /* Die *after* the last available frame. */ dietime = pm->frame + 1; @@ -2259,10 +2252,9 @@ float psys_particle_value_from_verts(Mesh *mesh, short from, ParticleData *pa, f ParticleSystemModifierData *psys_get_modifier(Object *ob, ParticleSystem *psys) { - ModifierData *md; ParticleSystemModifierData *psmd; - for (md = static_cast(ob->modifiers.first); md; md = md->next) { + LISTBASE_FOREACH (ModifierData *, md, &ob->modifiers) { if (md->type == eModifierType_ParticleSystem) { psmd = (ParticleSystemModifierData *)md; if (psmd->psys == psys) { @@ -2390,7 +2382,6 @@ void precalc_guides(ParticleSimulationData *sim, ListBase *effectors) EffectedPoint point; ParticleKey state; EffectorData efd; - EffectorCache *eff; ParticleSystem *psys = sim->psys; EffectorWeights *weights = sim->psys->part->effector_weights; GuideEffectorData *data; @@ -2419,7 +2410,7 @@ void precalc_guides(ParticleSimulationData *sim, ListBase *effectors) pd_point_from_particle(sim, pa, &state, &point); - for (eff = static_cast(effectors->first); eff; eff = eff->next) { + LISTBASE_FOREACH (EffectorCache *, eff, effectors) { if (eff->pd->forcefield != PFIELD_GUIDE) { continue; } @@ -2452,7 +2443,6 @@ bool do_guides(Depsgraph *depsgraph, nullptr; CurveMapping *roughcurve = (part->child_flag & PART_CHILD_USE_ROUGH_CURVE) ? part->roughcurve : nullptr; - EffectorCache *eff; PartDeflect *pd; Curve *cu; GuideEffectorData *data; @@ -2463,7 +2453,7 @@ bool do_guides(Depsgraph *depsgraph, float vec_to_point[3]; if (effectors) { - for (eff = static_cast(effectors->first); eff; eff = eff->next) { + LISTBASE_FOREACH (EffectorCache *, eff, effectors) { pd = eff->pd; if (pd->forcefield != PFIELD_GUIDE) { diff --git a/source/blender/blenkernel/intern/particle_system.cc b/source/blender/blenkernel/intern/particle_system.cc index 8ee75b2756e..b4895bff571 100644 --- a/source/blender/blenkernel/intern/particle_system.cc +++ b/source/blender/blenkernel/intern/particle_system.cc @@ -2847,7 +2847,6 @@ static int collision_detect(ParticleData *pa, ListBase *colliders) { const int raycast_flag = BVH_RAYCAST_DEFAULT & ~(BVH_RAYCAST_WATERTIGHT); - ColliderCache *coll; float ray_dir[3]; if (BLI_listbase_is_empty(colliders)) { @@ -2865,7 +2864,7 @@ static int collision_detect(ParticleData *pa, hit->dist = col->original_ray_length = 0.000001f; } - for (coll = static_cast(colliders->first); coll; coll = coll->next) { + LISTBASE_FOREACH (ColliderCache *, coll, colliders) { /* for boids: don't check with current ground object; also skip if permeated */ bool skip = false; @@ -5035,7 +5034,6 @@ static void particlesystem_modifiersForeachIDLink(void *user_data, void BKE_particlesystem_id_loop(ParticleSystem *psys, ParticleSystemIDFunc func, void *userdata) { - ParticleTarget *pt; LibraryForeachIDData *foreachid_data = static_cast(userdata); const int foreachid_data_flags = BKE_lib_query_foreachid_process_flags_get(foreachid_data); @@ -5056,7 +5054,7 @@ void BKE_particlesystem_id_loop(ParticleSystem *psys, ParticleSystemIDFunc func, } } - for (pt = static_cast(psys->targets.first); pt; pt = pt->next) { + LISTBASE_FOREACH (ParticleTarget *, pt, &psys->targets) { func(psys, (ID **)&pt->ob, userdata, IDWALK_CB_NOP); } diff --git a/source/blender/blenkernel/intern/pointcache.cc b/source/blender/blenkernel/intern/pointcache.cc index 791b79b089d..863ddeeb6e4 100644 --- a/source/blender/blenkernel/intern/pointcache.cc +++ b/source/blender/blenkernel/intern/pointcache.cc @@ -2936,8 +2936,6 @@ int BKE_ptcache_id_reset(Scene *scene, PTCacheID *pid, int mode) int BKE_ptcache_object_reset(Scene *scene, Object *ob, int mode) { PTCacheID pid; - ParticleSystem *psys; - ModifierData *md; int reset, skip; reset = 0; @@ -2948,7 +2946,7 @@ int BKE_ptcache_object_reset(Scene *scene, Object *ob, int mode) reset |= BKE_ptcache_id_reset(scene, &pid, mode); } - for (psys = static_cast(ob->particlesystem.first); psys; psys = psys->next) { + LISTBASE_FOREACH (ParticleSystem *, psys, &ob->particlesystem) { /* children or just redo can be calculated without resetting anything */ if (psys->recalc & ID_RECALC_PSYS_REDO || psys->recalc & ID_RECALC_PSYS_CHILD) { skip = 1; @@ -2973,7 +2971,7 @@ int BKE_ptcache_object_reset(Scene *scene, Object *ob, int mode) } } - for (md = static_cast(ob->modifiers.first); md; md = md->next) { + LISTBASE_FOREACH (ModifierData *, md, &ob->modifiers) { if (md->type == eModifierType_Cloth) { BKE_ptcache_id_from_cloth(&pid, ob, (ClothModifierData *)md); reset |= BKE_ptcache_id_reset(scene, &pid, mode); @@ -3081,9 +3079,7 @@ static PointCache *ptcache_copy(PointCache *cache, const bool copy_data) ncache->simframe = 0; } else { - PTCacheMem *pm; - - for (pm = static_cast(cache->mem_cache.first); pm; pm = pm->next) { + LISTBASE_FOREACH (PTCacheMem *, pm, &cache->mem_cache) { PTCacheMem *pmn = static_cast(MEM_dupallocN(pm)); int i; @@ -3200,10 +3196,9 @@ void BKE_ptcache_bake(PTCacheBaker *baker) else if (pid->type == PTCACHE_TYPE_SMOKE_HIGHRES) { /* get all pids from the object and search for smoke low res */ ListBase pidlist2; - PTCacheID *pid2; BLI_assert(GS(pid->owner_id->name) == ID_OB); BKE_ptcache_ids_from_object(&pidlist2, (Object *)pid->owner_id, scene, MAX_DUPLI_RECUR); - for (pid2 = static_cast(pidlist2.first); pid2; pid2 = pid2->next) { + LISTBASE_FOREACH (PTCacheID *, pid2, &pidlist2) { if (pid2->type == PTCACHE_TYPE_SMOKE_DOMAIN) { if (pid2->cache && !(pid2->cache->flag & PTCACHE_BAKED)) { if (bake || pid2->cache->flag & PTCACHE_REDO_NEEDED) { @@ -3366,7 +3361,7 @@ void BKE_ptcache_bake(PTCacheBaker *baker) for (SETLOOPER_VIEW_LAYER(scene, view_layer, sce_iter, base)) { BKE_ptcache_ids_from_object(&pidlist, base->object, scene, MAX_DUPLI_RECUR); - for (pid = static_cast(pidlist.first); pid; pid = pid->next) { + LISTBASE_FOREACH (PTCacheID *, pid, &pidlist) { /* skip hair particles */ if (pid->type == PTCACHE_TYPE_PARTICLES && ((ParticleSystem *)pid->calldata)->part->type == PART_HAIR) @@ -3677,7 +3672,6 @@ void BKE_ptcache_load_external(PTCacheID *pid) void BKE_ptcache_update_info(PTCacheID *pid) { PointCache *cache = pid->cache; - PTCacheExtra *extra = nullptr; int totframes = 0; char mem_info[sizeof(PointCache::info) / sizeof(*PointCache::info)]; @@ -3740,7 +3734,7 @@ void BKE_ptcache_update_info(PTCacheID *pid) bytes += MEM_allocN_len(pm->data[i]); } - for (extra = static_cast(pm->extradata.first); extra; extra = extra->next) { + LISTBASE_FOREACH (PTCacheExtra *, extra, &pm->extradata) { bytes += MEM_allocN_len(extra->data); bytes += sizeof(PTCacheExtra); } diff --git a/source/blender/blenkernel/intern/report.cc b/source/blender/blenkernel/intern/report.cc index 6e995a7b06d..2cc13192a01 100644 --- a/source/blender/blenkernel/intern/report.cc +++ b/source/blender/blenkernel/intern/report.cc @@ -146,8 +146,7 @@ static void reports_prepend_impl(ReportList *reports, const char *prepend) /* Caller must ensure. */ BLI_assert(reports && reports->list.first); const size_t prefix_len = strlen(prepend); - for (Report *report = static_cast(reports->list.first); report; report = report->next) - { + LISTBASE_FOREACH (Report *, report, &reports->list) { char *message = BLI_string_joinN(prepend, report->message); MEM_freeN((void *)report->message); report->message = message; @@ -217,7 +216,6 @@ void BKE_report_store_level_set(ReportList *reports, eReportType level) char *BKE_reports_string(ReportList *reports, eReportType level) { - Report *report; DynStr *ds; char *cstring; @@ -226,7 +224,7 @@ char *BKE_reports_string(ReportList *reports, eReportType level) } ds = BLI_dynstr_new(); - for (report = static_cast(reports->list.first); report; report = report->next) { + LISTBASE_FOREACH (Report *, report, &reports->list) { if (report->type >= level) { BLI_dynstr_appendf(ds, "%s: %s\n", report->typestr, report->message); } @@ -276,9 +274,7 @@ void BKE_reports_print(ReportList *reports, eReportType level) Report *BKE_reports_last_displayable(ReportList *reports) { - Report *report; - - for (report = static_cast(reports->list.last); report; report = report->prev) { + LISTBASE_FOREACH_BACKWARD (Report *, report, &reports->list) { if (ELEM(report->type, RPT_ERROR, RPT_WARNING, RPT_INFO)) { return report; } @@ -289,9 +285,8 @@ Report *BKE_reports_last_displayable(ReportList *reports) bool BKE_reports_contain(ReportList *reports, eReportType level) { - Report *report; if (reports != nullptr) { - for (report = static_cast(reports->list.first); report; report = report->next) { + LISTBASE_FOREACH (Report *, report, &reports->list) { if (report->type >= level) { return true; } @@ -302,13 +297,11 @@ bool BKE_reports_contain(ReportList *reports, eReportType level) bool BKE_report_write_file_fp(FILE *fp, ReportList *reports, const char *header) { - Report *report; - if (header) { fputs(header, fp); } - for (report = static_cast(reports->list.first); report; report = report->next) { + LISTBASE_FOREACH (Report *, report, &reports->list) { fprintf((FILE *)fp, "%s # %s\n", report->message, report->typestr); } diff --git a/source/blender/blenkernel/intern/shader_fx.cc b/source/blender/blenkernel/intern/shader_fx.cc index 51391ff28ff..e53a50de48d 100644 --- a/source/blender/blenkernel/intern/shader_fx.cc +++ b/source/blender/blenkernel/intern/shader_fx.cc @@ -45,8 +45,7 @@ static ShaderFxTypeInfo *shader_fx_types[NUM_SHADER_FX_TYPES] = {nullptr}; bool BKE_shaderfx_has_gpencil(const Object *ob) { - const ShaderFxData *fx; - for (fx = static_cast(ob->shader_fx.first); fx; fx = fx->next) { + LISTBASE_FOREACH (const ShaderFxData *, fx, &ob->shader_fx) { const ShaderFxTypeInfo *fxi = BKE_shaderfx_get_info(ShaderFxType(fx->type)); if (fxi->type == eShaderFxType_GpencilType) { return true; diff --git a/source/blender/blenkernel/intern/sound.cc b/source/blender/blenkernel/intern/sound.cc index 49cd60db005..f3cfc41f4e8 100644 --- a/source/blender/blenkernel/intern/sound.cc +++ b/source/blender/blenkernel/intern/sound.cc @@ -1133,8 +1133,6 @@ void BKE_sound_read_waveform(Main *bmain, bSound *sound, bool *stop) static void sound_update_base(Scene *scene, Object *object, void *new_set) { - NlaTrack *track; - NlaStrip *strip; Speaker *speaker; float quat[4]; @@ -1145,9 +1143,8 @@ static void sound_update_base(Scene *scene, Object *object, void *new_set) return; } - for (track = static_cast(object->adt->nla_tracks.first); track; track = track->next) - { - for (strip = static_cast(track->strips.first); strip; strip = strip->next) { + LISTBASE_FOREACH (NlaTrack *, track, &object->adt->nla_tracks) { + LISTBASE_FOREACH (NlaStrip *, strip, &track->strips) { if (strip->type != NLASTRIP_TYPE_SOUND) { continue; } diff --git a/source/blender/blenkernel/intern/undo_system.cc b/source/blender/blenkernel/intern/undo_system.cc index 318ba998dc3..6d13b6535c0 100644 --- a/source/blender/blenkernel/intern/undo_system.cc +++ b/source/blender/blenkernel/intern/undo_system.cc @@ -638,7 +638,7 @@ UndoStep *BKE_undosys_step_find_by_name_with_type(UndoStack *ustack, const char *name, const UndoType *ut) { - for (UndoStep *us = static_cast(ustack->steps.last); us; us = us->prev) { + LISTBASE_FOREACH_BACKWARD (UndoStep *, us, &ustack->steps) { if (us->type == ut) { if (STREQ(name, us->name)) { return us; @@ -655,7 +655,7 @@ UndoStep *BKE_undosys_step_find_by_name(UndoStack *ustack, const char *name) UndoStep *BKE_undosys_step_find_by_type(UndoStack *ustack, const UndoType *ut) { - for (UndoStep *us = static_cast(ustack->steps.last); us; us = us->prev) { + LISTBASE_FOREACH_BACKWARD (UndoStep *, us, &ustack->steps) { if (us->type == ut) { return us; } diff --git a/source/blender/blenlib/intern/listbase.cc b/source/blender/blenlib/intern/listbase.cc index 41ea569fd75..b4178569bfe 100644 --- a/source/blender/blenlib/intern/listbase.cc +++ b/source/blender/blenlib/intern/listbase.cc @@ -522,10 +522,8 @@ int BLI_listbase_count_at_most(const ListBase *listbase, const int count_max) int BLI_listbase_count(const ListBase *listbase) { - Link *link; int count = 0; - - for (link = static_cast(listbase->first); link; link = link->next) { + LISTBASE_FOREACH (Link *, link, listbase) { count++; } @@ -601,14 +599,13 @@ int BLI_findindex(const ListBase *listbase, const void *vlink) void *BLI_findstring(const ListBase *listbase, const char *id, const int offset) { - Link *link = nullptr; const char *id_iter; if (id == nullptr) { return nullptr; } - for (link = static_cast(listbase->first); link; link = link->next) { + LISTBASE_FOREACH (Link *, link, listbase) { id_iter = ((const char *)link) + offset; if (id[0] == id_iter[0] && STREQ(id, id_iter)) { @@ -621,13 +618,8 @@ void *BLI_findstring(const ListBase *listbase, const char *id, const int offset) void *BLI_rfindstring(const ListBase *listbase, const char *id, const int offset) { /* Same as #BLI_findstring but find reverse. */ - - Link *link = nullptr; - const char *id_iter; - - for (link = static_cast(listbase->last); link; link = link->prev) { - id_iter = ((const char *)link) + offset; - + LISTBASE_FOREACH_BACKWARD (Link *, link, listbase) { + const char *id_iter = ((const char *)link) + offset; if (id[0] == id_iter[0] && STREQ(id, id_iter)) { return link; } @@ -638,10 +630,9 @@ void *BLI_rfindstring(const ListBase *listbase, const char *id, const int offset void *BLI_findstring_ptr(const ListBase *listbase, const char *id, const int offset) { - Link *link = nullptr; const char *id_iter; - for (link = static_cast(listbase->first); link; link = link->next) { + LISTBASE_FOREACH (Link *, link, listbase) { /* exact copy of BLI_findstring(), except for this line */ id_iter = *((const char **)(((const char *)link) + offset)); @@ -656,13 +647,11 @@ void *BLI_rfindstring_ptr(const ListBase *listbase, const char *id, const int of { /* Same as #BLI_findstring_ptr but find reverse. */ - Link *link = nullptr; const char *id_iter; - for (link = static_cast(listbase->last); link; link = link->prev) { - /* exact copy of BLI_rfindstring(), except for this line */ + LISTBASE_FOREACH_BACKWARD (Link *, link, listbase) { + /* Exact copy of #BLI_rfindstring(), except for this line */ id_iter = *((const char **)(((const char *)link) + offset)); - if (id[0] == id_iter[0] && STREQ(id, id_iter)) { return link; } @@ -673,36 +662,26 @@ void *BLI_rfindstring_ptr(const ListBase *listbase, const char *id, const int of void *BLI_findptr(const ListBase *listbase, const void *ptr, const int offset) { - Link *link = nullptr; - const void *ptr_iter; - - for (link = static_cast(listbase->first); link; link = link->next) { - /* exact copy of BLI_findstring(), except for this line */ - ptr_iter = *((const void **)(((const char *)link) + offset)); - + LISTBASE_FOREACH (Link *, link, listbase) { + /* Exact copy of #BLI_findstring(), except for this line. */ + const void *ptr_iter = *((const void **)(((const char *)link) + offset)); if (ptr == ptr_iter) { return link; } } - return nullptr; } void *BLI_rfindptr(const ListBase *listbase, const void *ptr, const int offset) { /* Same as #BLI_findptr but find reverse. */ - - Link *link = nullptr; - const void *ptr_iter; - - for (link = static_cast(listbase->last); link; link = link->prev) { - /* exact copy of BLI_rfindstring(), except for this line */ - ptr_iter = *((const void **)(((const char *)link) + offset)); + LISTBASE_FOREACH_BACKWARD (Link *, link, listbase) { + /* Exact copy of #BLI_rfindstring(), except for this line. */ + const void *ptr_iter = *((const void **)(((const char *)link) + offset)); if (ptr == ptr_iter) { return link; } } - return nullptr; } @@ -711,12 +690,8 @@ void *BLI_listbase_bytes_find(const ListBase *listbase, const size_t bytes_size, const int offset) { - Link *link = nullptr; - const void *ptr_iter; - - for (link = static_cast(listbase->first); link; link = link->next) { - ptr_iter = (const void *)(((const char *)link) + offset); - + LISTBASE_FOREACH (Link *, link, listbase) { + const void *ptr_iter = (const void *)(((const char *)link) + offset); if (memcmp(bytes, ptr_iter, bytes_size) == 0) { return link; } @@ -730,18 +705,12 @@ void *BLI_listbase_bytes_rfind(const ListBase *listbase, const int offset) { /* Same as #BLI_listbase_bytes_find but find reverse. */ - - Link *link = nullptr; - const void *ptr_iter; - - for (link = static_cast(listbase->last); link; link = link->prev) { - ptr_iter = (const void *)(((const char *)link) + offset); - + LISTBASE_FOREACH_BACKWARD (Link *, link, listbase) { + const void *ptr_iter = (const void *)(((const char *)link) + offset); if (memcmp(bytes, ptr_iter, bytes_size) == 0) { return link; } } - return nullptr; } @@ -885,7 +854,7 @@ bool BLI_listbase_validate(ListBase *lb) /* Walk the list in bot directions to ensure all next & prev pointers are valid and consistent. */ - for (Link *lb_link = static_cast(lb->first); lb_link; lb_link = lb_link->next) { + LISTBASE_FOREACH (Link *, lb_link, lb) { if (lb_link == lb->first) { if (lb_link->prev != nullptr) { return false; @@ -897,7 +866,7 @@ bool BLI_listbase_validate(ListBase *lb) } } } - for (Link *lb_link = static_cast(lb->last); lb_link; lb_link = lb_link->prev) { + LISTBASE_FOREACH_BACKWARD (Link *, lb_link, lb) { if (lb_link == lb->last) { if (lb_link->next != nullptr) { return false; diff --git a/source/blender/blenloader/intern/readfile.cc b/source/blender/blenloader/intern/readfile.cc index f87d8f35b88..23b71685f01 100644 --- a/source/blender/blenloader/intern/readfile.cc +++ b/source/blender/blenloader/intern/readfile.cc @@ -530,7 +530,7 @@ static Main *blo_find_main(FileData *fd, const char *filepath, const char *relab // printf("blo_find_main: original in %s\n", filepath); // printf("blo_find_main: converted to %s\n", filepath_abs); - for (m = static_cast
(mainlist->first); m; m = m->next) { + LISTBASE_FOREACH (Main *, m, mainlist) { const char *libname = (m->curlib) ? m->curlib->filepath_abs : m->filepath; if (BLI_path_cmp(filepath_abs, libname) == 0) { @@ -2239,7 +2239,7 @@ static void direct_link_library(FileData *fd, Library *lib, Main *main) BLI_path_normalize(lib->filepath_abs); /* check if the library was already read */ - for (newmain = static_cast
(fd->mainlist->first); newmain; newmain = newmain->next) { + LISTBASE_FOREACH (Main *, newmain, fd->mainlist) { if (newmain->curlib) { if (BLI_path_cmp(newmain->curlib->filepath_abs, lib->filepath_abs) == 0) { BLO_reportf_wrap(fd->reports, diff --git a/source/blender/blenloader/intern/versioning_legacy.cc b/source/blender/blenloader/intern/versioning_legacy.cc index 83dda7aa030..a2887b41449 100644 --- a/source/blender/blenloader/intern/versioning_legacy.cc +++ b/source/blender/blenloader/intern/versioning_legacy.cc @@ -108,7 +108,6 @@ static void vcol_to_fcol(Mesh *me) static void do_version_bone_head_tail_237(Bone *bone) { - Bone *child; float vec[3]; /* head */ @@ -119,16 +118,14 @@ static void do_version_bone_head_tail_237(Bone *bone) mul_v3_fl(vec, bone->length); add_v3_v3v3(bone->arm_tail, bone->arm_head, vec); - for (child = static_cast(bone->childbase.first); child; child = child->next) { + LISTBASE_FOREACH (Bone *, child, &bone->childbase) { do_version_bone_head_tail_237(child); } } static void bone_version_238(ListBase *lb) { - Bone *bone; - - for (bone = static_cast(lb->first); bone; bone = bone->next) { + LISTBASE_FOREACH (Bone *, bone, lb) { if (bone->rad_tail == 0.0f && bone->rad_head == 0.0f) { bone->rad_head = 0.25f * bone->length; bone->rad_tail = 0.1f * bone->length; @@ -144,9 +141,7 @@ static void bone_version_238(ListBase *lb) static void bone_version_239(ListBase *lb) { - Bone *bone; - - for (bone = static_cast(lb->first); bone; bone = bone->next) { + LISTBASE_FOREACH (Bone *, bone, lb) { if (bone->layer == 0) { bone->layer = 1; } @@ -156,10 +151,8 @@ static void bone_version_239(ListBase *lb) static void ntree_version_241(bNodeTree *ntree) { - bNode *node; - if (ntree->type == NTREE_COMPOSIT) { - for (node = static_cast(ntree->nodes.first); node; node = node->next) { + LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { if (node->type == CMP_NODE_BLUR) { if (node->storage == nullptr) { NodeBlurData *nbd = static_cast( @@ -186,10 +179,8 @@ static void ntree_version_241(bNodeTree *ntree) static void ntree_version_242(bNodeTree *ntree) { - bNode *node; - if (ntree->type == NTREE_COMPOSIT) { - for (node = static_cast(ntree->nodes.first); node; node = node->next) { + LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { if (node->type == CMP_NODE_HUE_SAT) { if (node->storage) { NodeHueSat *nhs = static_cast(node->storage); @@ -204,14 +195,13 @@ static void ntree_version_242(bNodeTree *ntree) static void ntree_version_245(FileData *fd, Library * /*lib*/, bNodeTree *ntree) { - bNode *node; NodeTwoFloats *ntf; ID *nodeid; Image *image; ImageUser *iuser; if (ntree->type == NTREE_COMPOSIT) { - for (node = static_cast(ntree->nodes.first); node; node = node->next) { + LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { if (node->type == CMP_NODE_ALPHAOVER) { if (!node->storage) { ntf = static_cast(MEM_callocN(sizeof(NodeTwoFloats), "NodeTwoFloats")); @@ -370,10 +360,8 @@ static void customdata_version_243(Mesh *me) /* struct NodeImageAnim moved to ImageUser, and we make it default available */ static void do_version_ntree_242_2(bNodeTree *ntree) { - bNode *node; - if (ntree->type == NTREE_COMPOSIT) { - for (node = static_cast(ntree->nodes.first); node; node = node->next) { + LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { if (ELEM(node->type, CMP_NODE_IMAGE, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER)) { /* only image had storage */ if (node->storage) { @@ -421,10 +409,9 @@ static void do_version_free_effects_245(ListBase *lb) static void do_version_constraints_245(ListBase *lb) { - bConstraint *con; bConstraintTarget *ct; - for (con = static_cast(lb->first); con; con = con->next) { + LISTBASE_FOREACH (bConstraint *, con, lb) { if (con->type == CONSTRAINT_TYPE_PYTHON) { bPythonConstraint *data = (bPythonConstraint *)con->data; if (data->tar) { @@ -888,12 +875,8 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) for (screen = static_cast(bmain->screens.first); screen; screen = static_cast(screen->id.next)) { - ScrArea *area; - - for (area = static_cast(screen->areabase.first); area; area = area->next) { - SpaceLink *sl; - - for (sl = static_cast(area->spacedata.first); sl; sl = sl->next) { + LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) { + LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) { if (sl->spacetype == SPACE_GRAPH) { SpaceSeq *sseq = (SpaceSeq *)sl; sseq->v2d.keeptot = 0; @@ -921,8 +904,7 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) */ if (list) { - bConstraint *curcon; - for (curcon = static_cast(list->first); curcon; curcon = curcon->next) { + LISTBASE_FOREACH (bConstraint *, curcon, list) { if (curcon->type == CONSTRAINT_TYPE_TRACKTO) { bTrackToConstraint *data = static_cast(curcon->data); data->reserved1 = ob->trackflag; @@ -933,12 +915,8 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) if (ob->type == OB_ARMATURE) { if (ob->pose) { - bConstraint *curcon; - bPoseChannel *pchan; - for (pchan = static_cast(ob->pose->chanbase.first); pchan; - pchan = pchan->next) { - for (curcon = static_cast(pchan->constraints.first); curcon; - curcon = curcon->next) { + LISTBASE_FOREACH (bPoseChannel *, pchan, &ob->pose->chanbase) { + LISTBASE_FOREACH (bConstraint *, curcon, &pchan->constraints) { if (curcon->type == CONSTRAINT_TYPE_TRACKTO) { bTrackToConstraint *data = static_cast(curcon->data); data->reserved1 = ob->trackflag; @@ -966,12 +944,8 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) for (screen = static_cast(bmain->screens.first); screen; screen = static_cast(screen->id.next)) { - ScrArea *area; - - for (area = static_cast(screen->areabase.first); area; area = area->next) { - SpaceLink *sl; - - for (sl = static_cast(area->spacedata.first); sl; sl = sl->next) { + LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) { + LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) { if (sl->spacetype == SPACE_ACTION) { SpaceAction *sac = (SpaceAction *)sl; sac->v2d.max[0] = 32000; @@ -1002,8 +976,7 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) * set their track and up flag correctly */ if (list) { - bConstraint *curcon; - for (curcon = static_cast(list->first); curcon; curcon = curcon->next) { + LISTBASE_FOREACH (bConstraint *, curcon, list) { if (curcon->type == CONSTRAINT_TYPE_TRACKTO) { bTrackToConstraint *data = static_cast(curcon->data); data->reserved1 = ob->trackflag; @@ -1014,12 +987,8 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) if (ob->type == OB_ARMATURE) { if (ob->pose) { - bConstraint *curcon; - bPoseChannel *pchan; - for (pchan = static_cast(ob->pose->chanbase.first); pchan; - pchan = pchan->next) { - for (curcon = static_cast(pchan->constraints.first); curcon; - curcon = curcon->next) { + LISTBASE_FOREACH (bPoseChannel *, pchan, &ob->pose->chanbase) { + LISTBASE_FOREACH (bConstraint *, curcon, &pchan->constraints) { if (curcon->type == CONSTRAINT_TYPE_TRACKTO) { bTrackToConstraint *data = static_cast(curcon->data); data->reserved1 = ob->trackflag; @@ -1037,12 +1006,8 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) for (screen = static_cast(bmain->screens.first); screen; screen = static_cast(screen->id.next)) { - ScrArea *area; - - for (area = static_cast(screen->areabase.first); area; area = area->next) { - SpaceLink *sl; - - for (sl = static_cast(area->spacedata.first); sl; sl = sl->next) { + LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) { + LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) { if (sl->spacetype == SPACE_PROPERTIES) { SpaceProperties *sbuts = (SpaceProperties *)sl; @@ -1108,12 +1073,8 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) for (screen = static_cast(bmain->screens.first); screen; screen = static_cast(screen->id.next)) { - ScrArea *area; - - for (area = static_cast(screen->areabase.first); area; area = area->next) { - SpaceLink *sl; - - for (sl = static_cast(area->spacedata.first); sl; sl = sl->next) { + LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) { + LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) { /* added: 5x better zoom in for action */ if (sl->spacetype == SPACE_ACTION) { SpaceAction *sac = (SpaceAction *)sl; @@ -1194,10 +1155,8 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) for (screen = static_cast(bmain->screens.first); screen; screen = static_cast(screen->id.next)) { - ScrArea *area; - for (area = static_cast(screen->areabase.first); area; area = area->next) { - SpaceLink *sl; - for (sl = static_cast(area->spacedata.first); sl; sl = sl->next) { + LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) { + LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) { /* added: 5x better zoom in for nla */ if (sl->spacetype == SPACE_NLA) { SpaceNla *snla = (SpaceNla *)sl; @@ -1214,10 +1173,8 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) for (screen = static_cast(bmain->screens.first); screen; screen = static_cast(screen->id.next)) { - ScrArea *area; - for (area = static_cast(screen->areabase.first); area; area = area->next) { - SpaceLink *sl; - for (sl = static_cast(area->spacedata.first); sl; sl = sl->next) { + LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) { + LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) { if (sl->spacetype == SPACE_VIEW3D) { View3D *v3d = (View3D *)sl; v3d->flag |= V3D_SELECT_OUTLINE; @@ -1233,10 +1190,8 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) for (screen = static_cast(bmain->screens.first); screen; screen = static_cast(screen->id.next)) { - ScrArea *area; - for (area = static_cast(screen->areabase.first); area; area = area->next) { - SpaceLink *sl; - for (sl = static_cast(area->spacedata.first); sl; sl = sl->next) { + LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) { + LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) { if (sl->spacetype == SPACE_TEXT) { SpaceText *st = (SpaceText *)sl; if (st->tabnumber == 0) { @@ -1308,9 +1263,7 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) if (bmain->versionfile <= 237) { bArmature *arm; - bConstraint *con; Object *ob; - Bone *bone; /* armature recode checks */ for (arm = static_cast(bmain->armatures.first); arm; @@ -1318,7 +1271,7 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) { BKE_armature_where_is(arm); - for (bone = static_cast(arm->bonebase.first); bone; bone = bone->next) { + LISTBASE_FOREACH (Bone *, bone, &arm->bonebase) { do_version_bone_head_tail_237(bone); } } @@ -1385,7 +1338,7 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) } /* follow path constraint needs to set the 'path' option in curves... */ - for (con = static_cast(ob->constraints.first); con; con = con->next) { + LISTBASE_FOREACH (bConstraint *, con, &ob->constraints) { if (con->type == CONSTRAINT_TYPE_FOLLOWPATH) { bFollowPathConstraint *data = static_cast(con->data); Object *obc = static_cast( @@ -1435,7 +1388,7 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) ModifierData *md; PartEff *paf; - for (md = static_cast(ob->modifiers.first); md; md = md->next) { + LISTBASE_FOREACH (ModifierData *, md, &ob->modifiers) { if (md->type == eModifierType_Subsurf) { SubsurfModifierData *smd = (SubsurfModifierData *)md; @@ -1463,17 +1416,13 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) } if (ob->pose) { - bPoseChannel *pchan; - bConstraint *con; - for (pchan = static_cast(ob->pose->chanbase.first); pchan; - pchan = pchan->next) { + LISTBASE_FOREACH (bPoseChannel *, pchan, &ob->pose->chanbase) { /* NOTE: pchan->bone is also lib-link stuff. */ if (pchan->limitmin[0] == 0.0f && pchan->limitmax[0] == 0.0f) { pchan->limitmin[0] = pchan->limitmin[1] = pchan->limitmin[2] = -180.0f; pchan->limitmax[0] = pchan->limitmax[1] = pchan->limitmax[2] = 180.0f; - for (con = static_cast(pchan->constraints.first); con; con = con->next) - { + LISTBASE_FOREACH (bConstraint *, con, &pchan->constraints) { if (con->type == CONSTRAINT_TYPE_KINEMATIC) { bKinematicConstraint *data = (bKinematicConstraint *)con->data; data->weight = 1.0f; @@ -1524,10 +1473,9 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) for (key = static_cast(bmain->shapekeys.first); key; key = static_cast(key->id.next)) { - KeyBlock *kb; int index = 1; - for (kb = static_cast(key->block.first); kb; kb = kb->next) { + LISTBASE_FOREACH (KeyBlock *, kb, &key->block) { if (kb == key->refkey) { if (kb->name[0] == 0) { STRNCPY(kb->name, "Basis"); @@ -1553,9 +1501,7 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) /* deformflag is local in modifier now */ for (ob = static_cast(bmain->objects.first); ob; ob = static_cast(ob->id.next)) { - ModifierData *md; - - for (md = static_cast(ob->modifiers.first); md; md = md->next) { + LISTBASE_FOREACH (ModifierData *, md, &ob->modifiers) { if (md->type == eModifierType_Armature) { ArmatureModifierData *amd = (ArmatureModifierData *)md; if (amd->object && amd->deformflag == 0) { @@ -1626,11 +1572,10 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) /* We don't add default layer since blender2.8 because the layers * are now in Scene->view_layers and a default layer is created in - * the doversion later on. - */ - SceneRenderLayer *srl; + * the doversion later on. */ + /* new layer flag for sky, was default for solid */ - for (srl = static_cast(sce->r.layers.first); srl; srl = srl->next) { + LISTBASE_FOREACH (SceneRenderLayer *, srl, &sce->r.layers) { if (srl->layflag & SCE_LAY_SOLID) { srl->layflag |= SCE_LAY_SKY; } @@ -1686,7 +1631,6 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) Material *ma; Mesh *me; Collection *collection; - Nurb *nu; BezTriple *bezt; BPoint *bp; bNodeTree *ntree; @@ -1698,9 +1642,7 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) ScrArea *area; area = static_cast(screen->areabase.first); while (area) { - SpaceLink *sl; - - for (sl = static_cast(area->spacedata.first); sl; sl = sl->next) { + LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) { if (sl->spacetype == SPACE_VIEW3D) { View3D *v3d = (View3D *)sl; if (v3d->gridsubdiv == 0) { @@ -1743,7 +1685,7 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) /* add default radius values to old curve points */ for (cu = static_cast(bmain->curves.first); cu; cu = static_cast(cu->id.next)) { - for (nu = static_cast(cu->nurb.first); nu; nu = nu->next) { + LISTBASE_FOREACH (Nurb *, nu, &cu->nurb) { if (nu->bezt) { for (bezt = nu->bezt, a = 0; a < nu->pntsu; a++, bezt++) { if (!bezt->radius) { @@ -1763,7 +1705,6 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) for (ob = static_cast(bmain->objects.first); ob; ob = static_cast(ob->id.next)) { - ModifierData *md; ListBase *list; list = &ob->constraints; @@ -1771,8 +1712,7 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) * and update the sticky flagging */ if (list) { - bConstraint *curcon; - for (curcon = static_cast(list->first); curcon; curcon = curcon->next) { + LISTBASE_FOREACH (bConstraint *, curcon, list) { switch (curcon->type) { case CONSTRAINT_TYPE_ROTLIKE: { bRotateLikeConstraint *data = static_cast(curcon->data); @@ -1790,12 +1730,8 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) if (ob->type == OB_ARMATURE) { if (ob->pose) { - bConstraint *curcon; - bPoseChannel *pchan; - for (pchan = static_cast(ob->pose->chanbase.first); pchan; - pchan = pchan->next) { - for (curcon = static_cast(pchan->constraints.first); curcon; - curcon = curcon->next) { + LISTBASE_FOREACH (bPoseChannel *, pchan, &ob->pose->chanbase) { + LISTBASE_FOREACH (bConstraint *, curcon, &pchan->constraints) { switch (curcon->type) { case CONSTRAINT_TYPE_KINEMATIC: { bKinematicConstraint *data = static_cast(curcon->data); @@ -1821,7 +1757,7 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) } /* copy old object level track settings to curve modifiers */ - for (md = static_cast(ob->modifiers.first); md; md = md->next) { + LISTBASE_FOREACH (ModifierData *, md, &ob->modifiers) { if (md->type == eModifierType_Curve) { CurveModifierData *cmd = (CurveModifierData *)md; @@ -1934,10 +1870,7 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) Object *ob = static_cast(bmain->objects.first); for (; ob; ob = static_cast(ob->id.next)) { - bDeformGroup *curdef; - - for (curdef = static_cast(ob->defbase.first); curdef; curdef = curdef->next) - { + LISTBASE_FOREACH (bDeformGroup *, curdef, &ob->defbase) { /* replace an empty-string name with unique name */ if (curdef->name[0] == '\0') { BKE_object_defgroup_unique_name(curdef, ob); @@ -1945,10 +1878,8 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) } if (bmain->versionfile < 243 || bmain->subversionfile < 1) { - ModifierData *md; - /* translate old mirror modifier axis values to new flags */ - for (md = static_cast(ob->modifiers.first); md; md = md->next) { + LISTBASE_FOREACH (ModifierData *, md, &ob->modifiers) { if (md->type == eModifierType_Mirror) { MirrorModifierData *mmd = (MirrorModifierData *)md; @@ -1991,9 +1922,7 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) ScrArea *area; area = static_cast(screen->areabase.first); while (area) { - SpaceLink *sl; - - for (sl = static_cast(area->spacedata.first); sl; sl = sl->next) { + LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) { if (sl->spacetype == SPACE_ACTION) { SpaceAction *saction = (SpaceAction *)sl; @@ -2018,8 +1947,6 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) ParticleSettings *part; bNodeTree *ntree; Tex *tex; - ModifierData *md; - ParticleSystem *psys; /* unless the file was created 2.44.3 but not 2.45, update the constraints */ if (!(bmain->versionfile == 244 && bmain->subversionfile == 3) && @@ -2032,8 +1959,7 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) /* fix up constraints due to constraint recode changes (originally at 2.44.3) */ if (list) { - bConstraint *curcon; - for (curcon = static_cast(list->first); curcon; curcon = curcon->next) { + LISTBASE_FOREACH (bConstraint *, curcon, list) { /* old CONSTRAINT_LOCAL check -> convert to CONSTRAINT_SPACE_LOCAL */ if (curcon->flag & 0x20) { curcon->ownspace = CONSTRAINT_SPACE_LOCAL; @@ -2059,14 +1985,9 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) if (ob->type == OB_ARMATURE) { if (ob->pose) { - bConstraint *curcon; - bPoseChannel *pchan; - - for (pchan = static_cast(ob->pose->chanbase.first); pchan; - pchan = pchan->next) { + LISTBASE_FOREACH (bPoseChannel *, pchan, &ob->pose->chanbase) { /* make sure constraints are all up to date */ - for (curcon = static_cast(pchan->constraints.first); curcon; - curcon = curcon->next) { + LISTBASE_FOREACH (bConstraint *, curcon, &pchan->constraints) { /* old CONSTRAINT_LOCAL check -> convert to CONSTRAINT_SPACE_LOCAL */ if (curcon->flag & 0x20) { curcon->ownspace = CONSTRAINT_SPACE_LOCAL; @@ -2112,8 +2033,7 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) ob->soft->pointcache = BKE_ptcache_add(&ob->soft->ptcaches); } - for (psys = static_cast(ob->particlesystem.first); psys; psys = psys->next) - { + LISTBASE_FOREACH (ParticleSystem *, psys, &ob->particlesystem) { if (psys->pointcache) { if (psys->pointcache->flag & PTCACHE_BAKED && (psys->pointcache->flag & PTCACHE_DISK_CACHE) == 0) { @@ -2126,7 +2046,7 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) } } - for (md = static_cast(ob->modifiers.first); md; md = md->next) { + LISTBASE_FOREACH (ModifierData *, md, &ob->modifiers) { if (md->type == eModifierType_Cloth) { ClothModifierData *clmd = (ClothModifierData *)md; if (!clmd->point_cache) { @@ -2210,7 +2130,6 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) if (!MAIN_VERSION_FILE_ATLEAST(bmain, 245, 4)) { bArmature *arm; - ModifierData *md; Object *ob; for (arm = static_cast(bmain->armatures.first); arm; @@ -2221,7 +2140,7 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) for (ob = static_cast(bmain->objects.first); ob; ob = static_cast(ob->id.next)) { - for (md = static_cast(ob->modifiers.first); md; md = md->next) { + LISTBASE_FOREACH (ModifierData *, md, &ob->modifiers) { if (md->type == eModifierType_Armature) { ((ArmatureModifierData *)md)->deformflag |= ARM_DEF_B_BONE_REST; } @@ -2255,13 +2174,11 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) if (!MAIN_VERSION_FILE_ATLEAST(bmain, 245, 7)) { Object *ob; - bPoseChannel *pchan; for (ob = static_cast(bmain->objects.first); ob; ob = static_cast(ob->id.next)) { if (ob->pose) { - for (pchan = static_cast(ob->pose->chanbase.first); pchan; - pchan = pchan->next) { + LISTBASE_FOREACH (bPoseChannel *, pchan, &ob->pose->chanbase) { do_version_constraints_245(&pchan->constraints); } } @@ -2465,12 +2382,11 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) if (!MAIN_VERSION_FILE_ATLEAST(bmain, 245, 11)) { Object *ob; - bActionStrip *strip; /* NLA-strips - scale. */ for (ob = static_cast(bmain->objects.first); ob; ob = static_cast(ob->id.next)) { - for (strip = static_cast(ob->nlastrips.first); strip; strip = strip->next) { + LISTBASE_FOREACH (bActionStrip *, strip, &ob->nlastrips) { float length, actlength, repeat; if (strip->flag & ACTSTRIP_USESTRIDE) { @@ -2576,11 +2492,10 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) /* set the curve radius interpolation to 2.47 default - easy */ if (!MAIN_VERSION_FILE_ATLEAST(bmain, 247, 6)) { Curve *cu; - Nurb *nu; for (cu = static_cast(bmain->curves.first); cu; cu = static_cast(cu->id.next)) { - for (nu = static_cast(cu->nurb.first); nu; nu = nu->next) { + LISTBASE_FOREACH (Nurb *, nu, &cu->nurb) { nu->radius_interp = 3; /* resolu and resolv are now used differently for surfaces @@ -2614,12 +2529,8 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) for (screen = static_cast(bmain->screens.first); screen; screen = static_cast(screen->id.next)) { - ScrArea *area; - - for (area = static_cast(screen->areabase.first); area; area = area->next) { - SpaceLink *sl; - - for (sl = static_cast(area->spacedata.first); sl; sl = sl->next) { + LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) { + LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) { switch (sl->spacetype) { case SPACE_ACTION: { SpaceAction *sact = (SpaceAction *)sl; diff --git a/source/blender/blenloader/intern/versioning_userdef.cc b/source/blender/blenloader/intern/versioning_userdef.cc index 3a7b2db447c..839fa7ef87f 100644 --- a/source/blender/blenloader/intern/versioning_userdef.cc +++ b/source/blender/blenloader/intern/versioning_userdef.cc @@ -319,9 +319,7 @@ void blo_do_versions_userdef(UserDef *userdef) } if (!USER_VERSION_ATLEAST(250, 8)) { - wmKeyMap *km; - - for (km = static_cast(userdef->user_keymaps.first); km; km = km->next) { + LISTBASE_FOREACH (wmKeyMap *, km, &userdef->user_keymaps) { if (STREQ(km->idname, "Armature_Sketch")) { STRNCPY(km->idname, "Armature Sketch"); } diff --git a/source/blender/bmesh/intern/bmesh_construct.cc b/source/blender/bmesh/intern/bmesh_construct.cc index 9b20082ef4d..c1cdd0acf6b 100644 --- a/source/blender/bmesh/intern/bmesh_construct.cc +++ b/source/blender/bmesh/intern/bmesh_construct.cc @@ -607,7 +607,6 @@ BMesh *BM_mesh_copy(BMesh *bm_old) BMEdge *e, *e_new, **etable = nullptr; BMFace *f, *f_new, **ftable = nullptr; BMElem **eletable; - BMEditSelection *ese; BMIter iter; int i; const BMAllocTemplate allocsize = BMALLOC_TEMPLATE_FROM_BM(bm_old); @@ -683,7 +682,7 @@ BMesh *BM_mesh_copy(BMesh *bm_old) BLI_assert(i == bm_old->totface); /* copy over edit selection history */ - for (ese = static_cast(bm_old->selected.first); ese; ese = ese->next) { + LISTBASE_FOREACH (BMEditSelection *, ese, &bm_old->selected) { BMElem *ele = nullptr; switch (ese->htype) { diff --git a/source/blender/bmesh/intern/bmesh_edgeloop.cc b/source/blender/bmesh/intern/bmesh_edgeloop.cc index b0e8fbe904d..6bcffd244ea 100644 --- a/source/blender/bmesh/intern/bmesh_edgeloop.cc +++ b/source/blender/bmesh/intern/bmesh_edgeloop.cc @@ -398,27 +398,21 @@ void BM_mesh_edgeloops_free(ListBase *eloops) void BM_mesh_edgeloops_calc_center(BMesh *bm, ListBase *eloops) { - BMEdgeLoopStore *el_store; - for (el_store = static_cast(eloops->first); el_store; - el_store = el_store->next) { + LISTBASE_FOREACH (BMEdgeLoopStore *, el_store, eloops) { BM_edgeloop_calc_center(bm, el_store); } } void BM_mesh_edgeloops_calc_normal(BMesh *bm, ListBase *eloops) { - BMEdgeLoopStore *el_store; - for (el_store = static_cast(eloops->first); el_store; - el_store = el_store->next) { + LISTBASE_FOREACH (BMEdgeLoopStore *, el_store, eloops) { BM_edgeloop_calc_normal(bm, el_store); } } void BM_mesh_edgeloops_calc_normal_aligned(BMesh *bm, ListBase *eloops, const float no_align[3]) { - BMEdgeLoopStore *el_store; - for (el_store = static_cast(eloops->first); el_store; - el_store = el_store->next) { + LISTBASE_FOREACH (BMEdgeLoopStore *, el_store, eloops) { BM_edgeloop_calc_normal_aligned(bm, el_store, no_align); } } @@ -442,8 +436,7 @@ void BM_mesh_edgeloops_calc_order(BMesh * /*bm*/, ListBase *eloops, const bool u { BMEdgeLoopStore *el_store_best = nullptr; float len_best_sq = -1.0f; - for (el_store = static_cast(eloops->first); el_store; - el_store = el_store->next) { + LISTBASE_FOREACH (BMEdgeLoopStore *, el_store, eloops) { const float len_sq = len_squared_v3v3(cent, el_store->co); if (len_sq > len_best_sq) { len_best_sq = len_sq; @@ -466,8 +459,7 @@ void BM_mesh_edgeloops_calc_order(BMesh * /*bm*/, ListBase *eloops, const bool u BLI_ASSERT_UNIT_V3(no); } - for (el_store = static_cast(eloops->first); el_store; - el_store = el_store->next) { + LISTBASE_FOREACH (BMEdgeLoopStore *, el_store, eloops) { float len_sq; if (use_normals) { /* Scale the length by how close the loops are to pointing at each other. */ @@ -776,23 +768,21 @@ void BM_edgeloop_expand( bool BM_edgeloop_overlap_check(BMEdgeLoopStore *el_store_a, BMEdgeLoopStore *el_store_b) { - LinkData *node; - /* A little more efficient if 'a' as smaller. */ if (el_store_a->len > el_store_b->len) { SWAP(BMEdgeLoopStore *, el_store_a, el_store_b); } /* init */ - for (node = static_cast(el_store_a->verts.first); node; node = node->next) { + LISTBASE_FOREACH (LinkData *, node, &el_store_a->verts) { BM_elem_flag_enable((BMVert *)node->data, BM_ELEM_INTERNAL_TAG); } - for (node = static_cast(el_store_b->verts.first); node; node = node->next) { + LISTBASE_FOREACH (LinkData *, node, &el_store_b->verts) { BM_elem_flag_disable((BMVert *)node->data, BM_ELEM_INTERNAL_TAG); } /* Check 'a' (clear as we go). */ - for (node = static_cast(el_store_a->verts.first); node; node = node->next) { + LISTBASE_FOREACH (LinkData *, node, &el_store_a->verts) { if (!BM_elem_flag_test((BMVert *)node->data, BM_ELEM_INTERNAL_TAG)) { /* Finish clearing 'a', leave tag clean. */ while ((node = node->next)) { diff --git a/source/blender/bmesh/intern/bmesh_marking.cc b/source/blender/bmesh/intern/bmesh_marking.cc index 90b96de9cba..bde531ee5ba 100644 --- a/source/blender/bmesh/intern/bmesh_marking.cc +++ b/source/blender/bmesh/intern/bmesh_marking.cc @@ -1139,16 +1139,13 @@ bool BM_select_history_active_get(BMesh *bm, BMEditSelection *ese) GHash *BM_select_history_map_create(BMesh *bm) { - BMEditSelection *ese; - GHash *map; - if (BLI_listbase_is_empty(&bm->selected)) { return nullptr; } - map = BLI_ghash_ptr_new(__func__); + GHash *map = BLI_ghash_ptr_new(__func__); - for (ese = static_cast(bm->selected.first); ese; ese = ese->next) { + LISTBASE_FOREACH (BMEditSelection *, ese, &bm->selected) { BLI_ghash_insert(map, ese->ele, ese); } diff --git a/source/blender/bmesh/intern/bmesh_mesh.cc b/source/blender/bmesh/intern/bmesh_mesh.cc index d1b016bec31..77c65a164d0 100644 --- a/source/blender/bmesh/intern/bmesh_mesh.cc +++ b/source/blender/bmesh/intern/bmesh_mesh.cc @@ -990,8 +990,7 @@ void BM_mesh_remap(BMesh *bm, const uint *vert_idx, const uint *edge_idx, const /* Selection history */ { - BMEditSelection *ese; - for (ese = static_cast(bm->selected.first); ese; ese = ese->next) { + LISTBASE_FOREACH (BMEditSelection *, ese, &bm->selected) { switch (ese->htype) { case BM_VERT: if (vptr_map) { diff --git a/source/blender/bmesh/intern/bmesh_operators.cc b/source/blender/bmesh/intern/bmesh_operators.cc index c937ba241aa..6ec1f1e0f01 100644 --- a/source/blender/bmesh/intern/bmesh_operators.cc +++ b/source/blender/bmesh/intern/bmesh_operators.cc @@ -1512,7 +1512,7 @@ bool BMO_error_get_at_level(BMesh *bm, const char **r_msg, BMOperator **r_op) { - for (BMOpError *err = static_cast(bm->errorstack.first); err; err = err->next) { + LISTBASE_FOREACH (BMOpError *, err, &bm->errorstack) { if (err->level >= level) { if (r_msg) { *r_msg = err->msg; diff --git a/source/blender/bmesh/operators/bmo_bridge.cc b/source/blender/bmesh/operators/bmo_bridge.cc index 04921483bcc..6bd94ee8a1f 100644 --- a/source/blender/bmesh/operators/bmo_bridge.cc +++ b/source/blender/bmesh/operators/bmo_bridge.cc @@ -257,9 +257,7 @@ static void bridge_loop_pair(BMesh *bm, int winding_votes[2] = {0, 0}; int winding_dir = 1; for (i = 0; i < 2; i++, winding_dir = -winding_dir) { - LinkData *el; - for (el = static_cast(BM_edgeloop_verts_get(estore_pair[i])->first); el; - el = el->next) { + LISTBASE_FOREACH (LinkData *, el, BM_edgeloop_verts_get(estore_pair[i])) { LinkData *el_next = BM_EDGELINK_NEXT(estore_pair[i], el); if (el_next) { BMEdge *e = BM_edge_exists(static_cast(el->data), @@ -510,9 +508,7 @@ static void bridge_loop_pair(BMesh *bm, /* tag verts on each side so we can restrict rotation of edges to verts on the same side */ for (i = 0; i < 2; i++) { - LinkData *el; - for (el = static_cast(BM_edgeloop_verts_get(estore_pair[i])->first); el; - el = el->next) { + LISTBASE_FOREACH (LinkData *, el, BM_edgeloop_verts_get(estore_pair[i])) { BM_elem_flag_set((BMVert *)el->data, BM_ELEM_TAG, i); } } @@ -557,9 +553,7 @@ static void bridge_loop_pair(BMesh *bm, BMEdgeLoopStore *estore_pair[2] = {el_store_a, el_store_b}; int i; for (i = 0; i < 2; i++) { - LinkData *el; - for (el = static_cast(BM_edgeloop_verts_get(estore_pair[i])->first); el; - el = el->next) { + LISTBASE_FOREACH (LinkData *, el, BM_edgeloop_verts_get(estore_pair[i])) { LinkData *el_next = BM_EDGELINK_NEXT(estore_pair[i], el); if (el_next) { if (el->data != el_next->data) { @@ -580,7 +574,6 @@ static void bridge_loop_pair(BMesh *bm, void bmo_bridge_loops_exec(BMesh *bm, BMOperator *op) { ListBase eloops = {nullptr}; - LinkData *el_store; /* merge-bridge support */ const bool use_pairs = BMO_slot_bool_get(op->slots_in, "use_pairs"); @@ -610,7 +603,7 @@ void bmo_bridge_loops_exec(BMesh *bm, BMOperator *op) if (use_merge) { bool match = true; const int eloop_len = BM_edgeloop_length_get(static_cast(eloops.first)); - for (el_store = static_cast(eloops.first); el_store; el_store = el_store->next) { + LISTBASE_FOREACH (LinkData *, el_store, &eloops) { if (eloop_len != BM_edgeloop_length_get((BMEdgeLoopStore *)el_store)) { match = false; break; @@ -629,7 +622,7 @@ void bmo_bridge_loops_exec(BMesh *bm, BMOperator *op) BM_mesh_edgeloops_calc_order(bm, &eloops, use_pairs); } - for (el_store = static_cast(eloops.first); el_store; el_store = el_store->next) { + LISTBASE_FOREACH (LinkData *, el_store, &eloops) { LinkData *el_store_next = el_store->next; if (el_store_next == nullptr) { diff --git a/source/blender/bmesh/operators/bmo_create.cc b/source/blender/bmesh/operators/bmo_create.cc index 1e993a2c997..4d721f58d7c 100644 --- a/source/blender/bmesh/operators/bmo_create.cc +++ b/source/blender/bmesh/operators/bmo_create.cc @@ -222,11 +222,9 @@ void bmo_contextual_create_exec(BMesh *bm, BMOperator *op) * if all history verts have ELE_NEW flagged and the total number of history verts == totv, * then we know the history contains all verts here and we can continue... */ - - BMEditSelection *ese; int tot_ese_v = 0; - for (ese = static_cast(bm->selected.first); ese; ese = ese->next) { + LISTBASE_FOREACH (BMEditSelection *, ese, &bm->selected) { if (ese->htype == BM_VERT) { if (BMO_vert_flag_test(bm, (BMVert *)ese->ele, ELE_NEW)) { tot_ese_v++; @@ -243,7 +241,7 @@ void bmo_contextual_create_exec(BMesh *bm, BMOperator *op) BMVert *v_prev = nullptr; /* yes, all select-history verts are accounted for, now make edges */ - for (ese = static_cast(bm->selected.first); ese; ese = ese->next) { + LISTBASE_FOREACH (BMEditSelection *, ese, &bm->selected) { if (ese->htype == BM_VERT) { BMVert *v = (BMVert *)ese->ele; if (v_prev) { diff --git a/source/blender/bmesh/operators/bmo_hull.cc b/source/blender/bmesh/operators/bmo_hull.cc index 22d252d08cc..47dd9359260 100644 --- a/source/blender/bmesh/operators/bmo_hull.cc +++ b/source/blender/bmesh/operators/bmo_hull.cc @@ -160,7 +160,7 @@ static LinkData *final_edges_find_link(ListBase *adj, BMVert *v) { LinkData *link; - for (link = static_cast(adj->first); link; link = link->next) { + LISTBASE_FOREACH (LinkData *, link, adj) { if (link->data == v) { return link; } diff --git a/source/blender/bmesh/operators/bmo_subdivide_edgering.cc b/source/blender/bmesh/operators/bmo_subdivide_edgering.cc index f2a3973701d..d5bacdc4714 100644 --- a/source/blender/bmesh/operators/bmo_subdivide_edgering.cc +++ b/source/blender/bmesh/operators/bmo_subdivide_edgering.cc @@ -155,15 +155,13 @@ static bool bm_edgeloop_check_overlap_all(BMesh *bm, BMEdgeLoopStore *el_store_b) { bool has_overlap = true; - LinkData *node; - ListBase *lb_a = BM_edgeloop_verts_get(el_store_a); ListBase *lb_b = BM_edgeloop_verts_get(el_store_b); bm_edgeloop_vert_tag(el_store_a, false); bm_edgeloop_vert_tag(el_store_b, true); - for (node = static_cast(lb_a->first); node; node = node->next) { + LISTBASE_FOREACH (LinkData *, node, lb_a) { if (bm_vert_is_tag_edge_connect(bm, static_cast(node->data)) == false) { has_overlap = false; goto finally; @@ -173,7 +171,7 @@ static bool bm_edgeloop_check_overlap_all(BMesh *bm, bm_edgeloop_vert_tag(el_store_a, true); bm_edgeloop_vert_tag(el_store_b, false); - for (node = static_cast(lb_b->first); node; node = node->next) { + LISTBASE_FOREACH (LinkData *, node, lb_b) { if (bm_vert_is_tag_edge_connect(bm, static_cast(node->data)) == false) { has_overlap = false; goto finally; @@ -994,7 +992,6 @@ static void bm_edgering_pair_subdiv(BMesh *bm, STACK_DECLARE(edges_ring_arr); STACK_DECLARE(faces_ring_arr); BMEdgeLoopStore *el_store_ring; - LinkData *node; BMEdge *e; BMFace *f; @@ -1004,7 +1001,7 @@ static void bm_edgering_pair_subdiv(BMesh *bm, bm_edgeloop_vert_tag(el_store_a, false); bm_edgeloop_vert_tag(el_store_b, true); - for (node = static_cast(lb_a->first); node; node = node->next) { + LISTBASE_FOREACH (LinkData *, node, lb_a) { BMIter eiter; BM_ITER_ELEM (e, &eiter, (BMVert *)node->data, BM_EDGES_OF_VERT) { diff --git a/source/blender/bmesh/operators/bmo_triangulate.cc b/source/blender/bmesh/operators/bmo_triangulate.cc index c23686a5d2f..d6cf5898bfa 100644 --- a/source/blender/bmesh/operators/bmo_triangulate.cc +++ b/source/blender/bmesh/operators/bmo_triangulate.cc @@ -54,7 +54,6 @@ void bmo_triangle_fill_exec(BMesh *bm, BMOperator *op) BMEdge *e; ScanFillContext sf_ctx; /* ScanFillEdge *sf_edge; */ /* UNUSED */ - ScanFillFace *sf_tri; GHash *sf_vert_map; float normal[3]; const int scanfill_flag = BLI_SCANFILL_CALC_HOLES | BLI_SCANFILL_CALC_POLYS | @@ -181,9 +180,7 @@ void bmo_triangle_fill_exec(BMesh *bm, BMOperator *op) /* if we have existing faces, base winding on those */ if (calc_winding) { int winding_votes = 0; - for (sf_tri = static_cast(sf_ctx.fillfacebase.first); sf_tri; - sf_tri = sf_tri->next) - { + LISTBASE_FOREACH (ScanFillFace *, sf_tri, &sf_ctx.fillfacebase) { BMVert *v_tri[3] = {static_cast(sf_tri->v1->tmp.p), static_cast(sf_tri->v2->tmp.p), static_cast(sf_tri->v3->tmp.p)}; @@ -198,17 +195,13 @@ void bmo_triangle_fill_exec(BMesh *bm, BMOperator *op) } if (winding_votes < 0) { - for (sf_tri = static_cast(sf_ctx.fillfacebase.first); sf_tri; - sf_tri = sf_tri->next) - { + LISTBASE_FOREACH (ScanFillFace *, sf_tri, &sf_ctx.fillfacebase) { SWAP(ScanFillVert *, sf_tri->v2, sf_tri->v3); } } } - for (sf_tri = static_cast(sf_ctx.fillfacebase.first); sf_tri; - sf_tri = sf_tri->next) - { + LISTBASE_FOREACH (ScanFillFace *, sf_tri, &sf_ctx.fillfacebase) { BMFace *f; BMLoop *l; BMIter liter; diff --git a/source/blender/bmesh/tools/bmesh_edgesplit.cc b/source/blender/bmesh/tools/bmesh_edgesplit.cc index a5217fe8afd..f2d77011ed9 100644 --- a/source/blender/bmesh/tools/bmesh_edgesplit.cc +++ b/source/blender/bmesh/tools/bmesh_edgesplit.cc @@ -28,10 +28,8 @@ void BM_mesh_edgesplit(BMesh *bm, GHash *ese_gh = nullptr; if (copy_select && bm->selected.first) { - BMEditSelection *ese; - ese_gh = BLI_ghash_ptr_new(__func__); - for (ese = static_cast(bm->selected.first); ese; ese = ese->next) { + LISTBASE_FOREACH (BMEditSelection *, ese, &bm->selected) { if (ese->htype != BM_FACE) { BLI_ghash_insert(ese_gh, ese->ele, ese); } diff --git a/source/blender/compositor/operations/COM_MaskOperation.cc b/source/blender/compositor/operations/COM_MaskOperation.cc index 7edb00addb8..79be8aaf683 100644 --- a/source/blender/compositor/operations/COM_MaskOperation.cc +++ b/source/blender/compositor/operations/COM_MaskOperation.cc @@ -43,12 +43,9 @@ void MaskOperation::init_execution() /* trick so we can get unkeyed edits to display */ { - MaskLayer *masklay; - MaskLayerShape *masklay_shape; - - for (masklay = (MaskLayer *)mask_temp->masklayers.first; masklay; masklay = masklay->next) - { - masklay_shape = BKE_mask_layer_shape_verify_frame(masklay, frame_number_); + LISTBASE_FOREACH (MaskLayer *, masklay, &mask_temp->masklayers) { + MaskLayerShape *masklay_shape = BKE_mask_layer_shape_verify_frame(masklay, + frame_number_); BKE_mask_layer_shape_from_mask(masklay, masklay_shape); } } diff --git a/source/blender/compositor/operations/COM_OutputFileMultiViewOperation.cc b/source/blender/compositor/operations/COM_OutputFileMultiViewOperation.cc index 4b2ac156b1f..db797543142 100644 --- a/source/blender/compositor/operations/COM_OutputFileMultiViewOperation.cc +++ b/source/blender/compositor/operations/COM_OutputFileMultiViewOperation.cc @@ -37,7 +37,6 @@ void *OutputOpenExrSingleLayerMultiViewOperation::get_handle(const char *filepat { size_t width = this->get_width(); size_t height = this->get_height(); - SceneRenderView *srv; if (width != 0 && height != 0) { void *exrhandle; @@ -50,7 +49,7 @@ void *OutputOpenExrSingleLayerMultiViewOperation::get_handle(const char *filepat IMB_exr_clear_channels(exrhandle); - for (srv = (SceneRenderView *)rd_->views.first; srv; srv = srv->next) { + LISTBASE_FOREACH (SceneRenderView *, srv, &rd_->views) { if (BKE_scene_multiview_is_render_view_active(rd_, srv) == false) { continue; } @@ -139,12 +138,8 @@ void *OutputOpenExrMultiLayerMultiViewOperation::get_handle(const char *filepath uint height = this->get_height(); if (width != 0 && height != 0) { - - void *exrhandle; - SceneRenderView *srv; - - /* get a new global handle */ - exrhandle = IMB_exr_get_handle_name(filepath); + /* Get a new global handle. */ + void *exrhandle = IMB_exr_get_handle_name(filepath); if (!BKE_scene_multiview_is_render_view_first(rd_, view_name_)) { return exrhandle; @@ -153,7 +148,7 @@ void *OutputOpenExrMultiLayerMultiViewOperation::get_handle(const char *filepath IMB_exr_clear_channels(exrhandle); /* check renderdata for amount of views */ - for (srv = (SceneRenderView *)rd_->views.first; srv; srv = srv->next) { + LISTBASE_FOREACH (SceneRenderView *, srv, &rd_->views) { if (BKE_scene_multiview_is_render_view_active(rd_, srv) == false) { continue; diff --git a/source/blender/compositor/operations/COM_OutputFileOperation.cc b/source/blender/compositor/operations/COM_OutputFileOperation.cc index a8e9d364ca2..60456b9c1af 100644 --- a/source/blender/compositor/operations/COM_OutputFileOperation.cc +++ b/source/blender/compositor/operations/COM_OutputFileOperation.cc @@ -107,10 +107,8 @@ void free_exr_channels(void *exrhandle, const char *layer_name, const DataType datatype) { - SceneRenderView *srv; - /* check renderdata for amount of views */ - for (srv = (SceneRenderView *)rd->views.first; srv; srv = srv->next) { + LISTBASE_FOREACH (SceneRenderView *, srv, &rd->views) { float *rect = nullptr; if (BKE_scene_multiview_is_render_view_active(rd, srv) == false) { diff --git a/source/blender/depsgraph/intern/builder/deg_builder_nodes_view_layer.cc b/source/blender/depsgraph/intern/builder/deg_builder_nodes_view_layer.cc index 96d59168b94..4084abbfb82 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder_nodes_view_layer.cc +++ b/source/blender/depsgraph/intern/builder/deg_builder_nodes_view_layer.cc @@ -48,7 +48,7 @@ void DepsgraphNodeBuilder::build_layer_collections(ListBase *lb) const int visibility_flag = (graph_->mode == DAG_EVAL_VIEWPORT) ? COLLECTION_HIDE_VIEWPORT : COLLECTION_HIDE_RENDER; - for (LayerCollection *lc = (LayerCollection *)lb->first; lc; lc = lc->next) { + LISTBASE_FOREACH (LayerCollection *, lc, lb) { if (lc->collection->flag & visibility_flag) { continue; } diff --git a/source/blender/depsgraph/intern/builder/deg_builder_relations.cc b/source/blender/depsgraph/intern/builder/deg_builder_relations.cc index 8536e251b6e..7b95fa420c8 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder_relations.cc +++ b/source/blender/depsgraph/intern/builder/deg_builder_relations.cc @@ -1339,7 +1339,7 @@ void DepsgraphRelationBuilder::build_constraints(ID *id, OperationCode::BONE_CONSTRAINTS : OperationCode::TRANSFORM_CONSTRAINTS); /* Add dependencies for each constraint in turn. */ - for (bConstraint *con = (bConstraint *)constraints->first; con; con = con->next) { + LISTBASE_FOREACH (bConstraint *, con, constraints) { const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con); ListBase targets = {nullptr, nullptr}; /* Invalid constraint type. */ diff --git a/source/blender/draw/engines/overlay/overlay_armature.cc b/source/blender/draw/engines/overlay/overlay_armature.cc index 7d6e882a74b..1e0b8ade7e6 100644 --- a/source/blender/draw/engines/overlay/overlay_armature.cc +++ b/source/blender/draw/engines/overlay/overlay_armature.cc @@ -1406,13 +1406,11 @@ static void draw_bone_update_disp_matrix_default(UnifiedBonePtr bone) /* compute connected child pointer for B-Bone drawing */ static void edbo_compute_bbone_child(bArmature *arm) { - EditBone *eBone; - - for (eBone = static_cast(arm->edbo->first); eBone; eBone = eBone->next) { + LISTBASE_FOREACH (EditBone *, eBone, arm->edbo) { eBone->bbone_child = nullptr; } - for (eBone = static_cast(arm->edbo->first); eBone; eBone = eBone->next) { + LISTBASE_FOREACH (EditBone *, eBone, arm->edbo) { if (eBone->parent && (eBone->flag & BONE_CONNECTED)) { eBone->parent->bbone_child = eBone; } @@ -1800,12 +1798,11 @@ static void pchan_draw_ik_lines(const ArmatureDrawContext *ctx, const bPoseChannel *pchan, const bool only_temp) { - const bConstraint *con; const bPoseChannel *parchan; const float *line_start = nullptr, *line_end = nullptr; const ePchan_ConstFlag constflag = ePchan_ConstFlag(pchan->constflag); - for (con = static_cast(pchan->constraints.first); con; con = con->next) { + LISTBASE_FOREACH (bConstraint *, con, &pchan->constraints) { if (con->enforce == 0.0f) { continue; } diff --git a/source/blender/draw/engines/overlay/overlay_extra.cc b/source/blender/draw/engines/overlay/overlay_extra.cc index 89591e1cfa0..e2fac9dffeb 100644 --- a/source/blender/draw/engines/overlay/overlay_extra.cc +++ b/source/blender/draw/engines/overlay/overlay_extra.cc @@ -1286,7 +1286,7 @@ static void OVERLAY_relationship_lines(OVERLAY_ExtraCallBuffers *cb, } /* Drawing the hook lines. */ - for (ModifierData *md = static_cast(ob->modifiers.first); md; md = md->next) { + LISTBASE_FOREACH (ModifierData *, md, &ob->modifiers) { if (md->type == eModifierType_Hook) { HookModifierData *hmd = (HookModifierData *)md; float center[3]; @@ -1297,11 +1297,7 @@ static void OVERLAY_relationship_lines(OVERLAY_ExtraCallBuffers *cb, OVERLAY_extra_point(cb, center, relation_color); } } - for (GpencilModifierData *md = - static_cast(ob->greasepencil_modifiers.first); - md; - md = md->next) - { + LISTBASE_FOREACH (GpencilModifierData *, md, &ob->greasepencil_modifiers) { if (md->type == eGpencilModifierType_Hook) { HookGpencilModifierData *hmd = (HookGpencilModifierData *)md; float center[3]; @@ -1328,13 +1324,11 @@ static void OVERLAY_relationship_lines(OVERLAY_ExtraCallBuffers *cb, /* Drawing the constraint lines */ if (!BLI_listbase_is_empty(&ob->constraints)) { - bConstraint *curcon; - bConstraintOb *cob; ListBase *list = &ob->constraints; + bConstraintOb *cob = BKE_constraints_make_evalob( + depsgraph, scene, ob, nullptr, CONSTRAINT_OBTYPE_OBJECT); - cob = BKE_constraints_make_evalob(depsgraph, scene, ob, nullptr, CONSTRAINT_OBTYPE_OBJECT); - - for (curcon = static_cast(list->first); curcon; curcon = curcon->next) { + LISTBASE_FOREACH (bConstraint *, curcon, list) { if (ELEM(curcon->type, CONSTRAINT_TYPE_FOLLOWTRACK, CONSTRAINT_TYPE_OBJECTSOLVER)) { /* special case for object solver and follow track constraints because they don't fill * constraint targets properly (design limitation -- scene is needed for their target @@ -1360,11 +1354,9 @@ static void OVERLAY_relationship_lines(OVERLAY_ExtraCallBuffers *cb, ListBase targets = {nullptr, nullptr}; if ((curcon->ui_expand_flag & (1 << 0)) && BKE_constraint_targets_get(curcon, &targets)) { - bConstraintTarget *ct; - BKE_constraint_custom_object_space_init(cob, curcon); - for (ct = static_cast(targets.first); ct; ct = ct->next) { + LISTBASE_FOREACH (bConstraintTarget *, ct, &targets) { /* calculate target's matrix */ if (ct->flag & CONSTRAINT_TAR_CUSTOM_SPACE) { copy_m4_m4(ct->matrix, cob->space_obj_world_matrix); diff --git a/source/blender/draw/intern/draw_manager_c.cc b/source/blender/draw/intern/draw_manager_c.cc index 594b0f13efe..e945f7e21b8 100644 --- a/source/blender/draw/intern/draw_manager_c.cc +++ b/source/blender/draw/intern/draw_manager_c.cc @@ -790,9 +790,7 @@ void **DRW_view_layer_engine_data_ensure_ex(ViewLayer *view_layer, { ViewLayerEngineData *sled; - for (sled = static_cast(view_layer->drawdata.first); sled; - sled = sled->next) - { + LISTBASE_FOREACH (ViewLayerEngineData *, sled, &view_layer->drawdata) { if (sled->engine_type == engine_type) { return &sled->storage; } @@ -974,7 +972,6 @@ static void drw_drawdata_unlink_dupli(ID *id) void DRW_cache_free_old_batches(Main *bmain) { Scene *scene; - ViewLayer *view_layer; static int lasttime = 0; int ctime = int(PIL_check_seconds_timer()); @@ -987,9 +984,7 @@ void DRW_cache_free_old_batches(Main *bmain) for (scene = static_cast(bmain->scenes.first); scene; scene = static_cast(scene->id.next)) { - for (view_layer = static_cast(scene->view_layers.first); view_layer; - view_layer = view_layer->next) - { + LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) { Depsgraph *depsgraph = BKE_scene_get_depsgraph(scene, view_layer); if (depsgraph == nullptr) { continue; diff --git a/source/blender/editors/animation/anim_channels_edit.cc b/source/blender/editors/animation/anim_channels_edit.cc index c186bdcb878..f4f8ea4a053 100644 --- a/source/blender/editors/animation/anim_channels_edit.cc +++ b/source/blender/editors/animation/anim_channels_edit.cc @@ -410,7 +410,7 @@ static ListBase /*bAnimListElem*/ anim_channels_for_selection(bAnimContext *ac) static eAnimChannels_SetFlag anim_channels_selection_flag_for_toggle(const ListBase anim_data) { /* See if we should be selecting or deselecting. */ - for (bAnimListElem *ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { switch (ale->type) { case ANIMTYPE_SCENE: if (ale->flag & SCE_DS_SELECTED) { @@ -494,11 +494,10 @@ static void anim_channels_select_set(bAnimContext *ac, const ListBase anim_data, eAnimChannels_SetFlag sel) { - bAnimListElem *ale; /* Boolean to keep active channel status during range selection. */ const bool change_active = (sel != ACHANNEL_SETFLAG_EXTEND_RANGE); - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { switch (ale->type) { case ANIMTYPE_SCENE: { if (change_active) { @@ -751,7 +750,7 @@ void ANIM_flush_setting_anim_channels(bAnimContext *ac, eAnimChannel_Settings setting, eAnimChannels_SetFlag mode) { - bAnimListElem *ale, *match = nullptr; + bAnimListElem *match = nullptr; int matchLevel = 0; /* sanity check */ @@ -764,7 +763,7 @@ void ANIM_flush_setting_anim_channels(bAnimContext *ac, } /* find the channel that got changed */ - for (ale = static_cast(anim_data->first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, anim_data) { /* compare data, and type as main way of identifying the channel */ if ((ale->data == ale_setting->data) && (ale->type == ale_setting->type)) { /* We also have to check the ID, this is assigned to, @@ -1520,7 +1519,7 @@ static void split_groups_action_temp(bAction *act, bActionGroup *tgrp) /* ensure that all of these get their group set to this temp group * (so that visibility filtering works) */ - for (fcu = static_cast(tgrp->channels.first); fcu; fcu = fcu->next) { + LISTBASE_FOREACH (FCurve *, fcu, &tgrp->channels) { fcu->grp = tgrp; } } @@ -1532,9 +1531,7 @@ static void split_groups_action_temp(bAction *act, bActionGroup *tgrp) /* link lists of channels that groups have */ static void join_groups_action_temp(bAction *act) { - bActionGroup *agrp; - - for (agrp = static_cast(act->groups.first); agrp; agrp = agrp->next) { + LISTBASE_FOREACH (bActionGroup *, agrp, &act->groups) { /* add list of channels to action's channels */ const ListBase group_channels = agrp->channels; BLI_movelisttolist(&act->curves, &agrp->channels); @@ -1592,12 +1589,10 @@ static void rearrange_action_channels(bAnimContext *ac, bAction *act, eRearrange BLI_freelistN(&anim_data_visible); if (do_channels) { - bActionGroup *agrp; - /* Filter visible data. */ rearrange_animchannels_filter_visible(&anim_data_visible, ac, ANIMTYPE_FCURVE); - for (agrp = static_cast(act->groups.first); agrp; agrp = agrp->next) { + LISTBASE_FOREACH (bActionGroup *, agrp, &act->groups) { /* only consider F-Curves if they're visible (group expanded) */ if (EXPANDED_AGRP(ac, agrp)) { rearrange_animchannel_islands( @@ -1621,9 +1616,6 @@ static void rearrange_nla_control_channels(bAnimContext *ac, { ListBase anim_data_visible = {nullptr, nullptr}; - NlaTrack *nlt; - NlaStrip *strip; - /* get rearranging function */ AnimChanRearrangeFp rearrange_func = rearrange_get_mode_func(mode); @@ -1640,8 +1632,8 @@ static void rearrange_nla_control_channels(bAnimContext *ac, rearrange_animchannels_filter_visible(&anim_data_visible, ac, ANIMTYPE_NLACURVE); /* we cannot rearrange between strips, but within each strip, we can rearrange those curves */ - for (nlt = static_cast(adt->nla_tracks.first); nlt; nlt = nlt->next) { - for (strip = static_cast(nlt->strips.first); strip; strip = strip->next) { + LISTBASE_FOREACH (NlaTrack *, nlt, &adt->nla_tracks) { + LISTBASE_FOREACH (NlaStrip *, strip, &nlt->strips) { rearrange_animchannel_islands( &strip->fcurves, rearrange_func, mode, ANIMTYPE_NLACURVE, &anim_data_visible); } @@ -1656,7 +1648,6 @@ static void rearrange_nla_control_channels(bAnimContext *ac, static void rearrange_gpencil_channels(bAnimContext *ac, eRearrangeAnimChan_Mode mode) { ListBase anim_data = {nullptr, nullptr}; - bAnimListElem *ale; int filter; /* get rearranging function */ @@ -1672,7 +1663,7 @@ static void rearrange_gpencil_channels(bAnimContext *ac, eRearrangeAnimChan_Mode ANIM_animdata_filter( ac, &anim_data, eAnimFilter_Flags(filter), ac->data, eAnimCont_Types(ac->datatype)); - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { /* only consider grease pencil container channels */ if (!ELEM(ale->type, ANIMTYPE_GPDATABLOCK, ANIMTYPE_DSGPENCIL)) { continue; @@ -1736,7 +1727,6 @@ static int animchannels_rearrange_exec(bContext *C, wmOperator *op) } else { ListBase anim_data = {nullptr, nullptr}; - bAnimListElem *ale; int filter; if (ELEM(ac.datatype, ANIMCONT_DOPESHEET, ANIMCONT_TIMELINE)) { @@ -1749,7 +1739,7 @@ static int animchannels_rearrange_exec(bContext *C, wmOperator *op) ANIM_animdata_filter( &ac, &anim_data, eAnimFilter_Flags(filter), ac.data, eAnimCont_Types(ac.datatype)); - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { AnimData *adt = static_cast(ale->data); switch (ac.datatype) { @@ -1897,14 +1887,13 @@ static void animchannels_group_channels(bAnimContext *ac, if (anim_data.first) { bActionGroup *agrp; - bAnimListElem *ale; /* create new group, which should now be part of the action */ agrp = action_groups_add_new(act, name); BLI_assert(agrp != nullptr); /* Transfer selected F-Curves across to new group. */ - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { FCurve *fcu = (FCurve *)ale->data; bActionGroup *grp = fcu->grp; @@ -1941,7 +1930,6 @@ static int animchannels_group_exec(bContext *C, wmOperator *op) /* XXX: name for group should never be empty... */ if (name[0]) { ListBase anim_data = {nullptr, nullptr}; - bAnimListElem *ale; int filter; /* Handle each animdata block separately, so that the regrouping doesn't flow into blocks. */ @@ -1950,7 +1938,7 @@ static int animchannels_group_exec(bContext *C, wmOperator *op) ANIM_animdata_filter( &ac, &anim_data, eAnimFilter_Flags(filter), ac.data, eAnimCont_Types(ac.datatype)); - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { animchannels_group_channels(&ac, ale, name); } @@ -2001,7 +1989,6 @@ static int animchannels_ungroup_exec(bContext *C, wmOperator * /*op*/) bAnimContext ac; ListBase anim_data = {nullptr, nullptr}; - bAnimListElem *ale; int filter; /* get editor data */ @@ -2015,7 +2002,7 @@ static int animchannels_ungroup_exec(bContext *C, wmOperator * /*op*/) ANIM_animdata_filter( &ac, &anim_data, eAnimFilter_Flags(filter), ac.data, eAnimCont_Types(ac.datatype)); - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { /* find action for this F-Curve... */ if (ale->adt && ale->adt->action) { FCurve *fcu = (FCurve *)ale->data; @@ -2091,7 +2078,6 @@ static int animchannels_delete_exec(bContext *C, wmOperator * /*op*/) { bAnimContext ac; ListBase anim_data = {nullptr, nullptr}; - bAnimListElem *ale; int filter; /* get editor data */ @@ -2113,7 +2099,7 @@ static int animchannels_delete_exec(bContext *C, wmOperator * /*op*/) &ac, &anim_data, eAnimFilter_Flags(filter), ac.data, eAnimCont_Types(ac.datatype)); /* delete selected groups and their associated channels */ - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { /* only groups - don't check other types yet, since they may no-longer exist */ if (ale->type == ANIMTYPE_GROUP) { bActionGroup *agrp = (bActionGroup *)ale->data; @@ -2157,7 +2143,7 @@ static int animchannels_delete_exec(bContext *C, wmOperator * /*op*/) &ac, &anim_data, eAnimFilter_Flags(filter), ac.data, eAnimCont_Types(ac.datatype)); /* delete selected data channels */ - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { switch (ale->type) { case ANIMTYPE_FCURVE: { /* F-Curves if we can identify its parent */ @@ -2280,7 +2266,6 @@ static void setflag_anim_channels(bAnimContext *ac, { ListBase anim_data = {nullptr, nullptr}; ListBase all_data = {nullptr, nullptr}; - bAnimListElem *ale; int filter; /* filter data that we need if flush is on */ @@ -2323,7 +2308,7 @@ static void setflag_anim_channels(bAnimContext *ac, mode = ACHANNEL_SETFLAG_ADD; /* see if we should turn off instead... */ - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { /* set the setting in the appropriate way (if available) */ if (ANIM_channel_setting_get(ac, ale, setting) > 0) { mode = ACHANNEL_SETFLAG_CLEAR; @@ -2333,7 +2318,7 @@ static void setflag_anim_channels(bAnimContext *ac, } /* apply the setting */ - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { /* skip channel if setting is not available */ if (ANIM_channel_setting_get(ac, ale, setting) == -1) { continue; @@ -2612,7 +2597,6 @@ static int animchannels_clean_empty_exec(bContext *C, wmOperator * /*op*/) bAnimContext ac; ListBase anim_data = {nullptr, nullptr}; - bAnimListElem *ale; int filter; /* get editor data */ @@ -2626,7 +2610,7 @@ static int animchannels_clean_empty_exec(bContext *C, wmOperator * /*op*/) ANIM_animdata_filter( &ac, &anim_data, eAnimFilter_Flags(filter), ac.data, eAnimCont_Types(ac.datatype)); - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { ID *id = ale->id; AnimData *adt = static_cast(ale->data); @@ -2653,10 +2637,8 @@ static int animchannels_clean_empty_exec(bContext *C, wmOperator * /*op*/) nla_empty = true; } else { - NlaTrack *nlt; - /* empty tracks? */ - for (nlt = static_cast(adt->nla_tracks.first); nlt; nlt = nlt->next) { + LISTBASE_FOREACH (NlaTrack *, nlt, &adt->nla_tracks) { if (nlt->strips.first) { /* stop searching, as we found one that actually had stuff we don't want lost * NOTE: nla_empty gets reset to false, as a previous track may have been empty @@ -2734,7 +2716,6 @@ static int animchannels_enable_exec(bContext *C, wmOperator * /*op*/) bAnimContext ac; ListBase anim_data = {nullptr, nullptr}; - bAnimListElem *ale; int filter; /* get editor data */ @@ -2748,7 +2729,7 @@ static int animchannels_enable_exec(bContext *C, wmOperator * /*op*/) &ac, &anim_data, eAnimFilter_Flags(filter), ac.data, eAnimCont_Types(ac.datatype)); /* loop through filtered data and clean curves */ - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { FCurve *fcu = (FCurve *)ale->data; /* remove disabled flags from F-Curves */ @@ -2932,7 +2913,6 @@ static void ANIM_OT_channels_select_all(wmOperatorType *ot) static void box_select_anim_channels(bAnimContext *ac, rcti *rect, short selectmode) { ListBase anim_data = {nullptr, nullptr}; - bAnimListElem *ale; int filter; SpaceNla *snla = (SpaceNla *)ac->sl; @@ -2958,7 +2938,7 @@ static void box_select_anim_channels(bAnimContext *ac, rcti *rect, short selectm } /* loop over data, doing box select */ - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { float ymin; if (ale->type == ANIMTYPE_GPDATABLOCK) { @@ -3970,7 +3950,7 @@ static bool select_anim_channel_keys(bAnimContext *ac, int channel_index, bool e filter = (ANIMFILTER_DATA_VISIBLE); ANIM_animdata_filter( ac, &anim_data, eAnimFilter_Flags(filter), ac->data, eAnimCont_Types(ac->datatype)); - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { FCurve *fcu_inner = (FCurve *)ale->key_data; if (fcu_inner != nullptr && fcu_inner->bezt != nullptr) { @@ -4090,11 +4070,10 @@ static int graphkeys_view_selected_channels_exec(bContext *C, wmOperator *op) bounds.ymin = FLT_MAX; bounds.ymax = -FLT_MAX; - bAnimListElem *ale; const bool include_handles = RNA_boolean_get(op->ptr, "include_handles"); bool valid_bounds = false; - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { rctf channel_bounds; const bool found_bounds = get_channel_bounds( &ac, ale, range, include_handles, &channel_bounds); diff --git a/source/blender/editors/animation/anim_deps.cc b/source/blender/editors/animation/anim_deps.cc index 985d9ed24b6..9ce76e094a8 100644 --- a/source/blender/editors/animation/anim_deps.cc +++ b/source/blender/editors/animation/anim_deps.cc @@ -257,7 +257,6 @@ void ANIM_sync_animchannels_to_data(const bContext *C) { bAnimContext ac; ListBase anim_data = {nullptr, nullptr}; - bAnimListElem *ale; int filter; bActionGroup *active_agrp = nullptr; @@ -278,7 +277,7 @@ void ANIM_sync_animchannels_to_data(const bContext *C) &ac, &anim_data, eAnimFilter_Flags(filter), ac.data, eAnimCont_Types(ac.datatype)); /* flush settings as appropriate depending on the types of the channels */ - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { switch (ale->type) { case ANIMTYPE_GROUP: animchan_sync_group(&ac, ale, &active_agrp); @@ -309,9 +308,7 @@ void ANIM_sync_animchannels_to_data(const bContext *C) void ANIM_animdata_update(bAnimContext *ac, ListBase *anim_data) { - bAnimListElem *ale; - - for (ale = static_cast(anim_data->first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, anim_data) { if (ale->type == ANIMTYPE_GPLAYER) { bGPDlayer *gpl = static_cast(ale->data); diff --git a/source/blender/editors/animation/anim_markers.cc b/source/blender/editors/animation/anim_markers.cc index 79b29d34178..f9b58cbd2ef 100644 --- a/source/blender/editors/animation/anim_markers.cc +++ b/source/blender/editors/animation/anim_markers.cc @@ -105,7 +105,6 @@ ListBase *ED_animcontext_get_markers(const bAnimContext *ac) int ED_markers_post_apply_transform( ListBase *markers, Scene *scene, int mode, float value, char side) { - TimeMarker *marker; float cfra = float(scene->r.cfra); int changed_tot = 0; @@ -115,7 +114,7 @@ int ED_markers_post_apply_transform( } /* affect selected markers - it's unlikely that we will want to affect all in this way? */ - for (marker = static_cast(markers->first); marker; marker = marker->next) { + LISTBASE_FOREACH (TimeMarker *, marker, markers) { if (marker->flag & SELECT) { switch (mode) { case TFM_TIME_TRANSLATE: @@ -146,11 +145,11 @@ int ED_markers_post_apply_transform( TimeMarker *ED_markers_find_nearest_marker(ListBase *markers, float x) { - TimeMarker *marker, *nearest = nullptr; + TimeMarker *nearest = nullptr; float dist, min_dist = 1000000; if (markers) { - for (marker = static_cast(markers->first); marker; marker = marker->next) { + LISTBASE_FOREACH (TimeMarker *, marker, markers) { dist = fabsf(float(marker->frame) - x); if (dist < min_dist) { @@ -171,7 +170,6 @@ int ED_markers_find_nearest_marker_time(ListBase *markers, float x) void ED_markers_get_minmax(ListBase *markers, short sel, float *r_first, float *r_last) { - TimeMarker *marker; float min, max; /* sanity check */ @@ -184,7 +182,7 @@ void ED_markers_get_minmax(ListBase *markers, short sel, float *r_first, float * min = FLT_MAX; max = -FLT_MAX; - for (marker = static_cast(markers->first); marker; marker = marker->next) { + LISTBASE_FOREACH (TimeMarker *, marker, markers) { if (!sel || (marker->flag & SELECT)) { if (marker->frame < min) { min = float(marker->frame); @@ -298,8 +296,6 @@ static void add_marker_to_cfra_elem(ListBase *lb, TimeMarker *marker, short only void ED_markers_make_cfra_list(ListBase *markers, ListBase *lb, short only_sel) { - TimeMarker *marker; - if (lb) { /* Clear the list first, since callers have no way of knowing * whether this terminated early otherwise. This may lead @@ -315,7 +311,7 @@ void ED_markers_make_cfra_list(ListBase *markers, ListBase *lb, short only_sel) return; } - for (marker = static_cast(markers->first); marker; marker = marker->next) { + LISTBASE_FOREACH (TimeMarker *, marker, markers) { add_marker_to_cfra_elem(lb, marker, only_sel); } } @@ -346,10 +342,8 @@ void ED_markers_deselect_all(ListBase *markers, int action) TimeMarker *ED_markers_get_first_selected(ListBase *markers) { - TimeMarker *marker; - if (markers) { - for (marker = static_cast(markers->first); marker; marker = marker->next) { + LISTBASE_FOREACH (TimeMarker *, marker, markers) { if (marker->flag & SELECT) { return marker; } @@ -365,9 +359,6 @@ void debug_markers_print_list(ListBase *markers) { /* NOTE: do NOT make static or use `ifdef`'s as "unused code". * That's too much trouble when we need to use for quick debugging! */ - - TimeMarker *marker; - if (markers == nullptr) { printf("No markers list to print debug for\n"); return; @@ -375,7 +366,7 @@ void debug_markers_print_list(ListBase *markers) printf("List of markers follows: -----\n"); - for (marker = static_cast(markers->first); marker; marker = marker->next) { + LISTBASE_FOREACH (TimeMarker *, marker, markers) { printf( "\t'%s' on %d at %p with %u\n", marker->name, marker->frame, (void *)marker, marker->flag); } @@ -737,14 +728,14 @@ static int ed_marker_add_exec(bContext *C, wmOperator * /*op*/) /* prefer not having 2 markers at the same place, * though the user can move them to overlap once added */ - for (marker = static_cast(markers->first); marker; marker = marker->next) { + LISTBASE_FOREACH (TimeMarker *, marker, markers) { if (marker->frame == frame) { return OPERATOR_CANCELLED; } } /* deselect all */ - for (marker = static_cast(markers->first); marker; marker = marker->next) { + LISTBASE_FOREACH (TimeMarker *, marker, markers) { marker->flag &= ~SELECT; } @@ -1165,8 +1156,6 @@ static void MARKER_OT_move(wmOperatorType *ot) static void ed_marker_duplicate_apply(bContext *C) { ListBase *markers = ED_context_get_markers(C); - TimeMarker *marker, *newmarker; - if (markers == nullptr) { return; } @@ -1174,13 +1163,14 @@ static void ed_marker_duplicate_apply(bContext *C) /* go through the list of markers, duplicate selected markers and add duplicated copies * to the beginning of the list (unselect original markers) */ - for (marker = static_cast(markers->first); marker; marker = marker->next) { + LISTBASE_FOREACH (TimeMarker *, marker, markers) { if (marker->flag & SELECT) { /* unselect selected marker */ marker->flag &= ~SELECT; /* create and set up new marker */ - newmarker = static_cast(MEM_callocN(sizeof(TimeMarker), "TimeMarker")); + TimeMarker *newmarker = static_cast( + MEM_callocN(sizeof(TimeMarker), "TimeMarker")); newmarker->flag = SELECT; newmarker->frame = marker->frame; STRNCPY(newmarker->name, marker->name); @@ -1263,7 +1253,7 @@ static int select_timeline_marker_frame(ListBase *markers, } /* support for selection cycling */ - for (marker = static_cast(markers->first); marker; marker = marker->next) { + LISTBASE_FOREACH (TimeMarker *, marker, markers) { if (marker->frame == frame) { if (marker->flag & SELECT) { marker_cycle_selected = static_cast(marker->next ? marker->next : @@ -1304,14 +1294,13 @@ static void select_marker_camera_switch( Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); Base *base; - TimeMarker *marker; int sel = 0; if (!extend) { BKE_view_layer_base_deselect_all(scene, view_layer); } - for (marker = static_cast(markers->first); marker; marker = marker->next) { + LISTBASE_FOREACH (TimeMarker *, marker, markers) { if (marker->frame == cfra) { sel = (marker->flag & SELECT); break; @@ -1319,7 +1308,7 @@ static void select_marker_camera_switch( } BKE_view_layer_synced_ensure(scene, view_layer); - for (marker = static_cast(markers->first); marker; marker = marker->next) { + LISTBASE_FOREACH (TimeMarker *, marker, markers) { if (marker->camera) { if (marker->frame == cfra) { base = BKE_view_layer_base_find(view_layer, marker->camera); @@ -1766,7 +1755,7 @@ static int ed_marker_make_links_scene_exec(bContext *C, wmOperator *op) ListBase *markers = ED_context_get_markers(C); Scene *scene_to = static_cast( BLI_findlink(&bmain->scenes, RNA_enum_get(op->ptr, "scene"))); - TimeMarker *marker, *marker_new; + TimeMarker *marker_new; if (scene_to == nullptr) { BKE_report(op->reports, RPT_ERROR, "Scene not found"); @@ -1784,7 +1773,7 @@ static int ed_marker_make_links_scene_exec(bContext *C, wmOperator *op) } /* copy markers */ - for (marker = static_cast(markers->first); marker; marker = marker->next) { + LISTBASE_FOREACH (TimeMarker *, marker, markers) { if (marker->flag & SELECT) { marker_new = static_cast(MEM_dupallocN(marker)); marker_new->prev = marker_new->next = nullptr; diff --git a/source/blender/editors/animation/anim_motion_paths.cc b/source/blender/editors/animation/anim_motion_paths.cc index ba32d91eb4d..4863222d250 100644 --- a/source/blender/editors/animation/anim_motion_paths.cc +++ b/source/blender/editors/animation/anim_motion_paths.cc @@ -110,10 +110,7 @@ void animviz_get_object_motionpaths(Object *ob, ListBase *targets) /* bones */ if ((ob->pose) && (ob->pose->avs.recalc & ANIMVIZ_RECALC_PATHS)) { bArmature *arm = static_cast(ob->data); - bPoseChannel *pchan; - - for (pchan = static_cast(ob->pose->chanbase.first); pchan; pchan = pchan->next) - { + LISTBASE_FOREACH (bPoseChannel *, pchan, &ob->pose->chanbase) { if ((pchan->bone) && ANIM_bonecoll_is_visible_pchan(arm, pchan) && (pchan->mpath)) { /* new target for bone */ mpt = static_cast(MEM_callocN(sizeof(MPathTarget), "MPathTarget PoseBone")); @@ -132,10 +129,8 @@ void animviz_get_object_motionpaths(Object *ob, ListBase *targets) /* perform baking for the targets on the current frame */ static void motionpaths_calc_bake_targets(ListBase *targets, int cframe) { - MPathTarget *mpt; - /* for each target, check if it can be baked on the current frame */ - for (mpt = static_cast(targets->first); mpt; mpt = mpt->next) { + LISTBASE_FOREACH (MPathTarget *, mpt, targets) { bMotionPath *mpath = mpt->mpath; /* current frame must be within the range the cache works for diff --git a/source/blender/editors/animation/fmodifier_ui.cc b/source/blender/editors/animation/fmodifier_ui.cc index f54d5302334..02311289a26 100644 --- a/source/blender/editors/animation/fmodifier_ui.cc +++ b/source/blender/editors/animation/fmodifier_ui.cc @@ -884,7 +884,7 @@ void ANIM_fmodifier_panels(const bContext *C, if (!panels_match) { UI_panels_free_instanced(C, region); - for (FModifier *fcm = static_cast(fmodifiers->first); fcm; fcm = fcm->next) { + LISTBASE_FOREACH (FModifier *, fcm, fmodifiers) { char panel_idname[MAX_NAME]; panel_id_fn(fcm, panel_idname); @@ -987,7 +987,6 @@ bool ANIM_fmodifiers_copy_to_buf(ListBase *modifiers, bool active) bool ANIM_fmodifiers_paste_from_buf(ListBase *modifiers, bool replace, FCurve *curve) { - FModifier *fcm; bool ok = false; /* sanity checks */ @@ -1003,7 +1002,7 @@ bool ANIM_fmodifiers_paste_from_buf(ListBase *modifiers, bool replace, FCurve *c } /* now copy over all the modifiers in the buffer to the end of the list */ - for (fcm = static_cast(fmodifier_copypaste_buf.first); fcm; fcm = fcm->next) { + LISTBASE_FOREACH (FModifier *, fcm, &fmodifier_copypaste_buf) { /* make a copy of it */ FModifier *fcmN = copy_fmodifier(fcm); diff --git a/source/blender/editors/animation/keyframes_general.cc b/source/blender/editors/animation/keyframes_general.cc index 84a01521eac..2a5690bd6cd 100644 --- a/source/blender/editors/animation/keyframes_general.cc +++ b/source/blender/editors/animation/keyframes_general.cc @@ -1095,14 +1095,13 @@ void ANIM_fcurves_copybuf_free() short copy_animedit_keys(bAnimContext *ac, ListBase *anim_data) { - bAnimListElem *ale; Scene *scene = ac->scene; /* clear buffer first */ ANIM_fcurves_copybuf_free(); /* assume that each of these is an F-Curve */ - for (ale = static_cast(anim_data->first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, anim_data) { FCurve *fcu = (FCurve *)ale->key_data; tAnimCopybufItem *aci; BezTriple *bezt, *nbezt, *newbuf; @@ -1630,7 +1629,7 @@ eKeyPasteError paste_animedit_keys(bAnimContext *ac, for (pass = 0; pass < 3; pass++) { uint totmatch = 0; - for (ale = static_cast(anim_data->first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, anim_data) { /* Find buffer item to paste from: * - If names don't matter (i.e. only 1 channel in buffer), don't check id/group * - If names do matter, only check if id-type is ok for now diff --git a/source/blender/editors/animation/keyframing.cc b/source/blender/editors/animation/keyframing.cc index 51e0fb3bacd..6a21973c56c 100644 --- a/source/blender/editors/animation/keyframing.cc +++ b/source/blender/editors/animation/keyframing.cc @@ -2973,8 +2973,6 @@ bool fcurve_is_changed(PointerRNA ptr, */ static bool action_frame_has_keyframe(bAction *act, float frame) { - FCurve *fcu; - /* can only find if there is data */ if (act == nullptr) { return false; @@ -2987,7 +2985,7 @@ static bool action_frame_has_keyframe(bAction *act, float frame) /* loop over F-Curves, using binary-search to try to find matches * - this assumes that keyframes are only beztriples */ - for (fcu = static_cast(act->curves.first); fcu; fcu = fcu->next) { + LISTBASE_FOREACH (FCurve *, fcu, &act->curves) { /* only check if there are keyframes (currently only of type BezTriple) */ if (fcu->bezt && fcu->totvert) { if (fcurve_frame_has_keyframe(fcu, frame)) { diff --git a/source/blender/editors/animation/keyingsets.cc b/source/blender/editors/animation/keyingsets.cc index 5cda1ae301e..f01448f941f 100644 --- a/source/blender/editors/animation/keyingsets.cc +++ b/source/blender/editors/animation/keyingsets.cc @@ -724,7 +724,6 @@ static void anim_keyingset_visit_for_search_impl(const bContext *C, } Scene *scene = C ? CTX_data_scene(C) : nullptr; - KeyingSet *ks; /* Active Keying Set. */ if (!use_poll || (scene && scene->active_keyingset)) { @@ -736,7 +735,7 @@ static void anim_keyingset_visit_for_search_impl(const bContext *C, /* User-defined Keying Sets. */ if (scene && scene->keyingsets.first) { - for (ks = static_cast(scene->keyingsets.first); ks; ks = ks->next) { + LISTBASE_FOREACH (KeyingSet *, ks, &scene->keyingsets) { if (use_poll && !ANIM_keyingset_context_ok_poll((bContext *)C, ks)) { continue; } @@ -748,7 +747,7 @@ static void anim_keyingset_visit_for_search_impl(const bContext *C, } /* Builtin Keying Sets. */ - for (ks = static_cast(builtin_keyingsets.first); ks; ks = ks->next) { + LISTBASE_FOREACH (KeyingSet *, ks, &builtin_keyingsets) { if (use_poll && !ANIM_keyingset_context_ok_poll((bContext *)C, ks)) { continue; } @@ -920,9 +919,7 @@ static void RKS_ITER_overrides_list(KeyingSetInfo *ksi, KeyingSet *ks, ListBase *dsources) { - tRKS_DSource *ds; - - for (ds = static_cast(dsources->first); ds; ds = ds->next) { + LISTBASE_FOREACH (tRKS_DSource *, ds, dsources) { /* run generate callback on this data */ ksi->generate(ksi, C, ks, &ds->ptr); } @@ -1048,7 +1045,6 @@ int ANIM_apply_keyingset( Main *bmain = CTX_data_main(C); Scene *scene = CTX_data_scene(C); ReportList *reports = CTX_wm_reports(C); - KS_Path *ksp; ListBase nla_cache = {nullptr, nullptr}; const eInsertKeyFlags base_kflags = ANIM_get_keyframing_flags(scene, true); const char *groupname = nullptr; @@ -1082,7 +1078,7 @@ int ANIM_apply_keyingset( } /* apply the paths as specified in the KeyingSet now */ - for (ksp = static_cast(ks->paths.first); ksp; ksp = ksp->next) { + LISTBASE_FOREACH (KS_Path *, ksp, &ks->paths) { int arraylen, i; eInsertKeyFlags kflag2; diff --git a/source/blender/editors/armature/armature_add.cc b/source/blender/editors/armature/armature_add.cc index c437a80fb77..26f49bf2973 100644 --- a/source/blender/editors/armature/armature_add.cc +++ b/source/blender/editors/armature/armature_add.cc @@ -273,10 +273,8 @@ EditBone *add_points_bone(Object *obedit, float head[3], float tail[3]) static EditBone *get_named_editbone(ListBase *edbo, const char *name) { - EditBone *eBone; - if (name) { - for (eBone = static_cast(edbo->first); eBone; eBone = eBone->next) { + LISTBASE_FOREACH (EditBone *, eBone, edbo) { if (STREQ(name, eBone->name)) { return eBone; } @@ -376,20 +374,18 @@ static void updateDuplicateSubtarget(EditBone *dup_bone, */ EditBone *oldtarget, *newtarget; bPoseChannel *pchan; - bConstraint *curcon; ListBase *conlist; if ((pchan = BKE_pose_channel_ensure(ob->pose, dup_bone->name))) { if ((conlist = &pchan->constraints)) { - for (curcon = static_cast(conlist->first); curcon; curcon = curcon->next) { + LISTBASE_FOREACH (bConstraint *, curcon, conlist) { /* does this constraint have a subtarget in * this armature? */ ListBase targets = {nullptr, nullptr}; - bConstraintTarget *ct; if (BKE_constraint_targets_get(curcon, &targets)) { - for (ct = static_cast(targets.first); ct; ct = ct->next) { + LISTBASE_FOREACH (bConstraintTarget *, ct, &targets) { if ((ct->tar == ob) && (ct->subtarget[0])) { oldtarget = get_named_editbone(editbones, ct->subtarget); if (oldtarget) { @@ -504,7 +500,7 @@ static void updateDuplicateActionConstraintSettings( BKE_fcurves_filter(&ani_curves, &act->curves, "pose.bones[", orig_bone->name)) { /* Create a copy and mirror the animation */ - for (LinkData *ld = static_cast(ani_curves.first); ld; ld = ld->next) { + LISTBASE_FOREACH (LinkData *, ld, &ani_curves) { FCurve *old_curve = static_cast(ld->data); FCurve *new_curve = BKE_fcurve_copy(old_curve); bActionGroup *agrp; @@ -829,7 +825,6 @@ static void updateDuplicateConstraintSettings(EditBone *dup_bone, EditBone *orig * subtarget they point to has also been duplicated. */ bPoseChannel *pchan; - bConstraint *curcon; ListBase *conlist; if ((pchan = BKE_pose_channel_ensure(ob->pose, dup_bone->name)) == nullptr || @@ -838,7 +833,7 @@ static void updateDuplicateConstraintSettings(EditBone *dup_bone, EditBone *orig return; } - for (curcon = static_cast(conlist->first); curcon; curcon = curcon->next) { + LISTBASE_FOREACH (bConstraint *, curcon, conlist) { switch (curcon->type) { case CONSTRAINT_TYPE_ACTION: updateDuplicateActionConstraintSettings(dup_bone, orig_bone, ob, pchan, curcon); @@ -977,9 +972,7 @@ static int armature_duplicate_selected_exec(bContext *C, wmOperator *op) /* Select mirrored bones */ if (arm->flag & ARM_MIRROR_EDIT) { - for (ebone_iter = static_cast(arm->edbo->first); ebone_iter; - ebone_iter = ebone_iter->next) - { + LISTBASE_FOREACH (EditBone *, ebone_iter, arm->edbo) { if (EBONE_VISIBLE(arm, ebone_iter) && (ebone_iter->flag & BONE_SELECTED)) { EditBone *ebone; @@ -1162,9 +1155,7 @@ static int armature_symmetrize_exec(bContext *C, wmOperator *op) * and unique selected bones with an unique flippable name. * * Storing temp pointers to mirrored unselected ebones. */ - for (ebone_iter = static_cast(arm->edbo->first); ebone_iter; - ebone_iter = ebone_iter->next) - { + LISTBASE_FOREACH (EditBone *, ebone_iter, arm->edbo) { if (!(EBONE_VISIBLE(arm, ebone_iter) && (ebone_iter->flag & BONE_SELECTED))) { /* Skipping invisible selected bones. */ continue; @@ -1430,7 +1421,7 @@ static int armature_extrude_exec(bContext *C, wmOperator *op) ExtrudePoint do_extrude; /* since we allow root extrude too, we have to make sure selection is OK */ - for (ebone = static_cast(arm->edbo->first); ebone; ebone = ebone->next) { + LISTBASE_FOREACH (EditBone *, ebone, arm->edbo) { if (EBONE_VISIBLE(arm, ebone)) { if (ebone->flag & BONE_ROOTSEL) { if (ebone->parent && (ebone->flag & BONE_CONNECTED)) { @@ -1694,7 +1685,7 @@ void ARMATURE_OT_bone_primitive_add(wmOperatorType *ot) static int armature_subdivide_exec(bContext *C, wmOperator *op) { Object *obedit = CTX_data_edit_object(C); - EditBone *newbone, *tbone; + EditBone *newbone; int cuts, i; /* there may not be a number_cuts property defined (for 'simple' subdivide) */ @@ -1739,7 +1730,7 @@ static int armature_subdivide_exec(bContext *C, wmOperator *op) ED_armature_ebone_unique_name(arm->edbo, newbone->name, nullptr); /* correct parent bones */ - for (tbone = static_cast(arm->edbo->first); tbone; tbone = tbone->next) { + LISTBASE_FOREACH (EditBone *, tbone, arm->edbo) { if (tbone->parent == ebone) { tbone->parent = newbone; } diff --git a/source/blender/editors/armature/armature_edit.cc b/source/blender/editors/armature/armature_edit.cc index 9b233cb0f9a..1bee852cc97 100644 --- a/source/blender/editors/armature/armature_edit.cc +++ b/source/blender/editors/armature/armature_edit.cc @@ -55,14 +55,13 @@ void ED_armature_edit_transform(bArmature *arm, const float mat[4][4], const bool do_props) { - EditBone *ebone; float scale = mat4_to_scale(mat); /* store the scale of the matrix here to use on envelopes */ float mat3[3][3]; copy_m3_m4(mat3, mat); normalize_m3(mat3); /* Do the rotations */ - for (ebone = static_cast(arm->edbo->first); ebone; ebone = ebone->next) { + LISTBASE_FOREACH (EditBone *, ebone, arm->edbo) { float tmat[3][3]; /* find the current bone's roll matrix */ @@ -104,7 +103,6 @@ void ED_armature_origin_set( Main *bmain, Object *ob, const float cursor[3], int centermode, int around) { const bool is_editmode = BKE_object_is_in_editmode(ob); - EditBone *ebone; bArmature *arm = static_cast(ob->data); float cent[3]; @@ -123,7 +121,7 @@ void ED_armature_origin_set( if (around == V3D_AROUND_CENTER_BOUNDS) { float min[3], max[3]; INIT_MINMAX(min, max); - for (ebone = static_cast(arm->edbo->first); ebone; ebone = ebone->next) { + LISTBASE_FOREACH (EditBone *, ebone, arm->edbo) { minmax_v3v3_v3(min, max, ebone->head); minmax_v3v3_v3(min, max, ebone->tail); } @@ -132,7 +130,7 @@ void ED_armature_origin_set( else { /* #V3D_AROUND_CENTER_MEDIAN. */ int total = 0; zero_v3(cent); - for (ebone = static_cast(arm->edbo->first); ebone; ebone = ebone->next) { + LISTBASE_FOREACH (EditBone *, ebone, arm->edbo) { total += 2; add_v3_v3(cent, ebone->head); add_v3_v3(cent, ebone->tail); @@ -144,7 +142,7 @@ void ED_armature_origin_set( } /* Do the adjustments */ - for (ebone = static_cast(arm->edbo->first); ebone; ebone = ebone->next) { + LISTBASE_FOREACH (EditBone *, ebone, arm->edbo) { sub_v3_v3(ebone->head, cent); sub_v3_v3(ebone->tail, cent); } @@ -297,7 +295,7 @@ static int armature_calc_roll_exec(bContext *C, wmOperator *op) mul_m4_v3(ob->world_to_object, cursor_local); /* cursor */ - for (ebone = static_cast(arm->edbo->first); ebone; ebone = ebone->next) { + LISTBASE_FOREACH (EditBone *, ebone, arm->edbo) { if (EBONE_VISIBLE(arm, ebone) && EBONE_EDITABLE(ebone)) { float cursor_rel[3]; sub_v3_v3v3(cursor_rel, cursor_local, ebone->head); @@ -312,7 +310,7 @@ static int armature_calc_roll_exec(bContext *C, wmOperator *op) } } else if (ELEM(type, CALC_ROLL_TAN_POS_X, CALC_ROLL_TAN_POS_Z)) { - for (ebone = static_cast(arm->edbo->first); ebone; ebone = ebone->next) { + LISTBASE_FOREACH (EditBone *, ebone, arm->edbo) { if (ebone->parent) { bool is_edit = (EBONE_VISIBLE(arm, ebone) && EBONE_EDITABLE(ebone)); bool is_edit_parent = (EBONE_VISIBLE(arm, ebone->parent) && @@ -411,7 +409,7 @@ static int armature_calc_roll_exec(bContext *C, wmOperator *op) negate_v3(vec); } - for (ebone = static_cast(arm->edbo->first); ebone; ebone = ebone->next) { + LISTBASE_FOREACH (EditBone *, ebone, arm->edbo) { if (EBONE_VISIBLE(arm, ebone) && EBONE_EDITABLE(ebone)) { /* roll func is a callback which assumes that all is well */ ebone->roll = ED_armature_ebone_roll_to_vector(ebone, vec, axis_only); @@ -421,7 +419,7 @@ static int armature_calc_roll_exec(bContext *C, wmOperator *op) } if (arm->flag & ARM_MIRROR_EDIT) { - for (ebone = static_cast(arm->edbo->first); ebone; ebone = ebone->next) { + LISTBASE_FOREACH (EditBone *, ebone, arm->edbo) { if ((EBONE_VISIBLE(arm, ebone) && EBONE_EDITABLE(ebone)) == 0) { EditBone *ebone_mirr = ED_armature_ebone_get_mirrored(arm->edbo, ebone); if (ebone_mirr && (EBONE_VISIBLE(arm, ebone_mirr) && EBONE_EDITABLE(ebone_mirr))) { @@ -558,15 +556,15 @@ struct EditBonePoint { /* find chain-tips (i.e. bones without children) */ static void chains_find_tips(ListBase *edbo, ListBase *list) { - EditBone *curBone, *ebo; + EditBone *ebo; LinkData *ld; /* NOTE: this is potentially very slow ... there's got to be a better way. */ - for (curBone = static_cast(edbo->first); curBone; curBone = curBone->next) { + LISTBASE_FOREACH (EditBone *, curBone, edbo) { short stop = 0; /* is this bone contained within any existing chain? (skip if so) */ - for (ld = static_cast(list->first); ld; ld = ld->next) { + LISTBASE_FOREACH (LinkData *, ld, list) { for (ebo = static_cast(ld->data); ebo; ebo = ebo->parent) { if (ebo == curBone) { stop = 1; @@ -586,7 +584,7 @@ static void chains_find_tips(ListBase *edbo, ListBase *list) /* is any existing chain part of the chain formed by this bone? */ stop = 0; for (ebo = curBone->parent; ebo; ebo = ebo->parent) { - for (ld = static_cast(list->first); ld; ld = ld->next) { + LISTBASE_FOREACH (LinkData *, ld, list) { if (ld->data == ebo) { ld->data = curBone; stop = 1; @@ -629,7 +627,7 @@ static void fill_add_joint(EditBone *ebo, short eb_tail, ListBase *points) copy_v3_v3(vec, ebo->head); } - for (ebp = static_cast(points->first); ebp; ebp = ebp->next) { + LISTBASE_FOREACH (EditBonePoint *, ebp, points) { if (equals_v3v3(ebp->vec, vec)) { if (eb_tail) { if ((ebp->head_owner) && (ebp->head_owner->parent == ebo)) { @@ -884,9 +882,7 @@ void ARMATURE_OT_fill(wmOperatorType *ot) /* helper to clear BONE_TRANSFORM flags */ static void armature_clear_swap_done_flags(bArmature *arm) { - EditBone *ebone; - - for (ebone = static_cast(arm->edbo->first); ebone; ebone = ebone->next) { + LISTBASE_FOREACH (EditBone *, ebone, arm->edbo) { ebone->flag &= ~BONE_TRANSFORM; } } @@ -904,7 +900,6 @@ static int armature_switch_direction_exec(bContext *C, wmOperator * /*op*/) bArmature *arm = static_cast(ob->data); ListBase chains = {nullptr, nullptr}; - LinkData *chain; /* get chains of bones (ends on chains) */ chains_find_tips(arm->edbo, &chains); @@ -922,7 +917,7 @@ static int armature_switch_direction_exec(bContext *C, wmOperator * /*op*/) armature_clear_swap_done_flags(arm); /* loop over chains, only considering selected and visible bones */ - for (chain = static_cast(chains.first); chain; chain = chain->next) { + LISTBASE_FOREACH (LinkData *, chain, &chains) { EditBone *ebo, *child = nullptr, *parent = nullptr; /* loop over bones in chain */ @@ -1036,9 +1031,7 @@ static void fix_connected_bone(EditBone *ebone) /* helper to recursively find chains of connected bones starting at ebone and fix their position */ static void fix_editbone_connected_children(ListBase *edbo, EditBone *ebone) { - EditBone *selbone; - - for (selbone = static_cast(edbo->first); selbone; selbone = selbone->next) { + LISTBASE_FOREACH (EditBone *, selbone, edbo) { if ((selbone->parent) && (selbone->parent == ebone) && (selbone->flag & BONE_CONNECTED)) { fix_connected_bone(selbone); fix_editbone_connected_children(edbo, selbone); @@ -1330,7 +1323,7 @@ static int armature_dissolve_selected_exec(bContext *C, wmOperator * /*op*/) GHash *ebone_flag_orig = nullptr; int ebone_num = 0; - for (ebone = static_cast(arm->edbo->first); ebone; ebone = ebone->next) { + LISTBASE_FOREACH (EditBone *, ebone, arm->edbo) { ebone->temp.p = nullptr; ebone->flag &= ~BONE_DONE; ebone_num++; @@ -1340,7 +1333,7 @@ static int armature_dissolve_selected_exec(bContext *C, wmOperator * /*op*/) GHashIterator gh_iter; ebone_flag_orig = BLI_ghash_ptr_new_ex(__func__, ebone_num); - for (ebone = static_cast(arm->edbo->first); ebone; ebone = ebone->next) { + LISTBASE_FOREACH (EditBone *, ebone, arm->edbo) { union { int flag; void *p; @@ -1361,7 +1354,7 @@ static int armature_dissolve_selected_exec(bContext *C, wmOperator * /*op*/) } } - for (ebone = static_cast(arm->edbo->first); ebone; ebone = ebone->next) { + LISTBASE_FOREACH (EditBone *, ebone, arm->edbo) { if (ebone->parent && ebone->flag & BONE_CONNECTED) { if (ebone->parent->temp.ebone == ebone->parent) { /* ignore */ @@ -1378,13 +1371,13 @@ static int armature_dissolve_selected_exec(bContext *C, wmOperator * /*op*/) } /* cleanup multiple used bones */ - for (ebone = static_cast(arm->edbo->first); ebone; ebone = ebone->next) { + LISTBASE_FOREACH (EditBone *, ebone, arm->edbo) { if (ebone->temp.ebone == ebone) { ebone->temp.ebone = nullptr; } } - for (ebone = static_cast(arm->edbo->first); ebone; ebone = ebone->next) { + LISTBASE_FOREACH (EditBone *, ebone, arm->edbo) { /* break connections for unseen bones */ if ((ANIM_bonecoll_is_visible_editbone(arm, ebone) && (ED_armature_ebone_selectflag_get(ebone) & (BONE_TIPSEL | BONE_SELECTED))) == 0) @@ -1401,7 +1394,7 @@ static int armature_dissolve_selected_exec(bContext *C, wmOperator * /*op*/) } } - for (ebone = static_cast(arm->edbo->first); ebone; ebone = ebone->next) { + LISTBASE_FOREACH (EditBone *, ebone, arm->edbo) { if (ebone->parent && (ebone->parent->temp.ebone == ebone)) { ebone->flag |= BONE_DONE; @@ -1424,14 +1417,14 @@ static int armature_dissolve_selected_exec(bContext *C, wmOperator * /*op*/) } if (changed) { - for (ebone = static_cast(arm->edbo->first); ebone; ebone = ebone->next) { + LISTBASE_FOREACH (EditBone *, ebone, arm->edbo) { if (ebone->parent && ebone->parent->temp.ebone && (ebone->flag & BONE_CONNECTED)) { ebone->rad_head = ebone->parent->rad_tail; } } if (arm->flag & ARM_MIRROR_EDIT) { - for (ebone = static_cast(arm->edbo->first); ebone; ebone = ebone->next) { + LISTBASE_FOREACH (EditBone *, ebone, arm->edbo) { union Value { int flag; void *p; diff --git a/source/blender/editors/armature/armature_naming.cc b/source/blender/editors/armature/armature_naming.cc index 151e5321dc1..9f8d839640a 100644 --- a/source/blender/editors/armature/armature_naming.cc +++ b/source/blender/editors/armature/armature_naming.cc @@ -106,15 +106,12 @@ static void constraint_bone_name_fix(Object *ob, const char *oldname, const char *newname) { - bConstraint *curcon; - bConstraintTarget *ct; - - for (curcon = static_cast(conlist->first); curcon; curcon = curcon->next) { + LISTBASE_FOREACH (bConstraint *, curcon, conlist) { ListBase targets = {nullptr, nullptr}; /* constraint targets */ if (BKE_constraint_targets_get(curcon, &targets)) { - for (ct = static_cast(targets.first); ct; ct = ct->next) { + LISTBASE_FOREACH (bConstraintTarget *, ct, &targets) { if (ct->tar == ob) { if (STREQ(ct->subtarget, oldname)) { STRNCPY(ct->subtarget, newname); @@ -191,7 +188,6 @@ void ED_armature_bone_rename(Main *bmain, /* do entire dbase - objects */ for (ob = static_cast(bmain->objects.first); ob; ob = static_cast(ob->id.next)) { - ModifierData *md; /* we have the object using the armature */ if (arm == ob->data) { @@ -227,9 +223,7 @@ void ED_armature_bone_rename(Main *bmain, constraint_bone_name_fix(ob, &cob->constraints, oldname, newname); } if (cob->pose) { - bPoseChannel *pchan; - for (pchan = static_cast(cob->pose->chanbase.first); pchan; - pchan = pchan->next) { + LISTBASE_FOREACH (bPoseChannel *, pchan, &cob->pose->chanbase) { constraint_bone_name_fix(ob, &pchan->constraints, oldname, newname); } } @@ -255,7 +249,7 @@ void ED_armature_bone_rename(Main *bmain, } /* fix modifiers that might be using this name */ - for (md = static_cast(ob->modifiers.first); md; md = md->next) { + LISTBASE_FOREACH (ModifierData *, md, &ob->modifiers) { switch (md->type) { case eModifierType_Hook: { HookModifierData *hmd = (HookModifierData *)md; @@ -357,11 +351,9 @@ void ED_armature_bone_rename(Main *bmain, for (screen = static_cast(bmain->screens.first); screen; screen = static_cast(screen->id.next)) { - ScrArea *area; /* add regions */ - for (area = static_cast(screen->areabase.first); area; area = area->next) { - SpaceLink *sl; - for (sl = static_cast(area->spacedata.first); sl; sl = sl->next) { + LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) { + LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) { if (sl->spacetype == SPACE_VIEW3D) { View3D *v3d = (View3D *)sl; if (v3d->ob_center && v3d->ob_center->data == arm) { @@ -422,7 +414,7 @@ void ED_armature_bones_flip_names(Main *bmain, * Note that if the other bone was not selected, its name was not flipped, * so conflict remains and that second rename simply generates a new numbered alternative name. */ - for (bfn = static_cast(bones_names_conflicts.first); bfn; bfn = bfn->next) { + LISTBASE_FOREACH (BoneFlipNameData *, bfn, &bones_names_conflicts) { ED_armature_bone_rename(bmain, arm, bfn->name, bfn->name_flip); } } diff --git a/source/blender/editors/armature/armature_relations.cc b/source/blender/editors/armature/armature_relations.cc index 5dcd822611c..be38c8304b6 100644 --- a/source/blender/editors/armature/armature_relations.cc +++ b/source/blender/editors/armature/armature_relations.cc @@ -65,16 +65,14 @@ static void joined_armature_fix_links_constraints(Main *bmain, EditBone *curbone, ListBase *lb) { - bConstraint *con; bool changed = false; - for (con = static_cast(lb->first); con; con = con->next) { + LISTBASE_FOREACH (bConstraint *, con, lb) { ListBase targets = {nullptr, nullptr}; - bConstraintTarget *ct; /* constraint targets */ if (BKE_constraint_targets_get(con, &targets)) { - for (ct = static_cast(targets.first); ct; ct = ct->next) { + LISTBASE_FOREACH (bConstraintTarget *, ct, &targets) { if (ct->tar == srcArm) { if (ct->subtarget[0] == '\0') { ct->tar = tarArm; @@ -158,7 +156,6 @@ static void joined_armature_fix_animdata_cb(ID *id, FCurve *fcu, void *user_data /* Driver targets */ if (fcu->driver) { ChannelDriver *driver = fcu->driver; - DriverVar *dvar; /* Ensure that invalid drivers gets re-evaluated in case they become valid once the join * operation is finished. */ @@ -166,7 +163,7 @@ static void joined_armature_fix_animdata_cb(ID *id, FCurve *fcu, void *user_data driver->flag &= ~DRIVER_FLAG_INVALID; /* Fix driver references to invalid ID's */ - for (dvar = static_cast(driver->variables.first); dvar; dvar = dvar->next) { + LISTBASE_FOREACH (DriverVar *, dvar, &driver->variables) { /* only change the used targets, since the others will need fixing manually anyway */ DRIVER_TARGETS_USED_LOOPER_BEGIN (dvar) { /* change the ID's used... */ @@ -218,7 +215,6 @@ static void joined_armature_fix_links( { Object *ob; bPose *pose; - bPoseChannel *pchant; /* let's go through all objects in database */ for (ob = static_cast(bmain->objects.first); ob; @@ -226,8 +222,7 @@ static void joined_armature_fix_links( /* do some object-type specific things */ if (ob->type == OB_ARMATURE) { pose = ob->pose; - for (pchant = static_cast(pose->chanbase.first); pchant; - pchant = pchant->next) { + LISTBASE_FOREACH (bPoseChannel *, pchant, &pose->chanbase) { joined_armature_fix_links_constraints( bmain, ob, tarArm, srcArm, pchan, curbone, &pchant->constraints); } @@ -449,8 +444,6 @@ int ED_armature_join_objects_exec(bContext *C, wmOperator *op) static void separated_armature_fix_links(Main *bmain, Object *origArm, Object *newArm) { Object *ob; - bPoseChannel *pchan; - bConstraint *con; ListBase *opchans, *npchans; /* Get reference to list of bones in original and new armatures. */ @@ -462,15 +455,13 @@ static void separated_armature_fix_links(Main *bmain, Object *origArm, Object *n ob = static_cast(ob->id.next)) { /* do some object-type specific things */ if (ob->type == OB_ARMATURE) { - for (pchan = static_cast(ob->pose->chanbase.first); pchan; - pchan = pchan->next) { - for (con = static_cast(pchan->constraints.first); con; con = con->next) { + LISTBASE_FOREACH (bPoseChannel *, pchan, &ob->pose->chanbase) { + LISTBASE_FOREACH (bConstraint *, con, &pchan->constraints) { ListBase targets = {nullptr, nullptr}; - bConstraintTarget *ct; /* constraint targets */ if (BKE_constraint_targets_get(con, &targets)) { - for (ct = static_cast(targets.first); ct; ct = ct->next) { + LISTBASE_FOREACH (bConstraintTarget *, ct, &targets) { /* Any targets which point to original armature * are redirected to the new one only if: * - The target isn't origArm/newArm itself. @@ -498,13 +489,12 @@ static void separated_armature_fix_links(Main *bmain, Object *origArm, Object *n /* fix object-level constraints */ if (ob != origArm) { - for (con = static_cast(ob->constraints.first); con; con = con->next) { + LISTBASE_FOREACH (bConstraint *, con, &ob->constraints) { ListBase targets = {nullptr, nullptr}; - bConstraintTarget *ct; /* constraint targets */ if (BKE_constraint_targets_get(con, &targets)) { - for (ct = static_cast(targets.first); ct; ct = ct->next) { + LISTBASE_FOREACH (bConstraintTarget *, ct, &targets) { /* any targets which point to original armature are redirected to the new one only if: * - the target isn't origArm/newArm itself * - the target is one that can be found in newArm/origArm @@ -781,7 +771,7 @@ static void bone_connect_to_new_parent(ListBase *edbo, add_v3_v3(selbone->tail, offset); /* offset for all its children */ - for (ebone = static_cast(edbo->first); ebone; ebone = ebone->next) { + LISTBASE_FOREACH (EditBone *, ebone, edbo) { EditBone *par; for (par = ebone->parent; par; par = par->parent) { diff --git a/source/blender/editors/armature/armature_select.cc b/source/blender/editors/armature/armature_select.cc index 182a2142b85..32639c09ea1 100644 --- a/source/blender/editors/armature/armature_select.cc +++ b/source/blender/editors/armature/armature_select.cc @@ -1464,18 +1464,17 @@ static void armature_select_less(bArmature * /*arm*/, EditBone *ebone) static void armature_select_more_less(Object *ob, bool more) { bArmature *arm = (bArmature *)ob->data; - EditBone *ebone; /* XXX(@ideasman42): eventually we shouldn't need this. */ ED_armature_edit_sync_selection(arm->edbo); /* count bones & store selection state */ - for (ebone = static_cast(arm->edbo->first); ebone; ebone = ebone->next) { + LISTBASE_FOREACH (EditBone *, ebone, arm->edbo) { EBONE_PREV_FLAG_SET(ebone, ED_armature_ebone_selectflag_get(ebone)); } /* do selection */ - for (ebone = static_cast(arm->edbo->first); ebone; ebone = ebone->next) { + LISTBASE_FOREACH (EditBone *, ebone, arm->edbo) { if (EBONE_VISIBLE(arm, ebone)) { if (more) { armature_select_more(arm, ebone); @@ -1486,7 +1485,7 @@ static void armature_select_more_less(Object *ob, bool more) } } - for (ebone = static_cast(arm->edbo->first); ebone; ebone = ebone->next) { + LISTBASE_FOREACH (EditBone *, ebone, arm->edbo) { if (EBONE_VISIBLE(arm, ebone)) { if (more == false) { if (ebone->flag & BONE_SELECTED) { @@ -2047,14 +2046,12 @@ static int armature_select_hierarchy_exec(bContext *C, wmOperator *op) } } else { /* BONE_SELECT_CHILD */ - EditBone *ebone_iter, *ebone_child = nullptr; + EditBone *ebone_child = nullptr; int pass; /* first pass, only connected bones (the logical direct child) */ for (pass = 0; pass < 2 && (ebone_child == nullptr); pass++) { - for (ebone_iter = static_cast(arm->edbo->first); ebone_iter; - ebone_iter = ebone_iter->next) - { + LISTBASE_FOREACH (EditBone *, ebone_iter, arm->edbo) { /* possible we have multiple children, some invisible */ if (EBONE_SELECTABLE(arm, ebone_iter)) { if (ebone_iter->parent == ebone_active) { @@ -2141,14 +2138,14 @@ static int armature_select_mirror_exec(bContext *C, wmOperator *op) Object *ob = objects[ob_index]; bArmature *arm = static_cast(ob->data); - EditBone *ebone, *ebone_mirror_act = nullptr; + EditBone *ebone_mirror_act = nullptr; - for (ebone = static_cast(arm->edbo->first); ebone; ebone = ebone->next) { + LISTBASE_FOREACH (EditBone *, ebone, arm->edbo) { const int flag = ED_armature_ebone_selectflag_get(ebone); EBONE_PREV_FLAG_SET(ebone, flag); } - for (ebone = static_cast(arm->edbo->first); ebone; ebone = ebone->next) { + LISTBASE_FOREACH (EditBone *, ebone, arm->edbo) { if (EBONE_SELECTABLE(arm, ebone)) { EditBone *ebone_mirror; int flag_new = extend ? EBONE_PREV_FLAG_GET(ebone) : 0; diff --git a/source/blender/editors/armature/armature_utils.cc b/source/blender/editors/armature/armature_utils.cc index 966b02ddfde..d8bda7c5805 100644 --- a/source/blender/editors/armature/armature_utils.cc +++ b/source/blender/editors/armature/armature_utils.cc @@ -38,9 +38,7 @@ void ED_armature_edit_sync_selection(ListBase *edbo) { - EditBone *ebo; - - for (ebo = static_cast(edbo->first); ebo; ebo = ebo->next) { + LISTBASE_FOREACH (EditBone *, ebo, edbo) { /* if bone is not selectable, we shouldn't alter this setting... */ if ((ebo->flag & BONE_UNSELECTABLE) == 0) { if ((ebo->flag & BONE_CONNECTED) && (ebo->parent)) { @@ -144,10 +142,8 @@ void bone_free(bArmature *arm, EditBone *bone) void ED_armature_ebone_remove_ex(bArmature *arm, EditBone *exBone, bool clear_connected) { - EditBone *curBone; - /* Find any bones that refer to this bone */ - for (curBone = static_cast(arm->edbo->first); curBone; curBone = curBone->next) { + LISTBASE_FOREACH (EditBone *, curBone, arm->edbo) { if (curBone->parent == exBone) { curBone->parent = exBone->parent; if (clear_connected) { @@ -296,12 +292,10 @@ void armature_select_mirrored_ex(bArmature *arm, const int flag) BLI_assert((flag & ~(BONE_SELECTED | BONE_ROOTSEL | BONE_TIPSEL)) == 0); /* Select mirrored bones */ if (arm->flag & ARM_MIRROR_EDIT) { - EditBone *curBone, *ebone_mirr; - - for (curBone = static_cast(arm->edbo->first); curBone; curBone = curBone->next) { + LISTBASE_FOREACH (EditBone *, curBone, arm->edbo) { if (ANIM_bonecoll_is_visible_editbone(arm, curBone)) { if (curBone->flag & flag) { - ebone_mirr = ED_armature_ebone_get_mirrored(arm->edbo, curBone); + EditBone *ebone_mirr = ED_armature_ebone_get_mirrored(arm->edbo, curBone); if (ebone_mirr) { ebone_mirr->flag |= (curBone->flag & flag); } @@ -318,16 +312,14 @@ void armature_select_mirrored(bArmature *arm) void armature_tag_select_mirrored(bArmature *arm) { - EditBone *curBone; - /* always untag */ - for (curBone = static_cast(arm->edbo->first); curBone; curBone = curBone->next) { + LISTBASE_FOREACH (EditBone *, curBone, arm->edbo) { curBone->flag &= ~BONE_DONE; } /* Select mirrored bones */ if (arm->flag & ARM_MIRROR_EDIT) { - for (curBone = static_cast(arm->edbo->first); curBone; curBone = curBone->next) { + LISTBASE_FOREACH (EditBone *, curBone, arm->edbo) { if (ANIM_bonecoll_is_visible_editbone(arm, curBone)) { if (curBone->flag & (BONE_SELECTED | BONE_ROOTSEL | BONE_TIPSEL)) { EditBone *ebone_mirr = ED_armature_ebone_get_mirrored(arm->edbo, curBone); @@ -338,7 +330,7 @@ void armature_tag_select_mirrored(bArmature *arm) } } - for (curBone = static_cast(arm->edbo->first); curBone; curBone = curBone->next) { + LISTBASE_FOREACH (EditBone *, curBone, arm->edbo) { if (curBone->flag & BONE_DONE) { EditBone *ebone_mirr = ED_armature_ebone_get_mirrored(arm->edbo, curBone); curBone->flag |= ebone_mirr->flag & (BONE_SELECTED | BONE_ROOTSEL | BONE_TIPSEL); @@ -349,9 +341,7 @@ void armature_tag_select_mirrored(bArmature *arm) void armature_tag_unselect(bArmature *arm) { - EditBone *curBone; - - for (curBone = static_cast(arm->edbo->first); curBone; curBone = curBone->next) { + LISTBASE_FOREACH (EditBone *, curBone, arm->edbo) { if (curBone->flag & BONE_DONE) { curBone->flag &= ~(BONE_SELECTED | BONE_ROOTSEL | BONE_TIPSEL | BONE_DONE); } @@ -391,9 +381,7 @@ void ED_armature_ebone_transform_mirror_update(bArmature *arm, EditBone *ebo, bo eboflip->roll2 = -ebo->roll2; /* Also move connected children, in case children's name aren't mirrored properly. */ - EditBone *children; - for (children = static_cast(arm->edbo->first); children; - children = children->next) { + LISTBASE_FOREACH (EditBone *, children, arm->edbo) { if (children->parent == eboflip && children->flag & BONE_CONNECTED) { copy_v3_v3(children->head, eboflip->tail); children->rad_head = ebo->rad_tail; @@ -460,9 +448,8 @@ static EditBone *make_boneList_recursive(ListBase *edbo, EditBone *eBone; EditBone *eBoneAct = nullptr; EditBone *eBoneTest = nullptr; - Bone *curBone; - for (curBone = static_cast(bones->first); curBone; curBone = curBone->next) { + LISTBASE_FOREACH (Bone *, curBone, bones) { eBone = static_cast(MEM_callocN(sizeof(EditBone), "make_editbone")); eBone->temp.bone = curBone; @@ -595,10 +582,7 @@ EditBone *make_boneList(ListBase *edbo, ListBase *bones, Bone *actBone) */ static void armature_finalize_restpose(ListBase *bonelist, ListBase *editbonelist) { - Bone *curBone; - EditBone *ebone; - - for (curBone = static_cast(bonelist->first); curBone; curBone = curBone->next) { + LISTBASE_FOREACH (Bone *, curBone, bonelist) { /* Set bone's local head/tail. * Note that it's important to use final parent's rest-pose (arm_mat) here, * instead of setting those values from edit-bone's matrix (see #46010). */ @@ -624,7 +608,7 @@ static void armature_finalize_restpose(ListBase *bonelist, ListBase *editbonelis BKE_armature_where_is_bone(curBone, curBone->parent, false); /* Find the associated editbone */ - for (ebone = static_cast(editbonelist->first); ebone; ebone = ebone->next) { + LISTBASE_FOREACH (EditBone *, ebone, editbonelist) { if (ebone->temp.bone == curBone) { float premat[3][3]; float postmat[3][3]; @@ -678,10 +662,8 @@ void ED_armature_from_edit(Main *bmain, bArmature *arm) neBone = eBone->next; /* TODO(sergey): How to ensure this is a `constexpr`? */ if (len_sq <= square_f(0.000001f)) { /* FLT_EPSILON is too large? */ - EditBone *fBone; - /* Find any bones that refer to this bone */ - for (fBone = static_cast(arm->edbo->first); fBone; fBone = fBone->next) { + LISTBASE_FOREACH (EditBone *, fBone, arm->edbo) { if (fBone->parent == eBone) { fBone->parent = eBone->parent; } @@ -694,7 +676,7 @@ void ED_armature_from_edit(Main *bmain, bArmature *arm) } /* Copy the bones from the edit-data into the armature. */ - for (eBone = static_cast(arm->edbo->first); eBone; eBone = eBone->next) { + LISTBASE_FOREACH (EditBone *, eBone, arm->edbo) { newBone = static_cast(MEM_callocN(sizeof(Bone), "bone")); eBone->temp.bone = newBone; /* Associate the real Bones with the EditBones */ @@ -754,7 +736,7 @@ void ED_armature_from_edit(Main *bmain, bArmature *arm) * Do not set bone->head/tail here anymore, * using EditBone data for that is not OK since our later fiddling with parent's arm_mat * (for roll conversion) may have some small but visible impact on locations (#46010). */ - for (eBone = static_cast(arm->edbo->first); eBone; eBone = eBone->next) { + LISTBASE_FOREACH (EditBone *, eBone, arm->edbo) { newBone = eBone->temp.bone; if (eBone->parent) { newBone->parent = eBone->parent->temp.bone; @@ -793,12 +775,10 @@ void ED_armature_from_edit(Main *bmain, bArmature *arm) void ED_armature_edit_free(bArmature *arm) { - EditBone *eBone; - /* Clear the edit-bones list. */ if (arm->edbo) { if (arm->edbo->first) { - for (eBone = static_cast(arm->edbo->first); eBone; eBone = eBone->next) { + LISTBASE_FOREACH (EditBone *, eBone, arm->edbo) { if (eBone->prop) { IDP_FreeProperty(eBone->prop); } @@ -844,14 +824,10 @@ void ED_armature_ebone_listbase_free(ListBase *lb, const bool do_id_user) void ED_armature_ebone_listbase_copy(ListBase *lb_dst, ListBase *lb_src, const bool do_id_user) { - EditBone *ebone_src; - EditBone *ebone_dst; - BLI_assert(BLI_listbase_is_empty(lb_dst)); - for (ebone_src = static_cast(lb_src->first); ebone_src; ebone_src = ebone_src->next) - { - ebone_dst = static_cast(MEM_dupallocN(ebone_src)); + LISTBASE_FOREACH (EditBone *, ebone_src, lb_src) { + EditBone *ebone_dst = static_cast(MEM_dupallocN(ebone_src)); if (ebone_dst->prop) { ebone_dst->prop = IDP_CopyProperty_ex(ebone_dst->prop, do_id_user ? 0 : LIB_ID_CREATE_NO_USER_REFCOUNT); @@ -861,8 +837,7 @@ void ED_armature_ebone_listbase_copy(ListBase *lb_dst, ListBase *lb_src, const b } /* set pointers */ - for (ebone_dst = static_cast(lb_dst->first); ebone_dst; ebone_dst = ebone_dst->next) - { + LISTBASE_FOREACH (EditBone *, ebone_dst, lb_dst) { if (ebone_dst->parent) { ebone_dst->parent = ebone_dst->parent->temp.ebone; } @@ -877,9 +852,8 @@ void ED_armature_ebone_listbase_copy(ListBase *lb_dst, ListBase *lb_src, const b void ED_armature_ebone_listbase_temp_clear(ListBase *lb) { - EditBone *ebone; /* be sure they don't hang ever */ - for (ebone = static_cast(lb->first); ebone; ebone = ebone->next) { + LISTBASE_FOREACH (EditBone *, ebone, lb) { ebone->temp.p = nullptr; } } diff --git a/source/blender/editors/armature/pose_edit.cc b/source/blender/editors/armature/pose_edit.cc index 90311ea9de7..cca088d3cbd 100644 --- a/source/blender/editors/armature/pose_edit.cc +++ b/source/blender/editors/armature/pose_edit.cc @@ -384,7 +384,6 @@ void POSE_OT_paths_update(wmOperatorType *ot) /* for the object with pose/action: clear path curves for selected bones only */ static void ED_pose_clear_paths(Object *ob, bool only_selected) { - bPoseChannel *pchan; bool skipped = false; if (ELEM(nullptr, ob, ob->pose)) { @@ -392,7 +391,7 @@ static void ED_pose_clear_paths(Object *ob, bool only_selected) } /* free the motionpath blocks for all bones - This is easier for users to quickly clear all */ - for (pchan = static_cast(ob->pose->chanbase.first); pchan; pchan = pchan->next) { + LISTBASE_FOREACH (bPoseChannel *, pchan, &ob->pose->chanbase) { if (pchan->mpath) { if ((only_selected == false) || ((pchan->bone) && (pchan->bone->flag & BONE_SELECTED))) { animviz_free_motionpath(pchan->mpath); diff --git a/source/blender/editors/armature/pose_group.cc b/source/blender/editors/armature/pose_group.cc index 409723ca12a..a420f6c69a2 100644 --- a/source/blender/editors/armature/pose_group.cc +++ b/source/blender/editors/armature/pose_group.cc @@ -293,7 +293,6 @@ static int group_move_exec(bContext *C, wmOperator *op) { Object *ob = ED_pose_object_from_context(C); bPose *pose = (ob) ? ob->pose : nullptr; - bPoseChannel *pchan; bActionGroup *grp; int dir = RNA_enum_get(op->ptr, "direction"); @@ -317,8 +316,7 @@ static int group_move_exec(bContext *C, wmOperator *op) pose->active_group += dir; /* fix changed bone group indices in bones (swap grpIndexA with grpIndexB) */ - for (pchan = static_cast(ob->pose->chanbase.first); pchan; pchan = pchan->next) - { + LISTBASE_FOREACH (bPoseChannel *, pchan, &ob->pose->chanbase) { if (pchan->agrp_index == grpIndexB) { pchan->agrp_index = grpIndexA; } @@ -381,7 +379,6 @@ static int group_sort_exec(bContext *C, wmOperator * /*op*/) { Object *ob = ED_pose_object_from_context(C); bPose *pose = (ob) ? ob->pose : nullptr; - bPoseChannel *pchan; tSortActionGroup *agrp_array; bActionGroup *agrp; @@ -414,7 +411,7 @@ static int group_sort_exec(bContext *C, wmOperator * /*op*/) } /* Fix changed bone group indices in bones. */ - for (pchan = static_cast(ob->pose->chanbase.first); pchan; pchan = pchan->next) { + LISTBASE_FOREACH (bPoseChannel *, pchan, &ob->pose->chanbase) { for (i = 0; i < agrp_count; i++) { if (pchan->agrp_index == agrp_array[i].index) { pchan->agrp_index = i + 1; diff --git a/source/blender/editors/armature/pose_select.cc b/source/blender/editors/armature/pose_select.cc index 3214c686ad8..dfb4bc61c24 100644 --- a/source/blender/editors/armature/pose_select.cc +++ b/source/blender/editors/armature/pose_select.cc @@ -327,7 +327,6 @@ void ED_armature_pose_select_in_wpaint_mode(const Scene *scene, bool ED_pose_deselect_all(Object *ob, int select_mode, const bool ignore_visibility) { bArmature *arm = static_cast(ob->data); - bPoseChannel *pchan; /* we call this from outliner too */ if (ob->pose == nullptr) { @@ -337,8 +336,7 @@ bool ED_pose_deselect_all(Object *ob, int select_mode, const bool ignore_visibil /* Determine if we're selecting or deselecting */ if (select_mode == SEL_TOGGLE) { select_mode = SEL_SELECT; - for (pchan = static_cast(ob->pose->chanbase.first); pchan; pchan = pchan->next) - { + LISTBASE_FOREACH (bPoseChannel *, pchan, &ob->pose->chanbase) { if (ignore_visibility || PBONE_VISIBLE(arm, pchan->bone)) { if (pchan->bone->flag & BONE_SELECTED) { select_mode = SEL_DESELECT; @@ -350,7 +348,7 @@ bool ED_pose_deselect_all(Object *ob, int select_mode, const bool ignore_visibil /* Set the flags accordingly */ bool changed = false; - for (pchan = static_cast(ob->pose->chanbase.first); pchan; pchan = pchan->next) { + LISTBASE_FOREACH (bPoseChannel *, pchan, &ob->pose->chanbase) { /* ignore the pchan if it isn't visible or if its selection cannot be changed */ if (ignore_visibility || PBONE_VISIBLE(arm, pchan->bone)) { int flag_prev = pchan->bone->flag; @@ -426,8 +424,6 @@ bool ED_pose_deselect_all_multi(bContext *C, int select_mode, const bool ignore_ static void selectconnected_posebonechildren(Object *ob, Bone *bone, int extend) { - Bone *curBone; - /* stop when unconnected child is encountered, or when unselectable bone is encountered */ if (!(bone->flag & BONE_CONNECTED) || (bone->flag & BONE_UNSELECTABLE)) { return; @@ -440,7 +436,7 @@ static void selectconnected_posebonechildren(Object *ob, Bone *bone, int extend) bone->flag |= BONE_SELECTED; } - for (curBone = static_cast(bone->childbase.first); curBone; curBone = curBone->next) { + LISTBASE_FOREACH (Bone *, curBone, &bone->childbase) { selectconnected_posebonechildren(ob, curBone, extend); } } @@ -485,7 +481,7 @@ static int pose_select_connected_invoke(bContext *C, wmOperator *op, const wmEve } /* Select children */ - for (curBone = static_cast(bone->childbase.first); curBone; curBone = curBone->next) { + LISTBASE_FOREACH (Bone *, curBone, &bone->childbase) { selectconnected_posebonechildren(base->object, curBone, extend); } @@ -556,8 +552,7 @@ static int pose_select_linked_exec(bContext *C, wmOperator * /*op*/) } /* Select children */ - for (curBone = static_cast(pchan->bone->childbase.first); curBone; - curBone = curBone->next) { + LISTBASE_FOREACH (Bone *, curBone, &pchan->bone->childbase) { selectconnected_posebonechildren(ob, curBone, false); } ED_pose_bone_select_tag_update(ob); @@ -689,17 +684,14 @@ void POSE_OT_select_parent(wmOperatorType *ot) static int pose_select_constraint_target_exec(bContext *C, wmOperator * /*op*/) { - bConstraint *con; int found = 0; CTX_DATA_BEGIN (C, bPoseChannel *, pchan, visible_pose_bones) { if (pchan->bone->flag & BONE_SELECTED) { - for (con = static_cast(pchan->constraints.first); con; con = con->next) { + LISTBASE_FOREACH (bConstraint *, con, &pchan->constraints) { ListBase targets = {nullptr, nullptr}; - bConstraintTarget *ct; - if (BKE_constraint_targets_get(con, &targets)) { - for (ct = static_cast(targets.first); ct; ct = ct->next) { + LISTBASE_FOREACH (bConstraintTarget *, ct, &targets) { Object *ob = ct->tar; /* Any armature that is also in pose mode should be selected. */ @@ -781,15 +773,12 @@ static int pose_select_hierarchy_exec(bContext *C, wmOperator *op) } } else { /* direction == BONE_SELECT_CHILD */ - bPoseChannel *pchan_iter; Bone *bone_child = nullptr; int pass; /* first pass, only connected bones (the logical direct child) */ for (pass = 0; pass < 2 && (bone_child == nullptr); pass++) { - for (pchan_iter = static_cast(ob->pose->chanbase.first); pchan_iter; - pchan_iter = pchan_iter->next) - { + LISTBASE_FOREACH (bPoseChannel *, pchan_iter, &ob->pose->chanbase) { /* possible we have multiple children, some invisible */ if (PBONE_SELECTABLE(arm, pchan_iter->bone)) { if (pchan_iter->parent == pchan_act) { @@ -1059,7 +1048,6 @@ static bool pose_select_same_keyingset(bContext *C, ReportList *reports, bool ex ViewLayer *view_layer = CTX_data_view_layer(C); bool changed_multi = false; KeyingSet *ks = ANIM_scene_get_active_keyingset(CTX_data_scene(C)); - KS_Path *ksp; /* sanity checks: validate Keying Set and object */ if (ks == nullptr) { @@ -1109,7 +1097,7 @@ static bool pose_select_same_keyingset(bContext *C, ReportList *reports, bool ex /* iterate over elements in the Keying Set, setting selection depending on whether * that bone is visible or not... */ - for (ksp = static_cast(ks->paths.first); ksp; ksp = ksp->next) { + LISTBASE_FOREACH (KS_Path *, ksp, &ks->paths) { /* only items related to this object will be relevant */ if ((ksp->id == &ob->id) && (ksp->rna_path != nullptr)) { bPoseChannel *pchan = nullptr; @@ -1236,16 +1224,14 @@ static int pose_select_mirror_exec(bContext *C, wmOperator *op) for (uint ob_index = 0; ob_index < objects_len; ob_index++) { Object *ob = objects[ob_index]; bArmature *arm = static_cast(ob->data); - bPoseChannel *pchan, *pchan_mirror_act = nullptr; + bPoseChannel *pchan_mirror_act = nullptr; - for (pchan = static_cast(ob->pose->chanbase.first); pchan; pchan = pchan->next) - { + LISTBASE_FOREACH (bPoseChannel *, pchan, &ob->pose->chanbase) { const int flag = (pchan->bone->flag & BONE_SELECTED); PBONE_PREV_FLAG_SET(pchan, flag); } - for (pchan = static_cast(ob->pose->chanbase.first); pchan; pchan = pchan->next) - { + LISTBASE_FOREACH (bPoseChannel *, pchan, &ob->pose->chanbase) { if (PBONE_SELECTABLE(arm, pchan->bone)) { bPoseChannel *pchan_mirror; int flag_new = extend ? PBONE_PREV_FLAG_GET(pchan) : 0; diff --git a/source/blender/editors/armature/pose_slide.cc b/source/blender/editors/armature/pose_slide.cc index bb8d1caebb4..eb0860be60a 100644 --- a/source/blender/editors/armature/pose_slide.cc +++ b/source/blender/editors/armature/pose_slide.cc @@ -477,7 +477,6 @@ static void pose_slide_apply_props(tPoseSlideOp *pso, const char prop_prefix[]) { PointerRNA ptr = {nullptr}; - LinkData *ld; int len = strlen(pfl->pchan_path); /* Setup pointer RNA for resolving paths. */ @@ -488,7 +487,7 @@ static void pose_slide_apply_props(tPoseSlideOp *pso, * - bbone properties are similar, but they always start with a prefix "bbone_*", * so a similar method should work here for those too */ - for (ld = static_cast(pfl->fcurves.first); ld; ld = ld->next) { + LISTBASE_FOREACH (LinkData *, ld, &pfl->fcurves) { FCurve *fcu = (FCurve *)ld->data; const char *bPtr, *pPtr; @@ -760,10 +759,8 @@ static void pose_slide_rest_pose_apply_other_rot(tPoseSlideOp *pso, float vec[4] */ static void pose_slide_rest_pose_apply(bContext *C, tPoseSlideOp *pso) { - tPChanFCurveLink *pfl; - /* For each link, handle each set of transforms. */ - for (pfl = static_cast(pso->pfLinks.first); pfl; pfl = pfl->next) { + LISTBASE_FOREACH (tPChanFCurveLink *, pfl, &pso->pfLinks) { /* Valid transforms for each #bPoseChannel should have been noted already. * - Sliding the pose should be a straightforward exercise for location+rotation, * but rotations get more complicated since we may want to use quaternion blending @@ -819,8 +816,6 @@ static void pose_slide_rest_pose_apply(bContext *C, tPoseSlideOp *pso) */ static void pose_slide_apply(bContext *C, tPoseSlideOp *pso) { - tPChanFCurveLink *pfl; - /* Sanitize the frame ranges. */ if (pso->prev_frame == pso->next_frame) { /* Move out one step either side. */ @@ -843,7 +838,7 @@ static void pose_slide_apply(bContext *C, tPoseSlideOp *pso) } /* For each link, handle each set of transforms. */ - for (pfl = static_cast(pso->pfLinks.first); pfl; pfl = pfl->next) { + LISTBASE_FOREACH (tPChanFCurveLink *, pfl, &pso->pfLinks) { /* Valid transforms for each #bPoseChannel should have been noted already * - sliding the pose should be a straightforward exercise for location+rotation, * but rotations get more complicated since we may want to use quaternion blending @@ -1013,7 +1008,6 @@ static void pose_slide_draw_status(bContext *C, tPoseSlideOp *pso) */ static int pose_slide_invoke_common(bContext *C, wmOperator *op, const wmEvent *event) { - tPChanFCurveLink *pfl; wmWindow *win = CTX_wm_window(C); tPoseSlideOp *pso = static_cast(op->customdata); @@ -1021,11 +1015,9 @@ static int pose_slide_invoke_common(bContext *C, wmOperator *op, const wmEvent * ED_slider_init(pso->slider, event); /* For each link, add all its keyframes to the search tree. */ - for (pfl = static_cast(pso->pfLinks.first); pfl; pfl = pfl->next) { - LinkData *ld; - + LISTBASE_FOREACH (tPChanFCurveLink *, pfl, &pso->pfLinks) { /* Do this for each F-Curve. */ - for (ld = static_cast(pfl->fcurves.first); ld; ld = ld->next) { + LISTBASE_FOREACH (LinkData *, ld, &pfl->fcurves) { FCurve *fcu = (FCurve *)ld->data; fcurve_to_keylist(pfl->ob->adt, fcu, pso->keylist, 0); } diff --git a/source/blender/editors/armature/pose_transform.cc b/source/blender/editors/armature/pose_transform.cc index 8fbf3b4ea49..3c5661956f4 100644 --- a/source/blender/editors/armature/pose_transform.cc +++ b/source/blender/editors/armature/pose_transform.cc @@ -368,9 +368,7 @@ static void applyarmature_reset_bone_constraints(const bPoseChannel *pchan) * applied. */ static void applyarmature_reset_constraints(bPose *pose, const bool use_selected) { - for (bPoseChannel *pchan = static_cast(pose->chanbase.first); pchan; - pchan = pchan->next) - { + LISTBASE_FOREACH (bPoseChannel *, pchan, &pose->chanbase) { BLI_assert(pchan->bone != nullptr); if (use_selected && (pchan->bone->flag & BONE_SELECTED) == 0) { continue; @@ -390,7 +388,6 @@ static int apply_armature_pose2bones_exec(bContext *C, wmOperator *op) const Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob); bArmature *arm = BKE_armature_from_object(ob); bPose *pose; - bPoseChannel *pchan; ListBase selected_bones; const bool use_selected = RNA_boolean_get(op->ptr, "selected"); @@ -438,7 +435,7 @@ static int apply_armature_pose2bones_exec(bContext *C, wmOperator *op) BLI_freelistN(&selected_bones); } else { - for (pchan = static_cast(pose->chanbase.first); pchan; pchan = pchan->next) { + LISTBASE_FOREACH (bPoseChannel *, pchan, &pose->chanbase) { const bPoseChannel *pchan_eval = BKE_pose_channel_find_name(ob_eval->pose, pchan->name); EditBone *curbone = ED_armature_ebone_find_name(arm->edbo, pchan->name); @@ -602,10 +599,9 @@ void POSE_OT_visual_transform_apply(wmOperatorType *ot) static void set_pose_keys(Object *ob) { bArmature *arm = static_cast(ob->data); - bPoseChannel *chan; if (ob->pose) { - for (chan = static_cast(ob->pose->chanbase.first); chan; chan = chan->next) { + LISTBASE_FOREACH (bPoseChannel *, chan, &ob->pose->chanbase) { Bone *bone = chan->bone; if ((bone) && (bone->flag & BONE_SELECTED) && ANIM_bonecoll_is_visible(arm, bone)) { chan->flag |= POSE_KEY; @@ -849,7 +845,6 @@ static int pose_paste_exec(bContext *C, wmOperator *op) { Object *ob = BKE_object_pose_armature_get(CTX_data_active_object(C)); Scene *scene = CTX_data_scene(C); - bPoseChannel *chan; const bool flip = RNA_boolean_get(op->ptr, "flipped"); bool selOnly = RNA_boolean_get(op->ptr, "selected_mask"); @@ -900,7 +895,7 @@ static int pose_paste_exec(bContext *C, wmOperator *op) /* Safely merge all of the channels in the buffer pose into any * existing pose. */ - for (chan = static_cast(pose_from->chanbase.first); chan; chan = chan->next) { + LISTBASE_FOREACH (bPoseChannel *, chan, &pose_from->chanbase) { if (chan->flag & POSE_KEY) { /* Try to perform paste on this bone. */ bPoseChannel *pchan = pose_bone_do_paste(ob, chan, selOnly, flip); @@ -1378,7 +1373,6 @@ static int pose_clear_user_transforms_exec(bContext *C, wmOperator *op) */ bPose *dummyPose = nullptr; Object workob{}; - bPoseChannel *pchan; /* execute animation step for current frame using a dummy copy of the pose */ BKE_pose_copy_data(&dummyPose, ob->pose, false); @@ -1393,14 +1387,12 @@ static int pose_clear_user_transforms_exec(bContext *C, wmOperator *op) &workob.id, workob.adt, &anim_eval_context, ADT_RECALC_ANIM, false); /* Copy back values, but on selected bones only. */ - for (pchan = static_cast(dummyPose->chanbase.first); pchan; - pchan = pchan->next) { + LISTBASE_FOREACH (bPoseChannel *, pchan, &dummyPose->chanbase) { pose_bone_do_paste(ob, pchan, only_select, false); } /* free temp data - free manually as was copied without constraints */ - for (pchan = static_cast(dummyPose->chanbase.first); pchan; - pchan = pchan->next) { + LISTBASE_FOREACH (bPoseChannel *, pchan, &dummyPose->chanbase) { if (pchan->prop) { IDP_FreeProperty(pchan->prop); } diff --git a/source/blender/editors/armature/pose_utils.cc b/source/blender/editors/armature/pose_utils.cc index 6aafd5ca414..c7a7c522e48 100644 --- a/source/blender/editors/armature/pose_utils.cc +++ b/source/blender/editors/armature/pose_utils.cc @@ -214,10 +214,8 @@ void poseAnim_mapping_refresh(bContext *C, Scene * /*scene*/, Object *ob) void poseAnim_mapping_reset(ListBase *pfLinks) { - tPChanFCurveLink *pfl; - /* iterate over each pose-channel affected, restoring all channels to their original values */ - for (pfl = static_cast(pfLinks->first); pfl; pfl = pfl->next) { + LISTBASE_FOREACH (tPChanFCurveLink *, pfl, pfLinks) { bPoseChannel *pchan = pfl->pchan; /* just copy all the values over regardless of whether they changed or not */ @@ -277,13 +275,12 @@ void poseAnim_mapping_autoKeyframe(bContext *C, Scene *scene, ListBase *pfLinks, /* Insert keyframes as necessary if auto-key-framing. */ KeyingSet *ks = ANIM_get_keyingset_for_autokeying(scene, ANIM_KS_WHOLE_CHARACTER_ID); ListBase dsources = {nullptr, nullptr}; - tPChanFCurveLink *pfl; /* iterate over each pose-channel affected, tagging bones to be keyed */ /* XXX: here we already have the information about what transforms exist, though * it might be easier to just overwrite all using normal mechanisms */ - for (pfl = static_cast(pfLinks->first); pfl; pfl = pfl->next) { + LISTBASE_FOREACH (tPChanFCurveLink *, pfl, pfLinks) { bPoseChannel *pchan = pfl->pchan; if ((pfl->ob->id.tag & LIB_TAG_DOIT) == 0) { diff --git a/source/blender/editors/curve/editcurve.cc b/source/blender/editors/curve/editcurve.cc index fda2a3b2bdf..fe23c6d90af 100644 --- a/source/blender/editors/curve/editcurve.cc +++ b/source/blender/editors/curve/editcurve.cc @@ -4555,7 +4555,7 @@ static int make_segment_exec(bContext *C, wmOperator *op) } /* find both nurbs and points, nu1 will be put behind nu2 */ - for (nu = static_cast(nubase->first); nu; nu = nu->next) { + LISTBASE_FOREACH (Nurb *, nu, nubase) { if (nu->pntsu == 1) { nu->flagu &= ~CU_NURB_CYCLIC; } diff --git a/source/blender/editors/curve/editcurve_select.cc b/source/blender/editors/curve/editcurve_select.cc index 1d9a0b77aa1..db97a72063f 100644 --- a/source/blender/editors/curve/editcurve_select.cc +++ b/source/blender/editors/curve/editcurve_select.cc @@ -212,9 +212,8 @@ bool ED_curve_nurb_deselect_all(const Nurb *nu) int ED_curve_select_count(const View3D *v3d, const EditNurb *editnurb) { int sel = 0; - Nurb *nu; - for (nu = static_cast(editnurb->nurbs.first); nu; nu = nu->next) { + LISTBASE_FOREACH (Nurb *, nu, &editnurb->nurbs) { sel += ED_curve_nurb_select_count(v3d, nu); } diff --git a/source/blender/editors/curve/editcurve_undo.cc b/source/blender/editors/curve/editcurve_undo.cc index c8daa7c0906..c313f426e9d 100644 --- a/source/blender/editors/curve/editcurve_undo.cc +++ b/source/blender/editors/curve/editcurve_undo.cc @@ -64,7 +64,6 @@ static void undocurve_to_editcurve(Main *bmain, UndoCurve *ucu, Curve *cu, short { ListBase *undobase = &ucu->nubase; ListBase *editbase = BKE_curve_editNurbs_get(cu); - Nurb *nu, *newnu; EditNurb *editnurb = cu->editnurb; AnimData *ad = BKE_animdata_from_id(&cu->id); @@ -86,8 +85,8 @@ static void undocurve_to_editcurve(Main *bmain, UndoCurve *ucu, Curve *cu, short } /* Copy. */ - for (nu = static_cast(undobase->first); nu; nu = nu->next) { - newnu = BKE_nurb_duplicate(nu); + LISTBASE_FOREACH (Nurb *, nu, undobase) { + Nurb *newnu = BKE_nurb_duplicate(nu); if (editnurb->keyindex) { ED_curve_keyindex_update_nurb(editnurb, nu, newnu); @@ -108,7 +107,6 @@ static void undocurve_from_editcurve(UndoCurve *ucu, Curve *cu, const short shap BLI_assert(BLI_array_is_zeroed(ucu, 1)); ListBase *nubase = BKE_curve_editNurbs_get(cu); EditNurb *editnurb = cu->editnurb, tmpEditnurb; - Nurb *nu, *newnu; AnimData *ad = BKE_animdata_from_id(&cu->id); /* TODO: include size of fcurve & undoIndex */ @@ -128,8 +126,8 @@ static void undocurve_from_editcurve(UndoCurve *ucu, Curve *cu, const short shap } /* Copy. */ - for (nu = static_cast(nubase->first); nu; nu = nu->next) { - newnu = BKE_nurb_duplicate(nu); + LISTBASE_FOREACH (Nurb *, nu, nubase) { + Nurb *newnu = BKE_nurb_duplicate(nu); if (ucu->undoIndex) { ED_curve_keyindex_update_nurb(&tmpEditnurb, nu, newnu); diff --git a/source/blender/editors/curve/editfont.cc b/source/blender/editors/curve/editfont.cc index b937fd22e15..d748cc61c7a 100644 --- a/source/blender/editors/curve/editfont.cc +++ b/source/blender/editors/curve/editfont.cc @@ -733,7 +733,6 @@ void ED_text_to_object(bContext *C, const Text *text, const bool split_lines) { Main *bmain = CTX_data_main(C); RegionView3D *rv3d = CTX_wm_region_view3d(C); - const TextLine *line; float offset[3]; int linenum = 0; @@ -742,7 +741,7 @@ void ED_text_to_object(bContext *C, const Text *text, const bool split_lines) } if (split_lines) { - for (line = static_cast(text->lines.first); line; line = line->next) { + LISTBASE_FOREACH (const TextLine *, line, &text->lines) { /* skip lines with no text, but still make space for them */ if (line->line[0] == '\0') { linenum++; diff --git a/source/blender/editors/gpencil_legacy/editaction_gpencil.cc b/source/blender/editors/gpencil_legacy/editaction_gpencil.cc index a3ae6662691..cd66d307375 100644 --- a/source/blender/editors/gpencil_legacy/editaction_gpencil.cc +++ b/source/blender/editors/gpencil_legacy/editaction_gpencil.cc @@ -318,7 +318,6 @@ void ED_gpencil_anim_copybuf_free() bool ED_gpencil_anim_copybuf_copy(bAnimContext *ac) { ListBase anim_data = {nullptr, nullptr}; - bAnimListElem *ale; int filter; Scene *scene = ac->scene; @@ -331,7 +330,7 @@ bool ED_gpencil_anim_copybuf_copy(bAnimContext *ac) ANIM_animdata_filter( ac, &anim_data, eAnimFilter_Flags(filter), ac->data, eAnimCont_Types(ac->datatype)); - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { /* This function only deals with grease pencil layer frames. * This check is needed in the case of a call from the main dopesheet. */ if (ale->type != ANIMTYPE_GPLAYER) { @@ -387,7 +386,6 @@ bool ED_gpencil_anim_copybuf_copy(bAnimContext *ac) bool ED_gpencil_anim_copybuf_paste(bAnimContext *ac, const short offset_mode) { ListBase anim_data = {nullptr, nullptr}; - bAnimListElem *ale; int filter; Scene *scene = ac->scene; @@ -428,7 +426,7 @@ bool ED_gpencil_anim_copybuf_paste(bAnimContext *ac, const short offset_mode) ac, &anim_data, eAnimFilter_Flags(filter), ac->data, eAnimCont_Types(ac->datatype)); /* from selected channels */ - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { /* only deal with GPlayers (case of calls from general dopesheet) */ if (ale->type != ANIMTYPE_GPLAYER) { continue; @@ -436,7 +434,7 @@ bool ED_gpencil_anim_copybuf_paste(bAnimContext *ac, const short offset_mode) bGPDlayer *gpld = (bGPDlayer *)ale->data; bGPDlayer *gpls = nullptr; - bGPDframe *gpfs, *gpf; + bGPDframe *gpf; /* find suitable layer from buffer to use to paste from */ for (gpls = static_cast(gpencil_anim_copybuf.first); gpls; gpls = gpls->next) { @@ -452,7 +450,7 @@ bool ED_gpencil_anim_copybuf_paste(bAnimContext *ac, const short offset_mode) } /* add frames from buffer */ - for (gpfs = static_cast(gpls->frames.first); gpfs; gpfs = gpfs->next) { + LISTBASE_FOREACH (bGPDframe *, gpfs, &gpls->frames) { /* temporarily apply offset to buffer-frame while copying */ gpfs->framenum += offset; @@ -462,8 +460,6 @@ bool ED_gpencil_anim_copybuf_paste(bAnimContext *ac, const short offset_mode) /* Ensure to use same keyframe type. */ gpf->key_type = gpfs->key_type; - bGPDstroke *gps, *gpsn; - /* This should be the right frame... as it may be a pre-existing frame, * must make sure that only compatible stroke types get copied over * - We cannot just add a duplicate frame, as that would cause errors @@ -471,9 +467,9 @@ bool ED_gpencil_anim_copybuf_paste(bAnimContext *ac, const short offset_mode) * don't have enough info to do so. Instead, we simply just paste, * if it works, it will show up. */ - for (gps = static_cast(gpfs->strokes.first); gps; gps = gps->next) { + LISTBASE_FOREACH (bGPDstroke *, gps, &gpfs->strokes) { /* make a copy of stroke, then of its points array */ - gpsn = BKE_gpencil_stroke_duplicate(gps, true, true); + bGPDstroke *gpsn = BKE_gpencil_stroke_duplicate(gps, true, true); /* append stroke to frame */ BLI_addtail(&gpf->strokes, gpsn); diff --git a/source/blender/editors/gpencil_legacy/gpencil_data.cc b/source/blender/editors/gpencil_legacy/gpencil_data.cc index b128a385929..8bd823bcf9a 100644 --- a/source/blender/editors/gpencil_legacy/gpencil_data.cc +++ b/source/blender/editors/gpencil_legacy/gpencil_data.cc @@ -1098,8 +1098,7 @@ static bool gpencil_reveal_poll(bContext *C) static void gpencil_reveal_select_frame(bContext *C, bGPDframe *frame, bool select) { - bGPDstroke *gps; - for (gps = static_cast(frame->strokes.first); gps; gps = gps->next) { + LISTBASE_FOREACH (bGPDstroke *, gps, &frame->strokes) { /* only deselect strokes that are valid in this view */ if (ED_gpencil_stroke_can_use(C, gps)) { @@ -1141,8 +1140,7 @@ static int gpencil_reveal_exec(bContext *C, wmOperator *op) } else { /* deselect strokes on all frames (same as deselect all operator) */ - bGPDframe *gpf; - for (gpf = static_cast(gpl->frames.first); gpf; gpf = gpf->next) { + LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) { gpencil_reveal_select_frame(C, gpf, false); } } @@ -1621,7 +1619,7 @@ static int gpencil_stroke_arrange_exec(bContext *C, wmOperator *op) continue; } /* verify if any selected stroke is in the extreme of the stack and select to move */ - for (gps = static_cast(gpf->strokes.first); gps; gps = gps->next) { + LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) { /* only if selected */ if (gps->flag & GP_STROKE_SELECT) { /* skip strokes that are invalid for current view */ @@ -1896,9 +1894,7 @@ static int gpencil_material_lock_unsused_exec(bContext *C, wmOperator * /*op*/) LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) { /* only editable and visible layers are considered */ if (BKE_gpencil_layer_is_editable(gpl) && (gpl->actframe != nullptr)) { - for (bGPDstroke *gps = static_cast(gpl->actframe->strokes.last); gps; - gps = gps->prev) - { + LISTBASE_FOREACH_BACKWARD (bGPDstroke *, gps, &gpl->actframe->strokes) { /* only if selected */ if (gps->flag & GP_STROKE_SELECT) { /* skip strokes that are invalid for current view */ @@ -3115,9 +3111,7 @@ static int gpencil_lock_layer_exec(bContext *C, wmOperator * /*op*/) if (BKE_gpencil_layer_is_editable(gpl) && (gpl->actframe != nullptr) && (gpl->flag & GP_LAYER_ACTIVE)) { - for (bGPDstroke *gps = static_cast(gpl->actframe->strokes.last); gps; - gps = gps->prev) - { + LISTBASE_FOREACH_BACKWARD (bGPDstroke *, gps, &gpl->actframe->strokes) { /* skip strokes that are invalid for current view */ if (ED_gpencil_stroke_can_use(C, gps) == false) { continue; diff --git a/source/blender/editors/gpencil_legacy/gpencil_edit.cc b/source/blender/editors/gpencil_legacy/gpencil_edit.cc index 20e370618c8..d5116269fc0 100644 --- a/source/blender/editors/gpencil_legacy/gpencil_edit.cc +++ b/source/blender/editors/gpencil_legacy/gpencil_edit.cc @@ -935,14 +935,13 @@ static int gpencil_duplicate_exec(bContext *C, wmOperator *op) CTX_DATA_BEGIN (C, bGPDlayer *, gpl, editable_gpencil_layers) { ListBase new_strokes = {nullptr, nullptr}; bGPDframe *gpf = gpl->actframe; - bGPDstroke *gps; if (gpf == nullptr) { continue; } /* make copies of selected strokes, and deselect these once we're done */ - for (gps = static_cast(gpf->strokes.first); gps; gps = gps->next) { + LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) { /* skip strokes that are invalid for current view */ if (ED_gpencil_stroke_can_use(C, gps) == false) { continue; @@ -1284,7 +1283,6 @@ static int gpencil_extrude_exec(bContext *C, wmOperator *op) bGPdata *gpd = (bGPdata *)obact->data; const bool is_curve_edit = bool(GPENCIL_CURVE_EDIT_SESSIONS_ON(gpd)); const bool is_multiedit = bool(GPENCIL_MULTIEDIT_SESSIONS_ON(gpd)); - bGPDstroke *gps = nullptr; if (gpd == nullptr) { BKE_report(op->reports, RPT_ERROR, "No Grease Pencil data"); @@ -1302,7 +1300,7 @@ static int gpencil_extrude_exec(bContext *C, wmOperator *op) continue; } - for (gps = static_cast(gpf->strokes.first); gps; gps = gps->next) { + LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) { /* skip strokes that are invalid for current view */ if (ED_gpencil_stroke_can_use(C, gps) == false) { continue; @@ -1520,8 +1518,7 @@ static int gpencil_strokes_copy_exec(bContext *C, wmOperator *op) } /* make copies of selected strokes, and deselect these once we're done */ - for (bGPDstroke *gps = static_cast(gpf->strokes.first); gps; - gps = gps->next) { + LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) { /* skip strokes that are invalid for current view */ if (ED_gpencil_stroke_can_use(C, gps) == false) { continue; @@ -1671,11 +1668,9 @@ static int gpencil_strokes_paste_exec(bContext *C, wmOperator *op) } else { /* Check that some of the strokes in the buffer can be used */ - bGPDstroke *gps; bool ok = false; - for (gps = static_cast(gpencil_strokes_copypastebuf.first); gps; gps = gps->next) - { + LISTBASE_FOREACH (bGPDstroke *, gps, &gpencil_strokes_copypastebuf) { if (ED_gpencil_stroke_can_use(C, gps)) { ok = true; break; @@ -3279,7 +3274,6 @@ static int gpencil_stroke_cyclical_set_exec(bContext *C, wmOperator *op) const bool geometry = RNA_boolean_get(op->ptr, "geometry"); const bool is_multiedit = bool(GPENCIL_MULTIEDIT_SESSIONS_ON(gpd)); const bool is_curve_edit = bool(GPENCIL_CURVE_EDIT_SESSIONS_ON(gpd)); - bGPDstroke *gps = nullptr; /* sanity checks */ if (ELEM(nullptr, gpd)) { @@ -3298,7 +3292,7 @@ static int gpencil_stroke_cyclical_set_exec(bContext *C, wmOperator *op) continue; } - for (gps = static_cast(gpf->strokes.first); gps; gps = gps->next) { + LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) { MaterialGPencilStyle *gp_style = BKE_gpencil_material_settings(ob, gps->mat_nr + 1); /* skip strokes that are not selected or invalid for current view */ if (((gps->flag & GP_STROKE_SELECT) == 0) || ED_gpencil_stroke_can_use(C, gps) == false) @@ -3448,8 +3442,7 @@ static int gpencil_stroke_caps_set_exec(bContext *C, wmOperator *op) continue; } - for (bGPDstroke *gps = static_cast(gpf->strokes.first); gps; gps = gps->next) - { + LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) { MaterialGPencilStyle *gp_style = BKE_gpencil_material_settings(ob, gps->mat_nr + 1); /* skip strokes that are not selected or invalid for current view */ @@ -3965,8 +3958,7 @@ static int gpencil_strokes_reproject_exec(bContext *C, wmOperator *op) if (gpf == nullptr) { continue; } - for (bGPDstroke *gps = static_cast(gpf->strokes.first); gps; gps = gps->next) - { + LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) { /* skip strokes that are invalid for current view */ if (ED_gpencil_stroke_can_use(C, gps) == false) { continue; @@ -4240,8 +4232,7 @@ static int gpencil_stroke_outline_exec(bContext *C, wmOperator *op) continue; } - for (bGPDstroke *gps = static_cast(gpf->strokes.first); gps; gps = gps->next) - { + LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) { if ((gps->flag & GP_STROKE_SELECT) == 0) { continue; } diff --git a/source/blender/editors/gpencil_legacy/gpencil_sculpt_paint.cc b/source/blender/editors/gpencil_legacy/gpencil_sculpt_paint.cc index 268bc2d6c15..6066d6bf348 100644 --- a/source/blender/editors/gpencil_legacy/gpencil_sculpt_paint.cc +++ b/source/blender/editors/gpencil_legacy/gpencil_sculpt_paint.cc @@ -923,14 +923,13 @@ struct tGPSB_CloneBrushData { static void gpencil_brush_clone_init(bContext *C, tGP_BrushEditData *gso) { tGPSB_CloneBrushData *data; - bGPDstroke *gps; /* Initialize custom-data. */ gso->customdata = data = static_cast( MEM_callocN(sizeof(tGPSB_CloneBrushData), "CloneBrushData")); /* compute midpoint of strokes on clipboard */ - for (gps = static_cast(gpencil_strokes_copypastebuf.first); gps; gps = gps->next) { + LISTBASE_FOREACH (bGPDstroke *, gps, &gpencil_strokes_copypastebuf) { if (ED_gpencil_stroke_can_use(C, gps)) { const float dfac = 1.0f / float(gps->totpoints); float mid[3] = {0.0f}; @@ -996,7 +995,6 @@ static void gpencil_brush_clone_add(bContext *C, tGP_BrushEditData *gso) Object *ob = gso->object; bGPdata *gpd = (bGPdata *)ob->data; Scene *scene = gso->scene; - bGPDstroke *gps; float delta[3]; size_t strokes_added = 0; @@ -1008,7 +1006,7 @@ static void gpencil_brush_clone_add(bContext *C, tGP_BrushEditData *gso) sub_v3_v3v3(delta, gso->dvec, data->buffer_midpoint); /* Copy each stroke into the layer */ - for (gps = static_cast(gpencil_strokes_copypastebuf.first); gps; gps = gps->next) { + LISTBASE_FOREACH (bGPDstroke *, gps, &gpencil_strokes_copypastebuf) { if (ED_gpencil_stroke_can_use(C, gps)) { bGPDstroke *new_stroke; bGPDspoint *pt; @@ -1241,12 +1239,10 @@ static bool gpencil_sculpt_brush_init(bContext *C, wmOperator *op) char tool = gso->brush->gpencil_sculpt_tool; switch (tool) { case GPSCULPT_TOOL_CLONE: { - bGPDstroke *gps; bool found = false; /* check that there are some usable strokes in the buffer */ - for (gps = static_cast(gpencil_strokes_copypastebuf.first); gps; - gps = gps->next) { + LISTBASE_FOREACH (bGPDstroke *, gps, &gpencil_strokes_copypastebuf) { if (ED_gpencil_stroke_can_use(C, gps)) { found = true; break; diff --git a/source/blender/editors/gpencil_legacy/gpencil_select.cc b/source/blender/editors/gpencil_legacy/gpencil_select.cc index 47057f48545..ec2445836ff 100644 --- a/source/blender/editors/gpencil_legacy/gpencil_select.cc +++ b/source/blender/editors/gpencil_legacy/gpencil_select.cc @@ -765,7 +765,6 @@ static bool gpencil_select_same_layer(bContext *C) bool changed = false; CTX_DATA_BEGIN (C, bGPDlayer *, gpl, editable_gpencil_layers) { bGPDframe *gpf = BKE_gpencil_layer_frame_get(gpl, scene->r.cfra, GP_GETFRAME_USE_PREV); - bGPDstroke *gps; bool found = false; if (gpf == nullptr) { @@ -773,7 +772,7 @@ static bool gpencil_select_same_layer(bContext *C) } /* Search for a selected stroke */ - for (gps = static_cast(gpf->strokes.first); gps; gps = gps->next) { + LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) { if (ED_gpencil_stroke_can_use(C, gps)) { if (gps->flag & GP_STROKE_SELECT) { found = true; @@ -785,7 +784,7 @@ static bool gpencil_select_same_layer(bContext *C) /* Select all if found */ if (found) { if (is_curve_edit) { - for (gps = static_cast(gpf->strokes.first); gps; gps = gps->next) { + LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) { if (gps->editcurve != nullptr && ED_gpencil_stroke_can_use(C, gps)) { bGPDcurve *gpc = gps->editcurve; for (int i = 0; i < gpc->tot_curve_points; i++) { @@ -802,7 +801,7 @@ static bool gpencil_select_same_layer(bContext *C) } } else { - for (gps = static_cast(gpf->strokes.first); gps; gps = gps->next) { + LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) { if (ED_gpencil_stroke_can_use(C, gps)) { bGPDspoint *pt; int i; diff --git a/source/blender/editors/gpencil_legacy/gpencil_utils.cc b/source/blender/editors/gpencil_legacy/gpencil_utils.cc index 7a23f0d710e..d9ca45f4a04 100644 --- a/source/blender/editors/gpencil_legacy/gpencil_utils.cc +++ b/source/blender/editors/gpencil_legacy/gpencil_utils.cc @@ -1465,15 +1465,13 @@ void ED_gpencil_vgroup_assign(bContext *C, Object *ob, float weight) CTX_DATA_BEGIN (C, bGPDlayer *, gpl, editable_gpencil_layers) { bGPDframe *init_gpf = static_cast((is_multiedit) ? gpl->frames.first : gpl->actframe); - bGPDstroke *gps = nullptr; - for (bGPDframe *gpf = init_gpf; gpf; gpf = gpf->next) { if ((gpf == gpl->actframe) || ((gpf->flag & GP_FRAME_SELECT) && (is_multiedit))) { if (gpf == nullptr) { continue; } - for (gps = static_cast(gpf->strokes.first); gps; gps = gps->next) { + LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) { /* skip strokes that are invalid for current view */ if (ED_gpencil_stroke_can_use(C, gps) == false) { @@ -1519,7 +1517,6 @@ void ED_gpencil_vgroup_remove(bContext *C, Object *ob) CTX_DATA_BEGIN (C, bGPDlayer *, gpl, editable_gpencil_layers) { bGPDframe *init_gpf = static_cast((is_multiedit) ? gpl->frames.first : gpl->actframe); - bGPDstroke *gps = nullptr; for (bGPDframe *gpf = init_gpf; gpf; gpf = gpf->next) { if ((gpf == gpl->actframe) || ((gpf->flag & GP_FRAME_SELECT) && (is_multiedit))) { @@ -1527,8 +1524,7 @@ void ED_gpencil_vgroup_remove(bContext *C, Object *ob) continue; } - for (gps = static_cast(gpf->strokes.first); gps; gps = gps->next) { - + LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) { /* skip strokes that are invalid for current view */ if (ED_gpencil_stroke_can_use(C, gps) == false) { continue; @@ -1572,16 +1568,13 @@ void ED_gpencil_vgroup_select(bContext *C, Object *ob) CTX_DATA_BEGIN (C, bGPDlayer *, gpl, editable_gpencil_layers) { bGPDframe *init_gpf = static_cast((is_multiedit) ? gpl->frames.first : gpl->actframe); - bGPDstroke *gps = nullptr; - for (bGPDframe *gpf = init_gpf; gpf; gpf = gpf->next) { if ((gpf == gpl->actframe) || ((gpf->flag & GP_FRAME_SELECT) && (is_multiedit))) { if (gpf == nullptr) { continue; } - for (gps = static_cast(gpf->strokes.first); gps; gps = gps->next) { - + LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) { /* skip strokes that are invalid for current view */ if (ED_gpencil_stroke_can_use(C, gps) == false) { continue; @@ -1627,15 +1620,13 @@ void ED_gpencil_vgroup_deselect(bContext *C, Object *ob) CTX_DATA_BEGIN (C, bGPDlayer *, gpl, editable_gpencil_layers) { bGPDframe *init_gpf = static_cast((is_multiedit) ? gpl->frames.first : gpl->actframe); - bGPDstroke *gps = nullptr; - for (bGPDframe *gpf = init_gpf; gpf; gpf = gpf->next) { if ((gpf == gpl->actframe) || ((gpf->flag & GP_FRAME_SELECT) && (is_multiedit))) { if (gpf == nullptr) { continue; } - for (gps = static_cast(gpf->strokes.first); gps; gps = gps->next) { + LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) { /* skip strokes that are invalid for current view */ if (ED_gpencil_stroke_can_use(C, gps) == false) { @@ -2581,9 +2572,7 @@ void ED_gpencil_select_toggle_all(bContext *C, int action) /* deselect all strokes on all frames */ LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) { - bGPDstroke *gps; - - for (gps = static_cast(gpf->strokes.first); gps; gps = gps->next) { + LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) { bGPDspoint *pt; int i; diff --git a/source/blender/editors/gpencil_legacy/gpencil_weight_paint.cc b/source/blender/editors/gpencil_legacy/gpencil_weight_paint.cc index afa55e1d87a..931aa0f65f2 100644 --- a/source/blender/editors/gpencil_legacy/gpencil_weight_paint.cc +++ b/source/blender/editors/gpencil_legacy/gpencil_weight_paint.cc @@ -299,7 +299,7 @@ static bool *gpencil_vgroup_bone_deformed_map_get(Object *ob, const int defbase_ /* Add all vertex group names to a hash table. */ gh = BLI_ghash_str_new_ex(__func__, defbase_tot); - for (dg = static_cast(defbase->first); dg; dg = dg->next) { + LISTBASE_FOREACH (bDeformGroup *, dg, defbase) { BLI_ghash_insert(gh, dg->name, nullptr); } BLI_assert(BLI_ghash_len(gh) == defbase_tot); @@ -314,9 +314,8 @@ static bool *gpencil_vgroup_bone_deformed_map_get(Object *ob, const int defbase_ if (amd->object && amd->object->pose) { bPose *pose = amd->object->pose; - bPoseChannel *chan; - for (chan = static_cast(pose->chanbase.first); chan; chan = chan->next) { + LISTBASE_FOREACH (bPoseChannel *, chan, &pose->chanbase) { void **val_p; if (chan->bone->flag & BONE_NO_DEFORM) { continue; diff --git a/source/blender/editors/interface/interface_layout.cc b/source/blender/editors/interface/interface_layout.cc index a272c26ce8e..606e474552a 100644 --- a/source/blender/editors/interface/interface_layout.cc +++ b/source/blender/editors/interface/interface_layout.cc @@ -6112,11 +6112,9 @@ static void ui_layout_introspect_button(DynStr *ds, uiButtonItem *bitem) static void ui_layout_introspect_items(DynStr *ds, ListBase *lb) { - uiItem *item; - BLI_dynstr_append(ds, "["); - for (item = static_cast(lb->first); item; item = item->next) { + LISTBASE_FOREACH (uiItem *, item, lb) { BLI_dynstr_append(ds, "{"); diff --git a/source/blender/editors/interface/interface_templates.cc b/source/blender/editors/interface/interface_templates.cc index dc36e5ee006..fa622b014ff 100644 --- a/source/blender/editors/interface/interface_templates.cc +++ b/source/blender/editors/interface/interface_templates.cc @@ -2307,7 +2307,7 @@ void uiTemplateModifiers(uiLayout * /*layout*/, bContext *C) if (!panels_match) { UI_panels_free_instanced(C, region); - for (ModifierData *md = static_cast(modifiers->first); md; md = md->next) { + LISTBASE_FOREACH (ModifierData *, md, modifiers) { const ModifierTypeInfo *mti = BKE_modifier_get_info(ModifierType(md->type)); if (mti->panel_register == nullptr) { continue; @@ -2556,9 +2556,7 @@ void uiTemplateGpencilModifiers(uiLayout * /*layout*/, bContext *C) if (!panels_match) { UI_panels_free_instanced(C, region); - for (GpencilModifierData *md = static_cast(modifiers->first); md; - md = md->next) - { + LISTBASE_FOREACH (GpencilModifierData *, md, modifiers) { const GpencilModifierTypeInfo *mti = BKE_gpencil_modifier_get_info( GpencilModifierType(md->type)); if (mti->panel_register == nullptr) { @@ -2631,7 +2629,7 @@ void uiTemplateShaderFx(uiLayout * /*layout*/, bContext *C) if (!panels_match) { UI_panels_free_instanced(C, region); - for (ShaderFxData *fx = static_cast(shaderfx->first); fx; fx = fx->next) { + LISTBASE_FOREACH (ShaderFxData *, fx, shaderfx) { char panel_idname[MAX_NAME]; shaderfx_panel_id(fx, panel_idname); diff --git a/source/blender/editors/mesh/editmesh_extrude.cc b/source/blender/editors/mesh/editmesh_extrude.cc index 3ca07c371d2..fce829c3539 100644 --- a/source/blender/editors/mesh/editmesh_extrude.cc +++ b/source/blender/editors/mesh/editmesh_extrude.cc @@ -40,12 +40,11 @@ static void edbm_extrude_edge_exclude_mirror( Object *obedit, BMEditMesh *em, const char hflag, BMOperator *op, BMOpSlot *slot_edges_exclude) { BMesh *bm = em->bm; - ModifierData *md; /* If a mirror modifier with clipping is on, we need to adjust some * of the cases above to handle edges on the line of symmetry. */ - for (md = static_cast(obedit->modifiers.first); md; md = md->next) { + LISTBASE_FOREACH (ModifierData *, md, &obedit->modifiers) { if ((md->type == eModifierType_Mirror) && (md->mode & eModifierMode_Realtime)) { MirrorModifierData *mmd = (MirrorModifierData *)md; diff --git a/source/blender/editors/mesh/editmesh_knife.cc b/source/blender/editors/mesh/editmesh_knife.cc index cab9721b164..904eb961a97 100644 --- a/source/blender/editors/mesh/editmesh_knife.cc +++ b/source/blender/editors/mesh/editmesh_knife.cc @@ -686,7 +686,6 @@ static void knifetool_draw_angle(const KnifeTool_OpData *kcd, static void knifetool_draw_visible_angles(const KnifeTool_OpData *kcd) { - Ref *ref; KnifeVert *kfv; KnifeVert *tempkfv; KnifeEdge *kfe; @@ -700,7 +699,7 @@ static void knifetool_draw_visible_angles(const KnifeTool_OpData *kcd) float *end; kfe = static_cast(((Ref *)kfv->edges.first)->ref); - for (ref = static_cast(kfv->edges.first); ref; ref = ref->next) { + LISTBASE_FOREACH (Ref *, ref, &kfv->edges) { tempkfe = static_cast(ref->ref); if (tempkfe->v1 != kfv) { tempkfv = tempkfe->v1; @@ -783,7 +782,7 @@ static void knifetool_draw_visible_angles(const KnifeTool_OpData *kcd) else { /* Choose minimum angle edge. */ kfe = static_cast(((Ref *)kfv->edges.first)->ref); - for (ref = static_cast(kfv->edges.first); ref; ref = ref->next) { + LISTBASE_FOREACH (Ref *, ref, &kfv->edges) { tempkfe = static_cast(ref->ref); if (tempkfe->v1 != kfv) { tempkfv = tempkfe->v1; @@ -1586,8 +1585,7 @@ static BMElem *bm_elem_from_knife_vert(KnifeVert *kfv, KnifeEdge **r_kfe) if (r_kfe || ele_test == nullptr) { if (kfv->v == nullptr) { - Ref *ref; - for (ref = static_cast(kfv->edges.first); ref; ref = ref->next) { + LISTBASE_FOREACH (Ref *, ref, &kfv->edges) { kfe = static_cast(ref->ref); if (kfe->e) { if (r_kfe) { @@ -1655,9 +1653,7 @@ static void knife_append_list(KnifeTool_OpData *kcd, ListBase *lst, void *elem) static Ref *find_ref(ListBase *lb, void *ref) { - Ref *ref1; - - for (ref1 = static_cast(lb->first); ref1; ref1 = ref1->next) { + LISTBASE_FOREACH (Ref *, ref1, lb) { if (ref1->ref == ref) { return ref1; } @@ -1694,10 +1690,8 @@ static void knife_add_edge_faces_to_vert(KnifeTool_OpData *kcd, KnifeVert *kfv, * If more than one, return the first; if none, return nullptr. */ static BMFace *knife_find_common_face(ListBase *faces1, ListBase *faces2) { - Ref *ref1, *ref2; - - for (ref1 = static_cast(faces1->first); ref1; ref1 = ref1->next) { - for (ref2 = static_cast(faces2->first); ref2; ref2 = ref2->next) { + LISTBASE_FOREACH (Ref *, ref1, faces1) { + LISTBASE_FOREACH (Ref *, ref2, faces2) { if (ref1->ref == ref2->ref) { return (BMFace *)(ref1->ref); } @@ -1852,7 +1846,7 @@ static KnifeVert *knife_split_edge(KnifeTool_OpData *kcd, kfe->v1->is_splitting = true; BLI_addtail(&kfe->v1->edges, ref); - for (ref = static_cast(kfe->faces.first); ref; ref = ref->next) { + LISTBASE_FOREACH (Ref *, ref, &kfe->faces) { knife_edge_append_face(kcd, newkfe, static_cast(ref->ref)); } @@ -2178,7 +2172,6 @@ static void knife_cut_face(KnifeTool_OpData *kcd, BMFace *f, ListBase *hits) static void knife_make_face_cuts(KnifeTool_OpData *kcd, BMesh *bm, BMFace *f, ListBase *kfedges) { KnifeEdge *kfe; - Ref *ref; int edge_array_len = BLI_listbase_count(kfedges); int i; @@ -2190,7 +2183,7 @@ static void knife_make_face_cuts(KnifeTool_OpData *kcd, BMesh *bm, BMFace *f, Li BLI_assert(BLI_gset_len(kcd->edgenet.edge_visit) == 0); i = 0; - for (ref = static_cast(kfedges->first); ref; ref = ref->next) { + LISTBASE_FOREACH (Ref *, ref, kfedges) { bool is_new_edge = false; kfe = static_cast(ref->ref); @@ -2320,7 +2313,6 @@ static void knife_make_cuts(KnifeTool_OpData *kcd, Object *ob) BMFace *f; BMEdge *e, *enew; ListBase *list; - Ref *ref; float pct; SmallHashIter hiter; BLI_mempool_iter iter; @@ -2366,7 +2358,7 @@ static void knife_make_cuts(KnifeTool_OpData *kcd, Object *ob) if (kfv->v || kfv->is_invalid || kfv->ob != ob) { continue; /* Already have a BMVert. */ } - for (ref = static_cast(kfv->edges.first); ref; ref = ref->next) { + LISTBASE_FOREACH (Ref *, ref, &kfv->edges) { kfe = static_cast(ref->ref); e = kfe->e; if (!e) { @@ -2390,7 +2382,7 @@ static void knife_make_cuts(KnifeTool_OpData *kcd, Object *ob) { BLI_listbase_sort_r(list, sort_verts_by_dist_cb, e->v1->co); - for (ref = static_cast(list->first); ref; ref = ref->next) { + LISTBASE_FOREACH (Ref *, ref, list) { kfv = static_cast(ref->ref); pct = line_point_factor_v3(kfv->co, e->v1->co, e->v2->co); kfv->v = BM_edge_split(bm, e, e->v1, &enew, pct); @@ -2422,7 +2414,6 @@ static void knife_add_cut(KnifeTool_OpData *kcd) int i; GHash *facehits; BMFace *f; - Ref *r; GHashIterator giter; ListBase *list; @@ -2462,12 +2453,12 @@ static void knife_add_cut(KnifeTool_OpData *kcd) add_hit_to_facehits(kcd, facehits, lh->f, lh); } if (lh->v) { - for (r = static_cast(lh->v->faces.first); r; r = r->next) { + LISTBASE_FOREACH (Ref *, r, &lh->v->faces) { add_hit_to_facehits(kcd, facehits, static_cast(r->ref), lh); } } if (lh->kfe) { - for (r = static_cast(lh->kfe->faces.first); r; r = r->next) { + LISTBASE_FOREACH (Ref *, r, &lh->kfe->faces) { add_hit_to_facehits(kcd, facehits, static_cast(r->ref), lh); } } @@ -2589,7 +2580,6 @@ static bool knife_ray_intersect_face(KnifeTool_OpData *kcd, float d, lambda; BMLoop **tri; ListBase *list; - Ref *ref; KnifeEdge *kfe; sub_v3_v3v3(raydir, v2, v1); @@ -2626,7 +2616,7 @@ static bool knife_ray_intersect_face(KnifeTool_OpData *kcd, interp_v3_v3v3v3_uv(hit_cageco, UNPACK3(tri_cos), ray_tri_uv); /* Now check that far enough away from verts and edges. */ list = knife_get_face_kedges(kcd, ob, ob_index, f); - for (ref = static_cast(list->first); ref; ref = ref->next) { + LISTBASE_FOREACH (Ref *, ref, list) { kfe = static_cast(ref->ref); if (kfe->is_invalid) { continue; @@ -3287,7 +3277,6 @@ static int knife_sample_screen_density_from_closest_face(KnifeTool_OpData *kcd, { const float radius_sq = radius * radius; ListBase *list; - Ref *ref; float sco[2]; float dis_sq; int c = 0; @@ -3295,7 +3284,7 @@ static int knife_sample_screen_density_from_closest_face(KnifeTool_OpData *kcd, knife_project_v2(kcd, cageco, sco); list = knife_get_face_kedges(kcd, ob, ob_index, f); - for (ref = static_cast(list->first); ref; ref = ref->next) { + LISTBASE_FOREACH (Ref *, ref, list) { KnifeEdge *kfe = static_cast(ref->ref); int i; @@ -3422,14 +3411,13 @@ static KnifeEdge *knife_find_closest_edge_of_face( KnifeEdge *cure = nullptr; float cur_cagep[3]; ListBase *list; - Ref *ref; float dis_sq, curdis_sq = maxdist_sq; knife_project_v2(kcd, cagep, sco); /* Look through all edges associated with this face. */ list = knife_get_face_kedges(kcd, ob, ob_index, f); - for (ref = static_cast(list->first); ref; ref = ref->next) { + LISTBASE_FOREACH (Ref *, ref, list) { KnifeEdge *kfe = static_cast(ref->ref); float kfv1_sco[2], kfv2_sco[2], test_cagep[3]; float lambda; @@ -3637,7 +3625,6 @@ static float snap_v3_angle_plane( /* Snap to required angle along the plane of the face nearest to kcd->prev. */ static bool knife_snap_angle_relative(KnifeTool_OpData *kcd) { - Ref *ref; KnifeEdge *kfe; KnifeVert *kfv; BMFace *f; @@ -3668,7 +3655,7 @@ static bool knife_snap_angle_relative(KnifeTool_OpData *kcd) * If none exists then exit. */ if (kcd->prev.vert) { int count = 0; - for (ref = static_cast(kcd->prev.vert->edges.first); ref; ref = ref->next) { + LISTBASE_FOREACH (Ref *, ref, &kcd->prev.vert->edges) { kfe = ((KnifeEdge *)(ref->ref)); if (kfe->is_invalid) { continue; @@ -3701,7 +3688,7 @@ static bool knife_snap_angle_relative(KnifeTool_OpData *kcd) /* Choose best face for plane. */ BMFace *fprev = nullptr; if (kcd->prev.vert && kcd->prev.vert->v) { - for (ref = static_cast(kcd->prev.vert->faces.first); ref; ref = ref->next) { + LISTBASE_FOREACH (Ref *, ref, &kcd->prev.vert->faces) { f = ((BMFace *)(ref->ref)); if (f == fcurr) { fprev = f; @@ -3709,7 +3696,7 @@ static bool knife_snap_angle_relative(KnifeTool_OpData *kcd) } } else if (kcd->prev.edge) { - for (ref = static_cast(kcd->prev.edge->faces.first); ref; ref = ref->next) { + LISTBASE_FOREACH (Ref *, ref, &kcd->prev.edge->faces) { f = ((BMFace *)(ref->ref)); if (f == fcurr) { fprev = f; @@ -3777,7 +3764,6 @@ static bool knife_snap_angle_relative(KnifeTool_OpData *kcd) static int knife_calculate_snap_ref_edges(KnifeTool_OpData *kcd) { - Ref *ref; KnifeEdge *kfe; /* Ray for kcd->curr. */ @@ -3800,7 +3786,7 @@ static int knife_calculate_snap_ref_edges(KnifeTool_OpData *kcd) } if (kcd->prev.vert) { - for (ref = static_cast(kcd->prev.vert->edges.first); ref; ref = ref->next) { + LISTBASE_FOREACH (Ref *, ref, &kcd->prev.vert->edges) { kfe = ((KnifeEdge *)(ref->ref)); if (kfe->is_invalid) { continue; @@ -3956,7 +3942,6 @@ static bool knife_snap_update_from_mval(KnifeTool_OpData *kcd, const float mval[ */ static void knifetool_undo(KnifeTool_OpData *kcd) { - Ref *ref; KnifeEdge *kfe, *newkfe; KnifeEdge *lastkfe = nullptr; KnifeVert *v1, *v2; @@ -3995,7 +3980,7 @@ static void knifetool_undo(KnifeTool_OpData *kcd) if (!v1->is_invalid && !v1->is_splitting) { v1->is_invalid = true; /* If the first vertex is touching any other cut edges don't remove it. */ - for (ref = static_cast(v1->edges.first); ref; ref = ref->next) { + LISTBASE_FOREACH (Ref *, ref, &v1->edges) { kfe = static_cast(ref->ref); if (kfe->is_cut && !kfe->is_invalid) { v1->is_invalid = false; @@ -4008,7 +3993,7 @@ static void knifetool_undo(KnifeTool_OpData *kcd) if (!v2->is_invalid && !v2->is_splitting) { v2->is_invalid = true; /* If the second vertex is touching any other cut edges don't remove it. */ - for (ref = static_cast(v2->edges.first); ref; ref = ref->next) { + LISTBASE_FOREACH (Ref *, ref, &v2->edges) { kfe = static_cast(ref->ref); if (kfe->is_cut && !kfe->is_invalid) { v2->is_invalid = false; diff --git a/source/blender/editors/mesh/editmesh_tools.cc b/source/blender/editors/mesh/editmesh_tools.cc index 7d7214f068e..8d05fdc6313 100644 --- a/source/blender/editors/mesh/editmesh_tools.cc +++ b/source/blender/editors/mesh/editmesh_tools.cc @@ -1508,12 +1508,11 @@ static bool bm_vert_connect_select_history(BMesh *bm) static bool bm_vert_connect_select_history_edge_to_vert_path(BMesh *bm, ListBase *r_selected) { ListBase selected_orig = {nullptr, nullptr}; - BMEditSelection *ese; int edges_len = 0; bool side = false; /* first check all edges are OK */ - for (ese = static_cast(bm->selected.first); ese; ese = ese->next) { + LISTBASE_FOREACH (BMEditSelection *, ese, &bm->selected) { if (ese->htype == BM_EDGE) { edges_len += 1; } @@ -1529,7 +1528,7 @@ static bool bm_vert_connect_select_history_edge_to_vert_path(BMesh *bm, ListBase SWAP(ListBase, bm->selected, selected_orig); /* convert edge selection into 2 ordered loops (where the first edge ends up in the middle) */ - for (ese = static_cast(selected_orig.first); ese; ese = ese->next) { + LISTBASE_FOREACH (BMEditSelection *, ese, &selected_orig) { BMEdge *e_curr = (BMEdge *)ese->ele; BMEdge *e_prev = ese->prev ? (BMEdge *)ese->prev->ele : nullptr; BMLoop *l_curr; @@ -5068,9 +5067,9 @@ static bool edbm_fill_grid_prepare(BMesh *bm, int offset, int *span_p, const boo } else { /* find the vertex with the best angle (a corner vertex) */ - LinkData *v_link, *v_link_best = nullptr; + LinkData *v_link_best = nullptr; float angle_best = -1.0f; - for (v_link = static_cast(verts->first); v_link; v_link = v_link->next) { + LISTBASE_FOREACH (LinkData *, v_link, verts) { const float angle = edbm_fill_grid_vert_tag_angle(static_cast(v_link->data)); if ((angle > angle_best) || (v_link_best == nullptr)) { angle_best = angle; diff --git a/source/blender/editors/metaball/mball_edit.cc b/source/blender/editors/metaball/mball_edit.cc index b32c64c2070..fc51fe3f2fd 100644 --- a/source/blender/editors/metaball/mball_edit.cc +++ b/source/blender/editors/metaball/mball_edit.cc @@ -220,9 +220,8 @@ static void mball_select_similar_type_get( Object *obedit, MetaBall *mb, int type, KDTree_1d *tree_1d, KDTree_3d *tree_3d) { float tree_entry[3] = {0.0f, 0.0f, 0.0f}; - MetaElem *ml; int tree_index = 0; - for (ml = static_cast(mb->editelems->first); ml; ml = ml->next) { + LISTBASE_FOREACH (MetaElem *, ml, mb->editelems) { if (ml->flag & SELECT) { switch (type) { case SIMMBALL_RADIUS: { @@ -267,9 +266,8 @@ static bool mball_select_similar_type(Object *obedit, const KDTree_3d *tree_3d, const float thresh) { - MetaElem *ml; bool changed = false; - for (ml = static_cast(mb->editelems->first); ml; ml = ml->next) { + LISTBASE_FOREACH (MetaElem *, ml, mb->editelems) { bool select = false; switch (type) { case SIMMBALL_RADIUS: { @@ -359,8 +357,7 @@ static int mball_select_similar_exec(bContext *C, wmOperator *op) switch (type) { case SIMMBALL_TYPE: { - MetaElem *ml; - for (ml = static_cast(mb->editelems->first); ml; ml = ml->next) { + LISTBASE_FOREACH (MetaElem *, ml, mb->editelems) { if (ml->flag & SELECT) { short mball_type = 1 << (ml->type + 1); type_ref |= mball_type; @@ -395,8 +392,7 @@ static int mball_select_similar_exec(bContext *C, wmOperator *op) switch (type) { case SIMMBALL_TYPE: { - MetaElem *ml; - for (ml = static_cast(mb->editelems->first); ml; ml = ml->next) { + LISTBASE_FOREACH (MetaElem *, ml, mb->editelems) { short mball_type = 1 << (ml->type + 1); if (mball_type & type_ref) { ml->flag |= SELECT; diff --git a/source/blender/editors/object/object_bake.cc b/source/blender/editors/object/object_bake.cc index 6503ddb6fad..cd2a27f7e44 100644 --- a/source/blender/editors/object/object_bake.cc +++ b/source/blender/editors/object/object_bake.cc @@ -466,14 +466,13 @@ static void init_multiresbake_job(bContext *C, MultiresBakeJob *bkj) static void multiresbake_startjob(void *bkv, bool *stop, bool *do_update, float *progress) { - MultiresBakerJobData *data; MultiresBakeJob *bkj = static_cast(bkv); int baked_objects = 0, tot_obj; tot_obj = BLI_listbase_count(&bkj->data); if (bkj->bake_clear) { /* clear images */ - for (data = static_cast(bkj->data.first); data; data = data->next) { + LISTBASE_FOREACH (MultiresBakerJobData *, data, &bkj->data) { ClearFlag clear_flag = ClearFlag(0); if (bkj->mode == RE_BAKE_NORMALS) { @@ -487,7 +486,7 @@ static void multiresbake_startjob(void *bkv, bool *stop, bool *do_update, float } } - for (data = static_cast(bkj->data.first); data; data = data->next) { + LISTBASE_FOREACH (MultiresBakerJobData *, data, &bkj->data) { MultiresBakeRender bkr = {nullptr}; /* copy data stored in job descriptor */ @@ -531,7 +530,6 @@ static void multiresbake_freejob(void *bkv) { MultiresBakeJob *bkj = static_cast(bkv); MultiresBakerJobData *data, *next; - LinkData *link; data = static_cast(bkj->data.first); while (data) { @@ -540,7 +538,7 @@ static void multiresbake_freejob(void *bkv) data->hires_dm->release(data->hires_dm); /* delete here, since this delete will be called from main thread */ - for (link = static_cast(data->images.first); link; link = link->next) { + LISTBASE_FOREACH (LinkData *, link, &data->images) { Image *ima = (Image *)link->data; BKE_image_partial_update_mark_full_update(ima); } diff --git a/source/blender/editors/object/object_bake_api.cc b/source/blender/editors/object/object_bake_api.cc index e2a1622d0cf..90df00bccdb 100644 --- a/source/blender/editors/object/object_bake_api.cc +++ b/source/blender/editors/object/object_bake_api.cc @@ -645,8 +645,6 @@ static bool bake_objects_check(Main *bmain, const bool is_selected_to_active, const eBakeTarget target) { - CollectionPointerLink *link; - /* error handling and tag (in case multiple materials share the same image) */ BKE_main_id_tag_idcode(bmain, ID_IM, LIB_TAG_DOIT, false); @@ -657,8 +655,7 @@ static bool bake_objects_check(Main *bmain, return false; } - for (link = static_cast(selected_objects->first); link; - link = link->next) { + LISTBASE_FOREACH (CollectionPointerLink *, link, selected_objects) { Object *ob_iter = (Object *)link->ptr.data; if (ob_iter == ob) { @@ -687,8 +684,7 @@ static bool bake_objects_check(Main *bmain, return false; } - for (link = static_cast(selected_objects->first); link; - link = link->next) { + LISTBASE_FOREACH (CollectionPointerLink *, link, selected_objects) { if (!bake_object_check( scene, view_layer, static_cast(link->ptr.data), target, reports)) { return false; @@ -1448,11 +1444,9 @@ static int bake(const BakeAPIRender *bkr, } if (bkr->is_selected_to_active) { - CollectionPointerLink *link; tot_highpoly = 0; - for (link = static_cast(selected_objects->first); link; - link = link->next) { + LISTBASE_FOREACH (CollectionPointerLink *, link, selected_objects) { Object *ob_iter = static_cast(link->ptr.data); if (ob_iter == ob_low) { @@ -1908,11 +1902,8 @@ static int bake_exec(bContext *C, wmOperator *op) result = bake(&bkr, bkr.ob, &bkr.selected_objects, bkr.reports); } else { - CollectionPointerLink *link; bkr.is_clear = bkr.is_clear && BLI_listbase_is_single(&bkr.selected_objects); - for (link = static_cast(bkr.selected_objects.first); link; - link = link->next) - { + LISTBASE_FOREACH (CollectionPointerLink *, link, &bkr.selected_objects) { Object *ob_iter = static_cast(link->ptr.data); result = bake(&bkr, ob_iter, nullptr, bkr.reports); } @@ -1964,11 +1955,8 @@ static void bake_startjob(void *bkv, bool * /*stop*/, bool *do_update, float *pr bkr->result = bake(bkr, bkr->ob, &bkr->selected_objects, bkr->reports); } else { - CollectionPointerLink *link; bkr->is_clear = bkr->is_clear && BLI_listbase_is_single(&bkr->selected_objects); - for (link = static_cast(bkr->selected_objects.first); link; - link = link->next) - { + LISTBASE_FOREACH (CollectionPointerLink *, link, &bkr->selected_objects) { Object *ob_iter = static_cast(link->ptr.data); bkr->result = bake(bkr, ob_iter, nullptr, bkr->reports); diff --git a/source/blender/editors/object/object_constraint.cc b/source/blender/editors/object/object_constraint.cc index 28461365af8..39849cdc21d 100644 --- a/source/blender/editors/object/object_constraint.cc +++ b/source/blender/editors/object/object_constraint.cc @@ -121,13 +121,10 @@ ListBase *ED_object_constraint_list_from_constraint(Object *ob, /* if armature, try pose bones too */ if (ob->pose) { - bPoseChannel *pchan; - /* try each bone in order * NOTE: it's not possible to directly look up the active bone yet, so this will have to do */ - for (pchan = static_cast(ob->pose->chanbase.first); pchan; pchan = pchan->next) - { + LISTBASE_FOREACH (bPoseChannel *, pchan, &ob->pose->chanbase) { if (BLI_findindex(&pchan->constraints, con) != -1) { if (r_pchan) { @@ -294,7 +291,6 @@ static void test_constraint( Main *bmain, Object *owner, bPoseChannel *pchan, bConstraint *con, int type) { ListBase targets = {nullptr, nullptr}; - bConstraintTarget *ct; bool check_targets = true; /* clear disabled-flag first */ @@ -469,7 +465,7 @@ static void test_constraint( /* Check targets for constraints */ if (check_targets && BKE_constraint_targets_get(con, &targets)) { /* disable and clear constraints targets that are incorrect */ - for (ct = static_cast(targets.first); ct; ct = ct->next) { + LISTBASE_FOREACH (bConstraintTarget *, ct, &targets) { /* general validity checks (for those constraints that need this) */ if (BKE_object_exists_check(bmain, ct->tar) == 0) { /* object doesn't exist, but constraint requires target */ @@ -573,7 +569,6 @@ static int constraint_type_get(Object *owner, bPoseChannel *pchan) */ static void test_constraints(Main *bmain, Object *ob, bPoseChannel *pchan) { - bConstraint *curcon; ListBase *conlist = nullptr; int type; @@ -595,7 +590,7 @@ static void test_constraints(Main *bmain, Object *ob, bPoseChannel *pchan) /* Check all constraints - is constraint valid? */ if (conlist) { - for (curcon = static_cast(conlist->first); curcon; curcon = curcon->next) { + LISTBASE_FOREACH (bConstraint *, curcon, conlist) { test_constraint(bmain, ob, pchan, curcon, type); } } @@ -608,10 +603,7 @@ void object_test_constraints(Main *bmain, Object *ob) } if (ob->type == OB_ARMATURE && ob->pose) { - bPoseChannel *pchan; - - for (pchan = static_cast(ob->pose->chanbase.first); pchan; pchan = pchan->next) - { + LISTBASE_FOREACH (bPoseChannel *, pchan, &ob->pose->chanbase) { if (pchan->constraints.first) { test_constraints(bmain, ob, pchan); } @@ -626,9 +618,7 @@ static void object_test_constraint(Main *bmain, Object *ob, bConstraint *con) test_constraint(bmain, ob, nullptr, con, CONSTRAINT_OBTYPE_OBJECT); } else { - bPoseChannel *pchan; - for (pchan = static_cast(ob->pose->chanbase.first); pchan; - pchan = pchan->next) { + LISTBASE_FOREACH (bPoseChannel *, pchan, &ob->pose->chanbase) { if (BLI_findindex(&pchan->constraints, con) != -1) { test_constraint(bmain, ob, pchan, con, CONSTRAINT_OBTYPE_BONE); break; diff --git a/source/blender/editors/object/object_data_transfer.cc b/source/blender/editors/object/object_data_transfer.cc index c1a1c6f15d0..42cb00dd785 100644 --- a/source/blender/editors/object/object_data_transfer.cc +++ b/source/blender/editors/object/object_data_transfer.cc @@ -357,16 +357,13 @@ static void data_transfer_exec_preprocess_objects(bContext *C, ListBase *ctx_objects, const bool reverse_transfer) { - CollectionPointerLink *ctx_ob; CTX_data_selected_editable_objects(C, ctx_objects); if (reverse_transfer) { return; /* Nothing else to do in this case... */ } - for (ctx_ob = static_cast(ctx_objects->first); ctx_ob; - ctx_ob = ctx_ob->next) - { + LISTBASE_FOREACH (CollectionPointerLink *, ctx_ob, ctx_objects) { Object *ob = static_cast(ctx_ob->ptr.data); Mesh *me; if ((ob == ob_src) || (ob->type != OB_MESH)) { @@ -428,7 +425,6 @@ static int data_transfer_exec(bContext *C, wmOperator *op) Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); ListBase ctx_objects; - CollectionPointerLink *ctx_ob_dst; bool changed = false; @@ -489,9 +485,7 @@ static int data_transfer_exec(bContext *C, wmOperator *op) data_transfer_exec_preprocess_objects(C, op, ob_src, &ctx_objects, reverse_transfer); - for (ctx_ob_dst = static_cast(ctx_objects.first); ctx_ob_dst; - ctx_ob_dst = ctx_ob_dst->next) - { + LISTBASE_FOREACH (CollectionPointerLink *, ctx_ob_dst, &ctx_objects) { Object *ob_dst = static_cast(ctx_ob_dst->ptr.data); if (reverse_transfer) { @@ -868,7 +862,6 @@ static int datalayout_transfer_exec(bContext *C, wmOperator *op) Object *ob_src = ob_act; ListBase ctx_objects; - CollectionPointerLink *ctx_ob_dst; const int data_type = RNA_enum_get(op->ptr, "data_type"); const bool use_delete = RNA_boolean_get(op->ptr, "use_delete"); @@ -888,9 +881,7 @@ static int datalayout_transfer_exec(bContext *C, wmOperator *op) data_transfer_exec_preprocess_objects(C, op, ob_src, &ctx_objects, false); - for (ctx_ob_dst = static_cast(ctx_objects.first); ctx_ob_dst; - ctx_ob_dst = ctx_ob_dst->next) - { + LISTBASE_FOREACH (CollectionPointerLink *, ctx_ob_dst, &ctx_objects) { Object *ob_dst = static_cast(ctx_ob_dst->ptr.data); if (data_transfer_exec_is_object_valid(op, ob_src, ob_dst, false)) { BKE_object_data_transfer_layout(depsgraph, diff --git a/source/blender/editors/object/object_relations.cc b/source/blender/editors/object/object_relations.cc index 1fb042195dc..70225b815b7 100644 --- a/source/blender/editors/object/object_relations.cc +++ b/source/blender/editors/object/object_relations.cc @@ -2161,9 +2161,7 @@ static bool make_local_all__instance_indirect_unused(Main *bmain, static void make_local_animdata_tag_strips(ListBase *strips) { - NlaStrip *strip; - - for (strip = static_cast(strips->first); strip; strip = strip->next) { + LISTBASE_FOREACH (NlaStrip *, strip, strips) { if (strip->act) { strip->act->id.tag &= ~LIB_TAG_PRE_EXISTING; } @@ -2208,7 +2206,6 @@ static void make_local_material_tag(Material *ma) static int make_local_exec(bContext *C, wmOperator *op) { Main *bmain = CTX_data_main(C); - ParticleSystem *psys; Material *ma, ***matarar; const int mode = RNA_enum_get(op->ptr, "type"); int a; @@ -2241,8 +2238,7 @@ static int make_local_exec(bContext *C, wmOperator *op) ob->id.tag &= ~LIB_TAG_PRE_EXISTING; make_local_animdata_tag(BKE_animdata_from_id(&ob->id)); - for (psys = static_cast(ob->particlesystem.first); psys; psys = psys->next) - { + LISTBASE_FOREACH (ParticleSystem *, psys, &ob->particlesystem) { psys->part->id.tag &= ~LIB_TAG_PRE_EXISTING; } diff --git a/source/blender/editors/object/object_select.cc b/source/blender/editors/object/object_select.cc index b57b91f571b..4809ed367c1 100644 --- a/source/blender/editors/object/object_select.cc +++ b/source/blender/editors/object/object_select.cc @@ -537,11 +537,7 @@ static bool object_select_all_by_particle(bContext *C, Object *ob) CTX_DATA_BEGIN (C, Base *, base, visible_bases) { if (((base->flag & BASE_SELECTED) == 0) && ((base->flag & BASE_SELECTABLE) != 0)) { /* Loop through other particles. */ - ParticleSystem *psys; - - for (psys = static_cast(base->object->particlesystem.first); psys; - psys = psys->next) - { + LISTBASE_FOREACH (ParticleSystem *, psys, &base->object->particlesystem) { if (psys->part == psys_act->part) { ED_object_base_select(base, BA_SELECT); changed = true; @@ -872,10 +868,9 @@ static bool select_grouped_object_hooks(bContext *C, Object *ob) bool changed = false; Base *base; - ModifierData *md; HookModifierData *hmd; - for (md = static_cast(ob->modifiers.first); md; md = md->next) { + LISTBASE_FOREACH (ModifierData *, md, &ob->modifiers) { if (md->type == eModifierType_Hook) { hmd = (HookModifierData *)md; if (hmd->object) { @@ -998,12 +993,9 @@ static bool select_grouped_keyingset(bContext *C, Object * /*ob*/, ReportList *r CTX_DATA_BEGIN (C, Base *, base, selectable_bases) { /* only check for this object if it isn't selected already, to limit time wasted */ if ((base->flag & BASE_SELECTED) == 0) { - KS_Path *ksp; - - /* this is the slow way... we could end up with > 500 items here, - * with none matching, but end up doing this on 1000 objects... - */ - for (ksp = static_cast(ks->paths.first); ksp; ksp = ksp->next) { + /* This is the slow way... we could end up with > 500 items here, + * with none matching, but end up doing this on 1000 objects. */ + LISTBASE_FOREACH (KS_Path *, ksp, &ks->paths) { /* if id matches, select then stop looping (match found) */ if (ksp->id == (ID *)base->object) { ED_object_base_select(base, BA_SELECT); @@ -1326,7 +1318,6 @@ static bool object_select_more_less(bContext *C, const bool select) } ListBase ctx_base_list; - CollectionPointerLink *ctx_base; CTX_data_selectable_bases(C, &ctx_base_list); CTX_DATA_BEGIN (C, Object *, ob, selected_objects) { @@ -1334,9 +1325,7 @@ static bool object_select_more_less(bContext *C, const bool select) } CTX_DATA_END; - for (ctx_base = static_cast(ctx_base_list.first); ctx_base; - ctx_base = ctx_base->next) - { + LISTBASE_FOREACH (CollectionPointerLink *, ctx_base, &ctx_base_list) { Object *ob = ((Base *)ctx_base->ptr.data)->object; if (ob->parent) { if ((ob->flag & OB_DONE) != (ob->parent->flag & OB_DONE)) { @@ -1350,9 +1339,7 @@ static bool object_select_more_less(bContext *C, const bool select) const short select_mode = select ? BA_SELECT : BA_DESELECT; const short select_flag = select ? BASE_SELECTED : 0; - for (ctx_base = static_cast(ctx_base_list.first); ctx_base; - ctx_base = ctx_base->next) - { + LISTBASE_FOREACH (CollectionPointerLink *, ctx_base, &ctx_base_list) { Base *base = static_cast(ctx_base->ptr.data); Object *ob = base->object; if ((ob->id.tag & LIB_TAG_DOIT) && ((base->flag & BASE_SELECTED) != select_flag)) { @@ -1446,10 +1433,7 @@ static int object_select_random_exec(bContext *C, wmOperator *op) int elem_map_len = 0; Base **elem_map = static_cast(MEM_mallocN(sizeof(*elem_map) * tot, __func__)); - CollectionPointerLink *ctx_link; - for (ctx_link = static_cast(ctx_data_list.first); ctx_link; - ctx_link = ctx_link->next) - { + LISTBASE_FOREACH (CollectionPointerLink *, ctx_link, &ctx_data_list) { elem_map[elem_map_len++] = static_cast(ctx_link->ptr.data); } BLI_freelistN(&ctx_data_list); diff --git a/source/blender/editors/object/object_shader_fx.cc b/source/blender/editors/object/object_shader_fx.cc index 372a4eed437..3147d03bddf 100644 --- a/source/blender/editors/object/object_shader_fx.cc +++ b/source/blender/editors/object/object_shader_fx.cc @@ -100,9 +100,7 @@ static bool UNUSED_FUNCTION(object_has_shaderfx)(const Object *ob, const ShaderFxData *exclude, ShaderFxType type) { - ShaderFxData *fx; - - for (fx = static_cast(ob->shader_fx.first); fx; fx = fx->next) { + LISTBASE_FOREACH (ShaderFxData *, fx, &ob->shader_fx) { if ((fx != exclude) && (fx->type == type)) { return true; } diff --git a/source/blender/editors/object/object_shapekey.cc b/source/blender/editors/object/object_shapekey.cc index 76a62e788b7..3a63f45f71c 100644 --- a/source/blender/editors/object/object_shapekey.cc +++ b/source/blender/editors/object/object_shapekey.cc @@ -394,7 +394,7 @@ static int shape_key_clear_exec(bContext *C, wmOperator * /*op*/) return OPERATOR_CANCELLED; } - for (kb = static_cast(key->block.first); kb; kb = kb->next) { + LISTBASE_FOREACH (KeyBlock *, kb, &key->block) { kb->curval = 0.0f; } @@ -431,7 +431,7 @@ static int shape_key_retime_exec(bContext *C, wmOperator * /*op*/) return OPERATOR_CANCELLED; } - for (kb = static_cast(key->block.first); kb; kb = kb->next) { + LISTBASE_FOREACH (KeyBlock *, kb, &key->block) { kb->pos = cfra; cfra += 0.1f; } diff --git a/source/blender/editors/object/object_vgroup.cc b/source/blender/editors/object/object_vgroup.cc index 372a4f17da5..48c0c75c2bc 100644 --- a/source/blender/editors/object/object_vgroup.cc +++ b/source/blender/editors/object/object_vgroup.cc @@ -3573,9 +3573,7 @@ static char *vgroup_init_remap(Object *ob) char *name; name = name_array; - for (const bDeformGroup *def = static_cast(defbase->first); def; - def = def->next) - { + LISTBASE_FOREACH (const bDeformGroup *, def, defbase) { BLI_strncpy(name, def->name, MAX_VGROUP_NAME); name += MAX_VGROUP_NAME; } @@ -3708,8 +3706,7 @@ static void vgroup_sort_bone_hierarchy(Object *ob, ListBase *bonebase) ListBase *defbase = BKE_object_defgroup_list_mutable(ob); if (bonebase != nullptr) { - Bone *bone; - for (bone = static_cast(bonebase->last); bone; bone = bone->prev) { + LISTBASE_FOREACH_BACKWARD (Bone *, bone, bonebase) { bDeformGroup *dg = BKE_object_defgroup_find_name(ob, bone->name); vgroup_sort_bone_hierarchy(ob, &bone->childbase); diff --git a/source/blender/editors/physics/particle_boids.cc b/source/blender/editors/physics/particle_boids.cc index 4ff01dd53cb..2fb0d3fea84 100644 --- a/source/blender/editors/physics/particle_boids.cc +++ b/source/blender/editors/physics/particle_boids.cc @@ -48,7 +48,7 @@ static int rule_add_exec(bContext *C, wmOperator *op) state = boid_get_current_state(part->boids); - for (rule = static_cast(state->rules.first); rule; rule = rule->next) { + LISTBASE_FOREACH (BoidRule *, rule, &state->rules) { rule->flag &= ~BOIDRULE_CURRENT; } @@ -92,7 +92,7 @@ static int rule_del_exec(bContext *C, wmOperator * /*op*/) state = boid_get_current_state(part->boids); - for (rule = static_cast(state->rules.first); rule; rule = rule->next) { + LISTBASE_FOREACH (BoidRule *, rule, &state->rules) { if (rule->flag & BOIDRULE_CURRENT) { BLI_remlink(&state->rules, rule); MEM_freeN(rule); @@ -130,7 +130,6 @@ static int rule_move_up_exec(bContext *C, wmOperator * /*op*/) { PointerRNA ptr = CTX_data_pointer_get_type(C, "particle_settings", &RNA_ParticleSettings); ParticleSettings *part = static_cast(ptr.data); - BoidRule *rule; BoidState *state; if (!part || part->phystype != PART_PHYS_BOIDS) { @@ -138,7 +137,7 @@ static int rule_move_up_exec(bContext *C, wmOperator * /*op*/) } state = boid_get_current_state(part->boids); - for (rule = static_cast(state->rules.first); rule; rule = rule->next) { + LISTBASE_FOREACH (BoidRule *, rule, &state->rules) { if (rule->flag & BOIDRULE_CURRENT && rule->prev) { BLI_remlink(&state->rules, rule); BLI_insertlinkbefore(&state->rules, rule->prev, rule); @@ -167,7 +166,6 @@ static int rule_move_down_exec(bContext *C, wmOperator * /*op*/) { PointerRNA ptr = CTX_data_pointer_get_type(C, "particle_settings", &RNA_ParticleSettings); ParticleSettings *part = static_cast(ptr.data); - BoidRule *rule; BoidState *state; if (!part || part->phystype != PART_PHYS_BOIDS) { @@ -175,7 +173,7 @@ static int rule_move_down_exec(bContext *C, wmOperator * /*op*/) } state = boid_get_current_state(part->boids); - for (rule = static_cast(state->rules.first); rule; rule = rule->next) { + LISTBASE_FOREACH (BoidRule *, rule, &state->rules) { if (rule->flag & BOIDRULE_CURRENT && rule->next) { BLI_remlink(&state->rules, rule); BLI_insertlinkafter(&state->rules, rule->next, rule); @@ -211,7 +209,7 @@ static int state_add_exec(bContext *C, wmOperator * /*op*/) return OPERATOR_CANCELLED; } - for (state = static_cast(part->boids->states.first); state; state = state->next) { + LISTBASE_FOREACH (BoidState *, state, &part->boids->states) { state->flag &= ~BOIDSTATE_CURRENT; } @@ -247,7 +245,7 @@ static int state_del_exec(bContext *C, wmOperator * /*op*/) return OPERATOR_CANCELLED; } - for (state = static_cast(part->boids->states.first); state; state = state->next) { + LISTBASE_FOREACH (BoidState *, state, &part->boids->states) { if (state->flag & BOIDSTATE_CURRENT) { BLI_remlink(&part->boids->states, state); MEM_freeN(state); @@ -292,7 +290,6 @@ static int state_move_up_exec(bContext *C, wmOperator * /*op*/) PointerRNA ptr = CTX_data_pointer_get_type(C, "particle_settings", &RNA_ParticleSettings); ParticleSettings *part = static_cast(ptr.data); BoidSettings *boids; - BoidState *state; if (!part || part->phystype != PART_PHYS_BOIDS) { return OPERATOR_CANCELLED; @@ -300,7 +297,7 @@ static int state_move_up_exec(bContext *C, wmOperator * /*op*/) boids = part->boids; - for (state = static_cast(boids->states.first); state; state = state->next) { + LISTBASE_FOREACH (BoidState *, state, &boids->states) { if (state->flag & BOIDSTATE_CURRENT && state->prev) { BLI_remlink(&boids->states, state); BLI_insertlinkbefore(&boids->states, state->prev, state); @@ -328,7 +325,6 @@ static int state_move_down_exec(bContext *C, wmOperator * /*op*/) PointerRNA ptr = CTX_data_pointer_get_type(C, "particle_settings", &RNA_ParticleSettings); ParticleSettings *part = static_cast(ptr.data); BoidSettings *boids; - BoidState *state; if (!part || part->phystype != PART_PHYS_BOIDS) { return OPERATOR_CANCELLED; @@ -336,7 +332,7 @@ static int state_move_down_exec(bContext *C, wmOperator * /*op*/) boids = part->boids; - for (state = static_cast(boids->states.first); state; state = state->next) { + LISTBASE_FOREACH (BoidState *, state, &boids->states) { if (state->flag & BOIDSTATE_CURRENT && state->next) { BLI_remlink(&boids->states, state); BLI_insertlinkafter(&boids->states, state->next, state); diff --git a/source/blender/editors/physics/particle_edit.cc b/source/blender/editors/physics/particle_edit.cc index cde4f4c7be0..5032f93f249 100644 --- a/source/blender/editors/physics/particle_edit.cc +++ b/source/blender/editors/physics/particle_edit.cc @@ -5405,18 +5405,17 @@ void PE_create_particle_edit( update_world_cos(ob, edit); } else { - PTCacheMem *pm; int totframe = 0; cache->edit = edit; cache->free_edit = PE_free_ptcache_edit; edit->psys = nullptr; - for (pm = static_cast(cache->mem_cache.first); pm; pm = pm->next) { + LISTBASE_FOREACH (PTCacheMem *, pm, &cache->mem_cache) { totframe++; } - for (pm = static_cast(cache->mem_cache.first); pm; pm = pm->next) { + LISTBASE_FOREACH (PTCacheMem *, pm, &cache->mem_cache) { LOOP_POINTS { void *cur[BPHYS_TOT_DATA]; if (BKE_ptcache_mem_pointers_seek(p, pm, cur) == 0) { diff --git a/source/blender/editors/physics/particle_object.cc b/source/blender/editors/physics/particle_object.cc index 2321c204eb9..dbfa94c0c57 100644 --- a/source/blender/editors/physics/particle_object.cc +++ b/source/blender/editors/physics/particle_object.cc @@ -423,14 +423,13 @@ static int dupliob_move_up_exec(bContext *C, wmOperator * /*op*/) PointerRNA ptr = CTX_data_pointer_get_type(C, "particle_system", &RNA_ParticleSystem); ParticleSystem *psys = static_cast(ptr.data); ParticleSettings *part; - ParticleDupliWeight *dw; if (!psys) { return OPERATOR_CANCELLED; } part = psys->part; - for (dw = static_cast(part->instance_weights.first); dw; dw = dw->next) { + LISTBASE_FOREACH (ParticleDupliWeight *, dw, &part->instance_weights) { if (dw->flag & PART_DUPLIW_CURRENT && dw->prev) { BLI_remlink(&part->instance_weights, dw); BLI_insertlinkbefore(&part->instance_weights, dw->prev, dw); @@ -463,13 +462,12 @@ static int copy_particle_dupliob_exec(bContext *C, wmOperator * /*op*/) PointerRNA ptr = CTX_data_pointer_get_type(C, "particle_system", &RNA_ParticleSystem); ParticleSystem *psys = static_cast(ptr.data); ParticleSettings *part; - ParticleDupliWeight *dw; if (!psys) { return OPERATOR_CANCELLED; } part = psys->part; - for (dw = static_cast(part->instance_weights.first); dw; dw = dw->next) { + LISTBASE_FOREACH (ParticleDupliWeight *, dw, &part->instance_weights) { if (dw->flag & PART_DUPLIW_CURRENT) { dw->flag &= ~PART_DUPLIW_CURRENT; dw = static_cast(MEM_dupallocN(dw)); @@ -511,7 +509,7 @@ static int remove_particle_dupliob_exec(bContext *C, wmOperator * /*op*/) } part = psys->part; - for (dw = static_cast(part->instance_weights.first); dw; dw = dw->next) { + LISTBASE_FOREACH (ParticleDupliWeight *, dw, &part->instance_weights) { if (dw->flag & PART_DUPLIW_CURRENT) { BLI_remlink(&part->instance_weights, dw); MEM_freeN(dw); @@ -551,14 +549,13 @@ static int dupliob_move_down_exec(bContext *C, wmOperator * /*op*/) PointerRNA ptr = CTX_data_pointer_get_type(C, "particle_system", &RNA_ParticleSystem); ParticleSystem *psys = static_cast(ptr.data); ParticleSettings *part; - ParticleDupliWeight *dw; if (!psys) { return OPERATOR_CANCELLED; } part = psys->part; - for (dw = static_cast(part->instance_weights.first); dw; dw = dw->next) { + LISTBASE_FOREACH (ParticleDupliWeight *, dw, &part->instance_weights) { if (dw->flag & PART_DUPLIW_CURRENT && dw->next) { BLI_remlink(&part->instance_weights, dw); BLI_insertlinkafter(&part->instance_weights, dw->next, dw); @@ -653,7 +650,7 @@ static int disconnect_hair_exec(bContext *C, wmOperator *op) } if (all) { - for (psys = static_cast(ob->particlesystem.first); psys; psys = psys->next) { + LISTBASE_FOREACH (ParticleSystem *, psys, &ob->particlesystem) { disconnect_hair(depsgraph, scene, ob, psys); } } @@ -951,7 +948,7 @@ static int connect_hair_exec(bContext *C, wmOperator *op) } if (all) { - for (psys = static_cast(ob->particlesystem.first); psys; psys = psys->next) { + LISTBASE_FOREACH (ParticleSystem *, psys, &ob->particlesystem) { any_connected |= connect_hair(depsgraph, scene, ob, psys); } } diff --git a/source/blender/editors/physics/physics_pointcache.cc b/source/blender/editors/physics/physics_pointcache.cc index d0a4cc1ae4c..bc3fd63da42 100644 --- a/source/blender/editors/physics/physics_pointcache.cc +++ b/source/blender/editors/physics/physics_pointcache.cc @@ -268,13 +268,12 @@ static void ptcache_bake_cancel(bContext *C, wmOperator *op) static int ptcache_free_bake_all_exec(bContext *C, wmOperator * /*op*/) { Scene *scene = CTX_data_scene(C); - PTCacheID *pid; ListBase pidlist; FOREACH_SCENE_OBJECT_BEGIN (scene, ob) { BKE_ptcache_ids_from_object(&pidlist, ob, scene, MAX_DUPLI_RECUR); - for (pid = static_cast(pidlist.first); pid; pid = pid->next) { + LISTBASE_FOREACH (PTCacheID *, pid, &pidlist) { ptcache_free_bake(pid->cache); } diff --git a/source/blender/editors/render/render_internal.cc b/source/blender/editors/render/render_internal.cc index 4a022bca06b..c8b6ec58731 100644 --- a/source/blender/editors/render/render_internal.cc +++ b/source/blender/editors/render/render_internal.cc @@ -743,8 +743,7 @@ static void render_image_restore_layer(RenderJob *rj) /* Only ever 1 `wm`. */ LISTBASE_FOREACH (wmWindowManager *, wm, &rj->main->wm) { - wmWindow *win; - for (win = static_cast(wm->windows.first); win; win = win->next) { + LISTBASE_FOREACH (wmWindow *, win, &wm->windows) { const bScreen *screen = WM_window_get_active_screen(win); LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) { diff --git a/source/blender/editors/render/render_opengl.cc b/source/blender/editors/render/render_opengl.cc index 9607065fdf3..653308db490 100644 --- a/source/blender/editors/render/render_opengl.cc +++ b/source/blender/editors/render/render_opengl.cc @@ -225,7 +225,7 @@ static void screen_opengl_views_setup(OGLRender *oglrender) } /* create all the views that are needed */ - for (srv = static_cast(rd->views.first); srv; srv = srv->next) { + LISTBASE_FOREACH (SceneRenderView *, srv, &rd->views) { if (BKE_scene_multiview_is_render_view_active(rd, srv) == false) { continue; } diff --git a/source/blender/editors/render/render_preview.cc b/source/blender/editors/render/render_preview.cc index 9f2691aa619..abd879fcf4f 100644 --- a/source/blender/editors/render/render_preview.cc +++ b/source/blender/editors/render/render_preview.cc @@ -1557,11 +1557,8 @@ static void icon_preview_startjob_all_sizes(void *customdata, float *progress) { IconPreview *ip = (IconPreview *)customdata; - IconPreviewSize *cur_size; - for (cur_size = static_cast(ip->sizes.first); cur_size; - cur_size = cur_size->next) - { + LISTBASE_FOREACH (IconPreviewSize *, cur_size, &ip->sizes) { PreviewImage *prv = static_cast(ip->owner); /* Is this a render job or a deferred loading job? */ const ePreviewRenderMethod pr_method = (prv->tag & PRV_TAG_DEFFERED) ? PR_ICON_DEFERRED : diff --git a/source/blender/editors/render/render_shading.cc b/source/blender/editors/render/render_shading.cc index 163bc99e171..e1f048defd3 100644 --- a/source/blender/editors/render/render_shading.cc +++ b/source/blender/editors/render/render_shading.cc @@ -328,11 +328,10 @@ static int material_slot_assign_exec(bContext *C, wmOperator * /*op*/) } } else if (ELEM(ob->type, OB_CURVES_LEGACY, OB_SURF)) { - Nurb *nu; ListBase *nurbs = BKE_curve_editNurbs_get((Curve *)ob->data); if (nurbs) { - for (nu = static_cast(nurbs->first); nu; nu = nu->next) { + LISTBASE_FOREACH (Nurb *, nu, nurbs) { if (ED_curve_nurb_select_check(v3d, nu)) { changed = true; nu->mat_nr = mat_nr_active; @@ -430,13 +429,12 @@ static int material_slot_de_select(bContext *C, bool select) } else if (ELEM(ob->type, OB_CURVES_LEGACY, OB_SURF)) { ListBase *nurbs = BKE_curve_editNurbs_get((Curve *)ob->data); - Nurb *nu; BPoint *bp; BezTriple *bezt; int a; if (nurbs) { - for (nu = static_cast(nurbs->first); nu; nu = nu->next) { + LISTBASE_FOREACH (Nurb *, nu, nurbs) { if (nu->mat_nr == mat_nr_active) { if (nu->bezt) { a = nu->pntsu; diff --git a/source/blender/editors/render/render_update.cc b/source/blender/editors/render/render_update.cc index ae8f35aa09d..05f59d5fbe6 100644 --- a/source/blender/editors/render/render_update.cc +++ b/source/blender/editors/render/render_update.cc @@ -153,14 +153,13 @@ void ED_render_scene_update(const DEGEditorUpdateContext *update_ctx, const bool void ED_render_engine_area_exit(Main *bmain, ScrArea *area) { /* clear all render engines in this area */ - ARegion *region; wmWindowManager *wm = static_cast(bmain->wm.first); if (area->spacetype != SPACE_VIEW3D) { return; } - for (region = static_cast(area->regionbase.first); region; region = region->next) { + LISTBASE_FOREACH (ARegion *, region, &area->regionbase) { if (region->regiontype != RGN_TYPE_WINDOW || !(region->regiondata)) { continue; } @@ -244,8 +243,6 @@ static void lamp_changed(Main * /*bmain*/, Light *la) static void texture_changed(Main *bmain, Tex *tex) { Scene *scene; - ViewLayer *view_layer; - bNode *node; /* icons */ BKE_icon_changed(BKE_icon_id_ensure(&tex->id)); @@ -254,14 +251,12 @@ static void texture_changed(Main *bmain, Tex *tex) scene = static_cast(scene->id.next)) { /* paint overlays */ - for (view_layer = static_cast(scene->view_layers.first); view_layer; - view_layer = view_layer->next) - { + LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) { BKE_paint_invalidate_overlay_tex(scene, view_layer, tex); } /* find compositing nodes */ if (scene->use_nodes && scene->nodetree) { - for (node = static_cast(scene->nodetree->nodes.first); node; node = node->next) { + LISTBASE_FOREACH (bNode *, node, &scene->nodetree->nodes) { if (node->id == &tex->id) { ED_node_tag_update_id(&scene->id); } diff --git a/source/blender/editors/render/render_view.cc b/source/blender/editors/render/render_view.cc index 9e8937f8363..6b525856183 100644 --- a/source/blender/editors/render/render_view.cc +++ b/source/blender/editors/render/render_view.cc @@ -45,11 +45,11 @@ static ScrArea *biggest_non_image_area(bContext *C) { bScreen *screen = CTX_wm_screen(C); - ScrArea *area, *big = nullptr; + ScrArea *big = nullptr; int size, maxsize = 0, bwmaxsize = 0; short foundwin = 0; - for (area = static_cast(screen->areabase.first); area; area = area->next) { + LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) { if (area->winx > 30 && area->winy > 30) { size = area->winx * area->winy; if (!area->full && area->spacetype == SPACE_PROPERTIES) { @@ -325,11 +325,11 @@ static int render_view_show_invoke(bContext *C, wmOperator *op, const wmEvent *e wm_window_lower(wincur); } else { - wmWindow *win, *winshow; + wmWindow *winshow; ScrArea *area = find_area_showing_r_result(C, CTX_data_scene(C), &winshow); /* is there another window on current scene showing result? */ - for (win = static_cast(CTX_wm_manager(C)->windows.first); win; win = win->next) { + LISTBASE_FOREACH (wmWindow *, win, &CTX_wm_manager(C)->windows) { const bScreen *screen = WM_window_get_active_screen(win); if ((WM_window_is_temp_screen(win) && diff --git a/source/blender/editors/sculpt_paint/paint_weight.cc b/source/blender/editors/sculpt_paint/paint_weight.cc index 8595a0d24de..ec3a59e8c14 100644 --- a/source/blender/editors/sculpt_paint/paint_weight.cc +++ b/source/blender/editors/sculpt_paint/paint_weight.cc @@ -1875,11 +1875,8 @@ static void wpaint_stroke_done(const bContext *C, PaintStroke *stroke) /* and particles too */ if (ob->particlesystem.first) { - ParticleSystem *psys; - int i; - - for (psys = (ParticleSystem *)ob->particlesystem.first; psys; psys = psys->next) { - for (i = 0; i < PSYS_TOT_VG; i++) { + LISTBASE_FOREACH (ParticleSystem *, psys, &ob->particlesystem) { + for (int i = 0; i < PSYS_TOT_VG; i++) { if (psys->vgroup[i] == BKE_object_defgroup_active_index_get(ob)) { psys->recalc |= ID_RECALC_PSYS_RESET; break; diff --git a/source/blender/editors/sculpt_paint/sculpt_cloth.cc b/source/blender/editors/sculpt_paint/sculpt_cloth.cc index 6bc4db06f78..0cda99b5738 100644 --- a/source/blender/editors/sculpt_paint/sculpt_cloth.cc +++ b/source/blender/editors/sculpt_paint/sculpt_cloth.cc @@ -664,16 +664,12 @@ static void cloth_brush_solve_collision(Object *object, { const int raycast_flag = BVH_RAYCAST_DEFAULT & ~(BVH_RAYCAST_WATERTIGHT); - ColliderCache *collider_cache; BVHTreeRayHit hit; float obmat_inv[4][4]; invert_m4_m4(obmat_inv, object->object_to_world); - for (collider_cache = static_cast(cloth_sim->collider_list->first); - collider_cache; - collider_cache = collider_cache->next) - { + LISTBASE_FOREACH (ColliderCache *, collider_cache, cloth_sim->collider_list) { float ray_start[3], ray_normal[3]; float pos_world_space[3], prev_pos_world_space[3]; diff --git a/source/blender/editors/sculpt_paint/sculpt_undo.cc b/source/blender/editors/sculpt_paint/sculpt_undo.cc index 8f396eb4bca..78174306a10 100644 --- a/source/blender/editors/sculpt_paint/sculpt_undo.cc +++ b/source/blender/editors/sculpt_paint/sculpt_undo.cc @@ -878,14 +878,13 @@ static void sculpt_undo_restore_list(bContext *C, Depsgraph *depsgraph, ListBase Object *ob = BKE_view_layer_active_object_get(view_layer); SculptSession *ss = ob->sculpt; SubdivCCG *subdiv_ccg = ss->subdiv_ccg; - SculptUndoNode *unode; bool update = false, rebuild = false, update_mask = false, update_visibility = false; bool update_face_sets = false; bool need_mask = false; bool need_refine_subdiv = false; bool clear_automask_cache = false; - for (unode = static_cast(lb->first); unode; unode = unode->next) { + LISTBASE_FOREACH (SculptUndoNode *, unode, lb) { if (!ELEM(unode->type, SCULPT_UNDO_COLOR, SCULPT_UNDO_MASK)) { clear_automask_cache = true; } @@ -933,7 +932,7 @@ static void sculpt_undo_restore_list(bContext *C, Depsgraph *depsgraph, ListBase char *undo_modified_grids = nullptr; bool use_multires_undo = false; - for (unode = static_cast(lb->first); unode; unode = unode->next) { + LISTBASE_FOREACH (SculptUndoNode *, unode, lb) { if (!STREQ(unode->idname, ob->id.name)) { continue; @@ -1016,7 +1015,7 @@ static void sculpt_undo_restore_list(bContext *C, Depsgraph *depsgraph, ListBase } if (use_multires_undo) { - for (unode = static_cast(lb->first); unode; unode = unode->next) { + LISTBASE_FOREACH (SculptUndoNode *, unode, lb) { if (!STREQ(unode->idname, ob->id.name)) { continue; } @@ -1796,10 +1795,9 @@ void SCULPT_undo_push_end(Object *ob) void SCULPT_undo_push_end_ex(Object *ob, const bool use_nested_undo) { UndoSculpt *usculpt = sculpt_undo_get_nodes(); - SculptUndoNode *unode; /* We don't need normals in the undo stack. */ - for (unode = static_cast(usculpt->nodes.first); unode; unode = unode->next) { + LISTBASE_FOREACH (SculptUndoNode *, unode, &usculpt->nodes) { if (unode->no) { usculpt->undo_size -= MEM_allocN_len(unode->no); MEM_freeN(unode->no); diff --git a/source/blender/editors/space_action/action_data.cc b/source/blender/editors/space_action/action_data.cc index e7cb6aad040..99ddb3186fb 100644 --- a/source/blender/editors/space_action/action_data.cc +++ b/source/blender/editors/space_action/action_data.cc @@ -732,9 +732,7 @@ void ACTION_OT_unlink(wmOperatorType *ot) /* Try to find NLA Strip to use for action layer up/down tool */ static NlaStrip *action_layer_get_nlastrip(ListBase *strips, float ctime) { - NlaStrip *strip; - - for (strip = static_cast(strips->first); strip; strip = strip->next) { + LISTBASE_FOREACH (NlaStrip *, strip, strips) { /* Can we use this? */ if (IN_RANGE_INCL(ctime, strip->start, strip->end)) { /* in range - use this one */ diff --git a/source/blender/editors/space_action/action_edit.cc b/source/blender/editors/space_action/action_edit.cc index abbaf09c60e..5935d3ddbf9 100644 --- a/source/blender/editors/space_action/action_edit.cc +++ b/source/blender/editors/space_action/action_edit.cc @@ -157,7 +157,6 @@ void ACTION_OT_markers_make_local(wmOperatorType *ot) static bool get_keyframe_extents(bAnimContext *ac, float *min, float *max, const short onlySel) { ListBase anim_data = {nullptr, nullptr}; - bAnimListElem *ale; eAnimFilter_Flags filter; bool found = false; @@ -175,14 +174,13 @@ static bool get_keyframe_extents(bAnimContext *ac, float *min, float *max, const /* check if any channels to set range with */ if (anim_data.first) { /* go through channels, finding max extents */ - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { AnimData *adt = ANIM_nla_mapping_get(ac, ale); if (ale->datatype == ALE_GPFRAME) { bGPDlayer *gpl = static_cast(ale->data); - bGPDframe *gpf; /* Find gp-frame which is less than or equal to current-frame. */ - for (gpf = static_cast(gpl->frames.first); gpf; gpf = gpf->next) { + LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) { if (!onlySel || (gpf->flag & GP_FRAME_SELECT)) { const float framenum = float(gpf->framenum); *min = min_ff(*min, framenum); @@ -193,13 +191,8 @@ static bool get_keyframe_extents(bAnimContext *ac, float *min, float *max, const } else if (ale->datatype == ALE_MASKLAY) { MaskLayer *masklay = static_cast(ale->data); - MaskLayerShape *masklay_shape; - /* Find mask layer which is less than or equal to current-frame. */ - for (masklay_shape = static_cast(masklay->splines_shapes.first); - masklay_shape; - masklay_shape = masklay_shape->next) - { + LISTBASE_FOREACH (MaskLayerShape *, masklay_shape, &masklay->splines_shapes) { const float framenum = float(masklay_shape->frame); *min = min_ff(*min, framenum); *max = max_ff(*max, framenum); @@ -865,7 +858,6 @@ static void insert_action_keys(bAnimContext *ac, short mode) { ListBase anim_data = {nullptr, nullptr}; ListBase nla_cache = {nullptr, nullptr}; - bAnimListElem *ale; eAnimFilter_Flags filter; Scene *scene = ac->scene; @@ -902,7 +894,7 @@ static void insert_action_keys(bAnimContext *ac, short mode) /* insert keyframes */ const AnimationEvalContext anim_eval_context = BKE_animsys_eval_context_construct( ac->depsgraph, float(scene->r.cfra)); - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { switch (ale->type) { case ANIMTYPE_GPLAYER: insert_gpencil_key(ac, ale, add_frame_mode, &gpd_old); @@ -987,7 +979,6 @@ void ACTION_OT_keyframe_insert(wmOperatorType *ot) static bool duplicate_action_keys(bAnimContext *ac) { ListBase anim_data = {nullptr, nullptr}; - bAnimListElem *ale; eAnimFilter_Flags filter; bool changed = false; @@ -997,7 +988,7 @@ static bool duplicate_action_keys(bAnimContext *ac) ANIM_animdata_filter(ac, &anim_data, filter, ac->data, eAnimCont_Types(ac->datatype)); /* loop through filtered data and delete selected keys */ - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { if (ELEM(ale->type, ANIMTYPE_FCURVE, ANIMTYPE_NLACURVE)) { changed |= duplicate_fcurve_keys((FCurve *)ale->key_data); } @@ -1070,7 +1061,6 @@ void ACTION_OT_duplicate(wmOperatorType *ot) static bool delete_action_keys(bAnimContext *ac) { ListBase anim_data = {nullptr, nullptr}; - bAnimListElem *ale; eAnimFilter_Flags filter; bool changed_final = false; @@ -1080,7 +1070,7 @@ static bool delete_action_keys(bAnimContext *ac) ANIM_animdata_filter(ac, &anim_data, filter, ac->data, eAnimCont_Types(ac->datatype)); /* loop through filtered data and delete selected keys */ - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { bool changed = false; if (ale->type == ANIMTYPE_GPLAYER) { @@ -1168,7 +1158,6 @@ void ACTION_OT_delete(wmOperatorType *ot) static void clean_action_keys(bAnimContext *ac, float thresh, bool clean_chan) { ListBase anim_data = {nullptr, nullptr}; - bAnimListElem *ale; eAnimFilter_Flags filter; /* filter data */ @@ -1177,7 +1166,7 @@ static void clean_action_keys(bAnimContext *ac, float thresh, bool clean_chan) ANIM_animdata_filter(ac, &anim_data, filter, ac->data, eAnimCont_Types(ac->datatype)); /* loop through filtered data and clean curves */ - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { clean_fcurve(ac, ale, thresh, clean_chan); ale->update |= ANIM_UPDATE_DEFAULT; @@ -1249,7 +1238,6 @@ void ACTION_OT_clean(wmOperatorType *ot) static void sample_action_keys(bAnimContext *ac) { ListBase anim_data = {nullptr, nullptr}; - bAnimListElem *ale; eAnimFilter_Flags filter; /* filter data */ @@ -1258,7 +1246,7 @@ static void sample_action_keys(bAnimContext *ac) ANIM_animdata_filter(ac, &anim_data, filter, ac->data, eAnimCont_Types(ac->datatype)); /* Loop through filtered data and add keys between selected keyframes on every frame. */ - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { sample_fcurve((FCurve *)ale->key_data); ale->update |= ANIM_UPDATE_DEPS; @@ -1348,7 +1336,6 @@ static const EnumPropertyItem prop_actkeys_expo_types[] = { static void setexpo_action_keys(bAnimContext *ac, short mode) { ListBase anim_data = {nullptr, nullptr}; - bAnimListElem *ale; eAnimFilter_Flags filter; /* filter data */ @@ -1357,7 +1344,7 @@ static void setexpo_action_keys(bAnimContext *ac, short mode) ANIM_animdata_filter(ac, &anim_data, filter, ac->data, eAnimCont_Types(ac->datatype)); /* loop through setting mode per F-Curve */ - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { FCurve *fcu = (FCurve *)ale->data; if (mode >= 0) { @@ -1566,7 +1553,6 @@ void ACTION_OT_easing_type(wmOperatorType *ot) static void sethandles_action_keys(bAnimContext *ac, short mode) { ListBase anim_data = {nullptr, nullptr}; - bAnimListElem *ale; eAnimFilter_Flags filter; KeyframeEditFunc edit_cb = ANIM_editkeyframes_handles(mode); @@ -1581,7 +1567,7 @@ static void sethandles_action_keys(bAnimContext *ac, short mode) * NOTE: we do not supply KeyframeEditData to the looper yet. * Currently that's not necessary here. */ - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { FCurve *fcu = (FCurve *)ale->key_data; /* any selected keyframes for editing? */ @@ -1655,7 +1641,6 @@ void ACTION_OT_handle_type(wmOperatorType *ot) static void setkeytype_action_keys(bAnimContext *ac, short mode) { ListBase anim_data = {nullptr, nullptr}; - bAnimListElem *ale; eAnimFilter_Flags filter; KeyframeEditFunc set_cb = ANIM_editkeyframes_keytype(mode); @@ -1668,7 +1653,7 @@ static void setkeytype_action_keys(bAnimContext *ac, short mode) * NOTE: we do not supply KeyframeEditData to the looper yet. * Currently that's not necessary here. */ - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { switch (ale->type) { case ANIMTYPE_GPLAYER: ED_gpencil_layer_frames_keytype_set(static_cast(ale->data), mode); @@ -1763,7 +1748,6 @@ static int actkeys_framejump_exec(bContext *C, wmOperator * /*op*/) { bAnimContext ac; ListBase anim_data = {nullptr, nullptr}; - bAnimListElem *ale; eAnimFilter_Flags filter; KeyframeEditData ked = {{nullptr}}; @@ -1777,13 +1761,12 @@ static int actkeys_framejump_exec(bContext *C, wmOperator * /*op*/) filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_NODUPLIS); ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, eAnimCont_Types(ac.datatype)); - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { switch (ale->datatype) { case ALE_GPFRAME: { bGPDlayer *gpl = static_cast(ale->data); - bGPDframe *gpf; - for (gpf = static_cast(gpl->frames.first); gpf; gpf = gpf->next) { + LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) { /* only if selected */ if (!(gpf->flag & GP_FRAME_SELECT)) { continue; @@ -1882,7 +1865,6 @@ static const EnumPropertyItem prop_actkeys_snap_types[] = { static void snap_action_keys(bAnimContext *ac, short mode) { ListBase anim_data = {nullptr, nullptr}; - bAnimListElem *ale; eAnimFilter_Flags filter; KeyframeEditData ked = {{nullptr}}; @@ -1908,7 +1890,7 @@ static void snap_action_keys(bAnimContext *ac, short mode) } /* snap keyframes */ - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { AnimData *adt = ANIM_nla_mapping_get(ac, ale); if (ale->type == ANIMTYPE_GPLAYER) { @@ -2015,7 +1997,6 @@ static const EnumPropertyItem prop_actkeys_mirror_types[] = { static void mirror_action_keys(bAnimContext *ac, short mode) { ListBase anim_data = {nullptr, nullptr}; - bAnimListElem *ale; eAnimFilter_Flags filter; KeyframeEditData ked = {{nullptr}}; @@ -2045,7 +2026,7 @@ static void mirror_action_keys(bAnimContext *ac, short mode) ANIM_animdata_filter(ac, &anim_data, filter, ac->data, eAnimCont_Types(ac->datatype)); /* mirror keyframes */ - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { AnimData *adt = ANIM_nla_mapping_get(ac, ale); if (ale->type == ANIMTYPE_GPLAYER) { diff --git a/source/blender/editors/space_action/action_select.cc b/source/blender/editors/space_action/action_select.cc index 20918c2b9ef..b9e46f16230 100644 --- a/source/blender/editors/space_action/action_select.cc +++ b/source/blender/editors/space_action/action_select.cc @@ -250,7 +250,6 @@ static bool actkeys_is_key_at_position(bAnimContext *ac, float region_x, float r static void deselect_action_keys(bAnimContext *ac, short test, short sel) { ListBase anim_data = {nullptr, nullptr}; - bAnimListElem *ale; eAnimFilter_Flags filter; KeyframeEditData ked = {{nullptr}}; @@ -267,7 +266,7 @@ static void deselect_action_keys(bAnimContext *ac, short test, short sel) /* See if we should be selecting or deselecting */ if (test) { - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { if (ale->type == ANIMTYPE_GPLAYER) { if (ED_gpencil_layer_frame_select_check(static_cast(ale->data))) { sel = SELECT_SUBTRACT; @@ -303,7 +302,7 @@ static void deselect_action_keys(bAnimContext *ac, short test, short sel) sel_cb = ANIM_editkeyframes_select(sel); /* Now set the flags */ - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { if (ale->type == ANIMTYPE_GPLAYER) { ED_gpencil_layer_frame_select_set(static_cast(ale->data), sel); ale->update |= ANIM_UPDATE_DEPS; @@ -1006,7 +1005,6 @@ static const EnumPropertyItem prop_column_select_types[] = { static void markers_selectkeys_between(bAnimContext *ac) { ListBase anim_data = {nullptr, nullptr}; - bAnimListElem *ale; eAnimFilter_Flags filter; KeyframeEditFunc ok_cb, select_cb; @@ -1030,7 +1028,7 @@ static void markers_selectkeys_between(bAnimContext *ac) ANIM_animdata_filter(ac, &anim_data, filter, ac->data, eAnimCont_Types(ac->datatype)); /* select keys in-between */ - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { switch (ale->type) { case ANIMTYPE_GREASE_PENCIL_LAYER: /* GPv3: To be implemented. */ @@ -1073,7 +1071,6 @@ static void markers_selectkeys_between(bAnimContext *ac) static void columnselect_action_keys(bAnimContext *ac, short mode) { ListBase anim_data = {nullptr, nullptr}; - bAnimListElem *ale; eAnimFilter_Flags filter; Scene *scene = ac->scene; @@ -1088,7 +1085,7 @@ static void columnselect_action_keys(bAnimContext *ac, short mode) filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE); ANIM_animdata_filter(ac, &anim_data, filter, ac->data, eAnimCont_Types(ac->datatype)); - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { switch (ale->type) { case ANIMTYPE_GPLAYER: ED_gpencil_layer_make_cfra_list( @@ -1108,7 +1105,7 @@ static void columnselect_action_keys(bAnimContext *ac, short mode) filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE); ANIM_animdata_filter(ac, &anim_data, filter, ac->data, eAnimCont_Types(ac->datatype)); - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { if (ale->datatype == ALE_GPFRAME) { ED_gpencil_layer_make_cfra_list(static_cast(ale->data), &ked.list, true); } @@ -1147,13 +1144,13 @@ static void columnselect_action_keys(bAnimContext *ac, short mode) filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE); ANIM_animdata_filter(ac, &anim_data, filter, ac->data, eAnimCont_Types(ac->datatype)); - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { AnimData *adt = ANIM_nla_mapping_get(ac, ale); /* loop over cfraelems (stored in the KeyframeEditData->list) * - we need to do this here, as we can apply fewer NLA-mapping conversions */ - for (ce = static_cast(ked.list.first); ce; ce = ce->next) { + LISTBASE_FOREACH (CfraElem *, ce, &ked.list) { /* set frame for validation callback to refer to */ if (adt) { ked.f1 = BKE_nla_tweakedit_remap(adt, ce->cfra, NLATIME_CONVERT_UNMAP); @@ -1249,7 +1246,6 @@ static int actkeys_select_linked_exec(bContext *C, wmOperator * /*op*/) bAnimContext ac; ListBase anim_data = {nullptr, nullptr}; - bAnimListElem *ale; eAnimFilter_Flags filter; KeyframeEditFunc ok_cb = ANIM_editkeyframes_ok(BEZT_OK_SELECTED); @@ -1265,7 +1261,7 @@ static int actkeys_select_linked_exec(bContext *C, wmOperator * /*op*/) ANIMFILTER_NODUPLIS); ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, eAnimCont_Types(ac.datatype)); - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { FCurve *fcu = (FCurve *)ale->key_data; /* check if anything selected? */ @@ -1311,7 +1307,6 @@ void ACTION_OT_select_linked(wmOperatorType *ot) static void select_moreless_action_keys(bAnimContext *ac, short mode) { ListBase anim_data = {nullptr, nullptr}; - bAnimListElem *ale; eAnimFilter_Flags filter; KeyframeEditData ked = {{nullptr}}; @@ -1325,7 +1320,7 @@ static void select_moreless_action_keys(bAnimContext *ac, short mode) ANIMFILTER_NODUPLIS); ANIM_animdata_filter(ac, &anim_data, filter, ac->data, eAnimCont_Types(ac->datatype)); - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { /* TODO: other types. */ if (ale->datatype != ALE_FCURVE) { @@ -1449,7 +1444,6 @@ static const EnumPropertyItem prop_actkeys_leftright_select_types[] = { static void actkeys_select_leftright(bAnimContext *ac, short leftright, short select_mode) { ListBase anim_data = {nullptr, nullptr}; - bAnimListElem *ale; eAnimFilter_Flags filter; KeyframeEditFunc ok_cb, select_cb; @@ -1484,7 +1478,7 @@ static void actkeys_select_leftright(bAnimContext *ac, short leftright, short se ANIM_animdata_filter(ac, &anim_data, filter, ac->data, eAnimCont_Types(ac->datatype)); /* select keys */ - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { switch (ale->type) { case ANIMTYPE_GREASE_PENCIL_LAYER: /* GPv3: To be implemented. */ @@ -1525,9 +1519,7 @@ static void actkeys_select_leftright(bAnimContext *ac, short leftright, short se if ((saction) && (saction->flag & SACTION_MARKERS_MOVE)) { ListBase *markers = ED_animcontext_get_markers(ac); - TimeMarker *marker; - - for (marker = static_cast(markers->first); marker; marker = marker->next) { + LISTBASE_FOREACH (TimeMarker *, marker, markers) { if (((leftright == ACTKEYS_LRSEL_LEFT) && (marker->frame < scene->r.cfra)) || ((leftright == ACTKEYS_LRSEL_RIGHT) && (marker->frame >= scene->r.cfra))) { @@ -1718,7 +1710,6 @@ static void actkeys_mselect_single(bAnimContext *ac, static void actkeys_mselect_column(bAnimContext *ac, short select_mode, float selx) { ListBase anim_data = {nullptr, nullptr}; - bAnimListElem *ale; eAnimFilter_Flags filter; KeyframeEditFunc select_cb, ok_cb; @@ -1734,7 +1725,7 @@ static void actkeys_mselect_column(bAnimContext *ac, short select_mode, float se filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_NODUPLIS); ANIM_animdata_filter(ac, &anim_data, filter, ac->data, eAnimCont_Types(ac->datatype)); - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { /* select elements with frame number matching cfra */ if (ale->type == ANIMTYPE_GPLAYER) { ED_gpencil_select_frame(static_cast(ale->data), selx, select_mode); diff --git a/source/blender/editors/space_action/space_action.cc b/source/blender/editors/space_action/space_action.cc index d9648cddbe0..542d98fc3b3 100644 --- a/source/blender/editors/space_action/space_action.cc +++ b/source/blender/editors/space_action/space_action.cc @@ -776,8 +776,6 @@ static void action_refresh(const bContext *C, ScrArea *area) * NOTE: the temp flag is used to indicate when this needs to be done, * and will be cleared once handled. */ if (saction->runtime.flag & SACTION_RUNTIME_FLAG_NEED_CHAN_SYNC) { - ARegion *region; - /* Perform syncing of channel state incl. selection * Active action setting also occurs here * (as part of anim channel filtering in `anim_filter.cc`). */ @@ -789,7 +787,7 @@ static void action_refresh(const bContext *C, ScrArea *area) * or else they don't update #28962. */ ED_area_tag_redraw(area); - for (region = static_cast(area->regionbase.first); region; region = region->next) { + LISTBASE_FOREACH (ARegion *, region, &area->regionbase) { ED_region_tag_redraw(region); } } diff --git a/source/blender/editors/space_buttons/buttons_texture.cc b/source/blender/editors/space_buttons/buttons_texture.cc index 79cddd228af..4f7e24ca93e 100644 --- a/source/blender/editors/space_buttons/buttons_texture.cc +++ b/source/blender/editors/space_buttons/buttons_texture.cc @@ -134,10 +134,8 @@ static void buttons_texture_users_find_nodetree(ListBase *users, bNodeTree *ntree, const char *category) { - bNode *node; - if (ntree) { - for (node = static_cast(ntree->nodes.first); node; node = node->next) { + LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { if (node->typeinfo->nclass == NODE_CLASS_TEXTURE) { PointerRNA ptr; // PropertyRNA *prop; /* UNUSED */ @@ -402,8 +400,7 @@ void buttons_texture_context_compute(const bContext *C, SpaceProperties *sbuts) /* Detect change of active texture node in same node tree, in that * case we also automatically switch to the other node. */ if ((ct->user->node->flag & NODE_ACTIVE_TEXTURE) == 0) { - ButsTextureUser *user; - for (user = static_cast(ct->users.first); user; user = user->next) { + LISTBASE_FOREACH (ButsTextureUser *, user, &ct->users) { if (user->ntree == ct->user->ntree && user->node != ct->user->node) { if (user->node->flag & NODE_ACTIVE_TEXTURE) { ct->user = user; @@ -487,11 +484,10 @@ static void template_texture_user_menu(bContext *C, uiLayout *layout, void * /*a /* callback when opening texture user selection menu, to create buttons. */ SpaceProperties *sbuts = CTX_wm_space_properties(C); ButsContextTexture *ct = static_cast(sbuts->texuser); - ButsTextureUser *user; uiBlock *block = uiLayoutGetBlock(layout); const char *last_category = nullptr; - for (user = static_cast(ct->users.first); user; user = user->next) { + LISTBASE_FOREACH (ButsTextureUser *, user, &ct->users) { uiBut *but; char name[UI_MAX_NAME_STR]; diff --git a/source/blender/editors/space_console/console_ops.cc b/source/blender/editors/space_console/console_ops.cc index 127da5a1262..1cbf0c43294 100644 --- a/source/blender/editors/space_console/console_ops.cc +++ b/source/blender/editors/space_console/console_ops.cc @@ -51,7 +51,7 @@ static char *console_select_to_buffer(SpaceConsole *sc) console_scrollback_prompt_begin(sc, &cl_dummy); int offset = 0; - for (ConsoleLine *cl = static_cast(sc->scrollback.first); cl; cl = cl->next) { + LISTBASE_FOREACH (ConsoleLine *, cl, &sc->scrollback) { offset += cl->len + 1; } @@ -60,7 +60,7 @@ static char *console_select_to_buffer(SpaceConsole *sc) offset -= 1; int sel[2] = {offset - sc->sel_end, offset - sc->sel_start}; DynStr *buf_dyn = BLI_dynstr_new(); - for (ConsoleLine *cl = static_cast(sc->scrollback.first); cl; cl = cl->next) { + LISTBASE_FOREACH (ConsoleLine *, cl, &sc->scrollback) { if (sel[0] <= cl->len && sel[1] >= 0) { int sta = max_ii(sel[0], 0); int end = min_ii(sel[1], cl->len); @@ -148,9 +148,7 @@ static void console_scrollback_limit(SpaceConsole *sc) static ConsoleLine *console_history_find(SpaceConsole *sc, const char *str, ConsoleLine *cl_ignore) { - ConsoleLine *cl; - - for (cl = static_cast(sc->history.last); cl; cl = cl->prev) { + LISTBASE_FOREACH_BACKWARD (ConsoleLine *, cl, &sc->history) { if (cl == cl_ignore) { continue; } diff --git a/source/blender/editors/space_graph/graph_buttons.cc b/source/blender/editors/space_graph/graph_buttons.cc index 513dc620e81..1a49ee89d14 100644 --- a/source/blender/editors/space_graph/graph_buttons.cc +++ b/source/blender/editors/space_graph/graph_buttons.cc @@ -1012,7 +1012,6 @@ static void graph_draw_driver_settings_panel(uiLayout *layout, const bool is_popover) { ChannelDriver *driver = fcu->driver; - DriverVar *dvar; PointerRNA driver_ptr; uiLayout *col, *row, *row_outer; @@ -1153,7 +1152,7 @@ static void graph_draw_driver_settings_panel(uiLayout *layout, uiItemO(row, "", ICON_PASTEDOWN, "GRAPH_OT_driver_variables_paste"); /* loop over targets, drawing them */ - for (dvar = static_cast(driver->variables.first); dvar; dvar = dvar->next) { + LISTBASE_FOREACH (DriverVar *, dvar, &driver->variables) { PointerRNA dvar_ptr; uiLayout *box; uiLayout *subrow, *sub; diff --git a/source/blender/editors/space_graph/graph_draw.cc b/source/blender/editors/space_graph/graph_draw.cc index 11a52e597ba..39f2a601856 100644 --- a/source/blender/editors/space_graph/graph_draw.cc +++ b/source/blender/editors/space_graph/graph_draw.cc @@ -1416,8 +1416,6 @@ static void graph_draw_driver_debug(bAnimContext *ac, ID *id, FCurve *fcu) void graph_draw_ghost_curves(bAnimContext *ac, SpaceGraph *sipo, ARegion *region) { - FCurve *fcu; - /* draw with thick dotted lines */ GPU_line_width(3.0f); @@ -1445,7 +1443,7 @@ void graph_draw_ghost_curves(bAnimContext *ac, SpaceGraph *sipo, ARegion *region * See issue #109920 for details. */ const bool draw_extrapolation = false; /* the ghost curves are simply sampled F-Curves stored in sipo->runtime.ghost_curves */ - for (fcu = static_cast(sipo->runtime.ghost_curves.first); fcu; fcu = fcu->next) { + LISTBASE_FOREACH (FCurve *, fcu, &sipo->runtime.ghost_curves) { /* set whatever color the curve has set * - this is set by the function which creates these * - draw with a fixed opacity of 2 @@ -1467,7 +1465,6 @@ void graph_draw_ghost_curves(bAnimContext *ac, SpaceGraph *sipo, ARegion *region void graph_draw_curves(bAnimContext *ac, SpaceGraph *sipo, ARegion *region, short sel) { ListBase anim_data = {nullptr, nullptr}; - bAnimListElem *ale; int filter; /* build list of curves to draw */ @@ -1481,7 +1478,7 @@ void graph_draw_curves(bAnimContext *ac, SpaceGraph *sipo, ARegion *region, shor * the data will be layered correctly */ bAnimListElem *ale_active_fcurve = nullptr; - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { const FCurve *fcu = (FCurve *)ale->key_data; if (fcu->flag & FCURVE_ACTIVE) { ale_active_fcurve = ale; diff --git a/source/blender/editors/space_graph/graph_edit.cc b/source/blender/editors/space_graph/graph_edit.cc index edd9b6d83d1..e06c7c7a0fa 100644 --- a/source/blender/editors/space_graph/graph_edit.cc +++ b/source/blender/editors/space_graph/graph_edit.cc @@ -105,7 +105,6 @@ static void insert_graph_keys(bAnimContext *ac, eGraphKeys_InsertKey_Types mode) { ListBase anim_data = {nullptr, nullptr}; ListBase nla_cache = {nullptr, nullptr}; - bAnimListElem *ale; int filter; size_t num_items; @@ -148,7 +147,7 @@ static void insert_graph_keys(bAnimContext *ac, eGraphKeys_InsertKey_Types mode) /* Insert keyframes. */ if (mode & GRAPHKEYS_INSERTKEY_CURSOR) { - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { AnimData *adt = ANIM_nla_mapping_get(ac, ale); FCurve *fcu = (FCurve *)ale->key_data; @@ -188,7 +187,7 @@ static void insert_graph_keys(bAnimContext *ac, eGraphKeys_InsertKey_Types mode) else { const AnimationEvalContext anim_eval_context = BKE_animsys_eval_context_construct( ac->depsgraph, float(scene->r.cfra)); - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { FCurve *fcu = (FCurve *)ale->key_data; /* Read value from property the F-Curve represents, or from the curve only? @@ -671,7 +670,6 @@ void GRAPH_OT_paste(wmOperatorType *ot) static bool duplicate_graph_keys(bAnimContext *ac) { ListBase anim_data = {nullptr, nullptr}; - bAnimListElem *ale; int filter; bool changed = false; @@ -682,7 +680,7 @@ static bool duplicate_graph_keys(bAnimContext *ac) ac, &anim_data, eAnimFilter_Flags(filter), ac->data, eAnimCont_Types(ac->datatype)); /* Loop through filtered data and delete selected keys. */ - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { changed |= duplicate_fcurve_keys((FCurve *)ale->key_data); ale->update |= ANIM_UPDATE_DEFAULT; @@ -743,7 +741,6 @@ void GRAPH_OT_duplicate(wmOperatorType *ot) static bool delete_graph_keys(bAnimContext *ac) { ListBase anim_data = {nullptr, nullptr}; - bAnimListElem *ale; int filter; bool changed_final = false; @@ -754,7 +751,7 @@ static bool delete_graph_keys(bAnimContext *ac) ac, &anim_data, eAnimFilter_Flags(filter), ac->data, eAnimCont_Types(ac->datatype)); /* Loop through filtered data and delete selected keys. */ - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { FCurve *fcu = (FCurve *)ale->key_data; AnimData *adt = ale->adt; bool changed; @@ -828,7 +825,6 @@ void GRAPH_OT_delete(wmOperatorType *ot) static void clean_graph_keys(bAnimContext *ac, float thresh, bool clean_chan) { ListBase anim_data = {nullptr, nullptr}; - bAnimListElem *ale; int filter; /* Filter data. */ @@ -838,7 +834,7 @@ static void clean_graph_keys(bAnimContext *ac, float thresh, bool clean_chan) ac, &anim_data, eAnimFilter_Flags(filter), ac->data, eAnimCont_Types(ac->datatype)); /* Loop through filtered data and clean curves. */ - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { clean_fcurve(ac, ale, thresh, clean_chan); ale->update |= ANIM_UPDATE_DEFAULT; @@ -906,7 +902,6 @@ void GRAPH_OT_clean(wmOperatorType *ot) static void bake_graph_curves(bAnimContext *ac, int start, int end) { ListBase anim_data = {nullptr, nullptr}; - bAnimListElem *ale; int filter; /* Filter data. */ @@ -916,7 +911,7 @@ static void bake_graph_curves(bAnimContext *ac, int start, int end) ac, &anim_data, eAnimFilter_Flags(filter), ac->data, eAnimCont_Types(ac->datatype)); /* Loop through filtered data and add keys between selected keyframes on every frame. */ - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { FCurve *fcu = (FCurve *)ale->key_data; ChannelDriver *driver = fcu->driver; @@ -996,7 +991,6 @@ void GRAPH_OT_bake(wmOperatorType *ot) static void unbake_graph_curves(bAnimContext *ac, int start, int end) { ListBase anim_data = {nullptr, nullptr}; - bAnimListElem *ale; /* Filter data. */ const int filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE | ANIMFILTER_FCURVESONLY | @@ -1005,7 +999,7 @@ static void unbake_graph_curves(bAnimContext *ac, int start, int end) ac, &anim_data, eAnimFilter_Flags(filter), ac->data, eAnimCont_Types(ac->datatype)); /* Loop through filtered data and add keys between selected keyframes on every frame. */ - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { FCurve *fcu = (FCurve *)ale->key_data; fcurve_samples_to_keyframes(fcu, start, end); @@ -1103,7 +1097,6 @@ static int graphkeys_sound_bake_exec(bContext *C, wmOperator *op) { bAnimContext ac; ListBase anim_data = {nullptr, nullptr}; - bAnimListElem *ale; int filter; tSoundBakeInfo sbi; @@ -1157,7 +1150,7 @@ static int graphkeys_sound_bake_exec(bContext *C, wmOperator *op) &ac, &anim_data, eAnimFilter_Flags(filter), ac.data, eAnimCont_Types(ac.datatype)); /* Loop through all selected F-Curves, replacing its data with the sound samples. */ - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { FCurve *fcu = (FCurve *)ale->key_data; /* Sample the sound. */ @@ -1314,7 +1307,6 @@ void GRAPH_OT_sound_bake(wmOperatorType *ot) static void sample_graph_keys(bAnimContext *ac) { ListBase anim_data = {nullptr, nullptr}; - bAnimListElem *ale; int filter; /* filter data */ @@ -1324,7 +1316,7 @@ static void sample_graph_keys(bAnimContext *ac) ac, &anim_data, eAnimFilter_Flags(filter), ac->data, eAnimCont_Types(ac->datatype)); /* Loop through filtered data and add keys between selected keyframes on every frame. */ - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { sample_fcurve((FCurve *)ale->key_data); ale->update |= ANIM_UPDATE_DEPS; @@ -1412,7 +1404,6 @@ static const EnumPropertyItem prop_graphkeys_expo_types[] = { static void setexpo_graph_keys(bAnimContext *ac, short mode) { ListBase anim_data = {nullptr, nullptr}; - bAnimListElem *ale; int filter; /* Filter data. */ @@ -1422,7 +1413,7 @@ static void setexpo_graph_keys(bAnimContext *ac, short mode) ac, &anim_data, eAnimFilter_Flags(filter), ac->data, eAnimCont_Types(ac->datatype)); /* Loop through setting mode per F-Curve. */ - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { FCurve *fcu = (FCurve *)ale->data; if (mode >= 0) { @@ -1517,7 +1508,6 @@ void GRAPH_OT_extrapolation_type(wmOperatorType *ot) static void setipo_graph_keys(bAnimContext *ac, short mode) { ListBase anim_data = {nullptr, nullptr}; - bAnimListElem *ale; int filter; KeyframeEditFunc set_cb = ANIM_editkeyframes_ipo(mode); @@ -1531,7 +1521,7 @@ static void setipo_graph_keys(bAnimContext *ac, short mode) * NOTE: we do not supply KeyframeEditData to the looper yet. * Currently that's not necessary here. */ - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { ANIM_fcurve_keyframes_loop( nullptr, static_cast(ale->key_data), nullptr, set_cb, BKE_fcurve_handles_recalc); @@ -1597,7 +1587,6 @@ void GRAPH_OT_interpolation_type(wmOperatorType *ot) static void seteasing_graph_keys(bAnimContext *ac, short mode) { ListBase anim_data = {nullptr, nullptr}; - bAnimListElem *ale; int filter; KeyframeEditFunc set_cb = ANIM_editkeyframes_easing(mode); @@ -1611,7 +1600,7 @@ static void seteasing_graph_keys(bAnimContext *ac, short mode) * NOTE: we do not supply KeyframeEditData to the looper yet. * Currently that's not necessary here. */ - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { ANIM_fcurve_keyframes_loop( nullptr, static_cast(ale->key_data), nullptr, set_cb, BKE_fcurve_handles_recalc); @@ -1675,7 +1664,6 @@ void GRAPH_OT_easing_type(wmOperatorType *ot) static void sethandles_graph_keys(bAnimContext *ac, short mode) { ListBase anim_data = {nullptr, nullptr}; - bAnimListElem *ale; int filter; KeyframeEditFunc edit_cb = ANIM_editkeyframes_handles(mode); @@ -1691,7 +1679,7 @@ static void sethandles_graph_keys(bAnimContext *ac, short mode) * NOTE: we do not supply KeyframeEditData to the looper yet. * Currently that's not necessary here. */ - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { FCurve *fcu = (FCurve *)ale->key_data; /* Any selected keyframes for editing? */ @@ -2112,7 +2100,6 @@ static bool graphkeys_framejump_poll(bContext *C) static KeyframeEditData sum_selected_keyframes(bAnimContext *ac) { ListBase anim_data = {nullptr, nullptr}; - bAnimListElem *ale; int filter; KeyframeEditData ked; @@ -2125,7 +2112,7 @@ static KeyframeEditData sum_selected_keyframes(bAnimContext *ac) ANIM_animdata_filter( ac, &anim_data, eAnimFilter_Flags(filter), ac->data, eAnimCont_Types(ac->datatype)); - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { AnimData *adt = ANIM_nla_mapping_get(ac, ale); short mapping_flag = ANIM_get_normalization_flags(ac); KeyframeEditData current_ked; @@ -2401,7 +2388,6 @@ static const EnumPropertyItem prop_graphkeys_snap_types[] = { static void snap_graph_keys(bAnimContext *ac, short mode) { ListBase anim_data = {nullptr, nullptr}; - bAnimListElem *ale; int filter; SpaceGraph *sipo = (SpaceGraph *)ac->sl; @@ -2440,7 +2426,7 @@ static void snap_graph_keys(bAnimContext *ac, short mode) /* Snap keyframes. */ const bool use_handle = (sipo->flag & SIPO_NOHANDLES) == 0; - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { AnimData *adt = ANIM_nla_mapping_get(ac, ale); /* Normalize cursor value (for normalized F-Curves display). */ @@ -2704,7 +2690,6 @@ static const EnumPropertyItem prop_graphkeys_mirror_types[] = { static void mirror_graph_keys(bAnimContext *ac, short mode) { ListBase anim_data = {nullptr, nullptr}; - bAnimListElem *ale; int filter; SpaceGraph *sipo = (SpaceGraph *)ac->sl; @@ -2754,7 +2739,7 @@ static void mirror_graph_keys(bAnimContext *ac, short mode) ac, &anim_data, eAnimFilter_Flags(filter), ac->data, eAnimCont_Types(ac->datatype)); /* Mirror keyframes. */ - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { AnimData *adt = ANIM_nla_mapping_get(ac, ale); /* Apply unit corrections. */ @@ -2842,7 +2827,6 @@ static int graphkeys_smooth_exec(bContext *C, wmOperator * /*op*/) { bAnimContext ac; ListBase anim_data = {nullptr, nullptr}; - bAnimListElem *ale; int filter; /* Get editor data. */ @@ -2857,7 +2841,7 @@ static int graphkeys_smooth_exec(bContext *C, wmOperator * /*op*/) &ac, &anim_data, eAnimFilter_Flags(filter), ac.data, eAnimCont_Types(ac.datatype)); /* Smooth keyframes. */ - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { /* For now, we can only smooth by flattening handles AND smoothing curve values. * Perhaps the mode argument could be removed, as that functionality is offered through * Snap->Flatten Handles anyway. @@ -2939,7 +2923,6 @@ static int graph_fmodifier_add_exec(bContext *C, wmOperator *op) { bAnimContext ac; ListBase anim_data = {nullptr, nullptr}; - bAnimListElem *ale; int filter; short type; @@ -2965,7 +2948,7 @@ static int graph_fmodifier_add_exec(bContext *C, wmOperator *op) &ac, &anim_data, eAnimFilter_Flags(filter), ac.data, eAnimCont_Types(ac.datatype)); /* Add f-modifier to each curve. */ - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { FCurve *fcu = (FCurve *)ale->data; FModifier *fcm; @@ -3095,7 +3078,6 @@ static int graph_fmodifier_paste_exec(bContext *C, wmOperator *op) bAnimContext ac; ListBase anim_data = {nullptr, nullptr}; - bAnimListElem *ale; int filter; const bool replace = RNA_boolean_get(op->ptr, "replace"); @@ -3123,7 +3105,7 @@ static int graph_fmodifier_paste_exec(bContext *C, wmOperator *op) &ac, &anim_data, eAnimFilter_Flags(filter), ac.data, eAnimCont_Types(ac.datatype)); /* Paste modifiers. */ - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { FCurve *fcu = (FCurve *)ale->data; int tot; @@ -3287,7 +3269,6 @@ static int graph_driver_delete_invalid_exec(bContext *C, wmOperator *op) { bAnimContext ac; ListBase anim_data = {nullptr, nullptr}; - bAnimListElem *ale; int filter; bool ok = false; uint deleted = 0; @@ -3306,7 +3287,7 @@ static int graph_driver_delete_invalid_exec(bContext *C, wmOperator *op) &ac, &anim_data, eAnimFilter_Flags(filter), ac.data, eAnimCont_Types(ac.datatype)); /* Find invalid drivers. */ - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { FCurve *fcu = (FCurve *)ale->data; if (ELEM(nullptr, fcu, fcu->driver)) { continue; diff --git a/source/blender/editors/space_graph/graph_ops.cc b/source/blender/editors/space_graph/graph_ops.cc index ace72863226..8435f3938fd 100644 --- a/source/blender/editors/space_graph/graph_ops.cc +++ b/source/blender/editors/space_graph/graph_ops.cc @@ -223,7 +223,6 @@ static int graphview_curves_hide_exec(bContext *C, wmOperator *op) bAnimContext ac; ListBase anim_data = {nullptr, nullptr}; ListBase all_data = {nullptr, nullptr}; - bAnimListElem *ale; int filter; const bool unselected = RNA_boolean_get(op->ptr, "unselected"); @@ -256,7 +255,7 @@ static int graphview_curves_hide_exec(bContext *C, wmOperator *op) ANIM_animdata_filter( &ac, &anim_data, eAnimFilter_Flags(filter), ac.data, eAnimCont_Types(ac.datatype)); - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { /* hack: skip object channels for now, since flushing those will always flush everything, * but they are always included */ /* TODO: find out why this is the case, and fix that */ @@ -287,7 +286,7 @@ static int graphview_curves_hide_exec(bContext *C, wmOperator *op) ANIM_animdata_filter( &ac, &anim_data, eAnimFilter_Flags(filter), ac.data, eAnimCont_Types(ac.datatype)); - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { /* hack: skip object channels for now, since flushing those * will always flush everything, but they are always included */ @@ -339,7 +338,6 @@ static int graphview_curves_reveal_exec(bContext *C, wmOperator *op) bAnimContext ac; ListBase anim_data = {nullptr, nullptr}; ListBase all_data = {nullptr, nullptr}; - bAnimListElem *ale; int filter; const bool select = RNA_boolean_get(op->ptr, "select"); @@ -364,7 +362,7 @@ static int graphview_curves_reveal_exec(bContext *C, wmOperator *op) ANIM_animdata_filter( &ac, &anim_data, eAnimFilter_Flags(filter), ac.data, eAnimCont_Types(ac.datatype)); - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { /* hack: skip object channels for now, since flushing those will always flush everything, * but they are always included. */ /* TODO: find out why this is the case, and fix that */ diff --git a/source/blender/editors/space_graph/graph_select.cc b/source/blender/editors/space_graph/graph_select.cc index 2a5c2208fb0..9ccfa915ea8 100644 --- a/source/blender/editors/space_graph/graph_select.cc +++ b/source/blender/editors/space_graph/graph_select.cc @@ -163,7 +163,6 @@ static void nearest_fcurve_vert_store(ListBase *matches, static void get_nearest_fcurve_verts_list(bAnimContext *ac, const int mval[2], ListBase *matches) { ListBase anim_data = {nullptr, nullptr}; - bAnimListElem *ale; int filter; SpaceGraph *sipo = (SpaceGraph *)ac->sl; @@ -184,7 +183,7 @@ static void get_nearest_fcurve_verts_list(bAnimContext *ac, const int mval[2], L ANIM_animdata_filter( ac, &anim_data, eAnimFilter_Flags(filter), ac->data, eAnimCont_Types(ac->datatype)); - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { FCurve *fcu = (FCurve *)ale->key_data; AnimData *adt = ANIM_nla_mapping_get(ac, ale); float offset; @@ -357,7 +356,6 @@ static tNearestVertInfo *find_nearest_fcurve_vert(bAnimContext *ac, const int mv void deselect_graph_keys(bAnimContext *ac, bool test, short sel, bool do_channels) { ListBase anim_data = {nullptr, nullptr}; - bAnimListElem *ale; int filter; KeyframeEditData ked = {{nullptr}}; @@ -376,7 +374,7 @@ void deselect_graph_keys(bAnimContext *ac, bool test, short sel, bool do_channel /* See if we should be selecting or deselecting */ if (test) { - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { if (ANIM_fcurve_keyframes_loop( &ked, static_cast(ale->key_data), nullptr, test_cb, nullptr)) { @@ -390,7 +388,7 @@ void deselect_graph_keys(bAnimContext *ac, bool test, short sel, bool do_channel sel_cb = ANIM_editkeyframes_select(sel); /* Now set the flags */ - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { FCurve *fcu = (FCurve *)ale->key_data; /* Keyframes First */ @@ -613,14 +611,11 @@ static bool box_select_graphkeys(bAnimContext *ac, const KeyframeEditFunc select_cb = ANIM_editkeyframes_select(selectmode); const KeyframeEditFunc ok_cb = ANIM_editkeyframes_ok(mode); - /* Try selecting the keyframes. */ - bAnimListElem *ale = nullptr; - /* This variable will be set to true if any key is selected or deselected. */ bool any_key_selection_changed = false; /* First loop over data, doing box select. try selecting keys only. */ - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { AnimData *adt = ANIM_nla_mapping_get(ac, ale); FCurve *fcu = (FCurve *)ale->key_data; float offset; @@ -1169,7 +1164,6 @@ static const EnumPropertyItem prop_column_select_types[] = { static void markers_selectkeys_between(bAnimContext *ac) { ListBase anim_data = {nullptr, nullptr}; - bAnimListElem *ale; int filter; KeyframeEditFunc ok_cb, select_cb; @@ -1195,7 +1189,7 @@ static void markers_selectkeys_between(bAnimContext *ac) ac, &anim_data, eAnimFilter_Flags(filter), ac->data, eAnimCont_Types(ac->datatype)); /* select keys in-between */ - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { AnimData *adt = ANIM_nla_mapping_get(ac, ale); if (adt) { @@ -1218,7 +1212,6 @@ static void markers_selectkeys_between(bAnimContext *ac) static void columnselect_graph_keys(bAnimContext *ac, short mode) { ListBase anim_data = {nullptr, nullptr}; - bAnimListElem *ale; int filter; Scene *scene = ac->scene; @@ -1237,7 +1230,7 @@ static void columnselect_graph_keys(bAnimContext *ac, short mode) ANIM_animdata_filter( ac, &anim_data, eAnimFilter_Flags(filter), ac->data, eAnimCont_Types(ac->datatype)); - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { ANIM_fcurve_keyframes_loop( &ked, static_cast(ale->key_data), nullptr, bezt_to_cfraelem, nullptr); } @@ -1273,13 +1266,13 @@ static void columnselect_graph_keys(bAnimContext *ac, short mode) ANIM_animdata_filter( ac, &anim_data, eAnimFilter_Flags(filter), ac->data, eAnimCont_Types(ac->datatype)); - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { AnimData *adt = ANIM_nla_mapping_get(ac, ale); /* loop over cfraelems (stored in the KeyframeEditData->list) * - we need to do this here, as we can apply fewer NLA-mapping conversions */ - for (ce = static_cast(ked.list.first); ce; ce = ce->next) { + LISTBASE_FOREACH (CfraElem *, ce, &ked.list) { /* set frame for validation callback to refer to */ ked.f1 = BKE_nla_tweakedit_remap(adt, ce->cfra, NLATIME_CONVERT_UNMAP); @@ -1352,7 +1345,6 @@ static int graphkeys_select_linked_exec(bContext *C, wmOperator * /*op*/) bAnimContext ac; ListBase anim_data = {nullptr, nullptr}; - bAnimListElem *ale; int filter; KeyframeEditFunc ok_cb = ANIM_editkeyframes_ok(BEZT_OK_SELECTED); @@ -1369,7 +1361,7 @@ static int graphkeys_select_linked_exec(bContext *C, wmOperator * /*op*/) ANIM_animdata_filter( &ac, &anim_data, eAnimFilter_Flags(filter), ac.data, eAnimCont_Types(ac.datatype)); - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { FCurve *fcu = (FCurve *)ale->key_data; /* check if anything selected? */ @@ -1413,7 +1405,6 @@ void GRAPH_OT_select_linked(wmOperatorType *ot) static void select_moreless_graph_keys(bAnimContext *ac, short mode) { ListBase anim_data = {nullptr, nullptr}; - bAnimListElem *ale; int filter; KeyframeEditData ked; @@ -1429,7 +1420,7 @@ static void select_moreless_graph_keys(bAnimContext *ac, short mode) ANIM_animdata_filter( ac, &anim_data, eAnimFilter_Flags(filter), ac->data, eAnimCont_Types(ac->datatype)); - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { FCurve *fcu = (FCurve *)ale->key_data; /* only continue if F-Curve has keyframes */ @@ -1544,7 +1535,6 @@ static const EnumPropertyItem prop_graphkeys_leftright_select_types[] = { static void graphkeys_select_leftright(bAnimContext *ac, short leftright, short select_mode) { ListBase anim_data = {nullptr, nullptr}; - bAnimListElem *ale; int filter; KeyframeEditFunc ok_cb, select_cb; @@ -1580,7 +1570,7 @@ static void graphkeys_select_leftright(bAnimContext *ac, short leftright, short ac, &anim_data, eAnimFilter_Flags(filter), ac->data, eAnimCont_Types(ac->datatype)); /* select keys */ - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { AnimData *adt = ANIM_nla_mapping_get(ac, ale); if (adt) { @@ -1888,7 +1878,6 @@ static int graphkeys_mselect_column(bAnimContext *ac, bool wait_to_deselect_others) { ListBase anim_data = {nullptr, nullptr}; - bAnimListElem *ale; int filter; bool run_modal = false; @@ -1941,7 +1930,7 @@ static int graphkeys_mselect_column(bAnimContext *ac, ANIM_animdata_filter( ac, &anim_data, eAnimFilter_Flags(filter), ac->data, eAnimCont_Types(ac->datatype)); - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { AnimData *adt = ANIM_nla_mapping_get(ac, ale); /* set frame for validation callback to refer to */ diff --git a/source/blender/editors/space_graph/graph_slider_ops.cc b/source/blender/editors/space_graph/graph_slider_ops.cc index b250682e27d..8de009e966a 100644 --- a/source/blender/editors/space_graph/graph_slider_ops.cc +++ b/source/blender/editors/space_graph/graph_slider_ops.cc @@ -151,13 +151,12 @@ static void store_original_bezt_arrays(tGraphSliderOp *gso) { ListBase anim_data = {nullptr, nullptr}; bAnimContext *ac = &gso->ac; - bAnimListElem *ale; ANIM_animdata_filter( ac, &anim_data, OPERATOR_DATA_FILTER, ac->data, eAnimCont_Types(ac->datatype)); /* Loop through filtered data and copy the curves. */ - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { FCurve *fcu = (FCurve *)ale->key_data; if (fcu->bezt == nullptr) { @@ -407,14 +406,13 @@ enum tDecimModes { static void decimate_graph_keys(bAnimContext *ac, float factor, float error_sq_max) { ListBase anim_data = {nullptr, nullptr}; - bAnimListElem *ale; /* Filter data. */ ANIM_animdata_filter( ac, &anim_data, OPERATOR_DATA_FILTER, ac->data, eAnimCont_Types(ac->datatype)); /* Loop through filtered data and clean curves. */ - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { if (!decimate_fcurve(ale, factor, error_sq_max)) { /* The selection contains unsupported keyframe types! */ WM_report(RPT_WARNING, "Decimate: Skipping non linear/bezier keyframes!"); diff --git a/source/blender/editors/space_graph/graph_utils.cc b/source/blender/editors/space_graph/graph_utils.cc index 52e4c0e8723..f2b9a27eb62 100644 --- a/source/blender/editors/space_graph/graph_utils.cc +++ b/source/blender/editors/space_graph/graph_utils.cc @@ -113,7 +113,6 @@ bAnimListElem *get_active_fcurve_channel(bAnimContext *ac) bool graphop_visible_keyframes_poll(bContext *C) { bAnimContext ac; - bAnimListElem *ale; ListBase anim_data = {nullptr, nullptr}; ScrArea *area = CTX_wm_area(C); size_t items; @@ -141,7 +140,7 @@ bool graphop_visible_keyframes_poll(bContext *C) return found; } - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { FCurve *fcu = (FCurve *)ale->data; /* visible curves for selection must fulfill the following criteria: @@ -166,7 +165,6 @@ bool graphop_visible_keyframes_poll(bContext *C) bool graphop_editable_keyframes_poll(bContext *C) { bAnimContext ac; - bAnimListElem *ale; ListBase anim_data = {nullptr, nullptr}; ScrArea *area = CTX_wm_area(C); size_t items; @@ -196,7 +194,7 @@ bool graphop_editable_keyframes_poll(bContext *C) return found; } - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { FCurve *fcu = (FCurve *)ale->data; /* editable curves must fulfill the following criteria: diff --git a/source/blender/editors/space_graph/graph_view.cc b/source/blender/editors/space_graph/graph_view.cc index f01cb8b14a2..8913c161f45 100644 --- a/source/blender/editors/space_graph/graph_view.cc +++ b/source/blender/editors/space_graph/graph_view.cc @@ -52,7 +52,6 @@ void get_graph_keyframe_extents(bAnimContext *ac, Scene *scene = ac->scene; ListBase anim_data = {nullptr, nullptr}; - bAnimListElem *ale; int filter; /* Get data to filter, from Dopesheet. */ @@ -84,7 +83,7 @@ void get_graph_keyframe_extents(bAnimContext *ac, bool foundBounds = false; /* Go through channels, finding max extents. */ - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { AnimData *adt = ANIM_nla_mapping_get(ac, ale); FCurve *fcu = (FCurve *)ale->key_data; rctf bounds; @@ -386,7 +385,6 @@ static void create_ghost_curves(bAnimContext *ac, int start, int end) { SpaceGraph *sipo = (SpaceGraph *)ac->sl; ListBase anim_data = {nullptr, nullptr}; - bAnimListElem *ale; int filter; /* Free existing ghost curves. */ @@ -405,7 +403,7 @@ static void create_ghost_curves(bAnimContext *ac, int start, int end) ac, &anim_data, eAnimFilter_Flags(filter), ac->data, eAnimCont_Types(ac->datatype)); /* Loop through filtered data and add keys between selected keyframes on every frame. */ - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { FCurve *fcu = (FCurve *)ale->key_data; FCurve *gcu = BKE_fcurve_create(); AnimData *adt = ANIM_nla_mapping_get(ac, ale); diff --git a/source/blender/editors/space_image/image_buttons.cc b/source/blender/editors/space_image/image_buttons.cc index 81b3d3a4caa..962248a6938 100644 --- a/source/blender/editors/space_image/image_buttons.cc +++ b/source/blender/editors/space_image/image_buttons.cc @@ -51,10 +51,8 @@ ImageUser *ntree_get_active_iuser(bNodeTree *ntree) { - bNode *node; - if (ntree) { - for (node = static_cast(ntree->nodes.first); node; node = node->next) { + LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { if (ELEM(node->type, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER)) { if (node->flag & NODE_DO_OUTPUT) { return static_cast(node->storage); @@ -689,10 +687,9 @@ static void uiblock_layer_pass_buttons(uiLayout *layout, else if ((BKE_image_is_stereo(image) && (!show_stereo)) || (BKE_image_is_multiview(image) && !BKE_image_is_stereo(image))) { - ImageView *iv; int nr = 0; - for (iv = static_cast(image->views.first); iv; iv = iv->next) { + LISTBASE_FOREACH (ImageView *, iv, &image->views) { if (nr++ == iuser->view) { display_name = iv->name; break; diff --git a/source/blender/editors/space_image/space_image.cc b/source/blender/editors/space_image/space_image.cc index fb65ddde063..e6229a13f7c 100644 --- a/source/blender/editors/space_image/space_image.cc +++ b/source/blender/editors/space_image/space_image.cc @@ -63,10 +63,9 @@ static void image_scopes_tag_refresh(ScrArea *area) { SpaceImage *sima = (SpaceImage *)area->spacedata.first; - ARegion *region; /* only while histogram is visible */ - for (region = static_cast(area->regionbase.first); region; region = region->next) { + LISTBASE_FOREACH (ARegion *, region, &area->regionbase) { if (region->regiontype == RGN_TYPE_TOOL_PROPS && region->flag & RGN_FLAG_HIDDEN) { return; } diff --git a/source/blender/editors/space_info/info_report.cc b/source/blender/editors/space_info/info_report.cc index d047f7b6f50..414c290d676 100644 --- a/source/blender/editors/space_info/info_report.cc +++ b/source/blender/editors/space_info/info_report.cc @@ -33,9 +33,7 @@ static void reports_select_all(ReportList *reports, int report_mask, int action) { if (action == SEL_TOGGLE) { action = SEL_SELECT; - for (const Report *report = static_cast(reports->list.last); report; - report = report->prev) - { + LISTBASE_FOREACH_BACKWARD (const Report *, report, &reports->list) { if ((report->type & report_mask) && (report->flag & SELECT)) { action = SEL_DESELECT; break; @@ -43,7 +41,7 @@ static void reports_select_all(ReportList *reports, int report_mask, int action) } } - for (Report *report = static_cast(reports->list.last); report; report = report->prev) { + LISTBASE_FOREACH_BACKWARD (Report *, report, &reports->list) { if (report->type & report_mask) { switch (action) { case SEL_SELECT: @@ -265,8 +263,7 @@ static int box_select_exec(bContext *C, wmOperator *op) if (report_max == nullptr) { // printf("find_max\n"); - for (Report *report = static_cast(reports->list.last); report; report = report->prev) - { + LISTBASE_FOREACH_BACKWARD (Report *, report, &reports->list) { if (report->type & report_mask) { report_max = report; break; @@ -363,12 +360,10 @@ static int report_copy_exec(bContext *C, wmOperator * /*op*/) ReportList *reports = CTX_wm_reports(C); int report_mask = info_report_mask(sinfo); - Report *report; - DynStr *buf_dyn = BLI_dynstr_new(); char *buf_str; - for (report = static_cast(reports->list.first); report; report = report->next) { + LISTBASE_FOREACH (Report *, report, &reports->list) { if ((report->type & report_mask) && (report->flag & SELECT)) { BLI_dynstr_append(buf_dyn, report->message); BLI_dynstr_append(buf_dyn, "\n"); diff --git a/source/blender/editors/space_node/node_relationships.cc b/source/blender/editors/space_node/node_relationships.cc index e7e26ed6db3..dc0e8f5d0b6 100644 --- a/source/blender/editors/space_node/node_relationships.cc +++ b/source/blender/editors/space_node/node_relationships.cc @@ -2450,11 +2450,10 @@ static void node_link_insert_offset_ntree(NodeInsertOfsData *iofsd, if (!insert.parent || (prev->parent && (prev->parent == next->parent) && (prev->parent != insert.parent))) { - bNode *frame; rctf totr_frame; /* check nodes front to back */ - for (frame = (bNode *)ntree->nodes.last; frame; frame = frame->prev) { + LISTBASE_FOREACH_BACKWARD (bNode *, frame, &ntree->nodes) { /* skip selected, those are the nodes we want to attach */ if ((frame->type != NODE_FRAME) || (frame->flag & NODE_SELECT)) { continue; diff --git a/source/blender/editors/space_node/node_templates.cc b/source/blender/editors/space_node/node_templates.cc index 176526df5b3..33d751a8e64 100644 --- a/source/blender/editors/space_node/node_templates.cc +++ b/source/blender/editors/space_node/node_templates.cc @@ -89,15 +89,13 @@ static void node_link_item_apply(bNodeTree *ntree, bNode *node, NodeLinkItem *it static void node_tag_recursive(bNode *node) { - bNodeSocket *input; - if (!node || (node->flag & NODE_TEST)) { return; /* in case of cycles */ } node->flag |= NODE_TEST; - for (input = (bNodeSocket *)node->inputs.first; input; input = input->next) { + LISTBASE_FOREACH (bNodeSocket *, input, &node->inputs) { if (input->link) { node_tag_recursive(input->link->fromnode); } @@ -106,15 +104,13 @@ static void node_tag_recursive(bNode *node) static void node_clear_recursive(bNode *node) { - bNodeSocket *input; - if (!node || !(node->flag & NODE_TEST)) { return; /* in case of cycles */ } node->flag &= ~NODE_TEST; - for (input = (bNodeSocket *)node->inputs.first; input; input = input->next) { + LISTBASE_FOREACH (bNodeSocket *, input, &node->inputs) { if (input->link) { node_clear_recursive(input->link->fromnode); } @@ -124,23 +120,22 @@ static void node_clear_recursive(bNode *node) static void node_remove_linked(Main *bmain, bNodeTree *ntree, bNode *rem_node) { bNode *node, *next; - bNodeSocket *sock; if (!rem_node) { return; } /* tag linked nodes to be removed */ - for (node = (bNode *)ntree->nodes.first; node; node = node->next) { + LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { node->flag &= ~NODE_TEST; } node_tag_recursive(rem_node); /* clear tags on nodes that are still used by other nodes */ - for (node = (bNode *)ntree->nodes.first; node; node = node->next) { + LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { if (!(node->flag & NODE_TEST)) { - for (sock = (bNodeSocket *)node->inputs.first; sock; sock = sock->next) { + LISTBASE_FOREACH (bNodeSocket *, sock, &node->inputs) { if (sock->link && sock->link->fromnode != rem_node) { node_clear_recursive(sock->link->fromnode); } @@ -254,12 +249,8 @@ static void node_socket_add_replace(const bContext *C, /* copy input sockets from previous node */ if (node_prev && node_from != node_prev) { - bNodeSocket *sock_prev, *sock_from; - - for (sock_prev = (bNodeSocket *)node_prev->inputs.first; sock_prev; - sock_prev = sock_prev->next) { - for (sock_from = (bNodeSocket *)node_from->inputs.first; sock_from; - sock_from = sock_from->next) { + LISTBASE_FOREACH (bNodeSocket *, sock_prev, &node_prev->inputs) { + LISTBASE_FOREACH (bNodeSocket *, sock_from, &node_from->inputs) { if (nodeCountSocketLinks(ntree, sock_from) >= nodeSocketLinkLimit(sock_from)) { continue; } @@ -924,14 +915,12 @@ void uiTemplateNodeView( { using namespace blender::ed::space_node; - bNode *tnode; - if (!ntree) { return; } /* clear for cycle check */ - for (tnode = (bNode *)ntree->nodes.first; tnode; tnode = tnode->next) { + LISTBASE_FOREACH (bNode *, tnode, &ntree->nodes) { tnode->flag &= ~NODE_TEST; } diff --git a/source/blender/editors/space_script/script_edit.cc b/source/blender/editors/space_script/script_edit.cc index 383a252e2a6..eb7f29558bb 100644 --- a/source/blender/editors/space_script/script_edit.cc +++ b/source/blender/editors/space_script/script_edit.cc @@ -72,12 +72,8 @@ void SCRIPT_OT_python_file_run(wmOperatorType *ot) #ifdef WITH_PYTHON static bool script_test_modal_operators(bContext *C) { - wmWindowManager *wm; - wmWindow *win; - - wm = CTX_wm_manager(C); - - for (win = static_cast(wm->windows.first); win; win = win->next) { + wmWindowManager *wm = CTX_wm_manager(C); + LISTBASE_FOREACH (wmWindow *, win, &wm->windows) { LISTBASE_FOREACH (wmEventHandler *, handler_base, &win->modalhandlers) { if (handler_base->type == WM_HANDLER_TYPE_OP) { wmEventHandler_Op *handler = (wmEventHandler_Op *)handler_base; diff --git a/source/blender/editors/space_text/text_autocomplete.cc b/source/blender/editors/space_text/text_autocomplete.cc index 2834e8d11c4..a22f00da7b8 100644 --- a/source/blender/editors/space_text/text_autocomplete.cc +++ b/source/blender/editors/space_text/text_autocomplete.cc @@ -151,11 +151,9 @@ static GHash *text_autocomplete_build(Text *text) /* now walk over entire doc and suggest words */ { - TextLine *linep; - gh = BLI_ghash_str_new(__func__); - for (linep = static_cast(text->lines.first); linep; linep = linep->next) { + LISTBASE_FOREACH (TextLine *, linep, &text->lines) { size_t i_start = 0; size_t i_end = 0; size_t i_pos = 0; diff --git a/source/blender/editors/space_text/text_format.cc b/source/blender/editors/space_text/text_format.cc index 1d202717287..1966cfb84a8 100644 --- a/source/blender/editors/space_text/text_format.cc +++ b/source/blender/editors/space_text/text_format.cc @@ -172,14 +172,12 @@ void ED_text_format_register(TextFormatType *tft) TextFormatType *ED_text_format_get(Text *text) { - TextFormatType *tft; - if (text) { const char *text_ext = strchr(text->id.name + 2, '.'); if (text_ext) { text_ext++; /* skip the '.' */ /* Check all text formats in the static list */ - for (tft = static_cast(tft_lb.first); tft; tft = tft->next) { + LISTBASE_FOREACH (TextFormatType *, tft, &tft_lb) { /* All formats should have an ext, but just in case */ const char **ext; for (ext = tft->ext; *ext; ext++) { @@ -212,8 +210,6 @@ bool ED_text_is_syntax_highlight_supported(Text *text) return false; } - TextFormatType *tft; - const char *text_ext = BLI_path_extension(text->id.name + 2); if (text_ext == nullptr) { /* Extensionless data-blocks are considered highlightable as Python. */ @@ -226,7 +222,7 @@ bool ED_text_is_syntax_highlight_supported(Text *text) } /* Check all text formats in the static list */ - for (tft = static_cast(tft_lb.first); tft; tft = tft->next) { + LISTBASE_FOREACH (TextFormatType *, tft, &tft_lb) { /* All formats should have an ext, but just in case */ const char **ext; for (ext = tft->ext; *ext; ext++) { diff --git a/source/blender/editors/space_text/text_ops.cc b/source/blender/editors/space_text/text_ops.cc index 456b27dc3d4..ee242786dd3 100644 --- a/source/blender/editors/space_text/text_ops.cc +++ b/source/blender/editors/space_text/text_ops.cc @@ -270,9 +270,7 @@ void text_update_line_edited(TextLine *line) void text_update_edited(Text *text) { - TextLine *line; - - for (line = static_cast(text->lines.first); line; line = line->next) { + LISTBASE_FOREACH (TextLine *, line, &text->lines) { text_update_line_edited(line); } } @@ -606,7 +604,6 @@ void TEXT_OT_make_internal(wmOperatorType *ot) static void txt_write_file(Main *bmain, Text *text, ReportList *reports) { FILE *fp; - TextLine *tmp; BLI_stat_t st; char filepath[FILE_MAX]; @@ -630,7 +627,7 @@ static void txt_write_file(Main *bmain, Text *text, ReportList *reports) return; } - for (tmp = static_cast(text->lines.first); tmp; tmp = tmp->next) { + LISTBASE_FOREACH (TextLine *, tmp, &text->lines) { fputs(tmp->line, fp); if (tmp->next) { fputc('\n', fp); @@ -1377,14 +1374,13 @@ static int text_convert_whitespace_exec(bContext *C, wmOperator *op) { SpaceText *st = CTX_wm_space_text(C); Text *text = CTX_data_edit_text(C); - TextLine *tmp; FlattenString fs; size_t a, j, max_len = 0; int type = RNA_enum_get(op->ptr, "type"); /* first convert to all space, this make it a lot easier to convert to tabs * because there is no mixtures of ' ' && '\t' */ - for (tmp = static_cast(text->lines.first); tmp; tmp = tmp->next) { + LISTBASE_FOREACH (TextLine *, tmp, &text->lines) { char *new_line; BLI_assert(tmp->line); @@ -1410,7 +1406,7 @@ static int text_convert_whitespace_exec(bContext *C, wmOperator *op) if (type == TO_TABS) { char *tmp_line = static_cast(MEM_mallocN(sizeof(*tmp_line) * (max_len + 1), __func__)); - for (tmp = static_cast(text->lines.first); tmp; tmp = tmp->next) { + LISTBASE_FOREACH (TextLine *, tmp, &text->lines) { const char *text_check_line = tmp->line; const int text_check_line_len = tmp->len; char *tmp_line_cur = tmp_line; diff --git a/source/blender/editors/space_topbar/space_topbar.cc b/source/blender/editors/space_topbar/space_topbar.cc index 9310234f4fd..92790097b3c 100644 --- a/source/blender/editors/space_topbar/space_topbar.cc +++ b/source/blender/editors/space_topbar/space_topbar.cc @@ -235,7 +235,7 @@ static void undo_history_draw_menu(const bContext *C, Menu *menu) int undo_step_count = 0; int undo_step_count_all = 0; - for (UndoStep *us = static_cast(wm->undo_stack->steps.last); us; us = us->prev) { + LISTBASE_FOREACH_BACKWARD (UndoStep *, us, &wm->undo_stack->steps) { undo_step_count_all += 1; if (us->skip) { continue; diff --git a/source/blender/editors/space_view3d/space_view3d.cc b/source/blender/editors/space_view3d/space_view3d.cc index 70221961fd3..626875c44bf 100644 --- a/source/blender/editors/space_view3d/space_view3d.cc +++ b/source/blender/editors/space_view3d/space_view3d.cc @@ -241,9 +241,7 @@ void ED_view3d_shade_update(Main *bmain, View3D *v3d, ScrArea *area) wmWindowManager *wm = static_cast(bmain->wm.first); if (v3d->shading.type != OB_RENDER) { - ARegion *region; - - for (region = static_cast(area->regionbase.first); region; region = region->next) { + LISTBASE_FOREACH (ARegion *, region, &area->regionbase) { if ((region->regiontype == RGN_TYPE_WINDOW) && region->regiondata) { ED_view3d_stop_render_preview(wm, region); } @@ -2056,14 +2054,13 @@ static void view3d_id_remap_v3d_ob_centers(View3D *v3d, const IDRemapper *mappin static void view3d_id_remap_v3d( ScrArea *area, SpaceLink *slink, View3D *v3d, const IDRemapper *mappings, const bool is_local) { - ARegion *region; if (BKE_id_remapper_apply(mappings, (ID **)&v3d->camera, ID_REMAP_APPLY_DEFAULT) == ID_REMAP_RESULT_SOURCE_UNASSIGNED) { /* 3D view might be inactive, in that case needs to use slink->regionbase */ ListBase *regionbase = (slink == area->spacedata.first) ? &area->regionbase : &slink->regionbase; - for (region = static_cast(regionbase->first); region; region = region->next) { + LISTBASE_FOREACH (ARegion *, region, regionbase) { if (region->regiontype == RGN_TYPE_WINDOW) { RegionView3D *rv3d = is_local ? ((RegionView3D *)region->regiondata)->localvd : static_cast(region->regiondata); diff --git a/source/blender/editors/space_view3d/view3d_gizmo_ruler.cc b/source/blender/editors/space_view3d/view3d_gizmo_ruler.cc index 277f3186d42..d1853020684 100644 --- a/source/blender/editors/space_view3d/view3d_gizmo_ruler.cc +++ b/source/blender/editors/space_view3d/view3d_gizmo_ruler.cc @@ -592,8 +592,7 @@ static bool view3d_ruler_from_gpencil(const bContext *C, wmGizmoGroup *gzgroup) bGPDframe *gpf; gpf = BKE_gpencil_layer_frame_get(gpl, scene->r.cfra, GP_GETFRAME_USE_PREV); if (gpf) { - bGPDstroke *gps; - for (gps = static_cast(gpf->strokes.first); gps; gps = gps->next) { + LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) { bGPDspoint *pt = gps->points; int j; RulerItem *ruler_item = nullptr; diff --git a/source/blender/editors/space_view3d/view3d_snap.cc b/source/blender/editors/space_view3d/view3d_snap.cc index 4afbfffe1c1..073c0711218 100644 --- a/source/blender/editors/space_view3d/view3d_snap.cc +++ b/source/blender/editors/space_view3d/view3d_snap.cc @@ -118,14 +118,11 @@ static int snap_sel_to_grid_exec(bContext *C, wmOperator * /*op*/) for (uint ob_index = 0; ob_index < objects_len; ob_index++) { Object *ob_eval = objects_eval[ob_index]; Object *ob = DEG_get_original_object(ob_eval); - bPoseChannel *pchan_eval; bArmature *arm_eval = static_cast(ob_eval->data); invert_m4_m4(ob_eval->world_to_object, ob_eval->object_to_world); - for (pchan_eval = static_cast(ob_eval->pose->chanbase.first); pchan_eval; - pchan_eval = pchan_eval->next) - { + LISTBASE_FOREACH (bPoseChannel *, pchan_eval, &ob_eval->pose->chanbase) { if (pchan_eval->bone->flag & BONE_SELECTED) { if (ANIM_bonecoll_is_visible_pchan(arm_eval, pchan_eval)) { if ((pchan_eval->bone->flag & BONE_CONNECTED) == 0) { @@ -389,15 +386,13 @@ static bool snap_selected_to_location(bContext *C, for (uint ob_index = 0; ob_index < objects_len; ob_index++) { Object *ob = objects[ob_index]; - bPoseChannel *pchan; bArmature *arm = static_cast(ob->data); float snap_target_local[3]; invert_m4_m4(ob->world_to_object, ob->object_to_world); mul_v3_m4v3(snap_target_local, ob->world_to_object, snap_target_global); - for (pchan = static_cast(ob->pose->chanbase.first); pchan; - pchan = pchan->next) { + LISTBASE_FOREACH (bPoseChannel *, pchan, &ob->pose->chanbase) { if ((pchan->bone->flag & BONE_SELECTED) && PBONE_VISIBLE(arm, pchan->bone) && /* if the bone has a parent and is connected to the parent, * don't do anything - will break chain unless we do auto-ik. @@ -411,8 +406,7 @@ static bool snap_selected_to_location(bContext *C, } } - for (pchan = static_cast(ob->pose->chanbase.first); pchan; - pchan = pchan->next) { + LISTBASE_FOREACH (bPoseChannel *, pchan, &ob->pose->chanbase) { if ((pchan->bone->flag & BONE_TRANSFORM) && /* check that our parents not transformed (if we have one) */ ((pchan->bone->parent && @@ -453,8 +447,7 @@ static bool snap_selected_to_location(bContext *C, } } - for (pchan = static_cast(ob->pose->chanbase.first); pchan; - pchan = pchan->next) { + LISTBASE_FOREACH (bPoseChannel *, pchan, &ob->pose->chanbase) { pchan->bone->flag &= ~BONE_TRANSFORM; } @@ -841,10 +834,7 @@ static bool snap_curs_to_sel_ex(bContext *C, const int pivot_point, float r_curs if (obact && (obact->mode & OB_MODE_POSE)) { Object *obact_eval = DEG_get_evaluated_object(depsgraph, obact); bArmature *arm = static_cast(obact_eval->data); - bPoseChannel *pchan; - for (pchan = static_cast(obact_eval->pose->chanbase.first); pchan; - pchan = pchan->next) - { + LISTBASE_FOREACH (bPoseChannel *, pchan, &obact_eval->pose->chanbase) { if (ANIM_bonecoll_is_visible_pchan(arm, pchan)) { if (pchan->bone->flag & BONE_SELECTED) { copy_v3_v3(vec, pchan->pose_head); diff --git a/source/blender/editors/space_view3d/view3d_utils.cc b/source/blender/editors/space_view3d/view3d_utils.cc index 23a9b460325..261e2fe29df 100644 --- a/source/blender/editors/space_view3d/view3d_utils.cc +++ b/source/blender/editors/space_view3d/view3d_utils.cc @@ -985,7 +985,7 @@ void ED_view3d_quadview_update(ScrArea *area, ARegion *region, bool do_clip) /* ensure locked regions have an axis, locked user views don't make much sense */ if (viewlock & RV3D_LOCK_ROTATION) { int index_qsplit = 0; - for (region = static_cast(area->regionbase.first); region; region = region->next) { + LISTBASE_FOREACH (ARegion *, region, &area->regionbase) { if (region->alignment == RGN_ALIGN_QSPLIT) { rv3d = static_cast(region->regiondata); if (rv3d->viewlock) { diff --git a/source/blender/editors/transform/transform_convert.cc b/source/blender/editors/transform/transform_convert.cc index 0f5dfd1b986..6cbbde46ebb 100644 --- a/source/blender/editors/transform/transform_convert.cc +++ b/source/blender/editors/transform/transform_convert.cc @@ -320,7 +320,6 @@ static void set_prop_dist(TransInfo *t, const bool with_dist) /* adjust pose-channel's auto-ik chainlen */ static bool pchan_autoik_adjust(bPoseChannel *pchan, short chainlen) { - bConstraint *con; bool changed = false; /* don't bother to search if no valid constraints */ @@ -329,7 +328,7 @@ static bool pchan_autoik_adjust(bPoseChannel *pchan, short chainlen) } /* check if pchan has ik-constraint */ - for (con = static_cast(pchan->constraints.first); con; con = con->next) { + LISTBASE_FOREACH (bConstraint *, con, &pchan->constraints) { if (con->flag & (CONSTRAINT_DISABLE | CONSTRAINT_OFF)) { continue; } @@ -359,7 +358,6 @@ void transform_autoik_update(TransInfo *t, short mode) Main *bmain = CTX_data_main(t->context); short *chainlen = &t->settings->autoik_chainlen; - bPoseChannel *pchan; /* mode determines what change to apply to chainlen */ if (mode == 1) { @@ -387,9 +385,7 @@ void transform_autoik_update(TransInfo *t, short mode) continue; } - for (pchan = static_cast(tc->poseobj->pose->chanbase.first); pchan; - pchan = pchan->next) - { + LISTBASE_FOREACH (bPoseChannel *, pchan, &tc->poseobj->pose->chanbase) { changed |= pchan_autoik_adjust(pchan, *chainlen); } } @@ -552,13 +548,11 @@ bool FrameOnMouseSide(char side, float frame, float cframe) bool constraints_list_needinv(TransInfo *t, ListBase *list) { - bConstraint *con; - /* loop through constraints, checking if there's one of the mentioned * constraints needing special crazy-space corrections */ if (list) { - for (con = static_cast(list->first); con; con = con->next) { + LISTBASE_FOREACH (bConstraint *, con, list) { /* only consider constraint if it is enabled, and has influence on result */ if ((con->flag & (CONSTRAINT_DISABLE | CONSTRAINT_OFF)) == 0 && (con->enforce != 0.0f)) { /* (affirmative) returns for specific constraints here... */ diff --git a/source/blender/editors/transform/transform_convert_action.cc b/source/blender/editors/transform/transform_convert_action.cc index f02ed4386aa..8d3bc7e40f6 100644 --- a/source/blender/editors/transform/transform_convert_action.cc +++ b/source/blender/editors/transform/transform_convert_action.cc @@ -81,7 +81,6 @@ static int count_fcurve_keys(FCurve *fcu, char side, float cfra, bool is_prop_ed /* fully select selected beztriples, but only include if it's on the right side of cfra */ static int count_gplayer_frames(bGPDlayer *gpl, char side, float cfra, bool is_prop_edit) { - bGPDframe *gpf; int count = 0, count_all = 0; if (gpl == nullptr) { @@ -89,7 +88,7 @@ static int count_gplayer_frames(bGPDlayer *gpl, char side, float cfra, bool is_p } /* only include points that occur on the right side of cfra */ - for (gpf = static_cast(gpl->frames.first); gpf; gpf = gpf->next) { + LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) { if (FrameOnMouseSide(side, float(gpf->framenum), cfra)) { if (gpf->flag & GP_FRAME_SELECT) { count++; @@ -107,7 +106,6 @@ static int count_gplayer_frames(bGPDlayer *gpl, char side, float cfra, bool is_p /* fully select selected beztriples, but only include if it's on the right side of cfra */ static int count_masklayer_frames(MaskLayer *masklay, char side, float cfra, bool is_prop_edit) { - MaskLayerShape *masklayer_shape; int count = 0, count_all = 0; if (masklay == nullptr) { @@ -115,10 +113,7 @@ static int count_masklayer_frames(MaskLayer *masklay, char side, float cfra, boo } /* only include points that occur on the right side of cfra */ - for (masklayer_shape = static_cast(masklay->splines_shapes.first); - masklayer_shape; - masklayer_shape = masklayer_shape->next) - { + LISTBASE_FOREACH (MaskLayerShape *, masklayer_shape, &masklay->splines_shapes) { if (FrameOnMouseSide(side, float(masklayer_shape->frame), cfra)) { if (masklayer_shape->flag & MASK_SHAPE_SELECT) { count++; @@ -230,11 +225,10 @@ static int GPLayerToTransData(TransData *td, bool is_prop_edit, float ypos) { - bGPDframe *gpf; int count = 0; /* check for select frames on right side of current frame */ - for (gpf = static_cast(gpl->frames.first); gpf; gpf = gpf->next) { + LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) { const bool is_selected = (gpf->flag & GP_FRAME_SELECT) != 0; if (is_prop_edit || is_selected) { if (FrameOnMouseSide(side, float(gpf->framenum), cfra)) { @@ -271,13 +265,10 @@ static int MaskLayerToTransData(TransData *td, bool is_prop_edit, float ypos) { - MaskLayerShape *masklay_shape; int count = 0; /* check for select frames on right side of current frame */ - for (masklay_shape = static_cast(masklay->splines_shapes.first); masklay_shape; - masklay_shape = masklay_shape->next) - { + LISTBASE_FOREACH (MaskLayerShape *, masklay_shape, &masklay->splines_shapes) { if (is_prop_edit || (masklay_shape->flag & MASK_SHAPE_SELECT)) { if (FrameOnMouseSide(side, float(masklay_shape->frame), cfra)) { tfd->val = float(masklay_shape->frame); @@ -317,7 +308,6 @@ static void createTransActionData(bContext *C, TransInfo *t) bAnimContext ac; ListBase anim_data = {nullptr, nullptr}; - bAnimListElem *ale; int filter; const bool is_prop_edit = (t->flag & T_PROP_EDIT) != 0; @@ -346,7 +336,7 @@ static void createTransActionData(bContext *C, TransInfo *t) } /* loop 1: fully select F-Curve keys and count how many BezTriples are selected */ - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { AnimData *adt = ANIM_nla_mapping_get(&ac, ale); int adt_count = 0; /* convert current-frame to action-time (slightly less accurate, especially under @@ -414,7 +404,7 @@ static void createTransActionData(bContext *C, TransInfo *t) } /* loop 2: build transdata array */ - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { if (is_prop_edit && !ale->tag) { continue; @@ -458,7 +448,7 @@ static void createTransActionData(bContext *C, TransInfo *t) if (is_prop_edit) { td = tc->data; - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { AnimData *adt; /* F-Curve may not have any keyframes */ @@ -476,17 +466,14 @@ static void createTransActionData(bContext *C, TransInfo *t) if (ale->type == ANIMTYPE_GPLAYER) { bGPDlayer *gpl = (bGPDlayer *)ale->data; - bGPDframe *gpf; - for (gpf = static_cast(gpl->frames.first); gpf; gpf = gpf->next) { + LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) { if (gpf->flag & GP_FRAME_SELECT) { td->dist = td->rdist = 0.0f; } else { - bGPDframe *gpf_iter; int min = INT_MAX; - for (gpf_iter = static_cast(gpl->frames.first); gpf_iter; - gpf_iter = gpf_iter->next) { + LISTBASE_FOREACH (bGPDframe *, gpf_iter, &gpl->frames) { if (gpf_iter->flag & GP_FRAME_SELECT) { if (FrameOnMouseSide(t->frame_side, float(gpf_iter->framenum), cfra)) { int val = abs(gpf->framenum - gpf_iter->framenum); @@ -503,23 +490,15 @@ static void createTransActionData(bContext *C, TransInfo *t) } else if (ale->type == ANIMTYPE_MASKLAYER) { MaskLayer *masklay = (MaskLayer *)ale->data; - MaskLayerShape *masklay_shape; - for (masklay_shape = static_cast(masklay->splines_shapes.first); - masklay_shape; - masklay_shape = masklay_shape->next) - { + LISTBASE_FOREACH (MaskLayerShape *, masklay_shape, &masklay->splines_shapes) { if (FrameOnMouseSide(t->frame_side, float(masklay_shape->frame), cfra)) { if (masklay_shape->flag & MASK_SHAPE_SELECT) { td->dist = td->rdist = 0.0f; } else { - MaskLayerShape *masklay_iter; int min = INT_MAX; - for (masklay_iter = static_cast(masklay->splines_shapes.first); - masklay_iter; - masklay_iter = masklay_iter->next) - { + LISTBASE_FOREACH (MaskLayerShape *, masklay_iter, &masklay->splines_shapes) { if (masklay_iter->flag & MASK_SHAPE_SELECT) { if (FrameOnMouseSide(t->frame_side, float(masklay_iter->frame), cfra)) { int val = abs(masklay_shape->frame - masklay_iter->frame); @@ -598,7 +577,6 @@ static void recalcData_actedit(TransInfo *t) bAnimContext ac = {nullptr}; ListBase anim_data = {nullptr, nullptr}; - bAnimListElem *ale; int filter; BKE_view_layer_synced_ensure(t->scene, t->view_layer); @@ -651,7 +629,7 @@ static void recalcData_actedit(TransInfo *t) * BUT only do this if realtime updates are enabled */ if ((saction->flag & SACTION_NOREALTIMEUPDATES) == 0) { - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { /* set refresh tags for objects using this animation */ ANIM_list_elem_update(CTX_data_main(t->context), t->scene, ale); } @@ -689,10 +667,7 @@ static int masklay_shape_cmp_frame(void *thunk, const void *a, const void *b) static void posttrans_mask_clean(Mask *mask) { - MaskLayer *masklay; - - for (masklay = static_cast(mask->masklayers.first); masklay; - masklay = masklay->next) { + LISTBASE_FOREACH (MaskLayer *, masklay, &mask->masklayers) { MaskLayerShape *masklay_shape, *masklay_shape_next; bool is_double = false; @@ -730,9 +705,7 @@ static void posttrans_mask_clean(Mask *mask) */ static void posttrans_gpd_clean(bGPdata *gpd) { - bGPDlayer *gpl; - - for (gpl = static_cast(gpd->layers.first); gpl; gpl = gpl->next) { + LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) { bGPDframe *gpf, *gpfn; bool is_double = false; @@ -766,7 +739,6 @@ static void posttrans_gpd_clean(bGPdata *gpd) static void posttrans_action_clean(bAnimContext *ac, bAction *act) { ListBase anim_data = {nullptr, nullptr}; - bAnimListElem *ale; int filter; /* filter data */ @@ -776,7 +748,7 @@ static void posttrans_action_clean(bAnimContext *ac, bAction *act) /* loop through relevant data, removing keyframes as appropriate * - all keyframes are converted in/out of global time */ - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { AnimData *adt = ANIM_nla_mapping_get(ac, ale); if (adt) { @@ -814,14 +786,13 @@ static void special_aftertrans_update__actedit(bContext *C, TransInfo *t) if (ELEM(ac.datatype, ANIMCONT_DOPESHEET, ANIMCONT_SHAPEKEY, ANIMCONT_TIMELINE)) { ListBase anim_data = {nullptr, nullptr}; - bAnimListElem *ale; short filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_FOREDIT); /* get channels to work on */ ANIM_animdata_filter( &ac, &anim_data, eAnimFilter_Flags(filter), ac.data, eAnimCont_Types(ac.datatype)); - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { switch (ale->datatype) { case ALE_GPFRAME: ale->id->tag &= ~LIB_TAG_DOIT; diff --git a/source/blender/editors/transform/transform_convert_armature.cc b/source/blender/editors/transform/transform_convert_armature.cc index 65542f8a20b..99b30f687f8 100644 --- a/source/blender/editors/transform/transform_convert_armature.cc +++ b/source/blender/editors/transform/transform_convert_armature.cc @@ -83,8 +83,6 @@ static void autokeyframe_pose( AnimData *adt = ob->adt; bAction *act = (adt) ? adt->action : nullptr; bPose *pose = ob->pose; - bPoseChannel *pchan; - FCurve *fcu; if (!autokeyframe_cfra_can_key(scene, id)) { return; @@ -110,7 +108,7 @@ static void autokeyframe_pose( flag |= INSERTKEY_MATRIX; } - for (pchan = static_cast(pose->chanbase.first); pchan; pchan = pchan->next) { + LISTBASE_FOREACH (bPoseChannel *, pchan, &pose->chanbase) { if ((pchan->bone->flag & BONE_TRANSFORM) == 0 && !((pose->flag & POSE_MIRROR_EDIT) && (pchan->bone->flag & BONE_TRANSFORM_MIRROR))) { @@ -131,7 +129,7 @@ static void autokeyframe_pose( /* only insert into available channels? */ else if (IS_AUTOKEY_FLAG(scene, INSERTAVAIL)) { if (act) { - for (fcu = static_cast(act->curves.first); fcu; fcu = fcu->next) { + LISTBASE_FOREACH (FCurve *, fcu, &act->curves) { /* only insert keyframes for this F-Curve if it affects the current bone */ char pchan_name[sizeof(pchan->name)]; if (!BLI_str_quoted_substr(fcu->rna_path, "bones[", pchan_name, sizeof(pchan_name))) { @@ -283,7 +281,6 @@ static short pose_grab_with_ik_add(bPoseChannel *pchan) { bKinematicConstraint *targetless = nullptr; bKinematicConstraint *data; - bConstraint *con; /* Sanity check */ if (pchan == nullptr) { @@ -291,7 +288,7 @@ static short pose_grab_with_ik_add(bPoseChannel *pchan) } /* Rule: not if there's already an IK on this channel */ - for (con = static_cast(pchan->constraints.first); con; con = con->next) { + LISTBASE_FOREACH (bConstraint *, con, &pchan->constraints) { if (con->type == CONSTRAINT_TYPE_KINEMATIC && (con->flag & CONSTRAINT_OFF) == 0) { data = static_cast(con->data); @@ -378,11 +375,10 @@ static short pose_grab_with_ik_add(bPoseChannel *pchan) /* bone is a candidate to get IK, but we don't do it if it has children connected */ static short pose_grab_with_ik_children(bPose *pose, Bone *bone) { - Bone *bonec; short wentdeeper = 0, added = 0; /* go deeper if children & children are connected */ - for (bonec = static_cast(bone->childbase.first); bonec; bonec = bonec->next) { + LISTBASE_FOREACH (Bone *, bonec, &bone->childbase) { if (bonec->flag & BONE_CONNECTED) { wentdeeper = 1; added += pose_grab_with_ik_children(pose, bonec); @@ -402,7 +398,6 @@ static short pose_grab_with_ik_children(bPose *pose, Bone *bone) static short pose_grab_with_ik(Main *bmain, Object *ob) { bArmature *arm; - bPoseChannel *pchan, *parent; Bone *bonec; short tot_ik = 0; @@ -414,7 +409,7 @@ static short pose_grab_with_ik(Main *bmain, Object *ob) /* Rule: allow multiple Bones * (but they must be selected, and only one ik-solver per chain should get added) */ - for (pchan = static_cast(ob->pose->chanbase.first); pchan; pchan = pchan->next) { + LISTBASE_FOREACH (bPoseChannel *, pchan, &ob->pose->chanbase) { if (BKE_pose_is_layer_visible(arm, pchan)) { if (pchan->bone->flag & (BONE_SELECTED | BONE_TRANSFORM_MIRROR)) { /* Rule: no IK for solitary (unconnected) bones. */ @@ -431,6 +426,7 @@ static short pose_grab_with_ik(Main *bmain, Object *ob) /* rule: if selected Bone is not a root bone, it gets a temporal IK */ if (pchan->parent) { /* only adds if there's no IK yet (and no parent bone was selected) */ + bPoseChannel *parent; for (parent = pchan->parent; parent; parent = parent->parent) { if (parent->bone->flag & (BONE_SELECTED | BONE_TRANSFORM_MIRROR)) { break; @@ -889,14 +885,13 @@ static void createTransArmatureVerts(bContext * /*C*/, TransInfo *t) t->data_len_all = 0; FOREACH_TRANS_DATA_CONTAINER (t, tc) { - EditBone *ebo, *eboflip; bArmature *arm = static_cast(tc->obedit->data); ListBase *edbo = arm->edbo; bool mirror = ((arm->flag & ARM_MIRROR_EDIT) != 0); int total_mirrored = 0; tc->data_len = 0; - for (ebo = static_cast(edbo->first); ebo; ebo = ebo->next) { + LISTBASE_FOREACH (EditBone *, ebo, edbo) { const int data_len_prev = tc->data_len; if (EBONE_VISIBLE(arm, ebo) && !(ebo->flag & BONE_EDITMODE_LOCKED)) { @@ -921,7 +916,7 @@ static void createTransArmatureVerts(bContext * /*C*/, TransInfo *t) } if (mirror && (data_len_prev < tc->data_len)) { - eboflip = ED_armature_ebone_get_mirrored(arm->edbo, ebo); + EditBone *eboflip = ED_armature_ebone_get_mirrored(arm->edbo, ebo); if (eboflip) { total_mirrored++; } @@ -952,7 +947,6 @@ static void createTransArmatureVerts(bContext * /*C*/, TransInfo *t) continue; } - EditBone *ebo, *eboflip; bArmature *arm = static_cast(tc->obedit->data); ListBase *edbo = arm->edbo; TransData *td, *td_old; @@ -967,7 +961,7 @@ static void createTransArmatureVerts(bContext * /*C*/, TransInfo *t) MEM_callocN(tc->data_len * sizeof(TransData), "TransEditBone")); int i = 0; - for (ebo = static_cast(edbo->first); ebo; ebo = ebo->next) { + LISTBASE_FOREACH (EditBone *, ebo, edbo) { td_old = td; /* (length == 0.0) on extrude, used for scaling radius of bone points. */ @@ -1118,7 +1112,7 @@ static void createTransArmatureVerts(bContext * /*C*/, TransInfo *t) } if (mirror && (td_old != td)) { - eboflip = ED_armature_ebone_get_mirrored(arm->edbo, ebo); + EditBone *eboflip = ED_armature_ebone_get_mirrored(arm->edbo, ebo); if (eboflip) { bid[i].bone = eboflip; bid[i].dist = eboflip->dist; @@ -1175,11 +1169,8 @@ static void restoreBones(TransDataContainer *tc) copy_v3_v3(ebo->tail, bid->tail); if (arm->flag & ARM_MIRROR_EDIT) { - EditBone *ebo_child; - /* Also move connected ebo_child, in case ebo_child's name aren't mirrored properly */ - for (ebo_child = static_cast(arm->edbo->first); ebo_child; - ebo_child = ebo_child->next) { + LISTBASE_FOREACH (EditBone *, ebo_child, arm->edbo) { if ((ebo_child->flag & BONE_CONNECTED) && (ebo_child->parent == ebo)) { copy_v3_v3(ebo_child->head, ebo->tail); ebo_child->rad_head = ebo->rad_tail; @@ -1212,7 +1203,7 @@ static void recalcData_edit_armature(TransInfo *t) int i; /* Ensure all bones are correctly adjusted */ - for (ebo = static_cast(edbo->first); ebo; ebo = ebo->next) { + LISTBASE_FOREACH (EditBone *, ebo, edbo) { ebo_parent = (ebo->flag & BONE_CONNECTED) ? ebo->parent : nullptr; if (ebo_parent) { @@ -1534,10 +1525,9 @@ static void bone_children_clear_transflag(int mode, short around, ListBase *lb) void transform_convert_pose_transflags_update(Object *ob, const int mode, const short around) { bArmature *arm = static_cast(ob->data); - bPoseChannel *pchan; Bone *bone; - for (pchan = static_cast(ob->pose->chanbase.first); pchan; pchan = pchan->next) { + LISTBASE_FOREACH (bPoseChannel *, pchan, &ob->pose->chanbase) { bone = pchan->bone; if (PBONE_VISIBLE(arm, bone)) { if (bone->flag & BONE_SELECTED) { @@ -1558,8 +1548,7 @@ void transform_convert_pose_transflags_update(Object *ob, const int mode, const /* make sure no bone can be transformed when a parent is transformed */ /* since pchans are depsgraph sorted, the parents are in beginning of list */ if (!ELEM(mode, TFM_BONESIZE, TFM_BONE_ENVELOPE_DIST)) { - for (pchan = static_cast(ob->pose->chanbase.first); pchan; pchan = pchan->next) - { + LISTBASE_FOREACH (bPoseChannel *, pchan, &ob->pose->chanbase) { bone = pchan->bone; if (bone->flag & BONE_TRANSFORM) { bone_children_clear_transflag(mode, around, &bone->childbase); @@ -1570,7 +1559,7 @@ void transform_convert_pose_transflags_update(Object *ob, const int mode, const static short apply_targetless_ik(Object *ob) { - bPoseChannel *pchan, *parchan, *chanlist[256]; + bPoseChannel *chanlist[256]; bKinematicConstraint *data; int segcount, apply = 0; @@ -1578,7 +1567,7 @@ static short apply_targetless_ik(Object *ob) * target-less IK pchans, and apply transformation to the all * pchans that were in the chain */ - for (pchan = static_cast(ob->pose->chanbase.first); pchan; pchan = pchan->next) { + LISTBASE_FOREACH (bPoseChannel *, pchan, &ob->pose->chanbase) { data = has_targetless_ik(pchan); if (data && (data->flag & CONSTRAINT_IK_AUTO)) { @@ -1586,12 +1575,7 @@ static short apply_targetless_ik(Object *ob) segcount = 0; /* exclude tip from chain? */ - if (!(data->flag & CONSTRAINT_IK_TIP)) { - parchan = pchan->parent; - } - else { - parchan = pchan; - } + bPoseChannel *parchan = (data->flag & CONSTRAINT_IK_TIP) ? pchan : pchan->parent; /* Find the chain's root & count the segments needed */ for (; parchan; parchan = parchan->parent) { @@ -1658,11 +1642,10 @@ static short apply_targetless_ik(Object *ob) static void pose_grab_with_ik_clear(Main *bmain, Object *ob) { bKinematicConstraint *data; - bPoseChannel *pchan; bConstraint *con, *next; bool relations_changed = false; - for (pchan = static_cast(ob->pose->chanbase.first); pchan; pchan = pchan->next) { + LISTBASE_FOREACH (bPoseChannel *, pchan, &ob->pose->chanbase) { /* clear all temporary lock flags */ pchan->ikflag &= ~(BONE_IK_NO_XDOF_TEMP | BONE_IK_NO_YDOF_TEMP | BONE_IK_NO_ZDOF_TEMP); @@ -1716,8 +1699,6 @@ static void special_aftertrans_update__pose(bContext *C, TransInfo *t) GSet *motionpath_updates = BLI_gset_ptr_new("motionpath updates"); FOREACH_TRANS_DATA_CONTAINER (t, tc) { - - bPoseChannel *pchan; short targetless_ik = 0; ob = tc->poseobj; @@ -1741,8 +1722,7 @@ static void special_aftertrans_update__pose(bContext *C, TransInfo *t) } else { /* not forget to clear the auto flag */ - for (pchan = static_cast(ob->pose->chanbase.first); pchan; - pchan = pchan->next) { + LISTBASE_FOREACH (bPoseChannel *, pchan, &ob->pose->chanbase) { bKinematicConstraint *data = has_targetless_ik(pchan); if (data) { data->flag &= ~CONSTRAINT_IK_AUTO; diff --git a/source/blender/editors/transform/transform_convert_gpencil_legacy.cc b/source/blender/editors/transform/transform_convert_gpencil_legacy.cc index 2aa3349c6e9..1af88ef0c34 100644 --- a/source/blender/editors/transform/transform_convert_gpencil_legacy.cc +++ b/source/blender/editors/transform/transform_convert_gpencil_legacy.cc @@ -415,13 +415,12 @@ static void createTransGPencil_strokes(bContext *C, /* Only editable and visible layers are considered. */ if (BKE_gpencil_layer_is_editable(gpl) && (gpl->actframe != nullptr)) { bGPDframe *gpf; - bGPDstroke *gps; bGPDframe *init_gpf = static_cast((is_multiedit) ? gpl->frames.first : gpl->actframe); for (gpf = init_gpf; gpf; gpf = gpf->next) { if ((gpf == gpl->actframe) || ((gpf->flag & GP_FRAME_SELECT) && (is_multiedit))) { - for (gps = static_cast(gpf->strokes.first); gps; gps = gps->next) { + LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) { /* skip strokes that are invalid for current view */ if (ED_gpencil_stroke_can_use(C, gps) == false) { continue; diff --git a/source/blender/editors/transform/transform_convert_graph.cc b/source/blender/editors/transform/transform_convert_graph.cc index 03db426fd3f..ad4c2d83f63 100644 --- a/source/blender/editors/transform/transform_convert_graph.cc +++ b/source/blender/editors/transform/transform_convert_graph.cc @@ -223,7 +223,6 @@ static void createTransGraphEditData(bContext *C, TransInfo *t) bAnimContext ac; ListBase anim_data = {nullptr, nullptr}; - bAnimListElem *ale; int filter; BezTriple *bezt; @@ -260,7 +259,7 @@ static void createTransGraphEditData(bContext *C, TransInfo *t) /* Loop 1: count how many BezTriples (specifically their verts) * are selected (or should be edited). */ - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { AnimData *adt = ANIM_nla_mapping_get(&ac, ale); FCurve *fcu = (FCurve *)ale->key_data; float cfra; @@ -368,7 +367,7 @@ static void createTransGraphEditData(bContext *C, TransInfo *t) } /* loop 2: build transdata arrays */ - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { AnimData *adt = ANIM_nla_mapping_get(&ac, ale); FCurve *fcu = (FCurve *)ale->key_data; bool intvals = (fcu->flag & FCURVE_INT_VALUES) != 0; @@ -561,7 +560,7 @@ static void createTransGraphEditData(bContext *C, TransInfo *t) /* loop 2: build transdata arrays */ td = tc->data; - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { AnimData *adt = ANIM_nla_mapping_get(&ac, ale); FCurve *fcu = (FCurve *)ale->key_data; TransData *td_start = td; @@ -879,11 +878,10 @@ static void beztmap_to_data(TransInfo *t, FCurve *fcu, BeztMap *bezms, int totve static void remake_graph_transdata(TransInfo *t, ListBase *anim_data) { SpaceGraph *sipo = (SpaceGraph *)t->area->spacedata.first; - bAnimListElem *ale; const bool use_handle = (sipo->flag & SIPO_NOHANDLES) == 0; /* sort and reassign verts */ - for (ale = static_cast(anim_data->first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, anim_data) { FCurve *fcu = (FCurve *)ale->key_data; if (fcu->bezt) { @@ -916,7 +914,6 @@ static void recalcData_graphedit(TransInfo *t) bAnimContext ac = {nullptr}; int filter; - bAnimListElem *ale; int dosort = 0; BKE_view_layer_synced_ensure(t->scene, t->view_layer); @@ -945,7 +942,7 @@ static void recalcData_graphedit(TransInfo *t) &ac, &anim_data, eAnimFilter_Flags(filter), ac.data, eAnimCont_Types(ac.datatype)); /* now test if there is a need to re-sort */ - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { FCurve *fcu = (FCurve *)ale->key_data; /* ignore FC-Curves without any selected verts */ @@ -1000,7 +997,6 @@ static void special_aftertrans_update__graph(bContext *C, TransInfo *t) if (ac.datatype) { ListBase anim_data = {nullptr, nullptr}; - bAnimListElem *ale; short filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_FOREDIT | ANIMFILTER_CURVE_VISIBLE | ANIMFILTER_FCURVESONLY); @@ -1008,7 +1004,7 @@ static void special_aftertrans_update__graph(bContext *C, TransInfo *t) ANIM_animdata_filter( &ac, &anim_data, eAnimFilter_Flags(filter), ac.data, eAnimCont_Types(ac.datatype)); - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { AnimData *adt = ANIM_nla_mapping_get(&ac, ale); FCurve *fcu = (FCurve *)ale->key_data; diff --git a/source/blender/editors/transform/transform_convert_mask.cc b/source/blender/editors/transform/transform_convert_mask.cc index 7282a2294cb..e54fee20643 100644 --- a/source/blender/editors/transform/transform_convert_mask.cc +++ b/source/blender/editors/transform/transform_convert_mask.cc @@ -250,7 +250,6 @@ static void createTransMaskingData(bContext *C, TransInfo *t) { Scene *scene = CTX_data_scene(C); Mask *mask = CTX_data_edit_mask(C); - MaskLayer *masklay; TransData *td = nullptr; TransData2D *td2d = nullptr; TransDataMasking *tdm = nullptr; @@ -267,16 +266,12 @@ static void createTransMaskingData(bContext *C, TransInfo *t) } /* count */ - for (masklay = static_cast(mask->masklayers.first); masklay; - masklay = masklay->next) { - MaskSpline *spline; - + LISTBASE_FOREACH (MaskLayer *, masklay, &mask->masklayers) { if (masklay->visibility_flag & (MASK_HIDE_VIEW | MASK_HIDE_SELECT)) { continue; } - for (spline = static_cast(masklay->splines.first); spline; spline = spline->next) - { + LISTBASE_FOREACH (MaskSpline *, spline, &masklay->splines) { int i; for (i = 0; i < spline->tot_point; i++) { @@ -328,16 +323,12 @@ static void createTransMaskingData(bContext *C, TransInfo *t) tc->custom.type.use_free = true; /* create data */ - for (masklay = static_cast(mask->masklayers.first); masklay; - masklay = masklay->next) { - MaskSpline *spline; - + LISTBASE_FOREACH (MaskLayer *, masklay, &mask->masklayers) { if (masklay->visibility_flag & (MASK_HIDE_VIEW | MASK_HIDE_SELECT)) { continue; } - for (spline = static_cast(masklay->splines.first); spline; spline = spline->next) - { + LISTBASE_FOREACH (MaskSpline *, spline, &masklay->splines) { int i; for (i = 0; i < spline->tot_point; i++) { diff --git a/source/blender/editors/transform/transform_convert_mball.cc b/source/blender/editors/transform/transform_convert_mball.cc index 718de056edd..125d5d161b7 100644 --- a/source/blender/editors/transform/transform_convert_mball.cc +++ b/source/blender/editors/transform/transform_convert_mball.cc @@ -27,7 +27,6 @@ static void createTransMBallVerts(bContext * /*C*/, TransInfo *t) { FOREACH_TRANS_DATA_CONTAINER (t, tc) { MetaBall *mb = (MetaBall *)tc->obedit->data; - MetaElem *ml; TransData *td; TransDataExtension *tx; float mtx[3][3], smtx[3][3]; @@ -36,7 +35,7 @@ static void createTransMBallVerts(bContext * /*C*/, TransInfo *t) const bool is_prop_connected = (t->flag & T_PROP_CONNECTED) != 0; /* count totals */ - for (ml = static_cast(mb->editelems->first); ml; ml = ml->next) { + LISTBASE_FOREACH (MetaElem *, ml, mb->editelems) { if (ml->flag & SELECT) { countsel++; } @@ -67,7 +66,7 @@ static void createTransMBallVerts(bContext * /*C*/, TransInfo *t) copy_m3_m4(mtx, tc->obedit->object_to_world); pseudoinverse_m3_m3(smtx, mtx, PSEUDOINVERSE_EPSILON); - for (ml = static_cast(mb->editelems->first); ml; ml = ml->next) { + LISTBASE_FOREACH (MetaElem *, ml, mb->editelems) { if (is_prop_edit || (ml->flag & SELECT)) { td->loc = &ml->x; copy_v3_v3(td->iloc, td->loc); diff --git a/source/blender/editors/transform/transform_convert_nla.cc b/source/blender/editors/transform/transform_convert_nla.cc index bce170c9dff..9a6284ccae0 100644 --- a/source/blender/editors/transform/transform_convert_nla.cc +++ b/source/blender/editors/transform/transform_convert_nla.cc @@ -446,7 +446,6 @@ static void createTransNlaData(bContext *C, TransInfo *t) bAnimContext ac; ListBase anim_data = {nullptr, nullptr}; - bAnimListElem *ale; int filter; int count = 0; @@ -475,15 +474,14 @@ static void createTransNlaData(bContext *C, TransInfo *t) } /* loop 1: count how many strips are selected (consider each strip as 2 points) */ - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { NlaTrack *nlt = (NlaTrack *)ale->data; - NlaStrip *strip; /* make some meta-strips for chains of selected strips */ BKE_nlastrips_make_metas(&nlt->strips, true); /* only consider selected strips */ - for (strip = static_cast(nlt->strips.first); strip; strip = strip->next) { + LISTBASE_FOREACH (NlaStrip *, strip, &nlt->strips) { /* TODO: we can make strips have handles later on. */ /* transition strips can't get directly transformed */ if (strip->type != NLASTRIP_TYPE_TRANSITION) { @@ -504,7 +502,7 @@ static void createTransNlaData(bContext *C, TransInfo *t) /* clear temp metas that may have been created but aren't needed now * because they fell on the wrong side of scene->r.cfra */ - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { NlaTrack *nlt = (NlaTrack *)ale->data; BKE_nlastrips_clear_metas(&nlt->strips, false, true); } @@ -525,15 +523,14 @@ static void createTransNlaData(bContext *C, TransInfo *t) tc->custom.type.use_free = true; /* loop 2: build transdata array */ - for (ale = static_cast(anim_data.first); ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { /* only if a real NLA-track */ if (ale->type == ANIMTYPE_NLATRACK) { AnimData *adt = ale->adt; NlaTrack *nlt = (NlaTrack *)ale->data; - NlaStrip *strip; /* only consider selected strips */ - for (strip = static_cast(nlt->strips.first); strip; strip = strip->next) { + LISTBASE_FOREACH (NlaStrip *, strip, &nlt->strips) { /* TODO: we can make strips have handles later on. */ /* transition strips can't get directly transformed */ if (strip->type != NLASTRIP_TYPE_TRANSITION) { diff --git a/source/blender/editors/transform/transform_convert_object.cc b/source/blender/editors/transform/transform_convert_object.cc index 1d8e3563f97..752c7f0ee3e 100644 --- a/source/blender/editors/transform/transform_convert_object.cc +++ b/source/blender/editors/transform/transform_convert_object.cc @@ -743,7 +743,6 @@ static void autokeyframe_object( { Main *bmain = CTX_data_main(C); ID *id = &ob->id; - FCurve *fcu; /* TODO: this should probably be done per channel instead. */ if (autokeyframe_cfra_can_key(scene, id)) { @@ -776,7 +775,7 @@ static void autokeyframe_object( /* only key on available channels */ if (adt && adt->action) { ListBase nla_cache = {nullptr, nullptr}; - for (fcu = static_cast(adt->action->curves.first); fcu; fcu = fcu->next) { + LISTBASE_FOREACH (FCurve *, fcu, &adt->action->curves) { insert_keyframe(bmain, reports, id, @@ -953,7 +952,6 @@ static void special_aftertrans_update__object(bContext *C, TransInfo *t) for (int i = 0; i < tc->data_len; i++) { TransData *td = tc->data + i; ListBase pidlist; - PTCacheID *pid; ob = td->ob; if (td->flag & TD_SKIP) { @@ -962,7 +960,7 @@ static void special_aftertrans_update__object(bContext *C, TransInfo *t) /* flag object caches as outdated */ BKE_ptcache_ids_from_object(&pidlist, ob, t->scene, MAX_DUPLI_RECUR); - for (pid = static_cast(pidlist.first); pid; pid = pid->next) { + LISTBASE_FOREACH (PTCacheID *, pid, &pidlist) { if (pid->type != PTCACHE_TYPE_PARTICLES) { /* particles don't need reset on geometry change */ pid->cache->flag |= PTCACHE_OUTDATED; diff --git a/source/blender/editors/transform/transform_convert_sequencer.cc b/source/blender/editors/transform/transform_convert_sequencer.cc index 0f54ad153a9..21b159e132c 100644 --- a/source/blender/editors/transform/transform_convert_sequencer.cc +++ b/source/blender/editors/transform/transform_convert_sequencer.cc @@ -152,10 +152,9 @@ static void SeqTransInfo(TransInfo *t, Sequence *seq, int *r_count, int *r_flag) static int SeqTransCount(TransInfo *t, ListBase *seqbase) { - Sequence *seq; int tot = 0, count, flag; - for (seq = static_cast(seqbase->first); seq; seq = seq->next) { + LISTBASE_FOREACH (Sequence *, seq, seqbase) { SeqTransInfo(t, seq, &count, &flag); /* ignore the flag */ tot += count; } @@ -231,12 +230,11 @@ static TransData *SeqToTransData(Scene *scene, static int SeqToTransData_build( TransInfo *t, ListBase *seqbase, TransData *td, TransData2D *td2d, TransDataSeq *tdsq) { - Sequence *seq; Scene *scene = t->scene; int count, flag; int tot = 0; - for (seq = static_cast(seqbase->first); seq; seq = seq->next) { + LISTBASE_FOREACH (Sequence *, seq, seqbase) { SeqTransInfo(t, seq, &count, &flag); diff --git a/source/blender/editors/transform/transform_gizmo_3d.cc b/source/blender/editors/transform/transform_gizmo_3d.cc index 8ef9379d783..5f14970fb6d 100644 --- a/source/blender/editors/transform/transform_gizmo_3d.cc +++ b/source/blender/editors/transform/transform_gizmo_3d.cc @@ -1672,7 +1672,7 @@ static int gizmo_modal(bContext *C, calc_params.use_only_center = true; if (ED_transform_calc_gizmo_stats(C, &calc_params, &tbounds, rv3d)) { gizmo_prepare_mat(C, rv3d, &tbounds); - for (wmGizmo *gz = static_cast(gzgroup->gizmos.first); gz; gz = gz->next) { + LISTBASE_FOREACH (wmGizmo *, gz, &gzgroup->gizmos) { WM_gizmo_set_matrix_location(gz, rv3d->twmat[3]); } } diff --git a/source/blender/editors/transform/transform_orientations.cc b/source/blender/editors/transform/transform_orientations.cc index 1dd2600faab..48d7166899f 100644 --- a/source/blender/editors/transform/transform_orientations.cc +++ b/source/blender/editors/transform/transform_orientations.cc @@ -545,11 +545,10 @@ static int armature_bone_transflags_update_recursive(bArmature *arm, ListBase *lb, const bool do_it) { - Bone *bone; bool do_next; int total = 0; - for (bone = static_cast(lb->first); bone; bone = bone->next) { + LISTBASE_FOREACH (Bone *, bone, lb) { bone->flag &= ~BONE_TRANSFORM; do_next = do_it; if (do_it) { @@ -830,9 +829,8 @@ static uint bm_mesh_elems_select_get_n__internal( if (!BLI_listbase_is_empty(&bm->selected)) { /* quick check */ - BMEditSelection *ese; i = 0; - for (ese = static_cast(bm->selected.last); ese; ese = ese->prev) { + LISTBASE_FOREACH_BACKWARD (BMEditSelection *, ese, &bm->selected) { /* shouldn't need this check */ if (BM_elem_flag_test(ese->ele, BM_ELEM_SELECT)) { @@ -1266,7 +1264,7 @@ int getTransformOrientation_ex(const Scene *scene, ok = true; } else { - for (ml = static_cast(mb->editelems->first); ml; ml = ml->next) { + LISTBASE_FOREACH (MetaElem *, ml, mb->editelems) { if (ml->flag & SELECT) { quat_to_mat3(tmat, ml->quat); add_v3_v3(normal, tmat[2]); @@ -1303,7 +1301,7 @@ int getTransformOrientation_ex(const Scene *scene, zero_v3(fallback_normal); zero_v3(fallback_plane); - for (ebone = static_cast(arm->edbo->first); ebone; ebone = ebone->next) { + LISTBASE_FOREACH (EditBone *, ebone, arm->edbo) { if (ANIM_bonecoll_is_visible_editbone(arm, ebone)) { if (ebone->flag & BONE_SELECTED) { ED_armature_ebone_to_mat3(ebone, tmat); @@ -1370,8 +1368,7 @@ int getTransformOrientation_ex(const Scene *scene, transformed_len = armature_bone_transflags_update_recursive(arm, &arm->bonebase, true); if (transformed_len) { /* use channels to get stats */ - for (pchan = static_cast(ob->pose->chanbase.first); pchan; - pchan = pchan->next) { + LISTBASE_FOREACH (bPoseChannel *, pchan, &ob->pose->chanbase) { if (pchan->bone && pchan->bone->flag & BONE_TRANSFORM) { add_v3_v3(normal, pchan->pose_mat[2]); add_v3_v3(plane, pchan->pose_mat[1]); diff --git a/source/blender/editors/transform/transform_snap.cc b/source/blender/editors/transform/transform_snap.cc index b02f868cd95..f108c822a3d 100644 --- a/source/blender/editors/transform/transform_snap.cc +++ b/source/blender/editors/transform/transform_snap.cc @@ -277,7 +277,6 @@ void drawSnapping(const bContext *C, TransInfo *t) } else if (t->spacetype == SPACE_NODE) { ARegion *region = CTX_wm_region(C); - TransSnapPoint *p; float size; size = 2.5f * UI_GetThemeValuef(TH_VERTEX_SIZE); @@ -288,7 +287,7 @@ void drawSnapping(const bContext *C, TransInfo *t) immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR); - for (p = static_cast(t->tsnap.points.first); p; p = p->next) { + LISTBASE_FOREACH (TransSnapPoint *, p, &t->tsnap.points) { if (p == t->tsnap.selectedPoint) { immUniformColor4ubv(selectedCol); } @@ -1002,11 +1001,11 @@ eRedrawFlag updateSelectedSnapPoint(TransInfo *t) eRedrawFlag status = TREDRAW_NOTHING; if (t->tsnap.status & SNAP_MULTI_POINTS) { - TransSnapPoint *p, *closest_p = nullptr; + TransSnapPoint *closest_p = nullptr; float dist_min_sq = TRANSFORM_SNAP_MAX_PX; float screen_loc[2]; - for (p = static_cast(t->tsnap.points.first); p; p = p->next) { + LISTBASE_FOREACH (TransSnapPoint *, p, &t->tsnap.points) { float dist_sq; if (ED_view3d_project_float_global(t->region, p->co, screen_loc, V3D_PROJ_TEST_NOP) != @@ -1451,9 +1450,7 @@ bool peelObjectsTransform(TransInfo *t, if (use_peel_object) { /* if peeling objects, take the first and last from each object */ hit_max = hit_min; - for (SnapObjectHitDepth *iter = static_cast(depths_peel.first); iter; - iter = iter->next) - { + LISTBASE_FOREACH (SnapObjectHitDepth *, iter, &depths_peel) { if ((iter->depth > hit_max->depth) && (iter->ob_uuid == hit_min->ob_uuid)) { hit_max = iter; } @@ -1461,9 +1458,7 @@ bool peelObjectsTransform(TransInfo *t, } else { /* otherwise, pair first with second and so on */ - for (SnapObjectHitDepth *iter = static_cast(depths_peel.first); iter; - iter = iter->next) - { + LISTBASE_FOREACH (SnapObjectHitDepth *, iter, &depths_peel) { if ((iter != hit_min) && (iter->ob_uuid == hit_min->ob_uuid)) { if (hit_max == nullptr) { hit_max = iter; @@ -1593,12 +1588,11 @@ static bool snapNodes(ToolSettings *ts, char *r_node_border) { bNodeTree *ntree = snode->edittree; - bNode *node; bool retval = false; *r_node_border = 0; - for (node = static_cast(ntree->nodes.first); node; node = node->next) { + LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { if (snapNodeTest(®ion->v2d, node, snap_target_select)) { retval |= snapNode(ts, snode, region, node, mval, r_loc, r_dist_px, r_node_border); } diff --git a/source/blender/editors/util/ed_transverts.cc b/source/blender/editors/util/ed_transverts.cc index 3a0bc3c9a79..7bb1f5178d9 100644 --- a/source/blender/editors/util/ed_transverts.cc +++ b/source/blender/editors/util/ed_transverts.cc @@ -111,12 +111,11 @@ void ED_transverts_update_obedit(TransVertStore *tvs, Object *obedit) } else if (obedit->type == OB_ARMATURE) { bArmature *arm = static_cast(obedit->data); - EditBone *ebo; TransVert *tv = tvs->transverts; int a = 0; /* Ensure all bone tails are correctly adjusted */ - for (ebo = static_cast(arm->edbo->first); ebo; ebo = ebo->next) { + LISTBASE_FOREACH (EditBone *, ebo, arm->edbo) { /* adjust tip if both ends selected */ if ((ebo->flag & BONE_ROOTSEL) && (ebo->flag & BONE_TIPSEL)) { if (tv) { @@ -134,7 +133,7 @@ void ED_transverts_update_obedit(TransVertStore *tvs, Object *obedit) } /* Ensure all bones are correctly adjusted */ - for (ebo = static_cast(arm->edbo->first); ebo; ebo = ebo->next) { + LISTBASE_FOREACH (EditBone *, ebo, arm->edbo) { if ((ebo->flag & BONE_CONNECTED) && ebo->parent) { /* If this bone has a parent tip that has been moved */ if (ebo->parent->flag & BONE_TIPSEL) { @@ -205,7 +204,6 @@ void ED_transverts_create_from_obedit(TransVertStore *tvs, const Object *obedit, TransVert *tv = nullptr; MetaElem *ml; BMVert *eve; - EditBone *ebo; int a; tvs->transverts_tot = 0; @@ -328,7 +326,7 @@ void ED_transverts_create_from_obedit(TransVertStore *tvs, const Object *obedit, tv = tvs->transverts = static_cast( MEM_callocN(totmalloc * sizeof(TransVert), __func__)); - for (ebo = static_cast(arm->edbo->first); ebo; ebo = ebo->next) { + LISTBASE_FOREACH (EditBone *, ebo, arm->edbo) { if (ANIM_bonecoll_is_visible_editbone(arm, ebo)) { const bool tipsel = (ebo->flag & BONE_TIPSEL) != 0; const bool rootsel = (ebo->flag & BONE_ROOTSEL) != 0; @@ -371,7 +369,7 @@ void ED_transverts_create_from_obedit(TransVertStore *tvs, const Object *obedit, int totmalloc = 0; ListBase *nurbs = BKE_curve_editNurbs_get(cu); - for (nu = static_cast(nurbs->first); nu; nu = nu->next) { + LISTBASE_FOREACH (Nurb *, nu, nurbs) { if (nu->type == CU_BEZIER) { totmalloc += 3 * nu->pntsu; } diff --git a/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp b/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp index f8536ada852..610a49f1f5e 100644 --- a/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp +++ b/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp @@ -219,7 +219,7 @@ Material *BlenderStrokeRenderer::GetStrokeShader(Main *bmain, ntree = blender::bke::ntreeCopyTree_ex(iNodeTree, bmain, do_id_user); // find the active Output Line Style node - for (bNode *node = (bNode *)ntree->nodes.first; node; node = node->next) { + LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { if (node->type == SH_NODE_OUTPUT_LINESTYLE && (node->flag & NODE_DO_OUTPUT)) { output_linestyle = node; break; @@ -382,7 +382,7 @@ Material *BlenderStrokeRenderer::GetStrokeShader(Main *bmain, RNA_float_set(&toptr, "default_value", RNA_float_get(&fromptr, "default_value")); } - for (bNode *node = (bNode *)ntree->nodes.first; node; node = node->next) { + LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { if (node->type == SH_NODE_UVALONGSTROKE) { // UV output of the UV Along Stroke node bNodeSocket *sock = (bNodeSocket *)BLI_findlink(&node->outputs, 0); @@ -401,7 +401,7 @@ Material *BlenderStrokeRenderer::GetStrokeShader(Main *bmain, fromsock = (bNodeSocket *)BLI_findlink(&input_uvmap->outputs, 0); // UV // replace links from the UV Along Stroke node by links from the UV Map node - for (bNodeLink *link = (bNodeLink *)ntree->links.first; link; link = link->next) { + LISTBASE_FOREACH (bNodeLink *, link, &ntree->links) { if (link->fromnode == node && link->fromsock == sock) { nodeAddLink(ntree, input_uvmap, fromsock, link->tonode, link->tosock); } diff --git a/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp b/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp index 39650b0cffb..835d354dbc7 100644 --- a/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp +++ b/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp @@ -302,10 +302,7 @@ static void prepare(Render *re, ViewLayer *view_layer, Depsgraph *depsgraph) if (G.debug & G_DEBUG_FREESTYLE) { cout << "Modules :" << endl; } - for (FreestyleModuleConfig *module_conf = (FreestyleModuleConfig *)config->modules.first; - module_conf; - module_conf = module_conf->next) - { + LISTBASE_FOREACH (FreestyleModuleConfig *, module_conf, &config->modules) { if (module_conf->script && module_conf->is_displayed) { const char *id_name = module_conf->script->id.name + 2; if (G.debug & G_DEBUG_FREESTYLE) { @@ -349,9 +346,7 @@ static void prepare(Render *re, ViewLayer *view_layer, Depsgraph *depsgraph) if (G.debug & G_DEBUG_FREESTYLE) { cout << "Linesets:" << endl; } - for (FreestyleLineSet *lineset = (FreestyleLineSet *)config->linesets.first; lineset; - lineset = lineset->next) - { + LISTBASE_FOREACH (FreestyleLineSet *, lineset, &config->linesets) { if (lineset->flags & FREESTYLE_LINESET_ENABLED) { if (G.debug & G_DEBUG_FREESTYLE) { cout << " " << layer_count + 1 << ": " << lineset->name << " - " @@ -448,7 +443,7 @@ static void prepare(Render *re, ViewLayer *view_layer, Depsgraph *depsgraph) // set diffuse and z depth passes RenderLayer *rl = RE_GetRenderLayer(re->result, view_layer->name); bool diffuse = false, z = false; - for (RenderPass *rpass = (RenderPass *)rl->passes.first; rpass; rpass = rpass->next) { + LISTBASE_FOREACH (RenderPass *, rpass, &rl->passes) { float *rpass_buffer_data = rpass->ibuf->float_buffer.data; if (STREQ(rpass->name, RE_PASSNAME_DIFFUSE_COLOR)) { controller->setPassDiffuse(rpass_buffer_data, rpass->rectx, rpass->recty); @@ -559,22 +554,14 @@ static int displayed_layer_count(ViewLayer *view_layer) switch (view_layer->freestyle_config.mode) { case FREESTYLE_CONTROL_SCRIPT_MODE: - for (FreestyleModuleConfig *module = - (FreestyleModuleConfig *)view_layer->freestyle_config.modules.first; - module; - module = module->next) - { + LISTBASE_FOREACH (FreestyleModuleConfig *, module, &view_layer->freestyle_config.modules) { if (module->script && module->is_displayed) { count++; } } break; case FREESTYLE_CONTROL_EDITOR_MODE: - for (FreestyleLineSet *lineset = - (FreestyleLineSet *)view_layer->freestyle_config.linesets.first; - lineset; - lineset = lineset->next) - { + LISTBASE_FOREACH (FreestyleLineSet *, lineset, &view_layer->freestyle_config.linesets) { if (lineset->flags & FREESTYLE_LINESET_ENABLED) { count++; } diff --git a/source/blender/gpencil_modifiers_legacy/intern/MOD_gpencil_legacy_build.cc b/source/blender/gpencil_modifiers_legacy/intern/MOD_gpencil_legacy_build.cc index f8f9ce46d5d..91dc28331a5 100644 --- a/source/blender/gpencil_modifiers_legacy/intern/MOD_gpencil_legacy_build.cc +++ b/source/blender/gpencil_modifiers_legacy/intern/MOD_gpencil_legacy_build.cc @@ -601,7 +601,7 @@ static void build_concurrent(BuildGpencilModifierData *mmd, /* 1) Determine the longest stroke, to figure out when short strokes should start */ /* Todo: A *really* long stroke here could dwarf everything else, causing bad timings */ - for (gps = static_cast(gpf->strokes.first); gps; gps = gps->next) { + LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) { if (gps->totpoints > max_points) { max_points = gps->totpoints; } diff --git a/source/blender/gpencil_modifiers_legacy/intern/MOD_gpencil_legacy_multiply.cc b/source/blender/gpencil_modifiers_legacy/intern/MOD_gpencil_legacy_multiply.cc index 9391daf0e1a..a5b572a777c 100644 --- a/source/blender/gpencil_modifiers_legacy/intern/MOD_gpencil_legacy_multiply.cc +++ b/source/blender/gpencil_modifiers_legacy/intern/MOD_gpencil_legacy_multiply.cc @@ -182,9 +182,8 @@ static void duplicateStroke(Object *ob, static void generate_geometry(GpencilModifierData *md, Object *ob, bGPDlayer *gpl, bGPDframe *gpf) { MultiplyGpencilModifierData *mmd = (MultiplyGpencilModifierData *)md; - bGPDstroke *gps; ListBase duplicates = {nullptr}; - for (gps = static_cast(gpf->strokes.first); gps; gps = gps->next) { + LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) { if (!is_stroke_affected_by_modifier(ob, mmd->layername, mmd->material, diff --git a/source/blender/gpencil_modifiers_legacy/intern/lineart/lineart_chain.cc b/source/blender/gpencil_modifiers_legacy/intern/lineart/lineart_chain.cc index 54f074ffcdb..b4abfc0c1df 100644 --- a/source/blender/gpencil_modifiers_legacy/intern/lineart/lineart_chain.cc +++ b/source/blender/gpencil_modifiers_legacy/intern/lineart/lineart_chain.cc @@ -263,7 +263,7 @@ void MOD_lineart_chain_feature_lines(LineartData *ld) } if (new_vt == new_e->v1) { - for (es = static_cast(new_e->segments.last); es; es = es->prev) { + LISTBASE_FOREACH_BACKWARD (LineartEdgeSegment *, es, &new_e->segments) { double gpos[3], lpos[3]; double *lfb = new_e->v1->fbcoord, *rfb = new_e->v2->fbcoord; double global_at = lfb[3] * es->ratio / (es->ratio * lfb[3] + (1 - es->ratio) * rfb[3]); @@ -420,7 +420,7 @@ void MOD_lineart_chain_feature_lines(LineartData *ld) eci->occlusion = last_occlusion; eci->material_mask_bits = last_transparency; eci->shadow_mask_bits = last_shadow; - for (es = static_cast(new_e->segments.last); es; es = es->prev) { + LISTBASE_FOREACH_BACKWARD (LineartEdgeSegment *, es, &new_e->segments) { double gpos[3], lpos[3]; double *lfb = new_e->v1->fbcoord, *rfb = new_e->v2->fbcoord; double global_at = lfb[3] * es->ratio / (es->ratio * lfb[3] + (1 - es->ratio) * rfb[3]); @@ -1036,7 +1036,7 @@ float MOD_lineart_chain_compute_length(LineartEdgeChain *ec) return 0; } copy_v2_v2(last_point, eci->pos); - for (eci = static_cast(ec->chain.first); eci; eci = eci->next) { + LISTBASE_FOREACH (LineartEdgeChainItem *, eci, &ec->chain) { dist = len_v2v2(eci->pos, last_point); offset_accum += dist; copy_v2_v2(last_point, eci->pos); @@ -1316,12 +1316,13 @@ void MOD_lineart_chain_split_angle(LineartData *ld, float angle_threshold_rad) break; /* No need to split at the last point anyway. */ } if (angle < angle_threshold_rad) { - LineartEdgeChain *new_ec = lineart_chain_create(ld); + LineartEdgeChain *new_ec; + new_ec = lineart_chain_create(ld); new_ec->chain.first = eci; new_ec->chain.last = ec->chain.last; ec->chain.last = eci->prev; - ((LineartEdgeChainItem *)ec->chain.last)->next = nullptr; - eci->prev = nullptr; + ((LineartEdgeChainItem *)ec->chain.last)->next = 0; + eci->prev = 0; /* End the previous one. */ lineart_chain_append_point(ld, diff --git a/source/blender/gpencil_modifiers_legacy/intern/lineart/lineart_shadow.cc b/source/blender/gpencil_modifiers_legacy/intern/lineart/lineart_shadow.cc index 2cb3008330f..f90943f386b 100644 --- a/source/blender/gpencil_modifiers_legacy/intern/lineart/lineart_shadow.cc +++ b/source/blender/gpencil_modifiers_legacy/intern/lineart/lineart_shadow.cc @@ -528,7 +528,7 @@ static void lineart_shadow_edge_cut(LineartData *ld, /* Begin looking for starting position of the segment. */ /* Not using a list iteration macro because of it more clear when using for loops to iterate * through the segments. */ - for (seg = static_cast(e->shadow_segments.first); seg; seg = seg->next) { + LISTBASE_FOREACH (LineartShadowSegment *, seg, &e->shadow_segments) { if (LRT_DOUBLE_CLOSE_ENOUGH(seg->ratio, start)) { cut_start_after = seg; new_seg_1 = cut_start_after; @@ -1076,7 +1076,6 @@ static void lineart_shadow_register_silhouette(LineartData *ld) static void lineart_shadow_register_enclosed_shapes(LineartData *ld, LineartData *shadow_ld) { LineartEdge *e; - LineartEdgeSegment *es; for (int i = 0; i < shadow_ld->pending_edges.next; i++) { e = shadow_ld->pending_edges.array[i]; @@ -1085,7 +1084,7 @@ static void lineart_shadow_register_enclosed_shapes(LineartData *ld, LineartData if (e->min_occ > 0) { continue; } - for (es = static_cast(e->segments.first); es; es = es->next) { + LISTBASE_FOREACH (LineartEdgeSegment *, es, &e->segments) { if (es->occlusion > 0) { continue; } diff --git a/source/blender/gpu/intern/gpu_batch_presets.cc b/source/blender/gpu/intern/gpu_batch_presets.cc index 0c4b98f2d27..a1973211242 100644 --- a/source/blender/gpu/intern/gpu_batch_presets.cc +++ b/source/blender/gpu/intern/gpu_batch_presets.cc @@ -366,7 +366,7 @@ void gpu_batch_presets_register(GPUBatch *preset_batch) bool gpu_batch_presets_unregister(GPUBatch *preset_batch) { BLI_mutex_lock(&g_presets_3d.mutex); - for (LinkData *link = static_cast(presets_list.last); link; link = link->prev) { + LISTBASE_FOREACH_BACKWARD (LinkData *, link, &presets_list) { if (preset_batch == link->data) { BLI_remlink(&presets_list, link); BLI_mutex_unlock(&g_presets_3d.mutex); diff --git a/source/blender/gpu/intern/gpu_node_graph.cc b/source/blender/gpu/intern/gpu_node_graph.cc index c75e925f441..c7c27074440 100644 --- a/source/blender/gpu/intern/gpu_node_graph.cc +++ b/source/blender/gpu/intern/gpu_node_graph.cc @@ -831,9 +831,7 @@ bool GPU_stack_link(GPUMaterial *material, static void gpu_inputs_free(ListBase *inputs) { - GPUInput *input; - - for (input = static_cast(inputs->first); input; input = input->next) { + LISTBASE_FOREACH (GPUInput *, input, inputs) { switch (input->source) { case GPU_SOURCE_ATTR: input->attr->users--; @@ -862,11 +860,9 @@ static void gpu_inputs_free(ListBase *inputs) static void gpu_node_free(GPUNode *node) { - GPUOutput *output; - gpu_inputs_free(&node->inputs); - for (output = static_cast(node->outputs.first); output; output = output->next) { + LISTBASE_FOREACH (GPUOutput *, output, &node->outputs) { if (output->link) { output->link->output = nullptr; gpu_node_link_free(output->link); diff --git a/source/blender/ikplugin/intern/iksolver_plugin.cc b/source/blender/ikplugin/intern/iksolver_plugin.cc index a7f12f4ce8a..3bbafb0dc53 100644 --- a/source/blender/ikplugin/intern/iksolver_plugin.cc +++ b/source/blender/ikplugin/intern/iksolver_plugin.cc @@ -278,7 +278,6 @@ static void execute_posetree(Depsgraph *depsgraph, Scene *scene, Object *ob, Pos bPoseChannel *pchan; IK_Segment *seg, *parent, **iktree, *iktarget; IK_Solver *solver; - PoseTarget *target; bKinematicConstraint *data, *poleangledata = nullptr; Bone *bone; @@ -409,7 +408,7 @@ static void execute_posetree(Depsgraph *depsgraph, Scene *scene, Object *ob, Pos mul_m4_m4m4(imat, ob->object_to_world, rootmat); invert_m4_m4(goalinv, imat); - for (target = static_cast(tree->targets.first); target; target = target->next) { + LISTBASE_FOREACH (PoseTarget *, target, &tree->targets) { float polepos[3]; int poleconstrain = 0; @@ -577,9 +576,7 @@ void iksolver_initialize_tree(Depsgraph * /*depsgraph*/, Object *ob, float /*ctime*/) { - bPoseChannel *pchan; - - for (pchan = static_cast(ob->pose->chanbase.first); pchan; pchan = pchan->next) { + LISTBASE_FOREACH (bPoseChannel *, pchan, &ob->pose->chanbase) { if (pchan->constflag & PCHAN_HAS_IK) { /* flag is set on editing constraints */ initialize_posetree(ob, pchan); /* will attach it to root! */ } diff --git a/source/blender/ikplugin/intern/itasc_plugin.cc b/source/blender/ikplugin/intern/itasc_plugin.cc index e8cca95e0d3..cb70ab2b654 100644 --- a/source/blender/ikplugin/intern/itasc_plugin.cc +++ b/source/blender/ikplugin/intern/itasc_plugin.cc @@ -395,12 +395,9 @@ static bool constraint_valid(bConstraint *con) static int initialize_scene(Object *ob, bPoseChannel *pchan_tip) { - bConstraint *con; - int treecount; - - /* find all IK constraints and validate them */ - treecount = 0; - for (con = (bConstraint *)pchan_tip->constraints.first; con; con = (bConstraint *)con->next) { + /* Find all IK constraints and validate them. */ + int treecount = 0; + LISTBASE_FOREACH (bConstraint *, con, &pchan_tip->constraints) { if (con->type == CONSTRAINT_TYPE_KINEMATIC) { if (constraint_valid(con)) { treecount += initialize_chain(ob, pchan_tip, con); @@ -1639,11 +1636,8 @@ static IK_Scene *convert_tree( static void create_scene(Depsgraph *depsgraph, Scene *scene, Object *ob, float ctime) { - bPoseChannel *pchan; - /* create the IK scene */ - for (pchan = (bPoseChannel *)ob->pose->chanbase.first; pchan; - pchan = (bPoseChannel *)pchan->next) { + LISTBASE_FOREACH (bPoseChannel *, pchan, &ob->pose->chanbase) { /* by construction there is only one tree */ PoseTree *tree = (PoseTree *)pchan->iktree.first; if (tree) { @@ -1877,7 +1871,6 @@ static void execute_scene(Depsgraph *depsgraph, void itasc_initialize_tree(Depsgraph *depsgraph, Scene *scene, Object *ob, float ctime) { - bPoseChannel *pchan; int count = 0; if (ob->pose->ikdata != nullptr && !(ob->pose->flag & POSE_WAS_REBUILT)) { @@ -1889,8 +1882,7 @@ void itasc_initialize_tree(Depsgraph *depsgraph, Scene *scene, Object *ob, float itasc_clear_data(ob->pose); /* we should handle all the constraint and mark them all disabled * for blender but we'll start with the IK constraint alone */ - for (pchan = (bPoseChannel *)ob->pose->chanbase.first; pchan; - pchan = (bPoseChannel *)pchan->next) { + LISTBASE_FOREACH (bPoseChannel *, pchan, &ob->pose->chanbase) { if (pchan->constflag & PCHAN_HAS_IK) { count += initialize_scene(ob, pchan); } diff --git a/source/blender/imbuf/intern/oiio/openimageio_support.cc b/source/blender/imbuf/intern/oiio/openimageio_support.cc index 7207292217b..7ce4f18d8c3 100644 --- a/source/blender/imbuf/intern/oiio/openimageio_support.cc +++ b/source/blender/imbuf/intern/oiio/openimageio_support.cc @@ -383,9 +383,7 @@ ImageSpec imb_create_write_spec(const WriteContext &ctx, int file_channels, Type */ if (ctx.ibuf->metadata) { - for (IDProperty *prop = static_cast(ctx.ibuf->metadata->data.group.first); prop; - prop = prop->next) - { + LISTBASE_FOREACH (IDProperty *, prop, &ctx.ibuf->metadata->data.group) { if (prop->type == IDP_STRING) { /* If this property has a prefixed name (oiio:, tiff:, etc.) and it belongs to * oiio or a different format, then skip. */ diff --git a/source/blender/imbuf/intern/openexr/openexr_api.cpp b/source/blender/imbuf/intern/openexr/openexr_api.cpp index aa85d5e6ed1..1583d271aa5 100644 --- a/source/blender/imbuf/intern/openexr/openexr_api.cpp +++ b/source/blender/imbuf/intern/openexr/openexr_api.cpp @@ -434,9 +434,7 @@ static void openexr_header_compression(Header *header, int compression) static void openexr_header_metadata(Header *header, ImBuf *ibuf) { if (ibuf->metadata) { - IDProperty *prop; - - for (prop = (IDProperty *)ibuf->metadata->data.group.first; prop; prop = prop->next) { + LISTBASE_FOREACH (IDProperty *, prop, &ibuf->metadata->data.group) { if (prop->type == IDP_STRING && !STREQ(prop->name, "compression")) { header->insert(prop->name, StringAttribute(IDP_String(prop))); } @@ -889,14 +887,13 @@ bool IMB_exr_begin_write(void *handle, { ExrHandle *data = (ExrHandle *)handle; Header header(width, height); - ExrChannel *echan; data->width = width; data->height = height; bool is_singlelayer, is_multilayer, is_multiview; - for (echan = (ExrChannel *)data->channels.first; echan; echan = echan->next) { + LISTBASE_FOREACH (ExrChannel *, echan, &data->channels) { header.channels().insert(echan->name, Channel(echan->use_half_float ? Imf::HALF : Imf::FLOAT)); } @@ -950,7 +947,6 @@ void IMB_exrtile_begin_write( ExrHandle *data = (ExrHandle *)handle; Header header(width, height); std::vector
headers; - ExrChannel *echan; data->tilex = tilex; data->tiley = tiley; @@ -979,7 +975,7 @@ void IMB_exrtile_begin_write( exr_printf("---------------------------------------------------------------\n"); /* Assign channels. */ - for (echan = (ExrChannel *)data->channels.first; echan; echan = echan->next) { + LISTBASE_FOREACH (ExrChannel *, echan, &data->channels) { /* Tiles are expected to be saved with full float currently. */ BLI_assert(echan->use_half_float == 0); @@ -1143,9 +1139,8 @@ float *IMB_exr_channel_rect(void *handle, void IMB_exr_clear_channels(void *handle) { ExrHandle *data = (ExrHandle *)handle; - ExrChannel *chan; - for (chan = (ExrChannel *)data->channels.first; chan; chan = chan->next) { + LISTBASE_FOREACH (ExrChannel *, chan, &data->channels) { delete chan->m; } @@ -1156,7 +1151,6 @@ void IMB_exr_write_channels(void *handle) { ExrHandle *data = (ExrHandle *)handle; FrameBuffer frameBuffer; - ExrChannel *echan; if (data->channels.first) { const size_t num_pixels = size_t(data->width) * data->height; @@ -1169,7 +1163,7 @@ void IMB_exr_write_channels(void *handle) current_rect_half = rect_half; } - for (echan = (ExrChannel *)data->channels.first; echan; echan = echan->next) { + LISTBASE_FOREACH (ExrChannel *, echan, &data->channels) { /* Writing starts from last scan-line, stride negative. */ if (echan->use_half_float) { float *rect = echan->rect; @@ -1227,10 +1221,7 @@ void IMB_exrtile_write_channels( exr_printf("---------------------------------------------------------------------\n"); if (!empty) { - ExrChannel *echan; - - for (echan = (ExrChannel *)data->channels.first; echan; echan = echan->next) { - + LISTBASE_FOREACH (ExrChannel *, echan, &data->channels) { /* eventually we can make the parts' channels to include * only the current view TODO */ if (!STREQ(viewname, echan->m->view.c_str())) { @@ -1295,9 +1286,8 @@ void IMB_exr_read_channels(void *handle) /* Insert all matching channel into frame-buffer. */ FrameBuffer frameBuffer; - ExrChannel *echan; - for (echan = (ExrChannel *)data->channels.first; echan; echan = echan->next) { + LISTBASE_FOREACH (ExrChannel *, echan, &data->channels) { if (echan->m->part_number != i) { continue; } @@ -1360,8 +1350,6 @@ void IMB_exr_multilayer_convert(void *handle, const char *view)) { ExrHandle *data = (ExrHandle *)handle; - ExrLayer *lay; - ExrPass *pass; /* RenderResult needs at least one RenderView */ if (data->multiView->empty()) { @@ -1379,10 +1367,10 @@ void IMB_exr_multilayer_convert(void *handle, return; } - for (lay = (ExrLayer *)data->layers.first; lay; lay = lay->next) { + LISTBASE_FOREACH (ExrLayer *, lay, &data->layers) { void *laybase = addlayer(base, lay->name); if (laybase) { - for (pass = (ExrPass *)lay->passes.first; pass; pass = pass->next) { + LISTBASE_FOREACH (ExrPass *, pass, &lay->passes) { addpass(base, laybase, pass->internal_name, @@ -1399,9 +1387,6 @@ void IMB_exr_multilayer_convert(void *handle, void IMB_exr_close(void *handle) { ExrHandle *data = (ExrHandle *)handle; - ExrLayer *lay; - ExrPass *pass; - ExrChannel *chan; delete data->ifile; delete data->ifile_stream; @@ -1416,13 +1401,13 @@ void IMB_exr_close(void *handle) data->mpofile = nullptr; data->ofile_stream = nullptr; - for (chan = (ExrChannel *)data->channels.first; chan; chan = chan->next) { + LISTBASE_FOREACH (ExrChannel *, chan, &data->channels) { delete chan->m; } BLI_freelistN(&data->channels); - for (lay = (ExrLayer *)data->layers.first; lay; lay = lay->next) { - for (pass = (ExrPass *)lay->passes.first; pass; pass = pass->next) { + LISTBASE_FOREACH (ExrLayer *, lay, &data->layers) { + LISTBASE_FOREACH (ExrPass *, pass, &lay->passes) { if (pass->rect) { MEM_freeN(pass->rect); } @@ -1639,8 +1624,8 @@ static bool imb_exr_multilayer_parse_channels_from_file(ExrHandle *data) } /* with some heuristics, try to merge the channels in buffers */ - for (ExrLayer *lay = (ExrLayer *)data->layers.first; lay; lay = lay->next) { - for (ExrPass *pass = (ExrPass *)lay->passes.first; pass; pass = pass->next) { + LISTBASE_FOREACH (ExrLayer *, lay, &data->layers) { + LISTBASE_FOREACH (ExrPass *, pass, &lay->passes) { if (pass->totchan) { pass->rect = (float *)MEM_callocN( data->width * data->height * pass->totchan * sizeof(float), "pass rect"); diff --git a/source/blender/io/collada/AnimationExporter.cpp b/source/blender/io/collada/AnimationExporter.cpp index eee6188679b..57860ef4530 100644 --- a/source/blender/io/collada/AnimationExporter.cpp +++ b/source/blender/io/collada/AnimationExporter.cpp @@ -144,7 +144,7 @@ void AnimationExporter::exportAnimation(Object *ob, BCAnimationSampler &sampler) /* Export skeletal animation (if any) */ bArmature *arm = (bArmature *)ob->data; - for (Bone *root_bone = (Bone *)arm->bonebase.first; root_bone; root_bone = root_bone->next) { + LISTBASE_FOREACH (Bone *, root_bone, &arm->bonebase) { export_bone_animations_recursive(ob, root_bone, sampler); } } @@ -248,7 +248,7 @@ void AnimationExporter::export_bone_animations_recursive(Object *ob, } } - for (Bone *child = (Bone *)bone->childbase.first; child; child = child->next) { + LISTBASE_FOREACH (Bone *, child, &bone->childbase) { export_bone_animations_recursive(ob, child, sampler); } } @@ -364,7 +364,7 @@ bool AnimationExporter::is_bone_deform_group(Bone *bone) } /* Check child bones */ - for (Bone *child = (Bone *)bone->childbase.first; child; child = child->next) { + LISTBASE_FOREACH (Bone *, child, &bone->childbase) { /* loop through all the children until deform bone is found, and then return */ is_def = is_bone_deform_group(child); if (is_def) { diff --git a/source/blender/io/collada/ArmatureExporter.cpp b/source/blender/io/collada/ArmatureExporter.cpp index c8405e103d4..b957b036fc8 100644 --- a/source/blender/io/collada/ArmatureExporter.cpp +++ b/source/blender/io/collada/ArmatureExporter.cpp @@ -43,7 +43,7 @@ void ArmatureExporter::add_armature_bones(Object *ob_arm, ED_armature_to_edit(armature); } - for (Bone *bone = (Bone *)armature->bonebase.first; bone; bone = bone->next) { + LISTBASE_FOREACH (Bone *, bone, &armature->bonebase) { add_bone_node(bone, ob_arm, se, child_objects); } @@ -61,7 +61,7 @@ void ArmatureExporter::write_bone_URLs(COLLADASW::InstanceController &ins, ins.addSkeleton(COLLADABU::URI(COLLADABU::Utils::EMPTY_STRING, joint_id)); } else { - for (Bone *child = (Bone *)bone->childbase.first; child; child = child->next) { + LISTBASE_FOREACH (Bone *, child, &bone->childbase) { write_bone_URLs(ins, ob_arm, child); } } @@ -84,7 +84,7 @@ bool ArmatureExporter::add_instance_controller(Object *ob) /* write root bone URLs */ Bone *bone; - for (bone = (Bone *)arm->bonebase.first; bone; bone = bone->next) { + LISTBASE_FOREACH (Bone *, bone, &arm->bonebase) { write_bone_URLs(ins, ob_arm, bone); } @@ -223,13 +223,13 @@ void ArmatureExporter::add_bone_node(Bone *bone, } } - for (Bone *child = (Bone *)bone->childbase.first; child; child = child->next) { + LISTBASE_FOREACH (Bone *, child, &bone->childbase) { add_bone_node(child, ob_arm, se, child_objects); } node.end(); } else { - for (Bone *child = (Bone *)bone->childbase.first; child; child = child->next) { + LISTBASE_FOREACH (Bone *, child, &bone->childbase) { add_bone_node(child, ob_arm, se, child_objects); } } diff --git a/source/blender/io/collada/ArmatureImporter.cpp b/source/blender/io/collada/ArmatureImporter.cpp index b89a2979080..1bd24c60eee 100644 --- a/source/blender/io/collada/ArmatureImporter.cpp +++ b/source/blender/io/collada/ArmatureImporter.cpp @@ -226,7 +226,7 @@ void ArmatureImporter::fix_leaf_bone_hierarchy(bArmature *armature, fix_leaf_bone(armature, ebone, be, fix_orientation); } - for (Bone *child = (Bone *)bone->childbase.first; child; child = child->next) { + LISTBASE_FOREACH (Bone *, child, &bone->childbase) { fix_leaf_bone_hierarchy(armature, child, fix_orientation); } } @@ -272,7 +272,7 @@ void ArmatureImporter::fix_parent_connect(bArmature *armature, Bone *bone) copy_v3_v3(bone->parent->tail, bone->head); } - for (Bone *child = (Bone *)bone->childbase.first; child; child = child->next) { + LISTBASE_FOREACH (Bone *, child, &bone->childbase) { fix_parent_connect(armature, child); } } @@ -338,7 +338,7 @@ void ArmatureImporter::connect_bone_chains(bArmature *armature, } } } - for (Bone *ch = (Bone *)parentbone->childbase.first; ch; ch = ch->next) { + LISTBASE_FOREACH (Bone *, ch, &parentbone->childbase) { ArmatureImporter::connect_bone_chains(armature, ch, UNLIMITED_CHAIN_MAX); } } @@ -351,7 +351,7 @@ void ArmatureImporter::connect_bone_chains(bArmature *armature, if (pbe) { pbe->set_leaf_bone(true); } - for (Bone *ch = (Bone *)parentbone->childbase.first; ch; ch = ch->next) { + LISTBASE_FOREACH (Bone *, ch, &parentbone->childbase) { ArmatureImporter::connect_bone_chains(armature, ch, UNLIMITED_CHAIN_MAX); } } diff --git a/source/blender/io/collada/BCAnimationSampler.cpp b/source/blender/io/collada/BCAnimationSampler.cpp index ed1a151e3e0..5eb41c69a8a 100644 --- a/source/blender/io/collada/BCAnimationSampler.cpp +++ b/source/blender/io/collada/BCAnimationSampler.cpp @@ -102,7 +102,7 @@ static void add_keyframes_from(bAction *action, BCFrameSet &frameset) { if (action) { FCurve *fcu = nullptr; - for (fcu = (FCurve *)action->curves.first; fcu; fcu = fcu->next) { + LISTBASE_FOREACH (FCurve *, fcu, &action->curves) { BezTriple *bezt = fcu->bezt; for (int i = 0; i < fcu->totvert; bezt++, i++) { int frame_index = nearbyint(bezt->vec[1][0]); @@ -155,7 +155,7 @@ BCSample &BCAnimationSampler::sample_object(Object *ob, int frame_index, bool fo if (ob->type == OB_ARMATURE) { bPoseChannel *pchan; - for (pchan = (bPoseChannel *)ob->pose->chanbase.first; pchan; pchan = pchan->next) { + LISTBASE_FOREACH (bPoseChannel *, pchan, &ob->pose->chanbase) { Bone *bone = pchan->bone; Matrix bmat; if (bc_bone_matrix_local_get(ob, bone, bmat, for_opensim)) { @@ -223,7 +223,7 @@ bool BCAnimationSampler::is_animated_by_constraint(Object *ob, std::set &animated_objects) { bConstraint *con; - for (con = (bConstraint *)conlist->first; con; con = con->next) { + LISTBASE_FOREACH (bConstraint *, con, conlist) { ListBase targets = {nullptr, nullptr}; if (!bc_validateConstraints(con)) { @@ -235,7 +235,7 @@ bool BCAnimationSampler::is_animated_by_constraint(Object *ob, Object *obtar; bool found = false; - for (ct = (bConstraintTarget *)targets.first; ct; ct = ct->next) { + LISTBASE_FOREACH (bConstraintTarget *, ct, &targets) { obtar = ct->tar; if (obtar) { if (animated_objects.find(obtar) != animated_objects.end()) { @@ -400,7 +400,7 @@ void BCAnimationSampler::generate_transforms(Object *ob, Bone *bone, BCAnimation std::string prep = "pose.bones[\"" + std::string(bone->name) + "\"]."; generate_transforms(ob, prep, BC_ANIMATION_TYPE_BONE, curves); - for (Bone *child = (Bone *)bone->childbase.first; child; child = child->next) { + LISTBASE_FOREACH (Bone *, child, &bone->childbase) { generate_transforms(ob, child, curves); } } @@ -446,7 +446,7 @@ void BCAnimationSampler::initialize_curves(BCAnimationCurveMap &curves, Object * generate_transforms(ob, EMPTY_STRING, object_type, curves); if (ob->type == OB_ARMATURE) { bArmature *arm = (bArmature *)ob->data; - for (Bone *root_bone = (Bone *)arm->bonebase.first; root_bone; root_bone = root_bone->next) { + LISTBASE_FOREACH (Bone *, root_bone, &arm->bonebase) { generate_transforms(ob, root_bone, curves); } } diff --git a/source/blender/io/collada/ControllerExporter.cpp b/source/blender/io/collada/ControllerExporter.cpp index 5ac8f272bde..a3cc098000f 100644 --- a/source/blender/io/collada/ControllerExporter.cpp +++ b/source/blender/io/collada/ControllerExporter.cpp @@ -48,7 +48,7 @@ void ControllerExporter::write_bone_URLs(COLLADASW::InstanceController &ins, ins.addSkeleton(COLLADABU::URI(COLLADABU::Utils::EMPTY_STRING, node_id)); } else { - for (Bone *child = (Bone *)bone->childbase.first; child; child = child->next) { + LISTBASE_FOREACH (Bone *, child, &bone->childbase) { write_bone_URLs(ins, ob_arm, child); } } @@ -71,7 +71,7 @@ bool ControllerExporter::add_instance_controller(Object *ob) /* write root bone URLs */ Bone *bone; - for (bone = (Bone *)arm->bonebase.first; bone; bone = bone->next) { + LISTBASE_FOREACH (Bone *, bone, &arm->bonebase) { write_bone_URLs(ins, ob_arm, bone); } @@ -425,7 +425,7 @@ std::string ControllerExporter::add_joints_source(Object *ob_arm, int totjoint = 0; bDeformGroup *def; - for (def = (bDeformGroup *)defbase->first; def; def = def->next) { + LISTBASE_FOREACH (bDeformGroup *, def, defbase) { if (is_bone_defgroup(ob_arm, def)) { totjoint++; } @@ -442,7 +442,7 @@ std::string ControllerExporter::add_joints_source(Object *ob_arm, source.prepareToAppendValues(); - for (def = (bDeformGroup *)defbase->first; def; def = def->next) { + LISTBASE_FOREACH (bDeformGroup *, def, defbase) { Bone *bone = get_bone_from_defgroup(ob_arm, def); if (bone) { source.appendValues(get_joint_sid(bone)); @@ -461,7 +461,7 @@ std::string ControllerExporter::add_inv_bind_mats_source(Object *ob_arm, std::string source_id = controller_id + BIND_POSES_SOURCE_ID_SUFFIX; int totjoint = 0; - for (bDeformGroup *def = (bDeformGroup *)defbase->first; def; def = def->next) { + LISTBASE_FOREACH (bDeformGroup *, def, defbase) { if (is_bone_defgroup(ob_arm, def)) { totjoint++; } @@ -493,7 +493,7 @@ std::string ControllerExporter::add_inv_bind_mats_source(Object *ob_arm, BKE_pose_where_is(depsgraph, scene, ob_arm); } - for (bDeformGroup *def = (bDeformGroup *)defbase->first; def; def = def->next) { + LISTBASE_FOREACH (bDeformGroup *, def, defbase) { if (is_bone_defgroup(ob_arm, def)) { bPoseChannel *pchan = BKE_pose_channel_find_name(pose, def->name); diff --git a/source/blender/io/collada/SceneExporter.cpp b/source/blender/io/collada/SceneExporter.cpp index fb084aba36a..83b37da9bc7 100644 --- a/source/blender/io/collada/SceneExporter.cpp +++ b/source/blender/io/collada/SceneExporter.cpp @@ -201,7 +201,7 @@ void SceneExporter::writeNode(Object *ob) bConstraintTarget *ct; Object *obtar; - for (ct = (bConstraintTarget *)targets.first; ct; ct = ct->next) { + LISTBASE_FOREACH (bConstraintTarget *, ct, &targets) { obtar = ct->tar; std::string tar_id((obtar) ? id_name(obtar) : ""); colladaNode.addExtraTechniqueChildParameter("blender", con_tag, "target_id", tar_id); diff --git a/source/blender/io/collada/collada_utils.cpp b/source/blender/io/collada/collada_utils.cpp index d6606dc43d0..b61cc220cde 100644 --- a/source/blender/io/collada/collada_utils.cpp +++ b/source/blender/io/collada/collada_utils.cpp @@ -254,7 +254,7 @@ Object *bc_get_assigned_armature(Object *ob) } else { ModifierData *mod; - for (mod = (ModifierData *)ob->modifiers.first; mod; mod = mod->next) { + LISTBASE_FOREACH (ModifierData *, mod, &ob->modifiers) { if (mod->type == eModifierType_Armature) { ob_arm = ((ArmatureModifierData *)mod)->object; } @@ -425,7 +425,7 @@ void bc_triangulate_mesh(Mesh *me) bool bc_is_leaf_bone(Bone *bone) { - for (Bone *child = (Bone *)bone->childbase.first; child; child = child->next) { + LISTBASE_FOREACH (Bone *, child, &bone->childbase) { if (child->flag & BONE_CONNECTED) { return false; } @@ -437,7 +437,7 @@ EditBone *bc_get_edit_bone(bArmature *armature, char *name) { EditBone *eBone; - for (eBone = (EditBone *)armature->edbo->first; eBone; eBone = eBone->next) { + LISTBASE_FOREACH (EditBone *, eBone, armature->edbo) { if (STREQ(name, eBone->name)) { return eBone; } @@ -774,7 +774,7 @@ void bc_enable_fcurves(bAction *act, char *bone_name) SNPRINTF(prefix, "pose.bones[\"%s\"]", bone_name_esc); } - for (fcu = (FCurve *)act->curves.first; fcu; fcu = fcu->next) { + LISTBASE_FOREACH (FCurve *, fcu, &act->curves) { if (bone_name) { if (STREQLEN(fcu->rna_path, prefix, strlen(prefix))) { fcu->flag &= ~FCURVE_DISABLED; @@ -1309,7 +1309,7 @@ bNode *bc_get_master_shader(Material *ma) { bNodeTree *nodetree = ma->nodetree; if (nodetree) { - for (bNode *node = (bNode *)nodetree->nodes.first; node; node = node->next) { + LISTBASE_FOREACH (bNode *, node, &nodetree->nodes) { if (node->typeinfo->type == SH_NODE_BSDF_PRINCIPLED) { return node; } diff --git a/source/blender/makesrna/intern/makesrna.cc b/source/blender/makesrna/intern/makesrna.cc index d2fad80fc0d..f313938374a 100644 --- a/source/blender/makesrna/intern/makesrna.cc +++ b/source/blender/makesrna/intern/makesrna.cc @@ -17,6 +17,7 @@ #include "MEM_guardedalloc.h" +#include "BLI_listbase.h" #include "BLI_string.h" #include "BLI_system.h" /* for 'BLI_system_backtrace' stub. */ #include "BLI_utildefines.h" @@ -2603,14 +2604,13 @@ static void rna_def_struct_function_prototype_cpp(FILE *f, const char *cpp_namespace, int close_prototype) { - PropertyDefRNA *dp; FunctionRNA *func = dfunc->func; int first = 1; const char *retval_type = "void"; if (func->c_ret) { - dp = rna_find_parameter_def(func->c_ret); + PropertyDefRNA *dp = rna_find_parameter_def(func->c_ret); retval_type = rna_parameter_type_cpp_name(dp->prop); } @@ -2629,7 +2629,7 @@ static void rna_def_struct_function_prototype_cpp(FILE *f, WRITE_PARAM("Context C"); } - for (dp = static_cast(dfunc->cont.properties.first); dp; dp = dp->next) { + LISTBASE_FOREACH (PropertyDefRNA *, dp, &dfunc->cont.properties) { int type, flag, flag_parameter, pout; const char *ptrstr; @@ -3387,7 +3387,6 @@ static void rna_def_function_funcs(FILE *f, StructDefRNA *dsrna, FunctionDefRNA static void rna_auto_types() { StructDefRNA *ds; - PropertyDefRNA *dp; for (ds = static_cast(DefRNA.structs.first); ds; ds = static_cast(ds->cont.next)) @@ -3405,7 +3404,7 @@ static void rna_auto_types() } } - for (dp = static_cast(ds->cont.properties.first); dp; dp = dp->next) { + LISTBASE_FOREACH (PropertyDefRNA *, dp, &ds->cont.properties) { if (dp->dnastructname) { if (STREQ(dp->dnastructname, "Screen")) { dp->dnastructname = "bScreen"; @@ -3646,9 +3645,7 @@ static void rna_generate_external_property_prototypes(BlenderRNA *brna, FILE *f) for (StructRNA *srna = static_cast(brna->structs.first); srna; srna = static_cast(srna->cont.next)) { - for (PropertyRNA *prop = static_cast(srna->cont.properties.first); prop; - prop = prop->next) - { + LISTBASE_FOREACH (PropertyRNA *, prop, &srna->cont.properties) { fprintf(f, "extern struct PropertyRNA rna_%s_%s;\n", srna->identifier, prop->identifier); } fprintf(f, "\n"); @@ -3659,13 +3656,12 @@ static void rna_generate_internal_property_prototypes(BlenderRNA * /*brna*/, StructRNA *srna, FILE *f) { - PropertyRNA *prop; StructRNA *base; base = srna->base; while (base) { fprintf(f, "\n"); - for (prop = static_cast(base->cont.properties.first); prop; prop = prop->next) { + LISTBASE_FOREACH (PropertyRNA *, prop, &base->cont.properties) { fprintf(f, "%s%s rna_%s_%s;\n", "RNA_EXTERN_C_OR_EXTERN ", @@ -3680,7 +3676,7 @@ static void rna_generate_internal_property_prototypes(BlenderRNA * /*brna*/, fprintf(f, "\n"); } - for (prop = static_cast(srna->cont.properties.first); prop; prop = prop->next) { + LISTBASE_FOREACH (PropertyRNA *, prop, &srna->cont.properties) { fprintf(f, "RNA_EXTERN_C %s rna_%s_%s;\n", rna_property_structname(prop->type), @@ -3695,9 +3691,7 @@ static void rna_generate_parameter_prototypes(BlenderRNA * /*brna*/, FunctionRNA *func, FILE *f) { - PropertyRNA *parm; - - for (parm = static_cast(func->cont.properties.first); parm; parm = parm->next) { + LISTBASE_FOREACH (PropertyRNA *, parm, &func->cont.properties) { fprintf(f, "%s%s rna_%s_%s_%s;\n", "extern ", @@ -3758,7 +3752,7 @@ static void rna_generate_static_parameter_prototypes(FILE *f, int close_prototype) { FunctionRNA *func; - PropertyDefRNA *dparm; + PropertyDefRNA *dparm_return = nullptr; StructDefRNA *dsrna; PropertyType type; int flag, flag_parameter, pout, cptr, first; @@ -3768,9 +3762,7 @@ static void rna_generate_static_parameter_prototypes(FILE *f, func = dfunc->func; /* return type */ - for (dparm = static_cast(dfunc->cont.properties.first); dparm; - dparm = dparm->next) - { + LISTBASE_FOREACH (PropertyDefRNA *, dparm, &dfunc->cont.properties) { if (dparm->prop == func->c_ret) { if (dparm->prop->arraydimension) { fprintf(f, "XXX no array return types yet"); /* XXX not supported */ @@ -3782,12 +3774,13 @@ static void rna_generate_static_parameter_prototypes(FILE *f, fprintf(f, "%s%s ", rna_type_struct(dparm->prop), rna_parameter_type_name(dparm->prop)); } + dparm_return = dparm; break; } } /* void if nothing to return */ - if (!dparm) { + if (!dparm_return) { fprintf(f, "void "); } @@ -3855,9 +3848,7 @@ static void rna_generate_static_parameter_prototypes(FILE *f, } /* defined parameters */ - for (dparm = static_cast(dfunc->cont.properties.first); dparm; - dparm = dparm->next) - { + LISTBASE_FOREACH (PropertyDefRNA *, dparm, &dfunc->cont.properties) { type = dparm->prop->type; flag = dparm->prop->flag; flag_parameter = dparm->prop->flag_parameter; @@ -3954,7 +3945,6 @@ static void rna_generate_static_function_prototypes(BlenderRNA * /*brna*/, static void rna_generate_struct_prototypes(FILE *f) { StructDefRNA *ds; - PropertyDefRNA *dp; FunctionDefRNA *dfunc; const char *structures[2048]; int all_structures = 0; @@ -3967,7 +3957,7 @@ static void rna_generate_struct_prototypes(FILE *f) dfunc = static_cast(dfunc->cont.next)) { if (dfunc->call) { - for (dp = static_cast(dfunc->cont.properties.first); dp; dp = dp->next) { + LISTBASE_FOREACH (PropertyDefRNA *, dp, &dfunc->cont.properties) { if (dp->prop->type == PROP_POINTER) { int a, found = 0; const char *struct_name = rna_parameter_type_name(dp->prop); @@ -4491,14 +4481,14 @@ static void rna_generate_struct(BlenderRNA * /*brna*/, StructRNA *srna, FILE *f) fprintf(f, "/* %s */\n", srna->name); - for (prop = static_cast(srna->cont.properties.first); prop; prop = prop->next) { + LISTBASE_FOREACH (PropertyRNA *, prop, &srna->cont.properties) { rna_generate_property(f, srna, nullptr, prop); } for (func = static_cast(srna->functions.first); func; func = static_cast(func->cont.next)) { - for (parm = static_cast(func->cont.properties.first); parm; parm = parm->next) { + LISTBASE_FOREACH (PropertyRNA *, parm, &func->cont.properties) { rna_generate_property(f, srna, func->identifier, parm); } @@ -4777,7 +4767,6 @@ static RNAProcessItem PROCESS_ITEMS[] = { static void rna_generate(BlenderRNA *brna, FILE *f, const char *filename, const char *api_filename) { StructDefRNA *ds; - PropertyDefRNA *dp; FunctionDefRNA *dfunc; fprintf(f, @@ -4855,7 +4844,7 @@ static void rna_generate(BlenderRNA *brna, FILE *f, const char *filename, const ds = static_cast(ds->cont.next)) { if (!filename || ds->filename == filename) { - for (dp = static_cast(ds->cont.properties.first); dp; dp = dp->next) { + LISTBASE_FOREACH (PropertyDefRNA *, dp, &ds->cont.properties) { rna_def_property_funcs(f, ds->srna, dp); } } @@ -4865,7 +4854,7 @@ static void rna_generate(BlenderRNA *brna, FILE *f, const char *filename, const ds = static_cast(ds->cont.next)) { if (!filename || ds->filename == filename) { - for (dp = static_cast(ds->cont.properties.first); dp; dp = dp->next) { + LISTBASE_FOREACH (PropertyDefRNA *, dp, &ds->cont.properties) { rna_def_property_wrapper_funcs(f, ds, dp); } @@ -4900,7 +4889,6 @@ static void rna_generate(BlenderRNA *brna, FILE *f, const char *filename, const static void rna_generate_header(BlenderRNA * /*brna*/, FILE *f) { StructDefRNA *ds; - PropertyDefRNA *dp; StructRNA *srna; FunctionDefRNA *dfunc; @@ -4942,7 +4930,7 @@ static void rna_generate_header(BlenderRNA * /*brna*/, FILE *f) } fprintf(f, "\n"); - for (dp = static_cast(ds->cont.properties.first); dp; dp = dp->next) { + LISTBASE_FOREACH (PropertyDefRNA *, dp, &ds->cont.properties) { rna_def_property_funcs_header(f, ds->srna, dp); } @@ -5326,7 +5314,6 @@ static int rna_is_collection_functions_struct(const char **collection_structs, static void rna_generate_header_class_cpp(StructDefRNA *ds, FILE *f) { StructRNA *srna = ds->srna; - PropertyDefRNA *dp; FunctionDefRNA *dfunc; fprintf(f, "/**************** %s ****************/\n\n", srna->name); @@ -5340,14 +5327,14 @@ static void rna_generate_header_class_cpp(StructDefRNA *ds, FILE *f) "\t%s(const PointerRNA &ptr_arg) :\n\t\t%s(ptr_arg)", srna->identifier, (srna->base) ? srna->base->identifier : "Pointer"); - for (dp = static_cast(ds->cont.properties.first); dp; dp = dp->next) { + LISTBASE_FOREACH (PropertyDefRNA *, dp, &ds->cont.properties) { if (rna_is_collection_prop(dp->prop)) { fprintf(f, ",\n\t\t%s(ptr_arg)", dp->prop->identifier); } } fprintf(f, "\n\t\t{}\n\n"); - for (dp = static_cast(ds->cont.properties.first); dp; dp = dp->next) { + LISTBASE_FOREACH (PropertyDefRNA *, dp, &ds->cont.properties) { rna_def_property_funcs_header_cpp(f, ds->srna, dp); } @@ -5364,7 +5351,6 @@ static void rna_generate_header_class_cpp(StructDefRNA *ds, FILE *f) static void rna_generate_header_cpp(BlenderRNA * /*brna*/, FILE *f) { StructDefRNA *ds; - PropertyDefRNA *dp; StructRNA *srna; FunctionDefRNA *dfunc; const char *first_collection_func_struct = nullptr; @@ -5401,7 +5387,7 @@ static void rna_generate_header_cpp(BlenderRNA * /*brna*/, FILE *f) for (ds = static_cast(DefRNA.structs.first); ds; ds = static_cast(ds->cont.next)) { - for (dp = static_cast(ds->cont.properties.first); dp; dp = dp->next) { + LISTBASE_FOREACH (PropertyDefRNA *, dp, &ds->cont.properties) { if (rna_is_collection_prop(dp->prop)) { PropertyRNA *prop = dp->prop; @@ -5473,7 +5459,7 @@ static void rna_generate_header_cpp(BlenderRNA * /*brna*/, FILE *f) { srna = ds->srna; - for (dp = static_cast(ds->cont.properties.first); dp; dp = dp->next) { + LISTBASE_FOREACH (PropertyDefRNA *, dp, &ds->cont.properties) { rna_def_property_funcs_impl_cpp(f, ds->srna, dp); } diff --git a/source/blender/makesrna/intern/rna_access.cc b/source/blender/makesrna/intern/rna_access.cc index ee0d2157c71..70d3c3df895 100644 --- a/source/blender/makesrna/intern/rna_access.cc +++ b/source/blender/makesrna/intern/rna_access.cc @@ -67,7 +67,6 @@ const PointerRNA PointerRNA_NULL = {nullptr}; void RNA_init() { StructRNA *srna; - PropertyRNA *prop; BLENDER_RNA.structs_map = BLI_ghash_str_new_ex(__func__, 2048); BLENDER_RNA.structs_len = 0; @@ -78,8 +77,7 @@ void RNA_init() if (!srna->cont.prophash) { srna->cont.prophash = BLI_ghash_str_new("RNA_init gh"); - for (prop = static_cast(srna->cont.properties.first); prop; prop = prop->next) - { + LISTBASE_FOREACH (PropertyRNA *, prop, &srna->cont.properties) { if (!(prop->flag_internal & PROP_INTERN_BUILTIN)) { BLI_ghash_insert(srna->cont.prophash, (void *)prop->identifier, prop); } @@ -5993,7 +5991,6 @@ ParameterList *RNA_parameter_list_create(ParameterList *parms, PointerRNA * /*ptr*/, FunctionRNA *func) { - PropertyRNA *parm; PointerRNA null_ptr = PointerRNA_NULL; void *data; int alloc_size = 0, size; @@ -6002,7 +5999,7 @@ ParameterList *RNA_parameter_list_create(ParameterList *parms, parms->ret_count = 0; /* allocate data */ - for (parm = static_cast(func->cont.properties.first); parm; parm = parm->next) { + LISTBASE_FOREACH (PropertyRNA *, parm, &func->cont.properties) { alloc_size += rna_parameter_size_pad(rna_parameter_size(parm)); if (parm->flag_parameter & PARM_OUTPUT) { @@ -6020,7 +6017,7 @@ ParameterList *RNA_parameter_list_create(ParameterList *parms, /* set default values */ data = parms->data; - for (parm = static_cast(func->cont.properties.first); parm; parm = parm->next) { + LISTBASE_FOREACH (PropertyRNA *, parm, &func->cont.properties) { size = rna_parameter_size(parm); /* set length to 0, these need to be set later, see bpy_array.c's py_to_array */ @@ -6543,7 +6540,6 @@ static int rna_function_parameter_parse(PointerRNA *ptr, case PROP_COLLECTION: { StructRNA *ptype; ListBase *lb, *clb; - Link *link; CollectionPointerLink *clink; if (ftype != 'C') { @@ -6572,7 +6568,7 @@ static int rna_function_parameter_parse(PointerRNA *ptr, return -1; } - for (link = static_cast(lb->first); link; link = link->next) { + LISTBASE_FOREACH (Link *, link, lb) { clink = MEM_cnew(__func__); RNA_pointer_create(nullptr, srna, link, &clink->ptr); BLI_addtail(clb, clink); diff --git a/source/blender/makesrna/intern/rna_define.cc b/source/blender/makesrna/intern/rna_define.cc index eaec676b467..6e7e9d37b0d 100644 --- a/source/blender/makesrna/intern/rna_define.cc +++ b/source/blender/makesrna/intern/rna_define.cc @@ -145,15 +145,12 @@ static void rna_remlink(ListBase *listbase, void *vlink) PropertyDefRNA *rna_findlink(ListBase *listbase, const char *identifier) { - Link *link; - - for (link = static_cast(listbase->first); link; link = link->next) { + LISTBASE_FOREACH (Link *, link, listbase) { PropertyRNA *prop = ((PropertyDefRNA *)link)->prop; if (prop && STREQ(prop->identifier, identifier)) { return (PropertyDefRNA *)link; } } - return nullptr; } @@ -712,9 +709,8 @@ void RNA_define_free(BlenderRNA * /*brna*/) { StructDefRNA *ds; FunctionDefRNA *dfunc; - AllocDefRNA *alloc; - for (alloc = static_cast(DefRNA.allocs.first); alloc; alloc = alloc->next) { + LISTBASE_FOREACH (AllocDefRNA *, alloc, &DefRNA.allocs) { MEM_freeN(alloc->mem); } rna_freelistN(&DefRNA.allocs); diff --git a/source/blender/modifiers/intern/MOD_particleinstance.cc b/source/blender/modifiers/intern/MOD_particleinstance.cc index 5d4e2aee72a..3d200ad725c 100644 --- a/source/blender/modifiers/intern/MOD_particleinstance.cc +++ b/source/blender/modifiers/intern/MOD_particleinstance.cc @@ -66,7 +66,6 @@ static bool is_disabled(const Scene *scene, ModifierData *md, bool use_render_pa { ParticleInstanceModifierData *pimd = (ParticleInstanceModifierData *)md; ParticleSystem *psys; - ModifierData *ob_md; /* The object type check is only needed here in case we have a placeholder * object assigned (because the library containing the mesh is missing). @@ -85,8 +84,7 @@ static bool is_disabled(const Scene *scene, ModifierData *md, bool use_render_pa /* If the psys modifier is disabled we cannot use its data. * First look up the psys modifier from the object, then check if it is enabled. */ - for (ob_md = static_cast(pimd->ob->modifiers.first); ob_md; ob_md = ob_md->next) - { + LISTBASE_FOREACH (ModifierData *, ob_md, &pimd->ob->modifiers) { if (ob_md->type == eModifierType_ParticleSystem) { ParticleSystemModifierData *psmd = (ParticleSystemModifierData *)ob_md; if (psmd->psys == psys) { diff --git a/source/blender/nodes/composite/node_composite_tree.cc b/source/blender/nodes/composite/node_composite_tree.cc index 6e74c5b8940..bab90d4f8e7 100644 --- a/source/blender/nodes/composite/node_composite_tree.cc +++ b/source/blender/nodes/composite/node_composite_tree.cc @@ -97,7 +97,7 @@ static void local_merge(Main *bmain, bNodeTree *localtree, bNodeTree *ntree) /* move over the compbufs and previews */ blender::bke::node_preview_merge_tree(ntree, localtree, true); - for (bNode *lnode = (bNode *)localtree->nodes.first; lnode; lnode = lnode->next) { + LISTBASE_FOREACH (bNode *, lnode, &localtree->nodes) { if (bNode *orig_node = nodeFindNodebyName(ntree, lnode->name)) { if (ELEM(lnode->type, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER)) { if (lnode->id && (lnode->flag & NODE_DO_OUTPUT)) { diff --git a/source/blender/nodes/composite/nodes/node_composite_scale.cc b/source/blender/nodes/composite/nodes/node_composite_scale.cc index 91ccfb8e72f..1b62d96c29a 100644 --- a/source/blender/nodes/composite/nodes/node_composite_scale.cc +++ b/source/blender/nodes/composite/nodes/node_composite_scale.cc @@ -44,11 +44,10 @@ static void cmp_node_scale_declare(NodeDeclarationBuilder &b) static void node_composite_update_scale(bNodeTree *ntree, bNode *node) { - bNodeSocket *sock; bool use_xy_scale = ELEM(node->custom1, CMP_NODE_SCALE_RELATIVE, CMP_NODE_SCALE_ABSOLUTE); /* Only show X/Y scale factor inputs for modes using them! */ - for (sock = (bNodeSocket *)node->inputs.first; sock; sock = sock->next) { + LISTBASE_FOREACH (bNodeSocket *, sock, &node->inputs) { if (STR_ELEM(sock->name, "X", "Y")) { bke::nodeSetSocketAvailability(ntree, sock, use_xy_scale); } diff --git a/source/blender/nodes/intern/node_common.cc b/source/blender/nodes/intern/node_common.cc index b467ebdd77f..e06fd6bf153 100644 --- a/source/blender/nodes/intern/node_common.cc +++ b/source/blender/nodes/intern/node_common.cc @@ -488,8 +488,7 @@ bool blender::bke::node_is_connected_to_output(const bNodeTree *ntree, const bNo bNodeSocket *node_group_input_find_socket(bNode *node, const char *identifier) { - bNodeSocket *sock; - for (sock = (bNodeSocket *)node->outputs.first; sock; sock = sock->next) { + LISTBASE_FOREACH (bNodeSocket *, sock, &node->outputs) { if (STREQ(sock->identifier, identifier)) { return sock; } @@ -582,8 +581,7 @@ void register_node_type_group_input() bNodeSocket *node_group_output_find_socket(bNode *node, const char *identifier) { - bNodeSocket *sock; - for (sock = (bNodeSocket *)node->inputs.first; sock; sock = sock->next) { + LISTBASE_FOREACH (bNodeSocket *, sock, &node->inputs) { if (STREQ(sock->identifier, identifier)) { return sock; } diff --git a/source/blender/nodes/intern/node_exec.cc b/source/blender/nodes/intern/node_exec.cc index 17585e17f9a..4be55cc4cc2 100644 --- a/source/blender/nodes/intern/node_exec.cc +++ b/source/blender/nodes/intern/node_exec.cc @@ -37,17 +37,15 @@ bNodeStack *node_get_socket_stack(bNodeStack *stack, bNodeSocket *sock) void node_get_stack(bNode *node, bNodeStack *stack, bNodeStack **in, bNodeStack **out) { - bNodeSocket *sock; - /* build pointer stack */ if (in) { - for (sock = (bNodeSocket *)node->inputs.first; sock; sock = sock->next) { + LISTBASE_FOREACH (bNodeSocket *, sock, &node->inputs) { *(in++) = node_get_socket_stack(stack, sock); } } if (out) { - for (sock = (bNodeSocket *)node->outputs.first; sock; sock = sock->next) { + LISTBASE_FOREACH (bNodeSocket *, sock, &node->outputs) { *(out++) = node_get_socket_stack(stack, sock); } } @@ -148,7 +146,6 @@ bNodeTreeExec *ntree_exec_begin(bNodeExecContext *context, bNode *node; bNodeExec *nodeexec; bNodeInstanceKey nodekey; - bNodeSocket *sock; bNodeStack *ns; int index; /* XXX: texture-nodes have threading issues with muting, have to disable it there. */ @@ -173,17 +170,17 @@ bNodeTreeExec *ntree_exec_begin(bNodeExecContext *context, node = nodelist[n]; /* init node socket stack indexes */ - for (sock = (bNodeSocket *)node->inputs.first; sock; sock = sock->next) { + LISTBASE_FOREACH (bNodeSocket *, sock, &node->inputs) { node_init_input_index(sock, &index); } if (node->flag & NODE_MUTED || node->type == NODE_REROUTE) { - for (sock = (bNodeSocket *)node->outputs.first; sock; sock = sock->next) { + LISTBASE_FOREACH (bNodeSocket *, sock, &node->outputs) { node_init_output_index_muted(sock, &index, node->runtime->internal_links); } } else { - for (sock = (bNodeSocket *)node->outputs.first; sock; sock = sock->next) { + LISTBASE_FOREACH (bNodeSocket *, sock, &node->outputs) { node_init_output_index(sock, &index); } } @@ -209,7 +206,7 @@ bNodeTreeExec *ntree_exec_begin(bNodeExecContext *context, nodeexec->free_exec_fn = node->typeinfo->free_exec_fn; /* tag inputs */ - for (sock = (bNodeSocket *)node->inputs.first; sock; sock = sock->next) { + LISTBASE_FOREACH (bNodeSocket *, sock, &node->inputs) { /* disable the node if an input link is invalid */ if (sock->link && !(sock->link->flag & NODE_LINK_VALID)) { node->runtime->need_exec = 0; @@ -222,7 +219,7 @@ bNodeTreeExec *ntree_exec_begin(bNodeExecContext *context, } /* tag all outputs */ - for (sock = (bNodeSocket *)node->outputs.first; sock; sock = sock->next) { + LISTBASE_FOREACH (bNodeSocket *, sock, &node->outputs) { /* ns = */ setup_stack(exec->stack, ntree, node, sock); } diff --git a/source/blender/nodes/texture/node_texture_tree.cc b/source/blender/nodes/texture/node_texture_tree.cc index f9071691fb9..5788a3cb3af 100644 --- a/source/blender/nodes/texture/node_texture_tree.cc +++ b/source/blender/nodes/texture/node_texture_tree.cc @@ -213,7 +213,6 @@ bNodeTreeExec *ntreeTexBeginExecTree_internal(bNodeExecContext *context, bNodeInstanceKey parent_key) { bNodeTreeExec *exec; - bNode *node; /* common base initialization */ exec = ntree_exec_begin(context, ntree, parent_key); @@ -221,7 +220,7 @@ bNodeTreeExec *ntreeTexBeginExecTree_internal(bNodeExecContext *context, /* allocate the thread stack listbase array */ exec->threadstack = MEM_cnew_array(BLENDER_MAX_THREADS, "thread stack array"); - for (node = static_cast(exec->nodetree->nodes.first); node; node = node->next) { + LISTBASE_FOREACH (bNode *, node, &exec->nodetree->nodes) { node->runtime->need_exec = 1; } @@ -255,13 +254,11 @@ bNodeTreeExec *ntreeTexBeginExecTree(bNodeTree *ntree) /* free texture delegates */ static void tex_free_delegates(bNodeTreeExec *exec) { - bNodeThreadStack *nts; bNodeStack *ns; int th, a; for (th = 0; th < BLENDER_MAX_THREADS; th++) { - for (nts = static_cast(exec->threadstack[th].first); nts; nts = nts->next) - { + LISTBASE_FOREACH (bNodeThreadStack *, nts, &exec->threadstack[th]) { for (ns = nts->stack, a = 0; a < exec->stacksize; a++, ns++) { if (ns->data && !ns->is_copy) { MEM_freeN(ns->data); @@ -273,15 +270,13 @@ static void tex_free_delegates(bNodeTreeExec *exec) void ntreeTexEndExecTree_internal(bNodeTreeExec *exec) { - bNodeThreadStack *nts; int a; if (exec->threadstack) { tex_free_delegates(exec); for (a = 0; a < BLENDER_MAX_THREADS; a++) { - for (nts = static_cast(exec->threadstack[a].first); nts; nts = nts->next) - { + LISTBASE_FOREACH (bNodeThreadStack *, nts, &exec->threadstack[a]) { if (nts->stack) { MEM_freeN(nts->stack); } diff --git a/source/blender/nodes/texture/node_texture_util.cc b/source/blender/nodes/texture/node_texture_util.cc index f0af220eee4..88b19c5bf1b 100644 --- a/source/blender/nodes/texture/node_texture_util.cc +++ b/source/blender/nodes/texture/node_texture_util.cc @@ -139,8 +139,7 @@ void tex_output(bNode *node, void ntreeTexCheckCyclics(bNodeTree *ntree) { - bNode *node; - for (node = static_cast(ntree->nodes.first); node; node = node->next) { + LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { if (node->type == TEX_NODE_TEXTURE && node->id) { /* custom2 stops the node from rendering */ diff --git a/source/blender/nodes/texture/nodes/node_texture_common.cc b/source/blender/nodes/texture/nodes/node_texture_common.cc index a161e27a661..a283732e632 100644 --- a/source/blender/nodes/texture/nodes/node_texture_common.cc +++ b/source/blender/nodes/texture/nodes/node_texture_common.cc @@ -61,12 +61,11 @@ static void group_freeexec(void *nodedata) static void group_copy_inputs(bNode *gnode, bNodeStack **in, bNodeStack *gstack) { bNodeTree *ngroup = (bNodeTree *)gnode->id; - bNode *node; bNodeSocket *sock; bNodeStack *ns; int a; - for (node = static_cast(ngroup->nodes.first); node; node = node->next) { + LISTBASE_FOREACH (bNode *, node, &ngroup->nodes) { if (node->type == NODE_GROUP_INPUT) { for (sock = static_cast(node->outputs.first), a = 0; sock; sock = sock->next, a++) { @@ -124,11 +123,8 @@ static void group_execute(void *data, /* XXX same behavior as trunk: all nodes inside group are executed. * it's stupid, but just makes it work. compo redesign will do this better. */ - { - bNode *inode; - for (inode = static_cast(exec->nodetree->nodes.first); inode; inode = inode->next) { - inode->runtime->need_exec = 1; - } + LISTBASE_FOREACH (bNode *, inode, &exec->nodetree->nodes) { + inode->runtime->need_exec = 1; } nts = ntreeGetThreadStack(exec, thread); diff --git a/source/blender/nodes/texture/nodes/node_texture_proc.cc b/source/blender/nodes/texture/nodes/node_texture_proc.cc index ec94bf3221c..046b707048c 100644 --- a/source/blender/nodes/texture/nodes/node_texture_proc.cc +++ b/source/blender/nodes/texture/nodes/node_texture_proc.cc @@ -68,9 +68,8 @@ static void texfn( static int count_outputs(bNode *node) { - bNodeSocket *sock; int num = 0; - for (sock = static_cast(node->outputs.first); sock; sock = sock->next) { + LISTBASE_FOREACH (bNodeSocket *, sock, &node->outputs) { num++; } return num; diff --git a/source/blender/python/intern/bpy_rna.cc b/source/blender/python/intern/bpy_rna.cc index a98cec5762d..9db0531ecfe 100644 --- a/source/blender/python/intern/bpy_rna.cc +++ b/source/blender/python/intern/bpy_rna.cc @@ -4224,9 +4224,8 @@ static PyObject *pyrna_struct_dir(BPy_StructRNA *self) if (self->ptr.type == &RNA_Context) { ListBase lb = CTX_data_dir_get(static_cast(self->ptr.data)); - LinkData *link; - for (link = static_cast(lb.first); link; link = link->next) { + LISTBASE_FOREACH (LinkData *, link, &lb) { PyList_APPEND(ret, PyUnicode_FromString(static_cast(link->data))); } @@ -4417,12 +4416,9 @@ static PyObject *pyrna_struct_getattro(BPy_StructRNA *self, PyObject *pyname) } break; case CTX_DATA_TYPE_COLLECTION: { - CollectionPointerLink *link; - ret = PyList_New(0); - for (link = static_cast(newlb.first); link; link = link->next) - { + LISTBASE_FOREACH (CollectionPointerLink *, link, &newlb) { PyList_APPEND(ret, pyrna_struct_CreatePyObject(&link->ptr)); } break; @@ -7198,10 +7194,9 @@ static void pyrna_subtype_set_rna(PyObject *newclass, StructRNA *srna) { const PointerRNA func_ptr = {nullptr, srna, nullptr}; const ListBase *lb; - Link *link; lb = RNA_struct_type_functions(srna); - for (link = static_cast(lb->first); link; link = link->next) { + LISTBASE_FOREACH (Link *, link, lb) { FunctionRNA *func = (FunctionRNA *)link; const int flag = RNA_function_flag(func); if ((flag & FUNC_NO_SELF) && /* Is `staticmethod` or `classmethod`. */ @@ -8220,13 +8215,12 @@ static int rna_function_arg_count(FunctionRNA *func, int *min_count) { const ListBase *lb = RNA_function_defined_parameters(func); PropertyRNA *parm; - Link *link; const int flag = RNA_function_flag(func); const bool is_staticmethod = (flag & FUNC_NO_SELF) && !(flag & FUNC_USE_SELF_TYPE); int count = is_staticmethod ? 0 : 1; bool done_min_count = false; - for (link = static_cast(lb->first); link; link = link->next) { + LISTBASE_FOREACH (Link *, link, lb) { parm = (PropertyRNA *)link; if (!(RNA_parameter_flag(parm) & PARM_OUTPUT)) { if (!done_min_count && (RNA_parameter_flag(parm) & PARM_PYFUNC_OPTIONAL)) { @@ -8252,7 +8246,6 @@ static int bpy_class_validate_recursive(PointerRNA *dummy_ptr, bool *have_function) { const ListBase *lb; - Link *link; const char *class_type = RNA_struct_identifier(srna); StructRNA *srna_base = RNA_struct_base(srna); PyObject *py_class = (PyObject *)py_data; @@ -8280,7 +8273,7 @@ static int bpy_class_validate_recursive(PointerRNA *dummy_ptr, /* Verify callback functions. */ lb = RNA_struct_type_functions(srna); i = 0; - for (link = static_cast(lb->first); link; link = link->next) { + LISTBASE_FOREACH (Link *, link, lb) { FunctionRNA *func = (FunctionRNA *)link; const int flag = RNA_function_flag(func); if (!(flag & FUNC_REGISTER)) { @@ -8387,7 +8380,7 @@ static int bpy_class_validate_recursive(PointerRNA *dummy_ptr, /* Verify properties. */ lb = RNA_struct_type_properties(srna); - for (link = static_cast(lb->first); link; link = link->next) { + LISTBASE_FOREACH (Link *, link, lb) { const char *identifier; PropertyRNA *prop = (PropertyRNA *)link; const int flag = RNA_property_flag(prop); @@ -9046,12 +9039,11 @@ static int pyrna_srna_contains_pointer_prop_srna(StructRNA *srna_props, const char **r_prop_identifier) { PropertyRNA *prop; - LinkData *link; /* Verify properties. */ const ListBase *lb = RNA_struct_type_properties(srna); - for (link = static_cast(lb->first); link; link = link->next) { + LISTBASE_FOREACH (LinkData *, link, lb) { prop = (PropertyRNA *)link; if (RNA_property_type(prop) == PROP_POINTER && !RNA_property_builtin(prop)) { PointerRNA tptr; diff --git a/source/blender/render/intern/multires_bake.cc b/source/blender/render/intern/multires_bake.cc index 83d779158f1..4e6c612f270 100644 --- a/source/blender/render/intern/multires_bake.cc +++ b/source/blender/render/intern/multires_bake.cc @@ -1465,13 +1465,11 @@ static void count_images(MultiresBakeRender *bkr) static void bake_images(MultiresBakeRender *bkr, MultiresBakeResult *result) { - LinkData *link; - /* construct bake result */ result->height_min = FLT_MAX; result->height_max = -FLT_MAX; - for (link = static_cast(bkr->image.first); link; link = link->next) { + LISTBASE_FOREACH (LinkData *, link, &bkr->image) { Image *ima = (Image *)link->data; LISTBASE_FOREACH (ImageTile *, tile, &ima->tiles) { @@ -1535,10 +1533,9 @@ static void bake_images(MultiresBakeRender *bkr, MultiresBakeResult *result) static void finish_images(MultiresBakeRender *bkr, MultiresBakeResult *result) { - LinkData *link; bool use_displacement_buffer = bkr->mode == RE_BAKE_DISPLACEMENT; - for (link = static_cast(bkr->image.first); link; link = link->next) { + LISTBASE_FOREACH (LinkData *, link, &bkr->image) { Image *ima = (Image *)link->data; LISTBASE_FOREACH (ImageTile *, tile, &ima->tiles) { diff --git a/source/blender/sequencer/intern/clipboard.cc b/source/blender/sequencer/intern/clipboard.cc index fd054670e75..fa87774d4a4 100644 --- a/source/blender/sequencer/intern/clipboard.cc +++ b/source/blender/sequencer/intern/clipboard.cc @@ -155,24 +155,21 @@ static void sequence_clipboard_pointers(Main *bmain, /* recursive versions of functions above */ void seq_clipboard_pointers_free(ListBase *seqbase) { - Sequence *seq; - for (seq = static_cast(seqbase->first); seq; seq = seq->next) { + LISTBASE_FOREACH (Sequence *, seq, seqbase) { sequence_clipboard_pointers(nullptr, seq, seqclipboard_ptr_free); seq_clipboard_pointers_free(&seq->seqbase); } } void SEQ_clipboard_pointers_store(Main *bmain, ListBase *seqbase) { - Sequence *seq; - for (seq = static_cast(seqbase->first); seq; seq = seq->next) { + LISTBASE_FOREACH (Sequence *, seq, seqbase) { sequence_clipboard_pointers(bmain, seq, seqclipboard_ptr_store); SEQ_clipboard_pointers_store(bmain, &seq->seqbase); } } void SEQ_clipboard_pointers_restore(ListBase *seqbase, Main *bmain) { - Sequence *seq; - for (seq = static_cast(seqbase->first); seq; seq = seq->next) { + LISTBASE_FOREACH (Sequence *, seq, seqbase) { sequence_clipboard_pointers(bmain, seq, seqclipboard_ptr_restore); SEQ_clipboard_pointers_restore(&seq->seqbase, bmain); } diff --git a/source/blender/sequencer/intern/modifier.cc b/source/blender/sequencer/intern/modifier.cc index c3f9e79010c..4501bf30460 100644 --- a/source/blender/sequencer/intern/modifier.cc +++ b/source/blender/sequencer/intern/modifier.cc @@ -1489,7 +1489,6 @@ ImBuf *SEQ_modifier_apply_stack(const SeqRenderData *context, ImBuf *ibuf, int timeline_frame) { - SequenceModifierData *smd; ImBuf *processed_ibuf = ibuf; if (seq->modifiers.first && (seq->flag & SEQ_USE_LINEAR_MODIFIERS)) { @@ -1497,7 +1496,7 @@ ImBuf *SEQ_modifier_apply_stack(const SeqRenderData *context, SEQ_render_imbuf_from_sequencer_space(context->scene, processed_ibuf); } - for (smd = static_cast(seq->modifiers.first); smd; smd = smd->next) { + LISTBASE_FOREACH (SequenceModifierData *, smd, &seq->modifiers) { const SequenceModifierTypeInfo *smti = SEQ_modifier_type_info_get(smd->type); /* could happen if modifier is being removed or not exists in current version of blender */ @@ -1543,9 +1542,7 @@ ImBuf *SEQ_modifier_apply_stack(const SeqRenderData *context, void SEQ_modifier_list_copy(Sequence *seqn, Sequence *seq) { - SequenceModifierData *smd; - - for (smd = static_cast(seq->modifiers.first); smd; smd = smd->next) { + LISTBASE_FOREACH (SequenceModifierData *, smd, &seq->modifiers) { SequenceModifierData *smdn; const SequenceModifierTypeInfo *smti = SEQ_modifier_type_info_get(smd->type); diff --git a/source/blender/sequencer/intern/proxy.cc b/source/blender/sequencer/intern/proxy.cc index 5853656a6a8..5f6595e4915 100644 --- a/source/blender/sequencer/intern/proxy.cc +++ b/source/blender/sequencer/intern/proxy.cc @@ -579,9 +579,7 @@ void SEQ_proxy_rebuild(SeqIndexBuildContext *context, bool *stop, bool *do_updat void SEQ_proxy_rebuild_finish(SeqIndexBuildContext *context, bool stop) { if (context->index_context) { - StripAnim *sanim; - - for (sanim = static_cast(context->seq->anims.first); sanim; sanim = sanim->next) { + LISTBASE_FOREACH (StripAnim *, sanim, &context->seq->anims) { IMB_close_anim_proxies(sanim->anim); } diff --git a/source/blender/sequencer/intern/proxy_job.cc b/source/blender/sequencer/intern/proxy_job.cc index 053dd996e13..d7b2ea1d867 100644 --- a/source/blender/sequencer/intern/proxy_job.cc +++ b/source/blender/sequencer/intern/proxy_job.cc @@ -45,9 +45,8 @@ static void proxy_freejob(void *pjv) static void proxy_startjob(void *pjv, bool *stop, bool *do_update, float *progress) { ProxyJob *pj = static_cast(pjv); - LinkData *link; - for (link = static_cast(pj->queue.first); link; link = link->next) { + LISTBASE_FOREACH (LinkData *, link, &pj->queue) { SeqIndexBuildContext *context = static_cast(link->data); SEQ_proxy_rebuild(context, stop, do_update, progress); @@ -64,9 +63,8 @@ static void proxy_endjob(void *pjv) { ProxyJob *pj = static_cast(pjv); Editing *ed = SEQ_editing_get(pj->scene); - LinkData *link; - for (link = static_cast(pj->queue.first); link; link = link->next) { + LISTBASE_FOREACH (LinkData *, link, &pj->queue) { SEQ_proxy_rebuild_finish(static_cast(link->data), pj->stop); } diff --git a/source/blender/sequencer/intern/sequencer.cc b/source/blender/sequencer/intern/sequencer.cc index c90c77435b2..634b44250f2 100644 --- a/source/blender/sequencer/intern/sequencer.cc +++ b/source/blender/sequencer/intern/sequencer.cc @@ -298,8 +298,6 @@ void SEQ_editing_free(Scene *scene, const bool do_id_user) static void seq_new_fix_links_recursive(Sequence *seq) { - SequenceModifierData *smd; - if (seq->type & SEQ_TYPE_EFFECT) { if (seq->seq1 && seq->seq1->tmp) { seq->seq1 = static_cast(seq->seq1->tmp); @@ -312,13 +310,12 @@ static void seq_new_fix_links_recursive(Sequence *seq) } } else if (seq->type == SEQ_TYPE_META) { - Sequence *seqn; - for (seqn = static_cast(seq->seqbase.first); seqn; seqn = seqn->next) { + LISTBASE_FOREACH (Sequence *, seqn, &seq->seqbase) { seq_new_fix_links_recursive(seqn); } } - for (smd = static_cast(seq->modifiers.first); smd; smd = smd->next) { + LISTBASE_FOREACH (SequenceModifierData *, smd, &seq->modifiers) { if (smd->mask_sequence && smd->mask_sequence->tmp) { smd->mask_sequence = static_cast(smd->mask_sequence->tmp); } @@ -608,8 +605,7 @@ static Sequence *sequence_dupli_recursive_do(const Scene *scene_src, seq->tmp = nullptr; seqn = seq_dupli(scene_src, scene_dst, new_seq_list, seq, dupe_flag, 0); if (seq->type == SEQ_TYPE_META) { - Sequence *s; - for (s = static_cast(seq->seqbase.first); s; s = s->next) { + LISTBASE_FOREACH (Sequence *, s, &seq->seqbase) { sequence_dupli_recursive_do(scene_src, scene_dst, &seqn->seqbase, s, dupe_flag); } } @@ -635,13 +631,10 @@ void SEQ_sequence_base_dupli_recursive(const Scene *scene_src, int dupe_flag, const int flag) { - Sequence *seq; - Sequence *seqn = nullptr; - - for (seq = static_cast(seqbase->first); seq; seq = seq->next) { + LISTBASE_FOREACH (Sequence *, seq, seqbase) { seq->tmp = nullptr; if ((seq->flag & SELECT) || (dupe_flag & SEQ_DUPE_ALL)) { - seqn = seq_dupli(scene_src, scene_dst, nseqbase, seq, dupe_flag, flag); + Sequence *seqn = seq_dupli(scene_src, scene_dst, nseqbase, seq, dupe_flag, flag); if (seqn == nullptr) { continue; /* Should never fail. */ @@ -663,7 +656,7 @@ void SEQ_sequence_base_dupli_recursive(const Scene *scene_src, } /* fix modifier linking */ - for (seq = static_cast(nseqbase->first); seq; seq = seq->next) { + LISTBASE_FOREACH (Sequence *, seq, nseqbase) { seq_new_fix_links_recursive(seq); } } diff --git a/source/blender/sequencer/intern/sound.cc b/source/blender/sequencer/intern/sound.cc index db522735db3..133d9fc89c0 100644 --- a/source/blender/sequencer/intern/sound.cc +++ b/source/blender/sequencer/intern/sound.cc @@ -32,10 +32,9 @@ #ifdef WITH_AUDASPACE static bool sequencer_refresh_sound_length_recursive(Main *bmain, Scene *scene, ListBase *seqbase) { - Sequence *seq; bool changed = false; - for (seq = static_cast(seqbase->first); seq; seq = seq->next) { + LISTBASE_FOREACH (Sequence *, seq, seqbase) { if (seq->type == SEQ_TYPE_META) { if (sequencer_refresh_sound_length_recursive(bmain, scene, &seq->seqbase)) { changed = true; @@ -80,9 +79,7 @@ void SEQ_sound_update_bounds_all(Scene *scene) Editing *ed = scene->ed; if (ed) { - Sequence *seq; - - for (seq = static_cast(ed->seqbase.first); seq; seq = seq->next) { + LISTBASE_FOREACH (Sequence *, seq, &ed->seqbase) { if (seq->type == SEQ_TYPE_META) { seq_update_sound_bounds_recursive(scene, seq); } @@ -116,9 +113,7 @@ void SEQ_sound_update_bounds(Scene *scene, Sequence *seq) static void seq_update_sound_recursive(Scene *scene, ListBase *seqbasep, bSound *sound) { - Sequence *seq; - - for (seq = static_cast(seqbasep->first); seq; seq = seq->next) { + LISTBASE_FOREACH (Sequence *, seq, seqbasep) { if (seq->type == SEQ_TYPE_META) { seq_update_sound_recursive(scene, &seq->seqbase, sound); } diff --git a/source/blender/sequencer/intern/strip_edit.cc b/source/blender/sequencer/intern/strip_edit.cc index 36b2039fdf1..a32ff055293 100644 --- a/source/blender/sequencer/intern/strip_edit.cc +++ b/source/blender/sequencer/intern/strip_edit.cc @@ -96,11 +96,9 @@ static void seq_update_muting_recursive(ListBase *channels, Sequence *metaseq, const bool mute) { - Sequence *seq; - /* For sound we go over full meta tree to update muted state, * since sound is played outside of evaluating the imbufs. */ - for (seq = static_cast(seqbasep->first); seq; seq = seq->next) { + LISTBASE_FOREACH (Sequence *, seq, seqbasep) { bool seqmute = (mute || SEQ_render_is_muted(channels, seq)); if (seq->type == SEQ_TYPE_META) { @@ -144,9 +142,7 @@ static void sequencer_flag_users_for_removal(Scene *scene, ListBase *seqbase, Se } /* Clear seq from modifiers. */ - SequenceModifierData *smd; - for (smd = static_cast(user_seq->modifiers.first); smd; - smd = smd->next) { + LISTBASE_FOREACH (SequenceModifierData *, smd, &user_seq->modifiers) { if (smd->mask_sequence == seq) { smd->mask_sequence = nullptr; } diff --git a/source/blender/sequencer/intern/strip_relations.cc b/source/blender/sequencer/intern/strip_relations.cc index 013c3830a63..4e2068118df 100644 --- a/source/blender/sequencer/intern/strip_relations.cc +++ b/source/blender/sequencer/intern/strip_relations.cc @@ -75,9 +75,7 @@ static bool seq_relations_check_depend(const Scene *scene, Sequence *seq, Sequen static void sequence_do_invalidate_dependent(Scene *scene, Sequence *seq, ListBase *seqbase) { - Sequence *cur; - - for (cur = static_cast(seqbase->first); cur; cur = cur->next) { + LISTBASE_FOREACH (Sequence *, cur, seqbase) { if (cur == seq) { continue; } @@ -251,12 +249,10 @@ void SEQ_relations_free_imbuf(Scene *scene, ListBase *seqbase, bool for_render) return; } - Sequence *seq; - SEQ_cache_cleanup(scene); SEQ_prefetch_stop(scene); - for (seq = static_cast(seqbase->first); seq; seq = seq->next) { + LISTBASE_FOREACH (Sequence *, seq, seqbase) { if (for_render && SEQ_time_strip_intersects_frame(scene, seq, scene->r.cfra)) { continue; } @@ -388,9 +384,7 @@ bool SEQ_relations_render_loop_check(Sequence *seq_main, Sequence *seq) return true; } - SequenceModifierData *smd; - for (smd = static_cast(seq_main->modifiers.first); smd; smd = smd->next) - { + LISTBASE_FOREACH (SequenceModifierData *, smd, &seq_main->modifiers) { if (smd->mask_sequence && SEQ_relations_render_loop_check(smd->mask_sequence, seq)) { return true; } @@ -453,9 +447,7 @@ void SEQ_relations_check_uuids_unique_and_report(const Scene *scene) Sequence *SEQ_find_metastrip_by_sequence(ListBase *seqbase, Sequence *meta, Sequence *seq) { - Sequence *iseq; - - for (iseq = static_cast(seqbase->first); iseq; iseq = iseq->next) { + LISTBASE_FOREACH (Sequence *, iseq, seqbase) { Sequence *rval; if (seq == iseq) { diff --git a/source/blender/sequencer/intern/strip_select.cc b/source/blender/sequencer/intern/strip_select.cc index f0fe69ad7f0..84734cb2bf6 100644 --- a/source/blender/sequencer/intern/strip_select.cc +++ b/source/blender/sequencer/intern/strip_select.cc @@ -48,11 +48,9 @@ bool SEQ_select_active_get_pair(Scene *scene, Sequence **r_seq_act, Sequence **r return false; } - Sequence *seq; - *r_seq_other = nullptr; - for (seq = static_cast(ed->seqbasep->first); seq; seq = seq->next) { + LISTBASE_FOREACH (Sequence *, seq, ed->seqbasep) { if (seq->flag & SELECT && (seq != (*r_seq_act))) { if (*r_seq_other) { return false; diff --git a/source/blender/sequencer/intern/strip_time.cc b/source/blender/sequencer/intern/strip_time.cc index 200e1f2bc6e..ab230bf0890 100644 --- a/source/blender/sequencer/intern/strip_time.cc +++ b/source/blender/sequencer/intern/strip_time.cc @@ -126,11 +126,9 @@ static void seq_update_sound_bounds_recursive_impl(const Scene *scene, int start, int end) { - Sequence *seq; - /* For sound we go over full meta tree to update bounds of the sound strips, * since sound is played outside of evaluating the image-buffers (#ImBuf). */ - for (seq = static_cast(metaseq->seqbase.first); seq; seq = seq->next) { + LISTBASE_FOREACH (Sequence *, seq, &metaseq->seqbase) { if (seq->type == SEQ_TYPE_META) { seq_update_sound_bounds_recursive_impl( scene, seq, max_ii(start, metaseq_start(seq)), min_ii(end, metaseq_end(seq))); @@ -265,7 +263,6 @@ int SEQ_time_find_next_prev_edit(Scene *scene, { Editing *ed = SEQ_editing_get(scene); ListBase *channels = SEQ_channels_displayed_get(ed); - Sequence *seq; int dist, best_dist, best_frame = timeline_frame; int seq_frames[2], seq_frames_tot; @@ -279,7 +276,7 @@ int SEQ_time_find_next_prev_edit(Scene *scene, return timeline_frame; } - for (seq = static_cast(ed->seqbasep->first); seq; seq = seq->next) { + LISTBASE_FOREACH (Sequence *, seq, ed->seqbasep) { int i; if (do_skip_mute && SEQ_render_is_muted(channels, seq)) { diff --git a/source/blender/sequencer/intern/strip_transform.cc b/source/blender/sequencer/intern/strip_transform.cc index 193885cd8b5..2ee4e955e04 100644 --- a/source/blender/sequencer/intern/strip_transform.cc +++ b/source/blender/sequencer/intern/strip_transform.cc @@ -43,11 +43,10 @@ bool SEQ_transform_single_image_check(Sequence *seq) bool SEQ_transform_seqbase_isolated_sel_check(ListBase *seqbase) { - Sequence *seq; /* is there more than 1 select */ bool ok = false; - for (seq = static_cast(seqbase->first); seq; seq = seq->next) { + LISTBASE_FOREACH (Sequence *, seq, seqbase) { if (seq->flag & SELECT) { ok = true; break; @@ -59,7 +58,7 @@ bool SEQ_transform_seqbase_isolated_sel_check(ListBase *seqbase) } /* test relationships */ - for (seq = static_cast(seqbase->first); seq; seq = seq->next) { + LISTBASE_FOREACH (Sequence *, seq, seqbase) { if ((seq->type & SEQ_TYPE_EFFECT) == 0) { continue; } @@ -166,10 +165,9 @@ bool SEQ_transform_seqbase_shuffle_ex(ListBase *seqbasep, /* Blender 2.4x would remove the strip. * nicer to move it to the end */ - Sequence *seq; int new_frame = SEQ_time_right_handle_frame_get(evil_scene, test); - for (seq = static_cast(seqbasep->first); seq; seq = seq->next) { + LISTBASE_FOREACH (Sequence *, seq, seqbasep) { if (seq->machine == orig_machine) { new_frame = max_ii(new_frame, SEQ_time_right_handle_frame_get(evil_scene, seq)); } @@ -272,9 +270,8 @@ bool SEQ_transform_seqbase_shuffle_time(SeqCollection *strips_to_shuffle, } if (use_sync_markers && !(evil_scene->toolsettings->lock_markers) && (markers != nullptr)) { - TimeMarker *marker; /* affect selected markers - it's unlikely that we will want to affect all in this way? */ - for (marker = static_cast(markers->first); marker; marker = marker->next) { + LISTBASE_FOREACH (TimeMarker *, marker, markers) { if (marker->flag & SELECT) { marker->frame += offset; } diff --git a/source/blender/sequencer/intern/utils.cc b/source/blender/sequencer/intern/utils.cc index f56f0910c47..fe43b0fba77 100644 --- a/source/blender/sequencer/intern/utils.cc +++ b/source/blender/sequencer/intern/utils.cc @@ -55,8 +55,7 @@ struct SeqUniqueInfo { static void seqbase_unique_name(ListBase *seqbasep, SeqUniqueInfo *sui) { - Sequence *seq; - for (seq = static_cast(seqbasep->first); seq; seq = seq->next) { + LISTBASE_FOREACH (Sequence *, seq, seqbasep) { if ((sui->seq != seq) && STREQ(sui->name_dest, seq->name + 2)) { /* SEQ_NAME_MAXSTR -4 for the number, -1 for \0, - 2 for r_prefix */ SNPRINTF( @@ -343,10 +342,10 @@ const Sequence *SEQ_get_topmost_sequence(const Scene *scene, int frame) } ListBase *channels = SEQ_channels_displayed_get(ed); - const Sequence *seq, *best_seq = nullptr; + const Sequence *best_seq = nullptr; int best_machine = -1; - for (seq = static_cast(ed->seqbasep->first); seq; seq = seq->next) { + LISTBASE_FOREACH (const Sequence *, seq, ed->seqbasep) { if (SEQ_render_is_muted(channels, seq) || !SEQ_time_strip_intersects_frame(scene, seq, frame)) { continue; @@ -422,17 +421,15 @@ Sequence *SEQ_sequence_from_strip_elem(ListBase *seqbase, StripElem *se) Sequence *SEQ_get_sequence_by_name(ListBase *seqbase, const char *name, bool recursive) { - Sequence *iseq = nullptr; - Sequence *rseq = nullptr; - - for (iseq = static_cast(seqbase->first); iseq; iseq = iseq->next) { + LISTBASE_FOREACH (Sequence *, iseq, seqbase) { if (STREQ(name, iseq->name + 2)) { return iseq; } - if (recursive && (iseq->seqbase.first) && - (rseq = SEQ_get_sequence_by_name(&iseq->seqbase, name, true))) - { - return rseq; + if (recursive && !BLI_listbase_is_empty(&iseq->seqbase)) { + Sequence *rseq = SEQ_get_sequence_by_name(&iseq->seqbase, name, true); + if (rseq != nullptr) { + return rseq; + } } } diff --git a/source/blender/windowmanager/gizmo/intern/wm_gizmo_group.cc b/source/blender/windowmanager/gizmo/intern/wm_gizmo_group.cc index 5b9794eb5ad..0146f291a34 100644 --- a/source/blender/windowmanager/gizmo/intern/wm_gizmo_group.cc +++ b/source/blender/windowmanager/gizmo/intern/wm_gizmo_group.cc @@ -222,7 +222,7 @@ void wm_gizmogroup_intersectable_gizmos_to_list(wmWindowManager *wm, BLI_Buffer *visible_gizmos) { int gzgroup_keymap_uses_modifier = -1; - for (wmGizmo *gz = static_cast(gzgroup->gizmos.last); gz; gz = gz->prev) { + LISTBASE_FOREACH_BACKWARD (wmGizmo *, gz, &gzgroup->gizmos) { if ((gz->flag & (WM_GIZMO_HIDDEN | WM_GIZMO_HIDDEN_SELECT)) == 0) { if (((gzgroup->type->flag & WM_GIZMOGROUPTYPE_3D) && (gz->type->draw_select || gz->type->test_select)) || diff --git a/source/blender/windowmanager/gizmo/intern/wm_gizmo_type.cc b/source/blender/windowmanager/gizmo/intern/wm_gizmo_type.cc index 1a428992a35..f4e37a0a3f9 100644 --- a/source/blender/windowmanager/gizmo/intern/wm_gizmo_type.cc +++ b/source/blender/windowmanager/gizmo/intern/wm_gizmo_type.cc @@ -132,9 +132,7 @@ static void gizmotype_unlink(bContext *C, Main *bmain, wmGizmoType *gzt) LISTBASE_FOREACH (ARegion *, region, lb) { wmGizmoMap *gzmap = region->gizmo_map; if (gzmap) { - wmGizmoGroup *gzgroup; - for (gzgroup = static_cast(gzmap->groups.first); gzgroup; - gzgroup = gzgroup->next) { + LISTBASE_FOREACH (wmGizmoGroup *, gzgroup, &gzmap->groups) { for (wmGizmo *gz = static_cast(gzgroup->gizmos.first), *gz_next; gz; gz = gz_next) { gz_next = gz->next; diff --git a/source/creator/creator_args.cc b/source/creator/creator_args.cc index 1f8861408fd..1c83cd1853a 100644 --- a/source/creator/creator_args.cc +++ b/source/creator/creator_args.cc @@ -1611,9 +1611,8 @@ static int arg_handle_engine_set(int argc, const char **argv, void *data) bContext *C = static_cast(data); if (argc >= 2) { if (STREQ(argv[1], "help")) { - RenderEngineType *type = nullptr; printf("Blender Engine Listing:\n"); - for (type = static_cast(R_engines.first); type; type = type->next) { + LISTBASE_FOREACH (RenderEngineType *, type, &R_engines) { printf("\t%s\n", type->idname); } exit(0);