diff options
Diffstat (limited to 'source/blender/blenkernel/intern/customdata.c')
-rw-r--r-- | source/blender/blenkernel/intern/customdata.c | 393 |
1 files changed, 131 insertions, 262 deletions
diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c index e2adaabca33..b10d910cd66 100644 --- a/source/blender/blenkernel/intern/customdata.c +++ b/source/blender/blenkernel/intern/customdata.c @@ -199,9 +199,7 @@ static void layerCopy_mdeformvert(const void *source, void *dest, int count) static void layerFree_mdeformvert(void *data, int count, int size) { - int i; - - for (i = 0; i < count; i++) { + for (int i = 0; i < count; i++) { MDeformVert *dvert = POINTER_OFFSET(data, i * size); if (dvert->dw) { @@ -232,9 +230,7 @@ void bpy_bm_generic_invalidate(struct BPy_BMGeneric *UNUSED(self)) static void layerFree_bmesh_elem_py_ptr(void *data, int count, int size) { - int i; - - for (i = 0; i < count; i++) { + for (int i = 0; i < count; i++) { void **ptr = POINTER_OFFSET(data, i * size); if (*ptr) { bpy_bm_generic_invalidate(*ptr); @@ -416,9 +412,7 @@ static void layerCopy_tface(const void *source, void *dest, int count) { const MTFace *source_tf = (const MTFace *)source; MTFace *dest_tf = (MTFace *)dest; - int i; - - for (i = 0; i < count; i++) { + for (int i = 0; i < count; i++) { dest_tf[i] = source_tf[i]; } } @@ -475,9 +469,8 @@ static void layerDefault_tface(void *data, int count) { static MTFace default_tf = {{{0, 0}, {1, 0}, {1, 1}, {0, 1}}}; MTFace *tf = (MTFace *)data; - int i; - for (i = 0; i < count; i++) { + for (int i = 0; i < count; i++) { tf[i] = default_tf; } } @@ -523,9 +516,8 @@ static void layerCopy_origspace_face(const void *source, void *dest, int count) { const OrigSpaceFace *source_tf = (const OrigSpaceFace *)source; OrigSpaceFace *dest_tf = (OrigSpaceFace *)dest; - int i; - for (i = 0; i < count; i++) { + for (int i = 0; i < count; i++) { dest_tf[i] = source_tf[i]; } } @@ -579,9 +571,8 @@ static void layerDefault_origspace_face(void *data, int count) { static OrigSpaceFace default_osf = {{{0, 0}, {1, 0}, {1, 1}, {0, 1}}}; OrigSpaceFace *osf = (OrigSpaceFace *)data; - int i; - for (i = 0; i < count; i++) { + for (int i = 0; i < count; i++) { osf[i] = default_osf; } } @@ -620,11 +611,10 @@ static void layerSwap_mdisps(void *data, const int *ci) static void layerCopy_mdisps(const void *source, void *dest, int count) { - int i; const MDisps *s = source; MDisps *d = dest; - for (i = 0; i < count; i++) { + for (int i = 0; i < count; i++) { if (s[i].disps) { d[i].disps = MEM_dupallocN(s[i].disps); d[i].hidden = MEM_dupallocN(s[i].hidden); @@ -642,10 +632,9 @@ static void layerCopy_mdisps(const void *source, void *dest, int count) static void layerFree_mdisps(void *data, int count, int UNUSED(size)) { - int i; MDisps *d = data; - for (i = 0; i < count; i++) { + for (int i = 0; i < count; i++) { if (d[i].disps) { MEM_freeN(d[i].disps); } @@ -695,9 +684,8 @@ static size_t layerFilesize_mdisps(CDataFile *UNUSED(cdf), const void *data, int { const MDisps *d = data; size_t size = 0; - int i; - for (i = 0; i < count; i++) { + for (int i = 0; i < count; i++) { size += sizeof(float[3]) * d[i].totdisp; } @@ -724,11 +712,10 @@ static void layerInterp_paint_mask( static void layerCopy_grid_paint_mask(const void *source, void *dest, int count) { - int i; const GridPaintMask *s = source; GridPaintMask *d = dest; - for (i = 0; i < count; i++) { + for (int i = 0; i < count; i++) { if (s[i].data) { d[i].data = MEM_dupallocN(s[i].data); d[i].level = s[i].level; @@ -742,10 +729,9 @@ static void layerCopy_grid_paint_mask(const void *source, void *dest, int count) static void layerFree_grid_paint_mask(void *data, int count, int UNUSED(size)) { - int i; GridPaintMask *gpm = data; - for (i = 0; i < count; i++) { + for (int i = 0; i < count; i++) { if (gpm[i].data) { MEM_freeN(gpm[i].data); } @@ -895,8 +881,7 @@ static void layerDefault_mloopcol(void *data, int count) { MLoopCol default_mloopcol = {255, 255, 255, 255}; MLoopCol *mlcol = (MLoopCol *)data; - int i; - for (i = 0; i < count; i++) { + for (int i = 0; i < count; i++) { mlcol[i] = default_mloopcol; } } @@ -1007,13 +992,12 @@ static void layerInterp_mloopuv( { float uv[2]; int flag = 0; - int i; zero_v2(uv); if (sub_weights) { const float *sub_weight = sub_weights; - for (i = 0; i < count; i++) { + for (int i = 0; i < count; i++) { float weight = (weights ? weights[i] : 1.0f) * (*sub_weight); const MLoopUV *src = sources[i]; madd_v2_v2fl(uv, src->uv, weight); @@ -1024,7 +1008,7 @@ static void layerInterp_mloopuv( } } else { - for (i = 0; i < count; i++) { + for (int i = 0; i < count; i++) { float weight = weights ? weights[i] : 1; const MLoopUV *src = sources[i]; madd_v2_v2fl(uv, src->uv, weight); @@ -1109,13 +1093,11 @@ static void layerInterp_mloop_origspace( const void **sources, const float *weights, const float *sub_weights, int count, void *dest) { float uv[2]; - int i; - zero_v2(uv); if (sub_weights) { const float *sub_weight = sub_weights; - for (i = 0; i < count; i++) { + for (int i = 0; i < count; i++) { float weight = weights ? weights[i] : 1.0f; const OrigSpaceLoop *src = sources[i]; madd_v2_v2fl(uv, src->uv, (*sub_weight) * weight); @@ -1123,7 +1105,7 @@ static void layerInterp_mloop_origspace( } } else { - for (i = 0; i < count; i++) { + for (int i = 0; i < count; i++) { float weight = weights ? weights[i] : 1.0f; const OrigSpaceLoop *src = sources[i]; madd_v2_v2fl(uv, src->uv, weight); @@ -1139,7 +1121,6 @@ static void layerInterp_mcol( const void **sources, const float *weights, const float *sub_weights, int count, void *dest) { MCol *mc = dest; - int i, j, k; struct { float a; float r; @@ -1147,20 +1128,18 @@ static void layerInterp_mcol( float b; } col[4] = {{0.0f}}; - const float *sub_weight; - if (count <= 0) { return; } - sub_weight = sub_weights; - for (i = 0; i < count; i++) { + const float *sub_weight = sub_weights; + for (int i = 0; i < count; i++) { float weight = weights ? weights[i] : 1; - for (j = 0; j < 4; j++) { + for (int j = 0; j < 4; j++) { if (sub_weights) { const MCol *src = sources[i]; - for (k = 0; k < 4; k++, sub_weight++, src++) { + for (int k = 0; k < 4; k++, sub_weight++, src++) { const float w = (*sub_weight) * weight; col[j].a += src->a * w; col[j].r += src->r * w; @@ -1179,7 +1158,7 @@ static void layerInterp_mcol( } /* Delay writing to the destination in case dest is in sources. */ - for (j = 0; j < 4; j++) { + for (int j = 0; j < 4; j++) { /* Subdivide smooth or fractal can cause problems without clamping * although weights should also not cause this situation */ @@ -1207,9 +1186,8 @@ static void layerDefault_mcol(void *data, int count) { static MCol default_mcol = {255, 255, 255, 255}; MCol *mcol = (MCol *)data; - int i; - for (i = 0; i < 4 * count; i++) { + for (int i = 0; i < 4 * count; i++) { mcol[i] = default_mcol; } } @@ -1225,23 +1203,21 @@ static void layerInterp_bweight(const void **sources, int count, void *dest) { - float f; float **in = (float **)sources; - int i; if (count <= 0) { return; } - f = 0.0f; + float f = 0.0f; if (weights) { - for (i = 0; i < count; i++) { + for (int i = 0; i < count; i++) { f += *in[i] * weights[i]; } } else { - for (i = 0; i < count; i++) { + for (int i = 0; i < count; i++) { f += *in[i]; } } @@ -1256,23 +1232,22 @@ static void layerInterp_shapekey(const void **sources, int count, void *dest) { - float co[3]; float **in = (float **)sources; - int i; if (count <= 0) { return; } + float co[3]; zero_v3(co); if (weights) { - for (i = 0; i < count; i++) { + for (int i = 0; i < count; i++) { madd_v3_v3fl(co, in[i], weights[i]); } } else { - for (i = 0; i < count; i++) { + for (int i = 0; i < count; i++) { add_v3_v3(co, in[i]); } } @@ -1284,9 +1259,8 @@ static void layerInterp_shapekey(const void **sources, static void layerDefault_mvert_skin(void *data, int count) { MVertSkin *vs = data; - int i; - for (i = 0; i < count; i++) { + for (int i = 0; i < count; i++) { copy_v3_fl(vs[i].radius, 0.25f); vs[i].flag = 0; } @@ -1304,13 +1278,13 @@ static void layerInterp_mvert_skin(const void **sources, void *dest) { MVertSkin *vs_dst = dest; - float radius[3], w; - int i; + float radius[3]; zero_v3(radius); - for (i = 0; i < count; i++) { + + for (int i = 0; i < count; i++) { const MVertSkin *vs_src = sources[i]; - w = weights ? weights[i] : 1.0f; + float w = weights ? weights[i] : 1.0f; madd_v3_v3fl(radius, vs_src->radius, w); } @@ -1437,8 +1411,7 @@ static void layerDefault_propcol(void *data, int count) /* Default to white, full alpha. */ MPropCol default_propcol = {{1.0f, 1.0f, 1.0f, 1.0f}}; MPropCol *pcol = (MPropCol *)data; - int i; - for (i = 0; i < count; i++) { + for (int i = 0; i < count; i++) { copy_v4_v4(pcol[i].color, default_propcol.color); } } @@ -2093,38 +2066,36 @@ static const char *layerType_getName(int type) void customData_mask_layers__print(const CustomData_MeshMasks *mask) { - int i; - printf("verts mask=0x%lx:\n", (long unsigned int)mask->vmask); - for (i = 0; i < CD_NUMTYPES; i++) { + for (int i = 0; i < CD_NUMTYPES; i++) { if (mask->vmask & CD_TYPE_AS_MASK(i)) { printf(" %s\n", layerType_getName(i)); } } printf("edges mask=0x%lx:\n", (long unsigned int)mask->emask); - for (i = 0; i < CD_NUMTYPES; i++) { + for (int i = 0; i < CD_NUMTYPES; i++) { if (mask->emask & CD_TYPE_AS_MASK(i)) { printf(" %s\n", layerType_getName(i)); } } printf("faces mask=0x%lx:\n", (long unsigned int)mask->fmask); - for (i = 0; i < CD_NUMTYPES; i++) { + for (int i = 0; i < CD_NUMTYPES; i++) { if (mask->fmask & CD_TYPE_AS_MASK(i)) { printf(" %s\n", layerType_getName(i)); } } printf("loops mask=0x%lx:\n", (long unsigned int)mask->lmask); - for (i = 0; i < CD_NUMTYPES; i++) { + for (int i = 0; i < CD_NUMTYPES; i++) { if (mask->lmask & CD_TYPE_AS_MASK(i)) { printf(" %s\n", layerType_getName(i)); } } printf("polys mask=0x%lx:\n", (long unsigned int)mask->pmask); - for (i = 0; i < CD_NUMTYPES; i++) { + for (int i = 0; i < CD_NUMTYPES; i++) { if (mask->pmask & CD_TYPE_AS_MASK(i)) { printf(" %s\n", layerType_getName(i)); } @@ -2253,8 +2224,7 @@ bool CustomData_merge(const struct CustomData *source, /* NOTE: Take care of referenced layers by yourself! */ void CustomData_realloc(CustomData *data, int totelem) { - int i; - for (i = 0; i < data->totlayer; i++) { + for (int i = 0; i < data->totlayer; i++) { CustomDataLayer *layer = &data->layers[i]; const LayerTypeInfo *typeInfo; if (layer->flag & CD_FLAG_NOFREE) { @@ -2313,9 +2283,7 @@ void CustomData_reset(CustomData *data) void CustomData_free(CustomData *data, int totelem) { - int i; - - for (i = 0; i < data->totlayer; i++) { + for (int i = 0; i < data->totlayer; i++) { customData_free_layer__internal(&data->layers[i], totelem); } @@ -2329,9 +2297,7 @@ void CustomData_free(CustomData *data, int totelem) void CustomData_free_typemask(struct CustomData *data, int totelem, CustomDataMask mask) { - int i; - - for (i = 0; i < data->totlayer; i++) { + for (int i = 0; i < data->totlayer; i++) { CustomDataLayer *layer = &data->layers[i]; if (!(mask & CD_TYPE_AS_MASK(layer->type))) { continue; @@ -2350,9 +2316,9 @@ void CustomData_free_typemask(struct CustomData *data, int totelem, CustomDataMa static void customData_update_offsets(CustomData *data) { const LayerTypeInfo *typeInfo; - int i, offset = 0; + int offset = 0; - for (i = 0; i < data->totlayer; i++) { + for (int i = 0; i < data->totlayer; i++) { typeInfo = layerType_getInfo(data->layers[i].type); data->layers[i].offset = offset; @@ -2366,9 +2332,7 @@ static void customData_update_offsets(CustomData *data) /* to use when we're in the middle of modifying layers */ static int CustomData_get_layer_index__notypemap(const CustomData *data, int type) { - int i; - - for (i = 0; i < data->totlayer; i++) { + for (int i = 0; i < data->totlayer; i++) { if (data->layers[i].type == type) { return i; } @@ -2400,9 +2364,7 @@ int CustomData_get_layer_index_n(const struct CustomData *data, int type, int n) int CustomData_get_named_layer_index(const CustomData *data, int type, const char *name) { - int i; - - for (i = 0; i < data->totlayer; i++) { + for (int i = 0; i < data->totlayer; i++) { if (data->layers[i].type == type) { if (STREQ(data->layers[i].name, name)) { return i; @@ -2482,9 +2444,7 @@ int CustomData_get_stencil_layer(const CustomData *data, int type) void CustomData_set_layer_active(CustomData *data, int type, int n) { - int i; - - for (i = 0; i < data->totlayer; i++) { + for (int i = 0; i < data->totlayer; i++) { if (data->layers[i].type == type) { data->layers[i].active = n; } @@ -2493,9 +2453,7 @@ void CustomData_set_layer_active(CustomData *data, int type, int n) void CustomData_set_layer_render(CustomData *data, int type, int n) { - int i; - - for (i = 0; i < data->totlayer; i++) { + for (int i = 0; i < data->totlayer; i++) { if (data->layers[i].type == type) { data->layers[i].active_rnd = n; } @@ -2504,9 +2462,7 @@ void CustomData_set_layer_render(CustomData *data, int type, int n) void CustomData_set_layer_clone(CustomData *data, int type, int n) { - int i; - - for (i = 0; i < data->totlayer; i++) { + for (int i = 0; i < data->totlayer; i++) { if (data->layers[i].type == type) { data->layers[i].active_clone = n; } @@ -2515,9 +2471,7 @@ void CustomData_set_layer_clone(CustomData *data, int type, int n) void CustomData_set_layer_stencil(CustomData *data, int type, int n) { - int i; - - for (i = 0; i < data->totlayer; i++) { + for (int i = 0; i < data->totlayer; i++) { if (data->layers[i].type == type) { data->layers[i].active_mask = n; } @@ -2528,9 +2482,7 @@ void CustomData_set_layer_stencil(CustomData *data, int type, int n) * CustomData_get_render_layer_index. */ void CustomData_set_layer_active_index(CustomData *data, int type, int n) { - int i; - - for (i = 0; i < data->totlayer; i++) { + for (int i = 0; i < data->totlayer; i++) { if (data->layers[i].type == type) { data->layers[i].active = n - i; } @@ -2539,9 +2491,7 @@ void CustomData_set_layer_active_index(CustomData *data, int type, int n) void CustomData_set_layer_render_index(CustomData *data, int type, int n) { - int i; - - for (i = 0; i < data->totlayer; i++) { + for (int i = 0; i < data->totlayer; i++) { if (data->layers[i].type == type) { data->layers[i].active_rnd = n - i; } @@ -2550,9 +2500,7 @@ void CustomData_set_layer_render_index(CustomData *data, int type, int n) void CustomData_set_layer_clone_index(CustomData *data, int type, int n) { - int i; - - for (i = 0; i < data->totlayer; i++) { + for (int i = 0; i < data->totlayer; i++) { if (data->layers[i].type == type) { data->layers[i].active_clone = n - i; } @@ -2561,9 +2509,7 @@ void CustomData_set_layer_clone_index(CustomData *data, int type, int n) void CustomData_set_layer_stencil_index(CustomData *data, int type, int n) { - int i; - - for (i = 0; i < data->totlayer; i++) { + for (int i = 0; i < data->totlayer; i++) { if (data->layers[i].type == type) { data->layers[i].active_mask = n - i; } @@ -2572,9 +2518,7 @@ void CustomData_set_layer_stencil_index(CustomData *data, int type, int n) void CustomData_set_layer_flag(struct CustomData *data, int type, int flag) { - int i; - - for (i = 0; i < data->totlayer; i++) { + for (int i = 0; i < data->totlayer; i++) { if (data->layers[i].type == type) { data->layers[i].flag |= flag; } @@ -2759,7 +2703,6 @@ bool CustomData_free_layer(CustomData *data, int type, int totelem, int index) { const int index_first = CustomData_get_layer_index(data, type); const int n = index - index_first; - int i; BLI_assert(index >= index_first); if ((index_first == -1) || (n < 0)) { @@ -2769,14 +2712,14 @@ bool CustomData_free_layer(CustomData *data, int type, int totelem, int index) customData_free_layer__internal(&data->layers[index], totelem); - for (i = index + 1; i < data->totlayer; i++) { + for (int i = index + 1; i < data->totlayer; i++) { data->layers[i - 1] = data->layers[i]; } data->totlayer--; /* if layer was last of type in array, set new active layer */ - i = CustomData_get_layer_index__notypemap(data, type); + int i = CustomData_get_layer_index__notypemap(data, type); if (i != -1) { /* don't decrement zero index */ @@ -2810,8 +2753,7 @@ bool CustomData_free_layer(CustomData *data, int type, int totelem, int index) bool CustomData_free_layer_active(CustomData *data, int type, int totelem) { - int index = 0; - index = CustomData_get_active_layer_index(data, type); + const int index = CustomData_get_active_layer_index(data, type); if (index == -1) { return false; } @@ -2833,9 +2775,9 @@ bool CustomData_has_layer(const CustomData *data, int type) int CustomData_number_of_layers(const CustomData *data, int type) { - int i, number = 0; + int number = 0; - for (i = 0; i < data->totlayer; i++) { + for (int i = 0; i < data->totlayer; i++) { if (data->layers[i].type == type) { number++; } @@ -2846,9 +2788,9 @@ int CustomData_number_of_layers(const CustomData *data, int type) int CustomData_number_of_layers_typemask(const CustomData *data, CustomDataMask mask) { - int i, number = 0; + int number = 0; - for (i = 0; i < data->totlayer; i++) { + for (int i = 0; i < data->totlayer; i++) { if (mask & CD_TYPE_AS_MASK(data->layers[i].type)) { number++; } @@ -2861,13 +2803,11 @@ static void *customData_duplicate_referenced_layer_index(CustomData *data, const int layer_index, const int totelem) { - CustomDataLayer *layer; - if (layer_index == -1) { return NULL; } - layer = &data->layers[layer_index]; + CustomDataLayer *layer = &data->layers[layer_index]; if (layer->flag & CD_FLAG_NOFREE) { /* MEM_dupallocN won't work in case of complex layers, like e.g. @@ -2894,10 +2834,8 @@ static void *customData_duplicate_referenced_layer_index(CustomData *data, void *CustomData_duplicate_referenced_layer(CustomData *data, const int type, const int totelem) { - int layer_index; - /* get the layer index of the first layer of type */ - layer_index = CustomData_get_active_layer_index(data, type); + int layer_index = CustomData_get_active_layer_index(data, type); return customData_duplicate_referenced_layer_index(data, layer_index, totelem); } @@ -2907,10 +2845,8 @@ void *CustomData_duplicate_referenced_layer_n(CustomData *data, const int n, const int totelem) { - int layer_index; - /* get the layer index of the desired layer */ - layer_index = CustomData_get_layer_index_n(data, type, n); + int layer_index = CustomData_get_layer_index_n(data, type, n); return customData_duplicate_referenced_layer_index(data, layer_index, totelem); } @@ -2920,26 +2856,21 @@ void *CustomData_duplicate_referenced_layer_named(CustomData *data, const char *name, const int totelem) { - int layer_index; - /* get the layer index of the desired layer */ - layer_index = CustomData_get_named_layer_index(data, type, name); + int layer_index = CustomData_get_named_layer_index(data, type, name); return customData_duplicate_referenced_layer_index(data, layer_index, totelem); } bool CustomData_is_referenced_layer(struct CustomData *data, int type) { - CustomDataLayer *layer; - int layer_index; - /* get the layer index of the first layer of type */ - layer_index = CustomData_get_active_layer_index(data, type); + int layer_index = CustomData_get_active_layer_index(data, type); if (layer_index == -1) { return false; } - layer = &data->layers[layer_index]; + CustomDataLayer *layer = &data->layers[layer_index]; return (layer->flag & CD_FLAG_NOFREE) != 0; } @@ -2980,9 +2911,7 @@ void CustomData_free_temporary(CustomData *data, int totelem) void CustomData_set_only_copy(const struct CustomData *data, CustomDataMask mask) { - int i; - - for (i = 0; i < data->totlayer; i++) { + for (int i = 0; i < data->totlayer; i++) { if (!(mask & CD_TYPE_AS_MASK(data->layers[i].type))) { data->layers[i].flag |= CD_FLAG_NOCOPY; } @@ -3044,12 +2973,10 @@ static void CustomData_copy_data_layer(const CustomData *source, void CustomData_copy_data_named( const CustomData *source, CustomData *dest, int source_index, int dest_index, int count) { - int src_i, dest_i; - /* copies a layer at a time */ - for (src_i = 0; src_i < source->totlayer; src_i++) { + for (int src_i = 0; src_i < source->totlayer; src_i++) { - dest_i = CustomData_get_named_layer_index( + int dest_i = CustomData_get_named_layer_index( dest, source->layers[src_i].type, source->layers[src_i].name); /* if we found a matching layer, copy the data */ @@ -3062,11 +2989,9 @@ void CustomData_copy_data_named( void CustomData_copy_data( const CustomData *source, CustomData *dest, int source_index, int dest_index, int count) { - int src_i, dest_i; - /* copies a layer at a time */ - dest_i = 0; - for (src_i = 0; src_i < source->totlayer; src_i++) { + int dest_i = 0; + for (int src_i = 0; src_i < source->totlayer; src_i++) { /* find the first dest layer with type >= the source type * (this should work because layers are ordered by type) @@ -3119,12 +3044,9 @@ void CustomData_copy_layer_type_data(const CustomData *source, void CustomData_free_elem(CustomData *data, int index, int count) { - int i; - const LayerTypeInfo *typeInfo; - - for (i = 0; i < data->totlayer; i++) { + for (int i = 0; i < data->totlayer; i++) { if (!(data->layers[i].flag & CD_FLAG_NOFREE)) { - typeInfo = layerType_getInfo(data->layers[i].type); + const LayerTypeInfo *typeInfo = layerType_getInfo(data->layers[i].type); if (typeInfo->free) { size_t offset = (size_t)index * typeInfo->size; @@ -3145,8 +3067,6 @@ void CustomData_interp(const CustomData *source, int count, int dest_index) { - int src_i, dest_i; - int j; const void *source_buf[SOURCE_BUF_SIZE]; const void **sources = source_buf; @@ -3156,8 +3076,8 @@ void CustomData_interp(const CustomData *source, } /* interpolates a layer at a time */ - dest_i = 0; - for (src_i = 0; src_i < source->totlayer; src_i++) { + int dest_i = 0; + for (int src_i = 0; src_i < source->totlayer; src_i++) { const LayerTypeInfo *typeInfo = layerType_getInfo(source->layers[src_i].type); if (!typeInfo->interp) { continue; @@ -3179,7 +3099,7 @@ void CustomData_interp(const CustomData *source, if (dest->layers[dest_i].type == source->layers[src_i].type) { void *src_data = source->layers[src_i].data; - for (j = 0; j < count; j++) { + for (int j = 0; j < count; j++) { sources[j] = POINTER_OFFSET(src_data, (size_t)src_indices[j] * typeInfo->size); } @@ -3212,11 +3132,8 @@ void CustomData_interp(const CustomData *source, */ void CustomData_swap_corners(struct CustomData *data, int index, const int *corner_indices) { - const LayerTypeInfo *typeInfo; - int i; - - for (i = 0; i < data->totlayer; i++) { - typeInfo = layerType_getInfo(data->layers[i].type); + for (int i = 0; i < data->totlayer; i++) { + const LayerTypeInfo *typeInfo = layerType_getInfo(data->layers[i].type); if (typeInfo->swap) { const size_t offset = (size_t)index * typeInfo->size; @@ -3231,14 +3148,13 @@ void CustomData_swap_corners(struct CustomData *data, int index, const int *corn */ void CustomData_swap(struct CustomData *data, const int index_a, const int index_b) { - int i; char buff_static[256]; if (index_a == index_b) { return; } - for (i = 0; i < data->totlayer; i++) { + for (int i = 0; i < data->totlayer; i++) { const LayerTypeInfo *typeInfo = layerType_getInfo(data->layers[i].type); const size_t size = typeInfo->size; const size_t offset_a = size * index_a; @@ -3259,12 +3175,10 @@ void CustomData_swap(struct CustomData *data, const int index_a, const int index void *CustomData_get(const CustomData *data, int index, int type) { - int layer_index; - BLI_assert(index >= 0); /* get the layer index of the active layer of type */ - layer_index = CustomData_get_active_layer_index(data, type); + int layer_index = CustomData_get_active_layer_index(data, type); if (layer_index == -1) { return NULL; } @@ -3277,12 +3191,10 @@ void *CustomData_get(const CustomData *data, int index, int type) void *CustomData_get_n(const CustomData *data, int type, int index, int n) { - int layer_index; - BLI_assert(index >= 0 && n >= 0); /* get the layer index of the first layer of type */ - layer_index = data->typemap[type]; + int layer_index = data->typemap[type]; if (layer_index == -1) { return NULL; } @@ -3436,12 +3348,10 @@ void CustomData_to_bmeshpoly(CustomData *fdata, CustomData *ldata, int totloop) void CustomData_from_bmeshpoly(CustomData *fdata, CustomData *ldata, int total) { - int i; - /* avoid accumulating extra layers */ BLI_assert(!CustomData_from_bmeshpoly_test(fdata, ldata, false)); - for (i = 0; i < ldata->totlayer; i++) { + for (int i = 0; i < ldata->totlayer; i++) { if (ldata->layers[i].type == CD_MLOOPUV) { CustomData_add_layer_named(fdata, CD_MTFACE, CD_CALLOC, NULL, total, ldata->layers[i].name); } @@ -3619,12 +3529,6 @@ bool CustomData_bmesh_merge(const CustomData *source, BMesh *bm, const char htype) { - BMHeader *h; - BMIter iter; - CustomData destold; - void *tmp; - int iter_type; - int totelem; if (CustomData_number_of_layers_typemask(source, mask) == 0) { return false; @@ -3632,7 +3536,7 @@ bool CustomData_bmesh_merge(const CustomData *source, /* copy old layer description so that old data can be copied into * the new allocation */ - destold = *dest; + CustomData destold = *dest; if (destold.layers) { destold.layers = MEM_dupallocN(destold.layers); } @@ -3644,6 +3548,8 @@ bool CustomData_bmesh_merge(const CustomData *source, return false; } + int iter_type; + int totelem; switch (htype) { case BM_VERT: iter_type = BM_VERTS_OF_MESH; @@ -3672,9 +3578,11 @@ bool CustomData_bmesh_merge(const CustomData *source, CustomData_bmesh_init_pool(dest, totelem, htype); if (iter_type != BM_LOOPS_OF_FACE) { + BMHeader *h; + BMIter iter; /*ensure all current elements follow new customdata layout*/ BM_ITER_MESH (h, &iter, bm, iter_type) { - tmp = NULL; + void *tmp = NULL; CustomData_bmesh_copy_data(&destold, dest, h->data, &tmp); CustomData_bmesh_free_block(&destold, &h->data); h->data = tmp; @@ -3683,12 +3591,13 @@ bool CustomData_bmesh_merge(const CustomData *source, else { BMFace *f; BMLoop *l; + BMIter iter; BMIter liter; /*ensure all current elements follow new customdata layout*/ BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) { BM_ITER_ELEM (l, &liter, f, BM_LOOPS_OF_FACE) { - tmp = NULL; + void *tmp = NULL; CustomData_bmesh_copy_data(&destold, dest, l->head.data, &tmp); CustomData_bmesh_free_block(&destold, &l->head.data); l->head.data = tmp; @@ -3707,16 +3616,13 @@ bool CustomData_bmesh_merge(const CustomData *source, void CustomData_bmesh_free_block(CustomData *data, void **block) { - const LayerTypeInfo *typeInfo; - int i; - if (*block == NULL) { return; } - for (i = 0; i < data->totlayer; i++) { + for (int i = 0; i < data->totlayer; i++) { if (!(data->layers[i].flag & CD_FLAG_NOFREE)) { - typeInfo = layerType_getInfo(data->layers[i].type); + const LayerTypeInfo *typeInfo = layerType_getInfo(data->layers[i].type); if (typeInfo->free) { int offset = data->layers[i].offset; @@ -3756,7 +3662,6 @@ void CustomData_bmesh_free_block_data(CustomData *data, void *block) static void CustomData_bmesh_alloc_block(CustomData *data, void **block) { - if (*block) { CustomData_bmesh_free_block(data, block); } @@ -3810,13 +3715,11 @@ static void CustomData_bmesh_set_default_n(CustomData *data, void **block, int n void CustomData_bmesh_set_default(CustomData *data, void **block) { - int i; - if (*block == NULL) { CustomData_bmesh_alloc_block(data, block); } - for (i = 0; i < data->totlayer; i++) { + for (int i = 0; i < data->totlayer; i++) { CustomData_bmesh_set_default_n(data, block, i); } } @@ -3830,7 +3733,6 @@ void CustomData_bmesh_copy_data_exclude_by_type(const CustomData *source, /* Note that having a version of this function without a 'mask_exclude' * would cause too much duplicate code, so add a check instead. */ const bool no_mask = (mask_exclude == 0); - int dest_i, src_i; if (*dest_block == NULL) { CustomData_bmesh_alloc_block(dest, dest_block); @@ -3840,8 +3742,8 @@ void CustomData_bmesh_copy_data_exclude_by_type(const CustomData *source, } /* copies a layer at a time */ - dest_i = 0; - for (src_i = 0; src_i < source->totlayer; src_i++) { + int dest_i = 0; + for (int src_i = 0; src_i < source->totlayer; src_i++) { /* find the first dest layer with type >= the source type * (this should work because layers are ordered by type) @@ -3898,10 +3800,8 @@ void CustomData_bmesh_copy_data(const CustomData *source, */ void *CustomData_bmesh_get(const CustomData *data, void *block, int type) { - int layer_index; - /* get the layer index of the first layer of type */ - layer_index = CustomData_get_active_layer_index(data, type); + int layer_index = CustomData_get_active_layer_index(data, type); if (layer_index == -1) { return NULL; } @@ -3911,10 +3811,8 @@ void *CustomData_bmesh_get(const CustomData *data, void *block, int type) void *CustomData_bmesh_get_n(const CustomData *data, void *block, int type, int n) { - int layer_index; - /* get the layer index of the first layer of type */ - layer_index = CustomData_get_layer_index(data, type); + int layer_index = CustomData_get_layer_index(data, type); if (layer_index == -1) { return NULL; } @@ -3957,10 +3855,8 @@ bool CustomData_layer_has_interp(const struct CustomData *data, int layer_n) bool CustomData_has_math(const struct CustomData *data) { - int i; - /* interpolates a layer at a time */ - for (i = 0; i < data->totlayer; i++) { + for (int i = 0; i < data->totlayer; i++) { if (CustomData_layer_has_math(data, i)) { return true; } @@ -3972,12 +3868,9 @@ bool CustomData_has_math(const struct CustomData *data) /* a non bmesh version would have to check layer->data */ bool CustomData_bmesh_has_free(const struct CustomData *data) { - const LayerTypeInfo *typeInfo; - int i; - - for (i = 0; i < data->totlayer; i++) { + for (int i = 0; i < data->totlayer; i++) { if (!(data->layers[i].flag & CD_FLAG_NOFREE)) { - typeInfo = layerType_getInfo(data->layers[i].type); + const LayerTypeInfo *typeInfo = layerType_getInfo(data->layers[i].type); if (typeInfo->free) { return true; } @@ -3988,10 +3881,8 @@ bool CustomData_bmesh_has_free(const struct CustomData *data) bool CustomData_has_interp(const struct CustomData *data) { - int i; - /* interpolates a layer at a time */ - for (i = 0; i < data->totlayer; i++) { + for (int i = 0; i < data->totlayer; i++) { if (CustomData_layer_has_interp(data, i)) { return true; } @@ -4002,8 +3893,7 @@ bool CustomData_has_interp(const struct CustomData *data) bool CustomData_has_referenced(const struct CustomData *data) { - int i; - for (i = 0; i < data->totlayer; i++) { + for (int i = 0; i < data->totlayer; i++) { if (data->layers[i].flag & CD_FLAG_NOFREE) { return true; } @@ -4210,16 +4100,13 @@ void CustomData_to_bmesh_block(const CustomData *source, void **dest_block, bool use_default_init) { - const LayerTypeInfo *typeInfo; - int dest_i, src_i; - if (*dest_block == NULL) { CustomData_bmesh_alloc_block(dest, dest_block); } /* copies a layer at a time */ - dest_i = 0; - for (src_i = 0; src_i < source->totlayer; src_i++) { + int dest_i = 0; + for (int src_i = 0; src_i < source->totlayer; src_i++) { /* find the first dest layer with type >= the source type * (this should work because layers are ordered by type) @@ -4242,7 +4129,7 @@ void CustomData_to_bmesh_block(const CustomData *source, const void *src_data = source->layers[src_i].data; void *dest_data = POINTER_OFFSET(*dest_block, offset); - typeInfo = layerType_getInfo(dest->layers[dest_i].type); + const LayerTypeInfo *typeInfo = layerType_getInfo(dest->layers[dest_i].type); const size_t src_offset = (size_t)src_index * typeInfo->size; if (typeInfo->copy) { @@ -4273,11 +4160,9 @@ void CustomData_from_bmesh_block(const CustomData *source, void *src_block, int dest_index) { - int dest_i, src_i; - /* copies a layer at a time */ - dest_i = 0; - for (src_i = 0; src_i < source->totlayer; src_i++) { + int dest_i = 0; + for (int src_i = 0; src_i < source->totlayer; src_i++) { /* find the first dest layer with type >= the source type * (this should work because layers are ordered by type) @@ -4431,9 +4316,8 @@ static bool CustomData_is_property_layer(int type) static bool cd_layer_find_dupe(CustomData *data, const char *name, int type, int index) { - int i; /* see if there is a duplicate */ - for (i = 0; i < data->totlayer; i++) { + for (int i = 0; i < data->totlayer; i++) { if (i != index) { CustomDataLayer *layer = &data->layers[i]; @@ -4520,7 +4404,6 @@ bool CustomData_verify_versions(struct CustomData *data, int index) const LayerTypeInfo *typeInfo; CustomDataLayer *layer = &data->layers[index]; bool keeplayer = true; - int i; if (layer->type >= CD_NUMTYPES) { keeplayer = false; /* unknown layer type from future version */ @@ -4548,7 +4431,7 @@ bool CustomData_verify_versions(struct CustomData *data, int index) } if (!keeplayer) { - for (i = index + 1; i < data->totlayer; i++) { + for (int i = index + 1; i < data->totlayer; i++) { data->layers[i - 1] = data->layers[i]; } data->totlayer--; @@ -4576,13 +4459,12 @@ bool CustomData_layer_validate(CustomDataLayer *layer, const uint totitems, cons void CustomData_layers__print(CustomData *data) { - int i; - const CustomDataLayer *layer; printf("{\n"); + int i; + const CustomDataLayer *layer; for (i = 0, layer = data->layers; i < data->totlayer; i++, layer++) { - const char *name = CustomData_layertype_name(layer->type); const int size = CustomData_sizeof(layer->type); const char *structname; @@ -4612,13 +4494,9 @@ static void customdata_external_filename(char filename[FILE_MAX], void CustomData_external_reload(CustomData *data, ID *UNUSED(id), CustomDataMask mask, int totelem) { - CustomDataLayer *layer; - const LayerTypeInfo *typeInfo; - int i; - - for (i = 0; i < data->totlayer; i++) { - layer = &data->layers[i]; - typeInfo = layerType_getInfo(layer->type); + for (int i = 0; i < data->totlayer; i++) { + CustomDataLayer *layer = &data->layers[i]; + const LayerTypeInfo *typeInfo = layerType_getInfo(layer->type); if (!(mask & CD_TYPE_AS_MASK(layer->type))) { /* pass */ @@ -4640,13 +4518,13 @@ void CustomData_external_read(CustomData *data, ID *id, CustomDataMask mask, int CDataFileLayer *blay; char filename[FILE_MAX]; const LayerTypeInfo *typeInfo; - int i, update = 0; + int update = 0; if (!external) { return; } - for (i = 0; i < data->totlayer; i++) { + for (int i = 0; i < data->totlayer; i++) { layer = &data->layers[i]; typeInfo = layerType_getInfo(layer->type); @@ -4674,7 +4552,7 @@ void CustomData_external_read(CustomData *data, ID *id, CustomDataMask mask, int return; } - for (i = 0; i < data->totlayer; i++) { + for (int i = 0; i < data->totlayer; i++) { layer = &data->layers[i]; typeInfo = layerType_getInfo(layer->type); @@ -4716,7 +4594,7 @@ void CustomData_external_write( CDataFile *cdf; CDataFileLayer *blay; const LayerTypeInfo *typeInfo; - int i, update = 0; + int update = 0; char filename[FILE_MAX]; if (!external) { @@ -4724,7 +4602,7 @@ void CustomData_external_write( } /* test if there is anything to write */ - for (i = 0; i < data->totlayer; i++) { + for (int i = 0; i < data->totlayer; i++) { layer = &data->layers[i]; typeInfo = layerType_getInfo(layer->type); @@ -4746,7 +4624,7 @@ void CustomData_external_write( cdf = cdf_create(CDF_TYPE_MESH); - for (i = 0; i < data->totlayer; i++) { + for (int i = 0; i < data->totlayer; i++) { layer = &data->layers[i]; typeInfo = layerType_getInfo(layer->type); @@ -4768,6 +4646,7 @@ void CustomData_external_write( return; } + int i; for (i = 0; i < data->totlayer; i++) { layer = &data->layers[i]; typeInfo = layerType_getInfo(layer->type); @@ -4844,16 +4723,13 @@ void CustomData_external_add( void CustomData_external_remove(CustomData *data, ID *id, int type, int totelem) { CustomDataExternal *external = data->external; - CustomDataLayer *layer; - // char filename[FILE_MAX]; - int layer_index; // i, remove_file; - layer_index = CustomData_get_active_layer_index(data, type); + int layer_index = CustomData_get_active_layer_index(data, type); if (layer_index == -1) { return; } - layer = &data->layers[layer_index]; + CustomDataLayer *layer = &data->layers[layer_index]; if (!external) { return; @@ -4870,15 +4746,12 @@ void CustomData_external_remove(CustomData *data, ID *id, int type, int totelem) bool CustomData_external_test(CustomData *data, int type) { - CustomDataLayer *layer; - int layer_index; - - layer_index = CustomData_get_active_layer_index(data, type); + int layer_index = CustomData_get_active_layer_index(data, type); if (layer_index == -1) { return false; } - layer = &data->layers[layer_index]; + CustomDataLayer *layer = &data->layers[layer_index]; return (layer->flag & CD_FLAG_EXTERNAL) != 0; } @@ -4974,15 +4847,13 @@ static void customdata_data_transfer_interp_generic(const CustomDataTransferLaye tmp_dst = MEM_mallocN(data_size, __func__); if (count > 1 && !interp_cd) { - int i; - if (data_flag) { /* Boolean case, we can 'interpolate' in two groups, * and choose value from highest weighted group. */ float tot_weight_true = 0.0f; int item_true_idx = -1, item_false_idx = -1; - for (i = 0; i < count; i++) { + for (int i = 0; i < count; i++) { if (check_bit_flag(sources[i], data_size, data_flag)) { tot_weight_true += weights[i]; item_true_idx = i; @@ -4997,7 +4868,7 @@ static void customdata_data_transfer_interp_generic(const CustomDataTransferLaye /* We just choose highest weighted source. */ float max_weight = 0.0f; - for (i = 0; i < count; i++) { + for (int i = 0; i < count; i++) { if (weights[i] > max_weight) { max_weight = weights[i]; best_src_idx = i; @@ -5086,7 +4957,6 @@ void CustomData_data_transfer(const MeshPairRemap *me_remap, { MeshPairRemapItem *mapit = me_remap->items; const int totelem = me_remap->items_num; - int i; const int data_type = laymap->data_type; const void *data_src = laymap->data_src; @@ -5126,11 +4996,10 @@ void CustomData_data_transfer(const MeshPairRemap *me_remap, interp = laymap->interp ? laymap->interp : customdata_data_transfer_interp_generic; - for (i = 0; i < totelem; i++, data_dst = POINTER_OFFSET(data_dst, data_step), mapit++) { + for (int i = 0; i < totelem; i++, data_dst = POINTER_OFFSET(data_dst, data_step), mapit++) { const int sources_num = mapit->sources_num; const float mix_factor = laymap->mix_factor * (laymap->mix_weights ? laymap->mix_weights[i] : 1.0f); - int j; if (!sources_num) { /* No sources for this element, skip it. */ @@ -5143,7 +5012,7 @@ void CustomData_data_transfer(const MeshPairRemap *me_remap, tmp_data_src = MEM_reallocN((void *)tmp_data_src, sizeof(*tmp_data_src) * tmp_buff_size); } - for (j = 0; j < sources_num; j++) { + for (int j = 0; j < sources_num; j++) { const size_t src_idx = (size_t)mapit->indices_src[j]; tmp_data_src[j] = POINTER_OFFSET(data_src, (data_step * src_idx) + data_offset); } |