[Bf-blender-cvs] [8965a812716] master: Cleanup: Split some code out of rna_access.c

Bastien Montagne noreply at git.blender.org
Thu Aug 22 15:36:07 CEST 2019


Commit: 8965a81271661d017c8dea93446c75677ba2f7eb
Author: Bastien Montagne
Date:   Thu Aug 22 15:31:07 2019 +0200
Branches: master
https://developer.blender.org/rB8965a81271661d017c8dea93446c75677ba2f7eb

Cleanup: Split some code out of rna_access.c

That file was getting out of control, now comparison/override RNA code is
in `rna_access_compare_override.c`. 1K lines of code for now, but that
area is likely to grow more in the future...

Note that we can probably split more out of `rna_access.c`, but for now
that will do.

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

M	source/blender/makesrna/intern/CMakeLists.txt
M	source/blender/makesrna/intern/rna_access.c
A	source/blender/makesrna/intern/rna_access_compare_override.c
A	source/blender/makesrna/intern/rna_access_internal.h

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

diff --git a/source/blender/makesrna/intern/CMakeLists.txt b/source/blender/makesrna/intern/CMakeLists.txt
index 7c31f078b6d..2745cfa9740 100644
--- a/source/blender/makesrna/intern/CMakeLists.txt
+++ b/source/blender/makesrna/intern/CMakeLists.txt
@@ -364,9 +364,11 @@ add_custom_command(
 # Build bf_rna
 set(SRC
   rna_access.c
+  rna_access_compare_override.c
   ${GENSRC}
 
   ${SRC_RNA_INC}
+  rna_access_internal.h
   rna_internal.h
   rna_internal_types.h
   rna_mesh_utils.h
diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c
index 7b7af5c12db..c4b0e43fd70 100644
--- a/source/blender/makesrna/intern/rna_access.c
+++ b/source/blender/makesrna/intern/rna_access.c
@@ -37,10 +37,6 @@
 #include "BLI_ghash.h"
 #include "BLI_math.h"
 
-#ifdef DEBUG_OVERRIDE_TIMEIT
-#  include "PIL_time_utildefines.h"
-#endif
-
 #include "BLF_api.h"
 #include "BLT_translation.h"
 
@@ -49,7 +45,6 @@
 #include "BKE_idcode.h"
 #include "BKE_idprop.h"
 #include "BKE_fcurve.h"
-#include "BKE_library_override.h"
 #include "BKE_main.h"
 #include "BKE_report.h"
 
@@ -67,6 +62,7 @@
 #include "WM_types.h"
 
 #include "rna_internal.h"
+#include "rna_access_internal.h"
 
 const PointerRNA PointerRNA_NULL = {{NULL}};
 
@@ -249,7 +245,7 @@ void RNA_pointer_recast(PointerRNA *ptr, PointerRNA *r_ptr)
 
 /* ID Properties */
 
-static void rna_idproperty_touch(IDProperty *idprop)
+void rna_idproperty_touch(IDProperty *idprop)
 {
   /* so the property is seen as 'set' by rna */
   idprop->flag &= ~IDP_FLAG_GHOST;
@@ -619,7 +615,7 @@ PropertyRNA *rna_ensure_property_realdata(PropertyRNA **prop, PointerRNA *ptr)
   return rna_idproperty_check_ex(prop, ptr, true);
 }
 
-static PropertyRNA *rna_ensure_property(PropertyRNA *prop)
+PropertyRNA *rna_ensure_property(PropertyRNA *prop)
 {
   /* the quick version if we don't need the idproperty */
 
@@ -1171,11 +1167,6 @@ int RNA_property_flag(PropertyRNA *prop)
   return rna_ensure_property(prop)->flag;
 }
 
-int RNA_property_override_flag(PropertyRNA *prop)
-{
-  return rna_ensure_property(prop)->flag_override;
-}
-
 /**
  * Get the tags set for \a prop as int bitfield.
  * \note Doesn't perform any validity check on the set bits. #RNA_def_property_tags does this
@@ -2194,77 +2185,6 @@ bool RNA_property_animated(PointerRNA *ptr, PropertyRNA *prop)
 
   return false;
 }
-
-/** \note Does not take into account editable status, this has to be checked separately
- * (using #RNA_property_editable_flag() usually). */
-bool RNA_property_overridable_get(PointerRNA *ptr, PropertyRNA *prop)
-{
-  if (prop->magic == RNA_MAGIC) {
-    /* Special handling for insertions of constraints or modifiers... */
-    /* TODO Note We may want to add a more generic system to RNA
-     * (like a special property in struct of items)
-     * if we get more overrideable collections,
-     * for now we can live with those special-cases handling I think. */
-    if (RNA_struct_is_a(ptr->type, &RNA_Constraint)) {
-      bConstraint *con = ptr->data;
-      if (con->flag & CONSTRAINT_OVERRIDE_LIBRARY_LOCAL) {
-        return true;
-      }
-    }
-    else if (RNA_struct_is_a(ptr->type, &RNA_Modifier)) {
-      ModifierData *mod = ptr->data;
-      if (mod->flag & eModifierFlag_OverrideLibrary_Local) {
-        return true;
-      }
-    }
-    /* If this is a RNA-defined property (real or 'virtual' IDProp),
-     * we want to use RNA prop flag. */
-    return !(prop->flag_override & PROPOVERRIDE_NO_COMPARISON) &&
-           (prop->flag_override & PROPOVERRIDE_OVERRIDABLE_LIBRARY);
-  }
-  else {
-    /* If this is a real 'pure' IDProp (aka custom property), we want to use the IDProp flag. */
-    return !(prop->flag_override & PROPOVERRIDE_NO_COMPARISON) &&
-           (((IDProperty *)prop)->flag & IDP_FLAG_OVERRIDABLE_LIBRARY);
-  }
-}
-
-/* Should only be used for custom properties */
-bool RNA_property_overridable_library_set(PointerRNA *UNUSED(ptr),
-                                          PropertyRNA *prop,
-                                          const bool is_overridable)
-{
-  /* Only works for pure custom properties IDProps. */
-  if (prop->magic != RNA_MAGIC) {
-    IDProperty *idprop = (IDProperty *)prop;
-
-    idprop->flag = is_overridable ? (idprop->flag | IDP_FLAG_OVERRIDABLE_LIBRARY) :
-                                    (idprop->flag & ~IDP_FLAG_OVERRIDABLE_LIBRARY);
-    return true;
-  }
-
-  return false;
-}
-
-bool RNA_property_overridden(PointerRNA *ptr, PropertyRNA *prop)
-{
-  char *rna_path = RNA_path_from_ID_to_property(ptr, prop);
-  ID *id = ptr->id.data;
-
-  if (rna_path == NULL || id == NULL || id->override_library == NULL) {
-    return false;
-  }
-
-  return (BKE_override_library_property_find(id->override_library, rna_path) != NULL);
-}
-
-bool RNA_property_comparable(PointerRNA *UNUSED(ptr), PropertyRNA *prop)
-{
-  prop = rna_ensure_property(prop);
-
-  return !(prop->flag_override & PROPOVERRIDE_NO_COMPARISON);
-}
-
 /* this function is to check if its possible to create a valid path from the ID
  * its slow so don't call in a loop */
 bool RNA_property_path_from_ID_check(PointerRNA *ptr, PropertyRNA *prop)
@@ -8115,59 +8035,6 @@ bool RNA_property_assign_default(PointerRNA *ptr, PropertyRNA *prop)
   }
 }
 
