Skip to content
Permalink
Browse files

fix(inspectorCanvas): fix texture cache: if change texture asset,clea…

…r its cache

clear cache:
	change texture->wrap/filter, remove texture, import package, init script api
  • Loading branch information...
yyc-git committed May 27, 2019
1 parent c711c20 commit c93df9f25da4022fd3a7f6e4fb405a27f74053c6
Showing with 415 additions and 184 deletions.
  1. +6 −0 ...ctor/atom_component/texture_Inspector/eventHandler/InspectorChangeTextureMagFilterEventHandler.re
  2. +6 −0 ...ctor/atom_component/texture_Inspector/eventHandler/InspectorChangeTextureMinFilterEventHandler.re
  3. +6 −0 ...nspector/atom_component/texture_Inspector/eventHandler/InspectorChangeTextureWrapSEventHandler.re
  4. +6 −0 ...nspector/atom_component/texture_Inspector/eventHandler/InspectorChangeTextureWrapTEventHandler.re
  5. +8 −0 src/core/job/init/InitScriptAPIJob.re
  6. +10 −0 src/service/state/editor/inspectorCanvas/SourceTextureCacheInspectorCanvasEditorService.re
  7. +26 −9 src/service/stateTuple/logic/asset/DisposeTreeAssetLogicService.re
  8. +9 −47 src/service/stateTuple/logic/engine/CloneMaterialEngineLogicService.re
  9. +50 −1 src/service/stateTuple/logic/engine/CloneTextureEngineLogicService.re
  10. +1 −30 test/integration/header/import_package/headerImportPackageDisposeAssets_test.re
  11. +1 −1 ...ssetTree_inspector/atom_component/material_inspector/__snapshots__/materialInspector_test.js.snap
  12. +2 −64 ...t/assetTree_inspector/atom_component/material_inspector/materialInspector_inspectorCanvas_test.re
  13. +1 −31 ...posable_component/assetTree_inspector/atom_component/material_inspector/materialInspector_test.re
  14. +259 −0 ...egration/inspector/composable_component/assetTree_inspector/inspectorCanvas_cloneMaterial_test.re
  15. +24 −1 test/integration/inspector/composable_component/assetTree_inspector/tool/InspectorCanvasTool.re
@@ -8,6 +8,12 @@ module CustomEventHandler = {
((uiState, dispatchFunc), (), (textureComponent, value)) => {
TextureFilterUtils.changeMagFilter(textureComponent, value);

SourceTextureCacheInspectorCanvasLogicService.removeCache(
textureComponent,
StateEngineService.unsafeGetState(),
)
|> StateLogicService.getAndSetEditorState;

();
};

@@ -8,6 +8,12 @@ module CustomEventHandler = {
((uiState, dispatchFunc), (), (textureComponent, value)) => {
TextureFilterUtils.changeMinFilter(textureComponent, value);

SourceTextureCacheInspectorCanvasLogicService.removeCache(
textureComponent,
StateEngineService.unsafeGetState(),
)
|> StateLogicService.getAndSetEditorState;

();
};

@@ -8,6 +8,12 @@ module CustomEventHandler = {
((uiState, dispatchFunc), (), (textureComponent, value)) => {
TextureWrapUtils.changeWrapS(textureComponent, value);

SourceTextureCacheInspectorCanvasLogicService.removeCache(
textureComponent,
StateEngineService.unsafeGetState(),
)
|> StateLogicService.getAndSetEditorState;

();
};

@@ -8,6 +8,12 @@ module CustomEventHandler = {
((uiState, dispatchFunc), (), (textureComponent, value)) => {
TextureWrapUtils.changeWrapT(textureComponent, value);

SourceTextureCacheInspectorCanvasLogicService.removeCache(
textureComponent,
StateEngineService.unsafeGetState(),
)
|> StateLogicService.getAndSetEditorState;

();
};

@@ -30,6 +30,10 @@ module DisposeGameObject = {
| None => editorState
};

/* TODO optimize: only clear material->maps cache */
let editorState =
editorState |> SourceTextureCacheInspectorCanvasEditorService.clearCache;

editorState;
};

@@ -518,6 +522,10 @@ module AssetBundle = {

let editorState = editorState |> PickingEditorService.clearSphereShape;

let editorState =
editorState
|> SourceTextureCacheInspectorCanvasEditorService.clearCache;

let engineState =
engineState
|> GameObjectEngineService.setGameObjectIsRoot(
@@ -0,0 +1,10 @@
open EditorType;

let clearCache = editorState => {
...editorState,
inspectorCanvasRecord: {
...editorState.inspectorCanvasRecord,
basicSourceTextureCacheMap:
WonderCommonlib.ImmutableSparseMapService.createEmpty(),
},
};
@@ -24,14 +24,26 @@ let _getClonedGameObjects = (wdbGameObjects, (editorState, engineState)) =>
|> WonderCommonlib.ArrayService.flatten
|> ArrayService.exclude(wdbGameObjects);

let _removeTextureImageDataFromImageDataMap =
({imageDataIndex}: textureNodeData, editorState) =>
TextureNodeAssetEditorService.doesAnyTextureUseImage(
imageDataIndex,
editorState,
) ?
editorState :
editorState |> ImageDataMapAssetEditorService.removeData(imageDataIndex);
let _disposeTextureNodeEditorDataBeforeRemoveNode =
(
{imageDataIndex, textureComponent}: textureNodeData,
engineState,
editorState,
) => {
let editorState =
TextureNodeAssetEditorService.doesAnyTextureUseImage(
imageDataIndex,
editorState,
) ?
editorState :
editorState |> ImageDataMapAssetEditorService.removeData(imageDataIndex);

editorState
|> SourceTextureCacheInspectorCanvasLogicService.removeCache(
textureComponent,
engineState,
);
};

let _disposeMaterialNodeEditorDataBeforeRemoveNode =
({imageDataIndex}: materialNodeData, editorState) =>
@@ -56,7 +68,11 @@ let _disposeNodeEditorDataBeforeRemoveNode = (node, engineState, editorState) =>
~node,
~textureNodeFunc=
(_, nodeData) =>
_removeTextureImageDataFromImageDataMap(nodeData, editorState),
_disposeTextureNodeEditorDataBeforeRemoveNode(
nodeData,
engineState,
editorState,
),
~materialNodeFunc=
(_, nodeData) =>
_disposeMaterialNodeEditorDataBeforeRemoveNode(nodeData, editorState),
@@ -236,6 +252,7 @@ let disposeTree = ((editorState, engineState)) => {

(
editorState
|> SourceTextureCacheInspectorCanvasEditorService.clearCache
|> TreeAssetEditorService.clearTree
|> ImageDataMapAssetEditorService.clearMap
|> SelectedFolderNodeIdInAssetTreeAssetEditorService.clearSelectedFolderNodeIdInAssetTree
@@ -53,54 +53,16 @@ let cloneLightMaterialToOtherEngineState =
);

let (editorState, targetEngineState) =
switch (
clonedEngineState
|> LightMaterialEngineService.getLightMaterialDiffuseMap(
clonedMaterialComponent,
)
) {
| None => (editorState, targetEngineState)
| Some(map) =>
let (targetTexture, editorState, targetEngineState) =
switch (
SourceTextureCacheInspectorCanvasLogicService.getCache(
map,
(editorState, clonedEngineState),
)
) {
| Some(targetTexture) => (
targetTexture,
editorState,
targetEngineState,
)
| None =>
let (targetTexture, targetEngineState) =
CloneTextureEngineLogicService.cloneTextureToOtherEngineState(
map,
clonedEngineState,
targetEngineState,
);

let editorState =
SourceTextureCacheInspectorCanvasLogicService.addCache(
map,
targetTexture,
targetEngineState,
editorState,
);

(targetTexture, editorState, targetEngineState);
};

CloneTextureEngineLogicService.cloneTextureAndAddToMaterial(
(clonedMaterialComponent, lightMaterial),
(
editorState,
targetEngineState
|> LightMaterialEngineService.setLightMaterialDiffuseMap(
targetTexture,
lightMaterial,
),
);
};
LightMaterialEngineService.getLightMaterialDiffuseMap,
LightMaterialEngineService.setLightMaterialDiffuseMap,
),
editorState,
clonedEngineState,
targetEngineState,
);

(lightMaterial, editorState, targetEngineState);
};
@@ -60,4 +60,53 @@ let cloneTextureToOtherEngineState =
);

(texture, targetEngineState);
};
};

let cloneTextureAndAddToMaterial =
(
(clonedMaterialComponent, targetMaterialComponent),
(getMaterialMapFunc, setMaterialMapFunc),
editorState,
clonedEngineState,
targetEngineState,
) =>
switch (clonedEngineState |> getMaterialMapFunc(clonedMaterialComponent)) {
| None => (editorState, targetEngineState)
| Some(map) =>
let (targetTexture, editorState, targetEngineState) =
switch (
SourceTextureCacheInspectorCanvasLogicService.getCache(
map,
(editorState, clonedEngineState),
)
) {
| Some(targetTexture) => (
targetTexture,
editorState,
targetEngineState,
)
| None =>
let (targetTexture, targetEngineState) =
cloneTextureToOtherEngineState(
map,
clonedEngineState,
targetEngineState,
);

let editorState =
SourceTextureCacheInspectorCanvasLogicService.addCache(
map,
targetTexture,
targetEngineState,
editorState,
);

(targetTexture, editorState, targetEngineState);
};

(
editorState,
targetEngineState
|> setMaterialMapFunc(targetTexture, targetMaterialComponent),
);
};
@@ -56,37 +56,8 @@ let _ =
),
(),
);
MainEditorSceneTool.initInspectorEngineState(
~sandbox,
~isInitJob=false,
~noWorkerJobRecord=
NoWorkerJobConfigToolEngine.buildNoWorkerJobConfig(
~initPipelines=
{|
[
{
"name": "default",
"jobs": [
{"name": "init_inspector_engine" }
]
}
]
|},
~initJobs=
{|
[
{"name": "init_inspector_engine" }
]
|},
(),
),
(),
);

