示例#1
0
        public override void Write()
        {
            int totalDataDim = ChunksToSend.Count * 16 * Section.BYTESIZE;

            byte[] totalData = new byte[totalDataDim];
            int    index     = 0;

            foreach (Chunk chunkToSend in ChunksToSend)
            {
                MapChunkData chunkData = MapChunkPacket.GetMapChunkData(chunkToSend);
                _mapChunksData.Enqueue(chunkData);
                Buffer.BlockCopy(chunkData.Data, 0, totalData, index, chunkData.Data.Length);
                index += chunkData.Data.Length;
            }

            int length;

            byte[] compressedData = MapChunkPacket.CompressChunkData(totalData, index, out length);

            SetCapacity(7 + length + (12 * ChunksToSend.Count));

            Writer.Write((short)ChunksToSend.Count);
            Writer.Write(length);
            Writer.Write(compressedData, 0, length);

            foreach (Chunk chunkToSend in ChunksToSend)
            {
                MapChunkData chunkData = _mapChunksData.Dequeue();

                Writer.Write(chunkToSend.Coords.ChunkX);
                Writer.Write(chunkToSend.Coords.ChunkZ);
                Writer.Write((short)chunkData.PrimaryBitMask);
                Writer.Write((short)chunkData.AddBitMask);
            }
        }
示例#2
0
        public static MapChunkData GetMapChunkData(Chunk chunk, bool firstInit)
        {
            MapChunkData chunkData = new MapChunkData();

            ushort mask = 1;

            Queue <Section> sectionsToBeSent = new Queue <Section>();

            for (int i = 0; i < 16; ++i)
            {
                Section currentSection = chunk.Sections[i];
                if (currentSection != null && (firstInit || (chunk.SectionsToBeUpdated & 1) << i != 0))
                {
                    sectionsToBeSent.Enqueue(currentSection);
                }
            }

            int dataDim = sectionsToBeSent.Count * (Section.BYTESIZE + Section.SIZE);

            if (firstInit)
            {
                dataDim += 256;
            }

            chunkData.Data = new byte[dataDim];

            int halfSize       = sectionsToBeSent.Count * Section.HALFSIZE;
            int offsetData     = sectionsToBeSent.Count * Section.SIZE;
            int offsetLight    = offsetData + halfSize;
            int offsetSkyLight = offsetLight + halfSize;

            int sectionIndex = 0;

            while (sectionsToBeSent.Count > 0)
            {
                Section section = sectionsToBeSent.Dequeue();

                Buffer.BlockCopy(section.Types, 0, chunkData.Data, sectionIndex * Section.SIZE, Section.SIZE);
                Buffer.BlockCopy(section.Data.Data, 0, chunkData.Data, offsetData + (sectionIndex * Section.HALFSIZE),
                                 Section.HALFSIZE);

                Buffer.BlockCopy(chunk.Light.Data, section.SectionId * Section.HALFSIZE, chunkData.Data, offsetLight + (sectionIndex * Section.HALFSIZE),
                                 Section.HALFSIZE);
                Buffer.BlockCopy(chunk.SkyLight.Data, section.SectionId * Section.HALFSIZE, chunkData.Data, offsetSkyLight + (sectionIndex * Section.HALFSIZE),
                                 Section.HALFSIZE);


                chunkData.PrimaryBitMask |= mask << section.SectionId;
                ++sectionIndex;
                // TODO: we leave add array and biome array to 0 (ocean), we need to change the chunk generator accordingly
            }

            return(chunkData);
        }
示例#3
0
        public static MapChunkData GetMapChunkData(Chunk chunk)
        {
            MapChunkData chunkData = new MapChunkData();


            ushort mask         = 1;
            int    sectionIndex = 0;

            int sectionsSent = 0;

            for (int i = 0; i < 16; ++i)
            {
                Section currentSection = chunk.Sections[i];
                if (currentSection != null)
                {
                    ++sectionsSent;
                }
            }

            int dataDim = (sectionsSent * Section.BYTESIZE) + 256; // (Number of sections * (Section dimension + Add array) + Biome array

            chunkData.Data = new byte[dataDim];

            int halfSize       = sectionsSent * Section.HALFSIZE;
            int offsetData     = sectionsSent * Section.SIZE;
            int offsetLight    = offsetData + halfSize;
            int offsetSkyLight = offsetLight + halfSize;

            for (int i = 0; i < 16; ++i)
            {
                Section currentSection = chunk.Sections[i];

                if (currentSection != null)
                {
                    Buffer.BlockCopy(currentSection.Types, 0, chunkData.Data, sectionIndex * Section.SIZE, Section.SIZE);
                    Buffer.BlockCopy(currentSection.Data.Data, 0, chunkData.Data, offsetData + (sectionIndex * Section.HALFSIZE),
                                     Section.HALFSIZE);

                    Buffer.BlockCopy(chunk.Light.Data, i * Section.HALFSIZE, chunkData.Data, offsetLight + (sectionIndex * Section.HALFSIZE),
                                     Section.HALFSIZE);
                    Buffer.BlockCopy(chunk.SkyLight.Data, i * Section.HALFSIZE, chunkData.Data, offsetSkyLight + (sectionIndex * Section.HALFSIZE),
                                     Section.HALFSIZE);


                    chunkData.PrimaryBitMask |= mask << i;
                    ++sectionIndex;
                }

                // TODO: we leave add array and biome array to 0 (ocean), we need to change the chunk generator accordingly
            }

            return(chunkData);
        }
