2024-10-21 20:23:37 +08:00
|
|
|
|
const isSubContext = wx.getOpenDataContext === undefined;
|
|
|
|
|
const sysinfo = wx.getSystemInfoSync();
|
|
|
|
|
const platform = sysinfo.platform.toLowerCase();
|
2024-10-22 17:17:13 +08:00
|
|
|
|
const isAndroid = platform === "android";
|
2024-10-24 17:27:28 +08:00
|
|
|
|
const isDevtools = platform === "devtools";
|
2024-10-21 20:23:37 +08:00
|
|
|
|
const sdkVersion = sysinfo.SDKVersion.split('.').map(Number);
|
|
|
|
|
// >= 2.20.2
|
|
|
|
|
const hasWorker = sdkVersion[0] > 2 || (sdkVersion[0] === 2 && (sdkVersion[1] > 20 || (sdkVersion[1] === 20 && sdkVersion[2] >= 2)));
|
2024-10-24 17:27:28 +08:00
|
|
|
|
// >= 2.27.3
|
|
|
|
|
const useSubpackage = sdkVersion[0] > 2 || (sdkVersion[0] === 2 && (sdkVersion[1] > 27 || (sdkVersion[1] === 27 && sdkVersion[2] >= 3)));
|
2024-10-21 20:23:37 +08:00
|
|
|
|
|
2024-10-24 17:27:28 +08:00
|
|
|
|
// 是否启用 Worker 驱动资源管线
|
2024-10-24 19:48:53 +08:00
|
|
|
|
if (!("CC_WORKER_ASSET_PIPELINE" in globalThis)) {
|
|
|
|
|
globalThis.CC_WORKER_ASSET_PIPELINE = false;
|
|
|
|
|
// NOTE 截止 2024.10.22,微信未修复 iOS、Windows、Mac 上仅文件系统 API 可以正常使用的问题
|
|
|
|
|
globalThis.CC_WORKER_ASSET_PIPELINE = (isAndroid || isDevtools) && globalThis.CC_WORKER_ASSET_PIPELINE;
|
|
|
|
|
}
|
2024-10-21 20:23:37 +08:00
|
|
|
|
|
2024-10-24 17:27:28 +08:00
|
|
|
|
// 是否启用 Worker 驱动音频系统
|
2024-10-24 19:48:53 +08:00
|
|
|
|
if (!("CC_WORKER_AUDIO_SYSTEM" in globalThis)) {
|
|
|
|
|
globalThis.CC_WORKER_AUDIO_SYSTEM = false;
|
2024-10-29 15:22:05 +08:00
|
|
|
|
// NOTE 截止 2024.10.22,微信未修复 iOS、Windows、Mac 上仅文件系统 API 可以正常使用的问题
|
|
|
|
|
globalThis.CC_WORKER_AUDIO_SYSTEM = (isAndroid || isDevtools) && globalThis.CC_WORKER_AUDIO_SYSTEM;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Worker 音频系统同步音频属性的间隔时间(单位:毫秒)
|
|
|
|
|
if (!("CC_WORKER_AUDIO_SYSTEM_SYNC_INTERVAL" in globalThis)) {
|
|
|
|
|
globalThis.CC_WORKER_AUDIO_SYSTEM_SYNC_INTERVAL = 500;
|
2024-10-24 19:48:53 +08:00
|
|
|
|
}
|
2024-10-22 17:17:13 +08:00
|
|
|
|
|
2024-10-21 20:23:37 +08:00
|
|
|
|
// 是否启用 Worker
|
2024-10-24 19:48:53 +08:00
|
|
|
|
if (!("CC_USE_WORKER" in globalThis)) {
|
2024-10-29 15:22:05 +08:00
|
|
|
|
globalThis.CC_USE_WORKER = (CC_WORKER_ASSET_PIPELINE || CC_WORKER_AUDIO_SYSTEM) && hasWorker && !isSubContext;
|
2024-10-24 19:48:53 +08:00
|
|
|
|
}
|
2024-10-21 20:23:37 +08:00
|
|
|
|
|
|
|
|
|
// 是否启用 Worker 调试模式
|
2024-10-24 19:48:53 +08:00
|
|
|
|
if (!("CC_WORKER_DEBUG" in globalThis)) {
|
|
|
|
|
globalThis.CC_WORKER_DEBUG = false;
|
|
|
|
|
}
|
2024-10-21 20:23:37 +08:00
|
|
|
|
|
|
|
|
|
// 是否启用 Worker 调度模式,这也许能减少通信次数带来的性能消耗(必须一致)
|
|
|
|
|
globalThis.CC_WORKER_SCHEDULER = true;
|
|
|
|
|
|
|
|
|
|
// 是否启用 Worker 使用同步版本的文件系统 API
|
2024-10-22 17:17:13 +08:00
|
|
|
|
// NOTE: IOS 不支持 async 文件系统 API,Android 不支持部分 sync 文件系统 API,其余系统暂不确定
|
2024-10-24 19:48:53 +08:00
|
|
|
|
if (!("CC_WORKER_FS_SYNC" in globalThis)) {
|
|
|
|
|
globalThis.CC_WORKER_FS_SYNC = !isAndroid && !isDevtools;
|
|
|
|
|
}
|
2024-10-24 17:27:28 +08:00
|
|
|
|
|
|
|
|
|
// 是否启用 Worker 子包
|
2024-10-24 19:48:53 +08:00
|
|
|
|
if (!("CC_WORKER_SUB_PACKAGE" in globalThis)) {
|
|
|
|
|
// NOTE 截止 2024.10.22,部分安卓机型声明使用子包 Worker 会报 java.string 错误
|
|
|
|
|
globalThis.CC_WORKER_SUB_PACKAGE = false; // useSubpackage
|
|
|
|
|
}
|