feat: updated engine
This commit is contained in:
parent
cbe99774ff
commit
f4cf6b3999
6607 changed files with 910135 additions and 430025 deletions
|
|
@ -34,7 +34,11 @@
|
|||
#include "core/extension/gdextension_manager.h"
|
||||
#include "core/io/dir_access.h"
|
||||
#include "core/io/file_access.h"
|
||||
#include "core/io/resource_importer.h"
|
||||
#include "core/io/resource_loader.h"
|
||||
#include "core/io/resource_saver.h"
|
||||
#include "core/object/callable_mp.h"
|
||||
#include "core/object/class_db.h"
|
||||
#include "core/object/worker_thread_pool.h"
|
||||
#include "core/os/os.h"
|
||||
#include "core/variant/variant_parser.h"
|
||||
|
|
@ -45,7 +49,9 @@
|
|||
#include "editor/script/script_editor_plugin.h"
|
||||
#include "editor/settings/editor_settings.h"
|
||||
#include "editor/settings/project_settings_editor.h"
|
||||
#include "scene/main/scene_tree.h"
|
||||
#include "scene/resources/packed_scene.h"
|
||||
#include "servers/display/display_server.h"
|
||||
|
||||
EditorFileSystem *EditorFileSystem::singleton = nullptr;
|
||||
int EditorFileSystem::nb_files_total = 0;
|
||||
|
|
@ -129,6 +135,11 @@ String EditorFileSystemDirectory::get_file_path(int p_idx) const {
|
|||
return get_path().path_join(get_file(p_idx));
|
||||
}
|
||||
|
||||
ResourceUID::ID EditorFileSystemDirectory::get_file_uid(int p_idx) const {
|
||||
ERR_FAIL_INDEX_V(p_idx, files.size(), ResourceUID::INVALID_ID);
|
||||
return files[p_idx]->uid;
|
||||
}
|
||||
|
||||
Vector<String> EditorFileSystemDirectory::get_file_deps(int p_idx) const {
|
||||
ERR_FAIL_INDEX_V(p_idx, files.size(), Vector<String>());
|
||||
Vector<String> deps;
|
||||
|
|
@ -234,6 +245,12 @@ EditorFileSystemDirectory::~EditorFileSystemDirectory() {
|
|||
}
|
||||
}
|
||||
|
||||
void EditorFileSystemImportFormatSupportQuery::_bind_methods() {
|
||||
GDVIRTUAL_BIND(_is_active);
|
||||
GDVIRTUAL_BIND(_get_file_extensions);
|
||||
GDVIRTUAL_BIND(_query);
|
||||
}
|
||||
|
||||
EditorFileSystem::ScannedDirectory::~ScannedDirectory() {
|
||||
for (ScannedDirectory *dir : subdirs) {
|
||||
memdelete(dir);
|
||||
|
|
@ -903,15 +920,26 @@ bool EditorFileSystem::_update_scan_actions() {
|
|||
const String new_file_path = ia.dir->get_file_path(idx);
|
||||
const ResourceUID::ID existing_id = ResourceLoader::get_resource_uid(new_file_path);
|
||||
if (existing_id != ResourceUID::INVALID_ID) {
|
||||
const String old_path = ResourceUID::get_singleton()->get_id_path(existing_id);
|
||||
if (old_path != new_file_path && FileAccess::exists(old_path)) {
|
||||
const bool id_known = ResourceUID::get_singleton()->has_id(existing_id);
|
||||
const String old_path = id_known ? ResourceUID::get_singleton()->get_id_path(existing_id) : String();
|
||||
|
||||
if (id_known && old_path != new_file_path && FileAccess::exists(old_path)) {
|
||||
const ResourceUID::ID new_id = ResourceUID::get_singleton()->create_id_for_path(new_file_path);
|
||||
ResourceUID::get_singleton()->add_id(new_id, new_file_path);
|
||||
ResourceSaver::set_uid(new_file_path, new_id);
|
||||
WARN_PRINT(vformat("Duplicate UID detected for Resource at \"%s\".\nOld Resource path: \"%s\". The new file UID was changed automatically.", new_file_path, old_path));
|
||||
ia.new_file->uid = new_id;
|
||||
} else {
|
||||
// Re-assign the UID to file, just in case it was pulled from cache.
|
||||
ResourceSaver::set_uid(new_file_path, existing_id);
|
||||
|
||||
if (id_known) {
|
||||
ResourceUID::get_singleton()->set_id(existing_id, new_file_path);
|
||||
} else {
|
||||
ResourceUID::get_singleton()->add_id(existing_id, new_file_path);
|
||||
}
|
||||
|
||||
ia.new_file->uid = existing_id;
|
||||
}
|
||||
} else if (ResourceLoader::should_create_uid_file(new_file_path)) {
|
||||
Ref<FileAccess> f = FileAccess::open(new_file_path + ".uid", FileAccess::WRITE);
|
||||
|
|
@ -1863,11 +1891,6 @@ bool EditorFileSystem::_find_file(const String &p_file, EditorFileSystemDirector
|
|||
}
|
||||
|
||||
String f = ProjectSettings::get_singleton()->localize_path(p_file);
|
||||
|
||||
// Note: Only checks if base directory is case sensitive.
|
||||
Ref<DirAccess> dir = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
|
||||
bool fs_case_sensitive = dir->is_case_sensitive("res://");
|
||||
|
||||
if (!f.begins_with("res://")) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -1879,25 +1902,28 @@ bool EditorFileSystem::_find_file(const String &p_file, EditorFileSystemDirector
|
|||
if (path.is_empty()) {
|
||||
return false;
|
||||
}
|
||||
String file = path[path.size() - 1];
|
||||
const String file = path[path.size() - 1];
|
||||
const String file_lower = file.to_lower();
|
||||
path.resize(path.size() - 1);
|
||||
|
||||
Ref<DirAccess> dir = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
|
||||
EditorFileSystemDirectory *fs = filesystem;
|
||||
|
||||
for (int i = 0; i < path.size(); i++) {
|
||||
if (path[i].begins_with(".")) {
|
||||
for (const String &path_bit : path) {
|
||||
if (path_bit.begins_with(".")) {
|
||||
return false;
|
||||
}
|
||||
const String path_bit_lower = path_bit.to_lower();
|
||||
|
||||
int idx = -1;
|
||||
for (int j = 0; j < fs->get_subdir_count(); j++) {
|
||||
if (fs_case_sensitive) {
|
||||
if (fs->get_subdir(j)->get_name() == path[i]) {
|
||||
if (is_case_sensitive) {
|
||||
if (fs->get_subdir(j)->get_name() == path_bit) {
|
||||
idx = j;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if (fs->get_subdir(j)->get_name().to_lower() == path[i].to_lower()) {
|
||||
if (fs->get_subdir(j)->get_name().to_lower() == path_bit_lower) {
|
||||
idx = j;
|
||||
break;
|
||||
}
|
||||
|
|
@ -1906,12 +1932,12 @@ bool EditorFileSystem::_find_file(const String &p_file, EditorFileSystemDirector
|
|||
|
||||
if (idx == -1) {
|
||||
// Only create a missing directory in memory when it exists on disk.
|
||||
if (!dir->dir_exists(fs->get_path().path_join(path[i]))) {
|
||||
if (!dir->dir_exists(fs->get_path().path_join(path_bit))) {
|
||||
return false;
|
||||
}
|
||||
EditorFileSystemDirectory *efsd = memnew(EditorFileSystemDirectory);
|
||||
|
||||
efsd->name = path[i];
|
||||
efsd->name = path_bit;
|
||||
efsd->parent = fs;
|
||||
|
||||
int idx2 = 0;
|
||||
|
|
@ -1935,13 +1961,13 @@ bool EditorFileSystem::_find_file(const String &p_file, EditorFileSystemDirector
|
|||
|
||||
int cpos = -1;
|
||||
for (int i = 0; i < fs->files.size(); i++) {
|
||||
if (fs_case_sensitive) {
|
||||
if (is_case_sensitive) {
|
||||
if (fs->files[i]->file == file) {
|
||||
cpos = i;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if (fs->files[i]->file.to_lower() == file.to_lower()) {
|
||||
if (fs->files[i]->file.to_lower() == file_lower) {
|
||||
cpos = i;
|
||||
break;
|
||||
}
|
||||
|
|
@ -2526,20 +2552,20 @@ void EditorFileSystem::update_files(const Vector<String> &p_script_paths) {
|
|||
if (!is_scanning()) {
|
||||
_process_update_pending();
|
||||
}
|
||||
if (!filesystem_changed_queued) {
|
||||
filesystem_changed_queued = true;
|
||||
if (!filesystem_changed_queued.is_set()) {
|
||||
filesystem_changed_queued.set();
|
||||
callable_mp(this, &EditorFileSystem::_notify_filesystem_changed).call_deferred();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EditorFileSystem::_notify_filesystem_changed() {
|
||||
emit_signal("filesystem_changed");
|
||||
filesystem_changed_queued = false;
|
||||
emit_signal(SNAME("filesystem_changed"));
|
||||
filesystem_changed_queued.clear();
|
||||
}
|
||||
|
||||
HashSet<String> EditorFileSystem::get_valid_extensions() const {
|
||||
return valid_extensions;
|
||||
return HashSet<String>(valid_extensions);
|
||||
}
|
||||
|
||||
void EditorFileSystem::_register_global_class_script(const String &p_search_path, const String &p_target_path, const ScriptClassInfoUpdate &p_script_update) {
|
||||
|
|
@ -2576,6 +2602,18 @@ void EditorFileSystem::register_global_class_script(const String &p_search_path,
|
|||
}
|
||||
}
|
||||
|
||||
void EditorFileSystem::filesystem_changed() {
|
||||
if (Thread::is_main_thread()) {
|
||||
_notify_filesystem_changed();
|
||||
return;
|
||||
}
|
||||
// If not already queued, queue a deferred call to notify about filesystem changes.
|
||||
if (!filesystem_changed_queued.is_set()) {
|
||||
filesystem_changed_queued.set();
|
||||
callable_mp(this, &EditorFileSystem::_notify_filesystem_changed).call_deferred();
|
||||
}
|
||||
}
|
||||
|
||||
Error EditorFileSystem::_reimport_group(const String &p_group_file, const Vector<String> &p_files) {
|
||||
String importer_name;
|
||||
|
||||
|
|
@ -2785,7 +2823,7 @@ Error EditorFileSystem::_reimport_file(const String &p_file, const HashMap<Strin
|
|||
|
||||
//try to obtain existing params
|
||||
|
||||
HashMap<StringName, Variant> params = p_custom_options;
|
||||
HashMap<StringName, Variant> params(p_custom_options);
|
||||
String importer_name; //empty by default though
|
||||
|
||||
if (!p_custom_importer.is_empty()) {
|
||||
|
|
@ -3019,6 +3057,7 @@ Error EditorFileSystem::_reimport_file(const String &p_file, const HashMap<Strin
|
|||
fs->files[cpos]->import_dest_paths = dest_paths;
|
||||
fs->files[cpos]->deps = _get_dependencies(p_file);
|
||||
fs->files[cpos]->type = importer->get_resource_type();
|
||||
fs->files[cpos]->resource_script_class = ResourceLoader::get_resource_script_class(p_file);
|
||||
fs->files[cpos]->uid = uid;
|
||||
fs->files[cpos]->import_valid = fs->files[cpos]->type == "TextFile" ? true : ResourceLoader::is_import_valid(p_file);
|
||||
}
|
||||
|
|
@ -3125,7 +3164,7 @@ Error EditorFileSystem::_copy_file(const String &p_from, const String &p_to) {
|
|||
Error err = OK;
|
||||
Ref<Resource> res = ResourceCache::get_ref(p_from);
|
||||
if (res.is_null()) {
|
||||
res = ResourceLoader::load(p_from, "", ResourceFormatLoader::CACHE_MODE_REUSE, &err);
|
||||
res = ResourceLoader::load(p_from, "", ResourceLoaderConstants::CACHE_MODE_REUSE, &err);
|
||||
} else {
|
||||
bool edited = false;
|
||||
List<Ref<Resource>> cached;
|
||||
|
|
@ -3230,9 +3269,9 @@ void EditorFileSystem::reimport_files(const Vector<String> &p_files) {
|
|||
// this could lead to a slow import process, especially when the editor is unfocused.
|
||||
// Temporarily disabling VSync and low_processor_usage_mode while reimporting fixes this.
|
||||
const bool old_low_processor_usage_mode = OS::get_singleton()->is_in_low_processor_usage_mode();
|
||||
const DisplayServer::VSyncMode old_vsync_mode = DisplayServer::get_singleton()->window_get_vsync_mode(DisplayServer::MAIN_WINDOW_ID);
|
||||
const DisplayServerEnums::VSyncMode old_vsync_mode = DisplayServer::get_singleton()->window_get_vsync_mode(DisplayServerEnums::MAIN_WINDOW_ID);
|
||||
OS::get_singleton()->set_low_processor_usage_mode(false);
|
||||
DisplayServer::get_singleton()->window_set_vsync_mode(DisplayServer::VSyncMode::VSYNC_DISABLED);
|
||||
DisplayServer::get_singleton()->window_set_vsync_mode(DisplayServerEnums::VSyncMode::VSYNC_DISABLED);
|
||||
|
||||
Vector<ImportFile> reimport_files;
|
||||
|
||||
|
|
@ -3426,7 +3465,7 @@ Error EditorFileSystem::_resource_import(const String &p_path) {
|
|||
return OK;
|
||||
}
|
||||
|
||||
Ref<Resource> EditorFileSystem::_load_resource_on_startup(ResourceFormatImporter *p_importer, const String &p_path, Error *r_error, bool p_use_sub_threads, float *r_progress, ResourceFormatLoader::CacheMode p_cache_mode) {
|
||||
Ref<Resource> EditorFileSystem::_load_resource_on_startup(ResourceFormatImporter *p_importer, const String &p_path, Error *r_error, bool p_use_sub_threads, float *r_progress, ResourceLoaderConstants::CacheMode p_cache_mode) {
|
||||
ERR_FAIL_NULL_V(p_importer, Ref<Resource>());
|
||||
|
||||
if (!FileAccess::exists(p_path)) {
|
||||
|
|
@ -3684,6 +3723,7 @@ bool EditorFileSystem::_scan_extensions() {
|
|||
void EditorFileSystem::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_filesystem"), &EditorFileSystem::get_filesystem);
|
||||
ClassDB::bind_method(D_METHOD("is_scanning"), &EditorFileSystem::is_scanning);
|
||||
ClassDB::bind_method(D_METHOD("is_importing"), &EditorFileSystem::is_importing);
|
||||
ClassDB::bind_method(D_METHOD("get_scanning_progress"), &EditorFileSystem::get_scanning_progress);
|
||||
ClassDB::bind_method(D_METHOD("scan"), &EditorFileSystem::scan);
|
||||
ClassDB::bind_method(D_METHOD("scan_sources"), &EditorFileSystem::scan_changes);
|
||||
|
|
@ -3692,7 +3732,7 @@ void EditorFileSystem::_bind_methods() {
|
|||
ClassDB::bind_method(D_METHOD("get_file_type", "path"), &EditorFileSystem::get_file_type);
|
||||
ClassDB::bind_method(D_METHOD("reimport_files", "files"), &EditorFileSystem::reimport_files);
|
||||
|
||||
ADD_SIGNAL(MethodInfo("filesystem_changed"));
|
||||
ADD_SIGNAL(MethodInfo("filesystem_changed")); // May only be emitted on the main thread.
|
||||
ADD_SIGNAL(MethodInfo("script_classes_updated"));
|
||||
ADD_SIGNAL(MethodInfo("sources_changed", PropertyInfo(Variant::BOOL, "exist")));
|
||||
ADD_SIGNAL(MethodInfo("resources_reimporting", PropertyInfo(Variant::PACKED_STRING_ARRAY, "resources")));
|
||||
|
|
@ -3779,6 +3819,9 @@ EditorFileSystem::EditorFileSystem() {
|
|||
// Set the callback method that the ResourceFormatImporter will use
|
||||
// if resources are loaded during the first scan.
|
||||
ResourceImporter::load_on_startup = _load_resource_on_startup;
|
||||
|
||||
Ref<DirAccess> dir = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
|
||||
is_case_sensitive = dir->is_case_sensitive("res://");
|
||||
}
|
||||
|
||||
EditorFileSystem::~EditorFileSystem() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue