diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/config/project_settings.cpp | 19 | ||||
-rw-r--r-- | core/config/project_settings.h | 8 | ||||
-rw-r--r-- | core/string/string_name.cpp | 59 |
3 files changed, 48 insertions, 38 deletions
diff --git a/core/config/project_settings.cpp b/core/config/project_settings.cpp index 39f8ad68e4..f0de22f2ef 100644 --- a/core/config/project_settings.cpp +++ b/core/config/project_settings.cpp @@ -40,6 +40,7 @@ #include "core/io/file_access_pack.h" #include "core/io/marshalls.h" #include "core/os/keyboard.h" +#include "core/variant/typed_array.h" #include "core/variant/variant_parser.h" #include "core/version.h" @@ -1136,20 +1137,27 @@ Variant ProjectSettings::get_setting(const String &p_setting, const Variant &p_d } } -Array ProjectSettings::get_global_class_list() { - Array script_classes; +TypedArray<Dictionary> ProjectSettings::get_global_class_list() { + if (is_global_class_list_loaded) { + return global_class_list; + } Ref<ConfigFile> cf; cf.instantiate(); if (cf->load(get_global_class_list_path()) == OK) { - script_classes = cf->get_value("", "list", Array()); + global_class_list = cf->get_value("", "list", Array()); } else { #ifndef TOOLS_ENABLED // Script classes can't be recreated in exported project, so print an error. ERR_PRINT("Could not load global script cache."); #endif } - return script_classes; + + // File read succeeded or failed. If it failed, assume everything is still okay. + // We will later receive updated class data in store_global_class_list(). + is_global_class_list_loaded = true; + + return global_class_list; } String ProjectSettings::get_global_class_list_path() const { @@ -1161,6 +1169,8 @@ void ProjectSettings::store_global_class_list(const Array &p_classes) { cf.instantiate(); cf->set_value("", "list", p_classes); cf->save(get_global_class_list_path()); + + global_class_list = p_classes; } bool ProjectSettings::has_custom_feature(const String &p_feature) const { @@ -1195,6 +1205,7 @@ void ProjectSettings::_bind_methods() { ClassDB::bind_method(D_METHOD("set_setting", "name", "value"), &ProjectSettings::set_setting); ClassDB::bind_method(D_METHOD("get_setting", "name", "default_value"), &ProjectSettings::get_setting, DEFVAL(Variant())); ClassDB::bind_method(D_METHOD("get_setting_with_override", "name"), &ProjectSettings::get_setting_with_override); + ClassDB::bind_method(D_METHOD("get_global_class_list"), &ProjectSettings::get_global_class_list); ClassDB::bind_method(D_METHOD("set_order", "name", "position"), &ProjectSettings::set_order); ClassDB::bind_method(D_METHOD("get_order", "name"), &ProjectSettings::get_order); ClassDB::bind_method(D_METHOD("set_initial_value", "name", "value"), &ProjectSettings::set_initial_value); diff --git a/core/config/project_settings.h b/core/config/project_settings.h index 70f697741f..50cb274831 100644 --- a/core/config/project_settings.h +++ b/core/config/project_settings.h @@ -37,6 +37,9 @@ #include "core/templates/local_vector.h" #include "core/templates/rb_set.h" +template <typename T> +class TypedArray; + class ProjectSettings : public Object { GDCLASS(ProjectSettings, Object); _THREAD_SAFE_CLASS_ @@ -99,6 +102,9 @@ protected: HashMap<StringName, AutoloadInfo> autoloads; + Array global_class_list; + bool is_global_class_list_loaded = false; + String project_data_dir_name; bool _set(const StringName &p_name, const Variant &p_value); @@ -141,7 +147,7 @@ public: void set_setting(const String &p_setting, const Variant &p_value); Variant get_setting(const String &p_setting, const Variant &p_default_value = Variant()) const; - Array get_global_class_list(); + TypedArray<Dictionary> get_global_class_list(); void store_global_class_list(const Array &p_classes); String get_global_class_list_path() const; diff --git a/core/string/string_name.cpp b/core/string/string_name.cpp index 95812fc311..df9b6b3f1a 100644 --- a/core/string/string_name.cpp +++ b/core/string/string_name.cpp @@ -226,19 +226,16 @@ StringName::StringName(const char *p_name, bool p_static) { _data = _data->next; } - if (_data) { - if (_data->refcount.ref()) { - // exists - if (p_static) { - _data->static_count.increment(); - } + if (_data && _data->refcount.ref()) { + // exists + if (p_static) { + _data->static_count.increment(); + } #ifdef DEBUG_ENABLED - if (unlikely(debug_stringname)) { - _data->debug_references++; - } -#endif + if (unlikely(debug_stringname)) { + _data->debug_references++; } - +#endif return; } @@ -288,19 +285,17 @@ StringName::StringName(const StaticCString &p_static_string, bool p_static) { _data = _data->next; } - if (_data) { - if (_data->refcount.ref()) { - // exists - if (p_static) { - _data->static_count.increment(); - } + if (_data && _data->refcount.ref()) { + // exists + if (p_static) { + _data->static_count.increment(); + } #ifdef DEBUG_ENABLED - if (unlikely(debug_stringname)) { - _data->debug_references++; - } -#endif - return; + if (unlikely(debug_stringname)) { + _data->debug_references++; } +#endif + return; } _data = memnew(_Data); @@ -348,19 +343,17 @@ StringName::StringName(const String &p_name, bool p_static) { _data = _data->next; } - if (_data) { - if (_data->refcount.ref()) { - // exists - if (p_static) { - _data->static_count.increment(); - } + if (_data && _data->refcount.ref()) { + // exists + if (p_static) { + _data->static_count.increment(); + } #ifdef DEBUG_ENABLED - if (unlikely(debug_stringname)) { - _data->debug_references++; - } -#endif - return; + if (unlikely(debug_stringname)) { + _data->debug_references++; } +#endif + return; } _data = memnew(_Data); |