summaryrefslogtreecommitdiff
path: root/scene/resources/resource_format_text.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/resources/resource_format_text.cpp')
-rw-r--r--scene/resources/resource_format_text.cpp57
1 files changed, 35 insertions, 22 deletions
diff --git a/scene/resources/resource_format_text.cpp b/scene/resources/resource_format_text.cpp
index 238bdf05ef..41146036f6 100644
--- a/scene/resources/resource_format_text.cpp
+++ b/scene/resources/resource_format_text.cpp
@@ -120,18 +120,23 @@ Error ResourceLoaderText::_parse_sub_resource(VariantParser::Stream *p_stream, R
int index = token.value;
- String path = local_path + "::" + itos(index);
+ if (use_nocache) {
+ r_res = int_resources[index];
+ } else {
- if (!ignore_resource_parsing) {
+ String path = local_path + "::" + itos(index);
- if (!ResourceCache::has(path)) {
- r_err_str = "Can't load cached sub-resource: " + path;
- return ERR_PARSE_ERROR;
- }
+ if (!ignore_resource_parsing) {
- r_res = RES(ResourceCache::get(path));
- } else {
- r_res = RES();
+ 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();
+ }
}
VariantParser::get_token(p_stream, token, line, r_err_str);
@@ -535,7 +540,7 @@ Error ResourceLoaderText::load() {
Ref<Resource> res;
- if (!ResourceCache::has(path)) { //only if it doesn't exist
+ if (use_nocache || !ResourceCache::has(path)) { //only if it doesn't exist
Object *obj = ClassDB::instance(type);
if (!obj) {
@@ -556,8 +561,10 @@ Error ResourceLoaderText::load() {
}
res = Ref<Resource>(r);
- resource_cache.push_back(res);
- res->set_path(path);
+ int_resources[id] = res;
+ if (!use_nocache) {
+ res->set_path(path);
+ }
}
resource_current++;
@@ -643,10 +650,12 @@ Error ResourceLoaderText::load() {
_printerr();
} else {
error = OK;
- if (!ResourceCache::has(res_path)) {
- resource->set_path(res_path);
+ if (!use_nocache) {
+ if (!ResourceCache::has(res_path)) {
+ resource->set_path(res_path);
+ }
+ resource->set_as_translation_remapped(translation_remapped);
}
- resource->set_as_translation_remapped(translation_remapped);
}
return error;
}
@@ -691,7 +700,7 @@ Error ResourceLoaderText::load() {
error = OK;
//get it here
resource = packed_scene;
- if (!ResourceCache::has(res_path)) {
+ if (!use_nocache && !ResourceCache::has(res_path)) {
packed_scene->set_path(res_path);
}
@@ -725,6 +734,9 @@ void ResourceLoaderText::set_translation_remapped(bool p_remapped) {
}
ResourceLoaderText::ResourceLoaderText() {
+
+ use_nocache = false;
+
resources_total = 0;
resource_current = 0;
use_sub_threads = false;
@@ -795,7 +807,7 @@ Error ResourceLoaderText::rename_dependencies(FileAccess *p_f, const String &p_p
ignore_resource_parsing = true;
//FileAccess
- FileAccess *fw = NULL;
+ FileAccess *fw = nullptr;
String base_path = local_path.get_base_dir();
@@ -961,7 +973,7 @@ void ResourceLoaderText::open(FileAccess *p_f, bool p_skip_first_tag) {
rp.ext_func = _parse_ext_resources;
rp.sub_func = _parse_sub_resources;
- rp.func = NULL;
+ rp.func = nullptr;
rp.userdata = this;
}
@@ -1285,7 +1297,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) {
+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) {
if (r_error)
*r_error = ERR_CANT_OPEN;
@@ -1298,6 +1310,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.use_sub_threads = p_use_sub_threads;
loader.local_path = ProjectSettings::get_singleton()->localize_path(path);
loader.progress = r_progress;
@@ -1392,7 +1405,7 @@ Error ResourceFormatLoaderText::rename_dependencies(const String &p_path, const
return loader.rename_dependencies(f, p_path, p_map);
}
-ResourceFormatLoaderText *ResourceFormatLoaderText::singleton = NULL;
+ResourceFormatLoaderText *ResourceFormatLoaderText::singleton = nullptr;
Error ResourceFormatLoaderText::convert_file_to_binary(const String &p_src_path, const String &p_dst_path) {
@@ -1674,7 +1687,7 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path, const RES &p_r
RES res = E->get();
ERR_CONTINUE(!resource_set.has(res));
- bool main = (E->next() == NULL);
+ bool main = (E->next() == nullptr);
if (main && packed_scene.is_valid())
break; //save as a scene
@@ -1880,7 +1893,7 @@ void ResourceFormatSaverText::get_recognized_extensions(const RES &p_resource, L
p_extensions->push_back("tres"); //text resource
}
-ResourceFormatSaverText *ResourceFormatSaverText::singleton = NULL;
+ResourceFormatSaverText *ResourceFormatSaverText::singleton = nullptr;
ResourceFormatSaverText::ResourceFormatSaverText() {
singleton = this;
}