Skip to content

Commit

Permalink
feat: use parallel hint for execution
Browse files Browse the repository at this point in the history
  • Loading branch information
zaucy committed Jun 7, 2023
1 parent dd15872 commit 6ab8ab8
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 53 deletions.
10 changes: 5 additions & 5 deletions WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
Expand Down
116 changes: 69 additions & 47 deletions ecsact/entt/runtime.hh
Original file line number Diff line number Diff line change
Expand Up @@ -692,71 +692,93 @@ private:
using caps_info = ecsact::system_capabilities_info<SystemT>;
using associations = typename caps_info::associations;

constexpr auto parallel_hint =
ecsact::system_parallel_execution<SystemT>::value;

auto assoc_views = system_association_views<SystemT>(info.registry);
auto assoc_views_itrs = system_association_views_iterators(assoc_views);

auto view = system_view<SystemT>(info.registry);
const void* action_data = nullptr;

auto itr_view_one = [&](entt_entity_type entity) {
_execute_system_user_itr<SystemT, ChildSystemsListT>(
info,
view,
assoc_views,
entity,
parent,
action_data,
actions
);
};

auto itr_view = [&] {
for(auto entity : view) {
bool missing_assoc_entities = false;
mp_for_each<mp_iota_c<mp_size<associations>::value>>([&](auto I) {
using boost::mp11::mp_at;
using boost::mp11::mp_size_t;
if constexpr(mp_size<associations>::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<mp_iota_c<mp_size<associations>::value>>([&](auto I) {
using boost::mp11::mp_at;
using boost::mp11::mp_size_t;

using Assoc = mp_at<associations, mp_size_t<I>>;
using ComponentT = typename Assoc::component_type;
using Assoc = mp_at<associations, mp_size_t<I>>;
using ComponentT = typename Assoc::component_type;

constexpr auto offset = Assoc::field_offset;
constexpr auto offset = Assoc::field_offset;

auto& assoc_view = std::get<I>(assoc_views);
auto& assoc_view_itr = std::get<I>(assoc_views_itrs);
if(assoc_view.begin() == assoc_view.end()) {
missing_assoc_entities = true;
return;
}
auto& assoc_view = std::get<I>(assoc_views);
auto& assoc_view_itr = std::get<I>(assoc_views_itrs);
if(assoc_view.begin() == assoc_view.end()) {
missing_assoc_entities = true;
return;
}

assert(view.contains(entity));
auto& comp = view.template get<ComponentT>(entity);
assert(view.contains(entity));
auto& comp = view.template get<ComponentT>(entity);

ecsact::entt::entity_id field_entity_value =
*reinterpret_cast<const ecsact_entity_id*>(
reinterpret_cast<const char*>(&comp) + offset
);
ecsact::entt::entity_id field_entity_value =
*reinterpret_cast<const ecsact_entity_id*>(
reinterpret_cast<const char*>(&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<SystemT, ChildSystemsListT>(
info,
view,
assoc_views,
entity,
parent,
action_data,
actions
);
if(!missing_assoc_entities) {
itr_view_one(entity);

mp_for_each<mp_iota_c<mp_size<associations>::value>>([&](auto I) {
++std::get<I>(assoc_views_itrs);
});
mp_for_each<mp_iota_c<mp_size<associations>::value>>([&](auto I) {
++std::get<I>(assoc_views_itrs);
});
}
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion runtime/test/runtime_test.ecsact
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ component EntityTesting {
i32 a;
}

system SimpleIncrementImportedComp {
system SimpleIncrementImportedComp(parallel) {
readwrite imported.test_pkg.ImportedComponent;
}

Expand Down

0 comments on commit 6ab8ab8

Please sign in to comment.