[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [31634] branches/particles-2010/source/ blender: Sockets use a StructRNA pointer to define the context type.

Lukas Toenne lukas.toenne at googlemail.com
Sat Aug 28 17:06:05 CEST 2010


Revision: 31634
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=31634
Author:   lukastoenne
Date:     2010-08-28 17:06:05 +0200 (Sat, 28 Aug 2010)

Log Message:
-----------
Sockets use a StructRNA pointer to define the context type. The actual context is a stored in a PointerRNA in the socket instances. This pointer is only defined at runtime (e.g. by creating arbitrary path strings in the tree), which means that the validity of a connection can change and cannot be determined during construction of the tree. The convention is that a NULL pointer is used when the data is a singleton (i.e. can be freely combined with any other socket) and a pointer to the source in case the context property is a collection.

Modified Paths:
--------------
    branches/particles-2010/source/blender/blenkernel/intern/node.c
    branches/particles-2010/source/blender/blenloader/intern/readfile.c
    branches/particles-2010/source/blender/editors/space_node/node_draw.c
    branches/particles-2010/source/blender/makesdna/DNA_node_types.h
    branches/particles-2010/source/blender/modifiers/intern/MOD_nodetree.c
    branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_get_data.c
    branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_set_data.c
    branches/particles-2010/source/blender/nodes/intern/SIM_util.c
    branches/particles-2010/source/blender/nodes/intern/SIM_util.h
    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-28 15:04:42 UTC (rev 31633)
+++ branches/particles-2010/source/blender/blenkernel/intern/node.c	2010-08-28 15:06:05 UTC (rev 31634)
@@ -142,9 +142,7 @@
 	BLI_strncpy(sock->name, name, NODE_MAXSTR);
 	sock->limit = (is_input ? 1 : 0xFFF);
 	sock->type= type;
-	sock->context.prop = NULL;
-	sock->context.id = NULL;
-	sock->context.data = NULL;
+	sock->contexttype = NULL;
 	sock->intern = 1;
 	if (type == SOCK_ANY)
 		sock->flag |= SOCK_ADAPT_TYPE;
@@ -1842,17 +1840,16 @@
 {
 	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->context = sock->link->fromsock->context;
+				sock->contexttype = sock->link->fromsock->contexttype;
 			}
 			else if (sock->intern) {
 				/* socket uses default singleton data */
-				sock->context.prop = NULL;
-				sock->context.id = NULL;
-				sock->context.data = NULL;
+				sock->contexttype = NULL;
 			}
 		}
 	}
@@ -1860,62 +1857,52 @@
 	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->context = sock->context;
+				sock->tosock->contexttype = sock->contexttype;
 	}
 }
 
 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->flag & SOCK_ADAPT_CONTEXT)!=0)
-				sock->context = sock->tosock->context;
+				sock->contexttype = sock->tosock->contexttype;
 		for (sock=node->outputs.first; sock; sock=sock->next)
 			if (sock->tosock && (sock->flag & SOCK_ADAPT_CONTEXT)!=0)
