RNA:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Fri, 29 May 2009 15:12:31 +0000 (15:12 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Fri, 29 May 2009 15:12:31 +0000 (15:12 +0000)
* Added PROP_ID_REFCOUNT flag to control if refcounting should
  be done on ID pointer properties. All ID pointers are refcounted,
  by default, with the exception of Object, Scene and Text.
* Also made TextureFace image pointer editable, with the special
  refcounting behavior.

source/blender/makesrna/RNA_define.h
source/blender/makesrna/RNA_types.h
source/blender/makesrna/intern/makesrna.c
source/blender/makesrna/intern/rna_ID.c
source/blender/makesrna/intern/rna_define.c
source/blender/makesrna/intern/rna_mesh.c
source/blender/makesrna/intern/rna_object.c
source/blender/makesrna/intern/rna_scene.c
source/blender/makesrna/intern/rna_text.c

index 540b9ec..0754114 100644 (file)
@@ -52,6 +52,7 @@ void RNA_def_struct_sdna_from(StructRNA *srna, const char *structname, const cha
 void RNA_def_struct_name_property(StructRNA *srna, PropertyRNA *prop);
 void RNA_def_struct_nested(BlenderRNA *brna, StructRNA *srna, const char *structname);
 void RNA_def_struct_flag(StructRNA *srna, int flag);
+void RNA_def_struct_clear_flag(StructRNA *srna, int flag);
 void RNA_def_struct_refine_func(StructRNA *srna, const char *refine);
 void RNA_def_struct_idproperties_func(StructRNA *srna, const char *refine);
 void RNA_def_struct_register_funcs(StructRNA *srna, const char *reg, const char *unreg);
index 0a88363..7e62ea6 100644 (file)
@@ -99,6 +99,9 @@ typedef enum PropertyFlag {
        PROP_REGISTER = 16,
        PROP_REGISTER_OPTIONAL = 16|32,
 
+       /* pointers */
+       PROP_ID_REFCOUNT = 64,
+
        /* internal flags */
        PROP_BUILTIN = 128,
        PROP_EXPORT = 256,
@@ -172,12 +175,13 @@ typedef struct FunctionRNA FunctionRNA;
 /* Struct */
 
 typedef enum StructFlag {
-       /* indicates that this struct is an ID struct */
+       /* indicates that this struct is an ID struct, and to use refcounting */
        STRUCT_ID = 1,
+       STRUCT_ID_REFCOUNT = 2,
 
        /* internal flags */
-       STRUCT_RUNTIME = 2,
-       STRUCT_GENERATED = 4
+       STRUCT_RUNTIME = 4,
+       STRUCT_GENERATED = 8
 } StructFlag;
 
 typedef int (*StructValidateFunc)(struct PointerRNA *ptr, void *data, int *have_function);
index b6ea00a..4381002 100644 (file)
@@ -509,17 +509,15 @@ static char *rna_def_property_set_func(FILE *f, StructRNA *srna, PropertyRNA *pr
                                fprintf(f, "    %s(ptr, value);\n", manualfunc);
                        }
                        else {
-                               PointerPropertyRNA *pprop= (PointerPropertyRNA*)prop;
-                               StructRNA *type= rna_find_struct((char*)pprop->type);
-
                                rna_print_data_get(f, dp);
 
-                               if(type && (type->flag & STRUCT_ID) && strcmp(type->identifier, "Object")!=0) {
+                               if(prop->flag & PROP_ID_REFCOUNT) {
                                        fprintf(f, "\n  if(data->%s)\n", dp->dnaname);
                                        fprintf(f, "            id_us_min((ID*)data->%s);\n", dp->dnaname);
                                        fprintf(f, "    if(value.data)\n");
                                        fprintf(f, "            id_us_plus((ID*)value.data);\n\n");
                                }
+
                                fprintf(f, "    data->%s= value.data;\n", dp->dnaname);
 
                        }
@@ -1212,9 +1210,16 @@ static void rna_auto_types()
                        if(dp->dnatype) {
                                if(dp->prop->type == PROP_POINTER) {
                                        PointerPropertyRNA *pprop= (PointerPropertyRNA*)dp->prop;
+                                       StructRNA *type;
 
                                        if(!pprop->type && !pprop->get)
                                                pprop->type= (StructRNA*)rna_find_type(dp->dnatype);
+
+                                       if(pprop->type) {
+                                               type= rna_find_struct((char*)pprop->type);
+                                               if(type && (type->flag & STRUCT_ID_REFCOUNT))
+                                                       pprop->property.flag |= PROP_ID_REFCOUNT;
+                                       }
                                }
                                else if(dp->prop->type== PROP_COLLECTION) {
                                        CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)dp->prop;
index ee1a1fe..ad1c7ea 100644 (file)
@@ -182,7 +182,7 @@ static void rna_def_ID(BlenderRNA *brna)
 
        srna= RNA_def_struct(brna, "ID", NULL);
        RNA_def_struct_ui_text(srna, "ID", "Base type for datablocks, defining a unique name, linking from other libraries and garbage collection.");
-       RNA_def_struct_flag(srna, STRUCT_ID);
+       RNA_def_struct_flag(srna, STRUCT_ID|STRUCT_ID_REFCOUNT);
        RNA_def_struct_refine_func(srna, "rna_ID_refine");
        RNA_def_struct_idproperties_func(srna, "rna_ID_idproperties");
 
index 924a1c9..49c8c69 100644 (file)
@@ -712,7 +712,12 @@ void RNA_def_struct_nested(BlenderRNA *brna, StructRNA *srna, const char *struct
 
 void RNA_def_struct_flag(StructRNA *srna, int flag)
 {
-       srna->flag= flag;
+       srna->flag |= flag;
+}
+
+void RNA_def_struct_clear_flag(StructRNA *srna, int flag)
+{
+       srna->flag &= ~flag;
 }
 
 void RNA_def_struct_refine_func(StructRNA *srna, const char *refine)
@@ -1059,6 +1064,10 @@ void RNA_def_property_struct_runtime(PropertyRNA *prop, StructRNA *type)
                case PROP_POINTER: {
                        PointerPropertyRNA *pprop= (PointerPropertyRNA*)prop;
                        pprop->type = type;
+
+                       if(type && (type->flag & STRUCT_ID_REFCOUNT))
+                               prop->flag |= PROP_ID_REFCOUNT;
+
                        break;
                }
                case PROP_COLLECTION: {
index c1fa0a4..c75558d 100644 (file)
@@ -467,6 +467,23 @@ static int rna_Mesh_string_layers_length(PointerRNA *ptr)
        return rna_CustomDataLayer_length(ptr, CD_PROP_STR);
 }
 
+static void rna_TextureFace_image_set(PointerRNA *ptr, PointerRNA value)
+{
+       MTFace *tf= (MTFace*)ptr->data;
+       ID *id= value.data;
+
+       if(id) {
+               /* special exception here, individual faces don't count
+                * as reference, but we do ensure the refcount is not zero */
+               if(id->us == 0)
+                       id_us_plus(id);
+               else
+                       id_lib_extern(id);
+       }
+
+       tf->tpage= (struct Image*)id;
+}
+
 /* path construction */
 
 static char *rna_VertexGroupElement_path(PointerRNA *ptr)
@@ -747,9 +764,11 @@ static void rna_def_mtface(BlenderRNA *brna)
        RNA_def_struct_ui_text(srna, "Mesh Texture Face", "UV mapping, texturing and game engine data for a face.");
        RNA_def_struct_path_func(srna, "rna_MeshTextureFace_path");
 
-       /* prop= RNA_def_property(srna, "image", PROP_POINTER, PROP_NONE);
+       prop= RNA_def_property(srna, "image", PROP_POINTER, PROP_NONE);
        RNA_def_property_pointer_sdna(prop, NULL, "tpage");
-       RNA_def_property_ui_text(prop, "Image", ""); */
+       RNA_def_property_pointer_funcs(prop, NULL, "rna_TextureFace_image_set");
+       RNA_def_property_flag(prop, PROP_EDITABLE);
+       RNA_def_property_ui_text(prop, "Image", "");
 
        prop= RNA_def_property(srna, "tex", PROP_BOOLEAN, PROP_NONE);
        RNA_def_property_boolean_sdna(prop, NULL, "mode", TF_TEX);
index 360b6e1..86df293 100644 (file)
@@ -513,6 +513,7 @@ static StructRNA *rna_def_object(BlenderRNA *brna)
 
        srna= RNA_def_struct(brna, "Object", "ID");
        RNA_def_struct_ui_text(srna, "Object", "Object datablock defining an object in a scene..");
+       RNA_def_struct_clear_flag(srna, STRUCT_ID_REFCOUNT);
 
        prop= RNA_def_property(srna, "data", PROP_POINTER, PROP_NONE);
        RNA_def_property_struct_type(prop, "ID");
index 790c2b6..caa6e73 100644 (file)
@@ -607,6 +607,7 @@ void RNA_def_scene(BlenderRNA *brna)
 
        srna= RNA_def_struct(brna, "Scene", "ID");
        RNA_def_struct_ui_text(srna, "Scene", "Scene consisting objects and defining time and render related settings.");
+       RNA_def_struct_clear_flag(srna, STRUCT_ID_REFCOUNT);
 
        prop= RNA_def_property(srna, "camera", PROP_POINTER, PROP_NONE);
        RNA_def_property_flag(prop, PROP_EDITABLE);
index 3dacd4c..d3e4a34 100644 (file)
@@ -172,6 +172,7 @@ static void rna_def_text(BlenderRNA *brna)
        
        srna = RNA_def_struct(brna, "Text", "ID");
        RNA_def_struct_ui_text(srna, "Text", "Text datablock referencing an external or packed text file.");
+       RNA_def_struct_clear_flag(srna, STRUCT_ID_REFCOUNT);
        
        prop= RNA_def_property(srna, "filename", PROP_STRING, PROP_NONE);
        RNA_def_property_string_funcs(prop, "rna_Text_filename_get", "rna_Text_filename_length", "rna_Text_filename_set");