wonder.js
Version:
243 lines (232 loc) • 17.1 kB
JavaScript
'use strict';
var Curry = require("bs-platform/lib/js/curry.js");
var Caml_option = require("bs-platform/lib/js/caml_option.js");
var Log$WonderLog = require("wonder-log/lib/js/src/Log.js");
var Contract$WonderLog = require("wonder-log/lib/js/src/Contract.js");
var MostUtils$Wonderjs = require("../../../../asset/utils/MostUtils.js");
var ViewService$Wonderjs = require("../../../../service/record/main/device/ViewService.js");
var ScreenService$Wonderjs = require("../../../../service/primitive/device/ScreenService.js");
var StateDataMain$Wonderjs = require("../../../../service/state/main/data/StateDataMain.js");
var WorkerService$Wonderjs = require("../../../../service/primitive/worker/WorkerService.js");
var JobConfigUtils$Wonderjs = require("../../utils/JobConfigUtils.js");
var AssetIMGUIAPI$WonderImgui = require("wonder-imgui/lib/js/src/api/AssetIMGUIAPI.js");
var IsDebugMainService$Wonderjs = require("../../../../service/state/main/state/IsDebugMainService.js");
var BufferSettingService$Wonderjs = require("../../../../service/record/main/setting/BufferSettingService.js");
var CopyTransformService$Wonderjs = require("../../../../service/record/main/transform/CopyTransformService.js");
var StateDataMainService$Wonderjs = require("../../../../service/state/main/state/StateDataMainService.js");
var OperateSettingService$Wonderjs = require("../../../../service/record/main/setting/OperateSettingService.js");
var WorkerInstanceService$Wonderjs = require("../../../../service/record/main/workerInstance/WorkerInstanceService.js");
var AssetIMGUIMainServiice$Wonderjs = require("../../../../service/state/main/imgui/AssetIMGUIMainServiice.js");
var ManageIMGUIMainService$Wonderjs = require("../../../../service/state/main/imgui/ManageIMGUIMainService.js");
var RecordIMGUIMainService$Wonderjs = require("../../../../service/state/main/imgui/RecordIMGUIMainService.js");
var WorkerDetectMainService$Wonderjs = require("../../../../service/state/main/workerDetect/WorkerDetectMainService.js");
var JudgeInstanceMainService$Wonderjs = require("../../../../service/state/main/instance/JudgeInstanceMainService.js");
var RecordGeometryMainService$Wonderjs = require("../../../../service/state/main/geometry/RecordGeometryMainService.js");
var GetDataRenderConfigService$Wonderjs = require("../../../../service/record/all/renderConfig/GetDataRenderConfigService.js");
var RecordTransformMainService$Wonderjs = require("../../../../service/state/main/transform/RecordTransformMainService.js");
var RecordPointLightMainService$Wonderjs = require("../../../../service/state/main/light/point/RecordPointLightMainService.js");
var InitSourceTextureMainService$Wonderjs = require("../../../../service/state/main/texture/source/InitSourceTextureMainService.js");
var InitCubemapTextureMainService$Wonderjs = require("../../../../service/state/main/texture/cubemap/InitCubemapTextureMainService.js");
var RecordMeshRendererMainService$Wonderjs = require("../../../../service/state/main/meshRenderer/RecordMeshRendererMainService.js");
var RecordRenderConfigMainService$Wonderjs = require("../../../../service/state/main/renderConfig/RecordRenderConfigMainService.js");
var RenderArrayPointLightServivce$Wonderjs = require("../../../../service/record/main/light/point/RenderArrayPointLightServivce.js");
var ExtendIMGUIRenderWorkerService$Wonderjs = require("../../../../service/state/render_worker/imgui/ExtendIMGUIRenderWorkerService.js");
var RecordBasicMaterialMainService$Wonderjs = require("../../../../service/state/main/material/basic/RecordBasicMaterialMainService.js");
var RecordLightMaterialMainService$Wonderjs = require("../../../../service/state/main/material/light/RecordLightMaterialMainService.js");
var RecordSourceTextureMainService$Wonderjs = require("../../../../service/state/main/texture/source/RecordSourceTextureMainService.js");
var OperateSourceTextureMainService$Wonderjs = require("../../../../service/state/main/texture/source/OperateSourceTextureMainService.js");
var RecordCubemapTextureMainService$Wonderjs = require("../../../../service/state/main/texture/cubemap/RecordCubemapTextureMainService.js");
var RecordDirectionLightMainService$Wonderjs = require("../../../../service/state/main/light/direction/RecordDirectionLightMainService.js");
var RecordSourceInstanceMainService$Wonderjs = require("../../../../service/state/main/instance/RecordSourceInstanceMainService.js");
var OperateCubemapTextureMainService$Wonderjs = require("../../../../service/state/main/texture/cubemap/OperateCubemapTextureMainService.js");
var RenderArrayDirectionLightServivce$Wonderjs = require("../../../../service/record/main/light/direction/RenderArrayDirectionLightServivce.js");
var RecordBasicSourceTextureMainService$Wonderjs = require("../../../../service/state/main/texture/source/basic_source/RecordBasicSourceTextureMainService.js");
var OperateBasicSourceTextureMainService$Wonderjs = require("../../../../service/state/main/texture/source/basic_source/OperateBasicSourceTextureMainService.js");
var RecordArrayBufferViewSourceTextureMainService$Wonderjs = require("../../../../service/state/main/texture/source/arrayBufferView_source/RecordArrayBufferViewSourceTextureMainService.js");
function _buildMaterialData(buffer, index, disposedIndexArray, isSourceInstanceMap) {
return {
buffer: buffer,
index: index,
disposedIndexArray: disposedIndexArray,
isSourceInstanceMap: isSourceInstanceMap
};
}
function _buildTextureData(state) {
Contract$WonderLog.requireCheck((function (param) {
var basicSourceTextureRecord = RecordBasicSourceTextureMainService$Wonderjs.getRecord(state);
var needInitedTextureIndexArray = basicSourceTextureRecord[/* needInitedTextureIndexArray */13];
Contract$WonderLog.test(Log$WonderLog.buildAssertMessage("basicSourceTextureRecord->needInitedTextureIndexArray should be empty", "is " + (String(needInitedTextureIndexArray) + "")), (function (param) {
return Contract$WonderLog.Operators[/* = */0](needInitedTextureIndexArray.length, 0);
}));
var arrayBufferViewSourceTextureRecord = RecordArrayBufferViewSourceTextureMainService$Wonderjs.getRecord(state);
var needInitedTextureIndexArray$1 = arrayBufferViewSourceTextureRecord[/* needInitedTextureIndexArray */15];
return Contract$WonderLog.test(Log$WonderLog.buildAssertMessage("arrayBufferViewSourceTextureRecord->needInitedTextureIndexArray should be empty", "is " + (String(needInitedTextureIndexArray$1) + "")), (function (param) {
return Contract$WonderLog.Operators[/* = */0](needInitedTextureIndexArray$1.length, 0);
}));
}), IsDebugMainService$Wonderjs.getIsDebug(StateDataMain$Wonderjs.stateData));
var sourceTextureRecord = RecordSourceTextureMainService$Wonderjs.getRecord(state);
var basicSourceTextureRecord = RecordBasicSourceTextureMainService$Wonderjs.getRecord(state);
var arrayBufferViewSourceTextureRecord = RecordArrayBufferViewSourceTextureMainService$Wonderjs.getRecord(state);
var cubemapTextureRecord = RecordCubemapTextureMainService$Wonderjs.getRecord(state);
return {
sourceTextureBuffer: sourceTextureRecord[/* buffer */0],
basicSourceTextureData: {
index: basicSourceTextureRecord[/* index */0],
needAddedImageDataArray: OperateBasicSourceTextureMainService$Wonderjs.convertNeedAddedSourceArrayToImageDataArr(basicSourceTextureRecord[/* needAddedSourceArray */12])
},
arrayBufferViewSourceTextureData: {
index: arrayBufferViewSourceTextureRecord[/* index */0],
sourceMap: arrayBufferViewSourceTextureRecord[/* sourceMap */11]
},
cubemapTextureData: {
buffer: cubemapTextureRecord[/* buffer */1],
index: cubemapTextureRecord[/* index */0],
needAddedPXImageDataArray: OperateCubemapTextureMainService$Wonderjs.convertNeedAddedSourceArrayToImageDataArr(cubemapTextureRecord[/* needAddedPXSourceArray */28]),
needAddedNXImageDataArray: OperateCubemapTextureMainService$Wonderjs.convertNeedAddedSourceArrayToImageDataArr(cubemapTextureRecord[/* needAddedNXSourceArray */29]),
needAddedPYImageDataArray: OperateCubemapTextureMainService$Wonderjs.convertNeedAddedSourceArrayToImageDataArr(cubemapTextureRecord[/* needAddedPYSourceArray */30]),
needAddedNYImageDataArray: OperateCubemapTextureMainService$Wonderjs.convertNeedAddedSourceArrayToImageDataArr(cubemapTextureRecord[/* needAddedNYSourceArray */31]),
needAddedPZImageDataArray: OperateCubemapTextureMainService$Wonderjs.convertNeedAddedSourceArrayToImageDataArr(cubemapTextureRecord[/* needAddedPZSourceArray */32]),
needAddedNZImageDataArray: OperateCubemapTextureMainService$Wonderjs.convertNeedAddedSourceArrayToImageDataArr(cubemapTextureRecord[/* needAddedNZSourceArray */33])
}
};
}
function _getFntData(imguiRecord) {
var match = AssetIMGUIAPI$WonderImgui.getFntData(imguiRecord);
if (match !== undefined) {
return JSON.stringify(match);
}
}
function _buildIMGUIData(state) {
var match = ManageIMGUIMainService$Wonderjs.getCanvasSize(state);
var wonderImguiIMGUIRecord = RecordIMGUIMainService$Wonderjs.getWonderIMGUIRecord(state);
return {
canvasWidth: match[0],
canvasHeight: match[1],
fntData: _getFntData(wonderImguiIMGUIRecord),
bitmapImageData: AssetIMGUIMainServiice$Wonderjs.convertBitmapToImageData(state),
customTextureSourceDataArr: AssetIMGUIMainServiice$Wonderjs.convertCustomTextureSourcesToImageDataArr(state),
extendData: {
customControlData: {
funcMap: Curry._1(ExtendIMGUIRenderWorkerService$Wonderjs.ExtendData[/* CustomControl */0][/* serializeFuncMap */0], state)
},
skinData: {
allSkinDataMap: Curry._1(ExtendIMGUIRenderWorkerService$Wonderjs.ExtendData[/* Skin */1][/* serializeAllSkinDataMap */0], state)
}
}
};
}
function _buildData(operateType, canvas, stateData) {
var state = StateDataMainService$Wonderjs.unsafeGetState(stateData);
var settingRecord = state[/* settingRecord */0];
var gameObjectRecord = state[/* gameObjectRecord */10];
var match = OperateSettingService$Wonderjs.unsafeGetGPU(settingRecord);
var match$1 = OperateSettingService$Wonderjs.unsafeGetMemory(settingRecord);
var buffer = BufferSettingService$Wonderjs.unsafeGetBuffer(settingRecord);
var renderConfigRecord = RecordRenderConfigMainService$Wonderjs.getRecord(state);
var transformRecord = RecordTransformMainService$Wonderjs.getRecord(state);
var basicMaterialRecord = RecordBasicMaterialMainService$Wonderjs.getRecord(state);
var lightMaterialRecord = RecordLightMaterialMainService$Wonderjs.getRecord(state);
var directionLightRecord = RecordDirectionLightMainService$Wonderjs.getRecord(state);
var pointLightRecord = RecordPointLightMainService$Wonderjs.getRecord(state);
var geometryRecord = RecordGeometryMainService$Wonderjs.getRecord(state);
var meshRendererRecord = RecordMeshRendererMainService$Wonderjs.getRecord(state);
var sourceInstanceRecord = RecordSourceInstanceMainService$Wonderjs.getRecord(state);
var match$2 = ScreenService$Wonderjs.queryFullScreenData(/* () */0);
return {
operateType: operateType,
canvas: canvas,
contextConfig: OperateSettingService$Wonderjs.unsafeGetContext(settingRecord),
isDebug: IsDebugMainService$Wonderjs.getIsDebug(stateData),
viewportData: /* array */[
match$2[0],
match$2[1],
match$2[2],
match$2[3]
],
bufferData: {
geometryPointCount: buffer[/* geometryPointCount */0],
geometryCount: buffer[/* geometryCount */1],
transformCount: buffer[/* transformCount */2],
basicMaterialCount: buffer[/* basicMaterialCount */3],
lightMaterialCount: buffer[/* lightMaterialCount */4],
meshRendererCount: buffer[/* meshRendererCount */10],
basicSourceTextureCount: buffer[/* basicSourceTextureCount */7],
arrayBufferViewSourceTextureCount: buffer[/* arrayBufferViewSourceTextureCount */8],
cubemapTextureCount: buffer[/* cubemapTextureCount */9],
directionLightCount: buffer[/* directionLightCount */5],
pointLightCount: buffer[/* pointLightCount */6]
},
gpuData: {
useHardwareInstance: match[/* useHardwareInstance */0]
},
memoryData: {
maxBigTypeArrayPoolSize: match$1[/* maxBigTypeArrayPoolSize */2]
},
instanceBufferData: {
sourceInstanceCount: BufferSettingService$Wonderjs.getSourceInstanceCount(settingRecord),
objectInstanceCountPerSourceInstance: BufferSettingService$Wonderjs.getObjectInstanceCountPerSourceInstance(settingRecord)
},
workerDetectData: {
isUseWorker: WorkerDetectMainService$Wonderjs.isUseWorker(state)
},
browserDetectData: {
browser: state[/* browserDetectRecord */42][/* browser */0]
},
renderConfigData: {
shaders: JSON.stringify(GetDataRenderConfigService$Wonderjs.getShaders(renderConfigRecord)),
shaderLibs: JSON.stringify(GetDataRenderConfigService$Wonderjs.getShaderLibs(renderConfigRecord))
},
transformData: {
buffer: CopyTransformService$Wonderjs.unsafeGetCopiedBuffer(transformRecord)
},
basicMaterialData: _buildMaterialData(basicMaterialRecord[/* buffer */1], basicMaterialRecord[/* index */0], basicMaterialRecord[/* disposedIndexArray */8], JudgeInstanceMainService$Wonderjs.buildMap(basicMaterialRecord[/* index */0], RecordBasicMaterialMainService$Wonderjs.getRecord(state)[/* gameObjectsMap */7], gameObjectRecord)),
lightMaterialData: _buildMaterialData(lightMaterialRecord[/* buffer */1], lightMaterialRecord[/* index */0], lightMaterialRecord[/* disposedIndexArray */12], JudgeInstanceMainService$Wonderjs.buildMap(lightMaterialRecord[/* index */0], RecordLightMaterialMainService$Wonderjs.getRecord(state)[/* gameObjectsMap */11], gameObjectRecord)),
geometryData: {
buffer: geometryRecord[/* buffer */1],
indicesTypeMap: geometryRecord[/* indicesTypeMap */17]
},
meshRendererData: {
buffer: meshRendererRecord[/* buffer */1]
},
directionLightData: {
buffer: directionLightRecord[/* buffer */1],
index: directionLightRecord[/* index */0],
renderLightArr: RenderArrayDirectionLightServivce$Wonderjs.getRenderLightArr(directionLightRecord)
},
pointLightData: {
buffer: pointLightRecord[/* buffer */1],
index: pointLightRecord[/* index */0],
renderLightArr: RenderArrayPointLightServivce$Wonderjs.getRenderLightArr(pointLightRecord)
},
sourceInstanceData: {
buffer: sourceInstanceRecord[/* buffer */2],
objectInstanceTransformIndexMap: sourceInstanceRecord[/* objectInstanceTransformIndexMap */1]
},
textureData: _buildTextureData(state),
imguiData: _buildIMGUIData(state)
};
}
function _clearData(state) {
return InitCubemapTextureMainService$Wonderjs.clearNeedInitedTextureIndexArray(InitSourceTextureMainService$Wonderjs.clearNeedInitedTextureIndexArray(OperateCubemapTextureMainService$Wonderjs.clearNeedAddedSourceArr(OperateSourceTextureMainService$Wonderjs.clearNeedAddedSourceArr(state))));
}
function execJob(flags, stateData) {
return MostUtils$Wonderjs.callFunc((function (param) {
var state = StateDataMainService$Wonderjs.unsafeGetState(stateData);
var viewRecord = state[/* viewRecord */8];
var workerInstanceRecord = state[/* workerInstanceRecord */39];
var operateType = JobConfigUtils$Wonderjs.getOperateType(flags);
var offscreen = ViewService$Wonderjs.unsafeGetCanvas(viewRecord).transferControlToOffscreen();
WorkerService$Wonderjs.postMessageWithTransferData(_buildData(operateType, offscreen, stateData), /* array */[offscreen], WorkerInstanceService$Wonderjs.unsafeGetRenderWorker(workerInstanceRecord));
var state$1 = _clearData(state);
StateDataMainService$Wonderjs.setState(stateData, state$1);
return Caml_option.some(operateType);
}));
}
exports._buildMaterialData = _buildMaterialData;
exports._buildTextureData = _buildTextureData;
exports._getFntData = _getFntData;
exports._buildIMGUIData = _buildIMGUIData;
exports._buildData = _buildData;
exports._clearData = _clearData;
exports.execJob = execJob;
/* Log-WonderLog Not a pure module */