Skip to content
Permalink
Browse files

feat(script): handle dispose script component

add "dispose" event function;
pass run test;
  • Loading branch information...
yyc-git committed Mar 26, 2019
1 parent 7d6e9a1 commit 2c5364902f1b325d4b73d9b6ac79b53e12c8f617
@@ -1,5 +1,5 @@
{
"is_debug": false,
"is_debug": true,
"context": {
"alpha": true,
"depth": true,
@@ -81,12 +81,35 @@
transform, state
);
var state =
api.setTransformLocalPosition(
transform, [x >= 20 ? -20 : x + 1, y, z], state
);
return state
if (x >= 20) {
var state = api.disposeGameObject(gameObject, state);
return state;
}
else {
var state =
api.setTransformLocalPosition(
transform, [x >= 20 ? -20 : x + 1, y, z], state
);
return state;
}
// var state =
// api.setTransformLocalPosition(
// transform, [x >= 20 ? -20 : x + 1, y, z], state
// );
// return state
};
function _dispose1(script, api, state) {
console.log("script: ", script);
return state;
};
function _addScript(box, state) {
@@ -102,6 +125,9 @@
},
"update": (script, api, state) => {
return _update1(script, api, state);
},
"dispose": (script, api, state) => {
return _dispose1(script, api, state);
}
}
);
@@ -372,6 +372,8 @@ let disposeGameObjectBasicCameraViewComponent = GameObjectAPI.disposeGameObjectB

let addGameObjectBasicCameraViewComponent = GameObjectAPI.addGameObjectBasicCameraViewComponent;

let disposeGameObjectScriptComponent = GameObjectAPI.disposeGameObjectScriptComponent;

let addGameObjectScriptComponent = GameObjectAPI.addGameObjectScriptComponent;

let createGameObject = GameObjectAPI.createGameObject;
@@ -1092,6 +1094,8 @@ let disposeGameObjectBasicCameraViewComponent = GameObjectAPI.disposeGameObjectB

let addGameObjectBasicCameraViewComponent = GameObjectAPI.addGameObjectBasicCameraViewComponent;

let disposeGameObjectScriptComponent = GameObjectAPI.disposeGameObjectScriptComponent;

let addGameObjectScriptComponent = GameObjectAPI.addGameObjectScriptComponent;

let createGameObject = GameObjectAPI.createGameObject;
@@ -58,23 +58,23 @@ let addGameObjectScriptComponent =
addScriptComponent(gameObject, component, state);
};

/* TODO
let disposeGameObjectScriptComponent =
(
gameObject: GameObjectPrimitiveType.gameObject,
component: component,
state: StateDataMainType.state,
) => {
WonderLog.Contract.requireCheck(
() =>
WonderLog.(
Contract.(Operators.(_checkGameObjectShouldAlive(gameObject, state)))
),
IsDebugMainService.getIsDebug(StateDataMain.stateData),
);
deferDisposeScriptComponent(. gameObject, component, state);
};
let disposeGameObjectScriptComponent =
(
gameObject: GameObjectPrimitiveType.gameObject,
component: component,
state: StateDataMainType.state,
) => {
WonderLog.Contract.requireCheck(
() =>
WonderLog.(
Contract.(Operators.(_checkGameObjectShouldAlive(gameObject, state)))
),
IsDebugMainService.getIsDebug(StateDataMain.stateData),
);
deferDisposeScriptComponent(. gameObject, component, state);
};

/* TODO
let unsafeGetGameObjectScriptComponent =
(
gameObject: GameObjectPrimitiveType.gameObject,
@@ -10,4 +10,5 @@ let createScriptEventFunctionData =
(jsObj: eventFunctionDataJsObj): eventFunctionData => {
init: _createScriptEventFunction(jsObj##init),
update: _createScriptEventFunction(jsObj##update),
dispose: _createScriptEventFunction(jsObj##dispose),
};
@@ -22,6 +22,8 @@ let _disposeComponents =
disposedDirectionLightArray,
disposedPointLightArray,
disposedMeshRendererComponentArray,
/* TODO test */
disposedScriptArray,
} = gameObjectRecord;
let state =
disposedBasicCameraViewArray
@@ -91,6 +93,13 @@ let _disposeComponents =
|> DisposeComponentGameObjectMainService.batchDisposeMeshRendererComponent(
state,
);

