Skip to content

Commit

Permalink
feat(imgCanvas): fix AssetTreeInspectorUtils->disposeContainerGameObj…
Browse files Browse the repository at this point in the history
…ectAllChildrenAndReallocateCPUMemory->_reallocateCPUMemory: add condition judge
  • Loading branch information
yyc-git committed May 24, 2019
1 parent a6a1fdd commit 90e4a49
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ module Method = {
StateInspectorEngineService.unsafeGetState(),
)
|> AssetTreeInspectorUtils.disposeContainerGameObjectAllChildrenAndReallocateCPUMemory
/* TODO why set camera distance here? */
|> AssetTreeInspectorUtils.setCameraDefaultDistance
|> StateInspectorEngineService.setState
|> ignore;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,18 @@ let hideInspectorCanvas = () =>
false,
);

let _reallocateEveryTime =
(inspectorEngineState: Wonderjs.StateDataMainType.state) => {
WonderLog.Log.log({j|trigger reallocateEveryTime|j});

/* let inspectorEngineState =
inspectorEngineState
/* TODO fix? */
|> ReallocateCPUMemoryJobEngineService.resetDisposeCount
|> ReallocateCPUMemoryJobEngineService.reallocateGameObjectByDisposeCount; */

let inspectorEngineState =
inspectorEngineState
|> ReallocateCPUMemoryJobEngineService.reallocateGameObject;

/* TODO optimize: judge and reallocate */
ReallocateCPUMemoryJobEngineService.reAllocateToBuffer(
ReallocateCPUMemoryJobEngineService.initGeometryBufferData(
inspectorEngineState,
),
inspectorEngineState,
);
};
let _reallocateCPUMemory =
(inspectorEngineState: Wonderjs.StateDataMainType.state) =>
inspectorEngineState
|> ReallocateCPUMemoryJobEngineService.reallocateGameObjectByDisposeCount
|> ReallocateCPUMemoryJobEngineService.reallocateGeometry(0.5);

/* TODO need fix bug */
let disposeContainerGameObjectAllChildrenAndReallocateCPUMemory =
((editorState, inspectorEngineState: Wonderjs.StateDataMainType.state)) =>
(editorState, inspectorEngineState)
|> InspectorEngineGameObjectLogicService.disposeInspectorEngineContainerGameObjectAllChildren
|> JobEngineService.execDisposeJob
|> _reallocateEveryTime;
|> _reallocateCPUMemory;

let setCameraDefaultDistance = inspectorEngineState => {
let camera =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ let resetDisposeCount = ReallocateCPUMemoryJobAPI.resetDisposeCount;

let reAllocateToBuffer = ReallocateCPUMemoryJobAPI.reAllocateToBuffer;

let initGeometryBufferData = ReallocateCPUMemoryJobAPI.initGeometryBufferData;
let initGeometryBufferData = ReallocateCPUMemoryJobAPI.initGeometryBufferData;

let reallocateGeometry = ReallocateCPUMemoryJobAPI.reallocateGeometry;
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ let _ =

let boxTexturedWDBArrayBuffer = ref(Obj.magic(1));
let sceneWDBArrayBuffer = ref(Obj.magic(1));

let _getInspectorCameraArcballCameraControllerDistance =
inspectorEngineState =>
inspectorEngineState
Expand All @@ -29,19 +30,12 @@ let _ =
inspectorEngineState,
);

beforeAll(() => {
boxTexturedWDBArrayBuffer := WDBTool.convertGLBToWDB("BoxTextured");
sceneWDBArrayBuffer := WDBTool.generateSceneWDB();
});

