diff options
author | Sybren A. Stüvel <sybren@blender.org> | 2021-03-01 20:18:20 +0300 |
---|---|---|
committer | Sybren A. Stüvel <sybren@blender.org> | 2021-03-01 20:18:20 +0300 |
commit | 03ab698921ef3452b3fc72e7edb47a0d1040d8d8 (patch) | |
tree | 7738be7ff962b4a8e244f44b0c5b8f4b1dad3fe0 | |
parent | fdbc54ca742e3a2b428be2ce4885ef85f61be9dd (diff) |
Cleanup: refactor `BKE_animsys_store_rna_setting()`
Lower the cognitive complexity of `BKE_animsys_store_rna_setting()` by
flipping conditions and using early returns.
No functional changes.
-rw-r--r-- | source/blender/blenkernel/intern/anim_sys.c | 69 |
1 files changed, 33 insertions, 36 deletions
diff --git a/source/blender/blenkernel/intern/anim_sys.c b/source/blender/blenkernel/intern/anim_sys.c index ca63d1cb692..a23b10a0da6 100644 --- a/source/blender/blenkernel/intern/anim_sys.c +++ b/source/blender/blenkernel/intern/anim_sys.c @@ -382,47 +382,44 @@ bool BKE_animsys_store_rna_setting(PointerRNA *ptr, const int array_index, PathResolvedRNA *r_result) { - bool success = false; - const char *path = rna_path; + if (rna_path == NULL) { + return false; + } - /* write value to setting */ - if (path) { - /* get property to write to */ - if (RNA_path_resolve_property(ptr, path, &r_result->ptr, &r_result->prop)) { - if ((ptr->owner_id == NULL) || RNA_property_animateable(&r_result->ptr, r_result->prop)) { - int array_len = RNA_property_array_length(&r_result->ptr, r_result->prop); - - if (array_len && array_index >= array_len) { - if (G.debug & G_DEBUG) { - CLOG_WARN(&LOG, - "Animato: Invalid array index. ID = '%s', '%s[%d]', array length is %d", - (ptr->owner_id) ? (ptr->owner_id->name + 2) : "<No ID>", - path, - array_index, - array_len - 1); - } - } - else { - r_result->prop_index = array_len ? array_index : -1; - success = true; - } - } + const char *path = rna_path; + if (!RNA_path_resolve_property(ptr, path, &r_result->ptr, &r_result->prop)) { + /* failed to get path */ + /* XXX don't tag as failed yet though, as there are some legit situations (Action Constraint) + * where some channels will not exist, but shouldn't lock up Action */ + if (G.debug & G_DEBUG) { + CLOG_WARN(&LOG, + "Animato: Invalid path. ID = '%s', '%s[%d]'", + (ptr->owner_id) ? (ptr->owner_id->name + 2) : "<No ID>", + path, + array_index); } - else { - /* failed to get path */ - /* XXX don't tag as failed yet though, as there are some legit situations (Action Constraint) - * where some channels will not exist, but shouldn't lock up Action */ - if (G.debug & G_DEBUG) { - CLOG_WARN(&LOG, - "Animato: Invalid path. ID = '%s', '%s[%d]'", - (ptr->owner_id) ? (ptr->owner_id->name + 2) : "<No ID>", - path, - array_index); - } + return false; + } + + if (ptr->owner_id != NULL && !RNA_property_animateable(&r_result->ptr, r_result->prop)) { + return false; + } + + int array_len = RNA_property_array_length(&r_result->ptr, r_result->prop); + if (array_len && array_index >= array_len) { + if (G.debug & G_DEBUG) { + CLOG_WARN(&LOG, + "Animato: Invalid array index. ID = '%s', '%s[%d]', array length is %d", + (ptr->owner_id) ? (ptr->owner_id->name + 2) : "<No ID>", + path, + array_index, + array_len - 1); } + return false; } - return success; + r_result->prop_index = array_len ? array_index : -1; + return true; } /* less than 1.0 evaluates to false, use epsilon to avoid float error */ |