diff options
author | Yuri Rubinsky <chaosus89@gmail.com> | 2024-07-02 18:16:04 +0300 |
---|---|---|
committer | Yuri Rubinsky <chaosus89@gmail.com> | 2024-07-02 18:16:04 +0300 |
commit | 4f657f5c6d7eab77eeb20f427cd6ff07c1a3f312 (patch) | |
tree | 58956c7f4399ef9040c75b24c471ad7be53e09e7 /servers | |
parent | 9db1a963beae8056cbd30d692d4160d09c10b2dc (diff) | |
download | redot-engine-4f657f5c6d7eab77eeb20f427cd6ff07c1a3f312.tar.gz |
Improve code for setup of `global_func_set` in `ShaderLanguage`
Diffstat (limited to 'servers')
-rw-r--r-- | servers/rendering/shader_language.cpp | 22 | ||||
-rw-r--r-- | servers/rendering/shader_language.h | 2 |
2 files changed, 15 insertions, 9 deletions
diff --git a/servers/rendering/shader_language.cpp b/servers/rendering/shader_language.cpp index f5e0b811a2..0b1595d988 100644 --- a/servers/rendering/shader_language.cpp +++ b/servers/rendering/shader_language.cpp @@ -39,6 +39,8 @@ #define HAS_WARNING(flag) (warning_flags & flag) +int ShaderLanguage::instance_counter = 0; + String ShaderLanguage::get_operator_text(Operator p_op) { static const char *op_names[OP_MAX] = { "==", "!=", @@ -10812,17 +10814,16 @@ ShaderLanguage::ShaderLanguage() { nodes = nullptr; completion_class = TAG_GLOBAL; - int idx = 0; - while (builtin_func_defs[idx].name) { - if (builtin_func_defs[idx].tag == SubClassTag::TAG_GLOBAL) { - const StringName &name = StringName(builtin_func_defs[idx].name); - - if (!global_func_set.has(name)) { - global_func_set.insert(name); + if (instance_counter == 0) { + int idx = 0; + while (builtin_func_defs[idx].name) { + if (builtin_func_defs[idx].tag == SubClassTag::TAG_GLOBAL) { + global_func_set.insert(builtin_func_defs[idx].name); } + idx++; } - idx++; } + instance_counter++; #ifdef DEBUG_ENABLED warnings_check_map.insert(ShaderWarning::UNUSED_CONSTANT, &used_constants); @@ -10837,5 +10838,8 @@ ShaderLanguage::ShaderLanguage() { ShaderLanguage::~ShaderLanguage() { clear(); - global_func_set.clear(); + instance_counter--; + if (instance_counter == 0) { + global_func_set.clear(); + } } diff --git a/servers/rendering/shader_language.h b/servers/rendering/shader_language.h index edac819a1e..076bd8def4 100644 --- a/servers/rendering/shader_language.h +++ b/servers/rendering/shader_language.h @@ -800,6 +800,8 @@ public: static bool is_control_flow_keyword(String p_keyword); static void get_builtin_funcs(List<String> *r_keywords); + static int instance_counter; + struct BuiltInInfo { DataType type = TYPE_VOID; bool constant = false; |