Fix registering ecs constructors & destructors
This commit is contained in:
parent
1da8e341c5
commit
713a479eed
1 changed files with 28 additions and 16 deletions
|
|
@ -390,6 +390,9 @@ namespace psemek::ecs
|
|||
|
||||
std::vector<query_cache> callback_caches_;
|
||||
|
||||
template <typename ... Components, typename Constructor, typename Destructor>
|
||||
query_cache cache_impl(Constructor && constructor, Destructor && destructor);
|
||||
|
||||
detail::table * insert_table(std::vector<std::unique_ptr<detail::column>> columns);
|
||||
void do_destroy(handle const & entity);
|
||||
void remove_row(detail::table & table, std::uint32_t row, util::span<detail::entity_data> entities);
|
||||
|
|
@ -538,16 +541,7 @@ namespace psemek::ecs
|
|||
template <typename ... Components>
|
||||
query_cache container::cache()
|
||||
{
|
||||
typename detail::filter_with <detail::component_uuid_helper, std::tuple<std::remove_cvref_t<Components>...>>::type with_uuids;
|
||||
typename detail::filter_without<detail::component_uuid_helper, std::tuple<std::remove_cvref_t<Components>...>>::type without_uuids;
|
||||
|
||||
auto result = query_cache_container_.create(with_uuids.get(), without_uuids.get());
|
||||
|
||||
table_container_.apply([&](detail::table & table){
|
||||
result->add(&table);
|
||||
}, with_uuids.get(), without_uuids.get());
|
||||
|
||||
return result;
|
||||
return cache_impl<Components...>(nullptr, nullptr);
|
||||
}
|
||||
|
||||
template <typename ... Components, typename Function>
|
||||
|
|
@ -632,9 +626,7 @@ namespace psemek::ecs
|
|||
|
||||
static_assert(invocable_type::value, "function is not invocable with these components");
|
||||
|
||||
query_cache cache = this->cache<Components...>();
|
||||
|
||||
cache->constructor_factory = [function = std::move(function)](std::vector<std::uint32_t> const & column_indices) -> detail::table_callback {
|
||||
auto constructor = [function = std::move(function)](std::vector<std::uint32_t> const & column_indices) -> detail::table_callback {
|
||||
return [function, column_indices](container & container, detail::table & table, std::uint32_t row){
|
||||
typename detail::filter_with<detail::static_apply_helper, std::tuple<Components ...>>::type apply_helper(container, table.entity_handles());
|
||||
|
||||
|
|
@ -646,6 +638,8 @@ namespace psemek::ecs
|
|||
};
|
||||
};
|
||||
|
||||
query_cache cache = this->cache_impl<Components...>(std::move(constructor), nullptr);
|
||||
|
||||
callback_caches_.push_back(cache);
|
||||
}
|
||||
|
||||
|
|
@ -658,9 +652,7 @@ namespace psemek::ecs
|
|||
|
||||
static_assert(invocable_type::value, "function is not invocable with these components");
|
||||
|
||||
query_cache cache = this->cache<Components...>();
|
||||
|
||||
cache->destructor_factory = [function = std::move(function)](std::vector<std::uint32_t> const & column_indices) -> detail::table_callback {
|
||||
auto destructor = [function = std::move(function)](std::vector<std::uint32_t> const & column_indices) -> detail::table_callback {
|
||||
return [function, column_indices](container & container, detail::table & table, std::uint32_t row){
|
||||
typename detail::filter_with<detail::static_apply_helper, std::tuple<Components ...>>::type apply_helper(container, table.entity_handles());
|
||||
|
||||
|
|
@ -672,6 +664,8 @@ namespace psemek::ecs
|
|||
};
|
||||
};
|
||||
|
||||
query_cache cache = this->cache_impl<Components...>(nullptr, std::move(destructor));
|
||||
|
||||
callback_caches_.push_back(cache);
|
||||
}
|
||||
|
||||
|
|
@ -681,4 +675,22 @@ namespace psemek::ecs
|
|||
return index_container_.get<Index>(*this, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename ... Components, typename Constructor, typename Destructor>
|
||||
query_cache container::cache_impl(Constructor && constructor, Destructor && destructor)
|
||||
{
|
||||
typename detail::filter_with <detail::component_uuid_helper, std::tuple<std::remove_cvref_t<Components>...>>::type with_uuids;
|
||||
typename detail::filter_without<detail::component_uuid_helper, std::tuple<std::remove_cvref_t<Components>...>>::type without_uuids;
|
||||
|
||||
auto result = query_cache_container_.create(with_uuids.get(), without_uuids.get());
|
||||
|
||||
result->constructor_factory = std::move(constructor);
|
||||
result->destructor_factory = std::move(destructor);
|
||||
|
||||
table_container_.apply([&](detail::table & table){
|
||||
result->add(&table);
|
||||
}, with_uuids.get(), without_uuids.get());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue