[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [43559] trunk/blender/source/blender: Cleanup of default_value handling in node sockets.

Lukas Toenne lukas.toenne at googlemail.com
Fri Jan 20 14:27:55 CET 2012


Revision: 43559
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=43559
Author:   lukastoenne
Date:     2012-01-20 13:27:54 +0000 (Fri, 20 Jan 2012)
Log Message:
-----------
Cleanup of default_value handling in node sockets.

The structs stored in the anonymous void *default_value in bNodeSocket are now handled completely inside node_socket.c. All allocation/freeing/duplicating for this has been replaced by the appropriate calls to generic API functions (declared in NOD_socket.h).

This will make the default value handling more reliable for future node socket code. Group socket copying and value conversion has also been moved into the generic socket API file.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/intern/node.c
    trunk/blender/source/blender/editors/space_node/node_templates.c
    trunk/blender/source/blender/nodes/NOD_socket.h
    trunk/blender/source/blender/nodes/intern/node_common.c
    trunk/blender/source/blender/nodes/intern/node_socket.c

Modified: trunk/blender/source/blender/blenkernel/intern/node.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/node.c	2012-01-20 13:25:54 UTC (rev 43558)
+++ trunk/blender/source/blender/blenkernel/intern/node.c	2012-01-20 13:27:54 UTC (rev 43559)
@@ -159,7 +159,6 @@
 
 static bNodeSocket *make_socket(bNodeTree *UNUSED(ntree), int in_out, const char *name, int type)
 {
-	bNodeSocketType *stype= ntreeGetSocketType(type);
 	bNodeSocket *sock;
 	
 	sock= MEM_callocN(sizeof(bNodeSocket), "sock");
@@ -169,8 +168,8 @@
 	sock->type= type;
 	sock->storage = NULL;
 	
-	if (stype->value_structsize > 0)
-		sock->default_value = MEM_callocN(stype->value_structsize, "default socket value");
+	sock->default_value = node_socket_make_default_value(type);
+	node_socket_init_default_value(type, sock->default_value);
 	
 	return sock;
 }
@@ -216,8 +215,7 @@
 	BLI_remlink(&node->inputs, sock);
 	BLI_remlink(&node->outputs, sock);
 	
-	if (sock->default_value)
-		MEM_freeN(sock->default_value);
+	node_socket_free_default_value(sock->type, sock->default_value);
 	MEM_freeN(sock);
 	
 	node->update |= NODE_UPDATE;
@@ -236,13 +234,10 @@
 	}
 	
 	for (sock=node->inputs.first; sock; sock=sock->next)
-		if (sock->default_value)
-			MEM_freeN(sock->default_value);
+		node_socket_free_default_value(sock->type, sock->default_value);
 	BLI_freelistN(&node->inputs);
 	for (sock=node->outputs.first; sock; sock=sock->next)
-		if (sock->default_value)
-			MEM_freeN(sock->default_value);
-	
+		node_socket_free_default_value(sock->type, sock->default_value);
 	BLI_freelistN(&node->outputs);
 	
 	node->update |= NODE_UPDATE;
@@ -396,7 +391,8 @@
 		oldsock->new_sock= sock;
 		sock->stack_index= 0;
 		
-		sock->default_value = (oldsock->default_value ? MEM_dupallocN(oldsock->default_value) : NULL);
+		sock->default_value = node_socket_make_default_value(oldsock->type);
+		node_socket_copy_default_value(oldsock->type, sock->default_value, oldsock->default_value);
 		
 		/* XXX some compositor node (e.g. image, render layers) still store
 		 * some persistent buffer data here, need to clear this to avoid dangling pointers.
@@ -410,7 +406,8 @@
 		oldsock->new_sock= sock;
 		sock->stack_index= 0;
 		
-		sock->default_value = (oldsock->default_value ? MEM_dupallocN(oldsock->default_value) : NULL);
+		sock->default_value = node_socket_make_default_value(oldsock->type);
+		node_socket_copy_default_value(oldsock->type, sock->default_value, oldsock->default_value);
 		
 		/* XXX some compositor node (e.g. image, render layers) still store
 		 * some persistent buffer data here, need to clear this to avoid dangling pointers.
@@ -658,13 +655,15 @@
 	for(gsock= newtree->inputs.first, oldgsock= ntree->inputs.first; gsock; gsock=gsock->next, oldgsock=oldgsock->next) {
 		oldgsock->new_sock= gsock;
 		gsock->groupsock = (oldgsock->groupsock ? oldgsock->groupsock->new_sock : NULL);
-		gsock->default_value = (oldgsock->default_value ? MEM_dupallocN(oldgsock->default_value) : NULL);
+		gsock->default_value = node_socket_make_default_value(oldgsock->type);
+		node_socket_copy_default_value(oldgsock->type, gsock->default_value, oldgsock->default_value);
 	}
 	BLI_duplicatelist(&newtree->outputs, &ntree->outputs);
 	for(gsock= newtree->outputs.first, oldgsock= ntree->outputs.first; gsock; gsock=gsock->next, oldgsock=oldgsock->next) {
 		oldgsock->new_sock= gsock;
 		gsock->groupsock = (oldgsock->groupsock ? oldgsock->groupsock->new_sock : NULL);
-		gsock->default_value = (oldgsock->default_value ? MEM_dupallocN(oldgsock->default_value) : NULL);
+		gsock->default_value = node_socket_make_default_value(oldgsock->type);
+		node_socket_copy_default_value(oldgsock->type, gsock->default_value, oldgsock->default_value);
 	}
 	
 	/* copy links */
@@ -863,14 +862,12 @@
 	
 	for (sock=node->inputs.first; sock; sock = nextsock) {
 		nextsock = sock->next;
-		if (sock->default_value)
-			MEM_freeN(sock->default_value);
+		node_socket_free_default_value(sock->type, sock->default_value);
 		MEM_freeN(sock);
 	}
 	for (sock=node->outputs.first; sock; sock = nextsock) {
 		nextsock = sock->next;
-		if (sock->default_value)
-			MEM_freeN(sock->default_value);
+		node_socket_free_default_value(sock->type, sock->default_value);
 		MEM_freeN(sock);
 	}
 
@@ -924,12 +921,10 @@
 	}
 	
 	for (sock=ntree->inputs.first; sock; sock=sock->next)
-		if (sock->default_value)
-			MEM_freeN(sock->default_value);
+		node_socket_free_default_value(sock->type, sock->default_value);
 	BLI_freelistN(&ntree->inputs);
 	for (sock=ntree->outputs.first; sock; sock=sock->next)
-		if (sock->default_value)
-			MEM_freeN(sock->default_value);
+		node_socket_free_default_value(sock->type, sock->default_value);
 	BLI_freelistN(&ntree->outputs);
 }
 

Modified: trunk/blender/source/blender/editors/space_node/node_templates.c
===================================================================
--- trunk/blender/source/blender/editors/space_node/node_templates.c	2012-01-20 13:25:54 UTC (rev 43558)
+++ trunk/blender/source/blender/editors/space_node/node_templates.c	2012-01-20 13:27:54 UTC (rev 43559)
@@ -49,6 +49,8 @@
 
 #include "RNA_access.h"
 
+#include "NOD_socket.h"
+
 #include "WM_api.h"
 #include "WM_types.h"
 
@@ -205,12 +207,9 @@
 						nodeRemLink(ntree, link);
 					}
 
-					if(sock_prev->default_value) {
-						if(sock_from->default_value)
-							MEM_freeN(sock_from->default_value);
-
-						sock_from->default_value = MEM_dupallocN(sock_prev->default_value);
-					}
+					node_socket_free_default_value(sock_from->type, sock_from->default_value);
+					sock_from->default_value = node_socket_make_default_value(sock_from->type);
+					node_socket_copy_default_value(sock_from->type, sock_from->default_value, sock_prev->default_value);
 				}
 			}
 		}

Modified: trunk/blender/source/blender/nodes/NOD_socket.h
===================================================================
--- trunk/blender/source/blender/nodes/NOD_socket.h	2012-01-20 13:25:54 UTC (rev 43558)
+++ trunk/blender/source/blender/nodes/NOD_socket.h	2012-01-20 13:27:54 UTC (rev 43559)
@@ -47,27 +47,20 @@
 
 void node_socket_type_init(struct bNodeSocketType *types[]);
 
