UNPKG

wonder.js

Version:
96 lines (88 loc) 6.53 kB
'use strict'; var Caml_array = require("bs-platform/lib/js/caml_array.js"); var Log$WonderLog = require("wonder-log/lib/js/src/Log.js"); var Contract$WonderLog = require("wonder-log/lib/js/src/Contract.js"); var StateDataMain$Wonderjs = require("../data/StateDataMain.js"); var IsDebugMainService$Wonderjs = require("../state/IsDebugMainService.js"); var ArrayService$WonderCommonlib = require("wonder-commonlib/lib/js/src/ArrayService.js"); var BufferSettingService$Wonderjs = require("../../../record/main/setting/BufferSettingService.js"); var ReduceStateMainService$Wonderjs = require("../array/ReduceStateMainService.js"); var DisposeComponentService$Wonderjs = require("../../../primitive/component/DisposeComponentService.js"); var GetComponentGameObjectService$Wonderjs = require("../../../record/main/gameObject/GetComponentGameObjectService.js"); var MutableSparseMapService$WonderCommonlib = require("wonder-commonlib/lib/js/src/MutableSparseMapService.js"); var GameObjectObjectInstanceService$Wonderjs = require("../../../record/main/instance/objectInstance/GameObjectObjectInstanceService.js"); var ObjectInstanceCollectionService$Wonderjs = require("../../../primitive/instance/ObjectInstanceCollectionService.js"); var RecordSourceInstanceMainService$Wonderjs = require("./RecordSourceInstanceMainService.js"); function isAlive(objectInstance, objectInstanceRecord) { return DisposeComponentService$Wonderjs.isAlive(objectInstance, objectInstanceRecord[/* disposedIndexArray */2]); } function _unsafeGetSourceInstance(objectInstance, param) { return Contract$WonderLog.ensureCheck((function (sourceInstance) { return Contract$WonderLog.test(Log$WonderLog.buildAssertMessage("souceInstance exist", "not"), (function (param) { return Contract$WonderLog.assertNullableExist(sourceInstance); })); }), IsDebugMainService$Wonderjs.getIsDebug(StateDataMain$Wonderjs.stateData), MutableSparseMapService$WonderCommonlib.unsafeGet(objectInstance, param[/* sourceInstanceMap */1])); } function _disposeData(objectInstance, state) { var objectInstanceRecord = state[/* objectInstanceRecord */7]; var newrecord = Caml_array.caml_array_dup(state); newrecord[/* objectInstanceRecord */7] = /* record */[ /* index */objectInstanceRecord[/* index */0], /* sourceInstanceMap */DisposeComponentService$Wonderjs.disposeSparseMapData(objectInstance, objectInstanceRecord[/* sourceInstanceMap */1]), /* disposedIndexArray */objectInstanceRecord[/* disposedIndexArray */2], /* gameObjectMap */DisposeComponentService$Wonderjs.disposeSparseMapData(objectInstance, objectInstanceRecord[/* gameObjectMap */3]) ]; return newrecord; } function _batchDisposeObjectInstance(sourceInstance, objectInstanceTransformArray, state) { var match = RecordSourceInstanceMainService$Wonderjs.getRecord(state); var objectInstanceCountPerSourceInstance = BufferSettingService$Wonderjs.getObjectInstanceCountPerSourceInstance(state[/* settingRecord */0]); ObjectInstanceCollectionService$Wonderjs.batchRemoveObjectInstanceTransform(sourceInstance, objectInstanceTransformArray, objectInstanceCountPerSourceInstance, /* tuple */[ match[/* objectInstanceTransformIndexMap */1], match[/* objectInstanceTransformCollections */4] ]); return state; } function handleBatchDisposeComponent(objectInstanceArray, state) { var objectInstanceRecord = state[/* objectInstanceRecord */7]; var gameObjectRecord = state[/* gameObjectRecord */10]; Contract$WonderLog.requireCheck((function (param) { var objectInstanceLen = objectInstanceArray.length; DisposeComponentService$Wonderjs.checkComponentShouldAliveWithBatchDispose(objectInstanceArray, isAlive, objectInstanceRecord); Contract$WonderLog.test(Log$WonderLog.buildAssertMessage("objectInstanceArray has one objectInstance at least", "" + (String(objectInstanceLen) + "")), (function (param) { return Contract$WonderLog.Operators[/* > */5](objectInstanceLen, 0); })); return Contract$WonderLog.test(Log$WonderLog.buildAssertMessage("all objectInstance belong to the same sourceInstance", "not"), (function (param) { var sourceInstance = _unsafeGetSourceInstance(objectInstanceArray[0], objectInstanceRecord); return ArrayService$WonderCommonlib.forEach((function (objectInstance) { return Contract$WonderLog.Operators[/* = */0](_unsafeGetSourceInstance(objectInstance, objectInstanceRecord), sourceInstance); }), objectInstanceArray); })); }), IsDebugMainService$Wonderjs.getIsDebug(StateDataMain$Wonderjs.stateData)); var objectInstanceRecord_000 = /* index */objectInstanceRecord[/* index */0]; var objectInstanceRecord_001 = /* sourceInstanceMap */objectInstanceRecord[/* sourceInstanceMap */1]; var objectInstanceRecord_002 = /* disposedIndexArray */objectInstanceRecord[/* disposedIndexArray */2].concat(objectInstanceArray); var objectInstanceRecord_003 = /* gameObjectMap */objectInstanceRecord[/* gameObjectMap */3]; var objectInstanceRecord$1 = /* record */[ objectInstanceRecord_000, objectInstanceRecord_001, objectInstanceRecord_002, objectInstanceRecord_003 ]; var objectInstanceTransformArray = objectInstanceArray.map((function (objectInstance) { return GetComponentGameObjectService$Wonderjs.unsafeGetTransformComponent(GameObjectObjectInstanceService$Wonderjs.unsafeGetGameObject(objectInstance, objectInstanceRecord$1), gameObjectRecord); })); var sourceInstance = _unsafeGetSourceInstance(objectInstanceArray[0], objectInstanceRecord$1); var newrecord = Caml_array.caml_array_dup(state); newrecord[/* objectInstanceRecord */7] = objectInstanceRecord$1; var state$1 = _batchDisposeObjectInstance(sourceInstance, objectInstanceTransformArray, newrecord); return ReduceStateMainService$Wonderjs.reduceState((function (state, objectInstance) { return _disposeData(objectInstance, state); }), state$1, objectInstanceArray); } exports.isAlive = isAlive; exports._unsafeGetSourceInstance = _unsafeGetSourceInstance; exports._disposeData = _disposeData; exports._batchDisposeObjectInstance = _batchDisposeObjectInstance; exports.handleBatchDisposeComponent = handleBatchDisposeComponent; /* Log-WonderLog Not a pure module */