Skip to content

Commit 555d250

Browse files
committed
Add _start_load(), _finish_load() to Resource
1 parent 91027cf commit 555d250

5 files changed

Lines changed: 24 additions & 1 deletion

File tree

core/io/resource.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,10 @@ String Resource::get_id_for_path(const String &p_referrer_path) const {
730730
#endif
731731
}
732732

733+
void Resource::_start_load(const StringName &p_res_format_type, int p_res_format_version) {}
734+
735+
void Resource::_finish_load(const StringName &p_res_format_type, int p_res_format_version) {}
736+
733737
void Resource::_bind_methods() {
734738
ClassDB::bind_method(D_METHOD("set_path", "path"), &Resource::_set_path);
735739
ClassDB::bind_method(D_METHOD("take_over_path", "path"), &Resource::_take_over_path);

core/io/resource.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,9 @@ class Resource : public RefCounted {
188188
void set_id_for_path(const String &p_referrer_path, const String &p_id) { set_resource_id_for_path(p_referrer_path, get_path(), p_id); }
189189
String get_id_for_path(const String &p_referrer_path) const;
190190

191+
virtual void _start_load(const StringName &p_res_format_type, int p_res_format_version);
192+
virtual void _finish_load(const StringName &p_res_format_type, int p_res_format_version);
193+
191194
Resource();
192195
~Resource();
193196
};

core/io/resource_format_binary.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,8 @@ Error ResourceLoaderBinary::load() {
810810
internal_index_cache[path] = res;
811811
}
812812

813+
res->_start_load(SNAME("binary"), ver_format);
814+
813815
int pc = f->get_32();
814816

815817
//set properties
@@ -886,6 +888,8 @@ Error ResourceLoaderBinary::load() {
886888
res->set_edited(false);
887889
#endif
888890

891+
res->_finish_load(SNAME("binary"), ver_format);
892+
889893
if (progress) {
890894
*progress = (i + 1) / float(internal_resources.size());
891895
}

scene/resources/resource_format_text.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ Ref<PackedScene> ResourceLoaderText::_parse_node_tag(VariantParser::ResourcePars
186186
if (packed_scene.is_null()) {
187187
packed_scene.instantiate();
188188
}
189+
packed_scene->_start_load(SNAME("text"), format_version);
189190

190191
while (true) {
191192
if (next_tag.name == "node") {
@@ -294,6 +295,7 @@ Ref<PackedScene> ResourceLoaderText::_parse_node_tag(VariantParser::ResourcePars
294295
return Ref<PackedScene>();
295296
} else {
296297
error = OK;
298+
packed_scene->_finish_load(SNAME("text"), format_version);
297299
return packed_scene;
298300
}
299301
}
@@ -385,6 +387,7 @@ Ref<PackedScene> ResourceLoaderText::_parse_node_tag(VariantParser::ResourcePars
385387
return Ref<PackedScene>();
386388
} else {
387389
error = OK;
390+
packed_scene->_finish_load("text", format_version);
388391
return packed_scene;
389392
}
390393
}
@@ -408,6 +411,7 @@ Ref<PackedScene> ResourceLoaderText::_parse_node_tag(VariantParser::ResourcePars
408411
return Ref<PackedScene>();
409412
} else {
410413
error = OK;
414+
packed_scene->_finish_load("text", format_version);
411415
return packed_scene;
412416
}
413417
}
@@ -629,6 +633,7 @@ Error ResourceLoaderText::load() {
629633

630634
int_resources[id] = res; // Always assign int resources.
631635
if (do_assign) {
636+
res->_start_load(SNAME("text"), format_version);
632637
if (cache_mode != ResourceFormatLoader::CACHE_MODE_IGNORE) {
633638
res->set_path(path, cache_mode == ResourceFormatLoader::CACHE_MODE_REPLACE);
634639
} else {
@@ -714,6 +719,10 @@ Error ResourceLoaderText::load() {
714719
if (!missing_resource_properties.is_empty()) {
715720
res->set_meta(META_MISSING_RESOURCES, missing_resource_properties);
716721
}
722+
723+
if (do_assign) {
724+
res->_finish_load(SNAME("text"), format_version);
725+
}
717726
}
718727

719728
while (true) {
@@ -766,6 +775,8 @@ Error ResourceLoaderText::load() {
766775
}
767776
}
768777

778+
resource->_start_load(SNAME("text"), format_version);
779+
769780
Dictionary missing_resource_properties;
770781

771782
while (true) {
@@ -859,6 +870,7 @@ Error ResourceLoaderText::load() {
859870
if (!missing_resource_properties.is_empty()) {
860871
resource->set_meta(META_MISSING_RESOURCES, missing_resource_properties);
861872
}
873+
resource->_finish_load(SNAME("text"), format_version);
862874

863875
error = OK;
864876

scene/resources/resource_format_text.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class ResourceLoaderText {
6565
};
6666

6767
bool is_scene = false;
68-
int format_version;
68+
int format_version = 0;
6969
String res_type;
7070

7171
bool ignore_resource_parsing = false;

0 commit comments

Comments
 (0)