Ejemplo n.º 1
0
        public void SaveChunkBlocks(TerrainChunk chunk)
        {
            _ = Time.RealTime;
            Terrain terrain = m_subsystemTerrain.Terrain;
            int     num     = chunk.Origin.X >> 4;
            int     num2    = chunk.Origin.Y >> 4;

            try
            {
                bool flag = false;
                if (m_chunkOffsets.TryGetValue(new Point2(num, num2), out int value))
                {
                    m_stream.Seek(value, SeekOrigin.Begin);
                }
                else
                {
                    flag  = true;
                    value = (int)m_stream.Length;
                    m_stream.Seek(value, SeekOrigin.Begin);
                }
                WriteChunkHeader(m_stream, num, num2);
                int num3 = 0;
                for (int i = 0; i < 16; i++)
                {
                    for (int j = 0; j < 16; j++)
                    {
                        int num4 = TerrainChunk.CalculateCellIndex(i, 0, j);
                        for (int k = 0; k < 256; k++)
                        {
                            int cellValueFast = chunk.GetCellValueFast(num4++);
                            m_buffer[num3++] = (byte)cellValueFast;
                            m_buffer[num3++] = (byte)(cellValueFast >> 8);
                        }
                    }
                }
                m_stream.Write(m_buffer, 0, 131072);
                num3 = 0;
                for (int l = 0; l < 16; l++)
                {
                    for (int m = 0; m < 16; m++)
                    {
                        int shaftValue = terrain.GetShaftValue(l + chunk.Origin.X, m + chunk.Origin.Y);
                        m_buffer[num3++] = (byte)shaftValue;
                        m_buffer[num3++] = (byte)(shaftValue >> 8);
                        m_buffer[num3++] = (byte)(shaftValue >> 16);
                        m_buffer[num3++] = (byte)(shaftValue >> 24);
                    }
                }
                m_stream.Write(m_buffer, 0, 1024);
                if (flag)
                {
                    m_stream.Flush();
                    int num5 = m_chunkOffsets.Count % 65536 * 3 * 4;
                    m_stream.Seek(num5, SeekOrigin.Begin);
                    WriteInt(m_stream, num);
                    WriteInt(m_stream, num2);
                    WriteInt(m_stream, value);
                    m_chunkOffsets[new Point2(num, num2)] = value;
                }
            }
            catch (Exception e)
            {
                Log.Error(ExceptionManager.MakeFullErrorMessage($"Error writing data for chunk ({num},{num2}).", e));
            }
            _ = Time.RealTime;
        }