Skip to content

Commit

Permalink
test(unit-integration-test): pass all tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yyc-git committed May 24, 2019
1 parent cf480b2 commit 33d2053
Show file tree
Hide file tree
Showing 10 changed files with 186 additions and 167 deletions.
22 changes: 1 addition & 21 deletions src/asset/assemble/AssembleCommon.re
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,4 @@ let addChildrenToParent = (parent, children, (parentMap, childMap)) => (
parentMap,
),
WonderCommonlib.MutableSparseMapService.set(parent, children, childMap),
);

let checkNotDisposedBefore = disposedIndexArray =>
WonderLog.Contract.requireCheck(
() =>
WonderLog.(
Contract.(
Operators.(
test(
Log.buildAssertMessage(
~expect={j|not disposed before|j},
~actual={j|do|j},
),
() =>
disposedIndexArray |> Js.Array.length == 0
)
)
)
),
IsDebugMainService.getIsDebug(StateDataMain.stateData),
);
);
4 changes: 0 additions & 4 deletions src/asset/assemble/BatchCreateSystem.re
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,6 @@ let _batchCreateBasicSourceTexture =
let basicSourceTextureRecord =
RecordBasicSourceTextureMainService.getRecord(state);

AssembleCommon.checkNotDisposedBefore(
basicSourceTextureRecord.disposedIndexArray,
);

basicSourceTextures
|> ArrayService.reduceOneParamValidi(
(. (state, indexArr), _, basicSourceTextureIndex) => {
Expand Down
3 changes: 3 additions & 0 deletions src/service/primitive/texture/DisposeTextureService.re
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
let needDisposeGlTextureMap = (texture, glTextureMap) =>
glTextureMap |> WonderCommonlib.MutableSparseMapService.has(texture);

let disposeGlTextureMap = (texture, gl, glTextureMap) =>
switch (
glTextureMap |> WonderCommonlib.MutableSparseMapService.get(texture)
Expand Down
75 changes: 42 additions & 33 deletions src/service/state/main/texture/DisposeTextureMainService.re
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,30 @@ let disposeBasicSourceTextureGlTextureMap = (texture, state) =>
};
} :
{
/* TODO optimize: add gl texture to pool? */
let gl =
DeviceManagerService.unsafeGetGl(. state.deviceManagerRecord);

let {glTextureMap} as basicSourceTextureRecord =
RecordBasicSourceTextureMainService.getRecord(state);

{
...state,
basicSourceTextureRecord:
Some({
...basicSourceTextureRecord,
glTextureMap:
DisposeTextureService.disposeGlTextureMap(
texture,
gl,
glTextureMap,
),
}),
};
DisposeTextureService.needDisposeGlTextureMap(texture, glTextureMap) ?
{
/* TODO optimize: add gl texture to pool? */
let gl =
DeviceManagerService.unsafeGetGl(. state.deviceManagerRecord);

{
...state,
basicSourceTextureRecord:
Some({
...basicSourceTextureRecord,
glTextureMap:
DisposeTextureService.disposeGlTextureMap(
texture,
gl,
glTextureMap,
),
}),
};
} :
state;
}
);

Expand All @@ -60,27 +64,32 @@ let disposeArrayBufferViewSourceTextureGlTextureMap = (texture, state) =>
};
} :
{
/* TODO optimize: add gl texture to pool? */
let gl = DeviceManagerService.unsafeGetGl(. state.deviceManagerRecord);

let (
{glTextureMap}: ArrayBufferViewSourceTextureType.arrayBufferViewSourceTextureRecord
) as arrayBufferViewSourceTextureRecord =
RecordArrayBufferViewSourceTextureMainService.getRecord(state);

{
...state,
arrayBufferViewSourceTextureRecord:
Some({
...arrayBufferViewSourceTextureRecord,
glTextureMap:
DisposeTextureService.disposeGlTextureMap(
texture,
gl,
glTextureMap,
),
}),
};
DisposeTextureService.needDisposeGlTextureMap(texture, glTextureMap) ?
{
/* TODO optimize: add gl texture to pool? */
let gl =
DeviceManagerService.unsafeGetGl(. state.deviceManagerRecord);

{
...state,
arrayBufferViewSourceTextureRecord:
Some({
...arrayBufferViewSourceTextureRecord,
glTextureMap:
DisposeTextureService.disposeGlTextureMap(
texture,
gl,
glTextureMap,
),
}),
};
} :
state;
};

let disposeNeedAddedSourceArray = (texture, needAddedSourceArray) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ let update =
(allocateSourceToTextureFunc, setFlipYFunc),
) => {
let isSourcePowerOfTwo = _isSourcePowerOfTwo(width, height);

setFlipYFunc(gl, flipY, browserDetectRecord);

gl
Expand Down
108 changes: 63 additions & 45 deletions src/service/state/render/texture/UpdateTextureRenderService.re
Original file line number Diff line number Diff line change
@@ -1,64 +1,82 @@
open StateRenderType;

let _handleUpdateBasicSourceTexture =
[@bs]
(
(.
basicSourceTexture,
(
basicSourceTextureInTypeArray,
(
gl,
{basicSourceTextureRecord, arrayBufferViewSourceTextureRecord, browserDetectRecord} as state
)
) => {
let (basicSourceTextureRecord, browserDetectRecord) =
UpdateBasicSourceTextureRenderService.isNeedUpdate(
gl,
{
basicSourceTextureRecord,
arrayBufferViewSourceTextureRecord,
browserDetectRecord,
} as state,
),
) => {
let basicSourceTextureInTypeArray = basicSourceTexture;

let (basicSourceTextureRecord, browserDetectRecord) =
UpdateBasicSourceTextureRenderService.isNeedUpdate(
basicSourceTextureInTypeArray,
basicSourceTextureRecord,
) ?
UpdateBasicSourceTextureRenderService.update(
gl,
basicSourceTextureInTypeArray,
basicSourceTextureRecord
) ?
UpdateBasicSourceTextureRenderService.update(
gl,
basicSourceTextureInTypeArray,
(basicSourceTextureRecord, browserDetectRecord)
) :
(basicSourceTextureRecord, browserDetectRecord);
state
}
);
(basicSourceTextureRecord, browserDetectRecord),
) :
(basicSourceTextureRecord, browserDetectRecord);
state;
};

