Skip to content

Commit d905e9b

Browse files
Kelwanzaucy
andauthored
Debugging actions and fixed trivial system checks (#16)
Co-authored-by: Ezekiel Warren <[email protected]>
1 parent 56542e5 commit d905e9b

File tree

3 files changed

+61
-68
lines changed

3 files changed

+61
-68
lines changed

ecsact/entt/runtime.hh

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -669,13 +669,16 @@ namespace ecsact::entt {
669669
)
670670
{
671671
using boost::mp11::mp_empty;
672+
const auto system_id = ecsact_id_cast<ecsact_system_like_id>(SystemT::id);
672673

673674
const void* action_data = nullptr;
674-
auto each_cb = [&](auto& view, auto entity) {
675+
auto each_cb = [&](auto& view, auto& assoc_views, auto entity) {
675676
if constexpr(!mp_empty<ChildSystemsListT>::value) {
676677
system_execution_context<SystemT> ctx(
677678
info,
679+
system_id,
678680
view,
681+
assoc_views,
679682
entity,
680683
parent,
681684
action_data
@@ -692,17 +695,11 @@ namespace ecsact::entt {
692695
for(auto& action : actions) {
693696
if(action.action_id == SystemT::id) {
694697
action_data = action.action_data;
695-
trivial_system_impl<package, SystemT>(
696-
info.registry,
697-
each_cb
698-
);
698+
trivial_system_impl<SystemT>(info, each_cb);
699699
}
700700
}
701701
} else {
702-
trivial_system_impl<package, SystemT>(
703-
info.registry,
704-
each_cb
705-
);
702+
trivial_system_impl<SystemT>(info, each_cb);
706703
}
707704
}
708705

@@ -838,7 +835,7 @@ namespace ecsact::entt {
838835
, const actions_span_t& actions
839836
)
840837
{
841-
if constexpr(is_trivial_system<package, SystemT>()) {
838+
if constexpr(is_trivial_system<SystemT>()) {
842839
_execute_system_trivial<SystemT, ChildSystemsListT>(
843840
info,
844841
parent,

ecsact/entt/system_view.hh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ namespace ecsact::entt {
4444
using readonly_components = typename caps_info::readonly_components;
4545
using readwrite_components = typename caps_info::readwrite_components;
4646
using removes_components = typename caps_info::removes_components;
47+
using adds_components = typename caps_info::adds_components;
4748
using include_components = typename caps_info::include_components;
4849
using exclude_components = typename caps_info::exclude_components;
4950

@@ -52,6 +53,7 @@ namespace ecsact::entt {
5253
readonly_components,
5354
readwrite_components,
5455
include_components,
56+
removes_components,
5557
mp_transform<beforechange_storage, readwrite_components>
5658
>,
5759
::ecsact::mp_list<>
@@ -60,7 +62,7 @@ namespace ecsact::entt {
6062
using exclude_types = mp_unique<mp_flatten<
6163
mp_push_back<
6264
exclude_components,
63-
removes_components
65+
adds_components
6466
>,
6567
::ecsact::mp_list<>
6668
>>;

ecsact/entt/trivial_system_impl.hh

Lines changed: 51 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@
66

77
namespace ecsact::entt {
88

9+
template<typename T>
10+
using is_not_empty = boost::mp11::mp_not<std::is_empty<T>>;
11+
912
/**
1013
* Checks if a system 'trivial' i.e. there is only a single possible
1114
* meaningful implementation.
1215
*/
13-
template<typename Package, typename SystemT>
16+
template<typename SystemT>
1417
constexpr bool is_trivial_system() {
1518
using boost::mp11::mp_filter;
1619
using boost::mp11::mp_empty;
@@ -22,81 +25,72 @@ namespace ecsact::entt {
2225
using readonly_components = typename caps_info::readonly_components;
2326
using readwrite_components = typename caps_info::readwrite_components;
2427
using writeonly_components = typename caps_info::writeonly_components;
28+
using include_components = typename caps_info::include_components;
29+
using exclude_components = typename caps_info::exclude_components;
2530
using adds_components = typename caps_info::adds_components;
2631
using removes_components = typename caps_info::removes_components;
2732
using adds_tag_components = mp_filter<std::is_empty, adds_components>;
33+
using remove_tag_components = mp_filter<std::is_empty, removes_components>;
34+
using adds_non_tag_components = mp_filter<is_not_empty, adds_components>;
35+
36+
const bool can_add = !mp_empty<adds_components>::value;
37+
const bool can_remove = !mp_empty<removes_components>::value;
38+
const bool can_add_non_tag = !mp_empty<adds_non_tag_components>::value;
39+
40+
const bool can_only_add_tag =
41+
mp_size<adds_tag_components>::value == mp_size<adds_components>::value;
42+
43+
const bool has_only_trivial_modifiers = can_remove || can_only_add_tag;
44+
const bool can_access =
45+
!mp_empty<readwrite_components>::value ||
46+
!mp_empty<readonly_components>::value ||
47+
!mp_empty<writeonly_components>::value;
48+
49+
if(!can_access && has_only_trivial_modifiers) {
50+
return true;
51+
}
2852

29-
const bool can_add_non_tag_compnents =
30-
mp_size<adds_components>::value != 0 && (
31-
mp_size<adds_tag_components>::value !=
32-
mp_size<adds_components>::value
33-
);
3453
const bool cant_write =
35-
mp_empty<readwrite_components>::value &&
36-
mp_empty<writeonly_components>::value;
37-
const bool cant_add = mp_empty<adds_components>::value;
38-
const bool cant_remove = mp_empty<removes_components>::value;
39-
const bool cant_read =
40-
mp_empty<readonly_components>::value &&
54+
mp_empty<writeonly_components>::value &&
4155
mp_empty<readwrite_components>::value;
56+
const bool has_modifiers = can_add || can_remove;
57+
58+
if(cant_write && !has_modifiers) {
59+
return true;
60+
}
4261

43-
return cant_write && cant_add && cant_remove && cant_read;
62+
return false;
4463
}
4564

46-
template<typename Package, typename SystemT, typename EachCallbackT>
47-
requires (is_trivial_system<Package, SystemT>())
65+
template<typename SystemT, typename EachCallbackT>
66+
requires (is_trivial_system<SystemT>())
4867
void trivial_system_impl
49-
( ::entt::registry& registry
50-
, EachCallbackT&& each_callback = [](auto&, auto){}
68+
( auto& info
69+
, EachCallbackT&& each_callback = [](auto&, auto&, auto){}
5170
)
5271
{
53-
using boost::mp11::mp_empty;
54-
using boost::mp11::mp_list;
5572
using boost::mp11::mp_for_each;
5673

5774
using caps_info = ecsact::system_capabilities_info<SystemT>;
58-
59-
using readonly_components = typename caps_info::readonly_components;
60-
using readwrite_components = typename caps_info::readwrite_components;
61-
using writeonly_components = typename caps_info::writeonly_components;
6275
using adds_components = typename caps_info::adds_components;
6376
using removes_components = typename caps_info::removes_components;
64-
using include_components = typename caps_info::include_components;
65-
using exclude_components = typename caps_info::exclude_components;
66-
using optional_components = typename caps_info::optional_components;
67-
68-
// If we have a system that can only remove and does not use any filtering
69-
// i.e. simply removes all of a component, then we can use a short cut and
70-
// use `registry.clear`.
71-
constexpr bool is_removes_only =
72-
!mp_empty<removes_components>::value &&
73-
mp_empty<readonly_components>::value &&
74-
mp_empty<readwrite_components>::value &&
75-
mp_empty<optional_components>::value &&
76-
mp_empty<adds_components>::value &&
77-
mp_empty<include_components>::value &&
78-
mp_empty<exclude_components>::value;
79-
80-
if constexpr(is_removes_only) {
77+
78+
auto view = system_view<SystemT>(info.registry);
79+
// TODO(zaucy): Iterate over association views in trivial systems
80+
auto assoc_views = system_association_views<SystemT>(info.registry);
81+
for(auto entity : view) {
82+
mp_for_each<adds_components>([&]<typename C>(C) {
83+
// Only empty components should have made it into this list if the
84+
// `is_trivial_system` constraint succeeded.
85+
static_assert(std::is_empty_v<C>);
86+
info.template add_component<C>(entity);
87+
});
88+
8189
mp_for_each<removes_components>([&]<typename C>(C) {
82-
registry.clear<C>();
90+
info.template remove_component<C>(entity);
8391
});
84-
} else {
85-
auto view = system_view<Package, SystemT>(registry);
86-
for(auto entity : view) {
87-
mp_for_each<adds_components>([&]<typename C>(C) {
88-
// Only empty comopnents should have made it into this list if the
89-
// `is_trivial_system` constraint succeeded.
90-
static_assert(std::is_empty_v<C>);
91-
registry.emplace<C>(entity);
92-
});
93-
94-
mp_for_each<removes_components>([&]<typename C>(C) {
95-
registry.erase<C>(entity);
96-
});
97-
98-
each_callback(view, entity);
99-
}
92+
93+
each_callback(view, assoc_views, entity);
10094
}
10195
}
10296

0 commit comments

Comments
 (0)