[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [36521] branches/particles-2010/source/ blender: Fix for problematic storage of RNA property subtype values in blend files.
Lukas Toenne
lukas.toenne at googlemail.com
Fri May 6 21:38:51 CEST 2011
Revision: 36521
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=36521
Author: lukastoenne
Date: 2011-05-06 19:38:51 +0000 (Fri, 06 May 2011)
Log Message:
-----------
Fix for problematic storage of RNA property subtype values in blend files. This would break backwards compatibility sooner or later when the PropertySubType enum is changed.
As a solution the socket default value subtypes are now a separate list of values in DNA. These values are then translated to RNA subtypes by makesrna.
Modified Paths:
--------------
branches/particles-2010/source/blender/makesdna/DNA_node_types.h
branches/particles-2010/source/blender/makesrna/intern/rna_nodetree.c
branches/particles-2010/source/blender/nodes/intern/CMP_nodes/CMP_alphaOver.c
branches/particles-2010/source/blender/nodes/intern/CMP_nodes/CMP_blur.c
branches/particles-2010/source/blender/nodes/intern/CMP_nodes/CMP_brightness.c
branches/particles-2010/source/blender/nodes/intern/CMP_nodes/CMP_colorSpill.c
branches/particles-2010/source/blender/nodes/intern/CMP_nodes/CMP_colorbalance.c
branches/particles-2010/source/blender/nodes/intern/CMP_nodes/CMP_composite.c
branches/particles-2010/source/blender/nodes/intern/CMP_nodes/CMP_curves.c
branches/particles-2010/source/blender/nodes/intern/CMP_nodes/CMP_defocus.c
branches/particles-2010/source/blender/nodes/intern/CMP_nodes/CMP_dilate.c
branches/particles-2010/source/blender/nodes/intern/CMP_nodes/CMP_displace.c
branches/particles-2010/source/blender/nodes/intern/CMP_nodes/CMP_filter.c
branches/particles-2010/source/blender/nodes/intern/CMP_nodes/CMP_gamma.c
branches/particles-2010/source/blender/nodes/intern/CMP_nodes/CMP_hueSatVal.c
branches/particles-2010/source/blender/nodes/intern/CMP_nodes/CMP_huecorrect.c
branches/particles-2010/source/blender/nodes/intern/CMP_nodes/CMP_idMask.c
branches/particles-2010/source/blender/nodes/intern/CMP_nodes/CMP_invert.c
branches/particles-2010/source/blender/nodes/intern/CMP_nodes/CMP_lensdist.c
branches/particles-2010/source/blender/nodes/intern/CMP_nodes/CMP_mapUV.c
branches/particles-2010/source/blender/nodes/intern/CMP_nodes/CMP_mapValue.c
branches/particles-2010/source/blender/nodes/intern/CMP_nodes/CMP_math.c
branches/particles-2010/source/blender/nodes/intern/CMP_nodes/CMP_mixrgb.c
branches/particles-2010/source/blender/nodes/intern/CMP_nodes/CMP_normal.c
branches/particles-2010/source/blender/nodes/intern/CMP_nodes/CMP_normalize.c
branches/particles-2010/source/blender/nodes/intern/CMP_nodes/CMP_outputFile.c
branches/particles-2010/source/blender/nodes/intern/CMP_nodes/CMP_rotate.c
branches/particles-2010/source/blender/nodes/intern/CMP_nodes/CMP_scale.c
branches/particles-2010/source/blender/nodes/intern/CMP_nodes/CMP_sepcombHSVA.c
branches/particles-2010/source/blender/nodes/intern/CMP_nodes/CMP_sepcombRGBA.c
branches/particles-2010/source/blender/nodes/intern/CMP_nodes/CMP_sepcombYCCA.c
branches/particles-2010/source/blender/nodes/intern/CMP_nodes/CMP_sepcombYUVA.c
branches/particles-2010/source/blender/nodes/intern/CMP_nodes/CMP_setalpha.c
branches/particles-2010/source/blender/nodes/intern/CMP_nodes/CMP_texture.c
branches/particles-2010/source/blender/nodes/intern/CMP_nodes/CMP_translate.c
branches/particles-2010/source/blender/nodes/intern/CMP_nodes/CMP_valToRgb.c
branches/particles-2010/source/blender/nodes/intern/CMP_nodes/CMP_vecBlur.c
branches/particles-2010/source/blender/nodes/intern/CMP_nodes/CMP_viewer.c
branches/particles-2010/source/blender/nodes/intern/CMP_nodes/CMP_zcombine.c
branches/particles-2010/source/blender/nodes/intern/SHD_nodes/SHD_curves.c
branches/particles-2010/source/blender/nodes/intern/SHD_nodes/SHD_hueSatVal.c
branches/particles-2010/source/blender/nodes/intern/SHD_nodes/SHD_invert.c
branches/particles-2010/source/blender/nodes/intern/SHD_nodes/SHD_mapping.c
branches/particles-2010/source/blender/nodes/intern/SHD_nodes/SHD_material.c
branches/particles-2010/source/blender/nodes/intern/SHD_nodes/SHD_math.c
branches/particles-2010/source/blender/nodes/intern/SHD_nodes/SHD_mixRgb.c
branches/particles-2010/source/blender/nodes/intern/SHD_nodes/SHD_normal.c
branches/particles-2010/source/blender/nodes/intern/SHD_nodes/SHD_output.c
branches/particles-2010/source/blender/nodes/intern/SHD_nodes/SHD_sepcombRGB.c
branches/particles-2010/source/blender/nodes/intern/SHD_nodes/SHD_squeeze.c
branches/particles-2010/source/blender/nodes/intern/SHD_nodes/SHD_texture.c
branches/particles-2010/source/blender/nodes/intern/SHD_nodes/SHD_valToRgb.c
branches/particles-2010/source/blender/nodes/intern/SHD_nodes/SHD_vectMath.c
branches/particles-2010/source/blender/nodes/intern/TEX_nodes/TEX_at.c
branches/particles-2010/source/blender/nodes/intern/TEX_nodes/TEX_bricks.c
branches/particles-2010/source/blender/nodes/intern/TEX_nodes/TEX_checker.c
branches/particles-2010/source/blender/nodes/intern/TEX_nodes/TEX_compose.c
branches/particles-2010/source/blender/nodes/intern/TEX_nodes/TEX_distance.c
branches/particles-2010/source/blender/nodes/intern/TEX_nodes/TEX_hueSatVal.c
branches/particles-2010/source/blender/nodes/intern/TEX_nodes/TEX_math.c
branches/particles-2010/source/blender/nodes/intern/TEX_nodes/TEX_mixRgb.c
branches/particles-2010/source/blender/nodes/intern/TEX_nodes/TEX_output.c
branches/particles-2010/source/blender/nodes/intern/TEX_nodes/TEX_proc.c
branches/particles-2010/source/blender/nodes/intern/TEX_nodes/TEX_rotate.c
branches/particles-2010/source/blender/nodes/intern/TEX_nodes/TEX_scale.c
branches/particles-2010/source/blender/nodes/intern/TEX_nodes/TEX_translate.c
branches/particles-2010/source/blender/nodes/intern/TEX_nodes/TEX_valToNor.c
branches/particles-2010/source/blender/nodes/intern/TEX_nodes/TEX_valToRgb.c
branches/particles-2010/source/blender/nodes/intern/node_socket.h
Modified: branches/particles-2010/source/blender/makesdna/DNA_node_types.h
===================================================================
--- branches/particles-2010/source/blender/makesdna/DNA_node_types.h 2011-05-06 15:31:45 UTC (rev 36520)
+++ branches/particles-2010/source/blender/makesdna/DNA_node_types.h 2011-05-06 19:38:51 UTC (rev 36521)
@@ -99,6 +99,16 @@
bNodeStack ns; /* custom data for inputs, only UI writes in this */
} bNodeSocket;
+/* sock->type */
+#define SOCK_VALUE 0
+#define SOCK_VECTOR 1
+#define SOCK_RGBA 2
+#define SOCK_INT 3
+#define SOCK_BOOLEAN 4
+#define SOCK_FLOAT 5
+#define SOCK_MESH 6
+#define NUM_SOCKET_TYPES 7 /* must be last! */
+
/* socket side (input/output) */
#define SOCK_IN 1
#define SOCK_OUT 2
@@ -267,6 +277,8 @@
float value;
float min, max;
} bNodeSocketValueFloat;
+/* value sockets use the same data as floats, typedef for RNA */
+typedef struct bNodeSocketValueFloat bNodeSocketValueValue;
typedef struct bNodeSocketValueBoolean {
char value;
@@ -283,7 +295,27 @@
float value[4];
} bNodeSocketValueRGBA;
+/* Socket value subtypes.
+ * Make sure these use the same suffix as their RNA counterparts,
+ * so the RNA definitions macros can match the subtype definitions.
+ * When adding a new subtype here, make sure you also add it
+ * to the NODE_DEFINE_SUBTYPES macro in node_socket.h.
+ */
+#define SOCK_SUBTYPE_NONE 0
+#define SOCK_SUBTYPE_UNSIGNED 1
+#define SOCK_SUBTYPE_PERCENTAGE 2
+#define SOCK_SUBTYPE_FACTOR 3
+#define SOCK_SUBTYPE_ANGLE 4
+#define SOCK_SUBTYPE_TIME 5
+#define SOCK_SUBTYPE_DISTANCE 6
+#define SOCK_SUBTYPE_TRANSLATION 7
+#define SOCK_SUBTYPE_DIRECTION 8
+#define SOCK_SUBTYPE_VELOCITY 9
+#define SOCK_SUBTYPE_ACCELERATION 10
+#define SOCK_SUBTYPE_EULER 11
+#define SOCK_SUBTYPE_XYZ 12
+
/* data structs, for node->storage */
/* this one has been replaced with ImageUser, keep it for do_versions() */
Modified: branches/particles-2010/source/blender/makesrna/intern/rna_nodetree.c
===================================================================
--- branches/particles-2010/source/blender/makesrna/intern/rna_nodetree.c 2011-05-06 15:31:45 UTC (rev 36520)
+++ branches/particles-2010/source/blender/makesrna/intern/rna_nodetree.c 2011-05-06 19:38:51 UTC (rev 36521)
@@ -118,6 +118,40 @@
{0, NULL, 0, NULL, NULL}};
+/* Add any new socket value subtype here.
+ * When adding a new subtype here, make sure you also add it
+ * to the subtype definitions in DNA_node_types.h.
+ * This macro is used by the RNA and the internal converter functions
+ * to define all socket subtypes. The SUBTYPE macro must be defined
+ * before using this macro, and undefined afterwards.
+ */
+#define NODE_DEFINE_SUBTYPES_INT \
+SUBTYPE(INT, Int, NONE, None) \
+SUBTYPE(INT, Int, UNSIGNED, Unsigned)
+
+#define NODE_DEFINE_SUBTYPES_FLOAT \
+SUBTYPE(FLOAT, Float, NONE, None) \
+SUBTYPE(FLOAT, Float, UNSIGNED, Unsigned) \
+SUBTYPE(FLOAT, Float, PERCENTAGE, Percentage) \
+SUBTYPE(FLOAT, Float, FACTOR, Factor) \
+SUBTYPE(FLOAT, Float, ANGLE, Angle) \
+SUBTYPE(FLOAT, Float, TIME, Time) \
+SUBTYPE(FLOAT, Float, DISTANCE, Distance)
+
+#define NODE_DEFINE_SUBTYPES_VECTOR \
+SUBTYPE(VECTOR, Vector, NONE, None) \
+SUBTYPE(VECTOR, Vector, TRANSLATION, Translation) \
+SUBTYPE(VECTOR, Vector, DIRECTION, Direction) \
+SUBTYPE(VECTOR, Vector, VELOCITY, Velocity) \
+SUBTYPE(VECTOR, Vector, ACCELERATION, Acceleration) \
+SUBTYPE(VECTOR, Vector, EULER, Euler) \
+SUBTYPE(VECTOR, Vector, XYZ, XYZ)
+
+#define NODE_DEFINE_SUBTYPES \
+NODE_DEFINE_SUBTYPES_INT \
+NODE_DEFINE_SUBTYPES_FLOAT \
+NODE_DEFINE_SUBTYPES_VECTOR
+
#ifdef RNA_RUNTIME
#include "BLI_linklist.h"
@@ -180,49 +214,37 @@
bNodeSocket *sock= (bNodeSocket*)ptr->data;
if (sock->default_value) {
- StructRNA *type= &RNA_NodeSocket;
+ /* This returns the refined socket type with the full definition
+ * of the default input value with type and subtype.
+ */
+ #define SUBTYPE(socktype, stypename, id, idname) \
+ { \
+ bNodeSocketValue##stypename *value= (bNodeSocketValue##stypename*)sock->default_value; \
+ if (value->subtype==SOCK_SUBTYPE_##id) \
+ return &RNA_NodeSocket##stypename##idname; \
+ }
+
switch (sock->type) {
case SOCK_VALUE:
case SOCK_FLOAT:
- {
- bNodeSocketValueFloat *value= (bNodeSocketValueFloat*)sock->default_value;
-
- #define DefSocketSubtypeFloat(name, _subtype) \
- if (value->subtype==_subtype) \
- type = &RNA_NodeSocketFloat##name;
- #include "rna_nodetree_types.h"
- }
+ NODE_DEFINE_SUBTYPES_FLOAT
break;
case SOCK_INT:
- {
- bNodeSocketValueInt *value= (bNodeSocketValueInt*)sock->default_value;
-
- #define DefSocketSubtypeInt(name, _subtype) \
- if (value->subtype==_subtype) \
- type = &RNA_NodeSocketInt##name;
- #include "rna_nodetree_types.h"
- }
+ NODE_DEFINE_SUBTYPES_INT
break;
case SOCK_BOOLEAN:
- type = &RNA_NodeSocketBoolean;
+ return &RNA_NodeSocketBoolean;
break;
case SOCK_VECTOR:
- {
- bNodeSocketValueVector *value= (bNodeSocketValueVector*)sock->default_value;
-
- #define DefSocketSubtypeVector(name, _subtype) \
- if (value->subtype==_subtype) \
- type = &RNA_NodeSocketVector##name;
- #include "rna_nodetree_types.h"
- }
+ NODE_DEFINE_SUBTYPES_VECTOR
break;
case SOCK_RGBA:
- type = &RNA_NodeSocketRGBA;
+ return &RNA_NodeSocketRGBA;
break;
}
- return type;
+ #undef SUBTYPE
}
return &RNA_NodeSocket;
@@ -2650,52 +2672,22 @@
RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_NodeGroupSocket_update");
}
-static void rna_def_node_socket_int(BlenderRNA *brna, const char *name, const char *ui_name, int subtype)
+static void rna_def_node_socket_subtype(BlenderRNA *brna, int type, int subtype, const char *name, const char *ui_name)
{
StructRNA *srna;
PropertyRNA *prop=NULL;
- #define DefSocketSubtypeInt(name, subtype) \
- { subtype, #subtype, 0, #name, ""},
-
- static EnumPropertyItem subtype_items[] = {
- #include "rna_nodetree_types.h"
- {0, NULL, 0, NULL, NULL}
- };
+ PropertySubType propsubtype= PROP_NONE;
+ #define SUBTYPE(socktype, stypename, id, idname) if (subtype==SOCK_SUBTYPE_##id) propsubtype = PROP_##id;
+ NODE_DEFINE_SUBTYPES
+ #undef SUBTYPE
- srna = RNA_def_struct(brna, name, "NodeSocket");
- RNA_def_struct_ui_text(srna, ui_name, "Input or output socket of a node");
- RNA_def_struct_sdna(srna, "bNodeSocket");
- RNA_def_struct_ui_icon(srna, ICON_PLUG);
- RNA_def_struct_path_func(srna, "rna_NodeSocket_path");
-
- RNA_def_struct_sdna_from(srna, "bNodeSocketValueInt", "default_value");
-
- prop = RNA_def_property(srna, "subtype", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "subtype");
- RNA_def_property_enum_items(prop, subtype_items);
- RNA_def_property_ui_text(prop, "Subtype", "Subtype defining the socket value details");
- RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_NodeSocket_update");
-
- prop = RNA_def_property(srna, "default_value", PROP_INT, subtype);
- RNA_def_property_int_sdna(prop, NULL, "value");
- RNA_def_property_int_funcs(prop, NULL, NULL, "rna_NodeSocketInt_range");
- RNA_def_property_ui_text(prop, "Default Value", "");
- RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_NodeSocket_update");
-}
-
-static void rna_def_node_socket_float(BlenderRNA *brna, const char *name, const char *ui_name, int subtype)
-{
- StructRNA *srna;
- PropertyRNA *prop=NULL;
-
- #define DefSocketSubtypeFloat(name, subtype) \
- { subtype, #subtype, 0, #name, ""},
-
+ #define SUBTYPE(socktype, stypename, id, idname) { SOCK_SUBTYPE_##id, #id, 0, #idname, ""},
static EnumPropertyItem subtype_items[] = {
- #include "rna_nodetree_types.h"
+ NODE_DEFINE_SUBTYPES
{0, NULL, 0, NULL, NULL}
};
+ #undef SUBTYPE
srna = RNA_def_struct(brna, name, "NodeSocket");
RNA_def_struct_ui_text(srna, ui_name, "Input or output socket of a node");
@@ -2703,93 +2695,71 @@
RNA_def_struct_ui_icon(srna, ICON_PLUG);
RNA_def_struct_path_func(srna, "rna_NodeSocket_path");
- RNA_def_struct_sdna_from(srna, "bNodeSocketValueFloat", "default_value");
-
- prop = RNA_def_property(srna, "subtype", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "subtype");
- RNA_def_property_enum_items(prop, subtype_items);
- RNA_def_property_ui_text(prop, "Subtype", "Subtype defining the socket value details");
- RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_NodeSocket_update");
-
- prop = RNA_def_property(srna, "default_value", PROP_FLOAT, subtype);
- RNA_def_property_float_sdna(prop, NULL, "value");
- RNA_def_property_float_funcs(prop, NULL, NULL, "rna_NodeSocketFloat_range");
- RNA_def_property_ui_text(prop, "Default Value", "");
- RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_NodeSocket_update");
+ switch (type) {
+ case SOCK_INT:
+ RNA_def_struct_sdna_from(srna, "bNodeSocketValueInt", "default_value");
+
+ prop = RNA_def_property(srna, "subtype", PROP_ENUM, PROP_NONE);
+ RNA_def_property_enum_sdna(prop, NULL, "subtype");
+ RNA_def_property_enum_items(prop, subtype_items);
+ RNA_def_property_ui_text(prop, "Subtype", "Subtype defining the socket value details");
+ RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_NodeSocket_update");
+
+ prop = RNA_def_property(srna, "default_value", PROP_INT, propsubtype);
+ RNA_def_property_int_sdna(prop, NULL, "value");
+ RNA_def_property_int_funcs(prop, NULL, NULL, "rna_NodeSocketInt_range");
+ RNA_def_property_ui_text(prop, "Default Value", "");
+ RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_NodeSocket_update");
+ break;
+ case SOCK_FLOAT:
+ RNA_def_struct_sdna_from(srna, "bNodeSocketValueFloat", "default_value");
+
+ prop = RNA_def_property(srna, "subtype", PROP_ENUM, PROP_NONE);
+ RNA_def_property_enum_sdna(prop, NULL, "subtype");
+ RNA_def_property_enum_items(prop, subtype_items);
+ RNA_def_property_ui_text(prop, "Subtype", "Subtype defining the socket value details");
+ RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_NodeSocket_update");
+
+ prop = RNA_def_property(srna, "default_value", PROP_FLOAT, propsubtype);
+ RNA_def_property_float_sdna(prop, NULL, "value");
+ RNA_def_property_float_funcs(prop, NULL, NULL, "rna_NodeSocketFloat_range");
+ RNA_def_property_ui_text(prop, "Default Value", "");
+ RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_NodeSocket_update");
+ break;
+ case SOCK_BOOLEAN:
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list