summaryrefslogtreecommitdiff
path: root/scene/resources
diff options
context:
space:
mode:
authorYuri Rubinsky <chaosus89@gmail.com>2023-02-03 15:09:51 +0300
committerYuri Rubinsky <chaosus89@gmail.com>2023-02-03 15:28:04 +0300
commitc0a3129210e980dfe80e2043d74eb9fb4686195b (patch)
tree944531a2d50aeba526190a0a463130fd680006fd /scene/resources
parent1ed549e64b141e068bfe1a59bf65e943cde3fc6c (diff)
Prevent preview error for the instance parameter in visual shader
Diffstat (limited to 'scene/resources')
-rw-r--r--scene/resources/visual_shader.cpp5
-rw-r--r--scene/resources/visual_shader.h13
2 files changed, 17 insertions, 1 deletions
diff --git a/scene/resources/visual_shader.cpp b/scene/resources/visual_shader.cpp
index 4132972cb3..3a6d40d22c 100644
--- a/scene/resources/visual_shader.cpp
+++ b/scene/resources/visual_shader.cpp
@@ -815,6 +815,8 @@ void VisualShader::remove_node(Type p_type, int p_id) {
if (E->get().from_node == p_id) {
g->nodes[E->get().to_node].prev_connected_nodes.erase(p_id);
g->nodes[E->get().to_node].node->set_input_port_connected(E->get().to_port, false);
+ } else if (E->get().to_node == p_id) {
+ g->nodes[E->get().from_node].next_connected_nodes.erase(p_id);
}
}
E = N;
@@ -981,6 +983,7 @@ void VisualShader::connect_nodes_forced(Type p_type, int p_from_node, int p_from
c.to_node = p_to_node;
c.to_port = p_to_port;
g->connections.push_back(c);
+ g->nodes[p_from_node].next_connected_nodes.push_back(p_to_node);
g->nodes[p_to_node].prev_connected_nodes.push_back(p_from_node);
g->nodes[p_from_node].node->set_output_port_connected(p_from_port, true);
g->nodes[p_to_node].node->set_input_port_connected(p_to_port, true);
@@ -1014,6 +1017,7 @@ Error VisualShader::connect_nodes(Type p_type, int p_from_node, int p_from_port,
c.to_node = p_to_node;
c.to_port = p_to_port;
g->connections.push_back(c);
+ g->nodes[p_from_node].next_connected_nodes.push_back(p_to_node);
g->nodes[p_to_node].prev_connected_nodes.push_back(p_from_node);
g->nodes[p_from_node].node->set_output_port_connected(p_from_port, true);
g->nodes[p_to_node].node->set_input_port_connected(p_to_port, true);
@@ -1029,6 +1033,7 @@ void VisualShader::disconnect_nodes(Type p_type, int p_from_node, int p_from_por
for (const List<Connection>::Element *E = g->connections.front(); E; E = E->next()) {
if (E->get().from_node == p_from_node && E->get().from_port == p_from_port && E->get().to_node == p_to_node && E->get().to_port == p_to_port) {
g->connections.erase(E);
+ g->nodes[p_from_node].next_connected_nodes.erase(p_to_node);
g->nodes[p_to_node].prev_connected_nodes.erase(p_from_node);
g->nodes[p_from_node].node->set_output_port_connected(p_from_port, false);
g->nodes[p_to_node].node->set_input_port_connected(p_to_port, false);
diff --git a/scene/resources/visual_shader.h b/scene/resources/visual_shader.h
index fc5e48410b..2838a49209 100644
--- a/scene/resources/visual_shader.h
+++ b/scene/resources/visual_shader.h
@@ -122,7 +122,8 @@ private:
struct Node {
Ref<VisualShaderNode> node;
Vector2 position;
- List<int> prev_connected_nodes;
+ LocalVector<int> prev_connected_nodes;
+ LocalVector<int> next_connected_nodes;
};
struct Graph {
@@ -199,6 +200,16 @@ public: // internal methods
Vector2 get_node_position(Type p_type, int p_id) const;
Ref<VisualShaderNode> get_node(Type p_type, int p_id) const;
+ _FORCE_INLINE_ Ref<VisualShaderNode> get_node_unchecked(Type p_type, int p_id) const {
+ return graph[p_type].nodes[p_id].node;
+ }
+ _FORCE_INLINE_ void get_next_connected_nodes(Type p_type, int p_id, LocalVector<int> &r_list) const {
+ r_list = graph[p_type].nodes[p_id].next_connected_nodes;
+ }
+ _FORCE_INLINE_ void get_prev_connected_nodes(Type p_type, int p_id, LocalVector<int> &r_list) const {
+ r_list = graph[p_type].nodes[p_id].prev_connected_nodes;
+ }
+
Vector<int> get_node_list(Type p_type) const;
int get_valid_node_id(Type p_type) const;