[Bf-blender-cvs] [7ab8c906865] blender2.8: Serious cleanup/refactor/fixing of new RNA comparison code.

Bastien Montagne noreply at git.blender.org
Mon Dec 18 10:21:07 CET 2017


Commit: 7ab8c906865dddf2ef6164b6271e4469a3a95319
Author: Bastien Montagne
Date:   Mon Dec 18 10:13:43 2017 +0100
Branches: blender2.8
https://developer.blender.org/rB7ab8c906865dddf2ef6164b6271e4469a3a95319

Serious cleanup/refactor/fixing of new RNA comparison code.

Code also handling auto-generation of static overrides.

Aside from some naming consistency cleanup, this commit:

* Is the first step addressing the 'operator' issue with static
overrides, by implementing a first version of the 'restore from
reference' behavior.

* Fixes several issues that were discovered on the way in enhanced
RNA comparision code, like the 'zero-length dynamic array' case, or some
infinite looping caused by some non-ID pointers (that for some
mysterious reasons did not show up previously...).

* Factorizes a bit said RNA comparison code (auto-static override
generation and comparison/check were essentially doing the same thing).

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

M	source/blender/blenkernel/intern/library_override.c
M	source/blender/makesrna/RNA_access.h
M	source/blender/makesrna/intern/rna_access.c
M	source/blender/makesrna/intern/rna_internal_types.h
M	source/blender/makesrna/intern/rna_rna.c

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

diff --git a/source/blender/blenkernel/intern/library_override.c b/source/blender/blenkernel/intern/library_override.c
index 26aeca0564d..a65aea4c292 100644
--- a/source/blender/blenkernel/intern/library_override.c
+++ b/source/blender/blenkernel/intern/library_override.c
@@ -394,7 +394,10 @@ bool BKE_override_static_status_check_local(ID *local)
 	RNA_id_pointer_create(local, &rnaptr_local);
 	RNA_id_pointer_create(reference, &rnaptr_reference);
 
-	if (!RNA_struct_override_matches(&rnaptr_local, &rnaptr_reference, local->override_static, true, true)) {
+	if (!RNA_struct_override_matches(
+	        &rnaptr_local, &rnaptr_reference, NULL, local->override_static,
+	        RNA_OVERRIDE_COMPARE_IGNORE_NON_OVERRIDABLE | RNA_OVERRIDE_COMPARE_IGNORE_OVERRIDDEN, NULL))
+	{
 		local->tag &= ~LIB_TAG_OVERRIDESTATIC_OK;
 		return false;
 	}
@@ -438,7 +441,10 @@ bool BKE_override_static_status_check_reference(ID *local)
 	RNA_id_pointer_create(local, &rnaptr_local);
 	RNA_id_pointer_create(reference, &rnaptr_reference);
 
-	if (!RNA_struct_override_matches(&rnaptr_local, &rnaptr_reference, local->override_static, false, true)) {
+	if (!RNA_struct_override_matches(
+	        &rnaptr_local, &rnaptr_reference, NULL, local->override_static,
+	        RNA_OVERRIDE_COMPARE_IGNORE_OVERRIDDEN, NULL))
+	{
 		local->tag &= ~LIB_TAG_OVERRIDESTATIC_OK;
 		return false;
 	}
@@ -469,8 +475,17 @@ bool BKE_override_static_operations_create(ID *local)
 		RNA_id_pointer_create(local, &rnaptr_local);
 		RNA_id_pointer_create(local->override_static->reference, &rnaptr_reference);
 
-		ret = RNA_struct_auto_override(&rnaptr_local, &rnaptr_reference, local->override_static, NULL);
+		eRNAOverrideMatchResult report_flags = 0;
+		RNA_struct_override_matches(
+		            &rnaptr_local, &rnaptr_reference, NULL, local->override_static,
+		            RNA_OVERRIDE_COMPARE_CREATE | RNA_OVERRIDE_COMPARE_RESTORE, &report_flags);
+		if (report_flags & RNA_OVERRIDE_MATCH_RESULT_CREATED) {
+			ret = true;
+		}
 #ifndef NDEBUG
+		if (report_flags & RNA_OVERRIDE_MATCH_RESULT_RESTORED) {
+			printf("We did restore some properties of %s from its reference.\n", local->name);
+		}
 		if (ret) {
 			printf("We did generate static override rules for %s\n", local->name);
 		}
diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h
index 8d66f59dde5..415e018a3c1 100644
--- a/source/blender/makesrna/RNA_access.h
+++ b/source/blender/makesrna/RNA_access.h
@@ -1251,14 +1251,35 @@ typedef enum eRNACompareMode {
 	RNA_EQ_COMPARE,
 } eRNACompareMode;
 
-bool RNA_property_equals(struct PointerRNA *a, struct PointerRNA *b, struct PropertyRNA *prop, eRNACompareMode mode);
-bool RNA_struct_equals(struct PointerRNA *a, struct PointerRNA *b, eRNACompareMode mode);
+bool RNA_property_equals(struct PointerRNA *ptr_a, struct PointerRNA *ptr_b, struct PropertyRNA *prop, eRNACompareMode mode);
+bool RNA_struct_equals(struct PointerRNA *ptr_a, struct PointerRNA *ptr_b, eRNACompareMode mode);
 
 /* Override. */
 
+/* flags for RNA_struct_override_matches. */
+typedef enum eRNAOverrideMatch {
+	/* Do not compare properties that are not overridable. */
+	RNA_OVERRIDE_COMPARE_IGNORE_NON_OVERRIDABLE = 1 << 0,
+	/* Do not compare properties that are already overridden. */
+	RNA_OVERRIDE_COMPARE_IGNORE_OVERRIDDEN = 1 << 1,
+
+	/* Create new property override if needed and possible. */
+	RNA_OVERRIDE_COMPARE_CREATE = 1 << 16,
+	/* Restore property's value(s) to reference ones if needed and possible. */
+	RNA_OVERRIDE_COMPARE_RESTORE = 1 << 17,
+} eRNAOverrideMatch;
+
+typedef enum eRNAOverrideMatchResult {
+	/* Some new property overrides were created to take into account differences between local and reference. */
+	RNA_OVERRIDE_MATCH_RESULT_CREATED = 1 << 0,
+	/* Some properties were reset to reference values. */
+	RNA_OVERRIDE_MATCH_RESULT_RESTORED = 1 << 1,
+} eRNAOverrideMatchResult;
+
 bool RNA_struct_override_matches(
-        struct PointerRNA *ptr_local, struct PointerRNA *ptr_reference,
-        struct IDOverrideStatic *override, const bool ignore_non_overridable, const bool ignore_overridden);
+        struct PointerRNA *ptr_local, struct PointerRNA *ptr_reference, const char *root_path,
+        struct IDOverrideStatic *override, const eRNAOverrideMatch flags,
+        eRNAOverrideMatchResult *r_report_flags);
 
 bool RNA_struct_override_store(
         struct PointerRNA *ptr_local, struct PointerRNA *ptr_reference, PointerRNA *ptr_storage,
@@ -1268,10 +1289,6 @@ void RNA_struct_override_apply(
         struct PointerRNA *ptr_local, struct PointerRNA *ptr_reference, struct PointerRNA *ptr_storage,
         struct IDOverrideStatic *override);
 
-bool RNA_struct_auto_override(
-        struct PointerRNA *ptr_local, struct PointerRNA *ptr_reference,
-        struct IDOverrideStatic *override, const char *root_path);
-
 struct IDOverrideStaticProperty *RNA_property_override_property_find(PointerRNA *ptr, PropertyRNA *prop);
 struct IDOverrideStaticProperty *RNA_property_override_property_get(PointerRNA *ptr, PropertyRNA *prop, bool *r_created);
 
diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c
index 2be26ccf3ee..da84f51cea2 100644
--- a/source/blender/makesrna/intern/rna_access.c
+++ b/source/blender/makesrna/intern/rna_access.c
@@ -7037,36 +7037,46 @@ void _RNA_warning(const char *format, ...)
 }
 
 static int rna_property_override_diff(
-        PointerRNA *a, PointerRNA *b, PropertyRNA *prop, eRNACompareMode mode,
-        IDOverrideStatic *override, const char *rna_path, bool *r_override_changed, const int flags);
+        PointerRNA *ptr_a, PointerRNA *ptr_b, PropertyRNA *prop_a, PropertyRNA *prop_b, const char *rna_path,
+        eRNACompareMode mode, IDOverrideStatic *override, const int flags, eRNAOverrideMatchResult *r_report_flags);
 
-bool RNA_property_equals(PointerRNA *a, PointerRNA *b, PropertyRNA *prop, eRNACompareMode mode)
+bool RNA_property_equals(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(a, b, prop, mode, NULL, NULL, NULL, 0) != 0);
+	PropertyRNA *prop_a = prop;
+	PropertyRNA *prop_b = prop;
+
+	if (prop_a->magic != RNA_MAGIC) {
+		/* In case of IDProperty, we have to find the *real* idprop of ptr,
+		 * since prop in this case is just a fake wrapper around actual IDProp data, and not a 'real' PropertyRNA. */
+		prop_a = (PropertyRNA *)rna_idproperty_find(ptr_a, ((IDProperty *)prop_a)->name);
+		prop_b = (PropertyRNA *)rna_idproperty_find(ptr_b, ((IDProperty *)prop_b)->name);
+	}
+
+	return (rna_property_override_diff(ptr_a, ptr_b, prop_a, prop_b, NULL, mode, NULL, 0, NULL) != 0);
 }
 
