[Bf-blender-cvs] [ec9f237a9ef] master: Cleanup: merge functions with similar usage

Germano Cavalcante noreply at git.blender.org
Sat Feb 5 00:17:16 CET 2022


Commit: ec9f237a9ef01e5966228e0789eeecc419021f56
Author: Germano Cavalcante
Date:   Fri Feb 4 20:15:45 2022 -0300
Branches: master
https://developer.blender.org/rBec9f237a9ef01e5966228e0789eeecc419021f56

Cleanup: merge functions with similar usage

`viewops_data_alloc` allocates and stores some pointers in
`ViewOpsData` while `viewops_data_create` reuses already stored
pointers and also stores others in `ViewOpsData`.

The similar names and usages can confuse and in this case it also
creates a dependency on the order in which these functions are called.

Merging these functions simplifies usage and deduplicates code.

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

M	source/blender/editors/space_view3d/view3d_navigate.c
M	source/blender/editors/space_view3d/view3d_navigate.h
M	source/blender/editors/space_view3d/view3d_navigate_dolly.c
M	source/blender/editors/space_view3d/view3d_navigate_move.c
M	source/blender/editors/space_view3d/view3d_navigate_ndof.c
M	source/blender/editors/space_view3d/view3d_navigate_roll.c
M	source/blender/editors/space_view3d/view3d_navigate_rotate.c
M	source/blender/editors/space_view3d/view3d_navigate_zoom.c

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

diff --git a/source/blender/editors/space_view3d/view3d_navigate.c b/source/blender/editors/space_view3d/view3d_navigate.c
index 692a3005607..e647e80ff36 100644
--- a/source/blender/editors/space_view3d/view3d_navigate.c
+++ b/source/blender/editors/space_view3d/view3d_navigate.c
@@ -143,21 +143,6 @@ void calctrackballvec(const rcti *rect, const int event_xy[2], float r_dir[3])
   }
 }
 
