[Bf-blender-cvs] [882ce6812fe] functions: cleanup graph generation for combine lists and get list element

Jacques Lucke noreply at git.blender.org
Tue Mar 19 11:08:00 CET 2019


Commit: 882ce6812fe4dc1487b16e6067d576c589461f56
Author: Jacques Lucke
Date:   Tue Mar 19 10:51:46 2019 +0100
Branches: functions
https://developer.blender.org/rB882ce6812fe4dc1487b16e6067d576c589461f56

cleanup graph generation for combine lists and get list element

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

M	source/blender/functions/frontends/data_flow_nodes/test_nodes.cpp
M	source/blender/functions/functions/lists.cpp
M	source/blender/functions/functions/lists.hpp
M	source/blender/functions/types/numeric.cpp

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

diff --git a/source/blender/functions/frontends/data_flow_nodes/test_nodes.cpp b/source/blender/functions/frontends/data_flow_nodes/test_nodes.cpp
index 4c415a5cebd..a355f3d75ca 100644
--- a/source/blender/functions/frontends/data_flow_nodes/test_nodes.cpp
+++ b/source/blender/functions/frontends/data_flow_nodes/test_nodes.cpp
@@ -82,66 +82,24 @@ namespace FN { namespace DataFlowNodes {
 		builder.map_sockets(node, bnode);
 	}
 
-	static SharedFunction &get_function__get_list_element(char *base_type)
-	{
-		if (STREQ(base_type, "Float")) {
-			return Functions::get_float_list_element();
-		}
-		else if (STREQ(base_type, "Vector")) {
-			return Functions::get_fvec3_list_element();
-		}
-		else if (STREQ(base_type, "Integer")) {
-			return Functions::get_int32_list_element();
-		}
-		else {
-			BLI_assert(false);
-			return *(SharedFunction *)nullptr;
-		}
-	}
-
 	static void insert_get_list_element_node(
 		Builder &builder,
 		const BuilderContext ctx,
 		bNode *bnode)
 	{
-		PointerRNA ptr;
-		ctx.get_rna(bnode, &ptr);
-		char base_type[64];
-		RNA_string_get(&ptr, "active_type", base_type);
-
-		SharedFunction &fn = get_function__get_list_element(base_type);
+		SharedType &base_type = ctx.type_from_rna(bnode, "active_type");
+		SharedFunction &fn = Functions::get_list_element(base_type);
 		Node *node = builder.insert_function(fn);
 		builder.map_sockets(node, bnode);
 	}
 
-	static SharedFunction &get_function__combine_lists(char *base_type)
-	{
-		if (STREQ(base_type, "Float")) {
-			return Functions::combine_float_lists();
-		}
-		else if (STREQ(base_type, "Vector")) {
-			return Functions::combine_fvec3_lists();
-		}
-		else if (STREQ(base_type, "Integer")) {
-			return Functions::combine_int32_lists();
-		}
-		else {
-			BLI_assert(false);
-			return *(SharedFunction *)nullptr;
-		}
-	}
-
 	static void insert_combine_lists_node(
 		Builder &builder,
 		const BuilderContext ctx,
 		bNode *bnode)
 	{
-		PointerRNA ptr;
-		ctx.get_rna(bnode, &ptr);
-		char base_type[64];
-		RNA_string_get(&ptr, "active_type", base_type);
-
-		SharedFunction &fn = get_function__combine_lists(base_type);
+		SharedType &base_type = ctx.type_from_rna(bnode, "active_type");
+		SharedFunction &fn = Functions::combine_lists(base_type);
 		Node *node = builder.insert_function(fn);
 		builder.map_sockets(node, bnode);
 	}
diff --git a/source/blender/functions/functions/lists.cpp b/source/blender/functions/functions/lists.cpp
index 170f42f36bd..4c11248bf5b 100644
--- a/source/blender/functions/functions/lists.cpp
+++ b/source/blender/functions/functions/lists.cpp
@@ -50,8 +50,6 @@ namespace FN { namespace Functions {
 		functions.add(base_type, fn);
 	}
 
-	FunctionPerType append_to_list_functions;
-
 	LAZY_INIT_REF_STATIC__NO_ARG(FunctionPerType, get_append_to_list_functions)
 	{
 		FunctionPerType functions;
@@ -108,31 +106,36 @@ namespace FN { namespace Functions {
 		return fn;
 	}
 
-	LAZY_INIT_REF__NO_ARG(SharedFunction, get_float_list_element)
+	template<typename T>
+	void insert_get_element_function(
+		FunctionPerType &functions,
+		SharedType &base_type,
+		SharedType &list_type)
 	{
-		return build_get_element_function<float>(
-			"Get Float List Element",
-			get_float_type(),
-			get_float_list_type());
+		std::string name = "Get " + base_type->name() + " List Element";
+		SharedFunction fn = build_get_element_function<T>(name, base_type, list_type);
+		functions.add(base_type, fn);
 	}
 
-	LAZY_INIT_REF__NO_ARG(SharedFunction, get_fvec3_list_element)
+	LAZY_INIT_REF_STATIC__NO_ARG(FunctionPerType, get_get_element_functions)
 	{
-		return build_get_element_function<Vector>(
-			"Get Vector List Element",
-			get_fvec3_type(),
-			get_fvec3_list_type());
+		FunctionPerType functions;
+		insert_get_element_function<float>(
+			functions, get_float_type(), get_float_list_type());
+		insert_get_element_function<Vector>(
+			functions, get_fvec3_type(), get_fvec3_list_type());
+		insert_get_element_function<int32_t>(
+			functions, get_int32_type(), get_int32_list_type());
+		return functions;
 	}
 
-	LAZY_INIT_REF__NO_ARG(SharedFunction, get_int32_list_element)
+	SharedFunction &get_list_element(SharedType &base_type)
 	{
-		return build_get_element_function<int32_t>(
-			"Get Int32 List Element",
-			get_int32_type(),
-			get_int32_list_type());
+		FunctionPerType &functions = get_get_element_functions();
+		BLI_assert(functions.contains(base_type));
+		return functions.lookup_ref(base_type);
 	}
 
-
 	template<typename T>
 	class CombineLists : public TupleCallBody {
 		void call(Tuple &fn_in, Tuple &fn_out) const override
@@ -158,29 +161,38 @@ namespace FN { namespace Functions {
 		}, {
 			OutputParameter("List", list_type),
 		}));
-		fn->add_body(new CombineLists<float>());
+		fn->add_body(new CombineLists<T>());
 		return fn;
 	}
 
-	LAZY_INIT_REF__NO_ARG(SharedFunction, combine_float_lists)
+	template<typename T>
+	void insert_combine_lists_function(
+		FunctionPerType &functions,
+		SharedType &base_type,
+		SharedType &list_type)
 	{
-		return build_combine_lists_function<float>(
-			"Combine Float Lists",
-			get_float_list_type());
+		std::string name = "Combine " + base_type->name() + " Lists";
+		SharedFunction fn = build_combine_lists_function<T>(name, list_type);
+		functions.add(base_type, fn);
 	}
 
-	LAZY_INIT_REF__NO_ARG(SharedFunction, combine_fvec3_lists)
+	LAZY_INIT_REF_STATIC__NO_ARG(FunctionPerType, get_combine_lists_function)
 	{
-		return build_combine_lists_function<Vector>(
-			"Combine Vector Lists",
-			get_fvec3_list_type());
+		FunctionPerType functions;
+		insert_combine_lists_function<float>(
+			functions, get_float_type(), get_float_list_type());
+		insert_combine_lists_function<Vector>(
+			functions, get_fvec3_type(), get_fvec3_list_type());
+		insert_combine_lists_function<int32_t>(
+			functions, get_int32_type(), get_int32_list_type());
+		return functions;
 	}
 
-	LAZY_INIT_REF__NO_ARG(SharedFunction, combine_int32_lists)
+	SharedFunction &combine_lists(SharedType &base_type)
 	{
-		return build_combine_lists_function<int32_t>(
-			"Combine Int32 Lists",
-			get_int32_list_type());
+		FunctionPerType &functions = get_combine_lists_function();
+		BLI_assert(functions.contains(base_type));
+		return functions.lookup_ref(base_type);
 	}
 
 } } /* namespace FN::Functions */
\ No newline at end of file
diff --git a/source/blender/functions/functions/lists.hpp b/source/blender/functions/functions/lists.hpp
index 8598108f2be..922f53b2af2 100644
--- a/source/blender/functions/functions/lists.hpp
+++ b/source/blender/functions/functions/lists.hpp
@@ -5,14 +5,7 @@
 namespace FN { namespace Functions {
 
 	SharedFunction &append_to_list(SharedType &base_type);
-
-	SharedFunction &get_float_list_element();
-	SharedFunction &combine_float_lists();
-
-	SharedFunction &get_fvec3_list_element();
-	SharedFunction &combine_fvec3_lists();
-
-	SharedFunction &get_int32_list_element();
-	SharedFunction &combine_int32_lists();
+	SharedFunction &get_list_element(SharedType &base_type);
+	SharedFunction &combine_lists(SharedType &base_type);
 
 } } /* namespace FN::Functions */
\ No newline at end of file
diff --git a/source/blender/functions/types/numeric.cpp b/source/blender/functions/types/numeric.cpp
index e116cc2e982..9d4b2f61efe 100644
--- a/source/blender/functions/types/numeric.cpp
+++ b/source/blender/functions/types/numeric.cpp
@@ -28,7 +28,7 @@ namespace FN { namespace Types {
 
 	LAZY_INIT_REF__NO_ARG(SharedType, get_fvec3_type)
 	{
-		SharedType type = SharedType::New("FloatVector3D");
+		SharedType type = SharedType::New("FVec3");
 		type->extend(new CPPTypeInfoForType<Vector>());
 		type->extend(new SimpleLLVMTypeInfo([](llvm::LLVMContext &context) {
 			llvm::Type *base = llvm::Type::getFloatTy(context);



More information about the Bf-blender-cvs mailing list