beforeEach(() => {
sandbox := createSandbox();

MainEditorSceneTool.initState(~sandbox, ());

let _prepareInspectorEngineState =
(~buffer=SettingToolEngine.buildBufferConfigStr(), ()) => {
MainEditorSceneTool.initInspectorEngineState(
~sandbox,
~isInitJob=false,
~buffer,
~noWorkerJobRecord=
NoWorkerJobConfigToolEngine.buildNoWorkerJobConfig(
~initPipelines=
Expand Down Expand Up @@ -69,6 +63,7 @@ let _ =
"jobs": [
{
"name": "dispose"
}
]
}
Expand All @@ -83,6 +78,19 @@ let _ =
|> MainUtils._handleInspectorEngineState
|> StateInspectorEngineService.setState
|> ignore;
};

beforeAll(() => {
boxTexturedWDBArrayBuffer := WDBTool.convertGLBToWDB("BoxTextured");
sceneWDBArrayBuffer := WDBTool.generateSceneWDB();
});

beforeEach(() => {
sandbox := createSandbox();

MainEditorSceneTool.initState(~sandbox, ());

_prepareInspectorEngineState();

CanvasTool.prepareInspectorCanvasAndImgCanvas(sandbox) |> ignore;

Expand Down Expand Up @@ -696,55 +704,102 @@ let _ =
})
);

describe("test dispose wdbGameObject in willUnmount", () => {
testPromise(
"the container gameObject children array should be empty", () => {
let (
addedMaterialNodeId,
newMaterialComponent,
imgCanvasFakeBase64Str,
(inspectorCanvasDom, imgCanvasDom),
) =
MainEditorLightMaterialForAssetTool.prepareInspectorMaterialSphereAndImgCanvas(
~sandbox,
describe("test willUnmount", () => {
describe("dispose wdbGameObject", () =>
testPromise(
"the container gameObject children array should be empty", () => {
let (
addedMaterialNodeId,
newMaterialComponent,
imgCanvasFakeBase64Str,
(inspectorCanvasDom, imgCanvasDom),
) =
MainEditorLightMaterialForAssetTool.prepareInspectorMaterialSphereAndImgCanvas(
~sandbox,
(),
);

MainEditorAssetUploadTool.loadOneWDB(
~arrayBuffer=sceneWDBArrayBuffer^,
(),
);
)
|> then_(uploadedWDBNodeId => {
let editorState = StateEditorService.getState();

MainEditorAssetUploadTool.loadOneWDB(
~arrayBuffer=sceneWDBArrayBuffer^,
(),
)
|> then_(uploadedWDBNodeId => {
let editorState = StateEditorService.getState();
let sceneWDBGameObject =
MainEditorAssetWDBNodeTool.getWDBGameObject(
uploadedWDBNodeId,
editorState,
);

let sceneWDBGameObject =
MainEditorAssetWDBNodeTool.getWDBGameObject(
uploadedWDBNodeId,
editorState,
);
WDBInspector.Method.didMount(sceneWDBGameObject);
WDBInspector.Method.willUnmount();

WDBInspector.Method.didMount(sceneWDBGameObject);
WDBInspector.Method.willUnmount();
let inspectorEngineState =
StateInspectorEngineService.unsafeGetState();
let editorState = StateEditorService.getState();
let containerGameObject =
ContainerGameObjectInspectorCanvasEditorService.unsafeGetContainerGameObject(
editorState,
);

let inspectorEngineState =
StateInspectorEngineService.unsafeGetState();
let editorState = StateEditorService.getState();
let containerGameObject =
ContainerGameObjectInspectorCanvasEditorService.unsafeGetContainerGameObject(
editorState,
);
inspectorEngineState
|> HierarchyGameObjectEngineService.getChildren(
containerGameObject,
)
|> Js.Array.length
|> expect == 0
|> resolve;
});
})
);

describe("reallocate cpu memory", () =>
describe("reallocate geometry", () =>
describe("if geometry buffer is used >= 50%, reallocate", () =>
testPromise("pack type array", () => {
TestTool.ignoreError(sandbox);
_prepareInspectorEngineState(
~buffer=
SettingToolEngine.buildBufferConfigStr(
~geometryPointCount=80,
(),
),
(),
);

MainEditorAssetUploadTool.loadOneWDB(
~arrayBuffer=boxTexturedWDBArrayBuffer^,
(),
)
|> then_(_ =>
MainEditorAssetUploadTool.loadOneWDB(
~arrayBuffer=boxTexturedWDBArrayBuffer^,
(),
)
|> then_(_ => {
let vertices =
StateInspectorEngineService.unsafeGetState()
|> GeometryToolEngine.getVertices;

vertices
|> Js.Typed_array.Float32Array.slice(
~start=72,
~end_=75,
)
|> expect
== Js.Typed_array.Float32Array.make([|0., 0., 0.|])
|> resolve;
})
);
})
)
)
);

inspectorEngineState
|> HierarchyGameObjectEngineService.getChildren(
containerGameObject,
)
|> Js.Array.length
|> expect == 0
|> resolve;
});
});
testPromise(
"test inspector canvas camera arcball controller distance", () => {
"set inspector canvas camera arcball controller distance to default",
() => {
let (
addedMaterialNodeId,
newMaterialComponent,
Expand Down
1 change: 1 addition & 0 deletions test/tool/MainEditorSceneTool.re
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ let initInspectorEngineState =
TestToolEngine.createAndSetInspectorEngineState(
~sandbox,
~isInitJob,
~buffer,
~noWorkerJobRecord,
(),
);
Expand Down
10 changes: 9 additions & 1 deletion test/tool/TestTool.re
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,21 @@ let initEngineStateAndInitSceneWithJob =
let openContractCheck = () => {
StateEditorService.setStateIsDebug(true);
StateEngineService.setIsDebug(true) |> ignore;
StateInspectorEngineService.setIsDebug(true) |> ignore;
};

let closeContractCheck = () => {
StateEditorService.setStateIsDebug(false);
StateEngineService.setIsDebug(false) |> ignore;
StateInspectorEngineService.setIsDebug(false) |> ignore;
};

let setLanguageTypeToEn = () =>
LanguageEditorService.setType(LanguageType.EN)
|> StateLogicService.getAndSetEditorState;
|> StateLogicService.getAndSetEditorState;

let ignoreError = sandbox => {
closeContractCheck();
Sinon.createMethodStub(sandbox^, ConsoleTool.console, "error");
Sinon.createMethodStub(sandbox^, ConsoleTool.console, "log");
};

0 comments on commit 90e4a49

Please sign in to comment.