Enhance cache modes in resource loading
- Unify documentation, hoping to clear misconcepctions about about propagation of the cache mode across dependant loads. - Clarify in docs that `CACHE_MODE_REPLACE` now also works on the main resource (from #87008). - Add two recursive modes, counterparts of `CACHE_MODE_REPLACE` and `CACHE_MODE_IGNORE`, since it seems some need them (see #59669, #82830). - Let resources, even loaded with one of the ignore-cache modes, get a path, which is useful for tools.
This commit is contained in:
parent
bb6b06c813
commit
5e144022e7
15 changed files with 104 additions and 28 deletions
|
|
@ -471,7 +471,7 @@ Error ResourceLoaderText::load() {
|
|||
|
||||
ext_resources[id].path = path;
|
||||
ext_resources[id].type = type;
|
||||
ext_resources[id].load_token = ResourceLoader::_load_start(path, type, use_sub_threads ? ResourceLoader::LOAD_THREAD_DISTRIBUTE : ResourceLoader::LOAD_THREAD_FROM_CURRENT, ResourceFormatLoader::CACHE_MODE_REUSE);
|
||||
ext_resources[id].load_token = ResourceLoader::_load_start(path, type, use_sub_threads ? ResourceLoader::LOAD_THREAD_DISTRIBUTE : ResourceLoader::LOAD_THREAD_FROM_CURRENT, cache_mode_for_external);
|
||||
if (!ext_resources[id].load_token.is_valid()) {
|
||||
if (ResourceLoader::get_abort_on_missing_resources()) {
|
||||
error = ERR_FILE_CORRUPT;
|
||||
|
|
@ -584,7 +584,7 @@ Error ResourceLoaderText::load() {
|
|||
if (do_assign) {
|
||||
if (cache_mode != ResourceFormatLoader::CACHE_MODE_IGNORE) {
|
||||
res->set_path(path, cache_mode == ResourceFormatLoader::CACHE_MODE_REPLACE);
|
||||
} else if (!path.is_resource_file()) {
|
||||
} else {
|
||||
res->set_path_cache(path);
|
||||
}
|
||||
res->set_scene_unique_id(id);
|
||||
|
|
@ -721,6 +721,8 @@ Error ResourceLoaderText::load() {
|
|||
resource->set_path(res_path);
|
||||
}
|
||||
resource->set_as_translation_remapped(translation_remapped);
|
||||
} else {
|
||||
resource->set_path_cache(res_path);
|
||||
}
|
||||
}
|
||||
return error;
|
||||
|
|
@ -805,8 +807,13 @@ Error ResourceLoaderText::load() {
|
|||
error = OK;
|
||||
//get it here
|
||||
resource = packed_scene;
|
||||
if (cache_mode != ResourceFormatLoader::CACHE_MODE_IGNORE && !ResourceCache::has(res_path)) {
|
||||
packed_scene->set_path(res_path);
|
||||
if (cache_mode != ResourceFormatLoader::CACHE_MODE_IGNORE) {
|
||||
if (!ResourceCache::has(res_path)) {
|
||||
packed_scene->set_path(res_path);
|
||||
}
|
||||
} else {
|
||||
packed_scene->get_state()->set_path(res_path);
|
||||
packed_scene->set_path_cache(res_path);
|
||||
}
|
||||
|
||||
resource_current++;
|
||||
|
|
@ -1650,7 +1657,22 @@ Ref<Resource> ResourceFormatLoaderText::load(const String &p_path, const String
|
|||
|
||||
ResourceLoaderText loader;
|
||||
String path = !p_original_path.is_empty() ? p_original_path : p_path;
|
||||
loader.cache_mode = p_cache_mode;
|
||||
switch (p_cache_mode) {
|
||||
case CACHE_MODE_IGNORE:
|
||||
case CACHE_MODE_REUSE:
|
||||
case CACHE_MODE_REPLACE:
|
||||
loader.cache_mode = p_cache_mode;
|
||||
loader.cache_mode_for_external = CACHE_MODE_REUSE;
|
||||
break;
|
||||
case CACHE_MODE_IGNORE_DEEP:
|
||||
loader.cache_mode = ResourceFormatLoader::CACHE_MODE_IGNORE;
|
||||
loader.cache_mode_for_external = p_cache_mode;
|
||||
break;
|
||||
case CACHE_MODE_REPLACE_DEEP:
|
||||
loader.cache_mode = ResourceFormatLoader::CACHE_MODE_REPLACE;
|
||||
loader.cache_mode_for_external = p_cache_mode;
|
||||
break;
|
||||
}
|
||||
loader.use_sub_threads = p_use_sub_threads;
|
||||
loader.local_path = ProjectSettings::get_singleton()->localize_path(path);
|
||||
loader.progress = r_progress;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue