[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [36653] branches/particles-2010/source/ blender: Reimplemented the socket verification function.
Lukas Toenne
lukas.toenne at googlemail.com
Fri May 13 06:50:02 CEST 2011
Revision: 36653
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=36653
Author: lukastoenne
Date: 2011-05-13 04:50:01 +0000 (Fri, 13 May 2011)
Log Message:
-----------
Reimplemented the socket verification function. This is used to update old nodes whose socket template lists have changed.
It would be preferable if this was done by explicit do_versions code instead, but is needed for backwards compatibility for now.
The new version of this function also takes the SOCK_DYNAMIC flag into account.
Modified Paths:
--------------
branches/particles-2010/source/blender/blenloader/CMakeLists.txt
branches/particles-2010/source/blender/blenloader/SConscript
branches/particles-2010/source/blender/blenloader/intern/readfile.c
branches/particles-2010/source/blender/makesdna/DNA_node_types.h
branches/particles-2010/source/blender/nodes/NOD_socket.h
branches/particles-2010/source/blender/nodes/intern/node_socket.c
Modified: branches/particles-2010/source/blender/blenloader/CMakeLists.txt
===================================================================
--- branches/particles-2010/source/blender/blenloader/CMakeLists.txt 2011-05-13 04:04:53 UTC (rev 36652)
+++ branches/particles-2010/source/blender/blenloader/CMakeLists.txt 2011-05-13 04:50:01 UTC (rev 36653)
@@ -31,6 +31,7 @@
../makesdna
../readblenfile
../makesrna
+ ../nodes
../render/extern/include
../../../intern/guardedalloc
${ZLIB_INCLUDE_DIRS}
Modified: branches/particles-2010/source/blender/blenloader/SConscript
===================================================================
--- branches/particles-2010/source/blender/blenloader/SConscript 2011-05-13 04:04:53 UTC (rev 36652)
+++ branches/particles-2010/source/blender/blenloader/SConscript 2011-05-13 04:50:01 UTC (rev 36653)
@@ -5,7 +5,7 @@
incs = '. #/intern/guardedalloc ../blenlib ../blenkernel'
incs += ' ../makesdna ../readblenfile ../editors/include'
-incs += ' ../render/extern/include ../makesrna'
+incs += ' ../render/extern/include ../makesrna ../nodes'
incs += ' ' + env['BF_ZLIB_INC']
Modified: branches/particles-2010/source/blender/blenloader/intern/readfile.c
===================================================================
--- branches/particles-2010/source/blender/blenloader/intern/readfile.c 2011-05-13 04:04:53 UTC (rev 36652)
+++ branches/particles-2010/source/blender/blenloader/intern/readfile.c 2011-05-13 04:50:01 UTC (rev 36653)
@@ -132,6 +132,8 @@
#include "BKE_utildefines.h" // SWITCH_INT DATA ENDB DNA1 O_BINARY GLOB USER TEST REND
#include "BKE_sound.h"
+#include "NOD_socket.h"
+
//XXX #include "BIF_butspace.h" // badlevel, for do_versions, patching event codes
//XXX #include "BIF_filelist.h" // badlevel too, where to move this? - elubie
//XXX #include "BIF_previewrender.h" // bedlelvel, for struct RenderInfo
@@ -2047,7 +2049,13 @@
static void lib_nodetree_init_types_cb(void *UNUSED(data), ID *UNUSED(id), bNodeTree *ntree)
{
+ bNode *node;
+
ntreeInitTypes(ntree);
+
+ /* XXX could be replaced by do_versions for new nodes */
+ for (node=ntree->nodes.first; node; node=node->next)
+ node_verify_socket_templates(ntree, node);
}
/* updates group node socket own_index so that
Modified: branches/particles-2010/source/blender/makesdna/DNA_node_types.h
===================================================================
--- branches/particles-2010/source/blender/makesdna/DNA_node_types.h 2011-05-13 04:04:53 UTC (rev 36652)
+++ branches/particles-2010/source/blender/makesdna/DNA_node_types.h 2011-05-13 04:50:01 UTC (rev 36653)
@@ -275,8 +275,6 @@
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;
Modified: branches/particles-2010/source/blender/nodes/NOD_socket.h
===================================================================
--- branches/particles-2010/source/blender/nodes/NOD_socket.h 2011-05-13 04:04:53 UTC (rev 36652)
+++ branches/particles-2010/source/blender/nodes/NOD_socket.h 2011-05-13 04:50:01 UTC (rev 36653)
@@ -64,6 +64,7 @@
struct bNodeSocket *node_add_input_from_template(struct bNodeTree *ntree, struct bNode *node, struct bNodeSocketTemplate *stemp);
struct bNodeSocket *node_add_output_from_template(struct bNodeTree *ntree, struct bNode *node, struct bNodeSocketTemplate *stemp);
+void node_verify_socket_templates(struct bNodeTree *ntree, struct bNode *node);
/* Socket Converters */
Modified: branches/particles-2010/source/blender/nodes/intern/node_socket.c
===================================================================
--- branches/particles-2010/source/blender/nodes/intern/node_socket.c 2011-05-13 04:04:53 UTC (rev 36652)
+++ branches/particles-2010/source/blender/nodes/intern/node_socket.c 2011-05-13 04:50:01 UTC (rev 36653)
@@ -302,3 +302,110 @@
return sock;
}
+static bNodeSocket *verify_socket_template(bNodeTree *ntree, bNode *node, int in_out, ListBase *socklist, bNodeSocketTemplate *stemp)
+{
+ bNodeSocket *sock;
+
+ for(sock= socklist->first; sock; sock= sock->next) {
+ if(!(sock->flag & SOCK_DYNAMIC) && strncmp(sock->name, stemp->name, NODE_MAXSTR)==0)
+ break;
+ }
+ if(sock) {
+ sock->type= stemp->type; /* in future, read this from tydefs! */
+ if(stemp->limit==0) sock->limit= 0xFFF;
+ else sock->limit= stemp->limit;
+
+ /* Copy the property range and subtype parameters in case the template changed.
+ * NOT copying the actual value here, only button behavior changes!
+ */
+ switch (sock->type) {
+ case SOCK_FLOAT:
+ {
+ bNodeSocketValueFloat *dval= sock->default_value;
+ dval->min = stemp->min;
+ dval->max = stemp->max;
+ dval->subtype = stemp->subtype;
+ }
+ break;
+ case SOCK_INT:
+ {
+ bNodeSocketValueInt *dval= sock->default_value;
+ dval->min = stemp->min;
+ dval->max = stemp->max;
+ dval->subtype = stemp->subtype;
+ }
+ break;
+ case SOCK_VECTOR:
+ {
+ bNodeSocketValueVector *dval= sock->default_value;
+ dval->min = stemp->min;
+ dval->max = stemp->max;
+ dval->subtype = stemp->subtype;
+ }
+ break;
+ }
+
+ BLI_remlink(socklist, sock);
+
+ return sock;
+ }
+ else {
+ /* no socket for this template found, make a new one */
+ if (in_out==SOCK_IN)
+ sock = node_add_input_from_template(ntree, node, stemp);
+ else
+ sock = node_add_output_from_template(ntree, node, stemp);
+ /* remove the new socket from the node socket list first,
+ * will be added back after verification.
+ */
+ BLI_remlink(socklist, sock);
+ }
+
+ return sock;
+}
+
+static void verify_socket_template_list(bNodeTree *ntree, bNode *node, int in_out, ListBase *socklist, bNodeSocketTemplate *stemp_first)
+{
+ bNodeSocket *sock;
+ bNodeSocketTemplate *stemp;
+
+ /* no inputs anymore? */
+ if(stemp_first==NULL) {
+ while(socklist->first) {
+ sock = (bNodeSocket*)socklist->first;
+ if (!(sock->flag & SOCK_DYNAMIC))
+ nodeRemoveSocket(ntree, node, socklist->first);
+ }
+ }
+ else {
+ /* step by step compare */
+ stemp= stemp_first;
+ while(stemp->type != -1) {
+ stemp->sock= verify_socket_template(ntree, node, in_out, socklist, stemp);
+ stemp++;
+ }
+ /* leftovers are removed */
+ while(socklist->first) {
+ sock = (bNodeSocket*)socklist->first;
+ if (!(sock->flag & SOCK_DYNAMIC))
+ nodeRemoveSocket(ntree, node, socklist->first);
+ }
+
+ /* and we put back the verified sockets */
+ stemp= stemp_first;
+ while(stemp->type != -1) {
+ /* put static sockets infront of dynamic */
+ BLI_addhead(socklist, stemp->sock);
+ stemp++;
+ }
+ }
+}
+
+void node_verify_socket_templates(bNodeTree *ntree, bNode *node)
+{
+ bNodeType *ntype= node->typeinfo;
+ if(ntype) {
+ verify_socket_template_list(ntree, node, SOCK_IN, &node->inputs, ntype->inputs);
+ verify_socket_template_list(ntree, node, SOCK_OUT, &node->outputs, ntype->outputs);
+ }
+}
More information about the Bf-blender-cvs
mailing list