重构WASM架构:移除npm包中的WASM文件,改为独立发布 - 移除自动WASM加载逻辑 - 添加手动initializeWasm API - 创建专门的WASM发布包构建脚本 - 更新Cocos Creator使用指南

This commit is contained in:
YHH
2025-06-09 15:54:34 +08:00
parent 94c050bacb
commit 996a7f3ddf
10 changed files with 839 additions and 29 deletions

68
wasm-release/README.md Normal file
View File

@@ -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)