diff --git a/WORKSPACE.bazel b/WORKSPACE.bazel index 0cd2c7c5..d60dc509 100644 --- a/WORKSPACE.bazel +++ b/WORKSPACE.bazel @@ -18,21 +18,21 @@ http_archive( http_archive( name = "ecsact_runtime", - sha256 = "dfc71e519d24b943c855d288d19f539fc9b9c65636c0376c7febb865233161b6", - strip_prefix = "ecsact_runtime-0.2.0", - urls = ["https://github.com/ecsact-dev/ecsact_runtime/archive/refs/tags/0.2.0.tar.gz"], + sha256 = "35b03aaef0925fda5b5aefb2d6a6e2c9593f31d6414ab157091f9ca26a992da3", + strip_prefix = "ecsact_runtime-0.3.0", + urls = ["https://github.com/ecsact-dev/ecsact_runtime/archive/refs/tags/0.3.0.tar.gz"], ) http_file( name = "ecsact_cli_windows", - url = "https://github.com/ecsact-dev/ecsact_cli/releases/download/0.1.0/ecsact_0.1.0_windows_x64.exe", + url = "https://github.com/ecsact-dev/ecsact_cli/releases/download/0.1.1/ecsact_0.1.1_windows_x64.exe", executable = True, downloaded_file_path = "ecsact.exe", ) http_file( name = "ecsact_cli_linux", - url = "https://github.com/ecsact-dev/ecsact_cli/releases/download/0.1.0/ecsact_0.1.0_linux_x64", + url = "https://github.com/ecsact-dev/ecsact_cli/releases/download/0.1.1/ecsact_0.1.1_linux_x64", executable = True, downloaded_file_path = "ecsact", ) diff --git a/ecsact/entt/runtime.hh b/ecsact/entt/runtime.hh index 1bb85c7d..5bc7a280 100644 --- a/ecsact/entt/runtime.hh +++ b/ecsact/entt/runtime.hh @@ -692,71 +692,93 @@ private: using caps_info = ecsact::system_capabilities_info; using associations = typename caps_info::associations; + constexpr auto parallel_hint = + ecsact::system_parallel_execution::value; + auto assoc_views = system_association_views(info.registry); auto assoc_views_itrs = system_association_views_iterators(assoc_views); auto view = system_view(info.registry); const void* action_data = nullptr; + auto itr_view_one = [&](entt_entity_type entity) { + _execute_system_user_itr( + info, + view, + assoc_views, + entity, + parent, + action_data, + actions + ); + }; + auto itr_view = [&] { - for(auto entity : view) { - bool missing_assoc_entities = false; - mp_for_each::value>>([&](auto I) { - using boost::mp11::mp_at; - using boost::mp11::mp_size_t; + if constexpr(mp_size::value == 0) { + if constexpr(parallel_hint) { + std::for_each( + std::execution::par_unseq, + view.begin(), + view.end(), + [&](auto entity) { itr_view_one(entity); } + ); + } else { + for(auto entity : view) { + itr_view_one(entity); + } + } + } else { + for(auto entity : view) { + bool missing_assoc_entities = false; + mp_for_each::value>>([&](auto I) { + using boost::mp11::mp_at; + using boost::mp11::mp_size_t; - using Assoc = mp_at>; - using ComponentT = typename Assoc::component_type; + using Assoc = mp_at>; + using ComponentT = typename Assoc::component_type; - constexpr auto offset = Assoc::field_offset; + constexpr auto offset = Assoc::field_offset; - auto& assoc_view = std::get(assoc_views); - auto& assoc_view_itr = std::get(assoc_views_itrs); - if(assoc_view.begin() == assoc_view.end()) { - missing_assoc_entities = true; - return; - } + auto& assoc_view = std::get(assoc_views); + auto& assoc_view_itr = std::get(assoc_views_itrs); + if(assoc_view.begin() == assoc_view.end()) { + missing_assoc_entities = true; + return; + } - assert(view.contains(entity)); - auto& comp = view.template get(entity); + assert(view.contains(entity)); + auto& comp = view.template get(entity); - ecsact::entt::entity_id field_entity_value = - *reinterpret_cast( - reinterpret_cast(&comp) + offset - ); + ecsact::entt::entity_id field_entity_value = + *reinterpret_cast( + reinterpret_cast(&comp) + offset + ); - bool found_associated_entity = *assoc_view_itr == - field_entity_value.as_entt(); - if(!found_associated_entity) { - assoc_view_itr = assoc_view.begin(); - for(; assoc_view_itr != assoc_view.end(); ++assoc_view_itr) { - found_associated_entity = *assoc_view_itr == - field_entity_value.as_entt(); - if(found_associated_entity) { - break; + bool found_associated_entity = *assoc_view_itr == + field_entity_value.as_entt(); + if(!found_associated_entity) { + assoc_view_itr = assoc_view.begin(); + for(; assoc_view_itr != assoc_view.end(); ++assoc_view_itr) { + found_associated_entity = *assoc_view_itr == + field_entity_value.as_entt(); + if(found_associated_entity) { + break; + } } } - } - if(!found_associated_entity) { - missing_assoc_entities = true; - } - }); + if(!found_associated_entity) { + missing_assoc_entities = true; + } + }); - if(!missing_assoc_entities) { - _execute_system_user_itr( - info, - view, - assoc_views, - entity, - parent, - action_data, - actions - ); + if(!missing_assoc_entities) { + itr_view_one(entity); - mp_for_each::value>>([&](auto I) { - ++std::get(assoc_views_itrs); - }); + mp_for_each::value>>([&](auto I) { + ++std::get(assoc_views_itrs); + }); + } } } }; diff --git a/runtime/test/runtime_test.ecsact b/runtime/test/runtime_test.ecsact index 046861b4..0b2375b9 100644 --- a/runtime/test/runtime_test.ecsact +++ b/runtime/test/runtime_test.ecsact @@ -111,7 +111,7 @@ component EntityTesting { i32 a; } -system SimpleIncrementImportedComp { +system SimpleIncrementImportedComp(parallel) { readwrite imported.test_pkg.ImportedComponent; }