Handle endon conditions on notify

This commit is contained in:
Federico Cecchetto 2022-07-17 20:26:39 +02:00
parent fca5243eb9
commit 2245d9812a
7 changed files with 25 additions and 7 deletions

View File

@ -66,6 +66,8 @@ namespace scripting
e.arguments.emplace_back(*value);
}
lua::engine::handle_endon_conditions(e);
scheduled_notifies.access([&](notify_list& list)
{
list.push_back(e);
@ -75,7 +77,7 @@ namespace scripting
vm_notify_hook.invoke<void>(notify_list_owner_id, string_value, top);
}
void clear_scheduler_notifies()
void clear_scheduled_notifies()
{
scheduled_notifies.access([](notify_list& list)
{
@ -87,7 +89,7 @@ namespace scripting
{
client_spawn_hook.invoke<void>(client);
scr_auto_respawn->current.enabled = true;
clear_scheduler_notifies();
clear_scheduled_notifies();
lua::engine::start();
}
@ -98,7 +100,7 @@ namespace scripting
canonical_string_table.clear();
}
clear_scheduler_notifies();
clear_scheduled_notifies();
lua::engine::stop();
g_shutdown_game_hook.invoke<void>(free_scripts);
}
@ -177,7 +179,7 @@ namespace scripting
if (save_game != nullptr)
{
scr_auto_respawn->current.enabled = true;
clear_scheduler_notifies();
clear_scheduled_notifies();
lua::engine::start();
}
return result;

View File

@ -877,10 +877,15 @@ namespace scripting::lua
void context::notify(const event& e)
{
this->scheduler_.dispatch(e);
this->event_handler_.dispatch(e);
}
void context::handle_endon_conditions(const event& e)
{
this->scheduler_.dispatch(e);
this->event_handler_.handle_endon_conditions(e);
}
void context::load_script(const std::string& script)
{
if (!this->loaded_scripts_.emplace(script).second)

View File

@ -29,6 +29,7 @@ namespace scripting::lua
void run_frame();
void notify(const event& e);
void handle_endon_conditions(const event& e);
std::string load(const std::string& code);

View File

@ -69,6 +69,14 @@ namespace scripting::lua::engine
}
}
void handle_endon_conditions(const event& e)
{
for (auto& script : get_scripts())
{
script->handle_endon_conditions(e);
}
}
void run_frame()
{
for (auto& script : get_scripts())

View File

@ -7,6 +7,7 @@ namespace scripting::lua::engine
void start();
void stop();
void notify(const event& e);
void handle_endon_conditions(const event& e);
void run_frame();
std::optional<std::string> load(const std::string& code);

View File

@ -31,7 +31,6 @@ namespace scripting::lua
callbacks_.access([&](task_list& tasks)
{
this->merge_callbacks();
this->handle_endon_conditions(event);
for (auto i = tasks.begin(); i != tasks.end();)
{
@ -157,6 +156,7 @@ namespace scripting::lua
};
callbacks_.access(deleter);
new_callbacks_.access(deleter);
}
event_arguments event_handler::build_arguments(const event& event) const

View File

@ -40,6 +40,8 @@ namespace scripting::lua
void clear();
void handle_endon_conditions(const event& event);
private:
sol::state& state_;
std::atomic_int64_t current_listener_id_ = 0;
@ -50,7 +52,6 @@ namespace scripting::lua
void remove(const event_listener_handle& handle);
void merge_callbacks();
void handle_endon_conditions(const event& event);
void add_endon_condition(const event_listener_handle& handle, const entity& entity, const std::string& event);