Commit: 9f801078625d3ff5ce9116e9d8eb75c5edb6eb6e
Author: Bastien Montagne
Date:   Mon Jan 9 10:27:44 2017 +0100
Branches: id_override_static
https://developer.blender.org/rB9f801078625d3ff5ce9116e9d8eb75c5edb6eb6e

Working proof-of-concept of differential override operations.

So, now 'proportional' RNA properties (here, Object's scale) is stored
as 'multiply' override op.

Once again, this is mostly testing for now, there are a lot of potential
issues and traps in current code that'll need more background work to
address later if we keep working in this direction.

Main remaining TODO to complete the proof of concept now is sketching
out a bit of UI/UX control over override!

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

M       source/blender/blenkernel/BKE_library_override.h
M       source/blender/blenkernel/intern/library_override.c
M       source/blender/blenloader/intern/writefile.c
M       source/blender/makesrna/RNA_access.h
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 68238df8b3..e170b41069 100644
--- a/source/blender/blenkernel/BKE_library_override.h
+++ b/source/blender/blenkernel/BKE_library_override.h
@@ -57,6 +57,9 @@ struct IDOverridePropertyOperation 
*BKE_override_property_operation_get(
 bool BKE_override_status_check_local(struct ID *local);
 bool BKE_override_status_check_reference(struct ID *local);
 
+bool BKE_override_operations_store_start(struct ID *local);
+void BKE_override_operations_store_end(struct ID *local);
+
 bool BKE_override_operations_create(struct ID *local);
 
 void BKE_override_update(struct ID *local, const bool do_init);
diff --git a/source/blender/blenkernel/intern/library_override.c 
b/source/blender/blenkernel/intern/library_override.c
index 77dffa4df3..669a8a8fe5 100644
--- a/source/blender/blenkernel/intern/library_override.c
+++ b/source/blender/blenkernel/intern/library_override.c
@@ -271,6 +271,58 @@ bool BKE_override_status_check_reference(ID *local)
 /** Compares local and reference data-blocks and create new override 
operations as needed,
  * or reset to reference values if overriding is not allowed.
  * \return true is new overriding op was created, or some local data was 
reset. */
+bool BKE_override_operations_store_start(ID *local)
+{
+       BLI_assert(local->override != NULL);
+
+       /* Here we work on original local data-block, after having made a temp 
copy of it.
+        * Once we are done, _store_end() will swap temp and local contents.
+        * This allows us to keep most of original data to write (whiwh is 
needed to (hopefully) avoid memory/pointers
+        * collisions in .blend file), and also neats things like original ID 
name. ;) */
+       /* Note: ideally I'd rather work on copy here as well, and not touch to 
original at all, but then we'd have
+        * issues with ID data itself (which is currently not swapped by 
BKE_id_swap()) AND pointers overlapping. */
+
+       ID *tmp_id;
+       id_copy(G.main, local, &tmp_id, false);  /* XXX ...and worse of all, 
this won't work with scene! */
+
+       if (tmp_id == NULL) {
+               return false;
+       }
+
+       PointerRNA rnaptr_reference, rnaptr_final;
+       RNA_id_pointer_create(local->override->reference, &rnaptr_reference);
+       RNA_id_pointer_create(local, &rnaptr_final);
+
+       if (!RNA_struct_override_store(&rnaptr_final, &rnaptr_reference, 
local->override)) {
+               BKE_libblock_free_ex(G.main, tmp_id, true, false);
+               return false;
+       }
+
+       local->tag &= ~LIB_TAG_OVERRIDE_OK;
+       local->newid = tmp_id;
+
+       return true;
+}
+
+void BKE_override_operations_store_end(ID *local)
+{
+       BLI_assert(local->override != NULL);
+
+       ID *tmp_id = local->newid;
+       BLI_assert(tmp_id != NULL);
+
+       /* Swapping here allows us to get back original data. */
+       BKE_id_swap(local, tmp_id);
+
+       local->tag |= LIB_TAG_OVERRIDE_OK;
+       local->newid = NULL;
+
+       BKE_libblock_free_ex(G.main, tmp_id, true, false);
+}
+
+/** Compares local and reference data-blocks and create new override 
operations as needed,
+ * or reset to reference values if overriding is not allowed.
+ * \return true is new overriding op was created, or some local data was 
reset. */
 bool BKE_override_operations_create(ID *local)
 {
        BLI_assert(local->override != NULL);
diff --git a/source/blender/blenloader/intern/writefile.c 
b/source/blender/blenloader/intern/writefile.c
index 2b6ad3db7a..fdf5cc3567 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -163,6 +163,7 @@
 #include "BKE_global.h" // for G
 #include "BKE_idcode.h"
 #include "BKE_library.h" // for  set_listbasepointers
+#include "BKE_library_override.h"
 #include "BKE_main.h"
 #include "BKE_node.h"
 #include "BKE_report.h"
@@ -1859,6 +1860,8 @@ static void write_objects(WriteData *wd, ListBase *idbase)
        ob = idbase->first;
        while (ob) {
                if (ob->id.us > 0 || wd->current) {
+                       const bool do_override = !wd->current && 
ob->id.override && BKE_override_operations_store_start(&ob->id);
+
                        /* write LibData */
                        writestruct(wd, ID_OB, Object, 1, ob);
                        write_iddata(wd, &ob->id);
@@ -1913,6 +1916,10 @@ static void write_objects(WriteData *wd, ListBase 
*idbase)
 
                        writelist(wd, DATA, LinkData, &ob->pc_ids);
                        writelist(wd, DATA, LodLevel, &ob->lodlevels);
+
+                       if (do_override) {
+                               BKE_override_operations_store_end(&ob->id);
+                       }
                }
 
                write_previews(wd, ob->preview);
diff --git a/source/blender/makesrna/RNA_access.h 
b/source/blender/makesrna/RNA_access.h
index 0c2aac3326..3a9bdbd9e7 100644
--- a/source/blender/makesrna/RNA_access.h
+++ b/source/blender/makesrna/RNA_access.h
@@ -1221,6 +1221,8 @@ bool RNA_struct_equals(struct PointerRNA *a, struct 
PointerRNA *b, eRNAEqualsMod
 bool RNA_struct_override_matches(struct PointerRNA *local, struct PointerRNA 
*reference,
         struct IDOverride *override, const bool ignore_non_overridable, const 
bool ignore_overridden);
 
+bool RNA_struct_override_store(struct PointerRNA *local, struct PointerRNA 
*reference, struct IDOverride *override);
+
 void RNA_property_override_apply(
         struct PointerRNA *dst, struct PointerRNA *src, struct PropertyRNA 
*prop,
         struct IDOverrideProperty *op, const bool do_init);
diff --git a/source/blender/makesrna/intern/rna_access.c 
b/source/blender/makesrna/intern/rna_access.c
index 6b6111762c..f11a55e867 100644
--- a/source/blender/makesrna/intern/rna_access.c
+++ b/source/blender/makesrna/intern/rna_access.c
@@ -6969,6 +6969,7 @@ static bool rna_property_override_equals(
 
                case PROP_FLOAT:
                {
+                       const bool is_proportional = (prop->flag & 
PROP_PROPORTIONAL) != 0;
                        if (len) {
                                float fixed_a[16], fixed_b[16];
                                float *array_a, *array_b;
@@ -6987,7 +6988,7 @@ static bool rna_property_override_equals(
                                        IDOverrideProperty *op = 
BKE_override_property_get(override, rna_path, &created);
 
                                        if (op != NULL && created) {
-                                               
BKE_override_property_operation_get(op, IDOVERRIDE_REPLACE, NULL, NULL, -1, -1, 
NULL);
+                                               
BKE_override_property_operation_get(op, is_proportional ? IDOVERRIDE_MULTIPLY : 
IDOVERRIDE_REPLACE, NULL, NULL, -1, -1, NULL);
                                                if (r_override_changed) {
                                                        *r_override_changed = 
created;
                                                }
@@ -7011,7 +7012,7 @@ static bool rna_property_override_equals(
                                        IDOverrideProperty *op = 
BKE_override_property_get(override, rna_path, &created);
 
                                        if (op != NULL && created) {  /* If not 
yet overridden... */
-                                               
BKE_override_property_operation_get(op, IDOVERRIDE_REPLACE, NULL, NULL, -1, -1, 
NULL);
+                                               
BKE_override_property_operation_get(op, is_proportional ? IDOVERRIDE_MULTIPLY : 
IDOVERRIDE_REPLACE, NULL, NULL, -1, -1, NULL);
                                                if (r_override_changed) {
                                                        *r_override_changed = 
created;
                                                }
@@ -7442,7 +7443,7 @@ static bool rna_property_override_operation_store(
 
                /* its possible the custom-prop doesn't exist on this 
data-block */
                if (prop == NULL) {
-                       return false;
+                       return changed;
                }
 
                /* Even though currently we now prop will always be the 
'fromprop', this might not be the case in the future. */
@@ -7519,6 +7520,7 @@ static bool rna_property_override_operation_store(
                                                                        }
                                                                }
                                                                if (do_set) {
+                                                                       changed 
= true;
                                                                        
RNA_property_int_set_array(ptr, prop, array_b);
                                                                }
                                                                if (array_b != 
fixed_b) MEM_freeN(array_b);
@@ -7549,12 +7551,13 @@ static bool rna_property_override_operation_store(
                                                                                
break;
                                                                        }
                                                                }
+                                                               changed = true;
                                                                
RNA_property_int_set_index(ptr, prop, index, b);
                                                                break;
                                                        }
                                                        default:
                                                                BLI_assert(0 && 
"Unsupported RNA override diff operation on integer");
-                                                               return false;
+                                                               break;
                                                }
                                        }
                                }
@@ -7576,12 +7579,13 @@ static bool rna_property_override_operation_store(
                                                                        break;
                                                                }
                                                        }
+                                                       changed = true;
                                                        
RNA_property_int_set(ptr, prop, b);
                                                        break;
                                                }
                                                default:
                                                        BLI_assert(0 && 
"Unsupported RNA override diff operation on integer");
-                                                       return false;
+                                                       break;
                                        }
                                }
                                break;
@@ -7626,6 +7630,7 @@ static bool rna_property_override_operation_store(
                                                                        }
                                                                }
                                                                if (do_set) {
+                                                                       changed 
= true;
                                                                        
RNA_property_float_set_array(ptr, prop, array_a);
                                                                }
                                                                if (array_b != 
fixed_b) MEM_freeN(array_b);
@@ -7645,6 +7650,7 @@ static bool rna_property_override_operation_store(
                                                                        }
                                                                }
                                                                if (do_set) {
+                                                                       changed 
= true;
                                                                        
RNA_property_float_set_array(ptr, prop, array_b);
                                                                }
                                                                if (array_b != 
fixed_b) MEM_freeN(array_b);
@@ -7652,7 +7658,7 @@ static bool rna_property_override_operation_store(
                                                        }
                                                        default:
                                                                BLI_assert(0 && 
"Unsupported RNA override diff operation on float");
-                                                               return false;
+                                                               break;
                                                }
 
                                                if (array_a != fixed_a) 
MEM_freeN(array_a);
@@ -7675,6 +7681,7 @@ static bool rna_property_override_operation_store(
                                                                                
break;
                                                                        }
                                                                }
+                                                               changed = true;
                                                                
RNA_property_float_set_index(ptr, prop, index, b);
                                                                break;
                                                        }
@@ -7685,12 +7692,13 @@ static bool rna_property_override_operation_store(
                                                                        
opop->operation = IDOVERRIDE_REPLACE;
                                                                        break;
                                                                }
+                                                               changed = true;
                                                                
RNA_property_float_set_index(ptr, prop, index, b);
                                                                break;
                                                        }
                                                        default:
                                                                BLI_assert(0 && 
"Unsupported RNA override diff operation on float");
-                                                               return false;
+                                                               break;
                                                }
                                        }
                                }
@@ -7712,6 +7720,7 @@ static bool rna_property_override_operation_store(
                                                                        break;
                                                                }
                                                        }
+                                                       changed = true;
                                                        
RNA_property_float_set(ptr, prop, b);
                                                        break;
                                                }
@@ -7722,12 +7731,13 @@ static bool rna_property_override_operation_store(
                                                                opop->operation 
= IDOVERRIDE_REPLACE;
                                                                break;
                                                        }
+                                                       changed = true;
                                                        
RNA_property_float_set(ptr, prop, b);
                                                        break;
                                                }
                                                default:
                                                        BLI_assert(0 && 
"Unsupported RNA override diff operation on float");
-                                                       return false;
+                                                       break;
                                        }
                                }
                                return true;
@@ -7798,6 +7808,26 @@ bool RNA_struct_override_matches(
        return equals;
 }
 
+/** Store needed 

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to