[Bf-blender-cvs] [3b476d020ab] master: Cleanup: Move particle.c to C++

Hans Goudey noreply at git.blender.org
Mon Jan 9 18:59:23 CET 2023


Commit: 3b476d020aba99309549011308ebfee4e7712129
Author: Hans Goudey
Date:   Mon Jan 9 12:58:16 2023 -0500
Branches: master
https://developer.blender.org/rB3b476d020aba99309549011308ebfee4e7712129

Cleanup: Move particle.c to C++

In order to simplify a mesh data structure refactor. See T103343

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

M	source/blender/blenkernel/BKE_particle.h
M	source/blender/blenkernel/CMakeLists.txt
R090	source/blender/blenkernel/intern/particle.c	source/blender/blenkernel/intern/particle.cc

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

diff --git a/source/blender/blenkernel/BKE_particle.h b/source/blender/blenkernel/BKE_particle.h
index 618e69b5436..7dfbf3c5cc5 100644
--- a/source/blender/blenkernel/BKE_particle.h
+++ b/source/blender/blenkernel/BKE_particle.h
@@ -267,7 +267,7 @@ BLI_INLINE void psys_frand_vec(ParticleSystem *psys, unsigned int seed, float ve
 }
 
 /* ----------- functions needed outside particlesystem ---------------- */
-/* particle.c */
+/* particle.cc */
 
 /* Few helpers for count-all etc. */
 
@@ -540,7 +540,7 @@ void BKE_particlesystem_reset_all(struct Object *object);
 
 /* ----------- functions needed only inside particlesystem ------------ */
 
-/* particle.c */
+/* particle.cc */
 
 void psys_disable_all(struct Object *ob);
 void psys_enable_all(struct Object *ob);
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index 101baf1e983..7e11481b9c8 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -244,7 +244,7 @@ set(SRC
   intern/paint.cc
   intern/paint_canvas.cc
   intern/paint_toolslots.c
-  intern/particle.c
+  intern/particle.cc
   intern/particle_child.c
   intern/particle_distribute.c
   intern/particle_system.c
diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.cc
similarity index 90%
rename from source/blender/blenkernel/intern/particle.c
rename to source/blender/blenkernel/intern/particle.cc
index f9abe7de830..0b1d8606807 100644
--- a/source/blender/blenkernel/intern/particle.c
+++ b/source/blender/blenkernel/intern/particle.cc
@@ -8,9 +8,9 @@
 /* Allow using deprecated functionality for .blend file I/O. */
 #define DNA_DEPRECATED_ALLOW
 
-#include <math.h>
-#include <stdlib.h>
-#include <string.h>
+#include <cmath>
+#include <cstdlib>
+#include <cstring>
 
 #include "MEM_guardedalloc.h"
 
@@ -87,24 +87,25 @@ static void particle_settings_init(ID *id)
 
   MEMCPY_STRUCT_AFTER(particle_settings, DNA_struct_default_get(ParticleSettings), id);
 
-  particle_settings->effector_weights = BKE_effector_add_weights(NULL);
+  particle_settings->effector_weights = BKE_effector_add_weights(nullptr);
   particle_settings->pd = BKE_partdeflect_new(PFIELD_NULL);
   particle_settings->pd2 = BKE_partdeflect_new(PFIELD_NULL);
 }
 
