[Bf-blender-cvs] [878a805ae8a] master: Cleanup/simplify BKE_fcurve_find_by_rna_context_ui code.

Bastien Montagne noreply at git.blender.org
Mon May 30 12:08:57 CEST 2022


Commit: 878a805ae8a1e541b2c227e7d51395a22ac68772
Author: Bastien Montagne
Date:   Fri May 27 14:35:57 2022 +0200
Branches: master
https://developer.blender.org/rB878a805ae8a1e541b2c227e7d51395a22ac68772

Cleanup/simplify BKE_fcurve_find_by_rna_context_ui code.

>From reading the code it looks like at some point the code was expecting
the `tptr` PointerRNA to change during the loop? But currently it did
not make any sense to have this complex looping and multi-checking of
RNA path and animdata, since the RNA pointer (and therefore its
`owner_id`) is never modified...

NOTE: there could be much more cleanup done in that area, goal of this
commit is mainly to simplify the logic by removing all the (seamingly)
dead code.

Differential Revision: https://developer.blender.org/D15026

===================================================================

M	source/blender/blenkernel/BKE_fcurve.h
M	source/blender/blenkernel/intern/fcurve.c
M	source/blender/makesrna/RNA_access.h
M	source/blender/makesrna/intern/rna_access.c

===================================================================

