Skip to content
Permalink
Browse files

feat(asset-bundle): fix "loadAndAssembleAllDependencyRAB and loadSABA…

…ndSetToState->load order" bug: now concat and merge loadAndAssembleAllDependencyRAB and then concat loadSABAndSetToState.

(run test: move origin abs to examples/asset_bundle/asset_bundle1/)
(run test: add new abs to examples/asset_bundle/asset_bundle2/)
  • Loading branch information...
yyc-git committed Apr 25, 2019
1 parent 596703a commit 2ac54418c7d7df971fc69d25fa10df23cb0b1530
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

Large diffs are not rendered by default.

@@ -51,12 +51,17 @@
});
function _init1(script, api, state) {
function _getAssetBundlePath() {
return "asset_bundle2/";
};
// var loadAssetBundle = api.loadAssetBundle;
// var flatMapStream = api.flatMapStream;
var abRelativePath = "sab1.sab";
var sabRelativePath = "sab1.sab";
var wabRelativePath = "wab1.wab";
@@ -65,7 +70,7 @@
api.loadAssetBundle(
wabRelativePath
_getAssetBundlePath() + wabRelativePath
).flatMap((wab) => {
console.log("wab: ", wab);
@@ -89,32 +94,28 @@
api.setState(state);
return api.concatExecStreamArr(
[() =>
api.loadAndAssembleAllDependencyRAB(
abRelativePath,
manifest,
[
api.getAssetBundlePath,
api.isAssetBundleArrayBufferCached,
api.getAssetBundleArrayBufferCache,
api.cacheAssetBundleArrayBuffer
]
),
() =>
api.loadSABAndSetToState(
abRelativePath,
manifest,
[
api.getAssetBundlePath,
api.isAssetBundleArrayBufferCached,
api.getAssetBundleArrayBufferCache,
api.cacheAssetBundleArrayBuffer
]
)
return api.loadAndAssembleAllDependencyRAB(
sabRelativePath,
manifest,
[
_getAssetBundlePath,
api.isAssetBundleArrayBufferCached,
api.getAssetBundleArrayBufferCache,
api.cacheAssetBundleArrayBuffer
]
).concat(
api.loadSABAndSetToState(
sabRelativePath,
manifest,
[
_getAssetBundlePath,
api.isAssetBundleArrayBufferCached,
api.getAssetBundleArrayBufferCache,
api.cacheAssetBundleArrayBuffer
]
)
)
})
.subscribe({
@@ -147,8 +148,8 @@
setTimeout(() => {
var wabRelativePath = "wab1.wab";
var sabRelativePath = "sab1.sab";
// var wabRelativePath = "wab1.wab";
// var sabRelativePath = "sab1.sab";
var state = api.unsafeGetState();
@@ -196,7 +197,6 @@
"complete": () => {
console.log("complete");
}
}
@@ -72,11 +72,9 @@ let concatExecStreamArr =
|> Js.Array.sliceFrom(1)
|> WonderCommonlib.ArrayService.reduceOneParam(
(. stream1, buildStream2Func) =>
/* let stream1 = */
_isFromEventStream(stream1) === true ?
stream1 |> concatMap(() => buildStream2Func(.)) :
stream1 |> concatMap(() => buildStream2Func(.)),
/* stream1 |> concat(stream2) : stream1 |> concat(stream2) */
(Array.unsafe_get(streamArr, 0))(.),
)
};
@@ -25,7 +25,7 @@ let _handleStreamError = e => {
};

let dynamicLoadAB = needRewriteAPI => {
/* LoadABSystem.load(PathABSystem.getAssetBundlePath() ++ "whole.wab")
/* LoadABSystem.load(PathABSystem.getAssetBundlePath(.) ++ "whole.wab")
|> Most.flatMap(wab => {
let manifest = ParseABSystem.WAB.parseManifest(wab);
@@ -41,7 +41,7 @@ let dynamicLoadAB = needRewriteAPI => {
stream
|> Most.flatMap(state =>
LoadABSystem.load(
PathABSystem.getAssetBundlePath() ++ abPath,
PathABSystem.getAssetBundlePath(.) ++ abPath,
)
|> Most.map(ab =>
AssembleABSystem.assemble(abPath, ab, state)
@@ -51,7 +51,7 @@ let dynamicLoadAB = needRewriteAPI => {
);
/* |> Js.Array.map(abPath =>
LoadABSystem.load(
PathABSystem.getAssetBundlePath() ++ abPath,
PathABSystem.getAssetBundlePath(.) ++ abPath,
)
|> Most.map(ab => {
@@ -75,9 +75,9 @@ let dynamicLoadAB = needRewriteAPI => {

let wabRelativePath = "whole.wab";

let abPath = getAssetBundlePath() ++ abRelativePath;
let abPath = getAssetBundlePath(.) ++ abRelativePath;

let wabPath = getAssetBundlePath() ++ wabRelativePath;
let wabPath = getAssetBundlePath(.) ++ wabRelativePath;

let _ =
LoadABSystem.load(wabPath, FetchCommon.fetch)
@@ -100,35 +100,30 @@ let dynamicLoadAB = needRewriteAPI => {
|> StateDataMainService.setState(StateDataMain.stateData)
|> ignore;

MostUtils.concatExecStreamArr([|
(.) =>
ImportABSystem.RAB.loadAndAssembleAllDependencyRAB(
abRelativePath,
manifest,
(
getAssetBundlePath,
isAssetBundleArrayBufferCached,
getAssetBundleArrayBufferCache,
cacheAssetBundleArrayBuffer,
FetchCommon.fetch,
),
/* state, */
),
(.) =>
ImportABSystem.SAB.loadSABAndSetToState(
abRelativePath,
manifest,
/* wholeDependencyRelationMap, */
(
getAssetBundlePath,
isAssetBundleArrayBufferCached,
getAssetBundleArrayBufferCache,
cacheAssetBundleArrayBuffer,
FetchCommon.fetch,
),
/* state, */
),
|]);
ImportABSystem.RAB.loadAndAssembleAllDependencyRAB(
abRelativePath,
manifest,
(
getAssetBundlePath,
isAssetBundleArrayBufferCached,
getAssetBundleArrayBufferCache,
cacheAssetBundleArrayBuffer,
FetchCommon.fetch,
),
)
|> Most.concat(
ImportABSystem.SAB.loadSABAndSetToState(
abRelativePath,
manifest,
(
getAssetBundlePath,
isAssetBundleArrayBufferCached,
getAssetBundleArrayBufferCache,
cacheAssetBundleArrayBuffer,
FetchCommon.fetch,
),
),
);
})
|> Most.subscribe({
"next": _ => (),
@@ -19,7 +19,10 @@ module All = {

isAssetBundleArrayBufferCachedFunc(abRelativePath, hashId) ?
getAssetBundleArrayBufferCacheFunc(abRelativePath) |> Most.just :
LoadABSystem.load(getAssetBundlePathFunc() ++ abRelativePath, fetchFunc)
LoadABSystem.load(
getAssetBundlePathFunc(.) ++ abRelativePath,
fetchFunc,
)
|> Most.tap(ab =>
cacheAssetBundleArrayBufferFunc(abRelativePath, ab, hashId)
);
@@ -39,41 +42,65 @@ module SAB = {
cacheAssetBundleArrayBufferFunc,
fetchFunc,
),
) => {
let state = StateDataMainService.unsafeGetState(StateDataMain.stateData);
) =>
/* let state = StateDataMainService.unsafeGetState(StateDataMain.stateData); */
/* let wholeDependencyRelationMap =
ParseABSystem.WAB.getWholeDependencyRelationMap(wholeManifest); */
Most.just(sabRelativePath)
|> Most.flatMap(sabRelativePath => {
let state =
StateDataMainService.unsafeGetState(StateDataMain.stateData);

let wholeDependencyRelationMap =
ParseABSystem.WAB.getWholeDependencyRelationMap(wholeManifest);
let wholeDependencyRelationMap =
ParseABSystem.WAB.getWholeDependencyRelationMap(wholeManifest);

OperateSABAssetBundleMainService.isLoaded(sabRelativePath, state) ?
Most.empty() :
All.loadAB(
sabRelativePath,
wholeManifest,
wholeDependencyRelationMap,
(
getAssetBundlePathFunc,
isAssetBundleArrayBufferCachedFunc,
getAssetBundleArrayBufferCacheFunc,
cacheAssetBundleArrayBufferFunc,
fetchFunc,
),
)
|> Most.tap(sab => {
let state =
StateDataMainService.unsafeGetState(StateDataMain.stateData);
OperateSABAssetBundleMainService.isLoaded(sabRelativePath, state) ?
Most.empty() :
All.loadAB(
sabRelativePath,
wholeManifest,
wholeDependencyRelationMap,
(
getAssetBundlePathFunc,
isAssetBundleArrayBufferCachedFunc,
getAssetBundleArrayBufferCacheFunc,
cacheAssetBundleArrayBufferFunc,
fetchFunc,
),
)
|> Most.tap(sab => {
let state =
StateDataMainService.unsafeGetState(
StateDataMain.stateData,
);

state
|> OperateSABAssetBundleMainService.markLoaded(sabRelativePath)
|> OperateSABAssetBundleMainService.setLoadedSAB(
sabRelativePath,
sab,
)
|> StateDataMainService.setState(StateDataMain.stateData)
|> ignore;
})
|> Most.map(_ => ());
};
state
|> OperateSABAssetBundleMainService.markLoaded(
sabRelativePath,
)
|> OperateSABAssetBundleMainService.setLoadedSAB(
sabRelativePath,
sab,
)
|> StateDataMainService.setState(StateDataMain.stateData)
|> ignore;
})
|> Most.map(_ => ());
});
/* OperateSABAssetBundleMainService.isLoaded(sabRelativePath, state) ?
Most.empty() :
All.loadAB(
sabRelativePath,
wholeManifest,
wholeDependencyRelationMap,
(
getAssetBundlePathFunc,
isAssetBundleArrayBufferCachedFunc,
getAssetBundleArrayBufferCacheFunc,
cacheAssetBundleArrayBufferFunc,
fetchFunc,
),
) */
};

module RAB = {
@@ -134,45 +161,25 @@ module RAB = {
abRelativePath,
wholeDependencyRelationMap,
)
|> Js.Array.map(rabRelativePathArr =>
(.) =>
rabRelativePathArr
|> Js.Array.map(rabRelativePath =>
_loadAndAssembleRAB(
rabRelativePath,
wholeManifest,
wholeDependencyRelationMap,
(
getAssetBundlePathFunc,
isAssetBundleArrayBufferCachedFunc,
getAssetBundleArrayBufferCacheFunc,
cacheAssetBundleArrayBufferFunc,
fetchFunc,
),
)
|> Most.from
|> Most.concatMap(rabRelativePathArr =>
rabRelativePathArr
|> Js.Array.map(rabRelativePath =>
_loadAndAssembleRAB(
rabRelativePath,
wholeManifest,
wholeDependencyRelationMap,
(
getAssetBundlePathFunc,
isAssetBundleArrayBufferCachedFunc,
getAssetBundleArrayBufferCacheFunc,
cacheAssetBundleArrayBufferFunc,
fetchFunc,
),
)
/* TODO need test in run test */
|> Most.mergeArray
)
|> MostUtils.concatExecStreamArr;
/* |> WonderCommonlib.ArrayService.reduceOneParam(
(. stream, rabRelativePath) =>
stream
|> Most.flatMap(state =>
loadAndAssembleAB(
rabRelativePath,
wholeManifest,
(
getAssetBundlePathFunc,
isAssetBundleArrayBufferCachedFunc,
getAssetBundleArrayBufferCacheFunc,
cacheAssetBundleArrayBufferFunc,
),
state,
)
),
Most.just(state),
); */
)
|> Most.mergeArray
);
};
};

@@ -47,9 +47,9 @@ let create = () => {
"setState":
(. state) =>
StateDataMainService.setState(StateDataMain.stateData, state),
"concatExecStreamArr":
(. streamArr) => MostUtils.concatExecStreamArr(streamArr),
"getAssetBundlePath": () => LoadABSystem.getAssetBundlePath(),
/* "concatExecStreamArr":
(. streamArr) => MostUtils.concatExecStreamArr(streamArr), */
"getAssetBundlePath": (.) => LoadABSystem.getAssetBundlePath(),
"isAssetBundleArrayBufferCached":
(. abRelativePath, hashId) =>
LoadABSystem.isAssetBundleArrayBufferCached(abRelativePath, hashId),

0 comments on commit 2ac5441

Please sign in to comment.
You can’t perform that action at this time.