diff options
Diffstat (limited to 'scene/gui/graph_edit_arranger.cpp')
| -rw-r--r-- | scene/gui/graph_edit_arranger.cpp | 42 |
1 files changed, 18 insertions, 24 deletions
diff --git a/scene/gui/graph_edit_arranger.cpp b/scene/gui/graph_edit_arranger.cpp index f4d9dcbf95..3f2007f7e0 100644 --- a/scene/gui/graph_edit_arranger.cpp +++ b/scene/gui/graph_edit_arranger.cpp @@ -33,7 +33,7 @@ #include "scene/gui/graph_edit.h" void GraphEditArranger::arrange_nodes() { - ERR_FAIL_COND(!graph_edit); + ERR_FAIL_NULL(graph_edit); if (!arranging_graph) { arranging_graph = true; @@ -65,6 +65,9 @@ void GraphEditArranger::arrange_nodes() { float gap_v = 100.0f; float gap_h = 100.0f; + List<GraphEdit::Connection> connection_list; + graph_edit->get_connection_list(&connection_list); + for (int i = graph_edit->get_child_count() - 1; i >= 0; i--) { GraphNode *graph_element = Object::cast_to<GraphNode>(graph_edit->get_child(i)); if (!graph_element) { @@ -74,8 +77,6 @@ void GraphEditArranger::arrange_nodes() { if (graph_element->is_selected() || arrange_entire_graph) { selected_nodes.insert(graph_element->get_name()); HashSet<StringName> s; - List<GraphEdit::Connection> connection_list; - graph_edit->get_connection_list(&connection_list); for (List<GraphEdit::Connection>::Element *E = connection_list.front(); E; E = E->next()) { GraphNode *p_from = Object::cast_to<GraphNode>(node_names[E->get().from_node]); if (E->get().to_node == graph_element->get_name() && (p_from->is_selected() || arrange_entire_graph) && E->get().to_node != E->get().from_node) { @@ -85,12 +86,6 @@ void GraphEditArranger::arrange_nodes() { String s_connection = String(p_from->get_name()) + " " + String(E->get().to_node); StringName _connection(s_connection); Pair<int, int> ports(E->get().from_port, E->get().to_port); - if (port_info.has(_connection)) { - Pair<int, int> p_ports = port_info[_connection]; - if (p_ports.first < ports.first) { - ports = p_ports; - } - } port_info.insert(_connection, ports); } } @@ -216,13 +211,14 @@ int GraphEditArranger::_set_operations(SET_OPERATIONS p_operation, HashSet<Strin return 1; } break; case GraphEditArranger::DIFFERENCE: { - for (HashSet<StringName>::Iterator E = r_u.begin(); E;) { - HashSet<StringName>::Iterator N = E; - ++N; - if (r_v.has(*E)) { - r_u.remove(E); + Vector<StringName> common; + for (const StringName &E : r_u) { + if (r_v.has(E)) { + common.append(E); } - E = N; + } + for (const StringName &E : common) { + r_u.erase(E); } return r_u.size(); } break; @@ -260,9 +256,7 @@ HashMap<int, Vector<StringName>> GraphEditArranger::_layering(const HashSet<Stri selected = true; t.append_array(l[current_layer]); l.insert(current_layer, t); - HashSet<StringName> V; - V.insert(E); - _set_operations(GraphEditArranger::UNION, u, V); + u.insert(E); } } if (!selected) { @@ -408,8 +402,8 @@ void GraphEditArranger::_calculate_inner_shifts(Dictionary &r_inner_shifts, cons int port_from = ports.first; int port_to = ports.second; - Vector2 pos_from = gnode_from->get_connection_output_position(port_from) * graph_edit->get_zoom(); - Vector2 pos_to = gnode_to->get_connection_input_position(port_to) * graph_edit->get_zoom(); + Vector2 pos_from = gnode_from->get_output_port_position(port_from) * graph_edit->get_zoom(); + Vector2 pos_to = gnode_to->get_input_port_position(port_to) * graph_edit->get_zoom(); real_t s = (real_t)r_inner_shifts[u] + (pos_from.y - pos_to.y) / graph_edit->get_zoom(); r_inner_shifts[v] = s; @@ -459,8 +453,8 @@ float GraphEditArranger::_calculate_threshold(StringName p_v, StringName p_w, co if (incoming.from_node != StringName()) { GraphNode *gnode_from = Object::cast_to<GraphNode>(r_node_names[incoming.from_node]); GraphNode *gnode_to = Object::cast_to<GraphNode>(r_node_names[p_w]); - Vector2 pos_from = gnode_from->get_connection_output_position(incoming.from_port) * graph_edit->get_zoom(); - Vector2 pos_to = gnode_to->get_connection_input_position(incoming.to_port) * graph_edit->get_zoom(); + Vector2 pos_from = gnode_from->get_output_port_position(incoming.from_port) * graph_edit->get_zoom(); + Vector2 pos_to = gnode_to->get_input_port_position(incoming.to_port) * graph_edit->get_zoom(); // If connected block node is selected, calculate thershold or add current block to list. if (gnode_from->is_selected()) { @@ -491,8 +485,8 @@ float GraphEditArranger::_calculate_threshold(StringName p_v, StringName p_w, co if (outgoing.to_node != StringName()) { GraphNode *gnode_from = Object::cast_to<GraphNode>(r_node_names[p_w]); GraphNode *gnode_to = Object::cast_to<GraphNode>(r_node_names[outgoing.to_node]); - Vector2 pos_from = gnode_from->get_connection_output_position(outgoing.from_port) * graph_edit->get_zoom(); - Vector2 pos_to = gnode_to->get_connection_input_position(outgoing.to_port) * graph_edit->get_zoom(); + Vector2 pos_from = gnode_from->get_output_port_position(outgoing.from_port) * graph_edit->get_zoom(); + Vector2 pos_to = gnode_to->get_input_port_position(outgoing.to_port) * graph_edit->get_zoom(); // If connected block node is selected, calculate thershold or add current block to list. if (gnode_to->is_selected()) { |
