Refactor: fcurve.cc

No functional changes.

Improve the readability of the code by

* returning early where possible
* moving variables closer to where they are used
* renaming variables

Pull Request: https://projects.blender.org/blender/blender/pulls/114568
This commit is contained in:
Christoph Lendenfeld
2023-11-07 10:53:43 +01:00
committed by Christoph Lendenfeld
parent 1699163feb
commit a338ecb9cb

View File

@@ -33,9 +33,6 @@ FCurve *action_fcurve_ensure(Main *bmain,
const char rna_path[],
const int array_index)
{
bActionGroup *agrp;
FCurve *fcu;
if (ELEM(nullptr, act, rna_path)) {
return nullptr;
}
@@ -44,66 +41,68 @@ FCurve *action_fcurve_ensure(Main *bmain,
* - add if not found and allowed to add one
* TODO: add auto-grouping support? how this works will need to be resolved
*/
fcu = BKE_fcurve_find(&act->curves, rna_path, array_index);
FCurve *fcu = BKE_fcurve_find(&act->curves, rna_path, array_index);
if (fcu == nullptr) {
fcu = BKE_fcurve_create();
fcu->flag = (FCURVE_VISIBLE | FCURVE_SELECTED);
fcu->auto_smoothing = U.auto_smoothing_new;
if (BLI_listbase_is_empty(&act->curves)) {
fcu->flag |= FCURVE_ACTIVE;
}
fcu->rna_path = BLI_strdup(rna_path);
fcu->array_index = array_index;
if (group) {
agrp = BKE_action_group_find_name(act, group);
if (agrp == nullptr) {
agrp = action_groups_add_new(act, group);
/* sync bone group colors if applicable */
if (ptr && (ptr->type == &RNA_PoseBone)) {
bPoseChannel *pchan = static_cast<bPoseChannel *>(ptr->data);
action_group_colors_set_from_posebone(agrp, pchan);
}
}
action_groups_add_channel(act, agrp, fcu);
}
else {
BLI_addtail(&act->curves, fcu);
}
/* New f-curve was added, meaning it's possible that it affects
* dependency graph component which wasn't previously animated.
*/
DEG_relations_tag_update(bmain);
if (fcu != nullptr) {
return fcu;
}
fcu = BKE_fcurve_create();
fcu->flag = (FCURVE_VISIBLE | FCURVE_SELECTED);
fcu->auto_smoothing = U.auto_smoothing_new;
if (BLI_listbase_is_empty(&act->curves)) {
fcu->flag |= FCURVE_ACTIVE;
}
fcu->rna_path = BLI_strdup(rna_path);
fcu->array_index = array_index;
if (group) {
bActionGroup *agrp = BKE_action_group_find_name(act, group);
if (agrp == nullptr) {
agrp = action_groups_add_new(act, group);
/* Sync bone group colors if applicable. */
if (ptr && (ptr->type == &RNA_PoseBone)) {
bPoseChannel *pchan = static_cast<bPoseChannel *>(ptr->data);
action_group_colors_set_from_posebone(agrp, pchan);
}
}
action_groups_add_channel(act, agrp, fcu);
}
else {
BLI_addtail(&act->curves, fcu);
}
/* New f-curve was added, meaning it's possible that it affects
* dependency graph component which wasn't previously animated.
*/
DEG_relations_tag_update(bmain);
return fcu;
}
bool delete_keyframe_fcurve(AnimData *adt, FCurve *fcu, float cfra)
{
bool found;
int i;
i = BKE_fcurve_bezt_binarysearch_index(fcu->bezt, cfra, fcu->totvert, &found);
if (found) {
/* Delete the key at the index (will sanity check + do recalc afterwards). */
BKE_fcurve_delete_key(fcu, i);
BKE_fcurve_handles_recalc(fcu);
/* Empty curves get automatically deleted. */
if (BKE_fcurve_is_empty(fcu)) {
ANIM_fcurve_delete_from_animdata(nullptr, adt, fcu);
}
return true;
const int index = BKE_fcurve_bezt_binarysearch_index(fcu->bezt, cfra, fcu->totvert, &found);
if (!found) {
return false;
}
return false;
/* Delete the key at the index (will sanity check + do recalc afterwards). */
BKE_fcurve_delete_key(fcu, index);
BKE_fcurve_handles_recalc(fcu);
/* Empty curves get automatically deleted. */
if (BKE_fcurve_is_empty(fcu)) {
ANIM_fcurve_delete_from_animdata(nullptr, adt, fcu);
}
return true;
}
} // namespace blender::animrig