[Bf-blender-cvs] [8684e15] id_override_static: More work and refactor in RNA override part mostly.

Bastien Montagne noreply at git.blender.org
Wed Jan 4 10:41:07 CET 2017


Commit: 8684e1566d6a52574b5c29cdd4982258d264e8ec
Author: Bastien Montagne
Date:   Tue Jan 3 18:45:09 2017 +0100
Branches: id_override_static
https://developer.blender.org/rB8684e1566d6a52574b5c29cdd4982258d264e8ec

More work and refactor in RNA override part mostly.

This commit mainly extend/refactor RNA prop copy and equals functions
into more advanced override utils (since equals is a subset of
aurooverride operations generation, and copy is a subset of override
operations application).

And some other work needed on the road...

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

M	source/blender/blenkernel/BKE_library_override.h
M	source/blender/blenkernel/intern/library_override.c
M	source/blender/blenlib/BLI_listbase.h
M	source/blender/blenlib/intern/listbase.c
M	source/blender/makesrna/intern/rna_access.c

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

diff --git a/source/blender/blenkernel/BKE_library_override.h b/source/blender/blenkernel/BKE_library_override.h
index ae68a9e..0ab90ed 100644
--- a/source/blender/blenkernel/BKE_library_override.h
+++ b/source/blender/blenkernel/BKE_library_override.h
@@ -35,6 +35,7 @@
 struct ID;
 struct IDOverride;
 struct IDOverrideProperty;
+struct IDOverridePropertyOperation;
 struct Main;
 
 struct IDOverride *BKE_override_init(struct ID *local_id, struct ID *reference_id);
@@ -42,6 +43,16 @@ void BKE_override_clear(struct IDOverride *override);
 void BKE_override_free(struct IDOverride **override);
 
 struct IDOverrideProperty *BKE_override_property_find(struct IDOverride *override, const char *rna_path);
+struct IDOverrideProperty *BKE_override_property_get(struct IDOverride *override, const char *rna_path, bool *r_created);
+
+struct IDOverridePropertyOperation *BKE_override_property_operation_find(
+        struct IDOverrideProperty *override_property,
+        const char *subitem_refname, const char *subitem_locname,
+        const int subitem_refindex, const int subitem_locindex);
+struct IDOverridePropertyOperation *BKE_override_property_operation_get(
+        struct IDOverrideProperty *override_property, const int operation,
+        const char *subitem_refname, const char *subitem_locname,
+        const int subitem_refindex, const int subitem_locindex, bool *r_created);
 
 bool BKE_override_status_check_local(struct ID *local);
 bool BKE_override_status_check_reference(struct ID *local);
diff --git a/source/blender/blenkernel/intern/library_override.c b/source/blender/blenkernel/intern/library_override.c
index 0ce436f..f65d31a 100644
--- a/source/blender/blenkernel/intern/library_override.c
+++ b/source/blender/blenkernel/intern/library_override.c
@@ -40,6 +40,7 @@
 
 #include "BLI_utildefines.h"
 #include "BLI_listbase.h"
+#include "BLI_string.h"
 
 #include "RNA_access.h"
 #include "RNA_types.h"
