Skip to content

Commit

Permalink
feat(asset): add loadImages api
Browse files Browse the repository at this point in the history
add test cases;

(refactor: move SinonCPTool to test/construct/tool/ and rename it to SinonTool)
  • Loading branch information
yyc-git committed Sep 27, 2020
1 parent b18a9dc commit 9829bf9
Show file tree
Hide file tree
Showing 39 changed files with 715 additions and 492 deletions.
1 change: 1 addition & 0 deletions .cz-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module.exports = {
{ name: "transform" },
{ name: "geometry" },
{ name: "pipeline" },
{ name: "asset" },
{ name: "dependency" },
{ name: "cloud-picture" },
],
Expand Down
3 changes: 3 additions & 0 deletions src/construct/application_layer/asset/AssetApService.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
let loadImages = imageDataList => {
LoadImageDoService.loadImages(imageDataList);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
let set = dp => {
DpContainer.setNetworkDp(dp);
};
23 changes: 13 additions & 10 deletions src/construct/domain_layer/dependency/container/DpContainer.re
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@ type t = {
mutable time: option(ITimeDp.time),
mutable webgpuCore: option(IWebGPUCoreDp.webgpuCore),
mutable webgpuRayTracing: option(IWebGPURayTracingDp.webgpuRayTracing),
// mutable network: option(INetworkDp.network),
mutable network: option(INetworkDp.network),
};

let dpContainer = {
otherConfig: None,
poConfig: None,
repo: None,
time: None,

webgpuCore: None,
webgpuRayTracing: None,
// network: None,
network: None,
};

let unsafeGetOtherConfigDp = () => {
Expand Down Expand Up @@ -87,6 +86,10 @@ let unsafeGetTimeRepoDp = () => {
_unsafeGetRepoDp().timeRepo;
};

let unsafeGetImageRepoDp = () => {
_unsafeGetRepoDp().imageRepo;
};

let setRepoDp = dp => {
dpContainer.repo = dp->Some;

Expand Down Expand Up @@ -123,12 +126,12 @@ let setWebGPURayTracingDp = dp => {
();
};

// let unsafeGetNetworkDp = () => {
// dpContainer.network->OptionSt.unsafeGet;
// };
let unsafeGetNetworkDp = () => {
dpContainer.network->OptionSt.unsafeGet;
};

// let setNetworkDp = dp => {
// dpContainer.network = dp->Some;
let setNetworkDp = dp => {
dpContainer.network = dp->Some;

// ();
// };
();
};
6 changes: 6 additions & 0 deletions src/construct/domain_layer/dependency/interface/INetworkDp.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type path = string;

type network = {
readImageFile:
path => Result.t2(WonderBsMost.Most.stream(ImagePOType.data)),
};
6 changes: 6 additions & 0 deletions src/construct/domain_layer/dependency/interface/IRepoDp.re
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ type timeRepo = {
start: TimePOType.time => unit,
};

type imageRepo = {
getData: ImagePOType.id => Js.Nullable.t(ImagePOType.data),
setData: (ImagePOType.id, ImagePOType.data) => unit,
};

type repo = {
sceneRepo,
gameObjectRepo,
Expand All @@ -178,4 +183,5 @@ type repo = {
globalTempRepo,
pipelineRepo,
timeRepo,
imageRepo,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
type id = string;

type data = {
width: int,
height: int,
data: Js.Typed_array.Uint8Array.t,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
open WonderBsMost.Most;

let loadImages = imageDataList => {
imageDataList
->ListSt.traverseResultM(((id, path)) => {
DpContainer.unsafeGetNetworkDp().readImageFile(path)
->Result.mapSuccess(stream => {
stream->tap(
imageData => {
DpContainer.unsafeGetImageRepoDp().setData(
id,
imageData,
)
},
_,
)
})
})
->Result.mapSuccess(streamList => {streamList->ListSt.toArray->mergeArray});
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
let set = (dp: INetworkDp.network) => {
NetworkDpApService.set(dp);
};
3 changes: 3 additions & 0 deletions src/construct/external_layer/api/run/domain/AssetRunAPI.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
let loadImages = imageDataList => {
AssetApService.loadImages(imageDataList);
};
3 changes: 3 additions & 0 deletions src/run/cloud_picture/application_layer/AssetCPApService.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
let loadImages = imageDataArr => {
AssetRunAPI.loadImages(imageDataArr->ListSt.fromArray);
};
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ let _injectDependencies = () => {
start: TimeCPRepoDp.start,
getElapsed: TimeCPRepoDp.getElapsed,
},
imageRepo: {
getData: ImageCPRepoDp.getData,
setData: ImageCPRepoDp.setData,
},
});

POConfigDpRunAPI.set({
Expand Down
3 changes: 3 additions & 0 deletions src/run/cloud_picture/domain_layer/repo/CreateCPRepo.re
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,7 @@ let create = () => {
staticBindGroupData: None,
pipeline: None,
},
image: {
dataMap: ImmutableHashMap.createEmpty(),
},
};
3 changes: 3 additions & 0 deletions src/run/cloud_picture/external_layer/api/AssetCPAPI.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
let loadImages = imageDataArr => {
AssetCPApService.loadImages(imageDataArr);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
let set = dp => {
NetworkDpRunAPI.set(dp);
};
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,15 @@ let setAccumulationPass = accumulationPass => {

{...po, accumulationPass}->CPContainerManager.setPO;
};

let getImage = () => {
let po = CPContainerManager.getPO();

po.image;
};

let setImage = image => {
let po = CPContainerManager.getPO();

{...po, image}->CPContainerManager.setPO;
};
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ type po = {
pass: PassCPPOType.pass,
pathTracingPass: PathTracingPassCPPOType.pathTracingPass,
accumulationPass: AccumulationPassCPPOType.accumulationPass,
image: ImageCPPOType.image,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
type image = {
dataMap: ImmutableHashMap.t(ImagePOType.id, ImagePOType.data),
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
open ImageCPPOType;

let setData = (id, data) => {
let {dataMap} as po = CPRepo.getImage();

CPRepo.setImage({
...CPRepo.getImage(),
dataMap: dataMap->ImmutableHashMap.set(id, data),
});
};

let getData = id => {
CPRepo.getImage().dataMap->ImmutableHashMap.getNullable(id);
};
13 changes: 12 additions & 1 deletion test/construct/tool/DependencyTool.re
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
open Sinon;

let injectAllDependencies = (~isDebug=true, ()) => {
DirectorCPApService._injectDependencies();

OtherConfigDpCPAPI.set({getIsDebug: () => isDebug});
};
};

let injectNetworkDp =
(
~sandbox,
~readImageFile=createEmptyStub(refJsObjToSandbox(sandbox^)),
(),
) => {
NetworkDpRunAPI.set({readImageFile: readImageFile});
};
File renamed without changes.
Loading

0 comments on commit 9829bf9

Please sign in to comment.