[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [32918] branches/particles-2010/source/ blender: Improved the socket type adaptation method.

Lukas Toenne lukas.toenne at googlemail.com
Sun Nov 7 15:44:57 CET 2010


Revision: 32918
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=32918
Author:   lukastoenne
Date:     2010-11-07 15:44:57 +0100 (Sun, 07 Nov 2010)

Log Message:
-----------
Improved the socket type adaptation method. Instead of building (arrayed) lists of "islands" of sockets adapting to the same type, the types of adaptable sockets are now resolved step-wise. The nodes in a tree are iterated over back and forth, resolving types until no more adaptations are possible. This allows more flexible setups, where nodes can resolve to only some types (math nodes) and more. It also avoids the somewhat meaningless "islands" pointer in the tree struct.

Modified Paths:
--------------
    branches/particles-2010/source/blender/blenkernel/BKE_node.h
    branches/particles-2010/source/blender/blenkernel/CMakeLists.txt
    branches/particles-2010/source/blender/blenkernel/intern/node.c
    branches/particles-2010/source/blender/makesdna/DNA_node_types.h
    branches/particles-2010/source/blender/nodes/intern/SIM_intern.c
    branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_add_particle.c
    branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_for.c
    branches/particles-2010/source/blender/nodes/intern/SIM_nodetree.c
    branches/particles-2010/source/blender/nodes/intern/SIM_util.h

Modified: branches/particles-2010/source/blender/blenkernel/BKE_node.h
===================================================================
--- branches/particles-2010/source/blender/blenkernel/BKE_node.h	2010-11-07 12:15:21 UTC (rev 32917)
+++ branches/particles-2010/source/blender/blenkernel/BKE_node.h	2010-11-07 14:44:57 UTC (rev 32918)
@@ -120,6 +120,7 @@
 
 	/* called when the node is updated (e.g. linked) in the editor. */
 	void (*updatefunc)(struct bNodeTree *ntree, struct bNode *node);
+	void (*adaptSocketTypes)(struct bNodeTree *ntree, struct bNode *node);
 
 	char socketstoragename[64];		/* socket storage struct name for DNA */
 	void (*initsocketfunc)(struct bNodeSocket *sock);
@@ -187,9 +188,7 @@
 	/* called when a node is updated (e.g. linked) in the editor.
 	 * individual node update calls should be made internally if this function is defined! */
 	void (*updateNode)(struct bNodeTree *ntree, struct bNode *node);
-
-	int (*compatibleSocketTypes)(int type_a, int type_b);
-	int (*preferredSocketType)(int type_a, int type_b);
+	int (*verifyLink)(struct bNodeTree *ntree, struct bNodeLink *link);
 } bNodeTreeTypeInfo;
 
 /* ************** GENERIC API, TREES *************** */

Modified: branches/particles-2010/source/blender/blenkernel/CMakeLists.txt
===================================================================
--- branches/particles-2010/source/blender/blenkernel/CMakeLists.txt	2010-11-07 12:15:21 UTC (rev 32917)
+++ branches/particles-2010/source/blender/blenkernel/CMakeLists.txt	2010-11-07 14:44:57 UTC (rev 32918)
@@ -110,6 +110,7 @@
 	intern/nla.c
 	intern/node.c
 	intern/object.c
+	intern/opencl.c
 	intern/packedFile.c
 	intern/paint.c
 	intern/particle.c

