Skip to content

Commit

Permalink
perf(inspectorCanvas): optimize render inspector canvas: cache texture
Browse files Browse the repository at this point in the history
CloneMaterialEngineLogicService->cloneLightMaterialToOtherEngineState: get diffuse map from cache or clone it and add to cache;
InspectorEngineGameObjectLogicService->disposeInspectorEngineContainerGameObjectAllChildren: disposeGameObject but remove texture;
update wonder.js, wonder-webgl version;
  • Loading branch information
yyc-git committed May 27, 2019
1 parent 5c166e9 commit 51a9e19
Show file tree
Hide file tree
Showing 19 changed files with 303 additions and 116 deletions.
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -74,11 +74,11 @@
"wonder-commonlib": "^0.2.32",
"wonder-hotkey": "^0.0.1",
"wonder-log": "^0.2.11",
"wonder.js": "1.1.0-alpha.8"
"wonder.js": "1.1.0-alpha.9"
},
"resolutions": {
"wonder-log": "^0.2.11",
"wonder-webgl": "^0.0.10",
"wonder-webgl": "^0.0.11",
"wonder-bs-sinon": "0.1.9",
"component-classes": "1.2.5",
"wonder-commonlib": "0.2.32",
Expand Down
Expand Up @@ -27,14 +27,18 @@ let _createAllMaterialSnapshot =
engineState,
(editorState, inspectorEngineState),
) => {
let inspectorEngineState =
let (editorState, inspectorEngineState) =
(editorState, inspectorEngineState)
|> AssetTreeInspectorUtils.disposeContainerGameObjectAllChildrenAndReallocateCPUMemory
|> MaterialInspectorEngineUtils.createMaterialSphereIntoInspectorCanvas(
MaterialDataAssetType.LightMaterial,
material,
(editorState, engineState),
)
editorState,
engineState,
);

let inspectorEngineState =
inspectorEngineState
|> StateLogicService.renderInspectorEngineStateAndReturnState;

let editorState =
Expand Down
Expand Up @@ -655,14 +655,18 @@ module AssetTree = {
~engineState,
);

let inspectorEngineState =
let (editorState, inspectorEngineState) =
(editorState, inspectorEngineState)
|> AssetTreeInspectorUtils.disposeContainerGameObjectAllChildrenAndReallocateCPUMemory
|> MaterialInspectorEngineUtils.createMaterialSphereIntoInspectorCanvas(
MaterialDataAssetType.LightMaterial,
material,
(editorState, engineState),
)
editorState,
engineState,
);

let inspectorEngineState =
inspectorEngineState
|> StateLogicService.renderInspectorEngineStateAndReturnState;

let editorState =
Expand Down
Expand Up @@ -10,17 +10,19 @@ module Method = {
AssetTreeInspectorUtils.showInspectorCanvas();

Console.tryCatch(
() =>
StateInspectorEngineService.unsafeGetState()
|> MaterialInspectorEngineUtils.createMaterialSphereIntoInspectorCanvas(
type_,
materialComponent,
(
StateEditorService.getState(),
StateEngineService.unsafeGetState(),
),
)
|> StateLogicService.refreshInspectorEngineState,
() => {
let (editorState, inspectorEngineState) =
MaterialInspectorEngineUtils.createMaterialSphereIntoInspectorCanvas(
type_,
materialComponent,
StateEditorService.getState(),
StateEngineService.unsafeGetState(),
StateInspectorEngineService.unsafeGetState(),
);

editorState |> StateEditorService.setState |> ignore;
inspectorEngineState |> StateLogicService.refreshInspectorEngineState;
},
e => Console.throwFatal(e) |> ignore,
);
};
Expand Down
Expand Up @@ -37,31 +37,31 @@ let _createLightMaterialSphereIntoInspectorCanvas =
(
materialComponent,
containerGameObject,
editorState,
engineState,
inspectorEngineState,
) => {
let (lightMaterial, inspectorEngineState) =
let (lightMaterial, editorState, inspectorEngineState) =
CloneMaterialEngineLogicService.cloneLightMaterialToOtherEngineState(
materialComponent,
editorState,
engineState,
inspectorEngineState,
);

inspectorEngineState
|> _createSphereWithClonedMaterial(
lightMaterial,
GameObjectComponentEngineService.addLightMaterialComponent,
containerGameObject,
);
(
editorState,
inspectorEngineState
|> _createSphereWithClonedMaterial(
lightMaterial,
GameObjectComponentEngineService.addLightMaterialComponent,
containerGameObject,
),
);
};

