[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [29829] branches/particles-2010/source/ blender: * Moved node tree type functions to individual headers to keep node. c clean of callbacks and improve code structure.

Lukas Toenne lukas.toenne at googlemail.com
Wed Jun 30 19:25:28 CEST 2010


Revision: 29829
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=29829
Author:   lukastoenne
Date:     2010-06-30 19:25:28 +0200 (Wed, 30 Jun 2010)

Log Message:
-----------
* Moved node tree type functions to individual headers to keep node.c clean of callbacks and improve code structure.
* Added callbacks for node tree execution. These made heavy use of special cases for different tree types. Apart from basic init flags the whole execution code is now in the tree type files, which should make it easier to implement more advanced execution models for particle nodes.

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/nodes/intern/CMP_util.h
    branches/particles-2010/source/blender/nodes/intern/PAR_util.h
    branches/particles-2010/source/blender/nodes/intern/SHD_util.h
    branches/particles-2010/source/blender/nodes/intern/TEX_util.h
    branches/particles-2010/source/blender/nodes/intern/node_util.c
    branches/particles-2010/source/blender/nodes/intern/node_util.h

Added Paths:
-----------
    branches/particles-2010/source/blender/nodes/intern/node_tree_composite.c
    branches/particles-2010/source/blender/nodes/intern/node_tree_particles.c
    branches/particles-2010/source/blender/nodes/intern/node_tree_shader.c
    branches/particles-2010/source/blender/nodes/intern/node_tree_texture.c

Modified: branches/particles-2010/source/blender/blenkernel/BKE_node.h
===================================================================
--- branches/particles-2010/source/blender/blenkernel/BKE_node.h	2010-06-30 15:40:54 UTC (rev 29828)
+++ branches/particles-2010/source/blender/blenkernel/BKE_node.h	2010-06-30 17:25:28 UTC (rev 29829)
@@ -33,6 +33,8 @@
 #ifndef BKE_NODE_H
 #define BKE_NODE_H
 
+#include "DNA_listBase.h"
+
 /* not very important, but the stack solver likes to know a maximum */
 #define MAX_SOCKET	64
 
@@ -44,11 +46,11 @@
 struct bNodeStack;
 struct uiLayout;
 struct rctf;
-struct ListBase;
 struct RenderData;
 struct Scene;
 struct Main;
 struct Tex;
+struct MTex;
 struct GPUMaterial;
 struct GPUNode;
 struct GPUNodeStack;
@@ -93,7 +95,7 @@
 	void (*copystoragefunc)(struct bNode *, struct bNode *);
 	
 	/* for use with dynamic typedefs */
-	ID *id;
+	struct ID *id;
 	void *pynode; /* holds pointer to python script */
 	void *pydict; /* holds pointer to python script dictionary (scope)*/
 
@@ -114,6 +116,9 @@
 	void (*freeCache)(struct bNodeTree *ntree);
 	void (*freeNodeCache)(struct bNodeTree *ntree, struct bNode *node);
 	void (*foreachNodeTree)(void *calldata, bNodeTreeCallback func);		/* iteration over all node trees */
+	void (*beginExec)(struct bNodeTree *ntree);
+	void (*endExec)(struct bNodeTree *ntree);
+	void (*exec)(struct bNodeTree *ntree, void *callerdata, int thread);
 } bNodeTreeTypeInfo;
 
 /* node->exec, now in use for composites (#define for break is same as ready yes) */

Modified: branches/particles-2010/source/blender/blenkernel/intern/node.c
===================================================================
--- branches/particles-2010/source/blender/blenkernel/intern/node.c	2010-06-30 15:40:54 UTC (rev 29828)
+++ branches/particles-2010/source/blender/blenkernel/intern/node.c	2010-06-30 17:25:28 UTC (rev 29829)
@@ -50,6 +50,7 @@
 #include "CMP_node.h"
 #include "intern/CMP_util.h"	/* stupid include path... */
 #include "SHD_node.h"