Modified: branches/particles-2010/source/blender/blenkernel/intern/node.c
===================================================================
--- branches/particles-2010/source/blender/blenkernel/intern/node.c	2010-11-07 12:15:21 UTC (rev 32917)
+++ branches/particles-2010/source/blender/blenkernel/intern/node.c	2010-11-07 14:44:57 UTC (rev 32918)
@@ -558,12 +558,15 @@
 	 * i.e. when no sockets exist yet!
 	 */
 	if (ntree != NULL) {
-		for (gsock= group->inputs.first; gsock; gsock = gsock->next) {
+		bNodeSocket *nextgsock;
+		for (gsock= group->inputs.first; gsock; gsock = nextgsock) {
+			nextgsock = gsock->next;
 			if (gsock->tonode == NULL) {
 				nodeRemoveInputSocket(ntree, group, gsock);
 			}
 		}
-		for (gsock= group->outputs.first; gsock; gsock = gsock->next) {
+		for (gsock= group->outputs.first; gsock; gsock = nextgsock) {
+			nextgsock = gsock->next;
 			if (gsock->tonode == NULL) {
 				nodeRemoveOutputSocket(ntree, group, gsock);
 			}
@@ -1086,12 +1089,27 @@
 {
 	bNode *nnode= MEM_callocN(sizeof(bNode), "dupli node");
 	bNodeSocket *sock, *oldsock;
+	bNodeSocketPanel *panel, *oldpanel;
 
 	*nnode= *node;
 	nodeUniqueName(ntree, nnode);
 	
 	BLI_addtail(&ntree->nodes, nnode);
+
+	BLI_duplicatelist(&nnode->inpanels, &node->inpanels);
+	for(panel= nnode->inpanels.first, oldpanel= node->inpanels.first; panel; panel= panel->next, oldpanel= oldpanel->next) {
+		oldpanel->new_panel= panel;
+		if (panel->storage)
+			oldpanel->storage = MEM_dupallocN(panel->storage);
+	}
 	
+	BLI_duplicatelist(&nnode->outpanels, &node->outpanels);
+	for(panel= nnode->outpanels.first, oldpanel= node->outpanels.first; panel; panel= panel->next, oldpanel= oldpanel->next) {
+		oldpanel->new_panel= panel;
+		if (panel->storage)
+			oldpanel->storage = MEM_dupallocN(panel->storage);
+	}
+
 	BLI_duplicatelist(&nnode->inputs, &node->inputs);
 	oldsock= node->inputs.first;
 	for(sock= nnode->inputs.first; sock; sock= sock->next, oldsock= oldsock->next) {
@@ -1103,6 +1121,9 @@
 		
 		if (node->typeinfo->copysocketstoragefunc)
 			node->typeinfo->copysocketstoragefunc(oldsock, sock);
+		
+		if (sock->panel)
+			sock->panel = sock->panel->new_panel;
 	}
 	
 	BLI_duplicatelist(&nnode->outputs, &node->outputs);
@@ -1114,6 +1135,9 @@
 		
 		if (node->typeinfo->copysocketstoragefunc)
 			node->typeinfo->copysocketstoragefunc(oldsock, sock);
+		
+		if (sock->panel)
+			sock->panel = sock->panel->new_panel;
 	}
 	
 	/* don't increase node->id users, freenode doesn't decrement either */
@@ -1482,8 +1506,6 @@
 	}
 	
 	if (ntree->type == NTREE_SIMULATION) {
-		if (ntree->islands)
-			MEM_freeN(ntree->islands);
 		ntreeSimulationReleaseProgram(ntree);
 	}
 }
@@ -1894,41 +1916,18 @@
 	bNodeTreeTypeInfo *tti = ntreeGetTypeInfo(ntree->type);
 	bNodeLink *link;
 	
-	if (tti->compatibleSocketTypes) {
-		for (link = ntree->links.first; link; link = link->next) {
-			int valid = 1;
-			if (link->fromsock == NULL || link->tosock == NULL) {
-				/* don't assume bad links when they're incomplete (e.g. in modal operator) */
-				valid = 1;
-			}
-			else {
-				valid = tti->compatibleSocketTypes(link->fromsock->type, link->tosock->type);
-				
-				/* would be nice to have at least a partial context check,
-				 * but this can not distinguish collections from singletons.
-				 * (S->S or S->C would still be valid!)
-				 */
-				#if 0
-				if (valid) {
-					StructRNA *fromctx = link->fromsock->contexttype;
-					StructRNA *toctx = link->tosock->contexttype;
-					if (fromctx && (toctx == NULL || !RNA_struct_is_a(fromctx, toctx))) {
-							valid =0;
-					}
-				}
-				#endif
-			}
-			
-			if (valid)
-				link->flag |= NLINK_VALID;
-			else
+	for (link = ntree->links.first; link; link = link->next) {
+		link->flag |= NLINK_VALID;
+		/* skip incomplete links (from modal linking operator) */
+		if (link->fromsock && link->tosock) {
+			if (link->fromnode->level <= link->tonode->level)
 				link->flag &= ~NLINK_VALID;
+			else if (tti->verifyLink) {
+				if (!tti->verifyLink(ntree, link))
+					link->flag &= ~NLINK_VALID;
+			}
 		}
 	}
-	else {
-		for (link = ntree->links.first; link; link = link->next)
-			link->flag |= NLINK_VALID;
-	}
 }
 
 

Modified: branches/particles-2010/source/blender/makesdna/DNA_node_types.h
===================================================================
--- branches/particles-2010/source/blender/makesdna/DNA_node_types.h	2010-11-07 12:15:21 UTC (rev 32917)
+++ branches/particles-2010/source/blender/makesdna/DNA_node_types.h	2010-11-07 14:44:57 UTC (rev 32918)
@@ -69,7 +69,7 @@
 #define NS_OSA_VALUES		2
 
 typedef struct bNodeSocketPanel {
-	struct bNodeSocketPanel *next, *prev;
+	struct bNodeSocketPanel *next, *prev, *new_panel;
 	char name[64];
 	short collapsed;
 	char pad[6];
@@ -97,16 +97,14 @@
 	
 	/* execution data */
 	short need_exec;
-	short pad;
 	
+	short resolved;				/* adaptable socket type has been resolved */
+	
 	void *storage;				/* custom storage */
 	
 	/* internal data to retrieve relations and groups */
 	int own_index, to_index;	/* group socket identifiers, to find matching pairs after reading files */
 	
-	int island;					/* used during island calculation, for finding shared socket groups */
-	int pad2;
-	
 	/* group-node sockets point to the internal group counterpart sockets, set after read file  */
 	struct bNode *tonode;
 	struct bNodeSocket *tosock;	
@@ -157,6 +155,9 @@
 	short lasty, menunr;	/* lasty: check preview render status, menunr: browse ID blocks */
 	short stack_index;		/* for groupnode, offset in global caller stack */
 	short nr;				/* number of this node in list, used for UI exec events */
+	short updated;			/* non-persistent update flag, used in type adaptation */
+	short pad1;
+	int pad2;
 	
 	ListBase inputs, outputs;
 	ListBase inpanels, outpanels;
@@ -206,9 +207,6 @@
 
 #define NLINK_VALID			1
 
-/* used during calculation of socket type islands */
-struct bNodeSocketIsland;
-
 /* the basis for a Node tree, all links and nodes reside internal here */
 /* only re-usable node trees are in the library though, materials and textures allocate own tree struct */
 typedef struct bNodeTree {
@@ -228,7 +226,6 @@
 	
 	/* TODO move this to a separate storage struct to keep the tree free of type-dependent stuff? */
 	/* simulation trees */
-	struct bNodeSocketIsland *islands;	/* used during calculation of socket type islands */
 	void *program;						/* OpenCL compiled program (in case it's available and activated) */
 	
 	/* execution data */

Modified: branches/particles-2010/source/blender/nodes/intern/SIM_intern.c
===================================================================
--- branches/particles-2010/source/blender/nodes/intern/SIM_intern.c	2010-11-07 12:15:21 UTC (rev 32917)
+++ branches/particles-2010/source/blender/nodes/intern/SIM_intern.c	2010-11-07 14:44:57 UTC (rev 32918)
@@ -45,7 +45,7 @@
 
 #include "RNA_access.h"
 
-void sim_init_socket_buffer(SimExecData *UNUSED(execdata), SimSocketStack *sock)
+void sim_init_socket_buffer(SimExecData *execdata, SimSocketStack *sock)
 {
 #ifdef WITH_OPENCL
 	if (BKE_opencl_is_active()) {
@@ -189,7 +189,7 @@
 	MEM_freeN(job);
 }
 
-void sim_finish_job(SimExecData *UNUSED(execdata), SimJob *job)
+void sim_finish_job(SimExecData *execdata, SimJob *job)
 {
 	job->event->status = SIM_COMPLETE;
 	for (job=job->next; job; job = job->next) {

Modified: branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_add_particle.c
===================================================================
--- branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_add_particle.c	2010-11-07 12:15:21 UTC (rev 32917)
+++ branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_add_particle.c	2010-11-07 14:44:57 UTC (rev 32918)
@@ -47,7 +47,7 @@
 	{ -1, 0, "" }
 };
 
-static void enqueue_op(SimExecData *UNUSED(execdata), SimNodeStack *UNUSED(node), SimDataContext *self, int execlevel, int *pushop)
+static void enqueue_op(SimExecData *execdata, SimNodeStack *node, SimDataContext *self, int execlevel, int *pushop)
 {
 	if (execlevel == 0) {
 		ID *id= sim_context_id(self);

Modified: branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_for.c
===================================================================
--- branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_for.c	2010-11-07 12:15:21 UTC (rev 32917)
+++ branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_for.c	2010-11-07 14:44:57 UTC (rev 32918)
@@ -41,7 +41,7 @@
 	{ -1, 0, "" }
 };
 
-static void enqueue_op(SimExecData *execdata, SimNodeStack *node, SimDataContext *UNUSED(self), int execlevel, int *pushop)
+static void enqueue_op(SimExecData *execdata, SimNodeStack *node, SimDataContext *self, int execlevel, int *pushop)
 {
 	int iterations;

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list