[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [21780] branches/blender2.5/blender/source /blender: RNA
Brecht Van Lommel
brecht at blender.org
Tue Jul 21 22:05:16 CEST 2009
Revision: 21780
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=21780
Author: blendix
Date: 2009-07-21 22:05:16 +0200 (Tue, 21 Jul 2009)
Log Message:
-----------
RNA
* ID blocks can now get RNA properties defined from python, e.g.:
bpy.types.Scene.BoolProperty(..)
* RNA structs/functions/properties can now get pointers duplicated
(mostly strings), since we can't point to some static string then.
* Added ExtensionRNA struct to add into *Type structs for subclassing,
is a bit more compact than defining the 4 variables each time.
Only disadvantage is it requires including RNA in more places.
Modified Paths:
--------------
branches/blender2.5/blender/source/blender/blenkernel/BKE_screen.h
branches/blender2.5/blender/source/blender/blenkernel/intern/screen.c
branches/blender2.5/blender/source/blender/blenloader/CMakeLists.txt
branches/blender2.5/blender/source/blender/blenloader/SConscript
branches/blender2.5/blender/source/blender/blenloader/intern/Makefile
branches/blender2.5/blender/source/blender/makesrna/RNA_define.h
branches/blender2.5/blender/source/blender/makesrna/RNA_types.h
branches/blender2.5/blender/source/blender/makesrna/intern/rna_define.c
branches/blender2.5/blender/source/blender/makesrna/intern/rna_ui.c
branches/blender2.5/blender/source/blender/nodes/CMakeLists.txt
branches/blender2.5/blender/source/blender/nodes/SConscript
branches/blender2.5/blender/source/blender/nodes/intern/CMP_nodes/Makefile
branches/blender2.5/blender/source/blender/nodes/intern/Makefile
branches/blender2.5/blender/source/blender/nodes/intern/SHD_nodes/Makefile
branches/blender2.5/blender/source/blender/nodes/intern/TEX_nodes/Makefile
branches/blender2.5/blender/source/blender/python/intern/bpy_rna.c
Modified: branches/blender2.5/blender/source/blender/blenkernel/BKE_screen.h
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/BKE_screen.h 2009-07-21 19:44:15 UTC (rev 21779)
+++ branches/blender2.5/blender/source/blender/blenkernel/BKE_screen.h 2009-07-21 20:05:16 UTC (rev 21780)
@@ -46,11 +46,9 @@
struct wmWindowManager;
struct uiLayout;
struct uiMenuItem;
-struct StructRNA;
-struct PointerRNA;
-struct FunctionRNA;
-struct ParameterList;
+#include "RNA_types.h"
+
/* spacetype has everything stored to get an editor working, it gets initialized via
ED_spacetypes_init() in editors/area/spacetypes.c */
/* an editor in Blender is a combined ScrArea + SpaceType + SpaceData */
@@ -169,11 +167,8 @@
/* draw entirely, view changes should be handled here */
void (*draw)(const struct bContext *, struct Panel *);
- /* python integration */
- void *py_data;
- struct StructRNA *py_srna;
- int (*py_call)(struct PointerRNA *, struct FunctionRNA *, struct ParameterList *);
- void (*py_free)(void *py_data);
+ /* RNA integration */
+ ExtensionRNA ext;
} PanelType;
/* header types */
@@ -187,11 +182,8 @@
/* draw entirely, view changes should be handled here */
void (*draw)(const struct bContext *, struct Header *);
- /* python integration */
- void *py_data;
- struct StructRNA *py_srna;
- int (*py_call)(struct PointerRNA *, struct FunctionRNA *, struct ParameterList *);
- void (*py_free)(void *py_data);
+ /* RNA integration */
+ ExtensionRNA ext;
} HeaderType;
typedef struct Header {
@@ -214,11 +206,8 @@
/* draw entirely, view changes should be handled here */
void (*draw)(const struct bContext *, struct Menu *);
- /* python integration */
- void *py_data;
- struct StructRNA *py_srna;
- int (*py_call)(struct PointerRNA *, struct FunctionRNA *, struct ParameterList *);
- void (*py_free)(void *py_data);
+ /* RNA integration */
+ ExtensionRNA ext;
} MenuType;
typedef struct Menu {
Modified: branches/blender2.5/blender/source/blender/blenkernel/intern/screen.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/intern/screen.c 2009-07-21 19:44:15 UTC (rev 21779)
+++ branches/blender2.5/blender/source/blender/blenkernel/intern/screen.c 2009-07-21 20:05:16 UTC (rev 21780)
@@ -61,16 +61,16 @@
BLI_freelistN(&art->drawcalls);
for(pt= art->paneltypes.first; pt; pt= pt->next)
- if(pt->py_free)
- pt->py_free(pt->py_data);
+ if(pt->ext.free)
+ pt->ext.free(pt->ext.data);
for(ht= art->headertypes.first; ht; ht= ht->next)
- if(ht->py_free)
- ht->py_free(ht->py_data);
+ if(ht->ext.free)
+ ht->ext.free(ht->ext.data);
for(mt= art->menutypes.first; mt; mt= mt->next)
- if(mt->py_free)
- mt->py_free(mt->py_data);
+ if(mt->ext.free)
+ mt->ext.free(mt->ext.data);
BLI_freelistN(&art->paneltypes);
BLI_freelistN(&art->headertypes);
Modified: branches/blender2.5/blender/source/blender/blenloader/CMakeLists.txt
===================================================================
--- branches/blender2.5/blender/source/blender/blenloader/CMakeLists.txt 2009-07-21 19:44:15 UTC (rev 21779)
+++ branches/blender2.5/blender/source/blender/blenloader/CMakeLists.txt 2009-07-21 20:05:16 UTC (rev 21780)
@@ -28,7 +28,7 @@
SET(INC
. ../../../intern/guardedalloc ../blenlib ../blenkernel
- ../makesdna ../readblenfile ../include
+ ../makesdna ../readblenfile ../include ../makesrna
../python ../../kernel/gen_messaging
../render/extern/include
${ZLIB_INC}
Modified: branches/blender2.5/blender/source/blender/blenloader/SConscript
===================================================================
--- branches/blender2.5/blender/source/blender/blenloader/SConscript 2009-07-21 19:44:15 UTC (rev 21779)
+++ branches/blender2.5/blender/source/blender/blenloader/SConscript 2009-07-21 20:05:16 UTC (rev 21780)
@@ -5,7 +5,7 @@
incs = '. #/intern/guardedalloc ../blenlib ../blenkernel'
incs += ' ../makesdna ../readblenfile ../editors/include'
-incs += ' ../render/extern/include'
+incs += ' ../render/extern/include ../makesrna'
incs += ' ' + env['BF_ZLIB_INC']
Modified: branches/blender2.5/blender/source/blender/blenloader/intern/Makefile
===================================================================
--- branches/blender2.5/blender/source/blender/blenloader/intern/Makefile 2009-07-21 19:44:15 UTC (rev 21779)
+++ branches/blender2.5/blender/source/blender/blenloader/intern/Makefile 2009-07-21 20:05:16 UTC (rev 21780)
@@ -54,6 +54,7 @@
# This mod uses the GEN, DNA, BLI and BKE modules
CPPFLAGS += -I../../../kernel/gen_messaging
CPPFLAGS += -I../../makesdna
+CPPFLAGS += -I../../makesrna
CPPFLAGS += -I../../blenlib
# path to the guarded memory allocator
CPPFLAGS += -I$(NAN_GUARDEDALLOC)/include
Modified: branches/blender2.5/blender/source/blender/makesrna/RNA_define.h
===================================================================
--- branches/blender2.5/blender/source/blender/makesrna/RNA_define.h 2009-07-21 19:44:15 UTC (rev 21779)
+++ branches/blender2.5/blender/source/blender/makesrna/RNA_define.h 2009-07-21 20:05:16 UTC (rev 21780)
@@ -170,6 +170,15 @@
void RNA_enum_items_add_value(EnumPropertyItem **items, int *totitem, EnumPropertyItem *item, int value);
void RNA_enum_item_end(EnumPropertyItem **items, int *totitem);
+/* Memory management */
+
+void RNA_def_struct_duplicate_pointers(StructRNA *srna);
+void RNA_def_struct_free_pointers(StructRNA *srna);
+void RNA_def_func_duplicate_pointers(FunctionRNA *func);
+void RNA_def_func_free_pointers(FunctionRNA *func);
+void RNA_def_property_duplicate_pointers(PropertyRNA *prop);
+void RNA_def_property_free_pointers(PropertyRNA *prop);
+
#ifdef __cplusplus
}
#endif
Modified: branches/blender2.5/blender/source/blender/makesrna/RNA_types.h
===================================================================
--- branches/blender2.5/blender/source/blender/makesrna/RNA_types.h 2009-07-21 19:44:15 UTC (rev 21779)
+++ branches/blender2.5/blender/source/blender/makesrna/RNA_types.h 2009-07-21 20:05:16 UTC (rev 21780)
@@ -113,6 +113,7 @@
PROP_IDPROPERTY = 1024,
PROP_RAW_ACCESS = 8192,
PROP_RAW_ARRAY = 16384,
+ PROP_FREE_POINTERS = 32768
} PropertyFlag;
typedef struct CollectionPropertyIterator {
@@ -198,7 +199,8 @@
/* internal flags */
FUNC_BUILTIN = 128,
FUNC_EXPORT = 256,
- FUNC_RUNTIME = 512
+ FUNC_RUNTIME = 512,
+ FUNC_FREE_POINTERS = 1024
} FunctionFlag;
typedef void (*CallFunc)(struct bContext *C, struct ReportList *reports, PointerRNA *ptr, ParameterList *parms);
@@ -214,7 +216,8 @@
/* internal flags */
STRUCT_RUNTIME = 4,
- STRUCT_GENERATED = 8
+ STRUCT_GENERATED = 8,
+ STRUCT_FREE_POINTERS = 16
} StructFlag;
typedef int (*StructValidateFunc)(struct PointerRNA *ptr, void *data, int *have_function);
@@ -232,6 +235,19 @@
typedef struct BlenderRNA BlenderRNA;
+/* Extending
+ *
+ * This struct must be embedded in *Type structs in
+ * order to make then definable through RNA. */
+
+typedef struct ExtensionRNA {
+ void *data;
+ StructRNA *srna;
+
+ int (*call)(PointerRNA *, FunctionRNA *, ParameterList *);
+ void (*free)(void *data);
+} ExtensionRNA;
+
#ifdef __cplusplus
}
#endif
Modified: branches/blender2.5/blender/source/blender/makesrna/intern/rna_define.c
===================================================================
--- branches/blender2.5/blender/source/blender/makesrna/intern/rna_define.c 2009-07-21 19:44:15 UTC (rev 21779)
+++ branches/blender2.5/blender/source/blender/makesrna/intern/rna_define.c 2009-07-21 20:05:16 UTC (rev 21780)
@@ -39,6 +39,7 @@
#include "RNA_types.h"
#include "BLI_ghash.h"
+#include "BLI_string.h"
#include "rna_internal.h"
@@ -445,6 +446,7 @@
void RNA_struct_free(BlenderRNA *brna, StructRNA *srna)
{
+#ifdef RNA_RUNTIME
FunctionRNA *func, *nextfunc;
PropertyRNA *prop, *nextprop;
PropertyRNA *parm, *nextparm;
@@ -452,6 +454,8 @@
for(prop=srna->cont.properties.first; prop; prop=nextprop) {
nextprop= prop->next;
+ RNA_def_property_free_pointers(prop);
+
if(prop->flag & PROP_RUNTIME)
rna_freelinkN(&srna->cont.properties, prop);
}
@@ -462,17 +466,23 @@
for(parm=func->cont.properties.first; parm; parm=nextparm) {
nextparm= parm->next;
+ RNA_def_property_free_pointers(parm);
+
if(parm->flag & PROP_RUNTIME)
rna_freelinkN(&func->cont.properties, parm);
}
- if(func->flag & FUNC_RUNTIME) {
+ RNA_def_func_free_pointers(func);
+
+ if(func->flag & FUNC_RUNTIME)
rna_freelinkN(&srna->functions, func);
- }
}
+ RNA_def_struct_free_pointers(srna);
+
if(srna->flag & STRUCT_RUNTIME)
rna_freelinkN(&brna->structs, srna);
+#endif
}
void RNA_free(BlenderRNA *brna)
@@ -2327,3 +2337,141 @@
RNA_enum_item_add(items, totitem, &empty);
}
+/* Memory management */
+
+#ifdef RNA_RUNTIME
+void RNA_def_struct_duplicate_pointers(StructRNA *srna)
+{
+ if(srna->identifier) srna->identifier= BLI_strdup(srna->identifier);
+ if(srna->name) srna->name= BLI_strdup(srna->name);
+ if(srna->description) srna->description= BLI_strdup(srna->description);
+
+ srna->flag |= STRUCT_FREE_POINTERS;
+}
+
+void RNA_def_struct_free_pointers(StructRNA *srna)
+{
+ if(srna->flag & STRUCT_FREE_POINTERS) {
+ if(srna->identifier) MEM_freeN((void*)srna->identifier);
+ if(srna->name) MEM_freeN((void*)srna->name);
+ if(srna->description) MEM_freeN((void*)srna->description);
+ }
+}
+
+void RNA_def_func_duplicate_pointers(FunctionRNA *func)
+{
+ if(func->identifier) func->identifier= BLI_strdup(func->identifier);
+ if(func->description) func->description= BLI_strdup(func->description);
+
+ func->flag |= FUNC_FREE_POINTERS;
+}
+
+void RNA_def_func_free_pointers(FunctionRNA *func)
+{
+ if(func->flag & FUNC_FREE_POINTERS) {
+ if(func->identifier) MEM_freeN((void*)func->identifier);
+ if(func->description) MEM_freeN((void*)func->description);
+ }
+}
+
+void RNA_def_property_duplicate_pointers(PropertyRNA *prop)
+{
+ EnumPropertyItem *earray;
+ float *farray;
+ int *iarray;
+
+ if(prop->identifier) prop->identifier= BLI_strdup(prop->identifier);
+ if(prop->name) prop->name= BLI_strdup(prop->name);
+ if(prop->description) prop->description= BLI_strdup(prop->description);
+
+ switch(prop->type) {
+ case PROP_BOOLEAN: {
+ BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop;
+
+ if(bprop->defaultarray) {
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list