[Bf-blender-cvs] [732d0b458b6] master: Blenkernel: move DerivedMesh.c to c++

Jacques Lucke noreply at git.blender.org
Mon Dec 14 13:17:21 CET 2020


Commit: 732d0b458b6f9024b285747a643cacb128888b8c
Author: Jacques Lucke
Date:   Mon Dec 14 13:00:28 2020 +0100
Branches: master
https://developer.blender.org/rB732d0b458b6f9024b285747a643cacb128888b8c

Blenkernel: move DerivedMesh.c to c++

Required changes to make it compile with clang tidy:
* Use c++ includes like (e.g. climits instead limits.h).
* Insert type casts when casting from void* to something else.
* Replace NULL with nullptr.
* Insert casts from int to enum.
* Replace designed initializers (not supported in C++ yet).
* Use blender::Vector instead of BLI_array_staticdeclare (does not compile with C++).
* Replace typedef statements.

Ref T83357.

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

M	source/blender/blenkernel/BKE_mesh.h
M	source/blender/blenkernel/BKE_mesh_runtime.h
M	source/blender/blenkernel/CMakeLists.txt
R088	source/blender/blenkernel/intern/DerivedMesh.c	source/blender/blenkernel/intern/DerivedMesh.cc
M	source/blender/blenkernel/intern/mesh_convert.c
M	source/blender/modifiers/intern/MOD_cloth.c

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

diff --git a/source/blender/blenkernel/BKE_mesh.h b/source/blender/blenkernel/BKE_mesh.h
index 807f13efe14..0f34549a3cd 100644
--- a/source/blender/blenkernel/BKE_mesh.h
+++ b/source/blender/blenkernel/BKE_mesh.h
@@ -678,7 +678,7 @@ void BKE_mesh_calc_edges_loose(struct Mesh *mesh);
 void BKE_mesh_calc_edges(struct Mesh *mesh, bool keep_existing_edges, const bool select_new_edges);
 void BKE_mesh_calc_edges_tessface(struct Mesh *mesh);
 
-/* In DerivedMesh.c */
+/* In DerivedMesh.cc */
 void BKE_mesh_wrapper_deferred_finalize(struct Mesh *me_eval,
                                         const CustomData_MeshMasks *cd_mask_finalize);
 
diff --git a/source/blender/blenkernel/BKE_mesh_runtime.h b/source/blender/blenkernel/BKE_mesh_runtime.h
index 87b55c581a2..67c87e96aff 100644
--- a/source/blender/blenkernel/BKE_mesh_runtime.h
+++ b/source/blender/blenkernel/BKE_mesh_runtime.h
@@ -57,9 +57,9 @@ void BKE_mesh_runtime_verttri_from_looptri(struct MVertTri *r_verttri,
                                            const struct MLoopTri *looptri,
                                            int looptri_num);
 
-/* NOTE: the functions below are defined in DerivedMesh.c, and are intended to be moved
+/* NOTE: the functions below are defined in DerivedMesh.cc, and are intended to be moved
  * to a more suitable location when that file is removed.
- * They should also be renamed to use conventions from BKE, not old DerivedMesh.c.
+ * They should also be renamed to use conventions from BKE, not old DerivedMesh.cc.
  * For now keep the names similar to avoid confusion. */
 struct Mesh *mesh_get_eval_final(struct Depsgraph *depsgraph,
                                  struct Scene *scene,
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index 65161317351..5b10f734d71 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -66,7 +66,7 @@ set(SRC
   intern/CCGSubSurf.c
   intern/CCGSubSurf_legacy.c
   intern/CCGSubSurf_util.c
-  intern/DerivedMesh.c
+  intern/DerivedMesh.cc
   intern/action.c
   intern/addon.c
   intern/anim_data.c
diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.cc
similarity index 88%
rename from source/blender/blenkernel/intern/DerivedMesh.c
rename to source/blender/blenkernel/intern/DerivedMesh.cc
index eeff04788f9..78d4ad6fe19 100644
--- a/source/blender/blenkernel/intern/DerivedMesh.c
+++ b/source/blender/blenkernel/intern/DerivedMesh.cc
@@ -21,8 +21,8 @@
  * \ingroup bke
  */
 
-#include <limits.h>
-#include <string.h>
+#include <climits>
+#include <cstring>
 
 #include "MEM_guardedalloc.h"
 
@@ -38,10 +38,12 @@
 #include "BLI_array.h"
 #include "BLI_bitmap.h"
 #include "BLI_blenlib.h"
+#include "BLI_float2.hh"
 #include "BLI_linklist.h"
 #include "BLI_math.h"
 #include "BLI_task.h"
 #include "BLI_utildefines.h"
+#include "BLI_vector.hh"
 
 #include "BKE_DerivedMesh.h"
 #include "BKE_bvhutils.h"
@@ -81,7 +83,7 @@
 
 #ifdef USE_MODIFIER_VALIDATE
 #  define ASSERT_IS_VALID_MESH(mesh) \
-    (BLI_assert((mesh == NULL) || (BKE_mesh_is_valid(mesh) == true)))
+    (BLI_assert((mesh == nullptr) || (BKE_mesh_is_valid(mesh) == true)))
 #else
 #  define ASSERT_IS_VALID_MESH(mesh)
 #endif
@@ -96,10 +98,11 @@ static void editbmesh_calc_modifier_final_normals(Mesh *mesh_final,
 
 static MVert *dm_getVertArray(DerivedMesh *dm)
 {
-  MVert *mvert = CustomData_get_layer(&dm->vertData, CD_MVERT);
+  MVert *mvert = (MVert *)CustomData_get_layer(&dm->vertData, CD_MVERT);
 
   if (!mvert) {
-    mvert = CustomData_add_layer(&dm->vertData, CD_MVERT, CD_CALLOC, NULL, dm->getNumVerts(dm));
+    mvert = (MVert *)CustomData_add_layer(
+        &dm->vertData, CD_MVERT, CD_CALLOC, nullptr, dm->getNumVerts(dm));
     CustomData_set_layer_flag(&dm->vertData, CD_MVERT, CD_FLAG_TEMPORARY);
     dm->copyVertArray(dm, mvert);
   }
@@ -109,10 +112,11 @@ static MVert *dm_getVertArray(DerivedMesh *dm)
 
 static MEdge *dm_getEdgeArray(DerivedMesh *dm)
 {
-  MEdge *medge = CustomData_get_layer(&dm->edgeData, CD_MEDGE);
+  MEdge *medge = (MEdge *)CustomData_get_layer(&dm->edgeData, CD_MEDGE);
 
   if (!medge) {
-    medge = CustomData_add_layer(&dm->edgeData, CD_MEDGE, CD_CALLOC, NULL, dm->getNumEdges(dm));
+    medge = (MEdge *)CustomData_add_layer(
+        &dm->edgeData, CD_MEDGE, CD_CALLOC, nullptr, dm->getNumEdges(dm));
     CustomData_set_layer_flag(&dm->edgeData, CD_MEDGE, CD_FLAG_TEMPORARY);
     dm->copyEdgeArray(dm, medge);
   }
@@ -122,7 +126,7 @@ static MEdge *dm_getEdgeArray(DerivedMesh *dm)
 
 static MFace *dm_getTessFaceArray(DerivedMesh *dm)
 {
-  MFace *mface = CustomData_get_layer(&dm->faceData, CD_MFACE);
+  MFace *mface = (MFace *)CustomData_get_layer(&dm->faceData, CD_MFACE);
 
   if (!mface) {
     int numTessFaces = dm->getNumTessFaces(dm);
@@ -132,10 +136,11 @@ static MFace *dm_getTessFaceArray(DerivedMesh *dm)
        * this layer is needed with non-zero size, but currently CD stuff does not check
        * for requested layer size on creation and just returns layer which was previously
        * added (sergey) */
-      return NULL;
+      return nullptr;
     }
 
-    mface = CustomData_add_layer(&dm->faceData, CD_MFACE, CD_CALLOC, NULL, numTessFaces);
+    mface = (MFace *)CustomData_add_layer(
+        &dm->faceData, CD_MFACE, CD_CALLOC, nullptr, numTessFaces);
     CustomData_set_layer_flag(&dm->faceData, CD_MFACE, CD_FLAG_TEMPORARY);
     dm->copyTessFaceArray(dm, mface);
   }
@@ -145,10 +150,11 @@ static MFace *dm_getTessFaceArray(DerivedMesh *dm)
 
 static MLoop *dm_getLoopArray(DerivedMesh *dm)
 {
-  MLoop *mloop = CustomData_get_layer(&dm->loopData, CD_MLOOP);
+  MLoop *mloop = (MLoop *)CustomData_get_layer(&dm->loopData, CD_MLOOP);
 
   if (!mloop) {
-    mloop = CustomData_add_layer(&dm->loopData, CD_MLOOP, CD_CALLOC, NULL, dm->getNumLoops(dm));
+    mloop = (MLoop *)CustomData_add_layer(
+        &dm->loopData, CD_MLOOP, CD_CALLOC, nullptr, dm->getNumLoops(dm));
     CustomData_set_layer_flag(&dm->loopData, CD_MLOOP, CD_FLAG_TEMPORARY);
     dm->copyLoopArray(dm, mloop);
   }
@@ -158,10 +164,11 @@ static MLoop *dm_getLoopArray(DerivedMesh *dm)
 
 static MPoly *dm_getPolyArray(DerivedMesh *dm)
 {
-  MPoly *mpoly = CustomData_get_layer(&dm->polyData, CD_MPOLY);
+  MPoly *mpoly = (MPoly *)CustomData_get_layer(&dm->polyData, CD_MPOLY);
 
   if (!mpoly) {
-    mpoly = CustomData_add_layer(&dm->polyData, CD_MPOLY, CD_CALLOC, NULL, dm->getNumPolys(dm));
+    mpoly = (MPoly *)CustomData_add_layer(
+        &dm->polyData, CD_MPOLY, CD_CALLOC, nullptr, dm->getNumPolys(dm));
     CustomData_set_layer_flag(&dm->polyData, CD_MPOLY, CD_FLAG_TEMPORARY);
     dm->copyPolyArray(dm, mpoly);
   }
@@ -171,7 +178,8 @@ static MPoly *dm_getPolyArray(DerivedMesh *dm)
 
 static MVert *dm_dupVertArray(DerivedMesh *dm)
 {
-  MVert *tmp = MEM_malloc_arrayN(dm->getNumVerts(dm), sizeof(*tmp), "dm_dupVertArray tmp");
+  MVert *tmp = (MVert *)MEM_malloc_arrayN(
+      dm->getNumVerts(dm), sizeof(*tmp), "dm_dupVertArray tmp");
 
   if (tmp) {
     dm->copyVertArray(dm, tmp);
@@ -182,7 +190,8 @@ static MVert *dm_dupVertArray(DerivedMesh *dm)
 
 static MEdge *dm_dupEdgeArray(DerivedMesh *dm)
 {
-  MEdge *tmp = MEM_malloc_arrayN(dm->getNumEdges(dm), sizeof(*tmp), "dm_dupEdgeArray tmp");
+  MEdge *tmp = (MEdge *)MEM_malloc_arrayN(
+      dm->getNumEdges(dm), sizeof(*tmp), "dm_dupEdgeArray tmp");
 
   if (tmp) {
     dm->copyEdgeArray(dm, tmp);
@@ -193,7 +202,8 @@ static MEdge *dm_dupEdgeArray(DerivedMesh *dm)
 
 static MFace *dm_dupFaceArray(DerivedMesh *dm)
 {
-  MFace *tmp = MEM_malloc_arrayN(dm->getNumTessFaces(dm), sizeof(*tmp), "dm_dupFaceArray tmp");
+  MFace *tmp = (MFace *)MEM_malloc_arrayN(
+      dm->getNumTessFaces(dm), sizeof(*tmp), "dm_dupFaceArray tmp");
 
   if (tmp) {
     dm->copyTessFaceArray(dm, tmp);
@@ -204,7 +214,8 @@ static MFace *dm_dupFaceArray(DerivedMesh *dm)
 
 static MLoop *dm_dupLoopArray(DerivedMesh *dm)
 {
-  MLoop *tmp = MEM_malloc_arrayN(dm->getNumLoops(dm), sizeof(*tmp), "dm_dupLoopArray tmp");
+  MLoop *tmp = (MLoop *)MEM_malloc_arrayN(
+      dm->getNumLoops(dm), sizeof(*tmp), "dm_dupLoopArray tmp");
 
   if (tmp) {
     dm->copyLoopArray(dm, tmp);
@@ -215,7 +226,8 @@ static MLoop *dm_dupLoopArray(DerivedMesh *dm)
 
 static MPoly *dm_dupPolyArray(DerivedMesh *dm)
 {
-  MPoly *tmp = MEM_malloc_arrayN(dm->getNumPolys(dm), sizeof(*tmp), "dm_dupPolyArray tmp");
+  MPoly *tmp = (MPoly *)MEM_malloc_arrayN(
+      dm->getNumPolys(dm), sizeof(*tmp), "dm_dupPolyArray tmp");
 
   if (tmp) {
     dm->copyPolyArray(dm, tmp);
@@ -239,14 +251,14 @@ static const MLoopTri *dm_getLoopTriArray(DerivedMesh *dm)
   looptri = dm->looptris.array;
   BLI_rw_mutex_unlock(&loops_cache_lock);
 
-  if (looptri != NULL) {
+  if (looptri != nullptr) {
     BLI_assert(dm->getNumLoopTri(dm) == dm->looptris.num);
   }
   else {
     BLI_rw_mutex_lock(&loops_cache_lock, THREAD_LOCK_WRITE);
-    /* We need to ensure array is still NULL inside mutex-protected code,
+    /* We need to ensure array is still nullptr inside mutex-protected code,
      * some other thread might have already recomputed those looptris. */
-    if (dm->looptris.array == NULL) {
+    if (dm->looptris.array == nullptr) {
       dm->recalcLoopTri(dm);
     }
     looptri = dm->looptris.array;
@@ -343,7 +355,7 @@ void DM_init(DerivedMesh *dm,
   DM_init_funcs(dm);
 
   dm->needsFree = 1;
-  dm->dirty = 0;
+  dm->dirty = (DMDirtyFlag)0;
 
   /* don't use CustomData_reset(...); because we dont want to touch customdata */
   copy_vn_i(dm->vertData.typemap, CD_NUMTYPES, -1);
@@ -385,7 +397,7 @@ void DM_from_template_ex(DerivedMesh *dm,
   DM_init_funcs(dm);
 
   dm->needsFree = 1;
-  dm->dirty = 0;
+  dm->dirty = (DMDirtyFlag)0;
 }
 void DM_from_template(DerivedMesh *dm,
                       DerivedMesh *source,
@@ -482,7 +494,7 @@ void DM_ensure_looptri_data(DerivedMesh *dm)
   const unsigned int totloop = dm->numLoopData;
   const int looptris_num = poly_to_tri_count(totpoly, totloop);
 
-  BLI_assert(dm->looptris.array_wip == NULL);
+  BLI_assert(dm->looptris.array_wip == nullptr);
 
   SWAP(MLoopTri *, dm->looptris.array, dm->looptris.array_wip);
 
@

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list