[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [29824] branches/particles-2010/source/ blender: Merged a patch that adds a node tree type info struct as a generic interface to replace the explicit references to tree types , especially NTREE_COMPOSIT (Patch No.
Lukas Toenne
lukas.toenne at googlemail.com
Wed Jun 30 16:43:52 CEST 2010
Revision: 29824
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=29824
Author: lukastoenne
Date: 2010-06-30 16:43:52 +0200 (Wed, 30 Jun 2010)
Log Message:
-----------
Merged a patch that adds a node tree type info struct as a generic interface to replace the explicit references to tree types, especially NTREE_COMPOSIT (Patch No. 22458 on the tracker). This can be used to delegate execution code without too much type-specific code.
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/editors/space_node/drawnode.c
branches/particles-2010/source/blender/editors/space_node/node_header.c
branches/particles-2010/source/blender/makesdna/DNA_node_types.h
Modified: branches/particles-2010/source/blender/blenkernel/BKE_node.h
===================================================================
--- branches/particles-2010/source/blender/blenkernel/BKE_node.h 2010-06-30 14:43:28 UTC (rev 29823)
+++ branches/particles-2010/source/blender/blenkernel/BKE_node.h 2010-06-30 14:43:52 UTC (rev 29824)
@@ -102,6 +102,20 @@
} bNodeType;
+typedef void (*bNodeTreeCallback)(void *calldata, struct ID *owner_id, struct bNodeTree *ntree);
+typedef struct bNodeTreeTypeInfo
+{
+ int type; /* type identifier */
+ char id_name[24]; /* id name for RNA identification */
+
+ ListBase node_types; /* type definitions */
+
+ /* callbacks */
+ void (*freeCache)(struct bNodeTree *ntree);
+ void (*freeNodeCache)(struct bNodeTree *ntree, struct bNode *node);
+ void (*foreachNodeTree)(void *calldata, bNodeTreeCallback func); /* iteration over all node trees */
+} bNodeTreeTypeInfo;
+
/* node->exec, now in use for composites (#define for break is same as ready yes) */
#define NODE_PROCESSING 1
#define NODE_READY 2
@@ -128,6 +142,8 @@
/* ************** GENERIC API, TREES *************** */
+bNodeTreeTypeInfo *ntreeGetTypeInfo(int type);
+
void ntreeVerifyTypes(struct bNodeTree *ntree);
struct bNodeTree *ntreeAddTree(int type);
@@ -265,9 +281,6 @@
#define NODE_DYNAMIC_REPARSE 6 /* 64 */
#define NODE_DYNAMIC_SET 15 /* sign */
-/* the type definitions array */
-extern struct ListBase node_all_shaders;
-
/* API */
void ntreeShaderExecTree(struct bNodeTree *ntree, struct ShadeInput *shi, struct ShadeResult *shr);
@@ -392,9 +405,6 @@
#define CMP_SCALE_SCENEPERCENT 2
-/* the type definitions array */
-extern struct ListBase node_all_composit;
-
/* API */
struct CompBuf;
void ntreeCompositTagRender(struct Scene *sce);
@@ -437,8 +447,6 @@
#define TEX_NODE_PROC 500
#define TEX_NODE_PROC_MAX 600
-extern struct ListBase node_all_textures;
-
/* API */
int ntreeTexTagAnimated(struct bNodeTree *ntree);
void ntreeTexSetPreviewFlag(int);
Modified: branches/particles-2010/source/blender/blenkernel/intern/node.c
===================================================================
--- branches/particles-2010/source/blender/blenkernel/intern/node.c 2010-06-30 14:43:28 UTC (rev 29823)
+++ branches/particles-2010/source/blender/blenkernel/intern/node.c 2010-06-30 14:43:52 UTC (rev 29824)
@@ -57,14 +57,131 @@
#include "GPU_material.h"
-static ListBase empty_list = {NULL, NULL};
-ListBase node_all_composit = {NULL, NULL};
-ListBase node_all_shaders = {NULL, NULL};
-ListBase node_all_textures = {NULL, NULL};
-ListBase node_all_particles = {NULL, NULL};
-
/* ************** 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];
+ static int types_init = 1;
+ if (types_init) {
+ types[NTREE_SHADER] = &ntreeType_Shader;
+ types[NTREE_COMPOSIT] = &ntreeType_Composite;
+ types[NTREE_TEXTURE] = &ntreeType_Texture;
+ types[NTREE_PARTICLES] = &ntreeType_Particles;
+ types_init = 0;
+ }
+
+ if(type >= 0 && type < NUM_NTREE_TYPES) {
+ return types[type];
+ }
+ else {
+ return NULL;
+ }
+}
+
+
static bNodeType *node_get_type(bNodeTree *ntree, int type, bNodeTree *ngroup, ID *id)
{
if(type==NODE_GROUP) {
@@ -74,7 +191,7 @@
return NULL;
}
else {
- bNodeType *ntype = ntree->alltypes.first;
+ bNodeType *ntype = ntreeGetTypeInfo(ntree->type)->node_types.first;
for(; ntype; ntype= ntype->next)
if(ntype->type==type && id==ntype->id )
return ntype;
@@ -87,19 +204,6 @@
{
bNode *node, *next;
- if(ntree->type==NTREE_SHADER)
- ntree->alltypes= node_all_shaders;
- else if(ntree->type==NTREE_COMPOSIT)
- ntree->alltypes= node_all_composit;
- else if(ntree->type==NTREE_TEXTURE)
- ntree->alltypes= node_all_textures;
- else if(ntree->type==NTREE_PARTICLES)
- ntree->alltypes= node_all_particles;
- else {
- ntree->alltypes= empty_list;
- printf("Error: no type definitions for nodes\n");
- }
-
for(node= ntree->nodes.first; node; node= next) {
next= node->next;
if(node->type==NODE_DYNAMIC) {
@@ -571,7 +675,6 @@
/* OK! new nodetree */
ngroup= alloc_libblock(&G.main->nodetree, ID_NT, "NodeGroup");
ngroup->type= ntree->type;
- ngroup->alltypes= ntree->alltypes;
/* move nodes over */
for(node= ntree->nodes.first; node; node= nextn) {
@@ -653,108 +756,61 @@
/* note: ungroup: group_indices zero! */
-/* here's a nasty little one, need to check users... */
-/* should become callbackable... */
+static void nodeVerifyGroupCallback(void *calldata, ID *owner_id, bNodeTree *ntree)
+{
+ ID *group_id= (ID*)calldata;
+ bNode *node;
+
+ /* find if group is in tree */
+ for(node= ntree->nodes.first; node; node= node->next)
+ if(node->id == group_id)
+ break;
+
+ if(node) {
+ /* set all type pointers OK */
+ ntreeInitTypes(ntree);
+
+ for(node= ntree->nodes.first; node; node= node->next)
+ if(node->id == group_id)
+ nodeVerifyType(ntree, node);
+ }
+}
+
void nodeVerifyGroup(bNodeTree *ngroup)
{
+ bNodeTreeTypeInfo *treetype= ntreeGetTypeInfo(ngroup->type);
/* group changed, so we rebuild the type definition */
ntreeMakeOwnType(ngroup);
- if(ngroup->type==NTREE_SHADER) {
- Material *ma;
- for(ma= G.main->mat.first; ma; ma= ma->id.next) {
- if(ma->nodetree) {
- bNode *node;
-
- /* find if group is in tree */
- for(node= ma->nodetree->nodes.first; node; node= node->next)
- if(node->id == (ID *)ngroup)
- break;
-
- if(node) {
- /* set all type pointers OK */
- ntreeInitTypes(ma->nodetree);
-
- for(node= ma->nodetree->nodes.first; node; node= node->next)
- if(node->id == (ID *)ngroup)
- nodeVerifyType(ma->nodetree, node);
- }
- }
- }
- }
- else if(ngroup->type==NTREE_COMPOSIT) {
- Scene *sce;
- for(sce= G.main->scene.first; sce; sce= sce->id.next) {
- if(sce->nodetree) {
- bNode *node;
-
- /* find if group is in tree */
- for(node= sce->nodetree->nodes.first; node; node= node->next)
- if(node->id == (ID *)ngroup)
- break;
-
- if(node) {
- /* set all type pointers OK */
- ntreeInitTypes(sce->nodetree);
-
- for(node= sce->nodetree->nodes.first; node; node= node->next)
- if(node->id == (ID *)ngroup)
- nodeVerifyType(sce->nodetree, node);
- }
- }
- }
- }
- else if(ngroup->type==NTREE_TEXTURE) {
- Tex *tx;
- for(tx= G.main->tex.first; tx; tx= tx->id.next) {
- if(tx->nodetree) {
- bNode *node;
-
- /* find if group is in tree */
- for(node= tx->nodetree->nodes.first; node; node= node->next)
- if(node->id == (ID *)ngroup)
- break;
-
- if(node) {
- /* set all type pointers OK */
- ntreeInitTypes(tx->nodetree);
-
- for(node= tx->nodetree->nodes.first; node; node= node->next)
- if(node->id == (ID *)ngroup)
- nodeVerifyType(tx->nodetree, node);
- }
- }
- }
- }
- else if(ngroup->type==NTREE_PARTICLES) {
- ParticleSettings *part;
- for(part= G.main->particle.first; part; part= part->id.next) {
- if(part->nodetree) {
- bNode *node;
-
- /* find if group is in tree */
- for(node= part->nodetree->nodes.first; node; node= node->next)
- if(node->id == (ID *)ngroup)
- break;
-
- if(node) {
- /* set all type pointers OK */
- ntreeInitTypes(part->nodetree);
-
- for(node= part->nodetree->nodes.first; node; node= node->next)
- if(node->id == (ID *)ngroup)
- nodeVerifyType(part->nodetree, node);
- }
- }
- }
- }
+ treetype->foreachNodeTree(ngroup, &nodeVerifyGroupCallback);
}
+static void nodeGroupSocketUseFlagsCallback(void *calldata, ID *owner_id, bNodeTree *ntree)
+{
+ ID *group_id= (ID*)calldata;
+ bNode *node;
+ bNodeSocket *sock;
+
+ for(node= ntree->nodes.first; node; node= node->next) {
+ if(node->id==group_id) {
+ for(sock= node->inputs.first; sock; sock= sock->next)
+ if(sock->link)
+ if(sock->tosock)
+ sock->tosock->flag |= SOCK_IN_USE;
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list