-static bool rna_property_override_operation_apply(Main *bmain,
-                                                  PointerRNA *ptr_local,
-                                                  PointerRNA *ptr_override,
-                                                  PointerRNA *ptr_storage,
-                                                  PropertyRNA *prop_local,
-                                                  PropertyRNA *prop_override,
-                                                  PropertyRNA *prop_storage,
-                                                  PointerRNA *ptr_item_local,
-                                                  PointerRNA *ptr_item_override,
-                                                  PointerRNA *ptr_item_storage,
-                                                  IDOverrideLibraryPropertyOperation *opop);
-
-bool RNA_property_copy(
-    Main *bmain, PointerRNA *ptr, PointerRNA *fromptr, PropertyRNA *prop, int index)
-{
-  if (!RNA_property_editable(ptr, prop)) {
-    return false;
-  }
-
-  PropertyRNA *prop_dst = prop;
-  PropertyRNA *prop_src = prop;
-
-  /* Ensure we get real property data,
-   * be it an actual RNA property, or an IDProperty in disguise. */
-  prop_dst = rna_ensure_property_realdata(&prop_dst, ptr);
-  prop_src = rna_ensure_property_realdata(&prop_src, fromptr);
-
-  /* IDprops: destination may not exist, if source does and is set, try to create it. */
-  /* Note: this is sort of quick hack/bandage to fix the issue,
-   * we need to rethink how IDProps are handled in 'diff' RNA code completely, imho... */
-  if (prop_src != NULL && prop_dst == NULL && RNA_property_is_set(fromptr, prop)) {
-    BLI_assert(prop_src->magic != RNA_MAGIC);
-    IDProperty *idp_dst = RNA_struct_idprops(ptr, true);
-    IDProperty *prop_idp_dst = IDP_CopyProperty((IDProperty *)prop_src);
-    IDP_AddToGroup(idp_dst, prop_idp_dst);
-    rna_idproperty_touch(prop_idp_dst);
-    /* Nothing else to do here... */
-    return true;
-  }
-
-  if (ELEM(NULL, prop_dst, prop_src)) {
-    return false;
-  }
-
-  IDOverrideLibraryPropertyOperation opop = {
-      .operation = IDOVERRIDE_LIBRARY_OP_REPLACE,
-      .subitem_reference_index = index,
-      .subitem_local_index = index,
-  };
-  return rna_property_override_operation_apply(
-      bmain, ptr, fromptr, NULL, prop_dst, prop_src, NULL, NULL, NULL, NULL, &opop);
-}
-
 /* use RNA_warning macro which includes __func__ suffix */
 void _RNA_warning(const char *format, ...)
 {
@@ -8190,934 +8057,6 @@ void _RNA_warning(const char *format, ...)
 #endif
 }
 
