This repository has been archived on 2024-10-22. You can view files and clone it, but cannot push or open issues or pull requests.
YimMenu/src/script_mgr.cpp
Andreas Maerten e07601347d
refactor: switch RAGE_JOAAT with string literal functions (#2806)
Why? Shorter to write and removes the macro usage

I used the following regex to find all occurrences:
```r
RAGE_JOAAT\("(.*?)"\)
```
then the following to replace it all:
```r
"$1"_J
```
2024-03-12 09:42:11 +01:00

62 lines
1.1 KiB
C++

#include "script_mgr.hpp"
#include "common.hpp"
#include "gta/script_thread.hpp"
#include "gta_util.hpp"
#include "pointers.hpp"
#include "script/tlsContext.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();
}
void script_mgr::tick()
{
gta_util::execute_as_script("main_persistent"_J, std::mem_fn(&script_mgr::tick_internal), this);
}
void script_mgr::ensure_main_fiber()
{
ConvertThreadToFiber(nullptr);
m_can_tick = true;
}
static void lua_manager_tick()
{
g_lua_manager->reload_changed_scripts();
g_lua_manager->for_each_module([](const std::shared_ptr<lua_module>& module) {
module->tick_scripts();
module->cleanup_done_scripts();
});
}
void script_mgr::tick_internal()
{
static bool ensure_it = (ensure_main_fiber(), true);
std::lock_guard lock(m_mutex);
lua_manager_tick();
for (const auto& script : m_scripts)
{
if (script->is_enabled())
script->tick();
}
}
}