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:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>2009-09-09 23:40:46 +0400
committerBrecht Van Lommel <brechtvanlommel@pandora.be>2009-09-09 23:40:46 +0400
commit297a53ebf833ebee7de8bd66a11d7cfe19f3ea8e (patch)
tree2276512004d18d0ccaf28ff98efd6b84854bded4 /source/blender/makesrna/intern/rna_access.c
parent939b72247d536de0f09b526403c91cb7044cccca (diff)
RNA: multidimensional & dyanmic array changes
* Disable setting array length of dynamic array for now, this was not implemented correct, and it's not really needed now. * Allow all dimensions to be dynamic size, not just the first. * Change storage of multidimensional to be simpler. * Rename API functions to be more compact. * Fix some bugs in the implementation. * RenderLayer.rect and RenderPass.rect use a multidimensional dynamic array now.
Diffstat (limited to 'source/blender/makesrna/intern/rna_access.c')
-rw-r--r--source/blender/makesrna/intern/rna_access.c273
1 files changed, 171 insertions, 102 deletions
diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c
index f37fa01480c..417ace6a455 100644
--- a/source/blender/makesrna/intern/rna_access.c
+++ b/source/blender/makesrna/intern/rna_access.c
@@ -209,7 +209,41 @@ static IDProperty *rna_idproperty_find(PointerRNA *ptr, const char *name)
return NULL;
}
-static int rna_idproperty_verify_valid(PropertyRNA *prop, IDProperty *idprop)
+static int rna_ensure_property_array_length(PointerRNA *ptr, PropertyRNA *prop)
+{
+ if(prop->magic == RNA_MAGIC) {
+ int arraylen[RNA_MAX_ARRAY_DIMENSION];
+ return (prop->getlength)? prop->getlength(ptr, arraylen): prop->totarraylength;
+ }
+ else {
+ IDProperty *idprop= (IDProperty*)prop;
+
+ if(idprop->type == IDP_ARRAY)
+ return idprop->len;
+ else
+ return 0;
+ }
+}
+
+static void rna_ensure_property_multi_array_length(PointerRNA *ptr, PropertyRNA *prop, int length[])
+{
+ if(prop->magic == RNA_MAGIC) {
+ if(prop->getlength)
+ prop->getlength(ptr, length);
+ else
+ memcpy(length, prop->arraylength, prop->arraydimension*sizeof(int));
+ }
+ else {
+ IDProperty *idprop= (IDProperty*)prop;
+
+ if(idprop->type == IDP_ARRAY)
+ length[0]= idprop->len;
+ else
+ length[0]= 0;
+ }
+}
+
+static int rna_idproperty_verify_valid(PointerRNA *ptr, PropertyRNA *prop, IDProperty *idprop)
{
/* this verifies if the idproperty actually matches the property
* description and otherwise removes it. this is to ensure that
@@ -222,7 +256,7 @@ static int rna_idproperty_verify_valid(PropertyRNA *prop, IDProperty *idprop)
return 0;
break;
case IDP_ARRAY:
- if(prop->arraylength != idprop->len)
+ if(rna_ensure_property_array_length(ptr, prop) != idprop->len)
return 0;
if(idprop->subtype == IDP_FLOAT && prop->type != PROP_FLOAT)
@@ -283,7 +317,7 @@ IDProperty *rna_idproperty_check(PropertyRNA **prop, PointerRNA *ptr)
if((*prop)->flag & PROP_IDPROPERTY) {
IDProperty *idprop= rna_idproperty_find(ptr, (*prop)->identifier);
- if(idprop && !rna_idproperty_verify_valid(*prop, idprop)) {
+ if(idprop && !rna_idproperty_verify_valid(ptr, *prop, idprop)) {
IDProperty *group= RNA_struct_idproperties(ptr, 0);
IDP_RemFromGroup(group, idprop);
@@ -310,7 +344,7 @@ IDProperty *rna_idproperty_check(PropertyRNA **prop, PointerRNA *ptr)
}
}
-PropertyRNA *rna_ensure_property(PropertyRNA *prop)
+static PropertyRNA *rna_ensure_property(PropertyRNA *prop)
{
/* the quick version if we don't need the idproperty */
@@ -327,7 +361,7 @@ PropertyRNA *rna_ensure_property(PropertyRNA *prop)
}
}
-const char *rna_ensure_property_identifier(PropertyRNA *prop)
+static const char *rna_ensure_property_identifier(PropertyRNA *prop)
{
if(prop->magic == RNA_MAGIC)
return prop->identifier;
@@ -335,7 +369,7 @@ const char *rna_ensure_property_identifier(PropertyRNA *prop)
return ((IDProperty*)prop)->name;
}
-const char *rna_ensure_property_name(PropertyRNA *prop)
+static const char *rna_ensure_property_name(PropertyRNA *prop)
{
if(prop->magic == RNA_MAGIC)
return prop->name;
@@ -343,21 +377,6 @@ const char *rna_ensure_property_name(PropertyRNA *prop)
return ((IDProperty*)prop)->name;
}
-int rna_ensure_property_array_length(PointerRNA *ptr, PropertyRNA *prop)
-{
- if(prop->magic == RNA_MAGIC) {
- return prop->getlength ? prop->getlength(ptr) : prop->arraylength;
- }
- else {
- IDProperty *idprop= (IDProperty*)prop;
-
- if(idprop->type == IDP_ARRAY)
- return idprop->len;
- else
- return 0;
- }
-}
-
/* Structs */
const char *RNA_struct_identifier(StructRNA *type)
@@ -555,51 +574,25 @@ int RNA_property_array_length(PointerRNA *ptr, PropertyRNA *prop)
return rna_ensure_property_array_length(ptr, prop);
}
-int RNA_property_dynamic_array_set_length(PointerRNA *ptr, PropertyRNA *prop, int length)
+/* used by BPY to make an array from the python object */
+int RNA_property_array_dimension(PointerRNA *ptr, PropertyRNA *prop, int length[])
{
- /* length 0 is not allowed */
- if (!length)
- return 0;
-
- if (prop->getlength) {
- if (prop->setlength)
- return prop->setlength(ptr, length);
- else
- /* length cannot be changed */
- return 0;
- }
- else
- prop->arraylength= length; /* function parameters only? */
+ PropertyRNA *rprop= rna_ensure_property(prop);
- return 1;
-}
+ if(length && rprop->arraydimension > 1)
+ rna_ensure_property_multi_array_length(ptr, prop, length);
-/* used by BPY to make an array from the python object */
-unsigned short RNA_property_array_dimension(PropertyRNA *prop, unsigned short dimsize[])
-{
- if (dimsize && prop->arraydimension > 1) {
- memcpy(dimsize, prop->dimsize, sizeof(prop->dimsize[0]) * (prop->arraydimension - 1));
- }
- return prop->arraydimension;
+ return rprop->arraydimension;
}
/* Return the size of Nth dimension. */
-int RNA_property_multidimensional_array_length(PointerRNA *ptr, PropertyRNA *prop, int dim)
+int RNA_property_multi_array_length(PointerRNA *ptr, PropertyRNA *prop, int dim)
{
- unsigned short i;
- int len;
+ int len[RNA_MAX_ARRAY_DIMENSION];
- if (dim == 0) {
- len= RNA_property_array_length(ptr, prop);
+ rna_ensure_property_multi_array_length(ptr, prop, len);
- for (i= 0; i < prop->arraydimension - 1; i++)
- len /= prop->dimsize[i];
- }
- else {
- len= prop->dimsize[dim - 1];
- }
-
- return len;
+ return len[dim];
}
char RNA_property_array_item_char(PropertyRNA *prop, int index)
@@ -902,27 +895,40 @@ void RNA_property_boolean_get_array(PointerRNA *ptr, PropertyRNA *prop, int *val
IDProperty *idprop;
if((idprop=rna_idproperty_check(&prop, ptr))) {
- if(prop->arraylength == 0)
+ if(prop->arraydimension == 0)
values[0]= RNA_property_boolean_get(ptr, prop);
else
memcpy(values, IDP_Array(idprop), sizeof(int)*idprop->len);
}
- else if(prop->arraylength == 0)
+ else if(prop->arraydimension == 0)
values[0]= RNA_property_boolean_get(ptr, prop);
else if(bprop->getarray)
bprop->getarray(ptr, values);
else if(bprop->defaultarray)
- memcpy(values, bprop->defaultarray, sizeof(int)*prop->arraylength);
+ memcpy(values, bprop->defaultarray, sizeof(int)*prop->totarraylength);
else
- memset(values, 0, sizeof(int)*prop->arraylength);
+ memset(values, 0, sizeof(int)*prop->totarraylength);
}
int RNA_property_boolean_get_index(PointerRNA *ptr, PropertyRNA *prop, int index)
{
- int tmp[RNA_MAX_ARRAY];
+ int tmp[RNA_MAX_ARRAY_LENGTH];
+ int len= rna_ensure_property_array_length(ptr, prop);
+
+ if(len <= RNA_MAX_ARRAY_LENGTH) {
+ RNA_property_boolean_get_array(ptr, prop, tmp);
+ return tmp[index];
+ }
+ else {
+ int *tmparray, value;
- RNA_property_boolean_get_array(ptr, prop, tmp);
- return tmp[index];
+ tmparray= MEM_callocN(sizeof(int)*len, "RNA_property_boolean_get_index");
+ RNA_property_boolean_get_array(ptr, prop, tmparray);
+ value= tmparray[index];
+ MEM_freeN(tmparray);
+
+ return value;
+ }
}
void RNA_property_boolean_set_array(PointerRNA *ptr, PropertyRNA *prop, const int *values)
@@ -931,12 +937,12 @@ void RNA_property_boolean_set_array(PointerRNA *ptr, PropertyRNA *prop, const in
IDProperty *idprop;
if((idprop=rna_idproperty_check(&prop, ptr))) {
- if(prop->arraylength == 0)
+ if(prop->arraydimension == 0)
IDP_Int(idprop)= values[0];
else
memcpy(IDP_Array(idprop), values, sizeof(int)*idprop->len);
}
- else if(prop->arraylength == 0)
+ else if(prop->arraydimension == 0)
RNA_property_boolean_set(ptr, prop, values[0]);
else if(bprop->setarray)
bprop->setarray(ptr, values);
@@ -944,7 +950,7 @@ void RNA_property_boolean_set_array(PointerRNA *ptr, PropertyRNA *prop, const in
IDPropertyTemplate val = {0};
IDProperty *group;
- val.array.len= prop->arraylength;
+ val.array.len= prop->totarraylength;
val.array.type= IDP_INT;
group= RNA_struct_idproperties(ptr, 1);
@@ -958,11 +964,23 @@ void RNA_property_boolean_set_array(PointerRNA *ptr, PropertyRNA *prop, const in
void RNA_property_boolean_set_index(PointerRNA *ptr, PropertyRNA *prop, int index, int value)
{
- int tmp[RNA_MAX_ARRAY];
+ int tmp[RNA_MAX_ARRAY_LENGTH];
+ int len= rna_ensure_property_array_length(ptr, prop);
+
+ if(len <= RNA_MAX_ARRAY_LENGTH) {
+ RNA_property_boolean_get_array(ptr, prop, tmp);
+ tmp[index]= value;
+ RNA_property_boolean_set_array(ptr, prop, tmp);
+ }
+ else {
+ int *tmparray;
- RNA_property_boolean_get_array(ptr, prop, tmp);
- tmp[index]= value;
- RNA_property_boolean_set_array(ptr, prop, tmp);
+ tmparray= MEM_callocN(sizeof(int)*len, "RNA_property_boolean_get_index");
+ RNA_property_boolean_get_array(ptr, prop, tmparray);
+ tmparray[index]= value;
+ RNA_property_boolean_set_array(ptr, prop, tmparray);
+ MEM_freeN(tmparray);
+ }
}
int RNA_property_int_get(PointerRNA *ptr, PropertyRNA *prop)
@@ -1005,27 +1023,40 @@ void RNA_property_int_get_array(PointerRNA *ptr, PropertyRNA *prop, int *values)
IDProperty *idprop;
if((idprop=rna_idproperty_check(&prop, ptr))) {
- if(prop->arraylength == 0)
+ if(prop->arraydimension == 0)
values[0]= RNA_property_int_get(ptr, prop);
else
memcpy(values, IDP_Array(idprop), sizeof(int)*idprop->len);
}
- else if(prop->arraylength == 0)
+ else if(prop->arraydimension == 0)
values[0]= RNA_property_int_get(ptr, prop);
else if(iprop->getarray)
iprop->getarray(ptr, values);
else if(iprop->defaultarray)
- memcpy(values, iprop->defaultarray, sizeof(int)*prop->arraylength);
+ memcpy(values, iprop->defaultarray, sizeof(int)*prop->totarraylength);
else
- memset(values, 0, sizeof(int)*prop->arraylength);
+ memset(values, 0, sizeof(int)*prop->totarraylength);
}
int RNA_property_int_get_index(PointerRNA *ptr, PropertyRNA *prop, int index)
{
- int tmp[RNA_MAX_ARRAY];
+ int tmp[RNA_MAX_ARRAY_LENGTH];
+ int len= rna_ensure_property_array_length(ptr, prop);
+
+ if(len <= RNA_MAX_ARRAY_LENGTH) {
+ RNA_property_int_get_array(ptr, prop, tmp);
+ return tmp[index];
+ }
+ else {
+ int *tmparray, value;
+
+ tmparray= MEM_callocN(sizeof(int)*len, "RNA_property_int_get_index");
+ RNA_property_int_get_array(ptr, prop, tmparray);
+ value= tmparray[index];
+ MEM_freeN(tmparray);
- RNA_property_int_get_array(ptr, prop, tmp);
- return tmp[index];
+ return value;
+ }
}
void RNA_property_int_set_array(PointerRNA *ptr, PropertyRNA *prop, const int *values)
@@ -1034,12 +1065,12 @@ void RNA_property_int_set_array(PointerRNA *ptr, PropertyRNA *prop, const int *v
IDProperty *idprop;
if((idprop=rna_idproperty_check(&prop, ptr))) {
- if(prop->arraylength == 0)
+ if(prop->arraydimension == 0)
IDP_Int(idprop)= values[0];
else
memcpy(IDP_Array(idprop), values, sizeof(int)*idprop->len);\
}
- else if(prop->arraylength == 0)
+ else if(prop->arraydimension == 0)
RNA_property_int_set(ptr, prop, values[0]);
else if(iprop->setarray)
iprop->setarray(ptr, values);
@@ -1047,7 +1078,7 @@ void RNA_property_int_set_array(PointerRNA *ptr, PropertyRNA *prop, const int *v
IDPropertyTemplate val = {0};
IDProperty *group;
- val.array.len= prop->arraylength;
+ val.array.len= prop->totarraylength;
val.array.type= IDP_INT;
group= RNA_struct_idproperties(ptr, 1);
@@ -1061,11 +1092,23 @@ void RNA_property_int_set_array(PointerRNA *ptr, PropertyRNA *prop, const int *v
void RNA_property_int_set_index(PointerRNA *ptr, PropertyRNA *prop, int index, int value)
{
- int tmp[RNA_MAX_ARRAY];
+ int tmp[RNA_MAX_ARRAY_LENGTH];
+ int len= rna_ensure_property_array_length(ptr, prop);
- RNA_property_int_get_array(ptr, prop, tmp);
- tmp[index]= value;
- RNA_property_int_set_array(ptr, prop, tmp);
+ if(len <= RNA_MAX_ARRAY_LENGTH) {
+ RNA_property_int_get_array(ptr, prop, tmp);
+ tmp[index]= value;
+ RNA_property_int_set_array(ptr, prop, tmp);
+ }
+ else {
+ int *tmparray;
+
+ tmparray= MEM_callocN(sizeof(int)*len, "RNA_property_int_get_index");
+ RNA_property_int_get_array(ptr, prop, tmparray);
+ tmparray[index]= value;
+ RNA_property_int_set_array(ptr, prop, tmparray);
+ MEM_freeN(tmparray);
+ }
}
float RNA_property_float_get(PointerRNA *ptr, PropertyRNA *prop)
@@ -1118,7 +1161,7 @@ void RNA_property_float_get_array(PointerRNA *ptr, PropertyRNA *prop, float *val
int i;
if((idprop=rna_idproperty_check(&prop, ptr))) {
- if(prop->arraylength == 0)
+ if(prop->arraydimension == 0)
values[0]= RNA_property_float_get(ptr, prop);
else if(idprop->subtype == IDP_FLOAT) {
memcpy(values, IDP_Array(idprop), sizeof(float)*idprop->len);
@@ -1128,22 +1171,36 @@ void RNA_property_float_get_array(PointerRNA *ptr, PropertyRNA *prop, float *val
values[i]= (float)(((double*)IDP_Array(idprop))[i]);
}
}
- else if(prop->arraylength == 0)
+ else if(prop->arraydimension == 0)
values[0]= RNA_property_float_get(ptr, prop);
else if(fprop->getarray)
fprop->getarray(ptr, values);
else if(fprop->defaultarray)
- memcpy(values, fprop->defaultarray, sizeof(float)*prop->arraylength);
+ memcpy(values, fprop->defaultarray, sizeof(float)*prop->totarraylength);
else
- memset(values, 0, sizeof(float)*prop->arraylength);
+ memset(values, 0, sizeof(float)*prop->totarraylength);
}
float RNA_property_float_get_index(PointerRNA *ptr, PropertyRNA *prop, int index)
{
- float tmp[RNA_MAX_ARRAY];
+ float tmp[RNA_MAX_ARRAY_LENGTH];
+ int len= rna_ensure_property_array_length(ptr, prop);
+
+ if(len <= RNA_MAX_ARRAY_LENGTH) {
+ RNA_property_float_get_array(ptr, prop, tmp);
+ return tmp[index];
+ }
+ else {
+ float *tmparray, value;
+
+ tmparray= MEM_callocN(sizeof(float)*len, "RNA_property_float_get_index");
+ RNA_property_float_get_array(ptr, prop, tmparray);
+ value= tmparray[index];
+ MEM_freeN(tmparray);
+
+ return value;
+ }
- RNA_property_float_get_array(ptr, prop, tmp);
- return tmp[index];
}
void RNA_property_float_set_array(PointerRNA *ptr, PropertyRNA *prop, const float *values)
@@ -1153,7 +1210,7 @@ void RNA_property_float_set_array(PointerRNA *ptr, PropertyRNA *prop, const floa
int i;
if((idprop=rna_idproperty_check(&prop, ptr))) {
- if(prop->arraylength == 0)
+ if(prop->arraydimension == 0)
IDP_Double(idprop)= values[0];
else if(idprop->subtype == IDP_FLOAT) {
memcpy(IDP_Array(idprop), values, sizeof(float)*idprop->len);
@@ -1163,7 +1220,7 @@ void RNA_property_float_set_array(PointerRNA *ptr, PropertyRNA *prop, const floa
((double*)IDP_Array(idprop))[i]= values[i];
}
}
- else if(prop->arraylength == 0)
+ else if(prop->arraydimension == 0)
RNA_property_float_set(ptr, prop, values[0]);
else if(fprop->setarray) {
fprop->setarray(ptr, values);
@@ -1172,7 +1229,7 @@ void RNA_property_float_set_array(PointerRNA *ptr, PropertyRNA *prop, const floa
IDPropertyTemplate val = {0};
IDProperty *group;
- val.array.len= prop->arraylength;
+ val.array.len= prop->totarraylength;
val.array.type= IDP_FLOAT;
group= RNA_struct_idproperties(ptr, 1);
@@ -1186,11 +1243,23 @@ void RNA_property_float_set_array(PointerRNA *ptr, PropertyRNA *prop, const floa
void RNA_property_float_set_index(PointerRNA *ptr, PropertyRNA *prop, int index, float value)
{
- float tmp[RNA_MAX_ARRAY];
+ float tmp[RNA_MAX_ARRAY_LENGTH];
+ int len= rna_ensure_property_array_length(ptr, prop);
- RNA_property_float_get_array(ptr, prop, tmp);
- tmp[index]= value;
- RNA_property_float_set_array(ptr, prop, tmp);
+ if(len <= RNA_MAX_ARRAY_LENGTH) {
+ RNA_property_float_get_array(ptr, prop, tmp);
+ tmp[index]= value;
+ RNA_property_float_set_array(ptr, prop, tmp);
+ }
+ else {
+ float *tmparray;
+
+ tmparray= MEM_callocN(sizeof(float)*len, "RNA_property_float_get_index");
+ RNA_property_float_get_array(ptr, prop, tmparray);
+ tmparray[index]= value;
+ RNA_property_float_set_array(ptr, prop, tmparray);
+ MEM_freeN(tmparray);
+ }
}
void RNA_property_string_get(PointerRNA *ptr, PropertyRNA *prop, char *value)
@@ -2912,15 +2981,15 @@ ParameterList *RNA_parameter_list_create(ParameterList *parms, PointerRNA *ptr,
if(!(parm->flag & PROP_REQUIRED)) {
switch(parm->type) {
case PROP_BOOLEAN:
- if(parm->arraylength) memcpy(data, &((BooleanPropertyRNA*)parm)->defaultarray, size);
+ if(parm->arraydimension) memcpy(data, &((BooleanPropertyRNA*)parm)->defaultarray, size);
else memcpy(data, &((BooleanPropertyRNA*)parm)->defaultvalue, size);
break;
case PROP_INT:
- if(parm->arraylength) memcpy(data, &((IntPropertyRNA*)parm)->defaultarray, size);
+ if(parm->arraydimension) memcpy(data, &((IntPropertyRNA*)parm)->defaultarray, size);
else memcpy(data, &((IntPropertyRNA*)parm)->defaultvalue, size);
break;
case PROP_FLOAT:
- if(parm->arraylength) memcpy(data, &((FloatPropertyRNA*)parm)->defaultarray, size);
+ if(parm->arraydimension) memcpy(data, &((FloatPropertyRNA*)parm)->defaultarray, size);
else memcpy(data, &((FloatPropertyRNA*)parm)->defaultvalue, size);
break;
case PROP_ENUM: