[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [31384] branches/particles-2010/source/ blender: Fixed group node instancing for executing simulation nodes, including operator nodes.
Lukas Toenne
lukas.toenne at googlemail.com
Mon Aug 16 17:59:42 CEST 2010
Revision: 31384
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=31384
Author: lukastoenne
Date: 2010-08-16 17:59:42 +0200 (Mon, 16 Aug 2010)
Log Message:
-----------
Fixed group node instancing for executing simulation nodes, including operator nodes.
Modified Paths:
--------------
branches/particles-2010/source/blender/blenkernel/intern/node.c
branches/particles-2010/source/blender/nodes/intern/node_tree_simulation.c
Modified: branches/particles-2010/source/blender/blenkernel/intern/node.c
===================================================================
--- branches/particles-2010/source/blender/blenkernel/intern/node.c 2010-08-16 15:54:58 UTC (rev 31383)
+++ branches/particles-2010/source/blender/blenkernel/intern/node.c 2010-08-16 15:59:42 UTC (rev 31384)
@@ -159,6 +159,7 @@
sock->type= stype->type;
sock->context.type = stype->contexttype;
sock->context.source = NULL;
+ sock->intern = 1;
sock->to_index= stype->own_index;
sock->tonode= stype->internnode;
@@ -190,6 +191,7 @@
sock->type= stype->type;
sock->context.type = stype->contexttype;
sock->context.source = NULL;
+ sock->intern = 1;
sock->to_index= stype->own_index;
sock->tonode= stype->internnode;
Modified: branches/particles-2010/source/blender/nodes/intern/node_tree_simulation.c
===================================================================
--- branches/particles-2010/source/blender/nodes/intern/node_tree_simulation.c 2010-08-16 15:54:58 UTC (rev 31383)
+++ branches/particles-2010/source/blender/nodes/intern/node_tree_simulation.c 2010-08-16 15:59:42 UTC (rev 31384)
@@ -78,7 +78,7 @@
/* Initialises output socket instances and creates pointers to them for input instances.
* This way the execution does not have to care about group nodes and their external sockets.
*/
-static void init_stack_recursive(bNodeTree *ntree, SimNodeInstance *stack_node, SimNodeSocketInstance **stack_in, SimNodeSocketInstance *stack_out, int index_node, int index_in, int index_out)
+static void init_stack_recursive(bNodeTree *ntree, SimNodeInstance *stack_node, SimNodeSocketInstance **stack_in, SimNodeSocketInstance *stack_out, int *index_node, int *index_in, int *index_out)
{
bNode *node;
bNodeSocket *sock;
@@ -86,54 +86,83 @@
for(node= ntree->nodes.first; node; node= node->next) {
if (node->type != NODE_GROUP) {
- stack_node[index_node].node = node;
- stack_node[index_node].inputs = stack_in + index_in;
- stack_node[index_node].outputs = stack_out + index_out;
- stack_node[index_node].jobs.first = stack_node[index_node].jobs.last = NULL;
+ stack_node[*index_node].node = node;
+ stack_node[*index_node].inputs = stack_in + (*index_in);
+ stack_node[*index_node].outputs = stack_out + (*index_out);
+ stack_node[*index_node].jobs.first = stack_node[*index_node].jobs.last = NULL;
- stack_node[index_node].totoutputs = stack_node[index_node].totinputs = 0;
+ stack_node[*index_node].totoutputs = stack_node[*index_node].totinputs = 0;
for (sock=node->outputs.first; sock; sock = sock->next) {
- stack_out[index_out].batches.first = stack_out[index_out].batches.last = NULL;
- stack_out[index_out].datatype = sock->type;
- stack_out[index_out].contexttype = sock->context.type;
- sock->stack_index = index_out; /* needed for finding the input socket fromnodes later on (only used inside this function!) */
+ stack_out[*index_out].batches.first = stack_out[*index_out].batches.last = NULL;
+ stack_out[*index_out].datatype = sock->type;
+ stack_out[*index_out].contexttype = sock->context.type;
+ /* Needed for finding the input instances later on
+ * Note: the stack_index is overwritten for each group instance, but only used directly after that!
+ */
+ sock->stack_index = *index_out;
/* prepare operator sockets */
- if (stack_out[index_out].datatype == SOCK_OP) {
+ /* TODO should be done in a separate function for clarity */
+ if (stack_out[*index_out].datatype == SOCK_OP) {
batch = MEM_callocN(sizeof(SimNodeBatch), "SimNodeBatch");
- sim_init_operator_socket_batch(batch, stack_node + index_node);
- BLI_addtail(&stack_out[index_out].batches, batch);
+ sim_init_operator_socket_batch(batch, stack_node + (*index_node));
+ BLI_addtail(&stack_out[*index_out].batches, batch);
}
- ++stack_node[index_node].totoutputs;
- ++index_out;
+ ++stack_node[*index_node].totoutputs;
+ ++(*index_out);
}
for (sock=node->inputs.first; sock; sock = sock->next) {
- if (sock->link && sock->link->fromnode) {
- stack_in[index_in] = stack_out + sock->link->fromsock->stack_index;
- } else {
- stack_in[index_in] = MEM_callocN(sizeof(SimNodeSocketInstance), "default SimNodeSocketInstance");
- stack_in[index_in]->branches = -1; /* this indicates a default socket, must be freed explicitly */
- stack_in[index_in]->batches.first = stack_in[index_in]->batches.last = NULL;
- stack_in[index_in]->datatype = sock->type;
- stack_in[index_in]->contexttype = NDC_SINGLETON;
-
- batch = MEM_callocN(sizeof(SimNodeBatch), "SimNodeBatch");
- sim_init_default_socket_batch(batch, sock);
- BLI_addtail(&stack_in[index_in]->batches, batch);
+ if (sock->intern==0) {
+ /* non-internal inputs are set by the group node container */
+ stack_in[*index_in] = NULL;
+ sock->stack_index = *index_in;
}
- ++stack_node[index_node].totinputs;
- ++index_in;
+ else {
+ if (sock->link && sock->link->fromsock) {
+ stack_in[*index_in] = stack_out + sock->link->fromsock->stack_index;
+ } else {
+ stack_in[*index_in] = MEM_callocN(sizeof(SimNodeSocketInstance), "default SimNodeSocketInstance");
+ stack_in[*index_in]->branches = -1; /* this indicates a default socket, must be freed explicitly */
+ stack_in[*index_in]->batches.first = stack_in[*index_in]->batches.last = NULL;
+ stack_in[*index_in]->datatype = sock->type;
+ stack_in[*index_in]->contexttype = NDC_SINGLETON;
+
+ batch = MEM_callocN(sizeof(SimNodeBatch), "SimNodeBatch");
+ sim_init_default_socket_batch(batch, sock);
+ BLI_addtail(&stack_in[*index_in]->batches, batch);
+ }
+ }
+ ++stack_node[*index_node].totinputs;
+ ++(*index_in);
}
- ++index_node;
+ ++(*index_node);
}
- else {
+ else if (node->id) {
init_stack_recursive((bNodeTree*)node->id, stack_node, stack_in, stack_out, index_node, index_in, index_out);
/* the internal sockets are prepared now, we can use the stack index for the group node sockets */
for (sock=node->outputs.first; sock; sock = sock->next)
- sock->stack_index = sock->tosock->stack_index; /* needed for finding the input socket fromnodes */
+ sock->stack_index = sock->tosock->stack_index;
+ for (sock=node->inputs.first; sock; sock = sock->next) {
+ if (sock->tosock) {
+ if (sock->link && sock->link->fromnode) {
+ stack_in[sock->tosock->stack_index] = stack_out + sock->link->fromsock->stack_index;
+ }
+ else {
+ stack_in[sock->tosock->stack_index] = MEM_callocN(sizeof(SimNodeSocketInstance), "default SimNodeSocketInstance");
+ stack_in[sock->tosock->stack_index]->branches = -1; /* this indicates a default socket, must be freed explicitly */
+ stack_in[sock->tosock->stack_index]->batches.first = stack_in[sock->tosock->stack_index]->batches.last = NULL;
+ stack_in[sock->tosock->stack_index]->datatype = sock->type;
+ stack_in[sock->tosock->stack_index]->contexttype = NDC_SINGLETON;
+
+ batch = MEM_callocN(sizeof(SimNodeBatch), "SimNodeBatch");
+ sim_init_default_socket_batch(batch, sock);
+ BLI_addtail(&stack_in[sock->tosock->stack_index]->batches, batch);
+ }
+ }
+ }
}
}
}
@@ -204,15 +233,15 @@
static void make_input_jobs(SimNodeInstance *nodestack, int totnode)
{
SimNodeInstance *node;
- bNodeSocket *sock;
+ SimNodeSocketInstance **sock;
int n, i;
SimNodeJob *job;
int inputsockets;
for (n=0, node=nodestack; n < totnode; ++n, ++node) {
inputsockets = 0;
- for (sock=node->node->inputs.first; sock; sock = sock->next)
- if (sock->link && sock->link->fromnode)
+ for (i=0, sock=node->inputs; i < node->totinputs; ++i, ++sock)
+ if ((*sock)->branches >= 0)
++inputsockets;
if (inputsockets == 0 && node->totbranches > 0) {
job = MEM_callocN(sizeof(SimNodeJob), "SimNodeJob");
@@ -671,7 +700,7 @@
node->totbranches += out->branches;
}
/* activate input nodes if part of at least one branch or an output node */
- if (node->totbranches > 0 || node == root) {
+ if (node->totbranches > 0 || (node->totbranches == 0 && node == root)) {
for (index_sock=0, in=node->inputs; index_sock < node->totinputs; ++index_sock, ++in) {
/* skip sockets using default data */
if ((*in)->branches >= 0)
@@ -869,7 +898,7 @@
ListBase thread_list;
SimNodeInstance *nodestack;
SimNodeSocketInstance **instack, *outstack;
- int i, totnode, totinputs, totoutputs;
+ int i, totnode, totinputs, totoutputs, index_node, index_in, index_out;
bNode *rootnode, *node;
SimNodeOperator *root_op;
@@ -894,8 +923,23 @@
nodestack = MEM_callocN(totnode * sizeof(SimNodeInstance), "SimNode node instances");
instack = MEM_callocN(totinputs * sizeof(SimNodeSocketInstance*), "SimNodes input socket instance pointers");
outstack = MEM_callocN(totoutputs * sizeof(SimNodeSocketInstance), "SimNode output socket instances");
- init_stack_recursive(ntree, nodestack, instack, outstack, 0, 0, 0);
+ index_node = index_in = index_out = 0;
+ init_stack_recursive(ntree, nodestack, instack, outstack, &index_node, &index_in, &index_out);
+ #if 0
+ {
+ int n;
+ printf("NodeInstance Stack: \n");
+ for (n=0; n < totnode; ++n) {
+ if (nodestack[n].node)
+ printf("\tNode %s\n", nodestack[n].node->name);
+ else
+ printf("\tNode NULL\n");
+ }
+ printf("ssssssssssssssssssss\n");
+ }
+ #endif
+
/* initialise the thread context */
ctx.sim = sim;
ctx.totthread = BLI_system_thread_count();
More information about the Bf-blender-cvs
mailing list