+#include "intern/SHD_util.h"
 #include "TEX_node.h"
 #include "intern/TEX_util.h"
 #include "PAR_node.h"
@@ -57,110 +58,7 @@
 
 #include "GPU_material.h"
 
-/* ************** Type stuff **********  */
-void ntreeType_Shader_foreachNodeTree(void *calldata, bNodeTreeCallback func)
-{
-	Material *ma;
-	for(ma= G.main->mat.first; ma; ma= ma->id.next) {
-		if(ma->nodetree) {
-			func(calldata, &ma->id, ma->nodetree);
-		}
-	}
-}
 
-bNodeTreeTypeInfo ntreeType_Shader = {
-	/* type */				NTREE_SHADER,
-	/* id_name */			"NTShader Nodetree",
-	
-	/* node_types */		{ NULL, NULL },
-	
-	/* freeCache */			NULL,
-	/* freeNodeCache */		NULL,
-	/* foreachNodeTree */	ntreeType_Shader_foreachNodeTree
-};
-
-void ntreeType_Composite_foreachNodeTree(void *calldata, bNodeTreeCallback func)
-{
-	Scene *sce;
-	for(sce= G.main->scene.first; sce; sce= sce->id.next) {
-		if(sce->nodetree) {
-			func(calldata, &sce->id, sce->nodetree);
-		}
-	}
-}
-
-void ntreeType_Composite_freeNodeCache(bNodeTree *ntree, bNode *node)
-{
-	bNodeSocket *sock;
-	
-	for(sock= node->outputs.first; sock; sock= sock->next) {
-		if(sock->ns.data) {
-			free_compbuf(sock->ns.data);
-			sock->ns.data= NULL;
-		}
-	}
-}
-
-void ntreeType_Composite_freeCache(bNodeTree *ntree)
-{
-	bNode *node;
-	for(node= ntree->nodes.first; node; node= node->next)
-		ntreeType_Composite_freeNodeCache(ntree, node);
-}
-
-bNodeTreeTypeInfo ntreeType_Composite = {
-	/* type */				NTREE_COMPOSIT,
-	/* id_name */			"NTCompositing Nodetree",
-	
-	/* node_types */		{ NULL, NULL },
-	
-	/* freeCache */			ntreeType_Composite_freeCache,
-	/* freeNodeCache */		ntreeType_Composite_freeNodeCache,
-	/* foreachNodeTree */	ntreeType_Composite_foreachNodeTree
-};
-
-void ntreeType_Texture_foreachNodeTree(void *calldata, bNodeTreeCallback func)
-{
-	Tex *tx;
-	for(tx= G.main->tex.first; tx; tx= tx->id.next) {
-		if(tx->nodetree) {
-			func(calldata, &tx->id, tx->nodetree);
-		}
-	}
-}
-
-bNodeTreeTypeInfo ntreeType_Texture = {
-	/* type */				NTREE_TEXTURE,
-	/* id_name */			"NTTexture Nodetree",
-	
-	/* node_types */		{ NULL, NULL },
-	
-	/* freeCache */			NULL,
-	/* freeNodeCache */		NULL,
-	/* foreachNodeTree */	ntreeType_Texture_foreachNodeTree
-};
-
-void ntreeType_Particles_foreachNodeTree(void *calldata, bNodeTreeCallback func)
-{
-	ParticleSettings *pset;
-	for(pset= G.main->particle.first; pset; pset= pset->id.next) {
-		if(pset->nodetree) {
-			func(calldata, &pset->id, pset->nodetree);
-		}
-	}
-}
-
-bNodeTreeTypeInfo ntreeType_Particles = {
-	/* type */				NTREE_PARTICLES,
-	/* id_name */			"NTParticles Nodetree",
-	
-	/* node_types */		{ NULL, NULL },
-	
-	/* freeCache */			NULL,
-	/* freeNodeCache */		NULL,
-	/* foreachNodeTree */	ntreeType_Particles_foreachNodeTree
-};
-
 bNodeTreeTypeInfo *ntreeGetTypeInfo(int type)
 {
 	static bNodeTreeTypeInfo *types[NUM_NTREE_TYPES];
@@ -1536,11 +1434,11 @@
 
 void ntreeFreeCache(bNodeTree *ntree)
 {
-	bNodeTreeTypeInfo *treetype= ntreeGetTypeInfo(ntree->type);
-	bNode *node;
+	bNodeTreeTypeInfo *treetype;
 	
 	if(ntree==NULL) return;
-
+	
+	treetype= ntreeGetTypeInfo(ntree->type);
 	if (treetype->freeCache)
 		treetype->freeCache(ntree);
 }
@@ -1935,420 +1833,38 @@
 
 
 /* ******************* executing ************* */
-
-/* see notes at ntreeBeginExecTree */
-static void group_node_get_stack(bNode *node, bNodeStack *stack, bNodeStack **in, bNodeStack **out, bNodeStack **gin, bNodeStack **gout)
-{
-	bNodeSocket *sock;
-	
-	/* build pointer stack */
-	for(sock= node->inputs.first; sock; sock= sock->next) {
-		if(sock->intern) {
-			/* yep, intern can have link or is hidden socket */
-			if(sock->link)
-				*(in++)= stack + sock->link->fromsock->stack_index;
-			else
-				*(in++)= &sock->ns;
-		}
-		else
-			*(in++)= gin[sock->stack_index_ext];
-	}
-	
-	for(sock= node->outputs.first; sock; sock= sock->next) {
-		if(sock->intern)
-			*(out++)= stack + sock->stack_index;
-		else
-			*(out++)= gout[sock->stack_index_ext];
-	}
-}
-
-static void node_group_execute(bNodeStack *stack, void *data, bNode *gnode, bNodeStack **in, bNodeStack **out)
-{
-	bNode *node;
-	bNodeTree *ntree= (bNodeTree *)gnode->id;
-	bNodeStack *nsin[MAX_SOCKET];	/* arbitrary... watch this */
-	bNodeStack *nsout[MAX_SOCKET];	/* arbitrary... watch this */
-	
-	if(ntree==NULL) return;
-	
-	stack+= gnode->stack_index;
-		
-	for(node= ntree->nodes.first; node; node= node->next) {
-		if(node->typeinfo->execfunc) {
-			group_node_get_stack(node, stack, nsin, nsout, in, out);
-			
-			/* for groups, only execute outputs for edited group */
-			if(node->typeinfo->nclass==NODE_CLASS_OUTPUT) {
-				if(gnode->flag & NODE_GROUP_EDIT)
-					if(node->flag & NODE_DO_OUTPUT)
-						node->typeinfo->execfunc(data, node, nsin, nsout);
-			}
-			else
-				node->typeinfo->execfunc(data, node, nsin, nsout);
-		}
-	}
-	
-	/* free internal group output nodes */
-	if(ntree->type==NTREE_COMPOSIT) {
-		for(node= ntree->nodes.first; node; node= node->next) {
-			if(node->typeinfo->execfunc) {
-				bNodeSocket *sock;
-				
-				for(sock= node->outputs.first; sock; sock= sock->next) {
-					if(sock->intern) {
-						bNodeStack *ns= stack + sock->stack_index;
-						if(ns->data) {
-							free_compbuf(ns->data);
-							ns->data= NULL;
-						}
-					}
-				}
-			}
-		}
-	}
-}
-
-/* recursively called for groups */
-/* we set all trees on own local indices, but put a total counter
-   in the groups, so each instance of a group has own stack */
-static int ntree_begin_exec_tree(bNodeTree *ntree)
-{
-	bNode *node;
-	bNodeSocket *sock;
-	int index= 0, index_in= 0, index_out= 0;
-	
-	if((ntree->init & NTREE_TYPE_INIT)==0)
-		ntreeInitTypes(ntree);
-	
-	/* create indices for stack, check preview */
-	for(node= ntree->nodes.first; node; node= node->next) {
-		
-		for(sock= node->inputs.first; sock; sock= sock->next) {
-			if(sock->intern==0)
-				sock->stack_index_ext= index_in++;
-		}
-		
-		for(sock= node->outputs.first; sock; sock= sock->next) {
-			sock->stack_index= index++;
-			if(sock->intern==0)
-				sock->stack_index_ext= index_out++;
-		}
-		
-		if(node->type==NODE_GROUP) {
-			if(node->id) {
-				node->stack_index= index;
-				index+= ntree_begin_exec_tree((bNodeTree *)node->id);
-			}
-		}
-	}
-	
-	return index;
-}
-
-/* copy socket compbufs to stack, initialize usage of curve nodes */
-static void composit_begin_exec(bNodeTree *ntree, int is_group)
-{
-	bNode *node;
-	bNodeSocket *sock;
-	
-	for(node= ntree->nodes.first; node; node= node->next) {
-		
-		/* initialize needed for groups */
-		node->exec= 0;	
-		
-		if(is_group==0) {
-			for(sock= node->outputs.first; sock; sock= sock->next) {
-				bNodeStack *ns= ntree->stack + sock->stack_index;
-				
-				if(sock->ns.data) {
-					ns->data= sock->ns.data;
-					sock->ns.data= NULL;
-				}
-			}
-		}
-		/* cannot initialize them while using in threads */
-		if(ELEM4(node->type, CMP_NODE_TIME, CMP_NODE_CURVE_VEC, CMP_NODE_CURVE_RGB, CMP_NODE_HUECORRECT)) {
-			curvemapping_initialize(node->storage);
-			if(node->type==CMP_NODE_CURVE_RGB)
-				curvemapping_premultiply(node->storage, 0);
-		}
-		if(node->type==NODE_GROUP)
-			composit_begin_exec((bNodeTree *)node->id, 1);
-
-	}
-}
-
-/* copy stack compbufs to sockets */
-static void composit_end_exec(bNodeTree *ntree, int is_group)
-{
-	extern void print_compbuf(char *str, struct CompBuf *cbuf);
-	bNode *node;
-	bNodeStack *ns;
-	int a;
-
-	for(node= ntree->nodes.first; node; node= node->next) {
-		if(is_group==0) {
-			bNodeSocket *sock;
-		
-			for(sock= node->outputs.first; sock; sock= sock->next) {
-				ns= ntree->stack + sock->stack_index;
-				if(ns->data) {
-					sock->ns.data= ns->data;
-					ns->data= NULL;
-				}
-			}
-		}
-		if(node->type==CMP_NODE_CURVE_RGB)
-			curvemapping_premultiply(node->storage, 1);
-		
-		if(node->type==NODE_GROUP)
-			composit_end_exec((bNodeTree *)node->id, 1);
-
-		node->need_exec= 0;
-	}
-	
-	if(is_group==0) {
-		/* internally, group buffers are not stored */
-		for(ns= ntree->stack, a=0; a<ntree->stacksize; a++, ns++) {
-			if(ns->data) {
-				printf("freed leftover buffer from stack\n");
-				free_compbuf(ns->data);
-				ns->data= NULL;
-			}
-		}
-	}
-}
-
-static void group_tag_used_outputs(bNode *gnode, bNodeStack *stack)
-{
-	bNodeTree *ntree= (bNodeTree *)gnode->id;
-	bNode *node;
-	
-	stack+= gnode->stack_index;
-	
-	for(node= ntree->nodes.first; node; node= node->next) {
-		if(node->typeinfo->execfunc) {
-			bNodeSocket *sock;
-			
-			for(sock= node->inputs.first; sock; sock= sock->next) {
-				if(sock->intern) {
-					if(sock->link) {

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list