let _handleUpdateArrayBufferViewSourceTexture =
[@bs]
(
(.
arrayBufferViewTexture,
(
arrayBufferViewTextureInTypeArray,
(
gl,
{basicSourceTextureRecord, arrayBufferViewSourceTextureRecord, browserDetectRecord} as state
)
) => {
let (arrayBufferViewSourceTextureRecord, browserDetectRecord) =
UpdateArrayBufferViewSourceTextureRenderService.isNeedUpdate(
arrayBufferViewTextureInTypeArray,
arrayBufferViewSourceTextureRecord
) ?
UpdateArrayBufferViewSourceTextureRenderService.update(
gl,
arrayBufferViewTextureInTypeArray,
(arrayBufferViewSourceTextureRecord, browserDetectRecord)
) :
(arrayBufferViewSourceTextureRecord, browserDetectRecord);
state
}
);
gl,
{
basicSourceTextureRecord,
arrayBufferViewSourceTextureRecord,
browserDetectRecord,
} as state,
),
) => {
let arrayBufferViewTextureInTypeArray =
IndexSourceTextureService.getArrayBufferViewSourceTextureIndexInTypeArray(
arrayBufferViewTexture,
arrayBufferViewSourceTextureRecord.textureIndexOffset,
);

let (arrayBufferViewSourceTextureRecord, browserDetectRecord) =
UpdateArrayBufferViewSourceTextureRenderService.isNeedUpdate(
arrayBufferViewTextureInTypeArray,
arrayBufferViewSourceTextureRecord,
) ?
UpdateArrayBufferViewSourceTextureRenderService.update(
gl,
(arrayBufferViewTexture,
arrayBufferViewTextureInTypeArray),
(arrayBufferViewSourceTextureRecord, browserDetectRecord),
) :
(arrayBufferViewSourceTextureRecord, browserDetectRecord);
state;
};

let handleUpdate =
(
gl,
texture,
{basicSourceTextureRecord, arrayBufferViewSourceTextureRecord, browserDetectRecord} as state
{
basicSourceTextureRecord,
arrayBufferViewSourceTextureRecord,
browserDetectRecord,
} as state,
) =>
IndexSourceTextureService.handleByJudgeSourceTextureIndex(
texture,
arrayBufferViewSourceTextureRecord.textureIndexOffset,
(gl, state),
(_handleUpdateBasicSourceTexture, _handleUpdateArrayBufferViewSourceTexture)
(
_handleUpdateBasicSourceTexture,
_handleUpdateArrayBufferViewSourceTexture,
),
);
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ open RenderArrayBufferViewSourceTextureType;
open BrowserDetectType;

/* let _setUnpackAlignmentaToOne = [%bs.raw
{|
function(gl){
{|
function(gl){
gl.pixelStorei(gl.UNPACK_ALIGNMENT, 1);
}
|}
]; */
gl.pixelStorei(gl.UNPACK_ALIGNMENT, 1);
}
|}
]; */

let _drawTexture =
(gl, (target, index, source, glFormat, glType), (width, height)) => {
Expand Down Expand Up @@ -59,7 +59,7 @@ let _allocateSourceToTexture = (sizeTuple, gl, paramTuple, source) =>
let update =
(
gl,
textureInTypeArray,
(texture, textureInTypeArray),
(arrayBufferViewSourceTextureRecord, browserDetectRecord),
) => {
let {
Expand All @@ -76,7 +76,8 @@ let update =
heights,
setFlipYFunc,
} = arrayBufferViewSourceTextureRecord;
switch (TextureSourceMapService.getSource(textureInTypeArray, sourceMap)) {

switch (TextureSourceMapService.getSource(texture, sourceMap)) {
| None => (arrayBufferViewSourceTextureRecord, browserDetectRecord)
| Some(source) =>
let width =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,16 @@ let _ =

describe("test dispose gameObject before assemble", () =>
testPromise(
"all components should create component from disposedIndexArray when assemble except basicSourceTexture component",
"all components should create component from disposedIndexArray when assemble",
() => {
let (state, gameObject1, geometry1, _, _, _) =
let (
state,
gameObject1,
geometry1,
_,
_,
(diffuseMap1, specularMap1),
) =
FrontRenderLightJobTool.prepareGameObjectWithCreatedMap(
sandbox,
state^,
Expand Down Expand Up @@ -68,7 +75,7 @@ let _ =
state,
),
)
|> expect == ([|geometry1|], [|specularMap2 + 1|]);
|> expect == ([|geometry1|], [|specularMap1|]);
},
state,
);
Expand Down
Loading

0 comments on commit 33d2053

Please sign in to comment.