diff --git a/COCOS_USAGE.md b/COCOS_USAGE.md index d3c61e1e..3b3acbce 100644 --- a/COCOS_USAGE.md +++ b/COCOS_USAGE.md @@ -8,11 +8,14 @@ npm install @esengine/ecs-framework ``` -## 重要说明 +## WASM 支持(可选) -⚠️ **Cocos Creator 环境下无法直接使用 WASM 加速** +🚀 **WASM 模块已独立发布,需要手动下载和配置** -由于 Cocos Creator 的特殊 WASM 加载机制,框架会自动检测 Cocos 环境并回退到 JavaScript 实现。这不会影响功能,只是性能稍有差异。 +WASM 模块不再包含在 npm 包中,如需使用请从 [GitHub Release](https://github.com/esengine/ecs-framework/releases) 下载。 + +- 不使用 WASM:框架自动使用 JavaScript 实现,功能完全正常 +- 使用 WASM:提供查询性能优化,需要手动配置 ## 基本使用 @@ -26,9 +29,34 @@ export class GameManager extends Component { private core: Core; onLoad() { - // 创建核心实例(Cocos环境会自动禁用WASM) + // 创建核心实例 this.core = Core.create(true); console.log('ECS核心已初始化'); + + // 可选:加载WASM支持(需要先下载WASM包) + this.loadWasmSupport(); + } + + private async loadWasmSupport() { + try { + // 1. 导入WASM胶水代码(需要将文件放到项目中) + const { default: wasmFactory } = await import('./ecs_wasm_core.js'); + + // 2. 使用Cocos API加载WASM文件(需要先导入到资源管理器) + const wasmFile = await this.loadWasmOrAsm("wasmFiles", "ecs_wasm_core", "your-wasm-uuid"); + + // 3. 初始化WASM支持 + const { ecsCore } = await import('@esengine/ecs-framework'); + const success = await ecsCore.initializeWasm(wasmFactory, wasmFile); + + if (success) { + console.log('✅ ECS WASM加速已启用'); + } else { + console.log('⚠️ WASM初始化失败,使用JavaScript实现'); + } + } catch (error) { + console.log('⚠️ WASM不可用,使用JavaScript实现:', error); + } } } ``` diff --git a/package.json b/package.json index 261c1813..e10a9387 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "build:watch": "tsc --watch", "rebuild": "npm run clean && npm run clean:wasm && npm run build", "build:npm": "npm run build && node scripts/build-rollup.js", + "build:wasm-release": "node scripts/build-wasm-release.js", "test:benchmark": "npm run build && node bin/Testing/Performance/benchmark.js", "test:unit": "npm run build && node bin/Testing/test-runner.js", "benchmark": "node scripts/benchmark.js", @@ -56,4 +57,4 @@ "type": "git", "url": "https://github.com/esengine/ecs-framework.git" } -} +} \ No newline at end of file diff --git a/scripts/build-rollup.js b/scripts/build-rollup.js index 69d9fb39..3ab51e99 100644 --- a/scripts/build-rollup.js +++ b/scripts/build-rollup.js @@ -60,7 +60,6 @@ function generatePackageJson() { 'index.umd.js', 'index.umd.js.map', 'index.d.ts', - 'wasm', 'README.md', 'LICENSE', 'SECURITY.md', @@ -108,29 +107,8 @@ function copyFiles() { } }); - // 复制WASM文件(过滤.gitignore) - const wasmDir = './bin/wasm'; - if (fs.existsSync(wasmDir)) { - const distWasmDir = './dist/wasm'; - if (!fs.existsSync(distWasmDir)) { - fs.mkdirSync(distWasmDir); - } - - let copiedCount = 0; - fs.readdirSync(wasmDir).forEach(file => { - // 过滤掉.gitignore文件 - if (file !== '.gitignore') { - fs.copyFileSync( - path.join(wasmDir, file), - path.join(distWasmDir, file) - ); - copiedCount++; - } - }); - if (copiedCount > 0) { - console.log(` ✓ 复制: ${copiedCount}个WASM文件`); - } - } + // WASM文件不再包含在npm包中,单独发布 + console.log(' ⚠️ WASM文件已移除,请从GitHub Release下载单独的WASM包'); } function showBuildResults() { diff --git a/scripts/build-wasm-release.js b/scripts/build-wasm-release.js new file mode 100644 index 00000000..8af09d20 --- /dev/null +++ b/scripts/build-wasm-release.js @@ -0,0 +1,135 @@ +const fs = require('fs'); +const path = require('path'); +const { execSync } = require('child_process'); + +console.log('🚀 构建WASM发布包...'); + +async function main() { + try { + // 确保WASM已构建 + if (!fs.existsSync('./bin/wasm')) { + console.log('📦 构建WASM...'); + execSync('npm run build:wasm', { stdio: 'inherit' }); + } + + // 创建发布目录 + const releaseDir = './wasm-release'; + if (fs.existsSync(releaseDir)) { + execSync(`rimraf ${releaseDir}`, { stdio: 'inherit' }); + } + fs.mkdirSync(releaseDir); + + // 复制WASM文件 + console.log('📁 复制WASM文件...'); + const wasmDir = './bin/wasm'; + fs.readdirSync(wasmDir).forEach(file => { + if (file !== '.gitignore') { + fs.copyFileSync( + path.join(wasmDir, file), + path.join(releaseDir, file) + ); + console.log(` ✓ ${file}`); + } + }); + + // 创建使用说明 + console.log('📋 生成使用说明...'); + generateUsageInstructions(releaseDir); + + // 显示结果 + showReleaseResults(releaseDir); + + console.log('\n✅ WASM发布包构建完成!'); + console.log(`📦 发布目录: ${releaseDir}`); + console.log('💡 可以将整个目录打包为zip文件上传到GitHub Release'); + + } catch (error) { + console.error('❌ 构建失败:', error.message); + process.exit(1); + } +} + +function generateUsageInstructions(releaseDir) { + const instructions = `# ECS Framework WASM 支持包 + +这个包包含了 @esengine/ecs-framework 的 WASM 加速模块。 + +## 包含文件 + +- \`ecs_wasm_core.js\` - WASM胶水代码 +- \`ecs_wasm_core.d.ts\` - TypeScript类型定义 +- \`ecs_wasm_core_bg.wasm\` - WASM二进制文件 +- \`ecs_wasm_core_bg.wasm.d.ts\` - WASM类型定义 +- \`package.json\` - 包信息 + +## 使用方法 + +### 1. Cocos Creator 3.8+ + +\`\`\`typescript +import { ecsCore } from '@esengine/ecs-framework'; + +// 1. 将WASM文件导入到项目资源中 +// 2. 导入胶水代码 +import('./ecs_wasm_core.js').then(({ default: wasmFactory }) => { + // 3. 使用Cocos API加载WASM文件 + this.loadWasmOrAsm("wasmFiles", "ecs_wasm_core", "your-wasm-uuid").then((wasmFile) => { + // 4. 初始化WASM支持 + ecsCore.initializeWasm(wasmFactory, wasmFile).then((success) => { + if (success) { + console.log("ECS WASM加速已启用"); + } else { + console.log("回退到JavaScript实现"); + } + }); + }); +}); +\`\`\` + +### 2. 其他环境(浏览器/Node.js) + +\`\`\`typescript +import { ecsCore } from '@esengine/ecs-framework'; + +// 1. 导入胶水代码 +import('./ecs_wasm_core.js').then(({ default: wasmFactory }) => { + // 2. 加载WASM文件 + fetch('./ecs_wasm_core_bg.wasm').then(response => response.arrayBuffer()).then((wasmFile) => { + // 3. 初始化WASM支持 + ecsCore.initializeWasm(wasmFactory, wasmFile).then((success) => { + if (success) { + console.log("ECS WASM加速已启用"); + } else { + console.log("回退到JavaScript实现"); + } + }); + }); +}); +\`\`\` + +## 注意事项 + +1. 如果不使用此WASM包,框架会自动使用JavaScript实现,功能完全正常 +2. WASM主要提供查询性能优化,对于大多数应用场景JavaScript实现已足够 +3. 确保在ECS系统初始化之前调用\`initializeWasm\`方法 + +## 技术支持 + +如遇问题,请访问: +- [GitHub Issues](https://github.com/esengine/ecs-framework/issues) +- [主项目文档](https://github.com/esengine/ecs-framework#readme) +`; + + fs.writeFileSync(path.join(releaseDir, 'README.md'), instructions); +} + +function showReleaseResults(releaseDir) { + console.log('\n📊 WASM发布包内容:'); + fs.readdirSync(releaseDir).forEach(file => { + const filePath = path.join(releaseDir, file); + const size = fs.statSync(filePath).size; + console.log(` ${file}: ${(size / 1024).toFixed(1)}KB`); + }); +} + +main().catch(console.error); \ No newline at end of file diff --git a/wasm-release/README.md b/wasm-release/README.md new file mode 100644 index 00000000..0217fef5 --- /dev/null +++ b/wasm-release/README.md @@ -0,0 +1,68 @@ +# ECS Framework WASM 支持包 + +这个包包含了 @esengine/ecs-framework 的 WASM 加速模块。 + +## 包含文件 + +- `ecs_wasm_core.js` - WASM胶水代码 +- `ecs_wasm_core.d.ts` - TypeScript类型定义 +- `ecs_wasm_core_bg.wasm` - WASM二进制文件 +- `ecs_wasm_core_bg.wasm.d.ts` - WASM类型定义 +- `package.json` - 包信息 + +## 使用方法 + +### 1. Cocos Creator 3.8+ + +```typescript +import { ecsCore } from '@esengine/ecs-framework'; + +// 1. 将WASM文件导入到项目资源中 +// 2. 导入胶水代码 +import('./ecs_wasm_core.js').then(({ default: wasmFactory }) => { + // 3. 使用Cocos API加载WASM文件 + this.loadWasmOrAsm("wasmFiles", "ecs_wasm_core", "your-wasm-uuid").then((wasmFile) => { + // 4. 初始化WASM支持 + ecsCore.initializeWasm(wasmFactory, wasmFile).then((success) => { + if (success) { + console.log("ECS WASM加速已启用"); + } else { + console.log("回退到JavaScript实现"); + } + }); + }); +}); +``` + +### 2. 其他环境(浏览器/Node.js) + +```typescript +import { ecsCore } from '@esengine/ecs-framework'; + +// 1. 导入胶水代码 +import('./ecs_wasm_core.js').then(({ default: wasmFactory }) => { + // 2. 加载WASM文件 + fetch('./ecs_wasm_core_bg.wasm').then(response => response.arrayBuffer()).then((wasmFile) => { + // 3. 初始化WASM支持 + ecsCore.initializeWasm(wasmFactory, wasmFile).then((success) => { + if (success) { + console.log("ECS WASM加速已启用"); + } else { + console.log("回退到JavaScript实现"); + } + }); + }); +}); +``` + +## 注意事项 + +1. 如果不使用此WASM包,框架会自动使用JavaScript实现,功能完全正常 +2. WASM主要提供查询性能优化,对于大多数应用场景JavaScript实现已足够 +3. 确保在ECS系统初始化之前调用`initializeWasm`方法 + +## 技术支持 + +如遇问题,请访问: +- [GitHub Issues](https://github.com/esengine/ecs-framework/issues) +- [主项目文档](https://github.com/esengine/ecs-framework#readme) diff --git a/wasm-release/ecs_wasm_core.d.ts b/wasm-release/ecs_wasm_core.d.ts new file mode 100644 index 00000000..8f869281 --- /dev/null +++ b/wasm-release/ecs_wasm_core.d.ts @@ -0,0 +1,141 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * 创建组件掩码的辅助函数 + */ +export function create_component_mask(component_ids: Uint32Array): bigint; +/** + * 检查掩码是否包含指定组件 + */ +export function mask_contains_component(mask: bigint, component_id: number): boolean; +/** + * 初始化函数 + */ +export function main(): void; +/** + * 高性能ECS核心,专注于实体查询和掩码管理 + */ +export class EcsCore { + free(): void; + /** + * 创建新的ECS核心 + */ + constructor(); + /** + * 创建新实体 + */ + create_entity(): number; + /** + * 删除实体 + */ + destroy_entity(entity_id: number): boolean; + /** + * 更新实体的组件掩码 + */ + update_entity_mask(entity_id: number, mask: bigint): void; + /** + * 批量更新实体掩码 + */ + batch_update_masks(entity_ids: Uint32Array, masks: BigUint64Array): void; + /** + * 查询实体 + */ + query_entities(mask: bigint, max_results: number): number; + /** + * 获取查询结果数量 + */ + get_query_result_count(): number; + /** + * 缓存查询实体 + */ + query_cached(mask: bigint): number; + /** + * 获取缓存查询结果数量 + */ + get_cached_query_count(mask: bigint): number; + /** + * 多组件查询 + */ + query_multiple_components(masks: BigUint64Array, max_results: number): number; + /** + * 排除查询 + */ + query_with_exclusion(include_mask: bigint, exclude_mask: bigint, max_results: number): number; + /** + * 获取实体的组件掩码 + */ + get_entity_mask(entity_id: number): bigint; + /** + * 检查实体是否存在 + */ + entity_exists(entity_id: number): boolean; + /** + * 获取实体数量 + */ + get_entity_count(): number; + /** + * 获取性能统计信息 + */ + get_performance_stats(): Array; + /** + * 清理所有数据 + */ + clear(): void; + /** + * 重建查询缓存 + */ + rebuild_query_cache(): void; +} + +export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module; + +export interface InitOutput { + readonly memory: WebAssembly.Memory; + readonly __wbg_ecscore_free: (a: number, b: number) => void; + readonly ecscore_new: () => number; + readonly ecscore_create_entity: (a: number) => number; + readonly ecscore_destroy_entity: (a: number, b: number) => number; + readonly ecscore_update_entity_mask: (a: number, b: number, c: bigint) => void; + readonly ecscore_batch_update_masks: (a: number, b: number, c: number, d: number, e: number) => void; + readonly ecscore_query_entities: (a: number, b: bigint, c: number) => number; + readonly ecscore_get_query_result_count: (a: number) => number; + readonly ecscore_query_cached: (a: number, b: bigint) => number; + readonly ecscore_get_cached_query_count: (a: number, b: bigint) => number; + readonly ecscore_query_multiple_components: (a: number, b: number, c: number, d: number) => number; + readonly ecscore_query_with_exclusion: (a: number, b: bigint, c: bigint, d: number) => number; + readonly ecscore_get_entity_mask: (a: number, b: number) => bigint; + readonly ecscore_entity_exists: (a: number, b: number) => number; + readonly ecscore_get_entity_count: (a: number) => number; + readonly ecscore_get_performance_stats: (a: number) => any; + readonly ecscore_clear: (a: number) => void; + readonly ecscore_rebuild_query_cache: (a: number) => void; + readonly create_component_mask: (a: number, b: number) => bigint; + readonly mask_contains_component: (a: bigint, b: number) => number; + readonly main: () => void; + readonly __wbindgen_exn_store: (a: number) => void; + readonly __externref_table_alloc: () => number; + readonly __wbindgen_export_2: WebAssembly.Table; + readonly __wbindgen_malloc: (a: number, b: number) => number; + readonly __wbindgen_start: () => void; +} + +export type SyncInitInput = BufferSource | WebAssembly.Module; +/** +* Instantiates the given `module`, which can either be bytes or +* a precompiled `WebAssembly.Module`. +* +* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated. +* +* @returns {InitOutput} +*/ +export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput; + +/** +* If `module_or_path` is {RequestInfo} or {URL}, makes a request and +* for everything else, calls `WebAssembly.instantiate` directly. +* +* @param {{ module_or_path: InitInput | Promise }} module_or_path - Passing `InitInput` directly is deprecated. +* +* @returns {Promise} +*/ +export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise } | InitInput | Promise): Promise; diff --git a/wasm-release/ecs_wasm_core.js b/wasm-release/ecs_wasm_core.js new file mode 100644 index 00000000..cdb1b1b5 --- /dev/null +++ b/wasm-release/ecs_wasm_core.js @@ -0,0 +1,415 @@ +let wasm; + +let cachedUint8ArrayMemory0 = null; + +function getUint8ArrayMemory0() { + if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) { + cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer); + } + return cachedUint8ArrayMemory0; +} + +function getArrayU8FromWasm0(ptr, len) { + ptr = ptr >>> 0; + return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len); +} + +function addToExternrefTable0(obj) { + const idx = wasm.__externref_table_alloc(); + wasm.__wbindgen_export_2.set(idx, obj); + return idx; +} + +function handleError(f, args) { + try { + return f.apply(this, args); + } catch (e) { + const idx = addToExternrefTable0(e); + wasm.__wbindgen_exn_store(idx); + } +} + +const cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } ); + +if (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); }; + +function getStringFromWasm0(ptr, len) { + ptr = ptr >>> 0; + return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len)); +} + +let cachedUint32ArrayMemory0 = null; + +function getUint32ArrayMemory0() { + if (cachedUint32ArrayMemory0 === null || cachedUint32ArrayMemory0.byteLength === 0) { + cachedUint32ArrayMemory0 = new Uint32Array(wasm.memory.buffer); + } + return cachedUint32ArrayMemory0; +} + +let WASM_VECTOR_LEN = 0; + +function passArray32ToWasm0(arg, malloc) { + const ptr = malloc(arg.length * 4, 4) >>> 0; + getUint32ArrayMemory0().set(arg, ptr / 4); + WASM_VECTOR_LEN = arg.length; + return ptr; +} + +let cachedBigUint64ArrayMemory0 = null; + +function getBigUint64ArrayMemory0() { + if (cachedBigUint64ArrayMemory0 === null || cachedBigUint64ArrayMemory0.byteLength === 0) { + cachedBigUint64ArrayMemory0 = new BigUint64Array(wasm.memory.buffer); + } + return cachedBigUint64ArrayMemory0; +} + +function passArray64ToWasm0(arg, malloc) { + const ptr = malloc(arg.length * 8, 8) >>> 0; + getBigUint64ArrayMemory0().set(arg, ptr / 8); + WASM_VECTOR_LEN = arg.length; + return ptr; +} +/** + * 创建组件掩码的辅助函数 + * @param {Uint32Array} component_ids + * @returns {bigint} + */ +export function create_component_mask(component_ids) { + const ptr0 = passArray32ToWasm0(component_ids, wasm.__wbindgen_malloc); + const len0 = WASM_VECTOR_LEN; + const ret = wasm.create_component_mask(ptr0, len0); + return BigInt.asUintN(64, ret); +} + +/** + * 检查掩码是否包含指定组件 + * @param {bigint} mask + * @param {number} component_id + * @returns {boolean} + */ +export function mask_contains_component(mask, component_id) { + const ret = wasm.mask_contains_component(mask, component_id); + return ret !== 0; +} + +/** + * 初始化函数 + */ +export function main() { + wasm.main(); +} + +const EcsCoreFinalization = (typeof FinalizationRegistry === 'undefined') + ? { register: () => {}, unregister: () => {} } + : new FinalizationRegistry(ptr => wasm.__wbg_ecscore_free(ptr >>> 0, 1)); +/** + * 高性能ECS核心,专注于实体查询和掩码管理 + */ +export class EcsCore { + + __destroy_into_raw() { + const ptr = this.__wbg_ptr; + this.__wbg_ptr = 0; + EcsCoreFinalization.unregister(this); + return ptr; + } + + free() { + const ptr = this.__destroy_into_raw(); + wasm.__wbg_ecscore_free(ptr, 0); + } + /** + * 创建新的ECS核心 + */ + constructor() { + const ret = wasm.ecscore_new(); + this.__wbg_ptr = ret >>> 0; + EcsCoreFinalization.register(this, this.__wbg_ptr, this); + return this; + } + /** + * 创建新实体 + * @returns {number} + */ + create_entity() { + const ret = wasm.ecscore_create_entity(this.__wbg_ptr); + return ret >>> 0; + } + /** + * 删除实体 + * @param {number} entity_id + * @returns {boolean} + */ + destroy_entity(entity_id) { + const ret = wasm.ecscore_destroy_entity(this.__wbg_ptr, entity_id); + return ret !== 0; + } + /** + * 更新实体的组件掩码 + * @param {number} entity_id + * @param {bigint} mask + */ + update_entity_mask(entity_id, mask) { + wasm.ecscore_update_entity_mask(this.__wbg_ptr, entity_id, mask); + } + /** + * 批量更新实体掩码 + * @param {Uint32Array} entity_ids + * @param {BigUint64Array} masks + */ + batch_update_masks(entity_ids, masks) { + const ptr0 = passArray32ToWasm0(entity_ids, wasm.__wbindgen_malloc); + const len0 = WASM_VECTOR_LEN; + const ptr1 = passArray64ToWasm0(masks, wasm.__wbindgen_malloc); + const len1 = WASM_VECTOR_LEN; + wasm.ecscore_batch_update_masks(this.__wbg_ptr, ptr0, len0, ptr1, len1); + } + /** + * 查询实体 + * @param {bigint} mask + * @param {number} max_results + * @returns {number} + */ + query_entities(mask, max_results) { + const ret = wasm.ecscore_query_entities(this.__wbg_ptr, mask, max_results); + return ret >>> 0; + } + /** + * 获取查询结果数量 + * @returns {number} + */ + get_query_result_count() { + const ret = wasm.ecscore_get_query_result_count(this.__wbg_ptr); + return ret >>> 0; + } + /** + * 缓存查询实体 + * @param {bigint} mask + * @returns {number} + */ + query_cached(mask) { + const ret = wasm.ecscore_query_cached(this.__wbg_ptr, mask); + return ret >>> 0; + } + /** + * 获取缓存查询结果数量 + * @param {bigint} mask + * @returns {number} + */ + get_cached_query_count(mask) { + const ret = wasm.ecscore_get_cached_query_count(this.__wbg_ptr, mask); + return ret >>> 0; + } + /** + * 多组件查询 + * @param {BigUint64Array} masks + * @param {number} max_results + * @returns {number} + */ + query_multiple_components(masks, max_results) { + const ptr0 = passArray64ToWasm0(masks, wasm.__wbindgen_malloc); + const len0 = WASM_VECTOR_LEN; + const ret = wasm.ecscore_query_multiple_components(this.__wbg_ptr, ptr0, len0, max_results); + return ret >>> 0; + } + /** + * 排除查询 + * @param {bigint} include_mask + * @param {bigint} exclude_mask + * @param {number} max_results + * @returns {number} + */ + query_with_exclusion(include_mask, exclude_mask, max_results) { + const ret = wasm.ecscore_query_with_exclusion(this.__wbg_ptr, include_mask, exclude_mask, max_results); + return ret >>> 0; + } + /** + * 获取实体的组件掩码 + * @param {number} entity_id + * @returns {bigint} + */ + get_entity_mask(entity_id) { + const ret = wasm.ecscore_get_entity_mask(this.__wbg_ptr, entity_id); + return BigInt.asUintN(64, ret); + } + /** + * 检查实体是否存在 + * @param {number} entity_id + * @returns {boolean} + */ + entity_exists(entity_id) { + const ret = wasm.ecscore_entity_exists(this.__wbg_ptr, entity_id); + return ret !== 0; + } + /** + * 获取实体数量 + * @returns {number} + */ + get_entity_count() { + const ret = wasm.ecscore_get_entity_count(this.__wbg_ptr); + return ret >>> 0; + } + /** + * 获取性能统计信息 + * @returns {Array} + */ + get_performance_stats() { + const ret = wasm.ecscore_get_performance_stats(this.__wbg_ptr); + return ret; + } + /** + * 清理所有数据 + */ + clear() { + wasm.ecscore_clear(this.__wbg_ptr); + } + /** + * 重建查询缓存 + */ + rebuild_query_cache() { + wasm.ecscore_rebuild_query_cache(this.__wbg_ptr); + } +} + +async function __wbg_load(module, imports) { + if (typeof Response === 'function' && module instanceof Response) { + if (typeof WebAssembly.instantiateStreaming === 'function') { + try { + return await WebAssembly.instantiateStreaming(module, imports); + + } catch (e) { + if (module.headers.get('Content-Type') != 'application/wasm') { + console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e); + + } else { + throw e; + } + } + } + + const bytes = await module.arrayBuffer(); + return await WebAssembly.instantiate(bytes, imports); + + } else { + const instance = await WebAssembly.instantiate(module, imports); + + if (instance instanceof WebAssembly.Instance) { + return { instance, module }; + + } else { + return instance; + } + } +} + +function __wbg_get_imports() { + const imports = {}; + imports.wbg = {}; + imports.wbg.__wbg_getRandomValues_3c9c0d586e575a16 = function() { return handleError(function (arg0, arg1) { + globalThis.crypto.getRandomValues(getArrayU8FromWasm0(arg0, arg1)); + }, arguments) }; + imports.wbg.__wbg_log_bb5387ff27ac9b37 = function(arg0, arg1) { + console.log(getStringFromWasm0(arg0, arg1)); + }; + imports.wbg.__wbg_new_78feb108b6472713 = function() { + const ret = new Array(); + return ret; + }; + imports.wbg.__wbg_push_737cfc8c1432c2c6 = function(arg0, arg1) { + const ret = arg0.push(arg1); + return ret; + }; + imports.wbg.__wbindgen_init_externref_table = function() { + const table = wasm.__wbindgen_export_2; + const offset = table.grow(4); + table.set(0, undefined); + table.set(offset + 0, undefined); + table.set(offset + 1, null); + table.set(offset + 2, true); + table.set(offset + 3, false); + ; + }; + imports.wbg.__wbindgen_number_new = function(arg0) { + const ret = arg0; + return ret; + }; + imports.wbg.__wbindgen_throw = function(arg0, arg1) { + throw new Error(getStringFromWasm0(arg0, arg1)); + }; + + return imports; +} + +function __wbg_init_memory(imports, memory) { + +} + +function __wbg_finalize_init(instance, module) { + wasm = instance.exports; + __wbg_init.__wbindgen_wasm_module = module; + cachedBigUint64ArrayMemory0 = null; + cachedUint32ArrayMemory0 = null; + cachedUint8ArrayMemory0 = null; + + + wasm.__wbindgen_start(); + return wasm; +} + +function initSync(module) { + if (wasm !== undefined) return wasm; + + + if (typeof module !== 'undefined') { + if (Object.getPrototypeOf(module) === Object.prototype) { + ({module} = module) + } else { + console.warn('using deprecated parameters for `initSync()`; pass a single object instead') + } + } + + const imports = __wbg_get_imports(); + + __wbg_init_memory(imports); + + if (!(module instanceof WebAssembly.Module)) { + module = new WebAssembly.Module(module); + } + + const instance = new WebAssembly.Instance(module, imports); + + return __wbg_finalize_init(instance, module); +} + +async function __wbg_init(module_or_path) { + if (wasm !== undefined) return wasm; + + + if (typeof module_or_path !== 'undefined') { + if (Object.getPrototypeOf(module_or_path) === Object.prototype) { + ({module_or_path} = module_or_path) + } else { + console.warn('using deprecated parameters for the initialization function; pass a single object instead') + } + } + + if (typeof module_or_path === 'undefined') { + module_or_path = new URL('ecs_wasm_core_bg.wasm', import.meta.url); + } + const imports = __wbg_get_imports(); + + if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) { + module_or_path = fetch(module_or_path); + } + + __wbg_init_memory(imports); + + const { instance, module } = await __wbg_load(await module_or_path, imports); + + return __wbg_finalize_init(instance, module); +} + +export { initSync }; +export default __wbg_init; diff --git a/wasm-release/ecs_wasm_core_bg.wasm b/wasm-release/ecs_wasm_core_bg.wasm new file mode 100644 index 00000000..77cfdc3f Binary files /dev/null and b/wasm-release/ecs_wasm_core_bg.wasm differ diff --git a/wasm-release/ecs_wasm_core_bg.wasm.d.ts b/wasm-release/ecs_wasm_core_bg.wasm.d.ts new file mode 100644 index 00000000..6b0a5bde --- /dev/null +++ b/wasm-release/ecs_wasm_core_bg.wasm.d.ts @@ -0,0 +1,29 @@ +/* tslint:disable */ +/* eslint-disable */ +export const memory: WebAssembly.Memory; +export const __wbg_ecscore_free: (a: number, b: number) => void; +export const ecscore_new: () => number; +export const ecscore_create_entity: (a: number) => number; +export const ecscore_destroy_entity: (a: number, b: number) => number; +export const ecscore_update_entity_mask: (a: number, b: number, c: bigint) => void; +export const ecscore_batch_update_masks: (a: number, b: number, c: number, d: number, e: number) => void; +export const ecscore_query_entities: (a: number, b: bigint, c: number) => number; +export const ecscore_get_query_result_count: (a: number) => number; +export const ecscore_query_cached: (a: number, b: bigint) => number; +export const ecscore_get_cached_query_count: (a: number, b: bigint) => number; +export const ecscore_query_multiple_components: (a: number, b: number, c: number, d: number) => number; +export const ecscore_query_with_exclusion: (a: number, b: bigint, c: bigint, d: number) => number; +export const ecscore_get_entity_mask: (a: number, b: number) => bigint; +export const ecscore_entity_exists: (a: number, b: number) => number; +export const ecscore_get_entity_count: (a: number) => number; +export const ecscore_get_performance_stats: (a: number) => any; +export const ecscore_clear: (a: number) => void; +export const ecscore_rebuild_query_cache: (a: number) => void; +export const create_component_mask: (a: number, b: number) => bigint; +export const mask_contains_component: (a: bigint, b: number) => number; +export const main: () => void; +export const __wbindgen_exn_store: (a: number) => void; +export const __externref_table_alloc: () => number; +export const __wbindgen_export_2: WebAssembly.Table; +export const __wbindgen_malloc: (a: number, b: number) => number; +export const __wbindgen_start: () => void; diff --git a/wasm-release/package.json b/wasm-release/package.json new file mode 100644 index 00000000..7c82e84e --- /dev/null +++ b/wasm-release/package.json @@ -0,0 +1,15 @@ +{ + "name": "ecs-wasm-core", + "type": "module", + "version": "0.1.0", + "files": [ + "ecs_wasm_core_bg.wasm", + "ecs_wasm_core.js", + "ecs_wasm_core.d.ts" + ], + "main": "ecs_wasm_core.js", + "types": "ecs_wasm_core.d.ts", + "sideEffects": [ + "./snippets/*" + ] +} \ No newline at end of file