Skip to content
Permalink
Browse files

feat(asset-bundle): add "assemble rab", "isAssembled" logic

  • Loading branch information...
yyc-git committed Apr 17, 2019
1 parent 3fc4ecb commit a92371d3acc31a68a404fb9a6bf3018a44a84842
Showing with 1,173 additions and 175 deletions.
  1. +2 −2 src/asset/utils/ConvertScriptDataUtils.re
  2. +8 −2 src/asset_bundle/AssetBundleUsageTest.re
  3. +7 −47 src/asset_bundle/all/dependency/RemoveDependencyDataSystem.re
  4. +18 −2 src/asset_bundle/all/dependency/utils/DependencyDataUtils.re
  5. +14 −0 src/asset_bundle/all/utils/ABArrayBufferUtils.re
  6. +23 −0 src/asset_bundle/all/utils/GenerateManifestABUtils.re
  7. +11 −11 src/asset_bundle/import/ImportABSystem.re
  8. +15 −47 src/asset_bundle/import/LoadABSystem.re
  9. +607 −6 src/asset_bundle/import/assemble/AssembleABSystem.re
  10. +0 −24 src/asset_bundle/import/assemble/OperateAssembleABResultSystem.re
  11. +5 −0 src/asset_bundle/rab/data/RABType.re
  12. +32 −14 src/asset_bundle/rab/generate/BuildRABJsonDataSystem.re
  13. +99 −0 src/service/record/main/data/assetBundle/AssetBundleType.re
  14. +2 −0 src/service/record/main/data/material/BasicMaterialType.re
  15. +4 −1 src/service/record/main/data/material/LightMaterialType.re
  16. +2 −0 src/service/record/main/data/texture/BasicSourceTextureType.re
  17. +199 −0 src/service/state/main/assetBundle/OperateRABAssetBundleMainService.re
  18. +31 −0 src/service/state/main/assetBundle/OperateSABAssetBundleMainService.re
  19. +21 −0 src/service/state/main/assetBundle/RecordAssetBundleMainService.re
  20. +50 −0 src/service/state/main/data/StateDataMainType.re
  21. +15 −15 src/service/state/main/script/OperateScriptDataMainService.re
  22. +3 −3 src/service/state/main/script/OperateScriptEventFunctionDataMainService.re
  23. +1 −0 src/service/state/main/state/CreateStateMainService.re
  24. +4 −1 test/unit/ecs/component/script/Script_test.re
@@ -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
@@ -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)
@@ -80,6 +80,9 @@ let dynamicLoadAB = needRewriteAPI => {

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

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

ImportABSystem.loadAndAssembleAllDependencies(
abRelativePath,
manifest,
@@ -95,6 +98,7 @@ let dynamicLoadAB = needRewriteAPI => {
ImportABSystem.loadAndAssembleAB(
abRelativePath,
manifest,
wholeDependencyRelationMap,
(
getAssetBundlePath,
isAssetBundleArrayBufferCached,
@@ -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
@@ -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";

@@ -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),
@@ -77,7 +65,7 @@ module RAB = {
) :
{
let arrayBuffer =
_getArrayBufferFromBufferViews(
ABArrayBufferUtils.RAB.getArrayBufferFromBufferViews(
buffer,
bufferView,
bufferViews,
@@ -145,7 +133,11 @@ module RAB = {
) :
{
let arrayBuffer =
_getArrayBufferFromBufferViews(buffer, bufferView, bufferViews);
ABArrayBufferUtils.RAB.getArrayBufferFromBufferViews(
buffer,
bufferView,
bufferViews,
);

let byteLength = arrayBuffer |> ArrayBuffer.byteLength;

@@ -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),
@@ -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;
@@ -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 =>
@@ -43,7 +48,10 @@ let rec _isCircleDependency =
| Some(abRelativePathArr) =>
_isCircleDependency(
dependencyRelation,
ArrayService.fastConcat(recordedAbPathArr, abRelativePathArr),
ArrayService.fastConcat(
recordedAbPathArr,
abRelativePathArr,
),
None,
abRelativePathArr,
)
@@ -125,6 +133,14 @@ module RAB = {
),
);
};

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

module SAB = {};
@@ -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,
);
};
}
@@ -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 = {};
@@ -4,6 +4,7 @@ let loadAndAssembleAB =
(
abRelativePath,
wholeManifest,
wholeDependencyRelationMap,
(
getAssetBundlePathFunc,
isAssetBundleArrayBufferCachedFunc,
@@ -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; */
)
);
};
};

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

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

AssembleABSystem.isAssembled(abRelativePath, state) ?
@@ -70,6 +69,7 @@ let loadAndAssembleAllDependencies =
loadAndAssembleAB(
abRelativePath,
wholeManifest,
wholeDependencyRelationMap,
(
getAssetBundlePathFunc,
isAssetBundleArrayBufferCachedFunc,
@@ -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;

0 comments on commit a92371d

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