[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [32393] branches/particles-2010/source/ blender/nodes/intern/simulation: "if" node is back.

Lukas Toenne lukas.toenne at googlemail.com
Sun Oct 10 09:34:55 CEST 2010


Revision: 32393
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=32393
Author:   lukastoenne
Date:     2010-10-10 09:34:55 +0200 (Sun, 10 Oct 2010)

Log Message:
-----------
"if" node is back. works for control flow ifs as well as branch selection for data.

Modified Paths:
--------------
    branches/particles-2010/source/blender/nodes/intern/simulation/node_tree_simulation.c
    branches/particles-2010/source/blender/nodes/intern/simulation/nodes/SIM_if.c
    branches/particles-2010/source/blender/nodes/intern/simulation/nodes/SIM_math.c

Modified: branches/particles-2010/source/blender/nodes/intern/simulation/node_tree_simulation.c
===================================================================
--- branches/particles-2010/source/blender/nodes/intern/simulation/node_tree_simulation.c	2010-10-10 07:01:56 UTC (rev 32392)
+++ branches/particles-2010/source/blender/nodes/intern/simulation/node_tree_simulation.c	2010-10-10 07:34:55 UTC (rev 32393)
@@ -750,7 +750,7 @@
 				break;
 		}
 		
-		#if 1
+		#if 0
 		{
 			int t;
 			SimJob *dbgjob;
@@ -1009,24 +1009,13 @@
 //				assert( (out->branches > 0 && sim_buffer_valid(&out->buffer)) || (out->branches == 0 && !sim_buffer_valid(&out->buffer)) );
 //			}
 			
+			#if 0
 			printf(">>> Node %s >>>\n", ns->base->name);
 			printf("input-events:\n");
 			print_event_list(&ns->inputevents);
 			printf("events:\n");
 			print_event_list(&ns->events);
 			printf("<<<<<<<<<<<<<<<\n");
-			#if 0
-			{
-				SimEventStatus debug_event_status[256];
-				SimEventLink *debug_link;
-				int debug_i;
-				for (debug_link=ns->events.first, debug_i=0; debug_link; debug_link=debug_link->next, ++debug_i) {
-					debug_event_status[debug_i] = sim_event_status(&debug_link->event);
-				}
-				for (; debug_i < 256; ++debug_i)
-					debug_event_status[debug_i] = -1;
-				debug_i=0;	/* nonsense for breakpoint */
-			}
 			#endif
 		}
 	}
@@ -1101,7 +1090,8 @@
 				out->users = 0;
 			/* activate the operator inputs */
 			for (in=op->node->instack, i=0; i < op->node->totin; ++in, ++i)
-				++(*in)->users;
+				if ((*in)->type != SOCK_OP)
+					++(*in)->users;
 			
 			/* enqueue nodes */
 			enqueue_nodes(execdata, &op->self);
@@ -1127,25 +1117,13 @@
 			/* increase the operator execution level */
 			++op->resume_level;
 			
+			#if 0
 			printf(">>> Operator %s >>>\n", op->node->base->name);
 			printf("input-events:\n");
 			print_event_list(&op->node->inputevents);
 			printf("events:\n");
 			print_event_list(&op->node->events);
 			printf("<<<<<<<<<<<<<<<<<<<\n");
-			
-			#if 0
-			{
-				SimEventStatus debug_event_status[256];
-				SimEventLink *debug_link;
-				int debug_i;
-				for (debug_link=op->node->events.first, debug_i=0; debug_link; debug_link=debug_link->next, ++debug_i) {
-					debug_event_status[debug_i] = sim_event_status(&debug_link->event);
-				}
-				for (; debug_i < 256; ++debug_i)
-					debug_event_status[debug_i] = -1;
-				debug_i=0;	/* nonsense for breakpoint */
-			}
 			#endif
 
 			/* wait for all enqueued nodes to finish */
