[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [31888] branches/particles-2010/source/ blender: reenabled updating procedure, using another callback for customized tree type updates other than sorting nodes and validating links (only simulation trees currently, which resolve adaptable socket types).

Lukas Toenne lukas.toenne at googlemail.com
Sun Sep 12 13:55:51 CEST 2010


Revision: 31888
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=31888
Author:   lukastoenne
Date:     2010-09-12 13:55:51 +0200 (Sun, 12 Sep 2010)

Log Message:
-----------
reenabled updating procedure, using another callback for customized tree type updates other than sorting nodes and validating links (only simulation trees currently, which resolve adaptable socket types).

Modified Paths:
--------------
    branches/particles-2010/source/blender/blenkernel/BKE_node.h
    branches/particles-2010/source/blender/blenkernel/intern/node.c
    branches/particles-2010/source/blender/nodes/intern/composite/node_tree_composite.c
    branches/particles-2010/source/blender/nodes/intern/shader/node_tree_shader.c
    branches/particles-2010/source/blender/nodes/intern/simulation/node_tree_simulation.c
    branches/particles-2010/source/blender/nodes/intern/texture/node_tree_texture.c

Modified: branches/particles-2010/source/blender/blenkernel/BKE_node.h
===================================================================
--- branches/particles-2010/source/blender/blenkernel/BKE_node.h	2010-09-12 10:51:54 UTC (rev 31887)
+++ branches/particles-2010/source/blender/blenkernel/BKE_node.h	2010-09-12 11:55:51 UTC (rev 31888)
@@ -173,6 +173,8 @@
 	void (*endExec)(struct bNodeTree *ntree, void *execdata);
 	void (*exec)(struct bNodeTree *ntree, void *execdata, void *callerdata, int thread);
 
+	/* general update function */
+	void (*update)(struct bNodeTree *ntree);
 	/* 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);
@@ -203,13 +205,8 @@
 void			ntreeUpdateGroupTree(struct bNodeTree *ntree, struct bNodeTree *group);
 void			ntreeUpdateFullTree(struct bNodeTree *ntree);
 
-//void			ntreeCalcSocketTypeIslands(struct bNodeTree *ntree);
-//void			ntreeFreeSocketTypeIslands(struct bNodeTree *ntree);
-//void			ntreeFindIslandSocketType(struct bNodeTree *ntree, int island, int *restype, int *resolved);
-//void			ntreeResolveSocketTypes(struct bNodeTree *ntree);
-//void			ntreeResolveSocketContexts(struct bNodeTree *ntree);
-//void			ntreeResolveInputContexts(struct bNode *node);
-//void			ntreeResolveOutputContexts(struct bNode *node);
+void			ntreeSolveNodeOrder(struct bNodeTree *ntree);
+void			ntreeValidateLinks(struct bNodeTree *ntree);
 
 void			ntreeBeginExecTree(struct bNodeTree *ntree);
 void			ntreeExecTree(struct bNodeTree *ntree, void *callerdata, int thread);

Modified: branches/particles-2010/source/blender/blenkernel/intern/node.c
===================================================================
--- branches/particles-2010/source/blender/blenkernel/intern/node.c	2010-09-12 10:51:54 UTC (rev 31887)
+++ branches/particles-2010/source/blender/blenkernel/intern/node.c	2010-09-12 11:55:51 UTC (rev 31888)
@@ -1583,7 +1583,7 @@
 	return level;
 }
 
-static void solve_node_order(bNodeTree *ntree)
+void ntreeSolveNodeOrder(bNodeTree *ntree)
 {
 	bNode *node, **nodesort, **nsort;
 	bNodeSocket *sock;
@@ -1658,312 +1658,8 @@
 	}
 }
 
-#if 0
-static void merge_socket_islands(bNodeSocketIsland *islands, int a, int b)
+void ntreeValidateLinks(bNodeTree *ntree)
 {
-	bNodeSocketIsland *i;
-	
-	if (a == b)
-		return;
-	if (a < b) {
-		/* merge island b into a */
-		for (i = islands + a; i->next; i = i->next);
-		i->next = islands + b;
-		islands[b].prev = i;
-		
-		for (i = islands + b; i; i = i->next)
-			i->sock->island = a;
-	}
-	else {
-		/* merge island a into b */
-		for (i = islands + b; i->next; i = i->next);
-		i->next = islands + a;
-		islands[a].prev = i;
-		
-		for (i = islands + a; i; i = i->next)
-			i->sock->island = b;
-	}
-}
-
-static void merge_node_type_islands(bNode *node, bNodeSocketIsland *islands)
-{
-	bNodeSocket *sock, *msock;
-	if (node->type == NODE_GROUP) {
-		if (node->id) {
-			/* TODO this way of merging islands by internal groups is O(n^2),
-			 * where n is the total number of sockets of the group node (inputs+outputs).
-			 * Should not be a problem as this number will probably not be very large,
-			 * otherwise a more elaborate method must be found (using sorting).
-			 */
-			int cur_island = -1;
-			int internal_island;
-			for (sock=node->inputs.first; sock; sock = sock->next) {
-				if (sock->tosock && sock->island > cur_island) {
-					cur_island = sock->island;
-					internal_island = sock->tosock->island;
-					/* merge this socket with all remaining sockets whose internal island matches */
-					for (msock=sock->next; msock; msock = msock->next)
-						if (msock->tosock && msock->tosock->island == internal_island)
-							merge_socket_islands(islands, cur_island, msock->island);
-					for (msock=node->outputs.first; msock; msock = msock->next)
-						if (msock->tosock && msock->tosock->island == internal_island)
-							merge_socket_islands(islands, cur_island, msock->island);
-				}
-			}
-			for (sock=node->outputs.first; sock; sock = sock->next) {
-				if (sock->tosock && sock->island > cur_island) {
-					cur_island = sock->island;
-					internal_island = sock->tosock->island;
-					/* merge this socket with all remaining sockets whose internal island matches */
-					for (msock=sock->next; msock; msock = msock->next)
-						if (msock->tosock && msock->tosock->island == internal_island)
-							merge_socket_islands(islands, cur_island, msock->island);
-				}
-			}
-		}
-	}
-	else {
-		/* TODO This procedure merges all sockets of ANY type to the same island.
-		 * Is there any situation where this model is insufficient?
-		 */
-		int any_island = -1;
-		for (sock=node->inputs.first; sock; sock = sock->next) {
-			if ((sock->flag & SOCK_ADAPT_TYPE)!=0) {
-				if (any_island >= 0)
-					merge_socket_islands(islands, any_island, sock->island);
-				any_island = sock->island;
-			}
-		}
-		for (sock=node->outputs.first; sock; sock = sock->next) {
-			if ((sock->flag & SOCK_ADAPT_TYPE)!=0) {
-				if (any_island >= 0)
-					merge_socket_islands(islands, any_island, sock->island);
-				any_island = sock->island;
-			}
-		}
-	}
-}
-
-static int link_merge_type(bNodeLink *link)
-{
-	return ((link->fromsock->flag & SOCK_ADAPT_TYPE)!=0 || (link->tosock->flag & SOCK_ADAPT_TYPE)!=0);
-}
-
-void ntreeCalcSocketTypeIslands(bNodeTree *ntree)
-{
-	bNode *node;
-	bNodeSocket *sock;
-	bNodeLink *link;
-	int totsock;
-	bNodeSocketIsland *cur;
-	
-	/* calculate nested groups */
-	for (node=ntree->nodes.first; node; node = node->next)
-		if (node->type == NODE_GROUP && node->id && ((bNodeTree*)node->id)->islands == NULL)
-			ntreeCalcSocketTypeIslands((bNodeTree*)node->id);
-			
-	/* initialise island indices */
-	totsock = 0;
-	for (node=ntree->nodes.first; node; node = node->next) {
-		for (sock=node->inputs.first; sock; sock = sock->next)
-			sock->island = totsock++;
-		for (sock=node->outputs.first; sock; sock = sock->next)
-			sock->island = totsock++;
-	}
-	
-	/* create the island pointer array */
-	cur = ntree->islands = MEM_callocN((totsock+1) * sizeof(bNodeSocketIsland), "bNodeSocketIsland");
-	for (node=ntree->nodes.first; node; node = node->next) {
-		for (sock=node->inputs.first; sock; sock = sock->next) {
-			cur->sock = sock;
-			cur->node = node;
-			cur->next = cur->prev = NULL;
-			cur->is_output = 0;
-			++cur;
-		}
-		for (sock=node->outputs.first; sock; sock = sock->next) {
-			cur->sock = sock;
-			cur->node = node;
-			cur->next = cur->prev = NULL;
-			cur->is_output = 1;
-			++cur;
-		}
-	}
-	/* marks the end of the island list */
-	cur->sock = NULL;
-	cur->node = NULL;
-	cur->next = cur->prev = NULL;
-	
-	/* merge islands inside nodes */
-	for (node=ntree->nodes.first; node; node = node->next) {
-		merge_node_type_islands(node, ntree->islands);
-	}
-	/* merge islands by links */
-	for (link=ntree->links.first; link; link = link->next) {
-		if (link->fromsock && link->tosock)
-			if (link_merge_type(link))
-				merge_socket_islands(ntree->islands, link->fromsock->island, link->tosock->island);
-	}
-}
-
-void ntreeFreeSocketTypeIslands(bNodeTree *ntree)
-{
-	bNode *node;
-	
-	/* free islands in groups */
-	for (node=ntree->nodes.first; node; node = node->next)
-		if (node->type == NODE_GROUP && node->id)
-			ntreeFreeSocketTypeIslands((bNodeTree*)node->id);
-	
-	if (ntree->islands != NULL) {
-		MEM_freeN(ntree->islands);
-		ntree->islands = NULL;
-	}
-}
-
-void ntreeFindIslandSocketType(bNodeTree *ntree, int island, int *restype, int *resolved)
-{
-	bNodeTreeTypeInfo *tti;
-	bNodeSocketIsland *cur;
-	
-	tti = ntreeGetTypeInfo(ntree->type);
-	if (!tti->preferredSocketType || !tti->compatibleSocketTypes)
-		return;
-	
-	for (cur = ntree->islands + island; cur; cur = cur->next) {
-		if (cur->node->type == NODE_GROUP) {
-			if (cur->node->id && cur->sock->tosock)
-				ntreeFindIslandSocketType((bNodeTree*)cur->node->id, cur->sock->tosock->island, restype, resolved);
-		}
-		else {
-			if (!(*resolved)) {
-				*restype = cur->sock->type;
-				*resolved = ((cur->sock->flag & SOCK_ADAPT_TYPE) == 0);
-			}
-			else {
-				/* restype == SOCK_ANY means the island contains incompatible types and cannot be resolved! */
-				if (*restype != SOCK_ANY && (cur->sock->flag & SOCK_ADAPT_TYPE) == 0) {
-					if (tti->compatibleSocketTypes(*restype, cur->sock->type))
-						*restype = tti->preferredSocketType(*restype, cur->sock->type);
-					else
-						*restype = SOCK_ANY;
-				}
-			}
-		}
-	}
-}
-
-void ntreeResolveSocketTypes(bNodeTree *ntree)
-{
-	bNodeSocketIsland *cur, *res;
-	int restype, resolved, island;
-	
-	island = -1;
-	for (cur = ntree->islands; cur->sock; ++cur) {
-		if (cur->sock->island > island) {
-			island = cur->sock->island;
-			resolved = 0;
-			restype = SOCK_ANY;
-			
-			ntreeFindIslandSocketType(ntree, island, &restype, &resolved);
-			
-			for (res = cur; res; res = res->next)
-				if ((res->sock->flag & SOCK_ADAPT_TYPE)!=0)
-					res->sock->type = restype;
-		}
-	}
-}
-
-void ntreeResolveInputContexts(bNode *node)
-{
-	bNodeSocket *sock;
-	
-	/* first get input contexts from links */
-	for (sock=node->inputs.first; sock; sock=sock->next) {
-		if ((sock->flag & SOCK_ADAPT_CONTEXT)!=0) {
-			/* propagate context along link (fromnode is fully resolved) */
-			if (sock->link && sock->link->fromsock) {
-				sock->contexttype = sock->link->fromsock->contexttype;
-			}
-			else if (sock->intern) {
-				/* socket uses default singleton data */
-				sock->contexttype = NULL;
-			}
-		}
-	}
-
-	if (node->type == NODE_GROUP) {
-		for (sock=node->inputs.first; sock; sock=sock->next)
-			if (sock->tosock && (sock->flag & SOCK_ADAPT_CONTEXT)!=0)
-				sock->tosock->contexttype = sock->contexttype;
-	}
-}
-
-void ntreeResolveOutputContexts(bNode *node)
-{
-	bNodeSocket *sock;
-	
-	if (node->type == NODE_GROUP) {
-		/* internal nodes may be unresolvable and have reset the context, so we copy it back to the inputs */
-		for (sock=node->inputs.first; sock; sock=sock->next)
-			if (sock->tosock && (sock->flag & SOCK_ADAPT_CONTEXT)!=0)
-				sock->contexttype = sock->tosock->contexttype;
-		for (sock=node->outputs.first; sock; sock=sock->next)
-			if (sock->tosock && (sock->flag & SOCK_ADAPT_CONTEXT)!=0)
-				sock->contexttype = sock->tosock->contexttype;
-	}
-	else {
-		StructRNA *res= NULL;
-		for (sock=node->inputs.first; sock; sock=sock->next) {
-			if ((sock->flag & SOCK_ADAPT_CONTEXT)!=0) {
-				if (res == NULL) {

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list