[Bf-blender-cvs] [fe6be70875b] master: CleanUp: Introduce BKE_fcurve_create

Jeroen Bakker noreply at git.blender.org
Fri Jun 5 08:41:38 CEST 2020


Commit: fe6be70875bca64e555d1cbedf1c2160493cf0e2
Author: Jeroen Bakker
Date:   Fri Jun 5 08:41:09 2020 +0200
Branches: master
https://developer.blender.org/rBfe6be70875bca64e555d1cbedf1c2160493cf0e2

CleanUp: Introduce BKE_fcurve_create

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

M	source/blender/blenkernel/BKE_fcurve.h
M	source/blender/blenkernel/intern/fcurve.c
M	source/blender/blenkernel/intern/ipo.c
M	source/blender/blenkernel/intern/nla.c
M	source/blender/editors/animation/drivers.c
M	source/blender/editors/animation/keyframing.c
M	source/blender/editors/space_graph/graph_edit.c
M	source/blender/io/collada/AnimationImporter.cpp
M	source/blender/io/collada/BCAnimationCurve.cpp
M	tests/gtests/blenkernel/BKE_fcurve_test.cc

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

diff --git a/source/blender/blenkernel/BKE_fcurve.h b/source/blender/blenkernel/BKE_fcurve.h
index 1eb5da974ce..b310d66d4bd 100644
--- a/source/blender/blenkernel/BKE_fcurve.h
+++ b/source/blender/blenkernel/BKE_fcurve.h
@@ -179,7 +179,7 @@ int BKE_fcm_envelope_find_index(struct FCM_EnvelopeData *array,
 #define BEZT_BINARYSEARCH_THRESH 0.01f /* was 0.00001, but giving errors */
 
 /* -------- Data Management  --------  */
-
+struct FCurve *BKE_fcurve_create(void);
 void free_fcurve(struct FCurve *fcu);
 struct FCurve *copy_fcurve(const struct FCurve *fcu);
 
diff --git a/source/blender/blenkernel/intern/fcurve.c b/source/blender/blenkernel/intern/fcurve.c
index c0843e049f3..5eb1b756ac7 100644
--- a/source/blender/blenkernel/intern/fcurve.c
+++ b/source/blender/blenkernel/intern/fcurve.c
@@ -58,7 +58,11 @@
 static CLG_LogRef LOG = {"bke.fcurve"};
 
 /* ************************** Data-Level Functions ************************* */
-
+FCurve *BKE_fcurve_create(void)
+{
+  FCurve *fcu = MEM_callocN(sizeof(FCurve), __func__);
+  return fcu;
+}
 /* ---------------------- Freeing --------------------------- */
 
 /* Frees the F-Curve itself too, so make sure BLI_remlink is called before calling this... */
diff --git a/source/blender/blenkernel/intern/ipo.c b/source/blender/blenkernel/intern/ipo.c
index 780c3c2f14a..a2dfbefdb2c 100644
--- a/source/blender/blenkernel/intern/ipo.c
+++ b/source/blender/blenkernel/intern/ipo.c
@@ -1341,7 +1341,7 @@ static void icu_to_fcurves(ID *id,
   int totbits;
 
   /* allocate memory for a new F-Curve */
-  fcu = MEM_callocN(sizeof(FCurve), "FCurve");
+  fcu = BKE_fcurve_create();
 
   /* convert driver */
   if (icu->driver) {
diff --git a/source/blender/blenkernel/intern/nla.c b/source/blender/blenkernel/intern/nla.c
index 4ef68b91a84..97b09d10ede 100644
--- a/source/blender/blenkernel/intern/nla.c
+++ b/source/blender/blenkernel/intern/nla.c
@@ -1499,7 +1499,7 @@ void BKE_nlastrip_validate_fcurves(NlaStrip *strip)
     /* add one if not found */
     if (fcu == NULL) {
       /* make new F-Curve */
-      fcu = MEM_callocN(sizeof(FCurve), "NlaStrip FCurve");
+      fcu = BKE_fcurve_create();
       BLI_addtail(&strip->fcurves, fcu);
 
       /* set default flags */
@@ -1530,7 +1530,7 @@ void BKE_nlastrip_validate_fcurves(NlaStrip *strip)
     /* add one if not found */
     if (fcu == NULL) {
       /* make new F-Curve */
-      fcu = MEM_callocN(sizeof(FCurve), "NlaStrip FCurve");
+      fcu = BKE_fcurve_create();
       BLI_addtail(&strip->fcurves, fcu);
 
       /* set default flags */
diff --git a/source/blender/editors/animation/drivers.c b/source/blender/editors/animation/drivers.c
index 82e24eaa6e3..f7416ce7566 100644
--- a/source/blender/editors/animation/drivers.c
+++ b/source/blender/editors/animation/drivers.c
@@ -110,7 +110,7 @@ struct FCurve *alloc_driver_fcurve(const char rna_path[],
                                    const int array_index,
                                    eDriverFCurveCreationMode creation_mode)
 {
-  FCurve *fcu = MEM_callocN(sizeof(FCurve), "FCurve");
+  FCurve *fcu = BKE_fcurve_create();
 
   fcu->flag = (FCURVE_VISIBLE | FCURVE_SELECTED);
   fcu->auto_smoothing = U.auto_smoothing_new;
diff --git a/source/blender/editors/animation/keyframing.c b/source/blender/editors/animation/keyframing.c
index 0e9b870df88..b3b818fafa9 100644
--- a/source/blender/editors/animation/keyframing.c
+++ b/source/blender/editors/animation/keyframing.c
@@ -214,7 +214,7 @@ FCurve *ED_action_fcurve_ensure(struct Main *bmain,
 
   if (fcu == NULL) {
     /* use default settings to make a F-Curve */
-    fcu = MEM_callocN(sizeof(FCurve), "FCurve");
+    fcu = BKE_fcurve_create();
 
     fcu->flag = (FCURVE_VISIBLE | FCURVE_SELECTED);
     fcu->auto_smoothing = U.auto_smoothing_new;
diff --git a/source/blender/editors/space_graph/graph_edit.c b/source/blender/editors/space_graph/graph_edit.c
index a974ec612a9..06da4416f04 100644
--- a/source/blender/editors/space_graph/graph_edit.c
+++ b/source/blender/editors/space_graph/graph_edit.c
@@ -425,7 +425,7 @@ static void create_ghost_curves(bAnimContext *ac, int start, int end)
   /* loop through filtered data and add keys between selected keyframes on every frame  */
   for (ale = anim_data.first; ale; ale = ale->next) {
     FCurve *fcu = (FCurve *)ale->key_data;
-    FCurve *gcu = MEM_callocN(sizeof(FCurve), "Ghost FCurve");
+    FCurve *gcu = BKE_fcurve_create();
     AnimData *adt = ANIM_nla_mapping_get(ac, ale);
     ChannelDriver *driver = fcu->driver;
     FPoint *fpt;
diff --git a/source/blender/io/collada/AnimationImporter.cpp b/source/blender/io/collada/AnimationImporter.cpp
index 2511d3c287d..0e5fa5ec161 100644
--- a/source/blender/io/collada/AnimationImporter.cpp
+++ b/source/blender/io/collada/AnimationImporter.cpp
@@ -57,7 +57,7 @@ template<class T> static const char *bc_get_joint_name(T *node)
 
 FCurve *AnimationImporter::create_fcurve(int array_index, const char *rna_path)
 {
-  FCurve *fcu = (FCurve *)MEM_callocN(sizeof(FCurve), "FCurve");
+  FCurve *fcu = BKE_fcurve_create();
   fcu->flag = (FCURVE_VISIBLE | FCURVE_AUTO_HANDLES | FCURVE_SELECTED);
   fcu->rna_path = BLI_strdupn(rna_path, strlen(rna_path));
   fcu->array_index = array_index;
@@ -100,7 +100,7 @@ void AnimationImporter::animation_to_fcurves(COLLADAFW::AnimationCurve *curve)
     case 16: /* matrix */
     {
       for (i = 0; i < dim; i++) {
-        FCurve *fcu = (FCurve *)MEM_callocN(sizeof(FCurve), "FCurve");
+        FCurve *fcu = BKE_fcurve_create();
 
         fcu->flag = (FCURVE_VISIBLE | FCURVE_AUTO_HANDLES | FCURVE_SELECTED);
         fcu->array_index = 0;
diff --git a/source/blender/io/collada/BCAnimationCurve.cpp b/source/blender/io/collada/BCAnimationCurve.cpp
index 98eb12f738e..67b96230b02 100644
--- a/source/blender/io/collada/BCAnimationCurve.cpp
+++ b/source/blender/io/collada/BCAnimationCurve.cpp
@@ -94,7 +94,7 @@ void BCAnimationCurve::delete_fcurve(FCurve *fcu)
 
 FCurve *BCAnimationCurve::create_fcurve(int array_index, const char *rna_path)
 {
-  FCurve *fcu = (FCurve *)MEM_callocN(sizeof(FCurve), "FCurve");
+  FCurve *fcu = BKE_fcurve_create();
   fcu->flag = (FCURVE_VISIBLE | FCURVE_AUTO_HANDLES | FCURVE_SELECTED);
   fcu->rna_path = BLI_strdupn(rna_path, strlen(rna_path));
   fcu->array_index = array_index;
diff --git a/tests/gtests/blenkernel/BKE_fcurve_test.cc b/tests/gtests/blenkernel/BKE_fcurve_test.cc
index d28c5075bd8..1d164cc47ab 100644
--- a/tests/gtests/blenkernel/BKE_fcurve_test.cc
+++ b/tests/gtests/blenkernel/BKE_fcurve_test.cc
@@ -32,14 +32,14 @@ static const float EPSILON = 1e-7f;
 
 TEST(evaluate_fcurve, EmptyFCurve)
 {
-  FCurve *fcu = static_cast<FCurve *>(MEM_callocN(sizeof(FCurve), "FCurve"));
+  FCurve *fcu = BKE_fcurve_create();
   EXPECT_EQ(evaluate_fcurve(fcu, 47.0f), 0.0f);
   free_fcurve(fcu);
 }
 
 TEST(evaluate_fcurve, OnKeys)
 {
-  FCurve *fcu = static_cast<FCurve *>(MEM_callocN(sizeof(FCurve), "FCurve"));
+  FCurve *fcu = BKE_fcurve_create();
 
   insert_vert_fcurve(fcu, 1.0f, 7.0f, BEZT_KEYTYPE_KEYFRAME, INSERTKEY_NO_USERPREF);
   insert_vert_fcurve(fcu, 2.0f, 13.0f, BEZT_KEYTYPE_KEYFRAME, INSERTKEY_NO_USERPREF);
@@ -61,7 +61,7 @@ TEST(evaluate_fcurve, OnKeys)
 
 TEST(evaluate_fcurve, InterpolationConstant)
 {
-  FCurve *fcu = static_cast<FCurve *>(MEM_callocN(sizeof(FCurve), "FCurve"));
+  FCurve *fcu = BKE_fcurve_create();
 
   EXPECT_EQ(insert_vert_fcurve(fcu, 1.0f, 7.0f, BEZT_KEYTYPE_KEYFRAME, INSERTKEY_NO_USERPREF), 0);
   EXPECT_EQ(insert_vert_fcurve(fcu, 2.0f, 13.0f, BEZT_KEYTYPE_KEYFRAME, INSERTKEY_NO_USERPREF), 1);
@@ -77,7 +77,7 @@ TEST(evaluate_fcurve, InterpolationConstant)
 
 TEST(evaluate_fcurve, InterpolationLinear)
 {
-  FCurve *fcu = static_cast<FCurve *>(MEM_callocN(sizeof(FCurve), "FCurve"));
+  FCurve *fcu = BKE_fcurve_create();
 
   EXPECT_EQ(insert_vert_fcurve(fcu, 1.0f, 7.0f, BEZT_KEYTYPE_KEYFRAME, INSERTKEY_NO_USERPREF), 0);
   EXPECT_EQ(insert_vert_fcurve(fcu, 2.0f, 13.0f, BEZT_KEYTYPE_KEYFRAME, INSERTKEY_NO_USERPREF), 1);
@@ -94,7 +94,7 @@ TEST(evaluate_fcurve, InterpolationLinear)
 
 TEST(evaluate_fcurve, InterpolationBezier)
 {
-  FCurve *fcu = static_cast<FCurve *>(MEM_callocN(sizeof(FCurve), "FCurve"));
+  FCurve *fcu = BKE_fcurve_create();
 
   EXPECT_EQ(insert_vert_fcurve(fcu, 1.0f, 7.0f, BEZT_KEYTYPE_KEYFRAME, INSERTKEY_NO_USERPREF), 0);
   EXPECT_EQ(insert_vert_fcurve(fcu, 2.0f, 13.0f, BEZT_KEYTYPE_KEYFRAME, INSERTKEY_NO_USERPREF), 1);
@@ -127,7 +127,7 @@ TEST(evaluate_fcurve, InterpolationBezier)
 
 TEST(evaluate_fcurve, InterpolationBounce)
 {
-  FCurve *fcu = static_cast<FCurve *>(MEM_callocN(sizeof(FCurve), "FCurve"));
+  FCurve *fcu = BKE_fcurve_create();
 
   EXPECT_EQ(insert_vert_fcurve(fcu, 1.0f, 7.0f, BEZT_KEYTYPE_KEYFRAME, INSERTKEY_NO_USERPREF), 0);
   EXPECT_EQ(insert_vert_fcurve(fcu, 2.0f, 13.0f, BEZT_KEYTYPE_KEYFRAME, INSERTKEY_NO_USERPREF), 1);
@@ -147,7 +147,7 @@ TEST(evaluate_fcurve, InterpolationBounce)
 
 TEST(evaluate_fcurve, ExtrapolationLinearKeys)
 {
-  FCurve *fcu = static_cast<FCurve *>(MEM_callocN(sizeof(FCurve), "FCurve"));
+  FCurve *fcu = BKE_fcurve_create();
 
   EXPECT_EQ(insert_vert_fcurve(fcu, 1.0f, 7.0f, BEZT_KEYTYPE_KEYFRAME, INSERTKEY_NO_USERPREF), 0);
   EXPECT_EQ(insert_vert_fcurve(fcu, 2.0f, 13.0f, BEZT_KEYTYPE_KEYFRAME, INSERTKEY_NO_USERPREF), 1);
@@ -176,7 +176,7 @@ TEST(evaluate_fcurve, ExtrapolationLinearKeys)
 
 TEST(evaluate_fcurve, ExtrapolationBezierKeys)
 {
-  FCurve *fcu = static_cast<FCurve *>(MEM_callocN(sizeof(FCurve), "FCurve"));
+  FCurve *fcu = BKE_fcurve_create();
 
   EXPECT_EQ(insert_vert_fcurve(fcu, 1.0f, 7.0f, BEZT_KEYTYPE_KEYFRAME, INSERTKEY_NO_USERPREF), 0);
   EXPECT_EQ(insert_vert_fcurve(fcu, 2.0f, 13.0f, BEZT_KEYTYPE_KEYFRAME, INSERTKEY_NO_USERPREF), 1);



More information about the Bf-blender-cvs mailing list