[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [31497] branches/particles-2010/source/ blender: Fixed context and data type resolution for socket instances in groups.
Lukas Toenne
lukas.toenne at googlemail.com
Sat Aug 21 10:10:25 CEST 2010
Revision: 31497
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=31497
Author: lukastoenne
Date: 2010-08-21 10:10:24 +0200 (Sat, 21 Aug 2010)
Log Message:
-----------
Fixed context and data type resolution for socket instances in groups. This allows using group nodes in different locations with different types and contexts linked to them. For resolving type islands the stack_indexes of sockets are now relative to their container node again, so this group index must be a parameter in recursive (per group) functions.
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/makesdna/DNA_node_types.h
branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_math.c
branches/particles-2010/source/blender/nodes/intern/node_tree_simulation.c
Modified: branches/particles-2010/source/blender/blenkernel/BKE_node.h
===================================================================
--- branches/particles-2010/source/blender/blenkernel/BKE_node.h 2010-08-21 07:48:25 UTC (rev 31496)
+++ branches/particles-2010/source/blender/blenkernel/BKE_node.h 2010-08-21 08:10:24 UTC (rev 31497)
@@ -44,6 +44,7 @@
struct bNodeSocket;
struct bNodeStack;
struct bNodeTree;
+struct bNodeSocketIsland;
struct GPUMaterial;
struct GPUNode;
struct GPUNodeStack;
@@ -190,6 +191,14 @@
void ntreeUpdateFullTree(struct bNodeTree *ntree);
void ntreeUpdateListSockets(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 ntreeBeginExecTree(struct bNodeTree *ntree);
void ntreeExecTree(struct bNodeTree *ntree, void *callerdata, int thread);
void ntreeCompositExecTree(struct bNodeTree *ntree, struct RenderData *rd, int do_previews);
Modified: branches/particles-2010/source/blender/blenkernel/intern/node.c
===================================================================
--- branches/particles-2010/source/blender/blenkernel/intern/node.c 2010-08-21 07:48:25 UTC (rev 31496)
+++ branches/particles-2010/source/blender/blenkernel/intern/node.c 2010-08-21 08:10:24 UTC (rev 31497)
@@ -171,6 +171,9 @@
sock->ns.vec[3]= stype->val4;
sock->ns.min= stype->min;
sock->ns.max= stype->max;
+ sock->ns.ival = (int)stype->val1;
+ sock->ns.imin = (int)stype->min;
+ sock->ns.imax = (int)stype->max;
sock->stype = stype;
@@ -203,6 +206,9 @@
sock->ns.vec[3]= stype->val4;
sock->ns.min= stype->min;
sock->ns.max= stype->max;
+ sock->ns.ival = (int)stype->val1;
+ sock->ns.imin = (int)stype->min;
+ sock->ns.imax = (int)stype->max;
sock->stype = stype;
@@ -1763,12 +1769,6 @@
}
}
-typedef struct bNodeSocketIsland {
- struct bNodeSocketIsland *next, *prev;
- struct bNodeSocket *sock;
- struct bNode *node;
-} bNodeSocketIsland;
-
static void merge_socket_islands(bNodeSocketIsland *islands, int a, int b)
{
bNodeSocketIsland *i;
@@ -1859,7 +1859,7 @@
return (link->fromsock->stype->type == SOCK_ANY || link->tosock->stype->type == SOCK_ANY);
}
-static void calc_type_islands_recursive(bNodeTree *ntree)
+void ntreeCalcSocketTypeIslands(bNodeTree *ntree)
{
bNode *node;
bNodeSocket *sock;
@@ -1870,7 +1870,7 @@
/* calculate nested groups */
for (node=ntree->nodes.first; node; node = node->next)
if (node->type == NODE_GROUP && node->id && ((bNodeTree*)node->id)->islands == NULL)
- calc_type_islands_recursive((bNodeTree*)node->id);
+ ntreeCalcSocketTypeIslands((bNodeTree*)node->id);
/* initialise island indices */
totsock = 0;
@@ -1888,12 +1888,14 @@
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;
}
}
@@ -1914,14 +1916,14 @@
}
}
-static void free_islands_recursive(bNodeTree *ntree)
+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)
- free_islands_recursive((bNodeTree*)node->id);
+ ntreeFreeSocketTypeIslands((bNodeTree*)node->id);
if (ntree->islands != NULL) {
MEM_freeN(ntree->islands);
@@ -1929,7 +1931,7 @@
}
}
-static void find_island_socket_type_recursive(bNodeTree *ntree, int island, int *restype, int *resolved)
+void ntreeFindIslandSocketType(bNodeTree *ntree, int island, int *restype, int *resolved)
{
bNodeTreeTypeInfo *tti;
bNodeSocketIsland *cur;
@@ -1941,7 +1943,7 @@
for (cur = ntree->islands + island; cur; cur = cur->next) {
if (cur->node->type == NODE_GROUP) {
if (cur->node->id && cur->sock->tosock)
- find_island_socket_type_recursive((bNodeTree*)cur->node->id, cur->sock->tosock->island, restype, resolved);
+ ntreeFindIslandSocketType((bNodeTree*)cur->node->id, cur->sock->tosock->island, restype, resolved);
}
else {
if (!(*resolved)) {
@@ -1961,7 +1963,7 @@
}
}
-static void resolve_socket_types(bNodeTree *ntree)
+void ntreeResolveSocketTypes(bNodeTree *ntree)
{
bNodeSocketIsland *cur, *res;
int restype, resolved, island;
@@ -1973,7 +1975,7 @@
resolved = 0;
restype = SOCK_ANY;
- find_island_socket_type_recursive(ntree, island, &restype, &resolved);
+ ntreeFindIslandSocketType(ntree, island, &restype, &resolved);
for (res = cur; res; res = res->next)
if (res->sock->stype->type == SOCK_ANY)
@@ -1982,86 +1984,101 @@
}
}
-static void resolve_socket_contexts(bNodeTree *ntree)
+void ntreeResolveInputContexts(bNode *node)
{
- bNode *node;
bNodeSocket *sock;
- /* nodes are assumed fully sorted, so context can be propagated from left to right */
- for (node=ntree->nodes.first; node; node = node->next) {
+ for (sock=node->inputs.first; sock; sock=sock->next) {
+ if (sock->stype->contexttype == NDC_UNDEFINED) {
+ /* propagate context along link (fromnode is fully resolved) */
+ if (sock->link && sock->link->fromsock) {
+ sock->context = sock->link->fromsock->context;
+ }
+ else if (sock->intern) {
+ /* socket uses default singleton data */
+ sock->context.type = NDC_SINGLETON;
+ sock->context.source = NULL;
+ }
+ }
+ }
+
+ if (node->type == NODE_GROUP) {
+ for (sock=node->inputs.first; sock; sock=sock->next)
+ if (sock->tosock && sock->stype->contexttype == NDC_UNDEFINED)
+ sock->tosock->context = sock->context;
+ }
+}
+
+void ntreeResolveOutputContexts(bNode *node)
+{
+ bNodeSocket *sock;
+ bNodeDataContext resctx;
+
+ 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->stype->contexttype == NDC_UNDEFINED)
+ sock->context = sock->tosock->context;
+ for (sock=node->outputs.first; sock; sock=sock->next)
+ if (sock->tosock && sock->stype->contexttype == NDC_UNDEFINED)
+ sock->context = sock->tosock->context;
+ }
+ else {
+ resctx.type = NDC_UNDEFINED;
+ resctx.source = NULL;
for (sock=node->inputs.first; sock; sock=sock->next) {
if (sock->stype->contexttype == NDC_UNDEFINED) {
- /* propagate context along link (fromnode is fully resolved) */
- if (sock->link && sock->link->fromsock) {
- sock->context = sock->link->fromsock->context;
+ if (resctx.type == NDC_UNDEFINED) {
+ if (sock->context.type != NDC_UNDEFINED)
+ resctx = sock->context;
}
- else if (sock->intern) {
- /* socket uses default singleton data */
- sock->context.type = NDC_SINGLETON;
- sock->context.source = NULL;
+ else if (ELEM(sock->context.type, NDC_UNDEFINED, NDC_SINGLETON)==0) {
+ if (resctx.type == NDC_SINGLETON) {
+ resctx = sock->context;
+ }
+ else {
+ if (resctx.type != sock->context.type || resctx.source != sock->context.source) {
+ resctx.type = NDC_UNDEFINED;
+ resctx.source = NULL;
+ }
+ }
}
}
}
- if (node->type == NODE_GROUP) {
- for (sock=node->inputs.first; sock; sock=sock->next)
- if (sock->tosock && sock->stype->contexttype == NDC_UNDEFINED)
- sock->tosock->context = sock->context;
-
- if (node->id)
- resolve_socket_contexts((bNodeTree*)node->id);
-
- /* 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->stype->contexttype == NDC_UNDEFINED)
- sock->context = sock->tosock->context;
- for (sock=node->outputs.first; sock; sock=sock->next)
- if (sock->tosock && sock->stype->contexttype == NDC_UNDEFINED)
- sock->context = sock->tosock->context;
- }
- else {
- bNodeDataContext resctx;
-
- resctx.type = NDC_UNDEFINED;
- resctx.source = NULL;
+ /* context unresolvable, reset all other inputs too */
+ if (resctx.type == NDC_UNDEFINED) {
for (sock=node->inputs.first; sock; sock=sock->next) {
if (sock->stype->contexttype == NDC_UNDEFINED) {
- if (resctx.type == NDC_UNDEFINED) {
- if (sock->context.type != NDC_UNDEFINED)
- resctx = sock->context;
- }
- else if (ELEM(sock->context.type, NDC_UNDEFINED, NDC_SINGLETON)==0) {
- if (resctx.type == NDC_SINGLETON) {
- resctx = sock->context;
- }
- else {
- if (resctx.type != sock->context.type || resctx.source != sock->context.source) {
- resctx.type = NDC_UNDEFINED;
- resctx.source = NULL;
- }
- }
- }
+ sock->context.type = NDC_UNDEFINED;
+ sock->context.source = NULL;
}
}
-
- /* context unresolvable, reset all other inputs too */
- if (resctx.type == NDC_UNDEFINED) {
- for (sock=node->inputs.first; sock; sock=sock->next) {
- if (sock->stype->contexttype == NDC_UNDEFINED) {
- sock->context.type = NDC_UNDEFINED;
- sock->context.source = NULL;
- }
- }
+ }
+ for (sock=node->outputs.first; sock; sock=sock->next) {
+ if (sock->stype->contexttype == NDC_UNDEFINED) {
+ sock->context = resctx;
}
- for (sock=node->outputs.first; sock; sock=sock->next) {
- if (sock->stype->contexttype == NDC_UNDEFINED) {
- sock->context = resctx;
- }
- }
}
}
}
+void ntreeResolveSocketContexts(bNodeTree *ntree)
+{
+ bNode *node;
+ bNodeSocket *sock;
+
+ /* nodes are assumed fully sorted, so context can be propagated from left to right */
+ for (node=ntree->nodes.first; node; node = node->next) {
+ ntreeResolveInputContexts(node);
+
+ if (node->type == NODE_GROUP && node->id)
+ ntreeResolveSocketContexts((bNodeTree*)node->id);
+
+ ntreeResolveOutputContexts(node);
+ }
+}
+
static void validate_links(bNodeTree *ntree)
{
bNodeTreeTypeInfo *tti = ntreeGetTypeInfo(ntree->type);
@@ -2122,8 +2139,8 @@
* They have to be recalculated for each tree up in the hierarchy,
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list