Commit: df9f633da2f505d94018a628d4e31e6e3a3cf12e
Author: Lukas Tönne
Date:   Wed Nov 25 09:09:30 2015 +0100
Branches: object_nodes
https://developer.blender.org/rBdf9f633da2f505d94018a628d4e31e6e3a3cf12e

Changed node instance storage in the node graph to pointers.

This makes it much easier to optimize the graph by removing and reconnecting 
nodes.

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

M       source/blender/blenvm/compile/bvm_codegen.cc
M       source/blender/blenvm/compile/bvm_nodegraph.cc
M       source/blender/blenvm/compile/bvm_nodegraph.h

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

diff --git a/source/blender/blenvm/compile/bvm_codegen.cc 
b/source/blender/blenvm/compile/bvm_codegen.cc
index 0dc1961..1dcbf3e 100644
--- a/source/blender/blenvm/compile/bvm_codegen.cc
+++ b/source/blender/blenvm/compile/bvm_codegen.cc
@@ -292,7 +292,7 @@ static void sort_nodes(const NodeGraph &graph, NodeList 
&result)
        NodeSet visited;
        
        for (NodeGraph::NodeInstanceMap::const_iterator it = 
graph.nodes.begin(); it != graph.nodes.end(); ++it) {
-               sort_nodes_append(&it->second, result, visited);
+               sort_nodes_append(it->second, result, visited);
        }
 }
 
