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; + } + }, +};