完善发布asm.js脚本

This commit is contained in:
janing
2025-11-29 01:42:48 +08:00
parent 8c7f70ae9b
commit e8a07c695e
11 changed files with 202 additions and 157 deletions

View File

@@ -21,7 +21,7 @@ export class WasmPhysicsEngine implements IPhysicsEngine {
* @param settings 物理设置
* @param wasmFactory WASM工厂函数可选推荐使用
*/
async initialize(settings: PhysicsSettings, wasmFactory?: any): Promise<void> {
async initialize(settings: PhysicsSettings ): Promise<void> {
if (this.state === WasmModuleState.LOADED) {
return;
}
@@ -29,15 +29,7 @@ export class WasmPhysicsEngine implements IPhysicsEngine {
this.state = WasmModuleState.LOADING;
try {
if (wasmFactory) {
// 使用新的 WasmLoader推荐方式
await this.initializeWithWasmLoader(wasmFactory);
} else {
// 回退到旧的加载方式(保持向后兼容)
console.warn('使用旧的 WASM 加载方式,推荐提供 wasmFactory 参数使用 WasmLoader');
await this.initializeLegacy();
}
await this.initializeLegacy();
this.state = WasmModuleState.LOADED;
console.log('WASM Physics Engine initialized successfully');
@@ -102,8 +94,18 @@ export class WasmPhysicsEngine implements IPhysicsEngine {
*/
private async initializeLegacy(): Promise<void> {
// 加载 WASM 文件
const wasmPath = 'assets/wasm/pinball_physics.wasm';
const wasmResponse = await fetch(wasmPath);
const result = await wasmLoader.loadWasmWithAsmFallback(
wasmFactory, // WASM 工厂函数
asmFactory, // ASM 工厂函数
'pinball_physics.wasm', // WASM 文件名
'pinball_physics.asm.mem', // ASM 内存文件名
'44cacb3c-e901-455d-b3e1-1c38a69718e1', // WASM UUID
'3400003e-dc3c-43c1-8757-3e082429125a', // ASM UUID
'wasmFiles' // Bundle 名称
);
console.log('模块加载成功,使用的是:', result.isWasm ? 'WASM' : 'ASM');
console.log('模块实例:', result.instance);
if (!wasmResponse.ok) {
throw new Error(`Failed to fetch WASM file: ${wasmResponse.statusText}`);

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "c244f34a-30ab-4c13-ad52-9660a71d9cc4",
"files": [],
"subMetas": {},
"userData": {}
}