Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacques Lucke <jacques@blender.org>2020-05-05 16:13:02 +0300
committerJacques Lucke <jacques@blender.org>2020-05-05 16:13:02 +0300
commit925166bed600fc418c7b9abef7194396b110458c (patch)
tree439ab34ec58f0bbbb32be0e7261d0dcfe02f285a
parentdd1a90353be9870fa37f10a379a197e6eeab982e (diff)
continue with derived node treenode-tree-ref
-rw-r--r--source/blender/blenkernel/BKE_derived_node_tree.hh18
-rw-r--r--source/blender/blenkernel/BKE_node_tree_ref.hh5
-rw-r--r--source/blender/blenkernel/intern/derived_node_tree.cc79
-rw-r--r--source/blender/blenlib/BLI_linear_allocator.hh2
4 files changed, 96 insertions, 8 deletions
diff --git a/source/blender/blenkernel/BKE_derived_node_tree.hh b/source/blender/blenkernel/BKE_derived_node_tree.hh
index 71e699aeaaa..535bde5a314 100644
--- a/source/blender/blenkernel/BKE_derived_node_tree.hh
+++ b/source/blender/blenkernel/BKE_derived_node_tree.hh
@@ -33,7 +33,6 @@ class DSocket : BLI::NonCopyable, BLI::NonMovable {
protected:
DNode *m_node;
const SocketRef *m_socket_ref;
- bool m_is_input;
uint m_id;
friend DerivedNodeTree;
@@ -104,8 +103,8 @@ class DNode : BLI::NonCopyable, BLI::NonMovable {
const NodeRef *m_node_ref;
DParentNode *m_parent;
- Vector<DInputSocket *> m_inputs;
- Vector<DOutputSocket *> m_outputs;
+ MutableArrayRef<DInputSocket *> m_inputs;
+ MutableArrayRef<DOutputSocket *> m_outputs;
uint m_id;
@@ -163,6 +162,15 @@ class DerivedNodeTree : BLI::NonCopyable, BLI::NonMovable {
~DerivedNodeTree();
ArrayRef<const DNode *> all_nodes() const;
+
+ private:
+ /* Utility functions used during construction. */
+ void insert_nodes_and_links_in_id_order(const NodeTreeRef &tree_ref,
+ DParentNode *parent,
+ Vector<DNode *> &r_nodes);
+ DNode &create_node(const NodeRef &node_ref,
+ DParentNode *parent,
+ MutableArrayRef<DSocket *> r_sockets_map);
};
/* --------------------------------------------------------------------
@@ -186,12 +194,12 @@ inline uint DSocket::index() const
inline bool DSocket::is_input() const
{
- return m_is_input;
+ return m_socket_ref->is_input();
}
inline bool DSocket::is_output() const
{
- return !m_is_input;
+ return m_socket_ref->is_output();
}
inline const DSocket &DSocket::as_base() const
diff --git a/source/blender/blenkernel/BKE_node_tree_ref.hh b/source/blender/blenkernel/BKE_node_tree_ref.hh
index d9a9232906d..d48dbb3d60a 100644
--- a/source/blender/blenkernel/BKE_node_tree_ref.hh
+++ b/source/blender/blenkernel/BKE_node_tree_ref.hh
@@ -17,6 +17,7 @@
#ifndef __BKE_NODE_TREE_REF_HH__
#define __BKE_NODE_TREE_REF_HH__
+#include "BLI_array.hh"
#include "BLI_linear_allocator.hh"
#include "BLI_map.hh"
#include "BLI_string_map.hh"
@@ -32,9 +33,11 @@
namespace BKE {
+using BLI::Array;
using BLI::ArrayRef;
using BLI::LinearAllocator;
using BLI::Map;
+using BLI::MutableArrayRef;
using BLI::StringMap;
using BLI::StringRef;
using BLI::StringRefNull;
@@ -158,7 +161,7 @@ class NodeTreeRef : BLI::NonCopyable, BLI::NonMovable {
std::string to_dot() const;
private:
- /* Utility functions used by constructor. */
+ /* Utility functions used during construction. */
InputSocketRef &find_input_socket(Map<bNode *, NodeRef *> &node_mapping,
bNode *bnode,
bNodeSocket *bsocket);
diff --git a/source/blender/blenkernel/intern/derived_node_tree.cc b/source/blender/blenkernel/intern/derived_node_tree.cc
index 7a0896a1f17..cebe4446a02 100644
--- a/source/blender/blenkernel/intern/derived_node_tree.cc
+++ b/source/blender/blenkernel/intern/derived_node_tree.cc
@@ -16,10 +16,87 @@
#include "BKE_derived_node_tree.hh"
+#define UNINITIALIZED_ID UINT32_MAX
+
namespace BKE {
-DerivedNodeTree::DerivedNodeTree(bNodeTree *UNUSED(btree), NodeTreeRefMap &UNUSED(node_tree_refs))
+static const NodeTreeRef &get_tree_ref(NodeTreeRefMap &node_tree_refs, bNodeTree *btree)
+{
+ return *node_tree_refs.lookup_or_add(btree,
+ [&]() { return BLI::make_unique<NodeTreeRef>(btree); });
+}
+
+DerivedNodeTree::DerivedNodeTree(bNodeTree *btree, NodeTreeRefMap &node_tree_refs)
+{
+ const NodeTreeRef &main_tree_ref = get_tree_ref(node_tree_refs, btree);
+
+ Vector<DNode *> all_nodes;
+
+ this->insert_nodes_and_links_in_id_order(main_tree_ref, nullptr, all_nodes);
+}
+
+void DerivedNodeTree::insert_nodes_and_links_in_id_order(const NodeTreeRef &tree_ref,
+ DParentNode *parent,
+ Vector<DNode *> &r_nodes)
+{
+ Array<DSocket *, 64> sockets_map(tree_ref.sockets().size());
+
+ /* Insert nodes. */
+ for (const NodeRef *node_ref : tree_ref.nodes()) {
+ DNode &node = this->create_node(*node_ref, parent, sockets_map);
+ r_nodes.append(&node);
+ }
+
+ /* Insert links. */
+ for (const NodeRef *node_ref : tree_ref.nodes()) {
+ for (const InputSocketRef *to_socket_ref : node_ref->inputs()) {
+ DInputSocket *to_socket = (DInputSocket *)sockets_map[to_socket_ref->id()];
+ for (const OutputSocketRef *from_socket_ref : to_socket_ref->linked_sockets()) {
+ DOutputSocket *from_socket = (DOutputSocket *)sockets_map[from_socket_ref->id()];
+ to_socket->m_linked_sockets.append(from_socket);
+ from_socket->m_linked_sockets.append(to_socket);
+ }
+ }
+ }
+}
+
+DNode &DerivedNodeTree::create_node(const NodeRef &node_ref,
+ DParentNode *parent,
+ MutableArrayRef<DSocket *> r_sockets_map)
{
+ DNode &node = *m_allocator.construct<DNode>();
+ node.m_node_ref = &node_ref;
+ node.m_parent = parent;
+ node.m_id = UNINITIALIZED_ID;
+
+ node.m_inputs = m_allocator.construct_elements_and_pointer_array<DInputSocket>(
+ node_ref.inputs().size());
+ node.m_outputs = m_allocator.construct_elements_and_pointer_array<DOutputSocket>(
+ node_ref.outputs().size());
+
+ for (uint i : node.m_inputs.index_range()) {
+ const InputSocketRef &socket_ref = node_ref.input(i);
+ DInputSocket &socket = *node.m_inputs[i];
+
+ socket.m_id = UNINITIALIZED_ID;
+ socket.m_node = &node;
+ socket.m_socket_ref = &socket_ref;
+
+ r_sockets_map[socket_ref.id()] = &socket;
+ }
+
+ for (uint i : node.m_outputs.index_range()) {
+ const OutputSocketRef &socket_ref = node_ref.output(i);
+ DOutputSocket &socket = *node.m_outputs[i];
+
+ socket.m_id = UNINITIALIZED_ID;
+ socket.m_node = &node;
+ socket.m_socket_ref = &socket_ref;
+
+ r_sockets_map[socket_ref.id()] = &socket;
+ }
+
+ return node;
}
DerivedNodeTree::~DerivedNodeTree()
diff --git a/source/blender/blenlib/BLI_linear_allocator.hh b/source/blender/blenlib/BLI_linear_allocator.hh
index cebf878580c..f93769eca8b 100644
--- a/source/blender/blenlib/BLI_linear_allocator.hh
+++ b/source/blender/blenlib/BLI_linear_allocator.hh
@@ -120,7 +120,7 @@ template<typename Allocator = GuardedAllocator> class LinearAllocator : NonCopya
}
template<typename T, typename... Args>
- ArrayRef<T *> construct_elements_and_pointer_array(uint n, Args &&... args)
+ MutableArrayRef<T *> construct_elements_and_pointer_array(uint n, Args &&... args)
{
void *pointer_buffer = this->allocate(n * sizeof(T *), alignof(T *));
void *element_buffer = this->allocate(n * sizeof(T), alignof(T));