diff options
126 files changed, 1266 insertions, 520 deletions
diff --git a/.github/workflows/windows_builds.yml b/.github/workflows/windows_builds.yml index b9bf510c71..19ff555b56 100644 --- a/.github/workflows/windows_builds.yml +++ b/.github/workflows/windows_builds.yml @@ -24,7 +24,7 @@ jobs: # Editing this is pretty dangerous for Windows since it can break and needs to be properly tested with a fresh cache. - name: Load .scons_cache directory id: windows-editor-cache - uses: RevoluPowered/cache@v2.1 + uses: actions/cache@v2 with: path: /.scons_cache/ key: ${{github.job}}-${{env.GODOT_BASE_BRANCH}}-${{github.ref}}-${{github.sha}} diff --git a/core/core_bind.cpp b/core/core_bind.cpp index 456a97e5e5..dd99c32fa8 100644 --- a/core/core_bind.cpp +++ b/core/core_bind.cpp @@ -86,9 +86,9 @@ RES _ResourceLoader::load_threaded_get(const String &p_path) { return res; } -RES _ResourceLoader::load(const String &p_path, const String &p_type_hint, bool p_no_cache) { +RES _ResourceLoader::load(const String &p_path, const String &p_type_hint, CacheMode p_cache_mode) { Error err = OK; - RES ret = ResourceLoader::load(p_path, p_type_hint, p_no_cache, &err); + RES ret = ResourceLoader::load(p_path, p_type_hint, ResourceFormatLoader::CacheMode(p_cache_mode), &err); ERR_FAIL_COND_V_MSG(err != OK, ret, "Error loading resource: '" + p_path + "'."); return ret; @@ -135,7 +135,7 @@ void _ResourceLoader::_bind_methods() { ClassDB::bind_method(D_METHOD("load_threaded_get_status", "path", "progress"), &_ResourceLoader::load_threaded_get_status, DEFVAL(Array())); ClassDB::bind_method(D_METHOD("load_threaded_get", "path"), &_ResourceLoader::load_threaded_get); - ClassDB::bind_method(D_METHOD("load", "path", "type_hint", "no_cache"), &_ResourceLoader::load, DEFVAL(""), DEFVAL(false)); + ClassDB::bind_method(D_METHOD("load", "path", "type_hint", "no_cache"), &_ResourceLoader::load, DEFVAL(""), DEFVAL(CACHE_MODE_REUSE)); ClassDB::bind_method(D_METHOD("get_recognized_extensions_for_type", "type"), &_ResourceLoader::get_recognized_extensions_for_type); ClassDB::bind_method(D_METHOD("set_abort_on_missing_resources", "abort"), &_ResourceLoader::set_abort_on_missing_resources); ClassDB::bind_method(D_METHOD("get_dependencies", "path"), &_ResourceLoader::get_dependencies); @@ -146,6 +146,10 @@ void _ResourceLoader::_bind_methods() { BIND_ENUM_CONSTANT(THREAD_LOAD_IN_PROGRESS); BIND_ENUM_CONSTANT(THREAD_LOAD_FAILED); BIND_ENUM_CONSTANT(THREAD_LOAD_LOADED); + + BIND_ENUM_CONSTANT(CACHE_MODE_IGNORE); + BIND_ENUM_CONSTANT(CACHE_MODE_REUSE); + BIND_ENUM_CONSTANT(CACHE_MODE_REPLACE); } ////// _ResourceSaver ////// @@ -1250,6 +1254,11 @@ Error _File::open(const String &p_path, ModeFlags p_mode_flags) { return err; } +void _File::flush() { + ERR_FAIL_COND_MSG(!f, "File must be opened before flushing."); + f->flush(); +} + void _File::close() { if (f) { memdelete(f); @@ -1543,6 +1552,7 @@ void _File::_bind_methods() { ClassDB::bind_method(D_METHOD("open_compressed", "path", "mode_flags", "compression_mode"), &_File::open_compressed, DEFVAL(0)); ClassDB::bind_method(D_METHOD("open", "path", "flags"), &_File::open); + ClassDB::bind_method(D_METHOD("flush"), &_File::flush); ClassDB::bind_method(D_METHOD("close"), &_File::close); ClassDB::bind_method(D_METHOD("get_path"), &_File::get_path); ClassDB::bind_method(D_METHOD("get_path_absolute"), &_File::get_path_absolute); diff --git a/core/core_bind.h b/core/core_bind.h index 3305c93089..7f945a9314 100644 --- a/core/core_bind.h +++ b/core/core_bind.h @@ -56,13 +56,19 @@ public: THREAD_LOAD_LOADED }; + enum CacheMode { + CACHE_MODE_IGNORE, //resource and subresources do not use path cache, no path is set into resource. + CACHE_MODE_REUSE, //resource and subresources use patch cache, reuse existing loaded resources instead of loading from disk when available + CACHE_MODE_REPLACE, //resource and and subresource use path cache, but replace existing loaded resources when available with information from disk + }; + static _ResourceLoader *get_singleton() { return singleton; } Error load_threaded_request(const String &p_path, const String &p_type_hint = "", bool p_use_sub_threads = false); ThreadLoadStatus load_threaded_get_status(const String &p_path, Array r_progress = Array()); RES load_threaded_get(const String &p_path); - RES load(const String &p_path, const String &p_type_hint = "", bool p_no_cache = false); + RES load(const String &p_path, const String &p_type_hint = "", CacheMode p_cache_mode = CACHE_MODE_REUSE); Vector<String> get_recognized_extensions_for_type(const String &p_type); void set_abort_on_missing_resources(bool p_abort); PackedStringArray get_dependencies(const String &p_path); @@ -73,6 +79,7 @@ public: }; VARIANT_ENUM_CAST(_ResourceLoader::ThreadLoadStatus); +VARIANT_ENUM_CAST(_ResourceLoader::CacheMode); class _ResourceSaver : public Object { GDCLASS(_ResourceSaver, Object); @@ -379,6 +386,7 @@ public: Error open_compressed(const String &p_path, ModeFlags p_mode_flags, CompressionMode p_compress_mode = COMPRESSION_FASTLZ); Error open(const String &p_path, ModeFlags p_mode_flags); // open a file. + void flush(); // Flush a file (write its buffer to disk). void close(); // Close a file. bool is_open() const; // True when file is open. diff --git a/core/crypto/crypto.cpp b/core/crypto/crypto.cpp index 99f4fb232d..f43f3e3290 100644 --- a/core/crypto/crypto.cpp +++ b/core/crypto/crypto.cpp @@ -141,7 +141,7 @@ void Crypto::_bind_methods() { /// Resource loader/saver -RES ResourceFormatLoaderCrypto::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) { +RES ResourceFormatLoaderCrypto::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_cache_mode) { String el = p_path.get_extension().to_lower(); if (el == "crt") { X509Certificate *cert = X509Certificate::create(); diff --git a/core/crypto/crypto.h b/core/crypto/crypto.h index 30d2129e3d..9438fcfea5 100644 --- a/core/crypto/crypto.h +++ b/core/crypto/crypto.h @@ -116,7 +116,7 @@ public: class ResourceFormatLoaderCrypto : public ResourceFormatLoader { public: - virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, bool p_no_cache = false); + virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, CacheMode p_cache_mode = CACHE_MODE_REUSE); virtual void get_recognized_extensions(List<String> *p_extensions) const; virtual bool handles_type(const String &p_type) const; virtual String get_resource_type(const String &p_path) const; diff --git a/core/io/image.cpp b/core/io/image.cpp index 986c29b539..5d46d75efe 100644 --- a/core/io/image.cpp +++ b/core/io/image.cpp @@ -2985,6 +2985,26 @@ void Image::set_pixel(int p_x, int p_y, const Color &p_color) { _set_color_at_ofs(data.ptrw(), ofs, p_color); } +void Image::adjust_bcs(float p_brightness, float p_contrast, float p_saturation) { + uint8_t *w = data.ptrw(); + uint32_t pixel_size = get_format_pixel_size(format); + uint32_t pixel_count = data.size() / pixel_size; + + for (uint32_t i = 0; i < pixel_count; i++) { + Color c = _get_color_at_ofs(w, i); + Vector3 rgb(c.r, c.g, c.b); + + rgb *= p_brightness; + rgb = Vector3(0.5, 0.5, 0.5).lerp(rgb, p_contrast); + float center = (rgb.x + rgb.y + rgb.z) / 3.0; + rgb = Vector3(center, center, center).lerp(rgb, p_saturation); + c.r = rgb.x; + c.g = rgb.y; + c.b = rgb.z; + _set_color_at_ofs(w, i, c); + } +} + Image::UsedChannels Image::detect_used_channels(CompressSource p_source) { ERR_FAIL_COND_V(data.size() == 0, USED_CHANNELS_RGBA); ERR_FAIL_COND_V(is_compressed(), USED_CHANNELS_RGBA); @@ -3132,6 +3152,8 @@ void Image::_bind_methods() { ClassDB::bind_method(D_METHOD("set_pixelv", "point", "color"), &Image::set_pixelv); ClassDB::bind_method(D_METHOD("set_pixel", "x", "y", "color"), &Image::set_pixel); + ClassDB::bind_method(D_METHOD("adjust_bcs", "brightness", "contrast", "saturation"), &Image::adjust_bcs); + ClassDB::bind_method(D_METHOD("load_png_from_buffer", "buffer"), &Image::load_png_from_buffer); ClassDB::bind_method(D_METHOD("load_jpg_from_buffer", "buffer"), &Image::load_jpg_from_buffer); ClassDB::bind_method(D_METHOD("load_webp_from_buffer", "buffer"), &Image::load_webp_from_buffer); diff --git a/core/io/image.h b/core/io/image.h index b894be7df4..df8f9b35a1 100644 --- a/core/io/image.h +++ b/core/io/image.h @@ -390,6 +390,8 @@ public: void set_pixelv(const Point2i &p_point, const Color &p_color); void set_pixel(int p_x, int p_y, const Color &p_color); + void adjust_bcs(float p_brightness, float p_contrast, float p_saturation); + void set_as_black(); void copy_internals_from(const Ref<Image> &p_image) { diff --git a/core/io/image_loader.cpp b/core/io/image_loader.cpp index 8ca1cb3beb..7de038e6fe 100644 --- a/core/io/image_loader.cpp +++ b/core/io/image_loader.cpp @@ -122,7 +122,7 @@ void ImageLoader::cleanup() { ///////////////// -RES ResourceFormatLoaderImage::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) { +RES ResourceFormatLoaderImage::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_cache_mode) { FileAccess *f = FileAccess::open(p_path, FileAccess::READ); if (!f) { if (r_error) { diff --git a/core/io/image_loader.h b/core/io/image_loader.h index bf67e1486f..a5d588e0b5 100644 --- a/core/io/image_loader.h +++ b/core/io/image_loader.h @@ -72,7 +72,7 @@ public: class ResourceFormatLoaderImage : public ResourceFormatLoader { public: - virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, bool p_no_cache = false); + virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, CacheMode p_cache_mode = CACHE_MODE_REUSE); virtual void get_recognized_extensions(List<String> *p_extensions) const; virtual bool handles_type(const String &p_type) const; virtual String get_resource_type(const String &p_path) const; diff --git a/core/io/resource.cpp b/core/io/resource.cpp index 801ec9432d..8560e2abc7 100644 --- a/core/io/resource.cpp +++ b/core/io/resource.cpp @@ -114,20 +114,18 @@ bool Resource::editor_can_reload_from_file() { return true; //by default yes } -void Resource::reload_from_file() { - String path = get_path(); - if (!path.is_resource_file()) { - return; +void Resource::reset_state() { +} +Error Resource::copy_from(const Ref<Resource> &p_resource) { + ERR_FAIL_COND_V(p_resource.is_null(), ERR_INVALID_PARAMETER); + if (get_class() != p_resource->get_class()) { + return ERR_INVALID_PARAMETER; } - Ref<Resource> s = ResourceLoader::load(ResourceLoader::path_remap(path), get_class(), true); - - if (!s.is_valid()) { - return; - } + reset_state(); //may want to reset state List<PropertyInfo> pi; - s->get_property_list(&pi); + p_resource->get_property_list(&pi); for (List<PropertyInfo>::Element *E = pi.front(); E; E = E->next()) { if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) { @@ -137,8 +135,23 @@ void Resource::reload_from_file() { continue; //do not change path } - set(E->get().name, s->get(E->get().name)); + set(E->get().name, p_resource->get(E->get().name)); } + return OK; +} +void Resource::reload_from_file() { + String path = get_path(); + if (!path.is_resource_file()) { + return; + } + + Ref<Resource> s = ResourceLoader::load(ResourceLoader::path_remap(path), get_class(), ResourceFormatLoader::CACHE_MODE_IGNORE); + + if (!s.is_valid()) { + return; + } + + copy_from(s); } Ref<Resource> Resource::duplicate_for_local_scene(Node *p_for_scene, Map<Ref<Resource>, Ref<Resource>> &remap_cache) { diff --git a/core/io/resource.h b/core/io/resource.h index d0cd6ea3ac..ae18ac0c8a 100644 --- a/core/io/resource.h +++ b/core/io/resource.h @@ -90,6 +90,8 @@ public: static Node *(*_get_local_scene_func)(); //used by editor virtual bool editor_can_reload_from_file(); + virtual void reset_state(); //for resources that use variable amount of properties, either via _validate_property or _get_property_list, this function needs to be implemented to correctly clear state + virtual Error copy_from(const Ref<Resource> &p_resource); virtual void reload_from_file(); void register_owner(Object *p_owner); diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp index fad58d65fd..fb6ad7d65e 100644 --- a/core/io/resource_format_binary.cpp +++ b/core/io/resource_format_binary.cpp @@ -313,17 +313,12 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) { uint32_t index = f->get_32(); String path = res_path + "::" + itos(index); - if (use_nocache) { - if (!internal_index_cache.has(path)) { - WARN_PRINT(String("Couldn't load resource (no cache): " + path).utf8().get_data()); - } - r_v = internal_index_cache[path]; + //always use internal cache for loading internal resources + if (!internal_index_cache.has(path)) { + WARN_PRINT(String("Couldn't load resource (no cache): " + path).utf8().get_data()); + r_v = Variant(); } else { - RES res = ResourceLoader::load(path); - if (res.is_null()) { - WARN_PRINT(String("Couldn't load resource: " + path).utf8().get_data()); - } - r_v = res; + r_v = internal_index_cache[path]; } } break; @@ -645,7 +640,7 @@ Error ResourceLoaderBinary::load() { } } else { - Error err = ResourceLoader::load_threaded_request(path, external_resources[i].type, use_sub_threads, local_path); + Error err = ResourceLoader::load_threaded_request(path, external_resources[i].type, use_sub_threads, ResourceFormatLoader::CACHE_MODE_REUSE, local_path); if (err != OK) { if (!ResourceLoader::get_abort_on_missing_resources()) { ResourceLoader::notify_dependency_error(local_path, path, external_resources[i].type); @@ -675,7 +670,7 @@ Error ResourceLoaderBinary::load() { path = res_path + "::" + path; } - if (!use_nocache) { + if (cache_mode == ResourceFormatLoader::CACHE_MODE_REUSE) { if (ResourceCache::has(path)) { //already loaded, don't do anything stage++; @@ -684,7 +679,7 @@ Error ResourceLoaderBinary::load() { } } } else { - if (!use_nocache && !ResourceCache::has(res_path)) { + if (cache_mode != ResourceFormatLoader::CACHE_MODE_IGNORE && !ResourceCache::has(res_path)) { path = res_path; } } @@ -695,26 +690,40 @@ Error ResourceLoaderBinary::load() { String t = get_unicode_string(); - Object *obj = ClassDB::instance(t); - if (!obj) { - error = ERR_FILE_CORRUPT; - ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, local_path + ":Resource of unrecognized type in file: " + t + "."); - } + RES res; - Resource *r = Object::cast_to<Resource>(obj); - if (!r) { - String obj_class = obj->get_class(); - error = ERR_FILE_CORRUPT; - memdelete(obj); //bye - ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, local_path + ":Resource type in resource field not a resource, type is: " + obj_class + "."); + if (cache_mode == ResourceFormatLoader::CACHE_MODE_REPLACE && ResourceCache::has(path)) { + //use the existing one + Resource *r = ResourceCache::get(path); + if (r->get_class() == t) { + r->reset_state(); + res = Ref<Resource>(r); + } } - RES res = RES(r); + if (res.is_null()) { + //did not replace - if (path != String()) { - r->set_path(path); + Object *obj = ClassDB::instance(t); + if (!obj) { + error = ERR_FILE_CORRUPT; + ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, local_path + ":Resource of unrecognized type in file: " + t + "."); + } + + Resource *r = Object::cast_to<Resource>(obj); + if (!r) { + String obj_class = obj->get_class(); + error = ERR_FILE_CORRUPT; + memdelete(obj); //bye + ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, local_path + ":Resource type in resource field not a resource, type is: " + obj_class + "."); + } + + res = RES(r); + if (path != String() && cache_mode != ResourceFormatLoader::CACHE_MODE_IGNORE) { + r->set_path(path, cache_mode == ResourceFormatLoader::CACHE_MODE_REPLACE); //if got here because the resource with same path has different type, replace it + } + r->set_subindex(subindex); } - r->set_subindex(subindex); if (!main) { internal_index_cache[path] = res; @@ -961,7 +970,7 @@ ResourceLoaderBinary::~ResourceLoaderBinary() { } } -RES ResourceFormatLoaderBinary::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) { +RES ResourceFormatLoaderBinary::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_cache_mode) { if (r_error) { *r_error = ERR_FILE_CANT_OPEN; } @@ -972,7 +981,7 @@ RES ResourceFormatLoaderBinary::load(const String &p_path, const String &p_origi ERR_FAIL_COND_V_MSG(err != OK, RES(), "Cannot open file '" + p_path + "'."); ResourceLoaderBinary loader; - loader.use_nocache = p_no_cache; + loader.cache_mode = p_cache_mode; loader.use_sub_threads = p_use_sub_threads; loader.progress = r_progress; String path = p_original_path != "" ? p_original_path : p_path; diff --git a/core/io/resource_format_binary.h b/core/io/resource_format_binary.h index 428725f1d2..3592bbdbc4 100644 --- a/core/io/resource_format_binary.h +++ b/core/io/resource_format_binary.h @@ -78,7 +78,7 @@ class ResourceLoaderBinary { Map<String, String> remaps; Error error = OK; - bool use_nocache = false; + ResourceFormatLoader::CacheMode cache_mode = ResourceFormatLoader::CACHE_MODE_REUSE; friend class ResourceFormatLoaderBinary; @@ -103,7 +103,7 @@ public: class ResourceFormatLoaderBinary : public ResourceFormatLoader { public: - virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, bool p_no_cache = false); + virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, CacheMode p_cache_mode = CACHE_MODE_REUSE); virtual void get_recognized_extensions_for_type(const String &p_type, List<String> *p_extensions) const; virtual void get_recognized_extensions(List<String> *p_extensions) const; virtual bool handles_type(const String &p_type) const; diff --git a/core/io/resource_importer.cpp b/core/io/resource_importer.cpp index d86877ee14..3e460726f6 100644 --- a/core/io/resource_importer.cpp +++ b/core/io/resource_importer.cpp @@ -116,7 +116,7 @@ Error ResourceFormatImporter::_get_path_and_type(const String &p_path, PathAndTy return OK; } -RES ResourceFormatImporter::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) { +RES ResourceFormatImporter::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_cache_mode) { PathAndType pat; Error err = _get_path_and_type(p_path, pat); @@ -128,7 +128,7 @@ RES ResourceFormatImporter::load(const String &p_path, const String &p_original_ return RES(); } - RES res = ResourceLoader::_load(pat.path, p_path, pat.type, p_no_cache, r_error, p_use_sub_threads, r_progress); + RES res = ResourceLoader::_load(pat.path, p_path, pat.type, p_cache_mode, r_error, p_use_sub_threads, r_progress); #ifdef TOOLS_ENABLED if (res.is_valid()) { diff --git a/core/io/resource_importer.h b/core/io/resource_importer.h index d31273e3cb..bda8b74b73 100644 --- a/core/io/resource_importer.h +++ b/core/io/resource_importer.h @@ -57,7 +57,7 @@ class ResourceFormatImporter : public ResourceFormatLoader { public: static ResourceFormatImporter *get_singleton() { return singleton; } - virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, bool p_no_cache = false); + virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, CacheMode p_cache_mode = CACHE_MODE_REUSE); virtual void get_recognized_extensions(List<String> *p_extensions) const; virtual void get_recognized_extensions_for_type(const String &p_type, List<String> *p_extensions) const; virtual bool recognize_path(const String &p_path, const String &p_for_type = String()) const; diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp index d66511a39f..588af0f0ae 100644 --- a/core/io/resource_loader.cpp +++ b/core/io/resource_loader.cpp @@ -113,9 +113,9 @@ void ResourceFormatLoader::get_recognized_extensions(List<String> *p_extensions) } } -RES ResourceFormatLoader::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) { +RES ResourceFormatLoader::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_cache_mode) { if (get_script_instance() && get_script_instance()->has_method("load")) { - Variant res = get_script_instance()->call("load", p_path, p_original_path, p_use_sub_threads); + Variant res = get_script_instance()->call("load", p_path, p_original_path, p_use_sub_threads, p_cache_mode); if (res.get_type() == Variant::INT) { if (r_error) { @@ -164,7 +164,7 @@ Error ResourceFormatLoader::rename_dependencies(const String &p_path, const Map< void ResourceFormatLoader::_bind_methods() { { - MethodInfo info = MethodInfo(Variant::NIL, "load", PropertyInfo(Variant::STRING, "path"), PropertyInfo(Variant::STRING, "original_path")); + MethodInfo info = MethodInfo(Variant::NIL, "load", PropertyInfo(Variant::STRING, "path"), PropertyInfo(Variant::STRING, "original_path"), PropertyInfo(Variant::BOOL, "use_sub_threads"), PropertyInfo(Variant::INT, "cache_mode")); info.return_val.usage |= PROPERTY_USAGE_NIL_IS_VARIANT; ClassDB::add_virtual_method(get_class_static(), info); } @@ -178,7 +178,7 @@ void ResourceFormatLoader::_bind_methods() { /////////////////////////////////// -RES ResourceLoader::_load(const String &p_path, const String &p_original_path, const String &p_type_hint, bool p_no_cache, Error *r_error, bool p_use_sub_threads, float *r_progress) { +RES ResourceLoader::_load(const String &p_path, const String &p_original_path, const String &p_type_hint, ResourceFormatLoader::CacheMode p_cache_mode, Error *r_error, bool p_use_sub_threads, float *r_progress) { bool found = false; // Try all loaders and pick the first match for the type hint @@ -187,7 +187,7 @@ RES ResourceLoader::_load(const String &p_path, const String &p_original_path, c continue; } found = true; - RES res = loader[i]->load(p_path, p_original_path != String() ? p_original_path : p_path, r_error, p_use_sub_threads, r_progress, p_no_cache); + RES res = loader[i]->load(p_path, p_original_path != String() ? p_original_path : p_path, r_error, p_use_sub_threads, r_progress, p_cache_mode); if (res.is_null()) { continue; } @@ -214,7 +214,7 @@ void ResourceLoader::_thread_load_function(void *p_userdata) { //this is an actual thread, so wait for Ok fom semaphore thread_load_semaphore->wait(); //wait until its ok to start loading } - load_task.resource = _load(load_task.remapped_path, load_task.remapped_path != load_task.local_path ? load_task.local_path : String(), load_task.type_hint, false, &load_task.error, load_task.use_sub_threads, &load_task.progress); + load_task.resource = _load(load_task.remapped_path, load_task.remapped_path != load_task.local_path ? load_task.local_path : String(), load_task.type_hint, load_task.cache_mode, &load_task.error, load_task.use_sub_threads, &load_task.progress); load_task.progress = 1.0; //it was fully loaded at this point, so force progress to 1.0 @@ -267,7 +267,7 @@ void ResourceLoader::_thread_load_function(void *p_userdata) { thread_load_mutex->unlock(); } -Error ResourceLoader::load_threaded_request(const String &p_path, const String &p_type_hint, bool p_use_sub_threads, const String &p_source_resource) { +Error ResourceLoader::load_threaded_request(const String &p_path, const String &p_type_hint, bool p_use_sub_threads, ResourceFormatLoader::CacheMode p_cache_mode, const String &p_source_resource) { String local_path; if (p_path.is_rel_path()) { local_path = "res://" + p_path; @@ -314,6 +314,7 @@ Error ResourceLoader::load_threaded_request(const String &p_path, const String & load_task.remapped_path = _path_remap(local_path, &load_task.xl_remapped); load_task.local_path = local_path; load_task.type_hint = p_type_hint; + load_task.cache_mode = p_cache_mode; load_task.use_sub_threads = p_use_sub_threads; { //must check if resource is already loaded before attempting to load it in a thread @@ -501,7 +502,7 @@ RES ResourceLoader::load_threaded_get(const String &p_path, Error *r_error) { return resource; } -RES ResourceLoader::load(const String &p_path, const String &p_type_hint, bool p_no_cache, Error *r_error) { +RES ResourceLoader::load(const String &p_path, const String &p_type_hint, ResourceFormatLoader::CacheMode p_cache_mode, Error *r_error) { if (r_error) { *r_error = ERR_CANT_OPEN; } @@ -513,7 +514,7 @@ RES ResourceLoader::load(const String &p_path, const String &p_type_hint, bool p local_path = ProjectSettings::get_singleton()->localize_path(p_path); } - if (!p_no_cache) { + if (p_cache_mode == ResourceFormatLoader::CACHE_MODE_IGNORE) { thread_load_mutex->lock(); //Is it already being loaded? poll until done @@ -561,6 +562,7 @@ RES ResourceLoader::load(const String &p_path, const String &p_type_hint, bool p load_task.local_path = local_path; load_task.remapped_path = _path_remap(local_path, &load_task.xl_remapped); load_task.type_hint = p_type_hint; + load_task.cache_mode = p_cache_mode; //ignore load_task.loader_id = Thread::get_caller_id(); thread_load_tasks[local_path] = load_task; @@ -581,7 +583,7 @@ RES ResourceLoader::load(const String &p_path, const String &p_type_hint, bool p print_verbose("Loading resource: " + path); float p; - RES res = _load(path, local_path, p_type_hint, p_no_cache, r_error, false, &p); + RES res = _load(path, local_path, p_type_hint, p_cache_mode, r_error, false, &p); if (res.is_null()) { print_verbose("Failed loading resource: " + path); diff --git a/core/io/resource_loader.h b/core/io/resource_loader.h index dbf6be46c5..38a756c52f 100644 --- a/core/io/resource_loader.h +++ b/core/io/resource_loader.h @@ -38,11 +38,18 @@ class ResourceFormatLoader : public Reference { GDCLASS(ResourceFormatLoader, Reference); +public: + enum CacheMode { + CACHE_MODE_IGNORE, //resource and subresources do not use path cache, no path is set into resource. + CACHE_MODE_REUSE, //resource and subresources use patch cache, reuse existing loaded resources instead of loading from disk when available + CACHE_MODE_REPLACE, //resource and and subresource use path cache, but replace existing loaded resources when available with information from disk + }; + protected: static void _bind_methods(); public: - virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, bool p_no_cache = false); + virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, CacheMode p_cache_mode = CACHE_MODE_REUSE); virtual bool exists(const String &p_path) const; virtual void get_recognized_extensions(List<String> *p_extensions) const; virtual void get_recognized_extensions_for_type(const String &p_type, List<String> *p_extensions) const; @@ -99,7 +106,7 @@ private: friend class ResourceFormatImporter; friend class ResourceInteractiveLoader; //internal load function - static RES _load(const String &p_path, const String &p_original_path, const String &p_type_hint, bool p_no_cache, Error *r_error, bool p_use_sub_threads, float *r_progress); + static RES _load(const String &p_path, const String &p_original_path, const String &p_type_hint, ResourceFormatLoader::CacheMode p_cache_mode, Error *r_error, bool p_use_sub_threads, float *r_progress); static ResourceLoadedCallback _loaded_callback; @@ -114,6 +121,7 @@ private: String type_hint; float progress = 0.0; ThreadLoadStatus status = THREAD_LOAD_IN_PROGRESS; + ResourceFormatLoader::CacheMode cache_mode = ResourceFormatLoader::CACHE_MODE_REUSE; Error error = OK; RES resource; bool xl_remapped = false; @@ -136,11 +144,11 @@ private: static float _dependency_get_progress(const String &p_path); public: - static Error load_threaded_request(const String &p_path, const String &p_type_hint = "", bool p_use_sub_threads = false, const String &p_source_resource = String()); + static Error load_threaded_request(const String &p_path, const String &p_type_hint = "", bool p_use_sub_threads = false, ResourceFormatLoader::CacheMode p_cache_mode = ResourceFormatLoader::CACHE_MODE_REUSE, const String &p_source_resource = String()); static ThreadLoadStatus load_threaded_get_status(const String &p_path, float *r_progress = nullptr); static RES load_threaded_get(const String &p_path, Error *r_error = nullptr); - static RES load(const String &p_path, const String &p_type_hint = "", bool p_no_cache = false, Error *r_error = nullptr); + static RES load(const String &p_path, const String &p_type_hint = "", ResourceFormatLoader::CacheMode p_cache_mode = ResourceFormatLoader::CACHE_MODE_REUSE, Error *r_error = nullptr); static bool exists(const String &p_path, const String &p_type_hint = ""); static void get_recognized_extensions_for_type(const String &p_type, List<String> *p_extensions); diff --git a/core/io/translation_loader_po.cpp b/core/io/translation_loader_po.cpp index ce2c3eb1cd..0e11ff514a 100644 --- a/core/io/translation_loader_po.cpp +++ b/core/io/translation_loader_po.cpp @@ -277,7 +277,7 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error) { return translation; } -RES TranslationLoaderPO::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) { +RES TranslationLoaderPO::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_cache_mode) { if (r_error) { *r_error = ERR_CANT_OPEN; } diff --git a/core/io/translation_loader_po.h b/core/io/translation_loader_po.h index a524972588..36d33fcac3 100644 --- a/core/io/translation_loader_po.h +++ b/core/io/translation_loader_po.h @@ -38,7 +38,7 @@ class TranslationLoaderPO : public ResourceFormatLoader { public: static RES load_translation(FileAccess *f, Error *r_error = nullptr); - virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, bool p_no_cache = false); + virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, CacheMode p_cache_mode = CACHE_MODE_REUSE); virtual void get_recognized_extensions(List<String> *p_extensions) const; virtual bool handles_type(const String &p_type) const; virtual String get_resource_type(const String &p_path) const; diff --git a/core/object/script_language.cpp b/core/object/script_language.cpp index d0636e8b84..42fb0a0caf 100644 --- a/core/object/script_language.cpp +++ b/core/object/script_language.cpp @@ -275,6 +275,14 @@ void ScriptServer::save_global_classes() { gcarr.push_back(d); } + Array old; + if (ProjectSettings::get_singleton()->has_setting("_global_script_classes")) { + old = ProjectSettings::get_singleton()->get("_global_script_classes"); + } + if ((!old.is_empty() || gcarr.is_empty()) && gcarr.hash() == old.hash()) { + return; + } + if (gcarr.is_empty()) { if (ProjectSettings::get_singleton()->has_setting("_global_script_classes")) { ProjectSettings::get_singleton()->clear("_global_script_classes"); diff --git a/doc/classes/File.xml b/doc/classes/File.xml index ff03f44789..e0781e807f 100644 --- a/doc/classes/File.xml +++ b/doc/classes/File.xml @@ -42,6 +42,7 @@ [/codeblocks] In the example above, the file will be saved in the user data folder as specified in the [url=https://docs.godotengine.org/en/latest/tutorials/io/data_paths.html]Data paths[/url] documentation. [b]Note:[/b] To access project resources once exported, it is recommended to use [ResourceLoader] instead of the [File] API, as some files are converted to engine-specific formats and their original source files might not be present in the exported PCK package. + [b]Note:[/b] Files are automatically closed only if the process exits "normally" (such as by clicking the window manager's close button or pressing [b]Alt + F4[/b]). If you stop the project execution by pressing [b]F8[/b] while the project is running, the file won't be closed as the game process will be killed. You can work around this by calling [method flush] at regular intervals. </description> <tutorials> <link title="File system">https://docs.godotengine.org/en/latest/getting_started/step_by_step/filesystem.html</link> @@ -52,7 +53,7 @@ <return type="void"> </return> <description> - Closes the currently opened file. + Closes the currently opened file and prevents subsequent read/write operations. Use [method flush] to persist the data to disk without closing the file. </description> </method> <method name="eof_reached" qualifiers="const"> @@ -73,6 +74,14 @@ [b]Note:[/b] Many resources types are imported (e.g. textures or sound files), and their source asset will not be included in the exported game, as only the imported version is used. See [method ResourceLoader.exists] for an alternative approach that takes resource remapping into account. </description> </method> + <method name="flush"> + <return type="void"> + </return> + <description> + Writes the file's buffer to disk. Flushing is automatically performed when the file is closed. This means you don't need to call [method flush] manually before closing a file using [method close]. Still, calling [method flush] can be used to ensure the data is safe even if the project crashes instead of being closed gracefully. + [b]Note:[/b] Only call [method flush] when you actually need it. Otherwise, it will decrease performance due to constant disk writes. + </description> + </method> <method name="get_16" qualifiers="const"> <return type="int"> </return> diff --git a/doc/classes/PackedScene.xml b/doc/classes/PackedScene.xml index d15bcfd114..1d9be7f165 100644 --- a/doc/classes/PackedScene.xml +++ b/doc/classes/PackedScene.xml @@ -5,7 +5,7 @@ </brief_description> <description> A simplified interface to a scene file. Provides access to operations and checks that can be performed on the scene resource itself. - Can be used to save a node to a file. When saving, the node as well as all the node it owns get saved (see [code]owner[/code] property on [Node]). + Can be used to save a node to a file. When saving, the node as well as all the nodes it owns get saved (see [code]owner[/code] property on [Node]). [b]Note:[/b] The node doesn't need to own itself. [b]Example of loading a saved scene:[/b] [codeblocks] diff --git a/drivers/dummy/texture_loader_dummy.cpp b/drivers/dummy/texture_loader_dummy.cpp index 2484e6d140..f148e42845 100644 --- a/drivers/dummy/texture_loader_dummy.cpp +++ b/drivers/dummy/texture_loader_dummy.cpp @@ -35,7 +35,7 @@ #include <string.h> -RES ResourceFormatDummyTexture::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) { +RES ResourceFormatDummyTexture::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_cache_mode) { unsigned int width = 8; unsigned int height = 8; diff --git a/drivers/dummy/texture_loader_dummy.h b/drivers/dummy/texture_loader_dummy.h index 3b71b5824f..00e6b9cc53 100644 --- a/drivers/dummy/texture_loader_dummy.h +++ b/drivers/dummy/texture_loader_dummy.h @@ -36,7 +36,7 @@ class ResourceFormatDummyTexture : public ResourceFormatLoader { public: - virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, bool p_no_cache = false); + virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, CacheMode p_cache_mode = CACHE_MODE_REUSE); virtual void get_recognized_extensions(List<String> *p_extensions) const; virtual bool handles_type(const String &p_type) const; virtual String get_resource_type(const String &p_path) const; diff --git a/editor/editor_audio_buses.cpp b/editor/editor_audio_buses.cpp index 2eef4636d6..69a13957e6 100644 --- a/editor/editor_audio_buses.cpp +++ b/editor/editor_audio_buses.cpp @@ -1193,7 +1193,7 @@ void EditorAudioBuses::_load_layout() { void EditorAudioBuses::_load_default_layout() { String layout_path = ProjectSettings::get_singleton()->get("audio/default_bus_layout"); - Ref<AudioBusLayout> state = ResourceLoader::load(layout_path, "", true); + Ref<AudioBusLayout> state = ResourceLoader::load(layout_path, "", ResourceFormatLoader::CACHE_MODE_IGNORE); if (state.is_null()) { EditorNode::get_singleton()->show_warning(vformat(TTR("There is no '%s' file."), layout_path)); return; @@ -1209,7 +1209,7 @@ void EditorAudioBuses::_load_default_layout() { void EditorAudioBuses::_file_dialog_callback(const String &p_string) { if (file_dialog->get_file_mode() == EditorFileDialog::FILE_MODE_OPEN_FILE) { - Ref<AudioBusLayout> state = ResourceLoader::load(p_string, "", true); + Ref<AudioBusLayout> state = ResourceLoader::load(p_string, "", ResourceFormatLoader::CACHE_MODE_IGNORE); if (state.is_null()) { EditorNode::get_singleton()->show_warning(TTR("Invalid file, not an audio bus layout.")); return; @@ -1330,7 +1330,7 @@ EditorAudioBuses::EditorAudioBuses() { void EditorAudioBuses::open_layout(const String &p_path) { EditorNode::get_singleton()->make_bottom_panel_item_visible(this); - Ref<AudioBusLayout> state = ResourceLoader::load(p_path, "", true); + Ref<AudioBusLayout> state = ResourceLoader::load(p_path, "", ResourceFormatLoader::CACHE_MODE_IGNORE); if (state.is_null()) { EditorNode::get_singleton()->show_warning(TTR("Invalid file, not an audio bus layout.")); return; diff --git a/editor/editor_data.cpp b/editor/editor_data.cpp index 18364dc32f..213c3f5631 100644 --- a/editor/editor_data.cpp +++ b/editor/editor_data.cpp @@ -942,6 +942,14 @@ void EditorData::script_class_save_icon_paths() { } } + Dictionary old; + if (ProjectSettings::get_singleton()->has_setting("_global_script_class_icons")) { + old = ProjectSettings::get_singleton()->get("_global_script_class_icons"); + } + if ((!old.is_empty() || d.is_empty()) && d.hash() == old.hash()) { + return; + } + if (d.is_empty()) { if (ProjectSettings::get_singleton()->has_setting("_global_script_class_icons")) { ProjectSettings::get_singleton()->clear("_global_script_class_icons"); diff --git a/editor/editor_folding.cpp b/editor/editor_folding.cpp index 9f98795e16..97a2c67c26 100644 --- a/editor/editor_folding.cpp +++ b/editor/editor_folding.cpp @@ -259,13 +259,17 @@ void EditorFolding::_do_object_unfolds(Object *p_object, Set<RES> &resources) { } } } - } - if (E->get().type == Variant::OBJECT) { - RES res = p_object->get(E->get().name); - if (res.is_valid() && !resources.has(res) && res->get_path() != String() && !res->get_path().is_resource_file()) { - resources.insert(res); - _do_object_unfolds(res.ptr(), resources); + if (E->get().type == Variant::OBJECT) { + RES res = p_object->get(E->get().name); + print_line("res: " + String(E->get().name) + " valid " + itos(res.is_valid())); + if (res.is_valid()) { + print_line("path " + res->get_path()); + } + if (res.is_valid() && !resources.has(res) && res->get_path() != String() && !res->get_path().is_resource_file()) { + resources.insert(res); + _do_object_unfolds(res.ptr(), resources); + } } } } diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp index 5fd03e44b9..a7f808f63a 100644 --- a/editor/editor_inspector.cpp +++ b/editor/editor_inspector.cpp @@ -81,7 +81,7 @@ Size2 EditorProperty::get_minimum_size() const { } if (bottom_editor != nullptr && bottom_editor->is_visible()) { - ms.height += get_theme_constant("vseparation", "Tree"); + ms.height += get_theme_constant("vseparation"); Size2 bems = bottom_editor->get_combined_minimum_size(); //bems.width += get_constant("item_margin", "Tree"); ms.height += bems.height; @@ -149,7 +149,7 @@ void EditorProperty::_notification(int p_what) { if (bottom_editor) { int m = 0; //get_constant("item_margin", "Tree"); - bottom_rect = Rect2(m, rect.size.height + get_theme_constant("vseparation", "Tree"), size.width - m, bottom_editor->get_combined_minimum_size().height); + bottom_rect = Rect2(m, rect.size.height + get_theme_constant("vseparation"), size.width - m, bottom_editor->get_combined_minimum_size().height); } if (keying) { @@ -226,11 +226,15 @@ void EditorProperty::_notification(int p_what) { size.height = label_reference->get_size().height; } + Ref<StyleBox> sb; if (selected) { - Ref<StyleBox> sb = get_theme_stylebox("selected", "Tree"); - draw_style_box(sb, Rect2(Vector2(), size)); + sb = get_theme_stylebox("bg_selected"); + } else { + sb = get_theme_stylebox("bg"); } + draw_style_box(sb, Rect2(Vector2(), size)); + if (draw_top_bg && right_child_rect != Rect2()) { draw_rect(right_child_rect, dark_color); } @@ -240,15 +244,15 @@ void EditorProperty::_notification(int p_what) { Color color; if (draw_red) { - color = get_theme_color("error_color", "Editor"); + color = get_theme_color("error_color"); } else { - color = get_theme_color("property_color", "Editor"); + color = get_theme_color("property_color"); } if (label.find(".") != -1) { color.a = 0.5; //this should be un-hacked honestly, as it's used for editor overrides } - int ofs = 0; + int ofs = get_theme_constant("font_offset"); int text_limit = text_size; if (checkable) { @@ -2180,17 +2184,30 @@ void EditorInspector::set_use_wide_editors(bool p_enable) { wide_editors = p_enable; } +void EditorInspector::_update_inspector_bg() { + if (sub_inspector) { + int count_subinspectors = 0; + Node *n = get_parent(); + while (n) { + EditorInspector *ei = Object::cast_to<EditorInspector>(n); + if (ei && ei->sub_inspector) { + count_subinspectors++; + } + n = n->get_parent(); + } + count_subinspectors = MIN(15, count_subinspectors); + add_theme_style_override("bg", get_theme_stylebox("sub_inspector_bg" + itos(count_subinspectors), "Editor")); + } else { + add_theme_style_override("bg", get_theme_stylebox("bg", "Tree")); + } +} void EditorInspector::set_sub_inspector(bool p_enable) { sub_inspector = p_enable; if (!is_inside_tree()) { return; } - if (sub_inspector) { - add_theme_style_override("bg", get_theme_stylebox("sub_inspector_bg", "Editor")); - } else { - add_theme_style_override("bg", get_theme_stylebox("bg", "Tree")); - } + _update_inspector_bg(); } void EditorInspector::set_use_deletable_properties(bool p_enabled) { @@ -2418,10 +2435,8 @@ void EditorInspector::_notification(int p_what) { } if (p_what == NOTIFICATION_ENTER_TREE) { - if (sub_inspector) { - add_theme_style_override("bg", get_theme_stylebox("sub_inspector_bg", "Editor")); - } else { - add_theme_style_override("bg", get_theme_stylebox("bg", "Tree")); + _update_inspector_bg(); + if (!sub_inspector) { get_tree()->connect("node_removed", callable_mp(this, &EditorInspector::_node_removed)); } } @@ -2485,11 +2500,7 @@ void EditorInspector::_notification(int p_what) { } if (p_what == EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED) { - if (sub_inspector) { - add_theme_style_override("bg", get_theme_stylebox("sub_inspector_bg", "Editor")); - } else if (is_inside_tree()) { - add_theme_style_override("bg", get_theme_stylebox("bg", "Tree")); - } + _update_inspector_bg(); update_tree(); } diff --git a/editor/editor_inspector.h b/editor/editor_inspector.h index ad8c1611b0..b98801975f 100644 --- a/editor/editor_inspector.h +++ b/editor/editor_inspector.h @@ -343,6 +343,8 @@ class EditorInspector : public ScrollContainer { bool _is_property_disabled_by_feature_profile(const StringName &p_property); + void _update_inspector_bg(); + protected: static void _bind_methods(); void _notification(int p_what); @@ -394,6 +396,7 @@ public: void set_use_wide_editors(bool p_enable); void set_sub_inspector(bool p_enable); + bool is_sub_inspector() const { return sub_inspector; } void set_use_deletable_properties(bool p_enabled); diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index dba19df578..57fa552845 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -430,6 +430,74 @@ void EditorNode::_unhandled_input(const Ref<InputEvent> &p_event) { } } +void EditorNode::_update_from_settings() { + int current_filter = GLOBAL_GET("rendering/canvas_textures/default_texture_filter"); + if (current_filter != scene_root->get_default_canvas_item_texture_filter()) { + Viewport::DefaultCanvasItemTextureFilter tf = (Viewport::DefaultCanvasItemTextureFilter)current_filter; + scene_root->set_default_canvas_item_texture_filter(tf); + } + int current_repeat = GLOBAL_GET("rendering/canvas_textures/default_texture_repeat"); + if (current_repeat != scene_root->get_default_canvas_item_texture_repeat()) { + Viewport::DefaultCanvasItemTextureRepeat tr = (Viewport::DefaultCanvasItemTextureRepeat)current_repeat; + scene_root->set_default_canvas_item_texture_repeat(tr); + } + + RS::DOFBokehShape dof_shape = RS::DOFBokehShape(int(GLOBAL_GET("rendering/quality/depth_of_field/depth_of_field_bokeh_shape"))); + RS::get_singleton()->camera_effects_set_dof_blur_bokeh_shape(dof_shape); + RS::DOFBlurQuality dof_quality = RS::DOFBlurQuality(int(GLOBAL_GET("rendering/quality/depth_of_field/depth_of_field_bokeh_quality"))); + bool dof_jitter = GLOBAL_GET("rendering/quality/depth_of_field/depth_of_field_use_jitter"); + RS::get_singleton()->camera_effects_set_dof_blur_quality(dof_quality, dof_jitter); + RS::get_singleton()->environment_set_ssao_quality(RS::EnvironmentSSAOQuality(int(GLOBAL_GET("rendering/quality/ssao/quality"))), GLOBAL_GET("rendering/quality/ssao/half_size"), GLOBAL_GET("rendering/quality/ssao/adaptive_target"), GLOBAL_GET("rendering/quality/ssao/blur_passes"), GLOBAL_GET("rendering/quality/ssao/fadeout_from"), GLOBAL_GET("rendering/quality/ssao/fadeout_to")); + RS::get_singleton()->screen_space_roughness_limiter_set_active(GLOBAL_GET("rendering/quality/screen_filters/screen_space_roughness_limiter_enabled"), GLOBAL_GET("rendering/quality/screen_filters/screen_space_roughness_limiter_amount"), GLOBAL_GET("rendering/quality/screen_filters/screen_space_roughness_limiter_limit")); + bool glow_bicubic = int(GLOBAL_GET("rendering/quality/glow/upscale_mode")) > 0; + RS::get_singleton()->environment_glow_set_use_bicubic_upscale(glow_bicubic); + bool glow_high_quality = GLOBAL_GET("rendering/quality/glow/use_high_quality"); + RS::get_singleton()->environment_glow_set_use_high_quality(glow_high_quality); + RS::EnvironmentSSRRoughnessQuality ssr_roughness_quality = RS::EnvironmentSSRRoughnessQuality(int(GLOBAL_GET("rendering/quality/screen_space_reflection/roughness_quality"))); + RS::get_singleton()->environment_set_ssr_roughness_quality(ssr_roughness_quality); + RS::SubSurfaceScatteringQuality sss_quality = RS::SubSurfaceScatteringQuality(int(GLOBAL_GET("rendering/quality/subsurface_scattering/subsurface_scattering_quality"))); + RS::get_singleton()->sub_surface_scattering_set_quality(sss_quality); + float sss_scale = GLOBAL_GET("rendering/quality/subsurface_scattering/subsurface_scattering_scale"); + float sss_depth_scale = GLOBAL_GET("rendering/quality/subsurface_scattering/subsurface_scattering_depth_scale"); + RS::get_singleton()->sub_surface_scattering_set_scale(sss_scale, sss_depth_scale); + + uint32_t directional_shadow_size = GLOBAL_GET("rendering/quality/directional_shadow/size"); + uint32_t directional_shadow_16_bits = GLOBAL_GET("rendering/quality/directional_shadow/16_bits"); + RS::get_singleton()->directional_shadow_atlas_set_size(directional_shadow_size, directional_shadow_16_bits); + + RS::ShadowQuality shadows_quality = RS::ShadowQuality(int(GLOBAL_GET("rendering/quality/shadows/soft_shadow_quality"))); + RS::get_singleton()->shadows_quality_set(shadows_quality); + RS::ShadowQuality directional_shadow_quality = RS::ShadowQuality(int(GLOBAL_GET("rendering/quality/directional_shadow/soft_shadow_quality"))); + RS::get_singleton()->directional_shadow_quality_set(directional_shadow_quality); + float probe_update_speed = GLOBAL_GET("rendering/lightmapper/probe_capture_update_speed"); + RS::get_singleton()->lightmap_set_probe_capture_update_speed(probe_update_speed); + RS::EnvironmentSDFGIFramesToConverge frames_to_converge = RS::EnvironmentSDFGIFramesToConverge(int(GLOBAL_GET("rendering/sdfgi/frames_to_converge"))); + RS::get_singleton()->environment_set_sdfgi_frames_to_converge(frames_to_converge); + RS::EnvironmentSDFGIRayCount ray_count = RS::EnvironmentSDFGIRayCount(int(GLOBAL_GET("rendering/sdfgi/probe_ray_count"))); + RS::get_singleton()->environment_set_sdfgi_ray_count(ray_count); + RS::GIProbeQuality gi_probe_quality = RS::GIProbeQuality(int(GLOBAL_GET("rendering/quality/gi_probes/quality"))); + RS::get_singleton()->gi_probe_set_quality(gi_probe_quality); + RS::get_singleton()->environment_set_volumetric_fog_volume_size(GLOBAL_GET("rendering/volumetric_fog/volume_size"), GLOBAL_GET("rendering/volumetric_fog/volume_depth")); + RS::get_singleton()->environment_set_volumetric_fog_filter_active(bool(GLOBAL_GET("rendering/volumetric_fog/use_filter"))); + RS::get_singleton()->canvas_set_shadow_texture_size(GLOBAL_GET("rendering/quality/2d_shadow_atlas/size")); + + bool use_half_res_gi = GLOBAL_DEF("rendering/quality/gi/use_half_resolution", false); + RS::get_singleton()->gi_set_use_half_resolution(use_half_res_gi); + + bool snap_2d_transforms = GLOBAL_GET("rendering/quality/2d/snap_2d_transforms_to_pixel"); + scene_root->set_snap_2d_transforms_to_pixel(snap_2d_transforms); + bool snap_2d_vertices = GLOBAL_GET("rendering/quality/2d/snap_2d_vertices_to_pixel"); + scene_root->set_snap_2d_vertices_to_pixel(snap_2d_vertices); + + Viewport::SDFOversize sdf_oversize = Viewport::SDFOversize(int(GLOBAL_GET("rendering/quality/2d_sdf/oversize"))); + scene_root->set_sdf_oversize(sdf_oversize); + Viewport::SDFScale sdf_scale = Viewport::SDFScale(int(GLOBAL_GET("rendering/quality/2d_sdf/scale"))); + scene_root->set_sdf_scale(sdf_scale); + + float lod_threshold = GLOBAL_GET("rendering/quality/mesh_lod/threshold_pixels"); + scene_root->set_lod_threshold(lod_threshold); +} + void EditorNode::_notification(int p_what) { switch (p_what) { case NOTIFICATION_PROCESS: { @@ -468,75 +536,13 @@ void EditorNode::_notification(int p_what) { editor_selection->update(); - { //TODO should only happen on settings changed - int current_filter = GLOBAL_GET("rendering/canvas_textures/default_texture_filter"); - if (current_filter != scene_root->get_default_canvas_item_texture_filter()) { - Viewport::DefaultCanvasItemTextureFilter tf = (Viewport::DefaultCanvasItemTextureFilter)current_filter; - scene_root->set_default_canvas_item_texture_filter(tf); - } - int current_repeat = GLOBAL_GET("rendering/canvas_textures/default_texture_repeat"); - if (current_repeat != scene_root->get_default_canvas_item_texture_repeat()) { - Viewport::DefaultCanvasItemTextureRepeat tr = (Viewport::DefaultCanvasItemTextureRepeat)current_repeat; - scene_root->set_default_canvas_item_texture_repeat(tr); - } + ResourceImporterTexture::get_singleton()->update_imports(); - RS::DOFBokehShape dof_shape = RS::DOFBokehShape(int(GLOBAL_GET("rendering/quality/depth_of_field/depth_of_field_bokeh_shape"))); - RS::get_singleton()->camera_effects_set_dof_blur_bokeh_shape(dof_shape); - RS::DOFBlurQuality dof_quality = RS::DOFBlurQuality(int(GLOBAL_GET("rendering/quality/depth_of_field/depth_of_field_bokeh_quality"))); - bool dof_jitter = GLOBAL_GET("rendering/quality/depth_of_field/depth_of_field_use_jitter"); - RS::get_singleton()->camera_effects_set_dof_blur_quality(dof_quality, dof_jitter); - RS::get_singleton()->environment_set_ssao_quality(RS::EnvironmentSSAOQuality(int(GLOBAL_GET("rendering/quality/ssao/quality"))), GLOBAL_GET("rendering/quality/ssao/half_size"), GLOBAL_GET("rendering/quality/ssao/adaptive_target"), GLOBAL_GET("rendering/quality/ssao/blur_passes"), GLOBAL_GET("rendering/quality/ssao/fadeout_from"), GLOBAL_GET("rendering/quality/ssao/fadeout_to")); - RS::get_singleton()->screen_space_roughness_limiter_set_active(GLOBAL_GET("rendering/quality/screen_filters/screen_space_roughness_limiter_enabled"), GLOBAL_GET("rendering/quality/screen_filters/screen_space_roughness_limiter_amount"), GLOBAL_GET("rendering/quality/screen_filters/screen_space_roughness_limiter_limit")); - bool glow_bicubic = int(GLOBAL_GET("rendering/quality/glow/upscale_mode")) > 0; - RS::get_singleton()->environment_glow_set_use_bicubic_upscale(glow_bicubic); - bool glow_high_quality = GLOBAL_GET("rendering/quality/glow/use_high_quality"); - RS::get_singleton()->environment_glow_set_use_high_quality(glow_high_quality); - RS::EnvironmentSSRRoughnessQuality ssr_roughness_quality = RS::EnvironmentSSRRoughnessQuality(int(GLOBAL_GET("rendering/quality/screen_space_reflection/roughness_quality"))); - RS::get_singleton()->environment_set_ssr_roughness_quality(ssr_roughness_quality); - RS::SubSurfaceScatteringQuality sss_quality = RS::SubSurfaceScatteringQuality(int(GLOBAL_GET("rendering/quality/subsurface_scattering/subsurface_scattering_quality"))); - RS::get_singleton()->sub_surface_scattering_set_quality(sss_quality); - float sss_scale = GLOBAL_GET("rendering/quality/subsurface_scattering/subsurface_scattering_scale"); - float sss_depth_scale = GLOBAL_GET("rendering/quality/subsurface_scattering/subsurface_scattering_depth_scale"); - RS::get_singleton()->sub_surface_scattering_set_scale(sss_scale, sss_depth_scale); - - uint32_t directional_shadow_size = GLOBAL_GET("rendering/quality/directional_shadow/size"); - uint32_t directional_shadow_16_bits = GLOBAL_GET("rendering/quality/directional_shadow/16_bits"); - RS::get_singleton()->directional_shadow_atlas_set_size(directional_shadow_size, directional_shadow_16_bits); - - RS::ShadowQuality shadows_quality = RS::ShadowQuality(int(GLOBAL_GET("rendering/quality/shadows/soft_shadow_quality"))); - RS::get_singleton()->shadows_quality_set(shadows_quality); - RS::ShadowQuality directional_shadow_quality = RS::ShadowQuality(int(GLOBAL_GET("rendering/quality/directional_shadow/soft_shadow_quality"))); - RS::get_singleton()->directional_shadow_quality_set(directional_shadow_quality); - float probe_update_speed = GLOBAL_GET("rendering/lightmapper/probe_capture_update_speed"); - RS::get_singleton()->lightmap_set_probe_capture_update_speed(probe_update_speed); - RS::EnvironmentSDFGIFramesToConverge frames_to_converge = RS::EnvironmentSDFGIFramesToConverge(int(GLOBAL_GET("rendering/sdfgi/frames_to_converge"))); - RS::get_singleton()->environment_set_sdfgi_frames_to_converge(frames_to_converge); - RS::EnvironmentSDFGIRayCount ray_count = RS::EnvironmentSDFGIRayCount(int(GLOBAL_GET("rendering/sdfgi/probe_ray_count"))); - RS::get_singleton()->environment_set_sdfgi_ray_count(ray_count); - RS::GIProbeQuality gi_probe_quality = RS::GIProbeQuality(int(GLOBAL_GET("rendering/quality/gi_probes/quality"))); - RS::get_singleton()->gi_probe_set_quality(gi_probe_quality); - RS::get_singleton()->environment_set_volumetric_fog_volume_size(GLOBAL_GET("rendering/volumetric_fog/volume_size"), GLOBAL_GET("rendering/volumetric_fog/volume_depth")); - RS::get_singleton()->environment_set_volumetric_fog_filter_active(bool(GLOBAL_GET("rendering/volumetric_fog/use_filter"))); - RS::get_singleton()->canvas_set_shadow_texture_size(GLOBAL_GET("rendering/quality/2d_shadow_atlas/size")); - - bool use_half_res_gi = GLOBAL_DEF("rendering/quality/gi/use_half_resolution", false); - RS::get_singleton()->gi_set_use_half_resolution(use_half_res_gi); - - bool snap_2d_transforms = GLOBAL_GET("rendering/quality/2d/snap_2d_transforms_to_pixel"); - scene_root->set_snap_2d_transforms_to_pixel(snap_2d_transforms); - bool snap_2d_vertices = GLOBAL_GET("rendering/quality/2d/snap_2d_vertices_to_pixel"); - scene_root->set_snap_2d_vertices_to_pixel(snap_2d_vertices); - - Viewport::SDFOversize sdf_oversize = Viewport::SDFOversize(int(GLOBAL_GET("rendering/quality/2d_sdf/oversize"))); - scene_root->set_sdf_oversize(sdf_oversize); - Viewport::SDFScale sdf_scale = Viewport::SDFScale(int(GLOBAL_GET("rendering/quality/2d_sdf/scale"))); - scene_root->set_sdf_scale(sdf_scale); - - float lod_threshold = GLOBAL_GET("rendering/quality/mesh_lod/threshold_pixels"); - scene_root->set_lod_threshold(lod_threshold); + if (settings_changed) { + _update_from_settings(); + settings_changed = false; + emit_signal("project_settings_changed"); } - - ResourceImporterTexture::get_singleton()->update_imports(); } break; case NOTIFICATION_ENTER_TREE: { @@ -960,6 +966,7 @@ void EditorNode::_reload_modified_scenes() { void EditorNode::_reload_project_settings() { ProjectSettings::get_singleton()->setup(ProjectSettings::get_singleton()->get_resource_path(), String(), true); + settings_changed = true; } void EditorNode::_vp_resized() { @@ -1003,7 +1010,7 @@ Error EditorNode::load_resource(const String &p_resource, bool p_ignore_broken_d dependency_errors.clear(); Error err; - RES res = ResourceLoader::load(p_resource, "", false, &err); + RES res = ResourceLoader::load(p_resource, "", ResourceFormatLoader::CACHE_MODE_REUSE, &err); ERR_FAIL_COND_V(!res.is_valid(), ERR_CANT_OPEN); if (!p_ignore_broken_deps && dependency_errors.has(p_resource)) { @@ -3452,7 +3459,7 @@ Error EditorNode::load_scene(const String &p_scene, bool p_ignore_broken_deps, b dependency_errors.clear(); Error err; - Ref<PackedScene> sdata = ResourceLoader::load(lpath, "", true, &err); + Ref<PackedScene> sdata = ResourceLoader::load(lpath, "", ResourceFormatLoader::CACHE_MODE_REPLACE, &err); if (!sdata.is_valid()) { _dialog_display_load_error(lpath, err); opening_prev = false; @@ -5274,6 +5281,8 @@ void EditorNode::_file_access_close_error_notify(const String &p_str) { } void EditorNode::reload_scene(const String &p_path) { + /* + * No longer necesary since scenes now reset and reload their internal resource if needed. //first of all, reload internal textures, materials, meshes, etc. as they might have changed on disk List<Ref<Resource>> cached; @@ -5291,6 +5300,8 @@ void EditorNode::reload_scene(const String &p_path) { to_clear.pop_front(); } + */ + int scene_idx = -1; for (int i = 0; i < editor_data.get_edited_scene_count(); i++) { if (editor_data.get_scene_path(i) == p_path) { @@ -5534,6 +5545,7 @@ void EditorNode::_bind_methods() { ADD_SIGNAL(MethodInfo("request_help_search")); ADD_SIGNAL(MethodInfo("script_add_function_request", PropertyInfo(Variant::OBJECT, "obj"), PropertyInfo(Variant::STRING, "function"), PropertyInfo(Variant::PACKED_STRING_ARRAY, "args"))); ADD_SIGNAL(MethodInfo("resource_saved", PropertyInfo(Variant::OBJECT, "obj"))); + ADD_SIGNAL(MethodInfo("project_settings_changed")); } static Node *_resource_get_edited_scene() { @@ -5601,6 +5613,10 @@ int EditorNode::execute_and_show_output(const String &p_title, const String &p_p return eta.exitcode; } +void EditorNode::notify_settings_changed() { + settings_changed = true; +} + EditorNode::EditorNode() { Input::get_singleton()->set_use_accumulated_input(true); Resource::_get_local_scene_func = _resource_get_edited_scene; @@ -5858,7 +5874,7 @@ EditorNode::EditorNode() { EDITOR_DEF("interface/inspector/horizontal_vector2_editing", false); EDITOR_DEF("interface/inspector/horizontal_vector_types_editing", true); EDITOR_DEF("interface/inspector/open_resources_in_current_inspector", true); - EDITOR_DEF("interface/inspector/resources_to_open_in_new_inspector", "StandardMaterial3D,ORMMaterial3D,Script,MeshLibrary,TileSet"); + EDITOR_DEF("interface/inspector/resources_to_open_in_new_inspector", "Script,MeshLibrary,TileSet"); EDITOR_DEF("interface/inspector/default_color_picker_mode", 0); EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::INT, "interface/inspector/default_color_picker_mode", PROPERTY_HINT_ENUM, "RGB,HSV,RAW", PROPERTY_USAGE_DEFAULT)); EDITOR_DEF("run/auto_save/save_before_running", true); diff --git a/editor/editor_node.h b/editor/editor_node.h index 3785d29c41..8068ca89ee 100644 --- a/editor/editor_node.h +++ b/editor/editor_node.h @@ -312,6 +312,9 @@ private: EditorSettingsDialog *settings_config_dialog; ProjectSettingsEditor *project_settings; + bool settings_changed = true; //make it update settings on first frame + void _update_from_settings(); + PopupMenu *vcs_actions_menu; EditorFileDialog *file; ExportTemplateManager *export_template_manager; @@ -847,6 +850,8 @@ public: void save_scene_list(Vector<String> p_scene_filenames); void restart_editor(); + void notify_settings_changed(); + void dim_editor(bool p_dimming, bool p_force_dim = false); bool is_editor_dimmed() const; diff --git a/editor/editor_plugin.cpp b/editor/editor_plugin.cpp index 840bae35bf..c0cecbc651 100644 --- a/editor/editor_plugin.cpp +++ b/editor/editor_plugin.cpp @@ -756,7 +756,6 @@ int find(const PackedStringArray &a, const String &v) { void EditorPlugin::enable_plugin() { // Called when the plugin gets enabled in project settings, after it's added to the tree. // You can implement it to register autoloads. - if (get_script_instance() && get_script_instance()->has_method("enable_plugin")) { get_script_instance()->call("enable_plugin"); } @@ -819,6 +818,18 @@ void EditorPlugin::remove_debugger_plugin(const Ref<Script> &p_script) { EditorDebuggerNode::get_singleton()->remove_debugger_plugin(p_script); } +void EditorPlugin::_editor_project_settings_changed() { + emit_signal("project_settings_changed"); +} +void EditorPlugin::_notification(int p_what) { + if (p_what == NOTIFICATION_ENTER_TREE) { + EditorNode::get_singleton()->connect("project_settings_changed", callable_mp(this, &EditorPlugin::_editor_project_settings_changed)); + } + if (p_what == NOTIFICATION_EXIT_TREE) { + EditorNode::get_singleton()->disconnect("project_settings_changed", callable_mp(this, &EditorPlugin::_editor_project_settings_changed)); + } +} + void EditorPlugin::_bind_methods() { ClassDB::bind_method(D_METHOD("add_control_to_container", "container", "control"), &EditorPlugin::add_control_to_container); ClassDB::bind_method(D_METHOD("add_control_to_bottom_panel", "control", "title"), &EditorPlugin::add_control_to_bottom_panel); @@ -890,6 +901,7 @@ void EditorPlugin::_bind_methods() { ADD_SIGNAL(MethodInfo("scene_closed", PropertyInfo(Variant::STRING, "filepath"))); ADD_SIGNAL(MethodInfo("main_screen_changed", PropertyInfo(Variant::STRING, "screen_name"))); ADD_SIGNAL(MethodInfo("resource_saved", PropertyInfo(Variant::OBJECT, "resource", PROPERTY_HINT_RESOURCE_TYPE, "Resource"))); + ADD_SIGNAL(MethodInfo("project_settings_changed")); BIND_ENUM_CONSTANT(CONTAINER_TOOLBAR); BIND_ENUM_CONSTANT(CONTAINER_SPATIAL_EDITOR_MENU); diff --git a/editor/editor_plugin.h b/editor/editor_plugin.h index 3b741a2f22..ae9fcfb28a 100644 --- a/editor/editor_plugin.h +++ b/editor/editor_plugin.h @@ -130,7 +130,11 @@ class EditorPlugin : public Node { String last_main_screen_name; + void _editor_project_settings_changed(); + protected: + void _notification(int p_what); + static void _bind_methods(); UndoRedo &get_undo_redo() { return *undo_redo; } diff --git a/editor/editor_properties.cpp b/editor/editor_properties.cpp index 669f381979..6bfc16ccd7 100644 --- a/editor/editor_properties.cpp +++ b/editor/editor_properties.cpp @@ -2859,6 +2859,41 @@ void EditorPropertyResource::_fold_other_editors(Object *p_self) { } } +void EditorPropertyResource::_update_property_bg() { + if (!is_inside_tree()) { + return; + } + + updating_theme = true; + if (sub_inspector != nullptr) { + int count_subinspectors = 0; + Node *n = get_parent(); + while (n) { + EditorInspector *ei = Object::cast_to<EditorInspector>(n); + if (ei && ei->is_sub_inspector()) { + count_subinspectors++; + } + n = n->get_parent(); + } + count_subinspectors = MIN(15, count_subinspectors); + + add_theme_color_override("property_color", get_theme_color("sub_inspector_property_color", "Editor")); + add_theme_style_override("bg_selected", get_theme_stylebox("sub_inspector_property_bg_selected" + itos(count_subinspectors), "Editor")); + add_theme_style_override("bg", get_theme_stylebox("sub_inspector_property_bg" + itos(count_subinspectors), "Editor")); + + add_theme_constant_override("font_offset", get_theme_constant("sub_inspector_font_offset", "Editor")); + add_theme_constant_override("vseparation", 0); + } else { + add_theme_color_override("property_color", get_theme_color("property_color", "EditorProperty")); + add_theme_style_override("bg_selected", get_theme_stylebox("bg_selected", "EditorProperty")); + add_theme_style_override("bg", get_theme_stylebox("bg", "EditorProperty")); + add_theme_constant_override("vseparation", get_theme_constant("vseparation", "EditorProperty")); + add_theme_constant_override("font_offset", get_theme_constant("font_offset", "EditorProperty")); + } + + updating_theme = false; + update(); +} void EditorPropertyResource::update_property() { RES res = get_edited_object()->get(get_edited_property()); @@ -2907,6 +2942,8 @@ void EditorPropertyResource::update_property() { } opened_editor = true; } + + _update_property_bg(); } if (res.ptr() != sub_inspector->get_edited_object()) { @@ -2923,6 +2960,7 @@ void EditorPropertyResource::update_property() { EditorNode::get_singleton()->hide_top_editors(); opened_editor = false; } + _update_property_bg(); } } } @@ -2976,8 +3014,12 @@ void EditorPropertyResource::setup(const String &p_base_type) { void EditorPropertyResource::_notification(int p_what) { if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) { + if (updating_theme) { + return; + } Ref<Texture2D> t = get_theme_icon("select_arrow", "Tree"); edit->set_icon(t); + _update_property_bg(); } if (p_what == NOTIFICATION_DRAG_BEGIN) { diff --git a/editor/editor_properties.h b/editor/editor_properties.h index 4775259111..6f097fb5df 100644 --- a/editor/editor_properties.h +++ b/editor/editor_properties.h @@ -654,6 +654,9 @@ class EditorPropertyResource : public EditorProperty { bool opened_editor; + bool updating_theme = false; + void _update_property_bg(); + protected: static void _bind_methods(); void _notification(int p_what); diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp index b874139022..b6fa2f6d03 100644 --- a/editor/editor_settings.cpp +++ b/editor/editor_settings.cpp @@ -396,6 +396,8 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) { hints["interface/theme/accent_color"] = PropertyInfo(Variant::COLOR, "interface/theme/accent_color", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT); _initial_set("interface/theme/contrast", 0.25); hints["interface/theme/contrast"] = PropertyInfo(Variant::FLOAT, "interface/theme/contrast", PROPERTY_HINT_RANGE, "0.01, 1, 0.01"); + _initial_set("interface/theme/icon_saturation", 1.0); + hints["interface/theme/icon_saturation"] = PropertyInfo(Variant::FLOAT, "interface/theme/icon_saturation", PROPERTY_HINT_RANGE, "0,2,0.01", PROPERTY_USAGE_DEFAULT); _initial_set("interface/theme/relationship_line_opacity", 0.1); hints["interface/theme/relationship_line_opacity"] = PropertyInfo(Variant::FLOAT, "interface/theme/relationship_line_opacity", PROPERTY_HINT_RANGE, "0.00, 1, 0.01"); _initial_set("interface/theme/highlight_tabs", false); @@ -446,6 +448,8 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) { // Property editor _initial_set("docks/property_editor/auto_refresh_interval", 0.2); //update 5 times per second by default + _initial_set("docks/property_editor/subresource_hue_tint", 0.75); + hints["docks/property_editor/subresource_hue_tint"] = PropertyInfo(Variant::FLOAT, "docks/property_editor/subresource_hue_tint", PROPERTY_HINT_RANGE, "0,1,0.01", PROPERTY_USAGE_DEFAULT); /* Text editor */ diff --git a/editor/editor_themes.cpp b/editor/editor_themes.cpp index 8f877a4762..aef069331b 100644 --- a/editor/editor_themes.cpp +++ b/editor/editor_themes.cpp @@ -106,7 +106,7 @@ static Ref<Texture2D> flip_icon(Ref<Texture2D> p_texture, bool p_flip_y = false, } #ifdef MODULE_SVG_ENABLED -static Ref<ImageTexture> editor_generate_icon(int p_index, bool p_convert_color, float p_scale = EDSCALE, bool p_force_filter = false) { +static Ref<ImageTexture> editor_generate_icon(int p_index, bool p_convert_color, float p_scale = EDSCALE, float p_saturation = 1.0) { Ref<ImageTexture> icon = memnew(ImageTexture); Ref<Image> img = memnew(Image); @@ -116,6 +116,9 @@ static Ref<ImageTexture> editor_generate_icon(int p_index, bool p_convert_color, const bool upsample = !Math::is_equal_approx(Math::round(p_scale), p_scale); ImageLoaderSVG::create_image_from_string(img, editor_icons_sources[p_index], p_scale, upsample, p_convert_color); + if (p_saturation != 1.0) { + img->adjust_bcs(1.0, 1.0, p_saturation); + } icon->create_from_image(img); // in this case filter really helps return icon; @@ -126,7 +129,7 @@ static Ref<ImageTexture> editor_generate_icon(int p_index, bool p_convert_color, #define ADD_CONVERT_COLOR(dictionary, old_color, new_color) dictionary[Color::html(old_color)] = Color::html(new_color) #endif -void editor_register_and_generate_icons(Ref<Theme> p_theme, bool p_dark_theme = true, int p_thumb_size = 32, bool p_only_thumbs = false) { +void editor_register_and_generate_icons(Ref<Theme> p_theme, bool p_dark_theme = true, int p_thumb_size = 32, bool p_only_thumbs = false, float p_icon_saturation = 1.0) { #ifdef MODULE_SVG_ENABLED // The default icon theme is designed to be used for a dark theme. // This dictionary stores color codes to convert to other colors @@ -239,14 +242,19 @@ void editor_register_and_generate_icons(Ref<Theme> p_theme, bool p_dark_theme = if (!p_only_thumbs) { for (int i = 0; i < editor_icons_count; i++) { float icon_scale = EDSCALE; + float saturation = p_icon_saturation; // Always keep the DefaultProjectIcon at the default size if (strcmp(editor_icons_names[i], "DefaultProjectIcon") == 0) { icon_scale = 1.0f; } + if (strcmp(editor_icons_names[i], "DefaultProjectIcon") == 0 || strcmp(editor_icons_names[i], "Godot") == 0 || strcmp(editor_icons_names[i], "Logo") == 0) { + saturation = 1.0; + } + const int is_exception = exceptions.has(editor_icons_names[i]); - const Ref<ImageTexture> icon = editor_generate_icon(i, !is_exception, icon_scale); + const Ref<ImageTexture> icon = editor_generate_icon(i, !is_exception, icon_scale, saturation); p_theme->set_icon(editor_icons_names[i], "EditorIcons", icon); } @@ -290,6 +298,7 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) { Color accent_color = EDITOR_GET("interface/theme/accent_color"); Color base_color = EDITOR_GET("interface/theme/base_color"); float contrast = EDITOR_GET("interface/theme/contrast"); + float icon_saturation = EDITOR_GET("interface/theme/icon_saturation"); float relationship_line_opacity = EDITOR_GET("interface/theme/relationship_line_opacity"); String preset = EDITOR_GET("interface/theme/preset"); @@ -393,6 +402,9 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) { const Color highlight_color = Color(mono_color.r, mono_color.g, mono_color.b, 0.2); + float prev_icon_saturation = theme->has_color("icon_saturation", "Editor") ? theme->get_color("icon_saturation", "Editor").r : 1.0; + + theme->set_color("icon_saturation", "Editor", Color(icon_saturation, icon_saturation, icon_saturation)); //can't save single float in theme, so using color theme->set_color("accent_color", "Editor", accent_color); theme->set_color("highlight_color", "Editor", highlight_color); theme->set_color("base_color", "Editor", base_color); @@ -444,13 +456,13 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) { //Register icons + font // the resolution and the icon color (dark_theme bool) has not changed, so we do not regenerate the icons - if (p_theme != nullptr && fabs(p_theme->get_constant("scale", "Editor") - EDSCALE) < 0.00001 && (bool)p_theme->get_constant("dark_theme", "Editor") == dark_theme) { + if (p_theme != nullptr && fabs(p_theme->get_constant("scale", "Editor") - EDSCALE) < 0.00001 && (bool)p_theme->get_constant("dark_theme", "Editor") == dark_theme && prev_icon_saturation == icon_saturation) { // register already generated icons for (int i = 0; i < editor_icons_count; i++) { theme->set_icon(editor_icons_names[i], "EditorIcons", p_theme->get_icon(editor_icons_names[i], "EditorIcons")); } } else { - editor_register_and_generate_icons(theme, dark_theme, thumb_size); + editor_register_and_generate_icons(theme, dark_theme, thumb_size, false, icon_saturation); } // thumbnail size has changed, so we regenerate the medium sizes if (p_theme != nullptr && fabs((double)p_theme->get_constant("thumb_size", "Editor") - thumb_size) > 0.00001) { @@ -724,14 +736,58 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) { theme->set_icon("visibility_xray", "PopupMenu", theme->get_icon("GuiVisibilityXray", "EditorIcons")); theme->set_constant("vseparation", "PopupMenu", (extra_spacing + default_margin_size + 1) * EDSCALE); - Ref<StyleBoxFlat> sub_inspector_bg = make_flat_stylebox(dark_color_1.lerp(accent_color, 0.08), 2, 0, 2, 2); - sub_inspector_bg->set_border_width(SIDE_LEFT, 2); - sub_inspector_bg->set_border_width(SIDE_RIGHT, 2); - sub_inspector_bg->set_border_width(SIDE_BOTTOM, 2); - sub_inspector_bg->set_border_color(accent_color * Color(1, 1, 1, 0.3)); - sub_inspector_bg->set_draw_center(true); + for (int i = 0; i < 16; i++) { + Color si_base_color = accent_color; + + float hue_rotate = (i * 2 % 16) / 16.0; + si_base_color.set_hsv(Math::fmod(float(si_base_color.get_h() + hue_rotate), float(1.0)), si_base_color.get_s(), si_base_color.get_v()); + si_base_color = accent_color.lerp(si_base_color, float(EDITOR_GET("docks/property_editor/subresource_hue_tint"))); + + Ref<StyleBoxFlat> sub_inspector_bg; + + sub_inspector_bg = make_flat_stylebox(dark_color_1.lerp(si_base_color, 0.08), 2, 0, 2, 2); + + sub_inspector_bg->set_border_width(SIDE_LEFT, 2); + sub_inspector_bg->set_border_width(SIDE_RIGHT, 2); + sub_inspector_bg->set_border_width(SIDE_BOTTOM, 2); + sub_inspector_bg->set_border_width(SIDE_TOP, 2); + sub_inspector_bg->set_default_margin(SIDE_LEFT, 3); + sub_inspector_bg->set_default_margin(SIDE_RIGHT, 3); + sub_inspector_bg->set_default_margin(SIDE_BOTTOM, 10); + sub_inspector_bg->set_default_margin(SIDE_TOP, 5); + sub_inspector_bg->set_border_color(si_base_color * Color(0.7, 0.7, 0.7, 0.8)); + sub_inspector_bg->set_draw_center(true); + + theme->set_stylebox("sub_inspector_bg" + itos(i), "Editor", sub_inspector_bg); + + Ref<StyleBoxFlat> bg_color; + bg_color.instance(); + bg_color->set_bg_color(si_base_color * Color(0.7, 0.7, 0.7, 0.8)); + bg_color->set_border_width_all(0); + + Ref<StyleBoxFlat> bg_color_selected; + bg_color_selected.instance(); + bg_color_selected->set_border_width_all(0); + bg_color_selected->set_bg_color(si_base_color * Color(0.8, 0.8, 0.8, 0.8)); + + theme->set_stylebox("sub_inspector_property_bg" + itos(i), "Editor", bg_color); + theme->set_stylebox("sub_inspector_property_bg_selected" + itos(i), "Editor", bg_color_selected); + } + + theme->set_color("sub_inspector_property_color", "Editor", dark_theme ? Color(1, 1, 1, 1) : Color(0, 0, 0, 1)); + theme->set_constant("sub_inspector_font_offset", "Editor", 4 * EDSCALE); + + Ref<StyleBoxFlat> style_property_bg = style_default->duplicate(); + style_property_bg->set_bg_color(highlight_color); + style_property_bg->set_border_width_all(0); + + theme->set_constant("font_offset", "EditorProperty", 1 * EDSCALE); + theme->set_stylebox("bg_selected", "EditorProperty", style_property_bg); + theme->set_stylebox("bg", "EditorProperty", Ref<StyleBoxEmpty>(memnew(StyleBoxEmpty))); + theme->set_constant("vseparation", "EditorProperty", (extra_spacing + default_margin_size) * EDSCALE); + theme->set_color("error_color", "EditorProperty", error_color); + theme->set_color("property_color", "EditorProperty", property_color); - theme->set_stylebox("sub_inspector_bg", "Editor", sub_inspector_bg); theme->set_constant("inspector_margin", "Editor", 8 * EDSCALE); // Tree & ItemList background diff --git a/editor/import/resource_importer_scene.cpp b/editor/import/resource_importer_scene.cpp index 9944712931..d0e5798045 100644 --- a/editor/import/resource_importer_scene.cpp +++ b/editor/import/resource_importer_scene.cpp @@ -964,7 +964,7 @@ void ResourceImporterScene::_make_external_resources(Node *p_node, const String if (FileAccess::exists(ext_name) && p_keep_animations) { // Copy custom animation tracks from previously imported files. - Ref<Animation> old_anim = ResourceLoader::load(ext_name, "Animation", true); + Ref<Animation> old_anim = ResourceLoader::load(ext_name, "Animation", ResourceFormatLoader::CACHE_MODE_IGNORE); if (old_anim.is_valid()) { for (int i = 0; i < old_anim->get_track_count(); i++) { if (!old_anim->track_is_imported(i)) { @@ -1004,7 +1004,7 @@ void ResourceImporterScene::_make_external_resources(Node *p_node, const String p_materials[mat] = ResourceLoader::load(ext_name); } else { ResourceSaver::save(ext_name, mat, ResourceSaver::FLAG_CHANGE_PATH); - p_materials[mat] = ResourceLoader::load(ext_name, "", true); // disable loading from the cache. + p_materials[mat] = ResourceLoader::load(ext_name, "", ResourceFormatLoader::CACHE_MODE_IGNORE); // disable loading from the cache. } } @@ -1061,7 +1061,7 @@ void ResourceImporterScene::_make_external_resources(Node *p_node, const String p_materials[mat] = ResourceLoader::load(ext_name); } else { ResourceSaver::save(ext_name, mat, ResourceSaver::FLAG_CHANGE_PATH); - p_materials[mat] = ResourceLoader::load(ext_name, "", true); // disable loading from the cache. + p_materials[mat] = ResourceLoader::load(ext_name, "", ResourceFormatLoader::CACHE_MODE_IGNORE); // disable loading from the cache. } } diff --git a/editor/plugins/node_3d_editor_plugin.cpp b/editor/plugins/node_3d_editor_plugin.cpp index a3009731f9..c591e7f42d 100644 --- a/editor/plugins/node_3d_editor_plugin.cpp +++ b/editor/plugins/node_3d_editor_plugin.cpp @@ -2335,7 +2335,43 @@ void Node3DEditorPlugin::edited_scene_changed() { } } +void Node3DEditorViewport::_project_settings_changed() { + //update shadow atlas if changed + int shadowmap_size = ProjectSettings::get_singleton()->get("rendering/quality/shadow_atlas/size"); + bool shadowmap_16_bits = ProjectSettings::get_singleton()->get("rendering/quality/shadow_atlas/16_bits"); + int atlas_q0 = ProjectSettings::get_singleton()->get("rendering/quality/shadow_atlas/quadrant_0_subdiv"); + int atlas_q1 = ProjectSettings::get_singleton()->get("rendering/quality/shadow_atlas/quadrant_1_subdiv"); + int atlas_q2 = ProjectSettings::get_singleton()->get("rendering/quality/shadow_atlas/quadrant_2_subdiv"); + int atlas_q3 = ProjectSettings::get_singleton()->get("rendering/quality/shadow_atlas/quadrant_3_subdiv"); + + viewport->set_shadow_atlas_size(shadowmap_size); + viewport->set_shadow_atlas_16_bits(shadowmap_16_bits); + viewport->set_shadow_atlas_quadrant_subdiv(0, Viewport::ShadowAtlasQuadrantSubdiv(atlas_q0)); + viewport->set_shadow_atlas_quadrant_subdiv(1, Viewport::ShadowAtlasQuadrantSubdiv(atlas_q1)); + viewport->set_shadow_atlas_quadrant_subdiv(2, Viewport::ShadowAtlasQuadrantSubdiv(atlas_q2)); + viewport->set_shadow_atlas_quadrant_subdiv(3, Viewport::ShadowAtlasQuadrantSubdiv(atlas_q3)); + + bool shrink = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_HALF_RESOLUTION)); + + if (shrink != (subviewport_container->get_stretch_shrink() > 1)) { + subviewport_container->set_stretch_shrink(shrink ? 2 : 1); + } + + // Update MSAA, screen-space AA and debanding if changed + + const int msaa_mode = ProjectSettings::get_singleton()->get("rendering/quality/screen_filters/msaa"); + viewport->set_msaa(Viewport::MSAA(msaa_mode)); + const int ssaa_mode = GLOBAL_GET("rendering/quality/screen_filters/screen_space_aa"); + viewport->set_screen_space_aa(Viewport::ScreenSpaceAA(ssaa_mode)); + const bool use_debanding = GLOBAL_GET("rendering/quality/screen_filters/use_debanding"); + viewport->set_use_debanding(use_debanding); +} + void Node3DEditorViewport::_notification(int p_what) { + if (p_what == NOTIFICATION_READY) { + EditorNode::get_singleton()->connect("project_settings_changed", callable_mp(this, &Node3DEditorViewport::_project_settings_changed)); + } + if (p_what == NOTIFICATION_VISIBILITY_CHANGED) { bool visible = is_visible_in_tree(); @@ -2442,37 +2478,6 @@ void Node3DEditorViewport::_notification(int p_what) { } } - //update shadow atlas if changed - - int shadowmap_size = ProjectSettings::get_singleton()->get("rendering/quality/shadow_atlas/size"); - bool shadowmap_16_bits = ProjectSettings::get_singleton()->get("rendering/quality/shadow_atlas/16_bits"); - int atlas_q0 = ProjectSettings::get_singleton()->get("rendering/quality/shadow_atlas/quadrant_0_subdiv"); - int atlas_q1 = ProjectSettings::get_singleton()->get("rendering/quality/shadow_atlas/quadrant_1_subdiv"); - int atlas_q2 = ProjectSettings::get_singleton()->get("rendering/quality/shadow_atlas/quadrant_2_subdiv"); - int atlas_q3 = ProjectSettings::get_singleton()->get("rendering/quality/shadow_atlas/quadrant_3_subdiv"); - - viewport->set_shadow_atlas_size(shadowmap_size); - viewport->set_shadow_atlas_16_bits(shadowmap_16_bits); - viewport->set_shadow_atlas_quadrant_subdiv(0, Viewport::ShadowAtlasQuadrantSubdiv(atlas_q0)); - viewport->set_shadow_atlas_quadrant_subdiv(1, Viewport::ShadowAtlasQuadrantSubdiv(atlas_q1)); - viewport->set_shadow_atlas_quadrant_subdiv(2, Viewport::ShadowAtlasQuadrantSubdiv(atlas_q2)); - viewport->set_shadow_atlas_quadrant_subdiv(3, Viewport::ShadowAtlasQuadrantSubdiv(atlas_q3)); - - bool shrink = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_HALF_RESOLUTION)); - - if (shrink != (subviewport_container->get_stretch_shrink() > 1)) { - subviewport_container->set_stretch_shrink(shrink ? 2 : 1); - } - - // Update MSAA, screen-space AA and debanding if changed - - const int msaa_mode = ProjectSettings::get_singleton()->get("rendering/quality/screen_filters/msaa"); - viewport->set_msaa(Viewport::MSAA(msaa_mode)); - const int ssaa_mode = GLOBAL_GET("rendering/quality/screen_filters/screen_space_aa"); - viewport->set_screen_space_aa(Viewport::ScreenSpaceAA(ssaa_mode)); - const bool use_debanding = GLOBAL_GET("rendering/quality/screen_filters/use_debanding"); - viewport->set_use_debanding(use_debanding); - bool show_info = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_INFORMATION)); if (show_info != info_label->is_visible()) { info_label->set_visible(show_info); diff --git a/editor/plugins/node_3d_editor_plugin.h b/editor/plugins/node_3d_editor_plugin.h index 9fb7488a0f..bf478f850e 100644 --- a/editor/plugins/node_3d_editor_plugin.h +++ b/editor/plugins/node_3d_editor_plugin.h @@ -463,6 +463,8 @@ private: bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const; void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from); + void _project_settings_changed(); + protected: void _notification(int p_what); static void _bind_methods(); diff --git a/editor/plugins/packed_scene_translation_parser_plugin.cpp b/editor/plugins/packed_scene_translation_parser_plugin.cpp index 1f20a87565..0a949c8610 100644 --- a/editor/plugins/packed_scene_translation_parser_plugin.cpp +++ b/editor/plugins/packed_scene_translation_parser_plugin.cpp @@ -42,7 +42,7 @@ Error PackedSceneEditorTranslationParserPlugin::parse_file(const String &p_path, // These properties are translated with the tr() function in the C++ code when being set or updated. Error err; - RES loaded_res = ResourceLoader::load(p_path, "PackedScene", false, &err); + RES loaded_res = ResourceLoader::load(p_path, "PackedScene", ResourceFormatLoader::CACHE_MODE_REUSE, &err); if (err) { ERR_PRINT("Failed to load " + p_path); return err; diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index 216c0c3bef..a6afd45686 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -894,7 +894,7 @@ void ScriptEditor::_reload_scripts() { Ref<Script> script = edited_res; if (script != nullptr) { - Ref<Script> rel_script = ResourceLoader::load(script->get_path(), script->get_class(), true); + Ref<Script> rel_script = ResourceLoader::load(script->get_path(), script->get_class(), ResourceFormatLoader::CACHE_MODE_IGNORE); ERR_CONTINUE(!rel_script.is_valid()); script->set_source_code(rel_script->get_source_code()); script->set_last_modified_time(rel_script->get_last_modified_time()); diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp index f57c8fbd6b..71b18497b0 100644 --- a/editor/plugins/script_text_editor.cpp +++ b/editor/plugins/script_text_editor.cpp @@ -688,7 +688,7 @@ void ScriptEditor::_update_modified_scripts_for_external_editor(Ref<Script> p_fo uint64_t date = FileAccess::get_modified_time(script->get_path()); if (last_date != date) { - Ref<Script> rel_script = ResourceLoader::load(script->get_path(), script->get_class(), true); + Ref<Script> rel_script = ResourceLoader::load(script->get_path(), script->get_class(), ResourceFormatLoader::CACHE_MODE_IGNORE); ERR_CONTINUE(!rel_script.is_valid()); script->set_source_code(rel_script->get_source_code()); script->set_last_modified_time(rel_script->get_last_modified_time()); diff --git a/editor/plugins/shader_editor_plugin.cpp b/editor/plugins/shader_editor_plugin.cpp index 05a1561f7d..8be82628cb 100644 --- a/editor/plugins/shader_editor_plugin.cpp +++ b/editor/plugins/shader_editor_plugin.cpp @@ -405,7 +405,7 @@ void ShaderEditor::_check_for_external_edit() { } void ShaderEditor::_reload_shader_from_disk() { - Ref<Shader> rel_shader = ResourceLoader::load(shader->get_path(), shader->get_class(), true); + Ref<Shader> rel_shader = ResourceLoader::load(shader->get_path(), shader->get_class(), ResourceFormatLoader::CACHE_MODE_IGNORE); ERR_FAIL_COND(!rel_shader.is_valid()); shader->set_code(rel_shader->get_code()); diff --git a/editor/plugins/sprite_2d_editor_plugin.cpp b/editor/plugins/sprite_2d_editor_plugin.cpp index 03ddaa2c74..4949d2b9b7 100644 --- a/editor/plugins/sprite_2d_editor_plugin.cpp +++ b/editor/plugins/sprite_2d_editor_plugin.cpp @@ -173,6 +173,11 @@ void Sprite2DEditor::_update_mesh_data() { Ref<Image> image = texture->get_data(); ERR_FAIL_COND(image.is_null()); + + if (image->is_compressed()) { + image->decompress(); + } + Rect2 rect; if (node->is_region()) { rect = node->get_region_rect(); diff --git a/editor/project_manager.cpp b/editor/project_manager.cpp index 16d319a5d5..7b00c688fa 100644 --- a/editor/project_manager.cpp +++ b/editor/project_manager.cpp @@ -2015,6 +2015,10 @@ void ProjectManager::_confirm_update_settings() { } void ProjectManager::_open_selected_projects() { + // Show loading text to tell the user that the project manager is busy loading. + // This is especially important for the HTML5 project manager. + loading_label->set_modulate(Color(1, 1, 1)); + const Set<String> &selected_list = _project_list->get_selected_project_keys(); for (const Set<String>::Element *E = selected_list.front(); E; E = E->next()) { @@ -2268,11 +2272,6 @@ void ProjectManager::_restart_confirm() { get_tree()->quit(); } -void ProjectManager::_exit_dialog() { - _dim_window(); - get_tree()->quit(); -} - void ProjectManager::_install_project(const String &p_zip_path, const String &p_title) { npdialog->set_mode(ProjectDialog::MODE_INSTALL); npdialog->set_zip_path(p_zip_path); @@ -2351,7 +2350,6 @@ void ProjectManager::_on_search_term_changed(const String &p_term) { } void ProjectManager::_bind_methods() { - ClassDB::bind_method("_exit_dialog", &ProjectManager::_exit_dialog); ClassDB::bind_method("_unhandled_key_input", &ProjectManager::_unhandled_key_input); ClassDB::bind_method("_update_project_buttons", &ProjectManager::_update_project_buttons); } @@ -2485,7 +2483,12 @@ ProjectManager::ProjectManager() { search_box->set_h_size_flags(Control::SIZE_EXPAND_FILL); hb->add_child(search_box); - hb->add_spacer(); + loading_label = memnew(Label(TTR("Loading, please wait..."))); + loading_label->add_theme_font_override("font", get_theme_font("bold", "EditorFonts")); + loading_label->set_h_size_flags(Control::SIZE_EXPAND_FILL); + hb->add_child(loading_label); + // Hide the label but make it still take up space. This prevents reflows when showing the label. + loading_label->set_modulate(Color(0, 0, 0, 0)); Label *sort_label = memnew(Label); sort_label->set_text(TTR("Sort:")); diff --git a/editor/project_manager.h b/editor/project_manager.h index db8cb8410c..6dc0e67cba 100644 --- a/editor/project_manager.h +++ b/editor/project_manager.h @@ -54,6 +54,7 @@ class ProjectManager : public Control { ProjectList *_project_list; LineEdit *search_box; + Label *loading_label; OptionButton *filter_option; Button *run_btn; @@ -98,7 +99,6 @@ class ProjectManager : public Control { void _update_project_buttons(); void _language_selected(int p_id); void _restart_confirm(); - void _exit_dialog(); void _confirm_update_settings(); void _nonempty_confirmation_ok_pressed(); diff --git a/editor/project_settings_editor.cpp b/editor/project_settings_editor.cpp index 4516180fa5..76fdf47eb6 100644 --- a/editor/project_settings_editor.cpp +++ b/editor/project_settings_editor.cpp @@ -55,6 +55,7 @@ void ProjectSettingsEditor::popup_project_settings() { } void ProjectSettingsEditor::queue_save() { + EditorNode::get_singleton()->notify_settings_changed(); timer->start(); } diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp index ac1beb1c37..c1edeeeb0e 100644 --- a/editor/scene_tree_dock.cpp +++ b/editor/scene_tree_dock.cpp @@ -87,6 +87,12 @@ void SceneTreeDock::_unhandled_key_input(Ref<InputEvent> p_event) { _tool_selected(TOOL_INSTANCE); } else if (ED_IS_SHORTCUT("scene_tree/expand_collapse_all", p_event)) { _tool_selected(TOOL_EXPAND_COLLAPSE); + } else if (ED_IS_SHORTCUT("scene_tree/cut_node", p_event)) { + _tool_selected(TOOL_CUT); + } else if (ED_IS_SHORTCUT("scene_tree/copy_node", p_event)) { + _tool_selected(TOOL_COPY); + } else if (ED_IS_SHORTCUT("scene_tree/paste_node", p_event)) { + _tool_selected(TOOL_PASTE); } else if (ED_IS_SHORTCUT("scene_tree/change_node_type", p_event)) { _tool_selected(TOOL_REPLACE); } else if (ED_IS_SHORTCUT("scene_tree/duplicate", p_event)) { @@ -397,6 +403,114 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { tree->ensure_cursor_is_visible(); } break; + case TOOL_CUT: + case TOOL_COPY: { + if (!edited_scene || !_validate_no_foreign()) { + break; + } + + List<Node *> selection = editor_selection->get_selected_node_list(); + if (selection.size() == 0) { + break; + } + + if (!node_clipboard.is_empty()) { + _clear_clipboard(); + } + clipboard_source_scene = editor->get_edited_scene()->get_filename(); + + selection.sort_custom<Node::Comparator>(); + + for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { + Node *node = E->get(); + Map<const Node *, Node *> duplimap; + Node *dup = node->duplicate_from_editor(duplimap); + + ERR_CONTINUE(!dup); + + node_clipboard.push_back(dup); + } + + if (p_tool == TOOL_CUT) { + _delete_confirm(true); + } + } break; + case TOOL_PASTE: { + if (node_clipboard.is_empty() || !edited_scene) { + break; + } + + bool has_cycle = false; + if (edited_scene->get_filename() != String()) { + for (List<Node *>::Element *E = node_clipboard.front(); E; E = E->next()) { + if (edited_scene->get_filename() == E->get()->get_filename()) { + has_cycle = true; + break; + } + } + } + + if (has_cycle) { + current_option = -1; + accept->set_text(TTR("Can't paste root node into the same scene.")); + accept->popup_centered(); + break; + } + + Node *paste_parent = edited_scene; + List<Node *> selection = editor_selection->get_selected_node_list(); + if (selection.size() > 0) { + paste_parent = selection.back()->get(); + } + + Node *owner = paste_parent->get_owner(); + if (!owner) { + owner = paste_parent; + } + + editor_data->get_undo_redo().create_action(TTR("Paste Node(s)")); + editor_data->get_undo_redo().add_do_method(editor_selection, "clear"); + + Map<RES, RES> resource_remap; + String target_scene = editor->get_edited_scene()->get_filename(); + if (target_scene != clipboard_source_scene) { + if (!clipboard_resource_remap.has(target_scene)) { + Map<RES, RES> remap; + for (List<Node *>::Element *E = node_clipboard.front(); E; E = E->next()) { + _create_remap_for_node(E->get(), remap); + } + clipboard_resource_remap[target_scene] = remap; + } + resource_remap = clipboard_resource_remap[target_scene]; + } + + for (List<Node *>::Element *E = node_clipboard.front(); E; E = E->next()) { + Node *node = E->get(); + Map<const Node *, Node *> duplimap; + + Node *dup = node->duplicate_from_editor(duplimap, resource_remap); + + ERR_CONTINUE(!dup); + + editor_data->get_undo_redo().add_do_method(paste_parent, "add_child", dup); + + for (Map<const Node *, Node *>::Element *E2 = duplimap.front(); E2; E2 = E2->next()) { + Node *d = E2->value(); + editor_data->get_undo_redo().add_do_method(d, "set_owner", owner); + } + + editor_data->get_undo_redo().add_do_method(dup, "set_owner", owner); + editor_data->get_undo_redo().add_do_method(editor_selection, "add_node", dup); + editor_data->get_undo_redo().add_undo_method(paste_parent, "remove_child", dup); + editor_data->get_undo_redo().add_do_reference(dup); + + if (node_clipboard.size() == 1) { + editor_data->get_undo_redo().add_do_method(editor, "push_item", dup); + } + } + + editor_data->get_undo_redo().commit_action(); + } break; case TOOL_REPLACE: { if (!profile_allow_editing) { break; @@ -1795,7 +1909,7 @@ void SceneTreeDock::_toggle_editable_children(Node *p_node) { } } -void SceneTreeDock::_delete_confirm() { +void SceneTreeDock::_delete_confirm(bool p_cut) { List<Node *> remove_list = editor_selection->get_selected_node_list(); if (remove_list.is_empty()) { @@ -1804,7 +1918,11 @@ void SceneTreeDock::_delete_confirm() { editor->get_editor_plugins_over()->make_visible(false); - editor_data->get_undo_redo().create_action(TTR("Remove Node(s)")); + if (p_cut) { + editor_data->get_undo_redo().create_action(TTR("Cut Node(s)")); + } else { + editor_data->get_undo_redo().create_action(TTR("Remove Node(s)")); + } bool entire_scene = false; @@ -2444,6 +2562,13 @@ void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) { } if (profile_allow_script_editing) { + menu->add_shortcut(ED_GET_SHORTCUT("scene_tree/cut_node"), TOOL_CUT); + menu->add_shortcut(ED_GET_SHORTCUT("scene_tree/copy_node"), TOOL_COPY); + if (selection.size() == 1 && !node_clipboard.is_empty()) { + menu->add_shortcut(ED_GET_SHORTCUT("scene_tree/paste_node"), TOOL_PASTE); + } + menu->add_separator(); + bool add_separator = false; if (full_selection.size() == 1) { @@ -2775,6 +2900,62 @@ void SceneTreeDock::_feature_profile_changed() { _update_script_button(); } +void SceneTreeDock::_clear_clipboard() { + for (List<Node *>::Element *E = node_clipboard.front(); E; E = E->next()) { + memdelete(E->get()); + } + node_clipboard.clear(); + clipboard_resource_remap.clear(); +} + +void SceneTreeDock::_create_remap_for_node(Node *p_node, Map<RES, RES> &r_remap) { + List<PropertyInfo> props; + p_node->get_property_list(&props); + + for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) { + if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) { + continue; + } + + Variant v = p_node->get(E->get().name); + if (v.is_ref()) { + RES res = v; + if (res.is_valid()) { + if (res->get_path() == "" && !r_remap.has(res)) { + _create_remap_for_resource(res, r_remap); + } + } + } + } + + for (int i = 0; i < p_node->get_child_count(); i++) { + _create_remap_for_node(p_node->get_child(i), r_remap); + } +} + +void SceneTreeDock::_create_remap_for_resource(RES p_resource, Map<RES, RES> &r_remap) { + r_remap[p_resource] = p_resource->duplicate(); + + List<PropertyInfo> props; + p_resource->get_property_list(&props); + + for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) { + if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) { + continue; + } + + Variant v = p_resource->get(E->get().name); + if (v.is_ref()) { + RES res = v; + if (res.is_valid()) { + if (res->get_path() == "" && !r_remap.has(res)) { + _create_remap_for_resource(res, r_remap); + } + } + } + } +} + void SceneTreeDock::_bind_methods() { ClassDB::bind_method(D_METHOD("_set_owners"), &SceneTreeDock::_set_owners); ClassDB::bind_method(D_METHOD("_unhandled_key_input"), &SceneTreeDock::_unhandled_key_input); @@ -2806,6 +2987,9 @@ SceneTreeDock::SceneTreeDock(EditorNode *p_editor, Node *p_scene_root, EditorSel ED_SHORTCUT("scene_tree/add_child_node", TTR("Add Child Node"), KEY_MASK_CMD | KEY_A); ED_SHORTCUT("scene_tree/instance_scene", TTR("Instance Child Scene")); ED_SHORTCUT("scene_tree/expand_collapse_all", TTR("Expand/Collapse All")); + ED_SHORTCUT("scene_tree/cut_node", TTR("Cut"), KEY_MASK_CMD | KEY_X); + ED_SHORTCUT("scene_tree/copy_node", TTR("Copy"), KEY_MASK_CMD | KEY_C); + ED_SHORTCUT("scene_tree/paste_node", TTR("Paste"), KEY_MASK_CMD | KEY_V); ED_SHORTCUT("scene_tree/change_node_type", TTR("Change Type")); ED_SHORTCUT("scene_tree/attach_script", TTR("Attach Script")); ED_SHORTCUT("scene_tree/extend_script", TTR("Extend Script")); @@ -2818,7 +3002,7 @@ SceneTreeDock::SceneTreeDock(EditorNode *p_editor, Node *p_scene_root, EditorSel ED_SHORTCUT("scene_tree/make_root", TTR("Make Scene Root")); ED_SHORTCUT("scene_tree/merge_from_scene", TTR("Merge From Scene")); ED_SHORTCUT("scene_tree/save_branch_as_scene", TTR("Save Branch as Scene")); - ED_SHORTCUT("scene_tree/copy_node_path", TTR("Copy Node Path"), KEY_MASK_CMD | KEY_C); + ED_SHORTCUT("scene_tree/copy_node_path", TTR("Copy Node Path"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_C); ED_SHORTCUT("scene_tree/delete_no_confirm", TTR("Delete (No Confirm)"), KEY_MASK_SHIFT | KEY_DELETE); ED_SHORTCUT("scene_tree/delete", TTR("Delete"), KEY_DELETE); @@ -2841,7 +3025,7 @@ SceneTreeDock::SceneTreeDock(EditorNode *p_editor, Node *p_scene_root, EditorSel filter->set_h_size_flags(SIZE_EXPAND_FILL); filter->set_placeholder(TTR("Filter nodes")); filter_hbc->add_child(filter); - filter->add_theme_constant_override("minimum_spaces", 0); + filter->add_theme_constant_override("minimum_character_width", 0); filter->connect("text_changed", callable_mp(this, &SceneTreeDock::_filter_changed)); button_create_script = memnew(Button); @@ -2936,7 +3120,7 @@ SceneTreeDock::SceneTreeDock(EditorNode *p_editor, Node *p_scene_root, EditorSel delete_dialog = memnew(ConfirmationDialog); add_child(delete_dialog); - delete_dialog->connect("confirmed", callable_mp(this, &SceneTreeDock::_delete_confirm)); + delete_dialog->connect("confirmed", callable_mp(this, &SceneTreeDock::_delete_confirm), varray(false)); editable_instance_remove_dialog = memnew(ConfirmationDialog); add_child(editable_instance_remove_dialog); @@ -2981,3 +3165,9 @@ SceneTreeDock::SceneTreeDock(EditorNode *p_editor, Node *p_scene_root, EditorSel EDITOR_DEF("interface/editors/derive_script_globals_by_name", true); EDITOR_DEF("_use_favorites_root_selection", false); } + +SceneTreeDock::~SceneTreeDock() { + if (!node_clipboard.is_empty()) { + _clear_clipboard(); + } +} diff --git a/editor/scene_tree_dock.h b/editor/scene_tree_dock.h index 4f8d85f07c..a042188be6 100644 --- a/editor/scene_tree_dock.h +++ b/editor/scene_tree_dock.h @@ -58,6 +58,9 @@ class SceneTreeDock : public VBoxContainer { TOOL_NEW, TOOL_INSTANCE, TOOL_EXPAND_COLLAPSE, + TOOL_CUT, + TOOL_COPY, + TOOL_PASTE, TOOL_RENAME, TOOL_BATCH_RENAME, TOOL_REPLACE, @@ -126,6 +129,10 @@ class SceneTreeDock : public VBoxContainer { EditorData *editor_data; EditorSelection *editor_selection; + List<Node *> node_clipboard; + String clipboard_source_scene; + HashMap<String, Map<RES, RES>> clipboard_resource_remap; + ScriptCreateDialog *script_create_dialog; AcceptDialog *accept; ConfirmationDialog *delete_dialog; @@ -183,7 +190,7 @@ class SceneTreeDock : public VBoxContainer { void _script_created(Ref<Script> p_script); void _script_creation_closed(); - void _delete_confirm(); + void _delete_confirm(bool p_cut = false); void _toggle_editable_children_from_selection(); void _toggle_editable_children(Node *p_node); @@ -230,6 +237,10 @@ class SceneTreeDock : public VBoxContainer { void _feature_profile_changed(); + void _clear_clipboard(); + void _create_remap_for_node(Node *p_node, Map<RES, RES> &r_remap); + void _create_remap_for_resource(RES p_resource, Map<RES, RES> &r_remap); + bool profile_allow_editing; bool profile_allow_script_editing; @@ -267,6 +278,7 @@ public: ScriptCreateDialog *get_script_create_dialog() { return script_create_dialog; } SceneTreeDock(EditorNode *p_editor, Node *p_scene_root, EditorSelection *p_editor_selection, EditorData &p_editor_data); + ~SceneTreeDock(); }; #endif // SCENE_TREE_DOCK_H diff --git a/editor/scene_tree_editor.cpp b/editor/scene_tree_editor.cpp index ce44a4bca1..2cd64a81dc 100644 --- a/editor/scene_tree_editor.cpp +++ b/editor/scene_tree_editor.cpp @@ -1260,7 +1260,7 @@ SceneTreeDialog::SceneTreeDialog() { filter = memnew(LineEdit); filter->set_h_size_flags(Control::SIZE_EXPAND_FILL); filter->set_placeholder(TTR("Filter nodes")); - filter->add_theme_constant_override("minimum_spaces", 0); + filter->add_theme_constant_override("minimum_character_width", 0); filter->connect("text_changed", callable_mp(this, &SceneTreeDialog::_filter_changed)); vbc->add_child(filter); diff --git a/modules/dds/texture_loader_dds.cpp b/modules/dds/texture_loader_dds.cpp index 5415fcc92e..2fef576b77 100644 --- a/modules/dds/texture_loader_dds.cpp +++ b/modules/dds/texture_loader_dds.cpp @@ -94,7 +94,7 @@ static const DDSFormatInfo dds_format_info[DDS_MAX] = { { "GRAYSCALE_ALPHA", false, false, 1, 2, Image::FORMAT_LA8 } }; -RES ResourceFormatDDS::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) { +RES ResourceFormatDDS::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_cache_mode) { if (r_error) { *r_error = ERR_CANT_OPEN; } diff --git a/modules/dds/texture_loader_dds.h b/modules/dds/texture_loader_dds.h index 605e791969..cf93156423 100644 --- a/modules/dds/texture_loader_dds.h +++ b/modules/dds/texture_loader_dds.h @@ -36,7 +36,7 @@ class ResourceFormatDDS : public ResourceFormatLoader { public: - virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, bool p_no_cache = false); + virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, CacheMode p_cache_mode = CACHE_MODE_REUSE); virtual void get_recognized_extensions(List<String> *p_extensions) const; virtual bool handles_type(const String &p_type) const; virtual String get_resource_type(const String &p_path) const; diff --git a/modules/etc/texture_loader_pkm.cpp b/modules/etc/texture_loader_pkm.cpp index 456473672d..95db9315d5 100644 --- a/modules/etc/texture_loader_pkm.cpp +++ b/modules/etc/texture_loader_pkm.cpp @@ -42,7 +42,7 @@ struct ETC1Header { uint16_t origHeight = 0; }; -RES ResourceFormatPKM::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) { +RES ResourceFormatPKM::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_cache_mode) { if (r_error) { *r_error = ERR_CANT_OPEN; } diff --git a/modules/etc/texture_loader_pkm.h b/modules/etc/texture_loader_pkm.h index 67fbee3a7e..2ed5e75807 100644 --- a/modules/etc/texture_loader_pkm.h +++ b/modules/etc/texture_loader_pkm.h @@ -36,7 +36,7 @@ class ResourceFormatPKM : public ResourceFormatLoader { public: - virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, bool p_no_cache = false); + virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, CacheMode p_cache_mode = CACHE_MODE_REUSE); virtual void get_recognized_extensions(List<String> *p_extensions) const; virtual bool handles_type(const String &p_type) const; virtual String get_resource_type(const String &p_path) const; diff --git a/modules/gdnative/gdnative.cpp b/modules/gdnative/gdnative.cpp index e3a359e09a..86bd8b820d 100644 --- a/modules/gdnative/gdnative.cpp +++ b/modules/gdnative/gdnative.cpp @@ -110,6 +110,16 @@ bool GDNativeLibrary::_get(const StringName &p_name, Variant &r_property) const return false; } +void GDNativeLibrary::reset_state() { + config_file.instance(); + current_library_path = ""; + current_dependencies.clear(); + symbol_prefix = default_symbol_prefix; + load_once = default_load_once; + singleton = default_singleton; + reloadable = default_reloadable; +} + void GDNativeLibrary::_get_property_list(List<PropertyInfo> *p_list) const { // set entries List<String> entry_key_list; @@ -508,7 +518,7 @@ Error GDNative::get_symbol(StringName p_procedure_name, void *&r_handle, bool p_ return result; } -RES GDNativeLibraryResourceLoader::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) { +RES GDNativeLibraryResourceLoader::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_cache_mode) { Ref<GDNativeLibrary> lib; lib.instance(); diff --git a/modules/gdnative/gdnative.h b/modules/gdnative/gdnative.h index 765087d176..a28c58ec0d 100644 --- a/modules/gdnative/gdnative.h +++ b/modules/gdnative/gdnative.h @@ -63,6 +63,8 @@ class GDNativeLibrary : public Resource { bool reloadable; public: + virtual void reset_state() override; + GDNativeLibrary(); ~GDNativeLibrary(); @@ -166,7 +168,7 @@ public: class GDNativeLibraryResourceLoader : public ResourceFormatLoader { public: - virtual RES load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads = false, float *r_progress = nullptr, bool p_no_cache = false); + virtual RES load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads = false, float *r_progress = nullptr, CacheMode p_cache_mode = CACHE_MODE_REUSE); virtual void get_recognized_extensions(List<String> *p_extensions) const; virtual bool handles_type(const String &p_type) const; virtual String get_resource_type(const String &p_path) const; diff --git a/modules/gdnative/nativescript/nativescript.cpp b/modules/gdnative/nativescript/nativescript.cpp index def020adad..64fb8ee9c7 100644 --- a/modules/gdnative/nativescript/nativescript.cpp +++ b/modules/gdnative/nativescript/nativescript.cpp @@ -1728,7 +1728,7 @@ void NativeScriptLanguage::unregister_script(NativeScript *script) { library_script_users.erase(S); Map<String, Ref<GDNative>>::Element *G = library_gdnatives.find(script->lib_path); - if (G) { + if (G && G->get()->get_library()->is_reloadable()) { G->get()->terminate(); library_gdnatives.erase(G); } @@ -1940,7 +1940,7 @@ void NativeReloadNode::_notification(int p_what) { #endif } -RES ResourceFormatLoaderNativeScript::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) { +RES ResourceFormatLoaderNativeScript::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_no_cache) { return ResourceFormatLoaderText::singleton->load(p_path, p_original_path, r_error); } diff --git a/modules/gdnative/nativescript/nativescript.h b/modules/gdnative/nativescript/nativescript.h index ea7ced6511..81a158d09b 100644 --- a/modules/gdnative/nativescript/nativescript.h +++ b/modules/gdnative/nativescript/nativescript.h @@ -402,7 +402,7 @@ public: class ResourceFormatLoaderNativeScript : public ResourceFormatLoader { public: - virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, bool p_no_cache = false); + virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, CacheMode p_cache_mode = CACHE_MODE_REUSE); virtual void get_recognized_extensions(List<String> *p_extensions) const; virtual bool handles_type(const String &p_type) const; virtual String get_resource_type(const String &p_path) const; diff --git a/modules/gdnative/pluginscript/pluginscript_loader.cpp b/modules/gdnative/pluginscript/pluginscript_loader.cpp index cd1879a13e..f2165cd225 100644 --- a/modules/gdnative/pluginscript/pluginscript_loader.cpp +++ b/modules/gdnative/pluginscript/pluginscript_loader.cpp @@ -39,7 +39,7 @@ ResourceFormatLoaderPluginScript::ResourceFormatLoaderPluginScript(PluginScriptL _language = language; } -RES ResourceFormatLoaderPluginScript::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) { +RES ResourceFormatLoaderPluginScript::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_cache_mode) { if (r_error) { *r_error = ERR_FILE_CANT_OPEN; } diff --git a/modules/gdnative/pluginscript/pluginscript_loader.h b/modules/gdnative/pluginscript/pluginscript_loader.h index 7b1a7f5423..e5d665c186 100644 --- a/modules/gdnative/pluginscript/pluginscript_loader.h +++ b/modules/gdnative/pluginscript/pluginscript_loader.h @@ -43,7 +43,7 @@ class ResourceFormatLoaderPluginScript : public ResourceFormatLoader { public: ResourceFormatLoaderPluginScript(PluginScriptLanguage *language); - virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, bool p_no_cache = false); + virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, CacheMode p_cache_mode = CACHE_MODE_REUSE); virtual void get_recognized_extensions(List<String> *p_extensions) const; virtual bool handles_type(const String &p_type) const; virtual String get_resource_type(const String &p_path) const; diff --git a/modules/gdnative/videodecoder/video_stream_gdnative.cpp b/modules/gdnative/videodecoder/video_stream_gdnative.cpp index 18d26a9528..a594ba41ec 100644 --- a/modules/gdnative/videodecoder/video_stream_gdnative.cpp +++ b/modules/gdnative/videodecoder/video_stream_gdnative.cpp @@ -360,7 +360,7 @@ void VideoStreamGDNative::set_audio_track(int p_track) { /* --- NOTE ResourceFormatLoaderVideoStreamGDNative starts here. ----- */ -RES ResourceFormatLoaderVideoStreamGDNative::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) { +RES ResourceFormatLoaderVideoStreamGDNative::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_cache_mode) { FileAccess *f = FileAccess::open(p_path, FileAccess::READ); if (!f) { if (r_error) { diff --git a/modules/gdnative/videodecoder/video_stream_gdnative.h b/modules/gdnative/videodecoder/video_stream_gdnative.h index 3db5609952..140888cd4b 100644 --- a/modules/gdnative/videodecoder/video_stream_gdnative.h +++ b/modules/gdnative/videodecoder/video_stream_gdnative.h @@ -196,7 +196,7 @@ public: class ResourceFormatLoaderVideoStreamGDNative : public ResourceFormatLoader { public: - virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, bool p_no_cache = false); + virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, CacheMode p_cache_mode = CACHE_MODE_REUSE); virtual void get_recognized_extensions(List<String> *p_extensions) const; virtual bool handles_type(const String &p_type) const; virtual String get_resource_type(const String &p_path) const; diff --git a/modules/gdscript/editor/gdscript_translation_parser_plugin.cpp b/modules/gdscript/editor/gdscript_translation_parser_plugin.cpp index 6e930b6bf4..9d0d91162c 100644 --- a/modules/gdscript/editor/gdscript_translation_parser_plugin.cpp +++ b/modules/gdscript/editor/gdscript_translation_parser_plugin.cpp @@ -44,7 +44,7 @@ Error GDScriptEditorTranslationParserPlugin::parse_file(const String &p_path, Ve // Search strings in AssignmentNode -> text = "__", hint_tooltip = "__" etc. Error err; - RES loaded_res = ResourceLoader::load(p_path, "", false, &err); + RES loaded_res = ResourceLoader::load(p_path, "", ResourceFormatLoader::CACHE_MODE_REUSE, &err); if (err) { ERR_PRINT("Failed to load " + p_path); return err; diff --git a/modules/gdscript/gdscript.cpp b/modules/gdscript/gdscript.cpp index f891145988..a129b73c1a 100644 --- a/modules/gdscript/gdscript.cpp +++ b/modules/gdscript/gdscript.cpp @@ -2316,7 +2316,7 @@ Ref<GDScript> GDScriptLanguage::get_orphan_subclass(const String &p_qualified_na /*************** RESOURCE ***************/ -RES ResourceFormatLoaderGDScript::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) { +RES ResourceFormatLoaderGDScript::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_cache_mode) { if (r_error) { *r_error = ERR_FILE_CANT_OPEN; } diff --git a/modules/gdscript/gdscript.h b/modules/gdscript/gdscript.h index ee270f6b2f..12c909fd4f 100644 --- a/modules/gdscript/gdscript.h +++ b/modules/gdscript/gdscript.h @@ -529,7 +529,7 @@ public: class ResourceFormatLoaderGDScript : public ResourceFormatLoader { public: - virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, bool p_no_cache = false); + virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, CacheMode p_cache_mode = CACHE_MODE_REUSE); virtual void get_recognized_extensions(List<String> *p_extensions) const; virtual bool handles_type(const String &p_type) const; virtual String get_resource_type(const String &p_path) const; diff --git a/modules/gridmap/grid_map_editor_plugin.cpp b/modules/gridmap/grid_map_editor_plugin.cpp index 565830c16f..da9cdb9bc5 100644 --- a/modules/gridmap/grid_map_editor_plugin.cpp +++ b/modules/gridmap/grid_map_editor_plugin.cpp @@ -1172,7 +1172,7 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) { floor->set_min(-32767); floor->set_max(32767); floor->set_step(1); - floor->get_line_edit()->add_theme_constant_override("minimum_spaces", 16); + floor->get_line_edit()->add_theme_constant_override("minimum_character_width", 16); spatial_editor_hb->add_child(floor); floor->connect("value_changed", callable_mp(this, &GridMapEditor::_floor_changed)); diff --git a/modules/mono/csharp_script.cpp b/modules/mono/csharp_script.cpp index bd29dc1876..25cc64393a 100644 --- a/modules/mono/csharp_script.cpp +++ b/modules/mono/csharp_script.cpp @@ -3644,7 +3644,7 @@ void CSharpScript::get_members(Set<StringName> *p_members) { /*************** RESOURCE ***************/ -RES ResourceFormatLoaderCSharpScript::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) { +RES ResourceFormatLoaderCSharpScript::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_cache_mode) { if (r_error) { *r_error = ERR_FILE_CANT_OPEN; } diff --git a/modules/mono/csharp_script.h b/modules/mono/csharp_script.h index 85edd8b9c6..a31135cd32 100644 --- a/modules/mono/csharp_script.h +++ b/modules/mono/csharp_script.h @@ -542,7 +542,7 @@ public: class ResourceFormatLoaderCSharpScript : public ResourceFormatLoader { public: - RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, bool p_no_cache = false) override; + RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, CacheMode p_cache_mode = CACHE_MODE_REUSE) override; void get_recognized_extensions(List<String> *p_extensions) const override; bool handles_type(const String &p_type) const override; String get_resource_type(const String &p_path) const override; diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Extensions/ResourceLoaderExtensions.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Extensions/ResourceLoaderExtensions.cs index 5f64c09a89..74fa05d1fd 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Extensions/ResourceLoaderExtensions.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Extensions/ResourceLoaderExtensions.cs @@ -2,7 +2,7 @@ namespace Godot { public static partial class ResourceLoader { - public static T Load<T>(string path, string typeHint = null, bool noCache = false) where T : class + public static T Load<T>(string path, string typeHint = null, CacheMode noCache = CacheMode.Reuse) where T : class { return (T)(object)Load(path, typeHint, noCache); } diff --git a/modules/pvr/texture_loader_pvr.cpp b/modules/pvr/texture_loader_pvr.cpp index 056a923a2d..83f032ca2b 100644 --- a/modules/pvr/texture_loader_pvr.cpp +++ b/modules/pvr/texture_loader_pvr.cpp @@ -46,7 +46,7 @@ enum PVRFLags { PVR_VFLIP = 0x00010000 }; -RES ResourceFormatPVR::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) { +RES ResourceFormatPVR::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_cache_mode) { if (r_error) { *r_error = ERR_CANT_OPEN; } diff --git a/modules/pvr/texture_loader_pvr.h b/modules/pvr/texture_loader_pvr.h index da425c3237..26071ce30f 100644 --- a/modules/pvr/texture_loader_pvr.h +++ b/modules/pvr/texture_loader_pvr.h @@ -36,7 +36,7 @@ class ResourceFormatPVR : public ResourceFormatLoader { public: - virtual RES load(const String &p_path, const String &p_original_path, Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, bool p_no_cache = false); + virtual RES load(const String &p_path, const String &p_original_path, Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, CacheMode p_cache_mode = CACHE_MODE_REUSE); virtual void get_recognized_extensions(List<String> *p_extensions) const; virtual bool handles_type(const String &p_type) const; virtual String get_resource_type(const String &p_path) const; diff --git a/modules/theora/video_stream_theora.cpp b/modules/theora/video_stream_theora.cpp index afe26d4a5f..4b404eae32 100644 --- a/modules/theora/video_stream_theora.cpp +++ b/modules/theora/video_stream_theora.cpp @@ -677,7 +677,7 @@ void VideoStreamTheora::_bind_methods() { //////////// -RES ResourceFormatLoaderTheora::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) { +RES ResourceFormatLoaderTheora::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_cache_mode) { FileAccess *f = FileAccess::open(p_path, FileAccess::READ); if (!f) { if (r_error) { diff --git a/modules/theora/video_stream_theora.h b/modules/theora/video_stream_theora.h index 71e56e2ee8..f92fe2340e 100644 --- a/modules/theora/video_stream_theora.h +++ b/modules/theora/video_stream_theora.h @@ -185,7 +185,7 @@ public: class ResourceFormatLoaderTheora : public ResourceFormatLoader { public: - virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, bool p_no_cache = false); + virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, CacheMode p_cache_mode = CACHE_MODE_REUSE); virtual void get_recognized_extensions(List<String> *p_extensions) const; virtual bool handles_type(const String &p_type) const; virtual String get_resource_type(const String &p_path) const; diff --git a/modules/visual_script/visual_script_expression.cpp b/modules/visual_script/visual_script_expression.cpp index 5fc2ccf6e3..f673cbb06d 100644 --- a/modules/visual_script/visual_script_expression.cpp +++ b/modules/visual_script/visual_script_expression.cpp @@ -1506,6 +1506,19 @@ VisualScriptNodeInstance *VisualScriptExpression::instance(VisualScriptInstance return instance; } +void VisualScriptExpression::reset_state() { + if (nodes) { + memdelete(nodes); + nodes = nullptr; + root = nullptr; + } + + error_str = String(); + error_set = false; + str_ofs = 0; + inputs.clear(); +} + VisualScriptExpression::VisualScriptExpression() { } diff --git a/modules/visual_script/visual_script_expression.h b/modules/visual_script/visual_script_expression.h index bbf76cef3b..c35075ea53 100644 --- a/modules/visual_script/visual_script_expression.h +++ b/modules/visual_script/visual_script_expression.h @@ -256,6 +256,8 @@ protected: void _get_property_list(List<PropertyInfo> *p_list) const; public: + virtual void reset_state() override; + virtual int get_output_sequence_port_count() const override; virtual bool has_input_sequence_port() const override; diff --git a/modules/visual_script/visual_script_flow_control.cpp b/modules/visual_script/visual_script_flow_control.cpp index cfe283d9df..e2a8323509 100644 --- a/modules/visual_script/visual_script_flow_control.cpp +++ b/modules/visual_script/visual_script_flow_control.cpp @@ -677,6 +677,10 @@ void VisualScriptSwitch::_get_property_list(List<PropertyInfo> *p_list) const { } } +void VisualScriptSwitch::reset_state() { + case_values.clear(); +} + void VisualScriptSwitch::_bind_methods() { } diff --git a/modules/visual_script/visual_script_flow_control.h b/modules/visual_script/visual_script_flow_control.h index 46a72bb92d..d9c4dedafd 100644 --- a/modules/visual_script/visual_script_flow_control.h +++ b/modules/visual_script/visual_script_flow_control.h @@ -202,6 +202,8 @@ protected: static void _bind_methods(); public: + virtual void reset_state() override; + virtual int get_output_sequence_port_count() const override; virtual bool has_input_sequence_port() const override; diff --git a/modules/visual_script/visual_script_nodes.cpp b/modules/visual_script/visual_script_nodes.cpp index e3ca5ef855..fed6637acb 100644 --- a/modules/visual_script/visual_script_nodes.cpp +++ b/modules/visual_script/visual_script_nodes.cpp @@ -303,6 +303,14 @@ VisualScriptNodeInstance *VisualScriptFunction::instance(VisualScriptInstance *p return instance; } +void VisualScriptFunction::reset_state() { + arguments.clear(); + stack_size = 256; + stack_less = false; + sequenced = true; + rpc_mode = MultiplayerAPI::RPC_MODE_DISABLED; +} + VisualScriptFunction::VisualScriptFunction() { stack_size = 256; stack_less = false; @@ -687,6 +695,13 @@ bool VisualScriptLists::is_sequenced() const { return sequenced; } +void VisualScriptLists::reset_state() { + inputports.clear(); + outputports.clear(); + sequenced = false; + flags = 0; +} + VisualScriptLists::VisualScriptLists() { // initialize sequenced = false; diff --git a/modules/visual_script/visual_script_nodes.h b/modules/visual_script/visual_script_nodes.h index ae5e04d096..7392443e4e 100644 --- a/modules/visual_script/visual_script_nodes.h +++ b/modules/visual_script/visual_script_nodes.h @@ -99,6 +99,8 @@ public: virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; + virtual void reset_state() override; + VisualScriptFunction(); }; @@ -134,6 +136,8 @@ protected: static void _bind_methods(); public: + virtual void reset_state() override; + virtual bool is_output_port_editable() const; virtual bool is_output_port_name_editable() const; virtual bool is_output_port_type_editable() const; diff --git a/modules/webm/video_stream_webm.cpp b/modules/webm/video_stream_webm.cpp index 5d8245c64c..7c16a1df34 100644 --- a/modules/webm/video_stream_webm.cpp +++ b/modules/webm/video_stream_webm.cpp @@ -429,7 +429,7 @@ void VideoStreamWebm::set_audio_track(int p_track) { //////////// -RES ResourceFormatLoaderWebm::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) { +RES ResourceFormatLoaderWebm::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_cache_mode) { FileAccess *f = FileAccess::open(p_path, FileAccess::READ); if (!f) { if (r_error) { diff --git a/modules/webm/video_stream_webm.h b/modules/webm/video_stream_webm.h index cb3cf58850..60e02ab38b 100644 --- a/modules/webm/video_stream_webm.h +++ b/modules/webm/video_stream_webm.h @@ -126,7 +126,7 @@ public: class ResourceFormatLoaderWebm : public ResourceFormatLoader { public: - virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, bool p_no_cache = false); + virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, CacheMode p_cache_mode = CACHE_MODE_REUSE); virtual void get_recognized_extensions(List<String> *p_extensions) const; virtual bool handles_type(const String &p_type) const; virtual String get_resource_type(const String &p_path) const; diff --git a/modules/xatlas_unwrap/register_types.cpp b/modules/xatlas_unwrap/register_types.cpp index 880fe2df61..fb4df10904 100644 --- a/modules/xatlas_unwrap/register_types.cpp +++ b/modules/xatlas_unwrap/register_types.cpp @@ -154,6 +154,7 @@ bool xatlas_mesh_lightmap_unwrap_callback(float p_texel_size, const float *p_ver float h = *r_size_hint_y; if (w == 0 || h == 0) { + xatlas::Destroy(atlas); return false; //could not bake because there is no area } diff --git a/platform/javascript/display_server_javascript.cpp b/platform/javascript/display_server_javascript.cpp index b54ac5230a..5e2dddd8e7 100644 --- a/platform/javascript/display_server_javascript.cpp +++ b/platform/javascript/display_server_javascript.cpp @@ -845,7 +845,8 @@ Size2i DisplayServerJavaScript::screen_get_size(int p_screen) const { EmscriptenFullscreenChangeEvent ev; EMSCRIPTEN_RESULT result = emscripten_get_fullscreen_status(&ev); ERR_FAIL_COND_V(result != EMSCRIPTEN_RESULT_SUCCESS, Size2i()); - return Size2i(ev.screenWidth, ev.screenHeight); + double scale = godot_js_display_pixel_ratio_get(); + return Size2i(ev.screenWidth * scale, ev.screenHeight * scale); } Rect2i DisplayServerJavaScript::screen_get_usable_rect(int p_screen) const { @@ -855,7 +856,11 @@ Rect2i DisplayServerJavaScript::screen_get_usable_rect(int p_screen) const { } int DisplayServerJavaScript::screen_get_dpi(int p_screen) const { - return 96; // TODO maybe check pixel ratio via window.devicePixelRatio * 96? Inexact. + return godot_js_display_screen_dpi_get(); +} + +float DisplayServerJavaScript::screen_get_scale(int p_screen) const { + return godot_js_display_pixel_ratio_get(); } Vector<DisplayServer::WindowID> DisplayServerJavaScript::get_window_list() const { diff --git a/platform/javascript/display_server_javascript.h b/platform/javascript/display_server_javascript.h index e28fbc56f3..e2fe731abf 100644 --- a/platform/javascript/display_server_javascript.h +++ b/platform/javascript/display_server_javascript.h @@ -136,6 +136,7 @@ public: Size2i screen_get_size(int p_screen = SCREEN_OF_MAIN_WINDOW) const override; Rect2i screen_get_usable_rect(int p_screen = SCREEN_OF_MAIN_WINDOW) const override; int screen_get_dpi(int p_screen = SCREEN_OF_MAIN_WINDOW) const override; + float screen_get_scale(int p_screen = SCREEN_OF_MAIN_WINDOW) const override; // windows Vector<DisplayServer::WindowID> get_window_list() const override; diff --git a/platform/javascript/godot_js.h b/platform/javascript/godot_js.h index e8f41d4cae..d2a2fbd6db 100644 --- a/platform/javascript/godot_js.h +++ b/platform/javascript/godot_js.h @@ -51,6 +51,7 @@ extern int godot_js_os_execute(const char *p_json); extern void godot_js_os_shell_open(const char *p_uri); // Display +extern int godot_js_display_screen_dpi_get(); extern double godot_js_display_pixel_ratio_get(); extern void godot_js_display_alert(const char *p_text); extern int godot_js_display_touchscreen_is_available(); diff --git a/platform/javascript/js/libs/library_godot_display.js b/platform/javascript/js/libs/library_godot_display.js index 7b085aebc8..9ec295b39f 100644 --- a/platform/javascript/js/libs/library_godot_display.js +++ b/platform/javascript/js/libs/library_godot_display.js @@ -405,6 +405,27 @@ const GodotDisplay = { $GodotDisplay__deps: ['$GodotConfig', '$GodotRuntime', '$GodotDisplayCursor', '$GodotDisplayListeners', '$GodotDisplayDragDrop', '$GodotDisplayGamepads'], $GodotDisplay: { window_icon: '', + findDPI: function () { + function testDPI(dpi) { + return window.matchMedia(`(max-resolution: ${dpi}dpi)`).matches; + } + function bisect(low, high, func) { + const mid = parseInt(((high - low) / 2) + low, 10); + if (high - low <= 1) { + return func(high) ? high : low; + } + if (func(mid)) { + return bisect(low, mid, func); + } + return bisect(mid, high, func); + } + try { + const dpi = bisect(0, 800, testDPI); + return dpi >= 96 ? dpi : 96; + } catch (e) { + return 96; + } + }, }, godot_js_display_is_swap_ok_cancel__sig: 'i', @@ -422,6 +443,11 @@ const GodotDisplay = { window.alert(GodotRuntime.parseString(p_text)); // eslint-disable-line no-alert }, + godot_js_display_screen_dpi_get__sig: 'i', + godot_js_display_screen_dpi_get: function () { + return GodotDisplay.findDPI(); + }, + godot_js_display_pixel_ratio_get__sig: 'f', godot_js_display_pixel_ratio_get: function () { return window.devicePixelRatio || 1; diff --git a/scene/3d/mesh_instance_3d.cpp b/scene/3d/mesh_instance_3d.cpp index 775757dc9f..7b3a0820f1 100644 --- a/scene/3d/mesh_instance_3d.cpp +++ b/scene/3d/mesh_instance_3d.cpp @@ -95,7 +95,7 @@ void MeshInstance3D::_get_property_list(List<PropertyInfo> *p_list) const { ls.sort(); for (List<String>::Element *E = ls.front(); E; E = E->next()) { - p_list->push_back(PropertyInfo(Variant::FLOAT, E->get(), PROPERTY_HINT_RANGE, "0,1,0.00001")); + p_list->push_back(PropertyInfo(Variant::FLOAT, E->get(), PROPERTY_HINT_RANGE, "-1,1,0.00001")); } if (mesh.is_valid()) { diff --git a/scene/animation/animation_blend_tree.cpp b/scene/animation/animation_blend_tree.cpp index fb16f95379..79a1dc1ac0 100644 --- a/scene/animation/animation_blend_tree.cpp +++ b/scene/animation/animation_blend_tree.cpp @@ -1121,6 +1121,13 @@ void AnimationNodeBlendTree::_get_property_list(List<PropertyInfo> *p_list) cons p_list->push_back(PropertyInfo(Variant::ARRAY, "node_connections", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR)); } +void AnimationNodeBlendTree::reset_state() { + graph_offset = Vector2(); + nodes.clear(); + emit_changed(); + emit_signal("tree_changed"); +} + void AnimationNodeBlendTree::_tree_changed() { emit_signal("tree_changed"); } diff --git a/scene/animation/animation_blend_tree.h b/scene/animation/animation_blend_tree.h index 4732f43af2..d82658c8c2 100644 --- a/scene/animation/animation_blend_tree.h +++ b/scene/animation/animation_blend_tree.h @@ -351,6 +351,8 @@ protected: bool _get(const StringName &p_name, Variant &r_ret) const; void _get_property_list(List<PropertyInfo> *p_list) const; + virtual void reset_state() override; + public: enum ConnectionError { CONNECTION_OK, diff --git a/scene/animation/animation_node_state_machine.cpp b/scene/animation/animation_node_state_machine.cpp index 4f69b05afe..71de3635f9 100644 --- a/scene/animation/animation_node_state_machine.cpp +++ b/scene/animation/animation_node_state_machine.cpp @@ -914,6 +914,18 @@ void AnimationNodeStateMachine::_get_property_list(List<PropertyInfo> *p_list) c p_list->push_back(PropertyInfo(Variant::VECTOR2, "graph_offset", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR)); } +void AnimationNodeStateMachine::reset_state() { + states.clear(); + transitions.clear(); + playback = "playback"; + start_node = StringName(); + end_node = StringName(); + graph_offset = Vector2(); + + emit_changed(); + emit_signal("tree_changed"); +} + void AnimationNodeStateMachine::set_node_position(const StringName &p_name, const Vector2 &p_position) { ERR_FAIL_COND(!states.has(p_name)); states[p_name].position = p_position; diff --git a/scene/animation/animation_node_state_machine.h b/scene/animation/animation_node_state_machine.h index 7abc6388a1..9c1bca63c3 100644 --- a/scene/animation/animation_node_state_machine.h +++ b/scene/animation/animation_node_state_machine.h @@ -171,6 +171,8 @@ protected: bool _get(const StringName &p_name, Variant &r_ret) const; void _get_property_list(List<PropertyInfo> *p_list) const; + virtual void reset_state() override; + public: virtual void get_parameter_list(List<PropertyInfo> *r_list) const override; virtual Variant get_parameter_default_value(const StringName &p_parameter) const override; diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp index bbe09af3aa..654507b933 100644 --- a/scene/gui/line_edit.cpp +++ b/scene/gui/line_edit.cpp @@ -1568,12 +1568,12 @@ Size2 LineEdit::get_minimum_size() const { Size2 min_size; // Minimum size of text. - int space_size = font->get_char_size('m', 0, font_size).x; - min_size.width = get_theme_constant("minimum_spaces") * space_size; + int em_space_size = font->get_char_size('M', 0, font_size).x; + min_size.width = get_theme_constant("minimum_character_width'") * em_space_size; if (expand_to_text_length) { // Add a space because some fonts are too exact, and because cursor needs a bit more when at the end. - min_size.width = MAX(min_size.width, full_width + space_size); + min_size.width = MAX(min_size.width, full_width + em_space_size); } min_size.height = MAX(TS->shaped_text_get_size(text_rid).y + font->get_spacing(Font::SPACING_TOP) + font->get_spacing(Font::SPACING_BOTTOM), font->get_height(font_size)); diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index f9f8f4f78a..07251cbed5 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -220,7 +220,7 @@ void RichTextLabel::_resize_line(ItemFrame *p_frame, int p_line, const Ref<Font> if (tab_size > 0) { // Align inline tabs. Vector<float> tabs; - tabs.push_back(tab_size * p_base_font->get_char_size('m', 0, p_base_font_size).width); + tabs.push_back(tab_size * p_base_font->get_char_size(' ', 0, p_base_font_size).width); l.text_buf->tab_align(tabs); } @@ -392,7 +392,7 @@ void RichTextLabel::_shape_line(ItemFrame *p_frame, int p_line, const Ref<Font> if (tab_size > 0) { // Align inline tabs. Vector<float> tabs; - tabs.push_back(tab_size * p_base_font->get_char_size('m', 0, p_base_font_size).width); + tabs.push_back(tab_size * p_base_font->get_char_size(' ', 0, p_base_font_size).width); l.text_buf->tab_align(tabs); } @@ -1859,7 +1859,7 @@ int RichTextLabel::_find_margin(Item *p_item, const Ref<Font> &p_base_font, int if (font_size == -1) { font_size = p_base_font_size; } - margin += tab_size * font->get_char_size('m', 0, font_size).width; + margin += tab_size * font->get_char_size(' ', 0, font_size).width; } else if (item->type == ITEM_LIST) { Ref<Font> font = _find_font(item); @@ -1870,7 +1870,7 @@ int RichTextLabel::_find_margin(Item *p_item, const Ref<Font> &p_base_font, int if (font_size == -1) { font_size = p_base_font_size; } - margin += tab_size * font->get_char_size('m', 0, font_size).width; + margin += tab_size * font->get_char_size(' ', 0, font_size).width; } item = item->parent; diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index d31d00675e..57426f6a21 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -202,7 +202,7 @@ void TextEdit::Text::invalidate_cache(int p_line, int p_column, const String &p_ // Apply tab align. if (indent_size > 0) { Vector<float> tabs; - tabs.push_back(font->get_char_size('m', 0, font_size).width * indent_size); + tabs.push_back(font->get_char_size(' ', 0, font_size).width * indent_size); text.write[p_line].data_buf->tab_align(tabs); } } @@ -212,7 +212,7 @@ void TextEdit::Text::invalidate_all_lines() { text.write[i].data_buf->set_width(width); if (indent_size > 0) { Vector<float> tabs; - tabs.push_back(font->get_char_size('m', 0, font_size).width * indent_size); + tabs.push_back(font->get_char_size(' ', 0, font_size).width * indent_size); text.write[i].data_buf->tab_align(tabs); } } @@ -500,7 +500,7 @@ void TextEdit::_update_minimap_click() { int row; _get_minimap_mouse_row(Point2i(mp.x, mp.y), row); - if (row >= get_first_visible_line() && (row < get_last_visible_line() || row >= (text.size() - 1))) { + if (row >= get_first_visible_line() && (row < get_last_full_visible_line() || row >= (text.size() - 1))) { minimap_scroll_ratio = v_scroll->get_as_ratio(); minimap_scroll_click_pos = mp.y; can_drag_minimap = true; @@ -977,6 +977,16 @@ void TextEdit::_notification(int p_what) { } } + int top_limit_y = 0; + int bottom_limit_y = get_size().height; + if (readonly) { + top_limit_y += cache.style_readonly->get_margin(SIDE_TOP); + bottom_limit_y -= cache.style_readonly->get_margin(SIDE_BOTTOM); + } else { + top_limit_y += cache.style_normal->get_margin(SIDE_TOP); + bottom_limit_y -= cache.style_normal->get_margin(SIDE_BOTTOM); + } + // draw main text int row_height = get_row_height(); int line = first_visible_line; @@ -1019,17 +1029,33 @@ void TextEdit::_notification(int p_what) { const String &str = wrap_rows[line_wrap_index]; int char_margin = xmargin_beg - cursor.x_ofs; - int ofs_readonly = 0; int ofs_x = 0; + int ofs_y = 0; if (readonly) { - ofs_readonly = cache.style_readonly->get_offset().y / 2; ofs_x = cache.style_readonly->get_offset().x / 2; + ofs_x -= cache.style_normal->get_offset().x / 2; + ofs_y = cache.style_readonly->get_offset().y / 2; + } else { + ofs_y = cache.style_normal->get_offset().y / 2; } - int ofs_y = (i * row_height + cache.line_spacing / 2) + ofs_readonly; + ofs_y += i * row_height + cache.line_spacing / 2; ofs_y -= cursor.wrap_ofs * row_height; ofs_y -= get_v_scroll_offset() * row_height; + bool clipped = false; + if (ofs_y + row_height < top_limit_y) { + // Line is outside the top margin, clip current line. + // Still need to go through the process to prepare color changes for next lines. + clipped = true; + } + + if (ofs_y > bottom_limit_y) { + // Line is outside the bottom margin, clip any remaining text. + i = draw_amount; + break; + } + if (text.is_marked(line)) { if (rtl) { RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(size.width - ofs_x - xmargin_end, ofs_y, xmargin_end - xmargin_beg, row_height), cache.mark_color); @@ -1050,7 +1076,7 @@ void TextEdit::_notification(int p_what) { // Give visual indication of empty selected line. if (selection.active && line >= selection.from_line && line <= selection.to_line && char_margin >= xmargin_beg) { - int char_w = cache.font->get_char_size('m', 0, cache.font_size).width; + int char_w = cache.font->get_char_size(' ', 0, cache.font_size).width; if (rtl) { RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(size.width - xmargin_beg - ofs_x - char_w, ofs_y, char_w, row_height), cache.selection_color); } else { @@ -1147,7 +1173,7 @@ void TextEdit::_notification(int p_what) { char_margin = size.width - char_margin - TS->shaped_text_get_size(rid).x; } - if (selection.active && line >= selection.from_line && line <= selection.to_line) { // Selection + if (!clipped && selection.active && line >= selection.from_line && line <= selection.to_line) { // Selection int sel_from = (line > selection.from_line) ? TS->shaped_text_get_range(rid).x : selection.from_column; int sel_to = (line < selection.to_line) ? TS->shaped_text_get_range(rid).y : selection.to_column; Vector<Vector2> sel = TS->shaped_text_get_selection(rid, sel_from, sel_to); @@ -1167,7 +1193,7 @@ void TextEdit::_notification(int p_what) { } int start = TS->shaped_text_get_range(rid).x; - if (!search_text.is_empty()) { // Search highhlight + if (!clipped && !search_text.is_empty()) { // Search highhlight int search_text_col = _get_column_pos_of_word(search_text, str, search_flags, 0); while (search_text_col != -1) { Vector<Vector2> sel = TS->shaped_text_get_selection(rid, search_text_col + start, search_text_col + search_text.length() + start); @@ -1190,7 +1216,7 @@ void TextEdit::_notification(int p_what) { } } - if (highlight_all_occurrences && !only_whitespaces_highlighted && !highlighted_text.is_empty()) { // Highlight + if (!clipped && highlight_all_occurrences && !only_whitespaces_highlighted && !highlighted_text.is_empty()) { // Highlight int highlighted_text_col = _get_column_pos_of_word(highlighted_text, str, SEARCH_MATCH_CASE | SEARCH_WHOLE_WORDS, 0); while (highlighted_text_col != -1) { Vector<Vector2> sel = TS->shaped_text_get_selection(rid, highlighted_text_col + start, highlighted_text_col + highlighted_text.length() + start); @@ -1212,7 +1238,7 @@ void TextEdit::_notification(int p_what) { } } - if (select_identifiers_enabled && highlighted_word.length() != 0) { // Highlight word + if (!clipped && select_identifiers_enabled && highlighted_word.length() != 0) { // Highlight word if (_is_char(highlighted_word[0]) || highlighted_word[0] == '.') { int highlighted_word_col = _get_column_pos_of_word(highlighted_word, str, SEARCH_MATCH_CASE | SEARCH_WHOLE_WORDS, 0); while (highlighted_word_col != -1) { @@ -1297,7 +1323,7 @@ void TextEdit::_notification(int p_what) { } for (int k = 0; k < glyphs[j].repeat; k++) { - if ((char_ofs + char_margin) >= xmargin_beg && (char_ofs + glyphs[j].advance + char_margin) <= xmargin_end) { + if (!clipped && (char_ofs + char_margin) >= xmargin_beg && (char_ofs + glyphs[j].advance + char_margin) <= xmargin_end) { if (glyphs[j].font_rid != RID()) { TS->font_draw_glyph(glyphs[j].font_rid, ci, glyphs[j].font_size, Vector2(char_margin + char_ofs + ofs_x + glyphs[j].x_off, ofs_y + glyphs[j].y_off), glyphs[j].index, current_color); } else if ((glyphs[j].flags & TextServer::GRAPHEME_IS_VIRTUAL) != TextServer::GRAPHEME_IS_VIRTUAL) { @@ -1327,7 +1353,7 @@ void TextEdit::_notification(int p_what) { #else int caret_width = 1; #endif - if (cursor.line == line && ((line_wrap_index == line_wrap_amount) || (cursor.column != TS->shaped_text_get_range(rid).y))) { + if (!clipped && cursor.line == line && ((line_wrap_index == line_wrap_amount) || (cursor.column != TS->shaped_text_get_range(rid).y))) { is_cursor_line_visible = true; cursor_pos.y = line_top_offset_y; @@ -1380,7 +1406,7 @@ void TextEdit::_notification(int p_what) { l_caret.size.y = h; } l_caret.position += Vector2(char_margin + ofs_x, ofs_y); - l_caret.size.x = cache.font->get_char_size('m', 0, cache.font_size).x; + l_caret.size.x = cache.font->get_char_size('M', 0, cache.font_size).x; draw_rect(l_caret, cache.caret_color, false); } @@ -1444,7 +1470,6 @@ void TextEdit::_notification(int p_what) { } } } - ofs_y += ldata->get_line_descent(line_wrap_index); } } @@ -3775,8 +3800,8 @@ void TextEdit::_scroll_lines_up() { if (!selection.active) { int cur_line = cursor.line; int cur_wrap = get_cursor_wrap_index(); - int last_vis_line = get_last_visible_line(); - int last_vis_wrap = get_last_visible_line_wrap_index(); + int last_vis_line = get_last_full_visible_line(); + int last_vis_wrap = get_last_full_visible_line_wrap_index(); if (cur_line > last_vis_line || (cur_line == last_vis_line && cur_wrap > last_vis_wrap)) { cursor_set_line(last_vis_line, false, false, last_vis_wrap); @@ -4149,8 +4174,8 @@ void TextEdit::adjust_viewport_to_cursor() { int first_vis_line = get_first_visible_line(); int first_vis_wrap = cursor.wrap_ofs; - int last_vis_line = get_last_visible_line(); - int last_vis_wrap = get_last_visible_line_wrap_index(); + int last_vis_line = get_last_full_visible_line(); + int last_vis_wrap = get_last_full_visible_line_wrap_index(); if (cur_line < first_vis_line || (cur_line == first_vis_line && cur_wrap < first_vis_wrap)) { // Cursor is above screen. @@ -6163,19 +6188,19 @@ int TextEdit::get_first_visible_line() const { return CLAMP(cursor.line_ofs, 0, text.size() - 1); } -int TextEdit::get_last_visible_line() const { +int TextEdit::get_last_full_visible_line() const { int first_vis_line = get_first_visible_line(); int last_vis_line = 0; int wi; - last_vis_line = first_vis_line + num_lines_from_rows(first_vis_line, cursor.wrap_ofs, get_visible_rows() + 1, wi) - 1; + last_vis_line = first_vis_line + num_lines_from_rows(first_vis_line, cursor.wrap_ofs, get_visible_rows(), wi) - 1; last_vis_line = CLAMP(last_vis_line, 0, text.size() - 1); return last_vis_line; } -int TextEdit::get_last_visible_line_wrap_index() const { +int TextEdit::get_last_full_visible_line_wrap_index() const { int first_vis_line = get_first_visible_line(); int wi; - num_lines_from_rows(first_vis_line, cursor.wrap_ofs, get_visible_rows() + 1, wi); + num_lines_from_rows(first_vis_line, cursor.wrap_ofs, get_visible_rows(), wi); return wi; } diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h index 37299ec063..bfe9369bef 100644 --- a/scene/gui/text_edit.h +++ b/scene/gui/text_edit.h @@ -373,8 +373,8 @@ private: void set_line_as_center_visible(int p_line, int p_wrap_index = 0); void set_line_as_last_visible(int p_line, int p_wrap_index = 0); int get_first_visible_line() const; - int get_last_visible_line() const; - int get_last_visible_line_wrap_index() const; + int get_last_full_visible_line() const; + int get_last_full_visible_line_wrap_index() const; double get_visible_rows_offset() const; double get_v_scroll_offset() const; diff --git a/scene/main/node.cpp b/scene/main/node.cpp index 9ac3b4a691..e109240f59 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -2138,8 +2138,17 @@ Node *Node::duplicate(int p_flags) const { #ifdef TOOLS_ENABLED Node *Node::duplicate_from_editor(Map<const Node *, Node *> &r_duplimap) const { + return duplicate_from_editor(r_duplimap, Map<RES, RES>()); +} + +Node *Node::duplicate_from_editor(Map<const Node *, Node *> &r_duplimap, const Map<RES, RES> &p_resource_remap) const { Node *dupe = _duplicate(DUPLICATE_SIGNALS | DUPLICATE_GROUPS | DUPLICATE_SCRIPTS | DUPLICATE_USE_INSTANCING | DUPLICATE_FROM_EDITOR, &r_duplimap); + // This is used by SceneTreeDock's paste functionality. When pasting to foreign scene, resources are duplicated. + if (!p_resource_remap.is_empty()) { + remap_node_resources(dupe, p_resource_remap); + } + // Duplication of signals must happen after all the node descendants have been copied, // because re-targeting of connections from some descendant to another is not possible // if the emitter node comes later in tree order than the receiver @@ -2147,6 +2156,54 @@ Node *Node::duplicate_from_editor(Map<const Node *, Node *> &r_duplimap) const { return dupe; } + +void Node::remap_node_resources(Node *p_node, const Map<RES, RES> &p_resource_remap) const { + List<PropertyInfo> props; + p_node->get_property_list(&props); + + for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) { + if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) { + continue; + } + + Variant v = p_node->get(E->get().name); + if (v.is_ref()) { + RES res = v; + if (res.is_valid()) { + if (p_resource_remap.has(res)) { + p_node->set(E->get().name, p_resource_remap[res]); + remap_nested_resources(res, p_resource_remap); + } + } + } + } + + for (int i = 0; i < p_node->get_child_count(); i++) { + remap_node_resources(p_node->get_child(i), p_resource_remap); + } +} + +void Node::remap_nested_resources(RES p_resource, const Map<RES, RES> &p_resource_remap) const { + List<PropertyInfo> props; + p_resource->get_property_list(&props); + + for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) { + if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) { + continue; + } + + Variant v = p_resource->get(E->get().name); + if (v.is_ref()) { + RES res = v; + if (res.is_valid()) { + if (p_resource_remap.has(res)) { + p_resource->set(E->get().name, p_resource_remap[res]); + remap_nested_resources(res, p_resource_remap); + } + } + } + } +} #endif void Node::_duplicate_and_reown(Node *p_new_parent, const Map<Node *, Node *> &p_reown_map) const { diff --git a/scene/main/node.h b/scene/main/node.h index 5253ed2e45..66104b5cf5 100644 --- a/scene/main/node.h +++ b/scene/main/node.h @@ -362,6 +362,9 @@ public: Node *duplicate_and_reown(const Map<Node *, Node *> &p_reown_map) const; #ifdef TOOLS_ENABLED Node *duplicate_from_editor(Map<const Node *, Node *> &r_duplimap) const; + Node *duplicate_from_editor(Map<const Node *, Node *> &r_duplimap, const Map<RES, RES> &p_resource_remap) const; + void remap_node_resources(Node *p_node, const Map<RES, RES> &p_resource_remap) const; + void remap_nested_resources(RES p_resource, const Map<RES, RES> &p_resource_remap) const; #endif // used by editors, to save what has changed only diff --git a/scene/resources/animation.cpp b/scene/resources/animation.cpp index 62a796b492..cc1dafd0db 100644 --- a/scene/resources/animation.cpp +++ b/scene/resources/animation.cpp @@ -580,6 +580,10 @@ void Animation::_get_property_list(List<PropertyInfo> *p_list) const { } } +void Animation::reset_state() { + clear(); +} + int Animation::add_track(TrackType p_type, int p_at_pos) { if (p_at_pos < 0 || p_at_pos >= tracks.size()) { p_at_pos = tracks.size(); diff --git a/scene/resources/animation.h b/scene/resources/animation.h index ab3bbfacba..fd22cc445c 100644 --- a/scene/resources/animation.h +++ b/scene/resources/animation.h @@ -252,6 +252,8 @@ protected: bool _get(const StringName &p_name, Variant &r_ret) const; void _get_property_list(List<PropertyInfo> *p_list) const; + virtual void reset_state() override; + static void _bind_methods(); public: diff --git a/scene/resources/default_theme/default_theme.cpp b/scene/resources/default_theme/default_theme.cpp index 31bc00e528..e66de82ed9 100644 --- a/scene/resources/default_theme/default_theme.cpp +++ b/scene/resources/default_theme/default_theme.cpp @@ -394,7 +394,7 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const theme->set_color("clear_button_color", "LineEdit", control_font_color); theme->set_color("clear_button_color_pressed", "LineEdit", control_font_pressed_color); - theme->set_constant("minimum_spaces", "LineEdit", 12 * scale); + theme->set_constant("minimum_character_width", "LineEdit", 4); theme->set_icon("clear", "LineEdit", make_icon(line_edit_clear_png)); diff --git a/scene/resources/font.cpp b/scene/resources/font.cpp index 3d610fd708..06a15e36d7 100644 --- a/scene/resources/font.cpp +++ b/scene/resources/font.cpp @@ -177,6 +177,14 @@ void FontData::_get_property_list(List<PropertyInfo> *p_list) const { } } +void FontData::reset_state() { + if (rid != RID()) { + TS->free(rid); + } + base_size = 16; + path = String(); +} + RID FontData::get_rid() const { return rid; } @@ -588,6 +596,14 @@ void Font::_get_property_list(List<PropertyInfo> *p_list) const { p_list->push_back(PropertyInfo(Variant::OBJECT, "data/" + itos(data.size()), PROPERTY_HINT_RESOURCE_TYPE, "FontData")); } +void Font::reset_state() { + spacing_top = 0; + spacing_bottom = 0; + cache.clear(); + cache_wrap.clear(); + data.clear(); +} + void Font::add_data(const Ref<FontData> &p_data) { ERR_FAIL_COND(p_data.is_null()); data.push_back(p_data); @@ -951,7 +967,7 @@ Font::~Font() { /*************************************************************************/ -RES ResourceFormatLoaderFont::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) { +RES ResourceFormatLoaderFont::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_cache_mode) { if (r_error) { *r_error = ERR_FILE_CANT_OPEN; } @@ -1006,7 +1022,7 @@ String ResourceFormatLoaderFont::get_resource_type(const String &p_path) const { #ifndef DISABLE_DEPRECATED -RES ResourceFormatLoaderCompatFont::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) { +RES ResourceFormatLoaderCompatFont::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_cache_mode) { if (r_error) { *r_error = ERR_FILE_CANT_OPEN; } diff --git a/scene/resources/font.h b/scene/resources/font.h index 086226c082..a91c9ec7a5 100644 --- a/scene/resources/font.h +++ b/scene/resources/font.h @@ -53,6 +53,8 @@ protected: bool _get(const StringName &p_name, Variant &r_ret) const; void _get_property_list(List<PropertyInfo> *p_list) const; + virtual void reset_state() override; + public: virtual RID get_rid() const override; @@ -151,6 +153,8 @@ protected: bool _get(const StringName &p_name, Variant &r_ret) const; void _get_property_list(List<PropertyInfo> *p_list) const; + virtual void reset_state() override; + void _data_changed(); public: @@ -201,7 +205,7 @@ VARIANT_ENUM_CAST(Font::SpacingType); class ResourceFormatLoaderFont : public ResourceFormatLoader { public: - virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, bool p_no_cache = false); + virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, CacheMode p_cache_mode = CACHE_MODE_REUSE); virtual void get_recognized_extensions_for_type(const String &p_type, List<String> *p_extensions) const; virtual void get_recognized_extensions(List<String> *p_extensions) const; virtual bool handles_type(const String &p_type) const; @@ -212,7 +216,7 @@ public: class ResourceFormatLoaderCompatFont : public ResourceFormatLoader { public: - virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, bool p_no_cache = false); + virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, CacheMode p_cache_mode = CACHE_MODE_REUSE); virtual void get_recognized_extensions_for_type(const String &p_type, List<String> *p_extensions) const; virtual void get_recognized_extensions(List<String> *p_extensions) const; virtual bool handles_type(const String &p_type) const; diff --git a/scene/resources/material.h b/scene/resources/material.h index 595db36a57..70452a5f74 100644 --- a/scene/resources/material.h +++ b/scene/resources/material.h @@ -519,7 +519,7 @@ private: AlphaAntiAliasing alpha_antialiasing_mode = ALPHA_ANTIALIASING_OFF; - bool features[FEATURE_MAX]; + bool features[FEATURE_MAX] = {}; Ref<Texture2D> textures[TEXTURE_MAX]; diff --git a/scene/resources/mesh.cpp b/scene/resources/mesh.cpp index 81dbb36288..1a2b21299a 100644 --- a/scene/resources/mesh.cpp +++ b/scene/resources/mesh.cpp @@ -1095,6 +1095,15 @@ bool ArrayMesh::_get(const StringName &p_name, Variant &r_ret) const { return true; } +void ArrayMesh::reset_state() { + clear_surfaces(); + clear_blend_shapes(); + + aabb = AABB(); + blend_shape_mode = BLEND_SHAPE_MODE_RELATIVE; + custom_aabb = AABB(); +} + void ArrayMesh::_get_property_list(List<PropertyInfo> *p_list) const { if (_is_generated()) { return; diff --git a/scene/resources/mesh.h b/scene/resources/mesh.h index 8883fb9c2b..2ce519e644 100644 --- a/scene/resources/mesh.h +++ b/scene/resources/mesh.h @@ -207,6 +207,8 @@ protected: bool _get(const StringName &p_name, Variant &r_ret) const; void _get_property_list(List<PropertyInfo> *p_list) const; + virtual void reset_state() override; + static void _bind_methods(); public: diff --git a/scene/resources/mesh_library.cpp b/scene/resources/mesh_library.cpp index 84da0feab0..ad90481fbd 100644 --- a/scene/resources/mesh_library.cpp +++ b/scene/resources/mesh_library.cpp @@ -264,6 +264,9 @@ Array MeshLibrary::_get_item_shapes(int p_item) const { return ret; } +void MeshLibrary::reset_state() { + clear(); +} void MeshLibrary::_bind_methods() { ClassDB::bind_method(D_METHOD("create_item", "id"), &MeshLibrary::create_item); ClassDB::bind_method(D_METHOD("set_item_name", "id", "name"), &MeshLibrary::set_item_name); diff --git a/scene/resources/mesh_library.h b/scene/resources/mesh_library.h index 5c302fcf08..1da624c275 100644 --- a/scene/resources/mesh_library.h +++ b/scene/resources/mesh_library.h @@ -65,6 +65,7 @@ protected: bool _get(const StringName &p_name, Variant &r_ret) const; void _get_property_list(List<PropertyInfo> *p_list) const; + virtual void reset_state() override; static void _bind_methods(); public: diff --git a/scene/resources/packed_scene.cpp b/scene/resources/packed_scene.cpp index ef0c3c830b..beb365d44e 100644 --- a/scene/resources/packed_scene.cpp +++ b/scene/resources/packed_scene.cpp @@ -1661,6 +1661,9 @@ void PackedScene::set_path(const String &p_path, bool p_take_over) { Resource::set_path(p_path, p_take_over); } +void PackedScene::reset_state() { + clear(); +} void PackedScene::_bind_methods() { ClassDB::bind_method(D_METHOD("pack", "path"), &PackedScene::pack); ClassDB::bind_method(D_METHOD("instance", "edit_state"), &PackedScene::instance, DEFVAL(GEN_EDIT_STATE_DISABLED)); diff --git a/scene/resources/packed_scene.h b/scene/resources/packed_scene.h index e24b09e77f..78a0aeaa9a 100644 --- a/scene/resources/packed_scene.h +++ b/scene/resources/packed_scene.h @@ -200,6 +200,7 @@ class PackedScene : public Resource { protected: virtual bool editor_can_reload_from_file() override { return false; } // this is handled by editor better static void _bind_methods(); + virtual void reset_state() override; public: enum GenEditState { diff --git a/scene/resources/resource_format_text.cpp b/scene/resources/resource_format_text.cpp index f42f957f6e..7ca532e1d6 100644 --- a/scene/resources/resource_format_text.cpp +++ b/scene/resources/resource_format_text.cpp @@ -114,23 +114,8 @@ Error ResourceLoaderText::_parse_sub_resource(VariantParser::Stream *p_stream, R } int index = token.value; - - if (use_nocache) { - r_res = int_resources[index]; - } else { - String path = local_path + "::" + itos(index); - - if (!ignore_resource_parsing) { - if (!ResourceCache::has(path)) { - r_err_str = "Can't load cached sub-resource: " + path; - return ERR_PARSE_ERROR; - } - - r_res = RES(ResourceCache::get(path)); - } else { - r_res = RES(); - } - } + ERR_FAIL_COND_V(!int_resources.has(index), ERR_INVALID_PARAMETER); + r_res = int_resources[index]; VariantParser::get_token(p_stream, token, line, r_err_str); if (token.type != VariantParser::TK_PARENTHESIS_CLOSE) { @@ -440,7 +425,7 @@ Error ResourceLoaderText::load() { er.type = type; if (use_sub_threads) { - Error err = ResourceLoader::load_threaded_request(path, type, use_sub_threads, local_path); + Error err = ResourceLoader::load_threaded_request(path, type, use_sub_threads, ResourceFormatLoader::CACHE_MODE_REUSE, local_path); if (err != OK) { if (ResourceLoader::get_abort_on_missing_resources()) { @@ -517,29 +502,44 @@ Error ResourceLoaderText::load() { //bool exists=ResourceCache::has(path); Ref<Resource> res; + bool do_assign = false; - if (use_nocache || !ResourceCache::has(path)) { //only if it doesn't exist - - Object *obj = ClassDB::instance(type); - if (!obj) { - error_text += "Can't create sub resource of type: " + type; - _printerr(); - error = ERR_FILE_CORRUPT; - return error; + if (cache_mode == ResourceFormatLoader::CACHE_MODE_REPLACE && ResourceCache::has(path)) { + //reuse existing + Resource *r = ResourceCache::get(path); + if (r && r->get_class() == type) { + res = Ref<Resource>(r); + res->reset_state(); + do_assign = true; } + } - Resource *r = Object::cast_to<Resource>(obj); - if (!r) { - error_text += "Can't create sub resource of type, because not a resource: " + type; - _printerr(); - error = ERR_FILE_CORRUPT; - return error; - } + if (res.is_null()) { //not reuse + if (cache_mode != ResourceFormatLoader::CACHE_MODE_IGNORE && ResourceCache::has(path)) { //only if it doesn't exist + //cached, do not assign + Resource *r = ResourceCache::get(path); + res = Ref<Resource>(r); + } else { + //create + + Object *obj = ClassDB::instance(type); + if (!obj) { + error_text += "Can't create sub resource of type: " + type; + _printerr(); + error = ERR_FILE_CORRUPT; + return error; + } + + Resource *r = Object::cast_to<Resource>(obj); + if (!r) { + error_text += "Can't create sub resource of type, because not a resource: " + type; + _printerr(); + error = ERR_FILE_CORRUPT; + return error; + } - res = Ref<Resource>(r); - int_resources[id] = res; - if (!use_nocache) { - res->set_path(path); + res = Ref<Resource>(r); + do_assign = true; } } @@ -557,7 +557,7 @@ Error ResourceLoaderText::load() { } if (assign != String()) { - if (res.is_valid()) { + if (do_assign) { res->set(assign, value); } //it's assignment @@ -572,6 +572,11 @@ Error ResourceLoaderText::load() { } } + int_resources[id] = res; //always assign int resources + if (do_assign && cache_mode != ResourceFormatLoader::CACHE_MODE_IGNORE) { + res->set_path(path, cache_mode == ResourceFormatLoader::CACHE_MODE_REPLACE); + } + if (progress && resources_total > 0) { *progress = resource_current / float(resources_total); } @@ -589,23 +594,33 @@ Error ResourceLoaderText::load() { return error; } - Object *obj = ClassDB::instance(res_type); - if (!obj) { - error_text += "Can't create sub resource of type: " + res_type; - _printerr(); - error = ERR_FILE_CORRUPT; - return error; + if (cache_mode == ResourceFormatLoader::CACHE_MODE_REPLACE && ResourceCache::has(local_path)) { + Resource *r = ResourceCache::get(local_path); + if (r->get_class() == res_type) { + r->reset_state(); + resource = Ref<Resource>(r); + } } - Resource *r = Object::cast_to<Resource>(obj); - if (!r) { - error_text += "Can't create sub resource of type, because not a resource: " + res_type; - _printerr(); - error = ERR_FILE_CORRUPT; - return error; - } + if (!resource.is_valid()) { + Object *obj = ClassDB::instance(res_type); + if (!obj) { + error_text += "Can't create sub resource of type: " + res_type; + _printerr(); + error = ERR_FILE_CORRUPT; + return error; + } - resource = Ref<Resource>(r); + Resource *r = Object::cast_to<Resource>(obj); + if (!r) { + error_text += "Can't create sub resource of type, because not a resource: " + res_type; + _printerr(); + error = ERR_FILE_CORRUPT; + return error; + } + + resource = Ref<Resource>(r); + } resource_current++; @@ -620,7 +635,7 @@ Error ResourceLoaderText::load() { _printerr(); } else { error = OK; - if (!use_nocache) { + if (cache_mode != ResourceFormatLoader::CACHE_MODE_IGNORE) { if (!ResourceCache::has(res_path)) { resource->set_path(res_path); } @@ -668,7 +683,7 @@ Error ResourceLoaderText::load() { error = OK; //get it here resource = packed_scene; - if (!use_nocache && !ResourceCache::has(res_path)) { + if (cache_mode != ResourceFormatLoader::CACHE_MODE_IGNORE && !ResourceCache::has(res_path)) { packed_scene->set_path(res_path); } @@ -1241,7 +1256,7 @@ String ResourceLoaderText::recognize(FileAccess *p_f) { ///////////////////// -RES ResourceFormatLoaderText::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) { +RES ResourceFormatLoaderText::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_cache_mode) { if (r_error) { *r_error = ERR_CANT_OPEN; } @@ -1254,7 +1269,7 @@ RES ResourceFormatLoaderText::load(const String &p_path, const String &p_origina ResourceLoaderText loader; String path = p_original_path != "" ? p_original_path : p_path; - loader.use_nocache = p_no_cache; + loader.cache_mode = p_cache_mode; loader.use_sub_threads = p_use_sub_threads; loader.local_path = ProjectSettings::get_singleton()->localize_path(path); loader.progress = r_progress; diff --git a/scene/resources/resource_format_text.h b/scene/resources/resource_format_text.h index 3fc7814fe5..2dc683415d 100644 --- a/scene/resources/resource_format_text.h +++ b/scene/resources/resource_format_text.h @@ -69,7 +69,7 @@ class ResourceLoaderText { VariantParser::Tag next_tag; - bool use_nocache = false; + ResourceFormatLoader::CacheMode cache_mode = ResourceFormatLoader::CACHE_MODE_REUSE; bool use_sub_threads = false; float *progress = nullptr; @@ -134,7 +134,7 @@ public: class ResourceFormatLoaderText : public ResourceFormatLoader { public: static ResourceFormatLoaderText *singleton; - virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, bool p_no_cache = false); + virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, CacheMode p_cache_mode = CACHE_MODE_REUSE); virtual void get_recognized_extensions_for_type(const String &p_type, List<String> *p_extensions) const; virtual void get_recognized_extensions(List<String> *p_extensions) const; virtual bool handles_type(const String &p_type) const; diff --git a/scene/resources/shader.cpp b/scene/resources/shader.cpp index 49d5ac8340..77c6199794 100644 --- a/scene/resources/shader.cpp +++ b/scene/resources/shader.cpp @@ -161,7 +161,7 @@ Shader::~Shader() { //////////// -RES ResourceFormatLoaderShader::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) { +RES ResourceFormatLoaderShader::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_cache_mode) { if (r_error) { *r_error = ERR_FILE_CANT_OPEN; } diff --git a/scene/resources/shader.h b/scene/resources/shader.h index bb83d8a032..6563181ca2 100644 --- a/scene/resources/shader.h +++ b/scene/resources/shader.h @@ -102,7 +102,7 @@ VARIANT_ENUM_CAST(Shader::Mode); class ResourceFormatLoaderShader : public ResourceFormatLoader { public: - virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, bool p_no_cache = false); + virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, CacheMode p_cache_mode = CACHE_MODE_REUSE); virtual void get_recognized_extensions(List<String> *p_extensions) const; virtual bool handles_type(const String &p_type) const; virtual String get_resource_type(const String &p_path) const; diff --git a/scene/resources/skin.cpp b/scene/resources/skin.cpp index 56c1dab4be..fee8fdbde2 100644 --- a/scene/resources/skin.cpp +++ b/scene/resources/skin.cpp @@ -81,6 +81,10 @@ void Skin::clear_binds() { emit_changed(); } +void Skin::reset_state() { + clear_binds(); +} + bool Skin::_set(const StringName &p_name, const Variant &p_value) { String name = p_name; if (name == "bind_count") { diff --git a/scene/resources/skin.h b/scene/resources/skin.h index d5f5e2085b..f5d64f96aa 100644 --- a/scene/resources/skin.h +++ b/scene/resources/skin.h @@ -52,6 +52,7 @@ protected: bool _get(const StringName &p_name, Variant &r_ret) const; void _get_property_list(List<PropertyInfo> *p_list) const; + virtual void reset_state() override; static void _bind_methods(); public: diff --git a/scene/resources/texture.cpp b/scene/resources/texture.cpp index 1ecc968176..8cccf81659 100644 --- a/scene/resources/texture.cpp +++ b/scene/resources/texture.cpp @@ -736,7 +736,7 @@ StreamTexture2D::~StreamTexture2D() { } } -RES ResourceFormatLoaderStreamTexture2D::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) { +RES ResourceFormatLoaderStreamTexture2D::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_cache_mode) { Ref<StreamTexture2D> st; st.instance(); Error err = st->load(p_path); @@ -1034,7 +1034,7 @@ StreamTexture3D::~StreamTexture3D() { ///////////////////////////// -RES ResourceFormatLoaderStreamTexture3D::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) { +RES ResourceFormatLoaderStreamTexture3D::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_cache_mode) { Ref<StreamTexture3D> st; st.instance(); Error err = st->load(p_path); @@ -2432,7 +2432,7 @@ StreamTextureLayered::~StreamTextureLayered() { ///////////////////////////////////////////////// -RES ResourceFormatLoaderStreamTextureLayered::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) { +RES ResourceFormatLoaderStreamTextureLayered::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_cache_mode) { Ref<StreamTextureLayered> st; if (p_path.get_extension().to_lower() == "stexarray") { Ref<StreamTexture2DArray> s; diff --git a/scene/resources/texture.h b/scene/resources/texture.h index ce2cf44530..a0d917fd86 100644 --- a/scene/resources/texture.h +++ b/scene/resources/texture.h @@ -211,7 +211,7 @@ public: class ResourceFormatLoaderStreamTexture2D : public ResourceFormatLoader { public: - virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, bool p_no_cache = false); + virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, CacheMode p_cache_mode = CACHE_MODE_REUSE); virtual void get_recognized_extensions(List<String> *p_extensions) const; virtual bool handles_type(const String &p_type) const; virtual String get_resource_type(const String &p_path) const; @@ -513,7 +513,7 @@ public: class ResourceFormatLoaderStreamTextureLayered : public ResourceFormatLoader { public: - virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, bool p_no_cache = false); + virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, CacheMode p_cache_mode = CACHE_MODE_REUSE); virtual void get_recognized_extensions(List<String> *p_extensions) const; virtual bool handles_type(const String &p_type) const; virtual String get_resource_type(const String &p_path) const; @@ -631,7 +631,7 @@ public: class ResourceFormatLoaderStreamTexture3D : public ResourceFormatLoader { public: - virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, bool p_no_cache = false); + virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, CacheMode p_cache_mode = CACHE_MODE_REUSE); virtual void get_recognized_extensions(List<String> *p_extensions) const; virtual bool handles_type(const String &p_type) const; virtual String get_resource_type(const String &p_path) const; diff --git a/scene/resources/theme.cpp b/scene/resources/theme.cpp index a6e261000f..0405ea98bb 100644 --- a/scene/resources/theme.cpp +++ b/scene/resources/theme.cpp @@ -930,6 +930,9 @@ void Theme::get_type_list(List<StringName> *p_list) const { } } +void Theme::reset_state() { + clear(); +} void Theme::_bind_methods() { ClassDB::bind_method(D_METHOD("set_icon", "name", "node_type", "texture"), &Theme::set_icon); ClassDB::bind_method(D_METHOD("get_icon", "name", "node_type"), &Theme::get_icon); diff --git a/scene/resources/theme.h b/scene/resources/theme.h index c802ba2536..35481126ea 100644 --- a/scene/resources/theme.h +++ b/scene/resources/theme.h @@ -80,6 +80,8 @@ protected: static void _bind_methods(); + virtual void reset_state() override; + public: static Ref<Theme> get_default(); static void set_default(const Ref<Theme> &p_default); diff --git a/scene/resources/tile_set.cpp b/scene/resources/tile_set.cpp index 406137b387..84be69d0d6 100644 --- a/scene/resources/tile_set.cpp +++ b/scene/resources/tile_set.cpp @@ -1076,6 +1076,10 @@ int TileSet::find_tile_by_name(const String &p_name) const { return -1; } +void TileSet::reset_state() { + clear(); +} + void TileSet::clear() { tile_map.clear(); notify_property_list_changed(); diff --git a/scene/resources/tile_set.h b/scene/resources/tile_set.h index 210520350f..0a8721f35b 100644 --- a/scene/resources/tile_set.h +++ b/scene/resources/tile_set.h @@ -136,6 +136,8 @@ protected: static void _bind_methods(); + virtual void reset_state() override; + public: void create_tile(int p_id); diff --git a/scene/resources/visual_shader.cpp b/scene/resources/visual_shader.cpp index 73fd01fb00..219cd84aa0 100644 --- a/scene/resources/visual_shader.cpp +++ b/scene/resources/visual_shader.cpp @@ -1095,6 +1095,12 @@ bool VisualShader::_get(const StringName &p_name, Variant &r_ret) const { return false; } +void VisualShader::reset_state() { +#ifndef _MSC_VER +#warning everything needs to be cleared here +#endif + emit_changed(); +} void VisualShader::_get_property_list(List<PropertyInfo> *p_list) const { //mode p_list->push_back(PropertyInfo(Variant::INT, "mode", PROPERTY_HINT_ENUM, "Node3D,CanvasItem,Particles,Sky")); diff --git a/scene/resources/visual_shader.h b/scene/resources/visual_shader.h index 57732cc7e3..f3f3caf15e 100644 --- a/scene/resources/visual_shader.h +++ b/scene/resources/visual_shader.h @@ -126,6 +126,8 @@ protected: bool _get(const StringName &p_name, Variant &r_ret) const; void _get_property_list(List<PropertyInfo> *p_list) const; + virtual void reset_state() override; + public: // internal methods void set_shader_type(Type p_type); Type get_shader_type() const; diff --git a/servers/physics_3d/collision_solver_3d_sat.cpp b/servers/physics_3d/collision_solver_3d_sat.cpp index 2a31cf1c22..f507cacdc3 100644 --- a/servers/physics_3d/collision_solver_3d_sat.cpp +++ b/servers/physics_3d/collision_solver_3d_sat.cpp @@ -35,7 +35,7 @@ #define fallback_collision_solver gjk_epa_calculate_penetration -// Cylinder SAT analytic methods for Cylinder-trimesh and Cylinder-box are based on ODE colliders. +// Cylinder SAT analytic methods and face-circle contact points for cylinder-trimesh and cylinder-box collision are based on ODE colliders. /* * Cylinder-trimesh and Cylinder-box colliders by Alen Ladavac @@ -119,28 +119,9 @@ static void _generate_contacts_point_circle(const Vector3 *p_points_A, int p_poi ERR_FAIL_COND(p_point_count_B != 3); #endif - const Vector3 &point_A = p_points_A[0]; - - const Vector3 &circle_B_pos = p_points_B[0]; - Vector3 circle_B_line_1 = p_points_B[1] - circle_B_pos; - Vector3 circle_B_line_2 = p_points_B[2] - circle_B_pos; - - real_t circle_B_radius = circle_B_line_1.length(); - Vector3 circle_B_normal = circle_B_line_1.cross(circle_B_line_2).normalized(); - - // Project point onto Circle B plane. - Plane circle_plane(circle_B_pos, circle_B_normal); - Vector3 proj_point_A = circle_plane.project(point_A); - - // Clip point. - Vector3 delta_point_1 = proj_point_A - circle_B_pos; - real_t dist_point_1 = delta_point_1.length_squared(); - if (!Math::is_zero_approx(dist_point_1)) { - dist_point_1 = Math::sqrt(dist_point_1); - proj_point_A = circle_B_pos + delta_point_1 * MIN(dist_point_1, circle_B_radius) / dist_point_1; - } + Vector3 closest_B = Plane(p_points_B[0], p_points_B[1], p_points_B[2]).project(*p_points_A); - p_callback->call(point_A, proj_point_A); + p_callback->call(*p_points_A, closest_B); } static void _generate_contacts_edge_edge(const Vector3 *p_points_A, int p_point_count_A, const Vector3 *p_points_B, int p_point_count_B, _CollectorCallback *p_callback) { @@ -189,6 +170,104 @@ static void _generate_contacts_edge_edge(const Vector3 *p_points_A, int p_point_ p_callback->call(closest_A, closest_B); } +static void _generate_contacts_edge_circle(const Vector3 *p_points_A, int p_point_count_A, const Vector3 *p_points_B, int p_point_count_B, _CollectorCallback *p_callback) { +#ifdef DEBUG_ENABLED + ERR_FAIL_COND(p_point_count_A != 2); + ERR_FAIL_COND(p_point_count_B != 3); +#endif + + const Vector3 &circle_B_pos = p_points_B[0]; + Vector3 circle_B_line_1 = p_points_B[1] - circle_B_pos; + Vector3 circle_B_line_2 = p_points_B[2] - circle_B_pos; + + real_t circle_B_radius = circle_B_line_1.length(); + Vector3 circle_B_normal = circle_B_line_1.cross(circle_B_line_2).normalized(); + + Plane circle_plane(circle_B_pos, circle_B_normal); + + static const int max_clip = 2; + Vector3 contact_points[max_clip]; + int num_points = 0; + + // Project edge point in circle plane. + const Vector3 &edge_A_1 = p_points_A[0]; + Vector3 proj_point_1 = circle_plane.project(edge_A_1); + + Vector3 dist_vec = proj_point_1 - circle_B_pos; + real_t dist_sq = dist_vec.length_squared(); + + // Point 1 is inside disk, add as contact point. + if (dist_sq <= circle_B_radius * circle_B_radius) { + contact_points[num_points] = edge_A_1; + ++num_points; + } + + const Vector3 &edge_A_2 = p_points_A[1]; + Vector3 proj_point_2 = circle_plane.project(edge_A_2); + + Vector3 dist_vec_2 = proj_point_2 - circle_B_pos; + real_t dist_sq_2 = dist_vec_2.length_squared(); + + // Point 2 is inside disk, add as contact point. + if (dist_sq_2 <= circle_B_radius * circle_B_radius) { + contact_points[num_points] = edge_A_2; + ++num_points; + } + + if (num_points < 2) { + Vector3 line_vec = proj_point_2 - proj_point_1; + real_t line_length_sq = line_vec.length_squared(); + + // Create a quadratic formula of the form ax^2 + bx + c = 0 + real_t a, b, c; + + a = line_length_sq; + b = 2.0 * dist_vec.dot(line_vec); + c = dist_sq - circle_B_radius * circle_B_radius; + + // Solve for t. + real_t sqrtterm = b * b - 4.0 * a * c; + + // If the term we intend to square root is less than 0 then the answer won't be real, + // so the line doesn't intersect. + if (sqrtterm >= 0) { + sqrtterm = Math::sqrt(sqrtterm); + + Vector3 edge_dir = edge_A_2 - edge_A_1; + + real_t fraction_1 = (-b - sqrtterm) / (2.0 * a); + if ((fraction_1 > 0.0) && (fraction_1 < 1.0)) { + Vector3 face_point_1 = edge_A_1 + fraction_1 * edge_dir; + ERR_FAIL_COND(num_points >= max_clip); + contact_points[num_points] = face_point_1; + ++num_points; + } + + real_t fraction_2 = (-b + sqrtterm) / (2.0 * a); + if ((fraction_2 > 0.0) && (fraction_2 < 1.0) && !Math::is_equal_approx(fraction_1, fraction_2)) { + Vector3 face_point_2 = edge_A_1 + fraction_2 * edge_dir; + ERR_FAIL_COND(num_points >= max_clip); + contact_points[num_points] = face_point_2; + ++num_points; + } + } + } + + // Generate contact points. + for (int i = 0; i < num_points; i++) { + const Vector3 &contact_point_A = contact_points[i]; + + real_t d = circle_plane.distance_to(contact_point_A); + Vector3 closest_B = contact_point_A - circle_plane.normal * d; + + if (p_callback->normal.dot(contact_point_A) >= p_callback->normal.dot(closest_B)) { + continue; + } + + p_callback->call(contact_point_A, closest_B); + } +} + static void _generate_contacts_face_face(const Vector3 *p_points_A, int p_point_count_A, const Vector3 *p_points_B, int p_point_count_B, _CollectorCallback *p_callback) { #ifdef DEBUG_ENABLED ERR_FAIL_COND(p_point_count_A < 2); @@ -280,7 +359,7 @@ static void _generate_contacts_face_face(const Vector3 *p_points_A, int p_point_ static void _generate_contacts_face_circle(const Vector3 *p_points_A, int p_point_count_A, const Vector3 *p_points_B, int p_point_count_B, _CollectorCallback *p_callback) { #ifdef DEBUG_ENABLED - ERR_FAIL_COND(p_point_count_A < 2); + ERR_FAIL_COND(p_point_count_A < 3); ERR_FAIL_COND(p_point_count_B != 3); #endif @@ -288,150 +367,60 @@ static void _generate_contacts_face_circle(const Vector3 *p_points_A, int p_poin Vector3 circle_B_line_1 = p_points_B[1] - circle_B_pos; Vector3 circle_B_line_2 = p_points_B[2] - circle_B_pos; - real_t circle_B_radius = circle_B_line_1.length(); + // Clip face with circle segments. + static const int circle_segments = 8; + Vector3 circle_points[circle_segments]; + + real_t angle_delta = 2.0 * Math_PI / circle_segments; + + for (int i = 0; i < circle_segments; ++i) { + Vector3 point_pos = circle_B_pos; + point_pos += circle_B_line_1 * Math::cos(i * angle_delta); + point_pos += circle_B_line_2 * Math::sin(i * angle_delta); + circle_points[i] = point_pos; + } + + _generate_contacts_face_face(p_points_A, p_point_count_A, circle_points, circle_segments, p_callback); + + // Clip face with circle plane. Vector3 circle_B_normal = circle_B_line_1.cross(circle_B_line_2).normalized(); Plane circle_plane(circle_B_pos, circle_B_normal); - bool edge = (p_point_count_A == 2); - static const int max_clip = 32; Vector3 contact_points[max_clip]; int num_points = 0; - // Clip edges with circle. for (int i = 0; i < p_point_count_A; i++) { int i_n = (i + 1) % p_point_count_A; - // Project edge point in circle plane. - const Vector3 &edge_A_1 = p_points_A[i]; - Vector3 proj_point_1 = circle_plane.project(edge_A_1); + const Vector3 &edge0_A = p_points_A[i]; + const Vector3 &edge1_A = p_points_A[i_n]; - Vector3 dist_vec = proj_point_1 - circle_B_pos; - real_t dist_sq = dist_vec.length_squared(); + real_t dist0 = circle_plane.distance_to(edge0_A); + real_t dist1 = circle_plane.distance_to(edge1_A); - // Point 1 is inside disk, add as contact point. - if (dist_sq <= circle_B_radius * circle_B_radius) { - //p_callback->call(edge_A_1, proj_point_1); + // First point in front of plane, generate contact point. + if (dist0 * circle_plane.d >= 0) { ERR_FAIL_COND(num_points >= max_clip); - contact_points[num_points] = edge_A_1; + contact_points[num_points] = edge0_A; ++num_points; } - // No need to test point 2 now, as it will be part of the next edge. - - if (edge && i > 0) { - // Done with testing the only two points. - break; - } - // Project edge point in circle plane. - const Vector3 &edge_A_2 = p_points_A[i_n]; - Vector3 proj_point_2 = circle_plane.project(edge_A_2); + // Points on different sides, generate contact point. + if (dist0 * dist1 < 0) { + // calculate intersection + Vector3 rel = edge1_A - edge0_A; + real_t den = circle_plane.normal.dot(rel); + real_t dist = -(circle_plane.normal.dot(edge0_A) - circle_plane.d) / den; + Vector3 inters = edge0_A + rel * dist; - Vector3 line_vec = proj_point_2 - proj_point_1; - real_t line_length_sq = line_vec.length_squared(); - - // Create a quadratic formula of the form ax^2 + bx + c = 0 - real_t a, b, c; - - a = line_length_sq; - b = 2.0 * dist_vec.dot(line_vec); - c = dist_sq - circle_B_radius * circle_B_radius; - - // Solve for t. - real_t sqrtterm = b * b - 4.0 * a * c; - - // If the term we intend to square root is less than 0 then the answer won't be real, - // so the line doesn't intersect. - if (sqrtterm < 0) { - continue; - } - - sqrtterm = Math::sqrt(sqrtterm); - - Vector3 edge_dir = edge_A_2 - edge_A_1; - - real_t fraction_1 = (-b - sqrtterm) / (2.0 * a); - if ((fraction_1 > 0.0) && (fraction_1 < 1.0)) { - //Vector3 intersection_1 = proj_point_1 + fraction_1 * line_vec; - Vector3 face_point_1 = edge_A_1 + fraction_1 * edge_dir; - //p_callback->call(face_point_1, intersection_1); - ERR_FAIL_COND(num_points >= max_clip); - contact_points[num_points] = face_point_1; - ++num_points; - } - - real_t fraction_2 = (-b + sqrtterm) / (2.0 * a); - if ((fraction_2 > 0.0) && (fraction_2 < 1.0) && !Math::is_equal_approx(fraction_1, fraction_2)) { - //Vector3 intersection_2 = proj_point_1 + fraction_2 * line_vec; - Vector3 face_point_2 = edge_A_1 + fraction_2 * edge_dir; - //p_callback->call(face_point_2, intersection_2); ERR_FAIL_COND(num_points >= max_clip); - contact_points[num_points] = face_point_2; + contact_points[num_points] = inters; ++num_points; } } - // In case of a face, add extra contact points for proper support. - if (!edge) { - Plane plane_A(p_points_A[0], p_points_A[1], p_points_A[2]); - - if (num_points < 3) { - if (num_points == 0) { - // Use 3 arbitrary equidistant points from the circle. - for (int i = 0; i < 3; ++i) { - Vector3 circle_point = circle_B_pos; - circle_point += circle_B_line_1 * Math::cos(2.0 * Math_PI * i / 3.0); - circle_point += circle_B_line_2 * Math::sin(2.0 * Math_PI * i / 3.0); - - Vector3 face_point = plane_A.project(circle_point); - - contact_points[num_points] = face_point; - ++num_points; - } - } else if (num_points == 1) { - Vector3 line_center = circle_B_pos - contact_points[0]; - Vector3 line_tangent = line_center.cross(plane_A.normal); - - Vector3 dir = line_tangent.cross(plane_A.normal).normalized(); - if (line_center.dot(dir) > 0.0) { - // Use 2 equidistant points on the circle inside the face. - line_center.normalize(); - line_tangent.normalize(); - for (int i = 0; i < 2; ++i) { - Vector3 circle_point = circle_B_pos; - circle_point -= line_center * circle_B_radius * Math::cos(2.0 * Math_PI * (i + 1) / 3.0); - circle_point += line_tangent * circle_B_radius * Math::sin(2.0 * Math_PI * (i + 1) / 3.0); - - Vector3 face_point = plane_A.project(circle_point); - - contact_points[num_points] = face_point; - ++num_points; - } - } - // Otherwise the circle touches an edge from the outside, no extra contact point. - } else { // if (num_points == 2) - // Use equidistant 3rd point on the circle inside the face. - Vector3 contacts_line = contact_points[1] - contact_points[0]; - Vector3 dir = contacts_line.cross(plane_A.normal).normalized(); - - Vector3 circle_point = contact_points[0] + 0.5 * contacts_line; - Vector3 line_center = (circle_B_pos - circle_point); - - if (line_center.dot(dir) > 0.0) { - circle_point += dir * (line_center.length() + circle_B_radius); - } else { - circle_point += dir * (circle_B_radius - line_center.length()); - } - - Vector3 face_point = plane_A.project(circle_point); - - contact_points[num_points] = face_point; - ++num_points; - } - } - } - // Generate contact points. for (int i = 0; i < num_points; i++) { const Vector3 &contact_point_A = contact_points[i]; @@ -567,7 +556,7 @@ static void _generate_contacts_from_supports(const Vector3 *p_points_A, int p_po nullptr, _generate_contacts_edge_edge, _generate_contacts_face_face, - _generate_contacts_face_circle, + _generate_contacts_edge_circle, }, { nullptr, diff --git a/servers/rendering/renderer_rd/shaders/skeleton.glsl b/servers/rendering/renderer_rd/shaders/skeleton.glsl index b19f5a9ad3..d675e548d7 100644 --- a/servers/rendering/renderer_rd/shaders/skeleton.glsl +++ b/servers/rendering/renderer_rd/shaders/skeleton.glsl @@ -100,7 +100,7 @@ void main() { for (uint i = 0; i < params.blend_shape_count; i++) { float w = blend_shape_weights.data[i]; - if (w > 0.0001) { + if ((w < 0.0001) || (w > 0.0001)) { uint base_offset = (params.vertex_count * i + index) * params.vertex_stride; blend_vertex += uintBitsToFloat(uvec3(src_blend_shapes.data[base_offset + 0], src_blend_shapes.data[base_offset + 1], src_blend_shapes.data[base_offset + 2])) * w; |