-bool RNA_struct_equals(PointerRNA *a, PointerRNA *b, eRNACompareMode mode)
+bool RNA_struct_equals(PointerRNA *ptr_a, PointerRNA *ptr_b, eRNACompareMode mode)
 {
 	CollectionPropertyIterator iter;
 	PropertyRNA *iterprop;
 	bool equals = true;
 
-	if (a == NULL && b == NULL)
+	if (ptr_a == NULL && ptr_b == NULL)
 		return true;
-	else if (a == NULL || b == NULL)
+	else if (ptr_a == NULL || ptr_b == NULL)
 		return false;
-	else if (a->type != b->type)
+	else if (ptr_a->type != ptr_b->type)
 		return false;
 
-	iterprop = RNA_struct_iterator_property(a->type);
+	iterprop = RNA_struct_iterator_property(ptr_a->type);
 
-	RNA_property_collection_begin(a, iterprop, &iter);
+	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(a, b, prop, mode)) {
+		if (!RNA_property_equals(ptr_a, ptr_b, prop, mode)) {
 			equals = false;
 			break;
 		}
@@ -7079,27 +7089,13 @@ bool RNA_struct_equals(PointerRNA *a, PointerRNA *b, eRNACompareMode mode)
 /* Low-level functions, also used by non-override RNA API like copy or equality check. */
 #include "PIL_time_utildefines.h"
 static int rna_property_override_diff(
-        PointerRNA *ptr_a, PointerRNA *ptr_b, PropertyRNA *prop_a, eRNACompareMode mode,
-        IDOverrideStatic *override, const char *rna_path, bool *r_override_changed, const int flags)
+        PointerRNA *ptr_a, PointerRNA *ptr_b, PropertyRNA *prop_a, PropertyRNA *prop_b, const char *rna_path,
+        eRNACompareMode mode, IDOverrideStatic *override, const int flags, eRNAOverrideMatchResult *r_report_flags)
 {
-	int len_a, len_b;
-
-	PropertyRNA *prop_b = prop_a;
-
-	if (prop_a->magic != RNA_MAGIC) {
-		/* In case of IDProperty, we have to find the *real* idprop of ptr,
-		 * since prop in this case is just a fake wrapper around actual IDProp data, and not a 'real' PropertyRNA. */
-		/* Note: so far callers never resolve IDProps, so we can keep it here for now... */
-		prop_a = (PropertyRNA *)rna_idproperty_find(ptr_a, ((IDProperty *)prop_a)->name);
-		prop_b = (PropertyRNA *)rna_idproperty_find(ptr_b, ((IDProperty *)prop_b)->name);
-
-		if (ELEM(NULL, prop_a, prop_b)) {
-			return 1;
-		}
+	if (ELEM(NULL, prop_a, prop_b)) {
+		return 1;
 	}
 
-	BLI_assert(prop_a->override_diff == prop_b->override_diff && prop_a->override_diff != NULL);
-
 	if (mode == RNA_EQ_UNSET_MATCH_ANY) {
 		/* uninitialized properties are assumed to match anything */
 		if (!RNA_property_is_set(ptr_a, prop_a) || !RNA_property_is_set(ptr_b, prop_b))
@@ -7112,16 +7108,58 @@ static int rna_property_override_diff(
 	}
 
 	/* get the length of the array to work with */
-	len_a = RNA_property_array_length(ptr_a, prop_a);
-	len_b = RNA_property_array_length(ptr_b, prop_b);
+	const int len_a = RNA_property_array_length(ptr_a, prop_a);
+	const int len_b = RNA_property_array_length(ptr_b, prop_b);
+
+	const bool is_array_a = RNA_property_array_check(prop_a);
+	const bool is_array_b = RNA_property_array_check(prop_b);
+
+	if (is_array_a != is_array_b) {
+		/* Should probably never happen actually... */
+		BLI_assert(0);
+		return is_array_a ? 1 : -1;
+	}
 
 	if (len_a != len_b) {
 		/* Do not handle override in that case, we do not support insertion/deletion from arrays for now. */
 		return len_a > len_b ? 1 : -1;
 	}
 
-	return prop_a->override_diff(
-	            ptr_

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list