mirror of
https://github.com/godotengine/godot.git
synced 2026-01-05 06:11:29 +03:00
Removed interactive loader, added proper thread loading.
This commit is contained in:
@@ -45,17 +45,17 @@
|
||||
|
||||
///
|
||||
|
||||
void ResourceInteractiveLoaderText::set_local_path(const String &p_local_path) {
|
||||
void ResourceLoaderText::set_local_path(const String &p_local_path) {
|
||||
|
||||
res_path = p_local_path;
|
||||
}
|
||||
|
||||
Ref<Resource> ResourceInteractiveLoaderText::get_resource() {
|
||||
Ref<Resource> ResourceLoaderText::get_resource() {
|
||||
|
||||
return resource;
|
||||
}
|
||||
|
||||
Error ResourceInteractiveLoaderText::_parse_sub_resource_dummy(DummyReadData *p_data, VariantParser::Stream *p_stream, Ref<Resource> &r_res, int &line, String &r_err_str) {
|
||||
Error ResourceLoaderText::_parse_sub_resource_dummy(DummyReadData *p_data, VariantParser::Stream *p_stream, Ref<Resource> &r_res, int &line, String &r_err_str) {
|
||||
|
||||
VariantParser::Token token;
|
||||
VariantParser::get_token(p_stream, token, line, r_err_str);
|
||||
@@ -85,7 +85,7 @@ Error ResourceInteractiveLoaderText::_parse_sub_resource_dummy(DummyReadData *p_
|
||||
return OK;
|
||||
}
|
||||
|
||||
Error ResourceInteractiveLoaderText::_parse_ext_resource_dummy(DummyReadData *p_data, VariantParser::Stream *p_stream, Ref<Resource> &r_res, int &line, String &r_err_str) {
|
||||
Error ResourceLoaderText::_parse_ext_resource_dummy(DummyReadData *p_data, VariantParser::Stream *p_stream, Ref<Resource> &r_res, int &line, String &r_err_str) {
|
||||
|
||||
VariantParser::Token token;
|
||||
VariantParser::get_token(p_stream, token, line, r_err_str);
|
||||
@@ -109,7 +109,7 @@ Error ResourceInteractiveLoaderText::_parse_ext_resource_dummy(DummyReadData *p_
|
||||
return OK;
|
||||
}
|
||||
|
||||
Error ResourceInteractiveLoaderText::_parse_sub_resource(VariantParser::Stream *p_stream, Ref<Resource> &r_res, int &line, String &r_err_str) {
|
||||
Error ResourceLoaderText::_parse_sub_resource(VariantParser::Stream *p_stream, Ref<Resource> &r_res, int &line, String &r_err_str) {
|
||||
|
||||
VariantParser::Token token;
|
||||
VariantParser::get_token(p_stream, token, line, r_err_str);
|
||||
@@ -143,7 +143,7 @@ Error ResourceInteractiveLoaderText::_parse_sub_resource(VariantParser::Stream *
|
||||
return OK;
|
||||
}
|
||||
|
||||
Error ResourceInteractiveLoaderText::_parse_ext_resource(VariantParser::Stream *p_stream, Ref<Resource> &r_res, int &line, String &r_err_str) {
|
||||
Error ResourceLoaderText::_parse_ext_resource(VariantParser::Stream *p_stream, Ref<Resource> &r_res, int &line, String &r_err_str) {
|
||||
|
||||
VariantParser::Token token;
|
||||
VariantParser::get_token(p_stream, token, line, r_err_str);
|
||||
@@ -164,15 +164,30 @@ Error ResourceInteractiveLoaderText::_parse_ext_resource(VariantParser::Stream *
|
||||
String path = ext_resources[id].path;
|
||||
String type = ext_resources[id].type;
|
||||
|
||||
if (path.find("://") == -1 && path.is_rel_path()) {
|
||||
// path is relative to file being loaded, so convert to a resource path
|
||||
path = ProjectSettings::get_singleton()->localize_path(res_path.get_base_dir().plus_file(path));
|
||||
}
|
||||
if (ext_resources[id].cache.is_valid()) {
|
||||
r_res = ext_resources[id].cache;
|
||||
} else if (use_sub_threads) {
|
||||
|
||||
r_res = ResourceLoader::load(path, type);
|
||||
RES res = ResourceLoader::load_threaded_get(path);
|
||||
if (res.is_null()) {
|
||||
|
||||
if (r_res.is_null()) {
|
||||
WARN_PRINT(String("Couldn't load external resource: " + path).utf8().get_data());
|
||||
if (ResourceLoader::get_abort_on_missing_resources()) {
|
||||
error = ERR_FILE_CORRUPT;
|
||||
error_text = "[ext_resource] referenced nonexistent resource at: " + path;
|
||||
_printerr();
|
||||
return error;
|
||||
} else {
|
||||
ResourceLoader::notify_dependency_error(local_path, path, type);
|
||||
}
|
||||
} else {
|
||||
ext_resources[id].cache = res;
|
||||
r_res = res;
|
||||
}
|
||||
} else {
|
||||
error = ERR_FILE_CORRUPT;
|
||||
error_text = "[ext_resource] referenced non-loaded resource at: " + path;
|
||||
_printerr();
|
||||
return error;
|
||||
}
|
||||
} else {
|
||||
r_res = RES();
|
||||
@@ -187,7 +202,7 @@ Error ResourceInteractiveLoaderText::_parse_ext_resource(VariantParser::Stream *
|
||||
return OK;
|
||||
}
|
||||
|
||||
Ref<PackedScene> ResourceInteractiveLoaderText::_parse_node_tag(VariantParser::ResourceParser &parser) {
|
||||
Ref<PackedScene> ResourceLoaderText::_parse_node_tag(VariantParser::ResourceParser &parser) {
|
||||
Ref<PackedScene> packed_scene;
|
||||
packed_scene.instance();
|
||||
|
||||
@@ -321,7 +336,7 @@ Ref<PackedScene> ResourceInteractiveLoaderText::_parse_node_tag(VariantParser::R
|
||||
NodePath to = next_tag.fields["to"];
|
||||
StringName method = next_tag.fields["method"];
|
||||
StringName signal = next_tag.fields["signal"];
|
||||
int flags = CONNECT_PERSIST;
|
||||
int flags = Object::CONNECT_PERSIST;
|
||||
Array binds;
|
||||
|
||||
if (next_tag.fields.has("flags")) {
|
||||
@@ -389,12 +404,15 @@ Ref<PackedScene> ResourceInteractiveLoaderText::_parse_node_tag(VariantParser::R
|
||||
return packed_scene;
|
||||
}
|
||||
|
||||
Error ResourceInteractiveLoaderText::poll() {
|
||||
Error ResourceLoaderText::load() {
|
||||
|
||||
if (error != OK)
|
||||
return error;
|
||||
|
||||
if (next_tag.name == "ext_resource") {
|
||||
while (true) {
|
||||
if (next_tag.name != "ext_resource") {
|
||||
break;
|
||||
}
|
||||
|
||||
if (!next_tag.fields.has("path")) {
|
||||
error = ERR_FILE_CORRUPT;
|
||||
@@ -430,30 +448,49 @@ Error ResourceInteractiveLoaderText::poll() {
|
||||
path = remaps[path];
|
||||
}
|
||||
|
||||
RES res = ResourceLoader::load(path, type);
|
||||
|
||||
if (res.is_null()) {
|
||||
|
||||
if (ResourceLoader::get_abort_on_missing_resources()) {
|
||||
error = ERR_FILE_CORRUPT;
|
||||
error_text = "[ext_resource] referenced nonexistent resource at: " + path;
|
||||
_printerr();
|
||||
return error;
|
||||
} else {
|
||||
ResourceLoader::notify_dependency_error(local_path, path, type);
|
||||
}
|
||||
} else {
|
||||
|
||||
resource_cache.push_back(res);
|
||||
#ifdef TOOLS_ENABLED
|
||||
//remember ID for saving
|
||||
res->set_id_for_path(local_path, index);
|
||||
#endif
|
||||
}
|
||||
|
||||
ExtResource er;
|
||||
er.path = path;
|
||||
er.type = type;
|
||||
|
||||
if (use_sub_threads) {
|
||||
|
||||
Error err = ResourceLoader::load_threaded_request(path, type, use_sub_threads, local_path);
|
||||
|
||||
if (err != OK) {
|
||||
if (ResourceLoader::get_abort_on_missing_resources()) {
|
||||
error = ERR_FILE_CORRUPT;
|
||||
error_text = "[ext_resource] referenced broken resource at: " + path;
|
||||
_printerr();
|
||||
return error;
|
||||
} else {
|
||||
ResourceLoader::notify_dependency_error(local_path, path, type);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
RES res = ResourceLoader::load(path, type);
|
||||
|
||||
if (res.is_null()) {
|
||||
|
||||
if (ResourceLoader::get_abort_on_missing_resources()) {
|
||||
error = ERR_FILE_CORRUPT;
|
||||
error_text = "[ext_resource] referenced nonexistent resource at: " + path;
|
||||
_printerr();
|
||||
return error;
|
||||
} else {
|
||||
ResourceLoader::notify_dependency_error(local_path, path, type);
|
||||
}
|
||||
} else {
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
//remember ID for saving
|
||||
res->set_id_for_path(local_path, index);
|
||||
#endif
|
||||
}
|
||||
|
||||
er.cache = res;
|
||||
}
|
||||
|
||||
ext_resources[index] = er;
|
||||
|
||||
error = VariantParser::parse_tag(&stream, lines, error_text, next_tag, &rp);
|
||||
@@ -463,9 +500,16 @@ Error ResourceInteractiveLoaderText::poll() {
|
||||
}
|
||||
|
||||
resource_current++;
|
||||
return error;
|
||||
}
|
||||
|
||||
} else if (next_tag.name == "sub_resource") {
|
||||
//these are the ones that count
|
||||
resources_total -= resource_current;
|
||||
resource_current = 0;
|
||||
|
||||
while (true) {
|
||||
if (next_tag.name != "sub_resource") {
|
||||
break;
|
||||
}
|
||||
|
||||
if (!next_tag.fields.has("type")) {
|
||||
error = ERR_FILE_CORRUPT;
|
||||
@@ -546,9 +590,15 @@ Error ResourceInteractiveLoaderText::poll() {
|
||||
}
|
||||
}
|
||||
|
||||
return OK;
|
||||
if (progress) {
|
||||
*progress = resource_current / float(resources_total);
|
||||
}
|
||||
}
|
||||
|
||||
} else if (next_tag.name == "resource") {
|
||||
while (true) {
|
||||
if (next_tag.name != "resource") {
|
||||
break;
|
||||
}
|
||||
|
||||
if (is_scene) {
|
||||
|
||||
@@ -609,14 +659,23 @@ Error ResourceInteractiveLoaderText::poll() {
|
||||
_printerr();
|
||||
return error;
|
||||
} else {
|
||||
error = ERR_FILE_EOF;
|
||||
error = OK;
|
||||
if (progress) {
|
||||
*progress = resource_current / float(resources_total);
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
return OK;
|
||||
if (progress) {
|
||||
*progress = resource_current / float(resources_total);
|
||||
}
|
||||
}
|
||||
|
||||
} else if (next_tag.name == "node") {
|
||||
//for scene files
|
||||
|
||||
if (next_tag.name == "node") {
|
||||
|
||||
if (!is_scene) {
|
||||
|
||||
@@ -631,49 +690,54 @@ Error ResourceInteractiveLoaderText::poll() {
|
||||
if (!packed_scene.is_valid())
|
||||
return error;
|
||||
|
||||
error = ERR_FILE_EOF;
|
||||
error = OK;
|
||||
//get it here
|
||||
resource = packed_scene;
|
||||
if (!ResourceCache::has(res_path)) {
|
||||
packed_scene->set_path(res_path);
|
||||
}
|
||||
|
||||
return error;
|
||||
resource_current++;
|
||||
|
||||
if (progress) {
|
||||
*progress = resource_current / float(resources_total);
|
||||
}
|
||||
|
||||
return error;
|
||||
} else {
|
||||
error_text += "Unknown tag in file: " + next_tag.name;
|
||||
_printerr();
|
||||
error = ERR_FILE_CORRUPT;
|
||||
return error;
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
int ResourceInteractiveLoaderText::get_stage() const {
|
||||
int ResourceLoaderText::get_stage() const {
|
||||
|
||||
return resource_current;
|
||||
}
|
||||
int ResourceInteractiveLoaderText::get_stage_count() const {
|
||||
int ResourceLoaderText::get_stage_count() const {
|
||||
|
||||
return resources_total; //+ext_resources;
|
||||
}
|
||||
|
||||
void ResourceInteractiveLoaderText::set_translation_remapped(bool p_remapped) {
|
||||
void ResourceLoaderText::set_translation_remapped(bool p_remapped) {
|
||||
|
||||
translation_remapped = p_remapped;
|
||||
}
|
||||
|
||||
ResourceInteractiveLoaderText::ResourceInteractiveLoaderText() {
|
||||
ResourceLoaderText::ResourceLoaderText() {
|
||||
progress = nullptr;
|
||||
translation_remapped = false;
|
||||
use_sub_threads = false;
|
||||
}
|
||||
|
||||
ResourceInteractiveLoaderText::~ResourceInteractiveLoaderText() {
|
||||
ResourceLoaderText::~ResourceLoaderText() {
|
||||
|
||||
memdelete(f);
|
||||
}
|
||||
|
||||
void ResourceInteractiveLoaderText::get_dependencies(FileAccess *p_f, List<String> *p_dependencies, bool p_add_types) {
|
||||
void ResourceLoaderText::get_dependencies(FileAccess *p_f, List<String> *p_dependencies, bool p_add_types) {
|
||||
|
||||
open(p_f);
|
||||
ignore_resource_parsing = true;
|
||||
@@ -720,7 +784,7 @@ void ResourceInteractiveLoaderText::get_dependencies(FileAccess *p_f, List<Strin
|
||||
}
|
||||
}
|
||||
|
||||
Error ResourceInteractiveLoaderText::rename_dependencies(FileAccess *p_f, const String &p_path, const Map<String, String> &p_map) {
|
||||
Error ResourceLoaderText::rename_dependencies(FileAccess *p_f, const String &p_path, const Map<String, String> &p_map) {
|
||||
|
||||
open(p_f, true);
|
||||
ERR_FAIL_COND_V(error != OK, error);
|
||||
@@ -822,7 +886,7 @@ Error ResourceInteractiveLoaderText::rename_dependencies(FileAccess *p_f, const
|
||||
return OK;
|
||||
}
|
||||
|
||||
void ResourceInteractiveLoaderText::open(FileAccess *p_f, bool p_skip_first_tag) {
|
||||
void ResourceLoaderText::open(FileAccess *p_f, bool p_skip_first_tag) {
|
||||
|
||||
error = OK;
|
||||
|
||||
@@ -908,7 +972,7 @@ static void bs_save_unicode_string(FileAccess *f, const String &p_string, bool p
|
||||
f->store_buffer((const uint8_t *)utf8.get_data(), utf8.length() + 1);
|
||||
}
|
||||
|
||||
Error ResourceInteractiveLoaderText::save_as_binary(FileAccess *p_f, const String &p_path) {
|
||||
Error ResourceLoaderText::save_as_binary(FileAccess *p_f, const String &p_path) {
|
||||
|
||||
if (error)
|
||||
return error;
|
||||
@@ -1172,7 +1236,7 @@ Error ResourceInteractiveLoaderText::save_as_binary(FileAccess *p_f, const Strin
|
||||
return OK;
|
||||
}
|
||||
|
||||
String ResourceInteractiveLoaderText::recognize(FileAccess *p_f) {
|
||||
String ResourceLoaderText::recognize(FileAccess *p_f) {
|
||||
|
||||
error = OK;
|
||||
|
||||
@@ -1217,24 +1281,34 @@ String ResourceInteractiveLoaderText::recognize(FileAccess *p_f) {
|
||||
|
||||
/////////////////////
|
||||
|
||||
Ref<ResourceInteractiveLoader> ResourceFormatLoaderText::load_interactive(const String &p_path, const String &p_original_path, Error *r_error) {
|
||||
RES ResourceFormatLoaderText::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress) {
|
||||
|
||||
if (r_error)
|
||||
*r_error = ERR_CANT_OPEN;
|
||||
|
||||
Error err;
|
||||
|
||||
FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err);
|
||||
|
||||
ERR_FAIL_COND_V_MSG(err != OK, Ref<ResourceInteractiveLoader>(), "Cannot open file '" + p_path + "'.");
|
||||
ERR_FAIL_COND_V_MSG(err != OK, RES(), "Cannot open file '" + p_path + "'.");
|
||||
|
||||
Ref<ResourceInteractiveLoaderText> ria = memnew(ResourceInteractiveLoaderText);
|
||||
ResourceLoaderText loader;
|
||||
String path = p_original_path != "" ? p_original_path : p_path;
|
||||
ria->local_path = ProjectSettings::get_singleton()->localize_path(path);
|
||||
ria->res_path = ria->local_path;
|
||||
//ria->set_local_path( ProjectSettings::get_singleton()->localize_path(p_path) );
|
||||
ria->open(f);
|
||||
|
||||
return ria;
|
||||
loader.use_sub_threads = p_use_sub_threads;
|
||||
loader.local_path = ProjectSettings::get_singleton()->localize_path(path);
|
||||
loader.progress = r_progress;
|
||||
loader.res_path = loader.local_path;
|
||||
//loader.set_local_path( ProjectSettings::get_singleton()->localize_path(p_path) );
|
||||
loader.open(f);
|
||||
err = loader.load();
|
||||
if (r_error) {
|
||||
*r_error = err;
|
||||
}
|
||||
if (err == OK) {
|
||||
return loader.get_resource();
|
||||
} else {
|
||||
return RES();
|
||||
}
|
||||
}
|
||||
|
||||
void ResourceFormatLoaderText::get_recognized_extensions_for_type(const String &p_type, List<String> *p_extensions) const {
|
||||
@@ -1276,11 +1350,11 @@ String ResourceFormatLoaderText::get_resource_type(const String &p_path) const {
|
||||
return ""; //could not rwead
|
||||
}
|
||||
|
||||
Ref<ResourceInteractiveLoaderText> ria = memnew(ResourceInteractiveLoaderText);
|
||||
ria->local_path = ProjectSettings::get_singleton()->localize_path(p_path);
|
||||
ria->res_path = ria->local_path;
|
||||
//ria->set_local_path( ProjectSettings::get_singleton()->localize_path(p_path) );
|
||||
String r = ria->recognize(f);
|
||||
ResourceLoaderText loader;
|
||||
loader.local_path = ProjectSettings::get_singleton()->localize_path(p_path);
|
||||
loader.res_path = loader.local_path;
|
||||
//loader.set_local_path( ProjectSettings::get_singleton()->localize_path(p_path) );
|
||||
String r = loader.recognize(f);
|
||||
return ClassDB::get_compatibility_remapped_class(r);
|
||||
}
|
||||
|
||||
@@ -1292,11 +1366,11 @@ void ResourceFormatLoaderText::get_dependencies(const String &p_path, List<Strin
|
||||
ERR_FAIL();
|
||||
}
|
||||
|
||||
Ref<ResourceInteractiveLoaderText> ria = memnew(ResourceInteractiveLoaderText);
|
||||
ria->local_path = ProjectSettings::get_singleton()->localize_path(p_path);
|
||||
ria->res_path = ria->local_path;
|
||||
//ria->set_local_path( ProjectSettings::get_singleton()->localize_path(p_path) );
|
||||
ria->get_dependencies(f, p_dependencies, p_add_types);
|
||||
ResourceLoaderText loader;
|
||||
loader.local_path = ProjectSettings::get_singleton()->localize_path(p_path);
|
||||
loader.res_path = loader.local_path;
|
||||
//loader.set_local_path( ProjectSettings::get_singleton()->localize_path(p_path) );
|
||||
loader.get_dependencies(f, p_dependencies, p_add_types);
|
||||
}
|
||||
|
||||
Error ResourceFormatLoaderText::rename_dependencies(const String &p_path, const Map<String, String> &p_map) {
|
||||
@@ -1307,11 +1381,11 @@ Error ResourceFormatLoaderText::rename_dependencies(const String &p_path, const
|
||||
ERR_FAIL_V(ERR_CANT_OPEN);
|
||||
}
|
||||
|
||||
Ref<ResourceInteractiveLoaderText> ria = memnew(ResourceInteractiveLoaderText);
|
||||
ria->local_path = ProjectSettings::get_singleton()->localize_path(p_path);
|
||||
ria->res_path = ria->local_path;
|
||||
//ria->set_local_path( ProjectSettings::get_singleton()->localize_path(p_path) );
|
||||
return ria->rename_dependencies(f, p_path, p_map);
|
||||
ResourceLoaderText loader;
|
||||
loader.local_path = ProjectSettings::get_singleton()->localize_path(p_path);
|
||||
loader.res_path = loader.local_path;
|
||||
//loader.set_local_path( ProjectSettings::get_singleton()->localize_path(p_path) );
|
||||
return loader.rename_dependencies(f, p_path, p_map);
|
||||
}
|
||||
|
||||
ResourceFormatLoaderText *ResourceFormatLoaderText::singleton = NULL;
|
||||
@@ -1323,13 +1397,13 @@ Error ResourceFormatLoaderText::convert_file_to_binary(const String &p_src_path,
|
||||
|
||||
ERR_FAIL_COND_V_MSG(err != OK, ERR_CANT_OPEN, "Cannot open file '" + p_src_path + "'.");
|
||||
|
||||
Ref<ResourceInteractiveLoaderText> ria = memnew(ResourceInteractiveLoaderText);
|
||||
ResourceLoaderText loader;
|
||||
const String &path = p_src_path;
|
||||
ria->local_path = ProjectSettings::get_singleton()->localize_path(path);
|
||||
ria->res_path = ria->local_path;
|
||||
//ria->set_local_path( ProjectSettings::get_singleton()->localize_path(p_path) );
|
||||
ria->open(f);
|
||||
return ria->save_as_binary(f, p_dst_path);
|
||||
loader.local_path = ProjectSettings::get_singleton()->localize_path(path);
|
||||
loader.res_path = loader.local_path;
|
||||
//loader.set_local_path( ProjectSettings::get_singleton()->localize_path(p_path) );
|
||||
loader.open(f);
|
||||
return loader.save_as_binary(f, p_dst_path);
|
||||
}
|
||||
|
||||
/*****************************************************************************************************/
|
||||
|
||||
Reference in New Issue
Block a user