-static int rna_property_override_diff(Main *bmain,
-                                      PointerRNA *ptr_a,
-                                      PointerRNA *ptr_b,
-                                      PropertyRNA *prop,
-                                      PropertyRNA *prop_a,
-                                      PropertyRNA *prop_b,
-                                      const char *rna_path,
-                                      eRNACompareMode mode,
-                                      IDOverrideLibrary *override,
-                                      const int flags,
-                                      eRNAOverrideMatchResult *r_report_flags);
-
-bool RNA_property_equals(
-    Main *bmain, PointerRNA *ptr_a, PointerRNA *ptr_b, PropertyRNA *prop, eRNACompareMode mode)
-{
-  BLI_assert(ELEM(mode, RNA_EQ_STRICT, RNA_EQ_UNSET_MATCH_ANY, RNA_EQ_UNSET_MATCH_NONE));
-
-  return (rna_property_override_diff(
-              bmain, ptr_a, ptr_b, prop, NULL, NULL, NULL, mode, NULL, 0, NULL) == 0);
-}
-
-bool RNA_struct_equals(Main *bmain, PointerRNA *ptr_a, PointerRNA *ptr_b, eRNACompareMode mode)
-{
-  CollectionPropertyIterator iter;
-  PropertyRNA *iterprop;
-  bool equals = true;
-
-  if (ptr_a == NULL && ptr_b == NULL) {
-    return true;
-  }
-  else if (ptr_a == NULL || ptr_b == NULL) {
-    return false;
-  }
-  else if (ptr_a->type != ptr_b->type) {
-    return false;
-  }
-
-  iterprop = RNA_struct_iterator_property(ptr_a->type);
-
-  RNA_property_collection_begin(ptr_a, iterprop, &iter);
-  for (; iter.valid; RNA_property_collection_next(&iter)) {
-    PropertyRNA *prop = iter.ptr.data;
-
-    if (!RNA_property_equals(bmain, ptr_a, ptr_b, prop, mode)) {
-      equals = false;
-      break;
-    }
-  }
-  RNA_property_collection_end(&iter);
-
-  return equals;
-}
-
-/* Low-level functions, also used by non-override RNA API like copy or equality check. */
-
-/** Generic RNA property diff function.
- *
- * \note about \a prop and \a prop_a/prop_b parameters:
- * the former is expected to be an 'un-resolved' one,
- * while the two later are expected to be fully resolved ones
- * (i.e. to be the IDProps when they should be, etc.).
- * When \a prop is given, \a prop_a and \a prop_b should always be NULL, and vice-versa.
- * This is necessary, because we cannot perform 'set/unset' checks on resolved properties
- * (unset IDProps w

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list