Support non-default-constructible per-species component types in util::ecs
This commit is contained in:
parent
a944f8c4f4
commit
4f53537d27
1 changed files with 4 additions and 4 deletions
|
|
@ -53,7 +53,7 @@ namespace psemek::util
|
||||||
template <typename Behavior>
|
template <typename Behavior>
|
||||||
void apply(Behavior & behavior)
|
void apply(Behavior & behavior)
|
||||||
{
|
{
|
||||||
apply_impl(behavior, typename Behavior::component_types{});
|
apply_impl(behavior, static_cast<typename Behavior::component_types *>(nullptr), std::make_index_sequence<std::tuple_size_v<typename Behavior::component_types>>{});
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~species_base() {}
|
virtual ~species_base() {}
|
||||||
|
|
@ -65,12 +65,12 @@ namespace psemek::util
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
template <typename Behavior, typename ... Components>
|
template <typename Behavior, typename ... Components, std::size_t ... Is>
|
||||||
void apply_impl(Behavior & behavior, std::tuple<Components...>)
|
void apply_impl(Behavior & behavior, std::tuple<Components...> *, std::index_sequence<Is...>)
|
||||||
{
|
{
|
||||||
std::tuple<typename Components::data * ...> cptrs;
|
std::tuple<typename Components::data * ...> cptrs;
|
||||||
|
|
||||||
((std::get<typename Components::data *>(cptrs) = get_entity_component<Components>()), ...);
|
((std::get<Is>(cptrs) = get_entity_component<Components>()), ...);
|
||||||
|
|
||||||
auto all_nonzero = [](auto * ... ptrs)
|
auto all_nonzero = [](auto * ... ptrs)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue