mirror of
https://github.com/godotengine/godot.git
synced 2025-12-07 22:00:10 +00:00
Merge pull request #103352 from MartinDelille/remove_load_steps
Remove `load_steps` from `resource_format_text.cpp`
This commit is contained in:
commit
5947dff88a
2 changed files with 43 additions and 22 deletions
|
|
@ -418,11 +418,48 @@ Ref<PackedScene> ResourceLoaderText::_parse_node_tag(VariantParser::ResourcePars
|
|||
}
|
||||
}
|
||||
|
||||
void ResourceLoaderText::_count_resources() {
|
||||
resources_total = 0;
|
||||
resource_current = 0;
|
||||
|
||||
// Save current file position to restore after counting.
|
||||
uint64_t original_pos = f->get_position();
|
||||
|
||||
// Seek to beginning to count all resources.
|
||||
f->seek(0);
|
||||
|
||||
bool has_main_resource = false;
|
||||
while (!f->eof_reached()) {
|
||||
String line = f->get_line().strip_edges();
|
||||
|
||||
// Only count resources that contribute to progress
|
||||
// (ext_resources are loaded asynchronously and don't count).
|
||||
// Note: nodes are all parsed together as part of the main resource (PackedScene),
|
||||
// so they only contribute 1 to the progress count, not one per node.
|
||||
if (line.begins_with("[sub_resource ")) {
|
||||
resources_total++;
|
||||
} else if (line.begins_with("[resource]") || line.begins_with("[node ")) {
|
||||
// Main resource or scene with nodes - only count once.
|
||||
if (!has_main_resource) {
|
||||
resources_total++;
|
||||
has_main_resource = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Restore original file position.
|
||||
f->seek(original_pos);
|
||||
}
|
||||
|
||||
Error ResourceLoaderText::load() {
|
||||
if (error != OK) {
|
||||
return error;
|
||||
}
|
||||
|
||||
if (progress) {
|
||||
_count_resources();
|
||||
}
|
||||
|
||||
while (true) {
|
||||
if (next_tag.name != "ext_resource") {
|
||||
break;
|
||||
|
|
@ -500,8 +537,6 @@ Error ResourceLoaderText::load() {
|
|||
_printerr();
|
||||
return error;
|
||||
}
|
||||
|
||||
resource_current++;
|
||||
}
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
|
|
@ -511,10 +546,6 @@ Error ResourceLoaderText::load() {
|
|||
}
|
||||
#endif
|
||||
|
||||
//these are the ones that count
|
||||
resources_total -= resource_current;
|
||||
resource_current = 0;
|
||||
|
||||
while (true) {
|
||||
if (next_tag.name != "sub_resource") {
|
||||
break;
|
||||
|
|
@ -1001,13 +1032,13 @@ Error ResourceLoaderText::rename_dependencies(Ref<FileAccess> p_f, const String
|
|||
}
|
||||
|
||||
if (is_scene) {
|
||||
fw->store_line("[gd_scene load_steps=" + itos(resources_total) + " format=" + itos(format_version) + uid_text + "]\n");
|
||||
fw->store_line("[gd_scene format=" + itos(format_version) + uid_text + "]\n");
|
||||
} else {
|
||||
String script_res_text;
|
||||
if (!script_class.is_empty()) {
|
||||
script_res_text = "script_class=\"" + script_class + "\" ";
|
||||
}
|
||||
fw->store_line("[gd_resource type=\"" + res_type + "\" " + script_res_text + "load_steps=" + itos(resources_total) + " format=" + itos(format_version) + uid_text + "]\n");
|
||||
fw->store_line("[gd_resource type=\"" + res_type + "\" " + script_res_text + "format=" + itos(format_version) + uid_text + "]\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1098,7 +1129,6 @@ void ResourceLoaderText::open(Ref<FileAccess> p_f, bool p_skip_first_tag) {
|
|||
stream.f = f;
|
||||
is_scene = false;
|
||||
ignore_resource_parsing = false;
|
||||
resource_current = 0;
|
||||
|
||||
VariantParser::Tag tag;
|
||||
Error err = VariantParser::parse_tag(&stream, lines, error_text, tag);
|
||||
|
|
@ -1151,12 +1181,6 @@ void ResourceLoaderText::open(Ref<FileAccess> p_f, bool p_skip_first_tag) {
|
|||
res_uid = ResourceUID::INVALID_ID;
|
||||
}
|
||||
|
||||
if (tag.fields.has("load_steps")) {
|
||||
resources_total = tag.fields["load_steps"];
|
||||
} else {
|
||||
resources_total = 0;
|
||||
}
|
||||
|
||||
if (!p_skip_first_tag) {
|
||||
err = VariantParser::parse_tag(&stream, lines, error_text, next_tag, &rp);
|
||||
|
||||
|
|
@ -1774,11 +1798,6 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path, const Ref<Reso
|
|||
}
|
||||
}
|
||||
|
||||
int load_steps = saved_resources.size() + external_resources.size();
|
||||
|
||||
if (load_steps > 1) {
|
||||
title += "load_steps=" + itos(load_steps) + " ";
|
||||
}
|
||||
title += "format=" + itos(use_compat ? ResourceLoaderText::FORMAT_VERSION_COMPAT : ResourceLoaderText::FORMAT_VERSION) + "";
|
||||
|
||||
ResourceUID::ID uid = ResourceSaver::get_resource_id_for_path(local_path, true);
|
||||
|
|
@ -2139,14 +2158,14 @@ Error ResourceLoaderText::set_uid(Ref<FileAccess> p_f, ResourceUID::ID p_uid) {
|
|||
|
||||
fw = FileAccess::open(local_path + ".uidren", FileAccess::WRITE);
|
||||
if (is_scene) {
|
||||
fw->store_string("[gd_scene load_steps=" + itos(resources_total) + " format=" + itos(format_version) + " uid=\"" + ResourceUID::get_singleton()->id_to_text(p_uid) + "\"]");
|
||||
fw->store_string("[gd_scene format=" + itos(format_version) + " uid=\"" + ResourceUID::get_singleton()->id_to_text(p_uid) + "\"]");
|
||||
} else {
|
||||
String script_res_text;
|
||||
if (!script_class.is_empty()) {
|
||||
script_res_text = "script_class=\"" + script_class + "\" ";
|
||||
}
|
||||
|
||||
fw->store_string("[gd_resource type=\"" + res_type + "\" " + script_res_text + "load_steps=" + itos(resources_total) + " format=" + itos(format_version) + " uid=\"" + ResourceUID::get_singleton()->id_to_text(p_uid) + "\"]");
|
||||
fw->store_string("[gd_resource type=\"" + res_type + "\" " + script_res_text + "format=" + itos(format_version) + " uid=\"" + ResourceUID::get_singleton()->id_to_text(p_uid) + "\"]");
|
||||
}
|
||||
|
||||
uint8_t c = f->get_8();
|
||||
|
|
|
|||
|
|
@ -75,6 +75,7 @@ private:
|
|||
|
||||
int resources_total = 0;
|
||||
int resource_current = 0;
|
||||
|
||||
String resource_type;
|
||||
String script_class;
|
||||
|
||||
|
|
@ -97,6 +98,7 @@ private:
|
|||
|
||||
Error _parse_sub_resource(VariantParser::Stream *p_stream, Ref<Resource> &r_res, int &line, String &r_err_str);
|
||||
Error _parse_ext_resource(VariantParser::Stream *p_stream, Ref<Resource> &r_res, int &line, String &r_err_str);
|
||||
void _count_resources();
|
||||
|
||||
struct DummyReadData {
|
||||
bool no_placeholders = false;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue