Fix ecs::dispatcher to work with ecs::without

This commit is contained in:
Nikita Lisitsa 2024-06-19 14:37:09 +03:00
parent bd202d08ae
commit 37a3d7f827

View file

@ -48,31 +48,25 @@ namespace psemek::ecs
handlers_[Event::uuid()].push_back([system = std::move(system), this, cache = container_->cache<Components...>()](void const * event_ptr) mutable { handlers_[Event::uuid()].push_back([system = std::move(system), this, cache = container_->cache<Components...>()](void const * event_ptr) mutable {
auto const & event = *reinterpret_cast<Event const *>(event_ptr); auto const & event = *reinterpret_cast<Event const *>(event_ptr);
if constexpr (std::invocable<System, Event const &, ecs::container &, handle, Components & ...>) container_->apply<Components...>([&]<typename ... FilteredComponents>(ecs::container & container, ecs::handle entity, FilteredComponents & ... filtered_components){
if constexpr (std::invocable<System, Event const &, ecs::container &, handle, FilteredComponents & ...>)
{ {
container_->apply<Components...>([&](ecs::container & container, ecs::handle handle, Components & ... components){ system(event, container, entity, filtered_components...);
system(event, container, handle, components...);
}, cache);
} }
else if constexpr (std::invocable<System, Event const &, ecs::container &, Components & ...>) else if constexpr (std::invocable<System, Event const &, ecs::container &, FilteredComponents & ...>)
{ {
container_->apply<Components...>([&](ecs::container & container, Components & ... components){ system(event, container, filtered_components...);
system(event, container, components...);
}, cache);
} }
else if constexpr (std::invocable<System, Event const &, handle, Components & ...>) else if constexpr (std::invocable<System, Event const &, handle, FilteredComponents & ...>)
{ {
container_->apply<Components...>([&](ecs::handle handle, Components & ... components){ system(event, entity, filtered_components...);
system(event, handle, components...);
}, cache);
} }
else else
{ {
container_->apply<Components...>([&](Components & ... components){ system(event, filtered_components...);
system(event, components...);
}, cache);
} }
}); });
});
} }
template <typename Event> template <typename Event>