[Bf-blender-cvs] [522295f] object_nodes: Create expression return values based on node tree outputs.

Lukas Tönne noreply at git.blender.org
Tue Nov 24 09:42:58 CET 2015


Commit: 522295f4f7c300e9f338d139949e8cd22cf429a1
Author: Lukas Tönne
Date:   Sun Oct 11 15:02:47 2015 +0200
Branches: object_nodes
https://developer.blender.org/rB522295f4f7c300e9f338d139949e8cd22cf429a1

Create expression return values based on node tree outputs.

===================================================================

M	source/blender/blenkernel/intern/effect.c
M	source/blender/blenvm/BVM_api.h
M	source/blender/blenvm/CMakeLists.txt
M	source/blender/blenvm/intern/bvm_api.cc
A	source/blender/blenvm/intern/bvm_codegen.cc
A	source/blender/blenvm/intern/bvm_codegen.h
M	source/blender/blenvm/intern/bvm_type_desc.h

===================================================================

diff --git a/source/blender/blenkernel/intern/effect.c b/source/blender/blenkernel/intern/effect.c
index da859ee..2f08f8e 100644
--- a/source/blender/blenkernel/intern/effect.c
+++ b/source/blender/blenkernel/intern/effect.c
@@ -210,7 +210,7 @@ static void add_object_nodes_to_effectors(EffectorContext *effctx, Scene *scene,
 				
 				if (ff_ntree) {
 					EffectorCache *eff = new_effector_cache(effctx, scene, ob, NULL, ob->pd);
-					eff->expression = BVM_gen_nodetree_expression(ff_ntree);
+					eff->expression = BVM_gen_forcefield_expression(ff_ntree);
 				}
 				
 				break;
diff --git a/source/blender/blenvm/BVM_api.h b/source/blender/blenvm/BVM_api.h
index 56724a0..50dacfc 100644
--- a/source/blender/blenvm/BVM_api.h
+++ b/source/blender/blenvm/BVM_api.h
@@ -77,7 +77,7 @@ void BVM_eval_forcefield(struct BVMEvalContext *context, struct BVMExpression *e
 
 struct bNodeTree;
 
-struct BVMExpression *BVM_gen_nodetree_expression(struct bNodeTree *ntree);
+struct BVMExpression *BVM_gen_forcefield_expression(struct bNodeTree *ntree);
 
 #ifdef __cplusplus
 }
diff --git a/source/blender/blenvm/CMakeLists.txt b/source/blender/blenvm/CMakeLists.txt
index bc36aa0..762cc10 100644
--- a/source/blender/blenvm/CMakeLists.txt
+++ b/source/blender/blenvm/CMakeLists.txt
@@ -38,6 +38,7 @@ set(INC_SYS
 
 set(SRC
 	intern/bvm_api.cc
+	intern/bvm_codegen.cc
 	intern/bvm_eval.cc
 	intern/bvm_expression.cc
 	intern/bvm_function.cc
@@ -45,6 +46,7 @@ set(SRC
 	intern/bvm_nodegraph.cc
 	intern/bvm_schedule.cc
 
+	intern/bvm_codegen.h
 	intern/bvm_eval.h
 	intern/bvm_expression.h
 	intern/bvm_function.h
diff --git a/source/blender/blenvm/intern/bvm_api.cc b/source/blender/blenvm/intern/bvm_api.cc
index c6beeb0..cc242d2 100644
--- a/source/blender/blenvm/intern/bvm_api.cc
+++ b/source/blender/blenvm/intern/bvm_api.cc
@@ -41,6 +41,7 @@ extern "C" {
 #include "BVM_api.h"
 }
 
+#include "bvm_codegen.h"
 #include "bvm_eval.h"
 #include "bvm_expression.h"
 #include "bvm_function.h"
@@ -99,7 +100,7 @@ void BVM_eval_forcefield(struct BVMEvalContext *ctx, struct BVMExpression *expr,
 
 /* ------------------------------------------------------------------------- */
 
-static void gen_nodetree_nodegraph(bNodeTree *btree, bvm::NodeGraph &graph)
+static void gen_forcefield_nodegraph(bNodeTree *btree, bvm::NodeGraph &graph)
 {
 	for (bNode *bnode = (bNode*)btree->nodes.first; bnode; bnode = bnode->next) {
 		BLI_assert(bnode->typeinfo != NULL);
@@ -117,18 +118,23 @@ static void gen_nodetree_nodegraph(bNodeTree *btree, bvm::NodeGraph &graph)
 		graph.add_link(blink->fromnode->name, blink->fromsock->name,
 		               blink->tonode->name, blink->tosock->name);
 	}
+	
+	{
+		float zero[3] = {0.0f, 0.0f, 0.0f};
+		graph.add_output("force", BVM_FLOAT3, zero);
+		graph.add_output("impulse", BVM_FLOAT3, zero);
+	}
 }
 
-struct BVMExpression *BVM_gen_nodetree_expression(bNodeTree *btree)
+struct BVMExpression *BVM_gen_forcefield_expression(bNodeTree *btree)
 {
 	using namespace bvm;
 	
 	NodeGraph graph;
 	
-	gen_nodetree_nodegraph(btree, graph);
+	gen_forcefield_nodegraph(btree, graph);
 	
-	// XXX TODO call codegen function here to turn nodegraph into an expression
-	Expression *expr = NULL;
+	Expression *expr = codegen_expression(graph);
 	
 	return (BVMExpression *)expr;
 }
diff --git a/source/blender/blenvm/intern/bvm_codegen.cc b/source/blender/blenvm/intern/bvm_codegen.cc
new file mode 100644
index 0000000..206ceef
--- /dev/null
+++ b/source/blender/blenvm/intern/bvm_codegen.cc
@@ -0,0 +1,60 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Lukas Toenne
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file bvm_codegen.cc
+ *  \ingroup bvm
+ */
+
+#include "bvm_codegen.h"
+#include "bvm_expression.h"
+#include "bvm_nodegraph.h"
+
+namespace bvm {
+
+Expression *codegen_expression(const NodeGraph &graph)
+{
+	Expression *expr = new Expression();
+	
+	for (NodeGraph::OutputList::const_iterator it = graph.outputs.begin();
+	     it != graph.outputs.end();
+	     ++it) {
+		const NodeGraphOutput &output = *it;
+		
+		expr->add_return_value(TypeDesc(output.type), output.name);
+	}
+	
+	for (NodeGraph::NodeInstanceMap::const_iterator it = graph.nodes.begin();
+	     it != graph.nodes.end();
+	     ++it) {
+		const NodeInstance &node = it->second;
+		
+	}
+	
+	return expr;
+}
+
+} /* namespace bvm */
diff --git a/source/blender/blenvm/intern/bvm_codegen.h b/source/blender/blenvm/intern/bvm_codegen.h
new file mode 100644
index 0000000..79d6063
--- /dev/null
+++ b/source/blender/blenvm/intern/bvm_codegen.h
@@ -0,0 +1,46 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Lukas Toenne
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#ifndef __BVM_CODEGEN_H__
+#define __BVM_CODEGEN_H__
+
+/** \file bvm_codegen.h
+ *  \ingroup bvm
+ */
+
+#include "bvm_util_string.h"
+
+namespace bvm {
+
+struct Expression;
+struct NodeGraph;
+
+Expression *codegen_expression(const NodeGraph &graph);
+
+} /* namespace bvm */
+
+#endif /* __BVM_CODEGEN_H__ */
diff --git a/source/blender/blenvm/intern/bvm_type_desc.h b/source/blender/blenvm/intern/bvm_type_desc.h
index 293a869..121eb11 100644
--- a/source/blender/blenvm/intern/bvm_type_desc.h
+++ b/source/blender/blenvm/intern/bvm_type_desc.h
@@ -94,8 +94,9 @@ struct ValueType : public Value {
 	{}
 	
 	template <typename T>
-	ValueType(T data)
-	{}
+	ValueType(T data) :
+	    Value(TypeDesc(type))
+	{ (void)data; }
 	
 	const POD &data() const { return m_data; }
 	
@@ -122,9 +123,10 @@ template <typename T>
 Value *Value::create(BVMType type, T data)
 {
 	switch (type) {
-		case BVM_FLOAT: return ValueType<BVM_FLOAT>(data);
-		case BVM_FLOAT3: return ValueType<BVM_FLOAT3>(data);
+		case BVM_FLOAT: return new ValueType<BVM_FLOAT>(data);
+		case BVM_FLOAT3: return new ValueType<BVM_FLOAT3>(data);
 	}
+	return 0;
 }
 
 template <typename T>




More information about the Bf-blender-cvs mailing list