Handle endon conditions on notify
This commit is contained in:
parent
fca5243eb9
commit
2245d9812a
@ -66,6 +66,8 @@ namespace scripting
|
|||||||
e.arguments.emplace_back(*value);
|
e.arguments.emplace_back(*value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lua::engine::handle_endon_conditions(e);
|
||||||
|
|
||||||
scheduled_notifies.access([&](notify_list& list)
|
scheduled_notifies.access([&](notify_list& list)
|
||||||
{
|
{
|
||||||
list.push_back(e);
|
list.push_back(e);
|
||||||
@ -75,7 +77,7 @@ namespace scripting
|
|||||||
vm_notify_hook.invoke<void>(notify_list_owner_id, string_value, top);
|
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)
|
scheduled_notifies.access([](notify_list& list)
|
||||||
{
|
{
|
||||||
@ -87,7 +89,7 @@ namespace scripting
|
|||||||
{
|
{
|
||||||
client_spawn_hook.invoke<void>(client);
|
client_spawn_hook.invoke<void>(client);
|
||||||
scr_auto_respawn->current.enabled = true;
|
scr_auto_respawn->current.enabled = true;
|
||||||
clear_scheduler_notifies();
|
clear_scheduled_notifies();
|
||||||
lua::engine::start();
|
lua::engine::start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,7 +100,7 @@ namespace scripting
|
|||||||
canonical_string_table.clear();
|
canonical_string_table.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
clear_scheduler_notifies();
|
clear_scheduled_notifies();
|
||||||
lua::engine::stop();
|
lua::engine::stop();
|
||||||
g_shutdown_game_hook.invoke<void>(free_scripts);
|
g_shutdown_game_hook.invoke<void>(free_scripts);
|
||||||
}
|
}
|
||||||
@ -177,7 +179,7 @@ namespace scripting
|
|||||||
if (save_game != nullptr)
|
if (save_game != nullptr)
|
||||||
{
|
{
|
||||||
scr_auto_respawn->current.enabled = true;
|
scr_auto_respawn->current.enabled = true;
|
||||||
clear_scheduler_notifies();
|
clear_scheduled_notifies();
|
||||||
lua::engine::start();
|
lua::engine::start();
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -877,10 +877,15 @@ namespace scripting::lua
|
|||||||
|
|
||||||
void context::notify(const event& e)
|
void context::notify(const event& e)
|
||||||
{
|
{
|
||||||
this->scheduler_.dispatch(e);
|
|
||||||
this->event_handler_.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)
|
void context::load_script(const std::string& script)
|
||||||
{
|
{
|
||||||
if (!this->loaded_scripts_.emplace(script).second)
|
if (!this->loaded_scripts_.emplace(script).second)
|
||||||
|
@ -29,6 +29,7 @@ namespace scripting::lua
|
|||||||
|
|
||||||
void run_frame();
|
void run_frame();
|
||||||
void notify(const event& e);
|
void notify(const event& e);
|
||||||
|
void handle_endon_conditions(const event& e);
|
||||||
|
|
||||||
std::string load(const std::string& code);
|
std::string load(const std::string& code);
|
||||||
|
|
||||||
|
@ -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()
|
void run_frame()
|
||||||
{
|
{
|
||||||
for (auto& script : get_scripts())
|
for (auto& script : get_scripts())
|
||||||
|
@ -7,6 +7,7 @@ namespace scripting::lua::engine
|
|||||||
void start();
|
void start();
|
||||||
void stop();
|
void stop();
|
||||||
void notify(const event& e);
|
void notify(const event& e);
|
||||||
|
void handle_endon_conditions(const event& e);
|
||||||
void run_frame();
|
void run_frame();
|
||||||
|
|
||||||
std::optional<std::string> load(const std::string& code);
|
std::optional<std::string> load(const std::string& code);
|
||||||
|
@ -31,7 +31,6 @@ namespace scripting::lua
|
|||||||
callbacks_.access([&](task_list& tasks)
|
callbacks_.access([&](task_list& tasks)
|
||||||
{
|
{
|
||||||
this->merge_callbacks();
|
this->merge_callbacks();
|
||||||
this->handle_endon_conditions(event);
|
|
||||||
|
|
||||||
for (auto i = tasks.begin(); i != tasks.end();)
|
for (auto i = tasks.begin(); i != tasks.end();)
|
||||||
{
|
{
|
||||||
@ -157,6 +156,7 @@ namespace scripting::lua
|
|||||||
};
|
};
|
||||||
|
|
||||||
callbacks_.access(deleter);
|
callbacks_.access(deleter);
|
||||||
|
new_callbacks_.access(deleter);
|
||||||
}
|
}
|
||||||
|
|
||||||
event_arguments event_handler::build_arguments(const event& event) const
|
event_arguments event_handler::build_arguments(const event& event) const
|
||||||
|
@ -40,6 +40,8 @@ namespace scripting::lua
|
|||||||
|
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
|
void handle_endon_conditions(const event& event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
sol::state& state_;
|
sol::state& state_;
|
||||||
std::atomic_int64_t current_listener_id_ = 0;
|
std::atomic_int64_t current_listener_id_ = 0;
|
||||||
@ -50,7 +52,6 @@ namespace scripting::lua
|
|||||||
|
|
||||||
void remove(const event_listener_handle& handle);
|
void remove(const event_listener_handle& handle);
|
||||||
void merge_callbacks();
|
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);
|
void add_endon_condition(const event_listener_handle& handle, const entity& entity, const std::string& event);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user