Skip to content

Commit

Permalink
feat(asset-bundle): fix "loadAndAssembleAllDependencyRAB and loadSABA…
Browse files Browse the repository at this point in the history
…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 2ac5441
Show file tree
Hide file tree
Showing 16 changed files with 537 additions and 182 deletions.
Binary file added examples/asset/image/1.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file added examples/asset_bundle/asset_bundle2/rab1.rab
Binary file not shown.
Binary file added examples/asset_bundle/asset_bundle2/rab2.rab
Binary file not shown.
Binary file added examples/asset_bundle/asset_bundle2/rab3.rab
Binary file not shown.
Binary file added examples/asset_bundle/asset_bundle2/sab1.sab
Binary file not shown.
Binary file added examples/asset_bundle/asset_bundle2/wab1.wab
Binary file not shown.
435 changes: 395 additions & 40 deletions examples/asset_bundle/index.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions examples/asset_bundle/use.html
Expand Up @@ -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";
Expand All @@ -65,7 +70,7 @@


api.loadAssetBundle(
wabRelativePath
_getAssetBundlePath() + wabRelativePath
).flatMap((wab) => {
console.log("wab: ", wab);

Expand All @@ -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({
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -196,7 +197,6 @@
"complete": () => {
console.log("complete");
}

}


Expand Down
2 changes: 0 additions & 2 deletions src/asset/utils/MostUtils.re
Expand Up @@ -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))(.),
)
};
Expand Down
63 changes: 29 additions & 34 deletions src/asset_bundle/AssetBundleUsageTest.re
Expand Up @@ -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);
Expand All @@ -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)
Expand All @@ -51,7 +51,7 @@ let dynamicLoadAB = needRewriteAPI => {
);
/* |> Js.Array.map(abPath =>
LoadABSystem.load(
PathABSystem.getAssetBundlePath() ++ abPath,
PathABSystem.getAssetBundlePath(.) ++ abPath,
)
|> Most.map(ab => {
Expand All @@ -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)
Expand All @@ -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": _ => (),
Expand Down
149 changes: 78 additions & 71 deletions src/asset_bundle/import/ImportABSystem.re
Expand Up @@ -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)
);
Expand All @@ -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 = {
Expand Down Expand Up @@ -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
);
};
};

Expand Down
Expand Up @@ -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),
Expand Down

0 comments on commit 2ac5441

Please sign in to comment.