Commit: f7a9d8f4479693f16f1041bd7fc5739b83c64ed5 Author: Jacques Lucke Date: Tue Mar 19 10:40:10 2019 +0100 Branches: functions https://developer.blender.org/rBf7a9d8f4479693f16f1041bd7fc5739b83c64ed5
cleanup Graph generation for Append to List node =================================================================== M source/blender/functions/frontends/data_flow_nodes/builder.cpp M source/blender/functions/frontends/data_flow_nodes/builder.hpp 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 =================================================================== diff --git a/source/blender/functions/frontends/data_flow_nodes/builder.cpp b/source/blender/functions/frontends/data_flow_nodes/builder.cpp index f1ec6faae33..03651d0ca31 100644 --- a/source/blender/functions/frontends/data_flow_nodes/builder.cpp +++ b/source/blender/functions/frontends/data_flow_nodes/builder.cpp @@ -89,14 +89,8 @@ namespace FN { namespace DataFlowNodes { return RNA_struct_find_property(&ptr, "data_type") != NULL; } - SharedType &BuilderContext::type_of_socket(bNodeSocket *bsocket) const + SharedType &BuilderContext::type_by_name(const char *data_type) const { - PointerRNA ptr; - this->get_rna(bsocket, &ptr); - - char data_type[64]; - RNA_string_get(&ptr, "data_type", data_type); - if (STREQ(data_type, "Float")) { return Types::get_float_type(); } @@ -121,6 +115,17 @@ namespace FN { namespace DataFlowNodes { } } + SharedType &BuilderContext::type_of_socket(bNodeSocket *bsocket) const + { + PointerRNA ptr; + this->get_rna(bsocket, &ptr); + + char data_type[64]; + RNA_string_get(&ptr, "data_type", data_type); + + return this->type_by_name(data_type); + } + void BuilderContext::get_rna(bNode *bnode, PointerRNA *ptr) const { RNA_pointer_create( @@ -135,4 +140,13 @@ namespace FN { namespace DataFlowNodes { bsocket, ptr); } + SharedType &BuilderContext::type_from_rna(bNode *bnode, const char *prop_name) const + { + PointerRNA ptr; + this->get_rna(bnode, &ptr); + char type_name[64]; + RNA_string_get(&ptr, prop_name, type_name); + return this->type_by_name(type_name); + } + } } /* namespace FN::DataFlowNodes */ \ No newline at end of file diff --git a/source/blender/functions/frontends/data_flow_nodes/builder.hpp b/source/blender/functions/frontends/data_flow_nodes/builder.hpp index d30cc6cce12..52436e269e2 100644 --- a/source/blender/functions/frontends/data_flow_nodes/builder.hpp +++ b/source/blender/functions/frontends/data_flow_nodes/builder.hpp @@ -48,10 +48,12 @@ namespace FN { namespace DataFlowNodes { ID *btree_id() const; bool is_data_socket(bNodeSocket *bsocket) const; + SharedType &type_by_name(const char *data_type) const; SharedType &type_of_socket(bNodeSocket *bsocket) const; - void get_rna(bNode *node, PointerRNA *ptr) const; + void get_rna(bNode *bnode, PointerRNA *ptr) const; void get_rna(bNodeSocket *bsocket, PointerRNA *ptr) const; + SharedType &type_from_rna(bNode *bnode, const char *prop_name) const; }; } } \ No newline at end of file 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 1f151fb461e..4c415a5cebd 100644 --- a/source/blender/functions/frontends/data_flow_nodes/test_nodes.cpp +++ b/source/blender/functions/frontends/data_flow_nodes/test_nodes.cpp @@ -71,34 +71,13 @@ namespace FN { namespace DataFlowNodes { builder.map_output(min_node->output(0), bnode, 0); } - static SharedFunction &get_function__append(char *base_type) - { - if (STREQ(base_type, "Float")) { - return Functions::append_float(); - } - else if (STREQ(base_type, "Vector")) { - return Functions::append_fvec3(); - } - else if (STREQ(base_type, "Integer")) { - return Functions::append_int32(); - } - else { - BLI_assert(false); - return *(SharedFunction *)nullptr; - } - } - static void insert_append_list_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__append(base_type); + SharedType &base_type = ctx.type_from_rna(bnode, "active_type"); + SharedFunction &fn = Functions::append_to_list(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 1bef40483d1..170f42f36bd 100644 --- a/source/blender/functions/functions/lists.cpp +++ b/source/blender/functions/functions/lists.cpp @@ -7,6 +7,7 @@ namespace FN { namespace Functions { using namespace Types; + using FunctionPerType = SmallMap<SharedType, SharedFunction>; template<typename T> class AppendToList : public TupleCallBody { @@ -38,28 +39,36 @@ namespace FN { namespace Functions { return fn; } - LAZY_INIT_REF__NO_ARG(SharedFunction, append_float) + template<typename T> + void insert_append_to_list_function( + FunctionPerType &functions, + SharedType &base_type, + SharedType &list_type) { - return build_append_function<float>( - "Append Float", - get_float_type(), - get_float_list_type()); + std::string name = "Append " + base_type->name(); + SharedFunction fn = build_append_function<T>(name, base_type, list_type); + functions.add(base_type, fn); } - LAZY_INIT_REF__NO_ARG(SharedFunction, append_fvec3) + FunctionPerType append_to_list_functions; + + LAZY_INIT_REF_STATIC__NO_ARG(FunctionPerType, get_append_to_list_functions) { - return build_append_function<Vector>( - "Append Vector", - get_fvec3_type(), - get_fvec3_list_type()); + FunctionPerType functions; + insert_append_to_list_function<float>( + functions, get_float_type(), get_float_list_type()); + insert_append_to_list_function<Vector>( + functions, get_fvec3_type(), get_fvec3_list_type()); + insert_append_to_list_function<int32_t>( + functions, get_int32_type(), get_int32_list_type()); + return functions; } - LAZY_INIT_REF__NO_ARG(SharedFunction, append_int32) + SharedFunction &append_to_list(SharedType &base_type) { - return build_append_function<int32_t>( - "Append Int32", - get_int32_type(), - get_int32_list_type()); + FunctionPerType &functions = get_append_to_list_functions(); + BLI_assert(functions.contains(base_type)); + return functions.lookup_ref(base_type); } diff --git a/source/blender/functions/functions/lists.hpp b/source/blender/functions/functions/lists.hpp index 647abd08671..8598108f2be 100644 --- a/source/blender/functions/functions/lists.hpp +++ b/source/blender/functions/functions/lists.hpp @@ -4,15 +4,14 @@ namespace FN { namespace Functions { - SharedFunction &append_float(); + SharedFunction &append_to_list(SharedType &base_type); + SharedFunction &get_float_list_element(); SharedFunction &combine_float_lists(); - SharedFunction &append_fvec3(); SharedFunction &get_fvec3_list_element(); SharedFunction &combine_fvec3_lists(); - SharedFunction &append_int32(); SharedFunction &get_int32_list_element(); SharedFunction &combine_int32_lists(); _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org https://lists.blender.org/mailman/listinfo/bf-blender-cvs