-void viewops_data_alloc(bContext *C, wmOperator *op)
-{
-  ViewOpsData *vod = MEM_callocN(sizeof(ViewOpsData), "viewops data");
-
-  /* store data */
-  op->customdata = vod;
-  vod->bmain = CTX_data_main(C);
-  vod->depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
-  vod->scene = CTX_data_scene(C);
-  vod->area = CTX_wm_area(C);
-  vod->region = CTX_wm_region(C);
-  vod->v3d = vod->area->spacedata.first;
-  vod->rv3d = vod->region->regiondata;
-}
-
 void view3d_orbit_apply_dyn_ofs(float r_ofs[3],
                                 const float ofs_old[3],
                                 const float viewquat_old[4],
@@ -294,8 +279,19 @@ void viewops_data_create(bContext *C,
                          const wmEvent *event,
                          enum eViewOpsFlag viewops_flag)
 {
-  Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
-  ViewOpsData *vod = op->customdata;
+  ViewOpsData *vod = MEM_callocN(sizeof(ViewOpsData), __func__);
+
+  /* Store data. */
+  op->customdata = vod;
+  vod->bmain = CTX_data_main(C);
+  vod->depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
+  vod->scene = CTX_data_scene(C);
+  vod->area = CTX_wm_area(C);
+  vod->region = CTX_wm_region(C);
+  vod->v3d = vod->area->spacedata.first;
+  vod->rv3d = vod->region->regiondata;
+
+  Depsgraph *depsgraph = vod->depsgraph;
   RegionView3D *rv3d = vod->rv3d;
 
   /* Could do this more nicely. */
@@ -1569,7 +1565,6 @@ static int viewpan_invoke(bContext *C, wmOperator *op, const wmEvent *event)
     y = 25;
   }
 
-  viewops_data_alloc(C, op);
   viewops_data_create(C, op, event, (viewops_flag_from_prefs() & ~VIEWOPS_FLAG_ORBIT_SELECT));
   ViewOpsData *vod = op->customdata;
 
diff --git a/source/blender/editors/space_view3d/view3d_navigate.h b/source/blender/editors/space_view3d/view3d_navigate.h
index c44f1f94708..2f9a0ff603c 100644
--- a/source/blender/editors/space_view3d/view3d_navigate.h
+++ b/source/blender/editors/space_view3d/view3d_navigate.h
@@ -82,7 +82,7 @@ enum eViewOpsFlag {
 
 /** Generic View Operator Custom-Data */
 typedef struct ViewOpsData {
-  /** Context pointers (assigned by #viewops_data_alloc). */
+  /** Context pointers (assigned by #viewops_data_create). */
   struct Main *bmain;
   struct Scene *scene;
   struct ScrArea *area;
@@ -166,14 +166,10 @@ bool view3d_orbit_calc_center(struct bContext *C, float r_dyn_ofs[3]);
 
 void view3d_operator_properties_common(struct wmOperatorType *ot, const enum eV3D_OpPropFlag flag);
 
-/**
- * Allocate and fill in context pointers for #ViewOpsData
- */
-void viewops_data_alloc(struct bContext *C, struct wmOperator *op);
 void viewops_data_free(struct bContext *C, struct wmOperator *op);
 
 /**
- * Calculate the values for #ViewOpsData
+ * Allocate, fill in context pointers and calculate the values for #ViewOpsData
  */
 void viewops_data_create(struct bContext *C,
                          struct wmOperator *op,
diff --git a/source/blender/editors/space_view3d/view3d_navigate_dolly.c b/source/blender/editors/space_view3d/view3d_navigate_dolly.c
index 7273ec7f7fa..07099ea221e 100644
--- a/source/blender/editors/space_view3d/view3d_navigate_dolly.c
+++ b/source/blender/editors/space_view3d/view3d_navigate_dolly.c
@@ -239,8 +239,14 @@ static int viewdolly_invoke(bContext *C, wmOperator *op, const wmEvent *event)
     return OPERATOR_CANCELLED;
   }
 
+  const bool use_cursor_init = RNA_boolean_get(op->ptr, "use_cursor_init");
+
   /* makes op->customdata */
-  viewops_data_alloc(C, op);
+  viewops_data_create(C,
+                      op,
+                      event,
+                      (viewops_flag_from_prefs() & ~VIEWOPS_FLAG_ORBIT_SELECT) |
+                          (use_cursor_init ? VIEWOPS_FLAG_USE_MOUSE_INIT : 0));
   vod = op->customdata;
 
   ED_view3d_smooth_view_force_finish(C, vod->v3d, vod->region);
@@ -259,14 +265,6 @@ static int viewdolly_invoke(bContext *C, wmOperator *op, const wmEvent *event)
     ED_region_tag_redraw(vod->region);
   }
 
-  const bool use_cursor_init = RNA_boolean_get(op->ptr, "use_cursor_init");
-
-  viewops_data_create(C,
-                      op,
-                      event,
-                      (viewops_flag_from_prefs() & ~VIEWOPS_FLAG_ORBIT_SELECT) |
-                          (use_cursor_init ? VIEWOPS_FLAG_USE_MOUSE_INIT : 0));
-
   /* if one or the other zoom position aren't set, set from event */
   if (!RNA_struct_property_is_set(op->ptr, "mx") || !RNA_struct_property_is_set(op->ptr, "my")) {
     RNA_int_set(op->ptr, "mx", event->xy[0]);
diff --git a/source/blender/editors/space_view3d/view3d_navigate_move.c b/source/blender/editors/space_view3d/view3d_navigate_move.c
index e23767923b1..a84da76b05f 100644
--- a/source/blender/editors/space_view3d/view3d_navigate_move.c
+++ b/source/blender/editors/space_view3d/view3d_navigate_move.c
@@ -132,7 +132,6 @@ static int viewmove_invoke(bContext *C, wmOperator *op, const wmEvent *event)
   const bool use_cursor_init = RNA_boolean_get(op->ptr, "use_cursor_init");
 
   /* makes op->customdata */
-  viewops_data_alloc(C, op);
   viewops_data_create(C,
                       op,
                       event,
diff --git a/source/blender/editors/space_view3d/view3d_navigate_ndof.c b/source/blender/editors/space_view3d/view3d_navigate_ndof.c
index 69394b36e54..668a5288190 100644
--- a/source/blender/editors/space_view3d/view3d_navigate_ndof.c
+++ b/source/blender/editors/space_view3d/view3d_navigate_ndof.c
@@ -378,7 +378,6 @@ static int ndof_orbit_invoke(bContext *C, wmOperator *op, const wmEvent *event)
 
   const wmNDOFMotionData *ndof = event->customdata;
 
-  viewops_data_alloc(C, op);
   viewops_data_create(C, op, event, (viewops_flag_from_prefs() & ~VIEWOPS_FLAG_DEPTH_NAVIGATE));
   vod = op->customdata;
 
@@ -458,7 +457,6 @@ static int ndof_orbit_zoom_invoke(bContext *C, wmOperator *op, const wmEvent *ev
 
   const wmNDOFMotionData *ndof = event->customdata;
 
-  viewops_data_alloc(C, op);
   viewops_data_create(C, op, event, (viewops_flag_from_prefs() & ~VIEWOPS_FLAG_DEPTH_NAVIGATE));
 
   vod = op->customdata;
diff --git a/source/blender/editors/space_view3d/view3d_navigate_roll.c b/source/blender/editors/space_view3d/view3d_navigate_roll.c
index c01346919a9..4675aad9af5 100644
--- a/source/blender/editors/space_view3d/view3d_navigate_roll.c
+++ b/source/blender/editors/space_view3d/view3d_navigate_roll.c
@@ -220,7 +220,6 @@ static int viewroll_invoke(bContext *C, wmOperator *op, const wmEvent *event)
   }
   else {
     /* makes op->customdata */
-    viewops_data_alloc(C, op);
     viewops_data_create(C, op, event, viewops_flag_from_prefs());
     vod = op->customdata;
     vod->init.dial = BLI_dial_init((const float[2]){BLI_rcti_cent_x(&vod->region->winrct),
diff --git a/source/blender/editors/space_view3d/view3d_navigate_rotate.c b/source/blender/editors/space_view3d/view3d_navigate_rotate.c
index c65acde0ad0..30af53c4bc6 100644
--- a/source/blender/editors/space_view3d/view3d_navigate_rotate.c
+++ b/source/blender/editors/space_view3d/view3d_navigate_rotate.c
@@ -383,17 +383,16 @@ static int viewrotate_invoke(bContext *C, wmOperator *op, const wmEvent *event)
   const bool use_cursor_init = RNA_boolean_get(op->ptr, "use_cursor_init");
 
   /* makes op->customdata */
-  viewops_data_alloc(C, op);
-  vod = op->customdata;
-
-  ED_view3d_smooth_view_force_finish(C, vod->v3d, vod->region);
-
   viewops_data_create(C,
                       op,
                       event,
                       viewops_flag_from_prefs() | VIEWOPS_FLAG_PERSP_ENSURE |
                           (use_cursor_init ? VIEWOPS_FLAG_USE_MOUSE_INIT : 0));
 
+  vod = op->customdata;
+
+  ED_view3d_smooth_view_force_finish(C, vod->v3d, vod->region);
+
   if (ELEM(event->type, MOUSEPAN, MOUSEROTATE)) {
     /* Rotate direction we keep always same */
     int event_xy[2];
diff --git a/source/blender/editors/space_view3d/view3d_navigate_zoom.c b/source/blender/editors/space_view3d/view3d_navigate_zoom.c
index 24a977f7521..d4f3de64341 100644
--- a/source/blender/editors/space_view3d/view3d_navigate_zoom.c
+++ b/source/blender/editors/space_view3d/view3d_navigate_zoom.c
@@ -512,7 +512,6 @@ static int viewzoom_invoke(bContext *C, wmOperator *op, const wmEvent *event)
   const bool use_cursor_init = RNA_boolean_get(op->ptr, "use_cursor_init");
 
   /* makes op->customdata */
-  viewops_data_alloc(C, op);
   viewops_data_create(C,
                       op,
                       event,



More information about the Bf-blender-cvs mailing list