-static void particle_settings_copy_data(Main *UNUSED(bmain),
+static void particle_settings_copy_data(Main * /*bmain*/,
                                         ID *id_dst,
                                         const ID *id_src,
-                                        const int UNUSED(flag))
+                                        const int /*flag*/)
 {
   ParticleSettings *particle_settings_dst = (ParticleSettings *)id_dst;
   const ParticleSettings *partticle_settings_src = (const ParticleSettings *)id_src;
 
   particle_settings_dst->pd = BKE_partdeflect_copy(partticle_settings_src->pd);
   particle_settings_dst->pd2 = BKE_partdeflect_copy(partticle_settings_src->pd2);
-  particle_settings_dst->effector_weights = MEM_dupallocN(
-      partticle_settings_src->effector_weights);
-  particle_settings_dst->fluid = MEM_dupallocN(partticle_settings_src->fluid);
+  particle_settings_dst->effector_weights = static_cast<EffectorWeights *>(
+      MEM_dupallocN(partticle_settings_src->effector_weights));
+  particle_settings_dst->fluid = static_cast<SPHFluidSettings *>(
+      MEM_dupallocN(partticle_settings_src->fluid));
 
   if (partticle_settings_src->clumpcurve) {
     particle_settings_dst->clumpcurve = BKE_curvemapping_copy(partticle_settings_src->clumpcurve);
@@ -120,7 +121,8 @@ static void particle_settings_copy_data(Main *UNUSED(bmain),
 
   for (int a = 0; a < MAX_MTEX; a++) {
     if (partticle_settings_src->mtex[a]) {
-      particle_settings_dst->mtex[a] = MEM_dupallocN(partticle_settings_src->mtex[a]);
+      particle_settings_dst->mtex[a] = static_cast<MTex *>(
+          MEM_dupallocN(partticle_settings_src->mtex[a]));
     }
   }
 
@@ -266,10 +268,10 @@ static void particle_settings_blend_write(BlendWriter *writer, ID *id, const voi
   }
 
   LISTBASE_FOREACH (ParticleDupliWeight *, dw, &part->instance_weights) {
-    /* update indices, but only if dw->ob is set (can be NULL after loading e.g.) */
-    if (dw->ob != NULL) {
+    /* update indices, but only if dw->ob is set (can be nullptr after loading e.g.) */
+    if (dw->ob != nullptr) {
       dw->index = 0;
-      if (part->instance_collection) { /* can be NULL if lining fails or set to None */
+      if (part->instance_collection) { /* can be nullptr if lining fails or set to None */
         FOREACH_COLLECTION_OBJECT_RECURSIVE_BEGIN (part->instance_collection, object) {
           if (object == dw->ob) {
             break;
@@ -300,10 +302,10 @@ static void particle_settings_blend_write(BlendWriter *writer, ID *id, const voi
   }
 }
 
-void BKE_particle_partdeflect_blend_read_data(BlendDataReader *UNUSED(reader), PartDeflect *pd)
+void BKE_particle_partdeflect_blend_read_data(BlendDataReader * /*reader*/, PartDeflect *pd)
 {
   if (pd) {
-    pd->rng = NULL;
+    pd->rng = nullptr;
   }
 }
 
@@ -479,33 +481,33 @@ static void particle_settings_blend_read_expand(BlendExpander *expander, ID *id)
 }
 
 IDTypeInfo IDType_ID_PA = {
-    .id_code = ID_PA,
-    .id_filter = FILTER_ID_PA,
-    .main_listbase_index = INDEX_ID_PA,
-    .struct_size = sizeof(ParticleSettings),
-    .name = "ParticleSettings",
-    .name_plural = "particles",
-    .translation_context = BLT_I18NCONTEXT_ID_PARTICLESETTINGS,
-    .flags = 0,
-    .asset_type_info = NULL,
-
-    .init_data = particle_settings_init,
-    .copy_data = particle_settings_copy_data,
-    .free_data = particle_settings_free_data,
-    .make_local = NULL,
-    .foreach_id = particle_settings_foreach_id,
-    .foreach_cache = NULL,
-    .foreach_path = NULL,
-    .owner_pointer_get = NULL,
-
-    .blend_write = particle_settings_blend_write,
-    .blend_read_data = particle_settings_blend_read_data,
-    .blend_read_lib = particle_settings_blend_read_lib,
-    .blend_read_expand = particle_settings_blend_read_expand,
-
-    .blend_read_undo_preserve = NULL,
-
-    .lib_override_apply_post = NULL,
+    /*id_code*/ ID_PA,
+    /*id_filter*/ FILTER_ID_PA,
+    /*main_listbase_index*/ INDEX_ID_PA,
+    /*struct_size*/ sizeof(ParticleSettings),
+    /*name*/ "ParticleSettings",
+    /*name_plural*/ "particles",
+    /*translation_context*/ BLT_I18NCONTEXT_ID_PARTICLESETTINGS,
+    /*flags*/ 0,
+    /*asset_type_info*/ nullptr,
+
+    /*init_data*/ particle_settings_init,
+    /*copy_data*/ particle_settings_copy_data,
+    /*free_data*/ particle_settings_free_data,
+    /*make_local*/ nullptr,
+    /*foreach_id*/ particle_settings_foreach_id,
+    /*foreach_cache*/ nullptr,
+    /*foreach_path*/ nullptr,
+    /*owner_pointer_get*/ nullptr,
+
+    /*blend_write*/ particle_settings_blend_write,
+    /*blend_read_data*/ particle_settings_blend_read_data,
+    /*blend_read_lib*/ particle_settings_blend_read_lib,
+    /*blend_read_expand*/ particle_settings_blend_read_expand,
+
+    /*blend_read_undo_preserve*/ nullptr,
+
+    /*lib_override_apply_post*/ nullptr,
 };
 
 uint PSYS_FRAND_SEED_OFFSET[PSYS_FRAND_COUNT];
@@ -597,11 +599,11 @@ static ParticleCacheKey **psys_alloc_path_cache_buffers(ListBase *bufs, int tot,
 
   tot = MAX2(tot, 1);
   totkey = 0;
-  cache = MEM_callocN(tot * sizeof(void *), "PathCacheArray");
+  cache = static_cast<ParticleCacheKey **>(MEM_callocN(tot * sizeof(void *), "PathCacheArray"));
 
   while (totkey < tot) {
     totbufkey = MIN2(tot - totkey, PATH_CACHE_BUF_SIZE);
-    buf = MEM_callocN(sizeof(LinkData), "PathCacheLinkData");
+    buf = static_cast<LinkData *>(MEM_callocN(sizeof(LinkData), "PathCacheLinkData"));
     buf->data = MEM_callocN(sizeof(ParticleCacheKey) * totbufkey * totkeys, "ParticleCacheKey");
 
     for (i = 0; i < totbufkey; i++) {
@@ -623,7 +625,7 @@ static void psys_free_path_cache_buffers(ParticleCacheKey **cache, ListBase *buf
     MEM_freeN(cache);
   }
 
-  for (buf = bufs->first; buf; buf = buf->next) {
+  for (buf = static_cast<LinkData *>(bufs->first); buf; buf = buf->next) {
     MEM_freeN(buf->data);
   }
   BLI_freelistN(bufs);
@@ -636,28 +638,29 @@ static void psys_free_path_cache_buffers(ParticleCacheKey **cache, ListBase *buf
 ParticleSystem *psys_get_current(Object *ob)
 {
   ParticleSystem *psys;
-  if (ob == NULL) {
-    return NULL;
+  if (ob == nullptr) {
+    return nullptr;
   }
 
-  for (psys = ob->particlesystem.first; psys; psys = psys->next) {
+  for (psys = static_cast<ParticleSystem *>(ob->particlesystem.first); psys; psys = psys->next) {
     if (psys->flag & PSYS_CURRENT) {
       return psys;
     }
   }
 
-  return NULL;
+  return nullptr;
 }
 short psys_get_current_num(Object *ob)
 {
   ParticleSystem *psys;
   short i;
 
-  if (ob == NULL) {
+  if (ob == nullptr) {
     return 0;
   }
 
-  for (psys = ob->particlesystem.first, i = 0; psys; psys = psys->next, i++) {
+  for (psys = static_cast<ParticleSystem *>(ob->particlesystem.first), i = 0; psys;
+       psys = psys->next, i++) {
     if (psys->flag & PSYS_CURRENT) {
       return i;
     }
@@ -670,11 +673,12 @@ void psys_set_current_num(Object *ob, int index)
   ParticleSystem *psys;
   short i;
 
-  if (ob == NULL) {
+  if (ob == nullptr) {
     return;
   }
 
-  for (psys = ob->particlesystem.first, i = 0; psys; psys = psys->next, i++) {
+  for (psys = static_cast<ParticleSystem *>(ob->particlesystem.first), i = 0; psys;
+       psys = psys->next, i++) {
     if (i == index) {
       psys->flag |= PSYS_CURRENT;
     }
@@ -690,9 +694,9 @@ void psys_sim_data_init(ParticleSimulationData *sim)
   ParticleSettings *part = psys->part;
 
   /* Prepare lattice deform. */
-  psys->lattice_deform_data = NULL;
+  psys->lattice_deform_data = nullptr;
   if (psys_in_edit_mode(sim->depsgraph, sim->psys) == 0) {
-    Object *lattice = NULL;
+    Object *lattice = nullptr;
     ModifierData *md = (ModifierData *)psys_get_modifier(sim->ob, sim->psys);
     bool for_render = DEG_get_mode(sim->depsgraph) == DAG_EVAL_RENDER;
     int mode = for_render ? eModifierMode_Render : eModifierMode_Realtime;
@@ -709,7 +713,7 @@ void psys_sim_data_init(ParticleSimu

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list