10 #include <NasNas/ecs/Storage.hpp> 14 template<
typename TEntity,
typename... TComps>
17 const components_pool_super* ref_set;
18 const std::tuple<components_pool<TEntity, TComps>*...> pools;
21 std::array<components_pool_super*,
sizeof...(TComps)> pools_vec = {
22 static_cast<components_pool_super*
>(std::get<components_pool<TEntity, TComps>*>(pools))...
24 std::sort(pools_vec.begin(), pools_vec.end(), [] (
auto* lhs,
auto* rhs) {
return lhs->size() < rhs->size();});
25 ref_set = pools_vec[0];
28 template<
typename... Comps>
29 auto get(
const TEntity ent)
const -> decltype(
auto) {
30 if constexpr(
sizeof...(Comps) == 0) {
32 }
else if constexpr(
sizeof...(Comps) == 1) {
39 auto for_each(std::function<
void(Entity, TComps&...)> fn) {
40 for (
auto& ent : ref_set->data()) {
43 std::apply(fn, std::tuple_cat(std::make_tuple(ent), comps_tuple));
48 auto for_each(std::function<
void(Entity)> fn) {
49 for (
auto& ent : ref_set->data()) {
51 std::apply(fn, std::make_tuple(ent));
56 auto for_each(std::function<
void(TComps&...)> fn) {
57 for (
auto& ent : ref_set->data()) {
60 std::apply(fn, comps_tuple);
65 auto for_each_pair(std::function<
void(Entity, Entity)> fn) {
66 for (
auto it1 = ref_set->data().begin(); it1 != ref_set->data().end(); ++it1) {
68 for (
auto it2 = it1+1; it2 != ref_set->data().end(); ++it2) {
70 std::apply(fn, std::make_tuple(*it1, *it2));