mirror of
https://github.com/enduro2d/enduro2d.git
synced 2026-01-06 11:51:00 +07:00
removed redundant module checks
This commit is contained in:
@@ -22,13 +22,6 @@ namespace e2d
|
||||
binary_asset::load_async_result binary_asset::load_async(
|
||||
library& library, str_view address)
|
||||
{
|
||||
E2D_UNUSED(library);
|
||||
|
||||
if ( !modules::is_initialized<vfs>() ) {
|
||||
return stdex::make_rejected_promise<load_result>(
|
||||
binary_asset_loading_exception());
|
||||
}
|
||||
|
||||
const auto asset_url = library.root() / address;
|
||||
return the<vfs>().load_async(asset_url)
|
||||
.then([](auto&& content){
|
||||
|
||||
@@ -25,9 +25,6 @@ namespace e2d
|
||||
{
|
||||
return library.load_asset_async<binary_asset>(address)
|
||||
.then([](const binary_asset::load_result& image_data){
|
||||
if ( !modules::is_initialized<deferrer>() ) {
|
||||
throw image_asset_loading_exception();
|
||||
}
|
||||
return the<deferrer>().do_in_worker_thread([image_data](){
|
||||
image content;
|
||||
if ( !images::try_load_image(content, image_data->content()) ) {
|
||||
|
||||
@@ -26,9 +26,6 @@ namespace e2d
|
||||
{
|
||||
return library.load_asset_async<text_asset>(address)
|
||||
.then([](const text_asset::load_result& json_data){
|
||||
if ( !modules::is_initialized<deferrer>() ) {
|
||||
throw json_asset_loading_exception();
|
||||
}
|
||||
return the<deferrer>().do_in_worker_thread([json_data](){
|
||||
rapidjson::Document doc;
|
||||
if ( doc.Parse(json_data->content().c_str()).HasParseError() ) {
|
||||
|
||||
@@ -1176,9 +1176,6 @@ namespace e2d
|
||||
&library,
|
||||
parent_address = path::parent_path(address)
|
||||
](const json_asset::load_result& material_data){
|
||||
if ( !modules::is_initialized<deferrer>() ) {
|
||||
throw material_asset_loading_exception();
|
||||
}
|
||||
return the<deferrer>().do_in_worker_thread([material_data](){
|
||||
const rapidjson::Document& doc = material_data->content();
|
||||
rapidjson::SchemaValidator validator(material_asset_schema());
|
||||
|
||||
@@ -25,9 +25,6 @@ namespace e2d
|
||||
{
|
||||
return library.load_asset_async<binary_asset>(address)
|
||||
.then([](const binary_asset::load_result& mesh_data){
|
||||
if ( !modules::is_initialized<deferrer>() ) {
|
||||
throw mesh_asset_loading_exception();
|
||||
}
|
||||
return the<deferrer>().do_in_worker_thread([mesh_data](){
|
||||
mesh content;
|
||||
if ( !meshes::try_load_mesh(content, mesh_data->content()) ) {
|
||||
|
||||
@@ -60,6 +60,7 @@ namespace
|
||||
path::combine(parent_address, root["mesh"].GetString()));
|
||||
|
||||
vector<stdex::promise<material_asset::load_result>> materials_p;
|
||||
|
||||
if ( root.HasMember("materials") ) {
|
||||
E2D_ASSERT(root["materials"].IsArray());
|
||||
const auto& materials_json = root["materials"];
|
||||
@@ -80,13 +81,12 @@ namespace
|
||||
mesh_asset::load_result,
|
||||
vector<material_asset::load_result>
|
||||
>& results){
|
||||
if ( !modules::is_initialized<deferrer>() ) {
|
||||
throw model_asset_loading_exception();
|
||||
}
|
||||
model content;
|
||||
content.set_mesh(std::get<0>(results));
|
||||
content.set_materials(std::get<1>(results));
|
||||
return the<deferrer>().do_in_main_thread([content = std::move(content)]() mutable {
|
||||
return the<deferrer>().do_in_main_thread([
|
||||
content = std::move(content)
|
||||
]() mutable {
|
||||
content.regenerate_geometry();
|
||||
return content;
|
||||
});
|
||||
@@ -104,9 +104,6 @@ namespace e2d
|
||||
&library,
|
||||
parent_address = path::parent_path(address)
|
||||
](const json_asset::load_result& model_data){
|
||||
if ( !modules::is_initialized<deferrer>() ) {
|
||||
throw model_asset_loading_exception();
|
||||
}
|
||||
return the<deferrer>().do_in_worker_thread([model_data](){
|
||||
const rapidjson::Document& doc = model_data->content();
|
||||
rapidjson::SchemaValidator validator(model_asset_schema());
|
||||
@@ -118,8 +115,9 @@ namespace e2d
|
||||
return parse_model(
|
||||
library, parent_address, model_data->content());
|
||||
})
|
||||
.then([](const model& model){
|
||||
return model_asset::create(model);
|
||||
.then([](auto&& content){
|
||||
return model_asset::create(
|
||||
std::forward<decltype(content)>(content));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -68,13 +68,7 @@ namespace
|
||||
text_asset::load_result,
|
||||
text_asset::load_result
|
||||
>& results){
|
||||
if ( !modules::is_initialized<deferrer>() ) {
|
||||
throw shader_asset_loading_exception();
|
||||
}
|
||||
return the<deferrer>().do_in_main_thread([results](){
|
||||
if ( !modules::is_initialized<render>() ) {
|
||||
throw shader_asset_loading_exception();
|
||||
}
|
||||
const shader_ptr content = the<render>().create_shader(
|
||||
std::get<0>(results)->content(),
|
||||
std::get<1>(results)->content());
|
||||
@@ -97,9 +91,6 @@ namespace e2d
|
||||
&library,
|
||||
parent_address = path::parent_path(address)
|
||||
](const json_asset::load_result& shader_data){
|
||||
if ( !modules::is_initialized<deferrer>() ) {
|
||||
throw shader_asset_loading_exception();
|
||||
}
|
||||
return the<deferrer>().do_in_worker_thread([shader_data](){
|
||||
const rapidjson::Document& doc = shader_data->content();
|
||||
rapidjson::SchemaValidator validator(shader_asset_schema());
|
||||
@@ -111,11 +102,9 @@ namespace e2d
|
||||
return parse_shader(
|
||||
library, parent_address, shader_data->content());
|
||||
})
|
||||
.then([](const shader_ptr& shader){
|
||||
if ( !shader ) {
|
||||
throw shader_asset_loading_exception();
|
||||
}
|
||||
return shader_asset::create(shader);
|
||||
.then([](auto&& content){
|
||||
return shader_asset::create(
|
||||
std::forward<decltype(content)>(content));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -118,9 +118,6 @@ namespace e2d
|
||||
&library,
|
||||
parent_address = path::parent_path(address)
|
||||
](const json_asset::load_result& sprite_data){
|
||||
if ( !modules::is_initialized<deferrer>() ) {
|
||||
throw sprite_asset_loading_exception();
|
||||
}
|
||||
return the<deferrer>().do_in_worker_thread([sprite_data](){
|
||||
const rapidjson::Document& doc = sprite_data->content();
|
||||
rapidjson::SchemaValidator validator(sprite_asset_schema());
|
||||
@@ -132,8 +129,9 @@ namespace e2d
|
||||
return parse_sprite(
|
||||
library, parent_address, sprite_data->content());
|
||||
})
|
||||
.then([](const sprite& sprite){
|
||||
return sprite_asset::create(sprite);
|
||||
.then([](auto&& content){
|
||||
return sprite_asset::create(
|
||||
std::forward<decltype(content)>(content));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -22,13 +22,6 @@ namespace e2d
|
||||
text_asset::load_async_result text_asset::load_async(
|
||||
library& library, str_view address)
|
||||
{
|
||||
E2D_UNUSED(library);
|
||||
|
||||
if ( !modules::is_initialized<vfs>() ) {
|
||||
return stdex::make_rejected_promise<load_result>(
|
||||
text_asset_loading_exception());
|
||||
}
|
||||
|
||||
const auto asset_url = library.root() / address;
|
||||
return the<vfs>().load_as_string_async(asset_url)
|
||||
.then([](auto&& content){
|
||||
|
||||
@@ -25,13 +25,7 @@ namespace e2d
|
||||
{
|
||||
return library.load_asset_async<image_asset>(address)
|
||||
.then([](const image_asset::load_result& texture_data){
|
||||
if ( !modules::is_initialized<deferrer>() ) {
|
||||
throw texture_asset_loading_exception();
|
||||
}
|
||||
return the<deferrer>().do_in_main_thread([texture_data](){
|
||||
if ( !modules::is_initialized<render>() ) {
|
||||
throw texture_asset_loading_exception();
|
||||
}
|
||||
const texture_ptr content = the<render>().create_texture(
|
||||
texture_data->content());
|
||||
if ( !content ) {
|
||||
|
||||
@@ -26,9 +26,6 @@ namespace e2d
|
||||
{
|
||||
return library.load_asset_async<text_asset>(address)
|
||||
.then([](const text_asset::load_result& xml_data){
|
||||
if ( !modules::is_initialized<deferrer>() ) {
|
||||
throw xml_asset_loading_exception();
|
||||
}
|
||||
return the<deferrer>().do_in_worker_thread([xml_data](){
|
||||
pugi::xml_document doc;
|
||||
if ( !doc.load_string(xml_data->content().c_str()) ) {
|
||||
|
||||
@@ -37,12 +37,6 @@ namespace
|
||||
render::geometry make_geometry(const mesh& mesh) {
|
||||
render::geometry geo;
|
||||
|
||||
if ( !modules::is_initialized<render>() ) {
|
||||
return geo;
|
||||
}
|
||||
|
||||
render& r = the<render>();
|
||||
|
||||
{
|
||||
std::size_t index_count{0u};
|
||||
for ( std::size_t i = 0; i < mesh.indices_submesh_count(); ++i ) {
|
||||
@@ -57,7 +51,7 @@ namespace
|
||||
indices.insert(indices.end(), mesh.indices(i).begin(), mesh.indices(i).end());
|
||||
}
|
||||
|
||||
const index_buffer_ptr index_buffer = r.create_index_buffer(
|
||||
const index_buffer_ptr index_buffer = the<render>().create_index_buffer(
|
||||
buffer(indices.data(), indices.size() * sizeof(indices[0])),
|
||||
index_declaration::index_type::unsigned_int,
|
||||
index_buffer::usage::static_draw);
|
||||
@@ -70,7 +64,7 @@ namespace
|
||||
|
||||
{
|
||||
const vector<v3f>& vertices = mesh.vertices();
|
||||
const vertex_buffer_ptr vertex_buffer = r.create_vertex_buffer(
|
||||
const vertex_buffer_ptr vertex_buffer = the<render>().create_vertex_buffer(
|
||||
buffer(vertices.data(), vertices.size() * sizeof(vertices[0])),
|
||||
vertex_buffer_decl,
|
||||
vertex_buffer::usage::static_draw);
|
||||
|
||||
@@ -42,7 +42,7 @@ TEST_CASE("library"){
|
||||
text_res.reset();
|
||||
text_res_from_cache.reset();
|
||||
|
||||
the<deferrer>().worker().wait_all();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||
REQUIRE(1u == the<asset_cache<text_asset>>().unload_self_unused_assets());
|
||||
REQUIRE(the<asset_cache<text_asset>>().asset_count() == 0);
|
||||
}
|
||||
@@ -59,7 +59,8 @@ TEST_CASE("library"){
|
||||
|
||||
text_res.reset();
|
||||
binary_res.reset();
|
||||
the<deferrer>().worker().wait_all();
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||
REQUIRE(2u == l.unload_unused_assets());
|
||||
}
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user