StateInspectorEngineService.unsafeGetState()
|> MainUtils._handleInspectorEngineState
|> StateInspectorEngineService.setState
|> ignore;
InspectorCanvasTool.prepareInspectorEngineState(sandbox);

CanvasTool.prepareInspectorCanvasAndImgCanvas(sandbox) |> ignore;

@@ -31,7 +31,7 @@ exports[`material inspector test rename material if type is basicMaterial, renam
onBlur={[Function]}
onChange={[Function]}
type="text"
value="New Material"
value="NoName Material"
/>
</div>
</article>
@@ -20,77 +20,15 @@ let _ =

let _prepareState = () => {
MainEditorSceneTool.initState(~sandbox, ());
MainEditorSceneTool.initInspectorEngineState(
~sandbox,
~isInitJob=false,
~noWorkerJobRecord=
NoWorkerJobConfigToolEngine.buildNoWorkerJobConfig(
~initPipelines=
{|
[
{
"name": "default",
"jobs": [
{"name": "init_inspector_engine" }
]
}
]
|},
~initJobs=
{|
[
{"name": "init_inspector_engine" }
]
|},
~loopPipelines=
{|
[
{
"name": "default",
"jobs": [
{
"name": "dispose"
},
{
"name": "get_camera_data"
},
{
"name": "create_basic_render_object_buffer"
},
{
"name": "create_light_render_object_buffer"
},
{
"name": "clear_last_send_component"
},
{
"name": "send_uniform_shader_data"
},
{
"name": "render_basic"
},
{
"name": "front_render_light"
}
]
}
]
|},
(),
),
(),
);

InspectorCanvasTool.prepareInspectorEngineState(sandbox);
};

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

_prepareState();

StateInspectorEngineService.unsafeGetState()
|> MainUtils._handleInspectorEngineState
|> StateInspectorEngineService.setState
|> ignore;
});
afterEach(() => restoreSandbox(refJsObjToSandbox(sandbox^)));

0 comments on commit c93df9f

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