Skip to content

Commit

Permalink
[unity]lazyload统一了,可以用原版的JSClassRegister
Browse files Browse the repository at this point in the history
  • Loading branch information
chexiongsheng committed Oct 15, 2024
1 parent 1585c04 commit 6cf0779
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 23 deletions.
4 changes: 0 additions & 4 deletions unity/native_src_il2cpp/Inc/JSClassRegister.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ PRAGMA_ENABLE_UNDEFINED_IDENTIFIER_WARNINGS
static const FAnsiStringView EditorOnlyPropertySuffix = "_EditorOnly";
#endif

#include <mutex>

namespace PUERTS_NAMESPACE
{
class CFunctionInfo;
Expand Down Expand Up @@ -93,8 +91,6 @@ struct JSENV_API JSClassDefinition

void JSENV_API RegisterJSClass(const JSClassDefinition& ClassDefinition);

std::recursive_mutex& JSENV_API RegisterMutex();

void JSENV_API SetClassTypeInfo(const void* TypeId, const NamedFunctionInfo* ConstructorInfos, const NamedFunctionInfo* MethodInfos,
const NamedFunctionInfo* FunctionInfos, const NamedPropertyInfo* PropertyInfos, const NamedPropertyInfo* VariableInfos);

Expand Down
21 changes: 2 additions & 19 deletions unity/native_src_il2cpp/Src/JSClassRegister.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,25 +69,19 @@ class JSClassRegister
~JSClassRegister();

void RegisterClass(const JSClassDefinition& ClassDefinition);


std::recursive_mutex& RegisterMutex()
{
return RegInfoMutex;
}

void SetClassTypeInfo(const void* TypeId, const NamedFunctionInfo* ConstructorInfos, const NamedFunctionInfo* MethodInfos,
const NamedFunctionInfo* FunctionInfos, const NamedPropertyInfo* PropertyInfos, const NamedPropertyInfo* VariableInfos);

void ForeachRegisterClass(std::function<void(const JSClassDefinition* ClassDefinition)>);

const JSClassDefinition* FindClassByID(const void* TypeId);

void OnClassNotFound(ClassNotFoundCallback InCallback)
{
ClassNotFoundCallback = InCallback;
}

const JSClassDefinition* LoadClassByID(const void* TypeId)
{
auto clsDef = FindClassByID(TypeId);
Expand Down Expand Up @@ -115,7 +109,6 @@ class JSClassRegister
private:
std::map<const void*, JSClassDefinition*> CDataIdToClassDefinition;
std::map<std::string, JSClassDefinition*> CDataNameToClassDefinition;
std::recursive_mutex RegInfoMutex;
ClassNotFoundCallback ClassNotFoundCallback = nullptr;
#if USING_IN_UNREAL_ENGINE
std::map<std::string, AddonRegisterFunc> AddonRegisterInfos;
Expand All @@ -129,7 +122,6 @@ JSClassRegister::JSClassRegister()

JSClassRegister::~JSClassRegister()
{
std::lock_guard<std::recursive_mutex> guard(RegInfoMutex);
for (auto& KV : CDataIdToClassDefinition)
{
JSClassDefinitionDelete(KV.second);
Expand All @@ -146,7 +138,6 @@ JSClassRegister::~JSClassRegister()

void JSClassRegister::RegisterClass(const JSClassDefinition& ClassDefinition)
{
std::lock_guard<std::recursive_mutex> guard(RegInfoMutex);
if (ClassDefinition.TypeId && ClassDefinition.ScriptName)
{
auto cd_iter = CDataIdToClassDefinition.find(ClassDefinition.TypeId);
Expand Down Expand Up @@ -222,7 +213,6 @@ void JSClassRegister::SetClassTypeInfo(const void* TypeId, const NamedFunctionIn

const JSClassDefinition* JSClassRegister::FindClassByID(const void* TypeId)
{
std::lock_guard<std::recursive_mutex> guard(RegInfoMutex);
auto Iter = CDataIdToClassDefinition.find(TypeId);
if (Iter == CDataIdToClassDefinition.end())
{
Expand All @@ -236,7 +226,6 @@ const JSClassDefinition* JSClassRegister::FindClassByID(const void* TypeId)

const JSClassDefinition* JSClassRegister::FindCppTypeClassByName(const std::string& Name)
{
std::lock_guard<std::recursive_mutex> guard(RegInfoMutex);
auto Iter = CDataNameToClassDefinition.find(Name);
if (Iter == CDataNameToClassDefinition.end())
{
Expand Down Expand Up @@ -283,7 +272,6 @@ const JSClassDefinition* JSClassRegister::FindClassByType(UStruct* Type)

void JSClassRegister::ForeachRegisterClass(std::function<void(const JSClassDefinition* ClassDefinition)> Callback)
{
std::lock_guard<std::recursive_mutex> guard(RegInfoMutex);
for (auto& KV : CDataNameToClassDefinition)
{
Callback(KV.second);
Expand Down Expand Up @@ -313,11 +301,6 @@ void SetClassTypeInfo(const void* TypeId, const NamedFunctionInfo* ConstructorIn
GetJSClassRegister()->SetClassTypeInfo(TypeId, ConstructorInfos, MethodInfos, FunctionInfos, PropertyInfos, VariableInfos);
}

std::recursive_mutex& RegisterMutex()
{
return GetJSClassRegister()->RegisterMutex();
}

void ForeachRegisterClass(std::function<void(const JSClassDefinition* ClassDefinition)> Callback)
{
GetJSClassRegister()->ForeachRegisterClass(Callback);
Expand Down

0 comments on commit 6cf0779

Please sign in to comment.