[Bf-blender-cvs] [456cb215c69] simulation-tree: initial C++ node builder
Jacques Lucke
noreply at git.blender.org
Mon Feb 17 18:16:14 CET 2020
Commit: 456cb215c6997e9400ed1a40c92ed3c30a40b85f
Author: Jacques Lucke
Date: Mon Feb 17 14:00:27 2020 +0100
Branches: simulation-tree
https://developer.blender.org/rB456cb215c6997e9400ed1a40c92ed3c30a40b85f
initial C++ node builder
===================================================================
M source/blender/simulations/nodes/my_test_node.cc
===================================================================
diff --git a/source/blender/simulations/nodes/my_test_node.cc b/source/blender/simulations/nodes/my_test_node.cc
index 5c3b4e17b39..789ea1f9fc0 100644
--- a/source/blender/simulations/nodes/my_test_node.cc
+++ b/source/blender/simulations/nodes/my_test_node.cc
@@ -6,7 +6,9 @@
#include "BLI_vector.h"
#include "BLI_string_ref.h"
#include "BLI_set.h"
+#include "BLI_linear_allocator.h"
+using BLI::LinearAllocator;
using BLI::Set;
using BLI::StringRef;
using BLI::StringRefNull;
@@ -126,18 +128,74 @@ class FixedTypeSocketDecl : public SocketDecl {
};
class NodeDecl {
- private:
+ public:
+ bNodeTree &m_ntree;
+ bNode &m_node;
Vector<SocketDecl *> m_inputs;
Vector<SocketDecl *> m_outputs;
+
+ NodeDecl(bNodeTree &ntree, bNode &node) : m_ntree(ntree), m_node(node)
+ {
+ }
+
+ void build() const
+ {
+ for (SocketDecl *decl : m_inputs) {
+ decl->build();
+ }
+ for (SocketDecl *decl : m_outputs) {
+ decl->build();
+ }
+ }
+};
+
+class NodeBuilder {
+ private:
+ LinearAllocator<> &m_allocator;
+ NodeDecl &m_node_decl;
+
+ public:
+ NodeBuilder(LinearAllocator<> &allocator, NodeDecl &node_decl)
+ : m_allocator(allocator), m_node_decl(node_decl)
+ {
+ }
+
+ void fixed_input(StringRef identifier, StringRef ui_name, SocketDataType &type)
+ {
+ FixedTypeSocketDecl *decl = m_allocator.construct<FixedTypeSocketDecl>(
+ m_node_decl.m_ntree,
+ m_node_decl.m_node,
+ SOCK_IN,
+ type,
+ m_allocator.copy_string(ui_name),
+ m_allocator.copy_string(identifier));
+ m_node_decl.m_inputs.append(decl);
+ }
+
+ void fixed_output(StringRef identifier, StringRef ui_name, SocketDataType &type)
+ {
+ FixedTypeSocketDecl *decl = m_allocator.construct<FixedTypeSocketDecl>(
+ m_node_decl.m_ntree,
+ m_node_decl.m_node,
+ SOCK_OUT,
+ type,
+ m_allocator.copy_string(ui_name),
+ m_allocator.copy_string(identifier));
+ m_node_decl.m_outputs.append(decl);
+ }
};
static void init_node(bNodeTree *ntree, bNode *node)
{
- FixedTypeSocketDecl decl1{*ntree, *node, SOCK_IN, *float_socket_type, "Hello 1", "hey"};
- FixedTypeSocketDecl decl2{*ntree, *node, SOCK_IN, *int_socket_type, "Hello 2", "qwe"};
+ LinearAllocator<> allocator;
+ NodeDecl node_decl{*ntree, *node};
+ NodeBuilder node_builder{allocator, node_decl};
+
+ node_builder.fixed_input("id1", "ID 1", *float_socket_type);
+ node_builder.fixed_input("id2", "ID 2", *int_socket_type);
+ node_builder.fixed_output("id3", "ID 3", *float_socket_type);
- decl1.build();
- decl2.build();
+ node_decl.build();
}
void register_node_type_my_test_node()
More information about the Bf-blender-cvs
mailing list