@@ -101,6 +102,102 @@ IDOverrideProperty *BKE_override_property_find(IDOverride *override, const char
 }
 
 /**
+ * Find override property from given RNA path, or create it if it does not exist.
+ */
+IDOverrideProperty *BKE_override_property_get(IDOverride *override, const char *rna_path, bool *r_created)
+{
+	/* XXX TODO we'll most likely want a runtime ghash to store taht mapping at some point. */
+	IDOverrideProperty *op = BKE_override_property_find(override, rna_path);
+
+	if (op == NULL) {
+		op = MEM_callocN(sizeof(IDOverrideProperty), __func__);
+		op->rna_path = BLI_strdup(rna_path);
+		BLI_addtail(&override->properties, op);
+
+		if (r_created) {
+			*r_created = true;
+		}
+	}
+	else if (r_created) {
+		*r_created = false;
+	}
+
+	return op;
+}
+
+/**
+ * Find override property operation from given sub-item(s), if it exists.
+ */
+IDOverridePropertyOperation *BKE_override_property_operation_find(
+        IDOverrideProperty *override_property,
+        const char *subitem_refname, const char *subitem_locname,
+        const int subitem_refindex, const int subitem_locindex)
+{
+	IDOverridePropertyOperation *opop;
+
+	if (subitem_refname &&
+	    (opop = BLI_findstring_ptr(&override_property->operations, subitem_refname,
+	                               offsetof(IDOverridePropertyOperation, subitem_reference_name))))
+	{
+		return opop;
+	}
+
+	if (subitem_locname &&
+	    (opop = BLI_findstring_ptr(&override_property->operations, subitem_locname,
+	                               offsetof(IDOverridePropertyOperation, subitem_local_name))))
+	{
+		return opop;
+	}
+
+	if ((opop = BLI_listbase_bytes_find(&override_property->operations, &subitem_refindex, sizeof(subitem_refindex),
+	                                    offsetof(IDOverridePropertyOperation, subitem_reference_index))))
+	{
+		return opop;
+	}
+
+	if ((opop = BLI_listbase_bytes_find(&override_property->operations, &subitem_locindex, sizeof(subitem_locindex),
+	                                    offsetof(IDOverridePropertyOperation, subitem_local_index))))
+	{
+		return opop;
+	}
+
+	return NULL;
+}
+
+/**
+ * Find override property operation from given sub-item(s), or create it if it does not exist.
+ */
+IDOverridePropertyOperation *BKE_override_property_operation_get(
+        IDOverrideProperty *override_property, const int operation,
+        const char *subitem_refname, const char *subitem_locname,
+        const int subitem_refindex, const int subitem_locindex, bool *r_created)
+{
+	IDOverridePropertyOperation *opop = BKE_override_property_operation_find(override_property,
+	                                                                         subitem_refname, subitem_locname,
+	                                                                         subitem_refindex, subitem_locindex);
+
+	if (opop == NULL) {
+		opop = MEM_callocN(sizeof(IDOverridePropertyOperation), __func__);
+		opop->operation = operation;
+		if (subitem_locname) {
+			opop->subitem_local_name = BLI_strdup(subitem_locname);
+		}
+		if (subitem_refname) {
+			opop->subitem_reference_name = BLI_strdup(subitem_refname);
+		}
+		opop->subitem_local_index = subitem_locindex;
+		opop->subitem_reference_index = subitem_refindex;
+
+		BLI_addtail(&override_property->operations, opop);
+	}
+	else if (r_created) {
+		*r_created = false;
+	}
+
+	return opop;
+}
+
+/**
  * Check that status of local data-block is still valid against current reference one.
  *
  * It means that all overridable, but not overridden, properties' local values must be equal to reference ones.
diff --git a/source/blender/blenlib/BLI_listbase.h b/source/blender/blenlib/BLI_listbase.h
index 96349a7..aa55a97 100644
--- a/source/blender/blenlib/BLI_listbase.h
+++ b/source/blender/blenlib/BLI_listbase.h
@@ -50,12 +50,14 @@ void *BLI_findlink(const struct ListBase *listbase, int number) ATTR_WARN_UNUSED
 void *BLI_findstring(const struct ListBase *listbase, const char *id, const int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
 void *BLI_findstring_ptr(const struct ListBase *listbase, const char *id, const int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
 void *BLI_findptr(const struct ListBase *listbase, const void *ptr, const int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
+void *BLI_listbase_bytes_find(const ListBase *listbase, const void *bytes, const size_t bytes_size, const int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1, 2);
 
 /* find backwards */
 void *BLI_rfindlink(const struct ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
 void *BLI_rfindstring(const struct ListBase *listbase, const char *id, const int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
 void *BLI_rfindstring_ptr(const struct ListBase *listbase, const char *id, const int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
 void *BLI_rfindptr(const struct ListBase *listbase, const void *ptr, const int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
+void *BLI_listbase_bytes_rfind(const ListBase *listbase, const void *bytes, const size_t bytes_size, const int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1, 2);
 
 void BLI_freelistN(struct ListBase *listbase) ATTR_NONNULL(1);
 void BLI_addtail(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1);
diff --git a/source/blender/blenlib/intern/listbase.c b/source/blender/blenlib/intern/listbase.c
index c9bf497..3502ddd 100644
--- a/source/blender/blenlib/intern/listbase.c
+++ b/source/blender/blenlib/intern/listbase.c
@@ -630,6 +630,46 @@ void *BLI_rfindptr(const ListBase *listbase, const void *ptr, const int offset)
 }
 
 /**
+ * Finds the first element of listbase which contains the specified bytes
+ * at the specified offset, returning NULL if not found.
+ */
+void *BLI_listbase_bytes_find(const ListBase *listbase, const void *bytes, const size_t bytes_size, const int offset)
+{
+	Link *link = NULL;
+	const void *ptr_iter;
+
+	for (link = listbase->first; link; link = link->next) {
+		ptr_iter = *((const void **)(((const char *)link) + offset));
+
+		if (memcmp(bytes, ptr_iter, bytes_size) == 0) {
+			return link;
+		}
+	}
+
+	return NULL;
+}
+/* same as above but find reverse */
+/**
+ * Finds the last element of listbase which contains the specified bytes
+ * at the specified offset, returning NULL if not found.
+ */
+void *BLI_listbase_bytes_rfind(const ListBase *listbase, const void *bytes, const size_t bytes_size, const int offset)
+{
+	Link *link = NULL;
+	const void *ptr_iter;
+
+	for (link = listbase->last; link; link = link->prev) {
+		ptr_iter = *((const void **)(((const char *)link) + offset));
+
+		if (memcmp(bytes, ptr_iter, bytes_size) == 0) {
+			return link;
+		}
+	}
+
+	return NULL;
+}
+
+/**
  * Returns the 1-based index of the first element of listbase which contains the specified
  * null-terminated string at the specified offset, or -1 if not found.
  */
diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c
index 61040f4..b1684ef 100644
--- a/source/blender/makesrna/intern/rna_access.c
+++ b/source/blender/makesrna/intern/rna_access.c
@@ -6749,120 +6749,12 @@ bool RNA_property_reset(PointerRNA *ptr, PropertyRNA *prop, int index)
 	}
 }
 
+static bool rna_property_override_operation_apply(
+        PointerRNA *ptr, PointerRNA *fromptr, PropertyRNA *prop, int index, int override_op);
+
 bool RNA_property_copy(PointerRNA *ptr, PointerRNA *fromptr, PropertyRNA *prop, int index)
 {
-	int len, fromlen;
-	PropertyRNA *fromprop = prop;
-
-	if (prop->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 = (PropertyRNA *)rna_idproperty_find(ptr, ((IDProperty *)fromprop)->name);
-
-		/* its possible the custom-prop doesn't exist on this data-block */
-		if (prop == NULL) {
-			return false;
-		}
-
-		/* Even though currently we now prop will always be the 'fromprop', this might not be the case in the future. */
-		if (prop == fromprop) {
-			fromprop = (PropertyRNA *)rna_idproperty_find(fromptr, ((IDProperty *)prop)->name);
-		}
-	}
-
-	/* get the length of the array to work with */
-	len = RNA_property_array_length(ptr, prop);
-	fromlen = RNA_property_array_lengt

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list