RNA
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Wed, 26 Nov 2008 22:24:26 +0000 (22:24 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Wed, 26 Nov 2008 22:24:26 +0000 (22:24 +0000)
* Made auto collection wrapping work for ** arrays.
  (Mesh.mats, still points to ID since there is no Material yet).
* Added sorting of RNA structs/properties before writing.

source/blender/makesrna/intern/SConscript
source/blender/makesrna/intern/makesrna.c
source/blender/makesrna/intern/rna_access.c
source/blender/makesrna/intern/rna_define.c
source/blender/makesrna/intern/rna_internal.h
source/blender/makesrna/intern/rna_mesh.c

index e493e274690ece575b35f7cbde83d104f457fdd0..f8d623dfa2bcc709ca7f7bec8142b2d46ea06529 100644 (file)
@@ -3,7 +3,7 @@ import sys
 import os
 
 Import ('env')
-cflags = '-Wall'
+cflags = ''
 defines = []
 root_build_dir=env['BF_BUILDDIR']
 
index 2f110b764a5c4e6d035a44ed92c15f642dd0a944..d9db1121ba23ede0eb7cbc654366741d5ec3f0f9 100644 (file)
 #endif
 #endif
 
+int cmp_struct(const void *a, const void *b)
+{
+       const StructRNA *structa= *(const StructRNA**)a;
+       const StructRNA *structb= *(const StructRNA**)b;
+
+       return strcmp(structa->identifier, structb->identifier);
+}
+
+int cmp_property(const void *a, const void *b)
+{
+       const PropertyRNA *propa= *(const PropertyRNA**)a;
+       const PropertyRNA *propb= *(const PropertyRNA**)b;
+
+       if(strcmp(propa->identifier, "rna_type") == 0) return -1;
+       else if(strcmp(propb->identifier, "rna_type") == 0) return 1;
+
+       if(strcmp(propa->identifier, "name") == 0) return -1;
+       else if(strcmp(propb->identifier, "name") == 0) return 1;
+
+       return strcmp(propa->name, propb->name);
+}
+
+void rna_sortlist(ListBase *listbase, int(*cmp)(const void*, const void*))
+{
+       Link *link;
+       void **array;
+       int a, size;
+       
+       if(listbase->first == listbase->last)
+               return;
+
+       for(size=0, link=listbase->first; link; link=link->next)
+               size++;
+
+       array= MEM_mallocN(sizeof(void*)*size, "rna_sortlist");
+       for(a=0, link=listbase->first; link; link=link->next, a++)
+               array[a]= link;
+
+       qsort(array, size, sizeof(void*), cmp);
+
+       listbase->first= listbase->last= NULL;
+       for(a=0; a<size; a++) {
+               link= array[a];
+               link->next= link->prev= NULL;
+               rna_addtail(listbase, link);
+       }
+
+       MEM_freeN(array);
+}
+
 /* Preprocessing */
 
 static void rna_print_c_string(FILE *f, const char *str)
@@ -499,6 +549,16 @@ static void rna_auto_functions(FILE *f)
                        rna_def_property_funcs(f, dp);
 }
 
