[Bf-blender-cvs] [630d32b1590] functions-experimental-refactor: new socket type mapping

Jacques Lucke noreply at git.blender.org
Tue Oct 15 15:57:16 CEST 2019


Commit: 630d32b15905807d1a0f67ad326416bb60b9dfca
Author: Jacques Lucke
Date:   Sun Oct 13 12:03:08 2019 +0200
Branches: functions-experimental-refactor
https://developer.blender.org/rB630d32b15905807d1a0f67ad326416bb60b9dfca

new socket type mapping

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

A	source/blender/blenkernel/BKE_function_nodes_data_types.h
M	source/blender/blenkernel/BKE_virtual_node_tree_cxx.h
M	source/blender/blenkernel/CMakeLists.txt
A	source/blender/blenkernel/intern/function_nodes_data_types.cc
M	source/blender/blenlib/BLI_math_cxx.h

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

diff --git a/source/blender/blenkernel/BKE_function_nodes_data_types.h b/source/blender/blenkernel/BKE_function_nodes_data_types.h
new file mode 100644
index 00000000000..9d3a02ac1b7
--- /dev/null
+++ b/source/blender/blenkernel/BKE_function_nodes_data_types.h
@@ -0,0 +1,31 @@
+#ifndef __BKE_VIRTUAL_NODE_TREE_DATA_FLOW_H__
+#define __BKE_VIRTUAL_NODE_TREE_DATA_FLOW_H__
+
+#include "BKE_cpp_types.h"
+
+#include "BLI_string_map.h"
+
+namespace BKE {
+
+using BLI::StringMap;
+
+enum DataTypeCategory {
+  Single,
+  List,
+};
+
+struct SocketDataType {
+  CPPType *type;
+  DataTypeCategory category;
+
+  static SocketDataType none_type()
+  {
+    return {nullptr, DataTypeCategory::Single};
+  }
+};
+
+StringMap<SocketDataType> &get_function_nodes_data_types();
+
+};  // namespace BKE
+
+#endif /* __BKE_VIRTUAL_NODE_TREE_DATA_FLOW_H__ */
diff --git a/source/blender/blenkernel/BKE_virtual_node_tree_cxx.h b/source/blender/blenkernel/BKE_virtual_node_tree_cxx.h
index 3291fc49ae6..3bb9da4b00e 100644
--- a/source/blender/blenkernel/BKE_virtual_node_tree_cxx.h
+++ b/source/blender/blenkernel/BKE_virtual_node_tree_cxx.h
@@ -30,6 +30,7 @@
 #include "BLI_listbase_wrapper.h"
 #include "BLI_multi_map.h"
 #include "BLI_monotonic_allocator.h"
+#include "BLI_string_map.h"
 
 #include "RNA_access.h"
 
@@ -41,6 +42,7 @@ using BLI::Map;
 using BLI::MonotonicAllocator;
 using BLI::MultiMap;
 using BLI::MutableArrayRef;
+using BLI::StringMap;
 using BLI::StringRef;
 using BLI::StringRefNull;
 using BLI::Vector;
@@ -97,11 +99,27 @@ class VirtualNodeTree {
     return m_frozen;
   }
 
-  uint socket_count()
+  uint socket_count() const
   {
     return m_socket_counter;
   }
 
+  template<typename T>
+  void map_socket_idnames(const StringMap<T> &map,
+                          const T &default_value,
+                          MutableArrayRef<T> r_result) const
+  {
+    BLI_assert(r_result.size() == this->socket_count());
+    for (const VirtualNode *vnode : m_nodes) {
+      for (const VirtualSocket *vsocket : vnode->m_inputs) {
+        r_result[vsocket->m_id] = map.lookup_default(vsocket->idname(), default_value);
+      }
+      for (const VirtualSocket *vsocket : vnode->m_outputs) {
+        r_result[vsocket->m_id] = map.lookup_default(vsocket->idname(), default_value);
+      }
+    }
+  }
+
  private:
   void initialize_direct_links();
   void initialize_links();
@@ -170,7 +188,7 @@ class VirtualNode {
     return m_bnode->name;
   }
 
-  StringRefNull idname()
+  StringRefNull idname() const
   {
     return m_bnode->idname;
   }
@@ -243,17 +261,17 @@ class VirtualSocket {
     return rna;
   }
 
-  StringRefNull name()
+  StringRefNull name() const
   {
     return m_bsocket->name;
   }
 
-  StringRefNull idname()
+  StringRefNull idname() const
   {
     return m_bsocket->idname;
   }
 
-  StringRefNull identifier()
+  StringRefNull identifier() const
   {
     return m_bsocket->identifier;
   }
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index aef6a3c1225..60e4bb500c1 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -120,6 +120,7 @@ set(SRC
   intern/fmodifier.c
   intern/font.c
   intern/freestyle.c
+  intern/function_nodes_data_types.cc
   intern/cpp_function.cc
   intern/generic_array_ref.cc
   intern/gpencil.c
diff --git a/source/blender/blenkernel/intern/function_nodes_data_types.cc b/source/blender/blenkernel/intern/function_nodes_data_types.cc
new file mode 100644
index 00000000000..716c1ba2f5a
--- /dev/null
+++ b/source/blender/blenkernel/intern/function_nodes_data_types.cc
@@ -0,0 +1,34 @@
+#include "BLI_lazy_init_cxx.h"
+#include "BLI_math_cxx.h"
+
+#include "BKE_function_nodes_data_types.h"
+
+#include "DNA_object_types.h"
+
+namespace BKE {
+
+void insert_single_and_list_type(StringMap<SocketDataType> &types, StringRef name, CPPType &type)
+{
+  std::string base_idname = "fn_" + name + "Socket";
+  std::string list_idname = "fn_" + name + "ListSocket";
+
+  types.add_new(base_idname, {&type, DataTypeCategory::Single});
+  types.add_new(list_idname, {&type, DataTypeCategory::List});
+}
+
+BLI_LAZY_INIT(StringMap<SocketDataType>, get_function_nodes_data_types)
+{
+  StringMap<SocketDataType> types;
+
+  insert_single_and_list_type(types, "Boolean", GET_TYPE<bool>());
+  insert_single_and_list_type(types, "Color", GET_TYPE<BLI::rgba_f>());
+  insert_single_and_list_type(types, "Float", GET_TYPE<float>());
+  insert_single_and_list_type(types, "Integer", GET_TYPE<int32_t>());
+  insert_single_and_list_type(types, "Object", GET_TYPE<Object *>());
+  insert_single_and_list_type(types, "Text", GET_TYPE<std::string>());
+  insert_single_and_list_type(types, "Vector", GET_TYPE<BLI::float3>());
+
+  return types;
+}
+
+}  // namespace BKE
\ No newline at end of file
diff --git a/source/blender/blenlib/BLI_math_cxx.h b/source/blender/blenlib/BLI_math_cxx.h
index 3f4e8e8914c..925cb09cbcd 100644
--- a/source/blender/blenlib/BLI_math_cxx.h
+++ b/source/blender/blenlib/BLI_math_cxx.h
@@ -25,6 +25,7 @@
 
 #include <array>
 
+#include "BLI_array_ref.h"
 #include "BLI_math_vector.h"
 #include "BLI_math_matrix.h"



More information about the Bf-blender-cvs mailing list