[Bf-blender-cvs] [4173877e87c] master: Cleanup: Declare variables where initialized

Hans Goudey noreply at git.blender.org
Fri Oct 9 22:08:07 CEST 2020


Commit: 4173877e87c5e867897e1060003138c4ff1c4417
Author: Hans Goudey
Date:   Fri Oct 9 15:08:01 2020 -0500
Branches: master
https://developer.blender.org/rB4173877e87c5e867897e1060003138c4ff1c4417

Cleanup: Declare variables where initialized

Also use LISTBASE_FOREACH macro in a few places.

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

M	source/blender/editors/object/object_modifier.c

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

diff --git a/source/blender/editors/object/object_modifier.c b/source/blender/editors/object/object_modifier.c
index 567e97a71ee..4eed9187d66 100644
--- a/source/blender/editors/object/object_modifier.c
+++ b/source/blender/editors/object/object_modifier.c
@@ -243,9 +243,7 @@ ModifierData *ED_object_modifier_add(
  * the modifier pointed to be 'exclude', otherwise returns false. */
 static bool object_has_modifier(const Object *ob, const ModifierData *exclude, ModifierType type)
 {
-  ModifierData *md;
-
-  for (md = ob->modifiers.first; md; md = md->next) {
+  LISTBASE_FOREACH (ModifierData *, md, &ob->modifiers) {
     if ((md != exclude) && (md->type == type)) {
       return true;
     }
@@ -309,10 +307,9 @@ static bool object_has_modifier_cb(Object *ob, void *data)
  * callback_data. */
 bool ED_object_multires_update_totlevels_cb(Object *ob, void *totlevel_v)
 {
-  ModifierData *md;
   int totlevel = *((char *)totlevel_v);
 
-  for (md = ob->modifiers.first; md; md = md->next) {
+  LISTBASE_FOREACH (ModifierData *, md, &ob->modifiers) {
     if (md->type == eModifierType_Multires) {
       multires_set_tot_level(ob, (MultiresModifierData *)md, totlevel);
       DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY);
@@ -392,9 +389,8 @@ bool ED_object_modifier_remove(
     ReportList *reports, Main *bmain, Scene *scene, Object *ob, ModifierData *md)
 {
   bool sort_depsgraph = false;
-  bool ok;
 
-  ok = object_modifier_remove(bmain, scene, ob, md, &sort_depsgraph);
+  bool ok = object_modifier_remove(bmain, scene, ob, md, &sort_depsgraph);
 
   if (!ok) {
     BKE_reportf(reports, RPT_ERROR, "Modifier '%s' not in object '%s'", md->name, ob->id.name);
@@ -417,9 +413,7 @@ void ED_object_modifier_clear(Main *bmain, Scene *scene, Object *ob)
   }
 
   while (md) {
-    ModifierData *next_md;
-
-    next_md = md->next;
+    ModifierData *next_md = md->next;
 
     object_modifier_remove(bmain, scene, ob, md, &sort_depsgraph);
 
@@ -547,16 +541,7 @@ bool ED_object_modifier_convert(ReportList *UNUSED(reports),
                                 Object *ob,
                                 ModifierData *md)
 {
-  Object *obn;
-  ParticleSystem *psys_orig, *psys_eval;
-  ParticleCacheKey *key, **cache;
-  ParticleSettings *part;
-  Mesh *me;
-  MVert *mvert;
-  MEdge *medge;
-  int a, k, kmax;
-  int totvert = 0, totedge = 0, cvert = 0;
-  int totpart = 0, totchild = 0;
+  int cvert = 0;
 
   if (md->type != eModifierType_ParticleSystem) {
     return false;
@@ -565,28 +550,29 @@ bool ED_object_modifier_convert(ReportList *UNUSED(reports),
     return false;
   }
 
-  psys_orig = ((ParticleSystemModifierData *)md)->psys;
-  part = psys_orig->part;
+  ParticleSystem *psys_orig = ((ParticleSystemModifierData *)md)->psys;
+  ParticleSettings *part = psys_orig->part;
 
   if (part->ren_as != PART_DRAW_PATH) {
     return false;
   }
-  psys_eval = psys_eval_get(depsgraph, ob, psys_orig);
+  ParticleSystem *psys_eval = psys_eval_get(depsgraph, ob, psys_orig);
   if (psys_eval->pathcache == NULL) {
     return false;
   }
 
-  totpart = psys_eval->totcached;
-  totchild = psys_eval->totchildcache;
+  int totpart = psys_eval->totcached;
+  int totchild = psys_eval->totchildcache;
 
   if (totchild && (part->draw & PART_DRAW_PARENT) == 0) {
     totpart = 0;
   }
 
   /* count */
-  cache = psys_eval->pathcache;
-  for (a = 0; a < totpart; a++) {
-    key = cache[a];
+  int totvert = 0, totedge = 0;
+  ParticleCacheKey **cache = psys_eval->pathcache;
+  for (int a = 0; a < totpart; a++) {
+    ParticleCacheKey *key = cache[a];
 
     if (key->segments > 0) {
       totvert += key->segments + 1;
@@ -595,8 +581,8 @@ bool ED_object_modifier_convert(ReportList *UNUSED(reports),
   }
 
   cache = psys_eval->childcache;
-  for (a = 0; a < totchild; a++) {
-    key = cache[a];
+  for (int a = 0; a < totchild; a++) {
+    ParticleCacheKey *key = cache[a];
 
     if (key->segments > 0) {
       totvert += key->segments + 1;
@@ -609,8 +595,8 @@ bool ED_object_modifier_convert(ReportList *UNUSED(reports),
   }
 
   /* add new mesh */
-  obn = BKE_object_add(bmain, view_layer, OB_MESH, NULL);
-  me = obn->data;
+  Object *obn = BKE_object_add(bmain, view_layer, OB_MESH, NULL);
+  Mesh *me = obn->data;
 
   me->totvert = totvert;
   me->totedge = totedge;
@@ -619,15 +605,15 @@ bool ED_object_modifier_convert(ReportList *UNUSED(reports),
   me->medge = CustomData_add_layer(&me->edata, CD_MEDGE, CD_CALLOC, NULL, totedge);
   me->mface = CustomData_add_layer(&me->fdata, CD_MFACE, CD_CALLOC, NULL, 0);
 
-  mvert = me->mvert;
-  medge = me->medge;
+  MVert *mvert = me->mvert;
+  MEdge *medge = me->medge;
 
   /* copy coordinates */
   cache = psys_eval->pathcache;
-  for (a = 0; a < totpart; a++) {
-    key = cache[a];
-    kmax = key->segments;
-    for (k = 0; k <= kmax; k++, key++, cvert++, mvert++) {
+  for (int a = 0; a < totpart; a++) {
+    ParticleCacheKey *key = cache[a];
+    int kmax = key->segments;
+    for (int k = 0; k <= kmax; k++, key++, cvert++, mvert++) {
       copy_v3_v3(mvert->co, key->co);
       if (k) {
         medge->v1 = cvert - 1;
@@ -643,10 +629,10 @@ bool ED_object_modifier_convert(ReportList *UNUSED(reports),
   }
 
   cache = psys_eval->childcache;
-  for (a = 0; a < totchild; a++) {
-    key = cache[a];
-    kmax = key->segments;
-    for (k = 0; k <= kmax; k++, key++, cvert++, mvert++) {
+  for (int a = 0; a < totchild; a++) {
+    ParticleCacheKey *key = cache[a];
+    int kmax = key->segments;
+    for (int k = 0; k <= kmax; k++, key++, cvert++, mvert++) {
       copy_v3_v3(mvert->co, key->co);
       if (k) {
         medge->v1 = cvert - 1;
@@ -708,7 +694,6 @@ static int modifier_apply_shape(Main *bmain,
     Mesh *mesh_applied;
     Mesh *me = ob->data;
     Key *key = me->key;
-    KeyBlock *kb;
 
     if (!BKE_modifier_is_same_topology(md_eval) || mti->type == eModifierTypeType_NonGeometrical) {
       BKE_report(reports, RPT_ERROR, "Only deforming modifiers can be applied to shapes");
@@ -726,11 +711,11 @@ static int modifier_apply_shape(Main *bmain,
       key->type = KEY_RELATIVE;
       /* if that was the first key block added, then it was the basis.
        * Initialize it with the mesh, and add another for the modifier */
-      kb = BKE_keyblock_add(key, NULL);
+      KeyBlock *kb = BKE_keyblock_add(key, NULL);
       BKE_keyblock_convert_from_mesh(me, key, kb);
     }
 
-    kb = BKE_keyblock_add(key, md_eval->name);
+    KeyBlock *kb = BKE_keyblock_add(key, md_eval->name);
     BKE_mesh_nomain_to_meshkey(mesh_applied, me, kb);
 
     BKE_id_free(NULL, mesh_applied);
@@ -792,8 +777,6 @@ static int modifier_apply_obdata(
     Object *object_eval = DEG_get_evaluated_object(depsgraph, ob);
     Curve *curve = ob->data;
     Curve *curve_eval = (Curve *)object_eval->data;
-    int numVerts;
-    float(*vertexCos)[3];
     ModifierEvalContext mectx = {depsgraph, object_eval, 0};
 
     if (ELEM(mti->type, eModifierTypeType_Constructive, eModifierTypeType_Nonconstructive)) {
@@ -806,7 +789,8 @@ static int modifier_apply_obdata(
                RPT_INFO,
                "Applied modifier only changed CV points, not tessellated/bevel vertices");
 
-    vertexCos = BKE_curve_nurbs_vert_coords_alloc(&curve_eval->nurb, &numVerts);
+    int numVerts;
+    float(*vertexCos)[3] = BKE_curve_nurbs_vert_coords_alloc(&curve_eval->nurb, &numVerts);
     mti->deformVerts(md_eval, &mectx, NULL, vertexCos, numVerts);
     BKE_curve_nurbs_vert_coords_apply(&curve->nurb, vertexCos, false);
 
@@ -822,11 +806,7 @@ static int modifier_apply_obdata(
 
   /* lattice modifier can be applied to particle system too */
   if (ob->particlesystem.first) {
-
-    ParticleSystem *psys = ob->particlesystem.first;
-
-    for (; psys; psys = psys->next) {
-
+    LISTBASE_FOREACH (ParticleSystem *, psys, &ob->particlesystem) {
       if (psys->part->type != PART_HAIR) {
         continue;
       }
@@ -847,8 +827,6 @@ bool ED_object_modifier_apply(Main *bmain,
                               int mode,
                               bool keep_modifier)
 {
-  int prev_mode;
-
   if (BKE_object_is_in_editmode(ob)) {
     BKE_report(reports, RPT_ERROR, "Modifiers cannot be applied in edit mode");
     return false;
@@ -875,7 +853,7 @@ bool ED_object_modifier_apply(Main *bmain,
   ModifierData *md_eval = (ob_eval) ? BKE_modifiers_findby_name(ob_eval, md->name) : md;
 
   /* allow apply of a not-realtime modifier, by first re-enabling realtime. */
-  prev_mode = md_eval->mode;
+  int prev_mode = md_eval->mode;
   md_eval->mode |= eModifierMode_Realtime;
 
   if (mode == MODIFIER_APPLY_SHAPE) {
@@ -953,20 +931,20 @@ static const EnumPropertyItem *modifier_add_itemf(bContext *C,
                                                   bool *r_free)
 {
   Object *ob = ED_object_active_context(C);
-  EnumPropertyItem *item = NULL;
-  const EnumPropertyItem *md_item, *group_item = NULL;
-  const ModifierTypeInfo *mti;
-  int totitem = 0, a;
 
   if (!ob) {
     return rna_enum_object_modifier_type_items;
   }
 
-  for (a = 0; rna_enum_object_modifier_type_items[a].identifier; a++) {
-    md_item = &rna_enum_object_modifier_type_items[a];
+  EnumPropertyItem *items = NULL;
+  int totitem = 0;
+
+  const EnumPropertyItem *group_item = NULL;
+  for (int a = 0; rna_enum_object_modifier_type_items[a].identifier; a++) {
+    const EnumPropertyItem *md_item = &rna_enum_object_modifier_type_items[a];
 
     if (md_item->identifier[0]) {
-      mti = BKE_modifier_get_info(md_item->value);
+      const ModifierTypeInfo *mti = BKE_modifier_get_info(md_item->value);
 
       if (mti->flags & eModifierTypeFlag_NoUserAdd) {
         continue;
@@ -978,23 +956,21 @@ static const EnumPropertyItem *modifier_add_itemf(bContext *C,
     }
     else {
       group_item = md_item;
-      md_item = NULL;
-
       continue;
     }
 
     if (group_item) {
-      RNA_enum_item_add(&item, &totitem, group_item);
+      RNA_enum_item_add(&items, &totitem, group_item);
       group_item = NULL;
     }
 
-    RNA_enum_item_add(&item, &totitem, md_item);
+    RNA_enum_item_add(&items, &totitem, md_item);
   }
 
-  RNA_enum_item_end(&item, &totitem);
+  RNA_enum_item_end(&items, &totitem);
   *r_free = true;
 
-  return ite

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list