Skip to content

Commit

Permalink
feat(asset-bundle): add "assemble rab", "isAssembled" logic
Browse files Browse the repository at this point in the history
  • Loading branch information
yyc-git committed Apr 17, 2019
1 parent 3fc4ecb commit a92371d
Show file tree
Hide file tree
Showing 24 changed files with 1,173 additions and 175 deletions.
4 changes: 2 additions & 2 deletions src/asset/utils/ConvertScriptDataUtils.re
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ let _convertEventFunctionDataMapToStr = eventDataMap =>
let _buildEmptyMapStr = () => "{}";

let unsafeGetEventFunctionDataMapStr = (script, {scriptRecord} as state) => {
let {scriptEventFunctionDataMap} as scriptRecord = scriptRecord;
let ({scriptEventFunctionDataMap}: StateDataMainType.scriptRecord) as scriptRecord = scriptRecord;

switch (
scriptEventFunctionDataMap
Expand All @@ -52,7 +52,7 @@ let _convertAttributeMapToStr = attributeMap =>
attributeMap |> Obj.magic |> Js.Json.stringify;

let unsafeGetAttributeMapStr = (script, {scriptRecord} as state) => {
let {scriptAttributeMap} as scriptRecord = scriptRecord;
let ({scriptAttributeMap}: StateDataMainType.scriptRecord) as scriptRecord = scriptRecord;

/* scriptAttributeMap
|> ImmutableSparseMapService.unsafeGetAndCheck(script)
Expand Down
10 changes: 8 additions & 2 deletions src/asset_bundle/AssetBundleUsageTest.re
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ let dynamicLoadAB = needRewriteAPI => {

/* let state = StateAPI.unsafeGetState(); */

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

ImportABSystem.loadAndAssembleAllDependencies(
abRelativePath,
manifest,
Expand All @@ -95,6 +98,7 @@ let dynamicLoadAB = needRewriteAPI => {
ImportABSystem.loadAndAssembleAB(
abRelativePath,
manifest,
wholeDependencyRelationMap,
(
getAssetBundlePath,
isAssetBundleArrayBufferCached,
Expand All @@ -119,10 +123,11 @@ let goToNextScene = (sabRelativePath, needRewriteAPI, state) =>
AssembleABSystem.isAssembled(sabRelativePath, state) ?
{
let sabAllGameObjects =
OperateAssembleABResultSystem.SAB.findAllGameObjects(
OperateSABAssetBundleMainService.unsafeFindAllGameObjects(
sabRelativePath,
state,
);
/* |> OptionService.unsafeGet; */

let state =
state
Expand All @@ -144,11 +149,12 @@ let replaceToRabLightMaterial = (rabRelativePath, needRewriteAPI, state) =>
AssembleABSystem.isAssembled(rabRelativePath, state) ?
{
let lightMaterial1 =
OperateAssembleABResultSystem.RAB.findLightMaterialByName(
OperateRABAssetBundleMainService.unsafeFindLightMaterialByName(
rabRelativePath,
"lightMaterial1",
state,
);
/* |> OptionService.unsafeGet; */

let gameObjectName = "gameObject10";

Expand Down
54 changes: 7 additions & 47 deletions src/asset_bundle/all/dependency/RemoveDependencyDataSystem.re
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,6 @@ module All = {
};

module RAB = {
let _getArrayBufferFromBufferViews =
(buffer, bufferView, bufferViews: array(RABType.bufferView)) => {
let {byteOffset, byteLength}: RABType.bufferView =
Array.unsafe_get(bufferViews, bufferView);

buffer
|> Js.Typed_array.ArrayBuffer.slice(
~start=byteOffset,
~end_=byteOffset + byteLength,
);
};

let _removeImageDuplicateBufferData =
(
(dependencyRelation, allRabDependentImageNameMap, rabRelativePath),
Expand Down Expand Up @@ -77,7 +65,7 @@ module RAB = {
) :
{
let arrayBuffer =
_getArrayBufferFromBufferViews(
ABArrayBufferUtils.RAB.getArrayBufferFromBufferViews(
buffer,
bufferView,
bufferViews,
Expand Down Expand Up @@ -145,7 +133,11 @@ module RAB = {
) :
{
let arrayBuffer =
_getArrayBufferFromBufferViews(buffer, bufferView, bufferViews);
ABArrayBufferUtils.RAB.getArrayBufferFromBufferViews(
buffer,
bufferView,
bufferViews,
);

let byteLength = arrayBuffer |> ArrayBuffer.byteLength;

Expand Down Expand Up @@ -290,39 +282,7 @@ module RAB = {
);
};

/* let _getJsonStr = (jsonByteLength, rab) => {
let decoder = TextDecoder.newTextDecoder("utf-8");
decoder
|> TextDecoder.decodeUint8Array(
Uint8Array.fromBufferRange(
rab,
~offset=GenerateABUtils.getHeaderTotalByteLength(),
~length=jsonByteLength,
),
);
}; */

let _getBuffer = (jsonByteLength, rab) =>
rab
|> ArrayBuffer.sliceFrom(
GenerateABUtils.getHeaderTotalByteLength()
+ jsonByteLength
|> BufferUtils.alignedLength,
);

/* let _readHeader = dataView => {
let (jsonByteLength, byteOffset) =
DataViewCommon.getUint32_1(. 0, dataView);
let (bufferByteLength, byteOffset) =
DataViewCommon.getUint32_1(. byteOffset, dataView);
(byteOffset, jsonByteLength, bufferByteLength);
}; */

let removeRABDuplicateBufferData =
/* {imageDependencyRelation, geometryDependencyRelation}, */
(
dependencyRelation,
(allRabDependentImageNameMap, allRabDependentGeometryNameMap),
Expand All @@ -334,7 +294,7 @@ module RAB = {
DependencyDataUtils.RAB.readHeader(dataView);

let jsonStr = DependencyDataUtils.RAB.getJsonStr(jsonByteLength, rab);
let buffer = _getBuffer(jsonByteLength, rab);
let buffer = DependencyDataUtils.RAB.getBuffer(jsonByteLength, rab);

let resourceAssetBundleContent: RABType.resourceAssetBundleContent =
jsonStr |> Js.Json.parseExn |> Obj.magic;
Expand Down
20 changes: 18 additions & 2 deletions src/asset_bundle/all/dependency/utils/DependencyDataUtils.re
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ open DependencyDataType;

/* TODO need test */
let rec _isCircleDependency =
(dependencyRelation, recordedAbPathArr, isCircleOpt, abRelativePathArr) =>
(
dependencyRelation,
recordedAbPathArr,
isCircleOpt,
abRelativePathArr,
) =>
switch (isCircleOpt) {
| Some(isCircle) => (isCircle, recordedAbPathArr)
| None =>
Expand All @@ -43,7 +48,10 @@ let rec _isCircleDependency =
| Some(abRelativePathArr) =>
_isCircleDependency(
dependencyRelation,
ArrayService.fastConcat(recordedAbPathArr, abRelativePathArr),
ArrayService.fastConcat(
recordedAbPathArr,
abRelativePathArr,
),
None,
abRelativePathArr,
)
Expand Down Expand Up @@ -125,6 +133,14 @@ module RAB = {
),
);
};

let getBuffer = (jsonByteLength, rab) =>
rab
|> ArrayBuffer.sliceFrom(
GenerateABUtils.getHeaderTotalByteLength()
+ jsonByteLength
|> BufferUtils.alignedLength,
);
};

module SAB = {};
14 changes: 14 additions & 0 deletions src/asset_bundle/all/utils/ABArrayBufferUtils.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module RAB = {

let getArrayBufferFromBufferViews =
(buffer, bufferView, bufferViews: array(RABType.bufferView)) => {
let {byteOffset, byteLength}: RABType.bufferView =
Array.unsafe_get(bufferViews, bufferView);

buffer
|> Js.Typed_array.ArrayBuffer.slice(
~start=byteOffset,
~end_=byteOffset + byteLength,
);
};
}
23 changes: 23 additions & 0 deletions src/asset_bundle/all/utils/GenerateManifestABUtils.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
open Js.Typed_array;

module RAB = {
let readHeader = dataView => {
let (manifestJsonByteLength, byteOffset) =
DataViewCommon.getUint32_1(. 0, dataView);

let (contentBufferByteLength, byteOffset) =
DataViewCommon.getUint32_1(. byteOffset, dataView);

(byteOffset, manifestJsonByteLength, contentBufferByteLength);
};

let getContentBuffer = (manifestJsonByteLength, rab) =>
rab
|> ArrayBuffer.sliceFrom(
GenerateABUtils.getHeaderTotalByteLength()
+ manifestJsonByteLength
|> BufferUtils.alignedLength,
);
};

module SAB = {};
22 changes: 11 additions & 11 deletions src/asset_bundle/import/ImportABSystem.re
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ let loadAndAssembleAB =
(
abRelativePath,
wholeManifest,
wholeDependencyRelationMap,
(
getAssetBundlePathFunc,
isAssetBundleArrayBufferCachedFunc,
Expand All @@ -27,15 +28,15 @@ let loadAndAssembleAB =
|> Most.tap(ab =>
cacheAssetBundleArrayBufferFunc(abRelativePath, ab, hashId)
)
|> Most.map(ab => {
let state =
StateDataMainService.unsafeGetState(StateDataMain.stateData);

let state = AssembleABSystem.assemble(abRelativePath, ab, state);

StateDataMainService.setState(StateDataMain.stateData, state)
|> ignore;
});
|> Most.flatMap(ab =>
AssembleABSystem.assemble(
abRelativePath,
ab,
wholeDependencyRelationMap,
/* StateDataMainService.setState(StateDataMain.stateData, state)
|> ignore; */
)
);
};
};

Expand All @@ -50,8 +51,6 @@ let loadAndAssembleAllDependencies =
cacheAssetBundleArrayBufferFunc,
),
) => {
/* state, */

let state = StateDataMainService.unsafeGetState(StateDataMain.stateData);

AssembleABSystem.isAssembled(abRelativePath, state) ?
Expand All @@ -70,6 +69,7 @@ let loadAndAssembleAllDependencies =
loadAndAssembleAB(
abRelativePath,
wholeManifest,
wholeDependencyRelationMap,
(
getAssetBundlePathFunc,
isAssetBundleArrayBufferCachedFunc,
Expand Down
62 changes: 15 additions & 47 deletions src/asset_bundle/import/LoadABSystem.re
Original file line number Diff line number Diff line change
Expand Up @@ -32,50 +32,18 @@ let load = abPath =>
|> then_(ab => ab |> LoadType.fetchArrayBufferToArrayBuffer |> resolve)
|> Most.fromPromise;

let isAssetBundleArrayBufferCached = () => {};

let getAssetBundleArrayBufferCache = () => {};

let cacheAssetBundleArrayBuffer = () => {};
/* let cache = () => {};
let getAllDependencies = () => {}; */

/* let loadAllDependencies = (abPath, wholeManifest) => {}; */

/* let loadFromCacheAndDownload = (abPath) => {
}; */

/* usage:
load(
getAssetBundlePath() + "whole.wab"
)
|> Most.flatMap((wab) => {
let manifest = WAB.parseManifest(wab);
let wholeDependencyRelationMap = getWholeDependencyRelationMap(manifest);
findAllDependencyAbRelativePath(
"sab/a.sab",
wholeDependencyRelationMap
)
/* |> WonderCommonlib.ArrayService.reduceOneParam */
|> Js.Array.map((abRelativePath) => {
load(
getAssetBundlePath() + abRelativePath
)
|> Most.map((ab) => {
assemble(
abRelativePath, ab
)
})

})
|> Most.mergeArray



})
*/
/* TODO need rewrite by editor */
let isAssetBundleArrayBufferCached = (abRelativePath, hashId) => false;

let getAssetBundleArrayBufferCache = abRelativePath =>
WonderLog.Log.fatal(
WonderLog.Log.buildFatalMessage(
~title="getAssetBundleArrayBufferCache",
~description={j|need rewrite|j},
~reason="",
~solution={j||j},
~params={j||j},
),
);

let cacheAssetBundleArrayBuffer = (abRelativePath, ab, hashId) => ab;
Loading

0 comments on commit a92371d

Please sign in to comment.