private MyEntity CreateFromObjectBuilder(MyMwcObjectBuilder_Base objectBuilder) { if (objectBuilder.GetObjectBuilderType() == MyMwcObjectBuilderTypeEnum.VoxelMap) { MyMwcObjectBuilder_VoxelMap voxelMapObjectBuilder = objectBuilder as MyMwcObjectBuilder_VoxelMap; return(MyEntities.CreateFromObjectBuilderAndAdd(null, voxelMapObjectBuilder, Matrix.Identity)); } else if (objectBuilder.GetObjectBuilderType() == MyMwcObjectBuilderTypeEnum.VoxelMap_Neighbour) { // Voxel map neighbours are handled in its static classe, so ignore it here } else { if (objectBuilder is MyMwcObjectBuilder_Object3dBase || objectBuilder is MyMwcObjectBuilder_InfluenceSphere) { MyEntity temporaryEntity = null; Matrix matrix = Matrix.Identity; if (objectBuilder is MyMwcObjectBuilder_Object3dBase) { var object3d = objectBuilder as MyMwcObjectBuilder_Object3dBase; matrix = Matrix.CreateWorld(object3d.PositionAndOrientation.Position, object3d.PositionAndOrientation.Forward, object3d.PositionAndOrientation.Up); MyUtils.AssertIsValid(matrix); } temporaryEntity = MyEntities.CreateFromObjectBuilderAndAdd(null, objectBuilder, matrix); MyEntities.TestEntityAfterInsertionForCollision(temporaryEntity); return(temporaryEntity); } } return(null); }
public override void OnOkClick(MyGuiControlButton sender) { base.OnOkClick(sender); if (HasEntity()) { if (m_changeMaterial.Checked) { m_entity.VoxelMaterial = ((MyMwcVoxelMaterialsEnum)m_selectVoxelMapMaterialCombobox.GetSelectedKey()); } float x, y, z; if (float.TryParse(m_positionX.Text, out x) && float.TryParse(m_positionY.Text, out y) && float.TryParse(m_positionZ.Text, out z)) { m_entity.SetPosition(new Vector3(x, y, z)); } } else { if (GetAsteroidType() == MyGuiAsteroidTypesEnum.VOXEL) { MyMwcObjectBuilder_SmallShip_TypesEnum shipType = (MyMwcObjectBuilder_SmallShip_TypesEnum) Enum.ToObject(typeof(MyMwcObjectBuilder_SmallShip_TypesEnum), m_selectVoxelMapCombobox.GetSelectedKey()); MyMwcVoxelFilesEnum voxelFileEnum = (MyMwcVoxelFilesEnum) Enum.ToObject(typeof(MyMwcVoxelFilesEnum), m_selectVoxelMapCombobox.GetSelectedKey()); MyMwcVoxelMaterialsEnum materialEnum = (MyMwcVoxelMaterialsEnum) Enum.ToObject(typeof(MyMwcVoxelMaterialsEnum), m_selectVoxelMapMaterialCombobox.GetSelectedKey()); MyMwcObjectBuilder_VoxelMap voxelMapBuilder = MyMwcObjectBuilder_Base.CreateNewObject(MyMwcObjectBuilderTypeEnum.VoxelMap, null) as MyMwcObjectBuilder_VoxelMap; voxelMapBuilder.VoxelMaterial = materialEnum; voxelMapBuilder.VoxelFile = voxelFileEnum; MyEditor.Static.CreateFromObjectBuilder(voxelMapBuilder, Matrix.CreateWorld(m_newObjectPosition, Vector3.Forward, Vector3.Up), m_screenPosition); } else if (GetAsteroidType() == MyGuiAsteroidTypesEnum.STATIC) { MyMwcObjectBuilder_StaticAsteroid_TypesEnum staticAsteroidType = (MyMwcObjectBuilder_StaticAsteroid_TypesEnum) Enum.ToObject(typeof(MyMwcObjectBuilder_StaticAsteroid_TypesEnum), m_selectVoxelMapCombobox.GetSelectedKey()); MyMwcVoxelMaterialsEnum?materialEnum = null; int materialKey = m_selectVoxelMapMaterialCombobox.GetSelectedKey(); if (materialKey != -1) { materialEnum = (MyMwcVoxelMaterialsEnum)Enum.ToObject(typeof(MyMwcVoxelMaterialsEnum), materialKey); } MyMwcObjectBuilder_StaticAsteroid staticAsteroidBuilder = new MyMwcObjectBuilder_StaticAsteroid(staticAsteroidType, materialEnum); MyEditor.Static.CreateFromObjectBuilder(staticAsteroidBuilder, Matrix.CreateWorld(m_newObjectPosition, Vector3.Forward, Vector3.Up), m_screenPosition); } } MyGuiManager.CloseAllScreensExcept(MyGuiScreenGamePlay.Static); }
private void LoadFile(Vector3 position, MyMwcObjectBuilder_VoxelMap objectBuilder) { MyCompressionFileLoad decompressFile = null; if (objectBuilder.VoxelData != null) { decompressFile = new MyCompressionFileLoad(objectBuilder.VoxelData); } else { string voxelFilePath = MyVoxelFiles.Get(objectBuilder.VoxelFile).GetVoxFilePath(); m_voxelFile = objectBuilder.VoxelFile; decompressFile = new MyCompressionFileLoad(voxelFilePath); } MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("Decompress file header"); // Version of a VOX file int fileVersion = decompressFile.GetInt32(); // Not supported VOX file version MyCommonDebugUtils.AssertRelease(fileVersion == MyVoxelConstants.VOXEL_FILE_ACTUAL_VERSION); // Size of this voxel map (in voxels) int sizeX = decompressFile.GetInt32(); int sizeY = decompressFile.GetInt32(); int sizeZ = decompressFile.GetInt32(); // Size of data cell in voxels. Has to be the same as current size specified by our constants. int cellSizeX = decompressFile.GetInt32(); int cellSizeY = decompressFile.GetInt32(); int cellSizeZ = decompressFile.GetInt32(); MyCommonDebugUtils.AssertDebug( cellSizeX == MyVoxelConstants.VOXEL_DATA_CELL_SIZE_IN_VOXELS && cellSizeY == MyVoxelConstants.VOXEL_DATA_CELL_SIZE_IN_VOXELS && cellSizeZ == MyVoxelConstants.VOXEL_DATA_CELL_SIZE_IN_VOXELS); int cellsCountX = sizeX / cellSizeX; int cellsCountY = sizeY / cellSizeY; int cellsCountZ = sizeZ / cellSizeZ; // Init ore deposit cells if (MyFakes.ENABLE_DISPLAYING_ORE_ON_HUD) { m_oreDepositCellsCountX = cellsCountX / MyVoxelConstants.VOXEL_MAP_ORE_DEPOSIT_CELL_IN_DATA_CELLS; m_oreDepositCellsCountY = cellsCountY / MyVoxelConstants.VOXEL_MAP_ORE_DEPOSIT_CELL_IN_DATA_CELLS; m_oreDepositCellsCountZ = cellsCountZ / MyVoxelConstants.VOXEL_MAP_ORE_DEPOSIT_CELL_IN_DATA_CELLS; m_oreDepositCells = new Dictionary<long, MyVoxelMapOreDepositCell>(); } MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("InitVoxelMap"); // Init this voxel map (arrays are allocated, sizes calculated). It must be called before we start reading and seting voxels. InitVoxelMap(position, new MyMwcVector3Int(sizeX, sizeY, sizeZ), objectBuilder.VoxelMaterial); MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("Cells foreach"); MyMwcVector3Int cellCoord; for (cellCoord.X = 0; cellCoord.X < cellsCountX; cellCoord.X++) { for (cellCoord.Y = 0; cellCoord.Y < cellsCountY; cellCoord.Y++) { for (cellCoord.Z = 0; cellCoord.Z < cellsCountZ; cellCoord.Z++) { //MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("cell"); MyVoxelCellType cellType = (MyVoxelCellType)decompressFile.GetByte(); // Cell's are FULL by default, therefore we don't need to change them if (cellType != MyVoxelCellType.FULL) { MyVoxelContentCell newCell = AddCell(ref cellCoord); // If cell is empty we don't need to set all its voxels to empty. Just allocate cell and set its type to empty. if (cellType == MyVoxelCellType.EMPTY) { newCell.SetToEmpty(); } else if (cellType == MyVoxelCellType.MIXED) { decompressFile.GetBytes(cellSizeX * cellSizeY * cellSizeZ, buffer); if (!MyFakes.MWCURIOSITY) { newCell.SetAllVoxelContents(buffer); } } } //MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock(); } } } MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("Materials + indestructible"); if (!decompressFile.EndOfFile()) { // Read materials and indestructible for (cellCoord.X = 0; cellCoord.X < cellsCountX; cellCoord.X++) { for (cellCoord.Y = 0; cellCoord.Y < cellsCountY; cellCoord.Y++) { for (cellCoord.Z = 0; cellCoord.Z < cellsCountZ; cellCoord.Z++) { //MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("mat"); var matCell = m_voxelMaterialCells[cellCoord.X][cellCoord.Y][cellCoord.Z]; bool isSingleMaterial = decompressFile.GetByte() == 1; MyMwcVoxelMaterialsEnum material = MyMwcVoxelMaterialsEnum.Indestructible_01; byte indestructibleContent = 0; MyMwcVector3Int oreDepositCellCoord = GetOreDepositCellCoordByDataCellCoord(ref cellCoord); if (isSingleMaterial) { //MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("single material"); material = (MyMwcVoxelMaterialsEnum)decompressFile.GetByte(); indestructibleContent = MyVoxelMaterials.IsIndestructible(material) ? (byte)255 : (byte)0; this.SetVoxelMaterialAndIndestructibleContentForWholeCell(material, indestructibleContent, ref cellCoord); //MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock(); } else { //MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("mixed material"); MyMwcVector3Int voxelCoordInCell; for (voxelCoordInCell.X = 0; voxelCoordInCell.X < MyVoxelConstants.VOXEL_DATA_CELL_SIZE_IN_VOXELS; voxelCoordInCell.X++) { for (voxelCoordInCell.Y = 0; voxelCoordInCell.Y < MyVoxelConstants.VOXEL_DATA_CELL_SIZE_IN_VOXELS; voxelCoordInCell.Y++) { for (voxelCoordInCell.Z = 0; voxelCoordInCell.Z < MyVoxelConstants.VOXEL_DATA_CELL_SIZE_IN_VOXELS; voxelCoordInCell.Z++) { material = (MyMwcVoxelMaterialsEnum)decompressFile.GetByte(); indestructibleContent = decompressFile.GetByte(); matCell.SetMaterialAndIndestructibleContent(material, indestructibleContent, ref voxelCoordInCell); } } } matCell.CalcAverageCellMaterial(); //MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock(); } //MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock(); } } } } // compute ore deposits if (MyFakes.ENABLE_DISPLAYING_ORE_ON_HUD) { MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("Compute ore deposits"); for (cellCoord.X = 0; cellCoord.X < cellsCountX; cellCoord.X++) { for (cellCoord.Y = 0; cellCoord.Y < cellsCountY; cellCoord.Y++) { for (cellCoord.Z = 0; cellCoord.Z < cellsCountZ; cellCoord.Z++) { MyMwcVector3Int oreDepositCellCoord = GetOreDepositCellCoordByDataCellCoord(ref cellCoord); var matCell = m_voxelMaterialCells[cellCoord.X][cellCoord.Y][cellCoord.Z]; var contentCell = m_voxelContentCells[cellCoord.X][cellCoord.Y][cellCoord.Z]; if (matCell.IsSingleMaterialForWholeCell()) { //MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("single material"); var material = matCell.GetAverageCellMaterial(); if (MyVoxelMapOreMaterials.IsRareOre(material)) { int content = (contentCell == null) ? MyVoxelConstants.VOXEL_CELL_CONTENT_SUM_TOTAL : contentCell.GetVoxelContentSum(); if (GetOreDepositCell(ref oreDepositCellCoord) == null) { AddOreDepositCell(ref oreDepositCellCoord).SetOreContent(material, content); } } //MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock(); } else { //MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("more materials"); // buffer one rare material MyMwcVoxelMaterialsEnum bufferedMaterial = MyMwcVoxelMaterialsEnum.Ice_01; // IMPORTANT: the default value must be a rare material int bufferedContent = 0; MyMwcVector3Int voxelCoordInCell; for (voxelCoordInCell.X = 0; voxelCoordInCell.X < MyVoxelConstants.VOXEL_DATA_CELL_SIZE_IN_VOXELS; voxelCoordInCell.X++) { for (voxelCoordInCell.Y = 0; voxelCoordInCell.Y < MyVoxelConstants.VOXEL_DATA_CELL_SIZE_IN_VOXELS; voxelCoordInCell.Y++) { for (voxelCoordInCell.Z = 0; voxelCoordInCell.Z < MyVoxelConstants.VOXEL_DATA_CELL_SIZE_IN_VOXELS; voxelCoordInCell.Z++) { var material = matCell.GetMaterial(ref voxelCoordInCell); if (material == bufferedMaterial) // do we buffer this material? { int content = (contentCell == null) ? MyVoxelConstants.VOXEL_CONTENT_FULL : contentCell.GetVoxelContent(ref voxelCoordInCell); bufferedContent += content; // yes: just update the content } else { if (MyVoxelMapOreMaterials.IsRareOre(material)) // skip non-rare materials { int content = (contentCell == null) ? MyVoxelConstants.VOXEL_CONTENT_FULL : contentCell.GetVoxelContent(ref voxelCoordInCell); if (content > 0) // skip empty cells { // new rare material: if there's any old buffered content, add it to the deposit if (bufferedContent > 0 && GetOreDepositCell(ref oreDepositCellCoord) == null) { AddOreDepositCell(ref oreDepositCellCoord).SetOreContent(bufferedMaterial, bufferedContent); } bufferedMaterial = material; bufferedContent = content; } } } } } } if (bufferedContent > 0 && GetOreDepositCell(ref oreDepositCellCoord) == null) // if there's any buffered content left, add it to the deposit { AddOreDepositCell(ref oreDepositCellCoord).SetOreContent(bufferedMaterial, bufferedContent); } //MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock(); } } } } } }
public virtual void Init(string hudLabelText, Vector3 position, MyMwcObjectBuilder_VoxelMap objectBuilder) { StringBuilder hudLabelTextSb = (hudLabelText == null) ? null : new StringBuilder(hudLabelText); MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("base init"); base.Init(hudLabelTextSb, null, null, null, null, objectBuilder); MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("Decompress file"); LoadFile(position, objectBuilder); MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock(); }