[adapters] 增加主线程的类型提示文件,优化多线程通信方式,增加对多线程自定义扩展的支持

This commit is contained in:
SmallMain
2024-11-07 17:36:59 +08:00
parent 6333ac01d2
commit b97579d9c0
9 changed files with 103 additions and 24 deletions

View File

@@ -121,7 +121,11 @@ const ipcMain = {
worker[name] = {};
}
worker[name][key] = (args, callback) => {
this.callToWorker(cmd, args, callback);
if (typeof args === "function") {
this.callToWorker(cmd, null, args);
} else {
this.callToWorker(cmd, args, callback);
}
};
}

View File

@@ -28,9 +28,14 @@ if (!("CC_WORKER_AUDIO_SYSTEM_SYNC_INTERVAL" in globalThis)) {
globalThis.CC_WORKER_AUDIO_SYSTEM_SYNC_INTERVAL = 500;
}
// 是否启用自定义 Worker
if (!("CC_CUSTOM_WORKER" in globalThis)) {
globalThis.CC_CUSTOM_WORKER = false;
}
// 是否启用 Worker
if (!("CC_USE_WORKER" in globalThis)) {
globalThis.CC_USE_WORKER = (CC_WORKER_ASSET_PIPELINE || CC_WORKER_AUDIO_SYSTEM) && hasWorker && !isSubContext;
globalThis.CC_USE_WORKER = (CC_WORKER_ASSET_PIPELINE || CC_WORKER_AUDIO_SYSTEM || CC_CUSTOM_WORKER) && hasWorker && !isSubContext;
}
// 是否启用 Worker 调试模式
@@ -38,7 +43,7 @@ if (!("CC_WORKER_DEBUG" in globalThis)) {
globalThis.CC_WORKER_DEBUG = false;
}
// 是否启用 Worker 调度模式,这也许能减少通信次数带来的性能消耗(必须一致)
// 是否启用 Worker 调度模式,这也许能减少通信次数带来的性能消耗
globalThis.CC_WORKER_SCHEDULER = true;
// 是否启用 Worker 使用同步版本的文件系统 API