diff options
Diffstat (limited to 'core/io')
-rw-r--r-- | core/io/dir_access.cpp | 14 | ||||
-rw-r--r-- | core/io/dir_access.h | 2 | ||||
-rw-r--r-- | core/io/file_access.cpp | 4 | ||||
-rw-r--r-- | core/io/file_access.h | 1 | ||||
-rw-r--r-- | core/io/file_access_pack.cpp | 2 | ||||
-rw-r--r-- | core/io/http_client_tcp.cpp | 4 | ||||
-rw-r--r-- | core/io/image.cpp | 4 | ||||
-rw-r--r-- | core/io/image.h | 2 | ||||
-rw-r--r-- | core/io/image_loader.cpp | 6 | ||||
-rw-r--r-- | core/io/image_loader.h | 9 | ||||
-rw-r--r-- | core/io/ip.cpp | 17 | ||||
-rw-r--r-- | core/io/ip.h | 9 | ||||
-rw-r--r-- | core/io/json.cpp | 23 | ||||
-rw-r--r-- | core/io/json.h | 3 | ||||
-rw-r--r-- | core/io/packed_data_container.cpp | 2 | ||||
-rw-r--r-- | core/io/resource.cpp | 40 | ||||
-rw-r--r-- | core/io/resource.h | 1 | ||||
-rw-r--r-- | core/io/resource_format_binary.cpp | 6 | ||||
-rw-r--r-- | core/io/resource_importer.cpp | 2 | ||||
-rw-r--r-- | core/io/resource_loader.cpp | 8 | ||||
-rw-r--r-- | core/io/resource_saver.cpp | 2 | ||||
-rw-r--r-- | core/io/resource_uid.cpp | 2 |
22 files changed, 74 insertions, 89 deletions
diff --git a/core/io/dir_access.cpp b/core/io/dir_access.cpp index f82d6f077f..bed41b8d89 100644 --- a/core/io/dir_access.cpp +++ b/core/io/dir_access.cpp @@ -106,7 +106,7 @@ static Error _erase_recursive(DirAccess *da) { if (err) { return err; } - err = da->remove(da->get_current_dir().plus_file(E)); + err = da->remove(da->get_current_dir().path_join(E)); if (err) { return err; } @@ -116,7 +116,7 @@ static Error _erase_recursive(DirAccess *da) { } for (const String &E : files) { - Error err = da->remove(da->get_current_dir().plus_file(E)); + Error err = da->remove(da->get_current_dir().path_join(E)); if (err) { return err; } @@ -138,7 +138,7 @@ Error DirAccess::make_dir_recursive(String p_dir) { if (p_dir.is_relative_path()) { //append current - full_dir = get_current_dir().plus_file(p_dir); + full_dir = get_current_dir().path_join(p_dir); } else { full_dir = p_dir; @@ -172,7 +172,7 @@ Error DirAccess::make_dir_recursive(String p_dir) { String curpath = base; for (int i = 0; i < subdirs.size(); i++) { - curpath = curpath.plus_file(subdirs[i]); + curpath = curpath.path_join(subdirs[i]); Error err = make_dir(curpath); if (err != OK && err != ERR_ALREADY_EXISTS) { ERR_FAIL_V_MSG(err, "Could not create directory: " + curpath); @@ -354,8 +354,8 @@ Error DirAccess::_copy_dir(Ref<DirAccess> &p_target_da, String p_to, int p_chmod String n = get_next(); while (!n.is_empty()) { if (n != "." && n != "..") { - if (p_copy_links && is_link(get_current_dir().plus_file(n))) { - create_link(read_link(get_current_dir().plus_file(n)), p_to + n); + if (p_copy_links && is_link(get_current_dir().path_join(n))) { + create_link(read_link(get_current_dir().path_join(n)), p_to + n); } else if (current_is_dir()) { dirs.push_back(n); } else { @@ -364,7 +364,7 @@ Error DirAccess::_copy_dir(Ref<DirAccess> &p_target_da, String p_to, int p_chmod list_dir_end(); return ERR_BUG; } - Error err = copy(get_current_dir().plus_file(n), p_to + rel_path, p_chmod_flags); + Error err = copy(get_current_dir().path_join(n), p_to + rel_path, p_chmod_flags); if (err) { list_dir_end(); return err; diff --git a/core/io/dir_access.h b/core/io/dir_access.h index d5318dfb45..2469c2a080 100644 --- a/core/io/dir_access.h +++ b/core/io/dir_access.h @@ -55,7 +55,7 @@ private: protected: String _get_root_path() const; - String _get_root_string() const; + virtual String _get_root_string() const; AccessType get_access_type() const; String fix_path(String p_path) const; diff --git a/core/io/file_access.cpp b/core/io/file_access.cpp index 8ed3d40c22..72c00bd678 100644 --- a/core/io/file_access.cpp +++ b/core/io/file_access.cpp @@ -115,6 +115,10 @@ FileAccess::CreateFunc FileAccess::get_create_func(AccessType p_access) { return create_func[p_access]; } +FileAccess::AccessType FileAccess::get_access_type() const { + return _access_type; +} + String FileAccess::fix_path(const String &p_path) const { //helper used by file accesses that use a single filesystem diff --git a/core/io/file_access.h b/core/io/file_access.h index 3386800686..fc0eb95d44 100644 --- a/core/io/file_access.h +++ b/core/io/file_access.h @@ -60,6 +60,7 @@ public: virtual Error _set_unix_permissions(const String &p_file, uint32_t p_permissions) = 0; protected: + AccessType get_access_type() const; String fix_path(const String &p_path) const; virtual Error _open(const String &p_path, int p_mode_flags) = 0; ///< open a file virtual uint64_t _get_modified_time(const String &p_file) = 0; diff --git a/core/io/file_access_pack.cpp b/core/io/file_access_pack.cpp index 595a6e9873..adae0db0f4 100644 --- a/core/io/file_access_pack.cpp +++ b/core/io/file_access_pack.cpp @@ -520,7 +520,7 @@ String DirAccessPack::get_current_dir(bool p_include_drive) const { while (pd->parent) { pd = pd->parent; - p = pd->name.plus_file(p); + p = pd->name.path_join(p); } return "res://" + p; diff --git a/core/io/http_client_tcp.cpp b/core/io/http_client_tcp.cpp index d983d86b99..9499a6f8e3 100644 --- a/core/io/http_client_tcp.cpp +++ b/core/io/http_client_tcp.cpp @@ -28,7 +28,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef JAVASCRIPT_ENABLED +#ifndef WEB_ENABLED #include "http_client_tcp.h" @@ -788,4 +788,4 @@ HTTPClientTCP::HTTPClientTCP() { HTTPClient *(*HTTPClient::_create)() = HTTPClientTCP::_create_func; -#endif // #ifndef JAVASCRIPT_ENABLED +#endif // WEB_ENABLED diff --git a/core/io/image.cpp b/core/io/image.cpp index 0f20aabd7e..2d87523ca4 100644 --- a/core/io/image.cpp +++ b/core/io/image.cpp @@ -416,8 +416,8 @@ int Image::get_height() const { return height; } -Vector2 Image::get_size() const { - return Vector2(width, height); +Vector2i Image::get_size() const { + return Vector2i(width, height); } bool Image::has_mipmaps() const { diff --git a/core/io/image.h b/core/io/image.h index 46820a4c08..9d415423be 100644 --- a/core/io/image.h +++ b/core/io/image.h @@ -209,7 +209,7 @@ private: public: int get_width() const; ///< Get image width int get_height() const; ///< Get image height - Vector2 get_size() const; + Vector2i get_size() const; bool has_mipmaps() const; int get_mipmap_count() const; diff --git a/core/io/image_loader.cpp b/core/io/image_loader.cpp index 9cf7c9caba..d09697b951 100644 --- a/core/io/image_loader.cpp +++ b/core/io/image_loader.cpp @@ -44,7 +44,7 @@ bool ImageFormatLoader::recognize(const String &p_extension) const { return false; } -Error ImageLoader::load_image(String p_file, Ref<Image> p_image, Ref<FileAccess> p_custom, bool p_force_linear, float p_scale) { +Error ImageLoader::load_image(String p_file, Ref<Image> p_image, Ref<FileAccess> p_custom, uint32_t p_flags, float p_scale) { ERR_FAIL_COND_V_MSG(p_image.is_null(), ERR_INVALID_PARAMETER, "It's not a reference to a valid Image object."); Ref<FileAccess> f = p_custom; @@ -60,7 +60,7 @@ Error ImageLoader::load_image(String p_file, Ref<Image> p_image, Ref<FileAccess> if (!loader[i]->recognize(extension)) { continue; } - Error err = loader[i]->load_image(p_image, f, p_force_linear, p_scale); + Error err = loader[i]->load_image(p_image, f, p_flags, p_scale); if (err != OK) { ERR_PRINT("Error loading image: " + p_file); } @@ -152,7 +152,7 @@ Ref<Resource> ResourceFormatLoaderImage::load(const String &p_path, const String Ref<Image> image; image.instantiate(); - Error err = ImageLoader::loader[idx]->load_image(image, f, false, 1.0); + Error err = ImageLoader::loader[idx]->load_image(image, f); if (err != OK) { if (r_error) { diff --git a/core/io/image_loader.h b/core/io/image_loader.h index c91d382c25..cb64d2310e 100644 --- a/core/io/image_loader.h +++ b/core/io/image_loader.h @@ -44,11 +44,16 @@ class ImageFormatLoader { friend class ResourceFormatLoaderImage; protected: - virtual Error load_image(Ref<Image> p_image, Ref<FileAccess> p_fileaccess, bool p_force_linear, float p_scale) = 0; + virtual Error load_image(Ref<Image> p_image, Ref<FileAccess> p_fileaccess, uint32_t p_flags = (uint32_t)FLAG_NONE, float p_scale = 1.0) = 0; virtual void get_recognized_extensions(List<String> *p_extensions) const = 0; bool recognize(const String &p_extension) const; public: + enum LoaderFlags { + FLAG_NONE = 0, + FLAG_FORCE_LINEAR = 1, + }; + virtual ~ImageFormatLoader() {} }; @@ -58,7 +63,7 @@ class ImageLoader { protected: public: - static Error load_image(String p_file, Ref<Image> p_image, Ref<FileAccess> p_custom = Ref<FileAccess>(), bool p_force_linear = false, float p_scale = 1.0); + static Error load_image(String p_file, Ref<Image> p_image, Ref<FileAccess> p_custom = Ref<FileAccess>(), uint32_t p_flags = (uint32_t)ImageFormatLoader::FLAG_NONE, float p_scale = 1.0); static void get_recognized_extensions(List<String> *p_extensions); static ImageFormatLoader *recognize(const String &p_extension); diff --git a/core/io/ip.cpp b/core/io/ip.cpp index 25e3bef5fc..a4d8dc3d5b 100644 --- a/core/io/ip.cpp +++ b/core/io/ip.cpp @@ -33,6 +33,7 @@ #include "core/os/semaphore.h" #include "core/os/thread.h" #include "core/templates/hash_map.h" +#include "core/variant/typed_array.h" VARIANT_ENUM_CAST(IP::ResolverStatus); @@ -124,11 +125,11 @@ struct _IP_ResolverPrivate { }; IPAddress IP::resolve_hostname(const String &p_hostname, IP::Type p_type) { - const Array addresses = resolve_hostname_addresses(p_hostname, p_type); - return addresses.size() ? addresses[0].operator IPAddress() : IPAddress(); + const PackedStringArray addresses = resolve_hostname_addresses(p_hostname, p_type); + return addresses.size() ? (IPAddress)addresses[0] : IPAddress(); } -Array IP::resolve_hostname_addresses(const String &p_hostname, Type p_type) { +PackedStringArray IP::resolve_hostname_addresses(const String &p_hostname, Type p_type) { List<IPAddress> res; String key = _IP_ResolverPrivate::get_cache_key(p_hostname, p_type); @@ -148,7 +149,7 @@ Array IP::resolve_hostname_addresses(const String &p_hostname, Type p_type) { } resolver->mutex.unlock(); - Array result; + PackedStringArray result; for (int i = 0; i < res.size(); ++i) { result.push_back(String(res[i])); } @@ -254,8 +255,8 @@ void IP::clear_cache(const String &p_hostname) { } } -Array IP::_get_local_addresses() const { - Array addresses; +PackedStringArray IP::_get_local_addresses() const { + PackedStringArray addresses; List<IPAddress> ip_addresses; get_local_addresses(&ip_addresses); for (const IPAddress &E : ip_addresses) { @@ -265,8 +266,8 @@ Array IP::_get_local_addresses() const { return addresses; } -Array IP::_get_local_interfaces() const { - Array results; +TypedArray<Dictionary> IP::_get_local_interfaces() const { + TypedArray<Dictionary> results; HashMap<String, Interface_Info> interfaces; get_local_interfaces(&interfaces); for (KeyValue<String, Interface_Info> &E : interfaces) { diff --git a/core/io/ip.h b/core/io/ip.h index 4d83515e2b..f2d93a454d 100644 --- a/core/io/ip.h +++ b/core/io/ip.h @@ -34,6 +34,9 @@ #include "core/io/ip_address.h" #include "core/os/os.h" +template <typename T> +class TypedArray; + struct _IP_ResolverPrivate; class IP : public Object { @@ -68,8 +71,8 @@ protected: static IP *singleton; static void _bind_methods(); - Array _get_local_addresses() const; - Array _get_local_interfaces() const; + PackedStringArray _get_local_addresses() const; + TypedArray<Dictionary> _get_local_interfaces() const; static IP *(*_create)(); @@ -82,7 +85,7 @@ public: }; IPAddress resolve_hostname(const String &p_hostname, Type p_type = TYPE_ANY); - Array resolve_hostname_addresses(const String &p_hostname, Type p_type = TYPE_ANY); + PackedStringArray resolve_hostname_addresses(const String &p_hostname, Type p_type = TYPE_ANY); // async resolver hostname ResolverID resolve_hostname_queue_item(const String &p_hostname, Type p_type = TYPE_ANY); ResolverStatus get_resolve_item_status(ResolverID p_id) const; diff --git a/core/io/json.cpp b/core/io/json.cpp index 4c4d91f851..91500ff3d5 100644 --- a/core/io/json.cpp +++ b/core/io/json.cpp @@ -528,11 +528,6 @@ Error JSON::_parse_string(const String &p_json, Variant &r_ret, String &r_err_st return err; } -String JSON::stringify(const Variant &p_var, const String &p_indent, bool p_sort_keys, bool p_full_precision) { - HashSet<const void *> markers; - return _stringify(p_var, p_indent, 0, p_sort_keys, markers, p_full_precision); -} - Error JSON::parse(const String &p_json_string) { Error err = _parse_string(p_json_string, data, err_str, err_line); if (err == Error::OK) { @@ -541,8 +536,24 @@ Error JSON::parse(const String &p_json_string) { return err; } +String JSON::stringify(const Variant &p_var, const String &p_indent, bool p_sort_keys, bool p_full_precision) { + Ref<JSON> jason; + jason.instantiate(); + HashSet<const void *> markers; + return jason->_stringify(p_var, p_indent, 0, p_sort_keys, markers, p_full_precision); +} + +Variant JSON::parse_string(const String &p_json_string) { + Ref<JSON> jason; + jason.instantiate(); + Error error = jason->parse(p_json_string); + ERR_FAIL_COND_V_MSG(error != Error::OK, Variant(), vformat("Parse JSON failed. Error at line %d: %s", jason->get_error_line(), jason->get_error_message())); + return jason->get_data(); +} + void JSON::_bind_methods() { - ClassDB::bind_method(D_METHOD("stringify", "data", "indent", "sort_keys", "full_precision"), &JSON::stringify, DEFVAL(""), DEFVAL(true), DEFVAL(false)); + ClassDB::bind_static_method("JSON", D_METHOD("stringify", "data", "indent", "sort_keys", "full_precision"), &JSON::stringify, DEFVAL(""), DEFVAL(true), DEFVAL(false)); + ClassDB::bind_static_method("JSON", D_METHOD("parse_string", "json_string"), &JSON::parse_string); ClassDB::bind_method(D_METHOD("parse", "json_string"), &JSON::parse); ClassDB::bind_method(D_METHOD("get_data"), &JSON::get_data); diff --git a/core/io/json.h b/core/io/json.h index 6ba0a8c76b..840b1cc08a 100644 --- a/core/io/json.h +++ b/core/io/json.h @@ -81,8 +81,9 @@ protected: static void _bind_methods(); public: - String stringify(const Variant &p_var, const String &p_indent = "", bool p_sort_keys = true, bool p_full_precision = false); Error parse(const String &p_json_string); + static String stringify(const Variant &p_var, const String &p_indent = "", bool p_sort_keys = true, bool p_full_precision = false); + static Variant parse_string(const String &p_json_string); inline Variant get_data() const { return data; } inline int get_error_line() const { return err_line; } diff --git a/core/io/packed_data_container.cpp b/core/io/packed_data_container.cpp index a456318148..2dcb86cbc6 100644 --- a/core/io/packed_data_container.cpp +++ b/core/io/packed_data_container.cpp @@ -353,7 +353,7 @@ Variant PackedDataContainer::_iter_get(const Variant &p_iter) { } void PackedDataContainer::_bind_methods() { - ClassDB::bind_method(D_METHOD("_set_data"), &PackedDataContainer::_set_data); + ClassDB::bind_method(D_METHOD("_set_data", "data"), &PackedDataContainer::_set_data); ClassDB::bind_method(D_METHOD("_get_data"), &PackedDataContainer::_get_data); ClassDB::bind_method(D_METHOD("_iter_init"), &PackedDataContainer::_iter_init); ClassDB::bind_method(D_METHOD("_iter_get"), &PackedDataContainer::_iter_get); diff --git a/core/io/resource.cpp b/core/io/resource.cpp index fec5ca5c7b..d117f86f39 100644 --- a/core/io/resource.cpp +++ b/core/io/resource.cpp @@ -543,43 +543,3 @@ int ResourceCache::get_cached_resource_count() { return rc; } - -void ResourceCache::dump(const char *p_file, bool p_short) { -#ifdef DEBUG_ENABLED - lock.lock(); - - HashMap<String, int> type_count; - - Ref<FileAccess> f; - if (p_file) { - f = FileAccess::open(String::utf8(p_file), FileAccess::WRITE); - ERR_FAIL_COND_MSG(f.is_null(), "Cannot create file at path '" + String::utf8(p_file) + "'."); - } - - for (KeyValue<String, Resource *> &E : resources) { - Resource *r = E.value; - - if (!type_count.has(r->get_class())) { - type_count[r->get_class()] = 0; - } - - type_count[r->get_class()]++; - - if (!p_short) { - if (f.is_valid()) { - f->store_line(r->get_class() + ": " + r->get_path()); - } - } - } - - for (const KeyValue<String, int> &E : type_count) { - if (f.is_valid()) { - f->store_line(E.key + " count: " + itos(E.value)); - } - } - - lock.unlock(); -#else - WARN_PRINT("ResourceCache::dump only with in debug builds."); -#endif -} diff --git a/core/io/resource.h b/core/io/resource.h index a2cde87990..a76a3920be 100644 --- a/core/io/resource.h +++ b/core/io/resource.h @@ -167,7 +167,6 @@ public: static void reload_externals(); static bool has(const String &p_path); static Ref<Resource> get_ref(const String &p_path); - static void dump(const char *p_file = nullptr, bool p_short = false); static void get_cached_resources(List<Ref<Resource>> *p_resources); static int get_cached_resource_count(); }; diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp index b731608b4f..4f1204fc48 100644 --- a/core/io/resource_format_binary.cpp +++ b/core/io/resource_format_binary.cpp @@ -421,7 +421,7 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) { if (!path.contains("://") && path.is_relative_path()) { // path is relative to file being loaded, so convert to a resource path - path = ProjectSettings::get_singleton()->localize_path(res_path.get_base_dir().plus_file(path)); + path = ProjectSettings::get_singleton()->localize_path(res_path.get_base_dir().path_join(path)); } if (remaps.find(path)) { @@ -683,7 +683,7 @@ Error ResourceLoaderBinary::load() { if (!path.contains("://") && path.is_relative_path()) { // path is relative to file being loaded, so convert to a resource path - path = ProjectSettings::get_singleton()->localize_path(path.get_base_dir().plus_file(external_resources[i].path)); + path = ProjectSettings::get_singleton()->localize_path(path.get_base_dir().path_join(external_resources[i].path)); } external_resources.write[i].path = path; //remap happens here, not on load because on load it can actually be used for filesystem dock resource remap @@ -1329,7 +1329,7 @@ Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path, cons bool relative = false; if (!path.begins_with("res://")) { - path = local_path.plus_file(path).simplify_path(); + path = local_path.path_join(path).simplify_path(); relative = true; } diff --git a/core/io/resource_importer.cpp b/core/io/resource_importer.cpp index e059fc842b..aa7f96a047 100644 --- a/core/io/resource_importer.cpp +++ b/core/io/resource_importer.cpp @@ -421,7 +421,7 @@ Ref<ResourceImporter> ResourceFormatImporter::get_importer_by_extension(const St } String ResourceFormatImporter::get_import_base_path(const String &p_for_file) const { - return ProjectSettings::get_singleton()->get_imported_files_path().plus_file(p_for_file.get_file() + "-" + p_for_file.md5_text()); + return ProjectSettings::get_singleton()->get_imported_files_path().path_join(p_for_file.get_file() + "-" + p_for_file.md5_text()); } bool ResourceFormatImporter::are_import_settings_valid(const String &p_path) const { diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp index 3e595557f9..eccb397e2e 100644 --- a/core/io/resource_loader.cpp +++ b/core/io/resource_loader.cpp @@ -794,6 +794,8 @@ String ResourceLoader::_path_remap(const String &p_path, bool *r_translation_rem // To find the path of the remapped resource, we extract the locale name after // the last ':' to match the project locale. + // An extra remap may still be necessary afterwards due to the text -> binary converter on export. + String locale = TranslationServer::get_singleton()->get_locale(); ERR_FAIL_COND_V_MSG(locale.length() < 2, p_path, "Could not remap path '" + p_path + "' for translation as configured locale '" + locale + "' is invalid."); @@ -829,12 +831,10 @@ String ResourceLoader::_path_remap(const String &p_path, bool *r_translation_rem if (path_remaps.has(new_path)) { new_path = path_remaps[new_path]; - } - - if (new_path == p_path) { // Did not remap. + } else { // Try file remap. Error err; - Ref<FileAccess> f = FileAccess::open(p_path + ".remap", FileAccess::READ, &err); + Ref<FileAccess> f = FileAccess::open(new_path + ".remap", FileAccess::READ, &err); if (f.is_valid()) { VariantParser::StreamFile stream; stream.f = f; diff --git a/core/io/resource_saver.cpp b/core/io/resource_saver.cpp index 274316f058..386ccb78e9 100644 --- a/core/io/resource_saver.cpp +++ b/core/io/resource_saver.cpp @@ -70,7 +70,7 @@ void ResourceFormatSaver::get_recognized_extensions(const Ref<Resource> &p_resou } void ResourceFormatSaver::_bind_methods() { - GDVIRTUAL_BIND(_save, "path", "resource", "flags"); + GDVIRTUAL_BIND(_save, "resource", "path", "flags"); GDVIRTUAL_BIND(_recognize, "resource"); GDVIRTUAL_BIND(_get_recognized_extensions, "resource"); } diff --git a/core/io/resource_uid.cpp b/core/io/resource_uid.cpp index fc324a26da..5324c5dd84 100644 --- a/core/io/resource_uid.cpp +++ b/core/io/resource_uid.cpp @@ -39,7 +39,7 @@ static constexpr uint32_t char_count = ('z' - 'a'); static constexpr uint32_t base = char_count + ('9' - '0'); String ResourceUID::get_cache_file() { - return ProjectSettings::get_singleton()->get_project_data_path().plus_file("uid_cache.bin"); + return ProjectSettings::get_singleton()->get_project_data_path().path_join("uid_cache.bin"); } String ResourceUID::id_to_text(ID p_id) const { |