Ported: Fix custom res caching sub-res even if no-cache

-Razoric480
2ceb93bbef
This commit is contained in:
Relintai 2023-08-30 12:55:37 +02:00
parent c95765d515
commit 5d93975c8d
51 changed files with 116 additions and 78 deletions

View File

@ -65,8 +65,8 @@ static const unsigned int MONTH_DAYS_TABLE[2][12] = {
_ResourceLoader *_ResourceLoader::singleton = nullptr; _ResourceLoader *_ResourceLoader::singleton = nullptr;
Ref<ResourceInteractiveLoader> _ResourceLoader::load_interactive(const String &p_path, const String &p_type_hint) { Ref<ResourceInteractiveLoader> _ResourceLoader::load_interactive(const String &p_path, const String &p_type_hint, bool p_no_cache) {
return ResourceLoader::load_interactive(p_path, p_type_hint); return ResourceLoader::load_interactive(p_path, p_type_hint, p_no_cache);
} }
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, bool p_no_cache) {
@ -121,7 +121,7 @@ bool _ResourceLoader::exists(const String &p_path, const String &p_type_hint) {
} }
void _ResourceLoader::_bind_methods() { void _ResourceLoader::_bind_methods() {
ClassDB::bind_method(D_METHOD("load_interactive", "path", "type_hint"), &_ResourceLoader::load_interactive, DEFVAL("")); ClassDB::bind_method(D_METHOD("load_interactive", "path", "type_hint", "no_cache"), &_ResourceLoader::load_interactive, DEFVAL(""), DEFVAL(false));
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(false));
ClassDB::bind_method(D_METHOD("get_recognized_extensions_for_type", "type"), &_ResourceLoader::get_recognized_extensions_for_type); 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("set_abort_on_missing_resources", "abort"), &_ResourceLoader::set_abort_on_missing_resources);

View File

@ -52,7 +52,7 @@ protected:
public: public:
static _ResourceLoader *get_singleton() { return singleton; } static _ResourceLoader *get_singleton() { return singleton; }
Ref<ResourceInteractiveLoader> load_interactive(const String &p_path, const String &p_type_hint = ""); Ref<ResourceInteractiveLoader> load_interactive(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 = "", bool p_no_cache = false); RES load(const String &p_path, const String &p_type_hint = "", bool p_no_cache = false);
PoolVector<String> get_recognized_extensions_for_type(const String &p_type); PoolVector<String> get_recognized_extensions_for_type(const String &p_type);
void set_abort_on_missing_resources(bool p_abort); void set_abort_on_missing_resources(bool p_abort);

View File

