[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [21239] branches/blender2.5/blender/source /blender/makesrna: RNA
Brecht Van Lommel
brecht at blender.org
Mon Jun 29 21:15:51 CEST 2009
Revision: 21239
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=21239
Author: blendix
Date: 2009-06-29 21:15:51 +0200 (Mon, 29 Jun 2009)
Log Message:
-----------
RNA
Implementation of RNA side of foreach_get/foreach_set,
Campbell will do python code.
Three functions for efficiently setting some property for all
items in a collection. RNA_property_collection_raw_array gives
access to the properties as an array with length, stride, and
type specified, if this is possible, i.e. not when it uses a
ListBase, or if a manual get/set function is implemented.
Two other functions take a C array pointer and get/set it
using the a collection + property name, using efficient array
access if possible, and otherwise using slower RNA iterator.
RNA_property_collection_raw_get
RNA_property_collection_raw_set
The number of type conversion required here got a bit out of
hand, it could be more efficient still if checking for more
cases, but function is already long enough.
Example: http://www.pasteall.org/6362/c
Modified Paths:
--------------
branches/blender2.5/blender/source/blender/makesrna/RNA_access.h
branches/blender2.5/blender/source/blender/makesrna/RNA_types.h
branches/blender2.5/blender/source/blender/makesrna/intern/makesrna.c
branches/blender2.5/blender/source/blender/makesrna/intern/rna_access.c
branches/blender2.5/blender/source/blender/makesrna/intern/rna_define.c
branches/blender2.5/blender/source/blender/makesrna/intern/rna_internal.h
branches/blender2.5/blender/source/blender/makesrna/intern/rna_internal_types.h
branches/blender2.5/blender/source/blender/makesrna/intern/rna_rna.c
Modified: branches/blender2.5/blender/source/blender/makesrna/RNA_access.h
===================================================================
--- branches/blender2.5/blender/source/blender/makesrna/RNA_access.h 2009-06-29 19:00:38 UTC (rev 21238)
+++ branches/blender2.5/blender/source/blender/makesrna/RNA_access.h 2009-06-29 19:15:51 UTC (rev 21239)
@@ -600,6 +600,11 @@
int RNA_property_collection_lookup_int(PointerRNA *ptr, PropertyRNA *prop, int key, PointerRNA *r_ptr);
int RNA_property_collection_lookup_string(PointerRNA *ptr, PropertyRNA *prop, const char *key, PointerRNA *r_ptr);
+/* efficient functions to set properties for arrays */
+int RNA_property_collection_raw_array(PointerRNA *ptr, PropertyRNA *prop, PropertyRNA *itemprop, RawArray *array);
+int RNA_property_collection_raw_get(struct ReportList *reports, PointerRNA *ptr, PropertyRNA *prop, char *propname, void *array, RawPropertyType type, int len);
+int RNA_property_collection_raw_set(struct ReportList *reports, PointerRNA *ptr, PropertyRNA *prop, char *propname, void *array, RawPropertyType type, int len);
+
/* to create ID property groups */
void RNA_property_pointer_add(PointerRNA *ptr, PropertyRNA *prop);
void RNA_property_pointer_remove(PointerRNA *ptr, PropertyRNA *prop);
Modified: branches/blender2.5/blender/source/blender/makesrna/RNA_types.h
===================================================================
--- branches/blender2.5/blender/source/blender/makesrna/RNA_types.h 2009-06-29 19:00:38 UTC (rev 21238)
+++ branches/blender2.5/blender/source/blender/makesrna/RNA_types.h 2009-06-29 19:15:51 UTC (rev 21239)
@@ -110,7 +110,9 @@
PROP_BUILTIN = 128,
PROP_EXPORT = 256,
PROP_RUNTIME = 512,
- PROP_IDPROPERTY = 1024
+ PROP_IDPROPERTY = 1024,
+ PROP_RAW_ACCESS = 8192,
+ PROP_RAW_ARRAY = 16384,
} PropertyFlag;
typedef struct CollectionPropertyIterator {
@@ -132,6 +134,21 @@
PointerRNA ptr;
} CollectionPointerLink;
+typedef enum RawPropertyType {
+ PROP_RAW_CHAR,
+ PROP_RAW_SHORT,
+ PROP_RAW_INT,
+ PROP_RAW_FLOAT,
+ PROP_RAW_DOUBLE
+} RawPropertyType;
+
+typedef struct RawArray {
+ void *array;
+ RawPropertyType type;
+ int len;
+ int stride;
+} RawArray;
+
/* Iterator Utility */
typedef struct EnumPropertyItem {
Modified: branches/blender2.5/blender/source/blender/makesrna/intern/makesrna.c
===================================================================
--- branches/blender2.5/blender/source/blender/makesrna/intern/makesrna.c 2009-06-29 19:00:38 UTC (rev 21238)
+++ branches/blender2.5/blender/source/blender/makesrna/intern/makesrna.c 2009-06-29 19:15:51 UTC (rev 21239)
@@ -762,6 +762,42 @@
return func;
}
+static void rna_set_raw_property(PropertyDefRNA *dp, PropertyRNA *prop)
+{
+ if(dp->dnapointerlevel != 0)
+ return;
+ if(!dp->dnatype || !dp->dnaname || !dp->dnastructname)
+ return;
+
+ if(strcmp(dp->dnatype, "char") == 0) {
+ prop->rawtype= PROP_RAW_CHAR;
+ prop->flag |= PROP_RAW_ACCESS;
+ }
+ else if(strcmp(dp->dnatype, "short") == 0) {
+ prop->rawtype= PROP_RAW_SHORT;
+ prop->flag |= PROP_RAW_ACCESS;
+ }
+ else if(strcmp(dp->dnatype, "int") == 0) {
+ prop->rawtype= PROP_RAW_INT;
+ prop->flag |= PROP_RAW_ACCESS;
+ }
+ else if(strcmp(dp->dnatype, "float") == 0) {
+ prop->rawtype= PROP_RAW_FLOAT;
+ prop->flag |= PROP_RAW_ACCESS;
+ }
+ else if(strcmp(dp->dnatype, "double") == 0) {
+ prop->rawtype= PROP_RAW_DOUBLE;
+ prop->flag |= PROP_RAW_ACCESS;
+ }
+}
+
+static void rna_set_raw_offset(FILE *f, StructRNA *srna, PropertyRNA *prop)
+{
+ PropertyDefRNA *dp= rna_find_struct_property_def(srna, prop);
+
+ fprintf(f, "\toffsetof(%s, %s), %d", dp->dnastructname, dp->dnaname, prop->rawtype);
+}
+
static void rna_def_property_funcs(FILE *f, StructRNA *srna, PropertyDefRNA *dp)
{
PropertyRNA *prop;
@@ -773,6 +809,9 @@
BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop;
if(!prop->arraylength) {
+ if(!bprop->get && !bprop->set && !dp->booleanbit)
+ rna_set_raw_property(dp, prop);
+
bprop->get= (void*)rna_def_property_get_func(f, srna, prop, dp, (char*)bprop->get);
bprop->set= (void*)rna_def_property_set_func(f, srna, prop, dp, (char*)bprop->set);
}
@@ -786,10 +825,16 @@
IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
if(!prop->arraylength) {
+ if(!iprop->get && !iprop->set)
+ rna_set_raw_property(dp, prop);
+
iprop->get= (void*)rna_def_property_get_func(f, srna, prop, dp, (char*)iprop->get);
iprop->set= (void*)rna_def_property_set_func(f, srna, prop, dp, (char*)iprop->set);
}
else {
+ if(!iprop->getarray && !iprop->setarray)
+ rna_set_raw_property(dp, prop);
+
iprop->getarray= (void*)rna_def_property_get_func(f, srna, prop, dp, (char*)iprop->getarray);
iprop->setarray= (void*)rna_def_property_set_func(f, srna, prop, dp, (char*)iprop->setarray);
}
@@ -799,10 +844,16 @@
FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
if(!prop->arraylength) {
+ if(!fprop->get && !fprop->set)
+ rna_set_raw_property(dp, prop);
+
fprop->get= (void*)rna_def_property_get_func(f, srna, prop, dp, (char*)fprop->get);
fprop->set= (void*)rna_def_property_set_func(f, srna, prop, dp, (char*)fprop->set);
}
else {
+ if(!fprop->getarray && !fprop->setarray)
+ rna_set_raw_property(dp, prop);
+
fprop->getarray= (void*)rna_def_property_get_func(f, srna, prop, dp, (char*)fprop->getarray);
fprop->setarray= (void*)rna_def_property_set_func(f, srna, prop, dp, (char*)fprop->setarray);
}
@@ -841,6 +892,13 @@
else if(dp->dnalengthname || dp->dnalengthfixed)
cprop->length= (void*)rna_def_property_length_func(f, srna, prop, dp, (char*)cprop->length);
+ /* test if we can allow raw array access, if it is using our standard
+ * array get/next function, we can be sure it is an actual array */
+ if(cprop->next && cprop->get)
+ if(strcmp((char*)cprop->next, "rna_iterator_array_next") == 0 &&
+ strcmp((char*)cprop->get, "rna_iterator_array_get") == 0)
+ prop->flag |= PROP_RAW_ARRAY;
+
cprop->get= (void*)rna_def_property_get_func(f, srna, prop, dp, (char*)cprop->get);
cprop->begin= (void*)rna_def_property_begin_func(f, srna, prop, dp, (char*)cprop->begin);
cprop->next= (void*)rna_def_property_next_func(f, srna, prop, dp, (char*)cprop->next);
@@ -1538,7 +1596,7 @@
DefRNA.error= 1;
}
break;
- }
+ }
case PROP_BOOLEAN: {
BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop;
unsigned int i;
@@ -1558,7 +1616,7 @@
fprintf(f, "};\n\n");
}
break;
- }
+ }
case PROP_INT: {
IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
unsigned int i;
@@ -1578,7 +1636,7 @@
fprintf(f, "};\n\n");
}
break;
- }
+ }
case PROP_FLOAT: {
FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
unsigned int i;
@@ -1598,7 +1656,7 @@
fprintf(f, "};\n\n");
}
break;
- }
+ }
default:
break;
}
@@ -1613,11 +1671,15 @@
rna_print_c_string(f, prop->identifier);
fprintf(f, ", %d, ", prop->flag);
rna_print_c_string(f, prop->name); fprintf(f, ",\n\t");
- rna_print_c_string(f, prop->description); fprintf(f, ",\n");
- fprintf(f, "%d, ", prop->icon);
+ rna_print_c_string(f, prop->description); fprintf(f, ",\n\t");
+ fprintf(f, "%d,\n", prop->icon);
fprintf(f, "\t%s, %s, %d,\n", rna_property_typename(prop->type), rna_property_subtypename(prop->subtype), prop->arraylength);
- fprintf(f, "\t%s, %d, %s},\n", rna_function_string(prop->update), prop->noteflag, rna_function_string(prop->editable));
+ fprintf(f, "\t%s, %d, %s,\n", rna_function_string(prop->update), prop->noteflag, rna_function_string(prop->editable));
+ if(prop->flag & PROP_RAW_ACCESS) rna_set_raw_offset(f, srna, prop);
+ else fprintf(f, "\t0, 0");
+ fprintf(f, "},\n");
+
switch(prop->type) {
case PROP_BOOLEAN: {
BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop;
@@ -1625,7 +1687,7 @@
if(prop->arraylength) fprintf(f, "rna_%s%s_%s_default\n", srna->identifier, strnest, prop->identifier);
else fprintf(f, "NULL\n");
break;
- }
+ }
case PROP_INT: {
IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
fprintf(f, "\t%s, %s, %s, %s, %s,\n\t", rna_function_string(iprop->get), rna_function_string(iprop->set), rna_function_string(iprop->getarray), rna_function_string(iprop->setarray), rna_function_string(iprop->range));
@@ -1638,7 +1700,7 @@
if(prop->arraylength) fprintf(f, "rna_%s%s_%s_default\n", srna->identifier, strnest, prop->identifier);
else fprintf(f, "NULL\n");
break;
- }
+ }
case PROP_FLOAT: {
FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
fprintf(f, "\t%s, %s, %s, %s, %s, ", rna_function_string(fprop->get), rna_function_string(fprop->set), rna_function_string(fprop->getarray), rna_function_string(fprop->setarray), rna_function_string(fprop->range));
@@ -1652,13 +1714,13 @@
if(prop->arraylength) fprintf(f, "rna_%s%s_%s_default\n", srna->identifier, strnest, prop->identifier);
else fprintf(f, "NULL\n");
break;
- }
+ }
case PROP_STRING: {
StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
fprintf(f, "\t%s, %s, %s, %d, ", rna_function_string(sprop->get), rna_function_string(sprop->length), rna_function_string(sprop->set), sprop->maxlength);
rna_print_c_string(f, sprop->defaultvalue); fprintf(f, "\n");
break;
- }
+ }
case PROP_ENUM: {
EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
fprintf(f, "\t%s, %s, %s, ", rna_function_string(eprop->get), rna_function_string(eprop->set), rna_function_string(eprop->itemf));
@@ -1668,14 +1730,14 @@
fprintf(f, "NULL, ");
fprintf(f, "%d, %d\n", eprop->totitem, eprop->defaultvalue);
break;
- }
+ }
case PROP_POINTER: {
PointerPropertyRNA *pprop= (PointerPropertyRNA*)prop;
fprintf(f, "\t%s, %s, %s, ", rna_function_string(pprop->get), rna_function_string(pprop->set), rna_function_string(pprop->typef));
if(pprop->type) fprintf(f, "&RNA_%s\n", (char*)pprop->type);
else fprintf(f, "NULL\n");
break;
- }
+ }
case PROP_COLLECTION: {
CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list