Skip to content

Commit

Permalink
[unity]彻底去掉UnityExports4Puerts.h
Browse files Browse the repository at this point in the history
  • Loading branch information
chexiongsheng committed Oct 15, 2024
1 parent d3220b0 commit 76a3ec2
Show file tree
Hide file tree
Showing 15 changed files with 16 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ export default function Gen(genInfos) {
#include "utils/StringUtils.h"
#include "gc/WriteBarrier.h"
#include "pesapi.h"
#include "UnityExports4Puerts.h"
#include "TDataTrans.h"
#include "PuertsValueType.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ export default function Gen(genInfos) {
#include "utils/StringUtils.h"
#include "gc/WriteBarrier.h"
#include "pesapi.h"
#include "UnityExports4Puerts.h"
#include "TDataTrans.h"
#include "PuertsValueType.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export default function Gen(genInfos) {
#include "il2cpp-object-internals.h"
#include "vm/Object.h"
#include "pesapi.h"
#include "UnityExports4Puerts.h"
#include "TDataTrans.h"
namespace puerts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ export default function Gen(genInfos) {
#include "utils/StringUtils.h"
#include "gc/WriteBarrier.h"
#include "pesapi.h"
#include "UnityExports4Puerts.h"
#include "TDataTrans.h"
#include "PuertsValueType.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include "gc/WriteBarrier.h"
#include "gc/GCHandle.h"
#include "pesapi.h"
#include "UnityExports4Puerts.h"
#include "TDataTrans.h"

#include <vector>
Expand Down Expand Up @@ -413,8 +412,6 @@ void* GetDefaultValuePtr(const MethodInfo* method, uint32_t index)
return (defaultValue && Class::IsValuetype(Class::FromIl2CppType(Method::GetParam(method, index), false))) ? Object::Unbox(defaultValue) : defaultValue;
}

static puerts::UnityExports g_unityExports;

void PLog(const char* Fmt, ...)
{
static char SLogBuffer[1024];
Expand All @@ -423,10 +420,10 @@ void PLog(const char* Fmt, ...)
vsnprintf(SLogBuffer, sizeof(SLogBuffer), Fmt, list);
va_end(list);

if (g_unityExports.LogCallback)
{
g_unityExports.LogCallback(SLogBuffer);
}
//if (g_unityExports.LogCallback)
//{
// g_unityExports.LogCallback(SLogBuffer);
//}
}

static void* CtorCallback(pesapi_callback_info info)
Expand Down Expand Up @@ -864,7 +861,7 @@ handle_underlying:
{
if (IsDelegate(klass))
{
JsClassInfoHeader* jsClassInfo = g_unityExports.GetJsClassInfo(klass, true);
JsClassInfoHeader* jsClassInfo = (JsClassInfoHeader*)pesapi_load_class_data(klass, true);
if (!jsClassInfo)
{
Exception::Raise(Exception::GetInvalidOperationException("call not load type of delegate"));
Expand Down Expand Up @@ -1757,12 +1754,6 @@ Il2CppObject* GetJSObjectValue(Il2CppObject* jsObject, Il2CppString* key, Il2Cpp
return JsValueToCSRef(type, env, val);
}

puerts::UnityExports* GetUnityExports()
{
//g_unityExports.CSharpTypeToTypeId = &CSharpTypeToTypeId;
return &g_unityExports;
}

Il2CppObject* EvalInternal(intptr_t ptr, Il2CppArray * __code, Il2CppString* __path, Il2CppReflectionType *__type)
{
pesapi_env_ref envRef = reinterpret_cast<pesapi_env_ref>(ptr);
Expand Down Expand Up @@ -1955,7 +1946,6 @@ void InitialPuerts(pesapi_func_ptr* func_array)
InternalCalls::Add("PuertsIl2cpp.NativeAPI::SetGlobalType_TypedValue(System.Type)", (Il2CppMethodPointer)puerts::SetGlobalType_TypedValue);
InternalCalls::Add("PuertsIl2cpp.NativeAPI::SetGlobalType_JSObject(System.Type)", (Il2CppMethodPointer)puerts::SetGlobalType_JSObject);
InternalCalls::Add("PuertsIl2cpp.NativeAPI::SetGlobalType_ArrayBuffer(System.Type)", (Il2CppMethodPointer)puerts::SetGlobalType_ArrayBuffer);
InternalCalls::Add("PuertsIl2cpp.NativeAPI::GetUnityExports()", (Il2CppMethodPointer)puerts::GetUnityExports);
InternalCalls::Add("PuertsIl2cpp.NativeAPI::EvalInternal(System.IntPtr,System.Byte[],System.String,System.Type)", (Il2CppMethodPointer)puerts::EvalInternal);
InternalCalls::Add("PuertsIl2cpp.NativeAPI::SetObjectToGlobal(System.IntPtr,System.String,System.Object)", (Il2CppMethodPointer)puerts::SetObjectToGlobal);
InternalCalls::Add("PuertsIl2cpp.NativeAPI::TypeIdToType(System.IntPtr)", (Il2CppMethodPointer)puerts::TypeIdToType);
Expand Down Expand Up @@ -2144,7 +2134,7 @@ void SetTypeInfo(puerts::WrapData* data, int index, Il2CppClass* typeInfo)

bool RegisterCSharpType(puerts::JsClassInfo* classInfo)
{
if (pesapi_find_class_data(classInfo->TypeId))
if (pesapi_load_class_data(classInfo->TypeId, false))
{
ReleaseCSharpTypeInfo(classInfo);
return true;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ PESAPI_EXTERN void pesapi_define_class(const void* type_id, const void* super_ty
pesapi_constructor constructor, pesapi_finalize finalize, size_t property_count, pesapi_property_descriptor properties,
void* data);

PESAPI_EXTERN void* pesapi_find_class_data(const void* type_id);
PESAPI_EXTERN void* pesapi_load_class_data(const void* type_id, bool callback_if_not_found);

PESAPI_EXTERN void pesapi_on_class_not_found(pesapi_class_not_found_callback callback);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -544,10 +544,10 @@ void pesapi_define_class (const void* type_id, const void* super_type_id, const
pesapi_define_class_ptr(type_id, super_type_id, type_name, constructor, finalize, property_count, properties, data);
}

typedef void* (*pesapi_find_class_dataType)(const void* type_id);
static pesapi_find_class_dataType pesapi_find_class_data_ptr;
void* pesapi_find_class_data (const void* type_id) {
return pesapi_find_class_data_ptr(type_id);
typedef void* (*pesapi_load_class_dataType)(const void* type_id, bool callback_if_not_found);
static pesapi_load_class_dataType pesapi_load_class_data_ptr;
void* pesapi_load_class_data (const void* type_id, bool callback_if_not_found) {
return pesapi_load_class_data_ptr(type_id, callback_if_not_found);
}

typedef void (*pesapi_on_class_not_foundType)(pesapi_class_not_found_callback callback);
Expand Down Expand Up @@ -661,7 +661,7 @@ void pesapi_init(pesapi_func_ptr* func_array){
pesapi_set_method_info_ptr = (pesapi_set_method_infoType)func_array[85];
pesapi_set_property_info_ptr = (pesapi_set_property_infoType)func_array[86];
pesapi_define_class_ptr = (pesapi_define_classType)func_array[87];
pesapi_find_class_data_ptr = (pesapi_find_class_dataType)func_array[88];
pesapi_load_class_data_ptr = (pesapi_load_class_dataType)func_array[88];
pesapi_on_class_not_found_ptr = (pesapi_on_class_not_foundType)func_array[89];
pesapi_class_type_info_ptr = (pesapi_class_type_infoType)func_array[90];
pesapi_find_type_id_ptr = (pesapi_find_type_idType)func_array[91];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,6 @@ public static void CopyXIl2cppCPlugin(string outDir)
{ "pesapi_adpt.c", Resources.Load<TextAsset>("puerts/xil2cpp/pesapi_adpt.c").text },
{ "pesapi.h", Resources.Load<TextAsset>("puerts/xil2cpp/pesapi.h").text },
{ "Puerts_il2cpp.cpp", Resources.Load<TextAsset>("puerts/xil2cpp/Puerts_il2cpp.cpp").text },
{ "UnityExports4Puerts.h", Resources.Load<TextAsset>("puerts/xil2cpp/UnityExports4Puerts.h").text },
{ "TDataTrans.h", Resources.Load<TextAsset>("puerts/xil2cpp/TDataTrans.h").text }
};

Expand Down
1 change: 0 additions & 1 deletion unity/Assets/core/upm/Runtime/Src/IL2Cpp/JsEnv.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ public JsEnv(ILoader loader, int debugPort = -1)
//only once is enough
PuertsIl2cpp.NativeAPI.SetLogCallback(PuertsIl2cpp.NativeAPI.Log);
PuertsIl2cpp.NativeAPI.InitialPuerts(PuertsIl2cpp.NativeAPI.GetPesapiImpl());
PuertsIl2cpp.NativeAPI.ExchangeAPI(PuertsIl2cpp.NativeAPI.GetUnityExports());
tryLoadTypeMethodInfo = typeof(TypeRegister).GetMethod("RegisterNoThrow");
PuertsIl2cpp.NativeAPI.SetTryLoadCallback(PuertsIl2cpp.NativeAPI.GetMethodInfoPointer(tryLoadTypeMethodInfo), PuertsIl2cpp.NativeAPI.GetMethodPointer(tryLoadTypeMethodInfo));

Expand Down
9 changes: 0 additions & 9 deletions unity/Assets/core/upm/Runtime/Src/IL2Cpp/Native/NativeAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,6 @@ public static void CleanupPapiEnvRef(IntPtr envRef)

[DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)]
public static extern bool RegisterCSharpType(IntPtr classInfo);

[DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)]
public static extern void ExchangeAPI(IntPtr exports);

[DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)]
public static extern void SetObjectPool(IntPtr jsEnv, IntPtr objectPoolAddMethodInfo, IntPtr objectPoolAdd, IntPtr objectPoolRemoveMethodInfo, IntPtr objectPoolRemove, IntPtr objectPoolInstance);
Expand Down Expand Up @@ -173,12 +170,6 @@ public static Type TypeIdToType(IntPtr typeId)
throw new NotImplementedException();
}

[MethodImpl(MethodImplOptions.InternalCall)]
public static IntPtr GetUnityExports()
{
throw new NotImplementedException();
}

[MethodImpl(MethodImplOptions.InternalCall)]
public static void SetGlobalType_JSObject(Type type)
{
Expand Down
2 changes: 1 addition & 1 deletion unity/native_src_il2cpp/Inc/pesapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ PESAPI_EXTERN void pesapi_define_class(const void* type_id, const void* super_ty
pesapi_constructor constructor, pesapi_finalize finalize, size_t property_count, pesapi_property_descriptor properties,
void* data);

PESAPI_EXTERN void* pesapi_find_class_data(const void* type_id);
PESAPI_EXTERN void* pesapi_load_class_data(const void* type_id, bool callback_if_not_found);

PESAPI_EXTERN void pesapi_on_class_not_found(pesapi_class_not_found_callback callback);

Expand Down
2 changes: 1 addition & 1 deletion unity/native_src_il2cpp/Src/PesapiAddonLoad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ static pesapi_func_ptr funcs[] = {(pesapi_func_ptr) &pesapi_create_null, (pesapi
(pesapi_func_ptr) &pesapi_alloc_type_infos, (pesapi_func_ptr) &pesapi_set_type_info,
(pesapi_func_ptr) &pesapi_create_signature_info, (pesapi_func_ptr) &pesapi_alloc_property_descriptors,
(pesapi_func_ptr) &pesapi_set_method_info, (pesapi_func_ptr) &pesapi_set_property_info, (pesapi_func_ptr) &pesapi_define_class,
(pesapi_func_ptr) &pesapi_find_class_data, (pesapi_func_ptr) &pesapi_on_class_not_found,
(pesapi_func_ptr) &pesapi_load_class_data, (pesapi_func_ptr) &pesapi_on_class_not_found,
(pesapi_func_ptr) &pesapi_class_type_info, (pesapi_func_ptr) &pesapi_find_type_id};
MSVC_PRAGMA(warning(pop))

Expand Down
4 changes: 2 additions & 2 deletions unity/native_src_il2cpp/Src/PesapiV8Impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1015,9 +1015,9 @@ void pesapi_define_class(const void* type_id, const void* super_type_id, const c
}
MSVC_PRAGMA(warning(pop))

void* pesapi_find_class_data(const void* type_id)
void* pesapi_load_class_data(const void* type_id, bool callback_if_not_found)
{
auto clsDef = puerts::FindClassByID(type_id);
auto clsDef = puerts::FindClassByID(type_id, callback_if_not_found);
return clsDef ? clsDef->Data : nullptr;
}

Expand Down
12 changes: 0 additions & 12 deletions unity/native_src_il2cpp/Src/Puerts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,9 @@
#include "JSClassRegister.h"
#include <stdarg.h>
#include "BackendEnv.h"
#include "ExecuteModuleJSCode.h"

#define USE_OUTSIZE_UNITY 1

#include "UnityExports4Puerts.h"

namespace puerts
{
enum Backend
Expand All @@ -43,8 +40,6 @@ typedef void(*LogCallback)(const char* value);

static LogCallback GLogCallback = nullptr;

static UnityExports GUnityExports;

typedef void (*LazyLoadTypeFunc) (const void* typeId, bool includeNonPublic, void* method);

void* GTryLoadTypeMethodInfo = nullptr;
Expand Down Expand Up @@ -200,13 +195,6 @@ V8_EXPORT pesapi_env_ref GetPapiEnvRef(puerts::JSEnv* jsEnv)
return pesapi_create_env_ref(env);
}

V8_EXPORT void ExchangeAPI(puerts::UnityExports * exports)
{
exports->GetJsClassInfo = &puerts::GetJsClassInfo;
exports->LogCallback = puerts::GLogCallback;
puerts::GUnityExports = *exports;
}

V8_EXPORT void SetObjectPool(puerts::JSEnv* jsEnv, void* ObjectPoolAddMethodInfo, puerts::ObjectPoolAddFunc ObjectPoolAdd, void* ObjectPoolRemoveMethodInfo, puerts::ObjectPoolRemoveFunc ObjectPoolRemove, void* ObjectPoolInstance)
{
jsEnv->CppObjectMapper.ObjectPoolAddMethodInfo = ObjectPoolAddMethodInfo;
Expand Down

0 comments on commit 76a3ec2

Please sign in to comment.