예제 #1
0
        public static LayerDataPacket CreateLayerDataPacket(TerrainPatch[] patches, TerrainPatch.LayerType type)
        {
            LayerDataPacket layer = new LayerDataPacket {
                LayerID = { Type = (byte)type }
            };

            TerrainPatch.GroupHeader header = new TerrainPatch.GroupHeader
            {
                Stride    = STRIDE,
                PatchSize = 16,
                Type      = type
            };

            // Should be enough to fit even the most poorly packed data
            byte[]  data    = new byte[patches.Length * 16 * 16 * 2];
            BitPack bitpack = new BitPack(data, 0);

            bitpack.PackBits(header.Stride, 16);
            bitpack.PackBits(header.PatchSize, 8);
            bitpack.PackBits((int)header.Type, 8);

            foreach (TerrainPatch t in patches)
            {
                CreatePatch(bitpack, t.Data, t.X, t.Y);
            }

            bitpack.PackBits(END_OF_PATCHES, 8);

            layer.LayerData.Data = new byte[bitpack.BytePos + 1];
            Buffer.BlockCopy(bitpack.Data, 0, layer.LayerData.Data, 0, bitpack.BytePos + 1);

            return(layer);
        }
        private void LayerDataHandler(object sender, PacketReceivedEventArgs e)
        {
            LayerDataPacket layer   = (LayerDataPacket)e.Packet;
            BitPack         bitpack = new BitPack(layer.LayerData.Data, 0);

            TerrainPatch.GroupHeader header = new TerrainPatch.GroupHeader();
            TerrainPatch.LayerType   type   = (TerrainPatch.LayerType)layer.LayerID.Type;

            // Stride
            header.Stride = bitpack.UnpackBits(16);
            // Patch size
            header.PatchSize = bitpack.UnpackBits(8);
            // Layer type
            header.Type = (TerrainPatch.LayerType)bitpack.UnpackBits(8);

            switch (type)
            {
            case TerrainPatch.LayerType.Land:
                if (m_LandPatchReceivedEvent != null || Client.Settings.STORE_LAND_PATCHES)
                {
                    DecompressLand(e.Simulator, bitpack, header);
                }
                break;

            case TerrainPatch.LayerType.Water:
                Logger.Log("Got a Water LayerData packet, implement me!", Helpers.LogLevel.Error, Client);
                break;

            case TerrainPatch.LayerType.Wind:
                DecompressWind(e.Simulator, bitpack, header);
                break;

            case TerrainPatch.LayerType.Cloud:
                DecompressCloud(e.Simulator, bitpack, header);
                break;

            default:
                Logger.Log("Unrecognized LayerData type " + type.ToString(), Helpers.LogLevel.Warning, Client);
                break;
            }
        }