From 0dddcee1219e8eb41c8a33a398af4c52d9047540 Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Tue, 12 Mar 2019 12:49:22 +0700 Subject: [PATCH] removed redundant module checks --- sources/enduro2d/high/assets/binary_asset.cpp | 7 ------- sources/enduro2d/high/assets/image_asset.cpp | 3 --- sources/enduro2d/high/assets/json_asset.cpp | 3 --- sources/enduro2d/high/assets/material_asset.cpp | 3 --- sources/enduro2d/high/assets/mesh_asset.cpp | 3 --- sources/enduro2d/high/assets/model_asset.cpp | 16 +++++++--------- sources/enduro2d/high/assets/shader_asset.cpp | 17 +++-------------- sources/enduro2d/high/assets/sprite_asset.cpp | 8 +++----- sources/enduro2d/high/assets/text_asset.cpp | 7 ------- sources/enduro2d/high/assets/texture_asset.cpp | 6 ------ sources/enduro2d/high/assets/xml_asset.cpp | 3 --- sources/enduro2d/high/model.cpp | 10 ++-------- untests/sources/untests_high/library.cpp | 5 +++-- 13 files changed, 18 insertions(+), 73 deletions(-) diff --git a/sources/enduro2d/high/assets/binary_asset.cpp b/sources/enduro2d/high/assets/binary_asset.cpp index 4d26b47d..ed321b77 100644 --- a/sources/enduro2d/high/assets/binary_asset.cpp +++ b/sources/enduro2d/high/assets/binary_asset.cpp @@ -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() ) { - return stdex::make_rejected_promise( - binary_asset_loading_exception()); - } - const auto asset_url = library.root() / address; return the().load_async(asset_url) .then([](auto&& content){ diff --git a/sources/enduro2d/high/assets/image_asset.cpp b/sources/enduro2d/high/assets/image_asset.cpp index e73be425..a86f10bf 100644 --- a/sources/enduro2d/high/assets/image_asset.cpp +++ b/sources/enduro2d/high/assets/image_asset.cpp @@ -25,9 +25,6 @@ namespace e2d { return library.load_asset_async(address) .then([](const binary_asset::load_result& image_data){ - if ( !modules::is_initialized() ) { - throw image_asset_loading_exception(); - } return the().do_in_worker_thread([image_data](){ image content; if ( !images::try_load_image(content, image_data->content()) ) { diff --git a/sources/enduro2d/high/assets/json_asset.cpp b/sources/enduro2d/high/assets/json_asset.cpp index 21bcf3d3..689d8fa2 100644 --- a/sources/enduro2d/high/assets/json_asset.cpp +++ b/sources/enduro2d/high/assets/json_asset.cpp @@ -26,9 +26,6 @@ namespace e2d { return library.load_asset_async(address) .then([](const text_asset::load_result& json_data){ - if ( !modules::is_initialized() ) { - throw json_asset_loading_exception(); - } return the().do_in_worker_thread([json_data](){ rapidjson::Document doc; if ( doc.Parse(json_data->content().c_str()).HasParseError() ) { diff --git a/sources/enduro2d/high/assets/material_asset.cpp b/sources/enduro2d/high/assets/material_asset.cpp index 68656713..02c96e53 100644 --- a/sources/enduro2d/high/assets/material_asset.cpp +++ b/sources/enduro2d/high/assets/material_asset.cpp @@ -1176,9 +1176,6 @@ namespace e2d &library, parent_address = path::parent_path(address) ](const json_asset::load_result& material_data){ - if ( !modules::is_initialized() ) { - throw material_asset_loading_exception(); - } return the().do_in_worker_thread([material_data](){ const rapidjson::Document& doc = material_data->content(); rapidjson::SchemaValidator validator(material_asset_schema()); diff --git a/sources/enduro2d/high/assets/mesh_asset.cpp b/sources/enduro2d/high/assets/mesh_asset.cpp index a51199e9..660a396b 100644 --- a/sources/enduro2d/high/assets/mesh_asset.cpp +++ b/sources/enduro2d/high/assets/mesh_asset.cpp @@ -25,9 +25,6 @@ namespace e2d { return library.load_asset_async(address) .then([](const binary_asset::load_result& mesh_data){ - if ( !modules::is_initialized() ) { - throw mesh_asset_loading_exception(); - } return the().do_in_worker_thread([mesh_data](){ mesh content; if ( !meshes::try_load_mesh(content, mesh_data->content()) ) { diff --git a/sources/enduro2d/high/assets/model_asset.cpp b/sources/enduro2d/high/assets/model_asset.cpp index 890e32a9..6f95b408 100644 --- a/sources/enduro2d/high/assets/model_asset.cpp +++ b/sources/enduro2d/high/assets/model_asset.cpp @@ -60,6 +60,7 @@ namespace path::combine(parent_address, root["mesh"].GetString())); vector> 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 >& results){ - if ( !modules::is_initialized() ) { - throw model_asset_loading_exception(); - } model content; content.set_mesh(std::get<0>(results)); content.set_materials(std::get<1>(results)); - return the().do_in_main_thread([content = std::move(content)]() mutable { + return the().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() ) { - throw model_asset_loading_exception(); - } return the().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(content)); }); }); } diff --git a/sources/enduro2d/high/assets/shader_asset.cpp b/sources/enduro2d/high/assets/shader_asset.cpp index 80f4191e..d9a66921 100644 --- a/sources/enduro2d/high/assets/shader_asset.cpp +++ b/sources/enduro2d/high/assets/shader_asset.cpp @@ -68,13 +68,7 @@ namespace text_asset::load_result, text_asset::load_result >& results){ - if ( !modules::is_initialized() ) { - throw shader_asset_loading_exception(); - } return the().do_in_main_thread([results](){ - if ( !modules::is_initialized() ) { - throw shader_asset_loading_exception(); - } const shader_ptr content = the().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() ) { - throw shader_asset_loading_exception(); - } return the().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(content)); }); }); } diff --git a/sources/enduro2d/high/assets/sprite_asset.cpp b/sources/enduro2d/high/assets/sprite_asset.cpp index bd72d998..ba7367a1 100644 --- a/sources/enduro2d/high/assets/sprite_asset.cpp +++ b/sources/enduro2d/high/assets/sprite_asset.cpp @@ -118,9 +118,6 @@ namespace e2d &library, parent_address = path::parent_path(address) ](const json_asset::load_result& sprite_data){ - if ( !modules::is_initialized() ) { - throw sprite_asset_loading_exception(); - } return the().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(content)); }); }); } diff --git a/sources/enduro2d/high/assets/text_asset.cpp b/sources/enduro2d/high/assets/text_asset.cpp index d6ff1dfa..ebd2db73 100644 --- a/sources/enduro2d/high/assets/text_asset.cpp +++ b/sources/enduro2d/high/assets/text_asset.cpp @@ -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() ) { - return stdex::make_rejected_promise( - text_asset_loading_exception()); - } - const auto asset_url = library.root() / address; return the().load_as_string_async(asset_url) .then([](auto&& content){ diff --git a/sources/enduro2d/high/assets/texture_asset.cpp b/sources/enduro2d/high/assets/texture_asset.cpp index 83850932..55430ef8 100644 --- a/sources/enduro2d/high/assets/texture_asset.cpp +++ b/sources/enduro2d/high/assets/texture_asset.cpp @@ -25,13 +25,7 @@ namespace e2d { return library.load_asset_async(address) .then([](const image_asset::load_result& texture_data){ - if ( !modules::is_initialized() ) { - throw texture_asset_loading_exception(); - } return the().do_in_main_thread([texture_data](){ - if ( !modules::is_initialized() ) { - throw texture_asset_loading_exception(); - } const texture_ptr content = the().create_texture( texture_data->content()); if ( !content ) { diff --git a/sources/enduro2d/high/assets/xml_asset.cpp b/sources/enduro2d/high/assets/xml_asset.cpp index 480dcb4c..89e6f6ce 100644 --- a/sources/enduro2d/high/assets/xml_asset.cpp +++ b/sources/enduro2d/high/assets/xml_asset.cpp @@ -26,9 +26,6 @@ namespace e2d { return library.load_asset_async(address) .then([](const text_asset::load_result& xml_data){ - if ( !modules::is_initialized() ) { - throw xml_asset_loading_exception(); - } return the().do_in_worker_thread([xml_data](){ pugi::xml_document doc; if ( !doc.load_string(xml_data->content().c_str()) ) { diff --git a/sources/enduro2d/high/model.cpp b/sources/enduro2d/high/model.cpp index 4cc0c0b0..b2a58462 100644 --- a/sources/enduro2d/high/model.cpp +++ b/sources/enduro2d/high/model.cpp @@ -37,12 +37,6 @@ namespace render::geometry make_geometry(const mesh& mesh) { render::geometry geo; - if ( !modules::is_initialized() ) { - return geo; - } - - render& r = the(); - { 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().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& vertices = mesh.vertices(); - const vertex_buffer_ptr vertex_buffer = r.create_vertex_buffer( + const vertex_buffer_ptr vertex_buffer = the().create_vertex_buffer( buffer(vertices.data(), vertices.size() * sizeof(vertices[0])), vertex_buffer_decl, vertex_buffer::usage::static_draw); diff --git a/untests/sources/untests_high/library.cpp b/untests/sources/untests_high/library.cpp index 536df7e0..dc55c2ac 100644 --- a/untests/sources/untests_high/library.cpp +++ b/untests/sources/untests_high/library.cpp @@ -42,7 +42,7 @@ TEST_CASE("library"){ text_res.reset(); text_res_from_cache.reset(); - the().worker().wait_all(); + std::this_thread::sleep_for(std::chrono::milliseconds(10)); REQUIRE(1u == the>().unload_self_unused_assets()); REQUIRE(the>().asset_count() == 0); } @@ -59,7 +59,8 @@ TEST_CASE("library"){ text_res.reset(); binary_res.reset(); - the().worker().wait_all(); + + std::this_thread::sleep_for(std::chrono::milliseconds(10)); REQUIRE(2u == l.unload_unused_assets()); } {