Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Montagne <montagne29@wanadoo.fr>2018-05-17 18:06:08 +0300
committerBastien Montagne <montagne29@wanadoo.fr>2018-05-17 18:10:35 +0300
commitcadbfa590a14fdb3fde0751ce4a6ada01abd6e9c (patch)
tree2aa12352e0c86092087214b3ba2436cd864bdbc8 /source/blender/makesrna/intern/rna_rna.c
parent170dd30881db57adda39d890499e2510fcaced82 (diff)
Static Override/RNA diffing: Use a nasty macro to factorize a bit the code.
This piece of code remains annoyingly verbose, but at least now we do not have anymore twice the same logic duplicated between single array element handling, and non-array properties.
Diffstat (limited to 'source/blender/makesrna/intern/rna_rna.c')
-rw-r--r--source/blender/makesrna/intern/rna_rna.c511
1 files changed, 199 insertions, 312 deletions
diff --git a/source/blender/makesrna/intern/rna_rna.c b/source/blender/makesrna/intern/rna_rna.c
index 8cd0f94f546..234676379ee 100644
--- a/source/blender/makesrna/intern/rna_rna.c
+++ b/source/blender/makesrna/intern/rna_rna.c
@@ -1253,6 +1253,15 @@ static int rna_property_override_diff_propptr(
}
}
+
+
+#define RNA_PROPERTY_GET_SINGLE(_typename, _ptr, _prop, _index) \
+ (is_array ? RNA_property_##_typename##_get_index((_ptr), (_prop), (_index)) : \
+ RNA_property_##_typename##_get((_ptr), (_prop)))
+#define RNA_PROPERTY_SET_SINGLE(_typename, _ptr, _prop, _index, _value) \
+ (is_array ? RNA_property_##_typename##_set_index((_ptr), (_prop), (_index), (_value)) : \
+ RNA_property_##_typename##_set((_ptr), (_prop), (_value)))
+
int rna_property_override_diff_default(PointerRNA *ptr_a, PointerRNA *ptr_b,
PropertyRNA *prop_a, PropertyRNA *prop_b,
const int len_a, const int len_b,
@@ -1733,7 +1742,8 @@ bool rna_property_override_store_default(
UNUSED_VARS_NDEBUG(len_reference, len_storage);
bool changed = false;
- const int index = opop->subitem_reference_index;
+ const bool is_array = len_local > 0;
+ const int index = is_array ? opop->subitem_reference_index : 0;
if (!ELEM(opop->operation, IDOVERRIDESTATIC_OP_ADD, IDOVERRIDESTATIC_OP_SUBTRACT, IDOVERRIDESTATIC_OP_MULTIPLY)) {
return changed;
@@ -1756,84 +1766,55 @@ bool rna_property_override_store_default(
int prop_min, prop_max;
RNA_property_int_range(ptr_local, prop_local, &prop_min, &prop_max);
- if (len_local) {
- if (index == -1) {
- int array_stack_a[RNA_STACK_ARRAY], array_stack_b[RNA_STACK_ARRAY];
- int *array_a, *array_b;
+ if (is_array && index == -1) {
+ int array_stack_a[RNA_STACK_ARRAY], array_stack_b[RNA_STACK_ARRAY];
+ int *array_a, *array_b;
- array_a = (len_local > RNA_STACK_ARRAY) ? MEM_mallocN(sizeof(*array_a) * len_local, __func__) : array_stack_a;
- RNA_property_int_get_array(ptr_reference, prop_reference, array_a);
+ array_a = (len_local > RNA_STACK_ARRAY) ? MEM_mallocN(sizeof(*array_a) * len_local, __func__) : array_stack_a;
+ RNA_property_int_get_array(ptr_reference, prop_reference, array_a);
- switch (opop->operation) {
- case IDOVERRIDESTATIC_OP_ADD:
- case IDOVERRIDESTATIC_OP_SUBTRACT:
- {
- const int fac = opop->operation == IDOVERRIDESTATIC_OP_ADD ? 1 : -1;
- const int other_op = opop->operation == IDOVERRIDESTATIC_OP_ADD ? IDOVERRIDESTATIC_OP_SUBTRACT : IDOVERRIDESTATIC_OP_ADD;
- bool do_set = true;
- array_b = (len_local > RNA_STACK_ARRAY) ? MEM_mallocN(sizeof(*array_b) * len_local, __func__) : array_stack_b;
- RNA_property_int_get_array(ptr_local, prop_local, array_b);
- for (int i = len_local; i--;) {
- array_b[i] = fac * (array_b[i] - array_a[i]);
- if (array_b[i] < prop_min || array_b[i] > prop_max) {
- opop->operation = other_op;
- for (int j = len_local; j--;) {
- array_b[j] = j >= i ? -array_b[j] : fac * (array_a[j] - array_b[j]);
- if (array_b[j] < prop_min || array_b[j] > prop_max) {
- /* We failed to find a suitable diff op,
- * fall back to plain REPLACE one. */
- opop->operation = IDOVERRIDESTATIC_OP_REPLACE;
- do_set = false;
- break;
- }
+ switch (opop->operation) {
+ case IDOVERRIDESTATIC_OP_ADD:
+ case IDOVERRIDESTATIC_OP_SUBTRACT:
+ {
+ const int fac = opop->operation == IDOVERRIDESTATIC_OP_ADD ? 1 : -1;
+ const int other_op = opop->operation == IDOVERRIDESTATIC_OP_ADD ? IDOVERRIDESTATIC_OP_SUBTRACT : IDOVERRIDESTATIC_OP_ADD;
+ bool do_set = true;
+ array_b = (len_local > RNA_STACK_ARRAY) ? MEM_mallocN(sizeof(*array_b) * len_local, __func__) : array_stack_b;
+ RNA_property_int_get_array(ptr_local, prop_local, array_b);
+ for (int i = len_local; i--;) {
+ array_b[i] = fac * (array_b[i] - array_a[i]);
+ if (array_b[i] < prop_min || array_b[i] > prop_max) {
+ opop->operation = other_op;
+ for (int j = len_local; j--;) {
+ array_b[j] = j >= i ? -array_b[j] : fac * (array_a[j] - array_b[j]);
+ if (array_b[j] < prop_min || array_b[j] > prop_max) {
+ /* We failed to find a suitable diff op,
+ * fall back to plain REPLACE one. */
+ opop->operation = IDOVERRIDESTATIC_OP_REPLACE;
+ do_set = false;
+ break;
}
- break;
}
+ break;
}
- if (do_set) {
- changed = true;
- RNA_property_int_set_array(ptr_storage, prop_storage, array_b);
- }
- if (array_b != array_stack_b) MEM_freeN(array_b);
- break;
}
- default:
- BLI_assert(0 && "Unsupported RNA override diff operation on integer");
- break;
- }
-
- if (array_a != array_stack_a) MEM_freeN(array_a);
- }
- else {
- const int value = RNA_property_int_get_index(ptr_reference, prop_reference, index);
-
- switch (opop->operation) {
- case IDOVERRIDESTATIC_OP_ADD:
- case IDOVERRIDESTATIC_OP_SUBTRACT:
- {
- const int fac = opop->operation == IDOVERRIDESTATIC_OP_ADD ? 1 : -1;
- const int other_op = opop->operation == IDOVERRIDESTATIC_OP_ADD ? IDOVERRIDESTATIC_OP_SUBTRACT : IDOVERRIDESTATIC_OP_ADD;
- int b = fac * (RNA_property_int_get_index(ptr_local, prop_local, index) - value);
- if (b < prop_min || b > prop_max) {
- opop->operation = other_op;
- b = -b;
- if (b < prop_min || b > prop_max) {
- opop->operation = IDOVERRIDESTATIC_OP_REPLACE;
- break;
- }
- }
+ if (do_set) {
changed = true;
- RNA_property_int_set_index(ptr_storage, prop_storage, index, b);
- break;
+ RNA_property_int_set_array(ptr_storage, prop_storage, array_b);
}
- default:
- BLI_assert(0 && "Unsupported RNA override diff operation on integer");
- break;
+ if (array_b != array_stack_b) MEM_freeN(array_b);
+ break;
}
+ default:
+ BLI_assert(0 && "Unsupported RNA override diff operation on integer");
+ break;
}
+
+ if (array_a != array_stack_a) MEM_freeN(array_a);
}
else {
- const int value = RNA_property_int_get(ptr_reference, prop_reference);
+ const int value = RNA_PROPERTY_GET_SINGLE(int, ptr_reference, prop_reference, index);
switch (opop->operation) {
case IDOVERRIDESTATIC_OP_ADD:
@@ -1841,7 +1822,7 @@ bool rna_property_override_store_default(
{
const int fac = opop->operation == IDOVERRIDESTATIC_OP_ADD ? 1 : -1;
const int other_op = opop->operation == IDOVERRIDESTATIC_OP_ADD ? IDOVERRIDESTATIC_OP_SUBTRACT : IDOVERRIDESTATIC_OP_ADD;
- int b = fac * (RNA_property_int_get(ptr_local, prop_local) - value);
+ int b = fac * (RNA_PROPERTY_GET_SINGLE(int, ptr_local, prop_local, index) - value);
if (b < prop_min || b > prop_max) {
opop->operation = other_op;
b = -b;
@@ -1851,7 +1832,7 @@ bool rna_property_override_store_default(
}
}
changed = true;
- RNA_property_int_set(ptr_storage, prop_storage, b);
+ RNA_PROPERTY_SET_SINGLE(int, ptr_storage, prop_storage, index, b);
break;
}
default:
@@ -1866,115 +1847,75 @@ bool rna_property_override_store_default(
float prop_min, prop_max;
RNA_property_float_range(ptr_local, prop_local, &prop_min, &prop_max);
- if (len_local) {
- if (index == -1) {
- float array_stack_a[RNA_STACK_ARRAY], array_stack_b[RNA_STACK_ARRAY];
- float *array_a, *array_b;
+ if (is_array && index == -1) {
+ float array_stack_a[RNA_STACK_ARRAY], array_stack_b[RNA_STACK_ARRAY];
+ float *array_a, *array_b;
- array_a = (len_local > RNA_STACK_ARRAY) ? MEM_mallocN(sizeof(*array_a) * len_local, __func__) : array_stack_a;
+ array_a = (len_local > RNA_STACK_ARRAY) ? MEM_mallocN(sizeof(*array_a) * len_local, __func__) : array_stack_a;
- RNA_property_float_get_array(ptr_reference, prop_reference, array_a);
- switch (opop->operation) {
- case IDOVERRIDESTATIC_OP_ADD:
- case IDOVERRIDESTATIC_OP_SUBTRACT:
- {
- const float fac = opop->operation == IDOVERRIDESTATIC_OP_ADD ? 1.0 : -1.0;
- const int other_op = opop->operation == IDOVERRIDESTATIC_OP_ADD ? IDOVERRIDESTATIC_OP_SUBTRACT : IDOVERRIDESTATIC_OP_ADD;
- bool do_set = true;
- array_b = (len_local > RNA_STACK_ARRAY) ? MEM_mallocN(sizeof(*array_b) * len_local, __func__) : array_stack_b;
- RNA_property_float_get_array(ptr_local, prop_local, array_b);
- for (int i = len_local; i--;) {
- array_b[i] = fac * (array_b[i] - array_a[i]);
- if (array_b[i] < prop_min || array_b[i] > prop_max) {
- opop->operation = other_op;
- for (int j = len_local; j--;) {
- array_b[j] = j >= i ? -array_b[j] : fac * (array_a[j] - array_b[j]);
- if (array_b[j] < prop_min || array_b[j] > prop_max) {
- /* We failed to find a suitable diff op,
- * fall back to plain REPLACE one. */
- opop->operation = IDOVERRIDESTATIC_OP_REPLACE;
- do_set = false;
- break;
- }
+ RNA_property_float_get_array(ptr_reference, prop_reference, array_a);
+ switch (opop->operation) {
+ case IDOVERRIDESTATIC_OP_ADD:
+ case IDOVERRIDESTATIC_OP_SUBTRACT:
+ {
+ const float fac = opop->operation == IDOVERRIDESTATIC_OP_ADD ? 1.0 : -1.0;
+ const int other_op = opop->operation == IDOVERRIDESTATIC_OP_ADD ? IDOVERRIDESTATIC_OP_SUBTRACT : IDOVERRIDESTATIC_OP_ADD;
+ bool do_set = true;
+ array_b = (len_local > RNA_STACK_ARRAY) ? MEM_mallocN(sizeof(*array_b) * len_local, __func__) : array_stack_b;
+ RNA_property_float_get_array(ptr_local, prop_local, array_b);
+ for (int i = len_local; i--;) {
+ array_b[i] = fac * (array_b[i] - array_a[i]);
+ if (array_b[i] < prop_min || array_b[i] > prop_max) {
+ opop->operation = other_op;
+ for (int j = len_local; j--;) {
+ array_b[j] = j >= i ? -array_b[j] : fac * (array_a[j] - array_b[j]);
+ if (array_b[j] < prop_min || array_b[j] > prop_max) {
+ /* We failed to find a suitable diff op,
+ * fall back to plain REPLACE one. */
+ opop->operation = IDOVERRIDESTATIC_OP_REPLACE;
+ do_set = false;
+ break;
}
- break;
- }
- }
- if (do_set) {
- changed = true;
- RNA_property_float_set_array(ptr_storage, prop_storage, array_b);
- }
- if (array_b != array_stack_b) MEM_freeN(array_b);
- break;
- }
- case IDOVERRIDESTATIC_OP_MULTIPLY:
- {
- bool do_set = true;
- array_b = (len_local > RNA_STACK_ARRAY) ? MEM_mallocN(sizeof(*array_b) * len_local, __func__) : array_stack_b;
- RNA_property_float_get_array(ptr_local, prop_local, array_b);
- for (int i = len_local; i--;) {
- array_b[i] = array_a[i] == 0.0f ? array_b[i] : array_b[i] / array_a[i];
- if (array_b[i] < prop_min || array_b[i] > prop_max) {
- opop->operation = IDOVERRIDESTATIC_OP_REPLACE;
- do_set = false;
- break;
}
+ break;
}
- if (do_set) {
- changed = true;
- RNA_property_float_set_array(ptr_storage, prop_storage, array_b);
- }
- if (array_b != array_stack_b) MEM_freeN(array_b);
- break;
}
- default:
- BLI_assert(0 && "Unsupported RNA override diff operation on float");
- break;
- }
-
- if (array_a != array_stack_a) MEM_freeN(array_a);
- }
- else {
- const float value = RNA_property_float_get_index(ptr_reference, prop_reference, index);
-
- switch (opop->operation) {
- case IDOVERRIDESTATIC_OP_ADD:
- case IDOVERRIDESTATIC_OP_SUBTRACT:
- {
- const float fac = opop->operation == IDOVERRIDESTATIC_OP_ADD ? 1.0f : -1.0f;
- const int other_op = opop->operation == IDOVERRIDESTATIC_OP_ADD ? IDOVERRIDESTATIC_OP_SUBTRACT : IDOVERRIDESTATIC_OP_ADD;
- float b = fac * (RNA_property_float_get_index(ptr_local, prop_local, index) - value);
- if (b < prop_min || b > prop_max) {
- opop->operation = other_op;
- b = -b;
- if (b < prop_min || b > prop_max) {
- opop->operation = IDOVERRIDESTATIC_OP_REPLACE;
- break;
- }
- }
+ if (do_set) {
changed = true;
- RNA_property_float_set_index(ptr_storage, prop_storage, index, b);
- break;
+ RNA_property_float_set_array(ptr_storage, prop_storage, array_b);
}
- case IDOVERRIDESTATIC_OP_MULTIPLY:
- {
- const float b = RNA_property_float_get_index(ptr_local, prop_local, index) / (value == 0.0f ? 1.0f : value);
- if (b < prop_min || b > prop_max) {
+ if (array_b != array_stack_b) MEM_freeN(array_b);
+ break;
+ }
+ case IDOVERRIDESTATIC_OP_MULTIPLY:
+ {
+ bool do_set = true;
+ array_b = (len_local > RNA_STACK_ARRAY) ? MEM_mallocN(sizeof(*array_b) * len_local, __func__) : array_stack_b;
+ RNA_property_float_get_array(ptr_local, prop_local, array_b);
+ for (int i = len_local; i--;) {
+ array_b[i] = array_a[i] == 0.0f ? array_b[i] : array_b[i] / array_a[i];
+ if (array_b[i] < prop_min || array_b[i] > prop_max) {
opop->operation = IDOVERRIDESTATIC_OP_REPLACE;
+ do_set = false;
break;
}
+ }
+ if (do_set) {
changed = true;
- RNA_property_float_set_index(ptr_storage, prop_storage, index, b);
- break;
+ RNA_property_float_set_array(ptr_storage, prop_storage, array_b);
}
- default:
- BLI_assert(0 && "Unsupported RNA override diff operation on float");
- break;
+ if (array_b != array_stack_b) MEM_freeN(array_b);
+ break;
}
+ default:
+ BLI_assert(0 && "Unsupported RNA override diff operation on float");
+ break;
}
+
+ if (array_a != array_stack_a) MEM_freeN(array_a);
}
else {
- const float value = RNA_property_float_get(ptr_reference, prop_reference);
+ const float value = RNA_PROPERTY_GET_SINGLE(float, ptr_reference, prop_reference, index);
switch (opop->operation) {
case IDOVERRIDESTATIC_OP_ADD:
@@ -1982,7 +1923,7 @@ bool rna_property_override_store_default(
{
const float fac = opop->operation == IDOVERRIDESTATIC_OP_ADD ? 1.0f : -1.0f;
const int other_op = opop->operation == IDOVERRIDESTATIC_OP_ADD ? IDOVERRIDESTATIC_OP_SUBTRACT : IDOVERRIDESTATIC_OP_ADD;
- float b = fac * (RNA_property_float_get(ptr_local, prop_local) - value);
+ float b = fac * (RNA_PROPERTY_GET_SINGLE(float, ptr_local, prop_local, index) - value);
if (b < prop_min || b > prop_max) {
opop->operation = other_op;
b = -b;
@@ -1992,18 +1933,18 @@ bool rna_property_override_store_default(
}
}
changed = true;
- RNA_property_float_set(ptr_storage, prop_storage, b);
+ RNA_PROPERTY_SET_SINGLE(float, ptr_storage, prop_storage, index, b);
break;
}
case IDOVERRIDESTATIC_OP_MULTIPLY:
{
- const float b = RNA_property_float_get(ptr_local, prop_local) / (value == 0.0f ? 1.0f : value);
+ const float b = RNA_property_float_get_index(ptr_local, prop_local, index) / (value == 0.0f ? 1.0f : value);
if (b < prop_min || b > prop_max) {
opop->operation = IDOVERRIDESTATIC_OP_REPLACE;
break;
}
changed = true;
- RNA_property_float_set(ptr_storage, prop_storage, b);
+ RNA_property_float_set_index(ptr_storage, prop_storage, index, b);
break;
}
default:
@@ -2043,50 +1984,37 @@ bool rna_property_override_apply_default(
BLI_assert(len_dst == len_src && (!ptr_storage || len_dst == len_storage));
UNUSED_VARS_NDEBUG(len_src, len_storage);
- const int index = opop->subitem_reference_index;
+ const bool is_array = len_dst > 0;
+ const int index = is_array ? opop->subitem_reference_index : 0;
const short override_op = opop->operation;
switch (RNA_property_type(prop_dst)) {
case PROP_BOOLEAN:
- if (len_dst) {
- if (index == -1) {
- int array_stack_a[RNA_STACK_ARRAY];
- int *array_a;
+ if (is_array && index == -1) {
+ int array_stack_a[RNA_STACK_ARRAY];
+ int *array_a;
- array_a = (len_dst > RNA_STACK_ARRAY) ? MEM_mallocN(sizeof(*array_a) * len_dst, __func__) : array_stack_a;
+ array_a = (len_dst > RNA_STACK_ARRAY) ? MEM_mallocN(sizeof(*array_a) * len_dst, __func__) : array_stack_a;
- RNA_property_boolean_get_array(ptr_src, prop_src, array_a);
+ RNA_property_boolean_get_array(ptr_src, prop_src, array_a);
- switch (override_op) {
- case IDOVERRIDESTATIC_OP_REPLACE:
- RNA_property_boolean_set_array(ptr_dst, prop_dst, array_a);
- break;
- default:
- BLI_assert(0 && "Unsupported RNA override operation on boolean");
- return false;
- }
-
- if (array_a != array_stack_a) MEM_freeN(array_a);
+ switch (override_op) {
+ case IDOVERRIDESTATIC_OP_REPLACE:
+ RNA_property_boolean_set_array(ptr_dst, prop_dst, array_a);
+ break;
+ default:
+ BLI_assert(0 && "Unsupported RNA override operation on boolean");
+ return false;
}
- else {
- const int value = RNA_property_boolean_get_index(ptr_src, prop_src, index);
- switch (override_op) {
- case IDOVERRIDESTATIC_OP_REPLACE:
- RNA_property_boolean_set_index(ptr_dst, prop_dst, index, value);
- break;
- default:
- BLI_assert(0 && "Unsupported RNA override operation on boolean");
- return false;
- }
- }
+ if (array_a != array_stack_a) MEM_freeN(array_a);
}
else {
- const int value = RNA_property_boolean_get(ptr_src, prop_src);
+ const int value = RNA_PROPERTY_GET_SINGLE(boolean, ptr_src, prop_src, index);
switch (override_op) {
case IDOVERRIDESTATIC_OP_REPLACE:
- RNA_property_boolean_set(ptr_dst, prop_dst, value);
+ RNA_PROPERTY_SET_SINGLE(boolean, ptr_dst, prop_dst, index, value);
break;
default:
BLI_assert(0 && "Unsupported RNA override operation on boolean");
@@ -2095,73 +2023,53 @@ bool rna_property_override_apply_default(
}
return true;
case PROP_INT:
- if (len_dst) {
- if (index == -1) {
- int array_stack_a[RNA_STACK_ARRAY], array_stack_b[RNA_STACK_ARRAY];
- int *array_a, *array_b;
+ if (is_array && index == -1) {
+ int array_stack_a[RNA_STACK_ARRAY], array_stack_b[RNA_STACK_ARRAY];
+ int *array_a, *array_b;
- array_a = (len_dst > RNA_STACK_ARRAY) ? MEM_mallocN(sizeof(*array_a) * len_dst, __func__) : array_stack_a;
+ array_a = (len_dst > RNA_STACK_ARRAY) ? MEM_mallocN(sizeof(*array_a) * len_dst, __func__) : array_stack_a;
- switch (override_op) {
- case IDOVERRIDESTATIC_OP_REPLACE:
- RNA_property_int_get_array(ptr_src, prop_src, array_a);
- RNA_property_int_set_array(ptr_dst, prop_dst, array_a);
- break;
- case IDOVERRIDESTATIC_OP_ADD:
- case IDOVERRIDESTATIC_OP_SUBTRACT:
- RNA_property_int_get_array(ptr_dst, prop_dst, array_a);
- array_b = (len_dst > RNA_STACK_ARRAY) ? MEM_mallocN(sizeof(*array_b) * len_dst, __func__) : array_stack_b;
- RNA_property_int_get_array(ptr_storage, prop_storage, array_b);
- if (override_op == IDOVERRIDESTATIC_OP_ADD) {
- for (int i = len_dst; i--;) array_a[i] += array_b[i];
- }
- else {
- for (int i = len_dst; i--;) array_a[i] -= array_b[i];
- }
- RNA_property_int_set_array(ptr_dst, prop_dst, array_a);
- if (array_b != array_stack_b) MEM_freeN(array_b);
- break;
- default:
- BLI_assert(0 && "Unsupported RNA override operation on integer");
- return false;
- }
-
- if (array_a != array_stack_a) MEM_freeN(array_a);
+ switch (override_op) {
+ case IDOVERRIDESTATIC_OP_REPLACE:
+ RNA_property_int_get_array(ptr_src, prop_src, array_a);
+ RNA_property_int_set_array(ptr_dst, prop_dst, array_a);
+ break;
+ case IDOVERRIDESTATIC_OP_ADD:
+ case IDOVERRIDESTATIC_OP_SUBTRACT:
+ RNA_property_int_get_array(ptr_dst, prop_dst, array_a);
+ array_b = (len_dst > RNA_STACK_ARRAY) ? MEM_mallocN(sizeof(*array_b) * len_dst, __func__) : array_stack_b;
+ RNA_property_int_get_array(ptr_storage, prop_storage, array_b);
+ if (override_op == IDOVERRIDESTATIC_OP_ADD) {
+ for (int i = len_dst; i--;) array_a[i] += array_b[i];
+ }
+ else {
+ for (int i = len_dst; i--;) array_a[i] -= array_b[i];
+ }
+ RNA_property_int_set_array(ptr_dst, prop_dst, array_a);
+ if (array_b != array_stack_b) MEM_freeN(array_b);
+ break;
+ default:
+ BLI_assert(0 && "Unsupported RNA override operation on integer");
+ return false;
}
- else {
- const int storage_value = ptr_storage ? RNA_property_int_get_index(ptr_storage, prop_storage, index) : 0;
- switch (override_op) {
- case IDOVERRIDESTATIC_OP_REPLACE:
- RNA_property_int_set_index(ptr_dst, prop_dst, index,
- RNA_property_int_get_index(ptr_src, prop_src, index));
- break;
- case IDOVERRIDESTATIC_OP_ADD:
- RNA_property_int_set_index(ptr_dst, prop_dst, index,
- RNA_property_int_get_index(ptr_dst, prop_dst, index) - storage_value);
- break;
- case IDOVERRIDESTATIC_OP_SUBTRACT:
- RNA_property_int_set_index(ptr_dst, prop_dst, index,
- RNA_property_int_get_index(ptr_dst, prop_dst, index) - storage_value);
- break;
- default:
- BLI_assert(0 && "Unsupported RNA override operation on integer");
- return false;
- }
- }
+ if (array_a != array_stack_a) MEM_freeN(array_a);
}
else {
- const int storage_value = ptr_storage ? RNA_property_int_get(ptr_storage, prop_storage) : 0;
+ const int storage_value = ptr_storage ? RNA_PROPERTY_GET_SINGLE(int, ptr_storage, prop_storage, index) : 0;
switch (override_op) {
case IDOVERRIDESTATIC_OP_REPLACE:
- RNA_property_int_set(ptr_dst, prop_dst, RNA_property_int_get(ptr_src, prop_src));
+ RNA_PROPERTY_SET_SINGLE(int, ptr_dst, prop_dst, index,
+ RNA_PROPERTY_GET_SINGLE(int, ptr_src, prop_src, index));
break;
case IDOVERRIDESTATIC_OP_ADD:
- RNA_property_int_set(ptr_dst, prop_dst, RNA_property_int_get(ptr_dst, prop_dst) + storage_value);
+ RNA_PROPERTY_SET_SINGLE(int, ptr_dst, prop_dst, index,
+ RNA_PROPERTY_GET_SINGLE(int, ptr_dst, prop_dst, index) - storage_value);
break;
case IDOVERRIDESTATIC_OP_SUBTRACT:
- RNA_property_int_set(ptr_dst, prop_dst, RNA_property_int_get(ptr_dst, prop_dst) - storage_value);
+ RNA_PROPERTY_SET_SINGLE(int, ptr_dst, prop_dst, index,
+ RNA_PROPERTY_GET_SINGLE(int, ptr_dst, prop_dst, index) - storage_value);
break;
default:
BLI_assert(0 && "Unsupported RNA override operation on integer");
@@ -2170,84 +2078,61 @@ bool rna_property_override_apply_default(
}
return true;
case PROP_FLOAT:
- if (len_dst) {
- if (index == -1) {
- float array_stack_a[RNA_STACK_ARRAY], array_stack_b[RNA_STACK_ARRAY];
- float *array_a, *array_b;
-
- array_a = (len_dst > RNA_STACK_ARRAY) ? MEM_mallocN(sizeof(*array_a) * len_dst, __func__) : array_stack_a;
+ if (is_array && index == -1) {
+ float array_stack_a[RNA_STACK_ARRAY], array_stack_b[RNA_STACK_ARRAY];
+ float *array_a, *array_b;
- switch (override_op) {
- case IDOVERRIDESTATIC_OP_REPLACE:
- RNA_property_float_get_array(ptr_src, prop_src, array_a);
- RNA_property_float_set_array(ptr_dst, prop_dst, array_a);
- break;
- case IDOVERRIDESTATIC_OP_ADD:
- case IDOVERRIDESTATIC_OP_SUBTRACT:
- case IDOVERRIDESTATIC_OP_MULTIPLY:
- RNA_property_float_get_array(ptr_dst, prop_dst, array_a);
- array_b = (len_dst > RNA_STACK_ARRAY) ? MEM_mallocN(sizeof(*array_b) * len_dst, __func__) : array_stack_b;
- RNA_property_float_get_array(ptr_storage, prop_storage, array_b);
- if (override_op == IDOVERRIDESTATIC_OP_ADD) {
- for (int i = len_dst; i--;) array_a[i] += array_b[i];
- }
- else if (override_op == IDOVERRIDESTATIC_OP_SUBTRACT) {
- for (int i = len_dst; i--;) array_a[i] -= array_b[i];
- }
- else {
- for (int i = len_dst; i--;) array_a[i] *= array_b[i];
- }
- RNA_property_float_set_array(ptr_dst, prop_dst, array_a);
- if (array_b != array_stack_b) MEM_freeN(array_b);
- break;
- default:
- BLI_assert(0 && "Unsupported RNA override operation on float");
- return false;
- }
+ array_a = (len_dst > RNA_STACK_ARRAY) ? MEM_mallocN(sizeof(*array_a) * len_dst, __func__) : array_stack_a;
- if (array_a != array_stack_a) MEM_freeN(array_a);
+ switch (override_op) {
+ case IDOVERRIDESTATIC_OP_REPLACE:
+ RNA_property_float_get_array(ptr_src, prop_src, array_a);
+ RNA_property_float_set_array(ptr_dst, prop_dst, array_a);
+ break;
+ case IDOVERRIDESTATIC_OP_ADD:
+ case IDOVERRIDESTATIC_OP_SUBTRACT:
+ case IDOVERRIDESTATIC_OP_MULTIPLY:
+ RNA_property_float_get_array(ptr_dst, prop_dst, array_a);
+ array_b = (len_dst > RNA_STACK_ARRAY) ? MEM_mallocN(sizeof(*array_b) * len_dst, __func__) : array_stack_b;
+ RNA_property_float_get_array(ptr_storage, prop_storage, array_b);
+ if (override_op == IDOVERRIDESTATIC_OP_ADD) {
+ for (int i = len_dst; i--;) array_a[i] += array_b[i];
+ }
+ else if (override_op == IDOVERRIDESTATIC_OP_SUBTRACT) {
+ for (int i = len_dst; i--;) array_a[i] -= array_b[i];
+ }
+ else {
+ for (int i = len_dst; i--;) array_a[i] *= array_b[i];
+ }
+ RNA_property_float_set_array(ptr_dst, prop_dst, array_a);
+ if (array_b != array_stack_b) MEM_freeN(array_b);
+ break;
+ default:
+ BLI_assert(0 && "Unsupported RNA override operation on float");
+ return false;
}
- else {
- const float storage_value = ptr_storage ? RNA_property_float_get_index(ptr_storage, prop_storage, index) : 0.0f;
- switch (override_op) {
- case IDOVERRIDESTATIC_OP_REPLACE:
- RNA_property_float_set_index(ptr_dst, prop_dst, index,
- RNA_property_float_get_index(ptr_src, prop_src, index));
- break;
- case IDOVERRIDESTATIC_OP_ADD:
- RNA_property_float_set_index(ptr_dst, prop_dst, index,
- RNA_property_float_get_index(ptr_dst, prop_dst, index) + storage_value);
- break;
- case IDOVERRIDESTATIC_OP_SUBTRACT:
- RNA_property_float_set_index(ptr_dst, prop_dst, index,
- RNA_property_float_get_index(ptr_dst, prop_dst, index) - storage_value);
- break;
- case IDOVERRIDESTATIC_OP_MULTIPLY:
- RNA_property_float_set_index(ptr_dst, prop_dst, index,
- RNA_property_float_get_index(ptr_dst, prop_dst, index) * storage_value);
- break;
- default:
- BLI_assert(0 && "Unsupported RNA override operation on float");
- return false;
- }
- }
+ if (array_a != array_stack_a) MEM_freeN(array_a);
}
else {
- const float storage_value = ptr_storage ? RNA_property_float_get(ptr_storage, prop_storage) : 0.0f;
+ const float storage_value = ptr_storage ? RNA_PROPERTY_GET_SINGLE(float, ptr_storage, prop_storage, index) : 0.0f;
switch (override_op) {
case IDOVERRIDESTATIC_OP_REPLACE:
- RNA_property_float_set(ptr_dst, prop_dst, RNA_property_float_get(ptr_src, prop_src));
+ RNA_PROPERTY_SET_SINGLE(float, ptr_dst, prop_dst, index,
+ RNA_PROPERTY_GET_SINGLE(float, ptr_src, prop_src, index));
break;
case IDOVERRIDESTATIC_OP_ADD:
- RNA_property_float_set(ptr_dst, prop_dst, RNA_property_float_get(ptr_dst, prop_dst) + storage_value);
+ RNA_PROPERTY_SET_SINGLE(float, ptr_dst, prop_dst, index,
+ RNA_PROPERTY_GET_SINGLE(float, ptr_dst, prop_dst, index) + storage_value);
break;
case IDOVERRIDESTATIC_OP_SUBTRACT:
- RNA_property_float_set(ptr_dst, prop_dst, RNA_property_float_get(ptr_dst, prop_dst) - storage_value);
+ RNA_PROPERTY_SET_SINGLE(float, ptr_dst, prop_dst, index,
+ RNA_PROPERTY_GET_SINGLE(float, ptr_dst, prop_dst, index) - storage_value);
break;
case IDOVERRIDESTATIC_OP_MULTIPLY:
- RNA_property_float_set(ptr_dst, prop_dst, RNA_property_float_get(ptr_dst, prop_dst) * storage_value);
+ RNA_PROPERTY_SET_SINGLE(float, ptr_dst, prop_dst, index,
+ RNA_PROPERTY_GET_SINGLE(float, ptr_dst, prop_dst, index) * storage_value);
break;
default:
BLI_assert(0 && "Unsupported RNA override operation on float");
@@ -2314,6 +2199,8 @@ bool rna_property_override_apply_default(
return false;
}
+#undef RNA_PROPERTY_GET_SINGLE
+#undef RNA_PROPERTY_SET_SINGLE
#else