Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/animation/keyframing.c
| Show First 20 Lines • Show All 3,088 Lines • ▼ Show 20 Lines | if (autokeyframe_cfra_can_key(scene, &ob->id)) { | ||||
| BLI_freelistN(&dsources); | BLI_freelistN(&dsources); | ||||
| return true; | return true; | ||||
| } | } | ||||
| return false; | return false; | ||||
| } | } | ||||
| bool ED_autokeyframe_property( | bool ED_autokeyframe_property(bContext *C, | ||||
| bContext *C, Scene *scene, PointerRNA *ptr, PropertyRNA *prop, int rnaindex, float cfra) | Scene *scene, | ||||
| PointerRNA *ptr, | |||||
| PropertyRNA *prop, | |||||
| int rnaindex, | |||||
| float cfra, | |||||
| bool only_if_property_keyed) | |||||
| { | { | ||||
| Main *bmain = CTX_data_main(C); | Main *bmain = CTX_data_main(C); | ||||
| Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); | Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); | ||||
| const AnimationEvalContext anim_eval_context = BKE_animsys_eval_context_construct(depsgraph, | const AnimationEvalContext anim_eval_context = BKE_animsys_eval_context_construct(depsgraph, | ||||
| cfra); | cfra); | ||||
| ID *id; | ID *id; | ||||
| bAction *action; | bAction *action; | ||||
| FCurve *fcu; | FCurve *fcu; | ||||
| bool driven; | bool driven; | ||||
| bool special; | bool special; | ||||
| bool changed = false; | bool changed = false; | ||||
| /* for entire array buttons we check the first component, it's not perfect | /* for entire array buttons we check the first component, it's not perfect | ||||
| * but works well enough in typical cases */ | * but works well enough in typical cases */ | ||||
| const int rnaindex_check = (rnaindex == -1) ? 0 : rnaindex; | const int rnaindex_check = (rnaindex == -1) ? 0 : rnaindex; | ||||
| fcu = BKE_fcurve_find_by_rna_context_ui( | fcu = BKE_fcurve_find_by_rna_context_ui( | ||||
| C, ptr, prop, rnaindex_check, NULL, &action, &driven, &special); | C, ptr, prop, rnaindex_check, NULL, &action, &driven, &special); | ||||
| if (fcu == NULL) { | if (driven || special) { | ||||
| only_if_property_keyed = true; | |||||
| } | |||||
| /* Only early out when we actually want an existing fcurve already (e.g. auto-keyframing from buttons). */ | |||||
| if (only_if_property_keyed && (fcu == NULL)) { | |||||
| return changed; | return changed; | ||||
sybren: This logic is confusing. Here `only_if_property_keyed` is set to `true`, but the check `if… | |||||
| } | } | ||||
| if (special) { | if (special) { | ||||
| /* NLA Strip property */ | /* NLA Strip property */ | ||||
| if (IS_AUTOKEY_ON(scene)) { | if (IS_AUTOKEY_ON(scene)) { | ||||
| ReportList *reports = CTX_wm_reports(C); | ReportList *reports = CTX_wm_reports(C); | ||||
| ToolSettings *ts = scene->toolsettings; | ToolSettings *ts = scene->toolsettings; | ||||
| Show All 18 Lines | bool ED_autokeyframe_property(bContext *C, | ||||
| else { | else { | ||||
| id = ptr->owner_id; | id = ptr->owner_id; | ||||
| /* TODO: this should probably respect the keyingset only option for anim */ | /* TODO: this should probably respect the keyingset only option for anim */ | ||||
| if (autokeyframe_cfra_can_key(scene, id)) { | if (autokeyframe_cfra_can_key(scene, id)) { | ||||
| ReportList *reports = CTX_wm_reports(C); | ReportList *reports = CTX_wm_reports(C); | ||||
| ToolSettings *ts = scene->toolsettings; | ToolSettings *ts = scene->toolsettings; | ||||
| const eInsertKeyFlags flag = ANIM_get_keyframing_flags(scene, true); | const eInsertKeyFlags flag = ANIM_get_keyframing_flags(scene, true); | ||||
| char *path = RNA_path_from_ID_to_property(ptr, prop); | |||||
Not Done Inline Actionspath is only used when fcu == NULL, so it's a bit inefficient to allocate memory, build the path, and free the memory again, when it's not going to be used. sybren: `path` is only used when `fcu == NULL`, so it's a bit inefficient to allocate memory, build the… | |||||
| if (only_if_property_keyed) { | |||||
| /* NOTE: We use rnaindex instead of fcu->array_index, | /* NOTE: We use rnaindex instead of fcu->array_index, | ||||
| * because a button may control all items of an array at once. | * because a button may control all items of an array at once. | ||||
| * E.g., color wheels (see T42567). */ | * E.g., color wheels (see T42567). */ | ||||
| BLI_assert((fcu->array_index == rnaindex) || (rnaindex == -1)); | BLI_assert((fcu->array_index == rnaindex) || (rnaindex == -1)); | ||||
| } | |||||
| changed = insert_keyframe(bmain, | changed = insert_keyframe(bmain, | ||||
| reports, | reports, | ||||
| id, | id, | ||||
| action, | action, | ||||
| ((fcu->grp) ? (fcu->grp->name) : (NULL)), | (fcu && fcu->grp) ? fcu->grp->name : NULL, | ||||
| fcu->rna_path, | fcu ? fcu->rna_path : path, | ||||
| rnaindex, | rnaindex, | ||||
| &anim_eval_context, | &anim_eval_context, | ||||
| ts->keyframe_type, | ts->keyframe_type, | ||||
| NULL, | NULL, | ||||
| flag) != 0; | flag) != 0; | ||||
| MEM_freeN(path); | |||||
| WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL); | WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL); | ||||
Not Done Inline ActionsMEM_SAFE_FREE(path); sybren: `MEM_SAFE_FREE(path);` | |||||
| } | } | ||||
| } | } | ||||
| return changed; | return changed; | ||||
| } | } | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Internal Utilities | /** \name Internal Utilities | ||||
| * \{ */ | * \{ */ | ||||
| Show All 29 Lines | |||||
This logic is confusing. Here only_if_property_keyed is set to true, but the check if (only_if_property_keyed) { further down can only be reached if (driven || special) is false. This means that setting the variable here to true is only done for the immediately following condition, but not for the other use of the same variable.
I'm not a fan of boolean parameters in the first place, but having them change semantics throughout the function is really not a good idea.
Declare the parameter as const bool, and change the condition on the next line to