[adapters] 降低 Worker 初始化对启动速度的影响,增加宏设置打印

This commit is contained in:
SmallMain 2024-10-22 15:45:08 +08:00
parent 9df0cdee8f
commit cf7307d7f5
No known key found for this signature in database
2 changed files with 39 additions and 12 deletions

View File

@ -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();
});

View File

@ -2,14 +2,38 @@ require("./macro.js");
require("./ipc-main.js");
require("./handlers.js");
module.exports = function init(callback) {
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);
callback();
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 = callback;
}
}
},
};