-				sock->context = sock->tosock->context;
+				sock->contexttype = sock->tosock->contexttype;
 	}
 	else {
-		resctx.prop = NULL;
-		resctx.id = NULL;
-		resctx.data = NULL;
+		StructRNA *res= NULL;
 		for (sock=node->inputs.first; sock; sock=sock->next) {
 			if ((sock->flag & SOCK_ADAPT_CONTEXT)!=0) {
-				if (resctx.data == NULL) {
-					if (sock->context.data != NULL)
-						resctx = sock->context;
+				if (res == NULL) {
+					if (sock->contexttype != NULL)
+						res = sock->contexttype;
 				}
-				else if (RNA_property_type(sock->context.prop) == PROP_COLLECTION) {
-					if (RNA_property_type(resctx.prop) == PROP_POINTER) {
-						resctx = sock->context;
+				else if (sock->contexttype != NULL) {
+					if (RNA_struct_is_a(sock->contexttype, res)) {
+						res = sock->contexttype;
+					} else {
+						res = NULL;
 					}
-					else {
-						if (resctx.prop != sock->context.prop || resctx.id != sock->context.id || resctx.data != sock->context.data) {
-							resctx.prop = NULL;
-							resctx.id = NULL;
-							resctx.data = NULL;
-						}
-					}
 				}
 			}
 		}
 		
 		/* context unresolvable, reset all other inputs too */
-		if (resctx.data == NULL) {
+		if (res == NULL) {
 			for (sock=node->inputs.first; sock; sock=sock->next) {
 				if ((sock->flag & SOCK_ADAPT_CONTEXT)!=0) {
-					sock->context.prop = NULL;
-					sock->context.id = NULL;
-					sock->context.data = NULL;
+					sock->contexttype = NULL;
 				}
 			}
 		}
 		for (sock=node->outputs.first; sock; sock=sock->next) {
 			if ((sock->flag & SOCK_ADAPT_CONTEXT)!=0) {
-				sock->context = resctx;
+				sock->contexttype = res;
 			}
 		}
 	}
@@ -1924,7 +1911,6 @@
 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) {
@@ -1953,15 +1939,10 @@
 				valid = tti->compatibleSocketTypes(link->fromsock->type, link->tosock->type);
 				
 				if (valid) {
-					bNodeDataContext *fromctx = &link->fromsock->context;
-					bNodeDataContext *toctx = &link->tosock->context;
-					if (fromctx->prop && RNA_property_type(fromctx->prop) == PROP_COLLECTION) {
-						if (toctx->data == NULL || RNA_property_type(toctx->prop) != PROP_COLLECTION) {
+					StructRNA *fromctx = link->fromsock->contexttype;
+					StructRNA *toctx = link->tosock->contexttype;
+					if (fromctx && (toctx == NULL || !RNA_struct_is_a(fromctx, toctx))) {
 							valid =0;
-						}
-						else if (fromctx->prop != toctx->prop || fromctx->id != toctx->id || fromctx->data != toctx->data) {
-							valid = 0;
-						}
 					}
 				}
 			}

Modified: branches/particles-2010/source/blender/blenloader/intern/readfile.c
===================================================================
--- branches/particles-2010/source/blender/blenloader/intern/readfile.c	2010-08-28 15:04:42 UTC (rev 31633)
+++ branches/particles-2010/source/blender/blenloader/intern/readfile.c	2010-08-28 15:06:05 UTC (rev 31634)
@@ -1997,6 +1997,7 @@
 static void lib_link_ntree(FileData *fd, ID *id, bNodeTree *ntree)
 {
 	bNode *node;
+	bNodeSocket *sock;
 	
 	if(ntree->adt) lib_link_animdata(fd, &ntree->id, ntree->adt);
 	
@@ -2005,9 +2006,16 @@
 	for(node= ntree->nodes.first; node; node= node->next) {
 		node->id= newlibadr_us(fd, id->lib, node->id);
 		
+		for (sock= node->inputs.first; sock; sock= sock->next) {
+			sock->contexttype= newlibadr_us(fd, id->lib, sock->contexttype);
+		}
+		for (sock= node->outputs.first; sock; sock= sock->next) {
+			sock->contexttype= newlibadr_us(fd, id->lib, sock->contexttype);
+		}
+		
 		if (ELEM(node->type, SIM_NODE_GETDATA, SIM_NODE_SETDATA) != 0) {
 			SimNodeData *stor= (SimNodeData*)node->storage;
-			newlibadr_us(fd, id->lib, stor->type);
+			stor->type= newlibadr_us(fd, id->lib, stor->type);
 		}
 	}
 }

Modified: branches/particles-2010/source/blender/editors/space_node/node_draw.c
===================================================================
--- branches/particles-2010/source/blender/editors/space_node/node_draw.c	2010-08-28 15:04:42 UTC (rev 31633)
+++ branches/particles-2010/source/blender/editors/space_node/node_draw.c	2010-08-28 15:06:05 UTC (rev 31634)
@@ -913,10 +913,8 @@
 			#if 1
 			{
 				char str[32], *p_str;
-				if (sock->context.prop) {
-					PointerRNA ptr;
-					RNA_pointer_create(sock->context.id, NULL, sock->context.data, &ptr);
-					p_str = RNA_path_from_ID_to_property(&ptr, sock->context.prop);
+				if (sock->contexttype) {
+					p_str= (char*)RNA_struct_identifier(sock->contexttype);
 				}
 				else {
 					p_str = str;
@@ -953,12 +951,21 @@
 			uiDefBut(node->block, LABEL, 0, sock->name+ofs, (short)(sock->locx-15.0f-slen), (short)(sock->locy-9.0f), 
 					 (short)(node->width-NODE_DY), NODE_DY,  NULL, 0, 0, 0, 0, "");
 			
-			#if 0
+			#if 1
 			{
-				static char *context_str[] = { "U", "S", "N", "P", "V", "E", "F" };
-				char str[32];
-				uiDefBut(node->block, LABEL, 0, context_str[sock->context.type], (short)(sock->locx+5), (short)(sock->locy-9.0f), 
+				char str[32], *p_str;
+				if (sock->contexttype) {
+					p_str= (char*)RNA_struct_identifier(sock->contexttype);
+				}
+				else {
+					p_str = str;
+					str[0] = '\0';
+				}
+				uiDefBut(node->block, LABEL, 0, p_str, (short)(sock->locx+5), (short)(sock->locy-9.0f), 
 						 (short)(node->width-NODE_DY), NODE_DY,  NULL, 0, 0, 0, 0, "");
+//				if (sock->context.prop)
+//					MEM_freeN(p_str);
+				
 				sprintf(str, "%d", sock->island);
 				uiDefBut(node->block, LABEL, 0, str, 
 						 (short)(sock->locx+20), (short)(sock->locy-9.0f), (short)(node->width-NODE_DY), NODE_DY,  NULL, 0, 0, 0, 0, "");

Modified: branches/particles-2010/source/blender/makesdna/DNA_node_types.h
===================================================================
--- branches/particles-2010/source/blender/makesdna/DNA_node_types.h	2010-08-28 15:04:42 UTC (rev 31633)
+++ branches/particles-2010/source/blender/makesdna/DNA_node_types.h	2010-08-28 15:06:05 UTC (rev 31634)
@@ -49,14 +49,6 @@
 
 #define NODE_MAXSTR 32
 
-
-/* Defines data context for simulation node sockets */
-typedef struct bNodeDataContext {
-	struct PropertyRNA *prop;
-	struct ID *id;
-	void *data;
-} bNodeDataContext;
-
 typedef struct bNodeStack {
 	float vec[4];
 	float min, max;			/* min/max for values (UI writes it, execute might use it) */
@@ -80,9 +72,10 @@
 	char name[32];
 	bNodeStack ns;				/* custom data for inputs, only UI writes in this */
 	
-	short type, flag;			/* type is copy from socket type struct */
+	short type, flag;			/* data type, flags */
 	short limit, stack_index;	/* limit for dependency sort, stack_index for exec */
-	bNodeDataContext context;	/* data context (simulation nodes) */
+	struct StructRNA *contexttype;	/* data context type (simulation nodes) */
+	
 	short intern;				/* intern = tag for group nodes */
 	short stack_index_ext;		/* for groups, to find the caller stack index */
 	

Modified: branches/particles-2010/source/blender/modifiers/intern/MOD_nodetree.c
===================================================================
--- branches/particles-2010/source/blender/modifiers/intern/MOD_nodetree.c	2010-08-28 15:04:42 UTC (rev 31633)
+++ branches/particles-2010/source/blender/modifiers/intern/MOD_nodetree.c	2010-08-28 15:06:05 UTC (rev 31634)
@@ -57,9 +57,8 @@
 	NodeTreeModifierData *ntmd= (NodeTreeModifierData*) md;
 	
 	if (ntmd->nodetree) {
-		/* TODO how to properly free the node tree? */
-//		ntreeFreeTree(ntmd->nodetree);
-//		MEM_freeN(ntmd->nodetree);
+		ntreeFreeTree(ntmd->nodetree);
+		MEM_freeN(ntmd->nodetree);
 	}
 }
 static void copyData(ModifierData *md, ModifierData *target)

Modified: branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_get_data.c
===================================================================
--- branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_get_data.c	2010-08-28 15:04:42 UTC (rev 31633)
+++ branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_get_data.c	2010-08-28 15:06:05 UTC (rev 31634)
@@ -51,7 +51,7 @@
 static int exec(SimNodeThreadContext *ctx, SimNodeJob *job)
 {
 	SimNodeDataStream istream[1];
-	SimNodeDataStream ostream[1];
+	SimNodeDataStream ostream[MAX_SOCKET];	/* can have arbitrary number of outputs */
 	

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list