예제 #1
0
 public void PasteChunkData(ChunkData chunkData)
 {
     GetChunk(chunkData.Pos).PasteChunkData(chunkData);
 }
예제 #2
0
 public void PasteChunkData(ChunkData chunkData)
 {
     GetChunk(chunkData.Pos).PasteChunkData(chunkData);
 }
예제 #3
0
        public void PasteChunkData(ChunkData chunkData)
        {
            if (chunkData == null)
            {
                throw new ArgumentNullException("chunkData");
            }

            IsCreated = chunkData.IsCreated;
            PasteChunkData(chunkData.Data);
        }
예제 #4
0
        public ushort this[int x, int y, int z]
        {
            get
            {
                int index = GetIndex(x, y, z);
                return _data == null ? (ushort)0 : _data[index];
            }

            set
            {
                int index = GetIndex(x, y, z);
                if (_data == null)
                {
                    if (value == 0)
                    {
                        return;
                    }

                    _data = new ushort[GeometryConstants.ChunkSize * GeometryConstants.ChunkSize * GeometryConstants.ChunkSize];
                }

                ushort oldValue = _data[index];
                if (oldValue != value)
                {
                    ContentHash = ContentHash - GetBlockHash(index, oldValue) + GetBlockHash(index, value);
                    _data[index] = value;
                    _chunkData = null;
                }
            }
        }
예제 #5
0
        public ChunkData GetChunkData()
        {
            if (_chunkData == null)
            {
                _chunkData = new ChunkData() { Pos = Pos, IsCreated = _isCreated };

                if (_data != null)
                {
                    using (var stream = new MemoryStream())
                    {
                        for (int i = 0; i < _data.Length; ++i)
                        {
                            ushort value = _data[i];
                            int length = 1;

                            while (length < 256 && i + length < _data.Length)
                            {
                                if (_data[i + length] == value)
                                {
                                    ++length;
                                }
                                else
                                {
                                    break;
                                }
                            }

                            stream.WriteByte((byte)(length - 1));
                            stream.WriteByte((byte)value);
                            stream.WriteByte((byte)(value >> 8));

                            i += length - 1;
                        }

                        _chunkData.Data = stream.ToArray();
                    }
                }
            }

            return _chunkData;
        }