Refactor: keyframing_auto.cc code cleanup

No functional changes

Clean up code by
* moving variables closer to their use
* inverting "if" for early returns
* using the enum type instead of int

Pull Request: https://projects.blender.org/blender/blender/pulls/113617
This commit is contained in:
Christoph Lendenfeld 2023-10-12 17:45:16 +02:00 committed by Christoph Lendenfeld
parent 2d9ea10892
commit 7be1b59daa
2 changed files with 140 additions and 138 deletions

View File

@ -11,6 +11,7 @@
#pragma once
#include "DNA_anim_types.h"
#include "ED_transform.hh"
#include "RNA_types.hh"
struct ID;
@ -126,7 +127,8 @@ bool is_autokey_flag(const Scene *scene, eAutokey_Flag flag);
*/
bool autokeyframe_cfra_can_key(const Scene *scene, ID *id);
void autokeyframe_object(bContext *C, Scene *scene, ViewLayer *view_layer, Object *ob, int tmode);
void autokeyframe_object(
bContext *C, Scene *scene, ViewLayer *view_layer, Object *ob, eTfmMode tmode);
bool autokeyframe_object(bContext *C, Scene *scene, Object *ob, KeyingSet *ks);
bool autokeyframe_pchan(bContext *C, Scene *scene, Object *ob, bPoseChannel *pchan, KeyingSet *ks);

View File

@ -57,10 +57,8 @@ bool is_autokey_flag(const Scene *scene, const eAutokey_Flag flag)
bool autokeyframe_cfra_can_key(const Scene *scene, ID *id)
{
const float cfra = BKE_scene_frame_get(scene);
/* only filter if auto-key mode requires this */
if (is_autokey_on(scene) == 0) {
if (!is_autokey_on(scene)) {
return false;
}
@ -69,6 +67,7 @@ bool autokeyframe_cfra_can_key(const Scene *scene, ID *id)
* For whole block, only key if there's a keyframe on that frame already
* This is a valid assumption when we're blocking + tweaking
*/
const float cfra = BKE_scene_frame_get(scene);
return id_frame_has_keyframe(id, cfra);
}
@ -91,15 +90,16 @@ bool autokeyframe_cfra_can_key(const Scene *scene, ID *id)
* \note Context may not always be available,
* so must check before using it as it's a luxury for a few cases.
*/
void autokeyframe_object(bContext *C, Scene *scene, ViewLayer *view_layer, Object *ob, int tmode)
void autokeyframe_object(
bContext *C, Scene *scene, ViewLayer *view_layer, Object *ob, const eTfmMode tmode)
{
Main *bmain = CTX_data_main(C);
ID *id = &ob->id;
/* TODO: this should probably be done per channel instead. */
if (autokeyframe_cfra_can_key(scene, id)) {
ID *id = &ob->id;
if (!autokeyframe_cfra_can_key(scene, id)) {
return;
}
ReportList *reports = CTX_wm_reports(C);
ToolSettings *ts = scene->toolsettings;
KeyingSet *active_ks = ANIM_scene_get_active_keyingset(scene);
ListBase dsources = {nullptr, nullptr};
Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C);
@ -123,6 +123,8 @@ void autokeyframe_object(bContext *C, Scene *scene, ViewLayer *view_layer, Objec
}
else if (is_autokey_flag(scene, AUTOKEY_FLAG_INSERTAVAIL)) {
AnimData *adt = ob->adt;
ToolSettings *ts = scene->toolsettings;
Main *bmain = CTX_data_main(C);
/* only key on available channels */
if (adt && adt->action) {
@ -204,13 +206,15 @@ void autokeyframe_object(bContext *C, Scene *scene, ViewLayer *view_layer, Objec
/* free temp info */
BLI_freelistN(&dsources);
}
}
bool autokeyframe_object(bContext *C, Scene *scene, Object *ob, KeyingSet *ks)
{
/* auto keyframing */
if (autokeyframe_cfra_can_key(scene, &ob->id)) {
if (!autokeyframe_cfra_can_key(scene, &ob->id)) {
return false;
}
ListBase dsources = {nullptr, nullptr};
/* Now insert the key-frame(s) using the Keying Set:
@ -223,13 +227,13 @@ bool autokeyframe_object(bContext *C, Scene *scene, Object *ob, KeyingSet *ks)
BLI_freelistN(&dsources);
return true;
}
return false;
}
bool autokeyframe_pchan(bContext *C, Scene *scene, Object *ob, bPoseChannel *pchan, KeyingSet *ks)
{
if (autokeyframe_cfra_can_key(scene, &ob->id)) {
return false;
}
ListBase dsources = {nullptr, nullptr};
/* Now insert the keyframe(s) using the Keying Set:
@ -242,26 +246,21 @@ bool autokeyframe_pchan(bContext *C, Scene *scene, Object *ob, bPoseChannel *pch
BLI_freelistN(&dsources);
return true;
}
return false;
}
bool autokeyframe_property(bContext *C,
Scene *scene,
PointerRNA *ptr,
PropertyRNA *prop,
int rnaindex,
float cfra,
const int rnaindex,
const float cfra,
const bool only_if_property_keyed)
{
Main *bmain = CTX_data_main(C);
Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C);
const AnimationEvalContext anim_eval_context = BKE_animsys_eval_context_construct(depsgraph,
cfra);
ID *id;
bAction *action;
FCurve *fcu;
bool driven;
bool special;
bool changed = false;
@ -269,7 +268,7 @@ bool autokeyframe_property(bContext *C,
/* for entire array buttons we check the first component, it's not perfect
* but works well enough in typical cases */
const int rnaindex_check = (rnaindex == -1) ? 0 : rnaindex;
fcu = BKE_fcurve_find_by_rna_context_ui(
FCurve *fcu = BKE_fcurve_find_by_rna_context_ui(
C, ptr, prop, rnaindex_check, nullptr, &action, &driven, &special);
/* Only early out when we actually want an existing F-curve already
@ -315,7 +314,8 @@ bool autokeyframe_property(bContext *C,
}
}
else {
id = ptr->owner_id;
ID *id = ptr->owner_id;
Main *bmain = CTX_data_main(C);
/* TODO: this should probably respect the keyingset only option for anim */
if (autokeyframe_cfra_can_key(scene, id)) {