[Bf-blender-cvs] [b2e9f35c5eb] master: Cleanup: Extract function to store bezt arrays

Christoph Lendenfeld noreply at git.blender.org
Sun Oct 31 12:28:17 CET 2021


Commit: b2e9f35c5eb21f63f5c20e06e910ef03965556ce
Author: Christoph Lendenfeld
Date:   Sun Oct 31 11:28:10 2021 +0000
Branches: master
https://developer.blender.org/rBb2e9f35c5eb21f63f5c20e06e910ef03965556ce

Cleanup: Extract function to store bezt arrays

The code to store an original bezt array previously lived in
`graphkeys_decimate_invoke`.
Since future graph slider operators will need this function as well,
it has been extracted.

No functional changes.

Reviewed by: Sybren A. Stüvel
Differential Revision: https://developer.blender.org/D12487
Ref: D12487

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

M	source/blender/editors/space_graph/graph_slider_ops.c

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

diff --git a/source/blender/editors/space_graph/graph_slider_ops.c b/source/blender/editors/space_graph/graph_slider_ops.c
index 958745ff281..ab3c6a89730 100644
--- a/source/blender/editors/space_graph/graph_slider_ops.c
+++ b/source/blender/editors/space_graph/graph_slider_ops.c
@@ -58,6 +58,48 @@
  * operators are modal and use a slider that allows the user to define a percentage to modify the
  * operator. */
 
+/* ******************** Utility Functions ************************* */
+
+/* Construct a list with the original bezt arrays so we can restore them during modal operation.
+ * The data is stored on the struct that is passed.*/
+static void store_original_bezt_arrays(tDecimateGraphOp *dgo)
+{
+  ListBase anim_data = {NULL, NULL};
+  bAnimContext *ac = &dgo->ac;
+  bAnimListElem *ale;
+
+  ANIM_animdata_filter(ac, &anim_data, OPERATOR_DATA_FILTER, ac->data, ac->datatype);
+
+  /* Loop through filtered data and copy the curves. */
+  for (ale = anim_data.first; ale; ale = ale->next) {
+    FCurve *fcu = (FCurve *)ale->key_data;
+
+    if (fcu->bezt == NULL) {
+      /* This curve is baked, skip it. */
+      continue;
+    }
+
+    const int arr_size = sizeof(BezTriple) * fcu->totvert;
+
+    tBeztCopyData *copy = MEM_mallocN(sizeof(tBeztCopyData), "bezts_copy");
+    BezTriple *bezts_copy = MEM_mallocN(arr_size, "bezts_copy_array");
+
+    copy->tot_vert = fcu->totvert;
+    memcpy(bezts_copy, fcu->bezt, arr_size);
+
+    copy->bezt = bezts_copy;
+
+    LinkData *link = NULL;
+
+    link = MEM_callocN(sizeof(LinkData), "Bezt Link");
+    link->data = copy;
+
+    BLI_addtail(&dgo->bezt_arr_list, link);
+  }
+
+  ANIM_animdata_freelist(&anim_data);
+}
+
 /* ******************** Decimate Keyframes Operator ************************* */
 
 static void decimate_graph_keys(bAnimContext *ac, float remove_ratio, float error_sq_max)
@@ -228,52 +270,14 @@ static int graphkeys_decimate_invoke(bContext *C, wmOperator *op, const wmEvent
   dgo->area = CTX_wm_area(C);
   dgo->region = CTX_wm_region(C);
 
+  store_original_bezt_arrays(dgo);
+
   dgo->slider = ED_slider_create(C);
   ED_slider_init(dgo->slider, event);
   ED_slider_allow_overshoot_set(dgo->slider, false);
 
   decimate_draw_status(C, dgo);
 
-  /* Construct a list with the original bezt arrays so we can restore them during modal operation.
-   */
-  {
-    ListBase anim_data = {NULL, NULL};
-    bAnimContext *ac = &dgo->ac;
-    bAnimListElem *ale;
-
-    /* Filter data. */
-    ANIM_animdata_filter(ac, &anim_data, OPERATOR_DATA_FILTER, ac->data, ac->datatype);
-
-    /* Loop through filtered data and copy the curves. */
-    for (ale = anim_data.first; ale; ale = ale->next) {
-      FCurve *fcu = (FCurve *)ale->key_data;
-
-      if (fcu->bezt == NULL) {
-        /* This curve is baked, skip it. */
-        continue;
-      }
-
-      const int arr_size = sizeof(BezTriple) * fcu->totvert;
-
-      tBeztCopyData *copy = MEM_mallocN(sizeof(tBeztCopyData), "bezts_copy");
-      BezTriple *bezts_copy = MEM_mallocN(arr_size, "bezts_copy_array");
-
-      copy->tot_vert = fcu->totvert;
-      memcpy(bezts_copy, fcu->bezt, arr_size);
-
-      copy->bezt = bezts_copy;
-
-      LinkData *link = NULL;
-
-      link = MEM_callocN(sizeof(LinkData), "Bezt Link");
-      link->data = copy;
-
-      BLI_addtail(&dgo->bezt_arr_list, link);
-    }
-
-    ANIM_animdata_freelist(&anim_data);
-  }
-
   if (dgo->bezt_arr_list.first == NULL) {
     WM_report(RPT_WARNING,
               "Fcurve Decimate: Can't decimate baked channels. Unbake them and try again.");



More information about the Bf-blender-cvs mailing list