2019-03-21 20:18:31 +01:00
|
|
|
#include "common.hpp"
|
|
|
|
#include "gta/array.hpp"
|
|
|
|
#include "gta/script_thread.hpp"
|
|
|
|
#include "gta/tls_context.hpp"
|
|
|
|
#include "gta_util.hpp"
|
2019-07-29 23:19:21 +02:00
|
|
|
#include "invoker.hpp"
|
2019-03-21 20:18:31 +01:00
|
|
|
#include "pointers.hpp"
|
|
|
|
#include "script_mgr.hpp"
|
|
|
|
|
|
|
|
namespace big
|
|
|
|
{
|
|
|
|
void script_mgr::add_script(std::unique_ptr<script> script)
|
|
|
|
{
|
|
|
|
std::lock_guard lock(m_mutex);
|
|
|
|
m_scripts.push_back(std::move(script));
|
|
|
|
}
|
|
|
|
|
|
|
|
void script_mgr::remove_all_scripts()
|
|
|
|
{
|
|
|
|
std::lock_guard lock(m_mutex);
|
|
|
|
m_scripts.clear();
|
|
|
|
}
|
|
|
|
|
2022-06-27 20:12:45 +02:00
|
|
|
script_list& script_mgr::scripts()
|
|
|
|
{
|
|
|
|
return m_scripts;
|
|
|
|
}
|
|
|
|
|
2019-03-21 20:18:31 +01:00
|
|
|
void script_mgr::tick()
|
|
|
|
{
|
|
|
|
gta_util::execute_as_script(RAGE_JOAAT("main_persistent"), std::mem_fn(&script_mgr::tick_internal), this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void script_mgr::tick_internal()
|
|
|
|
{
|
|
|
|
static bool ensure_main_fiber = (ConvertThreadToFiber(nullptr), true);
|
2019-07-29 23:19:21 +02:00
|
|
|
static bool ensure_native_handlers = (g_native_invoker.cache_handlers(), true);
|
2019-03-21 20:18:31 +01:00
|
|
|
|
|
|
|
std::lock_guard lock(m_mutex);
|
2022-06-27 20:12:45 +02:00
|
|
|
for (auto const& script : m_scripts)
|
|
|
|
if (script->is_enabled())
|
|
|
|
script->tick();
|
2019-03-21 20:18:31 +01:00
|
|
|
}
|
2022-06-27 20:12:45 +02:00
|
|
|
}
|