Skip to content

Commit 31bfc41

Browse files
committed
Replace VMap with HashMap in VisualShader.
1 parent 8f78e75 commit 31bfc41

File tree

2 files changed

+11
-26
lines changed

2 files changed

+11
-26
lines changed

scene/resources/visual_shader.cpp

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1516,16 +1516,9 @@ String VisualShader::generate_preview_shader(Type p_type, int p_node, int p_port
15161516
global_code += global_expressions;
15171517

15181518
//make it faster to go around through shader
1519-
VMap<ConnectionKey, const List<Connection>::Element *> input_connections;
1520-
VMap<ConnectionKey, const List<Connection>::Element *> output_connections;
1519+
HashMap<ConnectionKey, const List<Connection>::Element *> input_connections;
15211520

15221521
for (const List<Connection>::Element *E = graph[p_type].connections.front(); E; E = E->next()) {
1523-
ConnectionKey from_key;
1524-
from_key.node = E->get().from_node;
1525-
from_key.port = E->get().from_port;
1526-
1527-
output_connections.insert(from_key, E);
1528-
15291522
ConnectionKey to_key;
15301523
to_key.node = E->get().to_node;
15311524
to_key.port = E->get().to_port;
@@ -1536,7 +1529,7 @@ String VisualShader::generate_preview_shader(Type p_type, int p_node, int p_port
15361529
shader_code += "\nvoid fragment() {\n";
15371530

15381531
HashSet<int> processed;
1539-
Error err = _write_node(p_type, &global_code, &global_code_per_node, &global_code_per_func, shader_code, default_tex_params, input_connections, output_connections, p_node, processed, true, classes);
1532+
Error err = _write_node(p_type, &global_code, &global_code_per_node, &global_code_per_func, shader_code, default_tex_params, input_connections, p_node, processed, true, classes);
15401533
ERR_FAIL_COND_V(err != OK, String());
15411534

15421535
switch (node->get_output_port_type(p_port)) {
@@ -1955,7 +1948,7 @@ void VisualShader::_get_property_list(List<PropertyInfo> *p_list) const {
19551948
}
19561949
}
19571950

1958-
Error VisualShader::_write_node(Type type, StringBuilder *p_global_code, StringBuilder *p_global_code_per_node, HashMap<Type, StringBuilder> *p_global_code_per_func, StringBuilder &r_code, Vector<VisualShader::DefaultTextureParam> &r_def_tex_params, const VMap<ConnectionKey, const List<Connection>::Element *> &p_input_connections, const VMap<ConnectionKey, const List<Connection>::Element *> &p_output_connections, int p_node, HashSet<int> &r_processed, bool p_for_preview, HashSet<StringName> &r_classes) const {
1951+
Error VisualShader::_write_node(Type type, StringBuilder *p_global_code, StringBuilder *p_global_code_per_node, HashMap<Type, StringBuilder> *p_global_code_per_func, StringBuilder &r_code, Vector<VisualShader::DefaultTextureParam> &r_def_tex_params, const HashMap<ConnectionKey, const List<Connection>::Element *> &p_input_connections, int p_node, HashSet<int> &r_processed, bool p_for_preview, HashSet<StringName> &r_classes) const {
19591952
const Ref<VisualShaderNode> vsnode = graph[type].nodes[p_node].node;
19601953

19611954
if (vsnode->is_disabled()) {
@@ -1977,7 +1970,7 @@ Error VisualShader::_write_node(Type type, StringBuilder *p_global_code, StringB
19771970
continue;
19781971
}
19791972

1980-
Error err = _write_node(type, p_global_code, p_global_code_per_node, p_global_code_per_func, r_code, r_def_tex_params, p_input_connections, p_output_connections, from_node, r_processed, p_for_preview, r_classes);
1973+
Error err = _write_node(type, p_global_code, p_global_code_per_node, p_global_code_per_func, r_code, r_def_tex_params, p_input_connections, from_node, r_processed, p_for_preview, r_classes);
19811974
if (err) {
19821975
return err;
19831976
}
@@ -2702,8 +2695,7 @@ void VisualShader::_update_shader() const {
27022695
}
27032696

27042697
//make it faster to go around through shader
2705-
VMap<ConnectionKey, const List<Connection>::Element *> input_connections;
2706-
VMap<ConnectionKey, const List<Connection>::Element *> output_connections;
2698+
HashMap<ConnectionKey, const List<Connection>::Element *> input_connections;
27072699

27082700
StringBuilder func_code;
27092701
HashSet<int> processed;
@@ -2764,12 +2756,6 @@ void VisualShader::_update_shader() const {
27642756
}
27652757

27662758
for (const List<Connection>::Element *E = graph[i].connections.front(); E; E = E->next()) {
2767-
ConnectionKey from_key;
2768-
from_key.node = E->get().from_node;
2769-
from_key.port = E->get().from_port;
2770-
2771-
output_connections.insert(from_key, E);
2772-
27732759
ConnectionKey to_key;
27742760
to_key.node = E->get().to_node;
27752761
to_key.port = E->get().to_port;
@@ -2791,19 +2777,19 @@ void VisualShader::_update_shader() const {
27912777
}
27922778
insertion_pos.insert(i, shader_code.get_string_length() + func_code.get_string_length());
27932779

2794-
Error err = _write_node(Type(i), &global_code, &global_code_per_node, &global_code_per_func, func_code, default_tex_params, input_connections, output_connections, NODE_ID_OUTPUT, processed, false, classes);
2780+
Error err = _write_node(Type(i), &global_code, &global_code_per_node, &global_code_per_func, func_code, default_tex_params, input_connections, NODE_ID_OUTPUT, processed, false, classes);
27952781
ERR_FAIL_COND(err != OK);
27962782

27972783
if (varying_setters.has(i)) {
27982784
for (int &E : varying_setters[i]) {
2799-
err = _write_node(Type(i), &global_code, &global_code_per_node, nullptr, func_code, default_tex_params, input_connections, output_connections, E, processed, false, classes);
2785+
err = _write_node(Type(i), &global_code, &global_code_per_node, nullptr, func_code, default_tex_params, input_connections, E, processed, false, classes);
28002786
ERR_FAIL_COND(err != OK);
28012787
}
28022788
}
28032789

28042790
if (emitters.has(i)) {
28052791
for (int &E : emitters[i]) {
2806-
err = _write_node(Type(i), &global_code, &global_code_per_node, &global_code_per_func, func_code, default_tex_params, input_connections, output_connections, E, processed, false, classes);
2792+
err = _write_node(Type(i), &global_code, &global_code_per_node, &global_code_per_func, func_code, default_tex_params, input_connections, E, processed, false, classes);
28072793
ERR_FAIL_COND(err != OK);
28082794
}
28092795
}

scene/resources/visual_shader.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,11 @@ class VisualShader : public Shader {
156156
uint64_t port : 32;
157157
};
158158
uint64_t key = 0;
159-
bool operator<(const ConnectionKey &p_key) const {
160-
return key < p_key.key;
161-
}
159+
// This is used to apply default equal and hash methods for uint64_t to ConnectionKey.
160+
operator uint64_t() const { return key; }
162161
};
163162

164-
Error _write_node(Type p_type, StringBuilder *p_global_code, StringBuilder *p_global_code_per_node, HashMap<Type, StringBuilder> *p_global_code_per_func, StringBuilder &r_code, Vector<DefaultTextureParam> &r_def_tex_params, const VMap<ConnectionKey, const List<Connection>::Element *> &p_input_connections, const VMap<ConnectionKey, const List<Connection>::Element *> &p_output_connections, int p_node, HashSet<int> &r_processed, bool p_for_preview, HashSet<StringName> &r_classes) const;
163+
Error _write_node(Type p_type, StringBuilder *p_global_code, StringBuilder *p_global_code_per_node, HashMap<Type, StringBuilder> *p_global_code_per_func, StringBuilder &r_code, Vector<DefaultTextureParam> &r_def_tex_params, const HashMap<ConnectionKey, const List<Connection>::Element *> &p_input_connections, int p_node, HashSet<int> &r_processed, bool p_for_preview, HashSet<StringName> &r_classes) const;
165164

166165
void _input_type_changed(Type p_type, int p_id);
167166
bool has_func_name(RenderingServer::ShaderMode p_mode, const String &p_func_name) const;

0 commit comments

Comments
 (0)