mirror of
https://github.com/enduro2d/enduro2d.git
synced 2025-12-15 00:11:55 +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_;
|
||||
|
||||
Reference in New Issue
Block a user