-struct bNodeSocket *nodeAddInputInt(struct bNodeTree *ntree, struct bNode *node, const char *name, PropertySubType subtype, int value, int min, int max);
-struct bNodeSocket *nodeAddOutputInt(struct bNodeTree *ntree, struct bNode *node, const char *name);
+void *node_socket_make_default_value(int type);
+void node_socket_free_default_value(int type, void *default_value);
+void node_socket_init_default_value(int type, void *default_value);
+void node_socket_copy_default_value(int type, void *to_default_value, void *from_default_value);
+void node_socket_convert_default_value(int to_type, void *to_default_value, int from_type, void *from_default_value);
 
-struct bNodeSocket *nodeAddInputFloat(struct bNodeTree *ntree, struct bNode *node, const char *name, PropertySubType subtype, float value, float min, float max);
-struct bNodeSocket *nodeAddOutputFloat(struct bNodeTree *ntree, struct bNode *node, const char *name);
+void node_socket_set_default_value_int(void *default_value, PropertySubType subtype, int value, int min, int max);
+void node_socket_set_default_value_float(void *default_value, PropertySubType subtype, float value, float min, float max);
+void node_socket_set_default_value_boolean(void *default_value, char value);
+void node_socket_set_default_value_vector(void *default_value, PropertySubType subtype, float x, float y, float z, float min, float max);
+void node_socket_set_default_value_rgba(void *default_value, float r, float g, float b, float a);
+void node_socket_set_default_value_shader(void *default_value);
+void node_socket_set_default_value_mesh(void *default_value);
 
-struct bNodeSocket *nodeAddInputBoolean(struct bNodeTree *ntree, struct bNode *node, const char *name, char value);
-struct bNodeSocket *nodeAddOutputBoolean(struct bNodeTree *ntree, struct bNode *node, const char *name);
-
-struct bNodeSocket *nodeAddInputVector(struct bNodeTree *ntree, struct bNode *node, const char *name, PropertySubType subtype, float x, float y, float z, float min, float max);
-struct bNodeSocket *nodeAddOutputVector(struct bNodeTree *ntree, struct bNode *node, const char *name);
-
-struct bNodeSocket *nodeAddInputRGBA(struct bNodeTree *ntree, struct bNode *node, const char *name, float r, float g, float b, float a);
-struct bNodeSocket *nodeAddOutputRGBA(struct bNodeTree *ntree, struct bNode *node, const char *name);
-
-struct bNodeSocket *nodeAddInputShader(struct bNodeTree *ntree, struct bNode *node, const char *name);
-struct bNodeSocket *nodeAddOutputShader(struct bNodeTree *ntree, struct bNode *node, const char *name);
-
-struct bNodeSocket *nodeAddInputMesh(struct bNodeTree *ntree, struct bNode *node, const char *name);
-struct bNodeSocket *nodeAddOutputMesh(struct bNodeTree *ntree, struct bNode *node, const char *name);
-
 struct bNodeSocket *node_add_input_from_template(struct bNodeTree *ntree, struct bNode *node, struct bNodeSocketTemplate *stemp);
 struct bNodeSocket *node_add_output_from_template(struct bNodeTree *ntree, struct bNode *node, struct bNodeSocketTemplate *stemp);
 

Modified: trunk/blender/source/blender/nodes/intern/node_common.c
===================================================================
--- trunk/blender/source/blender/nodes/intern/node_common.c	2012-01-20 13:25:54 UTC (rev 43558)
+++ trunk/blender/source/blender/nodes/intern/node_common.c	2012-01-20 13:27:54 UTC (rev 43559)
@@ -100,8 +100,8 @@
 	sock->groupsock = gsock;
 	sock->limit = (in_out==SOCK_IN ? 1 : 0xFFF);
 	
-	if (gsock->default_value)
-		sock->default_value = MEM_dupallocN(gsock->default_value);
+	sock->default_value = node_socket_make_default_value(sock->type);
+	node_socket_copy_default_value(sock->type, sock->default_value, gsock->default_value);
 	
 	if(lb)
 		BLI_addtail(lb, sock);
@@ -247,177 +247,6 @@
 	return gnode;
 }
 
-/* XXX This is a makeshift function to have useful initial group socket values.
- * In the end this should be implemented by a flexible socket data conversion system,
- * which is yet to be implemented. The idea is that beside default standard conversions,
- * such as int-to-float, it should be possible to quickly select a conversion method or
- * a chain of conversions for each input, whenever there is more than one option.

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-blender-cvs mailing list