diff --git a/source/blender/blenkernel/BKE_fcurve.h b/source/blender/blenkernel/BKE_fcurve.h
index 6784a1296e9..78d80ce200e 100644
--- a/source/blender/blenkernel/BKE_fcurve.h
+++ b/source/blender/blenkernel/BKE_fcurve.h
@@ -293,7 +293,7 @@ struct FCurve *BKE_fcurve_find_by_rna(struct PointerRNA *ptr,
  * temp hack needed for complex paths like texture ones.
  */
 struct FCurve *BKE_fcurve_find_by_rna_context_ui(struct bContext *C,
-                                                 struct PointerRNA *ptr,
+                                                 const struct PointerRNA *ptr,
                                                  struct PropertyRNA *prop,
                                                  int rnaindex,
                                                  struct AnimData **r_animdata,
diff --git a/source/blender/blenkernel/intern/fcurve.c b/source/blender/blenkernel/intern/fcurve.c
index 34357c3e454..952d5df299c 100644
--- a/source/blender/blenkernel/intern/fcurve.c
+++ b/source/blender/blenkernel/intern/fcurve.c
@@ -351,8 +351,8 @@ FCurve *BKE_fcurve_find_by_rna(PointerRNA *ptr,
       NULL, ptr, prop, rnaindex, r_adt, r_action, r_driven, r_special);
 }
 
-FCurve *BKE_fcurve_find_by_rna_context_ui(bContext *C,
-                                          PointerRNA *ptr,
+FCurve *BKE_fcurve_find_by_rna_context_ui(bContext *UNUSED(C),
+                                          const PointerRNA *ptr,
                                           PropertyRNA *prop,
                                           int rnaindex,
                                           AnimData **r_animdata,
@@ -361,7 +361,6 @@ FCurve *BKE_fcurve_find_by_rna_context_ui(bContext *C,
                                           bool *r_special)
 {
   FCurve *fcu = NULL;
-  PointerRNA tptr = *ptr;
 
   *r_driven = false;
   *r_special = false;
@@ -388,79 +387,51 @@ FCurve *BKE_fcurve_find_by_rna_context_ui(bContext *C,
   }
 
   /* There must be some RNA-pointer + property combo. */
-  if (prop && tptr.owner_id && RNA_property_animateable(&tptr, prop)) {
-    AnimData *adt = BKE_animdata_from_id(tptr.owner_id);
-    int step = (
-        /* Always 1 in case we have no context (can't check in 'ancestors' of given RNA ptr). */
-        C ? 2 : 1);
-    char *path = NULL;
-
-    if (!adt && C) {
-      path = RNA_path_from_ID_to_property(&tptr, prop);
-      adt = BKE_animdata_from_id(tptr.owner_id);
-      step--;
-    }
-
-    /* Standard F-Curve - Animation (Action) or Drivers. */
-    while (adt && step--) {
-      if ((adt->action == NULL || adt->action->curves.first == NULL) &&
-          (adt->drivers.first == NULL)) {
-        continue;
-      }
-
-      /* XXX This function call can become a performance bottleneck. */
-      if (step) {
-        path = RNA_path_from_ID_to_property(&tptr, prop);
-      }
-      if (path == NULL) {
-        continue;
-      }
+  if (!prop || !ptr->owner_id || !RNA_property_animateable(ptr, prop)) {
+    return fcu;
+  }
 
-      /* XXX: The logic here is duplicated with a function up above. */
-      /* animation takes priority over drivers. */
-      if (adt->action && adt->action->curves.first) {
-        fcu = BKE_fcurve_find(&adt->action->curves, path, rnaindex);
+  AnimData *adt = BKE_animdata_from_id(ptr->owner_id);
+  if (adt == NULL) {
+    return fcu;
+  }
 
-        if (fcu && r_action) {
-          *r_action = adt->action;
-        }
-      }
+  const bool has_action_fcurves = adt->action != NULL &&
+                                  !BLI_listbase_is_empty(&adt->action->curves);
+  const bool has_drivers = !BLI_listbase_is_empty(&adt->drivers);
 
-      /* If not animated, check if driven. */
-      if (!fcu && (adt->drivers.first)) {
-        fcu = BKE_fcurve_find(&adt->drivers, path, rnaindex);
+  /* XXX This function call can become a performance bottleneck. */
+  char *path = RNA_path_from_ID_to_property(ptr, prop);
 
-        if (fcu) {
-          if (r_animdata) {
-            *r_animdata = adt;
-          }
-          *r_driven = true;
-        }
-      }
+  /* Standard F-Curve - Animation (Action) or Drivers. */
+  /* Animation takes priority over drivers. */
+  /* XXX: The logic here is duplicated with a function up above. */
+  if (has_action_fcurves) {
+    fcu = BKE_fcurve_find(&adt->action->curves, path, rnaindex);
 
-      if (fcu && r_action) {
-        if (r_animdata) {
-          *r_animdata = adt;
-        }
+    if (fcu) {
+      if (r_action) {
         *r_action = adt->action;
-        break;
       }
+      if (r_animdata) {
+        *r_animdata = adt;
+      }
+    }
+  }
 
-      if (step) {
-        char *tpath = path ? path : RNA_path_from_ID_to_property(&tptr, prop);
-        if (tpath && tpath != path) {
-          MEM_freeN(path);
-          path = tpath;
-          adt = BKE_animdata_from_id(tptr.owner_id);
-        }
-        else {
-          adt = NULL;
-        }
+  /* If not animated, check if driven. */
+  if (fcu == NULL && has_drivers) {
+    fcu = BKE_fcurve_find(&adt->drivers, path, rnaindex);
+
+    if (fcu) {
+      if (r_animdata) {
+        *r_animdata = adt;
       }
+      *r_driven = true;
     }
-    MEM_SAFE_FREE(path);
   }
 
+  MEM_SAFE_FREE(path);
   return fcu;
 }
 
diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h
index 4267ce47d81..e855395482e 100644
--- a/source/blender/makesrna/RNA_access.h
+++ b/source/blender/makesrna/RNA_access.h
@@ -284,7 +284,7 @@ bool RNA_property_editable_index(PointerRNA *ptr, PropertyRNA *prop, const int i
  */
 bool RNA_property_editable_flag(PointerRNA *ptr, PropertyRNA *prop);
 
-bool RNA_property_animateable(PointerRNA *ptr, PropertyRNA *prop);
+bool RNA_property_animateable(const PointerRNA *ptr, PropertyRNA *prop);
 bool RNA_property_animated(PointerRNA *ptr, PropertyRNA *prop);
 /**
  * \note Does not take into account editable status, this has to be checked separately
diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c
index c8cb0b7ffb8..75579107465 100644
--- a/source/blender/makesrna/intern/rna_access.c
+++ b/source/blender/makesrna/intern/rna_access.c
@@ -1989,7 +1989,7 @@ bool RNA_property_editable_index(PointerRNA *ptr, PropertyRNA *prop, const int i
   return rna_property_editable_do(ptr, prop, index, NULL);
 }
 
-bool RNA_property_animateable(PointerRNA *ptr, PropertyRNA *prop)
+bool RNA_property_animateable(const PointerRNA *ptr, PropertyRNA *prop)
 {
   /* check that base ID-block can support animation data */
   if (!id_can_have_animdata(ptr->owner_id)) {



More information about the Bf-blender-cvs mailing list