Commit: f93e0f1a9eefb162cf9432240b101a5d9c372910 Author: Bastien Montagne Date: Fri Jul 10 15:23:52 2020 +0200 Branches: master https://developer.blender.org/rBf93e0f1a9eefb162cf9432240b101a5d9c372910
Refactor override code to properly deal with runtime rna properties too. The triplet static RNA / runtime RNA / custom properties is a real pain to deal with... Using the new `PropertyRNAOrID` struct helps clarifying and properly dealing with all three cases. Note that this makes override of py-defined RNA properties working (support for that will be committed next). Differential Revision: https://developer.blender.org/D8249 =================================================================== M source/blender/makesrna/intern/rna_access.c M source/blender/makesrna/intern/rna_access_compare_override.c M source/blender/makesrna/intern/rna_internal.h M source/blender/makesrna/intern/rna_internal_types.h M source/blender/makesrna/intern/rna_rna.c =================================================================== diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c index c3b417ca79d..8bf715f93c1 100644 --- a/source/blender/makesrna/intern/rna_access.c +++ b/source/blender/makesrna/intern/rna_access.c @@ -2145,9 +2145,7 @@ bool RNA_property_editable_info(PointerRNA *ptr, PropertyRNA *prop, const char * return false; } if (ID_IS_OVERRIDE_LIBRARY(id)) { - /* We need the real data property in case of IDProperty here... */ - PropertyRNA *real_prop = rna_ensure_property_realdata(&prop, ptr); - if (real_prop == NULL || !RNA_property_overridable_get(ptr, real_prop)) { + if (!RNA_property_overridable_get(ptr, prop)) { if (!(*r_info)[0]) { *r_info = N_("Can't edit this property from an override data-block"); } diff --git a/source/blender/makesrna/intern/rna_access_compare_override.c b/source/blender/makesrna/intern/rna_access_compare_override.c index 6789b8173f3..a89c8c4667d 100644 --- a/source/blender/makesrna/intern/rna_access_compare_override.c +++ b/source/blender/makesrna/intern/rna_access_compare_override.c @@ -177,11 +177,8 @@ bool RNA_property_copy( } static int rna_property_override_diff(Main *bmain, - PointerRNA *ptr_a, - PointerRNA *ptr_b, - PropertyRNA *prop, - PropertyRNA *prop_a, - PropertyRNA *prop_b, + PropertyRNAOrID *prop_a, + PropertyRNAOrID *prop_b, const char *rna_path, const size_t rna_path_len, eRNACompareMode mode, @@ -194,8 +191,12 @@ bool RNA_property_equals( { 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, 0, mode, NULL, 0, NULL) == 0); + PropertyRNAOrID prop_a, prop_b; + + rna_property_rna_or_id_get(prop, ptr_a, &prop_a); + rna_property_rna_or_id_get(prop, ptr_b, &prop_b); + + return (rna_property_override_diff(bmain, &prop_a, &prop_b, NULL, 0, mode, NULL, 0, NULL) == 0); } bool RNA_struct_equals(Main *bmain, PointerRNA *ptr_a, PointerRNA *ptr_b, eRNACompareMode mode) @@ -247,11 +248,8 @@ bool RNA_struct_equals(Main *bmain, PointerRNA *ptr_a, PointerRNA *ptr_b, eRNACo * but we cannot determine an order (greater than/lesser than), we return 1. */ static int rna_property_override_diff(Main *bmain, - PointerRNA *ptr_a, - PointerRNA *ptr_b, - PropertyRNA *prop, - PropertyRNA *prop_a, - PropertyRNA *prop_b, + PropertyRNAOrID *prop_a, + PropertyRNAOrID *prop_b, const char *rna_path, const size_t rna_path_len, eRNACompareMode mode, @@ -259,47 +257,33 @@ static int rna_property_override_diff(Main *bmain, const eRNAOverrideMatch flags, eRNAOverrideMatchResult *r_report_flags) { - if (prop != NULL) { - BLI_assert(prop_a == NULL && prop_b == NULL); - prop_a = prop; - prop_b = prop; - } - - if (ELEM(NULL, prop_a, prop_b)) { - return (prop_a == prop_b) ? 0 : 1; - } + BLI_assert(!ELEM(NULL, prop_a, prop_b)); - if (!RNA_property_comparable(ptr_a, prop_a) || !RNA_property_comparable(ptr_b, prop_b)) { + if (prop_a->rnaprop->flag_override & PROPOVERRIDE_NO_COMPARISON || + prop_b->rnaprop->flag_override & PROPOVERRIDE_NO_COMPARISON) { return 0; } if (mode == RNA_EQ_UNSET_MATCH_ANY) { /* Unset properties are assumed to match anything. */ - if (!RNA_property_is_set(ptr_a, prop_a) || !RNA_property_is_set(ptr_b, prop_b)) { + if (!prop_a->is_set || !prop_b->is_set) { return 0; } } else if (mode == RNA_EQ_UNSET_MATCH_NONE) { /* Unset properties never match set properties. */ - if (RNA_property_is_set(ptr_a, prop_a) != RNA_property_is_set(ptr_b, prop_b)) { + if (prop_a->is_set != prop_b->is_set) { return 1; } } - if (prop != NULL) { - /* Ensure we get real property data, be it an actual RNA property, - * or an IDProperty in disguise. */ - prop_a = rna_ensure_property_realdata(&prop_a, ptr_a); - prop_b = rna_ensure_property_realdata(&prop_b, ptr_b); - - if (ELEM(NULL, prop_a, prop_b)) { - return (prop_a == prop_b) ? 0 : 1; - } + if (prop_a->is_idprop && ELEM(NULL, prop_a->idprop, prop_b->idprop)) { + return (prop_a->idprop == prop_b->idprop) ? 0 : 1; } /* Check if we are working with arrays. */ - const bool is_array_a = RNA_property_array_check(prop_a); - const bool is_array_b = RNA_property_array_check(prop_b); + const bool is_array_a = prop_a->is_array; + const bool is_array_b = prop_b->is_array; if (is_array_a != is_array_b) { /* Should probably never happen actually... */ @@ -308,8 +292,8 @@ static int rna_property_override_diff(Main *bmain, } /* Get the length of the array to work with. */ - 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 uint len_a = prop_a->array_len; + const uint len_b = prop_b->array_len; if (len_a != len_b) { /* Do not handle override in that case, @@ -324,30 +308,31 @@ static int rna_property_override_diff(Main *bmain, RNAPropOverrideDiff override_diff = NULL; /* Special case for IDProps, we use default callback then. */ - if (prop_a->magic != RNA_MAGIC) { + if (prop_a->is_idprop) { override_diff = rna_property_override_diff_default; - if (prop_b->magic == RNA_MAGIC && prop_b->override_diff != override_diff) { + if (!prop_b->is_idprop && prop_b->rnaprop->override_diff != override_diff) { override_diff = NULL; } } - else if (prop_b->magic != RNA_MAGIC) { + else if (prop_b->is_idprop) { override_diff = rna_property_override_diff_default; - if (prop_a->override_diff != override_diff) { + if (prop_a->rnaprop->override_diff != override_diff) { override_diff = NULL; } } - else if (prop_a->override_diff == prop_b->override_diff) { - override_diff = prop_a->override_diff; + else if (prop_a->rnaprop->override_diff == prop_b->rnaprop->override_diff) { + override_diff = prop_a->rnaprop->override_diff; + if (override_diff == NULL) { + override_diff = rna_property_override_diff_default; + } } if (override_diff == NULL) { #ifndef NDEBUG printf("'%s' gives unmatching or NULL RNA diff callbacks, should not happen (%d vs. %d).\n", - rna_path ? - rna_path : - (prop_a->magic != RNA_MAGIC ? ((IDProperty *)prop_a)->name : prop_a->identifier), - prop_a->magic == RNA_MAGIC, - prop_b->magic == RNA_MAGIC); + rna_path ? rna_path : prop_a->identifier, + !prop_a->is_idprop, + !prop_b->is_idprop); #endif BLI_assert(0); return 1; @@ -355,16 +340,12 @@ static int rna_property_override_diff(Main *bmain, bool override_changed = false; eRNAOverrideMatch diff_flags = flags; - if (!RNA_property_overridable_get(ptr_a, prop_a)) { + if (!RNA_property_overridable_get(&prop_a->ptr, prop_a->rawprop)) { diff_flags &= ~RNA_OVERRIDE_COMPARE_CREATE; } const int diff = override_diff(bmain, - ptr_a, - ptr_b, prop_a, prop_b, - len_a, - len_b, mode, override, rna_path, @@ -426,10 +407,13 @@ static bool rna_property_override_operation_store(Main *bmain, } else if (prop_local->override_store == prop_reference->override_store) { override_store = prop_local->override_store; + if (override_store == NULL) { + override_store = rna_property_override_store_default; + } } if (ptr_storage != NULL && prop_storage->magic == RNA_MAGIC && - prop_storage->override_store != override_store) { + !ELEM(prop_storage->override_store, NULL, override_store)) { override_store = NULL; } @@ -512,10 +496,13 @@ static bool rna_property_override_operation_apply(Main *bmain, } else if (prop_dst->override_apply == prop_src->override_apply) { override_apply = prop_dst->override_apply; + if (override_apply == NULL) { + override_apply = rna_property_override_apply_default; + } } if (ptr_storage && prop_storage->magic == RNA_MAGIC && - prop_storage->override_apply != override_apply) { + !ELEM(prop_storage->override_apply, NULL, override_apply)) { override_apply = NULL; } @@ -612,38 +599,29 @@ bool RNA_struct_override_matches(Main *bmain, for (RNA_property_collection_begin(ptr_local, iterprop, &iter); iter.valid; RNA_property_collection_next(&iter)) { - PropertyRNA *prop_local = iter.ptr.data; - PropertyRNA *prop_reference = iter.ptr.data; - - /* Ensure we get real property data, be it an actual RNA property, - * or an IDProperty in disguise. */ - prop_local = rna_ensure_property_realdata(&prop_local, ptr_local); - prop_reference = rna_ensure_property_realdata(&prop_reference, ptr_reference); - - /* IDProps (custom properties) are even more of a PITA here, we cannot use - * `rna_ensure_property_realdata()` to deal with them, we have to use the path generated from - * `prop_local` (which is valid) to access to the actual reference counterpart... */ - if (prop_local != NULL && prop_local->magic != RNA_MAGIC && prop_local == prop_reference) @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list [email protected] https://lists.blender.org/mailman/listinfo/bf-blender-cvs
