[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [33234] branches/particles-2010/source/ blender/nodes/intern: Fixed group node indexing for stack generation.

Lukas Toenne lukas.toenne at googlemail.com
Mon Nov 22 16:15:51 CET 2010


Revision: 33234
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=33234
Author:   lukastoenne
Date:     2010-11-22 16:15:51 +0100 (Mon, 22 Nov 2010)

Log Message:
-----------
Fixed group node indexing for stack generation.
"For" node now stores the iteration number at first call.

Modified Paths:
--------------
    branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_for.c
    branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_program.c
    branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_subprogram.c
    branches/particles-2010/source/blender/nodes/intern/SIM_nodetree.c
    branches/particles-2010/source/blender/nodes/intern/SIM_util.c
    branches/particles-2010/source/blender/nodes/intern/SIM_util.h

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-22 14:16:11 UTC (rev 33233)
+++ branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_for.c	2010-11-22 15:15:51 UTC (rev 33234)
@@ -41,17 +41,27 @@
 	{ -1, 0, "" }
 };
 
+typedef struct OpStorage {
+	int iterations;
+} OpStorage;
+
 static void enqueue_op(SimExecData *execdata, SimNodeStack *node, SimDataContext *self, int execlevel, int *pushop)
 {
-	int iterations;
+	OpStorage *storage;
 	SimSocketIterator sockiter;
 	
-	sim_input_begin(execdata, node->instack[0], &sockiter);
-	sim_input_read_int(execdata, &sockiter, &iterations);
-	sim_input_end(execdata, &sockiter);
-	if (execdata->error) return;
+	if (execlevel == 0) {
+		node->opstorage = storage = MEM_callocN(sizeof(OpStorage), "NodeOperatorStorage");
+		
+		sim_input_begin(execdata, node->instack[0], &sockiter);
+		sim_input_read_int(execdata, &sockiter, &storage->iterations);
+		sim_input_end(execdata, &sockiter);
+		if (execdata->error) return;
+	}
+	else
+		storage = (OpStorage*)node->opstorage;
 	
-	if (execlevel < iterations)
+	if (execlevel < storage->iterations)
 		*pushop = 1;
 }
 

Modified: branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_program.c
===================================================================
--- branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_program.c	2010-11-22 14:16:11 UTC (rev 33233)
+++ branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_program.c	2010-11-22 15:15:51 UTC (rev 33234)
@@ -62,7 +62,7 @@
 	
 	for (i=0; i < node->totin; ++i) {
 		/* skip default values */
-		if (node->instack[i]->node == node)
+		if (sim_socket_is_linked(node, &node->instack[i]))
 			continue;
 		
 		if (op == execlevel) {

Modified: branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_subprogram.c
===================================================================
--- branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_subprogram.c	2010-11-22 14:16:11 UTC (rev 33233)
+++ branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_subprogram.c	2010-11-22 15:15:51 UTC (rev 33234)
@@ -65,7 +65,7 @@
 	
 	for (i=0; i < node->totin; ++i) {
 		/* skip default values */
-		if (node->instack[i]->node == node)
+		if (sim_socket_is_linked(node, &node->instack[i]))
 			continue;
 		
 		if (op == execlevel) {

Modified: branches/particles-2010/source/blender/nodes/intern/SIM_nodetree.c
===================================================================
--- branches/particles-2010/source/blender/nodes/intern/SIM_nodetree.c	2010-11-22 14:16:11 UTC (rev 33233)
+++ branches/particles-2010/source/blender/nodes/intern/SIM_nodetree.c	2010-11-22 15:15:51 UTC (rev 33234)
@@ -536,31 +536,93 @@
 
 #endif
 
-#if 0
-static void print_stack_recursive(bNodeTree *ntree, int indent)
+#if 1
+static void print_tree_recursive(bNodeTree *ntree, int indent)
 {
 	bNode *node;
 	bNodeSocket *sock;
 	int i;
+	char indentstr[64];
 	
-	for (i=0; i < indent; ++i) printf(" ");
-	printf("NodeTree %s:\n", ntree->id.name);
+	indentstr[0] = '\0';
+	for (i=0; i < indent; ++i)
+		sprintf(indentstr, "    ");
+	
+	printf("%sNodeTree %s:\n", indentstr, ntree->id.name);
 	for (node=ntree->nodes.first; node; node = node->next) {
-		for (i=0; i < indent; ++i) printf(" ");
-		printf("  Node %s: stack_index=%d\n", node->name, node->stack_index);
+		printf("%s|-Node %s: stack_index=%d\n", indentstr, node->name, node->stack_index);
 		for (sock=node->inputs.first; sock; sock = sock->next) {
-			for (i=0; i < indent; ++i) printf(" ");
-			printf("    Input %s: stack_index=%d, stack_index_ext=%d\n", sock->name, sock->stack_index, sock->stack_index_ext);
+			printf("%s|   Input %s", indentstr, sock->name);
+			if (sock->link)
+				printf(" (-> %s:%s)", sock->link->fromnode->name, sock->link->fromsock->name);
+			printf(": stack_index=%d, stack_index_ext=%d\n", sock->stack_index, sock->stack_index_ext);
 		}
 		for (sock=node->outputs.first; sock; sock = sock->next) {
-			for (i=0; i < indent; ++i) printf(" ");
-			printf("    Output %s: stack_index=%d, stack_index_ext=%d\n", sock->name, sock->stack_index, sock->stack_index_ext);
+			printf("%s|   Output %s: stack_index=%d, stack_index_ext=%d\n", indentstr, sock->name, sock->stack_index, sock->stack_index_ext);
 		}
 		
 		if (node->type == NODE_GROUP && node->id)
-			print_stack_recursive((bNodeTree*)node->id, indent + 4);
+			print_tree_recursive((bNodeTree*)node->id, indent + 4);
 	}
+	printf("\n");
+	
 }
+
+static void print_nodestack(SimExecData *execdata) {
+	bNodeSocket *sock;
+	SimNodeStack *ns;
+	SimSocketStack **in, *out;
+	int i, n;
+	
+	printf("=== Output Stack ===\n");
+	for (i=0, out=execdata->outstack; i < execdata->totout; ++i, ++out) {
+		printf("%d. ", i);
+		if (out->node && out->node->base)
+			printf("%s", out->node->base->name);
+		else
+			printf("---");
+		if (out->base)
+			printf(", %s", out->base->name);
+		printf("\n");
+	}
+	printf("\n");
+	
+	printf("=== Input Stack ===\n");
+	for (i=0, in=execdata->instack; i < execdata->totin; ++i, ++in) {
+//		printf("%d. ->%s, %s\n", i, (*in)->base->name, (*in)->node->base->name);
+		printf("%d. -> %d\n", i, (int)(*in - execdata->outstack));
+	}
+	printf("\n");
+	
+	printf("=== Node Stack ===\n");
+	printf(" %-5s", "No.");
+	printf(" %-15s", "Name");
+	printf("%-10s", "Source");
+	printf("\n");
+	for (n=0, ns=execdata->nodestack; n < execdata->totnode; ++n, ++ns) {
+		printf("%5d.", n);
+		printf(" %-15s\n", ns->base->name);
+		
+		for (i=0, in=ns->instack; i < ns->totin; ++i, ++in) {
+			int index = (int)(in - execdata->instack);
+			sock = (bNodeSocket*)BLI_findlink(&ns->base->inputs, i);
+			
+			printf("<%5d", index);
+			printf(" %-15s", sock->name);
+			if (*in && index >= 0 && index < execdata->totout) {
+				int outindex = (int)(*in - execdata->outstack);
+				printf("%-10d", outindex);
+//				printf("(-> %s,%s)", (*in)->node->base->name, (*in)->base->name);
+			}
+			printf("\n");
+		}
+		for (i=0, out=ns->outstack; i < ns->totout; ++i, ++out) {
+			printf(">%5d", (int)(out - execdata->outstack));
+			printf(" %-15s", out->base->name);
+			printf("\n");
+		}
+	}
+}
 #endif
 
 static void init_socket(SimSocketStack *stack, bNodeSocket *sock, SimNodeStack *node)
@@ -575,79 +637,57 @@
 {
 	bNode *node;
 	bNodeSocket *sock;
+	int n= 0, in= 0, out= 0;
 	int ext_in= 0, ext_out= 0;
 	
 	for(node= ntree->nodes.first; node; node= node->next) {
-//		node->stack_index = (*totout);	/* unused */
-		if (node->type != NODE_GROUP) {
-			++(*totnode);
+		/* node counter is not increased for group nodes,
+		 * these are replaced by the internal tree in the stack.
+		 */
+		if (node->type != NODE_GROUP)
+			n++;
+		
+		for (sock=node->outputs.first; sock; sock = sock->next) {
+			if (node->type != NODE_GROUP)
+				sock->stack_index = out++;
+			else
+				sock->stack_index = -1;
+			if (sock->intern)
+				sock->stack_index_ext = -1;
+			else
+				sock->stack_index_ext = ext_out++;
+		}
+		for (sock=node->inputs.first; sock; sock = sock->next) {
+			/* group nodes don't need input stack */
+			if (node->type != NODE_GROUP)
+				in++;
 			
-			for (sock=node->outputs.first; sock; sock = sock->next) {
-				sock->stack_index = (*totout)++;
-				if (sock->intern)
-					sock->stack_index_ext = -1;
+			if (sock->intern) {
+				if (sock->link && sock->link->fromnode)
+					sock->stack_index = -1;
 				else
-					sock->stack_index_ext = ext_out++;
+					/* unlinked input sockets also have a stack entry */
+					sock->stack_index = out++;
+				sock->stack_index_ext = -1;
 			}
-			for (sock=node->inputs.first; sock; sock = sock->next) {
-				(*totin)++;
-				
-				if (sock->intern) {
-					if (sock->link && sock->link->fromnode)
-						sock->stack_index = -1;
-					else
-						/* defaulted input sockets also have a stack entry */
-						sock->stack_index = (*totout)++;
-					sock->stack_index_ext = -1;
-				}
-				else {
-					sock->stack_index = -1;
-					sock->stack_index_ext = ext_in++;
-				}
+			else {
+				sock->stack_index = -1;
+				sock->stack_index_ext = ext_in++;
 			}
 		}
-		else {
-			for (sock=node->outputs.first; sock; sock = sock->next) {
-				/* sock->stack_index is set after the internal sockets are prepared */
-				if (sock->intern)
-					sock->stack_index_ext = -1;
-				else
-					sock->stack_index_ext = ext_out++;
-			}
-			/* defaulted input sockets also have a stack entry */
-			for (sock=node->inputs.first; sock; sock = sock->next) {
-				if (sock->intern) {
-					if (sock->link && sock->link->fromnode) {
-						/* sock->stack_index is set after the internal sockets are prepared */
-					}
-					else
-						sock->stack_index = (*totout)++;
-					sock->stack_index_ext = -1;
-				}
-				else {
-					/* sock->stack_index is set after the internal sockets are prepared */
-					sock->stack_index_ext = ext_in++;
-				}
-			}
 		
-			if (node->id)
-				calc_stack_indexes_recursive((bNodeTree *)node->id, totnode, totin, totout);
-			
-			/* group nodes use their internal nodes sockets */
-			for (sock=node->outputs.first; sock; sock = sock->next) {
-				sock->stack_index = sock->tosock->stack_index;
-			}
-			for (sock=node->inputs.first; sock; sock = sock->next) {
-				if (sock->intern) {
-					if (sock->link && sock->link->fromnode)
-						sock->stack_index = sock->tosock->stack_index;
-				}
-				else {
-					sock->stack_index = sock->tosock->stack_index;
-				}
-			}
-		}
+		/* offset for internal group nodes */
+		node->stack_index = out;
+		
+		/* prepare the internal indices of the group tree */
+		/* XXX repeated for each instance, only needs to be done once (tag?) */
+		if (node->type == NODE_GROUP && node->id)
+			calc_stack_indexes_recursive((bNodeTree *)node->id, &n, &in, &out);
 	}
+	
+	*totnode += n;
+	*totin += in;
+	*totout += out;
 }
 
 static void init_stack_recursive(SimExecData *execdata, bNodeTree *ntree,
@@ -665,6 +705,9 @@
 	apply_socket_restypes(ntree);
 	
 	for(node= ntree->nodes.first; node; node= node->next) {
+		if (node->type == SIM_NODE_FOR) {
+			printf("blabla\n");
+		}
 		if (node->type != NODE_GROUP) {
 			nodestack[n].base = node;
 			nodestack[n].id = n;
@@ -675,9 +718,8 @@
 			nodestack[n].totout = 0;
 			for (sock=node->outputs.first; sock; sock = sock->next) {
 				init_socket(&(outstack[out]), sock, &(nodestack[n]));
-				
+				++out;
 				++nodestack[n].totout;

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list