[Bf-blender-cvs] [00ff3dfb23b] master: Cleanup: Reduce variable scope in object.c

Hans Goudey noreply at git.blender.org
Tue Dec 22 17:36:28 CET 2020


Commit: 00ff3dfb23b33078c2e52e7c6ad418f736fd0bd1
Author: Hans Goudey
Date:   Tue Dec 22 10:35:18 2020 -0600
Branches: master
https://developer.blender.org/rB00ff3dfb23b33078c2e52e7c6ad418f736fd0bd1

Cleanup: Reduce variable scope in object.c

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

M	source/blender/blenkernel/intern/object.c

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

diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c
index 2fea868bd34..7ed906e2cea 100644
--- a/source/blender/blenkernel/intern/object.c
+++ b/source/blender/blenkernel/intern/object.c
@@ -1317,9 +1317,7 @@ ModifierData *BKE_object_active_modifier(const Object *ob)
 
 bool BKE_object_support_modifier_type_check(const Object *ob, int modifier_type)
 {
-  const ModifierTypeInfo *mti;
-
-  mti = BKE_modifier_get_info(modifier_type);
+  const ModifierTypeInfo *mti = BKE_modifier_get_info(modifier_type);
 
   /* Only geometry objects should be able to get modifiers T25291. */
   if (ob->type == OB_HAIR) {
@@ -1349,8 +1347,6 @@ bool BKE_object_support_modifier_type_check(const Object *ob, int modifier_type)
 
 bool BKE_object_copy_modifier(struct Object *ob_dst, const struct Object *ob_src, ModifierData *md)
 {
-  ModifierData *nmd = NULL;
-
   if (ELEM(md->type, eModifierType_Hook, eModifierType_Collision)) {
     return false;
   }
@@ -1369,7 +1365,7 @@ bool BKE_object_copy_modifier(struct Object *ob_dst, const struct Object *ob_src
       break;
   }
 
-  nmd = BKE_modifier_new(md->type);
+  ModifierData *nmd = BKE_modifier_new(md->type);
   BLI_strncpy(nmd->name, md->name, sizeof(nmd->name));
 
   if (md->type == eModifierType_Multires) {
@@ -1387,9 +1383,7 @@ bool BKE_object_copy_modifier(struct Object *ob_dst, const struct Object *ob_src
 
 bool BKE_object_copy_gpencil_modifier(struct Object *ob_dst, GpencilModifierData *md)
 {
-  GpencilModifierData *nmd = NULL;
-
-  nmd = BKE_gpencil_modifier_new(md->type);
+  GpencilModifierData *nmd = BKE_gpencil_modifier_new(md->type);
   BLI_strncpy(nmd->name, md->name, sizeof(nmd->name));
 
   const GpencilModifierTypeInfo *mti = BKE_gpencil_modifier_get_info(md->type);
@@ -1604,7 +1598,6 @@ void BKE_object_free_derived_caches(Object *ob)
 
 void BKE_object_free_caches(Object *object)
 {
-  ModifierData *md;
   short update_flag = 0;
 
   /* Free particle system caches holding paths. */
@@ -1617,7 +1610,7 @@ void BKE_object_free_caches(Object *object)
   }
 
   /* Free memory used by cached derived meshes in the particle system modifiers. */
-  for (md = object->modifiers.first; md != NULL; md = md->next) {
+  LISTBASE_FOREACH (ModifierData *, md, &object->modifiers) {
     if (md->type == eModifierType_ParticleSystem) {
       ParticleSystemModifierData *psmd = (ParticleSystemModifierData *)md;
       if (psmd->mesh_final) {
@@ -1845,19 +1838,16 @@ int BKE_object_visibility(const Object *ob, const int dag_eval_mode)
 
 bool BKE_object_exists_check(Main *bmain, const Object *obtest)
 {
-  Object *ob;
-
   if (obtest == NULL) {
     return false;
   }
 
-  ob = bmain->objects.first;
-  while (ob) {
+  LISTBASE_FOREACH (Object *, ob, &bmain->objects) {
     if (ob == obtest) {
       return true;
     }
-    ob = ob->id.next;
   }
+
   return false;
 }
 
@@ -2012,14 +2002,12 @@ int BKE_object_obdata_to_type(const ID *id)
  */
 Object *BKE_object_add_only_object(Main *bmain, int type, const char *name)
 {
-  Object *ob;
-
   if (!name) {
     name = get_obdata_defname(type);
   }
 
   /* We cannot use #BKE_id_new here as we need some custom initialization code. */
-  ob = BKE_libblock_alloc(bmain, ID_OB, name, 0);
+  Object *ob = BKE_libblock_alloc(bmain, ID_OB, name, 0);
 
   /* We increase object user count when linking to Collections. */
   id_us_min(&ob->id);
@@ -2032,9 +2020,7 @@ Object *BKE_object_add_only_object(Main *bmain, int type, const char *name)
 
 static Object *object_add_common(Main *bmain, ViewLayer *view_layer, int type, const char *name)
 {
-  Object *ob;
-
-  ob = BKE_object_add_only_object(bmain, type, name);
+  Object *ob = BKE_object_add_only_object(bmain, type, name);
   ob->data = BKE_object_obdata_add_from_type(bmain, type, name);
   BKE_view_layer_base_deselect_all(view_layer);
 
@@ -2053,16 +2039,12 @@ static Object *object_add_common(Main *bmain, ViewLayer *view_layer, int type, c
  */
 Object *BKE_object_add(Main *bmain, ViewLayer *view_layer, int type, const char *name)
 {
-  Object *ob;
-  Base *base;
-  LayerCollection *layer_collection;
-
-  ob = object_add_common(bmain, view_layer, type, name);
+  Object *ob = object_add_common(bmain, view_layer, type, name);
 
-  layer_collection = BKE_layer_collection_get_active(view_layer);
+  LayerCollection *layer_collection = BKE_layer_collection_get_active(view_layer);
   BKE_collection_object_add(bmain, layer_collection->collection, ob);
 
-  base = BKE_view_layer_base_find(view_layer, ob);
+  Base *base = BKE_view_layer_base_find(view_layer, ob);
   BKE_view_layer_base_select_and_set_active(view_layer, base);
 
   return ob;
@@ -2076,13 +2058,10 @@ Object *BKE_object_add(Main *bmain, ViewLayer *view_layer, int type, const char
 Object *BKE_object_add_from(
     Main *bmain, Scene *scene, ViewLayer *view_layer, int type, const char *name, Object *ob_src)
 {
-  Object *ob;
-  Base *base;
-
-  ob = object_add_common(bmain, view_layer, type, name);
+  Object *ob = object_add_common(bmain, view_layer, type, name);
   BKE_collection_object_add_from(bmain, scene, ob_src, ob);
 
-  base = BKE_view_layer_base_find(view_layer, ob);
+  Base *base = BKE_view_layer_base_find(view_layer, ob);
   BKE_view_layer_base_select_and_set_active(view_layer, base);
 
   return ob;
@@ -2100,12 +2079,8 @@ Object *BKE_object_add_from(
 Object *BKE_object_add_for_data(
     Main *bmain, ViewLayer *view_layer, int type, const char *name, ID *data, bool do_id_user)
 {
-  Object *ob;
-  Base *base;
-  LayerCollection *layer_collection;
-
   /* same as object_add_common, except we don't create new ob->data */
-  ob = BKE_object_add_only_object(bmain, type, name);
+  Object *ob = BKE_object_add_only_object(bmain, type, name);
   ob->data = data;
   if (do_id_user) {
     id_us_plus(data);
@@ -2115,10 +2090,10 @@ Object *BKE_object_add_for_data(
   DEG_id_tag_update_ex(
       bmain, &ob->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY | ID_RECALC_ANIMATION);
 
-  layer_collection = BKE_layer_collection_get_active(view_layer);
+  LayerCollection *layer_collection = BKE_layer_collection_get_active(view_layer);
   BKE_collection_object_add(bmain, layer_collection->collection, ob);
 
-  base = BKE_view_layer_base_find(view_layer, ob);
+  Base *base = BKE_view_layer_base_find(view_layer, ob);
   BKE_view_layer_base_select_and_set_active(view_layer, base);
 
   return ob;
@@ -2127,7 +2102,6 @@ Object *BKE_object_add_for_data(
 void BKE_object_copy_softbody(struct Object *ob_dst, const struct Object *ob_src, const int flag)
 {
   SoftBody *sb = ob_src->soft;
-  SoftBody *sbn;
   bool tagged_no_main = ob_dst->id.tag & LIB_TAG_NO_MAIN;
 
   ob_dst->softflag = ob_src->softflag;
@@ -2136,7 +2110,7 @@ void BKE_object_copy_softbody(struct Object *ob_dst, const struct Object *ob_src
     return;
   }
 
-  sbn = MEM_dupallocN(sb);
+  SoftBody *sbn = MEM_dupallocN(sb);
 
   if ((flag & LIB_ID_COPY_CACHES) == 0) {
     sbn->totspring = sbn->totpoint = 0;
@@ -2234,22 +2208,19 @@ ParticleSystem *BKE_object_copy_particlesystem(ParticleSystem *psys, const int f
 
 void BKE_object_copy_particlesystems(Object *ob_dst, const Object *ob_src, const int flag)
 {
-  ParticleSystem *psys, *npsys;
-  ModifierData *md;
-
   if (ob_dst->type != OB_MESH) {
     /* currently only mesh objects can have soft body */
     return;
   }
 
   BLI_listbase_clear(&ob_dst->particlesystem);
-  for (psys = ob_src->particlesystem.first; psys; psys = psys->next) {
-    npsys = BKE_object_copy_particlesystem(psys, flag);
+  LISTBASE_FOREACH (ParticleSystem *, psys, &ob_src->particlesystem) {
+    ParticleSystem *npsys = BKE_object_copy_particlesystem(psys, flag);
 
     BLI_addtail(&ob_dst->particlesystem, npsys);
 
     /* need to update particle modifiers too */
-    for (md = ob_dst->modifiers.first; md; md = md->next) {
+    LISTBASE_FOREACH (ModifierData *, md, &ob_dst->modifiers) {
       if (md->type == eModifierType_ParticleSystem) {
         ParticleSystemModifierData *psmd = (ParticleSystemModifierData *)md;
         if (psmd->psys == psys) {
@@ -2281,22 +2252,18 @@ void BKE_object_copy_particlesystems(Object *ob_dst, const Object *ob_src, const
 
 static void copy_object_pose(Object *obn, const Object *ob, const int flag)
 {
-  bPoseChannel *chan;
-
   /* note: need to clear obn->pose pointer first,
    * so that BKE_pose_copy_data works (otherwise there's a crash) */
   obn->pose = NULL;
   BKE_pose_copy_data_ex(&obn->pose, ob->pose, flag, true); /* true = copy constraints */
 
-  for (chan = obn->pose->chanbase.first; chan; chan = chan->next) {
-    bConstraint *con;
-
+  LISTBASE_FOREACH (bPoseChannel *, chan, &obn->pose->chanbase) {
     chan->flag &= ~(POSE_LOC | POSE_ROT | POSE_SIZE);
 
     /* XXX Remapping object pointing onto itself should be handled by generic
      *     BKE_library_remap stuff, but...
      *     the flush_constraint_targets callback am not sure about, so will delay that for now. */
-    for (con = chan->constraints.first; con; con = con->next) {
+    LISTBASE_FOREACH (bConstraint *, con, &chan->constraints) {
       const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con);
       ListBase targets = {NULL, NULL};
       bConstraintTarget *ct;
@@ -3159,7 +3126,6 @@ static bool ob_parcurve(Object *ob, Object *par, float r_mat[4][4])
 
 static void ob_parbone(Object *ob, Object *par, float r_mat[4][4])
 {
-  bPoseChannel *pchan;
   float vec[3];
 
   if (par->type != OB_ARMATURE) {
@@ -3168,7 +3134,7 @@ static void ob_parbone(Object *ob, Object *par, float r_mat[4][4])
   }
 
   /* Make sure the bone is still valid */
-  pchan = BKE_pose_channel_find_name(par->pose, ob->parsubstr);
+  bPoseChannel *pchan = BKE_pose_channel_find_name(par->pose, ob->parsubstr);
   if (!pchan || !pchan->bone) {
     CLOG_ERROR(
         &LOG, "Object %s with Bone parent: bone %s doesn't exist", ob->id.name + 2, ob->parsubstr);
@@ -3312,7 +3278,6 @@ static void give_parvert(Object *par, int nr, float vec[3])
 
 static void ob_parvert3(Object *ob, Object *par, float r_mat[4][4])
 {
-
   /* in local ob space */
   if (OB_TYPE_SUPPORT_PARVERT(par->type)) {
     float cmat[3][3], v1[3], v2[3], v3[3], q[4];
@@ -3336,14 +3301,13 @@ void BKE_objec

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list