let createMaterialSphereIntoInspectorCanvas =
(
type_,
materialComponent,
(editorState, engineState),
inspectorEngineState,
) => {
(type_, materialComponent, editorState, engineState, inspectorEngineState) => {
WonderLog.Contract.requireCheck(
() =>
WonderLog.(
Expand Down Expand Up @@ -96,18 +96,21 @@ let createMaterialSphereIntoInspectorCanvas =
|> ContainerGameObjectInspectorCanvasEditorService.unsafeGetContainerGameObject;

switch (type_) {
| BasicMaterial =>
_createBasicMaterialSphereIntoInspectorCanvas(
materialComponent,
containerGameObject,
engineState,
inspectorEngineState,
| BasicMaterial => (
editorState,
_createBasicMaterialSphereIntoInspectorCanvas(
materialComponent,
containerGameObject,
engineState,
inspectorEngineState,
),
)

| LightMaterial =>
_createLightMaterialSphereIntoInspectorCanvas(
materialComponent,
containerGameObject,
editorState,
engineState,
inspectorEngineState,
)
Expand Down
Expand Up @@ -18,15 +18,17 @@ module Method = {

Console.tryCatch(
() => {
StateInspectorEngineService.unsafeGetState()
|> WDBInspectorEngineUtils.createWDBIntoInspectorCanvas(
wdbGameObject,
(
let (editorState, inspectorEngineState) =
StateInspectorEngineService.unsafeGetState()
|> WDBInspectorEngineUtils.createWDBIntoInspectorCanvas(
wdbGameObject,
StateEditorService.getState(),
StateEngineService.unsafeGetState(),
),
)
|> StateLogicService.refreshInspectorEngineState;
);

editorState |> StateEditorService.setState |> ignore;

inspectorEngineState |> StateLogicService.refreshInspectorEngineState;

_updateSnapshot(currentNodeId, dispatchFunc);
},
Expand Down
@@ -1,8 +1,9 @@
let rec _iterateCreateNewWDBGameObject =
(gameObject, engineState, inspectorEngineState) => {
let (newGameObject, inspectorEngineState) =
(gameObject, editorState, engineState, inspectorEngineState) => {
let (newGameObject, editorState, inspectorEngineState) =
CloneGameObjectLogicService.cloneGameObjectToOtherEngineState(
gameObject,
editorState,
engineState,
inspectorEngineState,
);
Expand All @@ -15,10 +16,14 @@ let rec _iterateCreateNewWDBGameObject =
engineState
|> HierarchyGameObjectEngineService.getChildren(gameObject)
|> Js.Array.reduce(
((newGameObject, inspectorEngineState), gameObjectChild) => {
let (newGameObjectChild, inspectorEngineState) =
(
(newGameObject, editorState, inspectorEngineState),
gameObjectChild,
) => {
let (newGameObjectChild, editorState, inspectorEngineState) =
_iterateCreateNewWDBGameObject(
gameObjectChild,
editorState,
engineState,
inspectorEngineState,
);
Expand All @@ -30,11 +35,11 @@ let rec _iterateCreateNewWDBGameObject =
newGameObjectChild,
);

(newGameObject, inspectorEngineState);
(newGameObject, editorState, inspectorEngineState);
},
(newGameObject, inspectorEngineState),
(newGameObject, editorState, inspectorEngineState),
) :
(newGameObject, inspectorEngineState);
(newGameObject, editorState, inspectorEngineState);
};

let _setCameraFocusWDBGameObject = (newWDBGameObject, inspectorEngineState) => {
Expand All @@ -46,14 +51,15 @@ let _setCameraFocusWDBGameObject = (newWDBGameObject, inspectorEngineState) => {
};

let createWDBIntoInspectorCanvas =
(wdbGameObject, (editorState, engineState), inspectorEngineState) => {
(wdbGameObject, editorState, engineState, inspectorEngineState) => {
let containerGameObject =
editorState
|> ContainerGameObjectInspectorCanvasEditorService.unsafeGetContainerGameObject;

let (newWDBGameObject, inspectorEngineState) =
let (newWDBGameObject, editorState, inspectorEngineState) =
_iterateCreateNewWDBGameObject(
wdbGameObject,
editorState,
engineState,
inspectorEngineState,
);
Expand All @@ -64,5 +70,8 @@ let createWDBIntoInspectorCanvas =
newWDBGameObject,
);

inspectorEngineState |> _setCameraFocusWDBGameObject(newWDBGameObject);
(
editorState,
inspectorEngineState |> _setCameraFocusWDBGameObject(newWDBGameObject),
);
};
8 changes: 7 additions & 1 deletion src/service/record/editor/data/InspectorCanvasType.re
@@ -1 +1,7 @@
type inspectorCanvasRecord = {containerGameObject: option(int)};
type clonedBasicSourceTextureInInspectorEngineState = Wonderjs.BasicSourceTextureType.basicSourceTexture;

type inspectorCanvasRecord = {
containerGameObject: option(int),
basicSourceTextureCacheMap:
WonderCommonlib.ImmutableSparseMapService.t(clonedBasicSourceTextureInInspectorEngineState),
};
2 changes: 2 additions & 0 deletions src/service/state/editor/CreateEditorStateEditorService.re
Expand Up @@ -3,6 +3,8 @@ open EditorType;
let create = () => {
inspectorCanvasRecord: {
containerGameObject: None,
basicSourceTextureCacheMap:
WonderCommonlib.ImmutableSparseMapService.createEmpty(),
},
imgCanvasRecord: {
imgContext: None,
Expand Down
1 change: 1 addition & 0 deletions src/service/state/engine/SourceTextureEngineService.re
@@ -0,0 +1 @@
let isBasicSourceTextureIndex = Wonderjs.IndexSourceTextureMainService.isBasicSourceTextureIndex;
24 changes: 15 additions & 9 deletions src/service/state/engine/gameObject/GameObjectEngineService.re
Expand Up @@ -8,6 +8,8 @@ let isGameObjectAlive = GameObjectAPI.isGameObjectAlive;

let disposeGameObject = GameObjectAPI.disposeGameObject;

let disposeGameObjectRemoveTexture = GameObjectAPI.disposeGameObjectRemoveTexture;

let cloneGameObject =
(gameObject, count, isShareMaterial, engineState)
: (array(array('a)), Wonderjs.StateDataMainType.state) => {
Expand Down Expand Up @@ -179,7 +181,7 @@ let getGameObjectActiveBasicCameraView = (gameObject, engineState) => {
_getGameObjectActiveBasicCameraViews(gameObject, engineState);

activeBasicCameraViews |> Js.Array.length === 0 ?
None : Array.unsafe_get(activeBasicCameraViews, 0) |. Some;
None : Array.unsafe_get(activeBasicCameraViews, 0)->Some;
};

let setAllGameObjectsIsRenderIfHasMeshRenderer =
Expand All @@ -193,14 +195,18 @@ let setAllGameObjectsIsRenderIfHasMeshRenderer =
|> GameObjectComponentEngineService.hasMeshRendererComponent(
gameObject,
) ?
engineState
|> GameObjectComponentEngineService.unsafeGetMeshRendererComponent(
gameObject,
)
|. MeshRendererEngineService.setMeshRendererIsRender(
isRender,
engineState,
) :
(
engineState
|> GameObjectComponentEngineService.unsafeGetMeshRendererComponent(
gameObject,
)
)
->(
MeshRendererEngineService.setMeshRendererIsRender(
isRender,
engineState,
)
) :
engineState;

_iterateGameObjectArr(
Expand Down
10 changes: 7 additions & 3 deletions src/service/stateTuple/logic/asset/WDBAssetLogicService.re
Expand Up @@ -54,13 +54,17 @@ let createWDBNodeUseImageDataMapSnapshot =

let createWDBNodeUseCreatedSnapshot =
((wdbNodeId, name, gameObject, parentFolderNode), editorState) => {
let inspectorEngineState =
let (editorState, inspectorEngineState) =
(editorState, StateInspectorEngineService.unsafeGetState())
|> AssetTreeInspectorUtils.disposeContainerGameObjectAllChildrenAndReallocateCPUMemory
|> WDBInspectorEngineUtils.createWDBIntoInspectorCanvas(
gameObject,
(editorState, StateEngineService.unsafeGetState()),
)
editorState,
StateEngineService.unsafeGetState(),
);

let inspectorEngineState =
inspectorEngineState
|> StateLogicService.renderInspectorEngineStateAndReturnState;

let editorState =
Expand Down

0 comments on commit 51a9e19

Please sign in to comment.