+static void rna_sort(BlenderRNA *brna)
+{
+       StructRNA *srna;
+
+       rna_sortlist(&brna->structs, cmp_struct);
+
+       for(srna=brna->structs.first; srna; srna=srna->next)
+               rna_sortlist(&srna->properties, cmp_property);
+}
+
 static const char *rna_property_structname(PropertyType type)
 {
        switch(type) {
@@ -830,6 +890,7 @@ static int rna_preprocess(char *basedirectory, FILE *f)
        fprintf(f, "\n");
 
        rna_auto_functions(f);
+       rna_sort(brna);
 
        for(srna=brna->structs.first; srna; srna=srna->next)
                rna_generate_struct(brna, srna, f);
index 488a49588304d724f445a05f8a3e83e4993ed5f4..7351ff700e663aeee4959c7c7d1f6f54e96aa80f 100644 (file)
@@ -1106,6 +1106,14 @@ void *rna_iterator_array_get(CollectionPropertyIterator *iter)
        return internal->ptr;
 }
 
+void *rna_iterator_array_dereference_get(CollectionPropertyIterator *iter)
+{
+       ArrayIterator *internal= iter->internal;
+
+       /* for ** arrays */
+       return *(void**)(internal->ptr);
+}
+
 void rna_iterator_array_end(CollectionPropertyIterator *iter)
 {
        MEM_freeN(iter->internal);
index 9d9606809f6eb243f2f1ba877e77d1cf01ba9346..63df7252e9e69622af565d2230944bb5898f4a9a 100644 (file)
@@ -97,6 +97,7 @@ typedef struct DNAStructMember {
        char *type;
        char *name;
        int arraylength;
+       int pointerlevel;
 } DNAStructMember;
 
 static int rna_member_cmp(const char *name, const char *oname)
@@ -125,7 +126,7 @@ static int rna_find_sdna_member(SDNA *sdna, const char *structname, const char *
 {
        char *dnaname;
        short *sp;
-       int a, structnr, totmember, cmp;
+       int a, b, structnr, totmember, cmp;
 
        structnr= DNA_struct_find_nr(sdna, structname);
        if(structnr == -1)
@@ -144,6 +145,11 @@ static int rna_find_sdna_member(SDNA *sdna, const char *structname, const char *
                        smember->type= sdna->types[sp[0]];
                        smember->name= dnaname;
                        smember->arraylength= DNA_elem_array_size(smember->name, strlen(smember->name));
+
+                       smember->pointerlevel= 0;
+                       for(b=0; dnaname[b] == '*'; b++)
+                               smember->pointerlevel++;
+
                        return 1;
                }
                else if(cmp == 2) {
@@ -864,6 +870,7 @@ static PropertyDefRNA *rna_def_property_sdna(PropertyRNA *prop, const char *stru
        dp->dnaname= propname;
        dp->dnatype= smember.type;
        dp->dnaarraylength= smember.arraylength;
+       dp->dnapointerlevel= smember.pointerlevel;
 
        return dp;
 }
@@ -1077,8 +1084,12 @@ void RNA_def_property_collection_sdna(PropertyRNA *prop, const char *structname,
                        dp->dnalengthname= lengthpropname;
 
                        cprop->next= (PropCollectionNextFunc)"rna_iterator_array_next";
-                       cprop->get= (PropCollectionGetFunc)"rna_iterator_array_get";
                        cprop->end= (PropCollectionEndFunc)"rna_iterator_array_end";
+
+                       if(dp->dnapointerlevel >= 2) 
+                               cprop->get= (PropCollectionGetFunc)"rna_iterator_array_dereference_get";
+                       else
+                               cprop->get= (PropCollectionGetFunc)"rna_iterator_array_get";
                }
        }
 }
index f5079ac437f4ff4f8d2589298bc6d984c2c8c059..03ef6016c07229ee015a3af6d2b6e6ecb39f235c 100644 (file)
@@ -46,6 +46,7 @@ typedef struct PropertyDefRNA {
        const char *dnalengthname;
        const char *dnatype;
        int dnaarraylength;
+       int dnapointerlevel;
 
        int booleanbit;
 } PropertyDefRNA;
@@ -136,6 +137,7 @@ typedef struct ArrayIterator {
 void rna_iterator_array_begin(struct CollectionPropertyIterator *iter, void *ptr, int itemsize, int length, IteratorSkipFunc skip);
 void rna_iterator_array_next(struct CollectionPropertyIterator *iter);
 void *rna_iterator_array_get(struct CollectionPropertyIterator *iter);
+void *rna_iterator_array_dereference_get(struct CollectionPropertyIterator *iter);
 void rna_iterator_array_end(struct CollectionPropertyIterator *iter);
 
 /* Duplicated code since we can't link in blenlib */
index 369bd1a5d372978d11113168e723805da9bc42b8..522641318bc22ce58c222896cb255fc8ee147cbe 100644 (file)
@@ -721,7 +721,7 @@ static void rna_def_mcol(BlenderRNA *brna)
        RNA_def_property_float_funcs(prop, "rna_MCol_color4_get", "rna_MCol_color4_set", NULL);
        RNA_def_property_ui_text(prop, "Color 4", "");
 
-       srna= RNA_def_struct(brna, "MColLayer", NULL, "Mesh Texture Face Layer");
+       srna= RNA_def_struct(brna, "MColLayer", NULL, "Mesh Vertex Color Layer");
        RNA_def_struct_sdna(srna, "CustomDataLayer");
 
        prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
@@ -937,10 +937,10 @@ static void rna_def_mesh(BlenderRNA *brna)
        RNA_def_property_pointer_sdna(prop, NULL, "mr");
        RNA_def_property_ui_text(prop, "Multires", "");
 
-       /*prop= RNA_def_property(srna, "materials", PROP_COLLECTION, PROP_NONE);
+       prop= RNA_def_property(srna, "materials", PROP_COLLECTION, PROP_NONE);
        RNA_def_property_collection_sdna(prop, NULL, "mat", "totcol");
-       RNA_def_property_struct_type(prop, "Material");
-       RNA_def_property_ui_text(prop, "Materials", "");*/
+       RNA_def_property_struct_type(prop, "ID");
+       RNA_def_property_ui_text(prop, "Materials", "");
 
        /*prop= RNA_def_property(srna, "key", PROP_POINTER, PROP_NONE);
        RNA_def_property_ui_text(prop, "Key", "");*/