@@ -302,24 +302,24 @@ static void count_output_users(const NodeGraph &graph, 
SocketUserMap &users)
 {
        users.clear();
        for (NodeGraph::NodeInstanceMap::const_iterator it = 
graph.nodes.begin(); it != graph.nodes.end(); ++it) {
-               const NodeInstance &node = it->second;
-               for (int i = 0; i < node.num_outputs(); ++i) {
-                       ConstSocketPair key(&node, node.type->outputs[i].name);
+               const NodeInstance *node = it->second;
+               for (int i = 0; i < node->num_outputs(); ++i) {
+                       ConstSocketPair key(node, node->type->outputs[i].name);
                        users[key] = 0;
                }
        }
        
        for (NodeGraph::NodeInstanceMap::const_iterator it = 
graph.nodes.begin(); it != graph.nodes.end(); ++it) {
-               const NodeInstance &node = it->second;
+               const NodeInstance *node = it->second;
                
                /* note: pass nodes are normally removed, but can exist for 
debugging purposes */
-               if (node.type->is_pass)
+               if (node->type->is_pass)
                        continue;
                
-               for (int i = 0; i < node.num_inputs(); ++i) {
-                       if (node.has_input_link(i)) {
-                               ConstSocketPair 
key(node.find_input_link_node(i),
-                                                   
node.find_input_link_socket(i)->name);
+               for (int i = 0; i < node->num_inputs(); ++i) {
+                       if (node->has_input_link(i)) {
+                               ConstSocketPair 
key(node->find_input_link_node(i),
+                                                   
node->find_input_link_socket(i)->name);
                                users[key] += 1;
                        }
                }
diff --git a/source/blender/blenvm/compile/bvm_nodegraph.cc 
b/source/blender/blenvm/compile/bvm_nodegraph.cc
index 1bdd965..a85491e 100644
--- a/source/blender/blenvm/compile/bvm_nodegraph.cc
+++ b/source/blender/blenvm/compile/bvm_nodegraph.cc
@@ -421,12 +421,13 @@ NodeGraph::NodeGraph()
 
 NodeGraph::~NodeGraph()
 {
+       remove_all_nodes();
 }
 
 NodeInstance *NodeGraph::get_node(const string &name)
 {
        NodeInstanceMap::iterator it = nodes.find(name);
-       return (it != nodes.end())? &it->second : NULL;
+       return (it != nodes.end())? it->second : NULL;
 }
 
 NodeInstance *NodeGraph::add_node(const string &type, const string &name)
@@ -446,10 +447,11 @@ NodeInstance *NodeGraph::add_node(const string &type, 
const string &name)
                final = ss.str();
        }
        
+       NodeInstance *node = new NodeInstance(nodetype, final);
        std::pair<NodeInstanceMap::iterator, bool> result =
-               nodes.insert(NodeInstanceMapPair(final, NodeInstance(nodetype, 
final)));
+               nodes.insert(NodeInstanceMapPair(final, node));
        
-       return (result.second)? &result.first->second : NULL;
+       return (result.second)? result.first->second : NULL;
 }
 
 const NodeGraphInput *NodeGraph::get_input(int index) const
@@ -650,17 +652,25 @@ SocketPair NodeGraph::add_type_converter(const SocketPair 
&from, const TypeDesc
 /* ------------------------------------------------------------------------- */
 /* Optimization */
 
+void NodeGraph::remove_all_nodes()
+{
+       for (NodeInstanceMap::iterator it = nodes.begin(); it != nodes.end(); 
++it) {
+               delete it->second;
+       }
+       nodes.clear();
+}
+
 void NodeGraph::skip_pass_nodes()
 {
        /* redirect links to skip over 'pass'-type nodes */
        for (NodeInstanceMap::iterator it = nodes.begin(); it != nodes.end(); 
++it) {
-               NodeInstance &node = it->second;
+               NodeInstance *node = it->second;
                
-               if (node.type->is_pass)
+               if (node->type->is_pass)
                        continue;
                
-               for (NodeInstance::InputMap::iterator it_input = 
node.inputs.begin();
-                    it_input != node.inputs.end();
+               for (NodeInstance::InputMap::iterator it_input = 
node->inputs.begin();
+                    it_input != node->inputs.end();
                     ++it_input) {
                        NodeInstance::InputInstance &input = it_input->second;
                        
@@ -705,7 +715,7 @@ void NodeGraph::dump(std::ostream &s)
        s << "NodeGraph\n";
        
        for (NodeInstanceMap::const_iterator it = nodes.begin(); it != 
nodes.end(); ++it) {
-               const NodeInstance *node = &it->second;
+               const NodeInstance *node = it->second;
                const NodeType *type = node->type;
                s << "  Node '" << node->name << "'\n";
                
@@ -973,7 +983,7 @@ void NodeGraph::dump_graphviz(FILE *f, const string &label)
        debug_fprintf(ctx, "];" NL);
 
        for (NodeInstanceMap::const_iterator it = nodes.begin(); it != 
nodes.end(); ++it) {
-               const NodeInstance *node = &it->second;
+               const NodeInstance *node = it->second;
                debug_graphviz_node(ctx, node);
        }
        
@@ -987,7 +997,7 @@ void NodeGraph::dump_graphviz(FILE *f, const string &label)
        }
        
        for (NodeInstanceMap::const_iterator it = nodes.begin(); it != 
nodes.end(); ++it) {
-               const NodeInstance *node = &it->second;
+               const NodeInstance *node = it->second;
                debug_graphviz_node_links(ctx, node);
        }
        for (OutputList::const_iterator it = outputs.begin(); it != 
outputs.end(); ++it) {
diff --git a/source/blender/blenvm/compile/bvm_nodegraph.h 
b/source/blender/blenvm/compile/bvm_nodegraph.h
index 76fe30d..4bf66d4 100644
--- a/source/blender/blenvm/compile/bvm_nodegraph.h
+++ b/source/blender/blenvm/compile/bvm_nodegraph.h
@@ -277,8 +277,8 @@ struct NodeGraph {
        
        typedef std::map<string, NodeType> NodeTypeMap;
        typedef std::pair<string, NodeType> NodeTypeMapPair;
-       typedef std::map<string, NodeInstance> NodeInstanceMap;
-       typedef std::pair<string, NodeInstance> NodeInstanceMapPair;
+       typedef std::map<string, NodeInstance*> NodeInstanceMap;
+       typedef std::pair<string, NodeInstance*> NodeInstanceMapPair;
        
        static NodeTypeMap node_types;
        
@@ -353,6 +353,7 @@ protected:
        SocketPair add_matrix44_converter(const SocketPair &/*from*/, BVMType 
/*to_type*/);
        SocketPair add_type_converter(const SocketPair &from, const TypeDesc 
&to_typedesc);
        
+       void remove_all_nodes();
        void skip_pass_nodes();
        
 public:

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to