Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSybren A. Stüvel <sybren@blender.org>2019-09-27 17:33:48 +0300
committerSybren A. Stüvel <sybren@blender.org>2019-09-27 18:02:39 +0300
commitb22afef72c5cab001b7458defc3d042742803b9d (patch)
tree65fe64463c91008ab36d2d180679c453f262842b /source/blender/editors/animation/drivers.c
parent3c7707b49fc634f4850c1b3f0e3a439a91bde891 (diff)
Cleanup: Replace 'add mode' short for driver FCurve creation with an enum
The 'add mode' was a `short` between -1 and 2 inclusive, and magic numbers sprinkled throughout the code. It's now an enum with descriptive names. No functional changes.
Diffstat (limited to 'source/blender/editors/animation/drivers.c')
-rw-r--r--source/blender/editors/animation/drivers.c38
1 files changed, 18 insertions, 20 deletions
diff --git a/source/blender/editors/animation/drivers.c b/source/blender/editors/animation/drivers.c
index 7b9e6a10f44..e75dd92e90b 100644
--- a/source/blender/editors/animation/drivers.c
+++ b/source/blender/editors/animation/drivers.c
@@ -62,13 +62,11 @@
/* Get (or add relevant data to be able to do so) F-Curve from the driver stack,
* for the given Animation Data block. This assumes that all the destinations are valid.
- *
- * - add: 0 - don't add anything if not found,
- * 1 - add new Driver FCurve (with keyframes for visual tweaking),
- * 2 - add new Driver FCurve (with generator, for script backwards compatibility)
- * -1 - add new Driver FCurve without driver stuff (for pasting)
*/
-FCurve *verify_driver_fcurve(ID *id, const char rna_path[], const int array_index, short add)
+FCurve *verify_driver_fcurve(ID *id,
+ const char rna_path[],
+ const int array_index,
+ eDriverFCurveCreationMode creation_mode)
{
AnimData *adt;
FCurve *fcu;
@@ -80,7 +78,7 @@ FCurve *verify_driver_fcurve(ID *id, const char rna_path[], const int array_inde
/* init animdata if none available yet */
adt = BKE_animdata_from_id(id);
- if ((adt == NULL) && (add)) {
+ if (adt == NULL && creation_mode != DRIVER_FCURVE_LOOKUP_ONLY) {
adt = BKE_animdata_add_id(id);
}
if (adt == NULL) {
@@ -94,9 +92,9 @@ FCurve *verify_driver_fcurve(ID *id, const char rna_path[], const int array_inde
*/
fcu = list_find_fcurve(&adt->drivers, rna_path, array_index);
- if ((fcu == NULL) && (add)) {
+ if (fcu == NULL && creation_mode != DRIVER_FCURVE_LOOKUP_ONLY) {
/* use default settings to make a F-Curve */
- fcu = alloc_driver_fcurve(rna_path, array_index, add);
+ fcu = alloc_driver_fcurve(rna_path, array_index, creation_mode);
/* just add F-Curve to end of driver list */
BLI_addtail(&adt->drivers, fcu);
@@ -106,7 +104,9 @@ FCurve *verify_driver_fcurve(ID *id, const char rna_path[], const int array_inde
return fcu;
}
-struct FCurve *alloc_driver_fcurve(const char rna_path[], const int array_index, short add)
+struct FCurve *alloc_driver_fcurve(const char rna_path[],
+ const int array_index,
+ eDriverFCurveCreationMode creation_mode)
{
FCurve *fcu = MEM_callocN(sizeof(FCurve), "FCurve");
@@ -119,9 +119,7 @@ struct FCurve *alloc_driver_fcurve(const char rna_path[], const int array_index,
}
fcu->array_index = array_index;
- /* If add is negative, don't init this data yet,
- * since it will be filled in by the pasted driver. */
- if (add > 0) {
+ if (!ELEM(creation_mode, DRIVER_FCURVE_LOOKUP_ONLY, DRIVER_FCURVE_EMPTY)) {
BezTriple *bezt;
size_t i;
@@ -129,8 +127,7 @@ struct FCurve *alloc_driver_fcurve(const char rna_path[], const int array_index,
fcu->driver = MEM_callocN(sizeof(ChannelDriver), "ChannelDriver");
/* F-Modifier or Keyframes? */
- // FIXME: replace these magic numbers with defines
- if (add == 2) {
+ if (creation_mode == DRIVER_FCURVE_GENERATOR) {
/* Python API Backwards compatibility hack:
* Create FModifier so that old scripts won't break
* for now before 2.7 series -- (September 4, 2013)
@@ -177,7 +174,8 @@ static int add_driver_with_target(ReportList *UNUSED(reports),
int driver_type)
{
FCurve *fcu;
- short add_mode = (flag & CREATEDRIVER_WITH_FMODIFIER) ? 2 : 1;
+ short add_mode = (flag & CREATEDRIVER_WITH_FMODIFIER) ? DRIVER_FCURVE_GENERATOR :
+ DRIVER_FCURVE_KEYFRAMES;
const char *prop_name = RNA_property_identifier(src_prop);
/* Create F-Curve with Driver */
@@ -593,7 +591,7 @@ bool ANIM_remove_driver(ReportList *UNUSED(reports),
* Note: here is one of the places where we don't want new F-Curve + Driver added!
* so 'add' var must be 0
*/
- fcu = verify_driver_fcurve(id, rna_path, array_index, 0);
+ fcu = verify_driver_fcurve(id, rna_path, array_index, DRIVER_FCURVE_LOOKUP_ONLY);
if (fcu) {
BLI_remlink(&adt->drivers, fcu);
free_fcurve(fcu);
@@ -653,7 +651,7 @@ bool ANIM_copy_driver(
}
/* try to get F-Curve with Driver */
- fcu = verify_driver_fcurve(id, rna_path, array_index, 0);
+ fcu = verify_driver_fcurve(id, rna_path, array_index, DRIVER_FCURVE_LOOKUP_ONLY);
/* clear copy/paste buffer first (for consistency with other copy/paste buffers) */
ANIM_drivers_copybuf_free();
@@ -711,7 +709,7 @@ bool ANIM_paste_driver(
}
/* create Driver F-Curve, but without data which will be copied across... */
- fcu = verify_driver_fcurve(id, rna_path, array_index, -1);
+ fcu = verify_driver_fcurve(id, rna_path, array_index, DRIVER_FCURVE_EMPTY);
if (fcu) {
/* copy across the curve data from the buffer curve
@@ -855,7 +853,7 @@ void ANIM_copy_as_driver(struct ID *target_id, const char *target_path, const ch
ANIM_driver_vars_copybuf_free();
/* Create a dummy driver F-Curve. */
- FCurve *fcu = alloc_driver_fcurve(NULL, 0, 1);
+ FCurve *fcu = alloc_driver_fcurve(NULL, 0, DRIVER_FCURVE_KEYFRAMES);
ChannelDriver *driver = fcu->driver;
/* Create a variable. */