From b415019c37a539652556c1120ffd6c909183a067 Mon Sep 17 00:00:00 2001 From: Federico Cecchetto Date: Sun, 13 Mar 2022 23:40:22 +0100 Subject: [PATCH] Better fix --- .../game/scripting/lua/event_handler.cpp | 22 ++++++++++--------- .../game/scripting/lua/event_handler.hpp | 2 +- src/client/game/scripting/lua/scheduler.cpp | 10 ++++----- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/client/game/scripting/lua/event_handler.cpp b/src/client/game/scripting/lua/event_handler.cpp index ef8597ce..c009bfd0 100644 --- a/src/client/game/scripting/lua/event_handler.cpp +++ b/src/client/game/scripting/lua/event_handler.cpp @@ -31,28 +31,30 @@ namespace scripting::lua this->merge_callbacks(); this->handle_endon_conditions(event); - for (auto i = tasks.begin(); i != tasks.end();) + auto size = tasks.size(); + for (auto i = 0; i < tasks.size();) { - if (i->event != event.name || i->entity != event.entity) + const auto task = tasks[i]; + if (task.event != event.name || task.entity != event.entity) { ++i; continue; } - if (!i->is_deleted) + if (!task.is_deleted) { - if(!has_built_arguments) + if (!has_built_arguments) { has_built_arguments = true; arguments = this->build_arguments(event); } - handle_error(i->callback(sol::as_args(arguments))); + handle_error(task.callback(sol::as_args(arguments))); } - if (i->is_volatile || i->is_deleted) + if (task.is_volatile || task.is_deleted) { - i = tasks.erase(i); + tasks.erase(tasks.begin() + i); } else { @@ -144,11 +146,11 @@ namespace scripting::lua { auto deleter = [&](task_list& tasks) { - for(auto& task : tasks) + for (auto& task : tasks) { - for(auto& condition : task.endon_conditions) + for (auto& condition : task.endon_conditions) { - if(condition.first == event.entity && condition.second == event.name) + if (condition.first == event.entity && condition.second == event.name) { task.is_deleted = true; break; diff --git a/src/client/game/scripting/lua/event_handler.hpp b/src/client/game/scripting/lua/event_handler.hpp index e12dcab6..fc95b704 100644 --- a/src/client/game/scripting/lua/event_handler.hpp +++ b/src/client/game/scripting/lua/event_handler.hpp @@ -43,7 +43,7 @@ namespace scripting::lua sol::state& state_; std::atomic_int64_t current_listener_id_ = 0; - using task_list = std::list; + using task_list = std::vector; utils::concurrency::container new_callbacks_; utils::concurrency::container callbacks_; diff --git a/src/client/game/scripting/lua/scheduler.cpp b/src/client/game/scripting/lua/scheduler.cpp index 1afb7df2..77efcf09 100644 --- a/src/client/game/scripting/lua/scheduler.cpp +++ b/src/client/game/scripting/lua/scheduler.cpp @@ -23,11 +23,11 @@ namespace scripting::lua { auto deleter = [&](task_list& tasks) { - for(auto& task : tasks) + for (auto& task : tasks) { - for(auto& condition : task.endon_conditions) + for (auto& condition : task.endon_conditions) { - if(condition.first == event.entity && condition.second == event.name) + if (condition.first == event.entity && condition.second == event.name) { task.is_deleted = true; break; @@ -122,9 +122,9 @@ namespace scripting::lua { auto merger = [&](task_list& tasks) { - for(auto& task : tasks) + for (auto& task : tasks) { - if(task.id == handle.id) + if (task.id == handle.id) { task.endon_conditions.emplace_back(entity, event); }