CleanUp: Introduce BKE_fcurve_create

This commit is contained in:
2020-06-05 08:41:09 +02:00
parent e3a32a22bf
commit fe6be70875
10 changed files with 23 additions and 19 deletions

View File

@@ -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);

View File

@@ -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... */

View File

@@ -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) {

View File

@@ -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 */

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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);