Improve resource load cache
-Added a new method in Resource: reset_state , used for reloading the same resource from disk -Added a new cache mode "replace" in ResourceLoader, which reuses existing loaded sub-resources but resets their data from disk (or replaces them if they chaged type) -Because the correct sub-resource paths are always loaded now, this fixes bugs with subresource folding or subresource ordering when saving.
This commit is contained in:
@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user