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