[Bf-blender-cvs] [f2bb044fdba] master: Cleanup: Move six mesh-related files to C++

Hans Goudey noreply at git.blender.org
Sat Jan 21 22:47:43 CET 2023


Commit: f2bb044fdba43139c26d3ce2de41965af1dfab0f
Author: Hans Goudey
Date:   Sat Jan 21 15:44:58 2023 -0600
Branches: master
https://developer.blender.org/rBf2bb044fdba43139c26d3ce2de41965af1dfab0f

Cleanup: Move six mesh-related files to C++

For continued refactoring of the Mesh data structure. See T103343.

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

M	source/blender/blenkernel/CMakeLists.txt
R088	source/blender/blenkernel/intern/deform.c	source/blender/blenkernel/intern/deform.cc
M	source/blender/editors/object/CMakeLists.txt
R088	source/blender/editors/object/object_bake.c	source/blender/editors/object/object_bake.cc
R090	source/blender/editors/object/object_bake_api.c	source/blender/editors/object/object_bake_api.cc
M	source/blender/editors/space_view3d/CMakeLists.txt
R078	source/blender/editors/space_view3d/drawobject.c	source/blender/editors/space_view3d/drawobject.cc
M	source/blender/editors/uvedit/CMakeLists.txt
R086	source/blender/editors/uvedit/uvedit_unwrap_ops.c	source/blender/editors/uvedit/uvedit_unwrap_ops.cc

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

diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index 8a714d8d911..8d6fe6c3cf7 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -119,7 +119,7 @@ set(SRC
   intern/customdata.cc
   intern/customdata_file.c
   intern/data_transfer.cc
-  intern/deform.c
+  intern/deform.cc
   intern/displist.cc
   intern/dynamicpaint.cc
   intern/editlattice.c
diff --git a/source/blender/blenkernel/intern/deform.c b/source/blender/blenkernel/intern/deform.cc
similarity index 88%
rename from source/blender/blenkernel/intern/deform.c
rename to source/blender/blenkernel/intern/deform.cc
index 8bc98270054..a01c6d724a4 100644
--- a/source/blender/blenkernel/intern/deform.c
+++ b/source/blender/blenkernel/intern/deform.cc
@@ -5,11 +5,11 @@
  * \ingroup bke
  */
 
-#include <ctype.h>
-#include <math.h>
-#include <stddef.h>
-#include <stdlib.h>
-#include <string.h>
+#include <cctype>
+#include <cmath>
+#include <cstddef>
+#include <cstdlib>
+#include <cstring>
 
 #include "MEM_guardedalloc.h"
 
@@ -46,7 +46,7 @@ bDeformGroup *BKE_object_defgroup_new(Object *ob, const char *name)
 
   BLI_assert(OB_TYPE_SUPPORT_VGROUP(ob->type));
 
-  defgroup = MEM_callocN(sizeof(bDeformGroup), __func__);
+  defgroup = MEM_cnew<bDeformGroup>(__func__);
 
   BLI_strncpy(defgroup->name, name, sizeof(defgroup->name));
 
@@ -62,31 +62,26 @@ bDeformGroup *BKE_object_defgroup_new(Object *ob, const char *name)
 
 void BKE_defgroup_copy_list(ListBase *outbase, const ListBase *inbase)
 {
-  bDeformGroup *defgroup, *defgroupn;
-
   BLI_listbase_clear(outbase);
-
-  for (defgroup = inbase->first; defgroup; defgroup = defgroup->next) {
-    defgroupn = BKE_defgroup_duplicate(defgroup);
+  LISTBASE_FOREACH (const bDeformGroup *, defgroup, inbase) {
+    bDeformGroup *defgroupn = BKE_defgroup_duplicate(defgroup);
     BLI_addtail(outbase, defgroupn);
   }
 }
 
 bDeformGroup *BKE_defgroup_duplicate(const bDeformGroup *ingroup)
 {
-  bDeformGroup *outgroup;
-
   if (!ingroup) {
     BLI_assert(0);
-    return NULL;
+    return nullptr;
   }
 
-  outgroup = MEM_callocN(sizeof(bDeformGroup), "copy deformGroup");
+  bDeformGroup *outgroup = MEM_cnew<bDeformGroup>(__func__);
 
   /* For now, just copy everything over. */
   memcpy(outgroup, ingroup, sizeof(bDeformGroup));
 
-  outgroup->next = outgroup->prev = NULL;
+  outgroup->next = outgroup->prev = nullptr;
 
   return outgroup;
 }
@@ -132,10 +127,10 @@ void BKE_defvert_copy(MDeformVert *dvert_dst, const MDeformVert *dvert_src)
     }
 
     if (dvert_src->totweight) {
-      dvert_dst->dw = MEM_dupallocN(dvert_src->dw);
+      dvert_dst->dw = static_cast<MDeformWeight *>(MEM_dupallocN(dvert_src->dw));
     }
     else {
-      dvert_dst->dw = NULL;
+      dvert_dst->dw = nullptr;
     }
 
     dvert_dst->totweight = dvert_src->totweight;
@@ -157,7 +152,7 @@ void BKE_defvert_copy_index(MDeformVert *dvert_dst,
     dw_dst->weight = dw_src->weight;
   }
   else {
-    /* Source was NULL, assign zero (could also remove). */
+    /* Source was nullptr, assign zero (could also remove). */
     dw_dst = BKE_defvert_find_index(dvert_dst, defgroup_dst);
 
     if (dw_dst) {
@@ -307,7 +302,7 @@ void BKE_defvert_normalize_lock_single(MDeformVert *dvert,
     }
   }
   else {
-    MDeformWeight *dw_lock = NULL;
+    MDeformWeight *dw_lock = nullptr;
     MDeformWeight *dw;
     uint i;
     float tot_weight = 0.0f;
@@ -423,7 +418,7 @@ void BKE_defvert_flip_merged(MDeformVert *dvert, const int *flip_map, const int
   for (dw = dvert->dw, i = 0; i < totweight; dw++, i++) {
     if (dw->def_nr < flip_map_num) {
       if (flip_map[dw->def_nr] >= 0) {
-        /* error checkers complain of this but we'll never get NULL return */
+        /* error checkers complain of this but we'll never get nullptr return */
         dw_cpy = BKE_defvert_ensure_index(dvert, flip_map[dw->def_nr]);
         dw = &dvert->dw[i]; /* in case array got realloced */
 
@@ -441,7 +436,7 @@ void BKE_defvert_flip_merged(MDeformVert *dvert, const int *flip_map, const int
 bool BKE_object_supports_vertex_groups(const Object *ob)
 {
   const ID *id = (const ID *)ob->data;
-  if (id == NULL) {
+  if (id == nullptr) {
     return false;
   }
 
@@ -467,7 +462,7 @@ const ListBase *BKE_id_defgroup_list_get(const ID *id)
       BLI_assert_unreachable();
     }
   }
-  return NULL;
+  return nullptr;
 }
 
 static const int *object_defgroup_active_index_get_p(const Object *ob)
@@ -487,7 +482,7 @@ static const int *object_defgroup_active_index_get_p(const Object *ob)
       return &gpd->vertex_group_active_index;
     }
   }
-  return NULL;
+  return nullptr;
 }
 
 ListBase *BKE_id_defgroup_list_get_mutable(ID *id)
@@ -498,38 +493,38 @@ ListBase *BKE_id_defgroup_list_get_mutable(ID *id)
 
 bDeformGroup *BKE_object_defgroup_find_name(const Object *ob, const char *name)
 {
-  if (name == NULL || name[0] == '\0') {
-    return NULL;
+  if (name == nullptr || name[0] == '\0') {
+    return nullptr;
   }
   const ListBase *defbase = BKE_object_defgroup_list(ob);
-  return BLI_findstring(defbase, name, offsetof(bDeformGroup, name));
+  return static_cast<bDeformGroup *>(BLI_findstring(defbase, name, offsetof(bDeformGroup, name)));
 }
 
 int BKE_id_defgroup_name_index(const ID *id, const char *name)
 {
   int index;
-  if (!BKE_id_defgroup_name_find(id, name, &index, NULL)) {
+  if (!BKE_id_defgroup_name_find(id, name, &index, nullptr)) {
     return -1;
   }
   return index;
 }
 
-bool BKE_id_defgroup_name_find(const struct ID *id,
+bool BKE_id_defgroup_name_find(const ID *id,
                                const char *name,
                                int *r_index,
-                               struct bDeformGroup **r_group)
+                               bDeformGroup **r_group)
 {
-  if (name == NULL || name[0] == '\0') {
+  if (name == nullptr || name[0] == '\0') {
     return false;
   }
   const ListBase *defbase = BKE_id_defgroup_list_get(id);
   int index;
   LISTBASE_FOREACH_INDEX (bDeformGroup *, group, defbase, index) {
     if (STREQ(name, group->name)) {
-      if (r_index != NULL) {
+      if (r_index != nullptr) {
         *r_index = index;
       }
-      if (r_group != NULL) {
+      if (r_group != nullptr) {
         *r_group = group;
       }
       return true;
@@ -582,19 +577,19 @@ static int *object_defgroup_unlocked_flip_map_ex(const Object *ob,
   *r_flip_map_num = defbase_num;
 
   if (defbase_num == 0) {
-    return NULL;
+    return nullptr;
   }
 
   bDeformGroup *dg;
   char name_flip[sizeof(dg->name)];
   int i, flip_num;
-  int *map = MEM_mallocN(defbase_num * sizeof(int), __func__);
+  int *map = static_cast<int *>(MEM_mallocN(defbase_num * sizeof(int), __func__));
 
   for (i = 0; i < defbase_num; i++) {
     map[i] = -1;
   }
 
-  for (dg = defbase->first, i = 0; dg; dg = dg->next, i++) {
+  for (dg = static_cast<bDeformGroup *>(defbase->first), i = 0; dg; dg = dg->next, i++) {
     if (map[i] == -1) { /* may be calculated previously */
 
       /* in case no valid value is found, use this */
@@ -642,18 +637,17 @@ int *BKE_object_defgroup_flip_map_single(const Object *ob,
   *r_flip_map_num = defbase_num;
 
   if (defbase_num == 0) {
-    return NULL;
+    return nullptr;
   }
 
-  bDeformGroup *dg;
-  char name_flip[sizeof(dg->name)];
-  int i, flip_num, *map = MEM_mallocN(defbase_num * sizeof(int), __func__);
+  char name_flip[sizeof(bDeformGroup::name)];
+  int i, flip_num, *map = static_cast<int *>(MEM_mallocN(defbase_num * sizeof(int), __func__));
 
   for (i = 0; i < defbase_num; i++) {
     map[i] = use_default ? i : -1;
   }
 
-  dg = BLI_findlink(defbase, defgroup);
+  bDeformGroup *dg = static_cast<bDeformGroup *>(BLI_findlink(defbase, defgroup));
 
   BLI_string_flip_side_name(name_flip, dg->name, false, sizeof(name_flip));
   if (!STREQ(name_flip, dg->name)) {
@@ -671,7 +665,7 @@ int *BKE_object_defgroup_flip_map_single(const Object *ob,
 int BKE_object_defgroup_flip_index(const Object *ob, int index, const bool use_default)
 {
   const ListBase *defbase = BKE_object_defgroup_list(ob);
-  bDeformGroup *dg = BLI_findlink(defbase, index);
+  bDeformGroup *dg = static_cast<bDeformGroup *>(BLI_findlink(defbase, index));
   int flip_index = -1;
 
   if (dg) {
@@ -691,7 +685,7 @@ static bool defgroup_find_name_dupe(const char *name, bDeformGroup *dg, Object *
   const ListBase *defbase = BKE_object_defgroup_list(ob);
   bDeformGroup *curdef;
 
-  for (curdef = defbase->first; curdef; curdef = curdef->next) {
+  for (curdef = static_cast<bDeformGroup *>(defbase->first); curdef; curdef = curdef->next) {
     if (dg != curdef) {
       if (STREQ(curdef->name, name)) {
         return true;
@@ -702,46 +696,42 @@ static bool defgroup_find_name_dupe(const char *name, bDeformGroup *dg, Object *
   return false;
 }
 
+struct DeformGroupUniqueNameData {
+  Object *ob;
+  bDeformGroup *dg;
+};
+
 static bool defgroup_unique_check(void *arg, const char *name)
 {
-  struct {
-    Object *ob;
-    void *dg;
-  } *data = arg;
+  DeformGroupUniqueNameData *data = static_cast<DeformGroupUniqueNameData *>(arg);
   return defgroup_find_name_dupe(name, data->dg, data->ob);
 }
 
 void BKE_object_defgroup_unique_name(bDeformGroup *dg, Object *ob)
 {
-  struct {
-    Object *ob;
-    void *dg;
-  } data;
-  data.ob = ob;
-  data.dg = dg;
-
+  DeformGroupUniqueNameData data{ob, dg};
   BLI_uniquename_cb(defgroup_unique_check, &data, DATA_("Group"), '.', dg->name, sizeof(dg->name));
 }
 
-float BKE_defvert_find_weight(const struct MDeformVert *dvert, const int defgroup)
+float BKE_defvert_find_weight(const MDeformVert *dvert, const int defgroup)
 {
   MDeformWeight *dw = BKE_defvert_find_index(dvert, defgroup);
   return dw ? dw->weight : 0.0f;
 }
 
-float BKE_defvert_array_find_weight_safe(const struct MDeformVert *dvert,
+float BKE_defvert_array_find_weight_safe(const MDeformVert *dvert,
                                          const int index,
                                          const int defgroup)
 {
   /* Invalid defgroup index means the vgroup selected is invalid,
    * does not exist, in that case it is OK to return 1.0
    * (i.e. maximum weight, as if no vgroup was selected

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list