Skip to content

Commit 67a1c8f

Browse files
committed
Remove load_steps from resource_format_text.cpp
1 parent 9dd6c4d commit 67a1c8f

File tree

2 files changed

+43
-22
lines changed

2 files changed

+43
-22
lines changed

scene/resources/resource_format_text.cpp

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -418,11 +418,48 @@ Ref<PackedScene> ResourceLoaderText::_parse_node_tag(VariantParser::ResourcePars
418418
}
419419
}
420420

421+
void ResourceLoaderText::_count_resources() {
422+
resources_total = 0;
423+
resource_current = 0;
424+
425+
// Save current file position to restore after counting.
426+
uint64_t original_pos = f->get_position();
427+
428+
// Seek to beginning to count all resources.
429+
f->seek(0);
430+
431+
bool has_main_resource = false;
432+
while (!f->eof_reached()) {
433+
String line = f->get_line().strip_edges();
434+
435+
// Only count resources that contribute to progress
436+
// (ext_resources are loaded asynchronously and don't count).
437+
// Note: nodes are all parsed together as part of the main resource (PackedScene),
438+
// so they only contribute 1 to the progress count, not one per node.
439+
if (line.begins_with("[sub_resource ")) {
440+
resources_total++;
441+
} else if (line.begins_with("[resource]") || line.begins_with("[node ")) {
442+
// Main resource or scene with nodes - only count once.
443+
if (!has_main_resource) {
444+
resources_total++;
445+
has_main_resource = true;
446+
}
447+
}
448+
}
449+
450+
// Restore original file position.
451+
f->seek(original_pos);
452+
}
453+
421454
Error ResourceLoaderText::load() {
422455
if (error != OK) {
423456
return error;
424457
}
425458

459+
if (progress) {
460+
_count_resources();
461+
}
462+
426463
while (true) {
427464
if (next_tag.name != "ext_resource") {
428465
break;
@@ -500,8 +537,6 @@ Error ResourceLoaderText::load() {
500537
_printerr();
501538
return error;
502539
}
503-
504-
resource_current++;
505540
}
506541

507542
#ifdef TOOLS_ENABLED
@@ -511,10 +546,6 @@ Error ResourceLoaderText::load() {
511546
}
512547
#endif
513548

514-
//these are the ones that count
515-
resources_total -= resource_current;
516-
resource_current = 0;
517-
518549
while (true) {
519550
if (next_tag.name != "sub_resource") {
520551
break;
@@ -1001,13 +1032,13 @@ Error ResourceLoaderText::rename_dependencies(Ref<FileAccess> p_f, const String
10011032
}
10021033

10031034
if (is_scene) {
1004-
fw->store_line("[gd_scene load_steps=" + itos(resources_total) + " format=" + itos(format_version) + uid_text + "]\n");
1035+
fw->store_line("[gd_scene format=" + itos(format_version) + uid_text + "]\n");
10051036
} else {
10061037
String script_res_text;
10071038
if (!script_class.is_empty()) {
10081039
script_res_text = "script_class=\"" + script_class + "\" ";
10091040
}
1010-
fw->store_line("[gd_resource type=\"" + res_type + "\" " + script_res_text + "load_steps=" + itos(resources_total) + " format=" + itos(format_version) + uid_text + "]\n");
1041+
fw->store_line("[gd_resource type=\"" + res_type + "\" " + script_res_text + "format=" + itos(format_version) + uid_text + "]\n");
10111042
}
10121043
}
10131044

@@ -1098,7 +1129,6 @@ void ResourceLoaderText::open(Ref<FileAccess> p_f, bool p_skip_first_tag) {
10981129
stream.f = f;
10991130
is_scene = false;
11001131
ignore_resource_parsing = false;
1101-
resource_current = 0;
11021132

11031133
VariantParser::Tag tag;
11041134
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) {
11511181
res_uid = ResourceUID::INVALID_ID;
11521182
}
11531183

1154-
if (tag.fields.has("load_steps")) {
1155-
resources_total = tag.fields["load_steps"];
1156-
} else {
1157-
resources_total = 0;
1158-
}
1159-
11601184
if (!p_skip_first_tag) {
11611185
err = VariantParser::parse_tag(&stream, lines, error_text, next_tag, &rp);
11621186

@@ -1774,11 +1798,6 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path, const Ref<Reso
17741798
}
17751799
}
17761800

1777-
int load_steps = saved_resources.size() + external_resources.size();
1778-
1779-
if (load_steps > 1) {
1780-
title += "load_steps=" + itos(load_steps) + " ";
1781-
}
17821801
title += "format=" + itos(use_compat ? ResourceLoaderText::FORMAT_VERSION_COMPAT : ResourceLoaderText::FORMAT_VERSION) + "";
17831802

17841803
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) {
21392158

21402159
fw = FileAccess::open(local_path + ".uidren", FileAccess::WRITE);
21412160
if (is_scene) {
2142-
fw->store_string("[gd_scene load_steps=" + itos(resources_total) + " format=" + itos(format_version) + " uid=\"" + ResourceUID::get_singleton()->id_to_text(p_uid) + "\"]");
2161+
fw->store_string("[gd_scene format=" + itos(format_version) + " uid=\"" + ResourceUID::get_singleton()->id_to_text(p_uid) + "\"]");
21432162
} else {
21442163
String script_res_text;
21452164
if (!script_class.is_empty()) {
21462165
script_res_text = "script_class=\"" + script_class + "\" ";
21472166
}
21482167

2149-
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) + "\"]");
2168+
fw->store_string("[gd_resource type=\"" + res_type + "\" " + script_res_text + "format=" + itos(format_version) + " uid=\"" + ResourceUID::get_singleton()->id_to_text(p_uid) + "\"]");
21502169
}
21512170

21522171
uint8_t c = f->get_8();

scene/resources/resource_format_text.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ class ResourceLoaderText {
7575

7676
int resources_total = 0;
7777
int resource_current = 0;
78+
7879
String resource_type;
7980
String script_class;
8081

@@ -97,6 +98,7 @@ class ResourceLoaderText {
9798

9899
Error _parse_sub_resource(VariantParser::Stream *p_stream, Ref<Resource> &r_res, int &line, String &r_err_str);
99100
Error _parse_ext_resource(VariantParser::Stream *p_stream, Ref<Resource> &r_res, int &line, String &r_err_str);
101+
void _count_resources();
100102

101103
struct DummyReadData {
102104
bool no_placeholders = false;

0 commit comments

Comments
 (0)