Esempio n. 1
0
        // Set voxel content for the whole cell.
        public void SetAllVoxelContents(byte[] buffer)
        {
            // quantize the buffer and compute sum
            m_voxelContentSum = 0;
            for (int i = 0; i < buffer.Length; i++)
            {
                buffer[i]          = MyVoxelContentCellContent.QuantizedValue(buffer[i]);
                m_voxelContentSum += buffer[i];
            }

            // mixed-->empty/full: deallocate
            // empty/full-->mixed: allocate
            // mixed: fill with values from buffer
            if (m_voxelContentSum == 0)
            {
                if (CellType == MyVoxelCellType.MIXED)
                {
                    Deallocate();
                }
                CellType = MyVoxelCellType.EMPTY;
            }
            else if (m_voxelContentSum == MyVoxelConstants.VOXEL_CELL_CONTENT_SUM_TOTAL)
            {
                if (CellType == MyVoxelCellType.MIXED)
                {
                    Deallocate();
                }
                CellType = MyVoxelCellType.FULL;
            }
            else
            {
                if (CellType == MyVoxelCellType.FULL || CellType == MyVoxelCellType.EMPTY)
                {
                    m_cellContent = MyVoxelContentCellContents.Allocate();
                }
                if (m_cellContent != null)
                {
                    m_cellContent.Value.SetAddVoxelContents(buffer);
                }
                CellType = MyVoxelCellType.MIXED;
            }
        }
Esempio n. 2
0
        //  Voxel at specified coordinate 'x, y, z' sets to value 'content'. Coordinates are relative to voxel cell
        //  IMPORTANT: Do not call this method directly! Always call it through MyVoxelMap.SetVoxelContent()
        public void SetVoxelContent(byte content, ref MyMwcVector3Int voxelCoordInCell)
        {
            //MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("QuantizedValue");
            content = MyVoxelContentCellContent.QuantizedValue(content);
            //MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock();

            if (MyFakes.MWCURIOSITY)
            {
                if (content > MyVoxelConstants.VOXEL_ISO_LEVEL)
                {
                    content = MyVoxelConstants.VOXEL_CONTENT_FULL;
                }
                else
                {
                    content = MyVoxelConstants.VOXEL_CONTENT_EMPTY;
                }
            }


            if (CellType == MyVoxelCellType.FULL)
            {
                if (content == MyVoxelConstants.VOXEL_CONTENT_FULL)
                {
                    //  Nothing is changing
                    return;
                }
                else
                {
                    //MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("FULL:CheckCellType");
                    m_voxelContentSum -= (MyVoxelConstants.VOXEL_CONTENT_FULL - content);
                    CheckCellType();
                    //MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock();

                    //  If this cell is mixed, we change voxel's value in the cell content array, but first allocate the array
                    if (CellType == MyVoxelCellType.MIXED)
                    {
                        //MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("FULL:MyVoxelCellType.MIXED");

                        m_cellContent = MyVoxelContentCellContents.Allocate();
                        if (m_cellContent != null)
                        {
                            m_cellContent.Value.Reset(MyVoxelConstants.VOXEL_CONTENT_FULL);
                            m_cellContent.Value.SetVoxelContent(content, ref voxelCoordInCell);
                        }
                        //MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock();
                    }
                }
            }
            else if (CellType == MyVoxelCellType.EMPTY)
            {
                if (content == MyVoxelConstants.VOXEL_CONTENT_EMPTY)
                {
                    //  Nothing is changing
                    return;
                }
                else
                {
                    //MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("EMPTY:CheckCellType");
                    m_voxelContentSum += content;
                    CheckCellType();
                    //MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock();

                    //  If this cell is mixed, we change voxel's value in the cell content array, but first allocate the array
                    if (CellType == MyVoxelCellType.MIXED)
                    {
                        //MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("EMPTY:MyVoxelCellType.MIXED");
                        m_cellContent = MyVoxelContentCellContents.Allocate();
                        if (m_cellContent != null)
                        {
                            m_cellContent.Value.Reset(MyVoxelConstants.VOXEL_CONTENT_EMPTY);
                            m_cellContent.Value.SetVoxelContent(content, ref voxelCoordInCell);
                        }
                        //MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock();
                    }
                }
            }
            else if (CellType == MyVoxelCellType.MIXED)
            {
                if (m_cellContent == null)
                {
                    return;
                }
                //MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("MyVoxelCellType.MIXED");
                //  Check for previous content value not only for optimisation, but because we need to know how much it changed
                //  for calculating whole cell content summary.
                byte previousContent = m_cellContent.Value.GetVoxelContent(ref voxelCoordInCell);
                //MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock();

                if (previousContent == content)
                {
                    //  New value is same as current, so nothing needs to be changed
                    return;
                }

                m_voxelContentSum -= previousContent - content;
                CheckCellType();

                //  If this cell is still mixed, we change voxel's value in the cell content array
                if (CellType == MyVoxelCellType.MIXED)
                {
                    //MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("MIXED:MyVoxelCellType.MIXED");
                    m_cellContent.Value.SetVoxelContent(content, ref voxelCoordInCell);
                    //MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock();
                }
            }
            else
            {
                throw new MyMwcExceptionApplicationShouldNotGetHere();
            }
        }