mirror of
https://github.com/enduro2d/enduro2d.git
synced 2026-04-30 07:53:04 +07:00
add library loading error messages
This commit is contained in:
@@ -15,6 +15,7 @@ namespace e2d
|
||||
{
|
||||
class atlas_asset final : public content_asset<atlas_asset, atlas> {
|
||||
public:
|
||||
static const char* type_name() noexcept { return "atlas_asset"; }
|
||||
static load_async_result load_async(const library& library, str_view address);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace e2d
|
||||
{
|
||||
class binary_asset final : public content_asset<binary_asset, buffer> {
|
||||
public:
|
||||
static const char* type_name() noexcept { return "binary_asset"; }
|
||||
static load_async_result load_async(const library& library, str_view address);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ namespace e2d
|
||||
{
|
||||
class flipbook_asset final : public content_asset<flipbook_asset, flipbook> {
|
||||
public:
|
||||
static const char* type_name() noexcept { return "flipbook_asset"; }
|
||||
static load_async_result load_async(const library& library, str_view address);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace e2d
|
||||
{
|
||||
class image_asset final : public content_asset<image_asset, image> {
|
||||
public:
|
||||
static const char* type_name() noexcept { return "image_asset"; }
|
||||
static load_async_result load_async(const library& library, str_view address);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ namespace e2d
|
||||
using json_uptr = std::unique_ptr<rapidjson::Document>;
|
||||
class json_asset final : public content_asset<json_asset, json_uptr> {
|
||||
public:
|
||||
static const char* type_name() noexcept { return "json_asset"; }
|
||||
static load_async_result load_async(const library& library, str_view address);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace e2d
|
||||
{
|
||||
class material_asset final : public content_asset<material_asset, render::material> {
|
||||
public:
|
||||
static const char* type_name() noexcept { return "material_asset"; }
|
||||
static load_async_result load_async(const library& library, str_view address);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace e2d
|
||||
{
|
||||
class mesh_asset final : public content_asset<mesh_asset, mesh> {
|
||||
public:
|
||||
static const char* type_name() noexcept { return "mesh_asset"; }
|
||||
static load_async_result load_async(const library& library, str_view address);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ namespace e2d
|
||||
{
|
||||
class model_asset final : public content_asset<model_asset, model> {
|
||||
public:
|
||||
static const char* type_name() noexcept { return "model_asset"; }
|
||||
static load_async_result load_async(const library& library, str_view address);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ namespace e2d
|
||||
{
|
||||
class prefab_asset final : public content_asset<prefab_asset, prefab> {
|
||||
public:
|
||||
static const char* type_name() noexcept { return "prefab_asset"; }
|
||||
static load_async_result load_async(const library& library, str_view address);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace e2d
|
||||
{
|
||||
class shader_asset final : public content_asset<shader_asset, shader_ptr> {
|
||||
public:
|
||||
static const char* type_name() noexcept { return "shader_asset"; }
|
||||
static load_async_result load_async(const library& library, str_view address);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace e2d
|
||||
{
|
||||
class shape_asset final : public content_asset<shape_asset, shape> {
|
||||
public:
|
||||
static const char* type_name() noexcept { return "shape_asset"; }
|
||||
static load_async_result load_async(const library& library, str_view address);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ namespace e2d
|
||||
{
|
||||
class sprite_asset final : public content_asset<sprite_asset, sprite> {
|
||||
public:
|
||||
static const char* type_name() noexcept { return "sprite_asset"; }
|
||||
static load_async_result load_async(const library& library, str_view address);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace e2d
|
||||
{
|
||||
class text_asset final : public content_asset<text_asset, str> {
|
||||
public:
|
||||
static const char* type_name() noexcept { return "text_asset"; }
|
||||
static load_async_result load_async(const library& library, str_view address);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace e2d
|
||||
{
|
||||
class texture_asset final : public content_asset<texture_asset, texture_ptr> {
|
||||
public:
|
||||
static const char* type_name() noexcept { return "texture_asset"; }
|
||||
static load_async_result load_async(const library& library, str_view address);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ namespace e2d
|
||||
using xml_uptr = std::unique_ptr<pugi::xml_document>;
|
||||
class xml_asset final : public content_asset<xml_asset, xml_uptr> {
|
||||
public:
|
||||
static const char* type_name() noexcept { return "xml_asset"; }
|
||||
static load_async_result load_async(const library& library, str_view address);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -105,10 +105,31 @@ namespace e2d
|
||||
return new_asset;
|
||||
}).except([
|
||||
this,
|
||||
main_address,
|
||||
main_address_hash
|
||||
](std::exception_ptr e) -> typename Asset::load_result {
|
||||
std::lock_guard<std::recursive_mutex> guard(mutex_);
|
||||
remove_loading_asset_<Asset>(main_address_hash);
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> guard(mutex_);
|
||||
remove_loading_asset_<Asset>(main_address_hash);
|
||||
}
|
||||
try {
|
||||
std::rethrow_exception(e);
|
||||
} catch ( const std::exception& ee ) {
|
||||
the<debug>().error("LIBRARY: Failed to load asset:\n"
|
||||
"--> Asset: %0\n"
|
||||
"--> Address: %1\n"
|
||||
"--> Exception: %2",
|
||||
Asset::type_name(),
|
||||
main_address,
|
||||
ee.what());
|
||||
} catch (...) {
|
||||
the<debug>().error("LIBRARY: Failed to load asset:\n"
|
||||
"--> Asset: %0\n"
|
||||
"--> Address: %1\n"
|
||||
"--> Exception: unexpected",
|
||||
Asset::type_name(),
|
||||
main_address);
|
||||
}
|
||||
std::rethrow_exception(e);
|
||||
});
|
||||
|
||||
@@ -130,17 +151,25 @@ namespace e2d
|
||||
template < typename Asset, typename Nested >
|
||||
typename Nested::load_async_result library::load_asset_async(str_view address) const {
|
||||
return load_main_asset_async<Asset>(address)
|
||||
.then([
|
||||
nested_address = address::nested(address)
|
||||
](const typename Asset::load_result& main_asset){
|
||||
typename Nested::load_result nested_asset = nested_address.empty()
|
||||
? dynamic_pointer_cast<Nested>(main_asset)
|
||||
: main_asset->template find_nested_asset<Nested>(nested_address);
|
||||
if ( nested_asset ) {
|
||||
return nested_asset;
|
||||
}
|
||||
throw asset_loading_exception();
|
||||
});
|
||||
.then([
|
||||
address = str(address),
|
||||
nested_address = address::nested(address)
|
||||
](const typename Asset::load_result& main_asset){
|
||||
typename Nested::load_result nested_asset = nested_address.empty()
|
||||
? dynamic_pointer_cast<Nested>(main_asset)
|
||||
: main_asset->template find_nested_asset<Nested>(nested_address);
|
||||
if ( nested_asset ) {
|
||||
return nested_asset;
|
||||
}
|
||||
the<debug>().error("LIBRARY: Failed to load asset:\n"
|
||||
"--> Asset: %0\n"
|
||||
"--> Nested: %1\n"
|
||||
"--> Address: %2\n",
|
||||
Asset::type_name(),
|
||||
Nested::type_name(),
|
||||
address);
|
||||
throw asset_loading_exception();
|
||||
});
|
||||
}
|
||||
|
||||
template < typename Asset >
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace e2d
|
||||
|
||||
gobject_iptr instantiate();
|
||||
gobject_iptr instantiate(const prefab& prefab);
|
||||
void destroy_instance(const gobject_iptr& inst, bool recursive) noexcept;
|
||||
void destroy_instance(const gobject_iptr& inst) noexcept;
|
||||
private:
|
||||
ecs::registry registry_;
|
||||
hash_map<ecs::entity_id, gobject_iptr> gobjects_;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
{
|
||||
"components" : {
|
||||
"camera" : {}
|
||||
"camera" : {
|
||||
"background" : [1.0, 0.4, 0.0, 1.0]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,12 +3,7 @@
|
||||
"scene" : {}
|
||||
},
|
||||
"children" : [{
|
||||
"prototype" : "camera_prefab.json",
|
||||
"components" : {
|
||||
"camera" : {
|
||||
"background" : [1.0, 0.4, 0.0, 1.0]
|
||||
}
|
||||
}
|
||||
"prototype" : "camera_prefab.json"
|
||||
},{
|
||||
"prototype" : "gnome_prefab.json",
|
||||
"components" : {
|
||||
|
||||
@@ -84,16 +84,19 @@ namespace
|
||||
|
||||
E2D_ASSERT(sprite_json.HasMember("name"));
|
||||
if ( !json_utils::try_parse_value(sprite_json["name"], tsprite_descs[i].name) ) {
|
||||
the<debug>().error("ATLAS: Incorrect formatting of 'name' property");
|
||||
return false;
|
||||
}
|
||||
|
||||
E2D_ASSERT(sprite_json.HasMember("pivot"));
|
||||
if ( !json_utils::try_parse_value(sprite_json["pivot"], tsprite_descs[i].pivot) ) {
|
||||
the<debug>().error("ATLAS: Incorrect formatting of 'pivot' property");
|
||||
return false;
|
||||
}
|
||||
|
||||
E2D_ASSERT(sprite_json.HasMember("texrect"));
|
||||
if ( !json_utils::try_parse_value(sprite_json["texrect"], tsprite_descs[i].texrect) ) {
|
||||
the<debug>().error("ATLAS: Incorrect formatting of 'texrect' property");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,18 +146,21 @@ namespace
|
||||
|
||||
f32 fps{0.f};
|
||||
if ( !json_utils::try_parse_value(sequence_json["fps"], fps) ) {
|
||||
the<debug>().error("FLIPBOOK: Incorrect formatting of 'fps' property");
|
||||
return stdex::make_rejected_promise<vector<flipbook::sequence>>(
|
||||
flipbook_asset_loading_exception());
|
||||
}
|
||||
|
||||
str_hash name_hash;
|
||||
if ( !json_utils::try_parse_value(sequence_json["name"], name_hash) ) {
|
||||
the<debug>().error("FLIPBOOK: Incorrect formatting of 'name' property");
|
||||
return stdex::make_rejected_promise<vector<flipbook::sequence>>(
|
||||
flipbook_asset_loading_exception());
|
||||
}
|
||||
|
||||
vector<std::size_t> frames;
|
||||
if ( !json_utils::try_parse_value(sequence_json["frames"], frames) ) {
|
||||
the<debug>().error("FLIPBOOK: Incorrect formatting of 'frames' property");
|
||||
return stdex::make_rejected_promise<vector<flipbook::sequence>>(
|
||||
flipbook_asset_loading_exception());
|
||||
}
|
||||
|
||||
@@ -134,6 +134,11 @@ namespace
|
||||
auto proto_res = dependencies.find_asset<prefab_asset>(
|
||||
path::combine(parent_address, root["prototype"].GetString()));
|
||||
if ( !proto_res ) {
|
||||
the<debug>().error("PREFAB: Dependency 'prototype' is not found:\n"
|
||||
"--> Parent address: %0\n"
|
||||
"--> Dependency address: %1",
|
||||
parent_address,
|
||||
root["flipbook"].GetString());
|
||||
throw prefab_asset_loading_exception();
|
||||
}
|
||||
content = proto_res->content();
|
||||
|
||||
@@ -61,15 +61,15 @@ namespace
|
||||
v2f pivot;
|
||||
E2D_ASSERT(root.HasMember("pivot"));
|
||||
if ( !json_utils::try_parse_value(root["pivot"], pivot) ) {
|
||||
return stdex::make_rejected_promise<sprite>(
|
||||
sprite_asset_loading_exception());
|
||||
the<debug>().error("SPRITE: Incorrect formatting of 'pivot' property");
|
||||
return stdex::make_rejected_promise<sprite>(sprite_asset_loading_exception());
|
||||
}
|
||||
|
||||
b2f texrect;
|
||||
E2D_ASSERT(root.HasMember("texrect"));
|
||||
if ( !json_utils::try_parse_value(root["texrect"], texrect) ) {
|
||||
return stdex::make_rejected_promise<sprite>(
|
||||
sprite_asset_loading_exception());
|
||||
the<debug>().error("SPRITE: Incorrect formatting of 'texrect' property");
|
||||
return stdex::make_rejected_promise<sprite>(sprite_asset_loading_exception());
|
||||
}
|
||||
|
||||
return texture_p.then([
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace e2d
|
||||
{
|
||||
world::~world() noexcept {
|
||||
while ( !gobjects_.empty() ) {
|
||||
destroy_instance(gobjects_.begin()->second, true);
|
||||
destroy_instance(gobjects_.begin()->second);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace e2d
|
||||
}
|
||||
inst_a.assign(inst_n);
|
||||
} catch (...) {
|
||||
destroy_instance(inst, true);
|
||||
destroy_instance(inst);
|
||||
throw;
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ namespace e2d
|
||||
}
|
||||
inst_a.assign(inst_n);
|
||||
} catch (...) {
|
||||
destroy_instance(inst, true);
|
||||
destroy_instance(inst);
|
||||
throw;
|
||||
}
|
||||
|
||||
@@ -68,28 +68,26 @@ namespace e2d
|
||||
auto child_a = child->get_component<actor>();
|
||||
inst_a->node()->add_child(child_a->node());
|
||||
} catch (...) {
|
||||
destroy_instance(child, true);
|
||||
destroy_instance(child);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
} catch (...) {
|
||||
destroy_instance(inst, true);
|
||||
destroy_instance(inst);
|
||||
throw;
|
||||
}
|
||||
|
||||
return inst;
|
||||
}
|
||||
|
||||
void world::destroy_instance(const gobject_iptr& inst, bool recursive) noexcept {
|
||||
if ( recursive ) {
|
||||
node_iptr inst_n = inst && inst->get_component<actor>()
|
||||
? inst->get_component<actor>()->node()
|
||||
: nullptr;
|
||||
if ( inst_n ) {
|
||||
inst_n->for_each_child([this](const node_iptr& child_n){
|
||||
destroy_instance(child_n->owner(), true);
|
||||
});
|
||||
}
|
||||
void world::destroy_instance(const gobject_iptr& inst) noexcept {
|
||||
node_iptr inst_n = inst && inst->get_component<actor>()
|
||||
? inst->get_component<actor>()->node()
|
||||
: nullptr;
|
||||
if ( inst_n ) {
|
||||
inst_n->for_each_child([this](const node_iptr& child_n){
|
||||
destroy_instance(child_n->owner());
|
||||
});
|
||||
}
|
||||
if ( inst ) {
|
||||
inst->entity().remove_all_components();
|
||||
|
||||
@@ -24,10 +24,14 @@ namespace
|
||||
};
|
||||
|
||||
class fake_nested_asset final : public content_asset<fake_nested_asset, int> {
|
||||
public:
|
||||
static const char* type_name() noexcept { return "fake_nested_asset"; }
|
||||
};
|
||||
|
||||
class fake_asset final : public content_asset<fake_asset, int> {
|
||||
public:
|
||||
static const char* type_name() noexcept { return "fake_asset"; }
|
||||
|
||||
static load_async_result load_async(const library& library, str_view address) {
|
||||
E2D_UNUSED(library);
|
||||
return address == "42"
|
||||
|
||||
@@ -25,6 +25,7 @@ namespace
|
||||
|
||||
class fake_asset final : public content_asset<fake_asset, int> {
|
||||
public:
|
||||
static const char* type_name() noexcept { return "fake_asset"; }
|
||||
static load_async_result load_async(const library& library, str_view address) {
|
||||
E2D_UNUSED(library, address);
|
||||
return stdex::make_resolved_promise(fake_asset::create(42));
|
||||
@@ -33,6 +34,7 @@ namespace
|
||||
|
||||
class big_fake_asset final : public content_asset<big_fake_asset, int> {
|
||||
public:
|
||||
static const char* type_name() noexcept { return "big_fake_asset"; }
|
||||
static load_async_result load_async(const library& library, str_view address) {
|
||||
E2D_UNUSED(library, address);
|
||||
return the<deferrer>().do_in_worker_thread([](){
|
||||
|
||||
Reference in New Issue
Block a user