From 2a337098e45086df96c47148be05e3a4a995f720 Mon Sep 17 00:00:00 2001 From: SmallMain Date: Fri, 22 Nov 2024 16:57:07 +0800 Subject: [PATCH] =?UTF-8?q?[common]=20=E8=BF=98=E5=8E=9F=E5=AF=B9=202.3.0?= =?UTF-8?q?=20=E7=89=88=E6=9C=AC=E6=A8=A1=E6=9D=BF=E7=9A=84=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E4=BF=AE=E6=94=B9=EF=BC=8C=E5=A2=9E=E5=8A=A0=202.4.0?= =?UTF-8?q?=20=E6=A8=A1=E6=9D=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../2.4.13/2.3.0/worker/creator-worker.d.ts | 5 -- .../2.4.13/2.4.0/worker/creator-worker.d.ts | 81 +++++++++++++++++++ .../2.4.13/2.4.0/worker/jsconfig.json | 13 +++ .../2.4.13/2.4.0/worker/src/index.js | 3 + .../templates/2.4.13/2.4.0/worker/src/math.js | 9 +++ 5 files changed, 106 insertions(+), 5 deletions(-) create mode 100644 extension/templates/2.4.13/2.4.0/worker/creator-worker.d.ts create mode 100644 extension/templates/2.4.13/2.4.0/worker/jsconfig.json create mode 100644 extension/templates/2.4.13/2.4.0/worker/src/index.js create mode 100644 extension/templates/2.4.13/2.4.0/worker/src/math.js diff --git a/extension/templates/2.4.13/2.3.0/worker/creator-worker.d.ts b/extension/templates/2.4.13/2.3.0/worker/creator-worker.d.ts index f21ad769..726c976d 100644 --- a/extension/templates/2.4.13/2.3.0/worker/creator-worker.d.ts +++ b/extension/templates/2.4.13/2.3.0/worker/creator-worker.d.ts @@ -74,8 +74,3 @@ declare var CC_WORKER_AUDIO_SYSTEM_SYNC_INTERVAL: number; * 是否启用 Worker 驱动 HTTP 请求 */ declare var CC_WORKER_HTTP_REQUEST: boolean; - -/** - * 是否启用 Worker 驱动 WebSocket - */ -declare var CC_WORKER_WEBSOCKET: boolean; diff --git a/extension/templates/2.4.13/2.4.0/worker/creator-worker.d.ts b/extension/templates/2.4.13/2.4.0/worker/creator-worker.d.ts new file mode 100644 index 00000000..f21ad769 --- /dev/null +++ b/extension/templates/2.4.13/2.4.0/worker/creator-worker.d.ts @@ -0,0 +1,81 @@ +declare namespace worker { + export const createInnerAudioContext: any; + export const connectSocket: any; + export function createSharedArrayBuffer(size: number): WXSharedArrayBuffer; + export const downloadFile: any; + export const env: { USER_DATA_PATH: string }; + export const getFileSystemManager: any; + export const onMessage: any; + export const postMessage: any; + export const request: any; + export const uploadFile: any; + export interface WXSharedArrayBuffer { + buffer: SharedArrayBuffer; + } +} + +declare module "ipc-worker.js" { + /** + * 是否初始化完成 + * + * - 初始化完成后,宏才被设为有效值 + */ + export const inited: boolean; + + /** + * 访问主线程的入口 + */ + export const main: any; + + /** + * 注册主线程可以访问的入口 + * + * 请务必在脚本执行时调用才有效。 + */ + export function registerHandler(name: string, handler: object): void; +} + +/** + * 是否启用自定义 Worker + */ +declare var CC_CUSTOM_WORKER: boolean; + +/** + * 是否启用 Worker 调度模式,这会减少通信次数 + */ +declare var CC_WORKER_SCHEDULER: boolean; + +/** + * 是否启用 Worker 调试模式 + */ +declare var CC_WORKER_DEBUG: boolean; + +/** + * 是否启用 Worker 使用同步版本的文件系统 API + */ +declare var CC_WORKER_FS_SYNC: boolean; + +/** + * 是否启用 Worker 驱动资源管线 + */ +declare var CC_WORKER_ASSET_PIPELINE: boolean; + +/** + * 是否启用 Worker 驱动音频系统 + */ +declare var CC_WORKER_AUDIO_SYSTEM: boolean; + +/** + * Worker 音频系统同步音频属性的间隔时间(单位:毫秒) + */ +declare var CC_WORKER_AUDIO_SYSTEM_SYNC_INTERVAL: number; + +/** + * 是否启用 Worker 驱动 HTTP 请求 + */ +declare var CC_WORKER_HTTP_REQUEST: boolean; + +/** + * 是否启用 Worker 驱动 WebSocket + */ +declare var CC_WORKER_WEBSOCKET: boolean; diff --git a/extension/templates/2.4.13/2.4.0/worker/jsconfig.json b/extension/templates/2.4.13/2.4.0/worker/jsconfig.json new file mode 100644 index 00000000..243325bd --- /dev/null +++ b/extension/templates/2.4.13/2.4.0/worker/jsconfig.json @@ -0,0 +1,13 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "ES5", + "skipLibCheck": true, + "downlevelIteration": true, + "allowSyntheticDefaultImports": true, + }, + "include": [ + "src", + "creator-worker.d.ts" + ], +} diff --git a/extension/templates/2.4.13/2.4.0/worker/src/index.js b/extension/templates/2.4.13/2.4.0/worker/src/index.js new file mode 100644 index 00000000..72659e85 --- /dev/null +++ b/extension/templates/2.4.13/2.4.0/worker/src/index.js @@ -0,0 +1,3 @@ +// 该文件会在 Worker 初始化时执行,可在这里初始化或者引用其它脚本 +// This file will be executed when the Worker is initialized, either initialize it here or require another script. +require("math.js"); diff --git a/extension/templates/2.4.13/2.4.0/worker/src/math.js b/extension/templates/2.4.13/2.4.0/worker/src/math.js new file mode 100644 index 00000000..f30a519b --- /dev/null +++ b/extension/templates/2.4.13/2.4.0/worker/src/math.js @@ -0,0 +1,9 @@ +const { registerHandler } = require("ipc-worker.js"); + +export function add(x, y, callback) { + callback(x + y); +} + +registerHandler("math", { + add, +});