[Bf-blender-cvs] [582f6032fc5] master: Cleanup: Move hair object type files to C++

Hans Goudey noreply at git.blender.org
Thu Dec 23 18:46:54 CET 2021


Commit: 582f6032fc5ab556fcfdec1d2e4537f53778089c
Author: Hans Goudey
Date:   Thu Dec 23 11:46:45 2021 -0600
Branches: master
https://developer.blender.org/rB582f6032fc5ab556fcfdec1d2e4537f53778089c

Cleanup: Move hair object type files to C++

Differential Revision: https://developer.blender.org/D13657

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

M	source/blender/blenkernel/CMakeLists.txt
R079	source/blender/blenkernel/intern/hair.c	source/blender/blenkernel/intern/hair.cc
M	source/blender/draw/CMakeLists.txt
R091	source/blender/draw/intern/draw_cache_impl_hair.c	source/blender/draw/intern/draw_cache_impl_hair.cc

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

diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index 02aef4ef79e..cff9bd845ec 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -156,7 +156,7 @@ set(SRC
   intern/gpencil_curve.c
   intern/gpencil_geom.cc
   intern/gpencil_modifier.c
-  intern/hair.c
+  intern/hair.cc
   intern/icons.cc
   intern/icons_rasterize.c
   intern/idprop.c
diff --git a/source/blender/blenkernel/intern/hair.c b/source/blender/blenkernel/intern/hair.cc
similarity index 79%
rename from source/blender/blenkernel/intern/hair.c
rename to source/blender/blenkernel/intern/hair.cc
index f2a5146422e..c5b154c9a4b 100644
--- a/source/blender/blenkernel/intern/hair.c
+++ b/source/blender/blenkernel/intern/hair.cc
@@ -18,6 +18,9 @@
  * \ingroup bke
  */
 
+#include <cmath>
+#include <cstring>
+
 #include "MEM_guardedalloc.h"
 
 #include "DNA_defaults.h"
@@ -25,8 +28,9 @@
 #include "DNA_material_types.h"
 #include "DNA_object_types.h"
 
+#include "BLI_float3.hh"
 #include "BLI_listbase.h"
-#include "BLI_math.h"
+#include "BLI_math_base.h"
 #include "BLI_rand.h"
 #include "BLI_string.h"
 #include "BLI_utildefines.h"
@@ -49,6 +53,8 @@
 
 #include "BLO_read_write.h"
 
+using blender::float3;
+
 static const char *HAIR_ATTR_POSITION = "position";
 static const char *HAIR_ATTR_RADIUS = "radius";
 
@@ -67,10 +73,10 @@ static void hair_init_data(ID *id)
   CustomData_reset(&hair->cdata);
 
   CustomData_add_layer_named(
-      &hair->pdata, CD_PROP_FLOAT3, CD_CALLOC, NULL, hair->totpoint, HAIR_ATTR_POSITION);
+      &hair->pdata, CD_PROP_FLOAT3, CD_CALLOC, nullptr, hair->totpoint, HAIR_ATTR_POSITION);
   CustomData_add_layer_named(
-      &hair->pdata, CD_PROP_FLOAT, CD_CALLOC, NULL, hair->totpoint, HAIR_ATTR_RADIUS);
-  CustomData_add_layer(&hair->cdata, CD_HAIRCURVE, CD_CALLOC, NULL, hair->totcurve);
+      &hair->pdata, CD_PROP_FLOAT, CD_CALLOC, nullptr, hair->totpoint, HAIR_ATTR_RADIUS);
+  CustomData_add_layer(&hair->cdata, CD_HAIRCURVE, CD_CALLOC, nullptr, hair->totcurve);
   BKE_hair_update_customdata_pointers(hair);
 
   hair_random(hair);
