From cf7307d7f503692925b59262406674ccbd1dee8d Mon Sep 17 00:00:00 2001 From: SmallMain Date: Tue, 22 Oct 2024 15:45:08 +0800 Subject: [PATCH] =?UTF-8?q?[adapters]=20=E9=99=8D=E4=BD=8E=20Worker=20?= =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E5=AF=B9=E5=90=AF=E5=8A=A8=E9=80=9F?= =?UTF-8?q?=E5=BA=A6=E7=9A=84=E5=BD=B1=E5=93=8D=EF=BC=8C=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=AE=8F=E8=AE=BE=E7=BD=AE=E6=89=93=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- adapters/platforms/wechat/res/game.js | 7 ++- .../wechat/res/worker_adapter/index.js | 44 ++++++++++++++----- 2 files changed, 39 insertions(+), 12 deletions(-) diff --git a/adapters/platforms/wechat/res/game.js b/adapters/platforms/wechat/res/game.js index 3091768f..26114179 100644 --- a/adapters/platforms/wechat/res/game.js +++ b/adapters/platforms/wechat/res/game.js @@ -1,5 +1,6 @@ -const initWorker = require('./worker_adapter/index.js'); +const { init: initWorker, onInited: onWorkerInited } = require('./worker_adapter/index.js'); require('adapter-js-path'); +initWorker(); __globalAdapter.init(); require('cocos2d-js-path'); require('physics-js-path'); @@ -18,6 +19,8 @@ if (cc.sys.platform !== cc.sys.WECHAT_GAME_SUB) { cc.macro.CLEANUP_IMAGE_CACHE = true; } -initWorker(() => { +const t = Date.now(); +onWorkerInited(() => { + console.log("worker waiting time:", Date.now() - t); window.boot(); }); diff --git a/adapters/platforms/wechat/res/worker_adapter/index.js b/adapters/platforms/wechat/res/worker_adapter/index.js index bf677a7d..9f18eb34 100644 --- a/adapters/platforms/wechat/res/worker_adapter/index.js +++ b/adapters/platforms/wechat/res/worker_adapter/index.js @@ -2,14 +2,38 @@ require("./macro.js"); require("./ipc-main.js"); require("./handlers.js"); -module.exports = function init(callback) { - if (CC_USE_WORKER) { - var t = Date.now(); - ipcMain.init(() => { - console.log("worker init cost:", Date.now() - t); +let inited = false; +let _callback = null; + +module.exports = { + init() { + if (CC_USE_WORKER) { + var t = Date.now(); + ipcMain.init(() => { + console.log("worker init cost:", Date.now() - t); + console.log("worker settings:", { + CC_USE_WORKER, + CC_WORKER_DEBUG, + CC_WORKER_ASSET_PIPELINE, + CC_WORKER_ASSET_PIPELINE_INCLUDE_LOAD, + CC_WORKER_SCHEDULER, + CC_WORKER_FS_SYNC, + }); + inited = true; + _callback && _callback(); + _callback = null; + }); + } else { + inited = true; + _callback && _callback(); + _callback = null; + } + }, + onInited(callback) { + if (inited) { callback(); - }); - } else { - callback(); - } -} + } else { + _callback = callback; + } + }, +};