示例#4
0
        public static MapChunkData GetMapChunkData(Chunk chunk, bool firstInit)
        {
            MapChunkData chunkData = new MapChunkData();

            ushort mask = 1;

            Queue<Section> sectionsToBeSent = new Queue<Section>();
            for (int i = 0; i < 16; ++i)
            {
                Section currentSection = chunk.Sections[i];
                if (currentSection != null && (firstInit || (chunk.SectionsToBeUpdated & 1) << i != 0))
                {
                    sectionsToBeSent.Enqueue(currentSection);
                }
            }

            int dataDim = sectionsToBeSent.Count * (Section.BYTESIZE + Section.SIZE);

            if (firstInit)
                dataDim += 256;

            chunkData.Data = new byte[dataDim];

            int halfSize = sectionsToBeSent.Count * Section.HALFSIZE;
            int offsetData = sectionsToBeSent.Count * Section.SIZE;
            int offsetLight = offsetData + halfSize;
            int offsetSkyLight = offsetLight + halfSize;

            int sectionIndex = 0;
            while(sectionsToBeSent.Count > 0)
            {
                Section section = sectionsToBeSent.Dequeue();

                Buffer.BlockCopy(section.Types, 0, chunkData.Data, sectionIndex * Section.SIZE, Section.SIZE);
                Buffer.BlockCopy(section.Data.Data, 0, chunkData.Data, offsetData + (sectionIndex * Section.HALFSIZE),
                                    Section.HALFSIZE);

                Buffer.BlockCopy(chunk.Light.Data, section.SectionId * Section.HALFSIZE, chunkData.Data, offsetLight + (sectionIndex * Section.HALFSIZE),
                                    Section.HALFSIZE);
                Buffer.BlockCopy(chunk.SkyLight.Data, section.SectionId * Section.HALFSIZE, chunkData.Data, offsetSkyLight + (sectionIndex * Section.HALFSIZE),
                                    Section.HALFSIZE);


                chunkData.PrimaryBitMask |= mask << section.SectionId;
                ++sectionIndex;
                // TODO: we leave add array and biome array to 0 (ocean), we need to change the chunk generator accordingly
            }

            return chunkData;
        }
示例#5
0
        public override void Write()
        {
            MapChunkData chunkData = GetMapChunkData(Chunk);

            int len;

            byte[] chunkCompressed = CompressChunkData(chunkData.Data, chunkData.Data.Length, out len);


            SetCapacity(18 + len);
            Writer.Write(Coords.ChunkX);
            Writer.Write(Coords.ChunkZ);
            Writer.Write(false);     // Ground Up Continous
            Writer.Write((ushort)chunkData.PrimaryBitMask);
            Writer.Write((ushort)0); // Add BitMask
            Writer.Write(len);
            Writer.Write(chunkCompressed, 0, len);

#if PROFILE_MAPCHUNK
            start = DateTime.Now;
            comp  = new byte[DataDimension];

            // Original Java compression version
            //java.util.zip.Deflater deflater = new java.util.zip.Deflater(-1);
            //try
            //{
            //    deflater.setInput(data);
            //    deflater.finish();

            //    len = deflater.deflate(comp);
            //}
            //finally
            //{
            //    deflater.end();
            //}
            end = DateTime.Now;
            TimeSpan jTime   = end - start;
            int      jLength = len;

            writeDiffsLength.Add(deflateLength - jLength);
            writeDiffsTime.Add(deflateTime.TotalMilliseconds - jTime.TotalMilliseconds);

            Console.WriteLine("Avg {0}, {1}", writeDiffsLength.Average(), writeDiffsTime.Average());
#endif
        }
示例#6
0
        public static MapChunkData GetMapChunkData(Chunk chunk)
        {
            MapChunkData chunkData = new MapChunkData();

            ushort mask = 1;
            int sectionIndex = 0;

            int sectionsSent = 0;

            for (int i = 0; i < 16; ++i )
            {
                Section currentSection = chunk.Sections[i];
                if (currentSection != null)
                    ++sectionsSent;
            }

            int dataDim = (sectionsSent * Section.BYTESIZE) + 256; // (Number of sections * (Section dimension + Add array) + Biome array

            chunkData.Data = new byte[dataDim];

            int halfSize = sectionsSent * Section.HALFSIZE;
            int offsetData = sectionsSent * Section.SIZE;
            int offsetLight = offsetData + halfSize;
            int offsetSkyLight = offsetLight + halfSize;

            for (int i = 0; i < 16; ++i)
            {
                Section currentSection = chunk.Sections[i];

                if (currentSection != null)
                {
                    Buffer.BlockCopy(currentSection.Types, 0, chunkData.Data, sectionIndex * Section.SIZE, Section.SIZE);
                    Buffer.BlockCopy(currentSection.Data.Data, 0, chunkData.Data, offsetData + (sectionIndex * Section.HALFSIZE),
                                        Section.HALFSIZE);

                    Buffer.BlockCopy(chunk.Light.Data, i * Section.HALFSIZE, chunkData.Data, offsetLight + (sectionIndex * Section.HALFSIZE),
                                        Section.HALFSIZE);
                    Buffer.BlockCopy(chunk.SkyLight.Data, i * Section.HALFSIZE, chunkData.Data, offsetSkyLight + (sectionIndex * Section.HALFSIZE),
                                        Section.HALFSIZE);

                    chunkData.PrimaryBitMask |= mask << i;
                    ++sectionIndex;
                }

                // TODO: we leave add array and biome array to 0 (ocean), we need to change the chunk generator accordingly
            }

            return chunkData;
        }