Reworked how non-imported resources are reloaded on change, fixes #19852
This commit is contained in:
parent
f2cc969843
commit
da0ec37aa9
|
@ -466,6 +466,7 @@ bool EditorFileSystem::_update_scan_actions() {
|
|||
bool fs_changed = false;
|
||||
|
||||
Vector<String> reimports;
|
||||
Vector<String> reloads;
|
||||
|
||||
for (List<ItemAction>::Element *E = scan_actions.front(); E; E = E->next()) {
|
||||
|
||||
|
@ -545,12 +546,25 @@ bool EditorFileSystem::_update_scan_actions() {
|
|||
|
||||
fs_changed = true;
|
||||
} break;
|
||||
case ItemAction::ACTION_FILE_RELOAD: {
|
||||
|
||||
int idx = ia.dir->find_file_index(ia.file);
|
||||
ERR_CONTINUE(idx == -1);
|
||||
String full_path = ia.dir->get_file_path(idx);
|
||||
|
||||
reloads.push_back(full_path);
|
||||
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
if (reimports.size()) {
|
||||
reimport_files(reimports);
|
||||
}
|
||||
|
||||
if (reloads.size()) {
|
||||
emit_signal("resources_reload", reloads);
|
||||
}
|
||||
scan_actions.clear();
|
||||
|
||||
return fs_changed;
|
||||
|
@ -905,11 +919,11 @@ void EditorFileSystem::_scan_fs_changes(EditorFileSystemDirectory *p_dir, const
|
|||
continue;
|
||||
}
|
||||
|
||||
String path = cd.plus_file(p_dir->files[i]->file);
|
||||
|
||||
if (import_extensions.has(p_dir->files[i]->file.get_extension().to_lower())) {
|
||||
//check here if file must be imported or not
|
||||
|
||||
String path = cd.plus_file(p_dir->files[i]->file);
|
||||
|
||||
uint64_t mt = FileAccess::get_modified_time(path);
|
||||
|
||||
bool reimport = false;
|
||||
|
@ -936,6 +950,20 @@ void EditorFileSystem::_scan_fs_changes(EditorFileSystemDirectory *p_dir, const
|
|||
ia.file = p_dir->files[i]->file;
|
||||
scan_actions.push_back(ia);
|
||||
}
|
||||
} else if (ResourceCache::has(path)) { //test for potential reload
|
||||
|
||||
uint64_t mt = FileAccess::get_modified_time(path);
|
||||
|
||||
if (mt != p_dir->files[i]->modified_time) {
|
||||
|
||||
p_dir->files[i]->modified_time = mt; //save new time, but test for reload
|
||||
|
||||
ItemAction ia;
|
||||
ia.action = ItemAction::ACTION_FILE_RELOAD;
|
||||
ia.dir = p_dir;
|
||||
ia.file = p_dir->files[i]->file;
|
||||
scan_actions.push_back(ia);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1726,6 +1754,7 @@ void EditorFileSystem::_bind_methods() {
|
|||
ADD_SIGNAL(MethodInfo("filesystem_changed"));
|
||||
ADD_SIGNAL(MethodInfo("sources_changed", PropertyInfo(Variant::BOOL, "exist")));
|
||||
ADD_SIGNAL(MethodInfo("resources_reimported", PropertyInfo(Variant::POOL_STRING_ARRAY, "resources")));
|
||||
ADD_SIGNAL(MethodInfo("resources_reload", PropertyInfo(Variant::POOL_STRING_ARRAY, "resources")));
|
||||
}
|
||||
|
||||
void EditorFileSystem::_update_extensions() {
|
||||
|
|
|
@ -116,7 +116,8 @@ class EditorFileSystem : public Node {
|
|||
ACTION_DIR_REMOVE,
|
||||
ACTION_FILE_ADD,
|
||||
ACTION_FILE_REMOVE,
|
||||
ACTION_FILE_TEST_REIMPORT
|
||||
ACTION_FILE_TEST_REIMPORT,
|
||||
ACTION_FILE_RELOAD
|
||||
};
|
||||
|
||||
Action action;
|
||||
|
|
|
@ -410,6 +410,40 @@ void EditorNode::_on_plugin_ready(Object *p_script, const String &p_activate_nam
|
|||
push_item(script.operator->());
|
||||
}
|
||||
|
||||
void EditorNode::_resources_changed(const PoolVector<String> &p_resources) {
|
||||
|
||||
List<Ref<Resource> > changed;
|
||||
|
||||
int rc = p_resources.size();
|
||||
for (int i = 0; i < rc; i++) {
|
||||
|
||||
Ref<Resource> res(ResourceCache::get(p_resources.get(i)));
|
||||
if (res.is_null()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!res->editor_can_reload_from_file())
|
||||
continue;
|
||||
if (!res->get_path().is_resource_file() && !res->get_path().is_abs_path())
|
||||
continue;
|
||||
if (!FileAccess::exists(res->get_path()))
|
||||
continue;
|
||||
|
||||
if (res->get_import_path() != String()) {
|
||||
//this is an imported resource, will be reloaded if reimported via the _resources_reimported() callback
|
||||
continue;
|
||||
}
|
||||
|
||||
changed.push_back(res);
|
||||
}
|
||||
|
||||
if (changed.size()) {
|
||||
for (List<Ref<Resource> >::Element *E = changed.front(); E; E = E->next()) {
|
||||
E->get()->reload_from_file();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EditorNode::_fs_changed() {
|
||||
|
||||
for (Set<FileDialog *>::Element *E = file_dialogs.front(); E; E = E->next()) {
|
||||
|
@ -422,41 +456,6 @@ void EditorNode::_fs_changed() {
|
|||
E->get()->invalidate();
|
||||
}
|
||||
|
||||
{
|
||||
//reload changed resources
|
||||
List<Ref<Resource> > changed;
|
||||
|
||||
List<Ref<Resource> > cached;
|
||||
ResourceCache::get_cached_resources(&cached);
|
||||
// FIXME: This should be done in a thread.
|
||||
for (List<Ref<Resource> >::Element *E = cached.front(); E; E = E->next()) {
|
||||
|
||||
if (!E->get()->editor_can_reload_from_file())
|
||||
continue;
|
||||
if (!E->get()->get_path().is_resource_file() && !E->get()->get_path().is_abs_path())
|
||||
continue;
|
||||
if (!FileAccess::exists(E->get()->get_path()))
|
||||
continue;
|
||||
|
||||
if (E->get()->get_import_path() != String()) {
|
||||
//this is an imported resource, will be reloaded if reimported via the _resources_reimported() callback
|
||||
continue;
|
||||
}
|
||||
|
||||
uint64_t mt = FileAccess::get_modified_time(E->get()->get_path());
|
||||
|
||||
if (mt != E->get()->get_last_modified_time()) {
|
||||
changed.push_back(E->get());
|
||||
}
|
||||
}
|
||||
|
||||
if (changed.size()) {
|
||||
for (List<Ref<Resource> >::Element *E = changed.front(); E; E = E->next()) {
|
||||
E->get()->reload_from_file();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_mark_unsaved_scenes();
|
||||
|
||||
if (export_defer.preset != "" && !EditorFileSystem::get_singleton()->is_scanning()) {
|
||||
|
@ -4650,6 +4649,8 @@ void EditorNode::_bind_methods() {
|
|||
|
||||
ClassDB::bind_method(D_METHOD("_video_driver_selected"), &EditorNode::_video_driver_selected);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("_resources_changed"), &EditorNode::_resources_changed);
|
||||
|
||||
ADD_SIGNAL(MethodInfo("play_pressed"));
|
||||
ADD_SIGNAL(MethodInfo("pause_pressed"));
|
||||
ADD_SIGNAL(MethodInfo("stop_pressed"));
|
||||
|
@ -5819,6 +5820,7 @@ EditorNode::EditorNode() {
|
|||
EditorFileSystem::get_singleton()->connect("sources_changed", this, "_sources_changed");
|
||||
EditorFileSystem::get_singleton()->connect("filesystem_changed", this, "_fs_changed");
|
||||
EditorFileSystem::get_singleton()->connect("resources_reimported", this, "_resources_reimported");
|
||||
EditorFileSystem::get_singleton()->connect("resources_reload", this, "_resources_changed");
|
||||
|
||||
_build_icon_type_cache();
|
||||
|
||||
|
|
|
@ -606,6 +606,8 @@ private:
|
|||
static void _resource_saved(RES p_resource, const String &p_path);
|
||||
static void _resource_loaded(RES p_resource, const String &p_path);
|
||||
|
||||
void _resources_changed(const PoolVector<String> &p_resources);
|
||||
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
static void _bind_methods();
|
||||
|
|
Loading…
Reference in New Issue