Cache native handlers

This commit is contained in:
Pocakking 2019-07-29 23:19:21 +02:00
parent 91c688b395
commit 9538705b21
3 changed files with 13 additions and 12 deletions

View File

@ -12,18 +12,15 @@ namespace big
m_args = &m_arg_stack[0];
}
bool native_invoker::map_native(rage::scrNativeHash *hash)
void native_invoker::cache_handlers()
{
for (auto const &mapping : g_crossmap)
for (const rage::scrNativeMapping &mapping : g_crossmap)
{
if (mapping.first == *hash)
{
*hash = mapping.second;
return true;
}
}
rage::scrNativeHandler handler = g_pointers->m_get_native_handler(
g_pointers->m_native_registration_table, mapping.second);
return false;
m_handler_cache.emplace(mapping.first, handler);
}
}
void native_invoker::begin_call()
@ -33,9 +30,10 @@ namespace big
void native_invoker::end_call(rage::scrNativeHash hash)
{
map_native(&hash);
if (auto handler = g_pointers->m_get_native_handler(g_pointers->m_native_registration_table, hash))
if (auto it = m_handler_cache.find(hash); it != m_handler_cache.end())
{
rage::scrNativeHandler handler = it->second;
__try
{
handler(&m_call_context);

View File

@ -19,7 +19,7 @@ namespace big
explicit native_invoker() = default;
~native_invoker() = default;
bool map_native(rage::scrNativeHash *hash);
void cache_handlers();
void begin_call();
void end_call(rage::scrNativeHash hash);
@ -37,6 +37,7 @@ namespace big
}
private:
native_call_context m_call_context;
std::unordered_map<rage::scrNativeHash, rage::scrNativeHandler> m_handler_cache;
};
inline native_invoker g_native_invoker;

View File

@ -3,6 +3,7 @@
#include "gta/script_thread.hpp"
#include "gta/tls_context.hpp"
#include "gta_util.hpp"
#include "invoker.hpp"
#include "pointers.hpp"
#include "script_mgr.hpp"
@ -28,6 +29,7 @@ namespace big
void script_mgr::tick_internal()
{
static bool ensure_main_fiber = (ConvertThreadToFiber(nullptr), true);
static bool ensure_native_handlers = (g_native_invoker.cache_handlers(), true);
std::lock_guard lock(m_mutex);
for (auto const &script : m_scripts)