Skip to content

Commit

Permalink
Merge pull request #53 from zombieyang/feature/opt_memory
Browse files Browse the repository at this point in the history
Optimize number bigint memory allocation
  • Loading branch information
zombieyang authored Jan 19, 2024
2 parents 27f814f + 85b0026 commit 2da50ed
Show file tree
Hide file tree
Showing 9 changed files with 512 additions and 480 deletions.
360 changes: 192 additions & 168 deletions unity/Assets/webgl/upm/Javascripts~/PuertsDLLMock/dist/puerts-runtime.js

Large diffs are not rendered by default.

25 changes: 7 additions & 18 deletions unity/Assets/webgl/upm/Javascripts~/PuertsDLLMock/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,8 @@ global.PuertsWebGL = {
inited: false,
debug: false,
// puerts首次初始化时会调用这里,并把Unity的通信接口传入
Init({
UTF8ToString, _malloc, _memcpy, _free, stringToUTF8, lengthBytesUTF8, unityInstance
}: PuertsJSEngine.EngineConstructorParam) {
const engine = new PuertsJSEngine({
UTF8ToString, _malloc, _memcpy, _free, stringToUTF8, lengthBytesUTF8, unityInstance
});
Init(ctorParam: PuertsJSEngine.EngineConstructorParam) {
const engine = new PuertsJSEngine(ctorParam);

const executeModuleCache: { [filename: string]: any } = {};

Expand All @@ -42,7 +38,9 @@ global.PuertsWebGL = {
// PuertsDLL的所有接口实现
global.PuertsWebGL = Object.assign(
global.PuertsWebGL,
{ unityInstance },
{
updateGlobalBufferAndViews: engine.updateGlobalBufferAndViews.bind(engine)
},
WebGLBackendGetFromJSArgumentAPI(engine),
WebGLBackendGetFromJSReturnAPI(engine),
WebGLBackendSetToInvokeJSArgumentApi(engine),
Expand All @@ -51,15 +49,6 @@ global.PuertsWebGL = {
WebGLBackendRegisterAPI(engine),
{
// bridgeLog: true,
SetCallV8: function (
callV8Function: MockIntPtr,
callV8Constructor: MockIntPtr,
callV8Destructor: MockIntPtr
) {
engine.callV8Function = callV8Function;
engine.callV8Constructor = callV8Constructor;
engine.callV8Destructor = callV8Destructor;
},
GetLibVersion: function () {
return 32;
},
Expand Down Expand Up @@ -184,7 +173,7 @@ global.PuertsWebGL = {
throw new Error("eval is not supported");
}
try {
const code = UTF8ToString(codeString);
const code = engine.unityApi.UTF8ToString(codeString);
const result = global.eval(code);
// return getIntPtrManager().GetPointerForJSValue(result);
engine.lastReturnCSResult = result;
Expand All @@ -199,7 +188,7 @@ global.PuertsWebGL = {
engine.GetJSArgumentsCallback = callback;
},
ThrowException: function (isolate: IntPtr, /*byte[] */messageString: CSString) {
throw new Error(UTF8ToString(messageString));
throw new Error(engine.unityApi.UTF8ToString(messageString));
},

InvokeJSFunction: function (_function: JSFunctionPtr, hasResult: bool) {
Expand Down
Loading

0 comments on commit 2da50ed

Please sign in to comment.