Skip to content

Commit

Permalink
Merge branch 'v3.8.0' of github.com:cocos/cocos-engine into v3.8.0-4-…
Browse files Browse the repository at this point in the history
…group-0625
  • Loading branch information
arsen2010 committed Jun 26, 2023
2 parents 736742f + 1090830 commit 33a66c3
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions pal/wasm/wasm-minigame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
THE SOFTWARE.
*/

// fsUtils is defined in engine-adapter
declare const fsUtils: any;
import { OPPO } from 'internal:constants';

export function instantiateWasm (wasmUrl: string, importObject: WebAssembly.Imports): Promise<any> {
wasmUrl = `cocos-js/${wasmUrl}`;
Expand All @@ -32,6 +31,20 @@ export function instantiateWasm (wasmUrl: string, importObject: WebAssembly.Impo

export function fetchBuffer (binaryUrl: string): Promise<ArrayBuffer> {
return new Promise<ArrayBuffer>((resolve, reject) => {
// fsUtils is defined in engine-adapter
const fsUtils = globalThis.fsUtils;
if (OPPO) {
getBinaryUrlOnOPPO(binaryUrl).then((url) => {
fsUtils.readArrayBuffer(url, (err, arrayBuffer) => {
if (err) {
reject(err);
return;
}
resolve(arrayBuffer);
});
}).catch((e) => {});
return;
}
fsUtils.readArrayBuffer(`cocos-js/${binaryUrl}`, (err, arrayBuffer) => {
if (err) {
reject(err);
Expand All @@ -41,3 +54,18 @@ export function fetchBuffer (binaryUrl: string): Promise<ArrayBuffer> {
});
});
}

// On OPPO platform, we put binary assets in cocos-library directory when using separate engine.
function getBinaryUrlOnOPPO (binaryUrl: string): Promise<string> {
return new Promise((resolve) => {
const urlInCocosJS = `cocos-js/${binaryUrl}`;
// fsUtils is defined in engine-adapter
globalThis.fsUtils.exists(urlInCocosJS, (isExists: boolean) => {
if (isExists) {
resolve(urlInCocosJS);
} else {
resolve(`cocos-library/${binaryUrl}`);
}
});
});
}

0 comments on commit 33a66c3

Please sign in to comment.