Skip to content
Permalink
Browse files

feat(dispose): GameObjectAPI add disposeGameObjectLightMaterialCompon…

…entRemoveTexture; LightMaterialAPI add batchDisposeLightMaterialRemoveTexture;

publish npm
  • Loading branch information...
yyc-git committed May 27, 2019
1 parent 8b17b8a commit 8b2ea84306fce30baaeca98bee144eab05560d07
@@ -1,6 +1,6 @@
{
"name": "wonder.js",
"version": "1.1.0-alpha.9",
"version": "1.1.0-alpha.10",
"authors": "Wonder",
"description": "3d webgl engine",
"homepage": "https://github.com/Wonder-Technology/Wonder.js",
@@ -592,6 +592,26 @@ let disposeGameObjectLightMaterialComponent =
deferDisposeLightMaterialComponent(. gameObject, component, state);
};

let disposeGameObjectLightMaterialComponentRemoveTexture =
(
gameObject: GameObjectPrimitiveType.gameObject,
component: component,
state: StateDataMainType.state,
) => {
WonderLog.Contract.requireCheck(
() =>
WonderLog.(
Contract.(Operators.(_checkGameObjectShouldAlive(gameObject, state)))
),
IsDebugMainService.getIsDebug(StateDataMain.stateData),
);
deferDisposeLightMaterialComponentRemoveTexture(.
gameObject,
component,
state,
);
};

