[Bf-blender-cvs] [ab1c36ad3f0] master: Cleanup: Move two modifier files to C++

Hans Goudey noreply at git.blender.org
Tue Dec 13 01:20:26 CET 2022


Commit: ab1c36ad3f0e6568fc951e4f75c5fbf01c463dd1
Author: Hans Goudey
Date:   Mon Dec 12 18:19:32 2022 -0600
Branches: master
https://developer.blender.org/rBab1c36ad3f0e6568fc951e4f75c5fbf01c463dd1

Cleanup: Move two modifier files to C++

===================================================================

M	source/blender/modifiers/CMakeLists.txt
R089	source/blender/modifiers/intern/MOD_array.c	source/blender/modifiers/intern/MOD_array.cc
R087	source/blender/modifiers/intern/MOD_screw.c	source/blender/modifiers/intern/MOD_screw.cc
M	source/blender/modifiers/intern/MOD_skin.c

===================================================================

diff --git a/source/blender/modifiers/CMakeLists.txt b/source/blender/modifiers/CMakeLists.txt
index 807d5012681..63be9581175 100644
--- a/source/blender/modifiers/CMakeLists.txt
+++ b/source/blender/modifiers/CMakeLists.txt
@@ -34,7 +34,7 @@ set(INC_SYS
 
 set(SRC
   intern/MOD_armature.c
-  intern/MOD_array.c
+  intern/MOD_array.cc
   intern/MOD_bevel.c
   intern/MOD_boolean.cc
   intern/MOD_build.c
@@ -71,7 +71,7 @@ set(SRC
   intern/MOD_particleinstance.c
   intern/MOD_particlesystem.cc
   intern/MOD_remesh.c
-  intern/MOD_screw.c
+  intern/MOD_screw.cc
   intern/MOD_shapekey.c
   intern/MOD_shrinkwrap.c
   intern/MOD_simpledeform.c
diff --git a/source/blender/modifiers/intern/MOD_array.c b/source/blender/modifiers/intern/MOD_array.cc
similarity index 89%
rename from source/blender/modifiers/intern/MOD_array.c
rename to source/blender/modifiers/intern/MOD_array.cc
index 2d725af7fe4..1478ca0ecc5 100644
--- a/source/blender/modifiers/intern/MOD_array.c
+++ b/source/blender/modifiers/intern/MOD_array.cc
@@ -73,11 +73,11 @@ static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphConte
 {
   ArrayModifierData *amd = (ArrayModifierData *)md;
   bool need_transform_dependency = false;
-  if (amd->start_cap != NULL) {
+  if (amd->start_cap != nullptr) {
     DEG_add_object_relation(
         ctx->node, amd->start_cap, DEG_OB_COMP_GEOMETRY, "Array Modifier Start Cap");
   }
-  if (amd->end_cap != NULL) {
+  if (amd->end_cap != nullptr) {
     DEG_add_object_relation(
         ctx->node, amd->end_cap, DEG_OB_COMP_GEOMETRY, "Array Modifier End Cap");
   }
@@ -86,7 +86,7 @@ static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphConte
         ctx->node, amd->curve_ob, DEG_OB_COMP_GEOMETRY, "Array Modifier Curve");
     DEG_add_special_eval_flag(ctx->node, &amd->curve_ob->id, DAG_EVAL_NEED_CURVE_PATH);
   }
-  if (amd->offset_ob != NULL) {
+  if (amd->offset_ob != nullptr) {
     DEG_add_object_relation(
         ctx->node, amd->offset_ob, DEG_OB_COMP_TRANSFORM, "Array Modifier Offset");
     need_transform_dependency = true;
@@ -103,16 +103,16 @@ BLI_INLINE float sum_v3(const float v[3])
 }
 
 /* Structure used for sorting vertices, when processing doubles */
-typedef struct SortVertsElem {
+struct SortVertsElem {
   int vertex_num; /* The original index of the vertex, prior to sorting */
   float co[3];    /* Its coordinates */
   float sum_co;   /* `sum_v3(co)`: just so we don't do the sum many times. */
-} SortVertsElem;
+};
 
 static int svert_sum_cmp(const void *e1, const void *e2)
 {
-  const SortVertsElem *sv1 = e1;
-  const SortVertsElem *sv2 = e2;
+  const SortVertsElem *sv1 = static_cast<const SortVertsElem *>(e1);
+  const SortVertsElem *sv2 = static_cast<const SortVertsElem *>(e2);
 
   if (sv1->sum_co > sv2->sum_co) {
     return 1;
@@ -152,9 +152,8 @@ static void dm_mvert_map_doubles(int *doubles_map,
                                  const int source_verts_num,
                                  const float dist)
 {
-  const float dist3 = ((float)M_SQRT3 + 0.00005f) * dist; /* Just above sqrt(3) */
+  const float dist3 = (float(M_SQRT3) + 0.00005f) * dist; /* Just above sqrt(3) */
   int i_source, i_target, i_target_low_bound, target_end, source_end;
-  SortVertsElem *sorted_verts_target, *sorted_verts_source;
   SortVertsElem *sve_source, *sve_target, *sve_target_low_bound;
   bool target_scan_completed;
 
@@ -162,8 +161,10 @@ static void dm_mvert_map_doubles(int *doubles_map,
   source_end = source_start + source_verts_num;
 
   /* build array of MVerts to be tested for merging */
-  sorted_verts_target = MEM_malloc_arrayN(target_verts_num, sizeof(SortVertsElem), __func__);
-  sorted_verts_source = MEM_malloc_arrayN(source_verts_num, sizeof(SortVertsElem), __func__);
+  SortVertsElem *sorted_verts_target = static_cast<SortVertsElem *>(
+      MEM_malloc_arrayN(target_verts_num, sizeof(SortVertsElem), __func__));
+  SortVertsElem *sorted_verts_source = static_cast<SortVertsElem *>(
+      MEM_malloc_arrayN(source_verts_num, sizeof(SortVertsElem), __func__));
 
   /* Copy target vertices index and cos into SortVertsElem array */
   svert_from_mvert(sorted_verts_target, mverts + target_start, target_start, target_end);
@@ -305,7 +306,7 @@ static void mesh_merge_transform(Mesh *result,
   }
 
   /* remap the vertex groups if necessary */
-  if (BKE_mesh_deform_verts(result) != NULL) {
+  if (BKE_mesh_deform_verts(result) != nullptr) {
     MDeformVert *dvert = BKE_mesh_deform_verts_for_write(result);
     BKE_object_defgroup_index_map_apply(&dvert[cap_verts_index], cap_nverts, remap, remap_len);
   }
@@ -331,22 +332,22 @@ static void mesh_merge_transform(Mesh *result,
   }
 
   /* Set #CD_ORIGINDEX. */
-  index_orig = CustomData_get_layer(&result->vdata, CD_ORIGINDEX);
+  index_orig = static_cast<int *>(CustomData_get_layer(&result->vdata, CD_ORIGINDEX));
   if (index_orig) {
     copy_vn_i(index_orig + cap_verts_index, cap_nverts, ORIGINDEX_NONE);
   }
 
-  index_orig = CustomData_get_layer(&result->edata, CD_ORIGINDEX);
+  index_orig = static_cast<int *>(CustomData_get_layer(&result->edata, CD_ORIGINDEX));
   if (index_orig) {
     copy_vn_i(index_orig + cap_edges_index, cap_nedges, ORIGINDEX_NONE);
   }
 
-  index_orig = CustomData_get_layer(&result->pdata, CD_ORIGINDEX);
+  index_orig = static_cast<int *>(CustomData_get_layer(&result->pdata, CD_ORIGINDEX));
   if (index_orig) {
     copy_vn_i(index_orig + cap_polys_index, cap_npolys, ORIGINDEX_NONE);
   }
 
-  index_orig = CustomData_get_layer(&result->ldata, CD_ORIGINDEX);
+  index_orig = static_cast<int *>(CustomData_get_layer(&result->ldata, CD_ORIGINDEX));
   if (index_orig) {
     copy_vn_i(index_orig + cap_loops_index, cap_nloops, ORIGINDEX_NONE);
   }
@@ -367,12 +368,12 @@ static Mesh *arrayModifier_doArray(ArrayModifierData *amd,
   bool offset_has_scale;
   float current_offset[4][4];
   float final_offset[4][4];
-  int *full_doubles_map = NULL;
+  int *full_doubles_map = nullptr;
   int tot_doubles;
 
   const bool use_merge = (amd->flags & MOD_ARR_MERGE) != 0;
   const bool use_recalc_normals = BKE_mesh_vertex_normals_are_dirty(mesh) || use_merge;
-  const bool use_offset_ob = ((amd->offset_type & MOD_ARR_OFF_OBJ) && amd->offset_ob != NULL);
+  const bool use_offset_ob = ((amd->offset_type & MOD_ARR_OFF_OBJ) && amd->offset_ob != nullptr);
 
   int start_cap_nverts = 0, start_cap_nedges = 0, start_cap_npolys = 0, start_cap_nloops = 0;
   int end_cap_nverts = 0, end_cap_nedges = 0, end_cap_npolys = 0, end_cap_nloops = 0;
@@ -380,11 +381,11 @@ static Mesh *arrayModifier_doArray(ArrayModifierData *amd,
   int chunk_nverts, chunk_nedges, chunk_nloops, chunk_npolys;
   int first_chunk_start, first_chunk_nverts, last_chunk_start, last_chunk_nverts;
 
-  Mesh *result, *start_cap_mesh = NULL, *end_cap_mesh = NULL;
+  Mesh *result, *start_cap_mesh = nullptr, *end_cap_mesh = nullptr;
 
-  int *vgroup_start_cap_remap = NULL;
+  int *vgroup_start_cap_remap = nullptr;
   int vgroup_start_cap_remap_len = 0;
-  int *vgroup_end_cap_remap = NULL;
+  int *vgroup_end_cap_remap = nullptr;
   int vgroup_end_cap_remap_len = 0;
 
   chunk_nverts = mesh->totvert;
@@ -470,10 +471,10 @@ static Mesh *arrayModifier_doArray(ArrayModifierData *amd,
   mat4_to_size(scale, offset);
   offset_has_scale = !is_one_v3(scale);
 
-  if (amd->fit_type == MOD_ARR_FITCURVE && amd->curve_ob != NULL) {
+  if (amd->fit_type == MOD_ARR_FITCURVE && amd->curve_ob != nullptr) {
     Object *curve_ob = amd->curve_ob;
     CurveCache *curve_cache = curve_ob->runtime.curve_cache;
-    if (curve_cache != NULL && curve_cache->anim_path_accum_length != NULL) {
+    if (curve_cache != nullptr && curve_cache->anim_path_accum_length != nullptr) {
       float scale_fac = mat4_to_scale(curve_ob->object_to_world);
       length = scale_fac * BKE_anim_path_get_length(curve_cache);
     }
@@ -548,7 +549,7 @@ static Mesh *arrayModifier_doArray(ArrayModifierData *amd,
 
   if (use_merge) {
     /* Will need full_doubles_map for handling merge */
-    full_doubles_map = MEM_malloc_arrayN(result_nverts, sizeof(int), "mod array doubles map");
+    full_doubles_map = static_cast<int *>(MEM_malloc_arrayN(result_nverts, sizeof(int), __func__));
     copy_vn_i(full_doubles_map, result_nverts, -1);
   }
 
@@ -576,8 +577,8 @@ static Mesh *arrayModifier_doArray(ArrayModifierData *amd,
   first_chunk_nverts = chunk_nverts;
 
   unit_m4(current_offset);
-  const float(*src_vert_normals)[3] = NULL;
-  float(*dst_vert_normals)[3] = NULL;
+  const float(*src_vert_normals)[3] = nullptr;
+  float(*dst_vert_normals)[3] = nullptr;
   if (!use_recalc_normals) {
     src_vert_normals = BKE_mesh_vertex_normals_ensure(mesh);
     dst_vert_normals = BKE_mesh_vertex_normals_for_write(result);
@@ -672,12 +673,13 @@ static Mesh *arrayModifier_doArray(ArrayModifierData *amd,
   if (chunk_nloops > 0 && is_zero_v2(amd->uv_offset) == false) {
     const int totuv = CustomData_number_of_layers(&result->ldata, CD_MLOOPUV);
     for (i = 0; i < totuv; i++) {
-      MLoopUV *dmloopuv = CustomData_get_layer_n(&result->ldata, CD_MLOOPUV, i);
+      MLoopUV *dmloopuv = static_cast<MLoopUV *>(
+          CustomData_get_layer_n(&result->ldata, CD_MLOOPUV, i));
       dmloopuv += chunk_nloops;
       for (c = 1; c < count; c++) {
         const float uv_offset[2] = {
-            amd->uv_offset[0] * (float)c,
-            amd->uv_offset[1] * (float)c,
+            amd->uv_offset[0] * float(c),
+            amd->uv_offset[1] * float(c),
         };
         int l_index = chunk_nloops;
         for (; l_index-- != 0; dmloopuv++) {
@@ -810,9 +812,7 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
   return arrayModifier_doArray(amd, ctx, mesh);
 }
 
-static bool isDisabled(const struct Scene *UNUSED(scene),
-                       ModifierData *md,
-                       bool UNUSED(useRenderParams))
+static bool isDisabled(const Scene * /*scene*/, ModifierData *md, bool /*useRenderParams*/)
 {
   ArrayModifierData *amd = (ArrayModifierData *)md;
 
@@ -835,7 +835,7 @@ static bool isDisabled(const struct Scene *UNUSED(scene),
   return false;
 }
 
-static void panel_draw(const bContext *UNUSED(C), Panel *pane

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list