Merge pull request #41955 from Chaosus/vs_performance_fix3
Improve performance of Add/Remove/Connect/Change nodes in visual shader
This commit is contained in:
commit
01191178bf
File diff suppressed because it is too large
Load Diff
|
@ -54,6 +54,10 @@ class VisualShaderGraphPlugin : public Reference {
|
|||
GDCLASS(VisualShaderGraphPlugin, Reference);
|
||||
|
||||
private:
|
||||
struct InputPort {
|
||||
Button *default_input_button;
|
||||
};
|
||||
|
||||
struct Port {
|
||||
TextureButton *preview_button;
|
||||
};
|
||||
|
@ -64,12 +68,16 @@ private:
|
|||
GraphNode *graph_node;
|
||||
bool preview_visible;
|
||||
int preview_pos;
|
||||
Map<int, InputPort> input_ports;
|
||||
Map<int, Port> output_ports;
|
||||
VBoxContainer *preview_box;
|
||||
Control *custom_editor;
|
||||
int editor_pos;
|
||||
};
|
||||
|
||||
Ref<VisualShader> visual_shader;
|
||||
Map<int, Link> links;
|
||||
List<VisualShader::Connection> connections;
|
||||
bool dirty = false;
|
||||
|
||||
protected:
|
||||
|
@ -77,15 +85,29 @@ protected:
|
|||
|
||||
public:
|
||||
void register_shader(VisualShader *p_visual_shader);
|
||||
void set_connections(List<VisualShader::Connection> &p_connections);
|
||||
void register_link(VisualShader::Type p_type, int p_id, VisualShaderNode *p_visual_node, GraphNode *p_graph_node);
|
||||
void register_output_port(int p_id, int p_port, TextureButton *p_button);
|
||||
void register_custom_editor(int p_node_id, Control *p_custom_editor);
|
||||
void register_editor_pos(int p_node_id, int p_pos);
|
||||
void clear_links();
|
||||
void set_shader_type(VisualShader::Type p_type);
|
||||
bool is_preview_visible(int p_id) const;
|
||||
bool is_dirty() const;
|
||||
void make_dirty(bool p_enabled);
|
||||
|
||||
void show_port_preview(int p_node_id, int p_port_id);
|
||||
void add_node(VisualShader::Type p_type, int p_id);
|
||||
void remove_node(VisualShader::Type p_type, int p_id);
|
||||
void connect_nodes(VisualShader::Type p_type, int p_from_node, int p_from_port, int p_to_node, int p_to_port);
|
||||
void disconnect_nodes(VisualShader::Type p_type, int p_from_node, int p_from_port, int p_to_node, int p_to_port);
|
||||
void show_port_preview(VisualShader::Type p_type, int p_node_id, int p_port_id);
|
||||
void set_node_position(VisualShader::Type p_type, int p_id, const Vector2 &p_position);
|
||||
void set_node_size(VisualShader::Type p_type, int p_id, const Vector2 &p_size);
|
||||
void refresh_node_ports(VisualShader::Type p_type, int p_node);
|
||||
void update_property_editor(VisualShader::Type p_type, int p_node_id);
|
||||
void update_property_editor_deferred(VisualShader::Type p_type, int p_node_id);
|
||||
void set_input_port_default_value(VisualShader::Type p_type, int p_node_id, int p_port_id, Variant p_value);
|
||||
void register_default_input_button(int p_node_id, int p_port_id, Button *p_button);
|
||||
VisualShader::Type get_shader_type() const;
|
||||
|
||||
VisualShaderGraphPlugin();
|
||||
~VisualShaderGraphPlugin();
|
||||
|
@ -328,6 +350,7 @@ class VisualShaderEditor : public VBoxContainer {
|
|||
|
||||
bool _is_available(int p_mode);
|
||||
void _update_created_node(GraphNode *node);
|
||||
void _update_uniforms();
|
||||
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
|
@ -339,6 +362,7 @@ public:
|
|||
void remove_plugin(const Ref<VisualShaderNodePlugin> &p_plugin);
|
||||
|
||||
static VisualShaderEditor *get_singleton() { return singleton; }
|
||||
VisualShaderGraphPlugin *get_graph_plugin() { return graph_plugin.ptr(); }
|
||||
|
||||
void clear_custom_types();
|
||||
void add_custom_type(const String &p_name, const Ref<Script> &p_script, const String &p_description, int p_return_icon_type, const String &p_category, bool p_highend);
|
||||
|
|
|
@ -40,7 +40,6 @@ bool VisualShaderNode::is_simple_decl() const {
|
|||
|
||||
void VisualShaderNode::set_output_port_for_preview(int p_index) {
|
||||
port_preview = p_index;
|
||||
emit_signal("show_port_preview", p_index);
|
||||
}
|
||||
|
||||
int VisualShaderNode::get_output_port_for_preview() const {
|
||||
|
@ -162,7 +161,6 @@ void VisualShaderNode::_bind_methods() {
|
|||
ADD_PROPERTY(PropertyInfo(Variant::INT, "output_port_for_preview"), "set_output_port_for_preview", "get_output_port_for_preview");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "default_input_values", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "set_default_input_values", "get_default_input_values");
|
||||
ADD_SIGNAL(MethodInfo("editor_refresh_request"));
|
||||
ADD_SIGNAL(MethodInfo("show_port_preview", PropertyInfo(Variant::INT, "port_id")));
|
||||
|
||||
BIND_ENUM_CONSTANT(PORT_TYPE_SCALAR);
|
||||
BIND_ENUM_CONSTANT(PORT_TYPE_SCALAR_INT);
|
||||
|
@ -319,13 +317,6 @@ VisualShaderNodeCustom::VisualShaderNodeCustom() {
|
|||
|
||||
/////////////////////////////////////////////////////////
|
||||
|
||||
void VisualShader::set_graph_node(Type p_type, int p_id, GraphNode *p_graph_node) {
|
||||
ERR_FAIL_INDEX(p_type, TYPE_MAX);
|
||||
Graph *g = &graph[p_type];
|
||||
ERR_FAIL_COND(!g->nodes.has(p_id));
|
||||
g->nodes[p_id].graph_node = p_graph_node;
|
||||
}
|
||||
|
||||
void VisualShader::set_shader_type(Type p_type) {
|
||||
current_type = p_type;
|
||||
}
|
||||
|
@ -417,11 +408,6 @@ void VisualShader::set_node_position(Type p_type, int p_id, const Vector2 &p_pos
|
|||
Graph *g = &graph[p_type];
|
||||
ERR_FAIL_COND(!g->nodes.has(p_id));
|
||||
g->nodes[p_id].position = p_position;
|
||||
if (current_type == p_type) {
|
||||
if (g->nodes[p_id].graph_node != nullptr) {
|
||||
g->nodes[p_id].graph_node->set_offset(p_position);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Vector2 VisualShader::get_node_position(Type p_type, int p_id) const {
|
||||
|
|
|
@ -33,7 +33,6 @@
|
|||
|
||||
#include "core/string_builder.h"
|
||||
#include "scene/gui/control.h"
|
||||
#include "scene/gui/graph_edit.h"
|
||||
#include "scene/resources/shader.h"
|
||||
|
||||
class VisualShaderNodeUniform;
|
||||
|
@ -76,7 +75,6 @@ private:
|
|||
Ref<VisualShaderNode> node;
|
||||
Vector2 position;
|
||||
List<int> prev_connected_nodes;
|
||||
GraphNode *graph_node;
|
||||
};
|
||||
|
||||
struct Graph {
|
||||
|
@ -129,7 +127,6 @@ protected:
|
|||
void _get_property_list(List<PropertyInfo> *p_list) const;
|
||||
|
||||
public: // internal methods
|
||||
void set_graph_node(Type p_type, int p_id, GraphNode *p_graph_node);
|
||||
void set_shader_type(Type p_type);
|
||||
Type get_shader_type() const;
|
||||
|
||||
|
|
Loading…
Reference in New Issue