diff options
Diffstat (limited to 'source')
25 files changed, 204 insertions, 355 deletions
diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c index f50b3e3dc79..351f73ea76e 100644 --- a/source/blender/blenkernel/intern/curve.c +++ b/source/blender/blenkernel/intern/curve.c @@ -5185,7 +5185,6 @@ void BKE_curve_transform(Curve *cu, const float mat[4][4], const bool do_keys, c void BKE_curve_translate(Curve *cu, const float offset[3], const bool do_keys) { ListBase *nurb_lb = BKE_curve_nurbs_get(cu); - Nurb *nu; LISTBASE_FOREACH (Nurb *, nu, nurb_lb) { if (nu->type == CU_BEZIER) { diff --git a/source/blender/blenkernel/intern/data_transfer.c b/source/blender/blenkernel/intern/data_transfer.c index 1b35fdd1706..7a3a6ea44a9 100644 --- a/source/blender/blenkernel/intern/data_transfer.c +++ b/source/blender/blenkernel/intern/data_transfer.c @@ -101,13 +101,12 @@ bool BKE_object_data_transfer_get_dttypes_capacity(const int dtdata_types, bool *r_advanced_mixing, bool *r_threshold) { - int i; bool ret = false; *r_advanced_mixing = false; *r_threshold = false; - for (i = 0; (i < DT_TYPE_MAX) && !(ret && *r_advanced_mixing && *r_threshold); i++) { + for (int i = 0; (i < DT_TYPE_MAX) && !(ret && *r_advanced_mixing && *r_threshold); i++) { const int dtdata_type = 1 << i; if (!(dtdata_types & dtdata_type)) { @@ -451,9 +450,7 @@ static void data_transfer_interp_char(const CustomDataTransferLayerMap *laymap, float val_src = 0.0f; const float val_dst = (float)(*data_dst) / 255.0f; - int i; - - for (i = count; i--;) { + for (int i = count; i--;) { val_src += ((float)(*data_src[i]) / 255.0f) * weights[i]; } @@ -1254,7 +1251,6 @@ void BKE_object_data_transfer_layout(struct Depsgraph *depsgraph, { Mesh *me_src; Mesh *me_dst; - int i; const bool use_create = true; /* We always create needed layers here. */ @@ -1272,7 +1268,7 @@ void BKE_object_data_transfer_layout(struct Depsgraph *depsgraph, } /* Check all possible data types. */ - for (i = 0; i < DT_TYPE_MAX; i++) { + for (int i = 0; i < DT_TYPE_MAX; i++) { const int dtdata_type = 1 << i; int cddata_type; int fromlayers, tolayers, fromto_idx; @@ -1410,7 +1406,6 @@ bool BKE_object_data_transfer_ex(struct Depsgraph *depsgraph, Mesh *me_src; /* Assumed always true if not using an evaluated mesh as destination. */ bool dirty_nors_dst = true; - int i; MDeformVert *mdef = NULL; int vg_idx = -1; @@ -1478,7 +1473,7 @@ bool BKE_object_data_transfer_ex(struct Depsgraph *depsgraph, /* Check all possible data types. * Note item mappings and dest mix weights are cached. */ - for (i = 0; i < DT_TYPE_MAX; i++) { + for (int i = 0; i < DT_TYPE_MAX; i++) { const int dtdata_type = 1 << i; int cddata_type; int fromlayers, tolayers, fromto_idx; @@ -1850,7 +1845,7 @@ bool BKE_object_data_transfer_ex(struct Depsgraph *depsgraph, data_transfer_dtdata_type_postprocess(ob_src, ob_dst, me_src, me_dst, dtdata_type, changed); } - for (i = 0; i < DATAMAX; i++) { + for (int i = 0; i < DATAMAX; i++) { BKE_mesh_remap_free(&geom_map[i]); MEM_SAFE_FREE(weights[i]); } diff --git a/source/blender/blenkernel/intern/deform.c b/source/blender/blenkernel/intern/deform.c index 74a8a4268fc..f7cf4faf7cb 100644 --- a/source/blender/blenkernel/intern/deform.c +++ b/source/blender/blenkernel/intern/deform.c @@ -200,9 +200,8 @@ void BKE_defvert_copy_index(MDeformVert *dvert_dst, void BKE_defvert_sync(MDeformVert *dvert_dst, const MDeformVert *dvert_src, const bool use_ensure) { if (dvert_src->totweight && dvert_dst->totweight) { - int i; - MDeformWeight *dw_src; - for (i = 0, dw_src = dvert_src->dw; i < dvert_src->totweight; i++, dw_src++) { + MDeformWeight *dw_src = dvert_src->dw; + for (int i = 0; i < dvert_src->totweight; i++, dw_src++) { MDeformWeight *dw_dst; if (use_ensure) { dw_dst = BKE_defvert_ensure_index(dvert_dst, dw_src->def_nr); @@ -228,9 +227,8 @@ void BKE_defvert_sync_mapped(MDeformVert *dvert_dst, const bool use_ensure) { if (dvert_src->totweight && dvert_dst->totweight) { - int i; - MDeformWeight *dw_src; - for (i = 0, dw_src = dvert_src->dw; i < dvert_src->totweight; i++, dw_src++) { + MDeformWeight *dw_src = dvert_src->dw; + for (int i = 0; i < dvert_src->totweight; i++, dw_src++) { if (dw_src->def_nr < flip_map_len) { MDeformWeight *dw_dst; if (use_ensure) { @@ -254,8 +252,7 @@ void BKE_defvert_sync_mapped(MDeformVert *dvert_dst, void BKE_defvert_remap(MDeformVert *dvert, const int *map, const int map_len) { MDeformWeight *dw = dvert->dw; - unsigned int i; - for (i = dvert->totweight; i != 0; i--, dw++) { + for (int i = dvert->totweight; i != 0; i--, dw++) { if (dw->def_nr < map_len) { BLI_assert(map[dw->def_nr] >= 0); @@ -281,11 +278,9 @@ void BKE_defvert_normalize_subset(MDeformVert *dvert, } } else { - MDeformWeight *dw; - unsigned int i; + MDeformWeight *dw = dvert->dw; float tot_weight = 0.0f; - - for (i = dvert->totweight, dw = dvert->dw; i != 0; i--, dw++) { + for (int i = dvert->totweight; i != 0; i--, dw++) { if ((dw->def_nr < vgroup_tot) && vgroup_subset[dw->def_nr]) { tot_weight += dw->weight; } @@ -293,7 +288,8 @@ void BKE_defvert_normalize_subset(MDeformVert *dvert, if (tot_weight > 0.0f) { float scalar = 1.0f / tot_weight; - for (i = dvert->totweight, dw = dvert->dw; i != 0; i--, dw++) { + dw = dvert->dw; + for (int i = dvert->totweight; i != 0; i--, dw++) { if ((dw->def_nr < vgroup_tot) && vgroup_subset[dw->def_nr]) { dw->weight *= scalar; @@ -822,8 +818,7 @@ int BKE_defvert_find_shared(const MDeformVert *dvert_a, const MDeformVert *dvert bool BKE_defvert_is_weight_zero(const struct MDeformVert *dvert, const int defgroup_tot) { MDeformWeight *dw = dvert->dw; - unsigned int i; - for (i = dvert->totweight; i != 0; i--, dw++) { + for (int i = dvert->totweight; i != 0; i--, dw++) { if (dw->weight != 0.0f) { /* check the group is in-range, happens on rare situations */ if (LIKELY(dw->def_nr < defgroup_tot)) { @@ -841,7 +836,6 @@ float BKE_defvert_total_selected_weight(const struct MDeformVert *dv, int defbase_tot, const bool *defbase_sel) { - int i; float total = 0.0f; const MDeformWeight *dw = dv->dw; @@ -849,7 +843,7 @@ float BKE_defvert_total_selected_weight(const struct MDeformVert *dv, return total; } - for (i = dv->totweight; i != 0; i--, dw++) { + for (int i = dv->totweight; i != 0; i--, dw++) { if (dw->def_nr < defbase_tot) { if (defbase_sel[dw->def_nr]) { total += dw->weight; @@ -947,7 +941,6 @@ float BKE_defvert_lock_relative_weight(float weight, void BKE_defvert_array_copy(MDeformVert *dst, const MDeformVert *src, int totvert) { /* Assumes dst is already set up */ - int i; if (!src || !dst) { return; @@ -955,7 +948,7 @@ void BKE_defvert_array_copy(MDeformVert *dst, const MDeformVert *src, int totver memcpy(dst, src, totvert * sizeof(MDeformVert)); - for (i = 0; i < totvert; i++) { + for (int i = 0; i < totvert; i++) { if (src[i].dw) { dst[i].dw = MEM_mallocN(sizeof(MDeformWeight) * src[i].totweight, "copy_deformWeight"); memcpy(dst[i].dw, src[i].dw, sizeof(MDeformWeight) * src[i].totweight); @@ -968,14 +961,13 @@ void BKE_defvert_array_free_elems(MDeformVert *dvert, int totvert) /* Instead of freeing the verts directly, * call this function to delete any special * vert data */ - int i; if (!dvert) { return; } /* Free any special data from the verts */ - for (i = 0; i < totvert; i++) { + for (int i = 0; i < totvert; i++) { if (dvert[i].dw) { MEM_freeN(dvert[i].dw); } diff --git a/source/blender/blenkernel/intern/dynamicpaint.c b/source/blender/blenkernel/intern/dynamicpaint.c index 50c9ce4fb75..b7309743af1 100644 --- a/source/blender/blenkernel/intern/dynamicpaint.c +++ b/source/blender/blenkernel/intern/dynamicpaint.c @@ -475,13 +475,12 @@ static void blendColors(const float t_color[3], float result[4]) { /* Same thing as BLI's blend_color_mix_float(), but for non-premultiplied alpha. */ - int i; float i_alpha = 1.0f - s_alpha; float f_alpha = t_alpha * i_alpha + s_alpha; /* blend colors */ if (f_alpha) { - for (i = 0; i < 3; i++) { + for (int i = 0; i < 3; i++) { result[i] = (t_color[i] * t_alpha * i_alpha + s_color[i] * s_alpha) / f_alpha; } } @@ -1429,9 +1428,6 @@ static void dynamicPaint_initAdjacencyData(DynamicPaintSurface *surface, const b } if (surface->format == MOD_DPAINT_SURFACE_F_VERTEX) { - int i; - int n_pos; - /* For vertex format, count every vertex that is connected by an edge */ int numOfEdges = mesh->totedge; int numOfPolys = mesh->totpoly; @@ -1440,7 +1436,7 @@ static void dynamicPaint_initAdjacencyData(DynamicPaintSurface *surface, const b struct MLoop *mloop = mesh->mloop; /* count number of edges per vertex */ - for (i = 0; i < numOfEdges; i++) { + for (int i = 0; i < numOfEdges; i++) { ad->n_num[edge[i].v1]++; ad->n_num[edge[i].v2]++; @@ -1450,7 +1446,7 @@ static void dynamicPaint_initAdjacencyData(DynamicPaintSurface *surface, const b /* also add number of vertices to temp_data * to locate points on "mesh edge" */ - for (i = 0; i < numOfPolys; i++) { + for (int i = 0; i < numOfPolys; i++) { for (int j = 0; j < mpoly[i].totloop; j++) { temp_data[mloop[mpoly[i].loopstart + j].v]++; } @@ -1458,7 +1454,7 @@ static void dynamicPaint_initAdjacencyData(DynamicPaintSurface *surface, const b /* now check if total number of edges+faces for * each vertex is even, if not -> vertex is on mesh edge */ - for (i = 0; i < sData->total_points; i++) { + for (int i = 0; i < sData->total_points; i++) { if ((temp_data[i] % 2) || (temp_data[i] < 4)) { ad->flags[i] |= ADJ_ON_MESH_EDGE; } @@ -1468,14 +1464,14 @@ static void dynamicPaint_initAdjacencyData(DynamicPaintSurface *surface, const b } /* order n_index array */ - n_pos = 0; - for (i = 0; i < sData->total_points; i++) { + int n_pos = 0; + for (int i = 0; i < sData->total_points; i++) { ad->n_index[i] = n_pos; n_pos += ad->n_num[i]; } /* and now add neighbor data using that info */ - for (i = 0; i < numOfEdges; i++) { + for (int i = 0; i < numOfEdges; i++) { /* first vertex */ int index = edge[i].v1; n_pos = ad->n_index[index] + temp_data[index]; @@ -1616,7 +1612,6 @@ static void dynamicPaint_setInitialColor(const Scene *scene, DynamicPaintSurface PaintSurfaceData *sData = surface->data; PaintPoint *pPoint = (PaintPoint *)sData->type_data; Mesh *mesh = dynamicPaint_canvas_mesh_get(surface->canvas); - int i; const bool scene_color_manage = BKE_scene_check_color_management_enabled(scene); if (surface->type != MOD_DPAINT_SURFACE_T_PAINT) { @@ -1630,7 +1625,7 @@ static void dynamicPaint_setInitialColor(const Scene *scene, DynamicPaintSurface /* Single color */ if (surface->init_color_type == MOD_DPAINT_INITIAL_COLOR) { /* apply color to every surface point */ - for (i = 0; i < sData->total_points; i++) { + for (int i = 0; i < sData->total_points; i++) { copy_v4_v4(pPoint[i].color, surface->init_color); } } @@ -1703,7 +1698,7 @@ static void dynamicPaint_setInitialColor(const Scene *scene, DynamicPaintSurface return; } - for (i = 0; i < totloop; i++) { + for (int i = 0; i < totloop; i++) { rgba_uchar_to_float(pPoint[mloop[i].v].color, (const unsigned char *)&col[mloop[i].v].r); } } @@ -2029,8 +2024,7 @@ static Mesh *dynamicPaint_Modifier_apply(DynamicPaintModifierData *pmd, Object * result->dvert = dvert; } if (defgrp_index != -1 && dvert) { - int i; - for (i = 0; i < sData->total_points; i++) { + for (int i = 0; i < sData->total_points; i++) { MDeformVert *dv = &dvert[i]; MDeformWeight *def_weight = BKE_defvert_find_index(dv, defgrp_index); @@ -4908,13 +4902,12 @@ static void surface_determineForceTargetPoints(const PaintSurfaceData *sData, { BakeAdjPoint *bNeighs = sData->bData->bNeighs; const int numOfNeighs = sData->adj_data->n_num[index]; - int i; closest_id[0] = closest_id[1] = -1; closest_d[0] = closest_d[1] = -1.0f; /* find closest neigh */ - for (i = 0; i < numOfNeighs; i++) { + for (int i = 0; i < numOfNeighs; i++) { const int n_index = sData->adj_data->n_index[index] + i; const float dir_dot = dot_v3v3(bNeighs[n_index].dir, force); @@ -4929,7 +4922,7 @@ static void surface_determineForceTargetPoints(const PaintSurfaceData *sData, } /* find second closest neigh */ - for (i = 0; i < numOfNeighs; i++) { + for (int i = 0; i < numOfNeighs; i++) { const int n_index = sData->adj_data->n_index[index] + i; if (n_index == closest_id[0]) { @@ -4989,26 +4982,24 @@ static void dynamicPaint_doSmudge(DynamicPaintSurface *surface, PaintSurfaceData *sData = surface->data; PaintBakeData *bData = sData->bData; BakeAdjPoint *bNeighs = sData->bData->bNeighs; - int index, steps, step; - float eff_scale, max_velocity = 0.0f; + float max_velocity = 0.0f; if (!sData->adj_data) { return; } /* find max velocity */ - for (index = 0; index < sData->total_points; index++) { + for (int index = 0; index < sData->total_points; index++) { float vel = bData->brush_velocity[index * 4 + 3]; CLAMP_MIN(max_velocity, vel); } - steps = (int)ceil((double)max_velocity / bData->average_dist * (double)timescale); + int steps = (int)ceil((double)max_velocity / bData->average_dist * (double)timescale); CLAMP(steps, 0, 12); - eff_scale = brush->smudge_strength / (float)steps * timescale; + float eff_scale = brush->smudge_strength / (float)steps * timescale; - for (step = 0; step < steps; step++) { - for (index = 0; index < sData->total_points; index++) { - int i; + for (int step = 0; step < steps; step++) { + for (int index = 0; index < sData->total_points; index++) { if (sData->adj_data->flags[index] & ADJ_BORDER_PIXEL) { continue; @@ -5030,7 +5021,7 @@ static void dynamicPaint_doSmudge(DynamicPaintSurface *surface, sData, index, &bData->brush_velocity[index * 4], closest_d, closest_id); /* Apply movement towards those two points */ - for (i = 0; i < 2; i++) { + for (int i = 0; i < 2; i++) { int n_index = closest_id[i]; if (n_index != -1 && closest_d[i] > 0.0f) { float dir_dot = closest_d[i], dir_factor; @@ -5753,10 +5744,9 @@ static void dynamicPaint_doWaveStep(DynamicPaintSurface *surface, float timescal /* calculate average neigh distance (single thread) */ for (index = 0; index < sData->total_points; index++) { - int i; int numOfNeighs = sData->adj_data->n_num[index]; - for (i = 0; i < numOfNeighs; i++) { + for (int i = 0; i < numOfNeighs; i++) { average_dist += (double)bNeighs[sData->adj_data->n_index[index] + i].dist; } } @@ -5827,8 +5817,7 @@ static void dynamic_paint_surface_pre_step_cb(void *__restrict userdata, /* drying */ if (surface->flags & MOD_DPAINT_USE_DRYING) { if (pPoint->wetness >= MIN_WETNESS) { - int i; - float dry_ratio, f_color[4]; + float f_color[4]; float p_wetness = pPoint->wetness; value_dissolve(&pPoint->wetness, @@ -5838,7 +5827,7 @@ static void dynamic_paint_surface_pre_step_cb(void *__restrict userdata, CLAMP_MIN(pPoint->wetness, 0.0f); if (pPoint->wetness < surface->color_dry_threshold) { - dry_ratio = pPoint->wetness / p_wetness; + float dry_ratio = pPoint->wetness / p_wetness; /* * Slowly "shift" paint from wet layer to dry layer as it drys: @@ -5858,7 +5847,7 @@ static void dynamic_paint_surface_pre_step_cb(void *__restrict userdata, /* For each rgb component, calculate a new dry layer color that keeps the final blend * color with these new alpha values. (wet layer color doesn't change). */ if (pPoint->color[3]) { - for (i = 0; i < 3; i++) { + for (int i = 0; i < 3; i++) { pPoint->color[i] = (f_color[i] * f_color[3] - pPoint->e_color[i] * pPoint->e_color[3]) / (pPoint->color[3] * (1.0f - pPoint->e_color[3])); @@ -5914,7 +5903,6 @@ static bool dynamicPaint_surfaceHasMoved(DynamicPaintSurface *surface, Object *o MVert *mvert = mesh->mvert; int numOfVerts = mesh->totvert; - int i; if (!bData->prev_verts) { return true; @@ -5926,7 +5914,7 @@ static bool dynamicPaint_surfaceHasMoved(DynamicPaintSurface *surface, Object *o } /* vertices */ - for (i = 0; i < numOfVerts; i++) { + for (int i = 0; i < numOfVerts; i++) { if (!equals_v3v3(bData->prev_verts[i].co, mvert[i].co)) { return true; } diff --git a/source/blender/blenkernel/intern/editmesh_bvh.c b/source/blender/blenkernel/intern/editmesh_bvh.c index dc194f0077c..a1e53a1f848 100644 --- a/source/blender/blenkernel/intern/editmesh_bvh.c +++ b/source/blender/blenkernel/intern/editmesh_bvh.c @@ -66,7 +66,6 @@ BMBVHTree *BKE_bmbvh_new_ex(BMesh *bm, BMBVHTree *bmtree = MEM_callocN(sizeof(*bmtree), "BMBVHTree"); float cos[3][3]; - int i; int tottri; /* avoid testing every tri */ @@ -95,7 +94,7 @@ BMBVHTree *BKE_bmbvh_new_ex(BMesh *bm, test_fn_ret = false; tottri = 0; - for (i = 0; i < looptris_tot; i++) { + for (int i = 0; i < looptris_tot; i++) { f_test = looptris[i][0]->f; if (f_test != f_test_prev) { test_fn_ret = test_fn(f_test, user_data); @@ -116,7 +115,7 @@ BMBVHTree *BKE_bmbvh_new_ex(BMesh *bm, f_test_prev = NULL; test_fn_ret = false; - for (i = 0; i < looptris_tot; i++) { + for (int i = 0; i < looptris_tot; i++) { if (test_fn) { /* note, the arrays wont align now! take care */ f_test = looptris[i][0]->f; @@ -422,13 +421,11 @@ static void bmbvh_find_vert_closest_cb(void *userdata, struct VertSearchUserData *bmcb_data = userdata; const BMLoop **ltri = bmcb_data->looptris[index]; const float dist_max_sq = bmcb_data->dist_max_sq; - int i; const float *tri_cos[3]; - bmbvh_tri_from_face(tri_cos, ltri, bmcb_data->cos_cage); - for (i = 0; i < 3; i++) { + for (int i = 0; i < 3; i++) { const float dist_sq = len_squared_v3v3(co, tri_cos[i]); if (dist_sq < hit->dist_sq && dist_sq < dist_max_sq) { copy_v3_v3(hit->co, tri_cos[i]); diff --git a/source/blender/blenkernel/intern/effect.c b/source/blender/blenkernel/intern/effect.c index 1c5c74379f8..40548189583 100644 --- a/source/blender/blenkernel/intern/effect.c +++ b/source/blender/blenkernel/intern/effect.c @@ -74,9 +74,7 @@ EffectorWeights *BKE_effector_add_weights(Collection *collection) { EffectorWeights *weights = MEM_callocN(sizeof(EffectorWeights), "EffectorWeights"); - int i; - - for (i = 0; i < NUM_PFIELD_TYPES; i++) { + for (int i = 0; i < NUM_PFIELD_TYPES; i++) { weights->weight[i] = 1.0f; } diff --git a/source/blender/blenkernel/intern/fcurve.c b/source/blender/blenkernel/intern/fcurve.c index 5d227ec2f9b..d5b54eb1cd1 100644 --- a/source/blender/blenkernel/intern/fcurve.c +++ b/source/blender/blenkernel/intern/fcurve.c @@ -617,11 +617,10 @@ static short get_fcurve_end_keyframes(FCurve *fcu, /* only include selected items? */ if (do_sel_only) { BezTriple *bezt; - unsigned int i; /* find first selected */ bezt = fcu->bezt; - for (i = 0; i < fcu->totvert; bezt++, i++) { + for (int i = 0; i < fcu->totvert; bezt++, i++) { if (BEZT_ISSEL_ANY(bezt)) { *first = bezt; found = true; @@ -631,7 +630,7 @@ static short get_fcurve_end_keyframes(FCurve *fcu, /* find last selected */ bezt = ARRAY_LAST_ITEM(fcu->bezt, BezTriple, fcu->totvert); - for (i = 0; i < fcu->totvert; bezt--, i++) { + for (int i = 0; i < fcu->totvert; bezt--, i++) { if (BEZT_ISSEL_ANY(bezt)) { *last = bezt; found = true; @@ -661,7 +660,6 @@ bool BKE_fcurve_calc_bounds(FCurve *fcu, float xminv = 999999999.0f, xmaxv = -999999999.0f; float yminv = 999999999.0f, ymaxv = -999999999.0f; bool foundvert = false; - unsigned int i; if (fcu->totvert) { if (fcu->bezt) { @@ -689,6 +687,7 @@ bool BKE_fcurve_calc_bounds(FCurve *fcu, if (ymin || ymax) { BezTriple *bezt, *prevbezt = NULL; + int i; for (bezt = fcu->bezt, i = 0; i < fcu->totvert; prevbezt = bezt, bezt++, i++) { if ((do_sel_only == false) || BEZT_ISSEL_ANY(bezt)) { /* keyframe itself */ @@ -726,6 +725,7 @@ bool BKE_fcurve_calc_bounds(FCurve *fcu, /* only loop over keyframes to find extents for values if needed */ if (ymin || ymax) { FPoint *fpt; + int i; for (fpt = fcu->fpt, i = 0; i < fcu->totvert; fpt++, i++) { if (fpt->vec[1] < yminv) { diff --git a/source/blender/blenkernel/intern/fluid.c b/source/blender/blenkernel/intern/fluid.c index 04f3b4f64d6..82ccd33a53b 100644 --- a/source/blender/blenkernel/intern/fluid.c +++ b/source/blender/blenkernel/intern/fluid.c @@ -593,8 +593,7 @@ static void clamp_bounds_in_domain(FluidDomainSettings *fds, int margin, float dt) { - int i; - for (i = 0; i < 3; i++) { + for (int i = 0; i < 3; i++) { int adapt = (fds->flags & FLUID_DOMAIN_USE_ADAPTIVE_DOMAIN) ? fds->adapt_res : 0; /* Add some margin. */ min[i] -= margin; @@ -3431,7 +3430,6 @@ static Mesh *create_smoke_geometry(FluidDomainSettings *fds, Mesh *orgmesh, Obje int num_verts = 8; int num_faces = 6; - int i; float ob_loc[3] = {0}; float ob_cache_loc[3] = {0}; @@ -3551,7 +3549,7 @@ static Mesh *create_smoke_geometry(FluidDomainSettings *fds, Mesh *orgmesh, Obje /* Convert shift to local space and apply to vertices. */ mul_mat3_m4_v3(ob->imat, fds->obj_shift_f); /* Apply shift to vertices. */ - for (i = 0; i < num_verts; i++) { + for (int i = 0; i < num_verts; i++) { add_v3_v3(mverts[i].co, fds->obj_shift_f); } } diff --git a/source/blender/blenkernel/intern/fmodifier.c b/source/blender/blenkernel/intern/fmodifier.c index c973b681fe7..56cd58b0493 100644 --- a/source/blender/blenkernel/intern/fmodifier.c +++ b/source/blender/blenkernel/intern/fmodifier.c @@ -178,12 +178,11 @@ static void fcm_generator_evaluate( /* we overwrite cvalue with the sum of the polynomial */ float *powers = MEM_callocN(sizeof(float) * data->arraysize, "Poly Powers"); float value = 0.0f; - unsigned int i; /* for each x^n, precalculate value based on previous one first... this should be * faster that calling pow() for each entry */ - for (i = 0; i < data->arraysize; i++) { + for (uint i = 0; i < data->arraysize; i++) { /* first entry is x^0 = 1, otherwise, calculate based on previous */ if (i) { powers[i] = powers[i - 1] * evaltime; @@ -194,7 +193,7 @@ static void fcm_generator_evaluate( } /* for each coefficient, add to value, which we'll write to *cvalue in one go */ - for (i = 0; i < data->arraysize; i++) { + for (uint i = 0; i < data->arraysize; i++) { value += data->coefficients[i] * powers[i]; } diff --git a/source/blender/blenkernel/intern/font.c b/source/blender/blenkernel/intern/font.c index 890cfd91710..604637e2350 100644 --- a/source/blender/blenkernel/intern/font.c +++ b/source/blender/blenkernel/intern/font.c @@ -434,20 +434,14 @@ static void build_underline(Curve *cu, BLI_addtail(nubase, nu2); if (rot != 0.0f) { - float si, co; - int i; - - si = sinf(rot); - co = cosf(rot); - - for (i = nu2->pntsu; i > 0; i--) { - float *fp; - float x, y; + float si = sinf(rot); + float co = cosf(rot); - fp = bp->vec; + for (int i = nu2->pntsu; i > 0; i--) { + float *fp = bp->vec; - x = fp[0] - rect->xmin; - y = fp[1] - rect->ymin; + float x = fp[0] - rect->xmin; + float y = fp[1] - rect->ymin; fp[0] = (+co * x + si * y) + rect->xmin; fp[1] = (-si * x + co * y) + rect->ymin; @@ -474,35 +468,29 @@ static void buildchar(Curve *cu, int charidx, const float fsize) { - BezTriple *bezt1, *bezt2; - Nurb *nu1 = NULL, *nu2 = NULL; - float *fp, shear, x, si, co; - VFontData *vfd = NULL; - VChar *che = NULL; - int i; - - vfd = vfont_get_data(which_vfont(cu, info)); + VFontData *vfd = vfont_get_data(which_vfont(cu, info)); if (!vfd) { return; } /* make a copy at distance ofsx, ofsy with shear */ - shear = cu->shear; - si = sinf(rot); - co = cosf(rot); + float shear = cu->shear; + float si = sinf(rot); + float co = cosf(rot); - che = find_vfont_char(vfd, character); + VChar *che = find_vfont_char(vfd, character); /* Select the glyph data */ + Nurb *nu1 = NULL; if (che) { nu1 = che->nurbsbase.first; } /* Create the character */ while (nu1) { - bezt1 = nu1->bezt; + BezTriple *bezt1 = nu1->bezt; if (bezt1) { - nu2 = (Nurb *)MEM_mallocN(sizeof(Nurb), "duplichar_nurb"); + Nurb *nu2 = (Nurb *)MEM_mallocN(sizeof(Nurb), "duplichar_nurb"); if (nu2 == NULL) { break; } @@ -520,20 +508,20 @@ static void buildchar(Curve *cu, } /* nu2->trim.first = 0; */ /* nu2->trim.last = 0; */ - i = nu2->pntsu; + int u = nu2->pntsu; - bezt2 = (BezTriple *)MEM_malloc_arrayN(i, sizeof(BezTriple), "duplichar_bezt2"); + BezTriple *bezt2 = (BezTriple *)MEM_malloc_arrayN(u, sizeof(BezTriple), "duplichar_bezt2"); if (bezt2 == NULL) { MEM_freeN(nu2); break; } - memcpy(bezt2, bezt1, i * sizeof(struct BezTriple)); + memcpy(bezt2, bezt1, u * sizeof(struct BezTriple)); nu2->bezt = bezt2; if (shear != 0.0f) { bezt2 = nu2->bezt; - for (i = nu2->pntsu; i > 0; i--) { + for (int i = nu2->pntsu; i > 0; i--) { bezt2->vec[0][0] += shear * bezt2->vec[0][1]; bezt2->vec[1][0] += shear * bezt2->vec[1][1]; bezt2->vec[2][0] += shear * bezt2->vec[2][1]; @@ -542,10 +530,10 @@ static void buildchar(Curve *cu, } if (rot != 0.0f) { bezt2 = nu2->bezt; - for (i = nu2->pntsu; i > 0; i--) { - fp = bezt2->vec[0]; + for (int i = nu2->pntsu; i > 0; i--) { + float *fp = bezt2->vec[0]; - x = fp[0]; + float x = fp[0]; fp[0] = co * x + si * fp[1]; fp[1] = -si * x + co * fp[1]; x = fp[3]; @@ -562,8 +550,8 @@ static void buildchar(Curve *cu, if (info->flag & CU_CHINFO_SMALLCAPS_CHECK) { const float sca = cu->smallcaps_scale; - for (i = nu2->pntsu; i > 0; i--) { - fp = bezt2->vec[0]; + for (int i = nu2->pntsu; i > 0; i--) { + float *fp = bezt2->vec[0]; fp[0] *= sca; fp[1] *= sca; fp[3] *= sca; @@ -575,8 +563,8 @@ static void buildchar(Curve *cu, } bezt2 = nu2->bezt; - for (i = nu2->pntsu; i > 0; i--) { - fp = bezt2->vec[0]; + for (int i = nu2->pntsu; i > 0; i--) { + float *fp = bezt2->vec[0]; fp[0] = (fp[0] + ofsx) * fsize; fp[1] = (fp[1] + ofsy) * fsize; fp[3] = (fp[3] + ofsx) * fsize; diff --git a/source/blender/blenkernel/intern/gpencil_geom.c b/source/blender/blenkernel/intern/gpencil_geom.c index 4226e65d8fa..937741c2ac0 100644 --- a/source/blender/blenkernel/intern/gpencil_geom.c +++ b/source/blender/blenkernel/intern/gpencil_geom.c @@ -392,9 +392,8 @@ static void stroke_interpolate_deform_weights( { const MDeformVert *vl = &gps->dvert[index_from]; const MDeformVert *vr = &gps->dvert[index_to]; - int i; - for (i = 0; i < vert->totweight; i++) { + for (int i = 0; i < vert->totweight; i++) { float wl = BKE_defvert_find_weight(vl, vert->dw[i].def_nr); float wr = BKE_defvert_find_weight(vr, vert->dw[i].def_nr); vert->dw[i].weight = interpf(wr, wl, ratio); @@ -411,7 +410,6 @@ bool BKE_gpencil_stroke_sample(bGPDstroke *gps, const float dist, const bool sel bGPDspoint *pt = gps->points; bGPDspoint *pt1 = NULL; bGPDspoint *pt2 = NULL; - int i; LinkData *ld; ListBase def_nr_list = {0}; @@ -432,7 +430,7 @@ bool BKE_gpencil_stroke_sample(bGPDstroke *gps, const float dist, const bool sel } int next_point_index = 1; - i = 0; + int i = 0; float pressure, strength, ratio_result; float vert_color[4]; int index_from, index_to; @@ -518,7 +516,6 @@ bool BKE_gpencil_stroke_sample(bGPDstroke *gps, const float dist, const bool sel bool BKE_gpencil_stroke_stretch(bGPDstroke *gps, const float dist, const float tip_length) { bGPDspoint *pt = gps->points, *last_pt, *second_last, *next_pt; - int i; float threshold = (tip_length == 0 ? 0.001f : tip_length); if (gps->totpoints < 2 || dist < FLT_EPSILON) { @@ -532,7 +529,7 @@ bool BKE_gpencil_stroke_stretch(bGPDstroke *gps, const float dist, const float t float len1 = 0.0f; float len2 = 0.0f; - i = 1; + int i = 1; while (len1 < threshold && gps->totpoints > i) { next_pt = &pt[i]; len1 = len_v3v3(&next_pt->x, &pt->x); @@ -1298,11 +1295,9 @@ float BKE_gpencil_stroke_length(const bGPDstroke *gps, bool use_3d) return 0.0f; } float *last_pt = &gps->points[0].x; - int i; - bGPDspoint *pt; float total_length = 0.0f; - for (i = 1; i < gps->totpoints; i++) { - pt = &gps->points[i]; + for (int i = 1; i < gps->totpoints; i++) { + bGPDspoint *pt = &gps->points[i]; if (use_3d) { total_length += len_v3v3(&pt->x, last_pt); } @@ -2313,7 +2308,6 @@ void BKE_gpencil_convert_mesh(Main *bmain, MPoly *mp, *mpoly = me_eval->mpoly; MLoop *mloop = me_eval->mloop; int mpoly_len = me_eval->totpoly; - int i; int stroke_mat_index = gpencil_material_find_index_by_name_prefix(ob_gp, "Stroke"); int fill_mat_index = gpencil_material_find_index_by_name_prefix(ob_gp, "Fill"); @@ -2340,7 +2334,7 @@ void BKE_gpencil_convert_mesh(Main *bmain, if (create_mat) { /* Find a material slot with material assigned. */ bool material_found = false; - for (i = 0; i < ob_mesh->totcol; i++) { + for (int i = 0; i < ob_mesh->totcol; i++) { Material *ma = BKE_object_material_get(ob_mesh, i + 1); if (ma != NULL) { material_found = true; @@ -2357,7 +2351,7 @@ void BKE_gpencil_convert_mesh(Main *bmain, } else { /* Create all materials for fill. */ - for (i = 0; i < ob_mesh->totcol; i++) { + for (int i = 0; i < ob_mesh->totcol; i++) { Material *ma = BKE_object_material_get(ob_mesh, i + 1); if (ma == NULL) { continue; @@ -2378,6 +2372,7 @@ void BKE_gpencil_convert_mesh(Main *bmain, } bGPDframe *gpf_fill = BKE_gpencil_layer_frame_get( gpl_fill, CFRA + frame_offset, GP_GETFRAME_ADD_NEW); + int i; for (i = 0, mp = mpoly; i < mpoly_len; i++, mp++) { MLoop *ml = &mloop[mp->loopstart]; /* Create fill stroke. */ @@ -2389,8 +2384,7 @@ void BKE_gpencil_convert_mesh(Main *bmain, gps_fill->flag |= GP_STROKE_CYCLIC; /* Add points to strokes. */ - int j; - for (j = 0; j < mp->totloop; j++, ml++) { + for (int j = 0; j < mp->totloop; j++, ml++) { MVert *mv = &me_eval->mvert[ml->v]; bGPDspoint *pt = &gps_fill->points[j]; diff --git a/source/blender/blenkernel/intern/icons.c b/source/blender/blenkernel/intern/icons.c index bec0da750e1..6f181cc74d5 100644 --- a/source/blender/blenkernel/intern/icons.c +++ b/source/blender/blenkernel/intern/icons.c @@ -214,17 +214,14 @@ void BKE_icons_deferred_free(void) static PreviewImage *previewimg_create_ex(size_t deferred_data_size) { - PreviewImage *prv_img = NULL; - int i; - - prv_img = MEM_mallocN(sizeof(PreviewImage) + deferred_data_size, "img_prv"); + PreviewImage *prv_img = MEM_mallocN(sizeof(PreviewImage) + deferred_data_size, "img_prv"); memset(prv_img, 0, sizeof(*prv_img)); /* leave deferred data dirty */ if (deferred_data_size) { prv_img->tag |= PRV_TAG_DEFFERED; } - for (i = 0; i < NUM_ICON_SIZES; i++) { + for (int i = 0; i < NUM_ICON_SIZES; i++) { prv_img->flag[i] |= PRV_CHANGED; prv_img->changed_timestamp[i] = 0; } @@ -240,9 +237,7 @@ void BKE_previewimg_freefunc(void *link) { PreviewImage *prv = (PreviewImage *)link; if (prv) { - int i; - - for (i = 0; i < NUM_ICON_SIZES; i++) { + for (int i = 0; i < NUM_ICON_SIZES; i++) { if (prv->rect[i]) { MEM_freeN(prv->rect[i]); } @@ -277,8 +272,7 @@ void BKE_previewimg_clear_single(struct PreviewImage *prv, enum eIconSizes size) void BKE_previewimg_clear(struct PreviewImage *prv) { - int i; - for (i = 0; i < NUM_ICON_SIZES; i++) { + for (int i = 0; i < NUM_ICON_SIZES; i++) { BKE_previewimg_clear_single(prv, i); } } @@ -286,11 +280,10 @@ void BKE_previewimg_clear(struct PreviewImage *prv) PreviewImage *BKE_previewimg_copy(const PreviewImage *prv) { PreviewImage *prv_img = NULL; - int i; if (prv) { prv_img = MEM_dupallocN(prv); - for (i = 0; i < NUM_ICON_SIZES; i++) { + for (int i = 0; i < NUM_ICON_SIZES; i++) { if (prv->rect[i]) { prv_img->rect[i] = MEM_dupallocN(prv->rect[i]); } @@ -546,8 +539,7 @@ void BKE_icon_changed(const int icon_id) /* If we have previews, they all are now invalid changed. */ if (p_prv && *p_prv) { - int i; - for (i = 0; i < NUM_ICON_SIZES; i++) { + for (int i = 0; i < NUM_ICON_SIZES; i++) { (*p_prv)->flag[i] |= PRV_CHANGED; (*p_prv)->changed_timestamp[i]++; } diff --git a/source/blender/blenkernel/intern/idprop.c b/source/blender/blenkernel/intern/idprop.c index 7195ebda5ff..189eef5e175 100644 --- a/source/blender/blenkernel/intern/idprop.c +++ b/source/blender/blenkernel/intern/idprop.c @@ -95,7 +95,6 @@ IDProperty *IDP_CopyIDPArray(const IDProperty *array, const int flag) { /* don't use MEM_dupallocN because this may be part of an array */ IDProperty *narray, *tmp; - int i; BLI_assert(array->type == IDP_IDPARRAY); @@ -103,7 +102,7 @@ IDProperty *IDP_CopyIDPArray(const IDProperty *array, const int flag) *narray = *array; narray->data.pointer = MEM_dupallocN(array->data.pointer); - for (i = 0; i < narray->len; i++) { + for (int i = 0; i < narray->len; i++) { /* ok, the copy functions always allocate a new structure, * which doesn't work here. instead, simply copy the * contents of the new structure into the array cell, @@ -120,11 +119,9 @@ IDProperty *IDP_CopyIDPArray(const IDProperty *array, const int flag) static void IDP_FreeIDPArray(IDProperty *prop, const bool do_id_user) { - int i; - BLI_assert(prop->type == IDP_IDPARRAY); - for (i = 0; i < prop->len; i++) { + for (int i = 0; i < prop->len; i++) { IDP_FreePropertyContent_ex(GETPROP(prop, i), do_id_user); } @@ -176,9 +173,7 @@ void IDP_ResizeIDPArray(IDProperty *prop, int newlen) /* first check if the array buffer size has room */ if (newlen <= prop->totallen) { if (newlen < prop->len && prop->totallen - newlen < IDP_ARRAY_REALLOC_LIMIT) { - int i; - - for (i = newlen; i < prop->len; i++) { + for (int i = newlen; i < prop->len; i++) { IDP_FreePropertyContent(GETPROP(prop, i)); } @@ -194,8 +189,7 @@ void IDP_ResizeIDPArray(IDProperty *prop, int newlen) /* free trailing items */ if (newlen < prop->len) { /* newlen is smaller */ - int i; - for (i = newlen; i < prop->len; i++) { + for (int i = newlen; i < prop->len; i++) { IDP_FreePropertyContent(GETPROP(prop, i)); } } @@ -921,13 +915,12 @@ bool IDP_EqualsProperties_ex(IDProperty *prop1, IDProperty *prop2, const bool is case IDP_IDPARRAY: { IDProperty *array1 = IDP_IDPArray(prop1); IDProperty *array2 = IDP_IDPArray(prop2); - int i; if (prop1->len != prop2->len) { return false; } - for (i = 0; i < prop1->len; i++) { + for (int i = 0; i < prop1->len; i++) { if (!IDP_EqualsProperties_ex(&array1[i], &array2[i], is_strict)) { return false; } @@ -1253,7 +1246,6 @@ static void IDP_DirectLinkProperty(IDProperty *prop, BlendDataReader *reader); static void IDP_DirectLinkIDPArray(IDProperty *prop, BlendDataReader *reader) { IDProperty *array; - int i; /* since we didn't save the extra buffer, set totallen to len */ prop->totallen = prop->len; @@ -1268,7 +1260,7 @@ static void IDP_DirectLinkIDPArray(IDProperty *prop, BlendDataReader *reader) prop->totallen = 0; } - for (i = 0; i < prop->len; i++) { + for (int i = 0; i < prop->len; i++) { IDP_DirectLinkProperty(&array[i], reader); } } @@ -1276,7 +1268,6 @@ static void IDP_DirectLinkIDPArray(IDProperty *prop, BlendDataReader *reader) static void IDP_DirectLinkArray(IDProperty *prop, BlendDataReader *reader) { IDProperty **array; - int i; /* since we didn't save the extra buffer, set totallen to len */ prop->totallen = prop->len; @@ -1285,7 +1276,7 @@ static void IDP_DirectLinkArray(IDProperty *prop, BlendDataReader *reader) BLO_read_pointer_array(reader, &prop->data.pointer); array = prop->data.pointer; - for (i = 0; i < prop->len; i++) { + for (int i = 0; i < prop->len; i++) { IDP_DirectLinkProperty(array[i], reader); } } diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c index be3795a02b1..88dc29305ea 100644 --- a/source/blender/blenkernel/intern/image.c +++ b/source/blender/blenkernel/intern/image.c @@ -4073,12 +4073,11 @@ static ImBuf *image_load_sequence_file(Image *ima, ImageUser *iuser, int entry, } else { const int totviews = BLI_listbase_count(&ima->views); - int i; struct ImBuf **ibuf_arr; ibuf_arr = MEM_mallocN(sizeof(ImBuf *) * totviews, "Image Views Imbufs"); - for (i = 0; i < totfiles; i++) { + for (int i = 0; i < totfiles; i++) { ibuf_arr[i] = load_sequence_single(ima, iuser, frame, i, &assign); } @@ -4090,13 +4089,13 @@ static ImBuf *image_load_sequence_file(Image *ima, ImageUser *iuser, int entry, ibuf = ibuf_arr[(iuser ? iuser->multi_index : 0)]; if (assign) { - for (i = 0; i < totviews; i++) { + for (int i = 0; i < totviews; i++) { image_assign_ibuf(ima, ibuf_arr[i], i, entry); } } /* "remove" the others (decrease their refcount) */ - for (i = 0; i < totviews; i++) { + for (int i = 0; i < totviews; i++) { if (ibuf_arr[i] != ibuf) { IMB_freeImBuf(ibuf_arr[i]); } @@ -4232,12 +4231,11 @@ static ImBuf *image_load_movie_file(Image *ima, ImageUser *iuser, int frame) const bool is_multiview = BKE_image_is_multiview(ima); const int totfiles = image_num_files(ima); ImageTile *tile = BKE_image_get_tile(ima, 0); - int i; if (totfiles != BLI_listbase_count_at_most(&ima->anims, totfiles + 1)) { image_free_anims(ima); - for (i = 0; i < totfiles; i++) { + for (int i = 0; i < totfiles; i++) { /* allocate the ImageAnim */ ImageAnim *ia = MEM_callocN(sizeof(ImageAnim), "Image Anim"); BLI_addtail(&ima->anims, ia); @@ -4254,7 +4252,7 @@ static ImBuf *image_load_movie_file(Image *ima, ImageUser *iuser, int frame) ibuf_arr = MEM_mallocN(sizeof(ImBuf *) * totviews, "Image Views (movie) Imbufs"); - for (i = 0; i < totfiles; i++) { + for (int i = 0; i < totfiles; i++) { ibuf_arr[i] = load_movie_single(ima, iuser, frame, i); } @@ -4262,7 +4260,7 @@ static ImBuf *image_load_movie_file(Image *ima, ImageUser *iuser, int frame) IMB_ImBufFromStereo3d(ima->stereo3d_format, ibuf_arr[0], &ibuf_arr[0], &ibuf_arr[1]); } - for (i = 0; i < totviews; i++) { + for (int i = 0; i < totviews; i++) { if (ibuf_arr[i]) { image_assign_ibuf(ima, ibuf_arr[i], i, frame); } @@ -4275,7 +4273,7 @@ static ImBuf *image_load_movie_file(Image *ima, ImageUser *iuser, int frame) ibuf = ibuf_arr[(iuser ? iuser->multi_index : 0)]; /* "remove" the others (decrease their refcount) */ - for (i = 0; i < totviews; i++) { + for (int i = 0; i < totviews; i++) { if (ibuf_arr[i] != ibuf) { IMB_freeImBuf(ibuf_arr[i]); } @@ -4411,12 +4409,11 @@ static ImBuf *image_load_image_file(Image *ima, ImageUser *iuser, int cfra) else { struct ImBuf **ibuf_arr; const int totviews = BLI_listbase_count(&ima->views); - int i; BLI_assert(totviews > 0); ibuf_arr = MEM_callocN(sizeof(ImBuf *) * totviews, "Image Views Imbufs"); - for (i = 0; i < totfiles; i++) { + for (int i = 0; i < totfiles; i++) { ibuf_arr[i] = load_image_single(ima, iuser, cfra, i, has_packed, &assign); } @@ -4427,7 +4424,7 @@ static ImBuf *image_load_image_file(Image *ima, ImageUser *iuser, int cfra) } /* return the original requested ImBuf */ - i = (iuser && iuser->multi_index < totviews) ? iuser->multi_index : 0; + int i = (iuser && iuser->multi_index < totviews) ? iuser->multi_index : 0; ibuf = ibuf_arr[i]; if (assign) { @@ -5681,10 +5678,9 @@ static void image_update_views_format(Image *ima, ImageUser *iuser) /* nothing to do */ } else if (ima->views_format == R_IMF_VIEWS_STEREO_3D) { - int i; const char *names[2] = {STEREO_LEFT_NAME, STEREO_RIGHT_NAME}; - for (i = 0; i < 2; i++) { + for (int i = 0; i < 2; i++) { image_add_view(ima, names[i], ima->filepath); } return; diff --git a/source/blender/blenkernel/intern/image_save.c b/source/blender/blenkernel/intern/image_save.c index 19eb3380b8e..e571499ba8e 100644 --- a/source/blender/blenkernel/intern/image_save.c +++ b/source/blender/blenkernel/intern/image_save.c @@ -252,7 +252,6 @@ static bool image_save_single(ReportList *reports, } /* individual multiview images */ else if (imf->views_format == R_IMF_VIEWS_INDIVIDUAL) { - int i; unsigned char planes = ibuf->planes; const int totviews = (rr ? BLI_listbase_count(&rr->views) : BLI_listbase_count(&ima->views)); @@ -260,7 +259,7 @@ static bool image_save_single(ReportList *reports, BKE_image_release_ibuf(ima, ibuf, lock); } - for (i = 0; i < totviews; i++) { + for (int i = 0; i < totviews; i++) { char filepath[FILE_MAX]; bool ok_view = false; const char *view = rr ? ((RenderView *)BLI_findlink(&rr->views, i))->name : @@ -324,12 +323,11 @@ static bool image_save_single(ReportList *reports, unsigned char planes = ibuf->planes; const char *names[2] = {STEREO_LEFT_NAME, STEREO_RIGHT_NAME}; - int i; /* we need to get the specific per-view buffers */ BKE_image_release_ibuf(ima, ibuf, lock); - for (i = 0; i < 2; i++) { + for (int i = 0; i < 2; i++) { ImageUser view_iuser; if (iuser) { @@ -382,7 +380,7 @@ static bool image_save_single(ReportList *reports, IMB_freeImBuf(ibuf); - for (i = 0; i < 2; i++) { + for (int i = 0; i < 2; i++) { IMB_freeImBuf(ibuf_stereo[i]); } } diff --git a/source/blender/blenkernel/intern/key.c b/source/blender/blenkernel/intern/key.c index 456325851a6..9cdbb30b90a 100644 --- a/source/blender/blenkernel/intern/key.c +++ b/source/blender/blenkernel/intern/key.c @@ -1242,7 +1242,6 @@ static float *get_weights_array(Object *ob, char *vgroup, WeightsArrayCache *cac defgrp_index = BKE_object_defgroup_name_index(ob, vgroup); if (defgrp_index != -1) { float *weights; - int i; if (cache) { if (cache->defgroup_weights == NULL) { @@ -1260,6 +1259,7 @@ static float *get_weights_array(Object *ob, char *vgroup, WeightsArrayCache *cac weights = MEM_mallocN(totvert * sizeof(float), "weights"); if (em) { + int i; const int cd_dvert_offset = CustomData_get_offset(&em->bm->vdata, CD_MDEFORMVERT); BM_ITER_MESH_INDEX (eve, &iter, em->bm, BM_VERTS_OF_MESH, i) { dvert = BM_ELEM_CD_GET_VOID_P(eve, cd_dvert_offset); @@ -1267,7 +1267,7 @@ static float *get_weights_array(Object *ob, char *vgroup, WeightsArrayCache *cac } } else { - for (i = 0; i < totvert; i++, dvert++) { + for (int i = 0; i < totvert; i++, dvert++) { weights[i] = BKE_defvert_find_weight(dvert, defgrp_index); } } @@ -1860,13 +1860,10 @@ KeyBlock *BKE_keyblock_from_object_reference(Object *ob) /* get the appropriate KeyBlock given an index */ KeyBlock *BKE_keyblock_from_key(Key *key, int index) { - KeyBlock *kb; - int i; - if (key) { - kb = key->block.first; + KeyBlock *kb = key->block.first; - for (i = 1; i < key->totkey; i++) { + for (int i = 1; i < key->totkey; i++) { kb = kb->next; if (index == i) { diff --git a/source/blender/blenkernel/intern/lattice.c b/source/blender/blenkernel/intern/lattice.c index 5201faef9cd..a3267c0762e 100644 --- a/source/blender/blenkernel/intern/lattice.c +++ b/source/blender/blenkernel/intern/lattice.c @@ -249,11 +249,10 @@ void BKE_lattice_bitmap_from_flag( Lattice *lt, BLI_bitmap *bitmap, const short flag, const bool clear, const bool respecthide) { const unsigned int tot = lt->pntsu * lt->pntsv * lt->pntsw; - unsigned int i; BPoint *bp; bp = lt->def; - for (i = 0; i < tot; i++, bp++) { + for (int i = 0; i < tot; i++, bp++) { if ((bp->f1 & flag) && (!respecthide || !bp->hide)) { BLI_BITMAP_ENABLE(bitmap, i); } diff --git a/source/blender/blenkernel/intern/mask.c b/source/blender/blenkernel/intern/mask.c index 79b8a30242e..272c9fda9ae 100644 --- a/source/blender/blenkernel/intern/mask.c +++ b/source/blender/blenkernel/intern/mask.c @@ -362,7 +362,6 @@ void BKE_mask_point_direction_switch(MaskSplinePoint *point) { const int tot_uw = point->tot_uw; const int tot_uw_half = tot_uw / 2; - int i; float co_tmp[2]; @@ -377,14 +376,14 @@ void BKE_mask_point_direction_switch(MaskSplinePoint *point) /* swap UW's */ if (tot_uw > 1) { /* count */ - for (i = 0; i < tot_uw_half; i++) { + for (int i = 0; i < tot_uw_half; i++) { MaskSplinePointUW *uw_a = &point->uw[i]; MaskSplinePointUW *uw_b = &point->uw[tot_uw - (i + 1)]; SWAP(MaskSplinePointUW, *uw_a, *uw_b); } } - for (i = 0; i < tot_uw; i++) { + for (int i = 0; i < tot_uw; i++) { MaskSplinePointUW *uw = &point->uw[i]; uw->u = 1.0f - uw->u; } @@ -731,10 +730,8 @@ float BKE_mask_point_weight(MaskSpline *spline, MaskSplinePoint *point, const fl } float cur_u = 0.0f, cur_w = 0.0f, next_u = 0.0f, next_w = 0.0f, fac; /* Quite warnings */ - int i; - - for (i = 0; i <= point->tot_uw; i++) { + for (int i = 0; i <= point->tot_uw; i++) { if (i == 0) { cur_u = 0.0f; cur_w = 1.0f; /* mask_point_interp_weight will scale it */ @@ -815,8 +812,6 @@ void BKE_mask_point_add_uw(MaskSplinePoint *point, float u, float w) void BKE_mask_point_select_set(MaskSplinePoint *point, const bool do_select) { - int i; - if (do_select) { MASKPOINT_SEL_ALL(point); } @@ -824,7 +819,7 @@ void BKE_mask_point_select_set(MaskSplinePoint *point, const bool do_select) MASKPOINT_DESEL_ALL(point); } - for (i = 0; i < point->tot_uw; i++) { + for (int i = 0; i < point->tot_uw; i++) { if (do_select) { point->uw[i].flag |= SELECT; } @@ -979,12 +974,9 @@ void BKE_mask_spline_free_list(ListBase *splines) static MaskSplinePoint *mask_spline_points_copy(const MaskSplinePoint *points, int tot_point) { - MaskSplinePoint *npoints; - int i; - - npoints = MEM_dupallocN(points); + MaskSplinePoint *npoints = MEM_dupallocN(points); - for (i = 0; i < tot_point; i++) { + for (int i = 0; i < tot_point; i++) { MaskSplinePoint *point = &npoints[i]; if (point->uw) { @@ -1435,8 +1427,7 @@ void BKE_mask_layer_calc_handles(MaskLayer *masklay) { MaskSpline *spline; for (spline = masklay->splines.first; spline; spline = spline->next) { - int i; - for (i = 0; i < spline->tot_point; i++) { + for (int i = 0; i < spline->tot_point; i++) { BKE_mask_calc_handle_point(spline, &spline->points[i]); } } @@ -1451,9 +1442,7 @@ void BKE_mask_spline_ensure_deform(MaskSpline *spline) // printf("alloc new deform spline\n"); if (spline->points_deform) { - int i; - - for (i = 0; i < allocated_points; i++) { + for (int i = 0; i < allocated_points; i++) { MaskSplinePoint *point = &spline->points_deform[i]; BKE_mask_point_free(point); } @@ -1538,8 +1527,7 @@ void BKE_mask_layer_shape_from_mask(MaskLayer *masklay, MaskLayerShape *masklay_ MaskSpline *spline; for (spline = masklay->splines.first; spline; spline = spline->next) { - int i; - for (i = 0; i < spline->tot_point; i++) { + for (int i = 0; i < spline->tot_point; i++) { mask_layer_shape_from_mask_point(&spline->points[i].bezt, fp); fp += MASK_OBJECT_SHAPE_ELEM_SIZE; } @@ -1563,8 +1551,7 @@ void BKE_mask_layer_shape_to_mask(MaskLayer *masklay, MaskLayerShape *masklay_sh MaskSpline *spline; for (spline = masklay->splines.first; spline; spline = spline->next) { - int i; - for (i = 0; i < spline->tot_point; i++) { + for (int i = 0; i < spline->tot_point; i++) { mask_layer_shape_to_mask_point(&spline->points[i].bezt, fp); fp += MASK_OBJECT_SHAPE_ELEM_SIZE; } @@ -1600,8 +1587,7 @@ void BKE_mask_layer_shape_to_mask_interp(MaskLayer *masklay, MaskSpline *spline; for (spline = masklay->splines.first; spline; spline = spline->next) { - int i; - for (i = 0; i < spline->tot_point; i++) { + for (int i = 0; i < spline->tot_point; i++) { BezTriple *bezt = &spline->points[i].bezt; /* *** BKE_mask_layer_shape_from_mask - swapped *** */ interp_v2_v2v2_flfl(bezt->vec[0], fp_a, fp_b, fac, ifac); @@ -1836,9 +1822,8 @@ void BKE_mask_layer_shape_changed_add(MaskLayer *masklay, const int pi_prev_abs = pi_prev + index_offset; const int pi_next_abs = pi_next + index_offset; - int i; if (do_init_interpolate) { - for (i = 0; i < 3; i++) { + for (int i = 0; i < 3; i++) { interp_weights_uv_v2_calc(uv[i], spline->points[pi_curr].bezt.vec[i], spline->points[pi_prev].bezt.vec[i], @@ -1873,7 +1858,7 @@ void BKE_mask_layer_shape_changed_add(MaskLayer *masklay, mask_layer_shape_from_mask_point(&spline->points[spline_point_index].bezt, fp); if (do_init_interpolate && spline->tot_point > 2) { - for (i = 0; i < 3; i++) { + for (int i = 0; i < 3; i++) { interp_weights_uv_v2_apply( uv[i], &fp[i * 2], @@ -1988,8 +1973,7 @@ void BKE_mask_clipboard_copy_from_layer(MaskLayer *mask_layer) for (spline = mask_layer->splines.first; spline; spline = spline->next) { if (spline->flag & SELECT) { MaskSpline *spline_new = BKE_mask_spline_copy(spline); - int i; - for (i = 0; i < spline_new->tot_point; i++) { + for (int i = 0; i < spline_new->tot_point; i++) { MaskSplinePoint *point = &spline_new->points[i]; if (point->parent.id) { if (!BLI_ghash_lookup(mask_clipboard.id_hash, point->parent.id)) { @@ -2019,9 +2003,8 @@ void BKE_mask_clipboard_paste_to_layer(Main *bmain, MaskLayer *mask_layer) for (spline = mask_clipboard.splines.first; spline; spline = spline->next) { MaskSpline *spline_new = BKE_mask_spline_copy(spline); - int i; - for (i = 0; i < spline_new->tot_point; i++) { + for (int i = 0; i < spline_new->tot_point; i++) { MaskSplinePoint *point = &spline_new->points[i]; if (point->parent.id) { const char *id_name = BLI_ghash_lookup(mask_clipboard.id_hash, point->parent.id); diff --git a/source/blender/blenkernel/intern/mask_evaluate.c b/source/blender/blenkernel/intern/mask_evaluate.c index 2fbf5f8648d..595fd0c9550 100644 --- a/source/blender/blenkernel/intern/mask_evaluate.c +++ b/source/blender/blenkernel/intern/mask_evaluate.c @@ -84,22 +84,19 @@ unsigned int BKE_mask_spline_feather_resolution(MaskSpline *spline, int width, i const float max_segment = 0.005; unsigned int resol = BKE_mask_spline_resolution(spline, width, height); float max_jump = 0.0f; - int i; /* avoid checking the featrher if we already hit the maximum value */ if (resol >= MASK_RESOL_MAX) { return MASK_RESOL_MAX; } - for (i = 0; i < spline->tot_point; i++) { + for (int i = 0; i < spline->tot_point; i++) { MaskSplinePoint *point = &spline->points[i]; - float prev_u, prev_w; - int j; - prev_u = 0.0f; - prev_w = point->bezt.weight; + float prev_u = 0.0f; + float prev_w = point->bezt.weight; - for (j = 0; j < point->tot_uw; j++) { + for (int j = 0; j < point->tot_uw; j++) { const float w_diff = (point->uw[j].w - prev_w); const float u_diff = (point->uw[j].u - prev_u); @@ -239,12 +236,10 @@ static void feather_bucket_check_intersect(float (*feather_points)[2], int cur_a, int cur_b) { - int i; - const float *v1 = (float *)feather_points[cur_a]; const float *v2 = (float *)feather_points[cur_b]; - for (i = 0; i < bucket->tot_segment; i++) { + for (int i = 0; i < bucket->tot_segment; i++) { int check_a = bucket->segments[i][0]; int check_b = bucket->segments[i][1]; @@ -346,7 +341,6 @@ void BKE_mask_spline_feather_collapse_inner_loops(MaskSpline *spline, FeatherEdgesBucket *buckets; - unsigned int i; float min[2], max[2]; float max_delta_x = -1.0f, max_delta_y = -1.0f, max_delta; @@ -361,7 +355,7 @@ void BKE_mask_spline_feather_collapse_inner_loops(MaskSpline *spline, /* find min/max corners of mask to build buckets in that space */ INIT_MINMAX2(min, max); - for (i = 0; i < tot_feather_point; i++) { + for (uint i = 0; i < tot_feather_point; i++) { unsigned int next = i + 1; float delta; @@ -426,7 +420,7 @@ void BKE_mask_spline_feather_collapse_inner_loops(MaskSpline *spline, /* fill in buckets' edges */ buckets = MEM_callocN(sizeof(FeatherEdgesBucket) * tot_bucket, "feather buckets"); - for (i = 0; i < tot_feather_point; i++) { + for (int i = 0; i < tot_feather_point; i++) { int start = i, end = i + 1; int start_bucket_index, end_bucket_index; @@ -462,7 +456,7 @@ void BKE_mask_spline_feather_collapse_inner_loops(MaskSpline *spline, } /* check all edges for intersection with edges from their buckets */ - for (i = 0; i < tot_feather_point; i++) { + for (int i = 0; i < tot_feather_point; i++) { int cur_a = i, cur_b = i + 1; int start_bucket_index, end_bucket_index; @@ -499,7 +493,7 @@ void BKE_mask_spline_feather_collapse_inner_loops(MaskSpline *spline, } /* free buckets */ - for (i = 0; i < tot_bucket; i++) { + for (int i = 0; i < tot_bucket; i++) { if (buckets[i].segments) { MEM_freeN(buckets[i].segments); } @@ -803,11 +797,10 @@ float *BKE_mask_point_segment_feather_diff(MaskSpline *spline, { float *feather, *fp; unsigned int resol = BKE_mask_spline_feather_resolution(spline, width, height); - unsigned int i; feather = fp = MEM_callocN(2 * resol * sizeof(float), "mask point spline feather diff points"); - for (i = 0; i < resol; i++, fp += 2) { + for (uint i = 0; i < resol; i++, fp += 2) { float u = (float)(i % resol) / resol, weight; float co[2], n[2]; diff --git a/source/blender/blenkernel/intern/mask_rasterize.c b/source/blender/blenkernel/intern/mask_rasterize.c index 92885535f57..583ee8f2857 100644 --- a/source/blender/blenkernel/intern/mask_rasterize.c +++ b/source/blender/blenkernel/intern/mask_rasterize.c @@ -226,10 +226,9 @@ MaskRasterHandle *BKE_maskrasterize_handle_new(void) void BKE_maskrasterize_handle_free(MaskRasterHandle *mr_handle) { const unsigned int layers_tot = mr_handle->layers_tot; - unsigned int i; MaskRasterLayer *layer = mr_handle->layers; - for (i = 0; i < layers_tot; i++, layer++) { + for (uint i = 0; i < layers_tot; i++, layer++) { if (layer->face_array) { MEM_freeN(layer->face_array); @@ -672,7 +671,6 @@ void BKE_maskrasterize_handle_init(MaskRasterHandle *mr_handle, if (width != height) { float *fp; float *ffp; - unsigned int i; float asp; if (width < height) { @@ -686,12 +684,12 @@ void BKE_maskrasterize_handle_init(MaskRasterHandle *mr_handle, asp = (float)height / (float)width; } - for (i = 0; i < tot_diff_point; i++, fp += 2) { + for (uint i = 0; i < tot_diff_point; i++, fp += 2) { (*fp) = (((*fp) - 0.5f) / asp) + 0.5f; } if (tot_diff_feather_points) { - for (i = 0; i < tot_diff_feather_points; i++, ffp += 2) { + for (uint i = 0; i < tot_diff_feather_points; i++, ffp += 2) { (*ffp) = (((*ffp) - 0.5f) / asp) + 0.5f; } } @@ -1353,13 +1351,12 @@ float BKE_maskrasterize_handle_sample(MaskRasterHandle *mr_handle, const float x /* if (BLI_rctf_isect_pt_v(&mr_handle->bounds, xy)) */ const unsigned int layers_tot = mr_handle->layers_tot; - unsigned int i; MaskRasterLayer *layer = mr_handle->layers; /* return value */ float value = 0.0f; - for (i = 0; i < layers_tot; i++, layer++) { + for (uint i = 0; i < layers_tot; i++, layer++) { float value_layer; /* also used as signal for unused layer (when render is disabled) */ diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c index d521d6c8a99..245cf19846e 100644 --- a/source/blender/blenkernel/intern/material.c +++ b/source/blender/blenkernel/intern/material.c @@ -1287,9 +1287,7 @@ void BKE_texpaint_slot_refresh_cache(Scene *scene, Material *ma) void BKE_texpaint_slots_refresh_object(Scene *scene, struct Object *ob) { - int i; - - for (i = 1; i < ob->totcol + 1; i++) { + for (int i = 1; i < ob->totcol + 1; i++) { Material *ma = BKE_object_material_get(ob, i); BKE_texpaint_slot_refresh_cache(scene, ma); } diff --git a/source/blender/blenkernel/intern/mball.c b/source/blender/blenkernel/intern/mball.c index fe6f1bd4a97..2a1ac12baaa 100644 --- a/source/blender/blenkernel/intern/mball.c +++ b/source/blender/blenkernel/intern/mball.c @@ -484,7 +484,6 @@ bool BKE_mball_minmax_ex( LISTBASE_FOREACH (const MetaElem *, ml, &mb->elems) { if ((ml->flag & flag) == flag) { const float scale_mb = (ml->rad * 0.5f) * scale; - int i; if (obmat) { mul_v3_m4v3(centroid, obmat, &ml->x); @@ -494,7 +493,7 @@ bool BKE_mball_minmax_ex( } /* TODO, non circle shapes cubes etc, probably nobody notices - campbell */ - for (i = -1; i != 3; i += 2) { + for (int i = -1; i != 3; i += 2) { copy_v3_v3(vec, centroid); add_v3_fl(vec, scale_mb * i); minmax_v3v3_v3(min, max, vec); diff --git a/source/blender/blenkernel/intern/mball_tessellate.c b/source/blender/blenkernel/intern/mball_tessellate.c index 2a7d3f1797d..7273d2a920d 100644 --- a/source/blender/blenkernel/intern/mball_tessellate.c +++ b/source/blender/blenkernel/intern/mball_tessellate.c @@ -410,7 +410,6 @@ static float densfunc(const MetaElem *ball, float x, float y, float z) */ static float metaball(PROCESS *process, float x, float y, float z) { - int i; float dens = 0.0f; unsigned int front = 0, back = 0; MetaballBVHNode *node; @@ -420,7 +419,7 @@ static float metaball(PROCESS *process, float x, float y, float z) while (front != back) { node = process->bvh_queue[back++]; - for (i = 0; i < 2; i++) { + for (int i = 0; i < 2; i++) { if ((node->bb[i].min[0] <= x) && (node->bb[i].max[0] >= x) && (node->bb[i].min[1] <= y) && (node->bb[i].max[1] >= y) && (node->bb[i].min[2] <= z) && (node->bb[i].max[2] >= z)) { if (node->child[i]) { @@ -833,18 +832,14 @@ static void makecubetable(void) void BKE_mball_cubeTable_free(void) { - int i; - INTLISTS *lists, *nlists; - INTLIST *ints, *nints; - - for (i = 0; i < 256; i++) { - lists = cubetable[i]; + for (int i = 0; i < 256; i++) { + INTLISTS *lists = cubetable[i]; while (lists) { - nlists = lists->next; + INTLISTS *nlists = lists->next; - ints = lists->list; + INTLIST *ints = lists->list; while (ints) { - nints = ints->next; + INTLIST *nints = ints->next; MEM_freeN(ints); ints = nints; } @@ -1014,8 +1009,6 @@ static int vertid(PROCESS *process, const CORNER *c1, const CORNER *c2) */ static void converge(PROCESS *process, const CORNER *c1, const CORNER *c2, float r_p[3]) { - float tmp, dens; - unsigned int i; float c1_value, c1_co[3]; float c2_value, c2_co[3]; @@ -1032,9 +1025,9 @@ static void converge(PROCESS *process, const CORNER *c1, const CORNER *c2, float copy_v3_v3(c2_co, c2->co); } - for (i = 0; i < process->converge_res; i++) { + for (uint i = 0; i < process->converge_res; i++) { interp_v3_v3v3(r_p, c1_co, c2_co, 0.5f); - dens = metaball(process, r_p[0], r_p[1], r_p[2]); + float dens = metaball(process, r_p[0], r_p[1], r_p[2]); if (dens > 0.0f) { c1_value = dens; @@ -1046,7 +1039,7 @@ static void converge(PROCESS *process, const CORNER *c1, const CORNER *c2, float } } - tmp = -c1_value / (c2_value - c1_value); + float tmp = -c1_value / (c2_value - c1_value); interp_v3_v3v3(r_p, c1_co, c2_co, tmp); } @@ -1154,7 +1147,6 @@ static void find_first_points(PROCESS *process, const unsigned int em) static void polygonize(PROCESS *process) { CUBE c; - unsigned int i; process->centers = MEM_callocN(HASHSIZE * sizeof(CENTERLIST *), "mbproc->centers"); process->corners = MEM_callocN(HASHSIZE * sizeof(CORNER *), "mbproc->corners"); @@ -1164,7 +1156,7 @@ static void polygonize(PROCESS *process) makecubetable(); - for (i = 0; i < process->totelem; i++) { + for (uint i = 0; i < process->totelem; i++) { find_first_points(process, i); } diff --git a/source/blender/blenkernel/intern/mesh_convert.c b/source/blender/blenkernel/intern/mesh_convert.c index 9426d09885e..60a9ef2df55 100644 --- a/source/blender/blenkernel/intern/mesh_convert.c +++ b/source/blender/blenkernel/intern/mesh_convert.c @@ -400,9 +400,7 @@ int BKE_mesh_nurbs_displist_to_mdata(Object *ob, mpoly->mat_nr = dl->col; if (mloopuv) { - int i; - - for (i = 0; i < 3; i++, mloopuv++) { + for (int i = 0; i < 3; i++, mloopuv++) { mloopuv->uv[0] = (mloop[i].v - startvert) / (float)(dl->nr - 1); mloopuv->uv[1] = 0.0f; } @@ -464,7 +462,6 @@ int BKE_mesh_nurbs_displist_to_mdata(Object *ob, if (mloopuv) { int orco_sizeu = dl->nr - 1; int orco_sizev = dl->parts - 1; - int i; /* exception as handled in convertblender.c too */ if (dl->flag & DL_CYCL_U) { @@ -477,7 +474,7 @@ int BKE_mesh_nurbs_displist_to_mdata(Object *ob, orco_sizev++; } - for (i = 0; i < 4; i++, mloopuv++) { + for (int i = 0; i < 4; i++, mloopuv++) { /* find uv based on vertex index into grid array */ int v = mloop[i].v - startvert; diff --git a/source/blender/blenkernel/intern/mesh_evaluate.c b/source/blender/blenkernel/intern/mesh_evaluate.c index fe4b8a60796..0c83820bce9 100644 --- a/source/blender/blenkernel/intern/mesh_evaluate.c +++ b/source/blender/blenkernel/intern/mesh_evaluate.c @@ -75,8 +75,7 @@ static CLG_LogRef LOG = {"bke.mesh_evaluate"}; */ static void mesh_calc_normals_vert_fallback(MVert *mverts, int numVerts) { - int i; - for (i = 0; i < numVerts; i++) { + for (int i = 0; i < numVerts; i++) { MVert *mv = &mverts[i]; float no[3]; @@ -149,9 +148,6 @@ void BKE_mesh_calc_normals_mapping_ex(MVert *mverts, const bool only_face_normals) { float(*pnors)[3] = r_polyNors, (*fnors)[3] = r_faceNors; - int i; - const MFace *mf; - const MPoly *mp; if (numPolys == 0) { if (only_face_normals == false) { @@ -180,8 +176,8 @@ void BKE_mesh_calc_normals_mapping_ex(MVert *mverts, } else { /* only calc poly normals */ - mp = mpolys; - for (i = 0; i < numPolys; i++, mp++) { + const MPoly *mp = mpolys; + for (int i = 0; i < numPolys; i++, mp++) { BKE_mesh_calc_poly_normal(mp, mloop + mp->loopstart, mverts, pnors[i]); } } @@ -190,8 +186,8 @@ void BKE_mesh_calc_normals_mapping_ex(MVert *mverts, /* fnors == r_faceNors */ /* NO NEED TO ALLOC YET */ fnors != NULL && numFaces) { - mf = mfaces; - for (i = 0; i < numFaces; i++, mf++, origIndexFace++) { + const MFace *mf = mfaces; + for (int i = 0; i < numFaces; i++, mf++, origIndexFace++) { if (*origIndexFace < numPolys) { copy_v3_v3(fnors[i], pnors[*origIndexFace]); } @@ -244,7 +240,6 @@ static void mesh_calc_normals_poly_prepare_cb(void *__restrict userdata, const int nverts = mp->totloop; float(*edgevecbuf)[3] = BLI_array_alloca(edgevecbuf, (size_t)nverts); - int i; /* Polygon Normal and edge-vector */ /* inline version of #BKE_mesh_calc_poly_normal, also does edge-vectors */ @@ -255,7 +250,7 @@ static void mesh_calc_normals_poly_prepare_cb(void *__restrict userdata, zero_v3(pnor); /* Newell's Method */ - for (i = 0; i < nverts; i++) { + for (int i = 0; i < nverts; i++) { v_curr = mverts[ml[i].v].co; add_newell_cross_v3_v3v3(pnor, v_prev, v_curr); @@ -277,7 +272,7 @@ static void mesh_calc_normals_poly_prepare_cb(void *__restrict userdata, { const float *prev_edge = edgevecbuf[nverts - 1]; - for (i = 0; i < nverts; i++) { + for (int i = 0; i < nverts; i++) { const int lidx = mp->loopstart + i; const float *cur_edge = edgevecbuf[i]; @@ -475,13 +470,12 @@ void BKE_mesh_calc_normals_looptri(MVert *mverts, float(*fnors)[3] = (r_tri_nors) ? r_tri_nors : MEM_calloc_arrayN((size_t)looptri_num, sizeof(*fnors), "meshnormals"); - int i; if (!tnorms || !fnors) { goto cleanup; } - for (i = 0; i < looptri_num; i++) { + for (int i = 0; i < looptri_num; i++) { const MLoopTri *lt = &looptri[i]; float *f_no = fnors[i]; const unsigned int vtri[3] = { @@ -502,7 +496,7 @@ void BKE_mesh_calc_normals_looptri(MVert *mverts, } /* following Mesh convention; we use vertex coordinate itself for normal in this case */ - for (i = 0; i < numVerts; i++) { + for (int i = 0; i < numVerts; i++) { MVert *mv = &mverts[i]; float *no = tnorms[i]; @@ -1785,7 +1779,6 @@ static void mesh_normals_loop_custom_set(const MVert *mverts, * and do not want to use angle to define smooth fans! */ const bool use_split_normals = true; const float split_angle = (float)M_PI; - int i; BLI_SMALLSTACK_DECLARE(clnors_data, short *); @@ -1808,14 +1801,14 @@ static void mesh_normals_loop_custom_set(const MVert *mverts, /* Set all given zero vectors to their default value. */ if (use_vertices) { - for (i = 0; i < numVerts; i++) { + for (int i = 0; i < numVerts; i++) { if (is_zero_v3(r_custom_loopnors[i])) { normal_short_to_float_v3(r_custom_loopnors[i], mverts[i].no); } } } else { - for (i = 0; i < numLoops; i++) { + for (int i = 0; i < numLoops; i++) { if (is_zero_v3(r_custom_loopnors[i])) { copy_v3_v3(r_custom_loopnors[i], lnors[i]); } @@ -1832,7 +1825,7 @@ static void mesh_normals_loop_custom_set(const MVert *mverts, * when we set custom normals per vertices, running this is absolutely useless. */ if (!use_vertices) { - for (i = 0; i < numLoops; i++) { + for (int i = 0; i < numLoops; i++) { if (!lnors_spacearr.lspacearr[i]) { /* This should not happen in theory, but in some rare case (probably ugly geometry) * we can get some NULL loopspacearr at this point. :/ @@ -1937,7 +1930,7 @@ static void mesh_normals_loop_custom_set(const MVert *mverts, /* And we just have to convert plain object-space custom normals to our * lnor space-encoded ones. */ - for (i = 0; i < numLoops; i++) { + for (int i = 0; i < numLoops; i++) { if (!lnors_spacearr.lspacearr[i]) { BLI_BITMAP_DISABLE(done_loops, i); if (G.debug & G_DEBUG) { @@ -2131,13 +2124,12 @@ void BKE_mesh_normals_loop_to_vertex(const int numVerts, const float (*clnors)[3], float (*r_vert_clnors)[3]) { - const MLoop *ml; - int i; - int *vert_loops_nbr = MEM_calloc_arrayN((size_t)numVerts, sizeof(*vert_loops_nbr), __func__); copy_vn_fl((float *)r_vert_clnors, 3 * numVerts, 0.0f); + int i; + const MLoop *ml; for (i = 0, ml = mloops; i < numLoops; i++, ml++) { const unsigned int v = ml->v; @@ -2175,12 +2167,11 @@ static void mesh_calc_ngon_normal(const MPoly *mpoly, const int nverts = mpoly->totloop; const float *v_prev = mvert[loopstart[nverts - 1].v].co; const float *v_curr; - int i; zero_v3(normal); /* Newell's Method */ - for (i = 0; i < nverts; i++) { + for (int i = 0; i < nverts; i++) { v_curr = mvert[loopstart[i].v].co; add_newell_cross_v3_v3v3(normal, v_prev, v_curr); v_prev = v_curr; @@ -2225,12 +2216,11 @@ static void mesh_calc_ngon_normal_coords(const MPoly *mpoly, const int nverts = mpoly->totloop; const float *v_prev = vertex_coords[loopstart[nverts - 1].v]; const float *v_curr; - int i; zero_v3(r_normal); /* Newell's Method */ - for (i = 0; i < nverts; i++) { + for (int i = 0; i < nverts; i++) { v_curr = vertex_coords[loopstart[i].v]; add_newell_cross_v3_v3v3(r_normal, v_prev, v_curr); v_prev = v_curr; @@ -2275,11 +2265,10 @@ static void mesh_calc_ngon_center(const MPoly *mpoly, float cent[3]) { const float w = 1.0f / (float)mpoly->totloop; - int i; zero_v3(cent); - for (i = 0; i < mpoly->totloop; i++) { + for (int i = 0; i < mpoly->totloop; i++) { madd_v3_v3fl(cent, mvert[(loopstart++)->v].co, w); } } @@ -2315,18 +2304,16 @@ float BKE_mesh_calc_poly_area(const MPoly *mpoly, const MLoop *loopstart, const mvarray[loopstart[0].v].co, mvarray[loopstart[1].v].co, mvarray[loopstart[2].v].co); } - int i; const MLoop *l_iter = loopstart; - float area; float(*vertexcos)[3] = BLI_array_alloca(vertexcos, (size_t)mpoly->totloop); /* pack vertex cos into an array for area_poly_v3 */ - for (i = 0; i < mpoly->totloop; i++, l_iter++) { + for (int i = 0; i < mpoly->totloop; i++, l_iter++) { copy_v3_v3(vertexcos[i], mvarray[l_iter->v].co); } /* finally calculate the area */ - area = area_poly_v3((const float(*)[3])vertexcos, (unsigned int)mpoly->totloop); + float area = area_poly_v3((const float(*)[3])vertexcos, (unsigned int)mpoly->totloop); return area; } @@ -2462,8 +2449,6 @@ static float mesh_calc_poly_area_centroid(const MPoly *mpoly, const MVert *mvarray, float r_cent[3]) { - int i; - float tri_area; float total_area = 0.0f; float v1[3], v2[3], v3[3], normal[3], tri_cent[3]; @@ -2472,10 +2457,10 @@ static float mesh_calc_poly_area_centroid(const MPoly *mpoly, copy_v3_v3(v2, mvarray[loopstart[1].v].co); zero_v3(r_cent); - for (i = 2; i < mpoly->totloop; i++) { + for (int i = 2; i < mpoly->totloop; i++) { copy_v3_v3(v3, mvarray[loopstart[i].v].co); - tri_area = area_tri_signed_v3(v1, v2, v3, normal); + float tri_area = area_tri_signed_v3(v1, v2, v3, normal); total_area += tri_area; mid_v3_v3v3v3(tri_cent, v1, v2, v3); @@ -2693,9 +2678,6 @@ static bool mesh_calc_center_centroid_ex(const MVert *mverts, const MLoop *mloop, float r_center[3]) { - const MLoopTri *lt; - float totweight; - int i; zero_v3(r_center); @@ -2703,7 +2685,9 @@ static bool mesh_calc_center_centroid_ex(const MVert *mverts, return false; } - totweight = 0.0f; + float totweight = 0.0f; + const MLoopTri *lt; + int i; for (i = 0, lt = looptri; i < looptri_num; i++, lt++) { const MVert *v1 = &mverts[mloop[lt->tri[0]].v]; const MVert *v2 = &mverts[mloop[lt->tri[1]].v]; @@ -3444,19 +3428,12 @@ static void bm_corners_to_loops_ex(ID *id, int numTex, int numCol) { - MTFace *texface; - MCol *mcol; - MLoopCol *mloopcol; - MLoopUV *mloopuv; - MFace *mf; - int i; - - mf = mface + findex; + MFace *mf = mface + findex; - for (i = 0; i < numTex; i++) { - texface = CustomData_get_n(fdata, CD_MTFACE, findex, i); + for (int i = 0; i < numTex; i++) { + MTFace *texface = CustomData_get_n(fdata, CD_MTFACE, findex, i); - mloopuv = CustomData_get_n(ldata, CD_MLOOPUV, loopstart, i); + MLoopUV *mloopuv = CustomData_get_n(ldata, CD_MLOOPUV, loopstart, i); copy_v2_v2(mloopuv->uv, texface->uv[0]); mloopuv++; copy_v2_v2(mloopuv->uv, texface->uv[1]); @@ -3470,9 +3447,9 @@ static void bm_corners_to_loops_ex(ID *id, } } - for (i = 0; i < numCol; i++) { - mloopcol = CustomData_get_n(ldata, CD_MLOOPCOL, loopstart, i); - mcol = CustomData_get_n(fdata, CD_MCOL, findex, i); + for (int i = 0; i < numCol; i++) { + MLoopCol *mloopcol = CustomData_get_n(ldata, CD_MLOOPCOL, loopstart, i); + MCol *mcol = CustomData_get_n(fdata, CD_MCOL, findex, i); MESH_MLOOPCOL_FROM_MCOL(mloopcol, &mcol[0]); mloopcol++; @@ -3491,7 +3468,7 @@ static void bm_corners_to_loops_ex(ID *id, short(*tlnors)[3] = CustomData_get(fdata, findex, CD_TESSLOOPNORMAL); const int max = mf->v4 ? 4 : 3; - for (i = 0; i < max; i++, lnors++, tlnors++) { + for (int i = 0; i < max; i++, lnors++, tlnors++) { normal_short_to_float_v3(*lnors, *tlnors); } } @@ -3521,7 +3498,7 @@ static void bm_corners_to_loops_ex(ID *id, const int side = (int)sqrtf((float)(fd->totdisp / corners)); const int side_sq = side * side; - for (i = 0; i < tot; i++, disps += side_sq, ld++) { + for (int i = 0; i < tot; i++, disps += side_sq, ld++) { ld->totdisp = side_sq; ld->level = (int)(logf((float)side - 1.0f) / (float)M_LN2) + 1; @@ -3879,15 +3856,11 @@ void BKE_mesh_flush_hidden_from_polys_ex(MVert *mvert, const MPoly *mpoly, const int totpoly) { - const MPoly *mp; - int i; - - i = totpoly; - for (mp = mpoly; i--; mp++) { + int i = totpoly; + for (const MPoly *mp = mpoly; i--; mp++) { if (mp->flag & ME_HIDE) { const MLoop *ml; - int j; - j = mp->totloop; + int j = mp->totloop; for (ml = &mloop[mp->loopstart]; j--; ml++) { mvert[ml->v].flag |= ME_HIDE; medge[ml->e].flag |= ME_HIDE; @@ -3896,11 +3869,10 @@ void BKE_mesh_flush_hidden_from_polys_ex(MVert *mvert, } i = totpoly; - for (mp = mpoly; i--; mp++) { + for (const MPoly *mp = mpoly; i--; mp++) { if ((mp->flag & ME_HIDE) == 0) { const MLoop *ml; - int j; - j = mp->totloop; + int j = mp->totloop; for (ml = &mloop[mp->loopstart]; j--; ml++) { mvert[ml->v].flag &= (char)~ME_HIDE; medge[ml->e].flag &= (short)~ME_HIDE; @@ -3928,9 +3900,8 @@ void BKE_mesh_flush_select_from_polys_ex(MVert *mvert, MVert *mv; MEdge *med; const MPoly *mp; - int i; - i = totvert; + int i = totvert; for (mv = mvert; i--; mv++) { mv->flag &= (char)~SELECT; } @@ -3971,10 +3942,9 @@ void BKE_mesh_flush_select_from_verts_ex(const MVert *mvert, { MEdge *med; MPoly *mp; - int i; /* edges */ - i = totedge; + int i = totedge; for (med = medge; i--; med++) { if ((med->flag & ME_HIDE) == 0) { if ((mvert[med->v1].flag & SELECT) && (mvert[med->v2].flag & SELECT)) { @@ -4052,9 +4022,8 @@ void BKE_mesh_calc_relative_deform(const MPoly *mpoly, for (i = 0, mp = mpoly; i < totpoly; i++, mp++) { const MLoop *loopstart = mloop + mp->loopstart; - int j; - for (j = 0; j < mp->totloop; j++) { + for (int j = 0; j < mp->totloop; j++) { unsigned int v_prev = loopstart[(mp->totloop + (j - 1)) % mp->totloop].v; unsigned int v_curr = loopstart[j].v; unsigned int v_next = loopstart[(j + 1) % mp->totloop].v; |