puerts_unreal_demo
puerts_unreal_demo copied to clipboard
作者能分享几个wasm的C++代码吗
自己在测试C++ 转的wasm 和 JS 实现的接口的效率,但一直生成不了合格的wasm,普通C++的则OK。 特请教下作者,项目中和UE相关的几个wasm是怎么生成的呢,非常感谢车神的解惑!
那是一个内部项目提交的例子 我看了下,大概思路是那个wasm并不直接include UE的类,只是封装个wrapper,比如FVector的wrapper
struct FVector
{
float X, Y, Z;
FRotator Rotation() const;
};
extern "C" FRotator FVector_Rotation(const FVector& InVector); //这个外部函数会由原生实现并赋值给wasm
//这只是简单调用下外部函数
FRotator FVector::Rotation() const
{
return FVector_Rotation(*this);
}
然后原生那实现FVector_Rotation
FRotator FVector_Rotation(const FVector& InVector)
{
return InVector.Rotation();
}
//...
WASM_BEGIN_LINK_GLOBAL(FVector, 0)
WASM_LINK_GLOBAL(FVector_Rotation)
//...
WASM_END_LINK_GLOBAL(FVector, 0)
那是一个内部项目提交的例子 我看了下,大概思路是那个wasm并不直接include UE的类,只是封装个wrapper,比如FVector的wrapper
struct FVector { float X, Y, Z; FRotator Rotation() const; }; extern "C" FRotator FVector_Rotation(const FVector& InVector); //这个外部函数会由原生实现并赋值给wasm //这只是简单调用下外部函数 FRotator FVector::Rotation() const { return FVector_Rotation(*this); }
然后原生那实现FVector_Rotation
FRotator FVector_Rotation(const FVector& InVector) { return InVector.Rotation(); } //... WASM_BEGIN_LINK_GLOBAL(FVector, 0) WASM_LINK_GLOBAL(FVector_Rotation) //... WASM_END_LINK_GLOBAL(FVector, 0)
好的 我往这个方向试下 感谢^_^