[Bf-blender-cvs] [f639b59a298] master: Cleanup: convert brush.c to C++

Brecht Van Lommel noreply at git.blender.org
Fri Jul 8 16:42:24 CEST 2022


Commit: f639b59a298d42410f4760d125b3e2b524199373
Author: Brecht Van Lommel
Date:   Wed Jun 22 20:16:36 2022 +0200
Branches: master
https://developer.blender.org/rBf639b59a298d42410f4760d125b3e2b524199373

Cleanup: convert brush.c to C++

In preparation of refactoring for texture nodes.

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

M	source/blender/blenkernel/CMakeLists.txt
R095	source/blender/blenkernel/intern/brush.c	source/blender/blenkernel/intern/brush.cc

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

diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index d0f9a67f167..044a306a1b9 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -88,7 +88,7 @@ set(SRC
   intern/blendfile_link_append.c
   intern/boids.c
   intern/bpath.c
-  intern/brush.c
+  intern/brush.cc
   intern/bvhutils.cc
   intern/cachefile.c
   intern/callbacks.c
diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.cc
similarity index 95%
rename from source/blender/blenkernel/intern/brush.c
rename to source/blender/blenkernel/intern/brush.cc
index dd38af126fe..ffa63f9792f 100644
--- a/source/blender/blenkernel/intern/brush.c
+++ b/source/blender/blenkernel/intern/brush.cc
@@ -68,12 +68,12 @@ static void brush_copy_data(Main *UNUSED(bmain), ID *id_dst, const ID *id_src, c
     BKE_previewimg_id_copy(&brush_dst->id, &brush_src->id);
   }
   else {
-    brush_dst->preview = NULL;
+    brush_dst->preview = nullptr;
   }
 
   brush_dst->curve = BKE_curvemapping_copy(brush_src->curve);
-  if (brush_src->gpencil_settings != NULL) {
-    brush_dst->gpencil_settings = MEM_dupallocN(brush_src->gpencil_settings);
+  if (brush_src->gpencil_settings != nullptr) {
+    brush_dst->gpencil_settings = MEM_cnew(__func__, *(brush_src->gpencil_settings));
     brush_dst->gpencil_settings->curve_sensitivity = BKE_curvemapping_copy(
         brush_src->gpencil_settings->curve_sensitivity);
     brush_dst->gpencil_settings->curve_strength = BKE_curvemapping_copy(
@@ -94,8 +94,8 @@ static void brush_copy_data(Main *UNUSED(bmain), ID *id_dst, const ID *id_src, c
     brush_dst->gpencil_settings->curve_rand_value = BKE_curvemapping_copy(
         brush_src->gpencil_settings->curve_rand_value);
   }
-  if (brush_src->curves_sculpt_settings != NULL) {
-    brush_dst->curves_sculpt_settings = MEM_dupallocN(brush_src->curves_sculpt_settings);
+  if (brush_src->curves_sculpt_settings != nullptr) {
+    brush_dst->curves_sculpt_settings = MEM_cnew(__func__, *(brush_src->curves_sculpt_settings));
   }
 
   /* enable fake user by default */
@@ -110,7 +110,7 @@ static void brush_free_data(ID *id)
   }
   BKE_curvemapping_free(brush->curve);
 
-  if (brush->gpencil_settings != NULL) {
+  if (brush->gpencil_settings != nullptr) {
     BKE_curvemapping_free(brush->gpencil_settings->curve_sensitivity);
     BKE_curvemapping_free(brush->gpencil_settings->curve_strength);
     BKE_curvemapping_free(brush->gpencil_settings->curve_jitter);
@@ -124,7 +124,7 @@ static void brush_free_data(ID *id)
 
     MEM_SAFE_FREE(brush->gpencil_settings);
   }
-  if (brush->curves_sculpt_settings != NULL) {
+  if (brush->curves_sculpt_settings != nullptr) {
     MEM_freeN(brush->curves_sculpt_settings);
   }
 
@@ -153,7 +153,7 @@ static void brush_make_local(Main *bmain, ID *id, const int flags)
     /* NOTE: assert below ensures that the comment above is valid, and that exception is
      * acceptable for the time being. */
     BKE_lib_id_make_local(bmain, &brush->clone.image->id, 0);
-    BLI_assert(!ID_IS_LINKED(brush->clone.image) && brush->clone.image->id.newid == NULL);
+    BLI_assert(!ID_IS_LINKED(brush->clone.image) && brush->clone.image->id.newid == nullptr);
   }
 
   if (force_local) {
@@ -268,7 +268,7 @@ static void brush_blend_read_data(BlendDataReader *reader, ID *id)
 
   /* grease pencil */
   BLO_read_data_address(reader, &brush->gpencil_settings);
-  if (brush->gpencil_settings != NULL) {
+  if (brush->gpencil_settings != nullptr) {
     BLO_read_data_address(reader, &brush->gpencil_settings->curve_sensitivity);
     BLO_read_data_address(reader, &brush->gpencil_settings->curve_strength);
     BLO_read_data_address(reader, &brush->gpencil_settings->curve_jitter);
@@ -319,8 +319,8 @@ static void brush_blend_read_data(BlendDataReader *reader, ID *id)
 
   BLO_read_data_address(reader, &brush->curves_sculpt_settings);
 
-  brush->preview = NULL;
-  brush->icon_imbuf = NULL;
+  brush->preview = nullptr;
+  brush->icon_imbuf = nullptr;
 }
 
 static void brush_blend_read_lib(BlendLibReader *reader, ID *id)
@@ -335,7 +335,7 @@ static void brush_blend_read_lib(BlendLibReader *reader, ID *id)
   BLO_read_id_address(reader, brush->id.lib, &brush->paint_curve);
 
   /* link default grease pencil palette */
-  if (brush->gpencil_settings != NULL) {
+  if (brush->gpencil_settings != nullptr) {
     if (brush->gpencil_settings->flag & GP_BRUSH_MATERIAL_PINNED) {
       BLO_read_id_address(reader, brush->id.lib, &brush->gpencil_settings->material);
 
@@ -344,7 +344,7 @@ static void brush_blend_read_lib(BlendLibReader *reader, ID *id)
       }
     }
     else {
-      brush->gpencil_settings->material = NULL;
+      brush->gpencil_settings->material = nullptr;
     }
   }
 }
@@ -356,20 +356,20 @@ static void brush_blend_read_expand(BlendExpander *expander, ID *id)
   BLO_expand(expander, brush->mask_mtex.tex);
   BLO_expand(expander, brush->clone.image);
   BLO_expand(expander, brush->paint_curve);
-  if (brush->gpencil_settings != NULL) {
+  if (brush->gpencil_settings != nullptr) {
     BLO_expand(expander, brush->gpencil_settings->material);
   }
 }
 
 static int brush_undo_preserve_cb(LibraryIDLinkCallbackData *cb_data)
 {
-  BlendLibReader *reader = cb_data->user_data;
+  BlendLibReader *reader = (BlendLibReader *)cb_data->user_data;
   ID *id_old = *cb_data->id_pointer;
   /* Old data has not been remapped to new values of the pointers, if we want to keep the old
    * pointer here we need its new address. */
-  ID *id_old_new = id_old != NULL ? BLO_read_get_new_id_address(reader, id_old->lib, id_old) :
-                                    NULL;
-  BLI_assert(id_old_new == NULL || ELEM(id_old, id_old_new, id_old_new->orig_id));
+  ID *id_old_new = id_old != nullptr ? BLO_read_get_new_id_address(reader, id_old->lib, id_old) :
+                                       nullptr;
+  BLI_assert(id_old_new == nullptr || ELEM(id_old, id_old_new, id_old_new->orig_id));
   if (cb_data->cb_flag & IDWALK_CB_USER) {
     id_us_plus_no_lib(id_old_new);
     id_us_min(id_old);
@@ -381,11 +381,11 @@ static int brush_undo_preserve_cb(LibraryIDLinkCallbackData *cb_data)
 static void brush_undo_preserve(BlendLibReader *reader, ID *id_new, ID *id_old)
 {
   /* Whole Brush is preserved across undo-steps. */
-  BKE_lib_id_swap(NULL, id_new, id_old);
+  BKE_lib_id_swap(nullptr, id_new, id_old);
 
   /* `id_new` now has content from `id_old`, we need to ensure those old ID pointers are valid.
    * NOTE: Since we want to re-use all old pointers here, code is much simpler than for Scene. */
-  BKE_library_foreach_ID_link(NULL, id_new, brush_undo_preserve_cb, reader, IDWALK_NOP);
+  BKE_library_foreach_ID_link(nullptr, id_new, brush_undo_preserve_cb, reader, IDWALK_NOP);
 
   /* NOTE: We do not swap IDProperties, as dealing with potential ID pointers in those would be
    *       fairly delicate. */
@@ -393,33 +393,33 @@ static void brush_undo_preserve(BlendLibReader *reader, ID *id_new, ID *id_old)
 }
 
 IDTypeInfo IDType_ID_BR = {
-    .id_code = ID_BR,
-    .id_filter = FILTER_ID_BR,
-    .main_listbase_index = INDEX_ID_BR,
-    .struct_size = sizeof(Brush),
-    .name = "Brush",
-    .name_plural = "brushes",
-    .translation_context = BLT_I18NCONTEXT_ID_BRUSH,
-    .flags = IDTYPE_FLAGS_NO_ANIMDATA,
-    .asset_type_info = NULL,
-
-    .init_data = brush_init_data,
-    .copy_data = brush_copy_data,
-    .free_data = brush_free_data,
-    .make_local = brush_make_local,
-    .foreach_id = brush_foreach_id,
-    .foreach_cache = NULL,
-    .foreach_path = brush_foreach_path,
-    .owner_get = NULL,
-
-    .blend_write = brush_blend_write,
-    .blend_read_data = brush_blend_read_data,
-    .blend_read_lib = brush_blend_read_lib,
-    .blend_read_expand = brush_blend_read_expand,
-
-    .blend_read_undo_preserve = brush_undo_preserve,
-
-    .lib_override_apply_post = NULL,
+    /* id_code */ ID_BR,
+    /* id_filter */ FILTER_ID_BR,
+    /* main_listbase_index */ INDEX_ID_BR,
+    /* struct_size */ sizeof(Brush),
+    /* name */ "Brush",
+    /* name_plural */ "brushes",
+    /* translation_context */ BLT_I18NCONTEXT_ID_BRUSH,
+    /* flags */ IDTYPE_FLAGS_NO_ANIMDATA,
+    /* asset_type_info */ nullptr,
+
+    /* init_data */ brush_init_data,
+    /* copy_data */ brush_copy_data,
+    /* free_data */ brush_free_data,
+    /* make_local */ brush_make_local,
+    /* foreach_id */ brush_foreach_id,
+    /* foreach_cache */ nullptr,
+    /* foreach_path */ brush_foreach_path,
+    /* owner_get */ nullptr,
+
+    /* blend_write */ brush_blend_write,
+    /* blend_read_data */ brush_blend_read_data,
+    /* blend_read_lib */ brush_blend_read_lib,
+    /* blend_read_expand */ brush_blend_read_expand,
+
+    /* blend_read_undo_preserve */ brush_undo_preserve,
+
+    /* lib_override_apply_post */ nullptr,
 };
 
 static RNG *brush_rng;
@@ -432,11 +432,11 @@ void BKE_brush_system_init(void)
 
 void BKE_brush_system_exit(void)
 {
-  if (brush_rng == NULL) {
+  if (brush_rng == nullptr) {
     return;
   }
   BLI_rng_free(brush_rng);
-  brush_rng = NULL;
+  brush_rng = nullptr;
 }
 
 static void brush_defaults(Brush *brush)
@@ -494,9 +494,7 @@ static void brush_defaults(Brush *brush)
 
 Brush *BKE_brush_add(Main *bmain, const char *name, const eObjectMode ob_mode)
 {
-  Brush *brush;
-
-  brush = BKE_id_new(bmain, ID_BR, name);
+  Brush *brush = (Brush *)BKE_id_new(bmain, ID_BR, name);
 
   brush->ob_mode = ob_mode;
 
@@ -509,8 +507,8 @@ Brush *BKE_brush_add(Main *bmain, const char *name, const eObjectMode ob_mode)
 
 void BKE_brush_init_gpencil_settings(Brush *brush)
 {
-  if (brush->gpencil_settings == NULL) {
-    brush->gpencil_settings = MEM_callocN(sizeof(BrushGpencilSettings), "BrushGpencilSettings");
+  if (brush->gpencil_settings == nullptr) {
+    brush->gpencil_settings = MEM_cnew<BrushGpencilSettings>("BrushGpencilSettings");
   }
 
   brush->gpencil_settings->draw_smoothlvl = 1;
@@ -536,7 +534,7 @@ void BKE_brush_init_gpencil_settings(Brush *brush)
 
 Brush *BKE_brush_add_gpencil(Main *bmain, ToolSettings *ts, const char *name, eObjectMode mode)
 {
-  Paint *paint = NULL;
+  Paint *paint = nullptr;
   Brush *b

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list