let unsafeGetGameObjectLightMaterialComponent =
(
gameObject: GameObjectPrimitiveType.gameObject,
@@ -375,5 +375,13 @@ let getAllLightMaterials = state => {
let batchDisposeLightMaterial = (materialArr, state) =>
DisposeComponentGameObjectMainService.batchDisposeLightMaterialComponent(
materialArr,
false,
state,
);

let batchDisposeLightMaterialRemoveTexture = (materialArr, state) =>
DisposeComponentGameObjectMainService.batchDisposeLightMaterialComponent(
materialArr,
true,
state,
);
@@ -16,6 +16,7 @@ let _disposeComponents =
disposedArcballCameraControllerArray,
disposedBasicMaterialDataMap,
disposedLightMaterialDataMap,
disposedLightMaterialRemoveTextureDataMap,
disposedGeometryDataMap,
disposedSourceInstanceArray,
disposedObjectInstanceArray,
@@ -51,18 +52,27 @@ let _disposeComponents =
state,
true,
);

let state =
batchDisposeBasicMaterialComponentFunc(
state,
disposedBasicMaterialDataMap,
false,
);

let state =
batchDisposeLightMaterialComponentFunc(
state,
disposedLightMaterialDataMap,
false,
);
let state =
batchDisposeLightMaterialComponentFunc(
state,
disposedLightMaterialRemoveTextureDataMap,
true,
);

let (state, geometryNeedDisposeVboBufferArr) =
disposedGeometryDataMap
|> DisposeComponentGameObjectMainService.batchDisposeGeometryComponentData(
@@ -82,6 +82,7 @@ type gameObjectRecord = {
mutable disposedArcballCameraControllerArray: array(int),
mutable disposedBasicMaterialDataMap: disposedComponentDataMap,
mutable disposedLightMaterialDataMap: disposedComponentDataMap,
mutable disposedLightMaterialRemoveTextureDataMap: disposedComponentDataMap,
mutable disposedGeometryDataMap: disposedComponentDataMap,
mutable disposedSourceInstanceArray: array(int),
mutable disposedObjectInstanceArray: array(int),
@@ -27,6 +27,8 @@ let create = () => {
WonderCommonlib.ArrayService.createEmpty(),
disposedBasicMaterialDataMap: WonderCommonlib.ArrayService.createEmpty(),
disposedLightMaterialDataMap: WonderCommonlib.ArrayService.createEmpty(),
disposedLightMaterialRemoveTextureDataMap:
WonderCommonlib.ArrayService.createEmpty(),
disposedGeometryDataMap: WonderCommonlib.ArrayService.createEmpty(),
disposedSourceInstanceArray: WonderCommonlib.ArrayService.createEmpty(),
disposedObjectInstanceArray: WonderCommonlib.ArrayService.createEmpty(),
@@ -74,6 +76,7 @@ let deepCopyForRestore =
disposedArcballCameraControllerArray,
disposedBasicMaterialDataMap,
disposedLightMaterialDataMap,
disposedLightMaterialRemoveTextureDataMap,
disposedGeometryDataMap,
disposedSourceInstanceArray,
disposedObjectInstanceArray,
@@ -119,7 +122,6 @@ let deepCopyForRestore =
disposedUidArrayForDisposeGeometryRemoveMaterial:
disposedUidArrayForDisposeGeometryRemoveMaterial
|> WonderCommonlib.MutableSparseMapService.copy,
/* TODO test */
disposedUidArrayForRemoveTexture:
disposedUidArrayForRemoveTexture
|> WonderCommonlib.MutableSparseMapService.copy,
@@ -143,6 +145,9 @@ let deepCopyForRestore =
disposedLightMaterialDataMap:
disposedLightMaterialDataMap
|> WonderCommonlib.MutableSparseMapService.copy,
disposedLightMaterialRemoveTextureDataMap:
disposedLightMaterialRemoveTextureDataMap
|> WonderCommonlib.MutableSparseMapService.copy,
disposedGeometryDataMap:
disposedGeometryDataMap |> WonderCommonlib.MutableSparseMapService.copy,
disposedSourceInstanceArray:
@@ -109,6 +109,19 @@ let deferDisposeLightMaterialComponent =
},
};

let deferDisposeLightMaterialComponentRemoveTexture =
(. uid, component: component, {gameObjectRecord} as state) => {
...state,
gameObjectRecord: {
...gameObjectRecord,
lightMaterialMap:
_removeComponent(uid, gameObjectRecord.lightMaterialMap),
disposedLightMaterialRemoveTextureDataMap:
gameObjectRecord.disposedLightMaterialRemoveTextureDataMap
|> ArrayMapService.addValue(component, uid),
},
};

let deferDisposeGeometryComponent =
(. uid, component: component, {gameObjectRecord} as state) => {
...state,
@@ -399,14 +412,18 @@ let batchDisposeLightMaterialComponentDataForWorker =
};

let batchDisposeLightMaterialComponent =
(componentArray, {settingRecord} as state) =>
(componentArray, isRemoveTexture, {settingRecord} as state) =>
_batchDisposeSharableComponent(
componentArray,
(
RecordLightMaterialMainService.getRecord,
GameObjectLightMaterialService.getGameObjects,
deferDisposeLightMaterialComponent,
DisposeLightMaterialMainService.handleBatchDisposeComponent,
isRemoveTexture ?
deferDisposeLightMaterialComponentRemoveTexture :
deferDisposeLightMaterialComponent,
DisposeLightMaterialMainService.handleBatchDisposeComponent(
isRemoveTexture,
),
),
state,
);
@@ -36,7 +36,13 @@ let rec batchDispose =
) =
state
|> DisposeGameObjectComponentMainService.batchDispose(
(uidArray, isKeepOrder, isRemoveGeometry, isRemoveMaterial, isRemoveTexture),
(
uidArray,
isKeepOrder,
isRemoveGeometry,
isRemoveMaterial,
isRemoveTexture,
),
(
batchDisposeBasicMaterialComponentFunc,
batchDisposeLightMaterialComponentFunc,
@@ -75,7 +81,6 @@ let clearDeferDisposeData = state => {
WonderCommonlib.ArrayService.createEmpty(),
disposedUidArrayForDisposeGeometryRemoveMaterial:
WonderCommonlib.ArrayService.createEmpty(),
/* TODO test */
disposedUidArrayForRemoveTexture:
WonderCommonlib.ArrayService.createEmpty(),
disposedBasicCameraViewArray: WonderCommonlib.ArrayService.createEmpty(),
@@ -88,6 +93,8 @@ let clearDeferDisposeData = state => {
WonderCommonlib.ArrayService.createEmpty(),
disposedBasicMaterialDataMap: WonderCommonlib.ArrayService.createEmpty(),
disposedLightMaterialDataMap: WonderCommonlib.ArrayService.createEmpty(),
disposedLightMaterialRemoveTextureDataMap:
WonderCommonlib.ArrayService.createEmpty(),
disposedGeometryDataMap: WonderCommonlib.ArrayService.createEmpty(),
disposedSourceInstanceArray: WonderCommonlib.ArrayService.createEmpty(),
disposedObjectInstanceArray: WonderCommonlib.ArrayService.createEmpty(),
@@ -168,7 +168,7 @@ let handleBatchDisposeComponentData =
};

let handleBatchDisposeComponent =
(materialHasNoGameObjectArray, {settingRecord} as state) => {
(isRemoveTexture, materialHasNoGameObjectArray, {settingRecord} as state) => {
WonderLog.Contract.requireCheck(
() => {
open WonderLog;
@@ -211,7 +211,8 @@ let handleBatchDisposeComponent =
|> WonderCommonlib.ArrayService.reduceOneParam(
(. state, material) => {
let state =
state |> _disposeData(false, material, textureCountPerMaterial);
state
|> _disposeData(isRemoveTexture, material, textureCountPerMaterial);

let lightMaterialRecord =
RecordLightMaterialMainService.getRecord(state);
@@ -601,7 +601,16 @@ isActiveMap,
disposedUidArrayForKeepOrderRemoveGeometry,
disposedUidArrayForKeepOrderRemoveGeometryRemoveMaterial,
disposedBasicCameraViewArray, disposedTransformArray, disposedTransformArrayForKeepOrder, disposedPerspectiveCameraProjectionArray, disposedBasicMaterialDataMap, disposedLightMaterialDataMap, disposedGeometryDataMap, disposedSourceInstanceArray, disposedObjectInstanceArray, disposedDirectionLightArray, disposedPointLightArray, disposedMeshRendererComponentArray,
disposedUidArrayForRemoveTexture,
disposedBasicCameraViewArray, disposedTransformArray, disposedTransformArrayForKeepOrder, disposedPerspectiveCameraProjectionArray, disposedBasicMaterialDataMap,
disposedLightMaterialDataMap,
disposedLightMaterialRemoveTextureDataMap
disposedGeometryDataMap, disposedSourceInstanceArray, disposedObjectInstanceArray, disposedDirectionLightArray, disposedPointLightArray, disposedMeshRendererComponentArray,
disposedScriptArray,
disposedMeshRendererUidArray, aliveUidArray, transformMap, basicCameraViewMap, geometryMap, meshRendererMap, basicMaterialMap, lightMaterialMap, directionLightMap, pointLightMap, sourceInstanceMap, objectInstanceMap, scriptMap|},
@@ -619,12 +628,14 @@ isActiveMap,
disposedUidArrayForKeepOrder,
disposedUidArrayForKeepOrderRemoveGeometry,
disposedUidArrayForKeepOrderRemoveGeometryRemoveMaterial,
disposedUidArrayForRemoveTexture,
disposedBasicCameraViewArray,
disposedTransformArray,
disposedTransformArrayForKeepOrder,
disposedPerspectiveCameraProjectionArray,
disposedBasicMaterialDataMap,
disposedLightMaterialDataMap,
disposedLightMaterialRemoveTextureDataMap,
disposedGeometryDataMap,
disposedSourceInstanceArray,
disposedObjectInstanceArray,
@@ -656,12 +667,14 @@ isActiveMap,
disposedUidArrayForKeepOrderRemoveGeometry |> Obj.magic,
disposedUidArrayForKeepOrderRemoveGeometryRemoveMaterial
|> Obj.magic,
disposedUidArrayForRemoveTexture |> Obj.magic,
disposedBasicCameraViewArray |> Obj.magic,
disposedTransformArray |> Obj.magic,
disposedTransformArrayForKeepOrder |> Obj.magic,
disposedPerspectiveCameraProjectionArray |> Obj.magic,
disposedBasicMaterialDataMap |> Obj.magic,
disposedLightMaterialDataMap |> Obj.magic,
disposedLightMaterialRemoveTextureDataMap |> Obj.magic,
disposedGeometryDataMap |> Obj.magic,
disposedSourceInstanceArray |> Obj.magic,
disposedObjectInstanceArray |> Obj.magic,
@@ -835,9 +835,9 @@ let _ =
});
});

describe("clear all defer disposed data", () =>
describe(
"not dispose the same one again in the second job execution", () => {
describe(
"clear all defer disposed data(not dispose the same one again in the second job execution)",
() => {
test("test dispose gameObject", () => {
open GameObjectType;
TestTool.closeContractCheck();
@@ -858,18 +858,20 @@ let _ =
disposedUidArrayForKeepOrderRemoveGeometry,
disposedUidArrayForKeepOrderRemoveGeometryRemoveMaterial,
disposedUidArrayForDisposeGeometryRemoveMaterial,
disposedUidArrayForRemoveTexture,
} =
GameObjectTool.getGameObjectRecord(state);
(
disposedUidArrayForKeepOrder,
disposedUidArrayForKeepOrderRemoveGeometry,
disposedUidArrayForKeepOrderRemoveGeometryRemoveMaterial,
disposedUidArrayForDisposeGeometryRemoveMaterial,
disposedUidArrayForRemoveTexture,
)
|> expect == ([||], [||], [||], [||]);
|> expect == ([||], [||], [||], [||], [||]);
});

describe("test dispose component", () =>
describe("test dispose component", () => {
test("test dispose script component", () => {
open GameObjectType;
let (state, gameObject1, script1) =
@@ -886,8 +888,39 @@ let _ =
let {disposedScriptArray} =
GameObjectTool.getGameObjectRecord(state);
disposedScriptArray |> expect == [||];
})
);
})
});
test("test dispose light component", () => {
open GameObjectType;
let (state, gameObject1, material1) =
LightMaterialTool.createGameObject(state^);
let (state, gameObject2, (material2, (texture2_1, texture2_2))) =
LightMaterialTool.createGameObjectWithMap(state);

let state =
state
|> GameObjectAPI.disposeGameObjectLightMaterialComponent(
gameObject1,
material1,
)
|> GameObjectAPI.disposeGameObjectLightMaterialComponentRemoveTexture(
gameObject2,
material2,
);

let state = state |> DisposeJob.execJob(None);

let {
disposedLightMaterialDataMap,
disposedLightMaterialRemoveTextureDataMap,
} =
GameObjectTool.getGameObjectRecord(state);
(
disposedLightMaterialDataMap,
disposedLightMaterialRemoveTextureDataMap,
)
|> expect == ([||], [||]);
});
});
},
);
});
@@ -172,4 +172,10 @@ let hasMaterial = (texture, material, state) =>
|> Js.Array.find(((materialInData, _)) => materialInData === material)
|> Js.Option.isSome
| _ => false
};
};

let isAlive = (texture, engineState) =>
DisposeBasicSourceTextureMainService.isAlive(
texture,
RecordBasicSourceTextureMainService.getRecord(engineState),
);

0 comments on commit 8b2ea84

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