[Bf-blender-cvs] [7ab8d7c939e] master: Cleanup: Declare variables where initialized

Hans Goudey noreply at git.blender.org
Fri Oct 9 23:40:09 CEST 2020


Commit: 7ab8d7c939e82e882410313e7d45113f5cd45f48
Author: Hans Goudey
Date:   Fri Oct 9 16:39:39 2020 -0500
Branches: master
https://developer.blender.org/rB7ab8d7c939e82e882410313e7d45113f5cd45f48

Cleanup: Declare variables where initialized

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

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

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

diff --git a/source/blender/editors/object/object_add.c b/source/blender/editors/object/object_add.c
index 96f13578513..860876f4dc2 100644
--- a/source/blender/editors/object/object_add.c
+++ b/source/blender/editors/object/object_add.c
@@ -528,7 +528,6 @@ Object *ED_object_add_type_with_obdata(bContext *C,
   Main *bmain = CTX_data_main(C);
   Scene *scene = CTX_data_scene(C);
   ViewLayer *view_layer = CTX_data_view_layer(C);
-  Object *ob;
 
   /* For as long scene has editmode... */
   {
@@ -539,6 +538,7 @@ Object *ED_object_add_type_with_obdata(bContext *C,
   }
 
   /* deselects all, sets active object */
+  Object *ob;
   if (obdata != NULL) {
     BLI_assert(type == BKE_object_obdata_to_type(obdata));
     ob = BKE_object_add_for_data(bmain, view_layer, type, name, obdata, true);
@@ -595,18 +595,16 @@ Object *ED_object_add_type(bContext *C,
 /* for object add operator */
 static int object_add_exec(bContext *C, wmOperator *op)
 {
-  Object *ob;
-  bool enter_editmode;
   ushort local_view_bits;
+  bool enter_editmode;
   float loc[3], rot[3], radius;
-
   WM_operator_view3d_unit_defaults(C, op);
   if (!ED_object_add_generic_get_opts(
           C, op, 'Z', loc, rot, NULL, &enter_editmode, &local_view_bits, NULL)) {
     return OPERATOR_CANCELLED;
   }
   radius = RNA_float_get(op->ptr, "radius");
-  ob = ED_object_add_type(
+  Object *ob = ED_object_add_type(
       C, RNA_enum_get(op->ptr, "type"), NULL, loc, rot, enter_editmode, local_view_bits);
 
   if (ob->type == OB_LATTICE) {
@@ -666,27 +664,22 @@ static const char *get_lightprobe_defname(int type)
 
 static int lightprobe_add_exec(bContext *C, wmOperator *op)
 {
-  Object *ob;
-  LightProbe *probe;
-  int type;
   bool enter_editmode;
   ushort local_view_bits;
   float loc[3], rot[3];
-  float radius;
-
   WM_operator_view3d_unit_defaults(C, op);
   if (!ED_object_add_generic_get_opts(
           C, op, 'Z', loc, rot, NULL, &enter_editmode, &local_view_bits, NULL)) {
     return OPERATOR_CANCELLED;
   }
-  type = RNA_enum_get(op->ptr, "type");
-  radius = RNA_float_get(op->ptr, "radius");
+  int type = RNA_enum_get(op->ptr, "type");
+  float radius = RNA_float_get(op->ptr, "radius");
 
-  ob = ED_object_add_type(
+  Object *ob = ED_object_add_type(
       C, OB_LIGHTPROBE, get_lightprobe_defname(type), loc, rot, false, local_view_bits);
   copy_v3_fl(ob->scale, radius);
 
-  probe = (LightProbe *)ob->data;
+  LightProbe *probe = (LightProbe *)ob->data;
 
   BKE_lightprobe_type_set(probe, type);
 
@@ -765,22 +758,18 @@ static const char *get_effector_defname(ePFieldType type)
 
 static int effector_add_exec(bContext *C, wmOperator *op)
 {
-  Object *ob;
-  int type;
   bool enter_editmode;
   ushort local_view_bits;
   float loc[3], rot[3];
-  float mat[4][4];
-  float dia;
-
   WM_operator_view3d_unit_defaults(C, op);
   if (!ED_object_add_generic_get_opts(
           C, op, 'Z', loc, rot, NULL, &enter_editmode, &local_view_bits, NULL)) {
     return OPERATOR_CANCELLED;
   }
-  type = RNA_enum_get(op->ptr, "type");
-  dia = RNA_float_get(op->ptr, "radius");
+  int type = RNA_enum_get(op->ptr, "type");
+  float dia = RNA_float_get(op->ptr, "radius");
 
+  Object *ob;
   if (type == PFIELD_GUIDE) {
     Main *bmain = CTX_data_main(C);
     Scene *scene = CTX_data_scene(C);
@@ -791,6 +780,8 @@ static int effector_add_exec(bContext *C, wmOperator *op)
     cu = ob->data;
     cu->flag |= CU_PATH | CU_3D;
     ED_object_editmode_enter_ex(bmain, scene, ob, 0);
+
+    float mat[4][4];
     ED_object_new_primitive_matrix(C, ob, loc, rot, mat);
     BLI_addtail(&cu->editnurb->nurbs,
                 ED_curve_add_nurbs_primitive(C, ob, mat, CU_NURBS | CU_PRIM_PATH, dia));
@@ -845,20 +836,18 @@ static int object_camera_add_exec(bContext *C, wmOperator *op)
 {
   View3D *v3d = CTX_wm_view3d(C);
   Scene *scene = CTX_data_scene(C);
-  Object *ob;
-  Camera *cam;
-  bool enter_editmode;
-  ushort local_view_bits;
-  float loc[3], rot[3];
 
   /* force view align for cameras */
   RNA_enum_set(op->ptr, "align", ALIGN_VIEW);
 
+  ushort local_view_bits;
+  bool enter_editmode;
+  float loc[3], rot[3];
   if (!ED_object_add_generic_get_opts(
           C, op, 'Z', loc, rot, NULL, &enter_editmode, &local_view_bits, NULL)) {
     return OPERATOR_CANCELLED;
   }
-  ob = ED_object_add_type(C, OB_CAMERA, NULL, loc, rot, false, local_view_bits);
+  Object *ob = ED_object_add_type(C, OB_CAMERA, NULL, loc, rot, false, local_view_bits);
 
   if (v3d) {
     if (v3d->camera == NULL) {
@@ -869,7 +858,7 @@ static int object_camera_add_exec(bContext *C, wmOperator *op)
     }
   }
 
-  cam = ob->data;
+  Camera *cam = ob->data;
   cam->drawsize = v3d ? ED_view3d_grid_scale(scene, v3d, NULL) : ED_scene_grid_scale(scene, NULL);
 
   return OPERATOR_FINISHED;
@@ -909,19 +898,18 @@ static int object_metaball_add_exec(bContext *C, wmOperator *op)
   Main *bmain = CTX_data_main(C);
   Scene *scene = CTX_data_scene(C);
   ViewLayer *view_layer = CTX_data_view_layer(C);
-  Object *obedit = OBEDIT_FROM_VIEW_LAYER(view_layer);
-  bool newob = false;
-  bool enter_editmode;
+
   ushort local_view_bits;
+  bool enter_editmode;
   float loc[3], rot[3];
-  float mat[4][4];
-  float dia;
-
   WM_operator_view3d_unit_defaults(C, op);
   if (!ED_object_add_generic_get_opts(
           C, op, 'Z', loc, rot, NULL, &enter_editmode, &local_view_bits, NULL)) {
     return OPERATOR_CANCELLED;
   }
+
+  bool newob = false;
+  Object *obedit = OBEDIT_FROM_VIEW_LAYER(view_layer);
   if (obedit == NULL || obedit->type != OB_MBALL) {
     obedit = ED_object_add_type(C, OB_MBALL, NULL, loc, rot, true, local_view_bits);
     newob = true;
@@ -930,11 +918,12 @@ static int object_metaball_add_exec(bContext *C, wmOperator *op)
     DEG_id_tag_update(&obedit->id, ID_RECALC_GEOMETRY);
   }
 
+  float mat[4][4];
   ED_object_new_primitive_matrix(C, obedit, loc, rot, mat);
   /* Halving here is done to account for constant values from #BKE_mball_element_add.
    * While the default radius of the resulting meta element is 2,
    * we want to pass in 1 so other values such as resolution are scaled by 1.0. */
-  dia = RNA_float_get(op->ptr, "radius") / 2;
+  float dia = RNA_float_get(op->ptr, "radius") / 2;
 
   ED_mball_add_primitive(C, obedit, newob, mat, dia, RNA_enum_get(op->ptr, "type"));
 
@@ -1621,15 +1610,14 @@ void OBJECT_OT_data_instance_add(wmOperatorType *ot)
 static int object_speaker_add_exec(bContext *C, wmOperator *op)
 {
   Main *bmain = CTX_data_main(C);
-  Object *ob;
-  ushort local_view_bits;
-  float loc[3], rot[3];
   Scene *scene = CTX_data_scene(C);
 
+  ushort local_view_bits;
+  float loc[3], rot[3];
   if (!ED_object_add_generic_get_opts(C, op, 'Z', loc, rot, NULL, NULL, &local_view_bits, NULL)) {
     return OPERATOR_CANCELLED;
   }
-  ob = ED_object_add_type(C, OB_SPEAKER, NULL, loc, rot, false, local_view_bits);
+  Object *ob = ED_object_add_type(C, OB_SPEAKER, NULL, loc, rot, false, local_view_bits);
 
   /* to make it easier to start using this immediately in NLA, a default sound clip is created
    * ready to be moved around to retime the sound and/or make new sound clips
@@ -1690,10 +1678,10 @@ static int object_hair_add_exec(bContext *C, wmOperator *op)
 {
   ushort local_view_bits;
   float loc[3], rot[3];
-
   if (!ED_object_add_generic_get_opts(C, op, 'Z', loc, rot, NULL, NULL, &local_view_bits, NULL)) {
     return OPERATOR_CANCELLED;
   }
+
   Object *object = ED_object_add_type(C, OB_HAIR, NULL, loc, rot, false, local_view_bits);
   object->dtx |= OB_DRAWBOUNDOX; /* TODO: remove once there is actual drawing. */
 
@@ -1735,10 +1723,10 @@ static int object_pointcloud_add_exec(bContext *C, wmOperator *op)
 {
   ushort local_view_bits;
   float loc[3], rot[3];
-
   if (!ED_object_add_generic_get_opts(C, op, 'Z', loc, rot, NULL, NULL, &local_view_bits, NULL)) {
     return OPERATOR_CANCELLED;
   }
+
   Object *object = ED_object_add_type(C, OB_POINTCLOUD, NULL, loc, rot, false, local_view_bits);
   object->dtx |= OB_DRAWBOUNDOX; /* TODO: remove once there is actual drawing. */
 
@@ -1791,7 +1779,6 @@ static int object_delete_exec(bContext *C, wmOperator *op)
   Main *bmain = CTX_data_main(C);
   Scene *scene = CTX_data_scene(C);
   wmWindowManager *wm = CTX_wm_manager(C);
-  wmWindow *win;
   const bool use_global = RNA_boolean_get(op->ptr, "use_global");
   uint changed_count = 0;
 
@@ -1884,7 +1871,7 @@ static int object_delete_exec(bContext *C, wmOperator *op)
 
   /* delete has to handle all open scenes */
   BKE_main_id_tag_listbase(&bmain->scenes, LIB_TAG_DOIT, true);
-  for (win = wm->windows.first; win; win = win->next) {
+  LISTBASE_FOREACH (wmWindow *, win, &wm->windows) {
     scene = WM_window_get_active_scene(win);
 
     if (scene->id.tag & LIB_TAG_DOIT) {
@@ -2076,18 +2063,16 @@ static void make_object_duplilist_real(bContext *C,
 {
   Main *bmain = CTX_data_main(C);
   ViewLayer *view_layer = CTX_data_view_layer(C);
-  ListBase *lb_duplis;
-  DupliObject *dob;
-  GHash *dupli_gh, *parent_gh = NULL, *instancer_gh = NULL;
+  GHash *parent_gh = NULL, *instancer_gh = NULL;
 
   if (!(base->object->transflag & OB_DUPLI)) {
     return;
   }
 
   Object *object_eval = DEG_get_evaluated_object(depsgraph, base->object);
-  lb_duplis = object_duplilist(depsgraph, scene, object_eval);
+  ListBase *lb_duplis = object_duplilist(depsgraph, scene, object_eval);
 
-  dupli_gh = BLI_ghash_ptr_new(__func__);
+  GHash *dupli_gh = BLI_ghash_ptr_new(__func__);
   if (use_hierarchy) {
     parent_gh = BLI_ghash_new(dupliobject_hash, dupliobject_cmp, __func__);
 
@@ -2097,11 +2082,10 @@ static void make_object_duplilist_real(bContext *C,
     }
   }
 
-  for (dob = lb_duplis->first; dob; dob = dob->next) {
+  LISTBASE_FOREACH (DupliObject *, dob, lb_duplis) {
     Object *ob_src = DEG_get_original_object(dob->ob);
     Object *ob_dst = ID_NEW_SET(ob_src, BKE_id_copy(bmain, &ob_src->id));
     id_us_min(&ob_dst->id);
-    Base *base_dst;
 
     /* font duplis can have a totcol without material, we get them from parent
      * should be implemented better...
@@ -2111,7 +2095,7 @@ static void make_object_duplilist_real(bContext *C,
     }
 
     BKE_collection_object_add_from(bmain, scene, base->object, ob_dst);
-    

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list