Support mutable lambdas in ecs::dispatcher

This commit is contained in:
Nikita Lisitsa 2024-02-05 13:04:53 +03:00
parent 13a86a76c8
commit 04443b1e3a

View file

@ -30,7 +30,7 @@ namespace psemek::ecs
template <typename Event, typename Handler> template <typename Event, typename Handler>
void handler(Handler handler) void handler(Handler handler)
{ {
handlers_[Event::uuid()].push_back([handler = std::move(handler), this](void const * event_ptr){ handlers_[Event::uuid()].push_back([handler = std::move(handler), this](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<Handler, Event const &, ecs::container &>) if constexpr (std::invocable<Handler, Event const &, ecs::container &>)
@ -47,7 +47,7 @@ namespace psemek::ecs
template <typename Event, typename ... Components, typename System> template <typename Event, typename ... Components, typename System>
void system(System system) void system(System system)
{ {
handlers_[Event::uuid()].push_back([system = std::move(system), this, cache = container_->cache<Components...>()](void const * event_ptr){ 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 & ...>) if constexpr (std::invocable<System, Event const &, ecs::container &, handle, Components & ...>)