@@ -1159,20 +1137,11 @@
 			#endif
 			{
 				while (1) {
-					#if 0
-					SimJob *debug_jobs[256];		/* for usable variable display during debugging */
-					int debug_i=0;
-					#endif
-					
 					/* TODO free finished node buffers and enqueue remaining nodes */
 					waiting_jobs = 0;
 					for (job=execdata->queue.first; job; job = job->next) {
 						if (sim_event_status(&job->event) != SIM_COMPLETE)
 							++waiting_jobs;
-						
-						#if 0
-						debug_jobs[debug_i++] = job;
-						#endif
 					}
 					
 					if (waiting_jobs > 0) {

Modified: branches/particles-2010/source/blender/nodes/intern/simulation/nodes/SIM_if.c
===================================================================
--- branches/particles-2010/source/blender/nodes/intern/simulation/nodes/SIM_if.c	2010-10-10 07:01:56 UTC (rev 32392)
+++ branches/particles-2010/source/blender/nodes/intern/simulation/nodes/SIM_if.c	2010-10-10 07:34:55 UTC (rev 32393)
@@ -45,31 +45,86 @@
 	{ -1, 0, "" }
 };
 
-static void enqueue_op(SimExecData *execdata, SimNodeStack *node, SimDataContext *self, int execlevel, int *pushop)
+static char *generate_source(struct SimNodeStack *node)
 {
-//	SimEvent unmap_event;
-//	void *iterbuf= sim_enqueue_map_buffer(execdata, &node->instack[0]->buffer, 1, SIM_MAP_READ, 0, 1, node->totinputevents, node->inputevents, NULL);
-//	sim_mapped_buffer_read_int(iterbuf);
-//	sim_enqueue_unmap_buffer(execdata, &node->instack[0]->buffer, iterbuf, 0, NULL, &unmap_event);
-//	sim_enqueue_read_buffer(execdata, &node->instack[0]->buffer, 1, 0, 1, path, node->totinputevents, node->inputevents, NULL);
-//	if (execdata->error) return;
+	int restype= node->outstack[0].type;
+	DynStr *source= sim_kernel_source_begin(node, NULL, 0, NULL);
+	BLI_dynstr_appendf(source, "*OUTPUT0_FLOAT(get_global_id(0)) = (INPUT0_BOOL(get_global_id(0)) ? INPUT1_%s(get_global_id(0)) : INPUT2_%s(get_global_id(0)));\n", sim_get_typename(restype), sim_get_typename(restype));
+	return sim_kernel_source_end(source);
+}
 
-//	int i, op=0, nextop= -1;
-//	
-//	for (i=0; i < node->totin; ++i) {
-//		/* skip default values */
-//		if (node->instack[i]->node == node)
-//			continue;
-//		
-//		if (op == execlevel) {
-//			nextop = i;
-//			break;
-//		}
-//		++op;
-//	}
-//	*pushop = nextop;
+void kernel_float(int global_id, void **args, SimNodeStack *node)
+{
+	*SIM_OUTPUT_FLOAT(0, global_id) = (SIM_INPUT_BOOL(0, global_id) ? SIM_INPUT_FLOAT(1, global_id) : SIM_INPUT_FLOAT(2, global_id));
 }
 
+void kernel_int(int global_id, void **args, SimNodeStack *node)
+{
+	*SIM_OUTPUT_INT(0, global_id) = (SIM_INPUT_BOOL(0, global_id) ? SIM_INPUT_INT(1, global_id) : SIM_INPUT_INT(2, global_id));
+}
+
+void kernel_bool(int global_id, void **args, SimNodeStack *node)
+{
+	*SIM_OUTPUT_BOOL(0, global_id) = (SIM_INPUT_BOOL(0, global_id) ? SIM_INPUT_BOOL(1, global_id) : SIM_INPUT_BOOL(2, global_id));
+}
+
+void kernel_vector(int global_id, void **args, SimNodeStack *node)
+{
+	copy_v3_v3(SIM_OUTPUT_VECTOR(0, global_id), (SIM_INPUT_BOOL(0, global_id) ? SIM_INPUT_VECTOR(1, global_id) : SIM_INPUT_VECTOR(2, global_id)));
+}
+
+void kernel_rgba(int global_id, void **args, SimNodeStack *node)
+{
+	copy_v4_v4(SIM_OUTPUT_RGBA(0, global_id), (SIM_INPUT_BOOL(0, global_id) ? SIM_INPUT_RGBA(1, global_id) : SIM_INPUT_RGBA(2, global_id)));
+}
+
+/* "if" node for data sets */
+static void enqueue(SimExecData *execdata, SimNodeStack *node, SimDataContext *self)
+{
+	SimDataContext ctx;
+	SimKernel *kernel;
+	char kernelname[64];
+	SimKernelFunction kernelfunc;
+	
+	if (!sim_node_get_max_context(node->instack, node->totin, &ctx))
+		return;
+	if (!sim_node_init_output(execdata, &node->outstack[0], &ctx))
+		return;
+	
+	sim_kernel_source_name(node, NULL, kernelname);
+	kernelfunc = NULL;
+	switch (node->outstack[0].type) {
+	case SOCK_FLOAT:	kernelfunc= kernel_float;	break;
+	case SOCK_INT:		kernelfunc= kernel_int;		break;
+	case SOCK_BOOL:		kernelfunc= kernel_bool;	break;
+	case SOCK_VECTOR:	kernelfunc= kernel_vector;	break;
+	case SOCK_RGBA:		kernelfunc= kernel_rgba;	break;
+	}
+	
+	if (kernelfunc) {
+		kernel=MEM_callocN(sizeof(SimKernel), "SimKernel");
+		sim_kernel_init(execdata, kernel, kernelfunc, kernelname);
+		sim_kernel_set_node(execdata, kernel, node, 0);
+		sim_kernel_enqueue(execdata, kernel, ctx.size, &node->inputevents, &node->events);
+	}
+}
+
+/* "if" node for control */
+static void enqueue_op(SimExecData *execdata, SimNodeStack *node, SimDataContext *self, int execlevel, int *pushop)
+{
+	if (execlevel == 0) {
+		char cond;
+		SimSocketIterator sockiter;
+		
+		sim_input_begin(execdata, node->instack[0], &sockiter);
+		sim_input_read_bool(execdata, &sockiter, &cond);
+		sim_input_end(execdata, &sockiter);
+		if (execdata->error) return;
+		
+		*pushop = (cond ? 1 : 2);
+	}
+}
+
 bNodeType sim_node_if= {
 	/* *next,*prev     */	NULL, NULL,
 	/* type code       */	SIM_NODE_IF,
@@ -92,7 +147,7 @@
 	/* initsocketfunc  */	NULL,
 	/* copysocketstoragefunc */	NULL,
 	/* freesocketstoragefunc */	NULL,
-	/* generate_source */	NULL,
-	/* enqueue         */	NULL,
+	/* generate_source */	generate_source,
+	/* enqueue         */	enqueue,
 	/* enqueue         */	enqueue_op
 };

Modified: branches/particles-2010/source/blender/nodes/intern/simulation/nodes/SIM_math.c
===================================================================
--- branches/particles-2010/source/blender/nodes/intern/simulation/nodes/SIM_math.c	2010-10-10 07:01:56 UTC (rev 32392)
+++ branches/particles-2010/source/blender/nodes/intern/simulation/nodes/SIM_math.c	2010-10-10 07:34:55 UTC (rev 32393)
@@ -142,13 +142,8 @@
 	char kernelname[64];
 	SimKernelFunction kernelfunc;
 	
-	/* find the input context */
-	if (!sim_node_get_max_context(node->instack, node->totin, &ctx)) {
-		execdata->error = 1;
-		sprintf(execdata->error_string, "Cannot find input context.");
+	if (!sim_node_get_max_context(node->instack, node->totin, &ctx))
 		return;
-	}
-	
 	if (!sim_node_init_output(execdata, &node->outstack[0], &ctx))
 		return;
 	





More information about the Bf-blender-cvs mailing list