Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove old path remaps system #91594

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
84 changes: 30 additions & 54 deletions core/io/resource_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -953,41 +953,37 @@ String ResourceLoader::_path_remap(const String &p_path, bool *r_translation_rem
}
}

if (path_remaps.has(new_path)) {
new_path = path_remaps[new_path];
} else {
// Try file remap.
Error err;
Ref<FileAccess> f = FileAccess::open(new_path + ".remap", FileAccess::READ, &err);
if (f.is_valid()) {
VariantParser::StreamFile stream;
stream.f = f;

String assign;
Variant value;
VariantParser::Tag next_tag;

int lines = 0;
String error_text;
while (true) {
assign = Variant();
next_tag.fields.clear();
next_tag.name = String();

err = VariantParser::parse_tag_assign_eof(&stream, lines, error_text, next_tag, assign, value, nullptr, true);
if (err == ERR_FILE_EOF) {
break;
} else if (err != OK) {
ERR_PRINT("Parse error: " + p_path + ".remap:" + itos(lines) + " error: " + error_text + ".");
break;
}
// Try file remap.
Error err;
Ref<FileAccess> f = FileAccess::open(new_path + ".remap", FileAccess::READ, &err);
if (f.is_valid()) {
VariantParser::StreamFile stream;
stream.f = f;

String assign;
Variant value;
VariantParser::Tag next_tag;

int lines = 0;
String error_text;
while (true) {
assign = Variant();
next_tag.fields.clear();
next_tag.name = String();

err = VariantParser::parse_tag_assign_eof(&stream, lines, error_text, next_tag, assign, value, nullptr, true);
if (err == ERR_FILE_EOF) {
break;
} else if (err != OK) {
ERR_PRINT("Parse error: " + p_path + ".remap:" + itos(lines) + " error: " + error_text + ".");
break;
}

if (assign == "path") {
new_path = value;
break;
} else if (next_tag.name != "remap") {
break;
}
if (assign == "path") {
new_path = value;
break;
} else if (next_tag.name != "remap") {
break;
}
}
}
Expand Down Expand Up @@ -1095,25 +1091,6 @@ void ResourceLoader::clear_thread_load_tasks() {
thread_load_mutex.unlock();
}

void ResourceLoader::load_path_remaps() {
if (!ProjectSettings::get_singleton()->has_setting("path_remap/remapped_paths")) {
return;
}

Vector<String> remaps = GLOBAL_GET("path_remap/remapped_paths");
int rc = remaps.size();
ERR_FAIL_COND(rc & 1); //must be even
const String *r = remaps.ptr();

for (int i = 0; i < rc; i += 2) {
path_remaps[r[i]] = r[i + 1];
}
}

void ResourceLoader::clear_path_remaps() {
path_remaps.clear();
}

void ResourceLoader::set_load_callback(ResourceLoadedCallback p_callback) {
_loaded_callback = p_callback;
}
Expand Down Expand Up @@ -1218,6 +1195,5 @@ HashMap<String, ResourceLoader::LoadToken *> ResourceLoader::user_load_tokens;

SelfList<Resource>::List ResourceLoader::remapped_list;
HashMap<String, Vector<String>> ResourceLoader::translation_remaps;
HashMap<String, String> ResourceLoader::path_remaps;

ResourceLoaderImport ResourceLoader::import = nullptr;
4 changes: 0 additions & 4 deletions core/io/resource_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ class ResourceLoader {
static bool abort_on_missing_resource;
static bool create_missing_resources_if_class_unavailable;
static HashMap<String, Vector<String>> translation_remaps;
static HashMap<String, String> path_remaps;

static String _path_remap(const String &p_path, bool *r_translation_remapped = nullptr);
friend class Resource;
Expand Down Expand Up @@ -253,9 +252,6 @@ class ResourceLoader {
static String path_remap(const String &p_path);
static String import_remap(const String &p_path);

static void load_path_remaps();
static void clear_path_remaps();

static void reload_translation_remaps();
static void load_translation_remaps();
static void clear_translation_remaps();
Expand Down
1 change: 0 additions & 1 deletion editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6268,7 +6268,6 @@ EditorNode::EditorNode() {

SceneState::set_disable_placeholders(true);
ResourceLoader::clear_translation_remaps(); // Using no remaps if in editor.
ResourceLoader::clear_path_remaps();
ResourceLoader::set_create_missing_resources_if_class_unavailable(true);

EditorPropertyNameProcessor *epnp = memnew(EditorPropertyNameProcessor);
Expand Down
31 changes: 13 additions & 18 deletions editor/export/editor_export_platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1377,26 +1377,21 @@ Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> &

ProjectSettings::CustomMap custom_map;
if (path_remaps.size()) {
if (true) { //new remap mode, use always as it's friendlier with multiple .pck exports
for (int i = 0; i < path_remaps.size(); i += 2) {
const String &from = path_remaps[i];
const String &to = path_remaps[i + 1];
String remap_file = "[remap]\n\npath=\"" + to.c_escape() + "\"\n";
CharString utf8 = remap_file.utf8();
Vector<uint8_t> new_file;
new_file.resize(utf8.length());
for (int j = 0; j < utf8.length(); j++) {
new_file.write[j] = utf8[j];
}
for (int i = 0; i < path_remaps.size(); i += 2) {
const String &from = path_remaps[i];
const String &to = path_remaps[i + 1];
String remap_file = "[remap]\n\npath=\"" + to.c_escape() + "\"\n";
CharString utf8 = remap_file.utf8();
Vector<uint8_t> new_file;
new_file.resize(utf8.length());
for (int j = 0; j < utf8.length(); j++) {
new_file.write[j] = utf8[j];
}

err = p_func(p_udata, from + ".remap", new_file, idx, total, enc_in_filters, enc_ex_filters, key);
if (err != OK) {
return err;
}
err = p_func(p_udata, from + ".remap", new_file, idx, total, enc_in_filters, enc_ex_filters, key);
if (err != OK) {
return err;
}
} else {
//old remap mode, will still work, but it's unused because it's not multiple pck export friendly
custom_map["path_remap/remapped_paths"] = path_remaps;
}
}

Expand Down
5 changes: 0 additions & 5 deletions main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -710,8 +710,6 @@ Error Main::test_setup() {
translation_server->load_translations();
ResourceLoader::load_translation_remaps(); //load remaps for resources

ResourceLoader::load_path_remaps();

// Initialize ThemeDB early so that scene types can register their theme items.
// Default theme will be initialized later, after modules and ScriptServer are ready.
initialize_theme_db();
Expand Down Expand Up @@ -2968,8 +2966,6 @@ Error Main::setup2() {
translation_server->load_translations();
ResourceLoader::load_translation_remaps(); //load remaps for resources

ResourceLoader::load_path_remaps();

OS::get_singleton()->benchmark_end_measure("Startup", "Translations and Remaps");
}

Expand Down Expand Up @@ -4189,7 +4185,6 @@ void Main::cleanup(bool p_force) {
OS::get_singleton()->_local_clipboard = "";

ResourceLoader::clear_translation_remaps();
ResourceLoader::clear_path_remaps();

ScriptServer::finish_languages();

Expand Down