let state =
disposedScriptArray
|> DisposeComponentGameObjectMainService.batchDisposeScriptComponent(
state,
);

(
state,
geometryNeedDisposeVboBufferArr,
@@ -86,6 +86,7 @@ type gameObjectRecord = {
mutable disposedDirectionLightArray: array(int),
mutable disposedPointLightArray: array(int),
mutable disposedMeshRendererComponentArray: array(int),
mutable disposedScriptArray: array(int),
mutable aliveUidArray: gameObjectAliveUidArray,
mutable geometryMap: gameObjectGeometryMap,
mutable transformMap: gameObjectTransformMap,
@@ -14,6 +14,7 @@ let create = () => {
WonderCommonlib.ArrayService.createEmpty(),
disposedUidArrayForDisposeGeometryRemoveMaterial:
WonderCommonlib.ArrayService.createEmpty(),
disposedScriptArray: WonderCommonlib.ArrayService.createEmpty(),
disposedBasicCameraViewArray: WonderCommonlib.ArrayService.createEmpty(),
disposedTransformArray: WonderCommonlib.ArrayService.createEmpty(),
disposedTransformArrayForKeepOrder:
@@ -3,7 +3,8 @@ let create = () => {
"unsafeGetScriptAttributeFieldValue": OperateScriptAttributeDataMainService.unsafeGetScriptAttributeFieldValue,
"setScriptAttributeFieldValue": OperateScriptDataMainService.setScriptAttributeFieldValue,
"unsafeGetScriptGameObject": ScriptAPI.unsafeGetScriptGameObject,
"unsafeGetGameObjectTransformComponent": GameObjectAPI.unsafeGetGameObjectTransformComponent,
"getTransformLocalPosition": TransformAPI.getTransformLocalPosition,
"setTransformLocalPosition": TransformAPI.setTransformLocalPosition,
"unsafeGetGameObjectTransformComponent": GameObjectAPI.unsafeGetGameObjectTransformComponent,
"disposeGameObject": GameObjectAPI.disposeGameObject,
};
@@ -196,20 +196,8 @@ and scriptAPIJsObj = {
(string, ScriptAttributeType.scriptAttribute) =>
ScriptAttributeType.scriptAttributeValue,
"unsafeGetScriptGameObject": (int, state) => int,
"unsafeGetGameObjectTransformComponent":
(
GameObjectPrimitiveType.gameObject,
state
) =>
int,
"setScriptAttributeFieldValue":
(
int,
string,
string,
ScriptAttributeType.scriptAttributeValue,
state
) =>
(int, string, string, ScriptAttributeType.scriptAttributeValue, state) =>
state,
"getTransformLocalPosition":
(transform, state) =>
@@ -229,6 +217,9 @@ and scriptAPIJsObj = {
state
) =>
state,
"unsafeGetGameObjectTransformComponent":
(GameObjectPrimitiveType.gameObject, state) => int,
"disposeGameObject": (GameObjectPrimitiveType.gameObject, state) => state,
}
and apiRecord = {
scriptAPIJsObj,
@@ -353,10 +344,12 @@ and eventFunctionDataJsObj = {
.
"init": Js.Nullable.t(eventFunction),
"update": Js.Nullable.t(eventFunction),
"dispose": Js.Nullable.t(eventFunction),
}
and eventFunctionData = {
init: eventFunction,
update: eventFunction,
dispose: eventFunction,
}
and scriptRecord = {
index: int,
@@ -6,6 +6,9 @@ open ComponentMapService;

open BasicCameraViewType;

let batchGetScriptComponent = (uidArray: array(int), {gameObjectRecord}) =>
batchGetComponent(uidArray, gameObjectRecord.scriptMap);

let batchGetBasicCameraViewComponent =
(uidArray: array(int), {gameObjectRecord}) =>
batchGetComponent(uidArray, gameObjectRecord.basicCameraViewMap);
@@ -5,6 +5,18 @@ open ComponentType;
let _removeComponent = (uid: int, componentMap) =>
componentMap |> ComponentMapService.removeComponent(uid) |> Obj.magic;

let deferDisposeScriptComponent =
(. uid, component: component, {gameObjectRecord} as state) => {
...state,
gameObjectRecord: {
...gameObjectRecord,
scriptMap: _removeComponent(uid, gameObjectRecord.scriptMap),
disposedScriptArray:
state.gameObjectRecord.disposedScriptArray
|> ArrayService.push(component),
},
};

let deferDisposeBasicCameraViewComponent =
(. uid, component: component, {gameObjectRecord} as state) => {
...state,
@@ -173,6 +185,16 @@ let deferDisposeMeshRendererComponent =
},
};

let batchDisposeScriptComponent = (state, componentArray: array(component)) =>
/* ...state,
scriptRecord:
ComponentMapService.batchDisposeComponent(
scriptRecord,
DisposeScriptMainService.handleBatchDisposeComponent,
componentArray,
), */
DisposeScriptMainService.handleBatchDisposeComponent(componentArray, state);

let batchDisposeBasicCameraViewComponent =
({basicCameraViewRecord} as state, componentArray: array(component)) => {
...state,
@@ -112,6 +112,15 @@ let batchDispose =
state,
);

let state =
state
|> BatchGetComponentGameObjectMainService.batchGetScriptComponent(
uidArray,
)
|> DisposeComponentGameObjectMainService.batchDisposeScriptComponent(
state,
);

let state =
state
|> BatchGetComponentGameObjectMainService.batchGetBasicCameraViewComponent(
@@ -120,6 +129,7 @@ let batchDispose =
|> DisposeComponentGameObjectMainService.batchDisposeBasicCameraViewComponent(
state,
);

let state =
state
|> BatchGetComponentGameObjectMainService.batchGetPerspectiveCameraProjectionComponent(
@@ -180,6 +190,7 @@ let batchDispose =
|> DisposeComponentGameObjectMainService.batchDisposeObjectInstanceComponent(
state,
);

(
state,
geometryNeedDisposeVboBufferArr,
@@ -0,0 +1,70 @@
open StateDataMainType;

let isAlive = (script, {disposedIndexArray}: scriptRecord) =>
DisposeComponentService.isAlive(script, disposedIndexArray);

let _disposeData = (script, {scriptRecord} as state) => {
let {gameObjectMap, scriptEventFunctionDataMap, scriptAttributeMap} = scriptRecord;

{
...state,
scriptRecord: {
...scriptRecord,
gameObjectMap:
DisposeComponentService.disposeSparseMapData(script, gameObjectMap),
scriptEventFunctionDataMap:
scriptEventFunctionDataMap
|> WonderCommonlib.ImmutableSparseMapService.deleteVal(script),
scriptAttributeMap:
scriptAttributeMap
|> WonderCommonlib.ImmutableSparseMapService.deleteVal(script),
},
};
};

let _batchExecDisposeEventFunction = (scriptArray, {scriptRecord} as state) =>
state
|> OperateScriptEventFunctionDataMainService.execAllEventFunction(
OperateScriptEventFunctionDataMainService.getScriptAllDisposeEventFunctionData(
scriptArray,
state,
),
);

/* TODO test */
let handleBatchDisposeComponent =
(scriptArray: array(ComponentType.component), {scriptRecord} as state) => {
WonderLog.Contract.requireCheck(
() =>
WonderLog.(
Contract.(
Operators.(
DisposeComponentService.checkComponentShouldAliveWithBatchDispose(
scriptArray,
isAlive,
scriptRecord,
)
)
)
),
IsDebugMainService.getIsDebug(StateDataMain.stateData),
);

let {scriptRecord} as state =
_batchExecDisposeEventFunction(scriptArray, state);

let {disposedIndexArray} = scriptRecord;

scriptArray
|> WonderCommonlib.ArrayService.reduceOneParam(
(. state, script) => state |> _disposeData(script),
{
...state,
scriptRecord: {
...scriptRecord,
disposedIndexArray:
disposedIndexArray |> Js.Array.concat(scriptArray),
},
},
);
};

0 comments on commit 2c53649

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