Skip to content

Commit 8394da3

Browse files
committed
feat(asset-bundle): optimize load rabs and sab: 1.merge load all; 2.concat assemble dependency rabs
(feat(asset-bundle): add loadWABAndSetToState api) (feat(asset-bundle): fix progress: add replace old apis with new ones(getAllNeededABCount, getLoadedNeededABCount))
1 parent d3ea970 commit 8394da3

File tree

18 files changed

+902
-395
lines changed

18 files changed

+902
-395
lines changed

examples/asset_bundle/use.html

Lines changed: 72 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,7 @@
177177

178178
resolve(request.result[cacheFieldName]);
179179
} else {
180-
console.log("get no data");
181-
182-
resolve(null);
180+
reject("get no cache")
183181
}
184182
};
185183
})
@@ -234,9 +232,8 @@
234232

235233

236234

237-
238-
api.loadAssetBundle(
239-
_getAssetBundlePath() + wabRelativePath
235+
api.loadWABAndSetToState(
236+
wabRelativePath, _getAssetBundlePath
240237
).flatMap((wab) => {
241238
console.log("wab: ", wab);
242239

@@ -260,7 +257,7 @@
260257
api.setState(state);
261258

262259

263-
return api.loadAndAssembleAllDependencyRAB(
260+
return api.loadAllDependencyRABAndSetToState(
264261
sabRelativePath,
265262
manifest,
266263
[
@@ -270,8 +267,7 @@
270267
_getAssetBundleArrayBufferCache,
271268
_cacheAssetBundleArrayBuffer
272269
]
273-
274-
).concat(
270+
).merge(
275271
api.loadSABAndSetToState(
276272
sabRelativePath,
277273
manifest,
@@ -284,6 +280,8 @@
284280
]
285281

286282
)
283+
).concat(
284+
api.assembleAllDependencyRAB(sabRelativePath, wholeDependencyRelationMap)
287285
)
288286
})
289287
.subscribe({
@@ -315,77 +313,87 @@
315313
// console.log("init->a: ", a)
316314

317315

318-
// var intervalId = setInterval(() => {
319-
// var state = api.unsafeGetState();
316+
var intervalId = setInterval(() => {
317+
var state = api.unsafeGetState();
318+
319+
if (!api.isWABLoaded(
320+
wabRelativePath,
321+
state
322+
)) {
323+
console.log("wab is not loaded");
320324

321-
// if (api.isSABLoaded(
322-
// sabRelativePath, state
323-
// )) {
324-
// console.log("assemble sab");
325+
return;
326+
}
325327

326-
// clearInterval(intervalId);
328+
if (api.canAssembleSAB(
329+
sabRelativePath,
330+
wabRelativePath,
331+
state
332+
)) {
333+
console.log("assemble sab");
327334

328-
// api.assembleSAB(
329-
// sabRelativePath,
335+
clearInterval(intervalId);
330336

331-
// api.unsafeGetLoadedSAB(
332-
// sabRelativePath, state
333-
// ),
334-
// api.unsafeGetWholeDependencyRelationMap(
335-
// wabRelativePath, state
336-
// )
337-
// ).
337+
api.assembleSAB(
338+
sabRelativePath,
338339

339-
// subscribe(
340-
// {
341-
// "next": (sceneGameObject) => {
342-
// var state = api.unsafeGetState();
340+
api.unsafeGetLoadedSAB(
341+
sabRelativePath, state
342+
),
343+
api.unsafeGetWholeDependencyRelationMap(
344+
wabRelativePath, state
345+
)
346+
).
343347

344-
// var state = api.initAllSABGameObjects(
345-
// sceneGameObject, state
346-
// );
348+
subscribe(
349+
{
350+
"next": (sceneGameObject) => {
351+
var state = api.unsafeGetState();
347352

353+
var state = api.initAllSABGameObjects(
354+
sceneGameObject, state
355+
);
348356

349-
// // var state =
350-
// // api.disposeSceneAllChildren(state);
351357

352-
// // var state =
353-
// // api.setSABSceneGameObjectToBeScene(sceneGameObject, state);
358+
// var state =
359+
// api.disposeSceneAllChildren(state);
354360

361+
// var state =
362+
// api.setSABSceneGameObjectToBeScene(sceneGameObject, state);
355363

356-
// var state =
357-
// api.addSABSceneGameObjectChildrenToScene(sceneGameObject, state);
358364

365+
var state =
366+
api.addSABSceneGameObjectChildrenToScene(sceneGameObject, state);
359367

360-
// api.setState(state);
361-
// },
362-
// "error": e => {
363-
// console.log("error: ", e);
364-
// },
365-
// "complete": () => {
366-
// console.log("complete");
367-
// }
368-
// }
369368

369+
api.setState(state);
370+
},
371+
"error": e => {
372+
console.log("error: ", e);
373+
},
374+
"complete": () => {
375+
console.log("complete");
376+
}
377+
}
370378

371-
// )
372-
// }
373-
// else {
374-
// console.log("sab not loaded! need wait",
375-
// api.getAllDependencyRABCount(
376-
// sabRelativePath,
377-
// wabRelativePath,
378-
// state,
379-
// ),
380-
// api.getLoadedDependencyRABCount(
381-
// sabRelativePath,
382-
// wabRelativePath,
383-
// state,
384-
// )
385-
// )
386-
// }
387379

388-
// }, 30);
380+
)
381+
}
382+
else {
383+
console.log("sab can't be assembled! need wait",
384+
api.getAllNeededABCount(
385+
sabRelativePath,
386+
wabRelativePath,
387+
state,
388+
),
389+
api.getLoadedNeededABCount(
390+
sabRelativePath,
391+
wabRelativePath,
392+
state,
393+
)
394+
)
395+
}
396+
}, 30);
389397

390398

391399

src/asset_bundle/AssetBundleUsageTest.re

Lines changed: 0 additions & 178 deletions
This file was deleted.

0 commit comments

Comments
 (0)