@@ -80,14 +86,14 @@ static void hair_copy_data(Main *UNUSED(bmain), ID *id_dst, const ID *id_src, co
 {
   Hair *hair_dst = (Hair *)id_dst;
   const Hair *hair_src = (const Hair *)id_src;
-  hair_dst->mat = MEM_dupallocN(hair_src->mat);
+  hair_dst->mat = static_cast<Material **>(MEM_dupallocN(hair_src->mat));
 
   const eCDAllocType alloc_type = (flag & LIB_ID_COPY_CD_REFERENCE) ? CD_REFERENCE : CD_DUPLICATE;
   CustomData_copy(&hair_src->pdata, &hair_dst->pdata, CD_MASK_ALL, alloc_type, hair_dst->totpoint);
   CustomData_copy(&hair_src->cdata, &hair_dst->cdata, CD_MASK_ALL, alloc_type, hair_dst->totcurve);
   BKE_hair_update_customdata_pointers(hair_dst);
 
-  hair_dst->batch_cache = NULL;
+  hair_dst->batch_cache = nullptr;
 }
 
 static void hair_free_data(ID *id)
@@ -115,8 +121,8 @@ static void hair_blend_write(BlendWriter *writer, ID *id, const void *id_address
 {
   Hair *hair = (Hair *)id;
 
-  CustomDataLayer *players = NULL, players_buff[CD_TEMP_CHUNK_SIZE];
-  CustomDataLayer *clayers = NULL, clayers_buff[CD_TEMP_CHUNK_SIZE];
+  CustomDataLayer *players = nullptr, players_buff[CD_TEMP_CHUNK_SIZE];
+  CustomDataLayer *clayers = nullptr, clayers_buff[CD_TEMP_CHUNK_SIZE];
   CustomData_blend_write_prepare(&hair->pdata, &players, players_buff, ARRAY_SIZE(players_buff));
   CustomData_blend_write_prepare(&hair->cdata, &clayers, clayers_buff, ARRAY_SIZE(clayers_buff));
 
@@ -174,33 +180,33 @@ static void hair_blend_read_expand(BlendExpander *expander, ID *id)
 }
 
 IDTypeInfo IDType_ID_HA = {
-    .id_code = ID_HA,
-    .id_filter = FILTER_ID_HA,
-    .main_listbase_index = INDEX_ID_HA,
-    .struct_size = sizeof(Hair),
-    .name = "Hair",
-    .name_plural = "hairs",
-    .translation_context = BLT_I18NCONTEXT_ID_HAIR,
-    .flags = IDTYPE_FLAGS_APPEND_IS_REUSABLE,
-    .asset_type_info = NULL,
-
-    .init_data = hair_init_data,
-    .copy_data = hair_copy_data,
-    .free_data = hair_free_data,
-    .make_local = NULL,
-    .foreach_id = hair_foreach_id,
-    .foreach_cache = NULL,
-    .foreach_path = NULL,
-    .owner_get = NULL,
-
-    .blend_write = hair_blend_write,
-    .blend_read_data = hair_blend_read_data,
-    .blend_read_lib = hair_blend_read_lib,
-    .blend_read_expand = hair_blend_read_expand,
-
-    .blend_read_undo_preserve = NULL,
-
-    .lib_override_apply_post = NULL,
+    /*id_code */ ID_HA,
+    /*id_filter */ FILTER_ID_HA,
+    /*main_listbase_index */ INDEX_ID_HA,
+    /*struct_size */ sizeof(Hair),
+    /*name */ "Hair",
+    /*name_plural */ "hairs",
+    /*translation_context */ BLT_I18NCONTEXT_ID_HAIR,
+    /*flags */ IDTYPE_FLAGS_APPEND_IS_REUSABLE,
+    /*asset_type_info */ nullptr,
+
+    /*init_data */ hair_init_data,
+    /*copy_data */ hair_copy_data,
+    /*free_data */ hair_free_data,
+    /*make_local */ nullptr,
+    /*foreach_id */ hair_foreach_id,
+    /*foreach_cache */ nullptr,
+    /*foreach_path */ nullptr,
+    /*owner_get */ nullptr,
+
+    /*blend_write */ hair_blend_write,
+    /*blend_read_data */ hair_blend_read_data,
+    /*blend_read_lib */ hair_blend_read_lib,
+    /*blend_read_expand */ hair_blend_read_expand,
+
+    /*blend_read_undo_preserve */ nullptr,
+
+    /*lib_override_apply_post */ nullptr,
 };
 
 static void hair_random(Hair *hair)
@@ -250,7 +256,7 @@ static void hair_random(Hair *hair)
 
 void *BKE_hair_add(Main *bmain, const char *name)
 {
-  Hair *hair = BKE_id_new(bmain, ID_HA, name);
+  Hair *hair = static_cast<Hair *>(BKE_id_new(bmain, ID_HA, name));
 
   return hair;
 }
@@ -258,14 +264,14 @@ void *BKE_hair_add(Main *bmain, const char *name)
 BoundBox *BKE_hair_boundbox_get(Object *ob)
 {
   BLI_assert(ob->type == OB_HAIR);
-  Hair *hair = ob->data;
+  Hair *hair = static_cast<Hair *>(ob->data);
 
-  if (ob->runtime.bb != NULL && (ob->runtime.bb->flag & BOUNDBOX_DIRTY) == 0) {
+  if (ob->runtime.bb != nullptr && (ob->runtime.bb->flag & BOUNDBOX_DIRTY) == 0) {
     return ob->runtime.bb;
   }
 
-  if (ob->runtime.bb == NULL) {
-    ob->runtime.bb = MEM_callocN(sizeof(BoundBox), "hair boundbox");
+  if (ob->runtime.bb == nullptr) {
+    ob->runtime.bb = MEM_cnew<BoundBox>(__func__);
 
     float min[3], max[3];
     INIT_MINMAX(min, max);
@@ -289,10 +295,12 @@ BoundBox *BKE_hair_boundbox_get(Object *ob)
 
 void BKE_hair_update_customdata_pointers(Hair *hair)
 {
-  hair->co = CustomData_get_layer_named(&hair->pdata, CD_PROP_FLOAT3, HAIR_ATTR_POSITION);
-  hair->radius = CustomData_get_layer_named(&hair->pdata, CD_PROP_FLOAT, HAIR_ATTR_RADIUS);
-  hair->curves = CustomData_get_layer(&hair->cdata, CD_HAIRCURVE);
-  hair->mapping = CustomData_get_layer(&hair->cdata, CD_HAIRMAPPING);
+  hair->co = (float(*)[3])CustomData_get_layer_named(
+      &hair->pdata, CD_PROP_FLOAT3, HAIR_ATTR_POSITION);
+  hair->radius = (float *)CustomData_get_layer_named(
+      &hair->pdata, CD_PROP_FLOAT, HAIR_ATTR_RADIUS);
+  hair->curves = (HairCurve *)CustomData_get_layer(&hair->cdata, CD_HAIRCURVE);
+  hair->mapping = (HairMaping *)CustomData_get_layer(&hair->cdata, CD_HAIRMAPPING);
 }
 
 bool BKE_hair_customdata_required(Hair *UNUSED(hair), CustomDataLayer *layer)
@@ -304,10 +312,10 @@ bool BKE_hair_customdata_required(Hair *UNUSED(hair), CustomDataLayer *layer)
 
 Hair *BKE_hair_new_for_eval(const Hair *hair_src, int totpoint, int totcurve)
 {
-  Hair *hair_dst = BKE_id_new_nomain(ID_HA, NULL);
+  Hair *hair_dst = static_cast<Hair *>(BKE_id_new_nomain(ID_HA, nullptr));
 
   STRNCPY(hair_dst->id.name, hair_src->id.name);
-  hair_dst->mat = MEM_dupallocN(hair_src->mat);
+  hair_dst->mat = static_cast<Material **>(MEM_dupallocN(hair_src->mat));
   hair_dst->totcol = hair_src->totcol;
 
   hair_dst->totpoint = totpoint;
@@ -327,7 +335,7 @@ Hair *BKE_hair_copy_for_eval(Hair *hair_src, bool reference)
     flags |= LIB_ID_COPY_CD_REFERENCE;
   }
 
-  Hair *result = (Hair *)BKE_id_copy_ex(NULL, &hair_src->id, NULL, flags);
+  Hair *result = (Hair *)BKE_id_copy_ex(nullptr, &hair_src->id, nullptr, flags);
   return result;
 }
 
@@ -351,7 +359,7 @@ static Hair *hair_evaluate_modifiers(struct Depsgraph *depsgraph,
 
   /* Evaluate modifiers. */
   for (; md; md = md->next) {
-    const ModifierTypeInfo *mti = BKE_modifier_get_info(md->type);
+    const ModifierTypeInfo *mti = BKE_modifier_get_info(static_cast<ModifierType>(md->type));
 
     if (!BKE_modifier_is_enabled(scene, md, required_mode)) {
       continue;
@@ -370,7 +378,7 @@ static Hair *hair_evaluate_modifiers(struct Depsgraph *depsgraph,
       BKE_hair_update_customdata_pointers(hair);
 
       /* Created deformed coordinates array on demand. */
-      mti->deformVerts(md, &mectx, NULL, hair->co, hair->totpoint);
+      mti->deformVerts(md, &mectx, nullptr, hair->co, hair->totpoint);
     }
     else if (mti->modifyHair) {
       /* Ensure we are not modifying the input. */
@@ -383,7 +391,7 @@ static Hair *hair_evaluate_modifiers(struct Depsgraph *depsgraph,
       if (hair_next && hair_next != hair) {
         /* If the modifier returned a new hair, release the old one. */
         if (hair != hair_input) {
-          BKE_id_free(NULL, hair);
+          BKE_id_free(nullptr, hair);
         }
         hair = hair_next;
       }
@@ -399,7 +407,7 @@ void BKE_hair_data_update(struct Depsgraph *depsgraph, struct Scene *scene, Obje
   BKE_object_free_derived_caches(object);
 
   /* Evaluate modifiers. */
-  Hair *hair = object->data;
+  Hair *hair = static_cast<Hair *>(object->data);
   Hair *hair_eval = hair_evaluate_modifiers(depsgraph, scene, object, hair);
 
   /* Assign evaluated object. */
@@ -409,8 +417,8 @@ void BKE_hair_data_update(struct Depsgraph *depsgraph, struct Scene *scene, Obje
 
 /* Draw Cache */
 
-void (*BKE_hair_batch_cache_dirty_tag_cb)(Hair *hair, int mode) = NULL;
-void (*BKE_hair_batch_cache_free_cb)(Hair *hair) = NULL;
+void (*BKE_hair_batch_cache_dirty_tag_cb)(Hair *hair, int mode) = nullptr;
+void (*BKE_hair_batch_cache_free_cb)(Hair *hair) = nullptr;
 
 void BKE_hair_batch_cache_dirty_tag(Hair *hair, int mode)
 {
diff --git a/source/blender/draw/CMakeLists.txt b/source/blender/draw/CMakeLists.txt
index 30a3b8087c0.

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list