feat: modules moved and engine moved to submodule

This commit is contained in:
Jan van der Weide 2025-04-12 18:40:44 +02:00
parent dfb5e645cd
commit c33d2130cc
5136 changed files with 225275 additions and 64485 deletions

View file

@ -447,8 +447,8 @@ void EditorFileSystem::_scan_filesystem() {
name = cpath.path_join(name);
FileCache fc;
fc.type = split[1].get_slice("/", 0);
fc.resource_script_class = split[1].get_slice("/", 1);
fc.type = split[1].get_slicec('/', 0);
fc.resource_script_class = split[1].get_slicec('/', 1);
fc.uid = split[2].to_int();
fc.modification_time = split[3].to_int();
fc.import_modification_time = split[4].to_int();
@ -802,7 +802,7 @@ Vector<String> EditorFileSystem::_get_import_dest_paths(const String &p_path) {
}
bool EditorFileSystem::_scan_import_support(const Vector<String> &reimports) {
if (import_support_queries.size() == 0) {
if (import_support_queries.is_empty()) {
return false;
}
HashMap<String, int> import_support_test;
@ -818,7 +818,7 @@ bool EditorFileSystem::_scan_import_support(const Vector<String> &reimports) {
}
}
if (import_support_test.size() == 0) {
if (import_support_test.is_empty()) {
return false; //well nothing to do
}
@ -905,7 +905,7 @@ bool EditorFileSystem::_update_scan_actions() {
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 ResourceUID::ID new_id = ResourceUID::get_singleton()->create_id();
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));
@ -913,6 +913,12 @@ bool EditorFileSystem::_update_scan_actions() {
// Re-assign the UID to file, just in case it was pulled from cache.
ResourceSaver::set_uid(new_file_path, existing_id);
}
} else if (ResourceLoader::should_create_uid_file(new_file_path)) {
Ref<FileAccess> f = FileAccess::open(new_file_path + ".uid", FileAccess::WRITE);
if (f.is_valid()) {
ia.new_file->uid = ResourceUID::get_singleton()->create_id_for_path(new_file_path);
f->store_line(ResourceUID::get_singleton()->id_to_text(ia.new_file->uid));
}
}
if (ClassDB::is_parent_class(ia.new_file->type, SNAME("Script"))) {
@ -927,15 +933,16 @@ bool EditorFileSystem::_update_scan_actions() {
int idx = ia.dir->find_file_index(ia.file);
ERR_CONTINUE(idx == -1);
String class_name = ia.dir->files[idx]->class_info.name;
const String file_path = ia.dir->get_file_path(idx);
const String class_name = ia.dir->files[idx]->class_info.name;
if (ClassDB::is_parent_class(ia.dir->files[idx]->type, SNAME("Script"))) {
_queue_update_script_class(ia.dir->get_file_path(idx), ScriptClassInfoUpdate());
_queue_update_script_class(file_path, ScriptClassInfoUpdate());
}
if (ia.dir->files[idx]->type == SNAME("PackedScene")) {
_queue_update_scene_groups(ia.dir->get_file_path(idx));
_queue_update_scene_groups(file_path);
}
_delete_internal_files(ia.dir->files[idx]->file);
_delete_internal_files(file_path);
memdelete(ia.dir->files[idx]);
ia.dir->files.remove_at(idx);
@ -963,7 +970,7 @@ bool EditorFileSystem::_update_scan_actions() {
Vector<String> dependencies = _get_dependencies(full_path);
for (const String &dep : dependencies) {
const String &dependency_path = dep.contains("::") ? dep.get_slice("::", 0) : dep;
if (import_extensions.has(dep.get_extension())) {
if (_can_import_file(dep)) {
reimports.push_back(dependency_path);
}
}
@ -1061,6 +1068,19 @@ void EditorFileSystem::scan() {
// to be loaded to continue the scan and reimportations.
if (first_scan) {
_first_scan_filesystem();
#ifdef ANDROID_ENABLED
const String nomedia_file_path = ProjectSettings::get_singleton()->get_resource_path().path_join(".nomedia");
if (!FileAccess::exists(nomedia_file_path)) {
// Create a .nomedia file to hide assets from media apps on Android.
Ref<FileAccess> f = FileAccess::open(nomedia_file_path, FileAccess::WRITE);
if (f.is_null()) {
// .nomedia isn't so critical.
ERR_PRINT("Couldn't create .nomedia in project path.");
} else {
f->close();
}
}
#endif
}
_update_extensions();
@ -1145,15 +1165,15 @@ int EditorFileSystem::_scan_new_dir(ScannedDirectory *p_dir, Ref<DirAccess> &da)
int nb_files_total_scan = 0;
for (List<String>::Element *E = dirs.front(); E; E = E->next()) {
if (da->change_dir(E->get()) == OK) {
for (const String &dir : dirs) {
if (da->change_dir(dir) == OK) {
String d = da->get_current_dir();
if (d == cd || !d.begins_with(cd)) {
da->change_dir(cd); //avoid recursion
} else {
ScannedDirectory *sd = memnew(ScannedDirectory);
sd->name = E->get();
sd->name = dir;
sd->full_path = p_dir->full_path.path_join(sd->name);
nb_files_total_scan += _scan_new_dir(sd, da);
@ -1163,7 +1183,7 @@ int EditorFileSystem::_scan_new_dir(ScannedDirectory *p_dir, Ref<DirAccess> &da)
da->change_dir("..");
}
} else {
ERR_PRINT("Cannot go into subdir '" + E->get() + "'.");
ERR_PRINT("Cannot go into subdir '" + dir + "'.");
}
}
@ -1204,7 +1224,7 @@ void EditorFileSystem::_process_file_system(const ScannedDirectory *p_scan_dir,
FileCache *fc = file_cache.getptr(path);
uint64_t mt = FileAccess::get_modified_time(path);
if (import_extensions.has(ext)) {
if (_can_import_file(scan_file)) {
//is imported
uint64_t import_mt = FileAccess::get_modified_time(path + ".import");
@ -1333,7 +1353,7 @@ void EditorFileSystem::_process_file_system(const ScannedDirectory *p_scan_dir,
Ref<FileAccess> f = FileAccess::open(path + ".uid", FileAccess::WRITE);
if (f.is_valid()) {
if (fi->uid == ResourceUID::INVALID_ID) {
fi->uid = ResourceUID::get_singleton()->create_id();
fi->uid = ResourceUID::get_singleton()->create_id_for_path(path);
} else {
WARN_PRINT(vformat("Missing .uid file for path \"%s\". The file was re-created from cache.", path));
}
@ -1494,7 +1514,7 @@ void EditorFileSystem::_scan_fs_changes(EditorFileSystemDirectory *p_dir, ScanPr
scan_actions.push_back(ia);
}
if (import_extensions.has(ext)) {
if (_can_import_file(f)) {
//if it can be imported, and it was added, it needs to be reimported
ItemAction ia;
ia.action = ItemAction::ACTION_FILE_TEST_REIMPORT;
@ -1526,7 +1546,7 @@ void EditorFileSystem::_scan_fs_changes(EditorFileSystemDirectory *p_dir, ScanPr
String path = cd.path_join(p_dir->files[i]->file);
if (import_extensions.has(p_dir->files[i]->file.get_extension().to_lower())) {
if (_can_import_file(p_dir->files[i]->file)) {
// Check here if file must be imported or not.
// Same logic as in _process_file_system, the last modifications dates
// needs to be trusted to prevent reading all the .import files and the md5
@ -1846,12 +1866,12 @@ bool EditorFileSystem::_find_file(const String &p_file, EditorFileSystemDirector
if (!f.begins_with("res://")) {
return false;
}
f = f.substr(6, f.length());
f = f.replace("\\", "/");
f = f.substr(6);
f = f.replace_char('\\', '/');
Vector<String> path = f.split("/");
if (path.size() == 0) {
if (path.is_empty()) {
return false;
}
String file = path[path.size() - 1];
@ -1972,8 +1992,8 @@ EditorFileSystemDirectory *EditorFileSystem::get_filesystem_path(const String &p
return nullptr;
}
f = f.substr(6, f.length());
f = f.replace("\\", "/");
f = f.substr(6);
f = f.replace_char('\\', '/');
if (f.is_empty()) {
return filesystem;
}
@ -1984,7 +2004,7 @@ EditorFileSystemDirectory *EditorFileSystem::get_filesystem_path(const String &p
Vector<String> path = f.split("/");
if (path.size() == 0) {
if (path.is_empty()) {
return nullptr;
}
@ -2171,6 +2191,7 @@ void EditorFileSystem::_update_script_documentation() {
if (!efd || index < 0) {
// The file was removed
EditorHelp::remove_script_doc_by_path(path);
continue;
}
@ -2188,7 +2209,7 @@ void EditorFileSystem::_update_script_documentation() {
scr->reload_from_file();
}
for (const DocData::ClassDoc &cd : scr->get_documentation()) {
EditorHelp::get_doc_data()->add_doc(cd);
EditorHelp::add_doc(cd);
if (!first_scan) {
// Update the documentation in the Script Editor if it is open.
ScriptEditor::get_singleton()->update_doc(cd.name);
@ -2421,7 +2442,7 @@ void EditorFileSystem::update_files(const Vector<String> &p_script_paths) {
if (ResourceLoader::should_create_uid_file(file)) {
Ref<FileAccess> f = FileAccess::open(file + ".uid", FileAccess::WRITE);
if (f.is_valid()) {
const ResourceUID::ID id = ResourceUID::get_singleton()->create_id();
const ResourceUID::ID id = ResourceUID::get_singleton()->create_id_for_path(file);
ResourceUID::get_singleton()->add_id(id, file);
f->store_line(ResourceUID::get_singleton()->id_to_text(id));
fi->uid = id;
@ -2609,7 +2630,7 @@ Error EditorFileSystem::_reimport_group(const String &p_group_file, const Vector
}
if (uid == ResourceUID::INVALID_ID) {
uid = ResourceUID::get_singleton()->create_id();
uid = ResourceUID::get_singleton()->create_id_for_path(file);
}
f->store_line("uid=\"" + ResourceUID::get_singleton()->id_to_text(uid) + "\""); // Store in readable format.
@ -2799,7 +2820,7 @@ Error EditorFileSystem::_reimport_file(const String &p_file, const HashMap<Strin
if (importer.is_null()) {
//not found by name, find by extension
importer = ResourceFormatImporter::get_singleton()->get_importer_by_extension(p_file.get_extension());
importer = ResourceFormatImporter::get_singleton()->get_importer_by_file(p_file);
load_default = true;
if (importer.is_null()) {
ERR_FAIL_V_MSG(ERR_FILE_CANT_OPEN, "BUG: File queued for import, but can't be imported, importer for type '" + importer_name + "' not found.");
@ -2824,16 +2845,14 @@ Error EditorFileSystem::_reimport_file(const String &p_file, const HashMap<Strin
if (load_default && ProjectSettings::get_singleton()->has_setting("importer_defaults/" + importer->get_importer_name())) {
//use defaults if exist
Dictionary d = GLOBAL_GET("importer_defaults/" + importer->get_importer_name());
List<Variant> v;
d.get_key_list(&v);
for (const Variant &E : v) {
params[E] = d[E];
for (const KeyValue<Variant, Variant> &kv : d) {
params[kv.key] = kv.value;
}
}
if (uid == ResourceUID::INVALID_ID) {
uid = ResourceUID::get_singleton()->create_id();
uid = ResourceUID::get_singleton()->create_id_for_path(p_file);
}
//finally, perform import!!
@ -3093,7 +3112,7 @@ void EditorFileSystem::_queue_refresh_filesystem() {
void EditorFileSystem::_refresh_filesystem() {
for (const ObjectID &id : folders_to_sort) {
EditorFileSystemDirectory *dir = Object::cast_to<EditorFileSystemDirectory>(ObjectDB::get_instance(id));
EditorFileSystemDirectory *dir = ObjectDB::get_instance<EditorFileSystemDirectory>(id);
if (dir) {
dir->subdirs.sort_custom<DirectoryComparator>();
}
@ -3107,8 +3126,11 @@ void EditorFileSystem::_refresh_filesystem() {
}
void EditorFileSystem::_reimport_thread(uint32_t p_index, ImportThreadData *p_import_data) {
ResourceLoader::set_is_import_thread(true);
int file_idx = p_import_data->reimport_from + int(p_index);
_reimport_file(p_import_data->reimport_files[file_idx].path);
ResourceLoader::set_is_import_thread(false);
p_import_data->imported_sem->post();
}
@ -3437,7 +3459,7 @@ Error EditorFileSystem::make_dir_recursive(const String &p_path, const String &p
ERR_FAIL_NULL_V(parent, ERR_FILE_NOT_FOUND);
folders_to_sort.insert(parent->get_instance_id());
const PackedStringArray folders = p_path.trim_prefix(path).trim_suffix("/").split("/");
const PackedStringArray folders = p_path.trim_prefix(path).split("/", false);
for (const String &folder : folders) {
const int current = parent->find_dir_index(folder);
if (current > -1) {
@ -3519,14 +3541,14 @@ ResourceUID::ID EditorFileSystem::_resource_saver_get_resource_id_for_path(const
}
if (p_generate) {
return ResourceUID::get_singleton()->create_id(); // Just create a new one, we will be notified of save anyway and fetch the right UID at that time, to keep things simple.
return ResourceUID::get_singleton()->create_id_for_path(p_path); // Just create a new one, we will be notified of save anyway and fetch the right UID at that time, to keep things simple.
} else {
return ResourceUID::INVALID_ID;
}
} else if (fs->files[cpos]->uid != ResourceUID::INVALID_ID) {
return fs->files[cpos]->uid;
} else if (p_generate) {
return ResourceUID::get_singleton()->create_id(); // Just create a new one, we will be notified of save anyway and fetch the right UID at that time, to keep things simple.
return ResourceUID::get_singleton()->create_id_for_path(p_path); // Just create a new one, we will be notified of save anyway and fetch the right UID at that time, to keep things simple.
} else {
return ResourceUID::INVALID_ID;
}
@ -3604,10 +3626,20 @@ void EditorFileSystem::_update_extensions() {
extensionsl.clear();
ResourceFormatImporter::get_singleton()->get_recognized_extensions(&extensionsl);
for (const String &E : extensionsl) {
import_extensions.insert(E);
import_extensions.insert(!E.begins_with(".") ? "." + E : E);
}
}
bool EditorFileSystem::_can_import_file(const String &p_file) {
for (const String &F : import_extensions) {
if (p_file.right(F.length()).nocasecmp_to(F) == 0) {
return true;
}
}
return false;
}
void EditorFileSystem::add_import_format_support_query(Ref<EditorFileSystemImportFormatSupportQuery> p_query) {
ERR_FAIL_COND(import_support_queries.has(p_query));
import_support_queries.push_back(p_query);