@ -144,7 +144,7 @@ Crypto::Crypto() {
/// Resource loader/saver /// Resource loader/saver
RES ResourceFormatLoaderCrypto::load(const String &p_path, const String &p_original_path, Error *r_error) { RES ResourceFormatLoaderCrypto::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_no_subresource_cache) {
String el = p_path.get_extension().to_lower(); String el = p_path.get_extension().to_lower();
if (el == "crt") { if (el == "crt") {
X509Certificate *cert = X509Certificate::create(); X509Certificate *cert = X509Certificate::create();

View File

@ -117,7 +117,7 @@ public:
class ResourceFormatLoaderCrypto : public ResourceFormatLoader { class ResourceFormatLoaderCrypto : public ResourceFormatLoader {
public: public:
virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr); virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_no_subresource_cache = false);
virtual void get_recognized_extensions(List<String> *p_extensions) const; virtual void get_recognized_extensions(List<String> *p_extensions) const;
virtual bool handles_type(const String &p_type) const; virtual bool handles_type(const String &p_type) const;
virtual String get_resource_type(const String &p_path) const; virtual String get_resource_type(const String &p_path) const;

View File

@ -122,7 +122,7 @@ void ImageLoader::cleanup() {
///////////////// /////////////////
RES ResourceFormatLoaderImage::load(const String &p_path, const String &p_original_path, Error *r_error) { RES ResourceFormatLoaderImage::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_no_subresource_cache) {
FileAccess *f = FileAccess::open(p_path, FileAccess::READ); FileAccess *f = FileAccess::open(p_path, FileAccess::READ);
if (!f) { if (!f) {
if (r_error) { if (r_error) {

View File

@ -71,7 +71,7 @@ public:
class ResourceFormatLoaderImage : public ResourceFormatLoader { class ResourceFormatLoaderImage : public ResourceFormatLoader {
public: public:
virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr); virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_no_subresource_cache = false);
virtual void get_recognized_extensions(List<String> *p_extensions) const; virtual void get_recognized_extensions(List<String> *p_extensions) const;
virtual bool handles_type(const String &p_type) const; virtual bool handles_type(const String &p_type) const;
virtual String get_resource_type(const String &p_path) const; virtual String get_resource_type(const String &p_path) const;

View File

@ -350,7 +350,15 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) {
case OBJECT_INTERNAL_RESOURCE: { case OBJECT_INTERNAL_RESOURCE: {
uint32_t index = f->get_32(); uint32_t index = f->get_32();
String path = res_path + "::" + itos(index); String path = res_path + "::" + itos(index);
RES res = ResourceLoader::load(path);
RES res;
if (internal_resources_cache.has(index)) {
res = internal_resources_cache[index];
} else {
res = ResourceLoader::load(path, "", no_subresource_cache);
internal_resources_cache[index] = res;
}
if (res.is_null()) { if (res.is_null()) {
WARN_PRINT(String("Couldn't load resource: " + path).utf8().get_data()); WARN_PRINT(String("Couldn't load resource: " + path).utf8().get_data());
} }
@ -372,7 +380,7 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) {
path = remaps[path]; path = remaps[path];
} }
RES res = ResourceLoader::load(path, exttype); RES res = ResourceLoader::load(path, exttype, no_subresource_cache);
if (res.is_null()) { if (res.is_null()) {
WARN_PRINT(String("Couldn't load resource: " + path).utf8().get_data()); WARN_PRINT(String("Couldn't load resource: " + path).utf8().get_data());
@ -406,7 +414,7 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) {
} }
if (res.is_null()) { if (res.is_null()) {
res = ResourceLoader::load(path, exttype); res = ResourceLoader::load(path, exttype, no_subresource_cache);
} }
if (res.is_null()) { if (res.is_null()) {
@ -716,7 +724,7 @@ Error ResourceInteractiveLoaderBinary::poll() {
if (remaps.has(path)) { if (remaps.has(path)) {
path = remaps[path]; path = remaps[path];
} }
RES res = ResourceLoader::load(path, external_resources[s].type); RES res = ResourceLoader::load(path, external_resources[s].type, no_subresource_cache);
if (res.is_null()) { if (res.is_null()) {
if (!ResourceLoader::get_abort_on_missing_resources()) { if (!ResourceLoader::get_abort_on_missing_resources()) {
ResourceLoader::notify_dependency_error(local_path, path, external_resources[s].type); ResourceLoader::notify_dependency_error(local_path, path, external_resources[s].type);
@ -754,7 +762,7 @@ Error ResourceInteractiveLoaderBinary::poll() {
path = res_path + "::" + path; path = res_path + "::" + path;
} }
if (ResourceCache::has(path)) { if (!no_subresource_cache && ResourceCache::has(path)) {
//already loaded, don't do anything //already loaded, don't do anything
stage++; stage++;
error = OK; error = OK;
@ -788,7 +796,9 @@ Error ResourceInteractiveLoaderBinary::poll() {
RES res = RES(r); RES res = RES(r);
r->set_path(path); if (!no_subresource_cache) {
r->set_path(path);
}
r->set_subindex(subindex); r->set_subindex(subindex);
int pc = f->get_32(); int pc = f->get_32();
@ -1042,7 +1052,7 @@ ResourceInteractiveLoaderBinary::~ResourceInteractiveLoaderBinary() {
} }
} }
Ref<ResourceInteractiveLoader> ResourceFormatLoaderBinary::load_interactive(const String &p_path, const String &p_original_path, Error *r_error) { Ref<ResourceInteractiveLoader> ResourceFormatLoaderBinary::load_interactive(const String &p_path, const String &p_original_path, Error *r_error, bool p_no_subresource_cache) {
if (r_error) { if (r_error) {
*r_error = ERR_FILE_CANT_OPEN; *r_error = ERR_FILE_CANT_OPEN;
} }
@ -1053,6 +1063,7 @@ Ref<ResourceInteractiveLoader> ResourceFormatLoaderBinary::load_interactive(cons
ERR_FAIL_COND_V_MSG(err != OK, Ref<ResourceInteractiveLoader>(), "Cannot open file '" + p_path + "'."); ERR_FAIL_COND_V_MSG(err != OK, Ref<ResourceInteractiveLoader>(), "Cannot open file '" + p_path + "'.");
Ref<ResourceInteractiveLoaderBinary> ria = memnew(ResourceInteractiveLoaderBinary); Ref<ResourceInteractiveLoaderBinary> ria = memnew(ResourceInteractiveLoaderBinary);
ria->set_no_subresource_cache(p_no_subresource_cache);
String path = p_original_path != "" ? p_original_path : p_path; String path = p_original_path != "" ? p_original_path : p_path;
ria->local_path = ProjectSettings::get_singleton()->localize_path(path); ria->local_path = ProjectSettings::get_singleton()->localize_path(path);
ria->res_path = ria->local_path; ria->res_path = ria->local_path;

View File

@ -67,6 +67,7 @@ class ResourceInteractiveLoaderBinary : public ResourceInteractiveLoader {
}; };
Vector<IntResource> internal_resources; Vector<IntResource> internal_resources;
RBMap<uint32_t, RES> internal_resources_cache;
String get_unicode_string(); String get_unicode_string();
void _advance_padding(uint32_t p_len); void _advance_padding(uint32_t p_len);
@ -99,7 +100,7 @@ public:
class ResourceFormatLoaderBinary : public ResourceFormatLoader { class ResourceFormatLoaderBinary : public ResourceFormatLoader {
public: public:
virtual Ref<ResourceInteractiveLoader> load_interactive(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr); virtual Ref<ResourceInteractiveLoader> load_interactive(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_no_subresource_cache = false);
virtual void get_recognized_extensions_for_type(const String &p_type, List<String> *p_extensions) const; 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 void get_recognized_extensions(List<String> *p_extensions) const;
virtual bool handles_type(const String &p_type) const; virtual bool handles_type(const String &p_type) const;

View File

@ -116,7 +116,7 @@ Error ResourceFormatImporter::_get_path_and_type(const String &p_path, PathAndTy
return OK; return OK;
} }
RES ResourceFormatImporter::load(const String &p_path, const String &p_original_path, Error *r_error) { RES ResourceFormatImporter::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_no_subresource_cache) {
PathAndType pat; PathAndType pat;
Error err = _get_path_and_type(p_path, 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(); return RES();
} }
RES res = ResourceLoader::_load(pat.path, p_path, pat.type, false, r_error); RES res = ResourceLoader::_load(pat.path, p_path, pat.type, p_no_subresource_cache, r_error);
#ifdef TOOLS_ENABLED #ifdef TOOLS_ENABLED
if (res.is_valid()) { if (res.is_valid()) {

View File

@ -56,7 +56,7 @@ class ResourceFormatImporter : public ResourceFormatLoader {
public: public:
static ResourceFormatImporter *get_singleton() { return singleton; } static ResourceFormatImporter *get_singleton() { return singleton; }
virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr); virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_no_subresource_cache = false);
virtual void get_recognized_extensions(List<String> *p_extensions) 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; 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; virtual bool recognize_path(const String &p_path, const String &p_for_type = String()) const;

View File

@ -30,11 +30,11 @@
#include "resource_loader.h" #include "resource_loader.h"
#include "core/config/project_settings.h"
#include "core/io/resource_importer.h" #include "core/io/resource_importer.h"
#include "core/os/file_access.h" #include "core/os/file_access.h"
#include "core/os/os.h" #include "core/os/os.h"
#include "core/string/print_string.h" #include "core/string/print_string.h"
#include "core/config/project_settings.h"
#include "core/string/translation.h" #include "core/string/translation.h"
#include "core/variant/variant_parser.h" #include "core/variant/variant_parser.h"
@ -51,6 +51,14 @@ Error ResourceInteractiveLoader::wait() {
return err; return err;
} }
void ResourceInteractiveLoader::set_no_subresource_cache(bool p_no_subresource_cache) {
no_subresource_cache = p_no_subresource_cache;
}
bool ResourceInteractiveLoader::get_no_subresource_cache() {
return no_subresource_cache;
}
ResourceInteractiveLoader::~ResourceInteractiveLoader() { ResourceInteractiveLoader::~ResourceInteractiveLoader() {
if (path_loading != String()) { if (path_loading != String()) {
ResourceLoader::_remove_from_loading_map_and_thread(path_loading, path_loading_thread); ResourceLoader::_remove_from_loading_map_and_thread(path_loading, path_loading_thread);
@ -111,6 +119,10 @@ void ResourceInteractiveLoader::_bind_methods() {
ClassDB::bind_method(D_METHOD("wait"), &ResourceInteractiveLoader::wait); ClassDB::bind_method(D_METHOD("wait"), &ResourceInteractiveLoader::wait);
ClassDB::bind_method(D_METHOD("get_stage"), &ResourceInteractiveLoader::get_stage); ClassDB::bind_method(D_METHOD("get_stage"), &ResourceInteractiveLoader::get_stage);
ClassDB::bind_method(D_METHOD("get_stage_count"), &ResourceInteractiveLoader::get_stage_count); ClassDB::bind_method(D_METHOD("get_stage_count"), &ResourceInteractiveLoader::get_stage_count);
ClassDB::bind_method(D_METHOD("set_no_subresource_cache", "no_subresource_cache"), &ResourceInteractiveLoader::set_no_subresource_cache);
ClassDB::bind_method(D_METHOD("get_no_subresource_cache"), &ResourceInteractiveLoader::get_no_subresource_cache);
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "no_subresource_cache"), "set_no_subresource_cache", "get_no_subresource_cache");
} }
class ResourceInteractiveLoaderDefault : public ResourceInteractiveLoader { class ResourceInteractiveLoaderDefault : public ResourceInteractiveLoader {
@ -151,22 +163,23 @@ void ResourceFormatLoader::get_recognized_extensions(List<String> *p_extensions)
// here can trigger an infinite recursion otherwise, since `load` calls `load_interactive` // here can trigger an infinite recursion otherwise, since `load` calls `load_interactive`
// vice versa. // vice versa.
Ref<ResourceInteractiveLoader> ResourceFormatLoader::load_interactive(const String &p_path, const String &p_original_path, Error *r_error) { Ref<ResourceInteractiveLoader> ResourceFormatLoader::load_interactive(const String &p_path, const String &p_original_path, Error *r_error, bool p_no_subresource_cache) {
// Warning: See previous note about the risk of infinite recursion. // Warning: See previous note about the risk of infinite recursion.
Ref<Resource> res = load(p_path, p_original_path, r_error); Ref<Resource> res = load(p_path, p_original_path, r_error, p_no_subresource_cache);
if (res.is_null()) { if (res.is_null()) {
return Ref<ResourceInteractiveLoader>(); return Ref<ResourceInteractiveLoader>();
} }
Ref<ResourceInteractiveLoaderDefault> ril = Ref<ResourceInteractiveLoaderDefault>(memnew(ResourceInteractiveLoaderDefault)); Ref<ResourceInteractiveLoaderDefault> ril = Ref<ResourceInteractiveLoaderDefault>(memnew(ResourceInteractiveLoaderDefault));
ril->set_no_subresource_cache(p_no_subresource_cache);
ril->resource = res; ril->resource = res;
return ril; return ril;
} }
RES ResourceFormatLoader::load(const String &p_path, const String &p_original_path, Error *r_error) { RES ResourceFormatLoader::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_no_subresource_cache) {
// Check user-defined loader if there's any. Hard fail if it returns an error. // Check user-defined loader if there's any. Hard fail if it returns an error.
if (get_script_instance() && get_script_instance()->has_method("load")) { if (get_script_instance() && get_script_instance()->has_method("load")) {
Variant res = get_script_instance()->call("load", p_path, p_original_path); Variant res = get_script_instance()->call("load", p_path, p_original_path, p_no_subresource_cache);
if (res.get_type() == Variant::INT) { // Error code, abort. if (res.get_type() == Variant::INT) { // Error code, abort.
if (r_error) { if (r_error) {
@ -182,7 +195,7 @@ RES ResourceFormatLoader::load(const String &p_path, const String &p_original_pa
} }
// Warning: See previous note about the risk of infinite recursion. // Warning: See previous note about the risk of infinite recursion.
Ref<ResourceInteractiveLoader> ril = load_interactive(p_path, p_original_path, r_error); Ref<ResourceInteractiveLoader> ril = load_interactive(p_path, p_original_path, r_error, p_no_subresource_cache);
if (!ril.is_valid()) { if (!ril.is_valid()) {
return RES(); return RES();
} }
@ -235,7 +248,7 @@ Error ResourceFormatLoader::rename_dependencies(const String &p_path, const RBMa
void ResourceFormatLoader::_bind_methods() { 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, "no_subresource_cache"));
info.return_val.usage |= PROPERTY_USAGE_NIL_IS_VARIANT; info.return_val.usage |= PROPERTY_USAGE_NIL_IS_VARIANT;
ClassDB::add_virtual_method(get_class_static(), info); ClassDB::add_virtual_method(get_class_static(), info);
} }
@ -258,7 +271,7 @@ RES ResourceLoader::_load(const String &p_path, const String &p_original_path, c
continue; continue;
} }
found = true; found = true;
RES res = loader[i]->load(p_path, p_original_path != String() ? p_original_path : p_path, r_error); RES res = loader[i]->load(p_path, p_original_path != String() ? p_original_path : p_path, r_error, p_no_cache);
if (res.is_null()) { if (res.is_null()) {
continue; continue;
} }
@ -483,7 +496,7 @@ Ref<ResourceInteractiveLoader> ResourceLoader::load_interactive(const String &p_
continue; continue;
} }
found = true; found = true;
Ref<ResourceInteractiveLoader> ril = loader[i]->load_interactive(path, local_path, r_error); Ref<ResourceInteractiveLoader> ril = loader[i]->load_interactive(path, local_path, r_error, p_no_cache);
if (ril.is_null()) { if (ril.is_null()) {
continue; continue;
} }

View File

@ -30,8 +30,8 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/ /*************************************************************************/
#include "core/os/thread.h"
#include "core/object/resource.h" #include "core/object/resource.h"
#include "core/os/thread.h"
class ResourceInteractiveLoader : public Reference { class ResourceInteractiveLoader : public Reference {
GDCLASS(ResourceInteractiveLoader, Reference); GDCLASS(ResourceInteractiveLoader, Reference);
@ -40,6 +40,8 @@ class ResourceInteractiveLoader : public Reference {
Thread::ID path_loading_thread; Thread::ID path_loading_thread;
protected: protected:
bool no_subresource_cache = false;
static void _bind_methods(); static void _bind_methods();
public: public:
@ -50,6 +52,8 @@ public:
virtual int get_stage_count() const = 0; virtual int get_stage_count() const = 0;
virtual void set_translation_remapped(bool p_remapped) = 0; virtual void set_translation_remapped(bool p_remapped) = 0;
virtual Error wait(); virtual Error wait();
virtual void set_no_subresource_cache(bool p_no_subresource_cache);
virtual bool get_no_subresource_cache();
ResourceInteractiveLoader() {} ResourceInteractiveLoader() {}
~ResourceInteractiveLoader(); ~ResourceInteractiveLoader();
@ -62,8 +66,8 @@ protected:
static void _bind_methods(); static void _bind_methods();
public: public:
virtual Ref<ResourceInteractiveLoader> load_interactive(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr); virtual Ref<ResourceInteractiveLoader> load_interactive(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_no_subresource_cache = false);
virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr); virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_no_subresource_cache = false);
virtual bool exists(const String &p_path) const; virtual bool exists(const String &p_path) const;
virtual void get_recognized_extensions(List<String> *p_extensions) 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; virtual void get_recognized_extensions_for_type(const String &p_type, List<String> *p_extensions) const;

View File

@ -189,7 +189,7 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error) {
return translation; return translation;
} }
RES TranslationLoaderPO::load(const String &p_path, const String &p_original_path, Error *r_error) { RES TranslationLoaderPO::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_no_subresource_cache) {
if (r_error) { if (r_error) {
*r_error = ERR_CANT_OPEN; *r_error = ERR_CANT_OPEN;
} }

View File

@ -37,7 +37,7 @@
class TranslationLoaderPO : public ResourceFormatLoader { class TranslationLoaderPO : public ResourceFormatLoader {
public: public:
static RES load_translation(FileAccess *f, Error *r_error = nullptr); 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); virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_no_subresource_cache = false);
virtual void get_recognized_extensions(List<String> *p_extensions) const; virtual void get_recognized_extensions(List<String> *p_extensions) const;
virtual bool handles_type(const String &p_type) const; virtual bool handles_type(const String &p_type) const;
virtual String get_resource_type(const String &p_path) const; virtual String get_resource_type(const String &p_path) const;

View File

@ -44,8 +44,9 @@
<return type="Variant" /> <return type="Variant" />
<argument index="0" name="path" type="String" /> <argument index="0" name="path" type="String" />
<argument index="1" name="original_path" type="String" /> <argument index="1" name="original_path" type="String" />
<argument index="2" name="no_subresource_cache" type="bool" />
<description> <description>
Loads a resource when the engine finds this loader to be compatible. If the loaded resource is the result of an import, [code]original_path[/code] will target the source file. Returns a [Resource] object on success, or an [enum Error] constant in case of failure. Loads a resource when the engine finds this loader to be compatible. If the loaded resource is the result of an import, [code]original_path[/code] will target the source file. If [code]no_subresource_cache[/code] is true, sub-resources should not be cached. Returns a [Resource] object on success, or an [enum Error] constant in case of failure.
</description> </description>
</method> </method>
<method name="rename_dependencies" qualifiers="virtual"> <method name="rename_dependencies" qualifiers="virtual">

View File

@ -45,6 +45,11 @@
</description> </description>
</method> </method>
</methods> </methods>
<members>
<member name="no_subresource_cache" type="bool" setter="set_no_subresource_cache" getter="get_no_subresource_cache">
Configures whether nested resources, if included, should not be cached.
</member>
</members>
<constants> <constants>
</constants> </constants>
</class> </class>

View File

@ -58,7 +58,7 @@
Loads a resource at the given [code]path[/code], caching the result for further access. Loads a resource at the given [code]path[/code], caching the result for further access.
The registered [ResourceFormatLoader]s are queried sequentially to find the first one which can handle the file's extension, and then attempt loading. If loading fails, the remaining ResourceFormatLoaders are also attempted. The registered [ResourceFormatLoader]s are queried sequentially to find the first one which can handle the file's extension, and then attempt loading. If loading fails, the remaining ResourceFormatLoaders are also attempted.
An optional [code]type_hint[/code] can be used to further specify the [Resource] type that should be handled by the [ResourceFormatLoader]. Anything that inherits from [Resource] can be used as a type hint, for example [Image]. An optional [code]type_hint[/code] can be used to further specify the [Resource] type that should be handled by the [ResourceFormatLoader]. Anything that inherits from [Resource] can be used as a type hint, for example [Image].
If [code]no_cache[/code] is [code]true[/code], the resource cache will be bypassed and the resource will be loaded anew. Otherwise, the cached resource will be returned if it exists. If [code]no_cache[/code] is [code]true[/code], the resource cache will be bypassed, and the resource will be loaded anew. Otherwise, the cached resource will be returned if it exists.
Returns an empty resource if no [ResourceFormatLoader] could handle the file. Returns an empty resource if no [ResourceFormatLoader] could handle the file.
GDScript has a simplified [method @GDScript.load] built-in method which can be used in most situations, leaving the use of [ResourceLoader] for more advanced scenarios. GDScript has a simplified [method @GDScript.load] built-in method which can be used in most situations, leaving the use of [ResourceLoader] for more advanced scenarios.
</description> </description>
@ -67,9 +67,11 @@
<return type="ResourceInteractiveLoader" /> <return type="ResourceInteractiveLoader" />
<argument index="0" name="path" type="String" /> <argument index="0" name="path" type="String" />
<argument index="1" name="type_hint" type="String" default="&quot;&quot;" /> <argument index="1" name="type_hint" type="String" default="&quot;&quot;" />
<argument index="2" name="no_cache" type="bool" default="false" />
<description> <description>
Starts loading a resource interactively. The returned [ResourceInteractiveLoader] object allows to load with high granularity, calling its [method ResourceInteractiveLoader.poll] method successively to load chunks. Starts loading a resource interactively. The returned [ResourceInteractiveLoader] object allows to load with high granularity, calling its [method ResourceInteractiveLoader.poll] method successively to load chunks.
An optional [code]type_hint[/code] can be used to further specify the [Resource] type that should be handled by the [ResourceFormatLoader]. Anything that inherits from [Resource] can be used as a type hint, for example [Image]. An optional [code]type_hint[/code] can be used to further specify the [Resource] type that should be handled by the [ResourceFormatLoader]. Anything that inherits from [Resource] can be used as a type hint, for example [Image].
If [code]no_cache[/code] is [code]true[/code], the resource cache will be bypassed, and the resource will be loaded anew. Otherwise, the cached resource will be returned if it exists.
</description> </description>
</method> </method>
<method name="set_abort_on_missing_resources"> <method name="set_abort_on_missing_resources">

View File

@ -35,7 +35,7 @@
#include <string.h> #include <string.h>
RES ResourceFormatDummyTexture::load(const String &p_path, const String &p_original_path, Error *r_error) { RES ResourceFormatDummyTexture::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_no_subresource_cache) {
unsigned int width = 8; unsigned int width = 8;
unsigned int height = 8; unsigned int height = 8;

View File

@ -35,7 +35,7 @@
class ResourceFormatDummyTexture : public ResourceFormatLoader { class ResourceFormatDummyTexture : public ResourceFormatLoader {
public: public:
virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = NULL); virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_no_subresource_cache = false);
virtual void get_recognized_extensions(List<String> *p_extensions) const; virtual void get_recognized_extensions(List<String> *p_extensions) const;
virtual bool handles_type(const String &p_type) const; virtual bool handles_type(const String &p_type) const;
virtual String get_resource_type(const String &p_path) const; virtual String get_resource_type(const String &p_path) const;

View File

@ -42,7 +42,7 @@ struct ETC1Header {
uint16_t origHeight; uint16_t origHeight;
}; };
RES ResourceFormatPKM::load(const String &p_path, const String &p_original_path, Error *r_error) { RES ResourceFormatPKM::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_no_subresource_cache) {
if (r_error) { if (r_error) {
*r_error = ERR_CANT_OPEN; *r_error = ERR_CANT_OPEN;
} }

View File

@ -35,7 +35,7 @@
class ResourceFormatPKM : public ResourceFormatLoader { class ResourceFormatPKM : public ResourceFormatLoader {
public: public:
virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr); virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_no_subresource_cache = false);
virtual void get_recognized_extensions(List<String> *p_extensions) const; virtual void get_recognized_extensions(List<String> *p_extensions) const;
virtual bool handles_type(const String &p_type) const; virtual bool handles_type(const String &p_type) const;
virtual String get_resource_type(const String &p_path) const; virtual String get_resource_type(const String &p_path) const;

View File

@ -24,7 +24,7 @@ SOFTWARE.
#include "text_editor_file.h" #include "text_editor_file.h"
RES TextEditorTextLoader::load(const String &p_path, const String &p_original_path, Error *r_error) { RES TextEditorTextLoader::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_no_subresource_cache) {
if (r_error) { if (r_error) {
*r_error = ERR_FILE_CANT_OPEN; *r_error = ERR_FILE_CANT_OPEN;
} }

View File

@ -32,7 +32,7 @@ class TextEditorTextLoader : public ResourceFormatLoader {
GDCLASS(TextEditorTextLoader, ResourceFormatLoader); GDCLASS(TextEditorTextLoader, ResourceFormatLoader);
public: public:
virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr); virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_no_subresource_cache = false);
virtual void get_recognized_extensions(List<String> *p_extensions) const; virtual void get_recognized_extensions(List<String> *p_extensions) const;
virtual bool handles_type(const String &p_type) const; virtual bool handles_type(const String &p_type) const;
virtual String get_resource_type(const String &p_path) const; virtual String get_resource_type(const String &p_path) const;

View File

@ -2126,7 +2126,7 @@ Ref<CScript> CScriptLanguage::get_orphan_subclass(const String &p_qualified_name
/*************** RESOURCE ***************/ /*************** RESOURCE ***************/
RES ResourceFormatLoaderCScript::load(const String &p_path, const String &p_original_path, Error *r_error) { RES ResourceFormatLoaderCScript::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_no_subresource_cache) {
if (r_error) { if (r_error) {
*r_error = ERR_FILE_CANT_OPEN; *r_error = ERR_FILE_CANT_OPEN;
} }

View File

@ -538,7 +538,7 @@ public:
class ResourceFormatLoaderCScript : public ResourceFormatLoader { class ResourceFormatLoaderCScript : public ResourceFormatLoader {
public: public:
virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr); virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_no_subresource_cache = false);
virtual void get_recognized_extensions(List<String> *p_extensions) const; virtual void get_recognized_extensions(List<String> *p_extensions) const;
virtual bool handles_type(const String &p_type) const; virtual bool handles_type(const String &p_type) const;
virtual String get_resource_type(const String &p_path) const; virtual String get_resource_type(const String &p_path) const;

View File

@ -32,7 +32,7 @@
#include "core/os/file_access.h" #include "core/os/file_access.h"
RES ResourceFormatDDS::load(const String &p_path, const String &p_original_path, Error *r_error) { RES ResourceFormatDDS::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_no_subresource_cache) {
if (r_error) { if (r_error) {
*r_error = ERR_CANT_OPEN; *r_error = ERR_CANT_OPEN;
} }

View File

@ -35,7 +35,7 @@
class ResourceFormatDDS : public ResourceFormatLoader { class ResourceFormatDDS : public ResourceFormatLoader {
public: public:
virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr); virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_no_subresource_cache = false);
virtual void get_recognized_extensions(List<String> *p_extensions) const; virtual void get_recognized_extensions(List<String> *p_extensions) const;
virtual bool handles_type(const String &p_type) const; virtual bool handles_type(const String &p_type) const;
virtual String get_resource_type(const String &p_path) const; virtual String get_resource_type(const String &p_path) const;

View File

@ -520,7 +520,7 @@ Error GDNative::get_symbol(StringName p_procedure_name, void *&r_handle, bool p_
return result; return result;
} }
RES GDNativeLibraryResourceLoader::load(const String &p_path, const String &p_original_path, Error *r_error) { RES GDNativeLibraryResourceLoader::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_no_subresource_cache) {
Ref<GDNativeLibrary> lib; Ref<GDNativeLibrary> lib;
lib.instance(); lib.instance();

View File

@ -166,7 +166,7 @@ public:
class GDNativeLibraryResourceLoader : public ResourceFormatLoader { class GDNativeLibraryResourceLoader : public ResourceFormatLoader {
public: public:
virtual RES load(const String &p_path, const String &p_original_path, Error *r_error); virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_no_subresource_cache = false);
virtual void get_recognized_extensions(List<String> *p_extensions) const; virtual void get_recognized_extensions(List<String> *p_extensions) const;
virtual bool handles_type(const String &p_type) const; virtual bool handles_type(const String &p_type) const;
virtual String get_resource_type(const String &p_path) const; virtual String get_resource_type(const String &p_path) const;

View File

@ -1729,8 +1729,8 @@ void NativeReloadNode::_notification(int p_what) {
#endif #endif
} }
RES ResourceFormatLoaderNativeScript::load(const String &p_path, const String &p_original_path, Error *r_error) { RES ResourceFormatLoaderNativeScript::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_no_subresource_cache) {
return ResourceFormatLoaderText::singleton->load(p_path, p_original_path, r_error); return ResourceFormatLoaderText::singleton->load(p_path, p_original_path, r_error, p_no_subresource_cache);
} }
void ResourceFormatLoaderNativeScript::get_recognized_extensions(List<String> *p_extensions) const { void ResourceFormatLoaderNativeScript::get_recognized_extensions(List<String> *p_extensions) const {

View File

@ -377,7 +377,7 @@ public:
class ResourceFormatLoaderNativeScript : public ResourceFormatLoader { class ResourceFormatLoaderNativeScript : public ResourceFormatLoader {
public: public:
virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr); virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_no_subresource_cache = false);
virtual void get_recognized_extensions(List<String> *p_extensions) const; virtual void get_recognized_extensions(List<String> *p_extensions) const;
virtual bool handles_type(const String &p_type) const; virtual bool handles_type(const String &p_type) const;
virtual String get_resource_type(const String &p_path) const; virtual String get_resource_type(const String &p_path) const;

View File

@ -39,7 +39,7 @@ ResourceFormatLoaderPluginScript::ResourceFormatLoaderPluginScript(PluginScriptL
_language = language; _language = language;
} }
RES ResourceFormatLoaderPluginScript::load(const String &p_path, const String &p_original_path, Error *r_error) { RES ResourceFormatLoaderPluginScript::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_no_subresource_cache) {
if (r_error) { if (r_error) {
*r_error = ERR_FILE_CANT_OPEN; *r_error = ERR_FILE_CANT_OPEN;
} }

View File

@ -43,7 +43,7 @@ class ResourceFormatLoaderPluginScript : public ResourceFormatLoader {
public: public:
ResourceFormatLoaderPluginScript(PluginScriptLanguage *language); ResourceFormatLoaderPluginScript(PluginScriptLanguage *language);
virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr); virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_no_subresource_cache = false);
virtual void get_recognized_extensions(List<String> *p_extensions) const; virtual void get_recognized_extensions(List<String> *p_extensions) const;
virtual bool handles_type(const String &p_type) const; virtual bool handles_type(const String &p_type) const;
virtual String get_resource_type(const String &p_path) const; virtual String get_resource_type(const String &p_path) const;

View File

@ -361,7 +361,7 @@ void VideoStreamGDNative::set_audio_track(int p_track) {
/* --- NOTE ResourceFormatLoaderVideoStreamGDNative starts here. ----- */ /* --- NOTE ResourceFormatLoaderVideoStreamGDNative starts here. ----- */
RES ResourceFormatLoaderVideoStreamGDNative::load(const String &p_path, const String &p_original_path, Error *r_error) { RES ResourceFormatLoaderVideoStreamGDNative::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_no_subresource_cache) {
FileAccess *f = FileAccess::open(p_path, FileAccess::READ); FileAccess *f = FileAccess::open(p_path, FileAccess::READ);
if (!f) { if (!f) {
if (r_error) { if (r_error) {

View File

@ -198,7 +198,7 @@ public:
class ResourceFormatLoaderVideoStreamGDNative : public ResourceFormatLoader { class ResourceFormatLoaderVideoStreamGDNative : public ResourceFormatLoader {
public: public:
virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr); virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_no_subresource_cache = false);
virtual void get_recognized_extensions(List<String> *p_extensions) const; virtual void get_recognized_extensions(List<String> *p_extensions) const;
virtual bool handles_type(const String &p_type) const; virtual bool handles_type(const String &p_type) const;
virtual String get_resource_type(const String &p_path) const; virtual String get_resource_type(const String &p_path) const;

View File

@ -2154,7 +2154,7 @@ Ref<GDScript> GDScriptLanguage::get_orphan_subclass(const String &p_qualified_na
/*************** RESOURCE ***************/ /*************** RESOURCE ***************/
RES ResourceFormatLoaderGDScript::load(const String &p_path, const String &p_original_path, Error *r_error) { RES ResourceFormatLoaderGDScript::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_no_subresource_cache) {
if (r_error) { if (r_error) {
*r_error = ERR_FILE_CANT_OPEN; *r_error = ERR_FILE_CANT_OPEN;
} }

View File

@ -538,7 +538,7 @@ public:
class ResourceFormatLoaderGDScript : public ResourceFormatLoader { class ResourceFormatLoaderGDScript : public ResourceFormatLoader {
public: public:
virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr); virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_no_subresource_cache = false);
virtual void get_recognized_extensions(List<String> *p_extensions) const; virtual void get_recognized_extensions(List<String> *p_extensions) const;
virtual bool handles_type(const String &p_type) const; virtual bool handles_type(const String &p_type) const;
virtual String get_resource_type(const String &p_path) const; virtual String get_resource_type(const String &p_path) const;

View File

@ -48,7 +48,7 @@ enum PVRFLags {
}; };
RES ResourceFormatPVR::load(const String &p_path, const String &p_original_path, Error *r_error) { RES ResourceFormatPVR::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_no_subresource_cache) {
if (r_error) { if (r_error) {
*r_error = ERR_CANT_OPEN; *r_error = ERR_CANT_OPEN;
} }

View File

@ -35,7 +35,7 @@
class ResourceFormatPVR : public ResourceFormatLoader { class ResourceFormatPVR : public ResourceFormatLoader {
public: public:
virtual RES load(const String &p_path, const String &p_original_path, Error *r_error = nullptr); virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_no_subresource_cache = false);
virtual void get_recognized_extensions(List<String> *p_extensions) const; virtual void get_recognized_extensions(List<String> *p_extensions) const;
virtual bool handles_type(const String &p_type) const; virtual bool handles_type(const String &p_type) const;
virtual String get_resource_type(const String &p_path) const; virtual String get_resource_type(const String &p_path) const;

View File

@ -689,7 +689,7 @@ void VideoStreamTheora::_bind_methods() {
//////////// ////////////
RES ResourceFormatLoaderTheora::load(const String &p_path, const String &p_original_path, Error *r_error) { RES ResourceFormatLoaderTheora::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_no_subresource_cache) {
FileAccess *f = FileAccess::open(p_path, FileAccess::READ); FileAccess *f = FileAccess::open(p_path, FileAccess::READ);
if (!f) { if (!f) {
if (r_error) { if (r_error) {

View File

@ -185,7 +185,7 @@ public:
class ResourceFormatLoaderTheora : public ResourceFormatLoader { class ResourceFormatLoaderTheora : public ResourceFormatLoader {
public: public:
virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr); virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_no_subresource_cache = false);
virtual void get_recognized_extensions(List<String> *p_extensions) const; virtual void get_recognized_extensions(List<String> *p_extensions) const;
virtual bool handles_type(const String &p_type) const; virtual bool handles_type(const String &p_type) const;
virtual String get_resource_type(const String &p_path) const; virtual String get_resource_type(const String &p_path) const;

View File

@ -1429,7 +1429,7 @@ void DynamicFont::update_oversampling() {
///////////////////////// /////////////////////////
RES ResourceFormatLoaderDynamicFont::load(const String &p_path, const String &p_original_path, Error *r_error) { RES ResourceFormatLoaderDynamicFont::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_no_subresource_cache) {
if (r_error) { if (r_error) {
*r_error = ERR_FILE_CANT_OPEN; *r_error = ERR_FILE_CANT_OPEN;
} }

View File

@ -391,7 +391,7 @@ VARIANT_ENUM_CAST(DynamicFont::SpacingType);
class ResourceFormatLoaderDynamicFont : public ResourceFormatLoader { class ResourceFormatLoaderDynamicFont : public ResourceFormatLoader {
public: public:
virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr); virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_no_subresource_cache = false);
virtual void get_recognized_extensions(List<String> *p_extensions) const; virtual void get_recognized_extensions(List<String> *p_extensions) const;
virtual bool handles_type(const String &p_type) const; virtual bool handles_type(const String &p_type) const;
virtual String get_resource_type(const String &p_path) const; virtual String get_resource_type(const String &p_path) const;

View File

@ -830,7 +830,7 @@ BitmapFont::~BitmapFont() {
//////////// ////////////
RES ResourceFormatLoaderBMFont::load(const String &p_path, const String &p_original_path, Error *r_error) { RES ResourceFormatLoaderBMFont::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_no_subresource_cache) {
if (r_error) { if (r_error) {
*r_error = ERR_FILE_CANT_OPEN; *r_error = ERR_FILE_CANT_OPEN;
} }

View File

@ -223,7 +223,7 @@ public:
class ResourceFormatLoaderBMFont : public ResourceFormatLoader { class ResourceFormatLoaderBMFont : public ResourceFormatLoader {
public: public:
virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr); virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_no_subresource_cache = false);
virtual void get_recognized_extensions(List<String> *p_extensions) const; virtual void get_recognized_extensions(List<String> *p_extensions) const;
virtual bool handles_type(const String &p_type) const; virtual bool handles_type(const String &p_type) const;
virtual String get_resource_type(const String &p_path) const; virtual String get_resource_type(const String &p_path) const;

View File

@ -151,7 +151,7 @@ Error ResourceInteractiveLoaderText::_parse_ext_resource(VariantParser::Stream *
path = ProjectSettings::get_singleton()->localize_path(res_path.get_base_dir().plus_file(path)); path = ProjectSettings::get_singleton()->localize_path(res_path.get_base_dir().plus_file(path));
} }
r_res = ResourceLoader::load(path, type); r_res = ResourceLoader::load(path, type, no_subresource_cache);
if (r_res.is_null()) { if (r_res.is_null()) {
WARN_PRINT(String("Couldn't load external resource: " + path).utf8().get_data()); WARN_PRINT(String("Couldn't load external resource: " + path).utf8().get_data());
@ -403,7 +403,7 @@ Error ResourceInteractiveLoaderText::poll() {
path = remaps[path]; path = remaps[path];
} }
RES res = ResourceLoader::load(path, type); RES res = ResourceLoader::load(path, type, no_subresource_cache);
if (res.is_null()) { if (res.is_null()) {
if (ResourceLoader::get_abort_on_missing_resources()) { if (ResourceLoader::get_abort_on_missing_resources()) {
@ -460,7 +460,7 @@ Error ResourceInteractiveLoaderText::poll() {
bool do_assign = false; bool do_assign = false;
if (ResourceCache::has(path)) { if (!no_subresource_cache && ResourceCache::has(path)) {
//cached, do not assign //cached, do not assign
Resource *r = ResourceCache::get(path); Resource *r = ResourceCache::get(path);
res = Ref<Resource>(r); res = Ref<Resource>(r);
@ -488,7 +488,7 @@ Error ResourceInteractiveLoaderText::poll() {
int_resources[id] = res; //always assign int resources int_resources[id] = res; //always assign int resources
if (do_assign) { if (do_assign) {
res->set_path(path); res->set_path(path, no_subresource_cache);
res->set_subindex(id); res->set_subindex(id);
} }
@ -561,7 +561,7 @@ Error ResourceInteractiveLoaderText::poll() {
if (error != ERR_FILE_EOF) { if (error != ERR_FILE_EOF) {
_printerr(); _printerr();
} else { } else {
if (!ResourceCache::has(res_path)) { if (!no_subresource_cache && !ResourceCache::has(res_path)) {
resource->set_path(res_path); resource->set_path(res_path);
} }
resource->set_as_translation_remapped(translation_remapped); resource->set_as_translation_remapped(translation_remapped);
@ -602,7 +602,7 @@ Error ResourceInteractiveLoaderText::poll() {
error = ERR_FILE_EOF; error = ERR_FILE_EOF;
//get it here //get it here
resource = packed_scene; resource = packed_scene;
if (!ResourceCache::has(res_path)) { if (!no_subresource_cache && !ResourceCache::has(res_path)) {
packed_scene->set_path(res_path); packed_scene->set_path(res_path);
} }
@ -1173,7 +1173,7 @@ String ResourceInteractiveLoaderText::recognize(FileAccess *p_f) {
///////////////////// /////////////////////
Ref<ResourceInteractiveLoader> ResourceFormatLoaderText::load_interactive(const String &p_path, const String &p_original_path, Error *r_error) { Ref<ResourceInteractiveLoader> ResourceFormatLoaderText::load_interactive(const String &p_path, const String &p_original_path, Error *r_error, bool p_no_subresource_cache) {
if (r_error) { if (r_error) {
*r_error = ERR_CANT_OPEN; *r_error = ERR_CANT_OPEN;
} }
@ -1184,6 +1184,7 @@ Ref<ResourceInteractiveLoader> ResourceFormatLoaderText::load_interactive(const
ERR_FAIL_COND_V_MSG(err != OK, Ref<ResourceInteractiveLoader>(), "Cannot open file '" + p_path + "'."); ERR_FAIL_COND_V_MSG(err != OK, Ref<ResourceInteractiveLoader>(), "Cannot open file '" + p_path + "'.");
Ref<ResourceInteractiveLoaderText> ria = memnew(ResourceInteractiveLoaderText); Ref<ResourceInteractiveLoaderText> ria = memnew(ResourceInteractiveLoaderText);
ria->set_no_subresource_cache(p_no_subresource_cache);
String path = p_original_path != "" ? p_original_path : p_path; String path = p_original_path != "" ? p_original_path : p_path;
ria->local_path = ProjectSettings::get_singleton()->localize_path(path); ria->local_path = ProjectSettings::get_singleton()->localize_path(path);
ria->res_path = ria->local_path; ria->res_path = ria->local_path;

View File

@ -128,7 +128,7 @@ public:
class ResourceFormatLoaderText : public ResourceFormatLoader { class ResourceFormatLoaderText : public ResourceFormatLoader {
public: public:
static ResourceFormatLoaderText *singleton; static ResourceFormatLoaderText *singleton;
virtual Ref<ResourceInteractiveLoader> load_interactive(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr); virtual Ref<ResourceInteractiveLoader> load_interactive(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_no_subresource_cache = false);
virtual void get_recognized_extensions_for_type(const String &p_type, List<String> *p_extensions) const; 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 void get_recognized_extensions(List<String> *p_extensions) const;
virtual bool handles_type(const String &p_type) const; virtual bool handles_type(const String &p_type) const;

View File

@ -181,7 +181,7 @@ Shader::~Shader() {
} }
//////////// ////////////
RES ResourceFormatLoaderShader::load(const String &p_path, const String &p_original_path, Error *r_error) { RES ResourceFormatLoaderShader::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_no_subresource_cache) {
if (r_error) { if (r_error) {
*r_error = ERR_FILE_CANT_OPEN; *r_error = ERR_FILE_CANT_OPEN;
} }

View File

@ -105,7 +105,7 @@ VARIANT_ENUM_CAST(Shader::Mode);
class ResourceFormatLoaderShader : public ResourceFormatLoader { class ResourceFormatLoaderShader : public ResourceFormatLoader {
public: public:
virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr); virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_no_subresource_cache = false);
virtual void get_recognized_extensions(List<String> *p_extensions) const; virtual void get_recognized_extensions(List<String> *p_extensions) const;
virtual bool handles_type(const String &p_type) const; virtual bool handles_type(const String &p_type) const;
virtual String get_resource_type(const String &p_path) const; virtual String get_resource_type(const String &p_path) const;

View File

@ -834,7 +834,7 @@ StreamTexture::~StreamTexture() {
RS::get_singleton()->free(texture); RS::get_singleton()->free(texture);
} }
RES ResourceFormatLoaderStreamTexture::load(const String &p_path, const String &p_original_path, Error *r_error) { RES ResourceFormatLoaderStreamTexture::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_no_subresource_cache) {
Ref<StreamTexture> st; Ref<StreamTexture> st;
st.instance(); st.instance();
Error err = st->load(p_path); Error err = st->load(p_path);
@ -2738,7 +2738,7 @@ void TextureArray::_bind_methods() {
ClassDB::bind_method(D_METHOD("create", "width", "height", "depth", "format", "flags"), &TextureArray::create, DEFVAL(FLAGS_DEFAULT_TEXTURE_ARRAY)); ClassDB::bind_method(D_METHOD("create", "width", "height", "depth", "format", "flags"), &TextureArray::create, DEFVAL(FLAGS_DEFAULT_TEXTURE_ARRAY));
} }
RES ResourceFormatLoaderTextureLayered::load(const String &p_path, const String &p_original_path, Error *r_error) { RES ResourceFormatLoaderTextureLayered::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_no_subresource_cache) {
if (r_error) { if (r_error) {
*r_error = ERR_CANT_OPEN; *r_error = ERR_CANT_OPEN;
} }

View File

@ -235,7 +235,7 @@ public:
class ResourceFormatLoaderStreamTexture : public ResourceFormatLoader { class ResourceFormatLoaderStreamTexture : public ResourceFormatLoader {
public: public:
virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr); virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_no_subresource_cache = false);
virtual void get_recognized_extensions(List<String> *p_extensions) const; virtual void get_recognized_extensions(List<String> *p_extensions) const;
virtual bool handles_type(const String &p_type) const; virtual bool handles_type(const String &p_type) const;
virtual String get_resource_type(const String &p_path) const; virtual String get_resource_type(const String &p_path) const;
@ -560,7 +560,7 @@ public:
class ResourceFormatLoaderTextureLayered : public ResourceFormatLoader { class ResourceFormatLoaderTextureLayered : public ResourceFormatLoader {
public: public:
virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr); virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_no_subresource_cache = false);
virtual void get_recognized_extensions(List<String> *p_extensions) const; virtual void get_recognized_extensions(List<String> *p_extensions) const;
virtual bool handles_type(const String &p_type) const; virtual bool handles_type(const String &p_type) const;
virtual String get_resource_type(const String &p_path) const; virtual String get_resource_type(const String &p_path) const;