Skip to content

Commit 1b439d4

Browse files
committed
Merge pull request #100446 from YYF233333/vmap
Replace `VMap` used in `VisualShader` with `HashMap` and remove `VMap`
2 parents d68e271 + 2db0a44 commit 1b439d4

File tree

3 files changed

+11
-228
lines changed

3 files changed

+11
-228
lines changed

core/templates/vmap.h

Lines changed: 0 additions & 201 deletions
This file was deleted.

scene/resources/visual_shader.cpp

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
#include "visual_shader.h"
3232

3333
#include "core/templates/rb_map.h"
34-
#include "core/templates/vmap.h"
3534
#include "core/variant/variant_utility.h"
3635
#include "servers/rendering/shader_types.h"
3736
#include "visual_shader_nodes.h"
@@ -1516,16 +1515,9 @@ String VisualShader::generate_preview_shader(Type p_type, int p_node, int p_port
15161515
global_code += global_expressions;
15171516

15181517
//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;
1518+
HashMap<ConnectionKey, const List<Connection>::Element *> input_connections;
15211519

15221520
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-
15291521
ConnectionKey to_key;
15301522
to_key.node = E->get().to_node;
15311523
to_key.port = E->get().to_port;
@@ -1536,7 +1528,7 @@ String VisualShader::generate_preview_shader(Type p_type, int p_node, int p_port
15361528
shader_code += "\nvoid fragment() {\n";
15371529

15381530
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);
1531+
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);
15401532
ERR_FAIL_COND_V(err != OK, String());
15411533

15421534
switch (node->get_output_port_type(p_port)) {
@@ -1955,7 +1947,7 @@ void VisualShader::_get_property_list(List<PropertyInfo> *p_list) const {
19551947
}
19561948
}
19571949

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 {
1950+
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 {
19591951
const Ref<VisualShaderNode> vsnode = graph[type].nodes[p_node].node;
19601952

19611953
if (vsnode->is_disabled()) {
@@ -1977,7 +1969,7 @@ Error VisualShader::_write_node(Type type, StringBuilder *p_global_code, StringB
19771969
continue;
19781970
}
19791971

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);
1972+
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);
19811973
if (err) {
19821974
return err;
19831975
}
@@ -2702,8 +2694,7 @@ void VisualShader::_update_shader() const {
27022694
}
27032695

27042696
//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;
2697+
HashMap<ConnectionKey, const List<Connection>::Element *> input_connections;
27072698

27082699
StringBuilder func_code;
27092700
HashSet<int> processed;
@@ -2764,12 +2755,6 @@ void VisualShader::_update_shader() const {
27642755
}
27652756

27662757
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-
27732758
ConnectionKey to_key;
27742759
to_key.node = E->get().to_node;
27752760
to_key.port = E->get().to_port;
@@ -2791,19 +2776,19 @@ void VisualShader::_update_shader() const {
27912776
}
27922777
insertion_pos.insert(i, shader_code.get_string_length() + func_code.get_string_length());
27932778

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);
2779+
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);
27952780
ERR_FAIL_COND(err != OK);
27962781

27972782
if (varying_setters.has(i)) {
27982783
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);
2784+
err = _write_node(Type(i), &global_code, &global_code_per_node, nullptr, func_code, default_tex_params, input_connections, E, processed, false, classes);
28002785
ERR_FAIL_COND(err != OK);
28012786
}
28022787
}
28032788

28042789
if (emitters.has(i)) {
28052790
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);
2791+
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);
28072792
ERR_FAIL_COND(err != OK);
28082793
}
28092794
}

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)